Added: 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFFontReader.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFFontReader.java?rev=1685112&view=auto
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFFontReader.java
 (added)
+++ 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFFontReader.java
 Fri Jun 12 15:52:55 2015
@@ -0,0 +1,619 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.pcl.fonts.truetype;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.fop.fonts.CustomFont;
+import org.apache.fop.fonts.Typeface;
+import org.apache.fop.fonts.truetype.FontFileReader;
+import org.apache.fop.fonts.truetype.OFDirTabEntry;
+import org.apache.fop.fonts.truetype.OFFontLoader;
+import org.apache.fop.fonts.truetype.OFMtxEntry;
+import org.apache.fop.fonts.truetype.OFTableName;
+import org.apache.fop.fonts.truetype.OpenFont;
+import org.apache.fop.fonts.truetype.TTFFile;
+import org.apache.fop.render.java2d.CustomFontMetricsMapper;
+import org.apache.fop.render.pcl.fonts.PCLByteWriterUtil;
+import org.apache.fop.render.pcl.fonts.PCLFontReader;
+import org.apache.fop.render.pcl.fonts.PCLFontSegment;
+import org.apache.fop.render.pcl.fonts.PCLFontSegment.SegmentID;
+import org.apache.fop.render.pcl.fonts.PCLSymbolSet;
+
+public class PCLTTFFontReader extends PCLFontReader {
+    protected TTFFile ttfFont;
+    protected InputStream fontStream;
+    protected FontFileReader reader;
+    private PCLTTFPCLTFontTable pcltTable;
+    private PCLTTFOS2FontTable os2Table;
+    private PCLTTFPOSTFontTable postTable;
+    private PCLTTFTableFactory ttfTableFactory;
+
+    private static final int HMTX_RESTRICT_SIZE = 50000;
+
+    private static final Map<Integer, Integer> FONT_WEIGHT = new 
HashMap<Integer, Integer>() {
+        private static final long serialVersionUID = 1L;
+        {
+            put(100, -6); // 100 Thin
+            put(200, -4); // 200 Extra-Light
+            put(300, -3); // 300 Light
+            put(400, 0); // 400 Normal (Regular)
+            put(500, 0); // 500 Medium
+            put(600, 2); // 600 Semi-bold
+            put(700, 3); // 700 Bold
+            put(800, 4); // 800 Extra-bold
+            put(900, 5); // 900 Black (Heavy)
+        }
+    };
+
+    private static final Map<Integer, Integer> FONT_SERIF = new 
HashMap<Integer, Integer>() {
+        private static final long serialVersionUID = 1L;
+        {
+            /** The following are the best guess conversion between serif 
styles. Unfortunately
+             *  there appears to be no standard and so each specification has 
it's own set of values.
+             *  Please change if better fit found. **/
+            put(0, 0); // Any = Normal Sans
+            put(1, 64); // No Fit = Sans Serif
+            put(2, 9); // Cove = Script Nonconnecting
+            put(3, 12); // Obtuse Cove = Script Broken Letter
+            put(4, 10); // Square Cove = Script Joining
+            put(5, 0); // Obtuse Square Cove = Sans Serif Square
+            put(6, 128); // Square = Serif
+            put(7, 2); // Thin = Serif Line
+            put(8, 7); // Bone = Rounded Bracket
+            put(9, 11); // Exeraggerated = Script Calligraphic
+            put(10, 3); // Triangle = Serif Triangle
+            put(11, 0); // Normal Sans = Sans Serif Square
+            put(12, 4); // Obtuse Sans = Serif Swath
+            put(13, 6); // Perp Sans = Serif Bracket
+            put(14, 8); // Flared = Flair Serif
+            put(15, 1); // Rounded = Sans Serif Round
+        }
+    };
+
+    private static final Map<Integer, Integer> FONT_WIDTH = new 
HashMap<Integer, Integer>() {
+        private static final long serialVersionUID = 1L;
+        {
+            /** The conversions between TTF and PCL are not 1 to 1 **/
+            put(1, -5); // 1 = Ultra Compressed
+            put(2, -4); // 2 = Extra Compressed
+            put(3, -3); // 3 = Compresses
+            put(4, -2); // 4 = Condensed
+            put(5, 0); // 5 = Normal
+            put(6, 2); // 6 = Expanded
+            put(7, 3); // 5 = Extra Expanded
+        }
+    };
+
+    private int scaleFactor = -1;
+    private PCLSymbolSet symbolSet = PCLSymbolSet.Bound_Generic;
+
+    public PCLTTFFontReader(Typeface font, PCLByteWriterUtil pclByteWriter) 
throws IOException {
+        super(font, pclByteWriter);
+        loadFont();
+    }
+
+    protected void loadFont() throws IOException {
+        if (typeface instanceof CustomFontMetricsMapper) {
+            CustomFontMetricsMapper fontMetrics = (CustomFontMetricsMapper) 
typeface;
+            CustomFont customFont = (CustomFont) fontMetrics.getRealFont();
+            fontStream = customFont.getInputStream();
+            reader = new FontFileReader(fontStream);
+
+            ttfFont = new TTFFile();
+            String header = OFFontLoader.readHeader(reader);
+            ttfFont.readFont(reader, header, customFont.getFullName());
+            readFontTables();
+        } else {
+            // TODO - Handle when typeface is not in the expected format for a 
PCL TrueType object
+        }
+    }
+
+    protected void readFontTables() throws IOException {
+        PCLTTFTable fontTable;
+        fontTable = readFontTable(OFTableName.PCLT);
+        if (fontTable instanceof PCLTTFPCLTFontTable) {
+            pcltTable = (PCLTTFPCLTFontTable) fontTable;
+        }
+        fontTable = readFontTable(OFTableName.OS2);
+        if (fontTable instanceof PCLTTFOS2FontTable) {
+            os2Table = (PCLTTFOS2FontTable) fontTable;
+        }
+        fontTable = readFontTable(OFTableName.POST);
+        if (fontTable instanceof PCLTTFPOSTFontTable) {
+            postTable = (PCLTTFPOSTFontTable) fontTable;
+        }
+    }
+
+    private PCLTTFTable readFontTable(OFTableName tableName) throws 
IOException {
+        if (ttfFont.seekTab(reader, tableName, 0)) {
+            return getTTFTableFactory().newInstance(tableName);
+        }
+        return null;
+    }
+
+    private PCLTTFTableFactory getTTFTableFactory() {
+        if (ttfTableFactory == null) {
+            ttfTableFactory = PCLTTFTableFactory.getInstance(reader);
+        }
+        return ttfTableFactory;
+    }
+
+    @Override
+    public int getDescriptorSize() {
+        return 72; // Descriptor size (leave at 72 for our purposes)
+    }
+
+    @Override
+    public int getHeaderFormat() {
+        return 15; // TrueType Scalable Font
+    }
+
+    @Override
+    public int getFontType() {
+        if (symbolSet == PCLSymbolSet.Unbound) {
+            return 11; // Font Type - Unbound TrueType Scalable font
+        } else {
+            return 2; // 0-255 (except 0, 7 and 27)
+        }
+    }
+
+    @Override
+    public int getStyleMSB() {
+        if (pcltTable != null) {
+            return getMSB(pcltTable.getStyle());
+        }
+        return 3;
+    }
+
+    @Override
+    public int getBaselinePosition() {
+        return 0; // Baseline position must be set to 0 for TTF fonts
+    }
+
+    @Override
+    public int getCellWidth() {
+        int[] bbox = ttfFont.getBBoxRaw();
+        return bbox[2] - bbox[0];
+    }
+
+    @Override
+    public int getCellHeight() {
+        int[] bbox = ttfFont.getBBoxRaw();
+        return bbox[3] - bbox[1];
+    }
+
+    @Override
+    public int getOrientation() {
+        return 0; // Scalable fonts (TrueType) must be 0
+    }
+
+    @Override
+    public int getSpacing() {
+        if (os2Table != null) {
+            return (os2Table.getPanose()[4] == 9) ? 0 : 1;
+        } else if (postTable != null) {
+            return postTable.getIsFixedPitch();
+        }
+        return 1;
+    }
+
+    @Override
+    public int getSymbolSet() {
+        if (pcltTable != null) {
+            return pcltTable.getSymbolSet();
+        } else {
+            return symbolSet.getKind1();
+        }
+    }
+
+    @Override
+    public int getPitch() {
+        int pitch = ttfFont.getCharWidthRaw(0x20);
+        if (pitch < 0) {
+            // No advance width found for the space character
+            return 0;
+        }
+        return pitch;
+    }
+
+    @Override
+    public int getHeight() {
+        return 0; // Fixed zero value for TrueType fonts
+    }
+
+    @Override
+    public int getXHeight() {
+        if (pcltTable != null) {
+            return pcltTable.getXHeight();
+        } else if (os2Table != null) {
+            return os2Table.getXHeight();
+        }
+        return 0;
+    }
+
+    @Override
+    public int getWidthType() {
+        if (pcltTable != null) {
+            return pcltTable.getWidthType();
+        } else if (os2Table != null) {
+            return convertTTFWidthClass(os2Table.getWidthClass());
+        }
+        return 0;
+    }
+
+    private int convertTTFWidthClass(int widthClass) {
+        if (FONT_WIDTH.containsKey(widthClass)) {
+            return FONT_WIDTH.get(widthClass);
+        } else {
+            return 0; // No match - return normal
+        }
+    }
+
+    @Override
+    public int getStyleLSB() {
+        if (pcltTable != null) {
+            return getLSB(pcltTable.getStyle());
+        }
+        return 224;
+    }
+
+    @Override
+    public int getStrokeWeight() {
+        if (pcltTable != null) {
+            return pcltTable.getStrokeWeight();
+        } else if (os2Table != null) {
+            return convertTTFWeightClass(os2Table.getWeightClass());
+        }
+        return 0;
+    }
+
+    private int convertTTFWeightClass(int weightClass) {
+        if (FONT_WEIGHT.containsKey(weightClass)) {
+            return FONT_WEIGHT.get(weightClass);
+        } else {
+            return 0; // No match - return normal
+        }
+    }
+
+    @Override
+    public int getTypefaceLSB() {
+        if (pcltTable != null) {
+            return getLSB(pcltTable.getTypeFamily());
+        }
+        return 254;
+    }
+
+    @Override
+    public int getTypefaceMSB() {
+        if (pcltTable != null) {
+            return getMSB(pcltTable.getTypeFamily());
+        }
+        return 0;
+    }
+
+    @Override
+    public int getSerifStyle() {
+        if (pcltTable != null) {
+            return pcltTable.getSerifStyle();
+        } else {
+            return convertFromTTFSerifStyle();
+        }
+    }
+
+    private int convertFromTTFSerifStyle() {
+        if (os2Table != null) {
+            int serifStyle = os2Table.getPanose()[1];
+            return FONT_SERIF.get(serifStyle);
+        }
+        return 0;
+    }
+
+    @Override
+    public int getQuality() {
+        return 2; // Letter quality
+    }
+
+    @Override
+    public int getPlacement() {
+        return 0; // Fixed value of 0 for TrueType (scalable fonts)
+    }
+
+    @Override
+    public int getUnderlinePosition() {
+        return 0; // Scalable fonts has a fixed value of 0 - See Master 
Underline Position
+    }
+
+    @Override
+    public int getUnderlineThickness() {
+        return 0; // Scalable fonts has a fixed value of 0 - See Master 
Underline Thickness
+    }
+
+    @Override
+    public int getTextHeight() {
+        return 2048;
+    }
+
+    @Override
+    public int getTextWidth() {
+        if (os2Table != null) {
+            return os2Table.getAvgCharWidth();
+        }
+        return 0;
+    }
+
+    @Override
+    public int getFirstCode() {
+        return 32;
+    }
+
+    @Override
+    public int getLastCode() {
+        return 255; // Bound font with a maximum of 255 characters
+    }
+
+    @Override
+    public int getPitchExtended() {
+        return 0; // Zero for Scalable fonts
+    }
+
+    @Override
+    public int getHeightExtended() {
+        return 0; // Zero for Scalable fonts
+    }
+
+    @Override
+    public int getCapHeight() {
+        if (pcltTable != null) {
+            return pcltTable.getStrokeWeight();
+        } else if (os2Table != null) {
+            return os2Table.getCapHeight();
+        }
+        return 0;
+    }
+
+    @Override
+    public int getFontNumber() {
+        if (pcltTable != null) {
+            return (int) pcltTable.getFontNumber();
+        }
+        return 0;
+    }
+
+    @Override
+    public String getFontName() {
+        if (pcltTable != null) {
+            return pcltTable.getTypeface();
+        } else {
+            return ttfFont.getFullName();
+        }
+    }
+
+    @Override
+    public int getScaleFactor() throws IOException {
+        if (scaleFactor == -1) {
+            OFTableName headTag = OFTableName.HEAD;
+            if (ttfFont.seekTab(reader, headTag, 0)) {
+                reader.readTTFLong(); // Version
+                reader.readTTFLong(); // Font revision
+                reader.readTTFLong(); // Check sum adjustment
+                reader.readTTFLong(); // Magic number
+                reader.readTTFShort(); // Flags
+                scaleFactor = reader.readTTFUShort(); // Units per em
+                return scaleFactor;
+            }
+        } else {
+            return scaleFactor;
+        }
+        return 0;
+    }
+
+    @Override
+    public int getMasterUnderlinePosition() throws IOException {
+        return (int) Math.round(getScaleFactor() * 0.2);
+    }
+
+    @Override
+    public int getMasterUnderlineThickness() throws IOException {
+        return (int) Math.round(getScaleFactor() * 0.05);
+    }
+
+    @Override
+    public int getFontScalingTechnology() {
+        return 1; // TrueType scalable font
+    }
+
+    @Override
+    public int getVariety() {
+        return 0; // TrueType fonts must be set to zero
+    }
+
+    public List<PCLFontSegment> getFontSegments() throws IOException {
+        List<PCLFontSegment> fontSegments = new ArrayList<PCLFontSegment>();
+        fontSegments.add(new PCLFontSegment(SegmentID.CC, 
getCharacterComplement()));
+        fontSegments.add(new PCLFontSegment(SegmentID.PA, 
pclByteWriter.toByteArray(os2Table.getPanose())));
+        fontSegments.add(new PCLFontSegment(SegmentID.GT, 
getGlobalTrueTypeData()));
+        fontSegments.add(new PCLFontSegment(SegmentID.CP, 
ttfFont.getCopyrightNotice().getBytes("US-ASCII")));
+        fontSegments.add(new PCLFontSegment(SegmentID.NULL, new byte[0]));
+        return fontSegments;
+    }
+
+    /**
+     * See Font Header Format 11-35 (Character Complement Array) in the PCL 5 
Specification. Defined as an array of 8
+     * bytes specific to certain character sets. In this case specifying 0 for 
all values (default complement) means the
+     * font is compatible with any character sets. '110' on least significant 
bits signifies unicode. See specification
+     * for further customization.
+     */
+    private byte[] getCharacterComplement() {
+        byte[] ccUnicode = new byte[8];
+        ccUnicode[7] = 6;
+        return ccUnicode;
+    }
+
+    private byte[] getGlobalTrueTypeData() throws IOException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        Map<OFDirTabEntry, Integer> tableOffsets = new HashMap<OFDirTabEntry, 
Integer>();
+        // Version
+        baos.write(pclByteWriter.unsignedInt(1)); // Major
+        baos.write(pclByteWriter.unsignedInt(0)); // Minor
+        int numTables = 5; // head, hhea, hmtx, maxp and gdir
+        // Optional Hint Tables
+        OFDirTabEntry headTable = ttfFont.getDirectoryEntry(OFTableName.CVT);
+        if (headTable != null) {
+            numTables++;
+        }
+        OFDirTabEntry fpgmTable = ttfFont.getDirectoryEntry(OFTableName.FPGM);
+        if (fpgmTable != null) {
+            numTables++;
+        }
+        OFDirTabEntry prepTable = ttfFont.getDirectoryEntry(OFTableName.PREP);
+        if (prepTable != null) {
+            numTables++;
+        }
+        baos.write(pclByteWriter.unsignedInt(numTables)); // numTables
+        int maxPowerNumTables = pclByteWriter.maxPower2(numTables);
+        int searchRange = maxPowerNumTables * 16;
+        baos.write(pclByteWriter.unsignedInt(searchRange));
+        
baos.write(pclByteWriter.unsignedInt(pclByteWriter.log(maxPowerNumTables, 2))); 
// Entry Selector
+        baos.write(pclByteWriter.unsignedInt(numTables * 16 - searchRange)); 
// Range shift
+
+        // Add default data tables
+        writeTrueTypeTable(baos, OFTableName.HEAD, tableOffsets);
+        writeTrueTypeTable(baos, OFTableName.HHEA, tableOffsets);
+        writeTrueTypeTable(baos, OFTableName.HMTX, tableOffsets);
+        writeTrueTypeTable(baos, OFTableName.MAXP, tableOffsets);
+
+        // Write the blank GDIR directory which is built in memory on the 
printer
+        writeGDIR(baos);
+
+        // Add optional data tables (for hints)
+        writeTrueTypeTable(baos, OFTableName.CVT, tableOffsets);
+        writeTrueTypeTable(baos, OFTableName.FPGM, tableOffsets);
+        writeTrueTypeTable(baos, OFTableName.PREP, tableOffsets);
+
+        baos = copyTables(tableOffsets, baos);
+
+        return baos.toByteArray();
+    }
+
+    private void writeTrueTypeTable(ByteArrayOutputStream baos, OFTableName 
table,
+            Map<OFDirTabEntry, Integer> tableOffsets) throws IOException, 
UnsupportedEncodingException {
+        OFDirTabEntry tabEntry = ttfFont.getDirectoryEntry(table);
+        if (tabEntry != null) {
+            baos.write(tabEntry.getTag());
+            baos.write(pclByteWriter.unsignedLongInt(tabEntry.getChecksum()));
+            tableOffsets.put(tabEntry, baos.size());
+            baos.write(pclByteWriter.unsignedLongInt(0)); // Offset to be set 
later
+            long length = (tabEntry.getLength() > HMTX_RESTRICT_SIZE)
+                    ? HMTX_RESTRICT_SIZE
+                    : tabEntry.getLength();
+            baos.write(pclByteWriter.unsignedLongInt(length));
+        }
+    }
+
+    private void writeGDIR(ByteArrayOutputStream baos) throws 
UnsupportedEncodingException, IOException {
+        baos.write("gdir".getBytes("ISO-8859-1"));
+        baos.write(pclByteWriter.unsignedLongInt(0)); // Checksum
+        baos.write(pclByteWriter.unsignedLongInt(0)); // Offset
+        baos.write(pclByteWriter.unsignedLongInt(0)); // Length
+    }
+
+    private ByteArrayOutputStream copyTables(Map<OFDirTabEntry, Integer> 
tableOffsets, ByteArrayOutputStream baos)
+            throws IOException {
+        Map<Integer, byte[]> offsetValues = new HashMap<Integer, byte[]>();
+        //for (OFDirTabEntry table : tableOffsets.keySet()) {
+        for (Entry<OFDirTabEntry, Integer> table : tableOffsets.entrySet()) {
+            byte[] tableData = reader.getBytes((int) 
table.getKey().getOffset(), (int) table.getKey().getLength());
+            if (tableData.length > HMTX_RESTRICT_SIZE) {
+                byte[] truncated = new byte[HMTX_RESTRICT_SIZE];
+                System.arraycopy(tableData, 0, truncated, 0, 
HMTX_RESTRICT_SIZE);
+                tableData = truncated;
+            }
+            // Update the offset in the table directory
+            offsetValues.put(table.getValue(), 
pclByteWriter.unsignedLongInt(baos.size()));
+            // Write the table data to the end of the TrueType segment output
+            baos.write(tableData);
+        }
+        baos = updateOffsets(baos, offsetValues);
+        return baos;
+    }
+
+    private ByteArrayOutputStream updateOffsets(ByteArrayOutputStream baos, 
Map<Integer, byte[]> offsets)
+            throws IOException {
+        byte[] softFont = baos.toByteArray();
+        for (int offset : offsets.keySet()) {
+            pclByteWriter.updateDataAtLocation(softFont, offsets.get(offset), 
offset);
+        }
+        baos = new ByteArrayOutputStream();
+        baos.write(softFont);
+        return baos;
+    }
+
+    @Override
+    public Map<Integer, int[]> getCharacterOffsets() throws IOException {
+        List<OFMtxEntry> mtx = ttfFont.getMtx();
+        OFTableName glyfTag = OFTableName.GLYF;
+        Map<Integer, int[]> charOffsets = new HashMap<Integer, int[]>();
+        OFDirTabEntry tabEntry = ttfFont.getDirectoryEntry(glyfTag);
+        if (ttfFont.seekTab(reader, glyfTag, 0)) {
+            for (int i = 1; i < mtx.size(); i++) {
+                OFMtxEntry entry = mtx.get(i);
+                OFMtxEntry nextEntry;
+                int nextOffset = 0;
+                int charCode = 0;
+                if (entry.getUnicodeIndex().size() > 0) {
+                    charCode = (Integer) entry.getUnicodeIndex().get(0);
+                } else {
+                    charCode = entry.getIndex();
+                }
+
+                if (i < mtx.size() - 1) {
+                    nextEntry = mtx.get(i + 1);
+                    nextOffset = (int) nextEntry.getOffset();
+                } else {
+                    nextOffset = (int) ttfFont.getLastGlyfLocation();
+                }
+                int glyphOffset = (int) entry.getOffset();
+                int glyphLength = nextOffset - glyphOffset;
+
+                charOffsets.put(charCode, new int[]{(int) tabEntry.getOffset() 
+ glyphOffset, glyphLength});
+            }
+        }
+        return charOffsets;
+    }
+
+    @Override
+    public OpenFont getFontFile() {
+        return ttfFont;
+    }
+
+    @Override
+    public FontFileReader getFontFileReader() {
+        return reader;
+    }
+}

