From: Vincent Hennebert Date: Tue, 23 Nov 2010 19:23:59 +0000 (+0000) Subject: Bugzilla #49695: Replaced magic numbers with constants from UnitConv and GraphicsCons... X-Git-Tag: fop-1_1rc1old~404 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2e8f9428b4fa41d5a78f4cf67731bc8a9105272e;p=xmlgraphics-fop.git Bugzilla #49695: Replaced magic numbers with constants from UnitConv and GraphicsConstants Patch submitted by Joshua Marquart (joshua dot marquart _at. firstdata .dot_ com), applied with some modifications git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1038291 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/apps/FOUserAgent.java b/src/java/org/apache/fop/apps/FOUserAgent.java index 0a65203cc..071066e04 100644 --- a/src/java/org/apache/fop/apps/FOUserAgent.java +++ b/src/java/org/apache/fop/apps/FOUserAgent.java @@ -35,6 +35,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.xmlgraphics.image.loader.ImageContext; import org.apache.xmlgraphics.image.loader.ImageSessionContext; import org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext; +import org.apache.xmlgraphics.util.UnitConv; import org.apache.fop.Version; import org.apache.fop.accessibility.Accessibility; @@ -450,7 +451,7 @@ public class FOUserAgent { * @see #getTargetResolution() */ public float getTargetPixelUnitToMillimeter() { - return 25.4f / this.targetResolution; + return UnitConv.IN2MM / this.targetResolution; } /** @return the resolution for resolution-dependant output */ diff --git a/src/java/org/apache/fop/apps/FopFactory.java b/src/java/org/apache/fop/apps/FopFactory.java index 7bcdd2703..b86c52cf6 100644 --- a/src/java/org/apache/fop/apps/FopFactory.java +++ b/src/java/org/apache/fop/apps/FopFactory.java @@ -42,6 +42,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.xmlgraphics.image.loader.ImageContext; import org.apache.xmlgraphics.image.loader.ImageManager; +import org.apache.xmlgraphics.util.UnitConv; import org.apache.fop.fo.ElementMapping; import org.apache.fop.fo.ElementMappingRegistry; @@ -539,7 +540,7 @@ public class FopFactory implements ImageContext { * @see #getSourceResolution() */ public float getSourcePixelUnitToMillimeter() { - return 25.4f / getSourceResolution(); + return UnitConv.IN2MM / getSourceResolution(); } /** @@ -567,7 +568,7 @@ public class FopFactory implements ImageContext { * @see #getTargetResolution() */ public float getTargetPixelUnitToMillimeter() { - return 25.4f / this.targetResolution; + return UnitConv.IN2MM / this.targetResolution; } /** diff --git a/src/java/org/apache/fop/apps/FopFactoryConfigurator.java b/src/java/org/apache/fop/apps/FopFactoryConfigurator.java index ad0869ea1..161bd4a8f 100644 --- a/src/java/org/apache/fop/apps/FopFactoryConfigurator.java +++ b/src/java/org/apache/fop/apps/FopFactoryConfigurator.java @@ -33,6 +33,7 @@ import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.xmlgraphics.image.GraphicsConstants; import org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry; import org.apache.xmlgraphics.image.loader.util.Penalty; @@ -61,10 +62,10 @@ public class FopFactoryConfigurator { public static final String DEFAULT_PAGE_HEIGHT = "11in"; /** Defines the default source resolution (72dpi) for FOP */ - public static final float DEFAULT_SOURCE_RESOLUTION = 72.0f; //dpi + public static final float DEFAULT_SOURCE_RESOLUTION = GraphicsConstants.DEFAULT_DPI; //dpi /** Defines the default target resolution (72dpi) for FOP */ - public static final float DEFAULT_TARGET_RESOLUTION = 72.0f; //dpi + public static final float DEFAULT_TARGET_RESOLUTION = GraphicsConstants.DEFAULT_DPI; //dpi private static final String PREFER_RENDERER = "prefer-renderer"; @@ -159,7 +160,7 @@ public class FopFactoryConfigurator { lang = hyphPatConfig[i].getAttribute("lang", null); if (lang == null) { - addError("The lang attribute of a hyphenation-pattern configuration" + addError("The lang attribute of a hyphenation-pattern configuration" + " element must exist (" + location + ")", error); } else if (!lang.matches("[a-zA-Z]{2}")) { addError("The lang attribute of a hyphenation-pattern configuration" @@ -191,7 +192,7 @@ public class FopFactoryConfigurator { LogUtil.handleError(log, error.toString(), strict); continue; } - + String llccKey = HyphenationTreeCache.constructLlccKey(lang, country); hyphPatNames.put(llccKey, filename); if (log.isDebugEnabled()) { @@ -270,7 +271,7 @@ public class FopFactoryConfigurator { } error.append(message); } - + private void configureImageLoading(Configuration parent, boolean strict) throws FOPException { if (parent == null) { return; diff --git a/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java b/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java index 9efc2aaf0..0b7989fb2 100644 --- a/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java +++ b/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java @@ -33,6 +33,7 @@ import org.apache.batik.gvt.GraphicsNode; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.xmlgraphics.image.GraphicsConstants; import org.apache.xmlgraphics.image.loader.Image; import org.apache.xmlgraphics.image.loader.ImageException; import org.apache.xmlgraphics.image.loader.ImageFlavor; @@ -72,7 +73,7 @@ public class ImageConverterSVG2G2D extends AbstractImageConverter { } //Prepare - float pxToMillimeter = UnitConv.IN2MM / 72; //default: 72dpi + float pxToMillimeter = UnitConv.IN2MM / GraphicsConstants.DEFAULT_DPI; Number ptm = (Number)hints.get(ImageProcessingHints.SOURCE_RESOLUTION); if (ptm != null) { pxToMillimeter = (float)(UnitConv.IN2MM / ptm.doubleValue()); diff --git a/src/java/org/apache/fop/render/awt/AWTRenderer.java b/src/java/org/apache/fop/render/awt/AWTRenderer.java index 0128cf90e..99dece24a 100644 --- a/src/java/org/apache/fop/render/awt/AWTRenderer.java +++ b/src/java/org/apache/fop/render/awt/AWTRenderer.java @@ -29,14 +29,16 @@ package org.apache.fop.render.awt; // Java import java.awt.Color; import java.awt.Dimension; -import java.awt.geom.Rectangle2D; import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; import java.awt.print.PageFormat; import java.awt.print.Pageable; import java.awt.print.Paper; import java.awt.print.Printable; import java.io.IOException; +import org.apache.xmlgraphics.util.UnitConv; + import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.FopFactoryConfigurator; @@ -46,8 +48,8 @@ import org.apache.fop.area.PageViewport; import org.apache.fop.render.awt.viewer.PreviewDialog; import org.apache.fop.render.awt.viewer.Renderable; import org.apache.fop.render.awt.viewer.StatusListener; -import org.apache.fop.render.java2d.Java2DRenderer; import org.apache.fop.render.extensions.prepress.PageScale; +import org.apache.fop.render.java2d.Java2DRenderer; /** * The AWTRender outputs the pages generated by the layout engine to a Swing @@ -152,10 +154,10 @@ public class AWTRenderer extends Java2DRenderer implements Pageable { pageWidth = (int) Math.round(bounds.getWidth() / 1000f); pageHeight = (int) Math.round(bounds.getHeight() / 1000f); double scaleX = scaleFactor - * (25.4 / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION) + * (UnitConv.IN2MM / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION) / userAgent.getTargetPixelUnitToMillimeter(); double scaleY = scaleFactor - * (25.4 / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION) + * (UnitConv.IN2MM / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION) / userAgent.getTargetPixelUnitToMillimeter(); if (getPageViewport(pageNum).getForeignAttributes() != null) { String scale = (String) getPageViewport(pageNum).getForeignAttributes().get( diff --git a/src/java/org/apache/fop/render/java2d/Java2DImageHandlerRenderedImage.java b/src/java/org/apache/fop/render/java2d/Java2DImageHandlerRenderedImage.java index c29684118..4bdd52162 100644 --- a/src/java/org/apache/fop/render/java2d/Java2DImageHandlerRenderedImage.java +++ b/src/java/org/apache/fop/render/java2d/Java2DImageHandlerRenderedImage.java @@ -27,6 +27,7 @@ import java.awt.image.RenderedImage; import java.awt.image.WritableRaster; import java.io.IOException; +import org.apache.xmlgraphics.image.GraphicsConstants; import org.apache.xmlgraphics.image.loader.Image; import org.apache.xmlgraphics.image.loader.ImageFlavor; import org.apache.xmlgraphics.image.loader.ImageInfo; @@ -76,7 +77,7 @@ public class Java2DImageHandlerRenderedImage implements ImageHandler { //scaling because of image resolution //float sourceResolution = java2dContext.getUserAgent().getSourceResolution(); //source resolution seems to be a bad idea, not sure why - float sourceResolution = 72; + float sourceResolution = GraphicsConstants.DEFAULT_DPI; sourceResolution *= 1000; //we're working in the millipoint area sx *= sourceResolution / info.getSize().getDpiHorizontal(); sy *= sourceResolution / info.getSize().getDpiVertical(); diff --git a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java index 73af5c8be..353aefa25 100644 --- a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java +++ b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java @@ -53,6 +53,7 @@ import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D; import org.apache.xmlgraphics.image.loader.impl.ImageRendered; import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM; import org.apache.xmlgraphics.image.loader.util.ImageUtil; +import org.apache.xmlgraphics.util.UnitConv; import org.apache.fop.ResourceEventProducer; import org.apache.fop.apps.FOPException; @@ -317,10 +318,10 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem } scaleX = scaleX - * (25.4f / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION) + * (UnitConv.IN2MM / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION) / userAgent.getTargetPixelUnitToMillimeter(); scaleY = scaleY - * (25.4f / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION) + * (UnitConv.IN2MM / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION) / userAgent.getTargetPixelUnitToMillimeter(); int bitmapWidth = (int) ((pageWidth * scaleX) + 0.5); int bitmapHeight = (int) ((pageHeight * scaleY) + 0.5); diff --git a/src/java/org/apache/fop/render/rtf/FoUnitsConverter.java b/src/java/org/apache/fop/render/rtf/FoUnitsConverter.java index 33a2ff904..8540fcde3 100644 --- a/src/java/org/apache/fop/render/rtf/FoUnitsConverter.java +++ b/src/java/org/apache/fop/render/rtf/FoUnitsConverter.java @@ -24,6 +24,7 @@ import java.util.Map; import org.apache.fop.apps.FOPException; import org.apache.fop.fo.properties.FixedLength; +import org.apache.xmlgraphics.util.UnitConv; /** Converts XSL-FO units to RTF units @@ -43,8 +44,8 @@ final class FoUnitsConverter { public static final float POINT_TO_TWIPS = 20f; /** millimeters and centimeters to twips: , one point is 1/72 of an inch, one inch is 25.4 mm */ - public static final float IN_TO_TWIPS = 72f * POINT_TO_TWIPS; - public static final float MM_TO_TWIPS = IN_TO_TWIPS / 25.4f; + public static final float IN_TO_TWIPS = UnitConv.IN2PT * POINT_TO_TWIPS; + public static final float MM_TO_TWIPS = IN_TO_TWIPS / UnitConv.IN2MM; public static final float CM_TO_TWIPS = 10 * MM_TO_TWIPS; diff --git a/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java b/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java index aa8c5238c..01ef22efa 100644 --- a/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java +++ b/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java @@ -26,7 +26,6 @@ import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; import org.w3c.dom.DOMImplementation; - import org.xml.sax.EntityResolver; import org.apache.avalon.framework.configuration.Configurable; @@ -48,10 +47,12 @@ import org.apache.batik.util.SVGConstants; import org.apache.commons.logging.Log; import org.apache.commons.logging.impl.SimpleLog; +import org.apache.xmlgraphics.image.GraphicsConstants; import org.apache.xmlgraphics.image.loader.ImageContext; import org.apache.xmlgraphics.image.loader.ImageManager; import org.apache.xmlgraphics.image.loader.ImageSessionContext; import org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext; +import org.apache.xmlgraphics.util.UnitConv; /** * This is the common base class of all of FOP's transcoders. @@ -226,7 +227,7 @@ public abstract class AbstractFOPTranscoder extends SVGAbstractTranscoder implem if (hints.containsKey(KEY_DEVICE_RESOLUTION)) { return ((Float)hints.get(KEY_DEVICE_RESOLUTION)).floatValue(); } else { - return 72; + return GraphicsConstants.DEFAULT_DPI; } } @@ -253,7 +254,7 @@ public abstract class AbstractFOPTranscoder extends SVGAbstractTranscoder implem protected void setupImageInfrastructure(final String baseURI) { final ImageContext imageContext = new ImageContext() { public float getSourceResolution() { - return 25.4f / userAgent.getPixelUnitToMillimeter(); + return UnitConv.IN2MM / userAgent.getPixelUnitToMillimeter(); } }; this.imageManager = new ImageManager(imageContext); @@ -372,7 +373,7 @@ public abstract class AbstractFOPTranscoder extends SVGAbstractTranscoder implem return ((Float)getTranscodingHints().get(key)).floatValue(); } else { // return 0.3528f; // 72 dpi - return 25.4f / 96; //96dpi = 0.2645833333333333333f; + return UnitConv.IN2MM / 96; //96dpi = 0.2645833333333333333f; } } diff --git a/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java b/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java index 409b8dd9f..db1d9e2de 100644 --- a/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java +++ b/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java @@ -30,6 +30,8 @@ import java.io.IOException; import java.io.OutputStream; import java.io.StringWriter; +import org.apache.xmlgraphics.image.GraphicsConstants; + import org.apache.fop.Version; import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.FontSetup; @@ -64,7 +66,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D { /** Normal PDF resolution (72dpi) */ public static final int NORMAL_PDF_RESOLUTION = 72; /** Default device resolution (300dpi is a resonable quality for most purposes) */ - public static final int DEFAULT_NATIVE_DPI = 300; + public static final int DEFAULT_NATIVE_DPI = GraphicsConstants.DEFAULT_SAMPLE_DPI; /** * The device resolution may be different from the normal target resolution. See diff --git a/src/java/org/apache/fop/svg/PDFGraphics2D.java b/src/java/org/apache/fop/svg/PDFGraphics2D.java index 45189133a..7c8d4a6b9 100644 --- a/src/java/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/java/org/apache/fop/svg/PDFGraphics2D.java @@ -60,6 +60,7 @@ import org.apache.batik.ext.awt.RenderingHintsKeyExt; import org.apache.batik.gvt.GraphicsNode; import org.apache.batik.gvt.PatternPaint; +import org.apache.xmlgraphics.image.GraphicsConstants; import org.apache.xmlgraphics.image.loader.ImageInfo; import org.apache.xmlgraphics.image.loader.ImageSize; import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax; @@ -1270,7 +1271,8 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand private PDFXObject addRenderedImage(String key, RenderedImage img) { ImageInfo info = new ImageInfo(null, "image/unknown"); - ImageSize size = new ImageSize(img.getWidth(), img.getHeight(), 72); + ImageSize size = new ImageSize(img.getWidth(), img.getHeight(), + GraphicsConstants.DEFAULT_DPI); info.setSize(size); ImageRendered imgRend = new ImageRendered(info, img, null); ImageRenderedAdapter adapter = new ImageRenderedAdapter(imgRend, key); diff --git a/status.xml b/status.xml index b651ddf89..69aff4921 100644 --- a/status.xml +++ b/status.xml @@ -58,6 +58,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Replaced magic numbers with constants from UnitConv and GraphicsConstants. + Added some support for break-before/-after for RTF output.