git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1763525 13f79535-47bb-0310-9956-ffa450edef68pull/3/head
@@ -21,6 +21,7 @@ package org.apache.fop.complexscripts.fonts; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogFactory; | |||
@@ -72,8 +73,8 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
* Instantiate a <code>GlyphDefinitionTable</code> object using the specified subtables. | |||
* @param subtables a list of identified subtables | |||
*/ | |||
public GlyphDefinitionTable(List subtables) { | |||
super(null, new HashMap(0)); | |||
public GlyphDefinitionTable(List subtables, Map<String, ScriptProcessor> processors) { | |||
super(null, new HashMap(0), processors); | |||
if ((subtables == null) || (subtables.size() == 0)) { | |||
throw new AdvancedTypographicTableFormatException("subtables must be non-empty"); | |||
} else { | |||
@@ -101,7 +102,7 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
* @return the reordered (output) glyph sequence | |||
*/ | |||
public GlyphSequence reorderCombiningMarks(GlyphSequence gs, int[] widths, int[][] gpa, String script, String language) { | |||
ScriptProcessor sp = ScriptProcessor.getInstance(script); | |||
ScriptProcessor sp = ScriptProcessor.getInstance(script, processors); | |||
return sp.reorderCombiningMarks(this, gs, widths, gpa, script, language); | |||
} | |||
@@ -71,8 +71,9 @@ public class GlyphPositioningTable extends GlyphTable { | |||
* @param lookups a map of lookup specifications to subtable identifier strings | |||
* @param subtables a list of identified subtables | |||
*/ | |||
public GlyphPositioningTable(GlyphDefinitionTable gdef, Map lookups, List subtables) { | |||
super(gdef, lookups); | |||
public GlyphPositioningTable(GlyphDefinitionTable gdef, Map lookups, List subtables, | |||
Map<String, ScriptProcessor> processors) { | |||
super(gdef, lookups, processors); | |||
if ((subtables == null) || (subtables.size() == 0)) { | |||
throw new AdvancedTypographicTableFormatException("subtables must be non-empty"); | |||
} else { | |||
@@ -234,7 +235,7 @@ public class GlyphPositioningTable extends GlyphTable { | |||
public boolean position(GlyphSequence gs, String script, String language, int fontSize, int[] widths, int[][] adjustments) { | |||
Map<LookupSpec, List<LookupTable>> lookups = matchLookups(script, language, "*"); | |||
if ((lookups != null) && (lookups.size() > 0)) { | |||
ScriptProcessor sp = ScriptProcessor.getInstance(script); | |||
ScriptProcessor sp = ScriptProcessor.getInstance(script, processors); | |||
return sp.position(this, gs, script, language, fontSize, lookups, widths, adjustments); | |||
} else { | |||
return false; |
@@ -69,8 +69,9 @@ public class GlyphSubstitutionTable extends GlyphTable { | |||
* @param lookups a map of lookup specifications to subtable identifier strings | |||
* @param subtables a list of identified subtables | |||
*/ | |||
public GlyphSubstitutionTable(GlyphDefinitionTable gdef, Map lookups, List subtables) { | |||
super(gdef, lookups); | |||
public GlyphSubstitutionTable(GlyphDefinitionTable gdef, Map lookups, List subtables, | |||
Map<String, ScriptProcessor> processors) { | |||
super(gdef, lookups, processors); | |||
if ((subtables == null) || (subtables.size() == 0)) { | |||
throw new AdvancedTypographicTableFormatException("subtables must be non-empty"); | |||
} else { | |||
@@ -96,7 +97,7 @@ public class GlyphSubstitutionTable extends GlyphTable { | |||
GlyphSequence ogs; | |||
Map<LookupSpec, List<LookupTable>> lookups = matchLookups(script, language, "*"); | |||
if ((lookups != null) && (lookups.size() > 0)) { | |||
ScriptProcessor sp = ScriptProcessor.getInstance(script); | |||
ScriptProcessor sp = ScriptProcessor.getInstance(script, processors); | |||
ogs = sp.substitute(this, gs, script, language, lookups); | |||
} else { | |||
ogs = gs; |
@@ -33,6 +33,7 @@ import java.util.TreeSet; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogFactory; | |||
import org.apache.fop.complexscripts.scripts.ScriptProcessor; | |||
import org.apache.fop.complexscripts.util.GlyphSequence; | |||
import org.apache.fop.complexscripts.util.ScriptContextTester; | |||
@@ -74,12 +75,16 @@ public class GlyphTable { | |||
// if true, then prevent further subtable addition | |||
private boolean frozen; | |||
protected Map<String, ScriptProcessor> processors; | |||
/** | |||
* Instantiate glyph table with specified lookups. | |||
* @param gdef glyph definition table that applies | |||
* @param lookups map from lookup specs to lookup tables | |||
*/ | |||
public GlyphTable(GlyphTable gdef, Map<LookupSpec, List<String>> lookups) { | |||
public GlyphTable(GlyphTable gdef, Map<LookupSpec, List<String>> lookups, | |||
Map<String, ScriptProcessor> processors) { | |||
this.processors = processors; | |||
if ((gdef != null) && !(gdef instanceof GlyphDefinitionTable)) { | |||
throw new AdvancedTypographicTableFormatException("bad glyph definition table"); | |||
} else if (lookups == null) { |
@@ -21,12 +21,14 @@ package org.apache.fop.complexscripts.fonts; | |||
import java.io.IOException; | |||
import java.util.Arrays; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogFactory; | |||
import org.apache.fop.complexscripts.scripts.ScriptProcessor; | |||
import org.apache.fop.fonts.truetype.FontFileReader; | |||
import org.apache.fop.fonts.truetype.OFDirTabEntry; | |||
import org.apache.fop.fonts.truetype.OFTableName; | |||
@@ -57,6 +59,7 @@ public final class OTFAdvancedTypographicTableReader { | |||
private transient GlyphMappingTable seMapping; // subtable entry mappings | |||
private transient List seEntries; // subtable entry entries | |||
private transient List seSubtables; // subtable entry subtables | |||
private Map<String, ScriptProcessor> processors = new HashMap<String, ScriptProcessor>(); | |||
/** | |||
* Construct an <code>OTFAdvancedTypographicTableReader</code> instance. | |||
@@ -3515,7 +3518,7 @@ public final class OTFAdvancedTypographicTableReader { | |||
List subtables; | |||
if ((subtables = constructGDEFSubtables()) != null) { | |||
if (subtables.size() > 0) { | |||
gdef = new GlyphDefinitionTable(subtables); | |||
gdef = new GlyphDefinitionTable(subtables, processors); | |||
} | |||
} | |||
resetATState(); | |||
@@ -3534,7 +3537,7 @@ public final class OTFAdvancedTypographicTableReader { | |||
List subtables; | |||
if ((subtables = constructGSUBSubtables()) != null) { | |||
if ((lookups.size() > 0) && (subtables.size() > 0)) { | |||
gsub = new GlyphSubstitutionTable(gdef, lookups, subtables); | |||
gsub = new GlyphSubstitutionTable(gdef, lookups, subtables, processors); | |||
} | |||
} | |||
} | |||
@@ -3554,7 +3557,7 @@ public final class OTFAdvancedTypographicTableReader { | |||
List subtables; | |||
if ((subtables = constructGPOSSubtables()) != null) { | |||
if ((lookups.size() > 0) && (subtables.size() > 0)) { | |||
gpos = new GlyphPositioningTable(gdef, lookups, subtables); | |||
gpos = new GlyphPositioningTable(gdef, lookups, subtables, processors); | |||
} | |||
} | |||
} |
@@ -46,8 +46,6 @@ public abstract class ScriptProcessor { | |||
private final Map<AssembledLookupsKey, GlyphTable.UseSpec[]> assembledLookups; | |||
private static Map<String, ScriptProcessor> processors = new HashMap<String, ScriptProcessor>(); | |||
/** | |||
* Instantiate a script processor. | |||
* @param script a script identifier | |||
@@ -229,7 +227,7 @@ public abstract class ScriptProcessor { | |||
* @param script a script identifier | |||
* @return a script processor instance or null if none found | |||
*/ | |||
public static synchronized ScriptProcessor getInstance(String script) { | |||
public static synchronized ScriptProcessor getInstance(String script, Map<String, ScriptProcessor> processors) { | |||
ScriptProcessor sp = null; | |||
assert processors != null; | |||
if ((sp = processors.get(script)) == null) { |
@@ -62,6 +62,7 @@ import org.apache.fop.complexscripts.fonts.GlyphSubstitutionTable.LigatureSet; | |||
import org.apache.fop.complexscripts.fonts.GlyphSubtable; | |||
import org.apache.fop.complexscripts.fonts.GlyphTable; | |||
import org.apache.fop.complexscripts.fonts.GlyphTable.RuleLookup; | |||
import org.apache.fop.complexscripts.scripts.ScriptProcessor; | |||
import org.apache.fop.complexscripts.util.GlyphSequence; | |||
import org.apache.fop.complexscripts.util.UTF32; | |||
import org.apache.fop.util.CharUtilities; | |||
@@ -162,6 +163,7 @@ public class TTXFile { | |||
private GlyphDefinitionTable gdef; // constructed glyph definition table | |||
private GlyphSubstitutionTable gsub; // constructed glyph substitution table | |||
private GlyphPositioningTable gpos; // constructed glyph positioning table | |||
private Map<String, ScriptProcessor> processors = new HashMap<String, ScriptProcessor>(); | |||
public TTXFile() { | |||
elements = new Stack<String[]>(); | |||
@@ -2326,17 +2328,17 @@ public class TTXFile { | |||
} | |||
} else if (en[1].equals("GDEF")) { | |||
if (subtables.size() > 0) { | |||
gdef = new GlyphDefinitionTable(subtables); | |||
gdef = new GlyphDefinitionTable(subtables, processors); | |||
} | |||
clearTable(); | |||
} else if (en[1].equals("GPOS")) { | |||
if (subtables.size() > 0) { | |||
gpos = new GlyphPositioningTable(gdef, extractLookups(), subtables); | |||
gpos = new GlyphPositioningTable(gdef, extractLookups(), subtables, processors); | |||
} | |||
clearTable(); | |||
} else if (en[1].equals("GSUB")) { | |||
if (subtables.size() > 0) { | |||
gsub = new GlyphSubstitutionTable(gdef, extractLookups(), subtables); | |||
gsub = new GlyphSubstitutionTable(gdef, extractLookups(), subtables, processors); | |||
} | |||
clearTable(); | |||
} else if (en[1].equals("GlyphClassDef")) { |
@@ -21,6 +21,7 @@ package org.apache.fop.complexscripts.scripts.arabic; | |||
import java.nio.IntBuffer; | |||
import java.util.BitSet; | |||
import java.util.HashMap; | |||
import org.junit.Test; | |||
@@ -74,7 +75,7 @@ public class ArabicJoinersTestCase { | |||
@Test | |||
public void testArabicJoiners() { | |||
String script = CharScript.scriptTagFromCode(CharScript.SCRIPT_ARABIC); | |||
ScriptProcessor sp = ScriptProcessor.getInstance(script); | |||
ScriptProcessor sp = ScriptProcessor.getInstance(script, new HashMap<String, ScriptProcessor>()); | |||
assertTrue(sp != null); | |||
ScriptContextTester sct = sp.getSubstitutionContextTester(); | |||
assertTrue(sct != null); |