Added: 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFOS2FontTable.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFOS2FontTable.java?rev=1685112&view=auto
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFOS2FontTable.java
 (added)
+++ 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFOS2FontTable.java
 Fri Jun 12 15:52:55 2015
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.pcl.fonts.truetype;
+
+import java.io.IOException;
+
+import org.apache.fop.fonts.truetype.FontFileReader;
+
+public class PCLTTFOS2FontTable extends PCLTTFTable {
+    private int avgCharWidth;
+    private int xHeight;
+    private int widthClass;
+    private int weightClass;
+    private int capHeight;
+    private int[] panose = new int[10];
+
+    public PCLTTFOS2FontTable(FontFileReader in) throws IOException {
+        super(in);
+        int version = reader.readTTFUShort(); // Version
+        avgCharWidth = reader.readTTFShort();
+        weightClass = reader.readTTFShort();
+        widthClass = reader.readTTFShort();
+        skipShort(reader, 12);
+        for (int i = 0; i < 10; i++) {
+            panose[i] = reader.readTTFByte();
+        }
+        skipLong(reader, 4);
+        skipByte(reader, 4);
+        skipShort(reader, 8);
+        if (version >= 2) {
+            skipLong(reader, 2);
+            xHeight = reader.readTTFShort();
+            capHeight = reader.readTTFShort();
+        }
+    }
+
+    public int getAvgCharWidth() {
+        return avgCharWidth;
+    }
+
+    public int getXHeight() {
+        return xHeight;
+    }
+
+    public int getWidthClass() {
+        return widthClass;
+    }
+
+    public int getWeightClass() {
+        return weightClass;
+    }
+
+    public int getCapHeight() {
+        return capHeight;
+    }
+
+    public int[] getPanose() {
+        return panose;
+    }
+}

