aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorMehdi Houshmand <mehdi@apache.org>2012-07-02 10:13:54 +0000
committerMehdi Houshmand <mehdi@apache.org>2012-07-02 10:13:54 +0000
commitf5a033d38f700d70bbf679d87d535b37438c9ebb (patch)
tree4a5e6107ae8844b3e4a8b152adcf034bbe71871e /src/java/org/apache
parent12dc06840f1ccc107b4f83619c8c681ddf9607d0 (diff)
downloadxmlgraphics-fop-f5a033d38f700d70bbf679d87d535b37438c9ebb.tar.gz
xmlgraphics-fop-f5a033d38f700d70bbf679d87d535b37438c9ebb.zip
Changed the exception message when internal font key == null, also some clean up and encapsulation to *Painter classes
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1356161 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/fop/fonts/FontTriplet.java3
-rw-r--r--src/java/org/apache/fop/render/PrintRenderer.java2
-rw-r--r--src/java/org/apache/fop/render/afp/AFPDocumentHandler.java4
-rw-r--r--src/java/org/apache/fop/render/afp/AFPPainter.java55
-rw-r--r--src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java29
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFException.java25
-rw-r--r--src/java/org/apache/fop/render/java2d/Java2DDocumentHandler.java156
-rw-r--r--src/java/org/apache/fop/render/java2d/Java2DPainter.java12
-rw-r--r--src/java/org/apache/fop/render/pcl/PCLPainter.java41
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java35
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java6
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFPainter.java41
-rw-r--r--src/java/org/apache/fop/render/ps/PSDocumentHandler.java9
-rw-r--r--src/java/org/apache/fop/render/ps/PSPainter.java41
14 files changed, 300 insertions, 159 deletions
diff --git a/src/java/org/apache/fop/fonts/FontTriplet.java b/src/java/org/apache/fop/fonts/FontTriplet.java
index c14634460..fd2a47a16 100644
--- a/src/java/org/apache/fop/fonts/FontTriplet.java
+++ b/src/java/org/apache/fop/fonts/FontTriplet.java
@@ -27,6 +27,8 @@ import java.io.Serializable;
*/
public class FontTriplet implements Comparable<FontTriplet>, Serializable {
+ public static final FontTriplet DEFAULT_FONT_TRIPLET = new FontTriplet("any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
+
/** serial version UID */
private static final long serialVersionUID = 1168991106658033508L;
@@ -143,6 +145,5 @@ public class FontTriplet implements Comparable<FontTriplet>, Serializable {
*/
boolean matches(FontTriplet triplet);
}
-
}
diff --git a/src/java/org/apache/fop/render/PrintRenderer.java b/src/java/org/apache/fop/render/PrintRenderer.java
index 96a62cb11..2017dbd88 100644
--- a/src/java/org/apache/fop/render/PrintRenderer.java
+++ b/src/java/org/apache/fop/render/PrintRenderer.java
@@ -107,7 +107,7 @@ public abstract class PrintRenderer extends AbstractRenderer {
String key = fontInfo.getInternalFontKey(triplet);
if (key == null) {
//Find a default fallback font as last resort
- triplet = new FontTriplet("any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
+ triplet = FontTriplet.DEFAULT_FONT_TRIPLET;
key = fontInfo.getInternalFontKey(triplet);
}
return key;
diff --git a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
index 2ae95dd4c..76de3f704 100644
--- a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
+++ b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
@@ -58,8 +58,8 @@ import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFPainter;
/**
- * {@link org.apache.fop.render.intermediate.IFDocumentHandler} implementation that
- * produces AFP (MO:DCA).
+ * {@link org.apache.fop.render.intermediate.IFDocumentHandler} implementation that produces AFP
+ * (MO:DCA).
*/
public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
implements AFPCustomizable {
diff --git a/src/java/org/apache/fop/render/afp/AFPPainter.java b/src/java/org/apache/fop/render/afp/AFPPainter.java
index 8b2f31555..592b47eaa 100644
--- a/src/java/org/apache/fop/render/afp/AFPPainter.java
+++ b/src/java/org/apache/fop/render/afp/AFPPainter.java
@@ -36,6 +36,7 @@ import org.apache.xmlgraphics.image.loader.ImageProcessingHints;
import org.apache.xmlgraphics.image.loader.ImageSessionContext;
import org.apache.fop.afp.AFPBorderPainter;
+import org.apache.fop.afp.AFPEventProducer;
import org.apache.fop.afp.AFPPaintingState;
import org.apache.fop.afp.AFPUnitConverter;
import org.apache.fop.afp.AbstractAFPPainter;
@@ -53,13 +54,11 @@ import org.apache.fop.afp.ptoca.PtocaProducer;
import org.apache.fop.afp.util.DefaultFOPResourceAccessor;
import org.apache.fop.afp.util.ResourceAccessor;
import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.fonts.Typeface;
import org.apache.fop.render.RenderingContext;
import org.apache.fop.render.intermediate.AbstractIFPainter;
import org.apache.fop.render.intermediate.BorderPainter;
-import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFState;
import org.apache.fop.render.intermediate.IFUtil;
@@ -70,7 +69,7 @@ import org.apache.fop.util.CharUtilities;
/**
* IFPainter implementation that produces AFP (MO:DCA).
*/
-public class AFPPainter extends AbstractIFPainter {
+public class AFPPainter extends AbstractIFPainter<AFPDocumentHandler> {
//** logging instance */
//private static Log log = LogFactory.getLog(AFPPainter.class);
@@ -78,8 +77,6 @@ public class AFPPainter extends AbstractIFPainter {
private static final int X = 0;
private static final int Y = 1;
- private final AFPDocumentHandler documentHandler;
-
/** the border painter */
private final AFPBorderPainterAdapter borderPainter;
/** the rectangle painter */
@@ -88,36 +85,38 @@ public class AFPPainter extends AbstractIFPainter {
/** unit converter */
private final AFPUnitConverter unitConv;
+ private final AFPEventProducer eventProducer;
+
/**
* Default constructor.
* @param documentHandler the parent document handler
*/
public AFPPainter(AFPDocumentHandler documentHandler) {
- super();
- this.documentHandler = documentHandler;
+ super(documentHandler);
this.state = IFState.create();
this.borderPainter = new AFPBorderPainterAdapter(
new AFPBorderPainter(getPaintingState(), getDataStream()));
this.rectanglePainter = documentHandler.createRectanglePainter();
this.unitConv = getPaintingState().getUnitConverter();
+ this.eventProducer = AFPEventProducer.Provider.get(getUserAgent().getEventBroadcaster());
}
- /** {@inheritDoc} */
- @Override
- protected IFContext getContext() {
- return this.documentHandler.getContext();
- }
-
- FontInfo getFontInfo() {
- return this.documentHandler.getFontInfo();
+ private AFPPaintingState getPaintingState() {
+ return getDocumentHandler().getPaintingState();
}
- AFPPaintingState getPaintingState() {
- return this.documentHandler.getPaintingState();
+ private DataStream getDataStream() {
+ return getDocumentHandler().getDataStream();
}
- DataStream getDataStream() {
- return this.documentHandler.getDataStream();
+ @Override
+ public String getFontKey(FontTriplet triplet) throws IFException {
+ try {
+ return super.getFontKey(triplet);
+ } catch (IFException e) {
+ eventProducer.invalidConfiguration(null, e);
+ return super.getFontKey(FontTriplet.DEFAULT_FONT_TRIPLET);
+ }
}
/** {@inheritDoc} */
@@ -183,7 +182,7 @@ public class AFPPainter extends AbstractIFPainter {
protected RenderingContext createRenderingContext() {
AFPRenderingContext psContext = new AFPRenderingContext(
getUserAgent(),
- documentHandler.getResourceManager(),
+ getDocumentHandler().getResourceManager(),
getPaintingState(),
getFontInfo(),
getContext().getForeignAttributes());
@@ -192,7 +191,7 @@ public class AFPPainter extends AbstractIFPainter {
/** {@inheritDoc} */
public void drawImage(String uri, Rectangle rect) throws IFException {
- PageSegmentDescriptor pageSegment = documentHandler.getPageSegmentNameFor(uri);
+ PageSegmentDescriptor pageSegment = getDocumentHandler().getPageSegmentNameFor(uri);
if (pageSegment != null) {
float[] srcPts = {rect.x, rect.y};
@@ -206,10 +205,10 @@ public class AFPPainter extends AbstractIFPainter {
//Do we need to embed an external page segment?
if (pageSegment.getURI() != null) {
ResourceAccessor accessor = new DefaultFOPResourceAccessor (
- documentHandler.getUserAgent(), null, null);
+ getUserAgent(), null, null);
try {
URI resourceUri = new URI(pageSegment.getURI());
- documentHandler.getResourceManager().createIncludedResourceFromExternal(
+ getDocumentHandler().getResourceManager().createIncludedResourceFromExternal(
pageSegment.getName(), resourceUri, accessor);
} catch (URISyntaxException urie) {
@@ -365,14 +364,10 @@ public class AFPPainter extends AbstractIFPainter {
FontTriplet triplet = new FontTriplet(
state.getFontFamily(), state.getFontStyle(), state.getFontWeight());
//TODO Ignored: state.getFontVariant()
- String fontKey = getFontInfo().getInternalFontKey(triplet);
- if (fontKey == null) {
- triplet = new FontTriplet("any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
- fontKey = getFontInfo().getInternalFontKey(triplet);
- }
+ String fontKey = getFontKey(triplet);
// register font as necessary
- Map<String, Typeface> fontMetricMap = documentHandler.getFontInfo().getFonts();
+ Map<String, Typeface> fontMetricMap = getFontInfo().getFonts();
final AFPFont afpFont = (AFPFont)fontMetricMap.get(fontKey);
final Font font = getFontInfo().getFontInstance(triplet, fontSize);
AFPPageFonts pageFonts = getPaintingState().getPageFonts();
@@ -386,7 +381,7 @@ public class AFPPainter extends AbstractIFPainter {
if (afpFont.isEmbeddable()) {
try {
- documentHandler.getResourceManager().embedFont(afpFont, charSet);
+ getDocumentHandler().getResourceManager().embedFont(afpFont, charSet);
} catch (IOException ioe) {
throw new IFException("Error while embedding font resources", ioe);
}
diff --git a/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java b/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
index c696e552d..327eca14e 100644
--- a/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
+++ b/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
@@ -47,6 +47,8 @@ import org.apache.fop.ResourceEventProducer;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.fo.Constants;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.render.ImageHandler;
import org.apache.fop.render.ImageHandlerRegistry;
import org.apache.fop.render.ImageHandlerUtil;
@@ -57,7 +59,7 @@ import org.apache.fop.traits.RuleStyle;
/**
* Abstract base class for IFPainter implementations.
*/
-public abstract class AbstractIFPainter implements IFPainter {
+public abstract class AbstractIFPainter<T extends IFDocumentHandler> implements IFPainter {
/** logging instance */
private static Log log = LogFactory.getLog(AbstractIFPainter.class);
@@ -68,18 +70,39 @@ public abstract class AbstractIFPainter implements IFPainter {
/** Holds the intermediate format state */
protected IFState state;
+ private final T documentHandler;
/**
* Default constructor.
*/
- public AbstractIFPainter() {
+ public AbstractIFPainter(T documentHandler) {
+ this.documentHandler = documentHandler;
+ }
+
+ protected String getFontKey(FontTriplet triplet) throws IFException {
+ String key = getFontInfo().getInternalFontKey(triplet);
+ if (key == null) {
+ throw new IFException("The font triplet is not available: \"" + triplet + "\" "
+ + "for the MIME type: \"" + documentHandler.getMimeType() + "\"");
+ }
+ return key;
}
/**
* Returns the intermediate format context object.
* @return the context object
*/
- protected abstract IFContext getContext();
+ protected IFContext getContext() {
+ return documentHandler.getContext();
+ }
+
+ protected FontInfo getFontInfo() {
+ return documentHandler.getFontInfo();
+ }
+
+ protected T getDocumentHandler() {
+ return documentHandler;
+ }
/**
* Returns the user agent.
diff --git a/src/java/org/apache/fop/render/intermediate/IFException.java b/src/java/org/apache/fop/render/intermediate/IFException.java
index 52c650765..5f35c3e3a 100644
--- a/src/java/org/apache/fop/render/intermediate/IFException.java
+++ b/src/java/org/apache/fop/render/intermediate/IFException.java
@@ -27,20 +27,27 @@ public class IFException extends Exception {
private static final long serialVersionUID = 0L;
/**
- * Constructs a new exception with the specified detail message and
- * cause. <p>Note that the detail message associated with
- * <code>cause</code> is <i>not</i> automatically incorporated in
+ * Constructs a new exception with the specified detail message and cause. <p>Note that the
+ * detail message associated with <code>cause</code> is <i>not</i> automatically incorporated in
* this exception's detail message.
*
- * @param message the detail message (which is saved for later retrieval
- * by the {@link #getMessage()} method).
- * @param cause the cause (which is saved for later retrieval by the
- * {@link #getCause()} method). (A <code>null</code> value is
- * permitted, and indicates that the cause is nonexistent or
- * unknown.)
+ * @param message the detail message (which is saved for later retrieval by the
+ * {@link #getMessage()} method).
+ * @param cause the cause (which is saved for later retrieval by the {@link #getCause()}
+ * method). (A <code>null</code> value is permitted, and indicates that the cause is
+ * nonexistent or unknown.)
*/
public IFException(String message, Exception cause) {
super(message, cause);
}
+ /**
+ * Constructs a new exception with the specified detail message.
+ *
+ * @param message the detail message (which is saved for later retrieval by the
+ * {@link #getMessage()} method).
+ */
+ public IFException(String message) {
+ super(message);
+ }
}
diff --git a/src/java/org/apache/fop/render/java2d/Java2DDocumentHandler.java b/src/java/org/apache/fop/render/java2d/Java2DDocumentHandler.java
new file mode 100644
index 000000000..87003f077
--- /dev/null
+++ b/src/java/org/apache/fop/render/java2d/Java2DDocumentHandler.java
@@ -0,0 +1,156 @@
+/*
+ * 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.
+ */
+
+package org.apache.fop.render.java2d;
+
+import java.awt.Dimension;
+import java.util.Locale;
+
+import javax.xml.transform.Result;
+
+import org.apache.fop.accessibility.StructureTreeEventHandler;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.render.intermediate.IFContext;
+import org.apache.fop.render.intermediate.IFDocumentHandler;
+import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
+import org.apache.fop.render.intermediate.IFDocumentNavigationHandler;
+import org.apache.fop.render.intermediate.IFException;
+import org.apache.fop.render.intermediate.IFPainter;
+
+/**
+ * {@link org.apache.fop.render.intermediate.IFDocumentHandler} implementation that produces
+ * Graphics2D instance.
+ */
+public class Java2DDocumentHandler implements IFDocumentHandler {
+
+ public void setContext(IFContext context) {
+ throw new UnsupportedOperationException();
+ }
+
+ public IFContext getContext() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setResult(Result result) throws IFException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setFontInfo(FontInfo fontInfo) {
+ throw new UnsupportedOperationException();
+ }
+
+ public FontInfo getFontInfo() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setDefaultFontInfo(FontInfo fontInfo) {
+ throw new UnsupportedOperationException();
+ }
+
+ public IFDocumentHandlerConfigurator getConfigurator() {
+ throw new UnsupportedOperationException();
+ }
+
+ public StructureTreeEventHandler getStructureTreeEventHandler() {
+ throw new UnsupportedOperationException();
+ }
+
+ public IFDocumentNavigationHandler getDocumentNavigationHandler() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean supportsPagesOutOfOrder() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getMimeType() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void startDocument() throws IFException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void endDocument() throws IFException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setDocumentLocale(Locale locale) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void startDocumentHeader() throws IFException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void endDocumentHeader() throws IFException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void startDocumentTrailer() throws IFException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void endDocumentTrailer() throws IFException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void startPageSequence(String id) throws IFException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void endPageSequence() throws IFException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void startPage(int index, String name, String pageMasterName, Dimension size)
+ throws IFException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void endPage() throws IFException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void startPageHeader() throws IFException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void endPageHeader() throws IFException {
+ throw new UnsupportedOperationException();
+ }
+
+ public IFPainter startPageContent() throws IFException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void endPageContent() throws IFException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void startPageTrailer() throws IFException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void endPageTrailer() throws IFException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void handleExtensionObject(Object extension) throws IFException {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/src/java/org/apache/fop/render/java2d/Java2DPainter.java b/src/java/org/apache/fop/render/java2d/Java2DPainter.java
index 575242d38..89031787a 100644
--- a/src/java/org/apache/fop/render/java2d/Java2DPainter.java
+++ b/src/java/org/apache/fop/render/java2d/Java2DPainter.java
@@ -47,10 +47,10 @@ import org.apache.fop.traits.RuleStyle;
import org.apache.fop.util.CharUtilities;
/**
- * {@link org.apache.fop.render.intermediate.IFPainter} implementation
- * that paints on a Graphics2D instance.
+ * {@link org.apache.fop.render.intermediate.IFPainter} implementation that paints on a Graphics2D
+ * instance.
*/
-public class Java2DPainter extends AbstractIFPainter {
+public class Java2DPainter extends AbstractIFPainter<Java2DDocumentHandler> {
/** the IF context */
protected IFContext ifContext;
@@ -62,7 +62,7 @@ public class Java2DPainter extends AbstractIFPainter {
/** The current state, holds a Graphics2D and its context */
protected Java2DGraphicsState g2dState;
- private Stack g2dStateStack = new Stack();
+ private Stack<Java2DGraphicsState> g2dStateStack = new Stack<Java2DGraphicsState>();
/**
* Main constructor.
@@ -83,7 +83,7 @@ public class Java2DPainter extends AbstractIFPainter {
* @param state the IF state object
*/
public Java2DPainter(Graphics2D g2d, IFContext context, FontInfo fontInfo, IFState state) {
- super();
+ super(new Java2DDocumentHandler());
this.ifContext = context;
if (state != null) {
this.state = state.push();
@@ -256,7 +256,7 @@ public class Java2DPainter extends AbstractIFPainter {
/** Restores the last graphics state from the stack. */
protected void restoreGraphicsState() {
g2dState.dispose();
- g2dState = (Java2DGraphicsState)g2dStateStack.pop();
+ g2dState = g2dStateStack.pop();
}
private void concatenateTransformationMatrix(AffineTransform transform) throws IOException {
diff --git a/src/java/org/apache/fop/render/pcl/PCLPainter.java b/src/java/org/apache/fop/render/pcl/PCLPainter.java
index 0d630826c..f0d87d542 100644
--- a/src/java/org/apache/fop/render/pcl/PCLPainter.java
+++ b/src/java/org/apache/fop/render/pcl/PCLPainter.java
@@ -47,7 +47,6 @@ import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.render.ImageHandlerUtil;
import org.apache.fop.render.RenderingContext;
import org.apache.fop.render.intermediate.AbstractIFPainter;
-import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFState;
import org.apache.fop.render.intermediate.IFUtil;
@@ -58,15 +57,12 @@ import org.apache.fop.traits.RuleStyle;
import org.apache.fop.util.CharUtilities;
/**
- * {@link org.apache.fop.render.intermediate.IFPainter} implementation
- * that produces PCL 5.
+ * {@link org.apache.fop.render.intermediate.IFPainter} implementation that produces PCL 5.
*/
-public class PCLPainter extends AbstractIFPainter implements PCLConstants {
+public class PCLPainter extends AbstractIFPainter<PCLDocumentHandler> implements PCLConstants {
private static final boolean DEBUG = false;
- private PCLDocumentHandler parent;
-
/** The PCL generator */
private PCLGenerator gen;
@@ -74,7 +70,7 @@ public class PCLPainter extends AbstractIFPainter implements PCLConstants {
private int currentPrintDirection = 0;
//private GeneralPath currentPath = null;
- private Stack graphicContextStack = new Stack();
+ private Stack<GraphicContext> graphicContextStack = new Stack<GraphicContext>();
private GraphicContext graphicContext = new GraphicContext();
/**
@@ -83,24 +79,19 @@ public class PCLPainter extends AbstractIFPainter implements PCLConstants {
* @param pageDefinition the page definition describing the page to be rendered
*/
public PCLPainter(PCLDocumentHandler parent, PCLPageDefinition pageDefinition) {
- this.parent = parent;
+ super(parent);
this.gen = parent.getPCLGenerator();
this.state = IFState.create();
this.currentPageDefinition = pageDefinition;
}
- /** {@inheritDoc} */
- public IFContext getContext() {
- return this.parent.getContext();
- }
-
PCLRenderingUtil getPCLUtil() {
- return this.parent.getPCLUtil();
+ return getDocumentHandler().getPCLUtil();
}
/** @return the target resolution */
protected int getResolution() {
- int resolution = (int)Math.round(getUserAgent().getTargetResolution());
+ int resolution = Math.round(getUserAgent().getTargetResolution());
if (resolution <= 300) {
return 300;
} else {
@@ -223,7 +214,7 @@ public class PCLPainter extends AbstractIFPainter implements PCLConstants {
g2d.translate(-rect.x, -rect.y);
Java2DPainter painter = new Java2DPainter(g2d,
- getContext(), parent.getFontInfo(), state);
+ getContext(), getFontInfo(), state);
try {
painter.drawBorderRect(rect, top, bottom, left, right);
} catch (IFException e) {
@@ -258,7 +249,7 @@ public class PCLPainter extends AbstractIFPainter implements PCLConstants {
g2d.translate(-boundingBox.x, -boundingBox.y);
Java2DPainter painter = new Java2DPainter(g2d,
- getContext(), parent.getFontInfo(), state);
+ getContext(), getFontInfo(), state);
try {
painter.drawLine(start, end, width, color, style);
} catch (IFException e) {
@@ -315,9 +306,8 @@ public class PCLPainter extends AbstractIFPainter implements PCLConstants {
state.getFontFamily(), state.getFontStyle(), state.getFontWeight());
//TODO Ignored: state.getFontVariant()
//TODO Opportunity for font caching if font state is more heavily used
- String fontKey = parent.getFontInfo().getInternalFontKey(triplet);
- boolean pclFont = getPCLUtil().isAllTextAsBitmaps()
- ? false
+ String fontKey = getFontKey(triplet);
+ boolean pclFont = getPCLUtil().isAllTextAsBitmaps() ? false
: HardcodedFonts.setFont(gen, fontKey, state.getFontSize(), text);
if (pclFont) {
drawTextNative(x, y, letterSpacing, wordSpacing, dp, text, triplet);
@@ -346,7 +336,7 @@ public class PCLPainter extends AbstractIFPainter implements PCLConstants {
setCursorPos(x, y);
float fontSize = state.getFontSize() / 1000f;
- Font font = parent.getFontInfo().getFontInstance(triplet, state.getFontSize());
+ Font font = getFontInfo().getFontInstance(triplet, state.getFontSize());
int l = text.length();
int[] dx = IFUtil.convertDPToDX ( dp );
int dxl = (dx != null ? dx.length : 0);
@@ -438,10 +428,10 @@ public class PCLPainter extends AbstractIFPainter implements PCLConstants {
final int letterSpacing, final int wordSpacing, final int[][] dp,
final String text, FontTriplet triplet) throws IFException {
//Use Java2D to paint different fonts via bitmap
- final Font font = parent.getFontInfo().getFontInstance(triplet, state.getFontSize());
+ final Font font = getFontInfo().getFontInstance(triplet, state.getFontSize());
//for cursive fonts, so the text isn't clipped
- final FontMetricsMapper mapper = (FontMetricsMapper)parent.getFontInfo().getMetricsFor(
+ final FontMetricsMapper mapper = (FontMetricsMapper) getFontInfo().getMetricsFor(
font.getFontName());
final int maxAscent = mapper.getMaxAscent(font.getFontSize()) / 1000;
final int ascent = mapper.getAscender(font.getFontSize()) / 1000;
@@ -470,8 +460,7 @@ public class PCLPainter extends AbstractIFPainter implements PCLConstants {
rect = new Rectangle(x, y, 1000, -descent);
g2d.draw(rect);
}
- Java2DPainter painter = new Java2DPainter(g2d,
- getContext(), parent.getFontInfo(), state);
+ Java2DPainter painter = new Java2DPainter(g2d, getContext(), getFontInfo(), state);
try {
painter.drawText(x, y, letterSpacing, wordSpacing, dp, text);
} catch (IFException e) {
@@ -496,7 +485,7 @@ public class PCLPainter extends AbstractIFPainter implements PCLConstants {
/** Restores the last graphics state from the stack. */
private void restoreGraphicsState() {
- graphicContext = (GraphicContext)graphicContextStack.pop();
+ graphicContext = graphicContextStack.pop();
}
private void concatenateTransformationMatrix(AffineTransform transform) throws IOException {
diff --git a/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java b/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java
index 5be8c3001..c56bce218 100644
--- a/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java
+++ b/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java
@@ -40,7 +40,6 @@ import org.apache.fop.fo.extensions.xmp.XMPMetadata;
import org.apache.fop.pdf.PDFAnnotList;
import org.apache.fop.pdf.PDFDocument;
import org.apache.fop.pdf.PDFPage;
-import org.apache.fop.pdf.PDFResourceContext;
import org.apache.fop.pdf.PDFResources;
import org.apache.fop.render.extensions.prepress.PageBoundaries;
import org.apache.fop.render.extensions.prepress.PageScale;
@@ -67,31 +66,28 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
private PDFStructureTreeBuilder structureTreeBuilder;
/** the PDF Document being created */
- protected PDFDocument pdfDoc;
+ private PDFDocument pdfDoc;
/**
* Utility class which enables all sorts of features that are not directly connected to the
* normal rendering process.
*/
- protected PDFRenderingUtil pdfUtil;
+ private PDFRenderingUtil pdfUtil;
/** the /Resources object of the PDF document being created */
- protected PDFResources pdfResources;
+ private PDFResources pdfResources;
/** The current content generator */
- protected PDFContentGenerator generator;
-
- /** the current annotation list to add annotations to */
- protected PDFResourceContext currentContext;
+ private PDFContentGenerator generator;
/** the current page to add annotations to */
- protected PDFPage currentPage;
+ private PDFPage currentPage;
/** the current page's PDF reference */
- protected PageReference currentPageRef;
+ private PageReference currentPageRef;
/** Used for bookmarks/outlines. */
- protected Map<Integer, PageReference> pageReferences = new HashMap<Integer, PageReference>();
+ private Map<Integer, PageReference> pageReferences = new HashMap<Integer, PageReference>();
private final PDFDocumentNavigationHandler documentNavigationHandler
= new PDFDocumentNavigationHandler(this);
@@ -136,6 +132,22 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
return logicalStructureHandler;
}
+ PDFDocument getPDFDocument() {
+ return pdfDoc;
+ }
+
+ PDFPage getCurrentPage() {
+ return currentPage;
+ }
+
+ PageReference getCurrentPageRef() {
+ return currentPageRef;
+ }
+
+ PDFContentGenerator getGenerator() {
+ return generator;
+ }
+
/** {@inheritDoc} */
public void startDocument() throws IFException {
super.startDocument();
@@ -174,7 +186,6 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
pdfResources = null;
this.generator = null;
- currentContext = null;
currentPage = null;
} catch (IOException ioe) {
throw new IFException("I/O error in endDocument()", ioe);
diff --git a/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java b/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java
index af49fea4c..1ef637726 100644
--- a/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java
+++ b/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java
@@ -63,7 +63,7 @@ public class PDFDocumentNavigationHandler implements IFDocumentNavigationHandler
}
PDFDocument getPDFDoc() {
- return this.documentHandler.pdfDoc;
+ return this.documentHandler.getPDFDocument();
}
/** {@inheritDoc} */
@@ -100,7 +100,7 @@ public class PDFDocumentNavigationHandler implements IFDocumentNavigationHandler
/** {@inheritDoc} */
public void renderLink(Link link) throws IFException {
Rectangle targetRect = link.getTargetRect();
- int pageHeight = documentHandler.currentPageRef.getPageDimension().height;
+ int pageHeight = documentHandler.getCurrentPageRef().getPageDimension().height;
Rectangle2D targetRect2D = new Rectangle2D.Double(
targetRect.getMinX() / 1000.0,
(pageHeight - targetRect.getMinY() - targetRect.getHeight()) / 1000.0,
@@ -116,7 +116,7 @@ public class PDFDocumentNavigationHandler implements IFDocumentNavigationHandler
if (documentHandler.getUserAgent().isAccessibilityEnabled() && structure != null) {
documentHandler.getLogicalStructureHandler().addLinkContentItem(pdfLink, structure);
}
- documentHandler.currentPage.addAnnotation(pdfLink);
+ documentHandler.getCurrentPage().addAnnotation(pdfLink);
}
}
diff --git a/src/java/org/apache/fop/render/pdf/PDFPainter.java b/src/java/org/apache/fop/render/pdf/PDFPainter.java
index 4928e7251..0160ffc1c 100644
--- a/src/java/org/apache/fop/render/pdf/PDFPainter.java
+++ b/src/java/org/apache/fop/render/pdf/PDFPainter.java
@@ -30,19 +30,16 @@ import java.io.IOException;
import org.w3c.dom.Document;
import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.fonts.LazyFont;
import org.apache.fop.fonts.SingleByteFont;
import org.apache.fop.fonts.Typeface;
-import org.apache.fop.pdf.PDFDocument;
import org.apache.fop.pdf.PDFNumber;
import org.apache.fop.pdf.PDFStructElem;
import org.apache.fop.pdf.PDFTextUtil;
import org.apache.fop.pdf.PDFXObject;
import org.apache.fop.render.RenderingContext;
import org.apache.fop.render.intermediate.AbstractIFPainter;
-import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFState;
import org.apache.fop.render.intermediate.IFUtil;
@@ -55,9 +52,7 @@ import org.apache.fop.util.CharUtilities;
/**
* IFPainter implementation that produces PDF.
*/
-public class PDFPainter extends AbstractIFPainter {
-
- private final PDFDocumentHandler documentHandler;
+public class PDFPainter extends AbstractIFPainter<PDFDocumentHandler> {
/** The current content generator */
protected PDFContentGenerator generator;
@@ -77,34 +72,15 @@ public class PDFPainter extends AbstractIFPainter {
*/
public PDFPainter(PDFDocumentHandler documentHandler,
PDFLogicalStructureHandler logicalStructureHandler) {
- super();
- this.documentHandler = documentHandler;
+ super(documentHandler);
this.logicalStructureHandler = logicalStructureHandler;
- this.generator = documentHandler.generator;
+ this.generator = documentHandler.getGenerator();
this.borderPainter = new PDFBorderPainter(this.generator);
this.state = IFState.create();
accessEnabled = this.getUserAgent().isAccessibilityEnabled();
}
/** {@inheritDoc} */
- @Override
- protected IFContext getContext() {
- return this.documentHandler.getContext();
- }
-
- PDFRenderingUtil getPDFUtil() {
- return this.documentHandler.pdfUtil;
- }
-
- PDFDocument getPDFDoc() {
- return this.documentHandler.pdfDoc;
- }
-
- FontInfo getFontInfo() {
- return this.documentHandler.getFontInfo();
- }
-
- /** {@inheritDoc} */
public void startViewport(AffineTransform transform, Dimension size, Rectangle clipRect)
throws IFException {
generator.saveGraphicsState();
@@ -133,7 +109,7 @@ public class PDFPainter extends AbstractIFPainter {
/** {@inheritDoc} */
public void drawImage(String uri, Rectangle rect)
throws IFException {
- PDFXObject xobject = getPDFDoc().getXObject(uri);
+ PDFXObject xobject = getDocumentHandler().getPDFDocument().getXObject(uri);
if (xobject != null) {
if (accessEnabled) {
PDFStructElem structElem = (PDFStructElem) getContext().getStructureTreeElement();
@@ -160,7 +136,7 @@ public class PDFPainter extends AbstractIFPainter {
@Override
protected RenderingContext createRenderingContext() {
PDFRenderingContext pdfContext = new PDFRenderingContext(
- getUserAgent(), generator, this.documentHandler.currentPage, getFontInfo());
+ getUserAgent(), generator, getDocumentHandler().getCurrentPage(), getFontInfo());
pdfContext.setMarkedContentInfo(imageMCI);
return pdfContext;
}
@@ -321,12 +297,11 @@ public class PDFPainter extends AbstractIFPainter {
}
}
- private void drawTextWithDX ( int x, int y, String text, FontTriplet triplet,
- int letterSpacing, int wordSpacing, int[] dx ) {
-
+ private void drawTextWithDX(int x, int y, String text, FontTriplet triplet,
+ int letterSpacing, int wordSpacing, int[] dx) throws IFException {
//TODO Ignored: state.getFontVariant()
//TODO Opportunity for font caching if font state is more heavily used
- String fontKey = getFontInfo().getInternalFontKey(triplet);
+ String fontKey = getFontKey(triplet);
int sizeMillipoints = state.getFontSize();
float fontSize = sizeMillipoints / 1000f;
diff --git a/src/java/org/apache/fop/render/ps/PSDocumentHandler.java b/src/java/org/apache/fop/render/ps/PSDocumentHandler.java
index 0fe564827..bf2d95c1d 100644
--- a/src/java/org/apache/fop/render/ps/PSDocumentHandler.java
+++ b/src/java/org/apache/fop/render/ps/PSDocumentHandler.java
@@ -54,6 +54,7 @@ import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler;
import org.apache.fop.render.intermediate.IFContext;
+import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFPainter;
@@ -76,10 +77,10 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
* Utility class which enables all sorts of features that are not directly connected to the
* normal rendering process.
*/
- protected PSRenderingUtil psUtil;
+ private PSRenderingUtil psUtil;
/** The PostScript generator used to output the PostScript */
- protected PSGenerator gen;
+ PSGenerator gen;
/** the temporary file in case of two-pass processing */
private File tempFile;
@@ -126,6 +127,10 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
return MimeConstants.MIME_POSTSCRIPT;
}
+ PSGenerator getGenerator() {
+ return gen;
+ }
+
/** {@inheritDoc} */
public void setContext(IFContext context) {
super.setContext(context);
diff --git a/src/java/org/apache/fop/render/ps/PSPainter.java b/src/java/org/apache/fop/render/ps/PSPainter.java
index c2288019a..63e947e55 100644
--- a/src/java/org/apache/fop/render/ps/PSPainter.java
+++ b/src/java/org/apache/fop/render/ps/PSPainter.java
@@ -41,7 +41,6 @@ import org.apache.xmlgraphics.ps.PSGenerator;
import org.apache.xmlgraphics.ps.PSResource;
import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.fonts.LazyFont;
import org.apache.fop.fonts.MultiByteFont;
@@ -49,7 +48,6 @@ import org.apache.fop.fonts.SingleByteFont;
import org.apache.fop.fonts.Typeface;
import org.apache.fop.render.RenderingContext;
import org.apache.fop.render.intermediate.AbstractIFPainter;
-import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFState;
import org.apache.fop.render.intermediate.IFUtil;
@@ -61,12 +59,11 @@ import org.apache.fop.util.HexEncoder;
/**
* IFPainter implementation that produces PostScript.
*/
-public class PSPainter extends AbstractIFPainter {
+public class PSPainter extends AbstractIFPainter<PSDocumentHandler> {
/** logging instance */
private static Log log = LogFactory.getLog(PSPainter.class);
- private PSDocumentHandler documentHandler;
private PSBorderPainter borderPainter;
private boolean inTextMode = false;
@@ -80,27 +77,13 @@ public class PSPainter extends AbstractIFPainter {
}
protected PSPainter(PSDocumentHandler documentHandler, IFState state) {
- super();
- this.documentHandler = documentHandler;
- this.borderPainter = new PSBorderPainter(documentHandler.gen);
+ super(documentHandler);
+ this.borderPainter = new PSBorderPainter(getGenerator());
this.state = state;
}
- /** {@inheritDoc} */
- protected IFContext getContext() {
- return this.documentHandler.getContext();
- }
-
- PSRenderingUtil getPSUtil() {
- return this.documentHandler.psUtil;
- }
-
- FontInfo getFontInfo() {
- return this.documentHandler.getFontInfo();
- }
-
private PSGenerator getGenerator() {
- return this.documentHandler.gen;
+ return getDocumentHandler().getGenerator();
}
/** {@inheritDoc} */
@@ -168,7 +151,7 @@ public class PSPainter extends AbstractIFPainter {
/** {@inheritDoc} */
protected void drawImageUsingImageHandler(ImageInfo info, Rectangle rect)
throws ImageException, IOException {
- if (!getPSUtil().isOptimizeResources()
+ if (!getDocumentHandler().getPSUtil().isOptimizeResources()
|| PSImageUtils.isImageInlined(info,
(PSRenderingContext)createRenderingContext())) {
super.drawImageUsingImageHandler(info, rect);
@@ -177,7 +160,7 @@ public class PSPainter extends AbstractIFPainter {
log.debug("Image " + info + " is embedded as a form later");
}
//Don't load image at this time, just put a form placeholder in the stream
- PSResource form = documentHandler.getFormForImage(info.getOriginalURI());
+ PSResource form = getDocumentHandler().getFormForImage(info.getOriginalURI());
PSImageUtils.drawForm(form, info, rect, getGenerator());
}
}
@@ -246,7 +229,7 @@ public class PSPainter extends AbstractIFPainter {
if (top != null || bottom != null || left != null || right != null) {
try {
endTextObject();
- if (getPSUtil().getRenderingMode() == PSRenderingMode.SIZE
+ if (getDocumentHandler().getPSUtil().getRenderingMode() == PSRenderingMode.SIZE
&& hasOnlySolidBorders(top, bottom, left, right)) {
super.drawBorderRect(rect, top, bottom, left, right);
} else {
@@ -273,7 +256,7 @@ public class PSPainter extends AbstractIFPainter {
if (fontName == null) {
throw new NullPointerException("fontName must not be null");
}
- Typeface tf = (Typeface)getFontInfo().getFonts().get(fontName);
+ Typeface tf = getFontInfo().getFonts().get(fontName);
if (tf instanceof LazyFont) {
tf = ((LazyFont)tf).getRealFont();
}
@@ -363,10 +346,7 @@ public class PSPainter extends AbstractIFPainter {
state.getFontFamily(), state.getFontStyle(), state.getFontWeight());
//TODO Ignored: state.getFontVariant()
//TODO Opportunity for font caching if font state is more heavily used
- String fontKey = getFontInfo().getInternalFontKey(triplet);
- if (fontKey == null) {
- throw new IFException("Font not available: " + triplet, null);
- }
+ String fontKey = getFontKey(triplet);
int sizeMillipoints = state.getFontSize();
// This assumes that *all* CIDFonts use a /ToUnicode mapping
@@ -529,10 +509,9 @@ public class PSPainter extends AbstractIFPainter {
}
private void useFont(String key, int size) throws IOException {
- PSFontResource res = this.documentHandler.getPSResourceForFontKey(key);
+ PSFontResource res = getDocumentHandler().getPSResourceForFontKey(key);
PSGenerator generator = getGenerator();
generator.useFont("/" + res.getName(), size / 1000f);
res.notifyResourceUsageOnPage(generator.getResourceTracker());
}
-
}