From d781b5bb875bd8f73bfb9e97ed40d55a3c642e31 Mon Sep 17 00:00:00 2001 From: fotis Date: Thu, 2 Nov 2000 12:48:33 +0000 Subject: [PATCH] adds support for type 1 fonts by Jeremias Maerki based on work by Alain Fagot git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193740 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 12 + docs/xml-docs/fop.xml | 1 + docs/xml-docs/fop/fonts.xml | 94 +++++ docs/xml-docs/xml2xml.xsl | 1 + src/codegen/Courier-Bold.xml | 2 + src/codegen/Courier-BoldOblique.xml | 2 + src/codegen/Courier-Oblique.xml | 2 + src/codegen/Courier.xml | 2 + src/codegen/Helvetica-Bold.xml | 2 + src/codegen/Helvetica-BoldOblique.xml | 2 + src/codegen/Helvetica-Oblique.xml | 2 + src/codegen/Helvetica.xml | 2 + src/codegen/Symbol.xml | 2 + src/codegen/Times-Bold.xml | 2 + src/codegen/Times-BoldItalic.xml | 2 + src/codegen/Times-Italic.xml | 2 + src/codegen/Times-Roman.xml | 2 + src/codegen/ZapfDingbats.xml | 2 + src/codegen/charlist.xml | 386 +++++++++--------- src/codegen/font-file.xsl | 16 + src/org/apache/fop/dom/NodeImpl.java | 7 + src/org/apache/fop/fonts/PFMFile.java | 381 +++++++++++++++++ src/org/apache/fop/fonts/PFMInputStream.java | 132 ++++++ .../apache/fop/fonts/apps/FontPostProcess.xsl | 27 ++ .../fop/fonts/apps/FontPostProcessSort.xsl | 20 + src/org/apache/fop/fonts/apps/PFMReader.java | 358 ++++++++++++++++ src/org/apache/fop/layout/FontDescriptor.java | 69 ++++ src/org/apache/fop/layout/FontMetric.java | 13 +- src/org/apache/fop/pdf/PDFArray.java | 90 ++++ src/org/apache/fop/pdf/PDFDocument.java | 84 +++- src/org/apache/fop/pdf/PDFEncoding.java | 152 +++++++ src/org/apache/fop/pdf/PDFFont.java | 198 +++++++-- src/org/apache/fop/pdf/PDFFontDescriptor.java | 203 +++++++++ src/org/apache/fop/pdf/PDFFontNonBase14.java | 124 ++++++ src/org/apache/fop/pdf/PDFFontType1.java | 81 ++++ src/org/apache/fop/pdf/PDFRectangle.java | 103 +++++ src/org/apache/fop/render/pdf/FontSetup.java | 280 +++++++------ 37 files changed, 2480 insertions(+), 380 deletions(-) create mode 100644 docs/xml-docs/fop/fonts.xml create mode 100644 src/org/apache/fop/fonts/PFMFile.java create mode 100644 src/org/apache/fop/fonts/PFMInputStream.java create mode 100644 src/org/apache/fop/fonts/apps/FontPostProcess.xsl create mode 100644 src/org/apache/fop/fonts/apps/FontPostProcessSort.xsl create mode 100644 src/org/apache/fop/fonts/apps/PFMReader.java create mode 100644 src/org/apache/fop/layout/FontDescriptor.java create mode 100644 src/org/apache/fop/pdf/PDFArray.java create mode 100644 src/org/apache/fop/pdf/PDFEncoding.java create mode 100644 src/org/apache/fop/pdf/PDFFontDescriptor.java create mode 100644 src/org/apache/fop/pdf/PDFFontNonBase14.java create mode 100644 src/org/apache/fop/pdf/PDFFontType1.java create mode 100644 src/org/apache/fop/pdf/PDFRectangle.java diff --git a/build.xml b/build.xml index 8d52fa12c..82ae5904b 100644 --- a/build.xml +++ b/build.xml @@ -171,6 +171,7 @@ Sometimes ant gives out this warnings, but the build is finished without any pro + @@ -186,6 +187,11 @@ Sometimes ant gives out this warnings, but the build is finished without any pro + + + @@ -306,6 +312,12 @@ Sometimes ant gives out this warnings, but the build is finished without any pro + + + diff --git a/docs/xml-docs/fop.xml b/docs/xml-docs/fop.xml index 4889db954..106fb285d 100644 --- a/docs/xml-docs/fop.xml +++ b/docs/xml-docs/fop.xml @@ -11,6 +11,7 @@ + diff --git a/docs/xml-docs/fop/fonts.xml b/docs/xml-docs/fop/fonts.xml new file mode 100644 index 000000000..81a94aec5 --- /dev/null +++ b/docs/xml-docs/fop/fonts.xml @@ -0,0 +1,94 @@ + + + + + +

FOP (building PDF files) normally supports only the base 14 font package defined in the Adobe PDF specification. + That includes the following fonts: Helvetica, Times, Courier, Symbol and ZapfDingbats. +

+

Font support in FOP can be extended by the addition of font metric files (written in XML) created from Adobe + Type 1 fonts. No other font types (TrueType, Type 0, Type 3, etc.) are supported at this time. The current method + of adding fonts to FOP requires the package to be recompiled. +

+
+ +

As mentioned above you need an XML file containing font metrics to be able to use an additional font. FOP + contains a tool that can generate such a font metrics file from a PFM file. +

+ +

Run the class org.apache.fop.fonts.apps.PFMReader to generate the XML file. Important: The tool does two + XSL transformations, one of which uses charlist.xml. At the moment in order for the tool to work correctly you + have to copy charlist.xml temporarily to the local directory from where you intend to start the tool. + (If anyone has an improvement on this...) +

+

+ java -cp fop.jar;xerces.jar;xalan.jar;w3c.jar +

+

+ org.apache.fop.fonts.apps.PFMReader pfm-file xml-file +

+

Put the resulting XML file into the src/codegen directory. +

+

Note: The tool will construct some values (FontBBox, StemV and ItalicAngle) based on assumptions and + calculations which are only an approximation to the real values. FontBBox and Italic Angle can be found in + the human-readable part of the PFB file. The PFMReader tool does not yet interpret PFB files, so if you want + to be correct, you may have to adjust the values in the XML file manually. The constructed values however + appear to have no visible influence. +

+
+ +

Open the class org.apache.fop.render.pdf.FontSetup and add entries to the ones present according to + the following example: +

+

+ fontInfo.addMetrics("F14", new ZapfDingbats()); +

+

+ fontInfo.addMetrics("F15", new BauerBodoniRoman()); //This is the new entry. +

+

+ ... +

+

+ fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", "normal"); +

+

+ fontInfo.addFontProperties("F15", "BauerBodoni", "normal", "normal"); //This is the new entry. +

+

Note: The class name to use is visible in the <class-name> element of the font metrics file. +

+
+ +

In the src/codegen directory you find the font metrics files for the base 14 fonts. The are being transformed + during build into Java classes and then compiled. The newly generated font metrics file must be included in this + process. To do that open build.xml and add entries according to the following example: +

+

+ <property name="ZapfDingbats.xml" value="${build.codegen}/ZapfDingbats.xml"/> +

+

+ <property name="BauerBodoni.xml" value="${build.codegen}/BauerBodoni.xml"/> +

+

+ ... +

+

+ <xslt infile="${ZapfDingbats.xml}" xsltfile="${fontfile.xsl}" +

+

+ outfile="${build.src}/${replacestring}/render/pdf/fonts/ZapfDingbats.java" smart="yes"/> +

+

+ <xslt infile="${BauerBodoni.xml}" xsltfile="${t1fontfile.xsl}" +

+

+ outfile="${build.src}/${replacestring}/render/pdf/fonts/BauerBodoniRoman.java" smart="yes"/> +

+

Rebuild FOP! +

+

Note: Be sure to use ${t1fontfile.xsl} instead of ${fontfile.xsl}. This is neccessary because of the additional metrics + information needed for non base 14 fonts. +