Added: 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFPCLTFontTable.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFPCLTFontTable.java?rev=1685112&view=auto
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFPCLTFontTable.java
 (added)
+++ 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFPCLTFontTable.java
 Fri Jun 12 15:52:55 2015
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.pcl.fonts.truetype;
+
+import java.io.IOException;
+
+import org.apache.fop.fonts.truetype.FontFileReader;
+
+public class PCLTTFPCLTFontTable extends PCLTTFTable {
+    private long version;
+    private long fontNumber;
+    private int pitch;
+    private int xHeight;
+    private int style;
+    private int typeFamily;
+    private int capHeight;
+    private int symbolSet;
+    private String typeface;
+    private String characterComplement;
+    private String filename;
+    private int strokeWeight;
+    private int widthType;
+    private int serifStyle;
+
+    public PCLTTFPCLTFontTable(FontFileReader in) throws IOException {
+        super(in);
+        version = reader.readTTFULong();
+        fontNumber = reader.readTTFULong();
+        pitch = reader.readTTFUShort();
+        xHeight = reader.readTTFUShort();
+        style = reader.readTTFUShort();
+        typeFamily = reader.readTTFUShort();
+        capHeight = reader.readTTFUShort();
+        symbolSet = reader.readTTFUShort();
+        typeface = reader.readTTFString(16);
+        characterComplement = reader.readTTFString(8);
+        filename = reader.readTTFString(6);
+        strokeWeight = reader.readTTFUShort();
+        widthType = reader.readTTFUShort();
+        serifStyle = reader.readTTFUByte();
+    }
+
+    public long getVersion() {
+        return version;
+    }
+
+    public long getFontNumber() {
+        return fontNumber;
+    }
+
+    public int getPitch() {
+        return pitch;
+    }
+
+    public int getXHeight() {
+        return xHeight;
+    }
+
+    public int getStyle() {
+        return style;
+    }
+
+    public int getTypeFamily() {
+        return typeFamily;
+    }
+
+    public int getCapHeight() {
+        return capHeight;
+    }
+
+    public int getSymbolSet() {
+        return symbolSet;
+    }
+
+    public String getTypeface() {
+        return typeface;
+    }
+
+    public String getCharacterComplement() {
+        return characterComplement;
+    }
+
+    public String getFilename() {
+        return filename;
+    }
+
+    public int getStrokeWeight() {
+        return strokeWeight;
+    }
+
+    public int getWidthType() {
+        return widthType;
+    }
+
+    public int getSerifStyle() {
+        return serifStyle;
+    }
+}

