]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-3077: Use all rulesets for glyph substitution
authorSimon Steiner <ssteiner@apache.org>
Fri, 5 Aug 2022 07:04:37 +0000 (07:04 +0000)
committerSimon Steiner <ssteiner@apache.org>
Fri, 5 Aug 2022 07:04:37 +0000 (07:04 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1903233 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/complexscripts/fonts/GlyphSubstitutionTable.java
fop-core/src/test/java/org/apache/fop/complexscripts/fonts/GSUBTestCase.java

index e4065712d6ccc08abe5bad017819f75774f0146d..43a3bcb4ad5bec46a54a4fba79c2d46c20d61f25 100644 (file)
@@ -1146,19 +1146,20 @@ public class GlyphSubstitutionTable extends GlyphTable {
             assert (rv != null) && (rv.length > 0);
             assert rsa != null;
             if (rsa.length > 0) {
-                RuleSet rs = rsa [ 0 ];
-                if (rs != null) {
-                    Rule[] ra = rs.getRules();
-                    for (Rule r : ra) {
-                        if ((r != null) && (r instanceof ChainedClassSequenceRule)) {
-                            ChainedClassSequenceRule cr = (ChainedClassSequenceRule) r;
-                            int[] ica = cr.getClasses(icdt.getClassIndex(gi, ss.getClassMatchSet(gi)));
-                            if (matches(ss, icdt, ica, 0, rv)) {
-                                int[] bca = cr.getBacktrackClasses();
-                                if (matches(ss, bcdt, bca, -1, null)) {
-                                    int[] lca = cr.getLookaheadClasses();
-                                    if (matches(ss, lcdt, lca, rv[0], null)) {
-                                        return r.getLookups();
+                for (RuleSet rs : rsa) {
+                    if (rs != null) {
+                        Rule[] ra = rs.getRules();
+                        for (Rule r : ra) {
+                            if ((r != null) && (r instanceof ChainedClassSequenceRule)) {
+                                ChainedClassSequenceRule cr = (ChainedClassSequenceRule) r;
+                                int[] ica = cr.getClasses(icdt.getClassIndex(gi, ss.getClassMatchSet(gi)));
+                                if (matches(ss, icdt, ica, 0, rv)) {
+                                    int[] bca = cr.getBacktrackClasses();
+                                    if (matches(ss, bcdt, bca, -1, null)) {
+                                        int[] lca = cr.getLookaheadClasses();
+                                        if (matches(ss, lcdt, lca, rv[0], null)) {
+                                            return r.getLookups();
+                                        }
                                     }
                                 }
                             }
index 5519240c6c46efc12b02f19da6afa2e5e60c9462..ad43b920f746cf439a53a2f57b1836328a0589b6 100644 (file)
@@ -30,13 +30,15 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import org.apache.fop.apps.io.InternalResourceResolver;
+import org.apache.fop.apps.io.ResourceResolverFactory;
 import org.apache.fop.complexscripts.fonts.GlyphTable.LookupTable;
 import org.apache.fop.complexscripts.fonts.ttx.TTXFile;
 import org.apache.fop.complexscripts.util.GlyphContextTester;
 import org.apache.fop.complexscripts.util.GlyphSequence;
 import org.apache.fop.complexscripts.util.ScriptContextTester;
-
-// CSOFF: LineLength
+import org.apache.fop.fonts.MultiByteFont;
+import org.apache.fop.fonts.truetype.OFFontLoader;
 
 public class GSUBTestCase implements ScriptContextTester, GlyphContextTester {
 
@@ -120,7 +122,8 @@ public class GSUBTestCase implements ScriptContextTester, GlyphContextTester {
                         String[] ogia = ti[1];                  // output glyph id array
                         GlyphSequence igs = tf.getGlyphSequence(igia);
                         GlyphSequence ogs = tf.getGlyphSequence(ogia);
-                        GlyphSequence tgs = GlyphSubstitutionSubtable.substitute(igs, script, language, feature, sta, sct);
+                        GlyphSequence tgs =
+                                GlyphSubstitutionSubtable.substitute(igs, script, language, feature, sta, sct);
                         assertSameGlyphs(ogs, tgs);
                     }
                 }
@@ -151,7 +154,8 @@ public class GSUBTestCase implements ScriptContextTester, GlyphContextTester {
         }
     }
 
-    private GlyphSubstitutionSubtable[] findGSUBSubtables(GlyphSubstitutionTable gsub, String script, String language, String feature, String lid) {
+    private GlyphSubstitutionSubtable[] findGSUBSubtables(
+            GlyphSubstitutionTable gsub, String script, String language, String feature, String lid) {
         LookupTable lt = gsub.getLookupTable(lid);
         if (lt != null) {
             return (GlyphSubstitutionSubtable[]) lt.getSubtables();
@@ -191,4 +195,17 @@ public class GSUBTestCase implements ScriptContextTester, GlyphContextTester {
         GlyphClassTable classTable = GlyphClassTable.createClassTable(Collections.singletonList(coverageTable));
         assertNotNull(classTable);
     }
+
+    @Test
+    public void testSubRuleSets() throws Exception {
+        File fontfile = new File("test/resources/fonts/ttf/DejaVuLGCSerif.ttf");
+        InternalResourceResolver resourceResolver =
+                ResourceResolverFactory.createDefaultInternalResourceResolver(new File(".").toURI());
+        OFFontLoader fontLoader = new OFFontLoader(fontfile.toURI(), resourceResolver);
+        MultiByteFont font = (MultiByteFont) fontLoader.getFont();
+        String in = "\u006A\u0301";
+        String out = "\u0237\u0301";
+        String sub = font.performSubstitution(in, "latn", "dflt", null, false).toString();
+        assertEquals(sub, out);
+    }
 }