aboutsummaryrefslogtreecommitdiffstats
path: root/test/java
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2012-10-08 17:47:48 +0000
committerVincent Hennebert <vhennebert@apache.org>2012-10-08 17:47:48 +0000
commitd9d2ec28c23c9dc69dd87c1060ea506ad08beca8 (patch)
treecb1a215d26b61bd6f6581a2962d9384f2149df12 /test/java
parentd261730a4f7be752ae12a5ec52e6bad8ee4fa5c1 (diff)
downloadxmlgraphics-fop-d9d2ec28c23c9dc69dd87c1060ea506ad08beca8.tar.gz
xmlgraphics-fop-d9d2ec28c23c9dc69dd87c1060ea506ad08beca8.zip
Bugzilla #53980: PDF accessibility: Store language information coming from fo:block or fo:character in the structure tree.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1395692 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java')
-rw-r--r--test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java5
-rw-r--r--test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl13
-rw-r--r--test/java/org/apache/fop/accessibility/fo/language.fo30
-rw-r--r--test/java/org/apache/fop/fo/properties/CommonHyphenationTestCase.java58
4 files changed, 105 insertions, 1 deletions
diff --git a/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java b/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java
index 87b970576..a86b5b2b2 100644
--- a/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java
+++ b/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java
@@ -96,6 +96,11 @@ public class FO2StructureTreeConverterTestCase {
testConverter("table-header_scope.fo");
}
+ @Test
+ public void testLanguage() throws Exception {
+ testConverter("language.fo");
+ }
+
private static InputStream getResource(String name) {
return FO2StructureTreeConverterTestCase.class.getResourceAsStream(name);
}
diff --git a/test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl b/test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl
index 90d74a7c4..a9de38db1 100644
--- a/test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl
+++ b/test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl
@@ -150,11 +150,22 @@
<xsl:template match="fo:leader"/>
- <!-- Keep fox:alt-text and role attributes, discard everything else -->
+ <!-- Keep the relevant attributes, discard everything else -->
<xsl:template match="@fox:alt-text|@role">
<xsl:copy-of select="."/>
</xsl:template>
+ <xsl:template match="fo:block/@language[. != ../ancestor::*[@language][1]/@language]
+ |fo:character/@language[. != ../ancestor::*[@language][1]/@language]">
+ <xsl:attribute name="xml:lang">
+ <xsl:value-of select="."/>
+ <xsl:if test="../@country[. != 'none']">
+ <xsl:text>-</xsl:text>
+ <xsl:value-of select="../@country"/>
+ </xsl:if>
+ </xsl:attribute>
+ </xsl:template>
+
<xsl:template match="@*"/>
diff --git a/test/java/org/apache/fop/accessibility/fo/language.fo b/test/java/org/apache/fop/accessibility/fo/language.fo
new file mode 100644
index 000000000..8dfb2694a
--- /dev/null
+++ b/test/java/org/apache/fop/accessibility/fo/language.fo
@@ -0,0 +1,30 @@
+<?xml version="1.0" standalone="no"?>
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
+ xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"
+ font-family="sans-serif">
+ <fo:layout-master-set>
+ <fo:simple-page-master master-name="page"
+ page-height="170pt" page-width="220pt" margin="10pt">
+ <fo:region-body display-align="center"/>
+ </fo:simple-page-master>
+ </fo:layout-master-set>
+ <fo:page-sequence master-reference="page" language="en" country="GB">
+ <fo:flow flow-name="xsl-region-body" line-height="10pt" font-size="8pt" space-before="5pt"
+ space-after="5pt">
+ <fo:block>This block of text is written in the default language of the page sequence, which is
+ British English.</fo:block>
+ <fo:block language="fr" country="FR" space-before="inherit" space-after="inherit">Ce text est
+ écrit dans une autre langue, en l’occurence le français de France.
+ <fo:block language="en" country="US" space-before="inherit" start-indent="1em"
+ space-after="inherit">However, this block of French text encloses a block of American
+ English.
+ <fo:block space-before="inherit" start-indent="2em" space-after="inherit" language="en"
+ country="US">The structure element corresponding to this block should have no language
+ set as it is the same as on the parent block.</fo:block></fo:block>
+ Maintenant on revient au français.</fo:block>
+ <fo:block space-before="inherit">And now we are back to the English language, with a
+ <fo:character character="F" language="fr" country="none" color="blue"/>rench
+ character.</fo:block>
+ </fo:flow>
+ </fo:page-sequence>
+</fo:root>
diff --git a/test/java/org/apache/fop/fo/properties/CommonHyphenationTestCase.java b/test/java/org/apache/fop/fo/properties/CommonHyphenationTestCase.java
new file mode 100644
index 000000000..029146413
--- /dev/null
+++ b/test/java/org/apache/fop/fo/properties/CommonHyphenationTestCase.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fo.properties;
+
+import java.util.Locale;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+public class CommonHyphenationTestCase {
+
+ private final String lang = "en";
+
+ @Test
+ public void testToLocaleNull() {
+ Locale locale = CommonHyphenation.toLocale(null, null);
+ assertNull(locale);
+ locale = CommonHyphenation.toLocale("none", null);
+ assertNull(locale);
+ locale = CommonHyphenation.toLocale("NoNe", "US");
+ assertNull(locale);
+ }
+
+ @Test
+ public void testToLocaleWithJustLanguage() {
+ Locale locale = new Locale(lang);
+ assertEquals(locale, CommonHyphenation.toLocale(lang, null));
+ assertEquals(locale, CommonHyphenation.toLocale(lang, "none"));
+ assertEquals(locale, CommonHyphenation.toLocale(lang, "NONE"));
+ }
+
+ @Test
+ public void testToLocaleWithLanguageAndCountry() {
+ Locale locale = new Locale(lang, "US");
+ assertEquals(locale, CommonHyphenation.toLocale(lang, "US"));
+ assertEquals(locale, CommonHyphenation.toLocale(lang, "us"));
+ }
+
+}