Added: 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFPOSTFontTable.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFPOSTFontTable.java?rev=1685112&view=auto
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFPOSTFontTable.java
 (added)
+++ 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFPOSTFontTable.java
 Fri Jun 12 15:52:55 2015
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.pcl.fonts.truetype;
+
+import java.io.IOException;
+
+import org.apache.fop.fonts.truetype.FontFileReader;
+
+public class PCLTTFPOSTFontTable extends PCLTTFTable {
+    private int underlinePosition;
+    private int underlineThickness;
+    private int isFixedPitch;
+
+    public PCLTTFPOSTFontTable(FontFileReader in) throws IOException {
+        super(in);
+        reader.readTTFLong(); // Version
+        reader.readTTFLong(); // Italic Angle
+        underlinePosition = reader.readTTFShort();
+        underlineThickness = reader.readTTFShort();
+        isFixedPitch = (int) reader.readTTFULong();
+    }
+
+    public int getUnderlinePosition() {
+        return underlinePosition;
+    }
+
+    public int getUnderlineThickness() {
+        return underlineThickness;
+    }
+
+    public int getIsFixedPitch() {
+        return isFixedPitch;
+    }
+}

Added: 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFTable.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFTable.java?rev=1685112&view=auto
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFTable.java
 (added)
+++ 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFTable.java
 Fri Jun 12 15:52:55 2015
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.pcl.fonts.truetype;
+
+import java.io.IOException;
+
+import org.apache.fop.fonts.truetype.FontFileReader;
+
+public class PCLTTFTable {
+    protected FontFileReader reader;
+
+    public PCLTTFTable(FontFileReader reader) {
+        this.reader = reader;
+    }
+
+    protected void skipShort(FontFileReader reader, int skips)
+            throws IOException {
+        reader.skip(skips * 2);
+    }
+
+    protected void skipLong(FontFileReader reader, int skips)
+            throws IOException {
+        reader.skip(skips * 4);
+    }
+
+    protected void skipByte(FontFileReader reader, int skips)
+            throws IOException {
+        reader.skip(skips);
+    }
+}

