arved 02/04/23 15:26:59 Modified: src/org/apache/fop/render Tag: fop-0_20_2-maintain AbstractRenderer.java PrintRenderer.java Log: support for background-image (all renderers) author: Michael Gratton Revision Changes Path No revision No revision 1.4.2.2 +229 -12 xml-fop/src/org/apache/fop/render/AbstractRenderer.java Index: AbstractRenderer.java =================================================================== RCS file: /x1/home/cvs/xml-fop/src/org/apache/fop/render/AbstractRenderer.java,v retrieving revision 1.4.2.1 retrieving revision 1.4.2.2 diff -u -r1.4.2.1 -r1.4.2.2 --- AbstractRenderer.java 17 Mar 2002 23:37:07 -0000 1.4.2.1 +++ AbstractRenderer.java 23 Apr 2002 22:26:58 -0000 1.4.2.2 @@ -1,5 +1,5 @@ /* - * $Id: AbstractRenderer.java,v 1.4.2.1 2002/03/17 23:37:07 chrisg Exp $ + * $Id: AbstractRenderer.java,v 1.4.2.2 2002/04/23 22:26:58 arved Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -8,9 +8,9 @@ package org.apache.fop.render; // FOP -import org.apache.fop.pdf.PDFPathPaint; -import org.apache.fop.pdf.PDFColor; import org.apache.fop.image.ImageArea; +import org.apache.fop.image.FopImage; +import org.apache.fop.image.FopImageException; import org.apache.fop.apps.FOPException; import org.apache.fop.fo.properties.*; import org.apache.fop.layout.*; @@ -64,6 +64,133 @@ protected abstract void doFrame(Area area); /** + * Renders an area's background. + * @param x the x position of the left edge in millipoints + * @param y the y position of top edge in millipoints + * @param w the width in millipoints + * @param h the height in millipoints + */ + protected void doBackground(Area area, int x, int y, int w, int h) { + System.out.println("Doing background: " + area); + System.out.println(" x:" + x + " y:" + y); + System.out.println(" w:" + w + " h:" + h); + + if (h == 0 || w == 0) + return; + + BackgroundProps props = area.getBackground(); + if (props == null) + return; + + if (props.backColor.alpha() == 0) { + this.addFilledRect(x, y, w, -h, props.backColor); + } + + // XXX: I'm ignoring area rotation here 8( + // is this taken care of for me elsewhere in the codebase? + if (props.backImage != null) { + int imgW; + int imgH; + try { + // XXX: do correct unit conversion here + imgW = props.backImage.getWidth() * 1000; + imgH = props.backImage.getHeight() * 1000; + } + catch (FopImageException fie) { + log.error("Error obtaining bg image width and height", fie); + return; + } + + int dx = x; + int dy = y; + int endX = x + w; + int endY = y - h; + int clipW = w % imgW; + int clipH = h % imgH; + + boolean repeatX = true; + boolean repeatY = true; + switch (props.backRepeat) { + case BackgroundRepeat.REPEAT: + break; + + case BackgroundRepeat.REPEAT_X: + repeatY = false; + break; + + case BackgroundRepeat.REPEAT_Y: + repeatX = false; + break; + + case BackgroundRepeat.NO_REPEAT: + repeatX = false; + repeatY = false; + break; + + case BackgroundRepeat.INHERIT: + // XXX: what to do here? + break; + + default: + log.error("Ignoring invalid background-repeat property"); + } + + FontState fs = area.getFontState(); + + while (dy > endY) { // looping through rows + while (dx < endX) { // looping through cols + if (dx + imgW <= endX) { + // no x clipping + if (dy - imgH >= endY) { + // no x clipping, no y clipping + drawImageScaled(dx, dy, imgW, imgH, + props.backImage, fs); + } + else { + // no x clipping, y clipping + drawImageClipped(dx, dy, + 0, 0, imgW, clipH, + props.backImage, fs); + } + } + else { + // x clipping + if (dy - imgH >= endY) { + // x clipping, no y clipping + drawImageClipped(dx, dy, + 0, 0, clipW, imgH, + props.backImage, fs); + } + + else { + // x clipping, y clipping + drawImageClipped(dx, dy, + 0, 0, clipW, clipH, + props.backImage, fs); + } + } + + if (repeatX) { + dx += imgW; + } + else { + break; + } + } // end looping through cols + + dx = x; + + if (repeatY) { + dy -= imgH; + } + else { + break; + } + } // end looping through rows + } + } + + /** * Add a filled rectangle to the current stream * This default implementation calls addRect * using the same color for fill and border. @@ -77,6 +204,95 @@ protected abstract void addFilledRect(int x, int y, int w, int h, ColorType col); + /** + * Renders an image, rendered at the image's intrinsic size. + * This by default calls drawImageScaled() with the image's + * intrinsic width and height, but implementations may + * override this method if it can provide a more efficient solution. + * + * @param x the x position of left edge in millipoints + * @param y the y position of top edge in millipoints + * @param image the image to be rendered + * @param fs the font state to use when rendering text + * in non-bitmapped images. + */ + protected void drawImage(int x, int y, FopImage image, FontState fs) { + int w; + int h; + try { + // XXX: convert these units correctly + w = image.getWidth() * 1000; + h = image.getHeight() * 1000; + } + catch (FopImageException e) { + log.error("Failed to obtain the image width and height", e); + return; + } + drawImageScaled(x, y, w, h, image, fs); + } + + /** + * Renders an image, scaling it to the given width and height. + * If the scaled width and height is the same intrinsic size + * of the image, the image is not scaled. + * + * @param x the x position of left edge in millipoints + * @param y the y position of top edge in millipoints + * @param w the width in millipoints + * @param h the height in millipoints + * @param image the image to be rendered + * @param fs the font state to use when rendering text + * in non-bitmapped images. + */ + protected abstract void drawImageScaled(int x, int y, int w, int h, + FopImage image, + FontState fs); + + /** + * Renders an image, clipping it as specified. + * + * @param x the x position of left edge in millipoints. + * @param y the y position of top edge in millipoints. + * @param clipX the left edge of the clip in millipoints + * @param clipY the top edge of the clip in millipoints + * @param clipW the clip width in millipoints + * @param clipH the clip height in millipoints + * @param fill the image to be rendered + * @param fs the font state to use when rendering text + * in non-bitmapped images. + */ + protected abstract void drawImageClipped(int x, int y, + int clipX, int clipY, + int clipW, int clipH, + FopImage image, + FontState fs); + + /** + * Render an image area. + * + * @param area the image area to render + */ + public void renderImageArea(ImageArea area) { + // adapted from contribution by BoBoGi + int x = this.currentXPosition + area.getXOffset(); + int y = this.currentYPosition; + int w = area.getContentWidth(); + int h = area.getHeight(); + + this.currentYPosition -= h; + + FopImage img = area.getImage(); + + if (img == null) { + log.error("Error while loading image : area.getImage() is null"); + } + else { + drawImageScaled(x, y, w, h, img, area.getFontState()); + } + + this.currentXPosition += w; + } + public void renderBodyAreaContainer(BodyAreaContainer area) { int saveY = this.currentYPosition; int saveX = this.currentAreaContainerXPosition; @@ -91,18 +307,19 @@ } this.currentXPosition = this.currentAreaContainerXPosition; - int w, h; int rx = this.currentAreaContainerXPosition; - w = area.getContentWidth(); - h = area.getContentHeight(); int ry = this.currentYPosition; - ColorType bg = area.getBackgroundColor(); + // XXX: ([EMAIL PROTECTED]) I had to use getAllocationWidth() + // and getMaxHeight() as the content width and height are + // always 0. Is this supposed to be the case? + // IMHO, the bg should cover the entire area anyway, not + // just the parts with content, which makes this correct. + // Probably want to check this for the other region + // areas as well. + int w = area.getAllocationWidth(); + int h = area.getMaxHeight(); - // I'm not sure I should have to check for bg being null - // but I do - if ((bg != null) && (bg.alpha() == 0)) { - addFilledRect(rx, ry, w, -h, bg); - } + doBackground(area, rx, ry, w, h); // floats & footnotes stuff renderAreaContainer(area.getBeforeFloatReferenceArea()); 1.14.2.2 +2 -15 xml-fop/src/org/apache/fop/render/PrintRenderer.java Index: PrintRenderer.java =================================================================== RCS file: /x1/home/cvs/xml-fop/src/org/apache/fop/render/PrintRenderer.java,v retrieving revision 1.14.2.1 retrieving revision 1.14.2.2 diff -u -r1.14.2.1 -r1.14.2.2 --- PrintRenderer.java 9 Jan 2002 11:32:57 -0000 1.14.2.1 +++ PrintRenderer.java 23 Apr 2002 22:26:58 -0000 1.14.2.2 @@ -1,5 +1,5 @@ /* - * $Id: PrintRenderer.java,v 1.14.2.1 2002/01/09 11:32:57 keiron Exp $ + * $Id: PrintRenderer.java,v 1.14.2.2 2002/04/23 22:26:58 arved Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources." @@ -13,7 +13,6 @@ // FOP import org.apache.fop.pdf.PDFPathPaint; import org.apache.fop.pdf.PDFColor; -import org.apache.fop.image.ImageArea; import org.apache.fop.apps.FOPException; import org.apache.fop.fo.properties.*; import org.apache.fop.layout.*; @@ -191,18 +190,13 @@ rx += ((BlockArea)area).getStartIndent(); h = area.getContentHeight(); int ry = this.currentYPosition; - ColorType bg = area.getBackgroundColor(); rx = rx - area.getPaddingLeft(); ry = ry + area.getPaddingTop(); w = w + area.getPaddingLeft() + area.getPaddingRight(); h = h + area.getPaddingTop() + area.getPaddingBottom(); - // I'm not sure I should have to check for bg being null - // but I do - if ((bg != null) && (bg.alpha() == 0)) { - this.addFilledRect(rx, ry, w, -h, new PDFColor(bg)); - } + doBackground(area, rx, ry, w, h); // rx = rx - area.getBorderLeftWidth(); // ry = ry + area.getBorderTopWidth(); @@ -258,13 +252,6 @@ int d = space.getSize(); this.currentYPosition -= d; } - - /** - * render image area - * - * @param area the image area to render - */ - public abstract void renderImageArea(ImageArea area); /** * render a foreign object area
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]