Bläddra i källkod

FOP-3129: Symbol font was not being mapped to unicode

tags/2_9
Simon Steiner 1 år sedan
förälder
incheckning
6696559fc6

+ 17
- 11
fop-core/src/main/java/org/apache/fop/fonts/truetype/OpenFont.java Visa fil

unicodeMappings.add(new UnicodeMapping(this, glyphIdx, j)); unicodeMappings.add(new UnicodeMapping(this, glyphIdx, j));
mtxTab[glyphIdx].getUnicodeIndex().add(j); mtxTab[glyphIdx].getUnicodeIndex().add(j);


if (encodingID == 0 && j >= 0xF020 && j <= 0xF0FF) {
//Experimental: Mapping 0xF020-0xF0FF to 0x0020-0x00FF
//Tested with Wingdings and Symbol TTF fonts which map their
//glyphs in the region 0xF020-0xF0FF.
int mapped = j - 0xF000;
if (!eightBitGlyphs.get(mapped)) {
//Only map if Unicode code point hasn't been mapped before
unicodeMappings.add(new UnicodeMapping(this, glyphIdx, mapped));
mtxTab[glyphIdx].getUnicodeIndex().add(mapped);
}
}
mapSymbol(encodingID, j, eightBitGlyphs, glyphIdx);


// Also add winAnsiWidth // Also add winAnsiWidth
List<Integer> v = ansiIndex.get(j); List<Integer> v = ansiIndex.get(j);
+ mtxTab.length); + mtxTab.length);
} }


mapSymbol(encodingID, j, eightBitGlyphs, glyphIdx);

// Also add winAnsiWidth // Also add winAnsiWidth
List<Integer> v = ansiIndex.get(j); List<Integer> v = ansiIndex.get(j);
if (v != null) { if (v != null) {
return true; return true;
} }


private void mapSymbol(int encodingID, int unicodeIndex, BitSet eightBitGlyphs, int glyphIdx) {
if (encodingID == 0 && unicodeIndex >= 0xF020 && unicodeIndex <= 0xF0FF) {
/* Experimental: Mapping 0xF020-0xF0FF to 0x0020-0x00FF
Tested with Wingdings and Symbol TTF fonts which map their
glyphs in the region 0xF020-0xF0FF. */
int mapped = unicodeIndex - 0xF000;
if (!eightBitGlyphs.get(mapped)) {
//Only map if Unicode code point hasn't been mapped before
unicodeMappings.add(new UnicodeMapping(this, glyphIdx, mapped));
mtxTab[glyphIdx].getUnicodeIndex().add(mapped);
}
}
}

private boolean isInPrivateUseArea(int start, int end) { private boolean isInPrivateUseArea(int start, int end) {
return (isInPrivateUseArea(start) || isInPrivateUseArea(end)); return (isInPrivateUseArea(start) || isInPrivateUseArea(end));
} }

+ 37
- 0
fop-core/src/test/java/org/apache/fop/fonts/truetype/TTFFileTestCase.java Visa fil

ttfFile.updateBBoxAndOffset(); ttfFile.updateBBoxAndOffset();
Assert.assertEquals(ttfFile.mtxTab[0].getBoundingBox()[0], 4); Assert.assertEquals(ttfFile.mtxTab[0].getBoundingBox()[0], 4);
} }

@Test
public void testSymbolCmap() throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
dos.writeShort(0);
dos.writeShort(1); //num tables
dos.writeShort(3); //cmapPID
dos.writeShort(0); //cmapEID
dos.writeInt(12); //cmapOffset
dos.writeShort(4); //cmapFormat
dos.writeShort(0); //skip cmap length
dos.writeShort(0); //skip cmap version
dos.writeShort(2); //cmapSegCountX2
dos.writeShort(0); //cmapSearchRange
dos.writeShort(0); //cmapEntrySelector
dos.writeShort(0); //cmapRangeShift
dos.writeShort(0xF020); //cmapEndCounts
dos.writeShort(0); //Skip reservedPad
dos.writeShort(0xF020); //cmapStartCounts
dos.writeShort(0); //cmapDeltas
dos.writeShort(0); //cmapRangeOffsets
TTFFile symbolTTFFile = new TTFFile();
symbolTTFFile.mtxTab = new OFMtxEntry[0xF020 + 1];
symbolTTFFile.mtxTab[0] = new OFMtxEntry();
symbolTTFFile.mtxTab[0xF020] = new OFMtxEntry();
symbolTTFFile.dirTabs = new HashMap<>();
symbolTTFFile.dirTabs.put(OFTableName.CMAP, new OFDirTabEntry());
symbolTTFFile.fontFile = new FontFileReader(new ByteArrayInputStream(bos.toByteArray()));
symbolTTFFile.initAnsiWidths();
symbolTTFFile.readCMAP();
Assert.assertEquals(symbolTTFFile.unicodeMappings.get(0).getUnicodeIndex(), 0xF020);
Assert.assertEquals(symbolTTFFile.unicodeMappings.get(0).getGlyphIndex(), 0xF020);
Assert.assertEquals(symbolTTFFile.unicodeMappings.get(1).getUnicodeIndex(), 32);
Assert.assertEquals(symbolTTFFile.unicodeMappings.get(1).getGlyphIndex(), 0xF020);
Assert.assertEquals(symbolTTFFile.unicodeMappings.size(), 2);
}
} }

Laddar…
Avbryt
Spara