Added: 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFTableFactory.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFTableFactory.java?rev=1685112&view=auto
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFTableFactory.java
 (added)
+++ 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/src/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFTableFactory.java
 Fri Jun 12 15:52:55 2015
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.pcl.fonts.truetype;
+
+import java.io.IOException;
+
+import org.apache.fop.fonts.truetype.FontFileReader;
+import org.apache.fop.fonts.truetype.OFTableName;
+
+public final class PCLTTFTableFactory {
+    private FontFileReader reader;
+
+    private PCLTTFTableFactory(FontFileReader reader) {
+        this.reader = reader;
+    }
+
+    public static PCLTTFTableFactory getInstance(FontFileReader reader) {
+        return new PCLTTFTableFactory(reader);
+    }
+
+    public PCLTTFTable newInstance(OFTableName tableName)
+            throws IOException {
+        if (tableName == OFTableName.PCLT) {
+            return new PCLTTFPCLTFontTable(reader);
+        } else if (tableName == OFTableName.OS2) {
+            return new PCLTTFOS2FontTable(reader);
+        } else if (tableName == OFTableName.POST) {
+            return new PCLTTFPOSTFontTable(reader);
+        }
+        return null;
+    }
+}

Added: 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/MockPCLTTFFontReader.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/MockPCLTTFFontReader.java?rev=1685112&view=auto
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/MockPCLTTFFontReader.java
 (added)
