git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_URI_Unification@1353992 13f79535-47bb-0310-9956-ffa450edef68pull/26/head
@@ -92,13 +92,10 @@ public final class AFPResourceUtil { | |||
throws UnsupportedEncodingException { | |||
//The first 8 bytes of the field data represent the resource name | |||
byte[] nameBytes = new byte[8]; | |||
byte[] fieldData = field.getData(); | |||
if (fieldData.length < 8) { | |||
throw new IllegalArgumentException("Field data does not contain a resource name"); | |||
} | |||
System.arraycopy(fieldData, 0, nameBytes, 0, 8); | |||
return new String(nameBytes, AFPConstants.EBCIDIC_ENCODING); | |||
System.arraycopy(field.getData(), 0, nameBytes, 0, 8); | |||
String asciiName; | |||
asciiName = new String(nameBytes, AFPConstants.EBCIDIC_ENCODING); | |||
return asciiName; | |||
} | |||
/** | |||
@@ -131,13 +128,12 @@ public final class AFPResourceUtil { | |||
public static void copyNamedResource(String name, | |||
final InputStream in, final OutputStream out) throws IOException { | |||
final MODCAParser parser = new MODCAParser(in); | |||
Collection<String> resourceNames = new java.util.HashSet<String>(); | |||
Collection resourceNames = new java.util.HashSet(); | |||
//Find matching "Begin" field | |||
final UnparsedStructuredField fieldBegin; | |||
while (true) { | |||
final UnparsedStructuredField field = parser.readNextStructuredField(); | |||
UnparsedStructuredField field = parser.readNextStructuredField(); | |||
if (field == null) { | |||
throw new IOException("Requested resource '" + name | |||
+ "' not found. Encountered resource names: " + resourceNames); | |||
@@ -146,10 +142,8 @@ public final class AFPResourceUtil { | |||
if (field.getSfTypeCode() != TYPE_CODE_BEGIN) { //0xA8=Begin | |||
continue; //Not a "Begin" field | |||
} | |||
final String resourceName = getResourceName(field); | |||
String resourceName = getResourceName(field); | |||
resourceNames.add(resourceName); | |||
if (resourceName.equals(name)) { | |||
if (LOG.isDebugEnabled()) { | |||
LOG.debug("Start of requested structured field found:\n" | |||
@@ -176,35 +170,45 @@ public final class AFPResourceUtil { | |||
if (wrapInResource) { | |||
ResourceObject resourceObject = new ResourceObject(name) { | |||
protected void writeContent(OutputStream os) throws IOException { | |||
copyNamedStructuredFields(name, fieldBegin, parser, out); | |||
copyStructuredFields(name, fieldBegin, parser, out); | |||
} | |||
}; | |||
resourceObject.setType(ResourceObject.TYPE_PAGE_SEGMENT); | |||
resourceObject.writeToStream(out); | |||
} else { | |||
copyNamedStructuredFields(name, fieldBegin, parser, out); | |||
copyStructuredFields(name, fieldBegin, parser, out); | |||
} | |||
} | |||
private static void copyNamedStructuredFields(final String name, | |||
UnparsedStructuredField fieldBegin, MODCAParser parser, | |||
OutputStream out) throws IOException { | |||
private static void copyStructuredFields(String name, UnparsedStructuredField fieldBegin, | |||
MODCAParser parser, OutputStream out) throws IOException { | |||
boolean inRequestedResource; | |||
UnparsedStructuredField field = fieldBegin; | |||
//The "Begin" field first | |||
out.write(MODCAParser.CARRIAGE_CONTROL_CHAR); | |||
fieldBegin.writeTo(out); | |||
UnparsedStructuredField field; | |||
while (true) { | |||
//Then the rest of the fields until the corresponding "End" field | |||
inRequestedResource = true; | |||
do { | |||
field = parser.readNextStructuredField(); | |||
if (field == null) { | |||
throw new IOException("Ending structured field not found for resource " + name); | |||
break; //Unexpected EOF | |||
} | |||
out.write(MODCAParser.CARRIAGE_CONTROL_CHAR); | |||
field.writeTo(out); | |||
if (field.getSfTypeCode() == TYPE_CODE_END | |||
&& fieldBegin.getSfCategoryCode() == field.getSfCategoryCode() | |||
&& name.equals(getResourceName(field))) { | |||
break; | |||
if (field.getSfTypeCode() == TYPE_CODE_END) { | |||
String resourceName = getResourceName(field); | |||
if (resourceName.equals(name)) { | |||
inRequestedResource = false; //Signal end of loop | |||
} | |||
} | |||
field = parser.readNextStructuredField(); | |||
out.write(MODCAParser.CARRIAGE_CONTROL_CHAR); | |||
field.writeTo(out); | |||
} while (inRequestedResource); | |||
if (inRequestedResource) { | |||
throw new IOException("Ending structured field not found for resource " + name); | |||
} | |||
} | |||
} |
@@ -22,9 +22,27 @@ package org.apache.fop.apps.io; | |||
import java.io.IOException; | |||
import java.io.OutputStream; | |||
/** | |||
* Implementations of this interface resolve URIs for temporary files used by FOP. The temporary- | |||
* resource URI scheme comes from {@link TempResourceURIGenerator#TMP_SCHEMA}. | |||
*/ | |||
public interface TempResourceResolver { | |||
/** | |||
* Get a temporary-resource given the URI pointing to said resource. | |||
* | |||
* @param uri the resource URI | |||
* @return the resource | |||
* @throws IOException if an I/O error occured during resource acquisition | |||
*/ | |||
Resource getResource(String id) throws IOException; | |||
/** | |||
* Gets an temporary-output stream of a given URI. | |||
* | |||
* @param uri the output stream URI | |||
* @return the output stream | |||
* @throws IOException if an I/O error occured while creating an output stream | |||
*/ | |||
OutputStream getOutputStream(String id) throws IOException; | |||
} |
@@ -25,7 +25,7 @@ import java.util.concurrent.atomic.AtomicLong; | |||
*/ | |||
public final class TempResourceURIGenerator { | |||
private static final String TMP_SCHEMA = "tmp"; | |||
public static final String TMP_SCHEMA = "tmp"; | |||
private final String tempURIPrefix; | |||
@@ -52,13 +52,12 @@ import org.apache.fop.render.awt.AWTRenderer; | |||
import org.apache.fop.render.intermediate.IFContext; | |||
import org.apache.fop.render.intermediate.IFDocumentHandler; | |||
import org.apache.fop.render.intermediate.IFSerializer; | |||
import org.apache.fop.render.pdf.PDFEncryptionOption; | |||
import org.apache.fop.render.print.PagesMode; | |||
import org.apache.fop.render.print.PrintRenderer; | |||
import org.apache.fop.render.xml.XMLRenderer; | |||
import org.apache.fop.util.CommandLineLogger; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.ENCRYPTION_PARAMS; | |||
/** | |||
* Options parses the commandline arguments | |||
*/ | |||
@@ -822,14 +821,14 @@ public class CommandLineOptions { | |||
} | |||
private PDFEncryptionParams getPDFEncryptionParams() throws FOPException { | |||
PDFEncryptionParams params = (PDFEncryptionParams) renderingOptions.get(ENCRYPTION_PARAMS); | |||
PDFEncryptionParams params = (PDFEncryptionParams) renderingOptions.get(PDFEncryptionOption.ENCRYPTION_PARAMS); | |||
if (params == null) { | |||
if (!PDFEncryptionManager.checkAvailableAlgorithms()) { | |||
throw new FOPException("PDF encryption requested but it is not available." | |||
+ " Please make sure MD5 and RC4 algorithms are available."); | |||
} | |||
params = new PDFEncryptionParams(); | |||
renderingOptions.put(ENCRYPTION_PARAMS, params); | |||
renderingOptions.put(PDFEncryptionOption.ENCRYPTION_PARAMS, params); | |||
} | |||
return params; | |||
} |
@@ -64,8 +64,6 @@ public abstract class CustomFont extends Typeface | |||
private boolean useKerning = true; | |||
private boolean useAdvanced = true; | |||
/** the character map, mapping Unicode ranges to glyph indices. */ | |||
protected CMapSegment[] cmap; | |||
/** | |||
* @param resourceResolver the URI resource resolver for controlling file access | |||
@@ -73,6 +71,8 @@ public abstract class CustomFont extends Typeface | |||
public CustomFont(InternalResourceResolver resourceResolver) { | |||
this.resourceResolver = resourceResolver; | |||
} | |||
/** the character map, mapping Unicode ranges to glyph indices. */ | |||
protected CMapSegment[] cmap; | |||
/** {@inheritDoc} */ | |||
public String getFontName() { | |||
@@ -124,6 +124,7 @@ public abstract class CustomFont extends Typeface | |||
} | |||
/** | |||
* Returns the embedding mode for this font. | |||
* @return embedding mode | |||
*/ |
@@ -112,7 +112,7 @@ public final class DefaultFontConfig implements FontConfig { | |||
fontCfg.getAttribute("sub-font", null), fontCfg.getAttributeAsBoolean( | |||
"kerning", true), fontCfg.getAttributeAsBoolean("advanced", true), | |||
fontCfg.getAttribute("encoding-mode", EncodingMode.AUTO.getName()), | |||
fontCfg.getAttribute("embedding-mode", EmbeddingMode.AUTO.getName())); | |||
fontCfg.getAttribute("embedding-mode", EncodingMode.AUTO.getName())); | |||
instance.fonts.add(font); | |||
boolean hasTriplets = false; | |||
for (Configuration tripletCfg : fontCfg.getChildren("font-triplet")) { | |||
@@ -279,6 +279,10 @@ public final class DefaultFontConfig implements FontConfig { | |||
private final String embeddingMode; | |||
public String getEncodingMode() { | |||
return encodingMode; | |||
} | |||
private final List<FontTriplet> tripletList = new ArrayList<FontTriplet>(); | |||
public List<FontTriplet> getTripletList() { | |||
@@ -332,10 +336,6 @@ public final class DefaultFontConfig implements FontConfig { | |||
return subFont; | |||
} | |||
public String getEncodingMode() { | |||
return encodingMode; | |||
} | |||
public String getEmbeddingMode() { | |||
return embeddingMode; | |||
} |
@@ -42,6 +42,7 @@ public class EmbedFontInfo implements Serializable { | |||
protected final boolean advanced; | |||
/** the requested encoding mode for the font */ | |||
private final EncodingMode encodingMode; | |||
/** the requested embedding mode for this font */ | |||
private final EmbeddingMode embeddingMode; | |||
/** the PostScript name of the font */ | |||
@@ -63,7 +64,6 @@ public class EmbedFontInfo implements Serializable { | |||
* @param embedURI Path to the embeddable font file (may be null) | |||
* @param subFontName the sub-fontname used for TrueType Collections (null otherwise) | |||
* @param encodingMode the encoding mode to use for this font | |||
* @param embeddingMode the embedding mode for this font | |||
*/ | |||
public EmbedFontInfo(URI metricsURI, boolean kerning, boolean advanced, | |||
List<FontTriplet> fontTriplets, URI embedURI, String subFontName, |
@@ -233,6 +233,16 @@ public class FontManager { | |||
} | |||
} | |||
/** | |||
* Detect fonts from the operating system via FOPs autodetect mechanism. | |||
* | |||
* @param autoDetectFonts if autodetect has been enabled | |||
* @param fontAdder the font adding mechanism | |||
* @param strict whether to enforce strict validation | |||
* @param listener the listener for font related events | |||
* @param fontInfoList a list of font info objects | |||
* @throws FOPException if an exception was thrown auto-detecting fonts | |||
*/ | |||
public void autoDetectFonts(boolean autoDetectFonts, FontAdder fontAdder, boolean strict, | |||
FontEventListener listener, List<EmbedFontInfo> fontInfoList) throws FOPException { | |||
if (autoDetectFonts) { |
@@ -153,7 +153,6 @@ public class FontReader extends DefaultHandler { | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
@Override | |||
public void startElement(String uri, String localName, String qName, Attributes attributes) | |||
throws SAXException { | |||
if (localName.equals("font-metrics")) { |
@@ -46,9 +46,9 @@ public class LazyFont extends Typeface implements FontDescriptor, Substitutable, | |||
private final boolean useKerning; | |||
private final boolean useAdvanced; | |||
private final EncodingMode encodingMode; | |||
private final EmbeddingMode embeddingMode; | |||
private final boolean embedded; | |||
private EmbeddingMode embeddingMode; | |||
private final String subFontName; | |||
private final boolean embedded; | |||
private final InternalResourceResolver resourceResolver; | |||
private boolean isMetricsLoaded; | |||
@@ -70,8 +70,10 @@ public class LazyFont extends Typeface implements FontDescriptor, Substitutable, | |||
} else { | |||
this.useAdvanced = fontInfo.getAdvanced(); | |||
} | |||
this.encodingMode = fontInfo.getEncodingMode(); | |||
this.embeddingMode = fontInfo.getEmbeddingMode(); | |||
this.encodingMode = fontInfo.getEncodingMode() != null ? fontInfo.getEncodingMode() | |||
: EncodingMode.AUTO; | |||
this.embeddingMode = fontInfo.getEmbeddingMode() != null ? fontInfo.getEmbeddingMode() | |||
: EmbeddingMode.AUTO; | |||
this.subFontName = fontInfo.getSubFontName(); | |||
this.embedded = fontInfo.isEmbedded(); | |||
this.resourceResolver = resourceResolver; |
@@ -67,7 +67,7 @@ public class MultiByteFont extends CIDFont implements Substitutable, Positionabl | |||
private int lastUnmapped; | |||
/** | |||
* @param resourceResolver the resource resolver for accessing the font | |||
* Default constructor | |||
*/ | |||
public MultiByteFont(InternalResourceResolver resourceResolver) { | |||
super(resourceResolver); |
@@ -221,7 +221,8 @@ public class FontInfoFinder { | |||
} | |||
try { | |||
TTFFontLoader ttfLoader = new TTFFontLoader(fontURI, fontName, true, | |||
EmbeddingMode.AUTO, EncodingMode.AUTO, useKerning, useAdvanced, resourceResolver); | |||
EmbeddingMode.AUTO, EncodingMode.AUTO, useKerning, useAdvanced, | |||
resourceResolver); | |||
customFont = ttfLoader.getFont(); | |||
if (this.eventListener != null) { | |||
customFont.setEventListener(this.eventListener); |
@@ -124,9 +124,9 @@ public class FontFileReader { | |||
final byte buf = read(); | |||
if (buf < 0) { | |||
return (int)(256 + buf); | |||
return (256 + buf); | |||
} else { | |||
return (int)buf; | |||
return buf; | |||
} | |||
} | |||
@@ -150,7 +150,7 @@ public class FontFileReader { | |||
*/ | |||
public final int readTTFUShort() throws IOException { | |||
final int ret = (readTTFUByte() << 8) + readTTFUByte(); | |||
return (int)ret; | |||
return ret; | |||
} | |||
/** |
@@ -0,0 +1,118 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
/* $Id$ */ | |||
package org.apache.fop.fonts.truetype; | |||
/** | |||
* The CMap entry contains information of a Unicode range and the | |||
* the glyph indexes related to the range | |||
*/ | |||
public class TTFCmapEntry { | |||
private int unicodeStart; | |||
private int unicodeEnd; | |||
private int glyphStartIndex; | |||
TTFCmapEntry() { | |||
unicodeStart = 0; | |||
unicodeEnd = 0; | |||
glyphStartIndex = 0; | |||
} | |||
TTFCmapEntry(int unicodeStart, int unicodeEnd, int glyphStartIndex) { | |||
this.unicodeStart = unicodeStart; | |||
this.unicodeEnd = unicodeEnd; | |||
this.glyphStartIndex = glyphStartIndex; | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public int hashCode() { | |||
int hc = super.hashCode(); | |||
hc ^= ( hc * 11 ) + unicodeStart; | |||
hc ^= ( hc * 19 ) + unicodeEnd; | |||
hc ^= ( hc * 23 ) + glyphStartIndex; | |||
return hc; | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public boolean equals(Object o) { | |||
if (o instanceof TTFCmapEntry) { | |||
TTFCmapEntry ce = (TTFCmapEntry)o; | |||
if (ce.unicodeStart == this.unicodeStart | |||
&& ce.unicodeEnd == this.unicodeEnd | |||
&& ce.glyphStartIndex == this.glyphStartIndex) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
/** | |||
* Returns the glyphStartIndex. | |||
* @return int | |||
*/ | |||
public int getGlyphStartIndex() { | |||
return glyphStartIndex; | |||
} | |||
/** | |||
* Returns the unicodeEnd. | |||
* @return int | |||
*/ | |||
public int getUnicodeEnd() { | |||
return unicodeEnd; | |||
} | |||
/** | |||
* Returns the unicodeStart. | |||
* @return int | |||
*/ | |||
public int getUnicodeStart() { | |||
return unicodeStart; | |||
} | |||
/** | |||
* Sets the glyphStartIndex. | |||
* @param glyphStartIndex The glyphStartIndex to set | |||
*/ | |||
public void setGlyphStartIndex(int glyphStartIndex) { | |||
this.glyphStartIndex = glyphStartIndex; | |||
} | |||
/** | |||
* Sets the unicodeEnd. | |||
* @param unicodeEnd The unicodeEnd to set | |||
*/ | |||
public void setUnicodeEnd(int unicodeEnd) { | |||
this.unicodeEnd = unicodeEnd; | |||
} | |||
/** | |||
* Sets the unicodeStart. | |||
* @param unicodeStart The unicodeStart to set | |||
*/ | |||
public void setUnicodeStart(int unicodeStart) { | |||
this.unicodeStart = unicodeStart; | |||
} | |||
} |
@@ -2018,9 +2018,9 @@ public class TTFFile { | |||
try { | |||
boolean useKerning = true; | |||
boolean useAdvanced = true; | |||
stream = new FileInputStream(args[0]); | |||
TTFFile ttfFile = new TTFFile(useKerning, useAdvanced); | |||
stream = new FileInputStream(args[0]); | |||
FontFileReader reader = new FontFileReader(stream); | |||
String name = null; | |||
@@ -2037,6 +2037,5 @@ public class TTFFile { | |||
} finally { | |||
IOUtils.closeQuietly(stream); | |||
} | |||
} | |||
} |
@@ -72,10 +72,10 @@ public class TTFFontLoader extends FontLoader { | |||
* @param useAdvanced true to enable loading advanced info if available, false to disable | |||
* @param resolver the FontResolver for font URI resolution | |||
*/ | |||
public TTFFontLoader(URI fontFileURI, String subFontName, | |||
boolean embedded, EmbeddingMode embeddingMode, EncodingMode encodingMode, | |||
boolean useKerning, boolean useAdvanced, InternalResourceResolver resourceResolver) { | |||
super(fontFileURI, embedded, useKerning, useAdvanced, resourceResolver); | |||
public TTFFontLoader(URI fontFileURI, String subFontName, boolean embedded, | |||
EmbeddingMode embeddingMode, EncodingMode encodingMode, boolean useKerning, | |||
boolean useAdvanced, InternalResourceResolver resolver) { | |||
super(fontFileURI, embedded, useKerning, useAdvanced, resolver); | |||
this.subFontName = subFontName; | |||
this.encodingMode = encodingMode; | |||
this.embeddingMode = embeddingMode; |
@@ -29,6 +29,8 @@ import java.util.List; | |||
import java.util.Set; | |||
import org.apache.commons.io.IOUtils; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogFactory; | |||
import org.apache.fop.apps.io.InternalResourceResolver; | |||
import org.apache.fop.fonts.CodePointMapping; | |||
@@ -42,6 +44,8 @@ import org.apache.fop.fonts.SingleByteFont; | |||
*/ | |||
public class Type1FontLoader extends FontLoader { | |||
private static final Log log = LogFactory.getLog(Type1FontLoader.class); | |||
private SingleByteFont singleFont; | |||
/** |
@@ -40,6 +40,7 @@ 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; |
@@ -74,14 +74,35 @@ public abstract class PrintRendererConfigurator extends AbstractRendererConfigur | |||
this.fontInfoConfigurator = fontInfoConfigurator; | |||
} | |||
/** | |||
* Returns the renderer configuration data for a specific renderer. | |||
* | |||
* @param documentHandler the document handler | |||
* @return the renderer configuration data | |||
* @throws FOPException if an error occurs | |||
*/ | |||
protected RendererConfig getRendererConfig(IFDocumentHandler documentHandler) throws FOPException { | |||
return getRendererConfig(documentHandler.getMimeType()); | |||
return getRendererConfig(documentHandler.getMimeType()); | |||
} | |||
/** | |||
* gets the renderer configuration data for a specific renderer. | |||
* | |||
* @param mimeType the MIME type | |||
* @return the renderer configuration data | |||
* @throws FOPException if an error occurs | |||
*/ | |||
protected RendererConfig getRendererConfig(String mimeType) throws FOPException { | |||
return userAgent.getRendererConfig(mimeType, rendererConfigParser); | |||
} | |||
/** | |||
* gets the renderer configuration data for a specific renderer. | |||
* | |||
* @param renderer the renderer | |||
* @return the renderer configuration data | |||
* @throws FOPException if an error occurs | |||
*/ | |||
protected RendererConfig getRendererConfig(Renderer renderer) throws FOPException { | |||
return getRendererConfig(renderer.getMimeType()); | |||
} | |||
@@ -114,6 +135,14 @@ public abstract class PrintRendererConfigurator extends AbstractRendererConfigur | |||
protected abstract List<FontCollection> getDefaultFontCollection(); | |||
/** | |||
* Returns the font collection for custom configured fonts. | |||
* | |||
* @param resolver the resource resolver | |||
* @param mimeType the renderer MIME type | |||
* @return the font collection | |||
* @throws FOPException if an error occurs | |||
*/ | |||
protected FontCollection getCustomFontCollection(InternalResourceResolver resolver, String mimeType) | |||
throws FOPException { | |||
List<EmbedFontInfo> fontList; | |||
@@ -125,6 +154,13 @@ public abstract class PrintRendererConfigurator extends AbstractRendererConfigur | |||
return createCollectionFromFontList(resolver, fontList); | |||
} | |||
/*** | |||
* Creates the font collection given a list of embedded font infomation. | |||
* | |||
* @param resolver the resource resolver | |||
* @param fontList the embedded font infomation | |||
* @return the font collection | |||
*/ | |||
protected FontCollection createCollectionFromFontList(InternalResourceResolver resolver, | |||
List<EmbedFontInfo> fontList) { | |||
return new CustomFontCollection(resolver, fontList, |
@@ -45,23 +45,23 @@ import org.apache.fop.util.LogUtil; | |||
import static org.apache.fop.render.afp.AFPRendererConfig.ImagesModeOptions.MODE_COLOR; | |||
import static org.apache.fop.render.afp.AFPRendererConfig.ImagesModeOptions.MODE_GRAYSCALE; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.DEFAULT_RESOURCE_LEVELS; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.GOCA; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.GOCA_TEXT; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.IMAGES; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.IMAGES_DITHERING_QUALITY; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.IMAGES_FS45; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.IMAGES_JPEG; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.IMAGES_MAPPING_OPTION; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.IMAGES_MODE; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.IMAGES_NATIVE; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.IMAGES_WRAP_PSEG; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.JPEG_ALLOW_JPEG_EMBEDDING; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.JPEG_BITMAP_ENCODING_QUALITY; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.LINE_WIDTH_CORRECTION; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.RENDERER_RESOLUTION; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.RESOURCE_GROUP_URI; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.SHADING; | |||
import static org.apache.fop.render.afp.AFPRendererOption.DEFAULT_RESOURCE_LEVELS; | |||
import static org.apache.fop.render.afp.AFPRendererOption.GOCA; | |||
import static org.apache.fop.render.afp.AFPRendererOption.GOCA_TEXT; | |||
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES; | |||
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_DITHERING_QUALITY; | |||
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_FS45; | |||
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_JPEG; | |||
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_MAPPING_OPTION; | |||
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_MODE; | |||
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_NATIVE; | |||
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_WRAP_PSEG; | |||
import static org.apache.fop.render.afp.AFPRendererOption.JPEG_ALLOW_JPEG_EMBEDDING; | |||
import static org.apache.fop.render.afp.AFPRendererOption.JPEG_BITMAP_ENCODING_QUALITY; | |||
import static org.apache.fop.render.afp.AFPRendererOption.LINE_WIDTH_CORRECTION; | |||
import static org.apache.fop.render.afp.AFPRendererOption.RENDERER_RESOLUTION; | |||
import static org.apache.fop.render.afp.AFPRendererOption.RESOURCE_GROUP_URI; | |||
import static org.apache.fop.render.afp.AFPRendererOption.SHADING; | |||
/** | |||
* The AFP renderer config object. | |||
@@ -103,7 +103,7 @@ public final class AFPRendererConfig implements RendererConfig { | |||
} | |||
} | |||
private final EnumMap<AFPRendererConfigOption, Object> params = new EnumMap<AFPRendererConfigOption, Object>(AFPRendererConfigOption.class); | |||
private final EnumMap<AFPRendererOption, Object> params = new EnumMap<AFPRendererOption, Object>(AFPRendererOption.class); | |||
private final EnumMap<ImagesModeOptions, Object> imageModeParams | |||
= new EnumMap<ImagesModeOptions, Object>(ImagesModeOptions.class); | |||
@@ -189,12 +189,12 @@ public final class AFPRendererConfig implements RendererConfig { | |||
return getParam(GOCA_TEXT, Boolean.class); | |||
} | |||
private <T> T getParam(AFPRendererConfigOption options, Class<T> type) { | |||
private <T> T getParam(AFPRendererOption options, Class<T> type) { | |||
assert options.getType().equals(type); | |||
return type.cast(params.get(options)); | |||
} | |||
private <T> void setParam(AFPRendererConfigOption option, T value) { | |||
private <T> void setParam(AFPRendererOption option, T value) { | |||
assert option.getType().isInstance(value); | |||
params.put(option, value); | |||
} | |||
@@ -272,7 +272,7 @@ public final class AFPRendererConfig implements RendererConfig { | |||
createResourceLevel(); | |||
} | |||
private void setParam(AFPRendererConfigOption option, Object value) { | |||
private void setParam(AFPRendererOption option, Object value) { | |||
config.setParam(option, value); | |||
} | |||
@@ -289,7 +289,7 @@ public final class AFPRendererConfig implements RendererConfig { | |||
config.imageModeParams.put(MODE_GRAYSCALE, | |||
imagesCfg.getAttributeAsInteger(imagesMode.getModeAttribute(), 8)); | |||
} | |||
String dithering = imagesCfg.getAttribute(AFPRendererConfigOption.IMAGES_DITHERING_QUALITY.getName(), "medium"); | |||
String dithering = imagesCfg.getAttribute(AFPRendererOption.IMAGES_DITHERING_QUALITY.getName(), "medium"); | |||
float dq; | |||
if (dithering.startsWith("min")) { | |||
dq = 0.0f; |
@@ -25,7 +25,7 @@ import org.apache.fop.render.RendererConfigOption; | |||
/** | |||
* An enumeration of the configuration options available for the AFP renderer. | |||
*/ | |||
public enum AFPRendererConfigOption implements RendererConfigOption { | |||
public enum AFPRendererOption implements RendererConfigOption { | |||
DEFAULT_RESOURCE_LEVELS("default-resource-levels", AFPResourceLevelDefaults.class), | |||
IMAGES("images", null), | |||
IMAGES_JPEG("jpeg", null), | |||
@@ -48,7 +48,7 @@ public enum AFPRendererConfigOption implements RendererConfigOption { | |||
private final Class<?> type; | |||
private AFPRendererConfigOption(String name, Class<?> type) { | |||
private AFPRendererOption(String name, Class<?> type) { | |||
this.name = name; | |||
this.type = type; | |||
} |
@@ -34,21 +34,21 @@ import org.apache.fop.render.java2d.Java2DRendererConfig; | |||
import org.apache.fop.render.java2d.Java2DRendererConfig.Java2DRendererConfigParser; | |||
import org.apache.fop.util.ColorUtil; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.ANTI_ALIASING; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.BACKGROUND_COLOR; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.COLOR_MODE; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.JAVA2D_TRANSPARENT_PAGE_BACKGROUND; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.RENDERING_QUALITY; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.RENDERING_QUALITY_ELEMENT; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.RENDERING_SPEED; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.ANTI_ALIASING; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.BACKGROUND_COLOR; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.JAVA2D_TRANSPARENT_PAGE_BACKGROUND; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.RENDERING_QUALITY; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.RENDERING_QUALITY_ELEMENT; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.RENDERING_SPEED; | |||
/** | |||
* The Bitmap renderer config data object. | |||
*/ | |||
public class BitmapRendererConfig implements RendererConfig { | |||
private final EnumMap<BitmapRendererConfigOption, Object> params | |||
= new EnumMap<BitmapRendererConfigOption, Object>(BitmapRendererConfigOption.class); | |||
private final EnumMap<BitmapRendererOption, Object> params | |||
= new EnumMap<BitmapRendererOption, Object>(BitmapRendererOption.class); | |||
private final DefaultFontConfig fontConfig; | |||
@@ -82,7 +82,7 @@ public class BitmapRendererConfig implements RendererConfig { | |||
: JAVA2D_TRANSPARENT_PAGE_BACKGROUND.getDefaultValue()); | |||
} | |||
private Object get(BitmapRendererConfigOption option) { | |||
private Object get(BitmapRendererOption option) { | |||
return params.get(option); | |||
} | |||
@@ -97,7 +97,7 @@ public class BitmapRendererConfig implements RendererConfig { | |||
this.mimeType = mimeType; | |||
} | |||
private void setParam(BitmapRendererConfig config, BitmapRendererConfigOption option, | |||
private void setParam(BitmapRendererConfig config, BitmapRendererOption option, | |||
Object value) { | |||
config.params.put(option, value != null ? value : option.getDefaultValue()); | |||
} | |||
@@ -122,17 +122,17 @@ public class BitmapRendererConfig implements RendererConfig { | |||
ColorUtil.parseColorString(userAgent, background)); | |||
} | |||
setParam(config, BitmapRendererConfigOption.ANTI_ALIASING, | |||
setParam(config, BitmapRendererOption.ANTI_ALIASING, | |||
getChild(cfg, ANTI_ALIASING).getValueAsBoolean( | |||
(Boolean) ANTI_ALIASING.getDefaultValue())); | |||
String optimization = getValue(cfg, RENDERING_QUALITY_ELEMENT); | |||
setParam(config, RENDERING_QUALITY, | |||
!(BitmapRendererConfigOption.getValue(optimization) == RENDERING_SPEED)); | |||
!(BitmapRendererOption.getValue(optimization) == RENDERING_SPEED)); | |||
String color = getValue(cfg, COLOR_MODE); | |||
setParam(config, COLOR_MODE, | |||
getBufferedImageIntegerFromColor(BitmapRendererConfigOption.getValue(color))); | |||
getBufferedImageIntegerFromColor(BitmapRendererOption.getValue(color))); | |||
} | |||
} | |||
@@ -144,7 +144,7 @@ public class BitmapRendererConfig implements RendererConfig { | |||
return config; | |||
} | |||
private Integer getBufferedImageIntegerFromColor(BitmapRendererConfigOption option) { | |||
private Integer getBufferedImageIntegerFromColor(BitmapRendererOption option) { | |||
if (option == null) { | |||
return null; | |||
} | |||
@@ -163,11 +163,11 @@ public class BitmapRendererConfig implements RendererConfig { | |||
} | |||
} | |||
private Configuration getChild(Configuration cfg, BitmapRendererConfigOption option) { | |||
private Configuration getChild(Configuration cfg, BitmapRendererOption option) { | |||
return cfg.getChild(option.getName()); | |||
} | |||
private String getValue(Configuration cfg, BitmapRendererConfigOption option) { | |||
private String getValue(Configuration cfg, BitmapRendererOption option) { | |||
return cfg.getChild(option.getName()).getValue(null); | |||
} | |||
@@ -28,7 +28,7 @@ import org.apache.fop.render.RendererConfigOption; | |||
* An enumeration of the Bitmap renderer configuration opetions available to the user via the FOP | |||
* conf. | |||
*/ | |||
public enum BitmapRendererConfigOption implements RendererConfigOption { | |||
public enum BitmapRendererOption implements RendererConfigOption { | |||
JAVA2D_TRANSPARENT_PAGE_BACKGROUND("transparent-page-background", false), | |||
BACKGROUND_COLOR("background-color", Color.WHITE), | |||
ANTI_ALIASING("anti-aliasing", true), | |||
@@ -45,12 +45,12 @@ public enum BitmapRendererConfigOption implements RendererConfigOption { | |||
private final String name; | |||
private final Object defaultValue; | |||
private BitmapRendererConfigOption(String name, Object defaultValue) { | |||
private BitmapRendererOption(String name, Object defaultValue) { | |||
this.name = name; | |||
this.defaultValue = defaultValue; | |||
} | |||
private BitmapRendererConfigOption(String name) { | |||
private BitmapRendererOption(String name) { | |||
this(name, null); | |||
} | |||
@@ -63,8 +63,8 @@ public enum BitmapRendererConfigOption implements RendererConfigOption { | |||
return defaultValue; | |||
} | |||
public static BitmapRendererConfigOption getValue(String str) { | |||
for (BitmapRendererConfigOption opt : BitmapRendererConfigOption.values()) { | |||
public static BitmapRendererOption getValue(String str) { | |||
for (BitmapRendererOption opt : BitmapRendererOption.values()) { | |||
if (opt.getName().equalsIgnoreCase(str)) { | |||
return opt; | |||
} |
@@ -23,9 +23,9 @@ import org.apache.xmlgraphics.image.writer.ImageWriterParams; | |||
import org.apache.fop.render.java2d.Java2DRenderingSettings; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.ANTI_ALIASING; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.COLOR_MODE; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.RENDERING_QUALITY; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.ANTI_ALIASING; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.RENDERING_QUALITY; | |||
/** | |||
* This class holds settings used when rendering to bitmaps. |
@@ -31,7 +31,6 @@ import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator; | |||
*/ | |||
public class TIFFDocumentHandler extends AbstractBitmapDocumentHandler { | |||
TIFFDocumentHandler(IFContext context) { | |||
super(context); | |||
} | |||
@@ -51,5 +50,4 @@ public class TIFFDocumentHandler extends AbstractBitmapDocumentHandler { | |||
public IFDocumentHandlerConfigurator getConfigurator() { | |||
return new TIFFRendererConfigurator(getUserAgent(), new TIFFRendererConfigParser()); | |||
} | |||
} |
@@ -36,13 +36,13 @@ import org.apache.fop.render.RendererConfigOption; | |||
*/ | |||
public final class TIFFRendererConfig extends BitmapRendererConfig { | |||
public enum TIFFRendererConfigOption implements RendererConfigOption { | |||
public enum TIFFRendererOption implements RendererConfigOption { | |||
COMPRESSION("compression", TIFFCompressionValues.PACKBITS); | |||
private final String name; | |||
private final Object defaultValue; | |||
private TIFFRendererConfigOption(String name, Object defaultValue) { | |||
private TIFFRendererOption(String name, Object defaultValue) { | |||
this.name = name; | |||
this.defaultValue = defaultValue; | |||
} | |||
@@ -56,15 +56,15 @@ public final class TIFFRendererConfig extends BitmapRendererConfig { | |||
} | |||
} | |||
private final EnumMap<TIFFRendererConfigOption, Object> params | |||
= new EnumMap<TIFFRendererConfigOption, Object>(TIFFRendererConfigOption.class); | |||
private final EnumMap<TIFFRendererOption, Object> params | |||
= new EnumMap<TIFFRendererOption, Object>(TIFFRendererOption.class); | |||
private TIFFRendererConfig(DefaultFontConfig fontConfig) { | |||
super(fontConfig); | |||
} | |||
public TIFFCompressionValues getCompressionType() { | |||
return (TIFFCompressionValues) params.get(TIFFRendererConfigOption.COMPRESSION); | |||
return (TIFFCompressionValues) params.get(TIFFRendererOption.COMPRESSION); | |||
} | |||
/** | |||
@@ -78,11 +78,11 @@ public final class TIFFRendererConfig extends BitmapRendererConfig { | |||
private TIFFRendererConfig config; | |||
private void setParam(TIFFRendererConfigOption option, Object value) { | |||
private void setParam(TIFFRendererOption option, Object value) { | |||
config.params.put(option, value != null ? value : option.getDefaultValue()); | |||
} | |||
private String getValue(Configuration cfg, TIFFRendererConfigOption option) { | |||
private String getValue(Configuration cfg, TIFFRendererOption option) { | |||
return cfg.getChild(option.getName()).getValue(null); | |||
} | |||
@@ -92,9 +92,9 @@ public final class TIFFRendererConfig extends BitmapRendererConfig { | |||
.parse(cfg, userAgent.validateStrictly())); | |||
super.build(config, userAgent, cfg); | |||
if (cfg != null) { | |||
setParam(TIFFRendererConfigOption.COMPRESSION, | |||
setParam(TIFFRendererOption.COMPRESSION, | |||
TIFFCompressionValues.getValue(getValue(cfg, | |||
TIFFRendererConfigOption.COMPRESSION))); | |||
TIFFRendererOption.COMPRESSION))); | |||
} | |||
return config; | |||
} |
@@ -29,7 +29,6 @@ import org.apache.commons.logging.LogFactory; | |||
import org.apache.fop.apps.io.InternalResourceResolver; | |||
import org.apache.fop.fonts.CustomFont; | |||
import org.apache.fop.fonts.EmbedFontInfo; | |||
import org.apache.fop.fonts.EncodingMode; | |||
import org.apache.fop.fonts.FontCollection; | |||
import org.apache.fop.fonts.FontInfo; | |||
import org.apache.fop.fonts.FontLoader; | |||
@@ -82,10 +81,10 @@ public class ConfiguredFontCollection implements FontCollection { | |||
InputStream fontSource = resourceResolver.getResource(fontURI); | |||
font = new CustomFontMetricsMapper(fontMetrics, fontSource); | |||
} else { | |||
CustomFont fontMetrics = FontLoader.loadFont( | |||
fontURI, null, true, configFontInfo.getEmbeddingMode(), | |||
EncodingMode.AUTO, configFontInfo.getKerning(), | |||
configFontInfo.getAdvanced(), resourceResolver); | |||
CustomFont fontMetrics = FontLoader.loadFont(fontURI, null, true, | |||
configFontInfo.getEmbeddingMode(), configFontInfo.getEncodingMode(), | |||
configFontInfo.getKerning(), configFontInfo.getAdvanced(), | |||
resourceResolver); | |||
font = new CustomFontMetricsMapper(fontMetrics); | |||
} | |||
@@ -23,7 +23,7 @@ import org.apache.fop.render.RendererConfigOption; | |||
* An enumeration of the renderer configuration options available to the Java2D renderer via the | |||
* FOP conf. | |||
*/ | |||
public enum Java2DRendererConfigOption implements RendererConfigOption { | |||
public enum Java2DRendererOption implements RendererConfigOption { | |||
RENDERING_MODE("rendering", PCLRenderingMode.class), | |||
TEXT_RENDERING("text-rendering", Boolean.class), | |||
@@ -33,7 +33,7 @@ public enum Java2DRendererConfigOption implements RendererConfigOption { | |||
private final Class<?> type; | |||
private Java2DRendererConfigOption(String name, Class<?> type) { | |||
private Java2DRendererOption(String name, Class<?> type) { | |||
this.name = name; | |||
this.type = type; | |||
} |
@@ -31,17 +31,17 @@ import org.apache.fop.fonts.DefaultFontConfig; | |||
import org.apache.fop.fonts.DefaultFontConfig.DefaultFontConfigParser; | |||
import org.apache.fop.render.RendererConfig; | |||
import static org.apache.fop.render.pcl.Java2DRendererConfigOption.DISABLE_PJL; | |||
import static org.apache.fop.render.pcl.Java2DRendererConfigOption.RENDERING_MODE; | |||
import static org.apache.fop.render.pcl.Java2DRendererConfigOption.TEXT_RENDERING; | |||
import static org.apache.fop.render.pcl.Java2DRendererOption.DISABLE_PJL; | |||
import static org.apache.fop.render.pcl.Java2DRendererOption.RENDERING_MODE; | |||
import static org.apache.fop.render.pcl.Java2DRendererOption.TEXT_RENDERING; | |||
/** | |||
* The PCL renderer configuration data object. | |||
*/ | |||
public final class PCLRendererConfig implements RendererConfig { | |||
private final Map<Java2DRendererConfigOption, Object> params | |||
= new EnumMap<Java2DRendererConfigOption, Object>(Java2DRendererConfigOption.class); | |||
private final Map<Java2DRendererOption, Object> params | |||
= new EnumMap<Java2DRendererOption, Object>(Java2DRendererOption.class); | |||
private final DefaultFontConfig fontConfig; | |||
@@ -65,12 +65,12 @@ public final class PCLRendererConfig implements RendererConfig { | |||
return getParam(DISABLE_PJL, Boolean.class); | |||
} | |||
private <T> T getParam(Java2DRendererConfigOption option, Class<T> type) { | |||
private <T> T getParam(Java2DRendererOption option, Class<T> type) { | |||
assert option.getType().equals(type); | |||
return type.cast(params.get(option)); | |||
} | |||
private <T> void setParam(Java2DRendererConfigOption option, T value) { | |||
private <T> void setParam(Java2DRendererOption option, T value) { | |||
assert option.getType().isInstance(value); | |||
params.put(option, value); | |||
} |
@@ -125,8 +125,8 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { | |||
return this.documentNavigationHandler; | |||
} | |||
PDFRenderingUtil getPDFUtil() { | |||
return this.pdfUtil; | |||
void mergeRendererOptionsConfig(PDFRendererOptionsConfig config) { | |||
pdfUtil.mergeRendererOptionsConfig(config); | |||
} | |||
PDFLogicalStructureHandler getLogicalStructureHandler() { |
@@ -23,23 +23,8 @@ import org.apache.fop.pdf.PDFAMode; | |||
import org.apache.fop.pdf.PDFXMode; | |||
import org.apache.fop.render.RendererConfigOption; | |||
public enum PDFRendererConfigOption implements RendererConfigOption { | |||
FILTER_LIST("filterList"), | |||
/** Rendering Options key for the PDF/A mode, default: {@link PDFAMode#DISABLED} */ | |||
PDF_A_MODE("pdf-a-mode", PDFAMode.DISABLED), | |||
/** Rendering Options key for the PDF/X mode, default: {@link PDFXMode#DISABLED} */ | |||
PDF_X_MODE("pdf-x-mode", PDFXMode.DISABLED), | |||
/** PDF version entry: specify the version of the PDF document created, datatype: String */ | |||
VERSION("version"), | |||
/** | |||
* Rendering Options key for disabling the sRGB color space (only possible if no PDF/A or | |||
* PDF/X profile is active), default: false | |||
*/ | |||
DISABLE_SRGB_COLORSPACE("disable-srgb-colorspace", false), | |||
/** Rendering Options key for the ICC profile for the output intent. */ | |||
OUTPUT_PROFILE("output-profile"), | |||
/** PDF encryption parameter: all parameters as object, datatype: PDFEncryptionParams */ | |||
ENCRYPTION_PARAMS("encryption-params"), | |||
public enum PDFEncryptionOption implements RendererConfigOption { | |||
/** | |||
* PDF encryption length parameter: must be a multiple of 8 between 40 and 128, | |||
* default value 40, datatype: int, default: 40 | |||
@@ -90,15 +75,18 @@ public enum PDFRendererConfigOption implements RendererConfigOption { | |||
/** PDF encryption parameter: owner password, datatype: String, default: "" */ | |||
OWNER_PASSWORD("owner-password", ""); | |||
public static final String ENCRYPTION_PARAMS = "encryption-params"; | |||
private final String name; | |||
private final Object defaultValue; | |||
private PDFRendererConfigOption(String name, Object defaultValue) { | |||
private PDFEncryptionOption(String name, Object defaultValue) { | |||
this.name = name; | |||
this.defaultValue = defaultValue; | |||
} | |||
private PDFRendererConfigOption(String name) { | |||
private PDFEncryptionOption(String name) { | |||
this(name, null); | |||
} | |||
@@ -92,10 +92,6 @@ public class PDFPainter extends AbstractIFPainter { | |||
return this.documentHandler.getContext(); | |||
} | |||
PDFRenderingUtil getPDFUtil() { | |||
return this.documentHandler.pdfUtil; | |||
} | |||
PDFDocument getPDFDoc() { | |||
return this.documentHandler.pdfDoc; | |||
} |
@@ -19,8 +19,6 @@ | |||
package org.apache.fop.render.pdf; | |||
import java.net.URI; | |||
import java.net.URISyntaxException; | |||
import java.util.ArrayList; | |||
import java.util.EnumMap; | |||
import java.util.HashMap; | |||
@@ -35,35 +33,32 @@ import org.apache.commons.logging.LogFactory; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.apps.MimeConstants; | |||
import org.apache.fop.apps.io.InternalResourceResolver; | |||
import org.apache.fop.fonts.DefaultFontConfig; | |||
import org.apache.fop.fonts.DefaultFontConfig.DefaultFontConfigParser; | |||
import org.apache.fop.pdf.PDFAMode; | |||
import org.apache.fop.pdf.PDFEncryptionParams; | |||
import org.apache.fop.pdf.PDFFilterList; | |||
import org.apache.fop.pdf.PDFXMode; | |||
import org.apache.fop.pdf.Version; | |||
import org.apache.fop.render.RendererConfig; | |||
import org.apache.fop.render.RendererConfigOption; | |||
import org.apache.fop.util.LogUtil; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.DISABLE_SRGB_COLORSPACE; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.ENCRYPTION_LENGTH; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.ENCRYPTION_PARAMS; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.FILTER_LIST; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.NO_ACCESSCONTENT; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.NO_ANNOTATIONS; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.NO_ASSEMBLEDOC; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.NO_COPY_CONTENT; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.NO_EDIT_CONTENT; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.NO_FILLINFORMS; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.NO_PRINT; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.NO_PRINTHQ; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.OUTPUT_PROFILE; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.OWNER_PASSWORD; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.PDF_A_MODE; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.PDF_X_MODE; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.USER_PASSWORD; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.VERSION; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.ENCRYPTION_LENGTH; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.ENCRYPTION_PARAMS; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.NO_ACCESSCONTENT; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.NO_ANNOTATIONS; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.NO_ASSEMBLEDOC; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.NO_COPY_CONTENT; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.NO_EDIT_CONTENT; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.NO_FILLINFORMS; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.NO_PRINT; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.NO_PRINTHQ; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.OWNER_PASSWORD; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.USER_PASSWORD; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.DISABLE_SRGB_COLORSPACE; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.FILTER_LIST; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.OUTPUT_PROFILE; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.PDF_A_MODE; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.PDF_X_MODE; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.VERSION; | |||
/** | |||
* The PDF renderer configuration data object. | |||
@@ -72,46 +67,21 @@ public final class PDFRendererConfig implements RendererConfig { | |||
private static final Log LOG = LogFactory.getLog(PDFRendererConfig.class); | |||
private final Map<PDFRendererConfigOption, Object> configOptions | |||
= new EnumMap<PDFRendererConfigOption, Object>(PDFRendererConfigOption.class); | |||
private final PDFRendererOptionsConfig configOption; | |||
private final DefaultFontConfig fontConfig; | |||
private PDFRendererConfig(DefaultFontConfig fontConfig) { | |||
private PDFRendererConfig(DefaultFontConfig fontConfig, PDFRendererOptionsConfig config) { | |||
this.fontConfig = fontConfig; | |||
this.configOption = config; | |||
} | |||
public DefaultFontConfig getFontInfoConfig() { | |||
return fontConfig; | |||
} | |||
public Map<String, List<String>> getFilterMap() { | |||
return (Map<String, List<String>>) configOptions.get(FILTER_LIST); | |||
} | |||
public PDFAMode getPDFAMode() { | |||
return (PDFAMode) configOptions.get(PDF_A_MODE); | |||
} | |||
public PDFXMode getPDFXMode() { | |||
return (PDFXMode) configOptions.get(PDF_X_MODE); | |||
public PDFRendererOptionsConfig getConfigOptions() { | |||
return configOption; | |||
} | |||
public PDFEncryptionParams getEncryptionParameters() { | |||
return (PDFEncryptionParams) configOptions.get(ENCRYPTION_PARAMS); | |||
} | |||
public URI getOutputProfileURI() { | |||
return (URI) configOptions.get(OUTPUT_PROFILE); | |||
} | |||
public Boolean getDisableSRGBColorSpace() { | |||
return (Boolean) configOptions.get(DISABLE_SRGB_COLORSPACE); | |||
} | |||
public Version getPDFVersion() { | |||
String pdfVersion = (String) configOptions.get(VERSION); | |||
return pdfVersion == null ? null : Version.getValueOf(pdfVersion); | |||
public DefaultFontConfig getFontInfoConfig() { | |||
return fontConfig; | |||
} | |||
/** | |||
@@ -131,61 +101,70 @@ public final class PDFRendererConfig implements RendererConfig { | |||
private static final class ParserHelper { | |||
private final Map<PDFRendererOption, Object> configOptions | |||
= new EnumMap<PDFRendererOption, Object>(PDFRendererOption.class); | |||
private PDFEncryptionParams encryptionConfig; | |||
private PDFRendererConfig pdfConfig; | |||
private ParserHelper(Configuration cfg, FOUserAgent userAgent, boolean strict) throws FOPException { | |||
pdfConfig = new PDFRendererConfig(new DefaultFontConfigParser().parse(cfg, strict)); | |||
if (cfg != null) { | |||
configure(cfg, userAgent, strict); | |||
} | |||
pdfConfig = new PDFRendererConfig(new DefaultFontConfigParser().parse(cfg, strict), | |||
new PDFRendererOptionsConfig(configOptions, encryptionConfig)); | |||
} | |||
private void parseAndPut(PDFRendererOption option, Configuration cfg) { | |||
put(option, option.parse(parseConfig(cfg, option))); | |||
} | |||
private void put(PDFRendererConfigOption option, Object value) { | |||
private void put(PDFRendererOption option, Object value) { | |||
if (value != null && !value.equals(option.getDefaultValue())) { | |||
pdfConfig.configOptions.put(option, value); | |||
configOptions.put(option, value); | |||
} | |||
} | |||
private void configure(Configuration cfg, FOUserAgent userAgent, boolean strict) | |||
throws FOPException { | |||
private void configure(Configuration cfg, FOUserAgent userAgent, boolean strict) throws FOPException { | |||
try { | |||
buildFilterMapFromConfiguration(cfg); | |||
put(PDF_A_MODE, PDFAMode.getValueOf(parseConfig(cfg, PDF_A_MODE))); | |||
put(PDF_X_MODE, PDFXMode.getValueOf(parseConfig(cfg, PDF_X_MODE))); | |||
Configuration encryptCfg = cfg.getChild(ENCRYPTION_PARAMS.getName(), false); | |||
if (encryptCfg != null) { | |||
PDFEncryptionParams encryptionConfig = new PDFEncryptionParams(); | |||
encryptionConfig.setOwnerPassword(parseConfig(encryptCfg, OWNER_PASSWORD)); | |||
encryptionConfig.setUserPassword(parseConfig(encryptCfg, USER_PASSWORD)); | |||
encryptionConfig.setAllowPrint(!doesValueExist(encryptCfg, NO_PRINT)); | |||
encryptionConfig.setAllowCopyContent(!doesValueExist(encryptCfg, NO_COPY_CONTENT)); | |||
encryptionConfig.setAllowEditContent(!doesValueExist(encryptCfg, NO_EDIT_CONTENT)); | |||
encryptionConfig.setAllowEditAnnotations(!doesValueExist(encryptCfg, NO_ANNOTATIONS)); | |||
encryptionConfig.setAllowFillInForms(!doesValueExist(encryptCfg, NO_FILLINFORMS)); | |||
encryptionConfig.setAllowAccessContent(!doesValueExist(encryptCfg, NO_ACCESSCONTENT)); | |||
encryptionConfig.setAllowAssembleDocument(!doesValueExist(encryptCfg, | |||
NO_ASSEMBLEDOC)); | |||
encryptionConfig.setAllowPrintHq(!doesValueExist(encryptCfg, NO_PRINTHQ)); | |||
String encryptionLength = parseConfig(encryptCfg, ENCRYPTION_LENGTH); | |||
if (encryptionLength != null) { | |||
int validatedLength = checkEncryptionLength(Integer.parseInt(encryptionLength), | |||
userAgent); | |||
encryptionConfig.setEncryptionLengthInBits(validatedLength); | |||
} | |||
put(ENCRYPTION_PARAMS, encryptionConfig); | |||
} | |||
put(OUTPUT_PROFILE, InternalResourceResolver.cleanURI(parseConfig(cfg, OUTPUT_PROFILE))); | |||
put(DISABLE_SRGB_COLORSPACE, Boolean.valueOf(parseConfig(cfg, DISABLE_SRGB_COLORSPACE))); | |||
put(VERSION, getPDFDocVersion(cfg)); | |||
parseAndPut(PDF_A_MODE, cfg); | |||
parseAndPut(PDF_X_MODE, cfg); | |||
configureEncryptionParams(cfg, userAgent, strict); | |||
parseAndPut(OUTPUT_PROFILE, cfg); | |||
parseAndPut(DISABLE_SRGB_COLORSPACE, cfg); | |||
parseAndPut(VERSION, cfg); | |||
} catch (ConfigurationException e) { | |||
LogUtil.handleException(LOG, e, strict); | |||
} catch (URISyntaxException use) { | |||
LogUtil.handleException(LOG, use, strict); | |||
} | |||
} | |||
private void buildFilterMapFromConfiguration(Configuration cfg) | |||
throws ConfigurationException, FOPException { | |||
private void configureEncryptionParams(Configuration cfg, FOUserAgent userAgent, boolean strict) { | |||
Configuration encryptCfg = cfg.getChild(ENCRYPTION_PARAMS, false); | |||
if (encryptCfg != null) { | |||
encryptionConfig = new PDFEncryptionParams(); | |||
encryptionConfig.setOwnerPassword(parseConfig(encryptCfg, OWNER_PASSWORD)); | |||
encryptionConfig.setUserPassword(parseConfig(encryptCfg, USER_PASSWORD)); | |||
encryptionConfig.setAllowPrint(!doesValueExist(encryptCfg, NO_PRINT)); | |||
encryptionConfig.setAllowCopyContent(!doesValueExist(encryptCfg, NO_COPY_CONTENT)); | |||
encryptionConfig.setAllowEditContent(!doesValueExist(encryptCfg, NO_EDIT_CONTENT)); | |||
encryptionConfig.setAllowEditAnnotations(!doesValueExist(encryptCfg, NO_ANNOTATIONS)); | |||
encryptionConfig.setAllowFillInForms(!doesValueExist(encryptCfg, NO_FILLINFORMS)); | |||
encryptionConfig.setAllowAccessContent(!doesValueExist(encryptCfg, NO_ACCESSCONTENT)); | |||
encryptionConfig.setAllowAssembleDocument(!doesValueExist(encryptCfg, NO_ASSEMBLEDOC)); | |||
encryptionConfig.setAllowPrintHq(!doesValueExist(encryptCfg, NO_PRINTHQ)); | |||
String encryptionLength = parseConfig(encryptCfg, ENCRYPTION_LENGTH); | |||
if (encryptionLength != null) { | |||
int validatedLength = checkEncryptionLength(Integer.parseInt(encryptionLength), userAgent); | |||
encryptionConfig.setEncryptionLengthInBits(validatedLength); | |||
} | |||
} | |||
} | |||
private void buildFilterMapFromConfiguration(Configuration cfg) throws ConfigurationException, | |||
FOPException { | |||
Configuration[] filterLists = cfg.getChildren(FILTER_LIST.getName()); | |||
Map<String, List<String>> filterMap = new HashMap<String, List<String>>(); | |||
for (Configuration filters : filterLists) { | |||
@@ -218,28 +197,15 @@ public final class PDFRendererConfig implements RendererConfig { | |||
put(FILTER_LIST, filterMap); | |||
} | |||
private String parseConfig(Configuration cfg, PDFRendererConfigOption option) { | |||
private String parseConfig(Configuration cfg, RendererConfigOption option) { | |||
Configuration child = cfg.getChild(option.getName()); | |||
return child.getValue(null); | |||
} | |||
private boolean doesValueExist(Configuration cfg, PDFRendererConfigOption option) { | |||
private boolean doesValueExist(Configuration cfg, RendererConfigOption option) { | |||
return cfg.getChild(option.getName(), false) != null; | |||
} | |||
private String getPDFDocVersion(Configuration cfg) throws FOPException { | |||
Configuration pdfVersion = cfg.getChild(VERSION.getName(), false); | |||
if (pdfVersion != null) { | |||
String version = pdfVersion.getValue(null); | |||
if (version != null && version.length() != 0) { | |||
return version; | |||
} else { | |||
throw new FOPException("The PDF version has not been set."); | |||
} | |||
} | |||
return null; | |||
} | |||
private int checkEncryptionLength(int encryptionLength, FOUserAgent userAgent) { | |||
int correctEncryptionLength = encryptionLength; | |||
if (encryptionLength < 40) { |
@@ -21,7 +21,6 @@ package org.apache.fop.render.pdf; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.pdf.PDFEncryptionParams; | |||
import org.apache.fop.render.DefaultRendererConfigurator; | |||
import org.apache.fop.render.RendererConfig.RendererConfigParser; | |||
import org.apache.fop.render.intermediate.IFDocumentHandler; | |||
@@ -40,52 +39,10 @@ public class PDFRendererConfigurator extends DefaultRendererConfigurator { | |||
super(userAgent, rendererConfigParser); | |||
} | |||
// ---=== IFDocumentHandler configuration ===--- | |||
/** {@inheritDoc} */ | |||
public void configure(IFDocumentHandler documentHandler) throws FOPException { | |||
final PDFRendererConfig pdfConfig = (PDFRendererConfig) getRendererConfig(documentHandler); | |||
if (pdfConfig != null) { | |||
PDFDocumentHandler pdfDocumentHandler = (PDFDocumentHandler) documentHandler; | |||
PDFRenderingUtil pdfUtil = pdfDocumentHandler.getPDFUtil(); | |||
if (pdfConfig.getFilterMap() != null) { | |||
pdfUtil.setFilterMap(pdfConfig.getFilterMap()); | |||
} | |||
if (pdfConfig.getPDFAMode() != null) { | |||
pdfUtil.setAMode(pdfConfig.getPDFAMode()); | |||
} | |||
if (pdfConfig.getPDFXMode() != null) { | |||
pdfUtil.setXMode(pdfConfig.getPDFXMode()); | |||
} | |||
if (pdfConfig.getOutputProfileURI() != null) { | |||
pdfUtil.setOutputProfileURI(pdfConfig.getOutputProfileURI()); | |||
} | |||
if (pdfConfig.getPDFVersion() != null) { | |||
pdfUtil.setPDFVersion(pdfConfig.getPDFVersion()); | |||
} | |||
if (pdfConfig.getDisableSRGBColorSpace() != null) { | |||
pdfUtil.setDisableSRGBColorSpace(pdfConfig.getDisableSRGBColorSpace()); | |||
} | |||
PDFEncryptionParams config = pdfConfig.getEncryptionParameters(); | |||
if (config != null) { | |||
PDFEncryptionParams utilParams = pdfUtil.getEncryptionParams(); | |||
if (config.getUserPassword() != null) { | |||
utilParams.setUserPassword(config.getUserPassword()); | |||
} | |||
if (config.getOwnerPassword() != null) { | |||
utilParams.setOwnerPassword(config.getOwnerPassword()); | |||
} | |||
utilParams.setAllowPrint(config.isAllowPrint()); | |||
utilParams.setAllowCopyContent(config.isAllowCopyContent()); | |||
utilParams.setAllowEditContent(config.isAllowEditContent()); | |||
utilParams.setAllowAssembleDocument(config.isAllowAssembleDocument()); | |||
utilParams.setAllowAccessContent(config.isAllowAccessContent()); | |||
utilParams.setAllowFillInForms(config.isAllowFillInForms()); | |||
utilParams.setAllowPrintHq(config.isAllowPrintHq()); | |||
utilParams.setEncryptionLengthInBits(config.getEncryptionLengthInBits()); | |||
} | |||
} | |||
((PDFDocumentHandler) documentHandler).mergeRendererOptionsConfig( | |||
((PDFRendererConfig) getRendererConfig(documentHandler)).getConfigOptions()); | |||
} | |||
} |
@@ -0,0 +1,112 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
/* $Id$ */ | |||
package org.apache.fop.render.pdf; | |||
import java.net.URI; | |||
import java.net.URISyntaxException; | |||
import org.apache.fop.apps.io.InternalResourceResolver; | |||
import org.apache.fop.pdf.PDFAMode; | |||
import org.apache.fop.pdf.PDFXMode; | |||
import org.apache.fop.pdf.Version; | |||
import org.apache.fop.render.RendererConfigOption; | |||
public enum PDFRendererOption implements RendererConfigOption { | |||
FILTER_LIST("filterList", null) { | |||
@Override | |||
Object deserialize(String value) { | |||
throw new UnsupportedOperationException(); | |||
} | |||
}, | |||
/** Rendering Options key for the PDF/A mode, default: {@link PDFAMode#DISABLED} */ | |||
PDF_A_MODE("pdf-a-mode", PDFAMode.DISABLED){ | |||
@Override | |||
PDFAMode deserialize(String value) { | |||
return PDFAMode.getValueOf(value); | |||
} | |||
}, | |||
/** Rendering Options key for the PDF/X mode, default: {@link PDFXMode#DISABLED} */ | |||
PDF_X_MODE("pdf-x-mode", PDFXMode.DISABLED){ | |||
@Override | |||
PDFXMode deserialize(String value) { | |||
return PDFXMode.getValueOf(value); | |||
} | |||
}, | |||
/** PDF version entry: specify the version of the PDF document created, datatype: String */ | |||
VERSION("version") { | |||
@Override | |||
Version deserialize(String value) { | |||
return Version.getValueOf(value); | |||
} | |||
}, | |||
/** | |||
* Rendering Options key for disabling the sRGB color space (only possible if no PDF/A or | |||
* PDF/X profile is active), default: false | |||
*/ | |||
DISABLE_SRGB_COLORSPACE("disable-srgb-colorspace", false) { | |||
@Override | |||
Boolean deserialize(String value) { | |||
return Boolean.valueOf(value); | |||
} | |||
}, | |||
/** Rendering Options key for the ICC profile for the output intent. */ | |||
OUTPUT_PROFILE("output-profile") { | |||
@Override | |||
URI deserialize(String value) { | |||
try { | |||
return InternalResourceResolver.cleanURI(value); | |||
} catch (URISyntaxException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
}; | |||
private final String name; | |||
private final Object defaultValue; | |||
private PDFRendererOption(String name, Object defaultValue) { | |||
this.name = name; | |||
this.defaultValue = defaultValue; | |||
} | |||
private PDFRendererOption(String name) { | |||
this(name, null); | |||
} | |||
public String getName() { | |||
return name; | |||
} | |||
public Object getDefaultValue() { | |||
return defaultValue; | |||
} | |||
public Object parse(Object object) { | |||
if (object instanceof String) { | |||
return deserialize((String) object); | |||
} else { | |||
return object; | |||
} | |||
} | |||
abstract Object deserialize(String value); | |||
} |
@@ -0,0 +1,123 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
/* $Id$ */ | |||
package org.apache.fop.render.pdf; | |||
import java.net.URI; | |||
import java.util.EnumMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import org.apache.fop.pdf.PDFAMode; | |||
import org.apache.fop.pdf.PDFEncryptionParams; | |||
import org.apache.fop.pdf.PDFXMode; | |||
import org.apache.fop.pdf.Version; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.DISABLE_SRGB_COLORSPACE; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.FILTER_LIST; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.OUTPUT_PROFILE; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.PDF_A_MODE; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.PDF_X_MODE; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.VERSION; | |||
/** | |||
* The renderer options configuration data. | |||
*/ | |||
public final class PDFRendererOptionsConfig { | |||
static final PDFRendererOptionsConfig DEFAULT; | |||
static { | |||
final EnumMap<PDFRendererOption, Object> props | |||
= new EnumMap<PDFRendererOption, Object>(PDFRendererOption.class); | |||
for(PDFRendererOption option : PDFRendererOption.values()) { | |||
props.put(option, option.getDefaultValue()); | |||
} | |||
DEFAULT = new PDFRendererOptionsConfig(props, null); | |||
} | |||
private final Map<PDFRendererOption, Object> properties | |||
= new EnumMap<PDFRendererOption, Object>(PDFRendererOption.class); | |||
private final PDFEncryptionParams encryptionConfig; | |||
PDFRendererOptionsConfig(Map<PDFRendererOption, Object> props, | |||
PDFEncryptionParams encryptionParams) { | |||
properties.putAll(props); | |||
this.encryptionConfig = copyPDFEncryptionParams(encryptionParams); | |||
} | |||
private static PDFEncryptionParams copyPDFEncryptionParams(PDFEncryptionParams source) { | |||
return source == null ? null : new PDFEncryptionParams(source); | |||
} | |||
PDFRendererOptionsConfig merge(PDFRendererOptionsConfig config) { | |||
if (config == null) { | |||
return this; | |||
} else { | |||
return new PDFRendererOptionsConfig(merge(this.properties, config.properties), | |||
config.getEncryptionParameters() == null | |||
? copyPDFEncryptionParams(this.encryptionConfig) | |||
: copyPDFEncryptionParams(config.getEncryptionParameters())); | |||
} | |||
} | |||
private static Map<PDFRendererOption, Object> merge( | |||
Map<PDFRendererOption, Object> first, Map<PDFRendererOption, Object> second) { | |||
final EnumMap<PDFRendererOption, Object> merged | |||
= new EnumMap<PDFRendererOption, Object>(PDFRendererOption.class); | |||
for (PDFRendererOption option : PDFRendererOption.values()) { | |||
Object value = second.get(option); | |||
if (value != null) { | |||
merged.put(option, value); | |||
} else { | |||
merged.put(option, first.get(option)); | |||
} | |||
} | |||
return merged; | |||
} | |||
public Map<String, List<String>> getFilterMap() { | |||
return (Map<String, List<String>>) properties.get(FILTER_LIST); | |||
} | |||
public PDFAMode getPDFAMode() { | |||
return (PDFAMode) properties.get(PDF_A_MODE); | |||
} | |||
public PDFXMode getPDFXMode() { | |||
return (PDFXMode) properties.get(PDF_X_MODE); | |||
} | |||
public PDFEncryptionParams getEncryptionParameters() { | |||
return encryptionConfig; | |||
} | |||
public URI getOutputProfileURI() { | |||
return (URI) properties.get(OUTPUT_PROFILE); | |||
} | |||
public Boolean getDisableSRGBColorSpace() { | |||
return (Boolean) properties.get(DISABLE_SRGB_COLORSPACE); | |||
} | |||
public Version getPDFVersion() { | |||
return (Version) properties.get(VERSION); | |||
} | |||
} |
@@ -26,6 +26,7 @@ import java.io.InputStream; | |||
import java.io.OutputStream; | |||
import java.net.URI; | |||
import java.net.URISyntaxException; | |||
import java.util.EnumMap; | |||
import java.util.Map; | |||
import org.apache.commons.io.IOUtils; | |||
@@ -66,21 +67,18 @@ import org.apache.fop.pdf.Version; | |||
import org.apache.fop.pdf.VersionController; | |||
import org.apache.fop.render.pdf.extensions.PDFEmbeddedFileExtensionAttachment; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.DISABLE_SRGB_COLORSPACE; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.ENCRYPTION_PARAMS; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.NO_ACCESSCONTENT; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.NO_ANNOTATIONS; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.NO_ASSEMBLEDOC; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.NO_COPY_CONTENT; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.NO_EDIT_CONTENT; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.NO_FILLINFORMS; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.NO_PRINT; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.NO_PRINTHQ; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.OUTPUT_PROFILE; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.OWNER_PASSWORD; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.PDF_A_MODE; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.PDF_X_MODE; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.USER_PASSWORD; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.ENCRYPTION_PARAMS; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.NO_ACCESSCONTENT; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.NO_ANNOTATIONS; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.NO_ASSEMBLEDOC; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.NO_COPY_CONTENT; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.NO_EDIT_CONTENT; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.NO_FILLINFORMS; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.NO_PRINT; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.NO_PRINTHQ; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.OWNER_PASSWORD; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.USER_PASSWORD; | |||
/** | |||
* Utility class which enables all sorts of features that are not directly connected to the | |||
@@ -96,168 +94,40 @@ class PDFRenderingUtil { | |||
/** the PDF Document being created */ | |||
private PDFDocument pdfDoc; | |||
/** the PDF/A mode (Default: disabled) */ | |||
private PDFAMode pdfAMode = (PDFAMode) PDFRendererConfigOption.PDF_A_MODE.getDefaultValue(); | |||
/** the PDF/X mode (Default: disabled) */ | |||
private PDFXMode pdfXMode = (PDFXMode) PDFRendererConfigOption.PDF_X_MODE.getDefaultValue(); | |||
/** the (optional) encryption parameters */ | |||
private PDFEncryptionParams encryptionParams; | |||
/** Registry of PDF filters */ | |||
private Map filterMap; | |||
private PDFRendererOptionsConfig rendererConfig; | |||
/** the ICC stream used as output profile by this document for PDF/A and PDF/X functionality. */ | |||
private PDFICCStream outputProfile; | |||
/** the default sRGB color space. */ | |||
private PDFICCBasedColorSpace sRGBColorSpace; | |||
/** controls whether the sRGB color space should be installed */ | |||
private boolean disableSRGBColorSpace = false; | |||
/** Optional URI to an output profile to be used. */ | |||
private URI outputProfileURI; | |||
private Version maxPDFVersion; | |||
PDFRenderingUtil(FOUserAgent userAgent) { | |||
this.userAgent = userAgent; | |||
initialize(); | |||
} | |||
private static boolean booleanValueOf(Object obj) { | |||
if (obj instanceof Boolean) { | |||
return ((Boolean)obj).booleanValue(); | |||
} else if (obj instanceof String) { | |||
return Boolean.valueOf((String)obj).booleanValue(); | |||
} else { | |||
throw new IllegalArgumentException("Boolean or \"true\" or \"false\" expected."); | |||
} | |||
} | |||
private void initialize() { | |||
PDFEncryptionParams params | |||
= (PDFEncryptionParams) userAgent.getRendererOption(ENCRYPTION_PARAMS); | |||
if (params != null) { | |||
this.encryptionParams = params; //overwrite if available | |||
} | |||
String userPassword = (String) userAgent.getRendererOption(USER_PASSWORD); | |||
if (userPassword != null) { | |||
getEncryptionParams().setUserPassword(userPassword); | |||
} | |||
String ownerPassword = (String) userAgent.getRendererOption(OWNER_PASSWORD); | |||
if (ownerPassword != null) { | |||
getEncryptionParams().setOwnerPassword(ownerPassword); | |||
} | |||
Object noPrint = userAgent.getRendererOption(NO_PRINT); | |||
if (noPrint != null) { | |||
getEncryptionParams().setAllowPrint(!booleanValueOf(noPrint)); | |||
} | |||
Object noCopyContent = userAgent.getRendererOption(NO_COPY_CONTENT); | |||
if (noCopyContent != null) { | |||
getEncryptionParams().setAllowCopyContent(!booleanValueOf(noCopyContent)); | |||
} | |||
Object noEditContent = userAgent.getRendererOption(NO_EDIT_CONTENT); | |||
if (noEditContent != null) { | |||
getEncryptionParams().setAllowEditContent(!booleanValueOf(noEditContent)); | |||
} | |||
Object noAnnotations = userAgent.getRendererOption(NO_ANNOTATIONS); | |||
if (noAnnotations != null) { | |||
getEncryptionParams().setAllowEditAnnotations(!booleanValueOf(noAnnotations)); | |||
} | |||
Object noFillInForms = userAgent.getRendererOption(NO_FILLINFORMS); | |||
if (noFillInForms != null) { | |||
getEncryptionParams().setAllowFillInForms(!booleanValueOf(noFillInForms)); | |||
} | |||
Object noAccessContent = userAgent.getRendererOption(NO_ACCESSCONTENT); | |||
if (noAccessContent != null) { | |||
getEncryptionParams().setAllowAccessContent(!booleanValueOf(noAccessContent)); | |||
} | |||
Object noAssembleDoc = userAgent.getRendererOption(NO_ASSEMBLEDOC); | |||
if (noAssembleDoc != null) { | |||
getEncryptionParams().setAllowAssembleDocument(!booleanValueOf(noAssembleDoc)); | |||
} | |||
Object noPrintHQ = userAgent.getRendererOption(NO_PRINTHQ); | |||
if (noPrintHQ != null) { | |||
getEncryptionParams().setAllowPrintHq(!booleanValueOf(noPrintHQ)); | |||
} | |||
String s = (String) userAgent.getRendererOption(PDF_A_MODE); | |||
if (s != null) { | |||
this.pdfAMode = PDFAMode.getValueOf(s); | |||
} | |||
if (this.pdfAMode.isPDFA1LevelA()) { | |||
rendererConfig = PDFRendererOptionsConfig.DEFAULT.merge(createFromUserAgent(userAgent)); | |||
if (rendererConfig.getPDFAMode().isPDFA1LevelA()) { | |||
//Enable accessibility if PDF/A-1a is enabled because it requires tagged PDF. | |||
userAgent.getRendererOptions().put(Accessibility.ACCESSIBILITY, Boolean.TRUE); | |||
} | |||
s = (String) userAgent.getRendererOption(PDF_X_MODE); | |||
if (s != null) { | |||
this.pdfXMode = PDFXMode.getValueOf(s); | |||
} | |||
s = (String) userAgent.getRendererOption(OUTPUT_PROFILE); | |||
if (s != null) { | |||
this.outputProfileURI = URI.create(s); | |||
} | |||
Object disableSRGBColorSpace = userAgent.getRendererOption(DISABLE_SRGB_COLORSPACE); | |||
if (disableSRGBColorSpace != null) { | |||
this.disableSRGBColorSpace = booleanValueOf(disableSRGBColorSpace); | |||
} | |||
} | |||
public FOUserAgent getUserAgent() { | |||
return this.userAgent; | |||
} | |||
/** | |||
* Sets the PDF/A mode for the PDF renderer. | |||
* @param mode the PDF/A mode | |||
*/ | |||
public void setAMode(PDFAMode mode) { | |||
this.pdfAMode = mode; | |||
} | |||
/** | |||
* Sets the PDF/X mode for the PDF renderer. | |||
* @param mode the PDF/X mode | |||
*/ | |||
public void setXMode(PDFXMode mode) { | |||
this.pdfXMode = mode; | |||
} | |||
/** | |||
* Sets the output color profile for the PDF renderer. | |||
* @param outputProfileURI the URI to the output color profile | |||
*/ | |||
public void setOutputProfileURI(URI outputProfileURI) { | |||
this.outputProfileURI = outputProfileURI; | |||
} | |||
/** | |||
* Enables or disables the default sRGB color space needed for the PDF document to preserve | |||
* the sRGB colors used in XSL-FO. | |||
* @param disable true to disable, false to enable | |||
*/ | |||
public void setDisableSRGBColorSpace(boolean disable) { | |||
this.disableSRGBColorSpace = disable; | |||
} | |||
/** | |||
* Sets the filter map to be used by the PDF renderer. | |||
* @param filterMap the filter map | |||
*/ | |||
public void setFilterMap(Map filterMap) { | |||
this.filterMap = filterMap; | |||
private static PDFRendererOptionsConfig createFromUserAgent(FOUserAgent userAgent) { | |||
Map<PDFRendererOption, Object> properties | |||
= new EnumMap<PDFRendererOption, Object>(PDFRendererOption.class); | |||
for (PDFRendererOption option : PDFRendererOption.values()) { | |||
Object value = userAgent.getRendererOption(option); | |||
properties.put(option, option.parse(value)); | |||
} | |||
PDFEncryptionParams encryptionConfig = new EncryptionParamsBuilder().createParams(userAgent); | |||
return new PDFRendererOptionsConfig(properties, encryptionConfig); | |||
} | |||
/** | |||
* Gets the encryption parameters used by the PDF renderer. | |||
* @return encryptionParams the encryption parameters | |||
*/ | |||
PDFEncryptionParams getEncryptionParams() { | |||
if (this.encryptionParams == null) { | |||
this.encryptionParams = new PDFEncryptionParams(); | |||
} | |||
return this.encryptionParams; | |||
void mergeRendererOptionsConfig(PDFRendererOptionsConfig config) { | |||
rendererConfig = rendererConfig.merge(config); | |||
} | |||
private void updateInfo() { | |||
@@ -271,15 +141,15 @@ class PDFRenderingUtil { | |||
} | |||
private void updatePDFProfiles() { | |||
pdfDoc.getProfile().setPDFAMode(this.pdfAMode); | |||
pdfDoc.getProfile().setPDFXMode(this.pdfXMode); | |||
pdfDoc.getProfile().setPDFAMode(rendererConfig.getPDFAMode()); | |||
pdfDoc.getProfile().setPDFXMode(rendererConfig.getPDFXMode()); | |||
} | |||
private void addsRGBColorSpace() throws IOException { | |||
if (disableSRGBColorSpace) { | |||
if (this.pdfAMode != PDFAMode.DISABLED | |||
|| this.pdfXMode != PDFXMode.DISABLED | |||
|| this.outputProfileURI != null) { | |||
if (rendererConfig.getDisableSRGBColorSpace()) { | |||
if (rendererConfig.getPDFAMode() != PDFAMode.DISABLED | |||
|| rendererConfig.getPDFXMode() != PDFXMode.DISABLED | |||
|| rendererConfig.getOutputProfileURI() != null) { | |||
throw new IllegalStateException("It is not possible to disable the sRGB color" | |||
+ " space if PDF/A or PDF/X functionality is enabled or an" | |||
+ " output profile is set!"); | |||
@@ -299,9 +169,10 @@ class PDFRenderingUtil { | |||
} | |||
ICC_Profile profile; | |||
InputStream in = null; | |||
if (this.outputProfileURI != null) { | |||
URI outputProfileUri = rendererConfig.getOutputProfileURI(); | |||
if (outputProfileUri != null) { | |||
this.outputProfile = pdfDoc.getFactory().makePDFICCStream(); | |||
in = getUserAgent().getResourceResolver().getResource(outputProfileURI); | |||
in = userAgent.getResourceResolver().getResource(rendererConfig.getOutputProfileURI()); | |||
try { | |||
profile = ColorProfileUtil.getICC_Profile(in); | |||
} finally { | |||
@@ -386,7 +257,7 @@ class PDFRenderingUtil { | |||
} | |||
String producer = userAgent.getProducer() != null ? userAgent.getProducer() : ""; | |||
final Version maxPDFVersion = rendererConfig.getPDFVersion(); | |||
if (maxPDFVersion == null) { | |||
this.pdfDoc = new PDFDocument(producer); | |||
} else { | |||
@@ -396,22 +267,24 @@ class PDFRenderingUtil { | |||
} | |||
updateInfo(); | |||
updatePDFProfiles(); | |||
pdfDoc.setFilterMap(filterMap); | |||
pdfDoc.setFilterMap(rendererConfig.getFilterMap()); | |||
pdfDoc.outputHeader(out); | |||
//Setup encryption if necessary | |||
PDFEncryptionManager.setupPDFEncryption(encryptionParams, pdfDoc); | |||
PDFEncryptionManager.setupPDFEncryption(rendererConfig.getEncryptionParameters(), pdfDoc); | |||
addsRGBColorSpace(); | |||
if (this.outputProfileURI != null) { | |||
if (rendererConfig.getOutputProfileURI() != null) { | |||
addDefaultOutputProfile(); | |||
} | |||
PDFXMode pdfXMode = rendererConfig.getPDFXMode(); | |||
if (pdfXMode != PDFXMode.DISABLED) { | |||
log.debug(pdfXMode + " is active."); | |||
log.warn("Note: " + pdfXMode | |||
+ " support is work-in-progress and not fully implemented, yet!"); | |||
addPDFXOutputIntent(); | |||
} | |||
PDFAMode pdfAMode = rendererConfig.getPDFAMode(); | |||
if (pdfAMode.isPDFA1LevelB()) { | |||
log.debug("PDF/A is active. Conformance Level: " + pdfAMode); | |||
addPDFA1OutputIntent(); | |||
@@ -467,7 +340,7 @@ class PDFRenderingUtil { | |||
} catch (URISyntaxException use) { | |||
throw new RuntimeException(use); | |||
} | |||
InputStream in = getUserAgent().getResourceResolver().getResource(srcURI); | |||
InputStream in = userAgent.getResourceResolver().getResource(srcURI); | |||
if (in == null) { | |||
throw new FileNotFoundException(embeddedFile.getSrc()); | |||
} | |||
@@ -507,14 +380,72 @@ class PDFRenderingUtil { | |||
nameArray.add(new PDFReference(fileSpec)); | |||
} | |||
/** | |||
* Sets the PDF version of the output document. See {@link Version} for the format of | |||
* <code>version</code>. | |||
* @param version the PDF version | |||
* @throws IllegalArgumentException if the format of version doesn't conform to that specified | |||
* by {@link Version} | |||
*/ | |||
public void setPDFVersion(Version version) { | |||
maxPDFVersion = version; | |||
private static final class EncryptionParamsBuilder { | |||
private PDFEncryptionParams params; | |||
private EncryptionParamsBuilder() { | |||
} | |||
private PDFEncryptionParams createParams(FOUserAgent userAgent) { | |||
params = (PDFEncryptionParams) userAgent.getRendererOptions().get(ENCRYPTION_PARAMS); | |||
String userPassword = (String) userAgent.getRendererOption(USER_PASSWORD); | |||
if (userPassword != null) { | |||
getEncryptionParams().setUserPassword(userPassword); | |||
} | |||
String ownerPassword = (String) userAgent.getRendererOption(OWNER_PASSWORD); | |||
if (ownerPassword != null) { | |||
getEncryptionParams().setOwnerPassword(ownerPassword); | |||
} | |||
Object noPrint = userAgent.getRendererOption(NO_PRINT); | |||
if (noPrint != null) { | |||
getEncryptionParams().setAllowPrint(!booleanValueOf(noPrint)); | |||
} | |||
Object noCopyContent = userAgent.getRendererOption(NO_COPY_CONTENT); | |||
if (noCopyContent != null) { | |||
getEncryptionParams().setAllowCopyContent(!booleanValueOf(noCopyContent)); | |||
} | |||
Object noEditContent = userAgent.getRendererOption(NO_EDIT_CONTENT); | |||
if (noEditContent != null) { | |||
getEncryptionParams().setAllowEditContent(!booleanValueOf(noEditContent)); | |||
} | |||
Object noAnnotations = userAgent.getRendererOption(NO_ANNOTATIONS); | |||
if (noAnnotations != null) { | |||
getEncryptionParams().setAllowEditAnnotations(!booleanValueOf(noAnnotations)); | |||
} | |||
Object noFillInForms = userAgent.getRendererOption(NO_FILLINFORMS); | |||
if (noFillInForms != null) { | |||
getEncryptionParams().setAllowFillInForms(!booleanValueOf(noFillInForms)); | |||
} | |||
Object noAccessContent = userAgent.getRendererOption(NO_ACCESSCONTENT); | |||
if (noAccessContent != null) { | |||
getEncryptionParams().setAllowAccessContent(!booleanValueOf(noAccessContent)); | |||
} | |||
Object noAssembleDoc = userAgent.getRendererOption(NO_ASSEMBLEDOC); | |||
if (noAssembleDoc != null) { | |||
getEncryptionParams().setAllowAssembleDocument(!booleanValueOf(noAssembleDoc)); | |||
} | |||
Object noPrintHQ = userAgent.getRendererOption(NO_PRINTHQ); | |||
if (noPrintHQ != null) { | |||
getEncryptionParams().setAllowPrintHq(!booleanValueOf(noPrintHQ)); | |||
} | |||
return params; | |||
} | |||
private PDFEncryptionParams getEncryptionParams() { | |||
if (params == null) { | |||
params = new PDFEncryptionParams(); | |||
} | |||
return params; | |||
} | |||
private static boolean booleanValueOf(Object obj) { | |||
if (obj instanceof Boolean) { | |||
return ((Boolean)obj).booleanValue(); | |||
} else if (obj instanceof String) { | |||
return Boolean.valueOf((String)obj).booleanValue(); | |||
} else { | |||
throw new IllegalArgumentException("Boolean or \"true\" or \"false\" expected."); | |||
} | |||
} | |||
} | |||
} |
@@ -35,20 +35,20 @@ import org.apache.fop.fonts.DefaultFontConfig.DefaultFontConfigParser; | |||
import org.apache.fop.render.RendererConfig; | |||
import org.apache.fop.util.LogUtil; | |||
import static org.apache.fop.render.ps.PSRendererConfigurationOption.AUTO_ROTATE_LANDSCAPE; | |||
import static org.apache.fop.render.ps.PSRendererConfigurationOption.DSC_COMPLIANT; | |||
import static org.apache.fop.render.ps.PSRendererConfigurationOption.LANGUAGE_LEVEL; | |||
import static org.apache.fop.render.ps.PSRendererConfigurationOption.OPTIMIZE_RESOURCES; | |||
import static org.apache.fop.render.ps.PSRendererConfigurationOption.RENDERING_MODE; | |||
import static org.apache.fop.render.ps.PSRendererConfigurationOption.SAFE_SET_PAGE_DEVICE; | |||
import static org.apache.fop.render.ps.PSRendererOption.AUTO_ROTATE_LANDSCAPE; | |||
import static org.apache.fop.render.ps.PSRendererOption.DSC_COMPLIANT; | |||
import static org.apache.fop.render.ps.PSRendererOption.LANGUAGE_LEVEL; | |||
import static org.apache.fop.render.ps.PSRendererOption.OPTIMIZE_RESOURCES; | |||
import static org.apache.fop.render.ps.PSRendererOption.RENDERING_MODE; | |||
import static org.apache.fop.render.ps.PSRendererOption.SAFE_SET_PAGE_DEVICE; | |||
/** | |||
* The PostScript renderer configuration data object. | |||
*/ | |||
public final class PSRendererConfig implements RendererConfig { | |||
private final EnumMap<PSRendererConfigurationOption, Object> params | |||
= new EnumMap<PSRendererConfigurationOption, Object>(PSRendererConfigurationOption.class); | |||
private final EnumMap<PSRendererOption, Object> params | |||
= new EnumMap<PSRendererOption, Object>(PSRendererOption.class); | |||
private final DefaultFontConfig fontConfig; | |||
@@ -132,12 +132,12 @@ public final class PSRendererConfig implements RendererConfig { | |||
} | |||
} | |||
private void setConfigParameter(PSRendererConfigurationOption option, | |||
private void setConfigParameter(PSRendererOption option, | |||
Object value) { | |||
config.params.put(option, value != null ? value : option.getDefaultValue()); | |||
} | |||
private void setBoolConfigParam(Configuration cfg, PSRendererConfigurationOption option) { | |||
private void setBoolConfigParam(Configuration cfg, PSRendererOption option) { | |||
setConfigParameter(option, cfg.getChild( | |||
option.getName()).getValueAsBoolean((Boolean) option.getDefaultValue())); | |||
} |
@@ -26,7 +26,7 @@ import org.apache.fop.render.RendererConfigOption; | |||
/** | |||
* An enumeration of the PostScript renderer configuration options along with their default values. | |||
*/ | |||
public enum PSRendererConfigurationOption implements RendererConfigOption { | |||
public enum PSRendererOption implements RendererConfigOption { | |||
/** Indicates whether landscape pages should be rotated, default: false */ | |||
AUTO_ROTATE_LANDSCAPE("auto-rotate-landscape", false), | |||
/** Sets the PostScript language leven, default: {@see PSGenerator#DEFAULT_LANGUAGE_LEVEL}*/ | |||
@@ -42,7 +42,7 @@ public enum PSRendererConfigurationOption implements RendererConfigOption { | |||
private final String name; | |||
private final Object defaultValue; | |||
private PSRendererConfigurationOption(String name, Object defaultValue) { | |||
private PSRendererOption(String name, Object defaultValue) { | |||
this.name = name; | |||
this.defaultValue = defaultValue; | |||
} |
@@ -33,9 +33,9 @@ import org.apache.fop.render.ps.extensions.PSCommentBefore; | |||
import org.apache.fop.render.ps.extensions.PSExtensionAttachment; | |||
import org.apache.fop.render.ps.extensions.PSSetupCode; | |||
import static org.apache.fop.render.ps.PSRendererConfigurationOption.AUTO_ROTATE_LANDSCAPE; | |||
import static org.apache.fop.render.ps.PSRendererConfigurationOption.LANGUAGE_LEVEL; | |||
import static org.apache.fop.render.ps.PSRendererConfigurationOption.OPTIMIZE_RESOURCES; | |||
import static org.apache.fop.render.ps.PSRendererOption.AUTO_ROTATE_LANDSCAPE; | |||
import static org.apache.fop.render.ps.PSRendererOption.LANGUAGE_LEVEL; | |||
import static org.apache.fop.render.ps.PSRendererOption.OPTIMIZE_RESOURCES; | |||
/** | |||
* Utility class which enables all sorts of features that are not directly connected to the |
@@ -52,7 +52,7 @@ import org.apache.fop.util.CharUtilities; | |||
import org.apache.fop.util.HexEncoder; | |||
/** | |||
* Renders the attributed character iterator of a text node. | |||
* Renders the attributed character iterator of a {@link org.apache.batik.gvt.TextNode TextNode}. | |||
* This class draws the text directly using PostScript text operators so | |||
* the text is not drawn using shapes which makes the PS files larger. | |||
* <p> |
@@ -0,0 +1,101 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
/* $Id$ */ | |||
package org.apache.fop.render.ps.fonts; | |||
import java.io.IOException; | |||
import org.apache.xmlgraphics.ps.PSGenerator; | |||
import org.apache.xmlgraphics.util.io.ASCIIHexOutputStream; | |||
/** | |||
* This is a wrapper for {@link PSGenerator} that contains some members specific for streaming | |||
* TrueType fonts to a PostScript document. | |||
*/ | |||
public class PSTTFGenerator { | |||
private PSGenerator gen; | |||
private ASCIIHexOutputStream hexOut; | |||
/** | |||
* The buffer is used to store the font file in an array of hex-encoded strings. Strings are | |||
* limited to 65535 characters, string will start with a newline, 2 characters are needed to | |||
* hex-encode each byte. | |||
*/ | |||
public static final int MAX_BUFFER_SIZE = 32764; | |||
/** | |||
* Creates a new instance wrapping the given generator. | |||
* @param gen the PSGenerator to wrap | |||
*/ | |||
public PSTTFGenerator(PSGenerator gen) { | |||
this.gen = gen; | |||
hexOut = new ASCIIHexOutputStream(gen.getOutputStream()); | |||
} | |||
/** | |||
* Writes the '<' character that starts a string. | |||
*/ | |||
public void startString() throws IOException { | |||
// We need to reset the streamer so that it starts a new line in the PS document | |||
hexOut = new ASCIIHexOutputStream(gen.getOutputStream()); | |||
gen.writeln("<"); | |||
} | |||
/** | |||
* Writes the given string to the output. | |||
* @param cmd a string | |||
*/ | |||
public void write(String cmd) throws IOException { | |||
gen.write(cmd); | |||
} | |||
/** | |||
* Writes the given string to the output, followed by a newline. | |||
* @param cmd a string | |||
*/ | |||
public void writeln(String cmd) throws IOException { | |||
gen.writeln(cmd); | |||
} | |||
/** | |||
* Writes bytes from the given byte array to the output. | |||
* | |||
* @param byteArray byte[] a byte array | |||
* @param offset the position in the byte array where the streaming must start | |||
* @param length the number of bytes to stream. This MUST be less than | |||
* {@link #MAX_BUFFER_SIZE} - 1 since strings are suffixed by '00' (see Section 4.2 of | |||
* Adobe Technical Note #5012, <em>The Type 42 Font Format Specification</em>.). | |||
*/ | |||
public void streamBytes(byte[] byteArray, int offset, int length) throws IOException { | |||
if (length > MAX_BUFFER_SIZE) { | |||
throw new UnsupportedOperationException("Attempting to write a string to a PostScript" | |||
+ " file that is greater than the buffer size."); | |||
} | |||
hexOut.write(byteArray, offset, length); | |||
} | |||
/** | |||
* Finishes writing a string by appending '00' and '>' to the end. | |||
*/ | |||
public void endString() throws IOException { | |||
/* Appends a '00' to the end of the string as specified in the spec */ | |||
gen.write("00\n> "); | |||
} | |||
} |
@@ -0,0 +1,75 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
/* $Id$ */ | |||
package org.apache.fop.render.ps.fonts; | |||
import java.io.IOException; | |||
import org.apache.fop.fonts.truetype.TTFGlyphOutputStream; | |||
/** | |||
* Streams glyphs in accordance with the constraints of the PostScript file format. | |||
* Mainly, PostScript strings have a limited capacity and the font data may have to be | |||
* broken down into several strings; however, this must occur at well-defined places like | |||
* table or glyph boundaries. See also Adobe Technical Note #5012, <em>The Type 42 Font | |||
* Format Specification</em>. | |||
*/ | |||
public class PSTTFGlyphOutputStream implements TTFGlyphOutputStream { | |||
/** Total number of bytes written so far. */ | |||
private int byteCounter; | |||
private int lastStringBoundary; | |||
private PSTTFGenerator ttfGen; | |||
/** | |||
* Constructor | |||
* @param ttfGen PSTTFGenerator | |||
*/ | |||
public PSTTFGlyphOutputStream(PSTTFGenerator ttfGen) { | |||
this.ttfGen = ttfGen; | |||
} | |||
public void startGlyphStream() throws IOException { | |||
ttfGen.startString(); | |||
} | |||
public void streamGlyph(byte[] glyphData, int offset, int size) throws IOException { | |||
if (size > PSTTFGenerator.MAX_BUFFER_SIZE) { | |||
throw new UnsupportedOperationException("The glyph is " + size | |||
+ " bytes. There may be an error in the font file."); | |||
} | |||
if (size + (byteCounter - lastStringBoundary) < PSTTFGenerator.MAX_BUFFER_SIZE) { | |||
ttfGen.streamBytes(glyphData, offset, size); | |||
} else { | |||
ttfGen.endString(); | |||
lastStringBoundary = byteCounter; | |||
ttfGen.startString(); | |||
ttfGen.streamBytes(glyphData, offset, size); | |||
} | |||
byteCounter += size; | |||
} | |||
public void endGlyphStream() throws IOException { | |||
ttfGen.endString(); | |||
} | |||
} |
@@ -0,0 +1,62 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
/* $Id$ */ | |||
package org.apache.fop.render.ps.fonts; | |||
import java.io.IOException; | |||
import org.apache.xmlgraphics.ps.PSGenerator; | |||
import org.apache.fop.fonts.truetype.TTFGlyphOutputStream; | |||
import org.apache.fop.fonts.truetype.TTFOutputStream; | |||
import org.apache.fop.fonts.truetype.TTFTableOutputStream; | |||
/** | |||
* Streams a TrueType font according to the PostScript format. | |||
*/ | |||
public class PSTTFOutputStream implements TTFOutputStream { | |||
private final PSTTFGenerator ttfGen; | |||
/** | |||
* Creates a new instance wrapping the given generator. | |||
* | |||
* @param gen the generator to wrap | |||
*/ | |||
public PSTTFOutputStream(PSGenerator gen) { | |||
this.ttfGen = new PSTTFGenerator(gen); | |||
} | |||
public void startFontStream() throws IOException { | |||
ttfGen.write("/sfnts["); | |||
} | |||
public TTFTableOutputStream getTableOutputStream() { | |||
return new PSTTFTableOutputStream(ttfGen); | |||
} | |||
public TTFGlyphOutputStream getGlyphOutputStream() { | |||
return new PSTTFGlyphOutputStream(ttfGen); | |||
} | |||
public void endFontStream() throws IOException { | |||
ttfGen.writeln("] def"); | |||
} | |||
} |
@@ -0,0 +1,59 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
/* $Id$ */ | |||
package org.apache.fop.render.ps.fonts; | |||
import java.io.IOException; | |||
import org.apache.fop.fonts.truetype.TTFTableOutputStream; | |||
/** | |||
* Streams a TrueType table according to the PostScript format. | |||
*/ | |||
public class PSTTFTableOutputStream implements TTFTableOutputStream { | |||
private PSTTFGenerator ttfGen; | |||
/** | |||
* Constructor. | |||
* @param ttfGen the helper object to stream TrueType data | |||
*/ | |||
public PSTTFTableOutputStream(PSTTFGenerator ttfGen) { | |||
this.ttfGen = ttfGen; | |||
} | |||
public void streamTable(byte[] ttfData, int offset, int size) throws IOException { | |||
int offsetPosition = offset; | |||
// Need to split the table into MAX_BUFFER_SIZE chunks | |||
for (int i = 0; i < size / PSTTFGenerator.MAX_BUFFER_SIZE; i++) { | |||
streamString(ttfData, offsetPosition, PSTTFGenerator.MAX_BUFFER_SIZE); | |||
offsetPosition += PSTTFGenerator.MAX_BUFFER_SIZE; | |||
} | |||
if (size % PSTTFGenerator.MAX_BUFFER_SIZE > 0) { | |||
streamString(ttfData, offsetPosition, size % PSTTFGenerator.MAX_BUFFER_SIZE); | |||
} | |||
} | |||
private void streamString(byte[] byteArray, int offset, int length) throws IOException { | |||
ttfGen.startString(); | |||
ttfGen.streamBytes(byteArray, offset, length); | |||
ttfGen.endString(); | |||
} | |||
} |
@@ -36,13 +36,13 @@ import org.apache.fop.render.RendererConfigOption; | |||
*/ | |||
public final class TxtRendererConfig implements RendererConfig { | |||
public enum TxtRendererConfigOption implements RendererConfigOption { | |||
public enum TxtRendererOption implements RendererConfigOption { | |||
ENCODING("encoding", "UTF-8"); | |||
private final String name; | |||
private final Object defaultValue; | |||
private TxtRendererConfigOption(String name, Object defaultValue) { | |||
private TxtRendererOption(String name, Object defaultValue) { | |||
this.name = name; | |||
this.defaultValue = defaultValue; | |||
} | |||
@@ -56,8 +56,8 @@ public final class TxtRendererConfig implements RendererConfig { | |||
} | |||
} | |||
private final EnumMap<TxtRendererConfigOption, Object> params | |||
= new EnumMap<TxtRendererConfigOption, Object>(TxtRendererConfigOption.class); | |||
private final EnumMap<TxtRendererOption, Object> params | |||
= new EnumMap<TxtRendererOption, Object>(TxtRendererOption.class); | |||
private final DefaultFontConfig fontConfig; | |||
@@ -70,7 +70,7 @@ public final class TxtRendererConfig implements RendererConfig { | |||
} | |||
public String getEncoding() { | |||
return (String) params.get(TxtRendererConfigOption.ENCODING); | |||
return (String) params.get(TxtRendererOption.ENCODING); | |||
} | |||
/** | |||
@@ -83,7 +83,7 @@ public final class TxtRendererConfig implements RendererConfig { | |||
TxtRendererConfig config = new TxtRendererConfig(new DefaultFontConfigParser().parse(cfg, | |||
userAgent.validateStrictly())); | |||
if (cfg != null) { | |||
TxtRendererConfigOption option = TxtRendererConfigOption.ENCODING; | |||
TxtRendererOption option = TxtRendererOption.ENCODING; | |||
String value = cfg.getChild(option.getName(), true).getValue(null); | |||
config.params.put(option, value != null ? value : option.getDefaultValue()); | |||
} |
@@ -61,7 +61,7 @@ public class PDFDocumentGraphics2DConfigurator { | |||
try { | |||
//Filter map | |||
PDFRendererConfig pdfConfig = new PDFRendererConfigParser().build(null, cfg); | |||
pdfDoc.setFilterMap(pdfConfig.getFilterMap()); | |||
pdfDoc.setFilterMap(pdfConfig.getConfigOptions().getFilterMap()); | |||
} catch (FOPException e) { | |||
throw new RuntimeException(e); | |||
} |
@@ -31,7 +31,6 @@ import org.apache.fop.afp.modca.IncludeObjectTestCase; | |||
@RunWith(Suite.class) | |||
@SuiteClasses({ | |||
IncludeObjectTestCase.class, | |||
AFPResourceUtilTestCase.class, | |||
AFPObjectAreaInfoTestCase.class, | |||
AFPPaintingStateTestCase.class | |||
}) |
@@ -25,25 +25,25 @@ import org.w3c.dom.Element; | |||
import org.apache.fop.apps.FopConfBuilder.RendererConfBuilder; | |||
import org.apache.fop.render.afp.AFPRendererConfig; | |||
import org.apache.fop.render.afp.AFPRendererConfigOption; | |||
import org.apache.fop.render.afp.AFPRendererOption; | |||
import org.apache.fop.render.afp.AFPShadingMode; | |||
import static org.apache.fop.render.afp.AFPRendererConfig.ImagesModeOptions.MODE_GRAYSCALE; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.DEFAULT_RESOURCE_LEVELS; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.IMAGES; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.IMAGES_DITHERING_QUALITY; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.IMAGES_FS45; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.IMAGES_JPEG; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.IMAGES_MAPPING_OPTION; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.IMAGES_MODE; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.IMAGES_NATIVE; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.IMAGES_WRAP_PSEG; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.JPEG_ALLOW_JPEG_EMBEDDING; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.JPEG_BITMAP_ENCODING_QUALITY; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.LINE_WIDTH_CORRECTION; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.RENDERER_RESOLUTION; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.RESOURCE_GROUP_URI; | |||
import static org.apache.fop.render.afp.AFPRendererConfigOption.SHADING; | |||
import static org.apache.fop.render.afp.AFPRendererOption.DEFAULT_RESOURCE_LEVELS; | |||
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES; | |||
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_DITHERING_QUALITY; | |||
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_FS45; | |||
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_JPEG; | |||
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_MAPPING_OPTION; | |||
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_MODE; | |||
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_NATIVE; | |||
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_WRAP_PSEG; | |||
import static org.apache.fop.render.afp.AFPRendererOption.JPEG_ALLOW_JPEG_EMBEDDING; | |||
import static org.apache.fop.render.afp.AFPRendererOption.JPEG_BITMAP_ENCODING_QUALITY; | |||
import static org.apache.fop.render.afp.AFPRendererOption.LINE_WIDTH_CORRECTION; | |||
import static org.apache.fop.render.afp.AFPRendererOption.RENDERER_RESOLUTION; | |||
import static org.apache.fop.render.afp.AFPRendererOption.RESOURCE_GROUP_URI; | |||
import static org.apache.fop.render.afp.AFPRendererOption.SHADING; | |||
/** | |||
* A config builder specific to a particular renderer for specific MIME type. | |||
@@ -56,7 +56,7 @@ public final class AFPRendererConfBuilder extends RendererConfBuilder { | |||
super(MimeConstants.MIME_AFP); | |||
} | |||
private AFPRendererConfBuilder createTextElement(AFPRendererConfigOption option, String value) { | |||
private AFPRendererConfBuilder createTextElement(AFPRendererOption option, String value) { | |||
createTextElement(option.getName(), value); | |||
return this; | |||
} | |||
@@ -153,7 +153,11 @@ public final class AFPRendererConfBuilder extends RendererConfBuilder { | |||
return AFPRendererConfBuilder.this.endImages(); | |||
} | |||
private ImagesBuilder setAttribute(AFPRendererConfigOption options, Object value) { | |||
private ImagesBuilder setAttribute(AFPRendererOption options, String value) { | |||
return setAttribute(options.getName(), value); | |||
} | |||
private ImagesBuilder setAttribute(AFPRendererOption options, Object value) { | |||
return setAttribute(options.getName(), value); | |||
} | |||
@@ -21,11 +21,11 @@ package org.apache.fop.apps; | |||
import org.apache.fop.apps.FopConfBuilder.RendererConfBuilder; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.ANTI_ALIASING; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.BACKGROUND_COLOR; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.COLOR_MODE; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.JAVA2D_TRANSPARENT_PAGE_BACKGROUND; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.RENDERING_QUALITY_ELEMENT; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.ANTI_ALIASING; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.BACKGROUND_COLOR; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.JAVA2D_TRANSPARENT_PAGE_BACKGROUND; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.RENDERING_QUALITY_ELEMENT; | |||
public class BitmapRendererConfBuilder extends RendererConfBuilder { | |||
@@ -22,19 +22,21 @@ package org.apache.fop.apps; | |||
import org.w3c.dom.Element; | |||
import org.apache.fop.apps.FopConfBuilder.RendererConfBuilder; | |||
import org.apache.fop.pdf.PDFEncryptionParams; | |||
import org.apache.fop.render.RendererConfigOption; | |||
import org.apache.fop.render.pdf.PDFRendererConfigOption; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.DISABLE_SRGB_COLORSPACE; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.ENCRYPTION_LENGTH; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.ENCRYPTION_PARAMS; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.FILTER_LIST; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.OUTPUT_PROFILE; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.OWNER_PASSWORD; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.PDF_A_MODE; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.PDF_X_MODE; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.USER_PASSWORD; | |||
import static org.apache.fop.render.pdf.PDFRendererConfigOption.VERSION; | |||
import org.apache.fop.render.pdf.PDFEncryptionOption; | |||
import org.apache.fop.render.pdf.PDFRendererOption; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.ENCRYPTION_LENGTH; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.ENCRYPTION_PARAMS; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.OWNER_PASSWORD; | |||
import static org.apache.fop.render.pdf.PDFEncryptionOption.USER_PASSWORD; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.DISABLE_SRGB_COLORSPACE; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.FILTER_LIST; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.OUTPUT_PROFILE; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.PDF_A_MODE; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.PDF_X_MODE; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.VERSION; | |||
/** | |||
* A config builder specific to a particular renderer for specific MIME type. | |||
@@ -97,7 +99,7 @@ public final class PDFRendererConfBuilder extends RendererConfBuilder { | |||
private final Element el; | |||
private EncryptionParamsBuilder() { | |||
el = createElement(ENCRYPTION_PARAMS.getName()); | |||
el = createElement(ENCRYPTION_PARAMS); | |||
} | |||
public EncryptionParamsBuilder setEncryptionLength(int length) { | |||
@@ -115,7 +117,7 @@ public final class PDFRendererConfBuilder extends RendererConfBuilder { | |||
return this; | |||
} | |||
public EncryptionParamsBuilder setAllowParam(PDFRendererConfigOption option) { | |||
public EncryptionParamsBuilder setAllowParam(PDFEncryptionOption option) { | |||
el.appendChild(createElement(option.getName())); | |||
return this; | |||
} |
@@ -21,11 +21,11 @@ package org.apache.fop.apps; | |||
import org.apache.fop.apps.FopConfBuilder.RendererConfBuilder; | |||
import static org.apache.fop.render.ps.PSRendererConfigurationOption.AUTO_ROTATE_LANDSCAPE; | |||
import static org.apache.fop.render.ps.PSRendererConfigurationOption.DSC_COMPLIANT; | |||
import static org.apache.fop.render.ps.PSRendererConfigurationOption.LANGUAGE_LEVEL; | |||
import static org.apache.fop.render.ps.PSRendererConfigurationOption.OPTIMIZE_RESOURCES; | |||
import static org.apache.fop.render.ps.PSRendererConfigurationOption.SAFE_SET_PAGE_DEVICE; | |||
import static org.apache.fop.render.ps.PSRendererOption.AUTO_ROTATE_LANDSCAPE; | |||
import static org.apache.fop.render.ps.PSRendererOption.DSC_COMPLIANT; | |||
import static org.apache.fop.render.ps.PSRendererOption.LANGUAGE_LEVEL; | |||
import static org.apache.fop.render.ps.PSRendererOption.OPTIMIZE_RESOURCES; | |||
import static org.apache.fop.render.ps.PSRendererOption.SAFE_SET_PAGE_DEVICE; | |||
/** | |||
* A fop conf builder specific to a particular renderer for Postscript. |
@@ -19,7 +19,7 @@ | |||
package org.apache.fop.apps; | |||
import static org.apache.fop.render.bitmap.TIFFRendererConfig.TIFFRendererConfigOption.COMPRESSION; | |||
import static org.apache.fop.render.bitmap.TIFFRendererConfig.TIFFRendererOption.COMPRESSION; | |||
public class TIFFRendererConfBuilder extends BitmapRendererConfBuilder { | |||
@@ -21,7 +21,7 @@ package org.apache.fop.apps; | |||
import org.apache.fop.apps.FopConfBuilder.RendererConfBuilder; | |||
import static org.apache.fop.render.txt.TxtRendererConfig.TxtRendererConfigOption.ENCODING; | |||
import static org.apache.fop.render.txt.TxtRendererConfig.TxtRendererOption.ENCODING; | |||
public class TxtRendererConfBuilder extends RendererConfBuilder { | |||
@@ -28,14 +28,14 @@ import org.apache.fop.apps.AbstractRendererConfigParserTester; | |||
import org.apache.fop.apps.BitmapRendererConfBuilder; | |||
import org.apache.fop.render.bitmap.BitmapRendererConfig.BitmapRendererConfigParser; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.COLOR_MODE_BILEVEL; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.COLOR_MODE_BINARY; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.COLOR_MODE_GRAY; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.COLOR_MODE_RGB; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.COLOR_MODE_RGBA; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.JAVA2D_TRANSPARENT_PAGE_BACKGROUND; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.RENDERING_QUALITY; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.RENDERING_SPEED; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE_BILEVEL; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE_BINARY; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE_GRAY; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE_RGB; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE_RGBA; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.JAVA2D_TRANSPARENT_PAGE_BACKGROUND; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.RENDERING_QUALITY; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.RENDERING_SPEED; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertNull; |
@@ -28,13 +28,13 @@ import org.apache.fop.apps.BitmapRendererConfBuilder; | |||
import org.apache.fop.render.intermediate.IFDocumentHandler; | |||
import org.apache.fop.util.ColorUtil; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.COLOR_MODE_BILEVEL; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.COLOR_MODE_BINARY; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.COLOR_MODE_GRAY; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.COLOR_MODE_RGB; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.COLOR_MODE_RGBA; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.RENDERING_QUALITY; | |||
import static org.apache.fop.render.bitmap.BitmapRendererConfigOption.RENDERING_SPEED; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE_BILEVEL; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE_BINARY; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE_GRAY; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE_RGB; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE_RGBA; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.RENDERING_QUALITY; | |||
import static org.apache.fop.render.bitmap.BitmapRendererOption.RENDERING_SPEED; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertTrue; |
@@ -23,9 +23,9 @@ package org.apache.fop.render.pcl; | |||
import org.apache.fop.apps.FopConfBuilder.RendererConfBuilder; | |||
import org.apache.fop.apps.MimeConstants; | |||
import static org.apache.fop.render.pcl.Java2DRendererConfigOption.DISABLE_PJL; | |||
import static org.apache.fop.render.pcl.Java2DRendererConfigOption.RENDERING_MODE; | |||
import static org.apache.fop.render.pcl.Java2DRendererConfigOption.TEXT_RENDERING; | |||
import static org.apache.fop.render.pcl.Java2DRendererOption.DISABLE_PJL; | |||
import static org.apache.fop.render.pcl.Java2DRendererOption.RENDERING_MODE; | |||
import static org.apache.fop.render.pcl.Java2DRendererOption.TEXT_RENDERING; | |||
/** | |||
* A config builder specific to a particular renderer for specific MIME type. | |||
*/ | |||
@@ -51,7 +51,7 @@ public final class PCLRendererConfBuilder extends RendererConfBuilder { | |||
return createTextElement(DISABLE_PJL, String.valueOf(value)); | |||
} | |||
private PCLRendererConfBuilder createTextElement(Java2DRendererConfigOption option, String value) { | |||
private PCLRendererConfBuilder createTextElement(Java2DRendererOption option, String value) { | |||
createTextElement(option.getName(), value); | |||
return this; | |||
} |
@@ -19,8 +19,6 @@ | |||
package org.apache.fop.render.pdf; | |||
import static org.junit.Assert.fail; | |||
import java.io.File; | |||
import java.io.IOException; | |||
@@ -30,6 +28,8 @@ import org.xml.sax.SAXException; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.pdf.PDFConformanceException; | |||
import static org.junit.Assert.fail; | |||
/** | |||
* Tests PDF/A-1 functionality. | |||
*/ | |||
@@ -66,17 +66,12 @@ public class PDFAConformanceTestCase extends BasePDFTest { | |||
* Test exception when PDF/A-1 is enabled together with encryption. | |||
* @throws Exception if the test fails | |||
*/ | |||
@Test | |||
@Test(expected = PDFConformanceException.class) | |||
public void testNoEncryption() throws Exception { | |||
final FOUserAgent ua = getUserAgent(); | |||
ua.getRendererOptions().put("owner-password", "mypassword"); //To enabled encryption | |||
File foFile = new File(foBaseDir, "minimal-pdf-a.fo"); | |||
try { | |||
convertFO(foFile, ua, dumpPDF); | |||
fail("Expected PDFConformanceException. PDF/A-1 and PDF encryption don't go together."); | |||
} catch (PDFConformanceException e) { | |||
//Good! | |||
} | |||
convertFO(foFile, ua, dumpPDF); | |||
} | |||
/** |
@@ -22,8 +22,6 @@ package org.apache.fop.render.pdf; | |||
import org.junit.Test; | |||
import org.apache.fop.apps.AbstractRendererConfigParserTester; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.apps.FopConfBuilder; | |||
import org.apache.fop.apps.PDFRendererConfBuilder; | |||
import org.apache.fop.pdf.PDFAMode; | |||
import org.apache.fop.pdf.PDFXMode; | |||
@@ -48,11 +46,10 @@ public class PDFRendererConfigParserTestCase | |||
.startEncryptionParams() | |||
.setUserPassword(testPassword) | |||
.endEncryptionParams()); | |||
assertEquals(testPassword, conf.getEncryptionParameters().getUserPassword()); | |||
assertEquals(testPassword, conf.getConfigOptions().getEncryptionParameters().getUserPassword()); | |||
} | |||
private void testRestrictEncryptionParameter(PDFRendererConfigOption option) | |||
throws Exception { | |||
private void testRestrictEncryptionParameter(PDFEncryptionOption option) throws Exception { | |||
parseConfig(createRenderer().startEncryptionParams() | |||
.setAllowParam(option) | |||
.endEncryptionParams()); | |||
@@ -62,24 +59,24 @@ public class PDFRendererConfigParserTestCase | |||
assertTrue(testEncryptionParameter(option)); | |||
} | |||
public boolean testEncryptionParameter(PDFRendererConfigOption option) throws Exception { | |||
public boolean testEncryptionParameter(PDFEncryptionOption option) throws Exception { | |||
switch (option) { | |||
case NO_PRINT: | |||
return conf.getEncryptionParameters().isAllowPrint(); | |||
return conf.getConfigOptions().getEncryptionParameters().isAllowPrint(); | |||
case NO_ACCESSCONTENT: | |||
return conf.getEncryptionParameters().isAllowAccessContent(); | |||
return conf.getConfigOptions().getEncryptionParameters().isAllowAccessContent(); | |||
case NO_ANNOTATIONS: | |||
return conf.getEncryptionParameters().isAllowEditAnnotations(); | |||
return conf.getConfigOptions().getEncryptionParameters().isAllowEditAnnotations(); | |||
case NO_ASSEMBLEDOC: | |||
return conf.getEncryptionParameters().isAllowAssembleDocument(); | |||
return conf.getConfigOptions().getEncryptionParameters().isAllowAssembleDocument(); | |||
case NO_COPY_CONTENT: | |||
return conf.getEncryptionParameters().isAllowCopyContent(); | |||
return conf.getConfigOptions().getEncryptionParameters().isAllowCopyContent(); | |||
case NO_EDIT_CONTENT: | |||
return conf.getEncryptionParameters().isAllowEditContent(); | |||
return conf.getConfigOptions().getEncryptionParameters().isAllowEditContent(); | |||
case NO_FILLINFORMS: | |||
return conf.getEncryptionParameters().isAllowFillInForms(); | |||
return conf.getConfigOptions().getEncryptionParameters().isAllowFillInForms(); | |||
case NO_PRINTHQ: | |||
return conf.getEncryptionParameters().isAllowPrintHq(); | |||
return conf.getConfigOptions().getEncryptionParameters().isAllowPrintHq(); | |||
default: | |||
throw new IllegalStateException("Wrong parameter given"); | |||
} | |||
@@ -88,14 +85,14 @@ public class PDFRendererConfigParserTestCase | |||
@Test | |||
public void testAllEncryptionRestrictions() throws Exception { | |||
testRestrictEncryptionParameter(PDFRendererConfigOption.NO_PRINT); | |||
testRestrictEncryptionParameter(PDFRendererConfigOption.NO_ACCESSCONTENT); | |||
testRestrictEncryptionParameter(PDFRendererConfigOption.NO_ANNOTATIONS); | |||
testRestrictEncryptionParameter(PDFRendererConfigOption.NO_ASSEMBLEDOC); | |||
testRestrictEncryptionParameter(PDFRendererConfigOption.NO_COPY_CONTENT); | |||
testRestrictEncryptionParameter(PDFRendererConfigOption.NO_EDIT_CONTENT); | |||
testRestrictEncryptionParameter(PDFRendererConfigOption.NO_FILLINFORMS); | |||
testRestrictEncryptionParameter(PDFRendererConfigOption.NO_PRINTHQ); | |||
testRestrictEncryptionParameter(PDFEncryptionOption.NO_PRINT); | |||
testRestrictEncryptionParameter(PDFEncryptionOption.NO_ACCESSCONTENT); | |||
testRestrictEncryptionParameter(PDFEncryptionOption.NO_ANNOTATIONS); | |||
testRestrictEncryptionParameter(PDFEncryptionOption.NO_ASSEMBLEDOC); | |||
testRestrictEncryptionParameter(PDFEncryptionOption.NO_COPY_CONTENT); | |||
testRestrictEncryptionParameter(PDFEncryptionOption.NO_EDIT_CONTENT); | |||
testRestrictEncryptionParameter(PDFEncryptionOption.NO_FILLINFORMS); | |||
testRestrictEncryptionParameter(PDFEncryptionOption.NO_PRINTHQ); | |||
} | |||
@Test | |||
@@ -105,47 +102,47 @@ public class PDFRendererConfigParserTestCase | |||
.startEncryptionParams() | |||
.setOwnerPassword(testPassword) | |||
.endEncryptionParams()); | |||
assertEquals(testPassword, conf.getEncryptionParameters().getOwnerPassword()); | |||
assertEquals(testPassword, conf.getConfigOptions().getEncryptionParameters().getOwnerPassword()); | |||
} | |||
@Test | |||
public void testFilterListDefaultFlate() throws Exception { | |||
parseConfig(createRenderer().createFilterList(null, "flate")); | |||
assertEquals("flate", conf.getFilterMap().get("default").get(0)); | |||
assertEquals("flate", conf.getConfigOptions().getFilterMap().get("default").get(0)); | |||
} | |||
@Test | |||
public void testFilterListDefaultNull() throws Exception { | |||
parseConfig(createRenderer().createFilterList(null, "null")); | |||
assertEquals("null", conf.getFilterMap().get("default").get(0)); | |||
assertEquals("null", conf.getConfigOptions().getFilterMap().get("default").get(0)); | |||
} | |||
@Test | |||
public void testFilterListImage() throws Exception { | |||
parseConfig(createRenderer().createFilterList("image", "flate", "ascii-85")); | |||
assertEquals("flate", conf.getFilterMap().get("image").get(0)); | |||
assertEquals("ascii-85", conf.getFilterMap().get("image").get(1)); | |||
assertEquals("flate", conf.getConfigOptions().getFilterMap().get("image").get(0)); | |||
assertEquals("ascii-85", conf.getConfigOptions().getFilterMap().get("image").get(1)); | |||
} | |||
@Test | |||
public void testPDFAMode() throws Exception { | |||
parseConfig(createRenderer().setPDFAMode(PDFAMode.PDFA_1A.getName())); | |||
assertEquals(PDFAMode.PDFA_1A, conf.getPDFAMode()); | |||
assertEquals(PDFAMode.PDFA_1A, conf.getConfigOptions().getPDFAMode()); | |||
parseConfig(createRenderer().setPDFAMode(PDFAMode.PDFA_1B.getName())); | |||
assertEquals(PDFAMode.PDFA_1B, conf.getPDFAMode()); | |||
assertEquals(PDFAMode.PDFA_1B, conf.getConfigOptions().getPDFAMode()); | |||
parseConfig(createRenderer().setPDFAMode(PDFAMode.DISABLED.getName())); | |||
assertEquals(null, conf.getPDFAMode()); | |||
assertEquals(null, conf.getConfigOptions().getPDFAMode()); | |||
} | |||
@Test | |||
public void testPDFXMode() throws Exception { | |||
parseConfig(createRenderer().setPDFXMode(PDFXMode.PDFX_3_2003.getName())); | |||
assertEquals(PDFXMode.PDFX_3_2003, conf.getPDFXMode()); | |||
assertEquals(PDFXMode.PDFX_3_2003, conf.getConfigOptions().getPDFXMode()); | |||
parseConfig(createRenderer().setPDFXMode(PDFXMode.DISABLED.getName())); | |||
assertEquals(null, conf.getPDFXMode()); | |||
assertEquals(null, conf.getConfigOptions().getPDFXMode()); | |||
} | |||
@Test | |||
@@ -155,7 +152,7 @@ public class PDFRendererConfigParserTestCase | |||
.startEncryptionParams() | |||
.setEncryptionLength(i) | |||
.endEncryptionParams()); | |||
assertEquals(40, conf.getEncryptionParameters().getEncryptionLengthInBits()); | |||
assertEquals(40, conf.getConfigOptions().getEncryptionParameters().getEncryptionLengthInBits()); | |||
} | |||
for (int i = 40; i <= 128; i++) { | |||
@@ -164,7 +161,7 @@ public class PDFRendererConfigParserTestCase | |||
.setEncryptionLength(i) | |||
.endEncryptionParams()); | |||
int expectedLen = Math.round(i / 8.0f) * 8; | |||
assertEquals(expectedLen, conf.getEncryptionParameters() | |||
assertEquals(expectedLen, conf.getConfigOptions().getEncryptionParameters() | |||
.getEncryptionLengthInBits()); | |||
} | |||
@@ -173,7 +170,7 @@ public class PDFRendererConfigParserTestCase | |||
.startEncryptionParams() | |||
.setEncryptionLength(i) | |||
.endEncryptionParams()); | |||
assertEquals(128, conf.getEncryptionParameters().getEncryptionLengthInBits()); | |||
assertEquals(128, conf.getConfigOptions().getEncryptionParameters().getEncryptionLengthInBits()); | |||
} | |||
} | |||
@@ -186,7 +183,7 @@ public class PDFRendererConfigParserTestCase | |||
private void pdfVersionTester(String version) throws Exception { | |||
parseConfig(createRenderer().setPDFVersion(version)); | |||
assertEquals(Version.getValueOf(version), conf.getPDFVersion()); | |||
assertEquals(Version.getValueOf(version), conf.getConfigOptions().getPDFVersion()); | |||
} | |||
@Test(expected = IllegalArgumentException.class) | |||
@@ -199,7 +196,7 @@ public class PDFRendererConfigParserTestCase | |||
pdfVersionTester("0.9"); | |||
} | |||
@Test(expected = FOPException.class) | |||
@Test(expected = IllegalArgumentException.class) | |||
public void testErroneousPDFVersionsNotSet() throws Exception { | |||
pdfVersionTester(""); | |||
} |
@@ -1,246 +0,0 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
/* $Id$ */ | |||
package org.apache.fop.render.pdf; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.io.OutputStream; | |||
import java.net.URI; | |||
import java.util.List; | |||
import java.util.Map; | |||
import org.junit.Test; | |||
import org.xml.sax.SAXException; | |||
import org.apache.xmlgraphics.util.MimeConstants; | |||
import org.apache.fop.apps.AbstractRendererConfiguratorTest; | |||
import org.apache.fop.apps.FopConfBuilder.RendererConfBuilder; | |||
import org.apache.fop.apps.FopFactory; | |||
import org.apache.fop.apps.PDFRendererConfBuilder; | |||
import org.apache.fop.events.Event; | |||
import org.apache.fop.events.EventListener; | |||
import org.apache.fop.pdf.PDFAMode; | |||
import org.apache.fop.pdf.PDFEncryptionParams; | |||
import org.apache.fop.pdf.PDFXMode; | |||
import org.apache.fop.pdf.Version; | |||
import org.apache.fop.render.pdf.PDFRendererConfig.PDFRendererConfigParser; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.times; | |||
import static org.mockito.Mockito.verify; | |||
import static org.mockito.Mockito.when; | |||
/** | |||
* Tests that encryption length is properly set up. | |||
*/ | |||
public class PDFRendererConfiguratorTestCase extends | |||
AbstractRendererConfiguratorTest<PDFRendererConfigurator, PDFRendererConfBuilder> { | |||
private boolean eventTriggered; | |||
private PDFRenderingUtil pdfUtil; | |||
public PDFRendererConfiguratorTestCase() { | |||
super(MimeConstants.MIME_PDF, PDFRendererConfBuilder.class, PDFDocumentHandler.class); | |||
} | |||
@Override | |||
protected PDFRendererConfigurator createConfigurator() { | |||
return new PDFRendererConfigurator(userAgent, new PDFRendererConfigParser()); | |||
} | |||
@Override | |||
public void setUpDocumentHandler() { | |||
pdfUtil = new PDFRenderingUtil(userAgent); | |||
when(((PDFDocumentHandler) docHandler).getPDFUtil()).thenReturn(pdfUtil); | |||
} | |||
private void parseConfig(RendererConfBuilder builder, EventListener listener) | |||
throws SAXException, IOException { | |||
parseConfigWithUtil(builder, listener, false); | |||
} | |||
private void parseConfigWithUtil(RendererConfBuilder builder, EventListener listener, | |||
boolean mockUtil) throws SAXException, IOException { | |||
userAgent = FopFactory.newInstance( | |||
new File(".").toURI(), builder.endRendererConfig().build()).newFOUserAgent(); | |||
userAgent.getEventBroadcaster().addEventListener(listener); | |||
if (mockUtil) { | |||
this.pdfUtil = mock(PDFRenderingUtil.class); | |||
when(((PDFDocumentHandler) docHandler).getPDFUtil()).thenReturn(pdfUtil); | |||
} else { | |||
setUpDocumentHandler(); | |||
} | |||
sut = createConfigurator(); | |||
sut.configure(docHandler); | |||
} | |||
private void parseConfigMockUtil(RendererConfBuilder builder) | |||
throws SAXException, IOException { | |||
parseConfigWithUtil(builder, null, true); | |||
} | |||
/** | |||
* Non-multiple of 8 should be rounded. | |||
* | |||
* @throws Exception if an error occurs | |||
*/ | |||
@Test | |||
public void testRoundUp() throws Exception { | |||
testEncryptionAndEvent(55, 56); | |||
} | |||
/** | |||
* Non-multiple of 8 should be rounded. | |||
* | |||
* @throws Exception if an error occurs | |||
*/ | |||
@Test | |||
public void testRoundDown() throws Exception { | |||
testEncryptionAndEvent(67, 64); | |||
} | |||
/** | |||
* Encryption length must be at least 40. | |||
* | |||
* @throws Exception if an error occurs | |||
*/ | |||
@Test | |||
public void testBelow40() throws Exception { | |||
testEncryptionAndEvent(32, 40); | |||
} | |||
/** | |||
* Encryption length must be at most 128. | |||
* | |||
* @throws Exception if an error occurs | |||
*/ | |||
@Test | |||
public void testAbove128() throws Exception { | |||
testEncryptionAndEvent(233, 128); | |||
} | |||
/** | |||
* A correct value must be properly set up. | |||
* | |||
* @throws Exception if an error occurs | |||
*/ | |||
@Test | |||
public void testCorrectValue() throws Exception { | |||
runEncryptionTest(128, 128); | |||
} | |||
private void testEncryptionAndEvent(int specifiedEncryptionLength, | |||
int actualEncryptionLength) throws Exception { | |||
runEncryptionTest(specifiedEncryptionLength, actualEncryptionLength); | |||
assertTrue(eventTriggered); | |||
} | |||
private void runEncryptionTest(int specifiedEncryptionLength, int actualEncryptionLength) | |||
throws Exception { | |||
parseConfig(createBuilder().startEncryptionParams() | |||
.setEncryptionLength(specifiedEncryptionLength) | |||
.endEncryptionParams(), | |||
new EncryptionEventFilter(specifiedEncryptionLength, actualEncryptionLength)); | |||
thenEncryptionLengthShouldBe(actualEncryptionLength); | |||
} | |||
private void thenEncryptionLengthShouldBe(int expectedEncryptionLength) { | |||
PDFEncryptionParams encryptionParams = pdfUtil.getEncryptionParams(); | |||
assertEquals(expectedEncryptionLength, encryptionParams.getEncryptionLengthInBits()); | |||
} | |||
private class EncryptionEventFilter implements EventListener { | |||
private final int specifiedEncryptionLength; | |||
private final int correctedEncryptionLength; | |||
EncryptionEventFilter(int specifiedEncryptionLength, int correctedEncryptionLength) { | |||
this.specifiedEncryptionLength = specifiedEncryptionLength; | |||
this.correctedEncryptionLength = correctedEncryptionLength; | |||
} | |||
public void processEvent(Event event) { | |||
assertEquals(PDFEventProducer.class.getName() + ".incorrectEncryptionLength", | |||
event.getEventID()); | |||
assertEquals(specifiedEncryptionLength, event.getParam("originalValue")); | |||
assertEquals(correctedEncryptionLength, event.getParam("correctedValue")); | |||
eventTriggered = true; | |||
} | |||
} | |||
@Test | |||
public void testFilterMaps() throws Exception { | |||
parseConfig(createBuilder().createFilterList("image", "flate", "ascii-85")); | |||
OutputStream outStream = mock(OutputStream.class); | |||
Map<String, List<String>> filterMap = pdfUtil.setupPDFDocument(outStream).getFilterMap(); | |||
assertEquals("flate", filterMap.get("image").get(0)); | |||
assertEquals("ascii-85", filterMap.get("image").get(1)); | |||
} | |||
@Test | |||
public void testPDFAMode() throws Exception { | |||
parseConfigMockUtil(createBuilder().setPDFAMode(PDFAMode.DISABLED.getName())); | |||
// DISABLED is the default setting, it doesn't need to be set | |||
verify(pdfUtil, times(0)).setAMode(PDFAMode.DISABLED); | |||
parseConfigMockUtil(createBuilder().setPDFAMode(PDFAMode.PDFA_1A.getName())); | |||
verify(pdfUtil, times(1)).setAMode(PDFAMode.PDFA_1A); | |||
parseConfigMockUtil(createBuilder().setPDFAMode(PDFAMode.PDFA_1B.getName())); | |||
verify(pdfUtil, times(1)).setAMode(PDFAMode.PDFA_1B); | |||
} | |||
@Test | |||
public void testPDFXMode() throws Exception { | |||
parseConfigMockUtil(createBuilder().setPDFXMode(PDFXMode.DISABLED.getName())); | |||
// DISABLED is the default setting, it doesn't need to be set | |||
verify(pdfUtil, times(0)).setXMode(PDFXMode.DISABLED); | |||
parseConfigMockUtil(createBuilder().setPDFXMode(PDFXMode.PDFX_3_2003.getName())); | |||
verify(pdfUtil, times(1)).setXMode(PDFXMode.PDFX_3_2003); | |||
} | |||
@Test | |||
public void testSetProfile() throws Exception { | |||
String testString = "this.uri.is.purely.for.testing.and.has.no.contextual.meaning"; | |||
parseConfigMockUtil(createBuilder().setOutputProfile(testString)); | |||
verify(pdfUtil).setOutputProfileURI(URI.create(testString)); | |||
} | |||
@Test | |||
public void testDisableSRGBColourspace() throws Exception { | |||
parseConfigMockUtil(createBuilder().disableSRGBColorSpace(true)); | |||
verify(pdfUtil).setDisableSRGBColorSpace(true); | |||
parseConfigMockUtil(createBuilder().disableSRGBColorSpace(false)); | |||
verify(pdfUtil, times(0)).setDisableSRGBColorSpace(false); | |||
} | |||
@Test | |||
public void testPDFVersion() throws Exception { | |||
for (Version version : Version.values()) { | |||
parseConfigMockUtil(createBuilder().setPDFVersion(version.toString())); | |||
verify(pdfUtil).setPDFVersion(version); | |||
} | |||
} | |||
} |
@@ -0,0 +1,123 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
/* $Id$ */ | |||
package org.apache.fop.render.pdf; | |||
import java.net.URI; | |||
import java.net.URISyntaxException; | |||
import java.util.Collections; | |||
import java.util.EnumMap; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import org.junit.Test; | |||
import org.apache.fop.pdf.PDFAMode; | |||
import org.apache.fop.pdf.PDFEncryptionParams; | |||
import org.apache.fop.pdf.PDFXMode; | |||
import org.apache.fop.pdf.Version; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.DISABLE_SRGB_COLORSPACE; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.FILTER_LIST; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.OUTPUT_PROFILE; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.PDF_A_MODE; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.PDF_X_MODE; | |||
import static org.apache.fop.render.pdf.PDFRendererOption.VERSION; | |||
import static org.junit.Assert.assertEquals; | |||
public class PDFRendererOptionsConfigTestCase { | |||
private static final Map<PDFRendererOption, Object> DEFAULT_OPTIONS; | |||
private static final PDFEncryptionParams DEFAULT_ENCRYPTION_PARAMS = null; | |||
static { | |||
final EnumMap<PDFRendererOption, Object> props | |||
= new EnumMap<PDFRendererOption, Object>(PDFRendererOption.class); | |||
for(PDFRendererOption option : PDFRendererOption.values()) { | |||
props.put(option, option.getDefaultValue()); | |||
} | |||
DEFAULT_OPTIONS = Collections.unmodifiableMap(props); | |||
} | |||
@Test | |||
public void testDefaults() { | |||
assertConfigEquals(DEFAULT_OPTIONS, DEFAULT_ENCRYPTION_PARAMS, PDFRendererOptionsConfig.DEFAULT); | |||
} | |||
@Test | |||
public void testConstructor() throws URISyntaxException { | |||
final Map<PDFRendererOption, Object> options = createNonDefaultOptions(); | |||
final PDFEncryptionParams encryptionParams = new PDFEncryptionParams(); | |||
assertConfigEquals(options, encryptionParams, new PDFRendererOptionsConfig(options, encryptionParams)); | |||
} | |||
@Test | |||
public void testMerge() throws URISyntaxException { | |||
final PDFRendererOptionsConfig defaults = PDFRendererOptionsConfig.DEFAULT; | |||
final PDFEncryptionParams encryptionParams = new PDFEncryptionParams(); | |||
final Map<PDFRendererOption, Object> options = createNonDefaultOptions(); | |||
final PDFRendererOptionsConfig otherConfig = new PDFRendererOptionsConfig(options, encryptionParams); | |||
assertConfigEquals(options, encryptionParams, defaults.merge(otherConfig)); | |||
assertEquals(defaults, defaults.merge(null)); | |||
} | |||
private Map<PDFRendererOption, Object> createNonDefaultOptions() throws URISyntaxException { | |||
final EnumMap<PDFRendererOption, Object> options | |||
= new EnumMap<PDFRendererOption, Object>(PDFRendererOption.class); | |||
options.put(DISABLE_SRGB_COLORSPACE, Boolean.TRUE); | |||
options.put(FILTER_LIST, new HashMap<String, List<String>>()); | |||
options.put(OUTPUT_PROFILE, new URI("xxx")); | |||
options.put(PDF_A_MODE, PDFAMode.PDFA_1A); | |||
options.put(PDF_X_MODE, PDFXMode.PDFX_3_2003); | |||
options.put(VERSION, Version.V1_0); | |||
return Collections.unmodifiableMap(options); | |||
} | |||
private static void assertConfigEquals(Map<PDFRendererOption, Object> expectedOptions, | |||
PDFEncryptionParams expectedEncryptionParams, PDFRendererOptionsConfig actual) { | |||
assertEquals((Boolean) expectedOptions.get(DISABLE_SRGB_COLORSPACE), actual.getDisableSRGBColorSpace()); | |||
assertEquals((Map) expectedOptions.get(FILTER_LIST), actual.getFilterMap()); | |||
assertEquals((URI) expectedOptions.get(OUTPUT_PROFILE), actual.getOutputProfileURI()); | |||
assertEquals((PDFAMode) expectedOptions.get(PDF_A_MODE), actual.getPDFAMode()); | |||
assertEquals((PDFXMode) expectedOptions.get(PDF_X_MODE), actual.getPDFXMode()); | |||
assertEquals((Version) expectedOptions.get(VERSION), actual.getPDFVersion()); | |||
assertEncryptionParamsEquals(expectedEncryptionParams, actual.getEncryptionParameters()); | |||
} | |||
private static void assertEncryptionParamsEquals(PDFEncryptionParams expected, | |||
PDFEncryptionParams actual) { | |||
assertEquals(expected == null, actual == null); | |||
if (actual != null) { | |||
assertEquals(expected.getEncryptionLengthInBits(), actual.getEncryptionLengthInBits()); | |||
assertEquals(expected.getOwnerPassword(), actual.getOwnerPassword()); | |||
assertEquals(expected.getUserPassword(), actual.getUserPassword()); | |||
assertEquals(expected.isAllowAccessContent(), actual.isAllowAccessContent()); | |||
assertEquals(expected.isAllowAssembleDocument(), actual.isAllowAssembleDocument()); | |||
assertEquals(expected.isAllowCopyContent(), actual.isAllowCopyContent()); | |||
assertEquals(expected.isAllowEditAnnotations(), actual.isAllowEditAnnotations()); | |||
assertEquals(expected.isAllowEditContent(), actual.isAllowEditContent()); | |||
assertEquals(expected.isAllowFillInForms(), actual.isAllowFillInForms()); | |||
assertEquals(expected.isAllowPrint(), actual.isAllowPrint()); | |||
assertEquals(expected.isAllowPrintHq(), actual.isAllowPrintHq()); | |||
} | |||
} | |||
} |
@@ -28,6 +28,8 @@ import org.junit.runners.Suite.SuiteClasses; | |||
* A test suite for org.apache.fop.render.pdf.* | |||
*/ | |||
@RunWith(Suite.class) | |||
@SuiteClasses({ PDFRendererConfiguratorTestCase.class }) | |||
@SuiteClasses({ | |||
PDFRendererConfigParserTestCase.class | |||
}) | |||
public final class RenderPDFTestSuite { | |||
} |
@@ -24,7 +24,7 @@ import org.junit.Test; | |||
import org.apache.fop.apps.AbstractRendererConfigParserTester; | |||
import org.apache.fop.apps.TxtRendererConfBuilder; | |||
import org.apache.fop.render.RendererConfig.RendererConfigParser; | |||
import org.apache.fop.render.txt.TxtRendererConfig.TxtRendererConfigOption; | |||
import org.apache.fop.render.txt.TxtRendererConfig.TxtRendererOption; | |||
import org.apache.fop.render.txt.TxtRendererConfig.TxtRendererConfigParser; | |||
import static org.junit.Assert.assertEquals; | |||
@@ -47,7 +47,7 @@ public class TxtRendererConfigParserTestCase | |||
// Check the default behaviour is expected | |||
parseConfig(createRenderer()); | |||
assertEquals(TxtRendererConfigOption.ENCODING.getDefaultValue(), conf.getEncoding()); | |||
assertEquals(TxtRendererOption.ENCODING.getDefaultValue(), conf.getEncoding()); | |||
} | |||
} |
@@ -0,0 +1,48 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
/* $Id$ */ | |||
package org.apache.fop.svg; | |||
import java.awt.BasicStroke; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertTrue; | |||
public class PDFGraphics2DTestCase { | |||
@Test | |||
public void testApplyStrokeNullDash() { | |||
PDFGraphics2D g2d = new PDFGraphics2D(false); | |||
BasicStroke stroke = new BasicStroke(); | |||
g2d.applyStroke(stroke); | |||
assertTrue(g2d.getString().contains("[] 0 d\n")); | |||
} | |||
@Test | |||
public void testApplyStrokeNonNullDash() { | |||
PDFGraphics2D g2d = new PDFGraphics2D(false); | |||
float[] dashArray = {3.0f, 5.0f}; | |||
BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, | |||
dashArray, 0.0f); | |||
g2d.applyStroke(stroke); | |||
assertTrue(g2d.getString().contains("[3 5] 0 d\n")); | |||
} | |||
} |