diff options
Diffstat (limited to 'src/java/org/apache/fop/pdf')
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFAMode.java | 10 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFDocument.java | 19 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFEncryptionParams.java | 13 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFFactory.java | 105 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFXMode.java | 8 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/StreamCacheFactory.java | 62 |
6 files changed, 62 insertions, 155 deletions
diff --git a/src/java/org/apache/fop/pdf/PDFAMode.java b/src/java/org/apache/fop/pdf/PDFAMode.java index b5b764dd4..899f9aa7d 100644 --- a/src/java/org/apache/fop/pdf/PDFAMode.java +++ b/src/java/org/apache/fop/pdf/PDFAMode.java @@ -20,14 +20,14 @@ package org.apache.fop.pdf; /** Enum class for PDF/A modes. */ -public final class PDFAMode { +public enum PDFAMode { /** PDF/A disabled */ - public static final PDFAMode DISABLED = new PDFAMode("PDF/A disabled"); + DISABLED("PDF/A disabled"), /** PDF/A-1a enabled */ - public static final PDFAMode PDFA_1A = new PDFAMode("PDF/A-1a"); + PDFA_1A("PDF/A-1a"), /** PDF/A-1b enabled */ - public static final PDFAMode PDFA_1B = new PDFAMode("PDF/A-1b"); + PDFA_1B("PDF/A-1b"); private String name; @@ -66,7 +66,7 @@ public final class PDFAMode { * @param s the string * @return the PDFAMode enum object (DISABLED will be returned if no match is found) */ - public static PDFAMode valueOf(String s) { + public static PDFAMode getValueOf(String s) { if (PDFA_1A.getName().equalsIgnoreCase(s)) { return PDFA_1A; } else if (PDFA_1B.getName().equalsIgnoreCase(s)) { diff --git a/src/java/org/apache/fop/pdf/PDFDocument.java b/src/java/org/apache/fop/pdf/PDFDocument.java index 9850c605e..dad404d11 100644 --- a/src/java/org/apache/fop/pdf/PDFDocument.java +++ b/src/java/org/apache/fop/pdf/PDFDocument.java @@ -21,7 +21,6 @@ package org.apache.fop.pdf; // Java import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.security.NoSuchAlgorithmException; @@ -719,24 +718,6 @@ public class PDFDocument { } /** - * Resolve a URI. - * - * @param uri the uri to resolve - * @throws java.io.FileNotFoundException if the URI could not be resolved - * @return the InputStream from the URI. - */ - protected InputStream resolveURI(String uri) - throws java.io.FileNotFoundException { - try { - /* TODO: Temporary hack to compile, improve later */ - return new java.net.URL(uri).openStream(); - } catch (Exception e) { - throw new java.io.FileNotFoundException( - "URI could not be resolved (" + e.getMessage() + "): " + uri); - } - } - - /** * Get an image from the image map. * * @param key the image key to look for diff --git a/src/java/org/apache/fop/pdf/PDFEncryptionParams.java b/src/java/org/apache/fop/pdf/PDFEncryptionParams.java index 71dccd867..563c05233 100644 --- a/src/java/org/apache/fop/pdf/PDFEncryptionParams.java +++ b/src/java/org/apache/fop/pdf/PDFEncryptionParams.java @@ -273,4 +273,17 @@ public class PDFEncryptionParams { this.encryptionLengthInBits = encryptionLength; } + public String toString() { + return "userPassword = " + userPassword + "\n" + + "ownerPassword = " + ownerPassword + "\n" + + "allowPrint = " + allowPrint + "\n" + + "allowCopyContent = " + allowCopyContent + "\n" + + "allowEditContent = " + allowEditContent + "\n" + + "allowEditAnnotations = " + allowEditAnnotations + "\n" + + "allowFillInForms = " + allowFillInForms + "\n" + + "allowAccessContent = " + allowAccessContent + "\n" + + "allowAssembleDocument = " + allowAssembleDocument + "\n" + + "allowPrintHq = " + allowPrintHq; + } + } diff --git a/src/java/org/apache/fop/pdf/PDFFactory.java b/src/java/org/apache/fop/pdf/PDFFactory.java index beb384dcf..f6e9e255d 100644 --- a/src/java/org/apache/fop/pdf/PDFFactory.java +++ b/src/java/org/apache/fop/pdf/PDFFactory.java @@ -23,10 +23,8 @@ package org.apache.fop.pdf; import java.awt.Color; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.net.MalformedURLException; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; @@ -35,9 +33,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import javax.xml.transform.Source; -import javax.xml.transform.stream.StreamSource; - import org.apache.commons.io.IOUtils; import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.commons.logging.Log; @@ -45,7 +40,6 @@ import org.apache.commons.logging.LogFactory; import org.apache.xmlgraphics.java2d.color.ColorUtil; import org.apache.xmlgraphics.java2d.color.NamedColorSpace; - import org.apache.xmlgraphics.xmp.Metadata; import org.apache.fop.fonts.CIDFont; @@ -1637,79 +1631,48 @@ public class PDFFactory { InputStream in = null; try { - Source source = font.getEmbedFileSource(); - if (source == null && font.getEmbedResourceName() != null) { - source = new StreamSource(this.getClass() - .getResourceAsStream(font.getEmbedResourceName())); - } - if (source == null) { - return null; - } - if (source instanceof StreamSource) { - in = ((StreamSource) source).getInputStream(); - } - if (in == null && source.getSystemId() != null) { - try { - in = new java.net.URL(source.getSystemId()).openStream(); - } catch (MalformedURLException e) { - //TODO: Why construct a new exception here, when it is not thrown? - new FileNotFoundException( - "File not found. URL could not be resolved: " - + e.getMessage()); - } - } - if (in == null) { - return null; - } - //Make sure the InputStream is decorated with a BufferedInputStream - if (!(in instanceof java.io.BufferedInputStream)) { - in = new java.io.BufferedInputStream(in); - } + in = font.getInputStream(); if (in == null) { return null; } else { - try { - AbstractPDFStream embeddedFont; - if (desc.getFontType() == FontType.TYPE0) { - MultiByteFont mbfont = (MultiByteFont)font; - FontFileReader reader = new FontFileReader(in); - - TTFSubSetFile subset = new TTFSubSetFile(); - subset.readFont(reader, mbfont.getTTCName(), mbfont.getUsedGlyphs()); - byte[] subsetFont = subset.getFontSubset(); - // Only TrueType CID fonts are supported now - - embeddedFont = new PDFTTFStream(subsetFont.length); - ((PDFTTFStream)embeddedFont).setData(subsetFont, subsetFont.length); - } else if (desc.getFontType() == FontType.TYPE1) { - PFBParser parser = new PFBParser(); - PFBData pfb = parser.parsePFB(in); - embeddedFont = new PDFT1Stream(); - ((PDFT1Stream)embeddedFont).setData(pfb); - } else { - byte[] file = IOUtils.toByteArray(in); - embeddedFont = new PDFTTFStream(file.length); - ((PDFTTFStream)embeddedFont).setData(file, file.length); - } + AbstractPDFStream embeddedFont; + if (desc.getFontType() == FontType.TYPE0) { + MultiByteFont mbfont = (MultiByteFont) font; + FontFileReader reader = new FontFileReader(in); + + TTFSubSetFile subset = new TTFSubSetFile(); + subset.readFont(reader, mbfont.getTTCName(), mbfont.getUsedGlyphs()); + byte[] subsetFont = subset.getFontSubset(); + // Only TrueType CID fonts are supported now + + embeddedFont = new PDFTTFStream(subsetFont.length); + ((PDFTTFStream) embeddedFont).setData(subsetFont, subsetFont.length); + } else if (desc.getFontType() == FontType.TYPE1) { + PFBParser parser = new PFBParser(); + PFBData pfb = parser.parsePFB(in); + embeddedFont = new PDFT1Stream(); + ((PDFT1Stream) embeddedFont).setData(pfb); + } else { + byte[] file = IOUtils.toByteArray(in); + embeddedFont = new PDFTTFStream(file.length); + ((PDFTTFStream) embeddedFont).setData(file, file.length); + } - /* - embeddedFont.getFilterList().addFilter("flate"); - if (getDocument().isEncryptionActive()) { - getDocument().applyEncryption(embeddedFont); - } else { - embeddedFont.getFilterList().addFilter("ascii-85"); - }*/ + /* + embeddedFont.getFilterList().addFilter("flate"); + if (getDocument().isEncryptionActive()) { + getDocument().applyEncryption(embeddedFont); + } else { + embeddedFont.getFilterList().addFilter("ascii-85"); + }*/ - return embeddedFont; - } finally { - in.close(); - } + return embeddedFont; } } catch (IOException ioe) { - log.error( - "Failed to embed font [" + desc + "] " - + desc.getEmbedFontName(), ioe); + log.error("Failed to embed font [" + desc + "] " + desc.getEmbedFontName(), ioe); return null; + } finally { + IOUtils.closeQuietly(in); } } diff --git a/src/java/org/apache/fop/pdf/PDFXMode.java b/src/java/org/apache/fop/pdf/PDFXMode.java index 03813273b..be0312891 100644 --- a/src/java/org/apache/fop/pdf/PDFXMode.java +++ b/src/java/org/apache/fop/pdf/PDFXMode.java @@ -20,12 +20,12 @@ package org.apache.fop.pdf; /** Enum class for PDF/X modes. */ -public final class PDFXMode { +public enum PDFXMode { /** PDF/X disabled */ - public static final PDFXMode DISABLED = new PDFXMode("PDF/X disabled"); + DISABLED("PDF/X disabled"), /** PDF/X-3:2003 enabled */ - public static final PDFXMode PDFX_3_2003 = new PDFXMode("PDF/X-3:2003"); + PDFX_3_2003("PDF/X-3:2003"); private String name; @@ -47,7 +47,7 @@ public final class PDFXMode { * @param s the string * @return the PDFAMode enum object (DISABLED will be returned if no match is found) */ - public static PDFXMode valueOf(String s) { + public static PDFXMode getValueOf(String s) { if (PDFX_3_2003.getName().equalsIgnoreCase(s)) { return PDFX_3_2003; } else { diff --git a/src/java/org/apache/fop/pdf/StreamCacheFactory.java b/src/java/org/apache/fop/pdf/StreamCacheFactory.java index 4e2d12eb2..aa4d665da 100644 --- a/src/java/org/apache/fop/pdf/StreamCacheFactory.java +++ b/src/java/org/apache/fop/pdf/StreamCacheFactory.java @@ -24,56 +24,24 @@ import java.io.IOException; /** * This class is serves as a factory from */ -public class StreamCacheFactory { +public final class StreamCacheFactory { - private static boolean defaultCacheToFile = false; - private static StreamCacheFactory fileInstance = null; - private static StreamCacheFactory memoryInstance = null; - - private boolean cacheToFile = false; + private static StreamCacheFactory memoryInstance = new StreamCacheFactory(); /** * Returns an instance of a StreamCacheFactory with the requested features. * @param cacheToFile True if file shall be cached using a temporary file * @return StreamCacheFactory the requested factory */ - public static StreamCacheFactory getInstance(boolean cacheToFile) { - if (cacheToFile) { - if (fileInstance == null) { - fileInstance = new StreamCacheFactory(true); - } - return fileInstance; - } else { - if (memoryInstance == null) { - memoryInstance = new StreamCacheFactory(false); - } - return memoryInstance; - } - } - - /** - * Returns an instance of a StreamCacheFactory depending on the default - * setting for cacheToFile. - * @return StreamCacheFactory the requested factory - */ public static StreamCacheFactory getInstance() { - return getInstance(defaultCacheToFile); - } - - /** - * Sets the global default for cacheToFile - * @param cacheToFile True if stream caches should be held in files. - */ - public static void setDefaultCacheToFile(boolean cacheToFile) { - defaultCacheToFile = cacheToFile; + return memoryInstance; } /** * Creates a new StreamCacheFactory. * @param cacheToFile True if file shall be cached using a temporary file */ - public StreamCacheFactory(boolean cacheToFile) { - this.cacheToFile = cacheToFile; + private StreamCacheFactory() { } /** @@ -83,11 +51,7 @@ public class StreamCacheFactory { * @return a new StreamCache for caching streams */ public StreamCache createStreamCache() throws IOException { - if (this.cacheToFile) { - return new TempFileStreamCache(); - } else { - return new InMemoryStreamCache(); - } + return new InMemoryStreamCache(); } /** @@ -98,20 +62,6 @@ public class StreamCacheFactory { * @return a new StreamCache for caching streams */ public StreamCache createStreamCache(int hintSize) throws IOException { - if (this.cacheToFile) { - return new TempFileStreamCache(); - } else { - return new InMemoryStreamCache(hintSize); - } - } - - /** - * Get the value of the global cacheToFile flag. - * @return the current cache to file flag - */ - public boolean getCacheToFile() { - return this.cacheToFile; + return new InMemoryStreamCache(hintSize); } - - } |