+++ 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/MockPCLTTFFontReader.java
 Fri Jun 12 15:52:55 2015
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+package org.apache.fop.render.pcl.fonts;
+
+import java.io.IOException;
+
+import org.apache.fop.fonts.CustomFont;
+import org.apache.fop.fonts.Typeface;
+import org.apache.fop.fonts.truetype.FontFileReader;
+import org.apache.fop.fonts.truetype.TTFFile;
+import org.apache.fop.render.java2d.CustomFontMetricsMapper;
+import org.apache.fop.render.pcl.fonts.truetype.PCLTTFFontReader;
+
+public class MockPCLTTFFontReader extends PCLTTFFontReader {
+
+    public MockPCLTTFFontReader(Typeface font, PCLByteWriterUtil 
pclByteWriter) throws IOException {
+        super(font, pclByteWriter);
+    }
+
+    @Override
+    protected void loadFont() throws IOException {
+        if (typeface instanceof CustomFontMetricsMapper) {
+            CustomFontMetricsMapper fontMetrics = (CustomFontMetricsMapper) 
typeface;
+            CustomFont customFont = (CustomFont) fontMetrics.getRealFont();
+            fontStream = customFont.getInputStream();
+            reader = new FontFileReader(fontStream);
+
+            ttfFont = new TTFFile();
+            ttfFont.readFont(reader, customFont.getFullName());
+            readFontTables();
+        } else {
+            // TODO - Handle when typeface is not in the expected format for a 
PCL TrueType object
+        }
+    }
+}

Added: 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/PCLByteWriterUtilTestCase.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/PCLByteWriterUtilTestCase.java?rev=1685112&view=auto
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/PCLByteWriterUtilTestCase.java
 (added)