+
+
+
diff --git a/docs/xml-docs/xml2xml.xsl b/docs/xml-docs/xml2xml.xsl index 69333c99a..4f14ba59a 100644 --- a/docs/xml-docs/xml2xml.xsl +++ b/docs/xml-docs/xml2xml.xsl @@ -9,6 +9,7 @@ + diff --git a/src/codegen/Courier-Bold.xml b/src/codegen/Courier-Bold.xml index a2ded8d53..53c0a6f20 100644 --- a/src/codegen/Courier-Bold.xml +++ b/src/codegen/Courier-Bold.xml @@ -7,6 +7,8 @@ 439 626 -142 + 32 + 255 diff --git a/src/codegen/Courier-BoldOblique.xml b/src/codegen/Courier-BoldOblique.xml index 58a419ec5..5dac9ae2f 100644 --- a/src/codegen/Courier-BoldOblique.xml +++ b/src/codegen/Courier-BoldOblique.xml @@ -7,6 +7,8 @@ 439 626 -142 + 32 + 255 diff --git a/src/codegen/Courier-Oblique.xml b/src/codegen/Courier-Oblique.xml index f43986004..701ec8534 100644 --- a/src/codegen/Courier-Oblique.xml +++ b/src/codegen/Courier-Oblique.xml @@ -7,6 +7,8 @@ 426 629 -157 + 32 + 255 diff --git a/src/codegen/Courier.xml b/src/codegen/Courier.xml index 80f1bfc6e..8ec2e8492 100644 --- a/src/codegen/Courier.xml +++ b/src/codegen/Courier.xml @@ -7,6 +7,8 @@ 426 629 -157 + 32 + 255 diff --git a/src/codegen/Helvetica-Bold.xml b/src/codegen/Helvetica-Bold.xml index 6c9b6f4b9..ca39a70a2 100644 --- a/src/codegen/Helvetica-Bold.xml +++ b/src/codegen/Helvetica-Bold.xml @@ -7,6 +7,8 @@ 532 718 -207 + 32 + 255 diff --git a/src/codegen/Helvetica-BoldOblique.xml b/src/codegen/Helvetica-BoldOblique.xml index d07b5de49..e2da39782 100644 --- a/src/codegen/Helvetica-BoldOblique.xml +++ b/src/codegen/Helvetica-BoldOblique.xml @@ -7,6 +7,8 @@ 532 718 -207 + 32 + 255 diff --git a/src/codegen/Helvetica-Oblique.xml b/src/codegen/Helvetica-Oblique.xml index 00339df1d..f002086e6 100644 --- a/src/codegen/Helvetica-Oblique.xml +++ b/src/codegen/Helvetica-Oblique.xml @@ -7,6 +7,8 @@ 523 718 -207 + 32 + 255 diff --git a/src/codegen/Helvetica.xml b/src/codegen/Helvetica.xml index b5221bfb9..36f8b0b65 100644 --- a/src/codegen/Helvetica.xml +++ b/src/codegen/Helvetica.xml @@ -7,6 +7,8 @@ 523 718 -207 + 32 + 255 diff --git a/src/codegen/Symbol.xml b/src/codegen/Symbol.xml index 6e071fe81..cfd3f2061 100644 --- a/src/codegen/Symbol.xml +++ b/src/codegen/Symbol.xml @@ -6,6 +6,8 @@ 520 1010 -293 + 32 + 255 diff --git a/src/codegen/Times-Bold.xml b/src/codegen/Times-Bold.xml index f446d298d..aad20a103 100644 --- a/src/codegen/Times-Bold.xml +++ b/src/codegen/Times-Bold.xml @@ -7,6 +7,8 @@ 461 676 -205 + 32 + 255 diff --git a/src/codegen/Times-BoldItalic.xml b/src/codegen/Times-BoldItalic.xml index b79b83179..ea63d3a8d 100644 --- a/src/codegen/Times-BoldItalic.xml +++ b/src/codegen/Times-BoldItalic.xml @@ -7,6 +7,8 @@ 462 699 -205 + 32 + 255 diff --git a/src/codegen/Times-Italic.xml b/src/codegen/Times-Italic.xml index 5b0242e5e..83ab11330 100644 --- a/src/codegen/Times-Italic.xml +++ b/src/codegen/Times-Italic.xml @@ -7,6 +7,8 @@ 441 683 -205 + 32 + 255 diff --git a/src/codegen/Times-Roman.xml b/src/codegen/Times-Roman.xml index ae5c16151..0dee39bbc 100644 --- a/src/codegen/Times-Roman.xml +++ b/src/codegen/Times-Roman.xml @@ -7,6 +7,8 @@ 450 683 -217 + 32 + 255 diff --git a/src/codegen/ZapfDingbats.xml b/src/codegen/ZapfDingbats.xml index 7a86c635b..4e0511937 100644 --- a/src/codegen/ZapfDingbats.xml +++ b/src/codegen/ZapfDingbats.xml @@ -6,6 +6,8 @@ 426 820 -143 + 32 + 255 diff --git a/src/codegen/charlist.xml b/src/codegen/charlist.xml index 15700eb6e..8f923d144 100644 --- a/src/codegen/charlist.xml +++ b/src/codegen/charlist.xml @@ -18,9 +18,10 @@ + - + @@ -74,11 +75,11 @@ - - - - - + + + + + @@ -132,7 +133,7 @@ - + @@ -155,16 +156,16 @@ - + - + - + @@ -243,10 +244,7 @@ - - - @@ -448,191 +446,187 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + TBD: remove doublettes --> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - \ No newline at end of file +--> diff --git a/src/codegen/font-file.xsl b/src/codegen/font-file.xsl index 1ae887708..3c2f5ee8f 100644 --- a/src/codegen/font-file.xsl +++ b/src/codegen/font-file.xsl @@ -28,6 +28,8 @@ public class extends Font { private final static int xHeight = ; private final static int ascender = ; private final static int descender = ; + private final static int firstChar = ; + private final static int lastChar = ; private final static int[] width; static { @@ -60,9 +62,23 @@ public class extends Font { return xHeight; } + public int getFirstChar() { + return firstChar; + } + + public int getLastChar() { + return lastChar; + } + public int width(int i) { return width[i]; } + + public int[] getWidths() { + int[] arr = new int[getLastChar()-getFirstChar()+1]; + System.arraycopy(width, getFirstChar(), arr, 0, getLastChar()-getFirstChar()+1); + return arr; + } } diff --git a/src/org/apache/fop/dom/NodeImpl.java b/src/org/apache/fop/dom/NodeImpl.java index 86c6bd246..7a2c263d6 100644 --- a/src/org/apache/fop/dom/NodeImpl.java +++ b/src/org/apache/fop/dom/NodeImpl.java @@ -191,6 +191,13 @@ public class NodeImpl implements Node { return false; } + public boolean isSupported(String feature, + String version) + { + return false; + } + + public String getNamespaceURI() { return ""; diff --git a/src/org/apache/fop/fonts/PFMFile.java b/src/org/apache/fop/fonts/PFMFile.java new file mode 100644 index 000000000..8ab72dee1 --- /dev/null +++ b/src/org/apache/fop/fonts/PFMFile.java @@ -0,0 +1,381 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "Fop" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber . For more information on the Apache + Software Foundation, please see . + + */ +package org.apache.fop.fonts; + +import java.io.*; + +/** + * This class represents a PFM file (or parts of it) as a Java object. + * + * @author jeremias.maerki@outline.ch + */ +public class PFMFile { + + //Header stuff + private String windowsName; + private String postscriptName; + private short dfItalic; + private int dfWeight; + private short dfCharSet; + private short dfPitchAndFamily; + private int dfAvgWidth; + private int dfMaxWidth; + private int dfMinWidth; + private short dfFirstChar; + private short dfLastChar; + + //Extension stuff + //--- + + //Extend Text Metrics + private int etmCapHeight; + private int etmXHeight; + private int etmLowerCaseAscent; + private int etmLowerCaseDescent; + + //Extent table + private int[] extentTable; + + public PFMFile() { + } + + /** + * Parses a PFM file + * + * @param inStream The stream from which to read the PFM file. + */ + public void load(InputStream inStream) throws IOException { + InputStream bufin = new BufferedInputStream(inStream, 1024); + bufin.mark(1024); + PFMInputStream in = new PFMInputStream(bufin); + int version = in.readShort(); + long filesize = in.readInt(); + bufin.reset(); + + byte[] buf = new byte[(int)filesize]; + bufin.read(buf, 0, (int)filesize); + + bufin = new ByteArrayInputStream(buf); + in = new PFMInputStream(bufin); + loadHeader(in); + loadExtension(in); + } + + /** + * Parses the header of the PFM file. + * + * @param inStream The stream from which to read the PFM file. + */ + private void loadHeader(PFMInputStream inStream) throws IOException { + inStream.skip(80); + dfItalic = inStream.readByte(); + inStream.skip(2); + dfWeight = inStream.readShort(); + dfCharSet = inStream.readByte(); + inStream.skip(4); + dfPitchAndFamily = inStream.readByte(); + dfAvgWidth = inStream.readShort(); + dfMaxWidth = inStream.readShort(); + dfFirstChar = inStream.readByte(); + dfLastChar = inStream.readByte(); + inStream.skip(8); + long faceOffset = inStream.readInt(); + + inStream.reset(); + inStream.skip(faceOffset); + windowsName = inStream.readString(); + + inStream.reset(); + inStream.skip(117); + } + + /** + * Parses the extension part of the PFM file. + * + * @param inStream The stream from which to read the PFM file. + */ + private void loadExtension(PFMInputStream inStream) throws IOException { + int size = inStream.readShort(); + long extMetricsOffset = inStream.readInt(); + long extentTableOffset = inStream.readInt(); + inStream.skip(12); + long driverInfoOffset = inStream.readInt(); + inStream.reset(); + inStream.skip(driverInfoOffset); + postscriptName = inStream.readString(); + + if (extMetricsOffset != 0) { + inStream.reset(); + inStream.skip(extMetricsOffset); + loadExtMetrics(inStream); + } + if (extentTableOffset != 0) { + inStream.reset(); + inStream.skip(extentTableOffset); + loadExtentTable(inStream); + } + + } + + /** + * Parses the extended metrics part of the PFM file. + * + * @param inStream The stream from which to read the PFM file. + */ + private void loadExtMetrics(PFMInputStream inStream) throws IOException { + int size = inStream.readShort(); + inStream.skip(12); + etmCapHeight = inStream.readShort(); + etmXHeight = inStream.readShort(); + etmLowerCaseAscent = inStream.readShort(); + etmLowerCaseDescent = inStream.readShort(); + } + + /** + * Parses the extent table of the PFM file. + * + * @param inStream The stream from which to read the PFM file. + */ + private void loadExtentTable(PFMInputStream inStream) throws IOException { + extentTable = new int[dfLastChar-dfFirstChar]; + dfMinWidth = dfMaxWidth; + for (short i = dfFirstChar; i < dfLastChar; i++) { + extentTable[i-dfFirstChar] = inStream.readShort(); + if (extentTable[i-dfFirstChar] < dfMinWidth) { + dfMinWidth = extentTable[i-dfFirstChar]; + } + } + } + + /** + * Returns the Windows name of the font. + * + * @return The Windows name. + */ + public String getWindowsName() { + return windowsName; + } + + /** + * Returns the Postscript name of the font. + * + * @return The Postscript name. + */ + public String getPostscriptName() { + return postscriptName; + } + + /** + * Returns the charset used for the font. + * + * @return The charset (0=WinAnsi). + */ + public short getCharSet() { + return dfCharSet; + } + + /** + * Returns the charset of the font as a string. + * + * @return The name of the charset. + */ + public String getCharSetName() { + switch (dfCharSet) { + case 0: return "WinAnsi"; + case 128: return "Shift-JIS (Japanese)"; + default: return "Unknown"; + } + } + + /** + * Returns the number of the character that defines + * the first entry in the widths list. + * + * @return The number of the first character. + */ + public short getFirstChar() { + return dfFirstChar; + } + + /** + * Returns the number of the character that defines + * the last entry in the widths list. + * + * @return The number of the last character. + */ + public short getLastChar() { + return dfLastChar; + } + + /** + * Returns the CapHeight parameter for the font (height of uppercase H). + * + * @return The CapHeight parameter. + */ + public int getCapHeight() { + return etmCapHeight; + } + + /** + * Returns the XHeight parameter for the font (height of lowercase x). + * + * @return The CapHeight parameter. + */ + public int getXHeight() { + return etmXHeight; + } + + /** + * Returns the LowerCaseAscent parameter for the font (height of lowercase d). + * + * @return The LowerCaseAscent parameter. + */ + public int getLowerCaseAscent() { + return etmLowerCaseAscent; + } + + /** + * Returns the LowerCaseDescent parameter for the font (height of lowercase p). + * + * @return The LowerCaseDescent parameter. + */ + public int getLowerCaseDescent() { + return etmLowerCaseDescent; + } + + /** + * Tells whether the font has proportional character spacing. + * + * @return ex. true for Times, false for Courier. + */ + public boolean getIsProportional() { + return ((dfPitchAndFamily & 1) == 1); + } + + /** + * Returns the bounding box for the font. + * Note: this value is just an approximation, + * it does not really exist in the PFM file. + * + * @return The calculated Font BBox. + */ + public int[] getFontBBox() { + int[] bbox = new int[4]; + + //Just guessing.... + if (!getIsProportional() && (dfAvgWidth == dfMaxWidth)) { + bbox[0] = -20; + } else { + bbox[0] = -100; + } + bbox[1] = -(getLowerCaseDescent() + 5); + bbox[2] = dfMaxWidth + 10; + bbox[3] = getLowerCaseAscent() + 5; + return bbox; + } + + /** + * Returns the characteristics flags for the font as + * needed for a PDF font descriptor (See PDF specs). + * + * @return The characteristics flags. + */ + public int getFlags() { + int flags = 0; + if (!getIsProportional()) { flags |= 1; } + if ((dfPitchAndFamily & 16) == 16) { flags |= 2; } + if ((dfPitchAndFamily & 64) == 64) { flags |= 4; } + if (dfCharSet == 0) { flags |= 6; } + if (dfItalic != 0) { flags |= 7; } + return flags; + } + + /** + * Returns the width of the dominant vertical stems of the font. + * Note: this value is just an approximation, + * it does not really exist in the PFM file. + * + * @return The vertical stem width. + */ + public int getStemV() { + //Just guessing.... + if (dfItalic != 0) { + return (int)Math.round(dfMinWidth * 0.25); + } else { + return (int)Math.round(dfMinWidth * 0.6); + } + } + + /** + * Returns the italic angle of the font. + * Note: this value is just an approximation, + * it does not really exist in the PFM file. + * + * @return The italic angle. + */ + public int getItalicAngle() { + if (dfItalic != 0) { + return -16; //Just guessing.... + } else { + return 0; + } + } + + /** + * Returns the width of a character + * + * @param which The number of the character for which the width is requested. + * @return The width of a character. + */ + public int getCharWidth(short which) { + return extentTable[which-dfFirstChar]; + } +} \ No newline at end of file diff --git a/src/org/apache/fop/fonts/PFMInputStream.java b/src/org/apache/fop/fonts/PFMInputStream.java new file mode 100644 index 000000000..e45d5e1a5 --- /dev/null +++ b/src/org/apache/fop/fonts/PFMInputStream.java @@ -0,0 +1,132 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "Fop" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber . For more information on the Apache + Software Foundation, please see . + + */ +package org.apache.fop.fonts; + +import java.io.*; + +/** + * This is a helper class for reading PFM files. It defines functions for + * extracting specific values out of the stream. + * + * @author jeremias.maerki@outline.ch + */ +public class PFMInputStream extends java.io.FilterInputStream { + + DataInputStream inStream; + + /** + * Constructs a PFMInputStream based on an InputStream representing the PFM file. + * + * @param inStream The stream from which to read the PFM file. + */ + public PFMInputStream(InputStream in) { + super(in); + inStream = new DataInputStream(in); + } + + /** + * Parses a one byte value out of the stream. + * + * @return The value extracted. + */ + public short readByte() throws IOException { + short s = inStream.readByte(); + //Now, we've got to trick Java into forgetting the sign + int s1 = (((s & 0xF0) >>> 4) << 4) + (s & 0x0F); + return (short)s1; + } + + /** + * Parses a two byte value out of the stream. + * + * @return The value extracted. + */ + public int readShort() throws IOException { + int i = inStream.readShort(); + + //Change byte order + int high = (i & 0xFF00) >>> 8; + int low = (i & 0x00FF) << 8; + return low + high; + } + + /** + * Parses a four byte value out of the stream. + * + * @return The value extracted. + */ + public long readInt() throws IOException { + int i = inStream.readInt(); + + //Change byte order + int i1 = (i & 0xFF000000) >>> 24; + int i2 = (i & 0x00FF0000) >>> 8; + int i3 = (i & 0x0000FF00) << 8; + int i4 = (i & 0x000000FF) << 24; + return i1 + i2 + i3 + i4; + } + + /** + * Parses a zero-terminated string out of the stream. + * + * @return The value extracted. + */ + public String readString() throws IOException { + InputStreamReader reader = new InputStreamReader(in, "ISO-8859-1"); + StringBuffer buf = new StringBuffer(); + int ch = reader.read(); + while (ch != 0) { + buf.append((char) ch); + ch = reader.read(); + } + return buf.toString(); + } +} \ No newline at end of file diff --git a/src/org/apache/fop/fonts/apps/FontPostProcess.xsl b/src/org/apache/fop/fonts/apps/FontPostProcess.xsl new file mode 100644 index 000000000..5739a07e7 --- /dev/null +++ b/src/org/apache/fop/fonts/apps/FontPostProcess.xsl @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/org/apache/fop/fonts/apps/FontPostProcessSort.xsl b/src/org/apache/fop/fonts/apps/FontPostProcessSort.xsl new file mode 100644 index 000000000..63ca43408 --- /dev/null +++ b/src/org/apache/fop/fonts/apps/FontPostProcessSort.xsl @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/org/apache/fop/fonts/apps/PFMReader.java b/src/org/apache/fop/fonts/apps/PFMReader.java new file mode 100644 index 000000000..3a9eaddb5 --- /dev/null +++ b/src/org/apache/fop/fonts/apps/PFMReader.java @@ -0,0 +1,358 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "Fop" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber . For more information on the Apache + Software Foundation, please see . + + */ +package org.apache.fop.fonts.apps; + +import java.io.*; +import org.w3c.dom.*; +import org.apache.xerces.dom.*; +import org.apache.xml.serialize.*; +import org.apache.xalan.xslt.*; +import org.apache.fop.fonts.*; + +/** + * A tool which reads PFM files from Adobe Type 1 fonts and creates + * XML font metrics file for use in FOP. + * + * @author jeremias.maerki@outline.ch + */ +public class PFMReader { + + static private final String XSL_POSTPROCESS = "FontPostProcess.xsl"; + static private final String XSL_SORT = "FontPostProcessSort.xsl"; + + private boolean invokedStandalone = false; + + public PFMReader() { + } + + /** + * The main method for the PFM reader tool. + * + * @param args Command-line arguments: [pfm-file] {[xml-file]} + * If [xml-file] is not provided, then just a little preview of + * the PFM ist displayed. + */ + public static void main(String[] args) { + PFMReader app = new PFMReader(); + app.invokedStandalone = true; + + System.out.println("PFM Reader v1.0"); + System.out.println(); + + if (args.length > 0) { + PFMFile pfm = app.loadPFM(args[0]); + if (pfm != null) { + app.preview(pfm); + + if (args.length > 1) { + org.w3c.dom.Document doc = app.constructFontXML(pfm); + doc = app.postProcessXML(doc); + if (doc != null) { + app.writeFontXML(doc, args[1]); + } + } + } + } else { + System.out.println("Arguments: []"); + System.out.println("Example: COM_____.pfm COM_____.xml"); + } + } + + /** + * Read a PFM file and returns it as an object. + * + * @param filename The filename of the PFM file. + * @return The PFM as an object. + */ + public PFMFile loadPFM(String filename) { + try { + System.out.println("Reading " + filename + "..."); + System.out.println(); + FileInputStream in = new FileInputStream(filename); + PFMFile pfm = new PFMFile(); + pfm.load(in); + return pfm; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * Displays a preview of the PFM file on the console. + * + * @param pfm The PFM file to preview. + */ + public void preview(PFMFile pfm) { + PrintStream out = System.out; + + out.print("Font: "); + out.println(pfm.getWindowsName()); + out.print("Name: "); + out.println(pfm.getPostscriptName()); + out.print("CharSet: "); + out.println(pfm.getCharSetName()); + out.print("CapHeight: "); + out.println(pfm.getCapHeight()); + out.print("XHeight: "); + out.println(pfm.getXHeight()); + out.print("LowerCaseAscent: "); + out.println(pfm.getLowerCaseAscent()); + out.print("LowerCaseDescent: "); + out.println(pfm.getLowerCaseDescent()); + out.print("Having widths for "); + out.print(pfm.getLastChar()-pfm.getFirstChar()); + out.print(" characters ("); + out.print(pfm.getFirstChar()); + out.print("-"); + out.print(pfm.getLastChar()); + out.println(")."); + out.print("for example: Char "); + out.print(pfm.getFirstChar()); + out.print(" has a width of "); + out.println(pfm.getCharWidth(pfm.getFirstChar())); + out.println(); + } + + /** + * Writes the generated DOM Document to a file. + * + * @param doc The DOM Document to save. + * @param target The target filename for the XML file. + */ + public void writeFontXML(org.w3c.dom.Document doc, String target) { + System.out.println("Writing xml font file " + target + "..."); + System.out.println(); + + try { + OutputFormat format = new OutputFormat(doc); //Serialize DOM + FileWriter out = new FileWriter(target); //Writer will be a String + XMLSerializer serial = new XMLSerializer(out, format); + serial.asDOMSerializer(); // As a DOM Serializer + + serial.serialize(doc.getDocumentElement()); + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Generates the font metrics file from the PFM file. + * + * @param pfm The PFM file to generate the font metrics from. + * @return The DOM document representing the font metrics file. + */ + public org.w3c.dom.Document constructFontXML(PFMFile pfm) { + System.out.println("Creating xml font file..."); + System.out.println(); + + Document doc = new DocumentImpl(); + Element root = doc.createElement("font-metrics"); + doc.appendChild(root); + + Element el = doc.createElement("font-name"); + root.appendChild(el); + el.appendChild(doc.createTextNode(pfm.getPostscriptName())); + + String s = pfm.getPostscriptName(); + int pos = s.indexOf("-"); + if (pos >= 0) { + StringBuffer sb = new StringBuffer(s); + sb.deleteCharAt(pos); + s = sb.toString(); + } + + el = doc.createElement("class-name"); + root.appendChild(el); + el.appendChild(doc.createTextNode(s)); + + el = doc.createElement("subtype"); + root.appendChild(el); + el.appendChild(doc.createTextNode("Type1")); + + el = doc.createElement("encoding"); + root.appendChild(el); + el.appendChild(doc.createTextNode(pfm.getCharSetName()+"Encoding")); + + el = doc.createElement("cap-height"); + root.appendChild(el); + Integer value = new Integer(pfm.getCapHeight()); + el.appendChild(doc.createTextNode(value.toString())); + + el = doc.createElement("x-height"); + root.appendChild(el); + value = new Integer(pfm.getXHeight()); + el.appendChild(doc.createTextNode(value.toString())); + + el = doc.createElement("ascender"); + root.appendChild(el); + value = new Integer(pfm.getLowerCaseAscent()); + el.appendChild(doc.createTextNode(value.toString())); + + el = doc.createElement("descender"); + root.appendChild(el); + value = new Integer(-pfm.getLowerCaseDescent()); + el.appendChild(doc.createTextNode(value.toString())); + + Element bbox = doc.createElement("bbox"); + root.appendChild(bbox); + int[] bb = pfm.getFontBBox(); + String[] names = {"left","bottom","right","top"}; + for (int i=0; i<4; i++) { + el = doc.createElement(names[i]); + bbox.appendChild(el); + value = new Integer(bb[i]); + el.appendChild(doc.createTextNode(value.toString())); + } + + el = doc.createElement("flags"); + root.appendChild(el); + value = new Integer(pfm.getFlags()); + el.appendChild(doc.createTextNode(value.toString())); + + el = doc.createElement("stemv"); + root.appendChild(el); + value = new Integer(pfm.getStemV()); + el.appendChild(doc.createTextNode(value.toString())); + + el = doc.createElement("italicangle"); + root.appendChild(el); + value = new Integer(pfm.getItalicAngle()); + el.appendChild(doc.createTextNode(value.toString())); + + el = doc.createElement("first-char"); + root.appendChild(el); + value = new Integer(pfm.getFirstChar()); + el.appendChild(doc.createTextNode(value.toString())); + + el = doc.createElement("last-char"); + root.appendChild(el); + value = new Integer(pfm.getLastChar()); + el.appendChild(doc.createTextNode(value.toString())); + + Element widths = doc.createElement("widths"); + root.appendChild(widths); + + for (short i = pfm.getFirstChar(); i < pfm.getLastChar(); i++) { + el = doc.createElement("char"); + widths.appendChild(el); + el.setAttribute("ansichar", "0x00" + Integer.toHexString(i).toUpperCase()); + el.setAttribute("width", new Integer(pfm.getCharWidth(i)).toString()); + } + + return doc; + } + + /** + * Modifies the generated font metrics file. First, it processes the + * character mmappings, then it sorts them. + * + * @param doc The DOM document representing the font metrics file. + * @return A DOM document representing the processed font metrics file. + */ + public org.w3c.dom.Document postProcessXML(org.w3c.dom.Document doc) { + try { + + System.out.println("Postprocessing..."); + System.out.println(); + + // Create the 3 objects the XSLTProcessor needs to perform the transformation. + org.apache.xalan.xslt.XSLTInputSource xmlSource = + new org.apache.xalan.xslt.XSLTInputSource(doc); + + InputStream xsl = this.getClass().getResourceAsStream(XSL_POSTPROCESS); + if (xsl == null) { + throw new Exception("Resource " + XSL_POSTPROCESS + " not found"); + } + org.apache.xalan.xslt.XSLTInputSource xslSheet = + new org.apache.xalan.xslt.XSLTInputSource(xsl); + + Document targetDoc = new DocumentImpl(); + org.apache.xalan.xslt.XSLTResultTarget xmlResult = + new org.apache.xalan.xslt.XSLTResultTarget(targetDoc); + + // Use XSLTProcessorFactory to instantiate an XSLTProcessor. + org.apache.xalan.xslt.XSLTProcessor processor = + org.apache.xalan.xslt.XSLTProcessorFactory.getProcessor( + new org.apache.xalan.xpath.xdom.XercesLiaison()); + + // Perform the transformation. + processor.process(xmlSource, xslSheet, xmlResult); + + + System.out.println("Sorting..."); + System.out.println(); + + // Sort the whole thing + xmlSource.setNode(targetDoc); + + xsl = this.getClass().getResourceAsStream(XSL_SORT); + if (xsl == null) { + throw new Exception("Resource " + XSL_SORT + " not found"); + } + xslSheet = new org.apache.xalan.xslt.XSLTInputSource(xsl); + + org.w3c.dom.Document targetDocSorted = new DocumentImpl(); + xmlResult = + new org.apache.xalan.xslt.XSLTResultTarget(targetDocSorted); + + // Perform the transformation (sort). + processor.process(xmlSource, xslSheet, xmlResult); + + return targetDocSorted; + + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/src/org/apache/fop/layout/FontDescriptor.java b/src/org/apache/fop/layout/FontDescriptor.java new file mode 100644 index 000000000..defc71540 --- /dev/null +++ b/src/org/apache/fop/layout/FontDescriptor.java @@ -0,0 +1,69 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "Fop" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber . For more information on the Apache + Software Foundation, please see . + + */ +package org.apache.fop.layout; + + +public interface FontDescriptor { + + //Required + public int getAscender(); //Ascent in pdf spec + public int getCapHeight(); + public int getDescender(); //Descent in pdf spec + public int getFlags(); + public int[] getFontBBox(); + public String fontName(); //should be getFontName(). not? + public int getItalicAngle(); + public int getStemV(); + + //Optional + //public int getXHeight(); + +} diff --git a/src/org/apache/fop/layout/FontMetric.java b/src/org/apache/fop/layout/FontMetric.java index 68398b0a9..426702f8e 100644 --- a/src/org/apache/fop/layout/FontMetric.java +++ b/src/org/apache/fop/layout/FontMetric.java @@ -54,14 +54,19 @@ package org.apache.fop.layout; * interface for font metric classes */ public interface FontMetric { - int getAscender(); - int getCapHeight(); - int getDescender(); - int getXHeight(); + + public int getAscender(); + public int getCapHeight(); + public int getDescender(); + public int getXHeight(); + + public int getFirstChar(); + public int getLastChar(); /** * return width (in 1/1000ths of point size) of character at * code point i */ public int width(int i); + public int[] getWidths(); } diff --git a/src/org/apache/fop/pdf/PDFArray.java b/src/org/apache/fop/pdf/PDFArray.java new file mode 100644 index 000000000..012bd906f --- /dev/null +++ b/src/org/apache/fop/pdf/PDFArray.java @@ -0,0 +1,90 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "Fop" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber . For more information on the Apache + Software Foundation, please see . + + */ +package org.apache.fop.pdf; + +/** + * class representing an array object + */ +public class PDFArray extends PDFObject { + + protected int[] values; + + /** + * create the array object + * + * @param number the object's number + * @param values the actual array wrapped by this object + */ + public PDFArray(int number, int[] values) { + + /* generic creation of PDF object */ + super(number); + + /* set fields using paramaters */ + this.values = values; + } + + /** + * produce the PDF representation for the object + * + * @return the PDF + */ + public String toPDF() { + StringBuffer p = new StringBuffer(); + p.append(this.number + " " + this.generation + " obj\n["); + for (int i = 0; i < values.length; i++) { + p.append(" "); + p.append(values[i]); + } + p.append("]\nendobj\n"); + return p.toString(); + } +} diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index 44091602c..d93367faa 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -1,4 +1,4 @@ -/*-- $Id$ -- +/*-- $Id$ -- ============================================================================ The Apache Software License, Version 1.1 @@ -41,15 +41,16 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - + This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by - James Tauber . For more information on the Apache + James Tauber . For more information on the Apache Software Foundation, please see . - + */ /* image support modified from work of BoBoGi */ +/* font support based on work by Takayuki Takeuchi */ package org.apache.fop.pdf; @@ -62,6 +63,8 @@ import org.apache.fop.datatypes.ColorSpace; import org.apache.fop.datatypes.IDReferences; import org.apache.fop.layout.Page; +import org.apache.fop.layout.FontMetric; +import org.apache.fop.layout.FontDescriptor; // Java import java.io.IOException; import java.io.PrintWriter; @@ -71,7 +74,7 @@ import java.util.Enumeration; import java.awt.Rectangle; /** - * class representing a PDF document. + * class representing a PDF document. * * The document is built up by calling various methods and then finally * output to given filehandle using output method. @@ -716,25 +719,84 @@ public class PDFDocument { } + /** + * make a /Encoding object + * + * @param encodingName character encoding scheme name + * @return the created /Encoding object + */ + public PDFEncoding makeEncoding(String encodingName) { + + /* create a PDFEncoding with the next object number and add to the + list of objects */ + PDFEncoding encoding = new PDFEncoding(++this.objectcount, encodingName); + this.objects.addElement(encoding); + return encoding; + } + + /** * make a Type1 /Font object - * + * * @param fontname internal name to use for this font (eg "F1") * @param basefont name of the base font (eg "Helvetica") * @param encoding character encoding scheme used by the font + * @param metrics additional information about the font + * @param descriptor additional information about the font * @return the created /Font object */ public PDFFont makeFont(String fontname, String basefont, - String encoding) { + String encoding, FontMetric metrics, FontDescriptor descriptor) { /* create a PDFFont with the next object number and add to the list of objects */ - PDFFont font = new PDFFont(++this.objectcount, fontname, - basefont, encoding); - this.objects.addElement(font); - return font; + if (descriptor == null) { + PDFFont font = new PDFFont(++this.objectcount, fontname, PDFFont.TYPE1, + basefont, encoding); + this.objects.addElement(font); + return font; + } else { + PDFFontNonBase14 font = (PDFFontNonBase14)PDFFont.createFont( + ++this.objectcount, fontname, + PDFFont.TYPE1, basefont, encoding); + this.objects.addElement(font); + PDFFontDescriptor pdfdesc = makeFontDescriptor(descriptor); + font.setDescriptor(pdfdesc); + font.setWidthMetrics(metrics.getFirstChar(), metrics.getLastChar(), + makeArray(metrics.getWidths())); + return font; + } } + + /** + * make a /FontDescriptor object for a CID font + */ + public PDFFontDescriptor makeFontDescriptor(FontDescriptor desc) { + + /* create a PDFFontDescriptor with the next object number and add to + the list of objects */ + PDFFontDescriptor font = new PDFFontDescriptor(++this.objectcount, + desc.fontName(), desc.getAscender(), desc.getDescender(), + desc.getCapHeight(), desc.getFlags(), + new PDFRectangle(desc.getFontBBox()), desc.getStemV(), + desc.getItalicAngle()); + this.objects.addElement(font); + return font; + } + + + /** + * make an Array object (ex. Widths array for a font) + */ + public PDFArray makeArray(int[] values) { + + PDFArray array = new PDFArray(++this.objectcount, values); + this.objects.addElement(array); + return array; + } + + public int addImage(FopImage img) { // check if already created String url = img.getURL(); diff --git a/src/org/apache/fop/pdf/PDFEncoding.java b/src/org/apache/fop/pdf/PDFEncoding.java new file mode 100644 index 000000000..f5ed80a47 --- /dev/null +++ b/src/org/apache/fop/pdf/PDFEncoding.java @@ -0,0 +1,152 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "Fop" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber . For more information on the Apache + Software Foundation, please see . + + */ +package org.apache.fop.pdf; + +// Java +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Vector; + +/** + * class representing an /Encoding object. + * + * A small object expressing the base encoding name and + * the differences from the base encoding. + * + * The three base encodings are given by their name. + * + * Encodings are specified on page 213 and onwards of the PDF 1.3 spec. + */ +public class PDFEncoding extends PDFObject { + + /** the name for the standard encoding scheme */ + public static final String MacRomanEncoding = "MacRomanEncoding"; + /** the name for the standard encoding scheme */ + public static final String MacExpertEncoding = "MacExpertEncoding"; + /** the name for the standard encoding scheme */ + public static final String WinAnsiEncoding = "WinAnsiEncoding"; + + /** + * the name for the base encoding. + * One of the three base encoding scheme names or + * the default font's base encoding if null. + */ + protected String basename; + + /** the differences from the base encoding */ + protected Hashtable differences; + + /** + * create the /Encoding object + * + * @param number the object's number + * @param basename the name of the character encoding schema + */ + public PDFEncoding(int number, String basename) { + + /* generic creation of PDF object */ + super(number); + + /* set fields using paramaters */ + this.basename = basename; + this.differences = new Hashtable(); + } + + /** + * add differences to the encoding + * + * @param code the first index of the sequence to be changed + * @param sequence the sequence of glyph names (as String) + */ + public void addDifferences(int code, Vector sequence) { + differences.put(new Integer(code), sequence); + } + + /** + * produce the PDF representation for the object + * + * @return the PDF + */ + public String toPDF() { + StringBuffer p = new StringBuffer(); + p.append(this.number + " " + this.generation + + " obj\n<< /Type /Encoding"); + if ((basename != null) && (!basename.equals(""))) { + p.append("\n/BaseEncoding /" + this.basename); + } + if (!differences.isEmpty()) { + p.append("\n/Differences [ "); + Object code; + Enumeration codes = differences.keys(); + while (codes.hasMoreElements()) { + code = codes.nextElement(); + p.append(" "); p.append(code); + Vector sequence = (Vector)differences.get(code); + for (int i = 0; i < sequence.size(); i++) { + p.append(" /"); p.append((String)sequence.elementAt(i)); + } + } + p.append(" ]"); + } + p.append(" >>\nendobj\n"); + return p.toString(); + } + /* example (p. 214) + 25 0 obj + << + /Type /Encoding + /Differences [39 /quotesingle 96 /grave 128 + /Adieresis /Aring /Ccedilla /Eacute /Ntilde + /Odieresis /Udieresis /aacute /agrave] + >> + endobj + */ +} diff --git a/src/org/apache/fop/pdf/PDFFont.java b/src/org/apache/fop/pdf/PDFFont.java index 49a6c4791..a1226bb19 100644 --- a/src/org/apache/fop/pdf/PDFFont.java +++ b/src/org/apache/fop/pdf/PDFFont.java @@ -1,36 +1,36 @@ -/*-- $Id$ -- +/*-- $Id$ -- ============================================================================ The Apache Software License, Version 1.1 ============================================================================ - + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - + Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: - + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. - + 4. The names "Fop" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact apache@apache.org. - + 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. - + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE @@ -41,56 +41,158 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - + This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by - James Tauber . For more information on the Apache + James Tauber . For more information on the Apache Software Foundation, please see . - + */ package org.apache.fop.pdf; -// Java -import java.io.IOException; -import java.io.PrintWriter; - /** * class representing a /Font object. * - * A small object expressing the base font name and encoding of a - * Type 1 font along with an internal name for the font used within - * streams of content + * A more complete object expressing the base font name and encoding of a + * font along with an internal name for the font used within + * streams of content. + * + * Fonts are specified on page 198 and onwards of the PDF 1.3 spec. */ public class PDFFont extends PDFObject { + /** font subtype to be used as parameter to createFont() */ + public static final byte TYPE0 = 0; + /** font subtype to be used as parameter to createFont() */ + public static final byte TYPE1 = 1; + /** font subtype to be used as parameter to createFont() */ + public static final byte MMTYPE1 = 2; + /** font subtype to be used as parameter to createFont() */ + public static final byte TYPE3 = 3; + /** font subtype to be used as parameter to createFont() */ + public static final byte TRUETYPE = 4; + + /** font subtype names as output in the PDF */ + protected static final String[] TYPE_NAMES = new String[] // take care of the order + {"Type0", "Type1", "MMType1", "Type3", "TrueType"}; + /** the internal name for the font (eg "F1") */ protected String fontname; + /** + * the font's subtype + * (as defined by the constants TYPE0, TYPE1, MMTYPE1, TYPE3, TRUETYPE) + */ + protected byte subtype; + /** the base font name (eg "Helvetica") */ protected String basefont; - /** the character encoding scheme used by the font (eg - "WinAnsiEncoding") */ - protected String encoding; + /** + * the character encoding scheme used by the font. + * It can be a String for standard encodings, or + * a PDFEncoding for a more complex scheme, or + * a PDFStream containing a CMap in a Type0 font. + * If null then not written out in the PDF. + */ + protected Object encoding; + + /** the Unicode mapping mechanism */ + //protected PDFToUnicode mapping; /** * create the /Font object * - * @param the object's number + * @param number the object's number * @param fontname the internal name for the font + * @param subtype the font's subtype * @param basefont the base font name * @param encoding the character encoding schema used by the font + * @param mapping the Unicode mapping mechanism */ - public PDFFont(int number, String fontname, String basefont, - String encoding) { + public PDFFont(int number, String fontname, byte subtype, String basefont, + Object encoding/*, PDFToUnicode mapping*/) { - /* generic creation of PDF object */ - super(number); + /* generic creation of PDF object */ + super(number); - /* set fields using paramaters */ - this.fontname = fontname; - this.basefont = basefont; - this.encoding = encoding; + /* set fields using paramaters */ + this.fontname = fontname; + this.subtype = subtype; + this.basefont = basefont; + this.encoding = encoding; + //this.mapping = mapping; + } + + /** + * factory method with the basic parameters + * + * @param number the object's number + * @param fontname the internal name for the font + * @param subtype the font's subtype + * @param basefont the base font name + * @param encoding the character encoding schema used by the font + */ + public static PDFFont createFont(int number, String fontname, + byte subtype, String basefont, Object encoding) { + switch (subtype) { + /* + case TYPE0 : + return new PDFFontType0(number, fontname, subtype, basefont, encoding); + */ + case TYPE1 : + case MMTYPE1 : + return new PDFFontType1(number, fontname, subtype, basefont, encoding); + /* + case TYPE3 : + return new PDFFontType3(number, fontname, subtype, basefont, encoding); + case TRUETYPE : + return new PDFFontTrueType(number, fontname, subtype, basefont, encoding); + */ + } + return null; // should not happend + } + + /** + * factory method with the extended parameters + * for Type1, MMType1 and TrueType + * + * @param number the object's number + * @param fontname the internal name for the font + * @param subtype the font's subtype + * @param basefont the base font name + * @param encoding the character encoding schema used by the font + * @param firstChar the first character code in the font + * @param lastChar the last character code in the font + * @param widths an array of size (lastChar - firstChar +1) + * @param descriptor the descriptor for other font's metrics + */ + public static PDFFont createFont(int number, String fontname, + byte subtype, String basefont, Object encoding, + int firstChar, int lastChar, PDFArray widths, + PDFFontDescriptor descriptor) { + + PDFFontNonBase14 font; + switch (subtype) { + case TYPE0 : + return null; // should not happend + case TYPE1 : + case MMTYPE1 : + font = new PDFFontType1(number, fontname, subtype, basefont, encoding); + font.setWidthMetrics(firstChar, lastChar, widths); + font.setDescriptor(descriptor); + return font; + case TYPE3 : + return null; // should not happend + /* + case TRUETYPE : + font = new PDFFontTrueType(number, fontname, subtype, basefont, encoding); + font.setWidthMetrics(firstChar, lastChar, widths); + font.setDescriptor(descriptor); + return font; + */ + } + return null; // should not happend } /** @@ -99,7 +201,7 @@ public class PDFFont extends PDFObject { * @return the internal name */ public String getName() { - return this.fontname; + return this.fontname; } /** @@ -108,10 +210,32 @@ public class PDFFont extends PDFObject { * @return the PDF */ public String toPDF() { - String p = this.number + " " + this.generation - + " obj\n<< /Type /Font\n/Subtype /Type1\n/Name /" - + this.fontname + "\n/BaseFont /" + this.basefont - + "\n/Encoding /"+ this.encoding + " >>\nendobj\n"; - return p; + StringBuffer p = new StringBuffer(); + p.append(this.number + " " + this.generation + + " obj\n<< /Type /Font\n/Subtype /" + TYPE_NAMES[this.subtype] + + "\n/Name /" + this.fontname + "\n/BaseFont /" + this.basefont); + if (encoding != null) { + p.append("\n/Encoding "); + if (encoding instanceof PDFEncoding) { + p.append(((PDFEncoding)this.encoding).referencePDF()); + } else if (encoding instanceof PDFStream) { + p.append(((PDFStream)this.encoding).referencePDF()); + } else { + p.append("/").append((String)encoding); + } + } + fillInPDF(p); + p.append(" >>\nendobj\n"); + return p.toString(); + } + + /** + * fill in the specifics for the font's subtype. + * + * the given buffer already contains the fields common to all font types. + * + * @param begin the buffer to be completed with the type specific fields + */ + protected void fillInPDF(StringBuffer begin) { } } diff --git a/src/org/apache/fop/pdf/PDFFontDescriptor.java b/src/org/apache/fop/pdf/PDFFontDescriptor.java new file mode 100644 index 000000000..3f9f38d45 --- /dev/null +++ b/src/org/apache/fop/pdf/PDFFontDescriptor.java @@ -0,0 +1,203 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "Fop" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber . For more information on the Apache + Software Foundation, please see . + + */ +package org.apache.fop.pdf; + +/** + * class representing a font descriptor. + * + * Font descriptors are specified on page 222 and onwards of the PDF 1.3 spec. + */ +public class PDFFontDescriptor extends PDFObject { + + // Required fields + protected int ascent; + protected int capHeight; + protected int descent; + protected int flags; + protected PDFRectangle fontBBox; + protected String basefont; //PDF-spec: FontName + protected int italicAngle; + protected int stemV; + // Optional fields + protected int stemH = 0; + protected int xHeight = 0; + protected int leading = 0; + protected int avgWidth = 0; + protected int maxWidth = 0; + protected int missingWidth = 0; + protected PDFStream fontfile; + //protected String charSet = null; + + protected byte subtype; + + /** + * create the /FontDescriptor object + * + * @param number the object's number + * @param ascent the maximum height above the baseline + * @param descent the maximum depth below the baseline + * @param capHeight height of the capital letters + * @param flags various characteristics of the font + * @param fontBBox the bounding box for the described font + * @param basefont the base font name + * @param italicAngle the angle of the vertical dominant strokes + * @param stemV the width of the dominant vertical stems of glyphs + */ + public PDFFontDescriptor(int number, String basefont, int ascent, + int descent, int capHeight, int flags, PDFRectangle fontBBox, + int italicAngle, int stemV) { + + /* generic creation of PDF object */ + super(number); + + /* set fields using paramaters */ + this.basefont = basefont; + this.ascent = ascent; + this.descent = descent; + this.capHeight = capHeight; + this.flags = flags; + this.fontBBox = fontBBox; + this.italicAngle = italicAngle; + this.stemV = stemV; + } + + /** + * set the optional metrics + */ + public void setMetrics(int avgWidth, int maxWidth, int missingWidth, int leading, int stemH, int xHeight) { + this.avgWidth = avgWidth; + this.maxWidth = maxWidth; + this.missingWidth = missingWidth; + this.leading = leading; + this.stemH = stemH; + this.xHeight = xHeight; + } + + /** + * set the optional font file stream + * + * @param subtype the font type defined in the font stream + * @param fontfile the stream containing an embedded font + */ + public void setFontFile(byte subtype, PDFStream fontfile) { + this.subtype = subtype; + this.fontfile = fontfile; + } + + //public void setCharSet(){}//for subset fonts + + /** + * produce the PDF representation for the object + * + * @return the PDF + */ + public String toPDF() { + StringBuffer p = new StringBuffer( + this.number + " " + this.generation + + " obj\n<< /Type /FontDescriptor" + + "\n/FontName /" + this.basefont); + + p.append("\n/FontBBox "); p.append(fontBBox.toPDF()); + p.append("\n/Flags "); p.append(flags); + p.append("\n/CapHeight "); p.append(capHeight); + p.append("\n/Ascent "); p.append(ascent); + p.append("\n/Descent "); p.append(descent); + p.append("\n/ItalicAngle "); p.append(italicAngle); + p.append("\n/StemV "); p.append(stemV); + // optional fields + if (stemH != 0) { + p.append("\n/StemH "); p.append(stemH); + } + if (xHeight != 0) { + p.append("\n/XHeight "); p.append(xHeight); + } + if (avgWidth != 0) { + p.append("\n/AvgWidth "); p.append(avgWidth); + } + if (maxWidth != 0) { + p.append("\n/MaxWidth "); p.append(maxWidth); + } + if (missingWidth != 0) { + p.append("\n/MissingWidth "); p.append(missingWidth); + } + if (leading != 0) { + p.append("\n/Leading "); p.append(leading); + } + if (fontfile != null) { + switch (subtype) { + case PDFFont.TYPE1: + p.append("\n/FontFile "); + break; + case PDFFont.TRUETYPE: + p.append("\n/FontFile2 "); + break; + default: + p.append("\n/FontFile3 "); + } + p.append(fontfile.referencePDF()); + } + // charSet for subset fonts // not yet implemented + // CID optional field + fillInPDF(p); + p.append("\n >>\nendobj\n"); + return p.toString(); + } + + /** + * fill in the specifics for the font's descriptor. + * + * the given buffer already contains the fields common to all descriptors. + * + * @param begin the buffer to be completed with the specific fields + */ + protected void fillInPDF(StringBuffer begin) { + } +} diff --git a/src/org/apache/fop/pdf/PDFFontNonBase14.java b/src/org/apache/fop/pdf/PDFFontNonBase14.java new file mode 100644 index 000000000..583af810d --- /dev/null +++ b/src/org/apache/fop/pdf/PDFFontNonBase14.java @@ -0,0 +1,124 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "Fop" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber . For more information on the Apache + Software Foundation, please see . + + */ +package org.apache.fop.pdf; + +// Java + +/** + * A common ancestor for Type1, TrueType, MMType1 and Type3 fonts + * (all except base 14 fonts). + */ +public abstract class PDFFontNonBase14 extends PDFFont { + + /** first character code in the font */ + protected int firstChar; + /** last character code in the font */ + protected int lastChar; + /** widths of characters from firstChar to lastChar */ + protected PDFArray widths; + /** descriptor of font metrics */ + protected PDFFontDescriptor descriptor; + + /** + * create the /Font object + * + * @param number the object's number + * @param fontname the internal name for the font + * @param subtype the font's subtype + * @param basefont the base font name + * @param encoding the character encoding schema used by the font + * @param mapping the Unicode mapping mechanism + */ + public PDFFontNonBase14(int number, String fontname, byte subtype, + String basefont, Object encoding/*, PDFToUnicode mapping*/) { + + /* generic creation of PDF object */ + super(number, fontname, subtype, basefont, encoding); + + this.descriptor = null; + } + + /** + * set the width metrics for the font + * + * @param firstChar the first character code in the font + * @param lastChar the last character code in the font + * @param widths an array of size (lastChar - firstChar +1) + */ + public void setWidthMetrics(int firstChar, int lastChar, PDFArray widths) { + /* set fields using paramaters */ + this.firstChar = firstChar; + this.lastChar = lastChar; + this.widths = widths; + } + + /** + * set the font descriptor (unused for the Type3 fonts) + * + * @param descriptor the descriptor for other font's metrics + */ + public void setDescriptor(PDFFontDescriptor descriptor) { + this.descriptor = descriptor; + } + + /** + * fill in the specifics for the font's subtype + */ + protected void fillInPDF(StringBuffer p) { + p.append("\n/FirstChar "); p.append(firstChar); + p.append("\n/LastChar "); p.append(lastChar); + p.append("\n/Widths "); p.append(this.widths.referencePDF()); + if (descriptor != null) { + p.append("\n/FontDescriptor "); + p.append(this.descriptor.referencePDF()); + } + } +} diff --git a/src/org/apache/fop/pdf/PDFFontType1.java b/src/org/apache/fop/pdf/PDFFontType1.java new file mode 100644 index 000000000..3516b670b --- /dev/null +++ b/src/org/apache/fop/pdf/PDFFontType1.java @@ -0,0 +1,81 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "Fop" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber . For more information on the Apache + Software Foundation, please see . + + */ +package org.apache.fop.pdf; + +/** + * class representing a Type1 or MMType1 font (not necessary for the base 14). + * + * Type1 fonts are specified on page 201 and onwards of the PDF 1.3 spec. + * MMType1 fonts are specified on page 205 and onwards of the PDF 1.3 spec. + * + * In fact everything already done in the superclass. + * Must only define the not default constructor. + */ +public class PDFFontType1 extends PDFFontNonBase14 { + + /** + * create the /Font object + * + * @param number the object's number + * @param fontname the internal name for the font + * @param subtype the font's subtype (PDFFont.TYPE1 or PDFFont.MMTYPE1) + * @param basefont the base font name + * @param encoding the character encoding schema used by the font + * @param mapping the Unicode mapping mechanism + */ + public PDFFontType1(int number, String fontname, byte subtype, + String basefont, Object encoding/*, PDFToUnicode mapping*/) { + + /* generic creation of PDF object */ + super(number, fontname, subtype, basefont, encoding); + } + +} diff --git a/src/org/apache/fop/pdf/PDFRectangle.java b/src/org/apache/fop/pdf/PDFRectangle.java new file mode 100644 index 000000000..5c5a563d6 --- /dev/null +++ b/src/org/apache/fop/pdf/PDFRectangle.java @@ -0,0 +1,103 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "Fop" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber . For more information on the Apache + Software Foundation, please see . + + */ +package org.apache.fop.pdf; + +/** + * class representing a rectangle + * + * Rectangles are specified on page 183 of the PDF 1.3 spec. + */ +public class PDFRectangle { + /** lower left x coordinate */ + protected int llx; + /** lower left y coordinate */ + protected int lly; + /** upper right x coordinate */ + protected int urx; + /** upper right y coordinate */ + protected int ury; + + /** + * create a rectangle giving the four separate values + * + * @param llx lower left x coordinate + * @param lly lower left y coordinate + * @param urx upper right x coordinate + * @param ury upper right y coordinate + */ + public PDFRectangle(int llx, int lly, int urx, int ury) { + this.llx = llx; + this.lly = lly; + this.urx = urx; + this.ury = ury; + } + + /** + * create a rectangle giving an array of four values + * + * @param array values in the order llx, lly, urx, ury + */ + public PDFRectangle(int[] array) { + this.llx = array[0]; + this.lly = array[1]; + this.urx = array[2]; + this.ury = array[3]; + } + + /** + * produce the PDF representation for the object + * + * @return the PDF + */ + public String toPDF() { + return " [" + llx + " " + lly + " " + urx + " " + ury + "] "; + } +} diff --git a/src/org/apache/fop/render/pdf/FontSetup.java b/src/org/apache/fop/render/pdf/FontSetup.java index 68841f8b3..368a67af8 100644 --- a/src/org/apache/fop/render/pdf/FontSetup.java +++ b/src/org/apache/fop/render/pdf/FontSetup.java @@ -54,6 +54,7 @@ package org.apache.fop.render.pdf; import org.apache.fop.render.pdf.fonts.*; import org.apache.fop.messaging.MessageHandler; import org.apache.fop.layout.FontInfo; +import org.apache.fop.layout.FontDescriptor; import org.apache.fop.pdf.PDFDocument; import org.apache.fop.pdf.PDFResources; @@ -78,126 +79,136 @@ public class FontSetup { * @param fontInfo the font info object to set up */ public static void setup(FontInfo fontInfo) { - MessageHandler.logln("setting up fonts"); - - fontInfo.addMetrics("F1", new Helvetica()); - fontInfo.addMetrics("F2", new HelveticaOblique()); - fontInfo.addMetrics("F3", new HelveticaBold()); - fontInfo.addMetrics("F4", new HelveticaBoldOblique()); - fontInfo.addMetrics("F5", new TimesRoman()); - fontInfo.addMetrics("F6", new TimesItalic()); - fontInfo.addMetrics("F7", new TimesBold()); - fontInfo.addMetrics("F8", new TimesBoldItalic()); - fontInfo.addMetrics("F9", new Courier()); - fontInfo.addMetrics("F10", new CourierOblique()); - fontInfo.addMetrics("F11", new CourierBold()); - fontInfo.addMetrics("F12", new CourierBoldOblique()); - fontInfo.addMetrics("F13", new Symbol()); - fontInfo.addMetrics("F14", new ZapfDingbats()); - - /* any is treated as serif */ - fontInfo.addFontProperties("F5", "any", "normal", "normal"); - fontInfo.addFontProperties("F6", "any", "italic", "normal"); - fontInfo.addFontProperties("F6", "any", "oblique", "normal"); - fontInfo.addFontProperties("F7", "any", "normal", "bold"); - fontInfo.addFontProperties("F8", "any", "italic", "bold"); - fontInfo.addFontProperties("F8", "any", "oblique", "bold"); - - fontInfo.addFontProperties("F1", "sans-serif", "normal", - "normal"); - fontInfo.addFontProperties("F2", "sans-serif", "oblique", - "normal"); - fontInfo.addFontProperties("F2", "sans-serif", "italic", - "normal"); - fontInfo.addFontProperties("F3", "sans-serif", "normal", - "bold"); - fontInfo.addFontProperties("F4", "sans-serif", "oblique", - "bold"); - fontInfo.addFontProperties("F4", "sans-serif", "italic", - "bold"); - fontInfo.addFontProperties("F5", "serif", "normal", "normal"); - fontInfo.addFontProperties("F6", "serif", "oblique", - "normal"); - fontInfo.addFontProperties("F6", "serif", "italic", "normal"); - fontInfo.addFontProperties("F7", "serif", "normal", "bold"); - fontInfo.addFontProperties("F8", "serif", "oblique", "bold"); - fontInfo.addFontProperties("F8", "serif", "italic", "bold"); - fontInfo.addFontProperties("F9", "monospace", "normal", - "normal"); - fontInfo.addFontProperties("F10", "monospace", "oblique", - "normal"); - fontInfo.addFontProperties("F10", "monospace", "italic", - "normal"); - fontInfo.addFontProperties("F11", "monospace", "normal", - "bold"); - fontInfo.addFontProperties("F12", "monospace", "oblique", - "bold"); - fontInfo.addFontProperties("F12", "monospace", "italic", - "bold"); - - fontInfo.addFontProperties("F1", "Helvetica", "normal", - "normal"); - fontInfo.addFontProperties("F2", "Helvetica", "oblique", - "normal"); - fontInfo.addFontProperties("F2", "Helvetica", "italic", - "normal"); - fontInfo.addFontProperties("F3", "Helvetica", "normal", - "bold"); - fontInfo.addFontProperties("F4", "Helvetica", "oblique", - "bold"); - fontInfo.addFontProperties("F4", "Helvetica", "italic", - "bold"); - fontInfo.addFontProperties("F5", "Times", "normal", "normal"); - fontInfo.addFontProperties("F6", "Times", "oblique", - "normal"); - fontInfo.addFontProperties("F6", "Times", "italic", "normal"); - fontInfo.addFontProperties("F7", "Times", "normal", "bold"); - fontInfo.addFontProperties("F8", "Times", "oblique", "bold"); - fontInfo.addFontProperties("F8", "Times", "italic", "bold"); - fontInfo.addFontProperties("F9", "Courier", "normal", - "normal"); - fontInfo.addFontProperties("F10", "Courier", "oblique", - "normal"); - fontInfo.addFontProperties("F10", "Courier", "italic", - "normal"); - fontInfo.addFontProperties("F11", "Courier", "normal", - "bold"); - fontInfo.addFontProperties("F12", "Courier", "oblique", - "bold"); - fontInfo.addFontProperties("F12", "Courier", "italic", - "bold"); - fontInfo.addFontProperties("F13", "Symbol", "normal", - "normal"); - fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", - "normal"); + MessageHandler.logln("setting up fonts"); + + fontInfo.addMetrics("F1", new Helvetica()); + fontInfo.addMetrics("F2", new HelveticaOblique()); + fontInfo.addMetrics("F3", new HelveticaBold()); + fontInfo.addMetrics("F4", new HelveticaBoldOblique()); + fontInfo.addMetrics("F5", new TimesRoman()); + fontInfo.addMetrics("F6", new TimesItalic()); + fontInfo.addMetrics("F7", new TimesBold()); + fontInfo.addMetrics("F8", new TimesBoldItalic()); + fontInfo.addMetrics("F9", new Courier()); + fontInfo.addMetrics("F10", new CourierOblique()); + fontInfo.addMetrics("F11", new CourierBold()); + fontInfo.addMetrics("F12", new CourierBoldOblique()); + fontInfo.addMetrics("F13", new Symbol()); + fontInfo.addMetrics("F14", new ZapfDingbats()); + fontInfo.addMetrics("F15", new URWPalladioLRoma()); +// fontInfo.addMetrics("F15", new OMEP()); +// fontInfo.addMetrics("F16", new GaramondLightCondensed()); +// fontInfo.addMetrics("F17", new BauerBodoniBoldItalic()); - /* for compatibility with PassiveTex */ - fontInfo.addFontProperties("F5", "Times-Roman", "normal", - "normal"); - fontInfo.addFontProperties("F6", "Times-Roman", "oblique", - "normal"); - fontInfo.addFontProperties("F6", "Times-Roman", "italic", - "normal"); - fontInfo.addFontProperties("F7", "Times-Roman", "normal", - "bold"); - fontInfo.addFontProperties("F8", "Times-Roman", "oblique", - "bold"); - fontInfo.addFontProperties("F8", "Times-Roman", "italic", - "bold"); - fontInfo.addFontProperties("F5", "Times Roman", "normal", - "normal"); - fontInfo.addFontProperties("F6", "Times Roman", "oblique", - "normal"); - fontInfo.addFontProperties("F6", "Times Roman", "italic", - "normal"); - fontInfo.addFontProperties("F7", "Times Roman", "normal", - "bold"); - fontInfo.addFontProperties("F8", "Times Roman", "oblique", - "bold"); - fontInfo.addFontProperties("F8", "Times Roman", "italic", - "bold"); - fontInfo.addFontProperties("F9", "Computer-Modern-Typewriter", - "normal", "normal"); + /* any is treated as serif */ + fontInfo.addFontProperties("F5", "any", "normal", "normal"); + fontInfo.addFontProperties("F6", "any", "italic", "normal"); + fontInfo.addFontProperties("F6", "any", "oblique", "normal"); + fontInfo.addFontProperties("F7", "any", "normal", "bold"); + fontInfo.addFontProperties("F8", "any", "italic", "bold"); + fontInfo.addFontProperties("F8", "any", "oblique", "bold"); + + fontInfo.addFontProperties("F1", "sans-serif", "normal", + "normal"); + fontInfo.addFontProperties("F2", "sans-serif", "oblique", + "normal"); + fontInfo.addFontProperties("F2", "sans-serif", "italic", + "normal"); + fontInfo.addFontProperties("F3", "sans-serif", "normal", + "bold"); + fontInfo.addFontProperties("F4", "sans-serif", "oblique", + "bold"); + fontInfo.addFontProperties("F4", "sans-serif", "italic", + "bold"); + fontInfo.addFontProperties("F5", "serif", "normal", "normal"); + fontInfo.addFontProperties("F6", "serif", "oblique", + "normal"); + fontInfo.addFontProperties("F6", "serif", "italic", "normal"); + fontInfo.addFontProperties("F7", "serif", "normal", "bold"); + fontInfo.addFontProperties("F8", "serif", "oblique", "bold"); + fontInfo.addFontProperties("F8", "serif", "italic", "bold"); + fontInfo.addFontProperties("F9", "monospace", "normal", + "normal"); + fontInfo.addFontProperties("F10", "monospace", "oblique", + "normal"); + fontInfo.addFontProperties("F10", "monospace", "italic", + "normal"); + fontInfo.addFontProperties("F11", "monospace", "normal", + "bold"); + fontInfo.addFontProperties("F12", "monospace", "oblique", + "bold"); + fontInfo.addFontProperties("F12", "monospace", "italic", + "bold"); + + fontInfo.addFontProperties("F1", "Helvetica", "normal", + "normal"); + fontInfo.addFontProperties("F2", "Helvetica", "oblique", + "normal"); + fontInfo.addFontProperties("F2", "Helvetica", "italic", + "normal"); + fontInfo.addFontProperties("F3", "Helvetica", "normal", + "bold"); + fontInfo.addFontProperties("F4", "Helvetica", "oblique", + "bold"); + fontInfo.addFontProperties("F4", "Helvetica", "italic", + "bold"); + fontInfo.addFontProperties("F5", "Times", "normal", "normal"); + fontInfo.addFontProperties("F6", "Times", "oblique", + "normal"); + fontInfo.addFontProperties("F6", "Times", "italic", "normal"); + fontInfo.addFontProperties("F7", "Times", "normal", "bold"); + fontInfo.addFontProperties("F8", "Times", "oblique", "bold"); + fontInfo.addFontProperties("F8", "Times", "italic", "bold"); + fontInfo.addFontProperties("F9", "Courier", "normal", + "normal"); + fontInfo.addFontProperties("F10", "Courier", "oblique", + "normal"); + fontInfo.addFontProperties("F10", "Courier", "italic", + "normal"); + fontInfo.addFontProperties("F11", "Courier", "normal", + "bold"); + fontInfo.addFontProperties("F12", "Courier", "oblique", + "bold"); + fontInfo.addFontProperties("F12", "Courier", "italic", + "bold"); + fontInfo.addFontProperties("F13", "Symbol", "normal", + "normal"); + fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", + "normal"); + + fontInfo.addFontProperties("F15", "URWPalladioLRoma", "normal", "normal"); + //Custom type 1 fonts +// fontInfo.addFontProperties("F15", "OMEP", "normal", "normal"); +// fontInfo.addFontProperties("F16", "Garamond-LightCondensed", "normal", "normal"); +// fontInfo.addFontProperties("F17", "BauerBodoni", "italic", "bold"); + + /* for compatibility with PassiveTex */ + fontInfo.addFontProperties("F5", "Times-Roman", "normal", + "normal"); + fontInfo.addFontProperties("F6", "Times-Roman", "oblique", + "normal"); + fontInfo.addFontProperties("F6", "Times-Roman", "italic", + "normal"); + fontInfo.addFontProperties("F7", "Times-Roman", "normal", + "bold"); + fontInfo.addFontProperties("F8", "Times-Roman", "oblique", + "bold"); + fontInfo.addFontProperties("F8", "Times-Roman", "italic", + "bold"); + fontInfo.addFontProperties("F5", "Times Roman", "normal", + "normal"); + fontInfo.addFontProperties("F6", "Times Roman", "oblique", + "normal"); + fontInfo.addFontProperties("F6", "Times Roman", "italic", + "normal"); + fontInfo.addFontProperties("F7", "Times Roman", "normal", + "bold"); + fontInfo.addFontProperties("F8", "Times Roman", "oblique", + "bold"); + fontInfo.addFontProperties("F8", "Times Roman", "italic", + "bold"); + fontInfo.addFontProperties("F9", "Computer-Modern-Typewriter", + "normal", "normal"); } /** @@ -207,18 +218,23 @@ public class FontSetup { * @param fontInfo font info object to get font information from */ public static void addToResources(PDFDocument doc, FontInfo fontInfo) { - Hashtable fonts = fontInfo.getFonts(); - Enumeration e = fonts.keys(); - PDFResources resources = doc.getResources(); - while (e.hasMoreElements()) { - String f = (String) e.nextElement(); - resources.addFont(doc.makeFont(f, - ((Font) - fonts.get(f)).fontName(), - ((Font) - fonts.get(f)).encoding() - ) - ); - } + Hashtable fonts = fontInfo.getFonts(); + Enumeration e = fonts.keys(); + PDFResources resources = doc.getResources(); + while (e.hasMoreElements()) { + String f = (String) e.nextElement(); + Font font = (Font)fonts.get(f); + FontDescriptor desc = null; + if (font instanceof FontDescriptor) { + desc = (FontDescriptor)font; + } + resources.addFont(doc.makeFont(f, + font.fontName(), + font.encoding(), + font, + desc + ) + ); + } } } -- 2.39.5