From d2a740ec8e10ce56949b8402e5a0943cbef66090 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Fri, 5 Oct 2007 08:48:15 +0000 Subject: [PATCH] Bugzilla #43041: Added a configuration setting for the renderer/device resolution to the AFP renderer. Many Checkstyle violations fixed. Submitted by: Adrian Cumiskey Changes to the patch by jeremias: - Bugfix: SVGs were rendered in the wrong size when the target-resolution and the renderer-resolution differ. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@582131 13f79535-47bb-0310-9956-ffa450edef68 --- .../content/xdocs/trunk/output.xml | 7 + .../apache/fop/render/afp/AFPRenderer.java | 662 ++++++++++-------- .../render/afp/AFPRendererConfigurator.java | 15 +- .../fop/render/afp/modca/AFPDataStream.java | 406 ++++++----- .../render/afp/modca/AbstractDescriptor.java | 49 ++ .../afp/modca/AbstractNamedAFPObject.java | 14 +- .../render/afp/modca/AbstractPageObject.java | 158 +++-- .../afp/modca/ActiveEnvironmentGroup.java | 83 ++- .../apache/fop/render/afp/modca/Document.java | 41 +- .../fop/render/afp/modca/EndPageGroup.java | 16 +- .../fop/render/afp/modca/IMImageObject.java | 48 +- .../fop/render/afp/modca/ImageObject.java | 83 +-- .../fop/render/afp/modca/IncludeObject.java | 21 +- .../render/afp/modca/IncludePageOverlay.java | 25 +- .../render/afp/modca/IncludePageSegment.java | 31 +- .../fop/render/afp/modca/InvokeMediumMap.java | 7 +- .../afp/modca/ObjectAreaDescriptor.java | 91 ++- .../afp/modca/ObjectEnvironmentGroup.java | 37 +- .../apache/fop/render/afp/modca/Overlay.java | 36 +- .../fop/render/afp/modca/PageDescriptor.java | 79 +-- .../fop/render/afp/modca/PageGroup.java | 36 +- .../fop/render/afp/modca/PageObject.java | 41 +- .../afp/modca/PresentationTextDescriptor.java | 69 +- .../afp/modca/PresentationTextObject.java | 21 +- .../fop/render/afp/modca/ResourceGroup.java | 22 +- .../apache/fop/render/ps/PSTextPainter.java | 13 +- status.xml | 3 + 27 files changed, 1160 insertions(+), 954 deletions(-) create mode 100644 src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java diff --git a/src/documentation/content/xdocs/trunk/output.xml b/src/documentation/content/xdocs/trunk/output.xml index 798c61811..0fd85095c 100644 --- a/src/documentation/content/xdocs/trunk/output.xml +++ b/src/documentation/content/xdocs/trunk/output.xml @@ -544,6 +544,13 @@ out = proc.getOutputStream();]]> ]]> +
+ Output Resolution +

By default the AFP Renderer creates output with a resolution of 240 dpi. + This can be overridden by the <renderer-resolution/> configuration element. Example:

+ 240]]> +
Images

By default the AFP Renderer converts all images to 8 bit grey level. diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java index 423f48d73..27c363907 100644 --- a/src/java/org/apache/fop/render/afp/AFPRenderer.java +++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java @@ -28,7 +28,6 @@ import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -53,7 +52,6 @@ import org.apache.fop.area.inline.WordArea; import org.apache.fop.fo.Constants; import org.apache.fop.fo.extensions.ExtensionAttachment; import org.apache.fop.fonts.FontInfo; -import org.apache.fop.fonts.FontMetrics; import org.apache.fop.fonts.FontTriplet; import org.apache.fop.fonts.base14.Courier; import org.apache.fop.fonts.base14.Helvetica; @@ -78,7 +76,6 @@ import org.apache.fop.render.afp.modca.ImageObject; import org.apache.fop.render.afp.modca.PageObject; import org.w3c.dom.Document; - /** * This is an implementation of a FOP Renderer that renders areas to AFP. *

@@ -94,7 +91,7 @@ import org.w3c.dom.Document; *

* The renderer will be given each page as it is ready and an output stream to * write the data out. All pages are supplied in the order they appear in the - * document. In order to save memory it is possble to render the pages out of + * document. In order to save memory it is possible to render the pages out of * order. Any page that is not ready to be rendered is setup by the renderer * first so that it can reserve a space or reference for when the page is ready * to be rendered.The renderer is responsible for managing the output format and @@ -110,7 +107,7 @@ import org.w3c.dom.Document; *

* The render context is used by handlers. It contains information about the * current state of the renderer, such as the page, the position, and any other - * miscellanous objects that are required to draw into the page. + * miscellaneous objects that are required to draw into the page. *

*

* A renderer is created by implementing the Renderer interface. However, the @@ -121,7 +118,7 @@ import org.w3c.dom.Document; * different way or do some extra processing. *

*

- * The relevent AreaTree structures that will need to be rendered are Page, + * The relevant AreaTree structures that will need to be rendered are Page, * Viewport, Region, Span, Block, Line, Inline. A renderer implementation * renders each individual page, clips and aligns child areas to a viewport, * handle all types of inline area, text, image etc and draws various lines and @@ -136,99 +133,104 @@ import org.w3c.dom.Document; public class AFPRenderer extends AbstractPathOrientedRenderer { /** - * AFP factor for a 240 resolution = 72000/240 = 300 + * The default afp renderer output resolution */ - private static final int DPI_CONVERSION_FACTOR_240 = 300; + private static final int DEFAULT_DPI_RESOLUTION = 240; + + /** + * The afp factor for calculating resolutions (e.g. 72000/240 = 300) + */ + private static final int DPI_CONVERSION_FACTOR = 72000; /** * The afp data stream object responsible for generating afp data */ - private AFPDataStream _afpDataStream = null; + private AFPDataStream afpDataStream = null; /** * The map of afp root extensions */ - private HashMap _rootExtensionMap = null; - + // UNUSED + // private HashMap rootExtensionMap = null; /** * The map of page segments */ - private HashMap _pageSegmentsMap = null; + private HashMap pageSegmentsMap = null; /** * The fonts on the current page */ - private HashMap _currentPageFonts = null; + private HashMap currentPageFonts = null; /** * The current color object */ - private Color _currentColor = null; + private Color currentColor = null; /** * The page font number counter, used to determine the next font reference */ - private int _pageFontCounter = 0; + private int pageFontCounter = 0; /** * The current font family */ - private String _currentFontFamily = ""; - + // UNUSED + // private String currentFontFamily = ""; /** * The current font size */ - private int _currentFontSize = 0; + private int currentFontSize = 0; /** * The Options to be set on the AFPRenderer */ - private Map _afpOptions = null; - + // UNUSED + // private Map afpOptions = null; /** * The page width */ - private int _pageWidth = 0; + private int pageWidth = 0; /** * The page height */ - private int _pageHeight = 0; + private int pageHeight = 0; /** * The current page sequence id */ - private String _pageSequenceId = null; - + // UNUSED + // private String pageSequenceId = null; /** * The portrait rotation */ - private int _portraitRotation = 0; + private int portraitRotation = 0; /** * The landscape rotation */ - private int _landscapeRotation = 270; + private int landscapeRotation = 270; /** * The line cache, avoids drawing duplicate lines in tables. */ - private HashSet _lineCache = null; - + // UNUSED + // private HashSet lineCache = null; /** * The current x position for line drawing */ - private float _x; - + // UNUSED + // private float x; /** * The current y position for line drawing */ - private float _y; - + // UNUSED + // private float y; /** * The map of saved incomplete pages */ - private Map _pages = null; + private Map pages = null; /** * Flag to the set the output object type for images @@ -240,6 +242,11 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { */ private int bitsPerPixel = 8; + /** + * The output resolution + */ + private int resolution = DEFAULT_DPI_RESOLUTION; + /** * Constructor for AFPRenderer. */ @@ -312,19 +319,19 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { * {@inheritDoc} */ public void startRenderer(OutputStream outputStream) throws IOException { - _currentPageFonts = new HashMap(); - _currentColor = new Color(255, 255, 255); - _afpDataStream = new AFPDataStream(); - _afpDataStream.setPortraitRotation(_portraitRotation); - _afpDataStream.setLandscapeRotation(_landscapeRotation); - _afpDataStream.startDocument(outputStream); + currentPageFonts = new HashMap(); + currentColor = new Color(255, 255, 255); + afpDataStream = new AFPDataStream(); + afpDataStream.setPortraitRotation(portraitRotation); + afpDataStream.setLandscapeRotation(landscapeRotation); + afpDataStream.startDocument(outputStream); } /** * {@inheritDoc} */ public void stopRenderer() throws IOException { - _afpDataStream.endDocument(); + afpDataStream.endDocument(); } /** @@ -344,30 +351,32 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { * * {@inheritDoc} */ - public void preparePage(PageViewport pageViewport) { + public void preparePage(PageViewport page) { // initializeRootExtensions(page); - _currentFontFamily = ""; - _currentFontSize = 0; - _pageFontCounter = 0; - _currentPageFonts.clear(); - _lineCache = new HashSet(); + // this.currentFontFamily = ""; + this.currentFontSize = 0; + this.pageFontCounter = 0; + this.currentPageFonts.clear(); + // this.lineCache = new HashSet(); - Rectangle2D bounds = pageViewport.getViewArea(); + Rectangle2D bounds = page.getViewArea(); - _pageWidth = mpts2units(bounds.getWidth()); - _pageHeight = mpts2units(bounds.getHeight()); + this.pageWidth = mpts2units(bounds.getWidth()); + this.pageHeight = mpts2units(bounds.getHeight()); // renderPageGroupExtensions(page); - _afpDataStream.startPage(_pageWidth, _pageHeight, 0); + final int pageRotation = 0; + this.afpDataStream.startPage(pageWidth, pageHeight, pageRotation, + getResolution(), getResolution()); - renderPageObjectExtensions(pageViewport); + renderPageObjectExtensions(page); - if (_pages == null) { - _pages = new HashMap(); + if (this.pages == null) { + this.pages = new HashMap(); } - _pages.put(pageViewport, _afpDataStream.savePage()); + this.pages.put(page, afpDataStream.savePage()); } @@ -546,7 +555,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { currentBPPosition += (int)(bv.getAllocBPD()); } - //currentFontName = saveFontName; + // currentFontName = saveFontName; } /** @@ -556,25 +565,27 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { // initializeRootExtensions(page); - _currentFontFamily = ""; - _currentFontSize = 0; - _pageFontCounter = 0; - _currentPageFonts.clear(); - _lineCache = new HashSet(); + // this.currentFontFamily = ""; + this.currentFontSize = 0; + this.pageFontCounter = 0; + this.currentPageFonts.clear(); + // this.lineCache = new HashSet(); Rectangle2D bounds = pageViewport.getViewArea(); - _pageWidth = mpts2units(bounds.getWidth()); - _pageHeight = mpts2units(bounds.getHeight()); + this.pageWidth = mpts2units(bounds.getWidth()); + this.pageHeight = mpts2units(bounds.getHeight()); - if (_pages != null && _pages.containsKey(pageViewport)) { + if (pages != null && pages.containsKey(pageViewport)) { - _afpDataStream.restorePage((PageObject)_pages.remove(pageViewport)); + this.afpDataStream.restorePage((PageObject) pages.remove(pageViewport)); } else { // renderPageGroupExtensions(page); - _afpDataStream.startPage(_pageWidth, _pageHeight, 0); + final int pageRotation = 0; + this.afpDataStream.startPage(pageWidth, pageHeight, pageRotation, + getResolution(), getResolution()); renderPageObjectExtensions(pageViewport); @@ -584,11 +595,11 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { renderPageAreas(pageViewport.getPage()); - Iterator i = _currentPageFonts.values().iterator(); + Iterator i = currentPageFonts.values().iterator(); while (i.hasNext()) { AFPFontAttributes afpFontAttributes = (AFPFontAttributes) i.next(); - _afpDataStream.createFont( + afpDataStream.createFont( afpFontAttributes.getFontReference(), afpFontAttributes.getFont(), afpFontAttributes.getPointSize()); @@ -596,7 +607,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { } try { - _afpDataStream.endPage(); + afpDataStream.endPage(); } catch (IOException ioex) { // TODO What shall we do? } @@ -645,22 +656,22 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { */ public void fillRect(float x, float y, float width, float height) { /* - _afpDataStream.createShading( + afpDataStream.createShading( pts2units(x), pts2units(y), pts2units(width), pts2units(height), - _currentColor.getRed(), - _currentColor.getGreen(), - _currentColor.getBlue()); + currentColor.getRed(), + currentColor.getGreen(), + currentColor.getBlue()); */ - _afpDataStream.createLine( + afpDataStream.createLine( pts2units(x), pts2units(y), pts2units(x + width), pts2units(y), pts2units(height), - _currentColor); + currentColor); } /** @@ -680,7 +691,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { float h3 = h / 3; float ym1 = y1; float ym2 = ym1 + h3 + h3; - _afpDataStream.createLine( + afpDataStream.createLine( pts2units(x1), pts2units(ym1), pts2units(x2), @@ -688,7 +699,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { pts2units(h3), col ); - _afpDataStream.createLine( + afpDataStream.createLine( pts2units(x1), pts2units(ym2), pts2units(x2), @@ -700,7 +711,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { float w3 = w / 3; float xm1 = x1; float xm2 = xm1 + w3 + w3; - _afpDataStream.createLine( + afpDataStream.createLine( pts2units(xm1), pts2units(y1), pts2units(xm1), @@ -708,7 +719,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { pts2units(w3), col ); - _afpDataStream.createLine( + afpDataStream.createLine( pts2units(xm2), pts2units(y1), pts2units(xm2), @@ -722,7 +733,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { if (horz) { float w2 = 2 * h; while (x1 + w2 < x2) { - _afpDataStream.createLine( + afpDataStream.createLine( pts2units(x1), pts2units(y1), pts2units(x1 + w2), @@ -735,7 +746,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { } else { float h2 = 2 * w; while (y1 + h2 < y2) { - _afpDataStream.createLine( + afpDataStream.createLine( pts2units(x1), pts2units(y1), pts2units(x1), @@ -750,7 +761,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { case Constants.EN_DOTTED: if (horz) { while (x1 + h < x2) { - _afpDataStream.createLine( + afpDataStream.createLine( pts2units(x1), pts2units(y1), pts2units(x1 + h), @@ -762,7 +773,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { } } else { while (y1 + w < y2) { - _afpDataStream.createLine( + afpDataStream.createLine( pts2units(x1), pts2units(y1), pts2units(x1), @@ -783,7 +794,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { Color lowercol = lightenColor(col, colFactor); float h3 = h / 3; float ym1 = y1; - _afpDataStream.createLine( + afpDataStream.createLine( pts2units(x1), pts2units(ym1), pts2units(x2), @@ -791,7 +802,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { pts2units(h3), uppercol ); - _afpDataStream.createLine( + afpDataStream.createLine( pts2units(x1), pts2units(ym1 + h3), pts2units(x2), @@ -799,7 +810,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { pts2units(h3), col ); - _afpDataStream.createLine( + afpDataStream.createLine( pts2units(x1), pts2units(ym1 + h3 + h3), pts2units(x2), @@ -812,7 +823,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { Color rightcol = lightenColor(col, colFactor); float w3 = w / 3; float xm1 = x1 + (w3 / 2); - _afpDataStream.createLine( + afpDataStream.createLine( pts2units(xm1), pts2units(y1), pts2units(xm1), @@ -820,7 +831,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { pts2units(w3), leftcol ); - _afpDataStream.createLine( + afpDataStream.createLine( pts2units(xm1 + w3), pts2units(y1), pts2units(xm1 + w3), @@ -828,7 +839,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { pts2units(w3), col ); - _afpDataStream.createLine( + afpDataStream.createLine( pts2units(xm1 + w3 + w3), pts2units(y1), pts2units(xm1 + w3 + w3), @@ -844,7 +855,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { case Constants.EN_INSET: case Constants.EN_OUTSET: default: - _afpDataStream.createLine( + afpDataStream.createLine( pts2units(x1), pts2units(y1), pts2units(horz ? x2 : x1), @@ -858,7 +869,8 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { /** * {@inheritDoc} */ - protected RendererContext createRendererContext(int x, int y, int width, int height, Map foreignAttributes) { + protected RendererContext createRendererContext(int x, int y, int width, int height, + Map foreignAttributes) { RendererContext context; context = super.createRendererContext(x, y, width, height, foreignAttributes); context.setProperty(AFPRendererContextConstants.AFP_GRAYSCALE, @@ -871,13 +883,13 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { */ public void drawImage(String url, Rectangle2D pos, Map foreignAttributes) { String name = null; - if (_pageSegmentsMap != null) { - name = (String)_pageSegmentsMap.get(url); + if (pageSegmentsMap != null) { + name = (String) pageSegmentsMap.get(url); } if (name != null) { int x = mpts2units(pos.getX() + currentIPPosition); int y = mpts2units(pos.getY() + currentBPPosition); - _afpDataStream.createIncludePageSegment(name, x, y); + afpDataStream.createIncludePageSegment(name, x, y); } else { url = ImageFactory.getURL(url); ImageFactory fact = userAgent.getFactory().getImageFactory(); @@ -929,7 +941,8 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { int y = mpts2units(pos.getY() + currentBPPosition); int w = mpts2units(pos.getWidth()); int h = mpts2units(pos.getHeight()); - ImageObject io = _afpDataStream.getImageObject(x, y, w, h); + ImageObject io = afpDataStream.getImageObject(x, y, w, h, + getResolution(), getResolution()); io.setImageParameters( (int)(fopimage.getHorizontalResolution() * 10), (int)(fopimage.getVerticalResolution() * 10), @@ -974,7 +987,8 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { int y = mpts2units(pos.getY() + currentBPPosition); int w = mpts2units(pos.getWidth()); int h = mpts2units(pos.getHeight()); - ImageObject io = _afpDataStream.getImageObject(x, y, w, h); + ImageObject io = afpDataStream.getImageObject(x, y, w, h, + getResolution(), getResolution()); io.setImageParameters( (int)(fopimage.getHorizontalResolution() * 10), (int)(fopimage.getVerticalResolution() * 10), @@ -1018,13 +1032,14 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { /** * Draws a BufferedImage to AFP. * @param bi the BufferedImage - * @param resolution the resolution of the BufferedImage + * @param imageResolution the resolution of the BufferedImage * @param x the x coordinate (in mpt) * @param y the y coordinate (in mpt) * @param w the width of the viewport (in mpt) * @param h the height of the viewport (in mpt) */ - public void drawBufferedImage(BufferedImage bi, int resolution, int x, int y, int w, int h) { + public void drawBufferedImage(BufferedImage bi, int imageResolution, int x, + int y, int w, int h) { int afpx = mpts2units(x); int afpy = mpts2units(y); int afpw = mpts2units(w); @@ -1036,9 +1051,10 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { byte[] buf = baout.toByteArray(); //Generate image - ImageObject io = _afpDataStream.getImageObject(afpx, afpy, afpw, afph); + ImageObject io = afpDataStream.getImageObject(afpx, afpy, afpw, afph, + getResolution(), getResolution()); io.setImageParameters( - resolution, resolution, + imageResolution, imageResolution, bi.getWidth(), bi.getHeight() ); @@ -1061,7 +1077,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { */ public void updateColor(Color col, boolean fill) { if (fill) { - _currentColor = col; + currentColor = col; } } @@ -1116,12 +1132,12 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { renderInlineAreaBackAndBorders(text); String name = getInternalFontNameForArea(text); - _currentFontSize = ((Integer) text.getTrait(Trait.FONT_SIZE)).intValue(); + currentFontSize = ((Integer) text.getTrait(Trait.FONT_SIZE)).intValue(); AFPFont tf = (AFPFont) fontInfo.getFonts().get(name); Color col = (Color) text.getTrait(Trait.COLOR); - int vsci = mpts2units(tf.getWidth(' ', _currentFontSize) / 1000 + int vsci = mpts2units(tf.getWidth(' ', currentFontSize) / 1000 + text.getTextWordSpaceAdjust() + text.getTextLetterSpaceAdjust()); @@ -1137,29 +1153,27 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { String worddata = text.getText(); // Create an AFPFontAttributes object from the current font details - AFPFontAttributes afpFontAttributes = - new AFPFontAttributes(name, tf, _currentFontSize); + AFPFontAttributes afpFontAttributes = new AFPFontAttributes(name, tf, currentFontSize); - if (!_currentPageFonts.containsKey(afpFontAttributes.getFontKey())) { + if (!currentPageFonts.containsKey(afpFontAttributes.getFontKey())) { // Font not found on current page, so add the new one - _pageFontCounter++; - afpFontAttributes.setFontReference(_pageFontCounter); - _currentPageFonts.put( - afpFontAttributes.getFontKey(), - afpFontAttributes); + pageFontCounter++; + afpFontAttributes.setFontReference(pageFontCounter); + currentPageFonts.put( + afpFontAttributes.getFontKey(), + afpFontAttributes); } else { // Use the previously stored font attributes - afpFontAttributes = - (AFPFontAttributes) _currentPageFonts.get( - afpFontAttributes.getFontKey()); + afpFontAttributes = (AFPFontAttributes) currentPageFonts.get( + afpFontAttributes.getFontKey()); } // Try and get the encoding to use for the font String encoding = null; try { - encoding = tf.getCharacterSet(_currentFontSize).getEncoding(); + encoding = tf.getCharacterSet(currentFontSize).getEncoding(); } catch (Throwable ex) { encoding = AFPConstants.EBCIDIC_ENCODING; log.warn( @@ -1169,7 +1183,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { } try { - _afpDataStream.createText( + afpDataStream.createText( afpFontAttributes.getFontReference(), mpts2units(rx), mpts2units(bl), @@ -1186,20 +1200,22 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { super.renderText(text); - renderTextDecoration(tf, _currentFontSize, text, bl, rx); + renderTextDecoration(tf, currentFontSize, text, bl, rx); } /** * {@inheritDoc} */ public void renderWord(WordArea word) { - String name = getInternalFontNameForArea(word.getParentArea()); - int size = ((Integer) word.getParentArea().getTrait(Trait.FONT_SIZE)).intValue(); - AFPFont tf = (AFPFont) fontInfo.getFonts().get(name); - - String s = word.getWord(); - - FontMetrics metrics = fontInfo.getMetricsFor(name); + // UNUSED + // String name = getInternalFontNameForArea(word.getParentArea()); + // int size = ((Integer) + // word.getParentArea().getTrait(Trait.FONT_SIZE)).intValue(); + // AFPFont tf = (AFPFont) fontInfo.getFonts().get(name); + // + // String s = word.getWord(); + // + // FontMetrics metrics = fontInfo.getMetricsFor(name); super.renderWord(word); } @@ -1208,13 +1224,15 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { * {@inheritDoc} */ public void renderSpace(SpaceArea space) { - String name = getInternalFontNameForArea(space.getParentArea()); - int size = ((Integer) space.getParentArea().getTrait(Trait.FONT_SIZE)).intValue(); - AFPFont tf = (AFPFont) fontInfo.getFonts().get(name); - - String s = space.getSpace(); - - FontMetrics metrics = fontInfo.getMetricsFor(name); + // UNUSED + // String name = getInternalFontNameForArea(space.getParentArea()); + // int size = ((Integer) + // space.getParentArea().getTrait(Trait.FONT_SIZE)).intValue(); + // AFPFont tf = (AFPFont) fontInfo.getFonts().get(name); + // + // String s = space.getSpace(); + // + // FontMetrics metrics = fontInfo.getMetricsFor(name); super.renderSpace(space); } @@ -1255,60 +1273,56 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { * Sets the AFPRenderer options * @param options the Map containing the options */ - public void setOptions(Map options) { - - _afpOptions = options; - - } - +// UNUSED +// public void setOptions(Map options) { +// +// this.afpOptions = options; +// +// } /** * Determines the orientation from the string representation, this method * guarantees to return a value of either 0, 90, 180 or 270. * * @return the orientation */ - private int getOrientation(String orientationString) { - - int orientation = 0; - if (orientationString != null && orientationString.length() > 0) { - try { - orientation = Integer.parseInt(orientationString); - } catch (NumberFormatException nfe) { - log.error( - "Cannot use orientation of " - + orientation - + " defaulting to zero."); - orientation = 0; - } - } else { - orientation = 0; - } - switch (orientation) { - case 0 : - break; - case 90 : - break; - case 180 : - break; - case 270 : - break; - default : - log.error( - "Cannot use orientation of " - + orientation - + " defaulting to zero."); - orientation = 0; - break; - } - - return orientation; - - } - +// UNUSED +// private int getOrientation(String orientationString) { +// +// int orientation = 0; +// if (orientationString != null && orientationString.length() > 0) { +// try { +// orientation = Integer.parseInt(orientationString); +// } catch (NumberFormatException nfe) { +// log.error("Cannot use orientation of " + orientation +// + " defaulting to zero."); +// orientation = 0; +// } +// } else { +// orientation = 0; +// } +// switch (orientation) { +// case 0: +// break; +// case 90: +// break; +// case 180: +// break; +// case 270: +// break; +// default: +// log.error("Cannot use orientation of " + orientation +// + " defaulting to zero."); +// orientation = 0; +// break; +// } +// +// return orientation; +// +// } /** * Sets the rotation to be used for portrait pages, valid values are 0 * (default), 90, 180, 270. - * + * * @param rotation * The rotation in degrees. */ @@ -1318,7 +1332,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { || rotation == 90 || rotation == 180 || rotation == 270) { - _portraitRotation = rotation; + portraitRotation = rotation; } else { throw new IllegalArgumentException("The portrait rotation must be one" + " of the values 0, 90, 180, 270"); @@ -1330,7 +1344,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { /** * Sets the rotation to be used for landsacpe pages, valid values are 0, 90, * 180, 270 (default). - * + * * @param rotation * The rotation in degrees. */ @@ -1340,7 +1354,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { || rotation == 90 || rotation == 180 || rotation == 270) { - _landscapeRotation = rotation; + landscapeRotation = rotation; } else { throw new IllegalArgumentException("The landscape rotation must be one" + " of the values 0, 90, 180, 270"); @@ -1350,7 +1364,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { /** * Get the MIME type of the renderer. - * + * * @return The MIME type of the renderer */ public String getMimeType() { @@ -1360,50 +1374,47 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { /** * Method to render the page extension. *

