@Override public int readUnsignedShort() throws IOException { return stream.readUnsignedShort(); }
/** * Reads a format 6 subtable. * * @param data the data stream of the to be parsed ttf font * @param numGlyphs number of glyphs to be read * @throws IOException If there is an error parsing the true type font. */ protected void processSubtype6(TTFDataStream data, int numGlyphs) throws IOException { int firstCode = data.readUnsignedShort(); int entryCount = data.readUnsignedShort(); // skip emtpy tables if (entryCount == 0) { return; } characterCodeToGlyphId = new HashMap<>(numGlyphs); int[] glyphIdArray = data.readUnsignedShortArray(entryCount); int maxGlyphId = 0; for (int i = 0; i < entryCount; i++) { maxGlyphId = Math.max(maxGlyphId, glyphIdArray[i]); characterCodeToGlyphId.put(firstCode + i, glyphIdArray[i]); } buildGlyphIdToCharacterCodeLookup(maxGlyphId); }
/** * Read an unsigned short array. * * @param length The length of the array to read. * @return An unsigned short array. * @throws IOException If there is an error reading the data. */ public int[] readUnsignedShortArray(int length) throws IOException { int[] array = new int[length]; for (int i = 0; i < length; i++) { array[i] = readUnsignedShort(); } return array; }
/** * This will read the required data from the stream. * * @param ttf The font that is being read. * @param data The stream to read the data from. * @throws IOException If there is an error reading the data. */ public void initData( TrueTypeFont ttf, TTFDataStream data ) throws IOException { platformId = data.readUnsignedShort(); platformEncodingId = data.readUnsignedShort(); languageId = data.readUnsignedShort(); nameId = data.readUnsignedShort(); stringLength = data.readUnsignedShort(); stringOffset = data.readUnsignedShort(); }
private RangeRecord readRangeRecord(TTFDataStream data) throws IOException { int startGlyphID = data.readUnsignedShort(); int endGlyphID = data.readUnsignedShort(); int startCoverageIndex = data.readUnsignedShort(); return new RangeRecord(startGlyphID, endGlyphID, startCoverageIndex); }
@Override public void read(TTFDataStream data) throws IOException { int numPairs = data.readUnsignedShort(); searchRange = data.readUnsignedShort()/6; int entrySelector = data.readUnsignedShort(); int rangeShift = data.readUnsignedShort(); pairs = new int[numPairs][3]; for (int i = 0; i < numPairs; ++i) { int left = data.readUnsignedShort(); int right = data.readUnsignedShort(); int value = data.readSignedShort(); pairs[i][0] = left; pairs[i][1] = right; pairs[i][2] = value; } }
/** * This will read the required data from the stream. * * @param data The stream to read the data from. * @throws IOException If there is an error reading the data. */ public void initData(TTFDataStream data) throws IOException { platformId = data.readUnsignedShort(); platformEncodingId = data.readUnsignedShort(); subTableOffset = data.readUnsignedInt(); }
/** * This will read the required data from the stream. * * @param ttf The font that is being read. * @param data The stream to read the data from. * @throws IOException If there is an error reading the data. */ public void read(TrueTypeFont ttf, TTFDataStream data) throws IOException { version = data.read32Fixed(); numGlyphs = data.readUnsignedShort(); maxPoints = data.readUnsignedShort(); maxContours = data.readUnsignedShort(); maxCompositePoints = data.readUnsignedShort(); maxCompositeContours = data.readUnsignedShort(); maxZones = data.readUnsignedShort(); maxTwilightPoints = data.readUnsignedShort(); maxStorage = data.readUnsignedShort(); maxFunctionDefs = data.readUnsignedShort(); maxInstructionDefs = data.readUnsignedShort(); maxStackElements = data.readUnsignedShort(); maxSizeOfInstructions = data.readUnsignedShort(); maxComponentElements = data.readUnsignedShort(); maxComponentDepth = data.readUnsignedShort(); initialized = true; } }
private LangSysTable readLangSysTable(TTFDataStream data, long offset) throws IOException { data.seek(offset); int lookupOrder = data.readUnsignedShort(); int requiredFeatureIndex = data.readUnsignedShort(); int featureIndexCount = data.readUnsignedShort(); int[] featureIndices = new int[featureIndexCount]; for (int i = 0; i < featureIndexCount; i++) { featureIndices[i] = data.readUnsignedShort(); } return new LangSysTable(lookupOrder, requiredFeatureIndex, featureIndexCount, featureIndices); }
private FeatureTable readFeatureTable(TTFDataStream data, long offset) throws IOException { data.seek(offset); int featureParams = data.readUnsignedShort(); int lookupIndexCount = data.readUnsignedShort(); int[] lookupListIndices = new int[lookupIndexCount]; for (int i = 0; i < lookupIndexCount; i++) { lookupListIndices[i] = data.readUnsignedShort(); } return new FeatureTable(featureParams, lookupIndexCount, lookupListIndices); }
private LigatureTable readLigatureTable(TTFDataStream data, long ligatureTableLocation, int coverageGlyphId) throws IOException { data.seek(ligatureTableLocation); int ligatureGlyph = data.readUnsignedShort(); int componentCount = data.readUnsignedShort(); int[] componentGlyphIDs = new int[componentCount]; componentGlyphIDs[0] = coverageGlyphId; for (int i = 1; i <= componentCount - 1; i++) { componentGlyphIDs[i] = data.readUnsignedShort(); } return new LigatureTable(ligatureGlyph, componentCount, componentGlyphIDs); }
/** * Read a 16.16 fixed value, where the first 16 bits are the decimal and the last 16 bits are the fraction. * * @return A 32 bit value. * @throws IOException If there is an error reading the data. */ public float read32Fixed() throws IOException { float retval = 0; retval = readSignedShort(); retval += (readUnsignedShort() / 65536.0); return retval; }
private LookupListTable readLookupList(TTFDataStream data, long offset) throws IOException { data.seek(offset); int lookupCount = data.readUnsignedShort(); int[] lookups = new int[lookupCount]; for (int i = 0; i < lookupCount; i++) { lookups[i] = data.readUnsignedShort(); } LookupTable[] lookupTables = new LookupTable[lookupCount]; for (int i = 0; i < lookupCount; i++) { lookupTables[i] = readLookupTable(data, offset + lookups[i]); } return new LookupListTable(lookupCount, lookupTables); }
/** * This will read the required data from the stream. * * @param ttf The font that is being read. * @param data The stream to read the data from. * @throws IOException If there is an error reading the data. */ @Override public void read(TrueTypeFont ttf, TTFDataStream data) throws IOException { version = data.read32Fixed(); defaultVertOriginY = data.readSignedShort(); int numVertOriginYMetrics = data.readUnsignedShort(); origins = new ConcurrentHashMap<>(numVertOriginYMetrics); for (int i = 0; i < numVertOriginYMetrics; ++i) { int g = data.readUnsignedShort(); int y = data.readSignedShort(); origins.put(g, y); } initialized = true; }
private LigatureSetTable readLigatureSetTable(TTFDataStream data, long ligatureSetTableLocation, int coverageGlyphId) throws IOException { data.seek(ligatureSetTableLocation); int ligatureCount = data.readUnsignedShort(); LOG.debug("ligatureCount=" + ligatureCount); int[] ligatureOffsets = new int[ligatureCount]; LigatureTable[] ligatureTables = new LigatureTable[ligatureCount]; for (int i = 0; i < ligatureOffsets.length; i++) { ligatureOffsets[i] = data.readUnsignedShort(); } for (int i = 0; i < ligatureOffsets.length; i++) { int ligatureOffset = ligatureOffsets[i]; ligatureTables[i] = readLigatureTable(data, ligatureSetTableLocation + ligatureOffset, coverageGlyphId); } return new LigatureSetTable(ligatureCount, ligatureTables); }
@Override @SuppressWarnings({"squid:S1854"}) void read(TrueTypeFont ttf, TTFDataStream data) throws IOException { long start = data.getCurrentPosition(); @SuppressWarnings({"unused"}) int majorVersion = data.readUnsignedShort(); int minorVersion = data.readUnsignedShort(); int scriptListOffset = data.readUnsignedShort(); int featureListOffset = data.readUnsignedShort(); int lookupListOffset = data.readUnsignedShort(); @SuppressWarnings({"unused"}) long featureVariationsOffset = -1L; if (minorVersion == 1L) { featureVariationsOffset = data.readUnsignedInt(); } scriptList = readScriptList(data, start + scriptListOffset); featureListTable = readFeatureList(data, start + featureListOffset); lookupListTable = readLookupList(data, start + lookupListOffset); GlyphSubstitutionDataExtractor glyphSubstitutionDataExtractor = new GlyphSubstitutionDataExtractor(); gsubData = glyphSubstitutionDataExtractor .getGsubData(scriptList, featureListTable, lookupListTable); }
/** * This will read the required data from the stream. * * @param ttf The font that is being read. * @param data The stream to read the data from. * @throws IOException If there is an error reading the data. */ @Override public void read(TrueTypeFont ttf, TTFDataStream data) throws IOException { @SuppressWarnings({"unused", "squid:S1854", "squid:S1481"}) int version = data.readUnsignedShort(); int numberOfTables = data.readUnsignedShort(); cmaps = new CmapSubtable[numberOfTables]; for (int i = 0; i < numberOfTables; i++) { CmapSubtable cmap = new CmapSubtable(); cmap.initData(data); cmaps[i] = cmap; } for (int i = 0; i < numberOfTables; i++) { cmaps[i].initSubtable(this, ttf.getNumberOfGlyphs(), data); } initialized = true; }
private Map<String, ScriptTable> readScriptList(TTFDataStream data, long offset) throws IOException { data.seek(offset); int scriptCount = data.readUnsignedShort(); ScriptTable[] scriptTables= new ScriptTable[scriptCount]; int[] scriptOffsets = new int[scriptCount]; String[] scriptTags = new String[scriptCount]; for (int i = 0; i < scriptCount; i++) { scriptTags[i] = data.readString(4); scriptOffsets[i] = data.readUnsignedShort(); } for (int i = 0; i < scriptCount; i++) { scriptTables[i] = readScriptTable(data, offset + scriptOffsets[i]); } Map<String, ScriptTable> resultScriptList = new LinkedHashMap<>(scriptCount); for (int i = 0; i < scriptCount; i++) { ScriptRecord scriptRecord = new ScriptRecord(scriptTags[i], scriptTables[i]); resultScriptList.put(scriptRecord.getScriptTag(), scriptRecord.getScriptTable()); } return Collections.unmodifiableMap(resultScriptList); }
private FeatureListTable readFeatureList(TTFDataStream data, long offset) throws IOException { data.seek(offset); int featureCount = data.readUnsignedShort(); FeatureRecord[] featureRecords = new FeatureRecord[featureCount]; int[] featureOffsets = new int[featureCount]; String[] featureTags = new String[featureCount]; for (int i = 0; i < featureCount; i++) { featureTags[i] = data.readString(4); featureOffsets[i] = data.readUnsignedShort(); } for (int i = 0; i < featureCount; i++) { FeatureTable featureTable = readFeatureTable(data, offset + featureOffsets[i]); featureRecords[i] = new FeatureRecord(featureTags[i], featureTable); } return new FeatureListTable(featureCount, featureRecords); }
/** * Constructor. * * @param bais the stream to be read * @param glyphTable the Glyphtable containing all glyphs * @throws IOException is thrown if something went wrong */ public GlyfCompositeDescript(TTFDataStream bais, GlyphTable glyphTable) throws IOException { super((short) -1, bais); this.glyphTable = glyphTable; // Get all of the composite components GlyfCompositeComp comp; do { comp = new GlyfCompositeComp(bais); components.add(comp); } while ((comp.getFlags() & GlyfCompositeComp.MORE_COMPONENTS) != 0); // Are there hinting instructions to read? if ((comp.getFlags() & GlyfCompositeComp.WE_HAVE_INSTRUCTIONS) != 0) { readInstructions(bais, (bais.readUnsignedShort())); } initDescriptions(); }