diff options
author | Glen Mazza <gmazza@apache.org> | 2003-09-01 01:28:51 +0000 |
---|---|---|
committer | Glen Mazza <gmazza@apache.org> | 2003-09-01 01:28:51 +0000 |
commit | 454a54eebec9c5dd122a99e0fa09dbe5936852b1 (patch) | |
tree | 4dc1050c6f871f45d41289c85fb09c27c02eaaee /src | |
parent | 6aafc198b620d73f6f045f97bfadfc57a76329cd (diff) | |
download | xmlgraphics-fop-454a54eebec9c5dd122a99e0fa09dbe5936852b1.tar.gz xmlgraphics-fop-454a54eebec9c5dd122a99e0fa09dbe5936852b1.zip |
1. Partial implementation of fo:region-xxx and background-color property
in AWTRenderer.
2. ColorType has a new getAWTColor() method, also alpha() function renamed
to getAlpha(). Definition of Alpha values switched to make consistent with
java.awt.Color (i.e., 0 is transparent and 1 is opaque).
3. AbstractRenderer's handleViewportTraits() renamed to handleRegionTraits()
to lesson confusion (FOP has three types of viewports--
Page, Region, and Block--handleViewportTraits() was only good for Region.)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196878 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
8 files changed, 203 insertions, 73 deletions
diff --git a/src/java/org/apache/fop/area/CachedRenderPagesModel.java b/src/java/org/apache/fop/area/CachedRenderPagesModel.java index e20582854..49626d69e 100644 --- a/src/java/org/apache/fop/area/CachedRenderPagesModel.java +++ b/src/java/org/apache/fop/area/CachedRenderPagesModel.java @@ -68,7 +68,7 @@ import java.io.BufferedInputStream; * A simple cached render pages model. * If the page is prepared for later rendering then this saves * the page contents to a file and once the page is resolved - * the contents a reloaded. + * the contents are reloaded. */ public class CachedRenderPagesModel extends RenderPagesModel { private Map pageMap = new HashMap(); diff --git a/src/java/org/apache/fop/datatypes/ColorType.java b/src/java/org/apache/fop/datatypes/ColorType.java index b0d04945b..a40fc32f3 100644 --- a/src/java/org/apache/fop/datatypes/ColorType.java +++ b/src/java/org/apache/fop/datatypes/ColorType.java @@ -50,6 +50,7 @@ */ package org.apache.fop.datatypes; +import java.awt.Color; import java.io.Serializable; import java.util.StringTokenizer; @@ -61,22 +62,24 @@ public class ColorType implements Serializable { /** * the red component */ - protected float red; + protected float red = 0f; /** * the green component */ - protected float green; + protected float green = 0f; /** * the blue component */ - protected float blue; + protected float blue = 0f; /** - * the alpha component + * the alpha component (indicator of opaque-ness) + * 0.0 - 1.0; 0.0 is completely transparent; 1.0 is completely opaque + * see definition at http://java.sun.com/j2se/1.3/docs/api/java/awt/Color.html */ - protected float alpha = 0; + protected float alpha = 1f; /** * Main constructor @@ -177,7 +180,7 @@ public class ColorType implements Serializable { this.red = 0; this.green = 0; this.blue = 0; - this.alpha = 1; + this.alpha = 0; } else { boolean found = false; for (int count = 0; count < NAMES.length; count++) { @@ -225,14 +228,22 @@ public class ColorType implements Serializable { } /** - * Returns the alpha (transparency) component of the color. - * @return float a value between 0.0 and 1.0 + * Returns the alpha (degree of opaque-ness) component of the color. + * @return float a value between 0.0 (fully transparent) and 1.0 (fully opaque) */ - public float alpha() { + public float getAlpha() { return this.alpha; } /** + * Returns an AWT instance of this color + * @return float the AWT color represented by this ColorType instance + */ + public Color getAWTColor() { + return new Color(this.red, this.green, this.blue, this.alpha); + } + + /** * @param floatValue value (between 0.0 and 1.0) of color channel * @return integer equivalent (between 0 and 255) */ diff --git a/src/java/org/apache/fop/fo/PropertyManager.java b/src/java/org/apache/fop/fo/PropertyManager.java index e9305d64c..f58e92419 100644 --- a/src/java/org/apache/fop/fo/PropertyManager.java +++ b/src/java/org/apache/fop/fo/PropertyManager.java @@ -337,7 +337,7 @@ public class PropertyManager { CommonBackground bp = new CommonBackground(); bp.backAttachment = properties.get("background-attachment").getEnum(); bp.backColor = properties.get("background-color").getColorType(); - if (bp.backColor.alpha() == 1) { + if (bp.backColor.getAlpha() == 0) { bp.backColor = null; } diff --git a/src/java/org/apache/fop/render/AbstractRenderer.java b/src/java/org/apache/fop/render/AbstractRenderer.java index 5becb0f6b..80f92edcd 100644 --- a/src/java/org/apache/fop/render/AbstractRenderer.java +++ b/src/java/org/apache/fop/render/AbstractRenderer.java @@ -311,7 +311,7 @@ public abstract class AbstractRenderer extends AbstractLogEnabled startVParea(region.getCTM()); // do after starting viewport area - handleViewportTraits(port); + handleRegionTraits(port); if (region.getRegionClass() == Region.BODY_CODE) { renderBodyRegion((BodyRegion) region); } else { @@ -329,13 +329,12 @@ public abstract class AbstractRenderer extends AbstractLogEnabled protected void startVParea(CTM ctm) { } /** - * Handle viewport traits. - * This should be overridden to draw border and background - * traits for the viewport area. - * - * @param rv the region viewport area + * Handle the traits for a region + * This is used to draw the traits for the given page region + * (see Sect. 6.4.1.2 of XSL-FO spec.) + * @param rv the RegionViewport whose region is to be drawn */ - protected void handleViewportTraits(RegionViewport rv) { + protected void handleRegionTraits(RegionViewport rv) { // draw border and background } diff --git a/src/java/org/apache/fop/render/awt/AWTRenderer.java b/src/java/org/apache/fop/render/awt/AWTRenderer.java index 0da4214e4..64743752a 100644 --- a/src/java/org/apache/fop/render/awt/AWTRenderer.java +++ b/src/java/org/apache/fop/render/awt/AWTRenderer.java @@ -86,9 +86,15 @@ import org.apache.fop.area.Area; import org.apache.fop.area.Page; import org.apache.fop.area.PageViewport; import org.apache.fop.area.RegionViewport; +import org.apache.fop.area.Trait; +import org.apache.fop.datatypes.ColorType; import org.apache.fop.fo.FOTreeControl; +import org.apache.fop.fo.properties.BackgroundRepeat; import org.apache.fop.fonts.Font; +import org.apache.fop.image.FopImage; +import org.apache.fop.image.ImageFactory; import org.apache.fop.render.AbstractRenderer; +import org.apache.fop.traits.BorderProps; import org.apache.fop.viewer.PreviewDialog; import org.apache.fop.viewer.Translator; @@ -100,6 +106,8 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable protected double scaleFactor = 100.0; protected int pageNumber = 0; protected Vector pageViewportList = new java.util.Vector(); + protected Vector pageList = new java.util.Vector(); + protected BufferedImage currentPageImage = null; /** Font configuration */ protected Document fontInfo; @@ -186,6 +194,7 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable throws IOException { // empty pageViewportList, in case of a reload from PreviewDialog pageViewportList.removeAllElements(); + pageList.removeAllElements(); } public void stopRenderer() @@ -242,6 +251,7 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable */ public void renderPage(PageViewport pageViewport) throws IOException, FOPException { pageViewportList.add(pageViewport); + pageList.add(pageViewport.getPage().clone()); } /** Generates a desired page from the renderer's page viewport vector. @@ -256,18 +266,23 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable + " page(s) available."); } PageViewport pageViewport = (PageViewport) pageViewportList.get(pageNum); - Page page = pageViewport.getPage(); + Page page = (Page) pageList.get(pageNum); Rectangle2D bounds = pageViewport.getViewArea(); int pageWidth = (int)((float) bounds.getWidth() / 1000f + .5); int pageHeight = (int)((float) bounds.getHeight() / 1000f + .5); - - BufferedImage pageImage = +/* + System.out.println("(Page) X, Y, Width, Height: " + bounds.getX() + + " " + bounds.getY() + + " " + bounds.getWidth() + + " " + bounds.getHeight()); +*/ + currentPageImage = new BufferedImage((int)((pageWidth * (int)scaleFactor) / 100), (int)((pageHeight * (int)scaleFactor) / 100), BufferedImage.TYPE_INT_RGB); - Graphics2D graphics = pageImage.createGraphics(); + Graphics2D graphics = currentPageImage.createGraphics(); graphics.setRenderingHint (RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); @@ -286,10 +301,116 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable graphics.drawLine(0, pageHeight + 2, pageWidth + 2, pageHeight + 2); graphics.drawLine(1, pageHeight + 3, pageWidth + 3, pageHeight + 3); - this.currentFontName = ""; - this.currentFontSize = 0; -// renderPageAreas(page); - return pageImage; + currentFontName = ""; + currentFontSize = 0; + renderPageAreas(page); + return currentPageImage; } + /** + * Handle the traits for a region + * This is used to draw the traits for the given page region + * (see Sect. 6.4.1.2 of XSL-FO spec.) + * @param region the RegionViewport whose region is to be drawn + */ + protected void handleRegionTraits(RegionViewport region) { + currentFontName = ""; + currentFontSize = 0; + Rectangle2D viewArea = region.getViewArea(); +/* + if (region.getRegion() != null) { + System.out.print("Region type = " + region.getRegion().getRegionClass()); + } + System.out.println(" X, Y, Width, Height: " + viewArea.getX() + + " " + viewArea.getY() + + " " + viewArea.getWidth() + + " " + viewArea.getHeight()); +*/ + int startX = (int)(((float) viewArea.getX() / 1000f + .5) + * (scaleFactor / 100f)); + int startY = (int)(((float) viewArea.getY() / 1000f + .5) + * (scaleFactor / 100f)); + int width = (int)(((float) viewArea.getWidth() / 1000f + .5) + * (scaleFactor / 100f)); + int height = (int)(((float) viewArea.getHeight() / 1000f + .5) + * (scaleFactor / 100f)); + + drawBackAndBorders(region, startX, startY, width, height); + } + + /** + * Draw the background and borders. + * This draws the background and border traits for an area given + * the position. + * + * @param block the area to get the traits from + * @param startx the start x position + * @param starty the start y position + * @param width the width of the area + * @param height the height of the area + */ + protected void drawBackAndBorders(Area block, + int startx, int starty, + int width, int height) { + + // draw background then border + Graphics2D graphics = currentPageImage.createGraphics(); + Trait.Background back; + back = (Trait.Background) block.getTrait(Trait.BACKGROUND); + if (back != null) { + + if (back.getColor() != null) { + graphics.setColor(back.getColor().getAWTColor()); + graphics.fillRect(startx, starty, width, height); + } + if (back.getURL() != null) { // TODO: implement + ImageFactory fact = ImageFactory.getInstance(); + FopImage fopimage = fact.getImage(back.getURL(), userAgent); + if (fopimage != null && fopimage.load(FopImage.DIMENSIONS, userAgent)) { + if (back.getRepeat() == BackgroundRepeat.REPEAT) { + // create a pattern for the image + } else { + // place once + Rectangle2D pos; + pos = new Rectangle2D.Float((startx + back.getHoriz()) * 1000, + (starty + back.getVertical()) * 1000, + fopimage.getWidth() * 1000, + fopimage.getHeight() * 1000); +// putImage(back.getURL(), pos); + } + } + } + } + + BorderProps bps = (BorderProps) block.getTrait(Trait.BORDER_BEFORE); + if (bps != null) { + int endx = startx + width; + int bwidth = bps.width; + graphics.setColor(bps.color.getAWTColor()); + graphics.drawLine(startx, starty + bwidth / 2, endx, starty + bwidth / 2); + } + bps = (BorderProps) block.getTrait(Trait.BORDER_START); + if (bps != null) { + int endy = starty + height; + int bwidth = bps.width; + graphics.setColor(bps.color.getAWTColor()); + graphics.drawLine(startx + bwidth / 2, starty, startx + bwidth / 2, endy); + } + bps = (BorderProps) block.getTrait(Trait.BORDER_AFTER); + if (bps != null) { + int sy = starty + height; + int endx = startx + width; + int bwidth = bps.width; + graphics.setColor(bps.color.getAWTColor()); + graphics.drawLine(startx, sy - bwidth / 2, endx, sy - bwidth / 2); + } + bps = (BorderProps) block.getTrait(Trait.BORDER_END); + if (bps != null) { + int sx = startx + width; + int endy = starty + height; + int bwidth = bps.width; + graphics.setColor(bps.color.getAWTColor()); + graphics.drawLine(sx - bwidth / 2, starty, sx - bwidth / 2, endy); + } + } } diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java index 2770b9a75..25c4c2971 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java @@ -67,46 +67,21 @@ import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; // FOP -import org.apache.fop.render.PrintRenderer; -import org.apache.fop.render.RendererContext; -import org.apache.fop.apps.FOUserAgent; -import org.apache.fop.image.FopImage; -import org.apache.fop.image.XMLImage; -import org.apache.fop.image.ImageFactory; import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Version; -import org.apache.fop.fo.properties.RuleStyle; -import org.apache.fop.fo.properties.BackgroundRepeat; -import org.apache.fop.fonts.Typeface; -import org.apache.fop.fonts.FontMetrics; -import org.apache.fop.pdf.PDFEncryptionManager; -import org.apache.fop.pdf.PDFFilterList; -import org.apache.fop.pdf.PDFStream; -import org.apache.fop.pdf.PDFDocument; -import org.apache.fop.pdf.PDFInfo; -import org.apache.fop.pdf.PDFResources; -import org.apache.fop.pdf.PDFResourceContext; -import org.apache.fop.pdf.PDFText; -import org.apache.fop.pdf.PDFXObject; -import org.apache.fop.pdf.PDFPage; -import org.apache.fop.pdf.PDFState; -import org.apache.fop.pdf.PDFLink; -import org.apache.fop.pdf.PDFOutline; -import org.apache.fop.pdf.PDFAnnotList; -import org.apache.fop.pdf.PDFColor; -import org.apache.fop.area.extensions.BookmarkData; - -import org.apache.fop.area.Trait; -import org.apache.fop.area.TreeExt; -import org.apache.fop.area.CTM; -import org.apache.fop.area.Title; -import org.apache.fop.area.PageViewport; -import org.apache.fop.area.Page; -import org.apache.fop.area.RegionViewport; import org.apache.fop.area.Area; import org.apache.fop.area.Block; import org.apache.fop.area.BlockViewport; +import org.apache.fop.area.CTM; import org.apache.fop.area.LineArea; +import org.apache.fop.area.Page; +import org.apache.fop.area.PageViewport; +import org.apache.fop.area.RegionViewport; +import org.apache.fop.area.Title; +import org.apache.fop.area.Trait; +import org.apache.fop.area.TreeExt; +import org.apache.fop.area.extensions.BookmarkData; import org.apache.fop.area.inline.Character; import org.apache.fop.area.inline.Word; import org.apache.fop.area.inline.Viewport; @@ -114,10 +89,34 @@ import org.apache.fop.area.inline.ForeignObject; import org.apache.fop.area.inline.Image; import org.apache.fop.area.inline.Leader; import org.apache.fop.area.inline.InlineParent; +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.fo.properties.BackgroundRepeat; +import org.apache.fop.fo.properties.RuleStyle; +import org.apache.fop.fonts.Typeface; import org.apache.fop.fonts.Font; +import org.apache.fop.fonts.FontMetrics; +import org.apache.fop.image.FopImage; +import org.apache.fop.image.ImageFactory; +import org.apache.fop.image.XMLImage; +import org.apache.fop.pdf.PDFAnnotList; +import org.apache.fop.pdf.PDFColor; +import org.apache.fop.pdf.PDFDocument; +import org.apache.fop.pdf.PDFEncryptionManager; +import org.apache.fop.pdf.PDFFilterList; +import org.apache.fop.pdf.PDFInfo; +import org.apache.fop.pdf.PDFLink; +import org.apache.fop.pdf.PDFOutline; +import org.apache.fop.pdf.PDFPage; +import org.apache.fop.pdf.PDFResourceContext; +import org.apache.fop.pdf.PDFResources; +import org.apache.fop.pdf.PDFState; +import org.apache.fop.pdf.PDFStream; +import org.apache.fop.pdf.PDFText; +import org.apache.fop.pdf.PDFXObject; +import org.apache.fop.render.PrintRenderer; +import org.apache.fop.render.RendererContext; import org.apache.fop.traits.BorderProps; -import org.apache.fop.datatypes.ColorType; -import org.apache.fop.apps.*; + /* todo: @@ -494,12 +493,12 @@ public class PDFRenderer extends PrintRenderer { } /** - * Handle the viewport traits. - * This is used to draw the traits for a viewport. - * - * @param region the viewport region to handle + * Handle the traits for a region + * This is used to draw the traits for the given page region + * (see Sect. 6.4.1.2 of XSL-FO spec.) + * @param region the RegionViewport whose region is to be drawn */ - protected void handleViewportTraits(RegionViewport region) { + protected void handleRegionTraits(RegionViewport region) { currentFontName = ""; float startx = 0; float starty = 0; diff --git a/src/java/org/apache/fop/render/ps/PSRenderer.java b/src/java/org/apache/fop/render/ps/PSRenderer.java index 97551e29b..bf02f03fa 100644 --- a/src/java/org/apache/fop/render/ps/PSRenderer.java +++ b/src/java/org/apache/fop/render/ps/PSRenderer.java @@ -652,12 +652,12 @@ public class PSRenderer extends AbstractRenderer { } /** - * Handle the viewport traits. - * This is used to draw the traits for a viewport. - * - * @param region the viewport region to handle + * Handle the traits for a region + * This is used to draw the traits for the given page region + * (see Sect. 6.4.1.2 of XSL-FO spec.) + * @param region the RegionViewport whose region is to be drawn */ - protected void handleViewportTraits(RegionViewport region) { + protected void handleRegionTraits(RegionViewport region) { currentFontName = ""; float startx = 0; float starty = 0; diff --git a/src/java/org/apache/fop/rtf/renderer/RTFHandler.java b/src/java/org/apache/fop/rtf/renderer/RTFHandler.java index f1953d7f2..723bdddfb 100644 --- a/src/java/org/apache/fop/rtf/renderer/RTFHandler.java +++ b/src/java/org/apache/fop/rtf/renderer/RTFHandler.java @@ -433,7 +433,7 @@ public class RTFHandler extends FOInputHandler { PDF output, so we will look for the default here & change it to white. */ if ((fopValue.getRed() == 0) && (fopValue.getGreen() == 0) - && (fopValue.getBlue() == 0) && (fopValue.alpha() == 1)) { + && (fopValue.getBlue() == 0) && (fopValue.getAlpha() == 0)) { rtfColor = RtfColorTable.getInstance().getColorNumber("white"); } else { rtfColor = convertFOPColorToRTF(fopValue); |