- * - * @param pageViewport - * the page object + * + * @param pageViewport the page object */ private void renderPageObjectExtensions(PageViewport pageViewport) { - _pageSegmentsMap = null; + pageSegmentsMap = null; if (pageViewport.getExtensionAttachments() != null - && pageViewport.getExtensionAttachments().size() > 0) { - //Extract all AFPPageSetup instances from the attachment list on the s-p-m + && pageViewport.getExtensionAttachments().size() > 0) { + // Extract all AFPPageSetup instances from the attachment list on + // the s-p-m Iterator i = pageViewport.getExtensionAttachments().iterator(); while (i.hasNext()) { ExtensionAttachment attachment = (ExtensionAttachment)i.next(); if (AFPPageSetup.CATEGORY.equals(attachment.getCategory())) { - if (attachment instanceof AFPPageSetup) { - AFPPageSetup aps = (AFPPageSetup)attachment; - if (log.isDebugEnabled()) { - log.debug(aps); + AFPPageSetup aps = (AFPPageSetup) attachment; + String element = aps.getElementName(); + if (AFPElementMapping.INCLUDE_PAGE_OVERLAY.equals(element)) { + String overlay = aps.getName(); + if (overlay != null) { + afpDataStream.createIncludePageOverlay(overlay); + } + } else if (AFPElementMapping.INCLUDE_PAGE_SEGMENT + .equals(element)) { + String name = aps.getName(); + String source = aps.getValue(); + if (pageSegmentsMap == null) { + pageSegmentsMap = new HashMap(); } - String element = aps.getElementName(); - if (AFPElementMapping.INCLUDE_PAGE_OVERLAY.equals(element)) { - String overlay = aps.getName(); - if (overlay != null) { - _afpDataStream.createIncludePageOverlay(overlay); - } - } else if (AFPElementMapping.INCLUDE_PAGE_SEGMENT.equals(element)) { - String name = aps.getName(); - String source = aps.getValue(); - if (_pageSegmentsMap == null) { - _pageSegmentsMap = new HashMap(); - } - _pageSegmentsMap.put(source, name); - } else if (AFPElementMapping.TAG_LOGICAL_ELEMENT.equals(element)) { - String name = aps.getName(); - String value = aps.getValue(); - if (_pageSegmentsMap == null) { - _pageSegmentsMap = new HashMap(); - } - _afpDataStream.createTagLogicalElement(name, value); - } else if (AFPElementMapping.NO_OPERATION.equals(element)) { - String content = aps.getContent(); - if (content != null) { - _afpDataStream.createNoOperation(content); - } + pageSegmentsMap.put(source, name); + } else if (AFPElementMapping.TAG_LOGICAL_ELEMENT + .equals(element)) { + String name = aps.getName(); + String value = aps.getValue(); + if (pageSegmentsMap == null) { + pageSegmentsMap = new HashMap(); + } + afpDataStream.createTagLogicalElement(name, value); + } else if (AFPElementMapping.NO_OPERATION.equals(element)) { + String content = aps.getContent(); + if (content != null) { + afpDataStream.createNoOperation(content); } } } @@ -1430,10 +1441,13 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { /** * Converts FOP mpt measurement to afp measurement units - * @param mpt the millipoints value + * + * @param mpt + * the millipoints value + * @return afp measurement unit value */ private int mpts2units(double mpt) { - return (int)Math.round(mpt / DPI_CONVERSION_FACTOR_240); + return (int)Math.round(mpt / (DPI_CONVERSION_FACTOR / getResolution())); } /** @@ -1460,120 +1474,124 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { double greyVal = 0.212671d * ((int) raw[i] & 0xff) + 0.715160d * ((int) raw[i + 1] & 0xff) + 0.072169d * ((int) raw[i + 2] & 0xff); - switch (bitsPerPixel) { - case 1: - if (greyVal < 128) { - ib |= (byte)(1 << (7 - (x % 8))); - } - break; - case 4: - greyVal /= 16; - ib |= (byte)((byte)greyVal << ((1 - (x % 2)) * 4)); - break; - case 8: - ib = (byte)greyVal; - break; - default: - throw new UnsupportedOperationException( + case 1: + if (greyVal < 128) { + ib |= (byte) (1 << (7 - (x % 8))); + } + break; + case 4: + greyVal /= 16; + ib |= (byte) ((byte) greyVal << ((1 - (x % 2)) * 4)); + break; + case 8: + ib = (byte) greyVal; + break; + default: + throw new UnsupportedOperationException( "Unsupported bits per pixel: " + bitsPerPixel); } - - if ((x % pixelsPerByte) == (pixelsPerByte - 1) || ((x + 1) == width)) { + + if ((x % pixelsPerByte) == (pixelsPerByte - 1) + || ((x + 1) == width)) { bw[(y * bytewidth) + (x / pixelsPerByte)] = ib; ib = 0; } } } - io.setImageIDESize((byte)bitsPerPixel); + io.setImageIDESize((byte) bitsPerPixel); io.setImageData(bw); } + + private final class ViewPortPos { + private int x = 0; + + private int y = 0; - private class ViewPortPos { - int x = 0; - int y = 0; - int rot = 0; + private int rot = 0; - ViewPortPos() { + private ViewPortPos() { } - ViewPortPos(Rectangle2D view, CTM ctm) { - ViewPortPos currentVP = (ViewPortPos)viewPortPositions.get(viewPortPositions.size() - 1); + private ViewPortPos(Rectangle2D view, CTM ctm) { + ViewPortPos currentVP = (ViewPortPos) viewPortPositions + .get(viewPortPositions.size() - 1); int xOrigin; int yOrigin; int width; int height; switch (currentVP.rot) { - case 90: - width = mpts2units(view.getHeight()); - height = mpts2units(view.getWidth()); - xOrigin = _pageWidth - width - mpts2units(view.getY()) - currentVP.y; - yOrigin = mpts2units(view.getX()) + currentVP.x; - break; - case 180: - width = mpts2units(view.getWidth()); - height = mpts2units(view.getHeight()); - xOrigin = _pageWidth - width - mpts2units(view.getX()) - currentVP.x; - yOrigin = _pageHeight - height - mpts2units(view.getY()) - currentVP.y; - break; - case 270: - width = mpts2units(view.getHeight()); - height = mpts2units(view.getWidth()); - xOrigin = mpts2units(view.getY()) + currentVP.y; - yOrigin = _pageHeight - height - mpts2units(view.getX()) - currentVP.x; - break; - default: - xOrigin = mpts2units(view.getX()) + currentVP.x; - yOrigin = mpts2units(view.getY()) + currentVP.y; - width = mpts2units(view.getWidth()); - height = mpts2units(view.getHeight()); - break; + case 90: + width = mpts2units(view.getHeight()); + height = mpts2units(view.getWidth()); + xOrigin = pageWidth - width - mpts2units(view.getY()) + - currentVP.y; + yOrigin = mpts2units(view.getX()) + currentVP.x; + break; + case 180: + width = mpts2units(view.getWidth()); + height = mpts2units(view.getHeight()); + xOrigin = pageWidth - width - mpts2units(view.getX()) + - currentVP.x; + yOrigin = pageHeight - height - mpts2units(view.getY()) + - currentVP.y; + break; + case 270: + width = mpts2units(view.getHeight()); + height = mpts2units(view.getWidth()); + xOrigin = mpts2units(view.getY()) + currentVP.y; + yOrigin = pageHeight - height - mpts2units(view.getX()) + - currentVP.x; + break; + default: + xOrigin = mpts2units(view.getX()) + currentVP.x; + yOrigin = mpts2units(view.getY()) + currentVP.y; + width = mpts2units(view.getWidth()); + height = mpts2units(view.getHeight()); + break; } this.rot = currentVP.rot; - double ctmf[] = ctm.toArray(); - if (ctmf[0] == 0.0d && ctmf[1] == -1.0d && ctmf[2] == 1.0d && ctmf[3] == 0.d) { + double[] ctmf = ctm.toArray(); + if (ctmf[0] == 0.0d && ctmf[1] == -1.0d && ctmf[2] == 1.0d + && ctmf[3] == 0.d) { this.rot += 270; - } else if (ctmf[0] == -1.0d && ctmf[1] == 0.0d && ctmf[2] == 0.0d && ctmf[3] == -1.0d) { + } else if (ctmf[0] == -1.0d && ctmf[1] == 0.0d && ctmf[2] == 0.0d + && ctmf[3] == -1.0d) { this.rot += 180; - } else if (ctmf[0] == 0.0d && ctmf[1] == 1.0d && ctmf[2] == -1.0d && ctmf[3] == 0.0d) { + } else if (ctmf[0] == 0.0d && ctmf[1] == 1.0d && ctmf[2] == -1.0d + && ctmf[3] == 0.0d) { this.rot += 90; } this.rot %= 360; switch (this.rot) { - /* - case 0: - this.x = mpts2units(view.getX()) + x; - this.y = mpts2units(view.getY()) + y; - break; - case 90: - this.x = mpts2units(view.getY()) + y; - this.y = _pageWidth - mpts2units(view.getX() + view.getWidth()) - x; - break; - case 180: - this.x = _pageWidth - mpts2units(view.getX() + view.getWidth()) - x; - this.y = _pageHeight - mpts2units(view.getY() + view.getHeight()) - y; - break; - case 270: - this.x = _pageHeight - mpts2units(view.getY() + view.getHeight()) - y; - this.y = mpts2units(view.getX()) + x; - break; - */ - case 0: - this.x = xOrigin; - this.y = yOrigin; - break; - case 90: - this.x = yOrigin; - this.y = _pageWidth - width - xOrigin; - break; - case 180: - this.x = _pageWidth - width - xOrigin; - this.y = _pageHeight - height - yOrigin; - break; - case 270: - this.x = _pageHeight - height - yOrigin; - this.y = xOrigin; - break; + /* + * case 0: this.x = mpts2units(view.getX()) + x; this.y = + * mpts2units(view.getY()) + y; break; case 90: this.x = + * mpts2units(view.getY()) + y; this.y = _pageWidth - + * mpts2units(view.getX() + view.getWidth()) - x; break; case 180: + * this.x = _pageWidth - mpts2units(view.getX() + view.getWidth()) - + * x; this.y = _pageHeight - mpts2units(view.getY() + + * view.getHeight()) - y; break; case 270: this.x = _pageHeight - + * mpts2units(view.getY() + view.getHeight()) - y; this.y = + * mpts2units(view.getX()) + x; break; + */ + case 0: + this.x = xOrigin; + this.y = yOrigin; + break; + case 90: + this.x = yOrigin; + this.y = pageWidth - width - xOrigin; + break; + case 180: + this.x = pageWidth - width - xOrigin; + this.y = pageHeight - height - yOrigin; + break; + case 270: + this.x = pageHeight - height - yOrigin; + this.y = xOrigin; + break; + default: } } @@ -1587,17 +1605,23 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { private void pushViewPortPos(ViewPortPos vpp) { viewPortPositions.add(vpp); - _afpDataStream.setOffsets(vpp.x, vpp.y, vpp.rot); + afpDataStream.setOffsets(vpp.x, vpp.y, vpp.rot); } private void popViewPortPos() { viewPortPositions.remove(viewPortPositions.size() - 1); if (viewPortPositions.size() > 0) { ViewPortPos vpp = (ViewPortPos)viewPortPositions.get(viewPortPositions.size() - 1); - _afpDataStream.setOffsets(vpp.x, vpp.y, vpp.rot); + afpDataStream.setOffsets(vpp.x, vpp.y, vpp.rot); } } + /** + * Sets the number of bits used per pixel + * + * @param bitsPerPixel + * number of bits per pixel + */ public void setBitsPerPixel(int bitsPerPixel) { this.bitsPerPixel = bitsPerPixel; switch (bitsPerPixel) { @@ -1612,8 +1636,34 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { } } + /** + * Sets whether images are color or not + * + * @param colorImages + * color image output + */ public void setColorImages(boolean colorImages) { this.colorImages = colorImages; } -} + /** + * Sets the output/device resolution + * + * @param resolution + * the output resolution (dpi) + */ + public void setResolution(int resolution) { + if (log.isDebugEnabled()) { + log.debug("renderer-resolution set to: " + resolution + "dpi"); + } + this.resolution = resolution; + } + + /** + * Returns the output/device resolution. + * @return the resolution in dpi + */ + public int getResolution() { + return this.resolution; + } +} diff --git a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java index aebabd97b..dee741ab4 100644 --- a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java +++ b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java @@ -41,7 +41,7 @@ import org.apache.fop.util.LogUtil; * AFP Renderer configurator */ public class AFPRendererConfigurator extends PrintRendererConfigurator { - + /** * Default constructor * @param userAgent user agent @@ -229,13 +229,18 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator { LogUtil.handleException(log, e, userAgent.getFactory().validateUserConfigStrictly()); } - - Configuration images = cfg.getChild("images"); - if (!"color".equalsIgnoreCase(images.getAttribute("mode", "b+w"))) { - afpRenderer.setBitsPerPixel(images.getAttributeAsInteger("bits-per-pixel", 8)); + + Configuration imagesCfg = cfg.getChild("images"); + if (!"color".equalsIgnoreCase(imagesCfg.getAttribute("mode", "b+w"))) { + afpRenderer.setBitsPerPixel(imagesCfg.getAttributeAsInteger("bits-per-pixel", 8)); } else { afpRenderer.setColorImages(true); } + + Configuration rendererResolutionCfg = cfg.getChild("renderer-resolution", false); + if (rendererResolutionCfg != null) { + afpRenderer.setResolution(rendererResolutionCfg.getValueAsInteger(240)); + } } } } diff --git a/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java b/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java index 88fc45ad7..ba37b989e 100644 --- a/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java +++ b/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java @@ -34,7 +34,7 @@ import org.apache.fop.render.afp.tools.StringUtils; * destined for a presentation service, archive library, presentation device or * another application program. The strategic presentation data stream * architectures used is Mixed Object Document Content Architecture (MO:DCA�). - * + * * The MO:DCA architecture defines the data stream used by applications to * describe documents and object envelopes for interchange with other * applications and application services. Documents defined in the MO:DCA format @@ -42,94 +42,96 @@ import org.apache.fop.render.afp.tools.StringUtils; * printed in local or distributed systems environments. Presentation fidelity * is accommodated by including resource objects in the documents that reference * them. - * + * */ public class AFPDataStream { /** * Static logging instance */ - protected static final Log log = LogFactory.getLog("org.apache.fop.render.afp.modca"); + protected static Log log = LogFactory.getLog("org.apache.fop.render.afp.modca"); /** * Boolean completion indicator */ - private boolean _complete = false; + private boolean complete = false; /** * The application producing the AFP document */ - private String _producer = null; +// not used +// private String producer = null; /** * The AFP document object */ - private Document _document = null; + private Document document = null; /** * The current page group object */ - private PageGroup _currentPageGroup = null; + private PageGroup currentPageGroup = null; /** * The current page object */ - private PageObject _currentPageObject = null; + private PageObject currentPageObject = null; /** * The current overlay object */ - private Overlay _currentOverlay = null; + private Overlay currentOverlay = null; /** * The current page */ - private AbstractPageObject _currentPage = null; + private AbstractPageObject currentPage = null; /** * The page count */ - private int _pageCount = 0; + private int pageCount = 0; /** * The page group count */ - private int _pageGroupCount = 0; +// not used +// private int pageGroupCount = 0; /** * The overlay count */ - private int _ovlCount = 0; + private int ovlCount = 0; /** * The portrait rotation */ - private int _portraitRotation = 0; + private int portraitRotation = 0; /** * The landscape rotation */ - private int _landscapeRotation = 270; + private int landscapeRotation = 270; /** * The x offset */ - private int _xOffset = 0; + private int xOffset = 0; /** * The y offset */ - private int _yOffset = 0; + private int yOffset = 0; /** * The rotation */ - private int _rotation; + private int rotation; /** * The outputstream for the data stream */ - private OutputStream _outputStream = null; + private OutputStream outputStream = null; /** * Default constructor for the AFPDataStream. @@ -140,17 +142,20 @@ public class AFPDataStream { /** * The document is started by invoking this method which creates an instance * of the AFP Document object. + * + * @param docOutputStream + * the outputStream which the document is written to. */ - public void startDocument(OutputStream outputStream) { + public void startDocument(OutputStream docOutputStream) { - if (_document != null) { + if (document != null) { String msg = "Invalid state - document already started."; log.warn("startDocument():: " + msg); throw new IllegalStateException(msg); } - _document = new Document(); - _outputStream = outputStream; + this.document = new Document(); + this.outputStream = docOutputStream; } @@ -158,63 +163,72 @@ public class AFPDataStream { * The document is ended by invoking this method which creates an instance * of the AFP Document object and registers the start with a validation map * which ensures that methods are not invoked out of the correct sequence. + * + * @throws java.io.IOException + * throws an I/O exception of some sort has occurred */ - public void endDocument() - throws IOException { + public void endDocument() throws IOException { - if (_complete) { + if (complete) { String msg = "Invalid state - document already ended."; log.warn("endDocument():: " + msg); throw new IllegalStateException(msg); } - if (_currentPageObject != null) { + if (currentPageObject != null) { // End the current page if necessary endPage(); } - if (_currentPageGroup != null) { + if (currentPageGroup != null) { // End the current page group if necessary endPageGroup(); } - _document.endDocument(); - _document.writeDataStream(_outputStream); - _outputStream.flush(); + document.endDocument(); + document.writeDataStream(this.outputStream); + this.outputStream.flush(); - _complete = true; + complete = true; - _document = null; + document = null; - _outputStream = null; + this.outputStream = null; } /** * Start a new page. When processing has finished on the current page, the * {@link #endPage()}method must be invoked to mark the page ending. - * + * * @param pageWidth * the width of the page * @param pageHeight * the height of the page * @param pageRotation * the rotation of the page + * @param pageWidthResolution + * the width resolution of the page + * @param pageHeightResolution + * the height resolution of the page */ - public void startPage(int pageWidth, int pageHeight, int pageRotation) { + public void startPage(int pageWidth, int pageHeight, int pageRotation, + int pageWidthResolution, int pageHeightResolution) { String pageName = "PGN" - + StringUtils.lpad(String.valueOf(_pageCount++), '0', 5); + + StringUtils.lpad(String.valueOf(pageCount++), '0', 5); - _currentPageObject = new PageObject(pageName, pageWidth, pageHeight, pageRotation); - _currentPage = _currentPageObject; - _currentOverlay = null; + currentPageObject = new PageObject(pageName, pageWidth, pageHeight, + pageRotation, pageWidthResolution, pageHeightResolution); + currentPage = currentPageObject; + currentOverlay = null; setOffsets(0, 0, 0); } /** - * Start a new overlay. When processing has finished on the current overlay, the - * {@link #endOverlay()}method must be invoked to mark the overlay ending. - * + * Start a new overlay. When processing has finished on the current overlay, + * the {@link #endOverlay()}method must be invoked to mark the overlay + * ending. + * * @param overlayX * the x position of the overlay on the page * @param overlayY @@ -223,18 +237,27 @@ public class AFPDataStream { * the width of the overlay * @param overlayHeight * the height of the overlay + * @param overlayWidthResolution + * the width resolution of the overlay + * @param overlayHeightResolution + * the height resolution of the overlay * @param overlayRotation * the rotation of the overlay */ - public void startOverlay(int overlayX, int overlayY, int overlayWidth, int overlayHeight, int overlayRotation) { + public void startOverlay(int overlayX, int overlayY, int overlayWidth, + int overlayHeight, int overlayWidthResolution, + int overlayHeightResolution, int overlayRotation) { String overlayName = "OVL" - + StringUtils.lpad(String.valueOf(_ovlCount++), '0', 5); - - _currentOverlay = new Overlay(overlayName, overlayWidth, overlayHeight, overlayRotation); - _currentPageObject.addOverlay(_currentOverlay); - _currentPageObject.createIncludePageOverlay(overlayName, overlayX, overlayY, 0); - _currentPage = _currentOverlay; + + StringUtils.lpad(String.valueOf(ovlCount++), '0', 5); + + currentOverlay = new Overlay(overlayName, overlayWidth, overlayHeight, + overlayWidthResolution, overlayHeightResolution, + overlayRotation); + currentPageObject.addOverlay(currentOverlay); + currentPageObject.createIncludePageOverlay(overlayName, overlayX, + overlayY, 0); + currentPage = currentOverlay; setOffsets(0, 0, 0); } @@ -243,79 +266,86 @@ public class AFPDataStream { */ public void endOverlay() { - _currentOverlay.endPage(); - _currentOverlay = null; - _currentPage = _currentPageObject; + currentOverlay.endPage(); + currentOverlay = null; + currentPage = currentPageObject; } /** * Helper method to save the current page. + * + * @return current page object that was saved */ public PageObject savePage() { - PageObject pageObject = _currentPageObject; - if (_currentPageGroup != null) { - _currentPageGroup.addPage(_currentPageObject); + PageObject pageObject = currentPageObject; + if (currentPageGroup != null) { + currentPageGroup.addPage(currentPageObject); } else { - _document.addPage(_currentPageObject); + document.addPage(currentPageObject); } - _currentPageObject = null; - _currentPage = null; + currentPageObject = null; + currentPage = null; return pageObject; } /** * Helper method to restore the current page. + * + * @param pageObject + * page object */ public void restorePage(PageObject pageObject) { - _currentPageObject = pageObject; - _currentPage = pageObject; + currentPageObject = pageObject; + currentPage = pageObject; } /** * Helper method to mark the end of the current page. + * + * @throws java.io.IOException + * thrown when an I/O exception of some sort has occurred */ - public void endPage() - throws IOException { + public void endPage() throws IOException { - _currentPageObject.endPage(); - if (_currentPageGroup != null) { - _currentPageGroup.addPage(_currentPageObject); + currentPageObject.endPage(); + if (currentPageGroup != null) { + currentPageGroup.addPage(currentPageObject); } else { - _document.addPage(_currentPageObject); - _document.writeDataStream(_outputStream); + document.addPage(currentPageObject); + document.writeDataStream(this.outputStream); } - _currentPageObject = null; - _currentPage = null; + currentPageObject = null; + currentPage = null; } /** * Sets the offsets to be used for element positioning - * - * @param xOffset + * + * @param xOff * the offset in the x direction - * @param yOffset + * @param yOff * the offset in the y direction - * @param rotation + * @param rot * the rotation */ - public void setOffsets(int xOffset, int yOffset, int rotation) { - _xOffset = xOffset; - _yOffset = yOffset; - _rotation = rotation; + public void setOffsets(int xOff, int yOff, int rot) { + this.xOffset = xOff; + this.yOffset = yOff; + this.rotation = rot; } /** * Helper method to create a map coded font object on the current page, this * method delegates the construction of the map coded font object to the * active environment group on the current page. - * + * * @param fontReference * the font number used as the resource identifier * @param font @@ -325,14 +355,14 @@ public class AFPDataStream { */ public void createFont(byte fontReference, AFPFont font, int size) { - _currentPage.createFont(fontReference, font, size); + currentPage.createFont(fontReference, font, size); } /** * Helper method to create text on the current page, this method delegates * to the current presentation text object in order to construct the text. - * + * * @param fontNumber * the font number used as the resource identifier * @param x @@ -348,15 +378,17 @@ public class AFPDataStream { * @param data * the text data to create */ - public void createText(int fontNumber, int x, int y, Color col, int vsci, int ica, byte[] data) { + public void createText(int fontNumber, int x, int y, Color col, int vsci, + int ica, byte[] data) { - _currentPage.createText(fontNumber, x + _xOffset, y + _yOffset, _rotation, col, vsci, ica, data); + currentPage.createText(fontNumber, x + xOffset, y + yOffset, rotation, + col, vsci, ica, data); } /** * Returns an ImageObject used to create an image in the datastream. - * + * * @param x * the x position of the image * @param y @@ -365,48 +397,65 @@ public class AFPDataStream { * the width of the image * @param h * the height of the image + * @param wr + * the width resolution of the image + * @param hr + * the height resolution of the image + * @return ImageObject used to create an image in the datastream */ - public ImageObject getImageObject(int x, int y, int w, int h) { + public ImageObject getImageObject(int x, int y, int w, int h, int wr, int hr) { int xOrigin; int yOrigin; int width; int height; - switch (_rotation) { - case 90: - xOrigin = _currentPage.getWidth() - y - _yOffset; - yOrigin = x + _xOffset; - width = h; - height = w; - break; - case 180: - xOrigin = _currentPage.getWidth() - x - _xOffset; - yOrigin = _currentPage.getHeight() - y - _yOffset; - width = w; - height = h; - break; - case 270: - xOrigin = y + _yOffset; - yOrigin = _currentPage.getHeight() - x - _xOffset; - width = h; - height = w; - break; - default: - xOrigin = x + _xOffset; - yOrigin = y + _yOffset; - width = w; - height = h; - break; + int widthResolution; + int heightResolution; + + switch (rotation) { + case 90: + xOrigin = currentPage.getWidth() - y - yOffset; + yOrigin = x + xOffset; + width = h; + height = w; + widthResolution = hr; + heightResolution = wr; + break; + case 180: + xOrigin = currentPage.getWidth() - x - xOffset; + yOrigin = currentPage.getHeight() - y - yOffset; + width = w; + height = h; + widthResolution = wr; + heightResolution = hr; + break; + case 270: + xOrigin = y + yOffset; + yOrigin = currentPage.getHeight() - x - xOffset; + width = h; + height = w; + widthResolution = hr; + heightResolution = wr; + break; + default: + xOrigin = x + xOffset; + yOrigin = y + yOffset; + width = w; + height = h; + widthResolution = wr; + heightResolution = hr; + break; } - ImageObject io = _currentPage.getImageObject(); - io.setImageViewport(xOrigin, yOrigin, width, height, _rotation); + ImageObject io = currentPage.getImageObject(); + io.setImageViewport(xOrigin, yOrigin, width, height, rotation, + widthResolution, heightResolution); return io; } /** * Method to create a line on the current page. - * + * * @param x1 * the first x coordinate of the line * @param y1 @@ -420,9 +469,11 @@ public class AFPDataStream { * @param col * The text color. */ - public void createLine(int x1, int y1, int x2, int y2, int thickness, Color col) { + public void createLine(int x1, int y1, int x2, int y2, int thickness, + Color col) { - _currentPage.createLine(x1 + _xOffset, y1 + _yOffset, x2 + _xOffset, y2 + _yOffset, thickness, _rotation, col); + currentPage.createLine(x1 + xOffset, y1 + yOffset, x2 + xOffset, y2 + + yOffset, thickness, rotation, col); } @@ -430,7 +481,7 @@ public class AFPDataStream { * This method will create shading on the page using the specified * coordinates (the shading contrast is controlled via the red, green, blue * parameters, by converting this to grey scale). - * + * * @param x * the x coordinate of the shading * @param y @@ -447,45 +498,47 @@ public class AFPDataStream { * the blue value */ public void createShading(int x, int y, int w, int h, int red, int green, - int blue) { + int blue) { - _currentPage.createShading(x + _xOffset, y + _xOffset, w, h, red, green, blue); + currentPage.createShading(x + xOffset, y + xOffset, w, h, red, green, + blue); } /** * Helper method which allows creation of the MPO object, via the AEG. And * the IPO via the Page. (See actual object for descriptions.) - * + * * @param name * the name of the static overlay */ public void createIncludePageOverlay(String name) { - _currentPageObject.createIncludePageOverlay(name, 0, 0, _rotation); - ActiveEnvironmentGroup aeg = _currentPageObject.getActiveEnvironmentGroup(); + currentPageObject.createIncludePageOverlay(name, 0, 0, rotation); + ActiveEnvironmentGroup aeg = currentPageObject + .getActiveEnvironmentGroup(); aeg.createOverlay(name); } /** * Helper method which allows creation of the IMM object. - * + * * @param name * the name of the medium map */ public void createInvokeMediumMap(String name) { - if (_currentPageGroup == null) { + if (currentPageGroup == null) { startPageGroup(); } - _currentPageGroup.createInvokeMediumMap(name); + currentPageGroup.createInvokeMediumMap(name); } /** * Creates an IncludePageSegment on the current page. - * + * * @param name * the name of the include page segment * @param x @@ -497,31 +550,31 @@ public class AFPDataStream { int xOrigin; int yOrigin; - switch (_rotation) { - case 90: - xOrigin = _currentPage.getWidth() - y - _yOffset; - yOrigin = x + _xOffset; - break; - case 180: - xOrigin = _currentPage.getWidth() - x - _xOffset; - yOrigin = _currentPage.getHeight() - y - _yOffset; - break; - case 270: - xOrigin = y + _yOffset; - yOrigin = _currentPage.getHeight() - x - _xOffset; - break; - default: - xOrigin = x + _xOffset; - yOrigin = y + _yOffset; - break; + switch (rotation) { + case 90: + xOrigin = currentPage.getWidth() - y - yOffset; + yOrigin = x + xOffset; + break; + case 180: + xOrigin = currentPage.getWidth() - x - xOffset; + yOrigin = currentPage.getHeight() - y - yOffset; + break; + case 270: + xOrigin = y + yOffset; + yOrigin = currentPage.getHeight() - x - xOffset; + break; + default: + xOrigin = x + xOffset; + yOrigin = y + yOffset; + break; } - _currentPage.createIncludePageSegment(name, xOrigin, yOrigin); + currentPage.createIncludePageSegment(name, xOrigin, yOrigin); } /** * Creates a TagLogicalElement on the current page. - * + * * @param attributes * the array of key value pairs. */ @@ -530,31 +583,31 @@ public class AFPDataStream { for (int i = 0; i < attributes.length; i++) { String name = (String) attributes[i].getKey(); String value = (String) attributes[i].getValue(); - _currentPage.createTagLogicalElement(name, value); + currentPage.createTagLogicalElement(name, value); } } /** * Creates a TagLogicalElement on the current page group. - * + * * @param attributes * the array of key value pairs. */ public void createPageGroupTagLogicalElement( - TagLogicalElementBean[] attributes) { + TagLogicalElementBean[] attributes) { for (int i = 0; i < attributes.length; i++) { String name = (String) attributes[i].getKey(); String value = (String) attributes[i].getValue(); - _currentPageGroup.createTagLogicalElement(name, value); + currentPageGroup.createTagLogicalElement(name, value); } } /** * Creates a TagLogicalElement on the current page or page group - * + * * @param name * The tag name * @param value @@ -562,10 +615,10 @@ public class AFPDataStream { */ public void createTagLogicalElement(String name, String value) { - if (_currentPageGroup != null) { - _currentPageGroup.createTagLogicalElement(name, value); + if (currentPageGroup != null) { + currentPageGroup.createTagLogicalElement(name, value); } else { - _currentPage.createTagLogicalElement(name, value); + currentPage.createTagLogicalElement(name, value); } } @@ -573,10 +626,11 @@ public class AFPDataStream { /** * Creates a NoOperation item * - * @param content byte data + * @param content + * byte data */ public void createNoOperation(String content) { - _currentPage.createNoOperation(content); + currentPage.createNoOperation(content); } /** @@ -587,40 +641,40 @@ public class AFPDataStream { public void startPageGroup() { String pageGroupName = "PGP" - + StringUtils.lpad(String.valueOf(_pageCount++), '0', 5); + + StringUtils.lpad(String.valueOf(pageCount++), '0', 5); - _currentPageGroup = new PageGroup(pageGroupName); + currentPageGroup = new PageGroup(pageGroupName); } /** * Helper method to mark the end of the page group. + * @throws IOException thrown if an I/O exception of some sort has occurred */ - public void endPageGroup() - throws IOException { + public void endPageGroup() throws IOException { - _currentPageGroup.endPageGroup(); - _document.addPageGroup(_currentPageGroup); - _document.writeDataStream(_outputStream); - _currentPageGroup = null; + currentPageGroup.endPageGroup(); + document.addPageGroup(currentPageGroup); + document.writeDataStream(outputStream); + currentPageGroup = null; } /** * Sets the rotation to be used for portrait pages, valid values are 0 * (default), 90, 180, 270. - * - * @param rotation + * + * @param pageRotation * The rotation in degrees. */ - public void setPortraitRotation(int rotation) { + public void setPortraitRotation(int pageRotation) { - if (rotation == 0 || rotation == 90 || rotation == 180 - || rotation == 270) { - _portraitRotation = rotation; + if (pageRotation == 0 || pageRotation == 90 || pageRotation == 180 + || pageRotation == 270) { + this.portraitRotation = pageRotation; } else { throw new IllegalArgumentException( - "The portrait rotation must be one of the values 0, 90, 180, 270"); + "The portrait rotation must be one of the values 0, 90, 180, 270"); } } @@ -628,18 +682,18 @@ public class AFPDataStream { /** * Sets the rotation to be used for landscape pages, valid values are 0, 90, * 180, 270 (default). - * - * @param rotation + * + * @param pageRotation * The rotation in degrees. */ - public void setLandscapeRotation(int rotation) { + public void setLandscapeRotation(int pageRotation) { - if (rotation == 0 || rotation == 90 || rotation == 180 - || rotation == 270) { - _landscapeRotation = rotation; + if (pageRotation == 0 || pageRotation == 90 || pageRotation == 180 + || pageRotation == 270) { + this.landscapeRotation = pageRotation; } else { throw new IllegalArgumentException( - "The landscape rotation must be one of the values 0, 90, 180, 270"); + "The landscape rotation must be one of the values 0, 90, 180, 270"); } } diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java b/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java new file mode 100644 index 000000000..6d827766e --- /dev/null +++ b/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java @@ -0,0 +1,49 @@ +/* + * 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.afp.modca; + +/** + * Base class for AFP descriptor objects + */ +public abstract class AbstractDescriptor extends AbstractAFPObject { + /** width of this descriptor */ + protected int width = 0; + /** height of this descriptor */ + protected int height = 0; + /** width resolution of this descriptor */ + protected int widthResolution = 0; + /** height resolution of this descriptor */ + protected int heightResolution = 0; + + /** + * Constructor a PresentationTextDescriptor for the specified + * width and height. + * @param width The width of the page. + * @param height The height of the page. + * @param widthResolution The width resolution of the page. + * @param heightResolution The height resolution of the page. + */ + public AbstractDescriptor(int width, int height, int widthResolution, int heightResolution) { + this.width = width; + this.height = height; + this.widthResolution = widthResolution; + this.heightResolution = heightResolution; + } +} diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java index b4e4022a7..d8c99fa9a 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java @@ -23,19 +23,18 @@ import java.io.UnsupportedEncodingException; /** * This is the base class for all named data stream objects. * A named data stream object has an 8 byte EBCIDIC name. - * */ -public abstract class AbstractNamedAFPObject extends AbstractAFPObject{ +public abstract class AbstractNamedAFPObject extends AbstractAFPObject { /** * The actual name of the object */ - protected String _name = null; + protected String name = null; /** * The name of the object in EBCIDIC bytes */ - protected byte[] _nameBytes; + protected byte[] nameBytes; /** * Constructor for the ActiveEnvironmentGroup, this takes a @@ -44,20 +43,21 @@ public abstract class AbstractNamedAFPObject extends AbstractAFPObject{ */ public AbstractNamedAFPObject(String name) { + this.name = name; if (name.length() < 8) { name = (name + " ").substring(0, 8); } else if (name.length() > 8) { - log.warn("Constructor:: name truncated to 8 chars"+ name); + log.warn("Constructor:: name truncated to 8 chars" + name); name = name.substring(0, 8); } try { - _nameBytes = name.getBytes(AFPConstants.EBCIDIC_ENCODING); + nameBytes = name.getBytes(AFPConstants.EBCIDIC_ENCODING); } catch (UnsupportedEncodingException usee) { - _nameBytes = name.getBytes(); + nameBytes = name.getBytes(); log.warn( "Constructor:: UnsupportedEncodingException translating the name " + name); diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java index 90d83cb55..a99b28107 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java @@ -20,7 +20,6 @@ package org.apache.fop.render.afp.modca; import java.awt.Color; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; @@ -52,47 +51,47 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { /** * The active environment group for the page */ - protected ActiveEnvironmentGroup _activeEnvironmentGroup = null; + protected ActiveEnvironmentGroup activeEnvironmentGroup = null; /** * The presentation text object, we only have one per page */ - private PresentationTextObject _presentationTextObject = null; + private PresentationTextObject presentationTextObject = null; /** * The list of objects within the page */ - protected List _objects = new ArrayList(); + protected List objects = new ArrayList(); /** * The list of tag logical elements */ - protected ArrayList _tagLogicalElements = new ArrayList(); + protected ArrayList tagLogicalElements = new ArrayList(); /** * The list of the include page segments */ - protected ArrayList _segments = new ArrayList(); + protected ArrayList segments = new ArrayList(); /** * The page width */ - private int _width; + private int width; /** * The page height */ - private int _height; + private int height; /** * The page rotation */ - private int _rotation = 0; + private int rotation = 0; /** * The page state */ - private boolean _complete = false; + private boolean complete = false; /** * Construct a new page object for the specified name argument, the page @@ -106,41 +105,45 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { * the height of the page. * @param rotation * the rotation of the page. + * @param widthResolution + * the width resolution of the page. + * @param heightResolution + * the height resolution of the page. */ - public AbstractPageObject(String name, int width, int height, int rotation) { + public AbstractPageObject(String name, int width, int height, int rotation, + int widthResolution, int heightResolution) { super(name); - - _name = name; - - _rotation = rotation; - _width = width; - _height = height; + this.width = width; + this.height = height; + this.rotation = rotation; /** * Every page object must have an ActiveEnvironmentGroup */ - _activeEnvironmentGroup = new ActiveEnvironmentGroup(_width, _height); + activeEnvironmentGroup = new ActiveEnvironmentGroup(width, height, + widthResolution, heightResolution); - if (_rotation != 0) { - switch (_rotation) { + if (rotation != 0) { + switch (rotation) { case 90: - _activeEnvironmentGroup.setPosition(_width, 0, _rotation); + activeEnvironmentGroup.setPosition(width, 0, rotation); break; case 180: - _activeEnvironmentGroup.setPosition(_width, _height, _rotation); + activeEnvironmentGroup.setPosition(width, height, rotation); break; case 270: - _activeEnvironmentGroup.setPosition(0, _height, _rotation); + activeEnvironmentGroup.setPosition(0, height, rotation); break; + default: } } /** * We have a presentation text object per page */ - _presentationTextObject = new PresentationTextObject(); - _objects.add(_presentationTextObject); + presentationTextObject = new PresentationTextObject(); + objects.add(presentationTextObject); } @@ -158,7 +161,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { */ public void createFont(byte fontReference, AFPFont font, int size) { - _activeEnvironmentGroup.createFont(fontReference, font, size, 0); + activeEnvironmentGroup.createFont(fontReference, font, size, 0); } @@ -176,18 +179,19 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { * the second y coordinate of the line * @param thickness * the thickness of the line - * @param rotation + * @param lineRotation * the rotation of the line * @param col * The text color. */ - public void createLine(int x1, int y1, int x2, int y2, int thickness, int rotation, Color col) { + public void createLine(int x1, int y1, int x2, int y2, int thickness, + int lineRotation, Color col) { - if (_presentationTextObject == null) { - _presentationTextObject = new PresentationTextObject(); - _objects.add(_presentationTextObject); + if (presentationTextObject == null) { + presentationTextObject = new PresentationTextObject(); + objects.add(presentationTextObject); } - _presentationTextObject.createLineData(x1, y1, x2, y2, thickness, rotation, col); + presentationTextObject.createLineData(x1, y1, x2, y2, thickness, lineRotation, col); } @@ -201,7 +205,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { * the x coordinate of the text data * @param y * the y coordinate of the text data - * @param rotation + * @param textRotation * the rotation of the text data * @param col * the text color @@ -212,13 +216,14 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { * @param data * the text data to create */ - public void createText(int fontNumber, int x, int y, int rotation, Color col, int vsci, int ica, byte[] data) { + public void createText(int fontNumber, int x, int y, int textRotation, Color col, + int vsci, int ica, byte[] data) { - if (_presentationTextObject == null) { - _presentationTextObject = new PresentationTextObject(); - _objects.add(_presentationTextObject); + if (presentationTextObject == null) { + presentationTextObject = new PresentationTextObject(); + objects.add(presentationTextObject); } - _presentationTextObject.createTextData(fontNumber, x, y, rotation, col, vsci, ica, data); + presentationTextObject.createTextData(fontNumber, x, y, textRotation, col, vsci, ica, data); } @@ -228,11 +233,11 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { */ public void endPage() { - if (_presentationTextObject != null) { - _presentationTextObject.endControlSequence(); + if (presentationTextObject != null) { + presentationTextObject.endControlSequence(); } - _complete = true; + complete = true; } @@ -261,33 +266,33 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { int xCoord = 0; int yCoord = 0; - int width = 0; - int height = 0; + int areaWidth = 0; + int areaHeight = 0; - switch (_rotation) { + switch (rotation) { case 90: - xCoord = _width - y - h; + xCoord = areaWidth - y - h; yCoord = x; - width = h; - height = w; + areaWidth = h; + areaHeight = w; break; case 180: - xCoord = _width - x - w; - yCoord = _height - y - h; - width = w; - height = h; + xCoord = areaWidth - x - w; + yCoord = areaHeight - y - h; + areaWidth = w; + areaHeight = h; break; case 270: xCoord = y; - yCoord = _height - x - w; - width = h; - height = w; + yCoord = areaHeight - x - w; + areaWidth = h; + areaHeight = w; break; default: xCoord = x; yCoord = y; - width = w; - height = h; + areaWidth = w; + areaHeight = h; break; } @@ -297,19 +302,19 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { int greyscale = Math.round((shade / 255) * 16); String imageName = "IMG" - + StringUtils.lpad(String.valueOf(_objects.size() + 1), + + StringUtils.lpad(String.valueOf(objects.size() + 1), '0', 5); IMImageObject io = new IMImageObject(imageName); ImageOutputControl ioc = new ImageOutputControl(0, 0); ImageInputDescriptor iid = new ImageInputDescriptor(); ImageCellPosition icp = new ImageCellPosition(xCoord, yCoord); - icp.setXFillSize(width); - icp.setYFillSize(height); + icp.setXFillSize(areaWidth); + icp.setYFillSize(areaHeight); icp.setXSize(64); icp.setYSize(8); - //defing this as a resource + //defining this as a resource ImageRasterData ird = new ImageRasterData(ImageRasterPattern .getRasterData(greyscale)); @@ -317,27 +322,28 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { io.setImageInputDescriptor(iid); io.setImageCellPosition(icp); io.setImageRasterData(ird); - _objects.add(io); + objects.add(io); } /** * Helper method to create an image on the current page and to return * the object. + * @return the image object */ public ImageObject getImageObject() { - if (_presentationTextObject != null) { - _presentationTextObject.endControlSequence(); + if (presentationTextObject != null) { + presentationTextObject.endControlSequence(); } - _presentationTextObject = null; + presentationTextObject = null; String imageName = "IMG" - + StringUtils.lpad(String.valueOf(_objects.size() + 1), + + StringUtils.lpad(String.valueOf(objects.size() + 1), '0', 5); ImageObject io = new ImageObject(imageName); - _objects.add(io); + objects.add(io); return io; } @@ -352,7 +358,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { public void createTagLogicalElement(String name, String value) { TagLogicalElement tle = new TagLogicalElement(name, value); - _tagLogicalElements.add(tle); + tagLogicalElements.add(tle); } @@ -364,7 +370,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { public void createNoOperation(String content) { NoOperation noOp = new NoOperation(content); - _objects.add(noOp); + objects.add(noOp); } @@ -381,7 +387,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { public void createIncludePageSegment(String name, int xCoor, int yCoor) { IncludePageSegment ips = new IncludePageSegment(name, xCoor, yCoor); - _segments.add(ips); + segments.add(ips); } @@ -391,35 +397,39 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { * @return the ActiveEnvironmentGroup object */ public ActiveEnvironmentGroup getActiveEnvironmentGroup() { - return _activeEnvironmentGroup; + return activeEnvironmentGroup; } /** * Returns an indication if the page is complete + * @return whether this page is complete */ public boolean isComplete() { - return _complete; + return complete; } /** * Returns the height of the page + * @return the height of the page */ public int getHeight() { - return _height; + return height; } /** * Returns the width of the page + * @return the width of the page */ public int getWidth() { - return _width; + return width; } /** * Returns the rotation of the page + * @return the rotation of the page */ public int getRotation() { - return _rotation; + return rotation; } } diff --git a/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java b/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java index 067997776..3e341c735 100644 --- a/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java @@ -20,8 +20,8 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; + import org.apache.fop.render.afp.fonts.AFPFont; /** @@ -47,41 +47,44 @@ public final class ActiveEnvironmentGroup extends AbstractNamedAFPObject { /** * The collection of MapCodedFont objects */ - private ArrayList _mapCodedFonts = new ArrayList(); + private ArrayList mapCodedFonts = new ArrayList(); /** * The Object Area Descriptor for the active environment group */ - private ObjectAreaDescriptor _objectAreaDescriptor = null; + private ObjectAreaDescriptor objectAreaDescriptor = null; /** * The Object Area Position for the active environment group */ - private ObjectAreaPosition _objectAreaPosition = null; + private ObjectAreaPosition objectAreaPosition = null; /** * The PresentationTextDescriptor for the active environment group */ - private PresentationTextDescriptor _presentationTextDataDescriptor = null; + private PresentationTextDescriptor presentationTextDataDescriptor = null; /** * The PageDescriptor for the active environment group */ - private PageDescriptor _pageDescriptor = null; + private PageDescriptor pageDescriptor = null; /** * The collection of MapPageOverlay objects */ - private ArrayList _mapPageOverlays = new ArrayList(); + private ArrayList mapPageOverlays = new ArrayList(); /** * Default constructor for the ActiveEnvironmentGroup. * @param width the page width * @param height the page height + * @param widthResolution the page width resolution + * @param heightResolution the page height resolution */ - public ActiveEnvironmentGroup(int width, int height) { + public ActiveEnvironmentGroup(int width, int height, + int widthResolution, int heightResolution) { - this(DEFAULT_NAME, width, height); + this(DEFAULT_NAME, width, height, widthResolution, heightResolution); } @@ -91,20 +94,24 @@ public final class ActiveEnvironmentGroup extends AbstractNamedAFPObject { * @param name the active environment group name * @param width the page width * @param height the page height + * @param widthResolution the page width resolution + * @param heightResolution the page height resolution */ - public ActiveEnvironmentGroup(String name, int width, int height) { + public ActiveEnvironmentGroup(String name, int width, int height, + int widthResolution, int heightResolution) { super(name); // Create PageDescriptor - _pageDescriptor = new PageDescriptor(width, height); + pageDescriptor = new PageDescriptor(width, height, widthResolution, heightResolution); // Create ObjectAreaDescriptor - _objectAreaDescriptor = new ObjectAreaDescriptor(width, height); + objectAreaDescriptor = new ObjectAreaDescriptor(width, height, + widthResolution, heightResolution); // Create PresentationTextDataDescriptor - _presentationTextDataDescriptor = - new PresentationTextDescriptor(width, height); + presentationTextDataDescriptor = new PresentationTextDescriptor(width, height, + widthResolution, heightResolution); } @@ -117,7 +124,7 @@ public final class ActiveEnvironmentGroup extends AbstractNamedAFPObject { public void setPosition(int x, int y, int rotation) { // Create ObjectAreaPosition - _objectAreaPosition = new ObjectAreaPosition(x, y, rotation); + objectAreaPosition = new ObjectAreaPosition(x, y, rotation); } @@ -128,7 +135,7 @@ public final class ActiveEnvironmentGroup extends AbstractNamedAFPObject { */ public PageDescriptor getPageDescriptor() { - return _pageDescriptor; + return pageDescriptor; } @@ -139,32 +146,32 @@ public final class ActiveEnvironmentGroup extends AbstractNamedAFPObject { */ public PresentationTextDescriptor getPresentationTextDataDescriptor() { - return _presentationTextDataDescriptor; + return presentationTextDataDescriptor; } /** * Accessor method to write the AFP datastream for the active environment group. * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException throws if an I/O exception of some sort has occurred */ public void writeDataStream(OutputStream os) throws IOException { writeStart(os); - writeObjectList(_mapCodedFonts, os); + writeObjectList(mapCodedFonts, os); - writeObjectList(_mapPageOverlays, os); + writeObjectList(mapPageOverlays, os); - _pageDescriptor.writeDataStream(os); + pageDescriptor.writeDataStream(os); - if (_objectAreaDescriptor != null && _objectAreaPosition != null) { - _objectAreaDescriptor.writeDataStream(os); - _objectAreaPosition.writeDataStream(os); + if (objectAreaDescriptor != null && objectAreaPosition != null) { + objectAreaDescriptor.writeDataStream(os); + objectAreaPosition.writeDataStream(os); } - _presentationTextDataDescriptor.writeDataStream(os); + presentationTextDataDescriptor.writeDataStream(os); writeEnd(os); @@ -189,9 +196,9 @@ public final class ActiveEnvironmentGroup extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } @@ -218,9 +225,9 @@ public final class ActiveEnvironmentGroup extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } @@ -245,7 +252,7 @@ public final class ActiveEnvironmentGroup extends AbstractNamedAFPObject { if (mcf == null) { mcf = new MapCodedFont(); - _mapCodedFonts.add(mcf); + mapCodedFonts.add(mcf); } try { @@ -259,7 +266,7 @@ public final class ActiveEnvironmentGroup extends AbstractNamedAFPObject { } catch (MaximumSizeExceededException msee) { mcf = new MapCodedFont(); - _mapCodedFonts.add(mcf); + mapCodedFonts.add(mcf); try { @@ -291,7 +298,7 @@ public final class ActiveEnvironmentGroup extends AbstractNamedAFPObject { if (mpo == null) { mpo = new MapPageOverlay(); - _mapPageOverlays.add(mpo); + mapPageOverlays.add(mpo); } try { @@ -300,7 +307,7 @@ public final class ActiveEnvironmentGroup extends AbstractNamedAFPObject { } catch (MaximumSizeExceededException msee) { mpo = new MapPageOverlay(); - _mapPageOverlays.add(mpo); + mapPageOverlays.add(mpo); try { mpo.addOverlay(name); } catch (MaximumSizeExceededException ex) { @@ -317,9 +324,9 @@ public final class ActiveEnvironmentGroup extends AbstractNamedAFPObject { */ private MapCodedFont getCurrentMapCodedFont() { - int size = _mapCodedFonts.size(); + int size = mapCodedFonts.size(); if (size > 0) { - return (MapCodedFont) _mapCodedFonts.get(_mapCodedFonts.size() - 1); + return (MapCodedFont) mapCodedFonts.get(mapCodedFonts.size() - 1); } else { return null; } @@ -333,10 +340,10 @@ public final class ActiveEnvironmentGroup extends AbstractNamedAFPObject { */ private MapPageOverlay getCurrentMapPageOverlay() { - int size = _mapPageOverlays.size(); + int size = mapPageOverlays.size(); if (size > 0) { - return (MapPageOverlay) _mapPageOverlays.get( - _mapPageOverlays.size() - 1); + return (MapPageOverlay) mapPageOverlays.get( + mapPageOverlays.size() - 1); } else { return null; } diff --git a/src/java/org/apache/fop/render/afp/modca/Document.java b/src/java/org/apache/fop/render/afp/modca/Document.java index b409e5567..3d2d40a3a 100644 --- a/src/java/org/apache/fop/render/afp/modca/Document.java +++ b/src/java/org/apache/fop/render/afp/modca/Document.java @@ -20,10 +20,8 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; import java.util.Iterator; - +import java.util.List; /** * The document is the highest level of the MO:DCA data-stream document @@ -55,22 +53,22 @@ public final class Document extends AbstractNamedAFPObject { /** * Ststic default name reference */ - private final static String DEFAULT_NAME = "DOC00001"; + private static final String DEFAULT_NAME = "DOC00001"; /** * A list of the objects in the document */ - private ArrayList _objects = new ArrayList(); + private List objects = new java.util.ArrayList(); /** * The document started state */ - private boolean _started = false; + private boolean started = false; /** * The document completion state */ - private boolean _complete = false; + private boolean complete = false; /** * Default constructor for the document object. @@ -94,8 +92,8 @@ public final class Document extends AbstractNamedAFPObject { * @param page - the Page object */ public void addPage(PageObject page) { - if (!_objects.contains(page)) { - _objects.add(page); + if (!objects.contains(page)) { + objects.add(page); } } @@ -104,7 +102,7 @@ public final class Document extends AbstractNamedAFPObject { * @param pageGroup the PageGroup object */ public void addPageGroup(PageGroup pageGroup) { - _objects.add(pageGroup); + objects.add(pageGroup); } /** @@ -112,31 +110,32 @@ public final class Document extends AbstractNamedAFPObject { */ public void endDocument() { - _complete = true; + complete = true; } /** * Returns an indication if the page group is complete + * @return whether or not this page group is complete */ public boolean isComplete() { - return _complete; + return complete; } /** * Accessor method to write the AFP datastream for document. * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException thrown if an I/O exception of some sort has occurred */ public void writeDataStream(OutputStream os) throws IOException { - if (!_started) { + if (!started) { writeStart(os); - _started = true; + started = true; } - for (Iterator it = _objects.iterator(); it.hasNext(); ) { + for (Iterator it = objects.iterator(); it.hasNext();) { AbstractAFPObject ao = (AbstractAFPObject)it.next(); if (ao instanceof PageObject && ((PageObject)ao).isComplete() || ao instanceof PageGroup && ((PageGroup)ao).isComplete()) { @@ -147,7 +146,7 @@ public final class Document extends AbstractNamedAFPObject { } } - if (_complete) { + if (complete) { writeEnd(os); } @@ -172,9 +171,9 @@ public final class Document extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } @@ -201,9 +200,9 @@ public final class Document extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } diff --git a/src/java/org/apache/fop/render/afp/modca/EndPageGroup.java b/src/java/org/apache/fop/render/afp/modca/EndPageGroup.java index 295bb2667..25fc006ce 100644 --- a/src/java/org/apache/fop/render/afp/modca/EndPageGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/EndPageGroup.java @@ -21,7 +21,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; /** * The End Named Page Group (ENG) structured field terminates a page group that was @@ -36,18 +35,23 @@ import java.io.UnsupportedEncodingException; */ public class EndPageGroup extends AbstractNamedAFPObject { + /** + * Main constructor + * @param groupId the group id + */ public EndPageGroup(String groupId) { super(groupId); - log.debug("A ENG is being created for group: " + groupId); - + if (log.isDebugEnabled()) { + log.debug("A ENG is being created for group: " + groupId); + } } /** * Accessor method to write the AFP datastream for the End Page Group. * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException thrown if an I/O exception of some sort has occurred */ public void writeDataStream(OutputStream os) throws IOException { @@ -63,9 +67,9 @@ public class EndPageGroup extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } diff --git a/src/java/org/apache/fop/render/afp/modca/IMImageObject.java b/src/java/org/apache/fop/render/afp/modca/IMImageObject.java index b848a1e2e..bb43950dd 100644 --- a/src/java/org/apache/fop/render/afp/modca/IMImageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/IMImageObject.java @@ -18,9 +18,9 @@ /* $Id$ */ package org.apache.fop.render.afp.modca; + import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; /** * An IM image data object specifies the contents of a raster image and @@ -40,22 +40,22 @@ public class IMImageObject extends AbstractNamedAFPObject { /** * The image output control */ - private ImageOutputControl _imageOutputControl = null; + private ImageOutputControl imageOutputControl = null; /** * The image input descriptor */ - private ImageInputDescriptor _imageInputDescriptor = null; + private ImageInputDescriptor imageInputDescriptor = null; /** * The image cell position */ - private ImageCellPosition _imageCellPosition = null; + private ImageCellPosition imageCellPosition = null; /** * The image rastor data */ - private ImageRasterData _imageRastorData = null; + private ImageRasterData imageRasterData = null; /** * Constructor for the image object with the specified name, @@ -73,7 +73,7 @@ public class IMImageObject extends AbstractNamedAFPObject { * @param imageOutputControl The imageOutputControl to set */ public void setImageOutputControl(ImageOutputControl imageOutputControl) { - _imageOutputControl = imageOutputControl; + this.imageOutputControl = imageOutputControl; } /** @@ -81,7 +81,7 @@ public class IMImageObject extends AbstractNamedAFPObject { * @param imageCellPosition The imageCellPosition to set */ public void setImageCellPosition(ImageCellPosition imageCellPosition) { - _imageCellPosition = imageCellPosition; + this.imageCellPosition = imageCellPosition; } /** @@ -89,41 +89,41 @@ public class IMImageObject extends AbstractNamedAFPObject { * @param imageInputDescriptor The imageInputDescriptor to set */ public void setImageInputDescriptor(ImageInputDescriptor imageInputDescriptor) { - _imageInputDescriptor = imageInputDescriptor; + this.imageInputDescriptor = imageInputDescriptor; } /** * Sets the ImageRastorData. - * @param imageRastorData The imageRastorData to set + * @param imageRasterData The imageRasterData to set */ - public void setImageRasterData(ImageRasterData imageRastorData) { - _imageRastorData = imageRastorData; + public void setImageRasterData(ImageRasterData imageRasterData) { + this.imageRasterData = imageRasterData; } /** * Accessor method to write the AFP datastream for the IM Image Objetc * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException thrown if an I/O exception of some sort has occurred */ public void writeDataStream(OutputStream os) throws IOException { writeStart(os); - if (_imageOutputControl != null) { - _imageOutputControl.writeDataStream(os); + if (imageOutputControl != null) { + imageOutputControl.writeDataStream(os); } - if (_imageInputDescriptor != null) { - _imageInputDescriptor.writeDataStream(os); + if (imageInputDescriptor != null) { + imageInputDescriptor.writeDataStream(os); } - if (_imageCellPosition != null) { - _imageCellPosition.writeDataStream(os); + if (imageCellPosition != null) { + imageCellPosition.writeDataStream(os); } - if (_imageRastorData != null) { - _imageRastorData.writeDataStream(os); + if (imageRasterData != null) { + imageRasterData.writeDataStream(os); } writeEnd(os); @@ -149,9 +149,9 @@ public class IMImageObject extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } @@ -178,9 +178,9 @@ public class IMImageObject extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } diff --git a/src/java/org/apache/fop/render/afp/modca/ImageObject.java b/src/java/org/apache/fop/render/afp/modca/ImageObject.java index 909139ef3..66c46c872 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageObject.java @@ -22,7 +22,6 @@ package org.apache.fop.render.afp.modca; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import org.apache.fop.render.afp.tools.BinaryUtils; /** @@ -33,12 +32,12 @@ public class ImageObject extends AbstractNamedAFPObject { /** * The object environment group */ - private ObjectEnvironmentGroup _objectEnvironmentGroup = null; + private ObjectEnvironmentGroup objectEnvironmentGroup = null; /** * The image segment */ - private ImageSegment _imageSegment = null; + private ImageSegment imageSegment = null; /** * Constructor for the image object with the specified name, @@ -64,12 +63,16 @@ public class ImageObject extends AbstractNamedAFPObject { * the height of the image * @param r * the rotation of the image + * @param wr + * the width resolution of the image + * @param hr + * the height resolution of the image */ - public void setImageViewport(int x, int y, int w, int h, int r) { - if (_objectEnvironmentGroup == null) { - _objectEnvironmentGroup = new ObjectEnvironmentGroup(); + public void setImageViewport(int x, int y, int w, int h, int r, int wr, int hr) { + if (objectEnvironmentGroup == null) { + objectEnvironmentGroup = new ObjectEnvironmentGroup(); } - _objectEnvironmentGroup.setObjectArea(x, y, w, h, r); + objectEnvironmentGroup.setObjectArea(x, y, w, h, r, wr, hr); } /** @@ -80,14 +83,14 @@ public class ImageObject extends AbstractNamedAFPObject { * @param height the image height */ public void setImageParameters(int xresol, int yresol, int width, int height) { - if (_objectEnvironmentGroup == null) { - _objectEnvironmentGroup = new ObjectEnvironmentGroup(); + if (objectEnvironmentGroup == null) { + objectEnvironmentGroup = new ObjectEnvironmentGroup(); } - _objectEnvironmentGroup.setImageData(xresol, yresol, width, height); - if (_imageSegment == null) { - _imageSegment = new ImageSegment(); + objectEnvironmentGroup.setImageData(xresol, yresol, width, height); + if (imageSegment == null) { + imageSegment = new ImageSegment(); } - _imageSegment.setImageSize(xresol, yresol, width, height); + imageSegment.setImageSize(xresol, yresol, width, height); } /** @@ -95,10 +98,10 @@ public class ImageObject extends AbstractNamedAFPObject { * @param encoding The image encoding. */ public void setImageEncoding(byte encoding) { - if (_imageSegment == null) { - _imageSegment = new ImageSegment(); + if (imageSegment == null) { + imageSegment = new ImageSegment(); } - _imageSegment.setImageEncoding(encoding); + imageSegment.setImageEncoding(encoding); } /** @@ -106,10 +109,10 @@ public class ImageObject extends AbstractNamedAFPObject { * @param compression The image compression. */ public void setImageCompression(byte compression) { - if (_imageSegment == null) { - _imageSegment = new ImageSegment(); + if (imageSegment == null) { + imageSegment = new ImageSegment(); } - _imageSegment.setImageCompression(compression); + imageSegment.setImageCompression(compression); } /** @@ -117,10 +120,10 @@ public class ImageObject extends AbstractNamedAFPObject { * @param size The IDE size. */ public void setImageIDESize(byte size) { - if (_imageSegment == null) { - _imageSegment = new ImageSegment(); + if (imageSegment == null) { + imageSegment = new ImageSegment(); } - _imageSegment.setImageIDESize(size); + imageSegment.setImageIDESize(size); } /** @@ -128,21 +131,21 @@ public class ImageObject extends AbstractNamedAFPObject { * @param colorModel the IDE color model. */ public void setImageIDEColorModel(byte colorModel) { - if (_imageSegment == null) { - _imageSegment = new ImageSegment(); + if (imageSegment == null) { + imageSegment = new ImageSegment(); } - _imageSegment.setImageIDEColorModel(colorModel); + imageSegment.setImageIDEColorModel(colorModel); } /** * Set the data of the image. * @param data The image data */ - public void setImageData(byte data[]) { - if (_imageSegment == null) { - _imageSegment = new ImageSegment(); + public void setImageData(byte[] data) { + if (imageSegment == null) { + imageSegment = new ImageSegment(); } - _imageSegment.setImageData(data); + imageSegment.setImageData(data); } /** @@ -150,7 +153,7 @@ public class ImageObject extends AbstractNamedAFPObject { * @param objectEnvironmentGroup The objectEnvironmentGroup to set */ public void setObjectEnvironmentGroup(ObjectEnvironmentGroup objectEnvironmentGroup) { - _objectEnvironmentGroup = objectEnvironmentGroup; + this.objectEnvironmentGroup = objectEnvironmentGroup; } /** @@ -183,21 +186,21 @@ public class ImageObject extends AbstractNamedAFPObject { /** * Accessor method to write the AFP datastream for the Image Object * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException thrown if an I/O exception of some sort has occurred */ public void writeDataStream(OutputStream os) throws IOException { writeStart(os); - if (_objectEnvironmentGroup != null) { - _objectEnvironmentGroup.writeDataStream(os); + if (objectEnvironmentGroup != null) { + objectEnvironmentGroup.writeDataStream(os); } - if (_imageSegment != null) { + if (imageSegment != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - _imageSegment.writeDataStream(baos); - byte b[] = baos.toByteArray(); + imageSegment.writeDataStream(baos); + byte[] b = baos.toByteArray(); int off = 0; while (off < b.length) { int len = Math.min(30000, b.length - off); @@ -230,9 +233,9 @@ public class ImageObject extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } @@ -259,9 +262,9 @@ public class ImageObject extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } diff --git a/src/java/org/apache/fop/render/afp/modca/IncludeObject.java b/src/java/org/apache/fop/render/afp/modca/IncludeObject.java index c829c6548..890fdcd9d 100644 --- a/src/java/org/apache/fop/render/afp/modca/IncludeObject.java +++ b/src/java/org/apache/fop/render/afp/modca/IncludeObject.java @@ -21,7 +21,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import org.apache.fop.render.afp.tools.BinaryUtils; @@ -43,12 +42,12 @@ public class IncludeObject extends AbstractNamedAFPObject { /** * The object type */ - private byte _objectType = (byte) 0x92; + private byte objectType = (byte) 0x92; /** * The orientation on the include object */ - private int _orientation = 0; + private int orientation = 0; /** * Constructor for the include object with the specified name, the name must @@ -61,12 +60,12 @@ public class IncludeObject extends AbstractNamedAFPObject { public IncludeObject(String name) { super(name); - _objectType = (byte) 0xFB; + objectType = (byte) 0xFB; } /** - * Sets the orienation to use for the Include Object. + * Sets the orientation to use for the Include Object. * * @param orientation * The orientation (0,90, 180, 270) @@ -75,7 +74,7 @@ public class IncludeObject extends AbstractNamedAFPObject { if (orientation == 0 || orientation == 90 || orientation == 180 || orientation == 270) { - _orientation = orientation; + this.orientation = orientation; } else { throw new IllegalArgumentException( "The orientation must be one of the values 0, 90, 180, 270"); @@ -86,7 +85,7 @@ public class IncludeObject extends AbstractNamedAFPObject { /** * Accessor method to write the AFP datastream for the Include Object * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException thrown if an I/O exception of some sort has occurred */ public void writeDataStream(OutputStream os) throws IOException { @@ -109,12 +108,12 @@ public class IncludeObject extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + for (int i = 0; i < nameBytes.length; i++) { + data[9 + i] = nameBytes[i]; } data[17] = 0x00; - data[18] = _objectType; + data[18] = objectType; // XoaOset data[20] = (byte) 0xFF; @@ -126,7 +125,7 @@ public class IncludeObject extends AbstractNamedAFPObject { data[24] = (byte) 0xFF; data[25] = (byte) 0xFF; - switch (_orientation) { + switch (orientation) { case 90: data[26] = 0x2D; data[27] = 0x00; diff --git a/src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java b/src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java index cc4c0a4c6..754679385 100644 --- a/src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java +++ b/src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java @@ -21,7 +21,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import org.apache.fop.render.afp.tools.BinaryUtils; @@ -43,17 +42,17 @@ public class IncludePageOverlay extends AbstractNamedAFPObject { /** * The x coordinate */ - private int _xCoor = 0; + private int xCoor = 0; /** * The y coordinate */ - private int _yCoor = 0; + private int yCoor = 0; /** * The orientation */ - private int _orientation = 0; + private int orientation = 0; /** * Constructor for the Include Page Overlay @@ -66,8 +65,8 @@ public class IncludePageOverlay extends AbstractNamedAFPObject { super(overlayName); - _xCoor = x; - _yCoor = y; + xCoor = x; + yCoor = y; setOrientation(orientation); } @@ -81,7 +80,7 @@ public class IncludePageOverlay extends AbstractNamedAFPObject { if (orientation == 0 || orientation == 90 || orientation == 180 || orientation == 270) { - _orientation = orientation; + this.orientation = orientation; } else { throw new IllegalArgumentException( "The orientation must be one of the values 0, 90, 180, 270"); @@ -92,7 +91,7 @@ public class IncludePageOverlay extends AbstractNamedAFPObject { /** * Accessor method to write the AFP datastream for the Include Page Overlay * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException thrown if an I/O exception of some sort has occurred */ public void writeDataStream(OutputStream os) throws IOException { @@ -115,23 +114,23 @@ public class IncludePageOverlay extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } - byte[] r2 = BinaryUtils.convert(_xCoor, 3); + byte[] r2 = BinaryUtils.convert(xCoor, 3); data[17] = r2[0]; // x coordinate data[18] = r2[1]; data[19] = r2[2]; - byte[] r3 = BinaryUtils.convert(_yCoor, 3); + byte[] r3 = BinaryUtils.convert(yCoor, 3); data[20] = r3[0]; // y coordinate data[21] = r3[1]; data[22] = r3[2]; - switch (_orientation) { + switch (orientation) { case 90: data[23] = 0x2D; data[24] = 0x00; diff --git a/src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java b/src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java index 4ca8b0832..518904878 100644 --- a/src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java +++ b/src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java @@ -21,7 +21,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import org.apache.fop.render.afp.tools.BinaryUtils; @@ -41,17 +40,17 @@ import org.apache.fop.render.afp.tools.BinaryUtils; * that may have to be placed at different positions on a document. * */ -public class IncludePageSegment extends AbstractNamedAFPObject{ +public class IncludePageSegment extends AbstractNamedAFPObject { /** * The x position where we need to put this object on the page */ - private byte [] _xCoor; + private byte[] xCoor; /** * The y position where we need to put this object on the page */ - private byte [] _yCoor; + private byte[] yCoor; /** * Constructor for the Include Page Segment @@ -59,18 +58,18 @@ public class IncludePageSegment extends AbstractNamedAFPObject{ * @param xVal The x position * @param yVal The y position */ - public IncludePageSegment(String name, int xVal, int yVal){ + public IncludePageSegment(String name, int xVal, int yVal) { super(name); - _xCoor = BinaryUtils.convert(xVal, 3); - _yCoor = BinaryUtils.convert(yVal, 3); + this.xCoor = BinaryUtils.convert(xVal, 3); + this.yCoor = BinaryUtils.convert(yVal, 3); } /** * Accessor method to write the AFP datastream for the Include Page Segment * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException thrown if an I/O exception of some sort has occurred */ public void writeDataStream(OutputStream os) throws IOException { @@ -93,19 +92,19 @@ public class IncludePageSegment extends AbstractNamedAFPObject{ data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } - data[17] = _xCoor[0]; // x coordinate - data[18] = _xCoor[1]; - data[19] = _xCoor[2]; + data[17] = xCoor[0]; // x coordinate + data[18] = xCoor[1]; + data[19] = xCoor[2]; - data[20] = _yCoor[0]; // y coordinate - data[21] = _yCoor[1]; - data[22] = _yCoor[2]; + data[20] = yCoor[0]; // y coordinate + data[21] = yCoor[1]; + data[22] = yCoor[2]; os.write(data); diff --git a/src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.java b/src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.java index c866ab1e2..f38096ade 100644 --- a/src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.java +++ b/src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.java @@ -21,7 +21,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import org.apache.fop.render.afp.tools.BinaryUtils; @@ -46,7 +45,7 @@ public class InvokeMediumMap extends AbstractNamedAFPObject { /** * Accessor method to write the AFP datastream for the Invoke Medium Map * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException if an I/O exception of some sort has occurred */ public void writeDataStream(OutputStream os) throws IOException { @@ -69,9 +68,9 @@ public class InvokeMediumMap extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java b/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java index 45335e3e0..7c940148b 100644 --- a/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java @@ -28,74 +28,69 @@ import org.apache.fop.render.afp.tools.BinaryUtils; * of an object area presentation space. * */ -public class ObjectAreaDescriptor extends AbstractAFPObject { - - private int _width = 0; - private int _height = 0; +public class ObjectAreaDescriptor extends AbstractDescriptor { /** * Construct an object area descriptor for the specified object width * and object height. * @param width The page width. * @param height The page height. + * @param widthResolution The page width resolution. + * @param heightResolution The page height resolution. */ - public ObjectAreaDescriptor(int width, int height) { - - _width = width; - _height = height; - + public ObjectAreaDescriptor(int width, int height, int widthResolution, int heightResolution) { + super(width, height, widthResolution, heightResolution); } /** * Accessor method to write the AFP datastream for the Object Area Descriptor * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException thrown if an I/O exception of some sort has occurred */ public void writeDataStream(OutputStream os) throws IOException { - byte[] data = new byte[] { - 0x5A, - 0x00, // Length - 0x1C, // Length - (byte) 0xD3, - (byte) 0xA6, - (byte) 0x6B, - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - 0x03, // Triplet length - 0x43, // tid = Descriptor Position Triplet - 0x01, // DesPosId = 1 - 0x08, // Triplet length - 0x4B, // tid = Measurement Units Triplet - 0x00, // XaoBase = 10 inches - 0x00, // YaoBase = 10 inches - 0x09, // XaoUnits = 2400 - 0x60, // XaoUnits = - 0x09, // YaoUnits = 2400 - 0x60, // YaoUnits = - 0x09, // Triplet length - 0x4C, // tid = Object Area Size - 0x02, // Size Type - 0x00, // XoaSize - 0x00, - 0x00, - 0x00, // YoaSize - 0x00, - 0x00, - }; - - byte[] l = BinaryUtils.convert(data.length - 1, 2); - data[1] = l[0]; - data[2] = l[1]; - - byte[] x = BinaryUtils.convert(_width, 3); + byte[] data = new byte[29]; + data[0] = 0x5A; + + byte[] len = BinaryUtils.convert(data.length - 1, 2); + data[1] = len[0]; // Length + data[2] = len[1]; + + data[3] = (byte) 0xD3; + data[4] = (byte) 0xA6; + data[5] = (byte) 0x6B; + data[6] = 0x00; // Flags + data[7] = 0x00; // Reserved + data[8] = 0x00; // Reserved + data[9] = 0x03; // Triplet length + data[10] = 0x43; // tid = Descriptor Position Triplet + data[11] = 0x01; // DesPosId = 1 + data[12] = 0x08; // Triplet length + data[13] = 0x4B; // tid = Measurement Units Triplet + data[14] = 0x00; // XaoBase = 10 inches + data[15] = 0x00; // YaoBase = 10 inches + + // XaoUnits + byte[] xdpi = BinaryUtils.convert(widthResolution * 10, 2); + data[16] = xdpi[0]; + data[17] = xdpi[1]; + + // YaoUnits + byte[] ydpi = BinaryUtils.convert(heightResolution * 10, 2); + data[18] = ydpi[0]; + data[19] = ydpi[1]; + + data[20] = 0x09; // Triplet length + data[21] = 0x4C; // tid = Object Area Size + data[22] = 0x02; // Size Type + + byte[] x = BinaryUtils.convert(width, 3); data[23] = x[0]; data[24] = x[1]; data[25] = x[2]; - byte[] y = BinaryUtils.convert(_height, 3); + byte[] y = BinaryUtils.convert(height, 3); data[26] = y[0]; data[27] = y[1]; data[28] = y[2]; diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java b/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java index dea3baab7..d6b029122 100644 --- a/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java @@ -20,7 +20,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; /** @@ -44,17 +43,17 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { /** * The ObjectAreaDescriptor for the object environment group */ - private ObjectAreaDescriptor _objectAreaDescriptor = null; + private ObjectAreaDescriptor objectAreaDescriptor = null; /** * The ObjectAreaPosition for the object environment group */ - private ObjectAreaPosition _objectAreaPosition = null; + private ObjectAreaPosition objectAreaPosition = null; /** * The ImageDataDescriptor for the object environment group */ - private ImageDataDescriptor _imageDataDescriptor = null; + private ImageDataDescriptor imageDataDescriptor = null; /** * Default constructor for the ObjectEnvironmentGroup. @@ -83,11 +82,15 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { * @param width the object width * @param height the object height * @param rotation the object orientation + * @param widthResolution the object resolution width + * @param heightResolution the object resolution height */ - public void setObjectArea(int x, int y, int width, int height, int rotation) { + public void setObjectArea(int x, int y, int width, int height, int rotation, + int widthResolution, int heightResolution) { - _objectAreaDescriptor = new ObjectAreaDescriptor(width, height); - _objectAreaPosition = new ObjectAreaPosition(x, y, rotation); + objectAreaDescriptor = new ObjectAreaDescriptor(width, height, + widthResolution, heightResolution); + objectAreaPosition = new ObjectAreaPosition(x, y, rotation); } @@ -99,14 +102,14 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { * @param height the image height */ public void setImageData(int xresol, int yresol, int width, int height) { - _imageDataDescriptor = new ImageDataDescriptor(xresol, yresol, width, height); + imageDataDescriptor = new ImageDataDescriptor(xresol, yresol, width, height); } /** * Accessor method to obtain write the AFP datastream for * the object environment group. * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException throw if an I/O exception of some sort has occurred */ public void writeDataStream(OutputStream os) throws IOException { @@ -114,12 +117,12 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { writeStart(os); - _objectAreaDescriptor.writeDataStream(os); + objectAreaDescriptor.writeDataStream(os); - _objectAreaPosition.writeDataStream(os); + objectAreaPosition.writeDataStream(os); - if (_imageDataDescriptor != null) { - _imageDataDescriptor.writeDataStream(os); + if (imageDataDescriptor != null) { + imageDataDescriptor.writeDataStream(os); } writeEnd(os); @@ -153,9 +156,9 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { 0x00, // }; - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } @@ -182,9 +185,9 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } diff --git a/src/java/org/apache/fop/render/afp/modca/Overlay.java b/src/java/org/apache/fop/render/afp/modca/Overlay.java index c6a7679e5..628ef5516 100644 --- a/src/java/org/apache/fop/render/afp/modca/Overlay.java +++ b/src/java/org/apache/fop/render/afp/modca/Overlay.java @@ -19,14 +19,17 @@ package org.apache.fop.render.afp.modca; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.util.Iterator; /** + * An overlay is a MO:DCA-P resource object. + * + * It may be stored in an external resource library or it may be + * carried in a resource group. An overlay is similar to a page in + * that it defines its own environment and carries the same data objects. */ -public class Overlay extends AbstractPageObject{ +public class Overlay extends AbstractPageObject { /** * Construct a new overlay object for the specified name argument, the overlay @@ -40,10 +43,15 @@ public class Overlay extends AbstractPageObject{ * the height of the page. * @param rotation * the rotation of the page. + * @param widthResolution + * the width resolution of the page. + * @param heightResolution + * the height resolution of the page. */ - public Overlay(String name, int width, int height, int rotation) { + public Overlay(String name, int width, int height, int rotation, + int widthResolution, int heightResolution) { - super(name, width, height, rotation); + super(name, width, height, rotation, widthResolution, heightResolution); } @@ -51,20 +59,20 @@ public class Overlay extends AbstractPageObject{ * Accessor method to write the AFP datastream for the overlay. * * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException thrown if an I/O exception of some sort has occurred */ public void writeDataStream(OutputStream os) throws IOException { writeStart(os); - _activeEnvironmentGroup.writeDataStream(os); + activeEnvironmentGroup.writeDataStream(os); - writeObjectList(_segments, os); + writeObjectList(segments, os); - writeObjectList(_tagLogicalElements, os); + writeObjectList(tagLogicalElements, os); - writeObjectList(_objects, os); + writeObjectList(objects, os); writeEnd(os); @@ -89,9 +97,9 @@ public class Overlay extends AbstractPageObject{ data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } @@ -118,9 +126,9 @@ public class Overlay extends AbstractPageObject{ data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } diff --git a/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java b/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java index e92099276..1cdec7616 100644 --- a/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java @@ -28,71 +28,72 @@ import org.apache.fop.render.afp.tools.BinaryUtils; * a page or overlay presentation space. * */ -public class PageDescriptor extends AbstractAFPObject { - - private int _width = 0; - private int _height = 0; +public class PageDescriptor extends AbstractDescriptor { /** * Construct a page descriptor for the specified page width * and page height. * @param width The page width. * @param height The page height. + * @param widthResolution The page width resolution + * @param heightResolution The page height resolution */ - public PageDescriptor(int width, int height) { - - _width = width; - _height = height; - + public PageDescriptor(int width, int height, int widthResolution, int heightResolution) { + super(width, height, widthResolution, heightResolution); } /** * Accessor method to write the AFP datastream for the Page Descriptor * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException in the event that an I/O Exception occurred */ public void writeDataStream(OutputStream os) throws IOException { - byte[] data = new byte[] { - 0x5A, - 0x00, - 0x17, - (byte) 0xD3, - (byte) 0xA6, - (byte) 0xAF, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x09, - 0x60, - 0x09, - 0x60, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - }; + log.debug("width=" + width); + log.debug("height=" + height); + byte[] data = new byte[24]; + data[0] = 0x5A; + data[1] = 0x00; + data[2] = 0x17; + data[3] = (byte) 0xD3; + data[4] = (byte) 0xA6; + data[5] = (byte) 0xAF; + + data[6] = 0x00; // Flags + data[7] = 0x00; // Reserved + data[8] = 0x00; // Reserved + + data[9] = 0x00; // XpgBase = 10 inches + data[10] = 0x00; // YpgBase = 10 inches + + // XpgUnits + byte[] xdpi = BinaryUtils.convert(widthResolution * 10, 2); + data[11] = xdpi[0]; + data[12] = xdpi[1]; - byte[] x = BinaryUtils.convert(_width, 3); + // YpgUnits + byte[] ydpi = BinaryUtils.convert(heightResolution * 10, 2); + data[13] = ydpi[0]; + data[14] = ydpi[1]; + + // XpgSize + byte[] x = BinaryUtils.convert(width, 3); data[15] = x[0]; data[16] = x[1]; data[17] = x[2]; - byte[] y = BinaryUtils.convert(_height, 3); + // YpgSize + byte[] y = BinaryUtils.convert(height, 3); data[18] = y[0]; data[19] = y[1]; data[20] = y[2]; - os.write(data); + data[21] = 0x00; // Reserved + data[22] = 0x00; // Reserved + data[23] = 0x00; // Reserved + os.write(data); } } \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/PageGroup.java b/src/java/org/apache/fop/render/afp/modca/PageGroup.java index 84e7149bc..0b40a83c5 100644 --- a/src/java/org/apache/fop/render/afp/modca/PageGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/PageGroup.java @@ -20,7 +20,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; @@ -40,17 +39,17 @@ public class PageGroup extends AbstractNamedAFPObject { /** * The pages contained within this group */ - private List _objects = new ArrayList(); + private List objects = new ArrayList(); /** * The tag logical elements contained within this group */ - private List _tagLogicalElements = new ArrayList(); + private List tagLogicalElements = new ArrayList(); /** * The page state */ - private boolean _complete = false; + private boolean complete = false; /** * Constructor for the PageGroup. @@ -72,8 +71,8 @@ public class PageGroup extends AbstractNamedAFPObject { */ public void addPage(PageObject page) { - if (!_objects.contains(page)) { - _objects.add(page); + if (!objects.contains(page)) { + objects.add(page); } } @@ -82,7 +81,7 @@ public class PageGroup extends AbstractNamedAFPObject { * @return the name of the page group */ public String getName() { - return _name; + return name; } /** @@ -96,7 +95,7 @@ public class PageGroup extends AbstractNamedAFPObject { public void createTagLogicalElement(String name, String value) { TagLogicalElement tle = new TagLogicalElement(name, value); - _tagLogicalElements.add(tle); + tagLogicalElements.add(tle); } @@ -109,7 +108,7 @@ public class PageGroup extends AbstractNamedAFPObject { public void createInvokeMediumMap(String name) { InvokeMediumMap imm = new InvokeMediumMap(name); - _objects.add(imm); + objects.add(imm); } @@ -118,30 +117,31 @@ public class PageGroup extends AbstractNamedAFPObject { */ public void endPageGroup() { - _complete = true; + complete = true; } /** * Returns an indication if the page group is complete + * @return whether or not this page group is complete or not */ public boolean isComplete() { - return _complete; + return complete; } /** * Accessor method to write the AFP datastream for the page group. * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException thrown if an I/O exception of some sort has occurred */ public void writeDataStream(OutputStream os) throws IOException { writeStart(os); - writeObjectList(_tagLogicalElements, os); + writeObjectList(tagLogicalElements, os); - writeObjectList(_objects, os); + writeObjectList(objects, os); writeEnd(os); @@ -166,9 +166,9 @@ public class PageGroup extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } @@ -195,9 +195,9 @@ public class PageGroup extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } diff --git a/src/java/org/apache/fop/render/afp/modca/PageObject.java b/src/java/org/apache/fop/render/afp/modca/PageObject.java index a85194f3b..5b9a00a89 100644 --- a/src/java/org/apache/fop/render/afp/modca/PageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/PageObject.java @@ -48,7 +48,7 @@ public class PageObject extends AbstractPageObject { /** * The resource group object */ - private ResourceGroup _resourceGroup = null; + private ResourceGroup resourceGroup = null; /** * Construct a new page object for the specified name argument, the page @@ -62,10 +62,15 @@ public class PageObject extends AbstractPageObject { * the height of the page. * @param rotation * the rotation of the page. + * @param widthResolution + * the width resolution of the page. + * @param heightResolution + * the height resolution of the page. */ - public PageObject(String name, int width, int height, int rotation) { + public PageObject(String name, int width, int height, int rotation, + int widthResolution, int heightResolution) { - super(name, width, height, rotation); + super(name, width, height, rotation, widthResolution, heightResolution); } @@ -74,10 +79,10 @@ public class PageObject extends AbstractPageObject { * @param overlay the overlay to add */ public void addOverlay(Overlay overlay) { - if (_resourceGroup == null) { - _resourceGroup = new ResourceGroup(); + if (resourceGroup == null) { + resourceGroup = new ResourceGroup(); } - _resourceGroup.addOverlay(overlay); + resourceGroup.addOverlay(overlay); } /** @@ -95,31 +100,31 @@ public class PageObject extends AbstractPageObject { public void createIncludePageOverlay(String name, int x, int y, int orientation) { IncludePageOverlay ipo = new IncludePageOverlay(name, x, y, orientation); - _objects.add(ipo); + objects.add(ipo); } /** * Accessor method to write the AFP datastream for the page. * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException thrown if an I/O exception of some sort has occurred */ public void writeDataStream(OutputStream os) throws IOException { writeStart(os); - if (_resourceGroup != null) { - _resourceGroup.writeDataStream(os); + if (resourceGroup != null) { + resourceGroup.writeDataStream(os); } - _activeEnvironmentGroup.writeDataStream(os); + activeEnvironmentGroup.writeDataStream(os); - writeObjectList(_segments, os); + writeObjectList(segments, os); - writeObjectList(_tagLogicalElements, os); + writeObjectList(tagLogicalElements, os); - writeObjectList(_objects, os); + writeObjectList(objects, os); writeEnd(os); @@ -144,9 +149,9 @@ public class PageObject extends AbstractPageObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } @@ -173,9 +178,9 @@ public class PageObject extends AbstractPageObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } diff --git a/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java b/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java index a093dc680..3858f4169 100644 --- a/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java @@ -45,68 +45,63 @@ import org.apache.fop.render.afp.tools.BinaryUtils; * in their semantic descriptions. * */ -public class PresentationTextDescriptor extends AbstractAFPObject { - - private int _width = 0; - private int _height = 0; +public class PresentationTextDescriptor extends AbstractDescriptor { /** * Constructor a PresentationTextDescriptor for the specified * width and height. * @param width The width of the page. * @param height The height of the page. + * @param widthResolution The width resolution of the page. + * @param heightResolution The height resolution of the page. */ - public PresentationTextDescriptor(int width, int height) { - - _width = width; - _height = height; - + public PresentationTextDescriptor(int width, int height, + int widthResolution, int heightResolution) { + super(width, height, widthResolution, heightResolution); } /** * Accessor method to write the AFP datastream for the Presentation Text Descriptor * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException thrown if an I/O exception of some sort has occurred */ public void writeDataStream(OutputStream os) throws IOException { - byte[] data = new byte[] { - 0x5A, - 0x00, - 0x16, - (byte) 0xD3, - (byte) 0xB1, - (byte) 0x9B, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x09, - 0x60, - 0x09, - 0x60, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - }; + byte[] data = new byte[23]; + data[0] = 0x5A; + data[1] = 0x00; + data[2] = 0x16; + data[3] = (byte) 0xD3; + data[4] = (byte) 0xB1; + data[5] = (byte) 0x9B; + data[6] = 0x00; + data[7] = 0x00; + data[8] = 0x00; + data[9] = 0x00; + data[10] = 0x00; - byte[] x = BinaryUtils.convert(_width, 3); + byte[] xdpi = BinaryUtils.convert(widthResolution * 10, 2); + data[11] = xdpi[0]; // xdpi + data[12] = xdpi[1]; + + byte[] ydpi = BinaryUtils.convert(heightResolution * 10, 2); + data[13] = ydpi[0]; // ydpi + data[14] = ydpi[1]; + + byte[] x = BinaryUtils.convert(width, 3); data[15] = x[0]; data[16] = x[1]; data[17] = x[2]; - byte[] y = BinaryUtils.convert(_height, 3); + byte[] y = BinaryUtils.convert(height, 3); data[18] = y[0]; data[19] = y[1]; data[20] = y[2]; + data[21] = 0x00; + data[22] = 0x00; + os.write(data); } diff --git a/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java b/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java index 00931ad2c..c0f06439e 100644 --- a/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java +++ b/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java @@ -22,7 +22,6 @@ package org.apache.fop.render.afp.modca; import java.awt.Color; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; /** @@ -64,6 +63,7 @@ public class PresentationTextObject extends AbstractNamedAFPObject { /** * Construct a new PresentationTextObject for the specified name argument, * the name should be an 8 character identifier. + * @param name the name of this presentation object */ public PresentationTextObject(String name) { @@ -89,7 +89,8 @@ public class PresentationTextObject extends AbstractNamedAFPObject { * @param data * The text data to be created. */ - public void createTextData(int fontNumber, int x, int y, Color col, int vsci, int ica, byte[] data) { + public void createTextData(int fontNumber, int x, int y, Color col, + int vsci, int ica, byte[] data) { // Use a default orientation of zero createTextData(fontNumber, x, y, 0, col, vsci, ica, data); @@ -225,7 +226,7 @@ public class PresentationTextObject extends AbstractNamedAFPObject { /** * Accessor method to write the AFP datastream for the PresentationTextObject. * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException thrown if an I/O exception of some sort has occurred */ public void writeDataStream(OutputStream os) throws IOException { @@ -238,9 +239,13 @@ public class PresentationTextObject extends AbstractNamedAFPObject { } + /** + * Returns the name of this presentation text object + * @return the name of this presentation text object + */ public String getName() { - return _name; + return name; } @@ -263,9 +268,9 @@ public class PresentationTextObject extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } @@ -293,9 +298,9 @@ public class PresentationTextObject extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } diff --git a/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java b/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java index 0a0b66301..07043dcf1 100644 --- a/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java @@ -21,7 +21,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; @@ -39,8 +38,11 @@ public final class ResourceGroup extends AbstractNamedAFPObject { /** * The overlays contained in this resource group */ - private List _overlays = new ArrayList(); + private List overlays = new ArrayList(); + /** + * Default constructor + */ public ResourceGroup() { this(DEFAULT_NAME); @@ -63,7 +65,7 @@ public final class ResourceGroup extends AbstractNamedAFPObject { * @param overlay the overlay to add */ public void addOverlay(Overlay overlay) { - _overlays.add(overlay); + overlays.add(overlay); } /** @@ -71,21 +73,21 @@ public final class ResourceGroup extends AbstractNamedAFPObject { * @return the list of overlays */ public List getOverlays() { - return _overlays; + return overlays; } /** * Accessor method to obtain write the AFP datastream for * the resource group. * @param os The stream to write to - * @throws java.io.IOException + * @throws java.io.IOException if an I/O exception of some sort has occurred */ public void writeDataStream(OutputStream os) throws IOException { writeStart(os); - writeObjectList(_overlays, os); + writeObjectList(overlays, os); writeEnd(os); @@ -110,9 +112,9 @@ public final class ResourceGroup extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } @@ -139,9 +141,9 @@ public final class ResourceGroup extends AbstractNamedAFPObject { data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved - for (int i = 0; i < _nameBytes.length; i++) { + for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = _nameBytes[i]; + data[9 + i] = nameBytes[i]; } diff --git a/src/java/org/apache/fop/render/ps/PSTextPainter.java b/src/java/org/apache/fop/render/ps/PSTextPainter.java index f4796fd2b..955db492d 100644 --- a/src/java/org/apache/fop/render/ps/PSTextPainter.java +++ b/src/java/org/apache/fop/render/ps/PSTextPainter.java @@ -40,6 +40,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.xmlgraphics.java2d.ps.PSGraphics2D; +import org.apache.xmlgraphics.java2d.ps.TextHandler; import org.apache.batik.dom.svg.SVGOMTextElement; import org.apache.batik.gvt.text.Mark; @@ -74,7 +75,7 @@ public class PSTextPainter implements TextPainter { protected Log log = LogFactory.getLog(PSTextPainter.class); private NativeTextHandler nativeTextHandler; - //private FontInfo fontInfo; + private FontInfo fontInfo; /** * Use the stroking text painter to get the bounds and shape. @@ -89,6 +90,7 @@ public class PSTextPainter implements TextPainter { */ public PSTextPainter(NativeTextHandler nativeTextHandler) { this.nativeTextHandler = nativeTextHandler; + this.fontInfo = nativeTextHandler.getFontInfo(); } /** @@ -314,6 +316,12 @@ public class PSTextPainter implements TextPainter { } } + drawPrimitiveString(g2d, loc, font, txt, tx); + loc.setLocation(loc.getX() + (double)advance, loc.getY()); + return loc; + } + + protected void drawPrimitiveString(Graphics2D g2d, Point2D loc, Font font, String txt, float tx) { //Finally draw text nativeTextHandler.setOverrideFont(font); try { @@ -327,8 +335,6 @@ public class PSTextPainter implements TextPainter { } finally { nativeTextHandler.setOverrideFont(null); } - loc.setLocation(loc.getX() + (double)advance, loc.getY()); - return loc; } private void updateLocationFromACI( @@ -380,7 +386,6 @@ public class PSTextPainter implements TextPainter { int weight = getWeight(aci); boolean found = false; - FontInfo fontInfo = nativeTextHandler.getFontInfo(); String fontFamily = null; List gvtFonts = (List) aci.getAttribute( GVTAttributedCharacterIterator.TextAttribute.GVT_FONT_FAMILIES); diff --git a/status.xml b/status.xml index ccf8190de..24b90423c 100644 --- a/status.xml +++ b/status.xml @@ -28,6 +28,9 @@ + + Added a configuration setting for the renderer/device resolution to the AFP renderer. + Facilitate the implementation for font-selection-strategy: * Changed FontInfo.fontLookup to always return an array of FontTriplet -- 2.39.5