diff options
author | Robert Meyer <rmeyer@apache.org> | 2015-08-04 15:05:19 +0000 |
---|---|---|
committer | Robert Meyer <rmeyer@apache.org> | 2015-08-04 15:05:19 +0000 |
commit | 1e7790e82370eaf36efe6751667b2c369ec59ca1 (patch) | |
tree | 975b8b6501b5223039d1bf0c3620e801495b7911 /test | |
parent | 5a7195cae382c971145f722d9404174c17827c99 (diff) | |
download | xmlgraphics-fop-1e7790e82370eaf36efe6751667b2c369ec59ca1.tar.gz xmlgraphics-fop-1e7790e82370eaf36efe6751667b2c369ec59ca1.zip |
FOP-2486 - Enhancements and fixes to existing patchTemp_PCLSoftFonts
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_PCLSoftFonts@1694075 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r-- | test/java/org/apache/fop/render/pcl/fonts/PCLTTFFontReaderTestCase.java | 80 | ||||
-rw-r--r-- | test/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFCharacterWriterTestCase.java | 2 |
2 files changed, 80 insertions, 2 deletions
diff --git a/test/java/org/apache/fop/render/pcl/fonts/PCLTTFFontReaderTestCase.java b/test/java/org/apache/fop/render/pcl/fonts/PCLTTFFontReaderTestCase.java index 88c613e7d..5673efbb4 100644 --- a/test/java/org/apache/fop/render/pcl/fonts/PCLTTFFontReaderTestCase.java +++ b/test/java/org/apache/fop/render/pcl/fonts/PCLTTFFontReaderTestCase.java @@ -18,9 +18,12 @@ /* $Id$ */ package org.apache.fop.render.pcl.fonts; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -33,6 +36,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.apache.fop.fonts.CustomFont; +import org.apache.fop.fonts.SingleByteFont; import org.apache.fop.render.java2d.CustomFontMetricsMapper; import org.apache.fop.render.pcl.fonts.PCLFontSegment.SegmentID; import org.apache.fop.render.pcl.fonts.truetype.PCLTTFFontReader; @@ -53,7 +57,13 @@ public class PCLTTFFontReaderTestCase { CustomFont sbFont = mock(CustomFont.class); when(sbFont.getInputStream()).thenReturn(new FileInputStream(new File(TEST_FONT_A))); when(customFont.getRealFont()).thenReturn(sbFont); + SingleByteFont font = mock(SingleByteFont.class); + when(font.getGIDFromChar('h')).thenReturn(104); + when(font.getGIDFromChar('e')).thenReturn(101); + when(font.getGIDFromChar('l')).thenReturn(108); + when(font.getGIDFromChar('o')).thenReturn(111); PCLTTFFontReader reader = new MockPCLTTFFontReader(customFont, byteWriter); + reader.setFont(font); verifyFontData(reader); validateOffsets(reader); validateFontSegments(reader); @@ -103,7 +113,13 @@ public class PCLTTFFontReaderTestCase { * @throws IOException */ private void validateFontSegments(PCLTTFFontReader reader) throws IOException { - List<PCLFontSegment> segments = reader.getFontSegments(); + HashMap<Character, Integer> mappedChars = new HashMap<Character, Integer>(); + mappedChars.put('H', 1); + mappedChars.put('e', 1); + mappedChars.put('l', 1); + mappedChars.put('o', 1); + + List<PCLFontSegment> segments = reader.getFontSegments(mappedChars); assertEquals(segments.size(), 5); for (PCLFontSegment segment : segments) { if (segment.getIdentifier() == SegmentID.PA) { @@ -111,10 +127,72 @@ public class PCLTTFFontReaderTestCase { assertEquals(segment.getData().length, 10); byte[] panose = {2, 6, 6, 3, 5, 6, 5, 2, 2, 4}; assertArrayEquals(segment.getData(), panose); + } else if (segment.getIdentifier() == SegmentID.GT) { + verifyGlobalTrueTypeData(segment, mappedChars.size()); } else if (segment.getIdentifier() == SegmentID.NULL) { // Terminating segment assertEquals(segment.getData().length, 0); } } } + + private void verifyGlobalTrueTypeData(PCLFontSegment segment, int mappedCharsSize) + throws IOException { + byte[] ttfData = segment.getData(); + int currentPos = 0; + //Version + assertEquals(readInt(new byte[]{ttfData[currentPos++], ttfData[currentPos++]}), 1); + assertEquals(readInt(new byte[]{ttfData[currentPos++], ttfData[currentPos++]}), 0); + //Number of tables + int numTables = readInt(new byte[]{ttfData[currentPos++], ttfData[currentPos++]}); + assertEquals(numTables, 8); + //Search range + assertEquals(readInt(new byte[]{ttfData[currentPos++], ttfData[currentPos++]}), 128); + //Entry Selector + assertEquals(readInt(new byte[]{ttfData[currentPos++], ttfData[currentPos++]}), 3); + //Range shift + assertEquals(readInt(new byte[]{ttfData[currentPos++], ttfData[currentPos++]}), 0); + String[] validTags = {"head", "hhea", "hmtx", "maxp", "gdir"}; + int matches = 0; + for (int i = 0; i < numTables; i++) { + String tag = readTag(new byte[]{ttfData[currentPos++], ttfData[currentPos++], + ttfData[currentPos++], ttfData[currentPos++]}); + if (Arrays.asList(validTags).contains(tag)) { + matches++; + } + if (tag.equals("hmtx")) { + currentPos += 4; + int offset = readLong(new byte[]{ttfData[currentPos++], ttfData[currentPos++], + ttfData[currentPos++], ttfData[currentPos++]}); + int length = readLong(new byte[]{ttfData[currentPos++], ttfData[currentPos++], + ttfData[currentPos++], ttfData[currentPos++]}); + verifyHmtx(ttfData, offset, length, mappedCharsSize); + } else { + currentPos += 12; + } + } + assertEquals(matches, 5); + } + + private void verifyHmtx(byte[] ttfData, int offset, int length, int mappedCharsSize) + throws IOException { + ByteArrayInputStream bais = new ByteArrayInputStream(ttfData); + byte[] subsetHmtx = new byte[length]; + bais.skip(offset); + bais.read(subsetHmtx); + assertEquals(subsetHmtx.length, (mappedCharsSize + 32) * 4); + } + + private int readInt(byte[] bytes) { + return ((0xFF & bytes[0]) << 8) | (0xFF & bytes[1]); + } + + private int readLong(byte[] bytes) { + return ((0xFF & bytes[0]) << 24) | ((0xFF & bytes[1]) << 16) | ((0xFF & bytes[2]) << 8) + | (0xFF & bytes[3]); + } + + private String readTag(byte[] tag) { + return new String(tag); + } } diff --git a/test/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFCharacterWriterTestCase.java b/test/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFCharacterWriterTestCase.java index 10263d067..04849db87 100644 --- a/test/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFCharacterWriterTestCase.java +++ b/test/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFCharacterWriterTestCase.java @@ -46,7 +46,7 @@ public class PCLTTFCharacterWriterTestCase { public void verifyCharacterDefinition() throws Exception { CustomFont sbFont = mock(CustomFont.class); when(customFont.getRealFont()).thenReturn(sbFont); - softFont = new PCLSoftFont(1, customFont); + softFont = new PCLSoftFont(1, customFont, false); TTFFile openFont = new TTFFile(); FontFileReader reader = new FontFileReader(new FileInputStream(new File(TEST_FONT_A))); String header = OFFontLoader.readHeader(reader); |