+++ 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/PCLByteWriterUtilTestCase.java
 Fri Jun 12 15:52:55 2015
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+package org.apache.fop.render.pcl.fonts;
+
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+
+public class PCLByteWriterUtilTestCase {
+    private PCLByteWriterUtil byteWriter;
+
+    @Before
+    public void setUp() {
+        byteWriter = new PCLByteWriterUtil();
+    }
+
+    @Test
+    public void testWriteMethods() throws IOException {
+        byte[] output = byteWriter.writeCommand("(s4X");
+        // 27 = PCL escape character with rest in ASCII format
+        byte[] command = {27, 40, 115, 52, 88};
+        assertArrayEquals(command, output);
+
+        byte[] resultB = byteWriter.unsignedLongInt(102494);
+        byte[] compareB = {0, 1, -112, 94};
+        assertArrayEquals(compareB, resultB);
+
+        byte[] resultC = byteWriter.unsignedInt(1024);
+        byte[] compareC = {4, 0};
+        assertArrayEquals(compareC, resultC);
+    }
+
+    @Test
+    public void testUtilMethods() throws IOException {
+        byte[] anArray = {1, 2, 3, 4, 5, 9, 10};
+        byte[] insertArray = {6, 7, 8};
+        byte[] result = byteWriter.insertIntoArray(5, anArray, insertArray);
+        byte[] compareA = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+        assertArrayEquals(compareA, result);
+
+        byte[] reverse = {10, 9, 8, 7, 6};
+        byteWriter.updateDataAtLocation(compareA, reverse, 5);
+        byte[] compareB = {1, 2, 3, 4, 5, 10, 9, 8, 7, 6};
+        assertArrayEquals(compareB, compareA);
+
+        byte[] anArrayC = {1, 2, 3, 4, 5};
+        byte[] resultC = byteWriter.padBytes(anArrayC, 10);
+        byte[] compareC = {1, 2, 3, 4, 5, 0, 0, 0, 0, 0};
+        assertArrayEquals(compareC, resultC);
+
+        byte[] resultD = byteWriter.padBytes(anArrayC, 10, 1);
+        byte[] compareD = {1, 2, 3, 4, 5, 1, 1, 1, 1, 1};
+        assertArrayEquals(compareD, resultD);
+    }
+}

Added: 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/PCLFontReaderFactoryTestCase.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/PCLFontReaderFactoryTestCase.java?rev=1685112&view=auto
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/PCLFontReaderFactoryTestCase.java
 (added)
+++ 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/PCLFontReaderFactoryTestCase.java
 Fri Jun 12 15:52:55 2015
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+package org.apache.fop.render.pcl.fonts;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.URI;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.fop.fonts.CustomFont;
+import org.apache.fop.fonts.FontType;
+import org.apache.fop.render.java2d.CustomFontMetricsMapper;
+import org.apache.fop.render.pcl.fonts.truetype.PCLTTFFontReader;
+
+public class PCLFontReaderFactoryTestCase {
+    private static final String TEST_FONT_TTF = 
"./test/resources/fonts/ttf/DejaVuLGCSerif.ttf";
+
+    @Test
+    public void verifyTypeIdentification() throws Exception {
+        CustomFont sbFont = mock(CustomFont.class);
+        when(sbFont.getInputStream()).thenReturn(new FileInputStream(new 
File(TEST_FONT_TTF)));
+        when(sbFont.getEmbedFileURI()).thenReturn(new URI(TEST_FONT_TTF));
+        CustomFontMetricsMapper customFont = new 
CustomFontMetricsMapper(sbFont);
+        when(customFont.getFontType()).thenReturn(FontType.TRUETYPE);
+        // Have to mock the input stream twice otherwise get a Stream is 
closed exception
+        when(((CustomFont) 
customFont.getRealFont()).getInputStream()).thenReturn(
+                new FileInputStream(new File(TEST_FONT_TTF)));
+        PCLFontReaderFactory fontReaderFactory = 
PCLFontReaderFactory.getInstance(null);
+        assertTrue(fontReaderFactory.createInstance(customFont) instanceof 
PCLTTFFontReader);
+    }
+}

Added: 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/PCLTTFFontReaderTestCase.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/PCLTTFFontReaderTestCase.java?rev=1685112&view=auto
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/PCLTTFFontReaderTestCase.java
 (added)
