* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
- *
+ *
* Copyright (C) 1999-2003 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
* (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 <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
- */
+ */
package org.apache.fop.pdf;
// Java
public class PDFFactory {
private PDFDocument document;
-
+
/**
* Creates a new PDFFactory.
* @param document the parent PDFDocument needed to register the generated
}
/* ========================= structure objects ========================= */
-
+
/**
* Make a /Catalog (Root) object. This object is written in
* the trailer.
/**
* Make a /Page object. The page is assigned an object number immediately
- * so references can already be made. The page must be added to the
+ * so references can already be made. The page must be added to the
* PDFDocument later using addObject().
*
* @param resources resources object to use
}
/* ========================= functions ================================= */
-
+
/**
* Make a Type 0 sampled function
*
* @param theXUID optional:the extended unique Identifier if used.
* @param theExtGState optional: the extended graphics state, if used.
* @param theMatrix Optional:List of Doubles that specify the matrix.
- * @return the PDF pattern that was created
+ * @return the PDF pattern that was created
*/
public PDFPattern makePattern(PDFResourceContext res,
int thePatternType, PDFShading theShading,
/**
* Make a gradient
- *
+ *
* @param res the PDF resource context to add the shading, may be null
* @param radial if true a radial gradient will be created
* @param theColorspace the colorspace of the gradient
getDocument().getColorSpace());
}
- if (getDocument().getColorSpace()
+ if (getDocument().getColorSpace()
!= nextColor.getColorSpace()) {
nextColor.setColorSpace(
getDocument().getColorSpace());
if (radial) {
if (theCoords.size() == 6) {
- myShad = makeShading(res, 3, getDocument().getPDFColorSpace(),
+ myShad = makeShading(res, 3, getDocument().getPDFColorSpace(),
null, null,
false, theCoords, null, myfunky,
null);
newCoords.add(theCoords.get(1));
newCoords.add(new Double(0.0));
- myShad = makeShading(res, 3, getDocument().getPDFColorSpace(),
+ myShad = makeShading(res, 3, getDocument().getPDFColorSpace(),
null, null,
false, newCoords, null, myfunky,
null);
}
} else {
- myShad = makeShading(res, 2, getDocument().getPDFColorSpace(),
- null, null,
- false, theCoords, null, myfunky,
+ myShad = makeShading(res, 2, getDocument().getPDFColorSpace(),
+ null, null,
+ false, theCoords, null, myfunky,
null);
}
goToReference = gt.referencePDF();
return goToReference;
}
-
+
/**
* Create and return a goto pdf document action.
* This creates a pdf files spec and pdf goto remote action.
return obj;
}
-
+
/* ========================= fonts ===================================== */
*/
public PDFEncoding makeEncoding(String encodingName) {
PDFEncoding encoding = new PDFEncoding(encodingName);
-
+
getDocument().registerObject(encoding);
return encoding;
}
new PDFCIDFont(basefont,
cidMetrics.getCIDType(),
cidMetrics.getDefaultWidth(),
- cidMetrics.getSubsetWidths(), sysInfo,
+ getSubsetWidths(cidMetrics), sysInfo,
(PDFCIDFontDescriptor)pdfdesc);
getDocument().registerObject(cidFont);
}
}
+ public PDFWArray getSubsetWidths(CIDFont cidFont) {
+ // Create widths for reencoded chars
+ PDFWArray warray = new PDFWArray();
+ int[] tmpWidth = new int[cidFont.usedGlyphsCount];
+
+ for (int i = 0; i < cidFont.usedGlyphsCount; i++) {
+ Integer nw = (Integer)cidFont.usedGlyphsIndex.get(new Integer(i));
+ int nwx = (nw == null) ? 0 : nw.intValue();
+ tmpWidth[i] = cidFont.width[nwx];
+ }
+ warray.addEntry(0, tmpWidth);
+ return warray;
+ }
/**
* make a /FontDescriptor object
if (desc.getFontType() == FontType.OTHER) {
throw new IllegalArgumentException("Trying to embed unsupported font type: "
+ desc.getFontType());
- }
-
+ }
+
Typeface tempFont;
if (desc instanceof LazyFont) {
tempFont = ((LazyFont)desc).getRealFont();
+ desc.getClass().getName());
}
CustomFont font = (CustomFont)tempFont;
-
+
InputStream in = null;
try {
// Get file first
in = getDocument().resolveURI(font.getEmbedFileName());
} catch (Exception e) {
getDocument().getLogger().error("Failed to embed fontfile: "
- + font.getEmbedFileName()
+ + font.getEmbedFileName()
+ "(" + e.getMessage() + ")");
}
}
-
+
// Get resource
if (in == null && font.getEmbedResourceName() != null) {
try {
+ "(" + e.getMessage() + ")");
}
}
-
+
if (in == null) {
return null;
} else {
TTFSubSetFile subset = new TTFSubSetFile();
ContainerUtil.enableLogging(subset,
getDocument().getLogger().getChildLogger("fonts"));
-
+
byte[] subsetFont = subset.readFont(reader,
mbfont.getTTCName(), mbfont.getUsedGlyphs());
// Only TrueType CID fonts are supported now
embeddedFont = new PDFTTFStream(file.length);
((PDFTTFStream)embeddedFont).setData(file, file.length);
}
-
+
/*
embeddedFont.getFilterList().addFilter("flate");
if (getDocument().isEncryptionActive()) {
} else {
embeddedFont.getFilterList().addFilter("ascii-85");
}*/
-
+
return embeddedFont;
} finally {
in.close();
*/
public PDFStream makeStream(String type, boolean add) {
- // create a PDFStream with the next object number
+ // create a PDFStream with the next object number
// and add it to the list of objects
PDFStream obj = new PDFStream();
obj.setDocument(getDocument());
obj.getFilterList().addDefaultFilters(
- getDocument().getFilterMap(),
+ getDocument().getFilterMap(),
type);
if (add) {
public PDFICCStream makePDFICCStream() {
PDFICCStream iccStream = new PDFICCStream();
iccStream.getFilterList().addDefaultFilters(
- getDocument().getFilterMap(),
+ getDocument().getFilterMap(),
PDFFilterList.CONTENT_FILTER);
-
+
getDocument().registerObject(iccStream);
//getDocument().applyEncryption(iccStream);
return iccStream;
*/
public PDFArray makeArray(int[] values) {
PDFArray array = new PDFArray(values);
-
+
getDocument().registerObject(array);
return array;
}
wanted.addValues(PDFGState.DEFAULT);
wanted.addValues(settings);
-
+
PDFGState existing = getDocument().findGState(wanted, current);
if (existing != null) {
return existing;