From: Simon Steiner Date: Fri, 5 Aug 2022 07:04:37 +0000 (+0000) Subject: FOP-3077: Use all rulesets for glyph substitution X-Git-Tag: fop-2_8~2^2~21 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a68ad9321fa53bb4704ecf70f257e6aa40853d85;p=xmlgraphics-fop.git FOP-3077: Use all rulesets for glyph substitution git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1903233 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/fop-core/src/main/java/org/apache/fop/complexscripts/fonts/GlyphSubstitutionTable.java b/fop-core/src/main/java/org/apache/fop/complexscripts/fonts/GlyphSubstitutionTable.java index e4065712d..43a3bcb4a 100644 --- a/fop-core/src/main/java/org/apache/fop/complexscripts/fonts/GlyphSubstitutionTable.java +++ b/fop-core/src/main/java/org/apache/fop/complexscripts/fonts/GlyphSubstitutionTable.java @@ -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(); + } } } } diff --git a/fop-core/src/test/java/org/apache/fop/complexscripts/fonts/GSUBTestCase.java b/fop-core/src/test/java/org/apache/fop/complexscripts/fonts/GSUBTestCase.java index 5519240c6..ad43b920f 100644 --- a/fop-core/src/test/java/org/apache/fop/complexscripts/fonts/GSUBTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/complexscripts/fonts/GSUBTestCase.java @@ -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); + } }