+++ 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/PCLTTFFontReaderTestCase.java
 Fri Jun 12 15:52:55 2015
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+package org.apache.fop.render.pcl.fonts;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.fop.fonts.CustomFont;
+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;
+
+public class PCLTTFFontReaderTestCase {
+
+    private CustomFontMetricsMapper customFont = 
mock(CustomFontMetricsMapper.class);
+    private PCLByteWriterUtil byteWriter;
+    private static final String TEST_FONT_A = 
"./test/resources/fonts/ttf/DejaVuLGCSerif.ttf";
+
+    @Before
+    public void setUp() {
+        byteWriter = new PCLByteWriterUtil();
+    }
+
+    @Test
+    public void verifyFontAData() throws Exception {
+        CustomFont sbFont = mock(CustomFont.class);
+        when(sbFont.getInputStream()).thenReturn(new FileInputStream(new 
File(TEST_FONT_A)));
+        when(customFont.getRealFont()).thenReturn(sbFont);
+        PCLTTFFontReader reader = new MockPCLTTFFontReader(customFont, 
byteWriter);
+        verifyFontData(reader);
+        validateOffsets(reader);
+        validateFontSegments(reader);
+    }
+
+    /**
+     * Compares the input font data against a sample of the data read and 
calculated by the reader. The assertions are
+     * made against data taken from the TrueType Font Analyzer tool.
+     * @param reader The reader
+     */
+    private void verifyFontData(PCLTTFFontReader reader) {
+        assertEquals(reader.getCellWidth(), 5015); // Bounding box X2 - X1
+        assertEquals(reader.getCellHeight(), 3254); // Bounding box Y2 - Y1
+        assertEquals(reader.getCapHeight(), 0); // OS2Table.capHeight
+        assertEquals(reader.getFontName(), "DejaVu LGC Serif"); // Full name 
read by TTFFont object
+        assertEquals(reader.getFirstCode(), 32); // Always 32 for bound font
+        assertEquals(reader.getLastCode(), 255); // Always 255 for bound font
+
+        // Values that require conversion tables (See PCLTTFFontReader.java)
+        assertEquals(reader.getStrokeWeight(), 0); // Weight Class 400 
(regular) should be equivalent 0
+        assertEquals(reader.getSerifStyle(), 128); // Serif Style 0 should 
equal 0
+        assertEquals(reader.getWidthType(), 0); // Width Class 5 (regular) 
should be equivalent 0
+    }
+
+    private void validateOffsets(PCLTTFFontReader reader) throws IOException {
+        // Offsets are stored with their character ID with the array [offset, 
length]
+        Map<Integer, int[]> offsets = reader.getCharacterOffsets();
+
+        // Test data
+        int[] charC = {27644, 144}; // Char index = 99
+        int[] charDollar = {16044, 264}; // Char index = 36
+        int[] charOne = {17808, 176}; // Char index = 49
+        int[] charUpperD = {21236, 148}; // Char index = 68
+        int[] charUpperJ = {22140, 176}; // Char index = 74
+
+        assertArrayEquals(offsets.get(99), charC);
+        assertArrayEquals(offsets.get(36), charDollar);
+        assertArrayEquals(offsets.get(49), charOne);
+        assertArrayEquals(offsets.get(68), charUpperD);
+        assertArrayEquals(offsets.get(74), charUpperJ);
+    }
+
+    /**
+     * Verifies the font segment data copied originally from the TrueType 
font. Data was verified using TrueType Font
+     * Analyzer and PCLParaphernalia tool.
+     * @param reader The reader
+     * @throws IOException
+     */
+    private void validateFontSegments(PCLTTFFontReader reader) throws 
IOException {
+        List<PCLFontSegment> segments = reader.getFontSegments();
+        assertEquals(segments.size(), 5);
+        for (PCLFontSegment segment : segments) {
+            if (segment.getIdentifier() == SegmentID.PA) {
+                // Panose
+                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.NULL) {
+                // Terminating segment
+                assertEquals(segment.getData().length, 0);
+            }
+        }
+    }
+}

Added: 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFCharacterWriterTestCase.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFCharacterWriterTestCase.java?rev=1685112&view=auto
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFCharacterWriterTestCase.java
 (added)
+++ 
xmlgraphics/fop/branches/Temp_PCLSoftFonts/test/java/org/apache/fop/render/pcl/fonts/truetype/PCLTTFCharacterWriterTestCase.java
 Fri Jun 12 15:52:55 2015
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+package org.apache.fop.render.pcl.fonts.truetype;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.fop.fonts.CustomFont;
+import org.apache.fop.fonts.truetype.FontFileReader;
+import org.apache.fop.fonts.truetype.OFFontLoader;
+import org.apache.fop.fonts.truetype.TTFFile;
+import org.apache.fop.render.java2d.CustomFontMetricsMapper;
+import org.apache.fop.render.pcl.fonts.PCLByteWriterUtil;
+import org.apache.fop.render.pcl.fonts.PCLSoftFont;
+
+public class PCLTTFCharacterWriterTestCase {
+
+    private PCLTTFCharacterWriter characterWriter;
+    private PCLSoftFont softFont;
+    private CustomFontMetricsMapper customFont = 
mock(CustomFontMetricsMapper.class);
+    private static final String TEST_FONT_A = 
"./test/resources/fonts/ttf/DejaVuLGCSerif.ttf";
+
+    @Test
+    public void verifyCharacterDefinition() throws Exception {
+        CustomFont sbFont = mock(CustomFont.class);
+        when(customFont.getRealFont()).thenReturn(sbFont);
+        softFont = new PCLSoftFont(1, customFont);
+        TTFFile openFont = new TTFFile();
+        FontFileReader reader = new FontFileReader(new FileInputStream(new 
File(TEST_FONT_A)));
+        String header = OFFontLoader.readHeader(reader);
+        openFont.readFont(reader, header);
+        softFont.setOpenFont(openFont);
+        softFont.setReader(reader);
+
+        characterWriter = new PCLTTFCharacterWriter(softFont);
+        byte[] charDefinition = characterWriter.writeCharacterDefinitions("f");
+        PCLByteWriterUtil pclByteWriter = new PCLByteWriterUtil();
+        // Character command
+        byte[] command = pclByteWriter.writeCommand(String.format("*c%dE", 
32));
+        assertArrayEquals(getBytes(charDefinition, 0, 6), command);
+        // Character definition command
+        byte[] charDefCommand = 
pclByteWriter.writeCommand(String.format("(s%dW", 210));
+        assertArrayEquals(getBytes(charDefinition, 6, 7), charDefCommand);
+    }
+
+    private byte[] getBytes(byte[] byteArray, int offset, int length) {
+        byte[] result = new byte[length];
+        int count = 0;
+        for (int i = offset; i < offset + length; i++) {
+            result[count++] = byteArray[i];
+        }
+        return result;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to