diff options
author | Mehdi Houshmand <mehdi@apache.org> | 2012-07-02 13:23:46 +0000 |
---|---|---|
committer | Mehdi Houshmand <mehdi@apache.org> | 2012-07-02 13:23:46 +0000 |
commit | ab426a49d46ec69b80e6accccd537522477df5b3 (patch) | |
tree | a4a4550b9d329c7a7eae6a8d00861f373911c081 /src/java | |
parent | c9f6e74ddf229f879ea7df1b389d6018286ca1aa (diff) | |
parent | f5a033d38f700d70bbf679d87d535b37438c9ebb (diff) | |
download | xmlgraphics-fop-ab426a49d46ec69b80e6accccd537522477df5b3.tar.gz xmlgraphics-fop-ab426a49d46ec69b80e6accccd537522477df5b3.zip |
Merged in trunk@1356161
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_URI_Unification@1356212 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
14 files changed, 305 insertions, 159 deletions
diff --git a/src/java/org/apache/fop/fonts/FontTriplet.java b/src/java/org/apache/fop/fonts/FontTriplet.java index 945739077..2c1d89088 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; @@ -135,6 +137,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 396a2c790..5302975f6 100644 --- a/src/java/org/apache/fop/render/PrintRenderer.java +++ b/src/java/org/apache/fop/render/PrintRenderer.java @@ -108,7 +108,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 b94f396b6..fb6c89ce4 100644 --- a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java +++ b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java @@ -61,8 +61,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 86858c3c8..7d659a8b4 100644 --- a/src/java/org/apache/fop/render/afp/AFPPainter.java +++ b/src/java/org/apache/fop/render/afp/AFPPainter.java @@ -30,7 +30,13 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.Map; +import org.w3c.dom.Document; + +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; @@ -47,27 +53,22 @@ import org.apache.fop.afp.ptoca.PtocaBuilder; import org.apache.fop.afp.ptoca.PtocaProducer; import org.apache.fop.afp.util.AFPResourceAccessor; 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; import org.apache.fop.traits.BorderProps; import org.apache.fop.traits.RuleStyle; import org.apache.fop.util.CharUtilities; -import org.apache.xmlgraphics.image.loader.ImageProcessingHints; -import org.apache.xmlgraphics.image.loader.ImageSessionContext; -import org.w3c.dom.Document; /** * 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); @@ -75,8 +76,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 */ @@ -85,36 +84,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} */ @@ -180,7 +181,7 @@ public class AFPPainter extends AbstractIFPainter { protected RenderingContext createRenderingContext() { AFPRenderingContext psContext = new AFPRenderingContext( getUserAgent(), - documentHandler.getResourceManager(), + getDocumentHandler().getResourceManager(), getPaintingState(), getFontInfo(), getContext().getForeignAttributes()); @@ -189,7 +190,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}; @@ -203,10 +204,10 @@ public class AFPPainter extends AbstractIFPainter { //Do we need to embed an external page segment? if (pageSegment.getURI() != null) { AFPResourceAccessor accessor = new AFPResourceAccessor( - documentHandler.getUserAgent().getResourceResolver()); + getDocumentHandler().getUserAgent().getResourceResolver()); try { URI resourceUri = new URI(pageSegment.getURI()); - documentHandler.getResourceManager().createIncludedResourceFromExternal( + getDocumentHandler().getResourceManager().createIncludedResourceFromExternal( pageSegment.getName(), resourceUri, accessor); } catch (URISyntaxException urie) { @@ -362,14 +363,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(); @@ -383,7 +380,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 e86cc435f..147b6d54b 100644 --- a/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java +++ b/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java @@ -46,6 +46,8 @@ import org.apache.xmlgraphics.image.loader.util.ImageUtil; import org.apache.fop.ResourceEventProducer; import org.apache.fop.apps.FOUserAgent; 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; @@ -56,7 +58,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); @@ -67,18 +69,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 2f22424f5..614ebf1d2 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,13 +428,12 @@ 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 FontMetricsMapper mapper; try { - mapper = (FontMetricsMapper)parent.getFontInfo().getMetricsFor( - font.getFontName()); + mapper = (FontMetricsMapper) getFontInfo().getMetricsFor(font.getFontName()); } catch (Exception t) { throw new RuntimeException(t); } @@ -475,8 +464,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) { @@ -501,7 +489,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 1ad8034e0..dd9320571 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; @@ -68,31 +67,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 final PDFRenderingUtil pdfUtil; + private final 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); @@ -133,6 +129,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(); @@ -171,7 +183,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 f51088fab..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,30 +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(); - } - - 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(); @@ -129,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(); @@ -156,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; } @@ -317,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 488abd559..d73beb759 100644 --- a/src/java/org/apache/fop/render/ps/PSDocumentHandler.java +++ b/src/java/org/apache/fop/render/ps/PSDocumentHandler.java @@ -56,6 +56,7 @@ import org.apache.fop.apps.MimeConstants; import org.apache.fop.apps.io.TempResourceURIGenerator; 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; @@ -80,10 +81,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 URI tempURI; @@ -134,6 +135,10 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { return MimeConstants.MIME_POSTSCRIPT; } + PSGenerator getGenerator() { + return gen; + } + /** {@inheritDoc} */ public IFDocumentHandlerConfigurator getConfigurator() { return new PSRendererConfigurator(getUserAgent(), new PSRendererConfigParser()); 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()); } - } |