diff -ru C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\apps\PrintStarter.java fop-0.20.5\src\org\apache\fop\apps\PrintStarter.java --- C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\apps\PrintStarter.java Tue Jul 15 04:03:14 2003 +++ fop-0.20.5\src\org\apache\fop\apps\PrintStarter.java Thu Sep 09 00:29:10 2004 @@ -194,8 +194,8 @@ } public void renderPage(Page page) { - pageWidth = (int)((float)page.getWidth() / 1000f); - pageHeight = (int)((float)page.getHeight() / 1000f); + pageWidth = page.getWidth() / 1000f; + pageHeight = page.getHeight() / 1000f; super.renderPage(page); } diff -ru C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\awt\AWTRenderer.java fop-0.20.5\src\org\apache\fop\render\awt\AWTRenderer.java --- C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\awt\AWTRenderer.java Tue Jul 15 04:03:18 2003 +++ fop-0.20.5\src\org\apache\fop\render\awt\AWTRenderer.java Thu Sep 09 00:28:51 2004 @@ -94,8 +94,8 @@ */ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable { - protected int pageWidth = 0; - protected int pageHeight = 0; + protected float pageWidth = 0; + protected float pageHeight = 0; protected double scaleFactor = 100.0; protected int pageNumber = 0; protected Vector pageList = new Vector(); @@ -191,108 +191,6 @@ } /** - * add a line to the current stream - * - * @param x1 the start x location in millipoints - * @param y1 the start y location in millipoints - * @param x2 the end x location in millipoints - * @param y2 the end y location in millipoints - * @param th the thickness in millipoints - * @param r the red component - * @param g the green component - * @param b the blue component - */ - - // corrected 7/13/01 aml,rlc to properly handle thickness - // - protected void addLine(int x1, int y1, int x2, int y2, int th, float r, - float g, float b) { - graphics.setColor(new Color(r, g, b)); - int x = x1; - int y = y1; - int height, width; - if (x1 == x2) // vertical line - { - height = y2 - y1; - if (height > 0) // y coordinates are reversed between fo and AWT - { - height = -height; - y = y2; - } - width = th; - if (width < 0) { - width = -width; - x -= width; - } - } else // horizontal line - { - width = x2 - x1; - if (width < 0) { - width = -width; - x = x2; - } - height = th; - if (height > 0) // y coordinates are reversed between fo and AWT - { - height = -height; - y -= height; - } - } - addRect(x, y, width, height, false); - - // // graphics.setColor(Color.red); - // graphics.drawLine((int)(x1 / 1000f), - // pageHeight - (int)(y1 / 1000f), (int)(x2 / 1000f), - // pageHeight - (int)(y2 / 1000f)); - } - - - /** - * draw a rectangle - * - * @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 r the red component - * @param g the green component - * @param b the blue component - */ - // changed by aml/rlc to use helper function that - // corrects for integer roundoff, and to remove 3D effect - protected void addRect(int x, int y, int w, int h, float r, float g, - float b) { - graphics.setColor(new Color(r, g, b)); - // graphics.setColor(Color.green); - addRect(x, y, w, h, true); - } - - /** - * draw a filled rectangle - * - * @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 r the red component of edges - * @param g the green component of edges - * @param b the blue component of edges - * @param fr the red component of the fill - * @param fg the green component of the fill - * @param fb the blue component of the fill - */ - - // changed by aml/rlc to use helper function that - // corrects for integer roundoff - protected void addRect(int x, int y, int w, int h, float r, float g, - float b, float fr, float fg, float fb) { - graphics.setColor(new Color(r, g, b)); - addRect(x, y, w, h, true); - graphics.setColor(new Color(fr, fg, fb)); - addRect(x, y, w, h, false); - } - - /** * draw a filled rectangle in the current color * * @param x the x position of left edge in millipoints @@ -305,19 +203,20 @@ // helper function by aml/rlc to correct integer roundoff problems // protected void addRect(int x, int y, int w, int h, - boolean drawAsOutline) { - int startx = (x + 500) / 1000; - int starty = pageHeight - ((y + 500) / 1000); - int endx = (x + w + 500) / 1000; - int endy = pageHeight - ((y + h + 500) / 1000); - if (drawAsOutline) { - graphics.drawRect(startx, starty, endx - startx, endy - starty); - } else { - //don't round down to zero - if (w != 0 && endx == startx) endx++; - if (h != 0 && endy == starty) endy++; - graphics.fillRect(startx, starty, endx - startx, endy - starty); + float r, float g, float b) { + graphics.setColor(new Color(r, g, b)); + + if ( h < 0 ) { + y += h; + h = -h; } + + Shape rect = new Rectangle2D.Double(x / 1000d, + pageHeight - ( y + h ) / 1000d, + w / 1000d, + h / 1000d ); + + graphics.fill(rect); } protected void addFilledRect(int x, int y, int w, int h, @@ -325,7 +224,7 @@ float r = col.red(); float g = col.green(); float b = col.blue(); - addRect(x, y, w, h, r, g, b, r, g, b); + addRect(x, y, w, h, r, g, b); } /** @@ -344,8 +243,8 @@ protected void drawFrame() { - int width = pageWidth; - int height = pageHeight; + int width = (int)pageWidth; + int height = (int)pageHeight; graphics.setColor(Color.white); graphics.fillRect(0, 0, width, height); @@ -394,8 +293,8 @@ throws IOException { idReferences = page.getIDReferences(); - pageWidth = (int)((float)page.getWidth() / 1000f + .5); - pageHeight = (int)((float)page.getHeight() / 1000f + .5); + pageWidth = page.getWidth() / 1000f; + pageHeight = page.getHeight() / 1000; pageImage = @@ -447,50 +346,29 @@ w = w + area.getPaddingLeft() + area.getPaddingRight(); h = h + area.getPaddingTop() + area.getPaddingBottom(); - doBackground(area, rx, ry, w, h); + doBackground(area, rx, ry, w, h); - rx = rx - area.getBorderLeftWidth(); - ry = ry + area.getBorderTopWidth(); - w = w + area.getBorderLeftWidth() + area.getBorderRightWidth(); - h = h + area.getBorderTopWidth() + area.getBorderBottomWidth(); + int left = area.getBorderLeftWidth(); + int right = area.getBorderRightWidth(); + int top = area.getBorderTopWidth(); + int bottom = area.getBorderBottomWidth(); BorderAndPadding bp = area.getBorderAndPadding(); - ColorType borderColor; - if (area.getBorderTopWidth() != 0) { - borderColor = bp.getBorderColor(BorderAndPadding.TOP); - // addLine(rx, ry, rx + w, ry, area.getBorderTopWidth(), // corrected aml/rlc - addLine(rx, ry, rx + w, ry, -area.getBorderTopWidth(), - borderColor.red(), borderColor.green(), - borderColor.blue()); - } - - if (area.getBorderLeftWidth() != 0) { - borderColor = bp.getBorderColor(BorderAndPadding.LEFT); - addLine(rx, ry, rx, ry - h, area.getBorderLeftWidth(), - borderColor.red(), borderColor.green(), - borderColor.blue()); - } - - if (area.getBorderRightWidth() != 0) { - borderColor = bp.getBorderColor(BorderAndPadding.RIGHT); - addLine(rx + w, ry, rx + w, ry - h, - // area.getBorderRightWidth(), borderColor.red(), // corrected aml/rlc - -area.getBorderRightWidth(), borderColor.red(), - borderColor.green(), - borderColor.blue()); - } - - if (area.getBorderBottomWidth() != 0) { - borderColor = bp.getBorderColor(BorderAndPadding.BOTTOM); - addLine(rx, ry - h, rx + w, ry - h, area.getBorderBottomWidth(), - borderColor.red(), borderColor.green(), - borderColor.blue()); - } + if (top != 0) + addFilledRect(rx, ry, w, top, + bp.getBorderColor(BorderAndPadding.TOP)); + if (left != 0) + addFilledRect(rx - left, ry - h - bottom, left, h + top + bottom, + bp.getBorderColor(BorderAndPadding.LEFT)); + if (right != 0) + addFilledRect(rx + w, ry - h - bottom, right, h + top + bottom, + bp.getBorderColor(BorderAndPadding.RIGHT)); + if (bottom != 0) + addFilledRect(rx, ry - h - bottom, w, bottom, + bp.getBorderColor(BorderAndPadding.BOTTOM)); } - - protected Rectangle2D getBounds(org.apache.fop.layout.Area a) { return new Rectangle2D.Double(currentAreaContainerXPosition, currentYPosition, @@ -552,6 +430,9 @@ // correct integer roundoff (aml/rlc) + private final static ColorType ABSENT_IMAGE_COLOR = + new ColorType(0.3f, 0.3f, 0.3f); + public void renderImageArea(ImageArea area) { int x = currentXPosition + area.getXOffset(); @@ -568,7 +449,7 @@ // correct integer roundoff // graphics.drawRect(x / 1000, pageHeight - y / 1000, // w / 1000, h / 1000); - addRect(x, y, w, h, true); // use helper function + addFilledRect(x, y, w, h, ABSENT_IMAGE_COLOR); // use helper function java.awt.Font f = graphics.getFont(); @@ -581,8 +462,8 @@ // graphics.drawString("area.getImage() is null", x / 1000, // pageHeight - y / 1000); - graphics.drawString("area.getImage() is null", (x + 500) / 1000, - pageHeight - (y + 500) / 1000); + graphics.drawString("area.getImage() is null", x / 1000f, + pageHeight - y / 1000f); graphics.setFont(f); @@ -602,19 +483,16 @@ ImageIcon icon = new ImageIcon(url); Image image = icon.getImage(); - // correct integer roundoff aml/rlc - // graphics.drawImage(image, x / 1000, - // pageHeight - y / 1000, w / 1000, h / 1000, - // null); - - int startx = (x + 500) / 1000; - int starty = pageHeight - ((y + 500) / 1000); - int endx = (x + w + 500) / 1000; - int endy = pageHeight - ((y + h + 500) / 1000); + int imageWidth = image.getWidth(null); + int imageHeight = image.getHeight(null); + + AffineTransform imageTr = graphics.getTransform(); + imageTr.translate(x, pageHeight - y); + imageTr.scale((double)w / imageWidth, + (double)h / imageHeight); // reverse start and end y because h is positive - graphics.drawImage(image, startx, starty, endx - startx, - starty - endy, null); + graphics.drawImage(image, imageTr, null); } catch (MalformedURLException mue) { // cannot normally occur because, if URL is wrong, constructing FopImage @@ -689,8 +567,8 @@ graphics.setFont(f); // correct starting location for integer roundoff - int newx = (int)(rx + 500) / 1000; - int newy = (int)(pageHeight - (bl + 500) / 1000); + float newx = rx / 1000f; + float newy = pageHeight - bl / 1000f; // draw text, corrected for integer roundoff graphics.drawString(s, newx, newy); @@ -730,7 +608,7 @@ graphics.setColor(this.lastColor); } - int width = (int)(space.getSize() + 500) / 1000; + double width = space.getSize() / 1000d; renderTextDecoration(rx, bl, width, graphics.getFont(), " ", space.getUnderlined(), space.getOverlined(), @@ -744,39 +622,40 @@ } - protected void renderTextDecoration(int x, int bl, int width, + protected void renderTextDecoration(int x, int bl, double width, java.awt.Font font, String text, boolean underline, boolean overline, boolean linethrough) { if (!(underline || overline || linethrough)) return; - int newx = (int)(x + 500) / 1000; - int newy = (int)(pageHeight - (bl + 500) / 1000); + double newx = x / 1000d; + double newy = pageHeight - bl / 1000d; // text decorations FontMetrics fm = graphics.getFontMetrics(font); LineMetrics lm = fm.getLineMetrics(text, graphics); - int ulthick = (int)lm.getUnderlineThickness(); - if (ulthick < 1) - ulthick = 1; // don't allow it to disappear + double ulthick = lm.getUnderlineThickness(); if (underline) { // nothing in awt specifies underline location, // descent/2 seems to match my word processor int deltay = fm.getDescent() / 2; - graphics.fillRect(newx, newy + deltay, width, ulthick); + graphics.fill(new Rectangle2D.Double( + newx, newy + deltay, width, ulthick)); } if (overline) { // todo: maybe improve positioning of overline int deltay = -(int)(lm.getAscent() * 0.8); - graphics.fillRect(newx, newy + deltay, width, ulthick); + graphics.fill(new Rectangle2D.Double( + newx, newy + deltay, width, ulthick)); } if (linethrough) { int ltthick = (int)lm.getStrikethroughThickness(); if (ltthick < 1) ltthick = 1; // don't allow it to disappear int deltay = (int)lm.getStrikethroughOffset(); - graphics.fillRect(newx, newy + deltay, width, ltthick); + graphics.fill(new Rectangle2D.Double( + newx, newy + deltay, width, ltthick)); } } @@ -795,21 +674,19 @@ int ry = this.currentYPosition; int w = area.getLeaderLength(); int h = area.getHeight(); - int th = area.getRuleThickness(); int st = area.getRuleStyle(); // not used at the moment float r = area.getRed(); float g = area.getGreen(); float b = area.getBlue(); Color oldColor = graphics.getColor(); - graphics.setColor(new Color(r, g, b)); - // use helper function to correct integer roundoff - aml/rlc // graphics.fillRect((int)(rx / 1000f), // (int)(pageHeight - ry / 1000f), (int)(w / 1000f), // (int)(th / 1000f)); - addRect(rx, ry, w, -th, false); // NB addRect expects negative height + // NB addRect expects negative height + addRect(rx, ry, w, h, r, g, b); graphics.setColor(oldColor); this.currentXPosition += area.getContentWidth(); @@ -844,33 +721,18 @@ float w = (float)ctx.getDocumentSize().getWidth() * 1000f; float h = (float)ctx.getDocumentSize().getHeight() * 1000f; - // correct integer roundoff aml/rlc - // graphics.translate(x / 1000f, pageHeight - y / 1000f); - graphics.translate((x + 500) / 1000, pageHeight - (y + 500) / 1000); + Graphics2D newGraphics = (Graphics2D)graphics.create(); + newGraphics.translate(x / 1000d, pageHeight - y / 1000d); SVGSVGElement svg = ((SVGDocument)doc).getRootElement(); AffineTransform at = ViewBox.getPreserveAspectRatioTransform(svg, w / 1000f, h / 1000f); - AffineTransform inverse = null; - try { - inverse = at.createInverse(); - } catch(NoninvertibleTransformException e) { - } - if(!at.isIdentity()) { - graphics.transform(at); - } + newGraphics.transform(at); try { - root.paint(graphics); + root.paint(newGraphics); } catch (Exception e) { e.printStackTrace(); } - - if(inverse != null && !inverse.isIdentity()) { - graphics.transform(inverse); - } - // correct integer roundoff aml/rlc - // graphics.translate(-x / 1000f, y / 1000f - pageHeight); - graphics.translate(-(x + 500) / 1000, (y + 500) / 1000 - pageHeight); } diff -ru C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\pcl\PCLRenderer.java fop-0.20.5\src\org\apache\fop\render\pcl\PCLRenderer.java --- C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\pcl\PCLRenderer.java Tue Jul 15 04:03:14 2003 +++ fop-0.20.5\src\org\apache\fop\render\pcl\PCLRenderer.java Wed Sep 08 14:11:11 2004 @@ -132,9 +132,9 @@ protected void addLine(int x1, int y1, int x2, int y2, int th, PDFPathPaint stroke) { if (x1 == x2) - addRect(x1 - (th / 2), y1, th, y2 - y1 + 1, stroke, stroke); + addFilledRect(x1 - (th / 2), y1, th, y2 - y1 + 1, stroke); else if (y1 == y2) - addRect(x1, y1 + (th / 2), x2 - x1 + 1, th, stroke, stroke); + addFilledRect(x1, y1 + (th / 2), x2 - x1 + 1, th, stroke); } /** @@ -174,11 +174,11 @@ while (start < y2) { if (start + len > y2) len = y2 - start; - addRect(x1 - (th / 2), start, th, len, stroke, stroke); + addFilledRect(x1 - (th / 2), start, th, len, stroke); start += (len + dashoff * th); } } else - addRect(x1 - (th / 2), y1, th, y2 - y1 + 1, stroke, stroke); + addFilledRect(x1 - (th / 2), y1, th, y2 - y1 + 1, stroke); } else if (y1 == y2) { if (dashon > 0 && dashoff > 0) { int start = x1; @@ -186,40 +186,11 @@ while (start < x2) { if (start + len > x2) len = x2 - start; - addRect(start, y1 + (th / 2), len, th, stroke, stroke); + addFilledRect(start, y1 + (th / 2), len, th, stroke); start += (len + dashoff * th); } } else - addRect(x1, y1 + (th / 2), x2 - x1 + 1, th, stroke, stroke); - } - } - - /** - * add a rectangle to the current stream - * - * @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 stroke the stroke color/gradient - */ - protected void addRect(int x, int y, int w, int h, PDFPathPaint stroke) { - //if (h < 0) - // h *= -1; - - if ((h >= 0 && h < 720) || (h < 0 && h > -720) || w < 720) { - if (w < 720) - w = 720; - if (h > 0 && h < 720) - h = 720; - else if (h < 0 && h > -720) - h = -720; - addRect(x, y, w, h, stroke, stroke); - } else { - addRect(x, y, w, 720, stroke, stroke); - addRect(x, y, 720, h, stroke, stroke); - addRect(x + w - 720, y, 720, h, stroke, stroke); - addRect(x, y - h + 720, w, 720, stroke, stroke); + addFilledRect(x1, y1 + (th / 2), x2 - x1 + 1, th, stroke); } } @@ -233,7 +204,7 @@ * @param fill the fill color/gradient * @param stroke the stroke color/gradient */ - protected void addRect(int x, int y, int w, int h, PDFPathPaint stroke, + protected void addFilledRect(int x, int y, int w, int h, PDFPathPaint fill) { if ((w == 0) || (h == 0)) return; @@ -243,16 +214,10 @@ y += h; - PDFColor sc = (PDFColor)stroke; PDFColor fc = (PDFColor)fill; - sc.setColorSpace(ColorSpace.DEVICE_RGB); fc.setColorSpace(ColorSpace.DEVICE_RGB); - int lineshade = - (int)(100 - - ((0.3f * sc.red() + 0.59f * sc.green() + 0.11f * sc.blue()) - * 100f)); int fillshade = (int)(100 - ((0.3f * fc.red() + 0.59f * fc.green() + 0.11f * fc.blue()) @@ -267,19 +232,7 @@ currentStream.add("\033*v1O\033&a" + xpos + "h" + (pageHeight - (y / 100)) + "V" + "\033*c" + (w / 100) + "h" + (h / 100) + "V" + "\033*c" - + lineshade + "G" + "\033*c2P"); - if (fillshade != lineshade && (w >= 720 || h >= 720)) { - xpos = xoffset + ((x + 240) / 100); - if (xpos < 0) { - xpos = 0; - log.warn("Horizontal position out of bounds."); - } - currentStream.add("\033&a" + xpos + "h" - + (pageHeight - ((y + 240)) / 100) + "V" - + "\033*c" + ((w - 480) / 100) + "h" - + ((h - 480) / 100) + "V" + "\033*c" - + fillshade + "G" + "\033*c2P"); - } + + fillshade + "G" + "\033*c2P"); // Reset pattern transparency mode. currentStream.add("\033*v0O"); } diff -ru C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\pdf\PDFRenderer.java fop-0.20.5\src\org\apache\fop\render\pdf\PDFRenderer.java --- C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\pdf\PDFRenderer.java Tue Jul 15 04:03:26 2003 +++ fop-0.20.5\src\org\apache\fop\render\pdf\PDFRenderer.java Wed Sep 08 14:11:11 2004 @@ -302,42 +302,6 @@ } /** - * add a rectangle to the current stream - * - * @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 stroke the stroke color/gradient - */ - protected void addRect(int x, int y, int w, int h, PDFPathPaint stroke) { - closeText(); - currentStream.add("ET\nq\n" + stroke.getColorSpaceOut(false) - + (x / 1000f) + " " + (y / 1000f) + " " - + (w / 1000f) + " " + (h / 1000f) + " re s\n" - + "Q\nBT\n"); - } - - /** - * add a filled rectangle to the current stream - * - * @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 fill the fill color/gradient - * @param stroke the stroke color/gradient - */ - protected void addRect(int x, int y, int w, int h, PDFPathPaint stroke, - PDFPathPaint fill) { - closeText(); - currentStream.add("ET\nq\n" + fill.getColorSpaceOut(true) - + stroke.getColorSpaceOut(false) + (x / 1000f) - + " " + (y / 1000f) + " " + (w / 1000f) + " " - + (h / 1000f) + " re b\n" + "Q\nBT\n"); - } - - /** * add a filled rectangle to the current stream * * @param x the x position of left edge in millipoints diff -ru C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\PrintRenderer.java fop-0.20.5\src\org\apache\fop\render\PrintRenderer.java --- C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\PrintRenderer.java Tue Jul 15 04:03:14 2003 +++ fop-0.20.5\src\org\apache\fop\render\PrintRenderer.java Wed Sep 08 14:11:11 2004 @@ -173,19 +173,7 @@ int rs, PDFPathPaint stroke); /** - * add a rectangle to the current stream - * - * @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 stroke the stroke color/gradient - */ - protected abstract void addRect(int x, int y, int w, int h, - PDFPathPaint stroke); - - /** - * add a filled and stroked rectangle to the current stream + * Add a filled rectangle to the current stream. * * @param x the x position of left edge in millipoints * @param y the y position of top edge in millipoints @@ -194,29 +182,13 @@ * @param fill the fill color/gradient * @param stroke the stroke color/gradient */ - protected abstract void addRect(int x, int y, int w, int h, - PDFPathPaint stroke, PDFPathPaint fill); - - /** - * Add a filled rectangle to the current stream - * This default implementation calls addRect - * using the same color for fill and border. - * - * @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 fill the fill color/gradient - */ - protected void addFilledRect(int x, int y, int w, int h, - PDFPathPaint fill) { - addRect(x, y, w, h, fill, fill); - } + protected abstract void addFilledRect(int x, int y, int w, int h, + PDFPathPaint fill); protected void addFilledRect(int x, int y, int w, int h, ColorType col) { PDFColor pdfcol = new PDFColor(col); - addRect(x, y, w, h, pdfcol, pdfcol); + addFilledRect(x, y, w, h, pdfcol); } protected void doFrame(Area area) { diff -ru C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\svg\SVGRenderer.java fop-0.20.5\src\org\apache\fop\render\svg\SVGRenderer.java --- C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\svg\SVGRenderer.java Tue Jul 15 04:03:20 2003 +++ fop-0.20.5\src\org\apache\fop\render\svg\SVGRenderer.java Wed Sep 08 14:11:11 2004 @@ -159,66 +159,41 @@ } /** - * draw a rectangle - * - * @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 r the red component - * @param g the green component - * @param b the blue component - */ - protected void addRect(int x, int y, int w, int h, float r, float g, - float b) { - Element rect = SVGUtilities.createRect(svgDocument, x / 1000f, pageHeight - (y / 1000f), w / 1000f, h / 1000f); - rect.setAttributeNS(null, "style", "stroke:rgb(" + ((int)(255 * r)) + "," + ((int)(255 * g)) + "," + ((int)(255 * b)) + ")"); - currentPageG.appendChild(rect); - } - - /** - * draw a filled rectangle - * - * @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 r the red component of edges - * @param g the green component of edges - * @param b the blue component of edges - * @param fr the red component of the fill - * @param fg the green component of the fill - * @param fb the blue component of the fill - */ - protected void addRect(int x, int y, int w, int h, float r, float g, - float b, float fr, float fg, float fb) { - Element rect = SVGUtilities.createRect(svgDocument, x / 1000f, pageHeight - (y / 1000f), w / 1000f, h / 1000f); - rect.setAttributeNS(null, "style", "stroke:rgb(" + ((int)(255 * r)) + "," + ((int)(255 * g)) + "," + ((int)(255 * b)) + ");fill:rgb(" + ((int)(255 * fr)) + "," + ((int)(255 * fg)) + "," + ((int)(255 * fb)) + ")"); - currentPageG.appendChild(rect); - } - - /** * draw a filled rectangle in the current color * * @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 r the red component of edges/fill + * @param g the green component of edges/fill + * @param b the blue component of edges/fill * @param drawAsOutline true for draw, false for fill */ protected void addRect(int x, int y, int w, int h, + float r, float g, float b, boolean drawAsOutline) { - int startx = (x + 500) / 1000; - int starty = pageHeight - ((y + 500) / 1000); - int endx = (x + w + 500) / 1000; - int endy = pageHeight - ((y + h + 500) / 1000); + float startx = x / 1000f; + float starty = pageHeight - (y / 1000f); + float endx = (x + w) / 1000f; + float endy = pageHeight - ((y + h) / 1000f); if (drawAsOutline) { Element rect = SVGUtilities.createRect(svgDocument, startx, starty, endx - startx, endy - starty); - rect.setAttributeNS(null, "style", "fill:none"); + rect.setAttributeNS(null, "style", + "stroke:rgb(" + + ((int)(255 * r)) + "," + + ((int)(255 * g)) + "," + + ((int)(255 * b)) + ");" + + "fill:none"); currentPageG.appendChild(rect); } else { Element rect = SVGUtilities.createRect(svgDocument, startx, starty, endx - startx, starty - endy); - rect.setAttributeNS(null, "style", "stroke:none"); + rect.setAttributeNS(null, "style", + "fill:rgb(" + + ((int)(255 * r)) + "," + + ((int)(255 * g)) + "," + + ((int)(255 * b)) + ");" + + "stroke:none "); currentPageG.appendChild(rect); } } @@ -228,7 +203,7 @@ float r = col.red(); float g = col.green(); float b = col.blue(); - addRect(x, y, w, h, r, g, b, r, g, b); + addRect(x, y, w, -h, r, g, b, false); } protected void drawFrame() { @@ -327,31 +302,37 @@ doBackground(area, rx, ry, w, h); - rx = rx - area.getBorderLeftWidth(); - ry = ry + area.getBorderTopWidth(); - w = w + area.getBorderLeftWidth() + area.getBorderRightWidth(); - h = h + area.getBorderTopWidth() + area.getBorderBottomWidth(); + int outerLeft = rx - area.getBorderLeftWidth(); + int middleLeft = rx - area.getBorderLeftWidth() / 2; + int outerTop = ry + area.getBorderTopWidth(); + int middleTop = ry + area.getBorderTopWidth() / 2; + int outerRight = rx + w + area.getBorderRightWidth(); + int middleRight = rx + w + area.getBorderRightWidth() / 2; + int outerBottom = ry - h - area.getBorderBottomWidth(); + int middleBottom = ry - h - area.getBorderBottomWidth() / 2; BorderAndPadding bp = area.getBorderAndPadding(); ColorType borderColor; if (area.getBorderTopWidth() != 0) { borderColor = bp.getBorderColor(BorderAndPadding.TOP); - addLine(rx, ry, rx + w, ry, area.getBorderTopWidth(), + addLine(outerLeft, middleTop, outerRight, middleTop, + area.getBorderTopWidth(), borderColor.red(), borderColor.green(), borderColor.blue()); } if (area.getBorderLeftWidth() != 0) { borderColor = bp.getBorderColor(BorderAndPadding.LEFT); - addLine(rx, ry, rx, ry - h, area.getBorderLeftWidth(), + addLine(middleLeft, outerTop, middleLeft, outerBottom, + area.getBorderLeftWidth(), borderColor.red(), borderColor.green(), borderColor.blue()); } if (area.getBorderRightWidth() != 0) { borderColor = bp.getBorderColor(BorderAndPadding.RIGHT); - addLine(rx + w, ry, rx + w, ry - h, + addLine(middleRight, outerTop, middleRight, outerBottom, area.getBorderRightWidth(), borderColor.red(), borderColor.green(), borderColor.blue()); @@ -359,7 +340,8 @@ if (area.getBorderBottomWidth() != 0) { borderColor = bp.getBorderColor(BorderAndPadding.BOTTOM); - addLine(rx, ry - h, rx + w, ry - h, area.getBorderBottomWidth(), + addLine(outerLeft, middleBottom, outerRight, middleBottom, + area.getBorderBottomWidth(), borderColor.red(), borderColor.green(), borderColor.blue()); } @@ -436,7 +418,7 @@ if (img == null) { log.error("Error while loading image : area.getImage() is null"); - addRect(x, y, w, h, true); // use helper function + addRect(x, y, w, h, 0, 0, 0, true); // use helper function } else { if (img instanceof SVGImage) { @@ -454,10 +436,10 @@ ImageIcon icon = new ImageIcon(url); Image image = icon.getImage(); - int startx = (x + 500) / 1000; - int starty = pageHeight - ((y + 500) / 1000); - int endx = (x + w + 500) / 1000; - int endy = pageHeight - ((y + h + 500) / 1000); + float startx = x / 1000f; + float starty = pageHeight - y / 1000f; + float endx = (x + w) / 1000f; + float endy = pageHeight - (y + h) / 1000f; // reverse start and end y because h is positive //graphics.drawImage(image, startx, starty, endx - startx, @@ -580,9 +562,7 @@ float g = area.getGreen(); float b = area.getBlue(); - //graphics.setColor(new Color(r, g, b)); - - addRect(rx, ry, w, th, false); + addRect(rx, ry, w, th, r, g, b, false); this.currentXPosition += area.getContentWidth(); } diff -ru C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\txt\TXTRenderer.java fop-0.20.5\src\org\apache\fop\render\txt\TXTRenderer.java --- C:\atagunov\play\fop\spaces\orig\fop-0.20.5\src\org\apache\fop\render\txt\TXTRenderer.java Tue Jul 15 04:03:28 2003 +++ fop-0.20.5\src\org\apache\fop\render\txt\TXTRenderer.java Wed Sep 08 14:11:11 2004 @@ -197,9 +197,9 @@ protected void addLine(int x1, int y1, int x2, int y2, int th, PDFPathPaint stroke) { if (x1 == x2) { - addRect(x1, y1, th, y2 - y1 + 1, stroke, stroke); + addFilledRect(x1, y1, th, y2 - y1 + 1, stroke); } else if (y1 == y2) { - addRect(x1, y1, x2 - x1 + 1, th, stroke, stroke); + addFilledRect(x1, y1, x2 - x1 + 1, th, stroke); } } @@ -222,261 +222,21 @@ else lstroke = (PDFColor)stroke; if (x1 == x2) { - addRect(x1, y1, th, y2 - y1 + 1, lstroke, lstroke); + addFilledRect(x1, y1, th, y2 - y1 + 1, lstroke); } else if (y1 == y2) { - addRect(x1, y1, x2 - x1 + 1, th, lstroke, lstroke); + addFilledRect(x1, y1, x2 - x1 + 1, th, lstroke); } } - protected void addLine(float x1, float y1, float x2, float y2, - PDFColor sc, float sw) { - /* - * SVG - Not yet implemented - * if ( debug ) - * System.out.println("TXTRenderer.addLine(" + x1 + ", " + y1 + ", " + x2 + ", " + y2 + ", " + sc + ", " + sw + ")"); - * if ( x1 == x2 ) - * { - * addRect(x1 - sw/2, y1, sw, y2 - y1 + 1, 0, 0, sc, null, 0); - * } - * else if ( y1 == y2 || (Math.abs(y1 - y2) <= 0.24) ) // 72/300=0.24 - * { - * addRect(x1, y1 - sw/2, x2 - x1 + 1, sw, 0, 0, sc, null, 0); - * } - * else if ( sc != null ) - * { - * // Convert dimensions to characters. - * //float cfact = 300f / 72f; // 300 dpi, 1pt=1/72in - * int ix1 = (int)(x1 * xFactor); - * int iy1 = (int)(y1 * yFactor); - * int ix2 = (int)(x2 * xFactor); - * int iy2 = (int)(y2 * yFactor); - * int isw = (int)(sw * xFactor); - * int origix; - * // Normalize - * if ( iy1 > iy2 ) - * { - * int tmp = ix1; - * ix1 = ix2; - * ix2 = tmp; - * tmp = iy1; - * iy1 = iy2; - * iy2 = tmp; - * } - * if ( ix1 > ix2 ) - * { - * origix = ix2; - * ix1 -=ix2; - * ix2 = 0; - * } - * else - * { - * origix = ix1; - * ix2 -= ix1; - * ix1 = 0; - * } - * // Convert line width to a pixel run length. - * //System.out.println("TXTRenderer.addLine(" + ix1 + ", " + iy1 + ", " + ix2 + ", " + iy2 + ", " + isw + ")"); - * int runlen = (int)Math.sqrt(Math.pow(isw, 2) * (1 + Math.pow((ix1 - ix2) / (iy1 - iy2), 2))); - * if ( runlen < 1 ) - * runlen = 1; - * StringBuffer rlbuff = new StringBuffer(); - * for ( int countr = 0 ; countr < runlen ; countr++ ) - * rlbuff.append('*'); - * String rlstr = rlbuff.toString(); - * //System.out.println("TXTRenderer.addLine: runlen = " + runlen); - * // Draw the line. - * int d, dx, dy; - * int Aincr, Bincr; - * int xincr = 1; - * int x, y; - * dx = Math.abs(ix2 - ix1); - * dy = iy2 - iy1; - * if ( dx > dy ) - * { - * xincr = dx / dy; - * // Move to starting position. - * //currentStream.add("\033*p" + origix + "x" + iy1 + "Y"); - * x = ix1 - runlen / 2; - * iy2 += (isw / 2); - * // Start raster graphics - * //currentStream.add("\033*t300R\033*r" + dx + "s1A\033*b1M"); - * } - * else - * { - * // Move to starting position. - * //currentStream.add("\033*p" + (origix - runlen / 2) + "x" + iy1 + "Y"); - * x = ix1; - * // Start raster graphics - * //currentStream.add("\033*t300R\033*r1A\033*b1M"); - * } - * if ( ix1 > ix2 ) - * xincr *= -1; - * d = 2 * dx - dy; - * Aincr = 2 * (dx - dy); - * Bincr = 2 * dx; - * y = iy1; - * xferLineBytes(x, runlen, null, -1); - * - * for ( y = iy1 + 1 ; y <= iy2 ; y++ ) - * { - * if ( d >= 0 ) - * { - * x += xincr; - * d += Aincr; - * } - * else - * d += Bincr; - * xferLineBytes(x, runlen, null, -1); - * } - * // End raster graphics - * //currentStream.add("\033*rB"); - * // Return to regular print mode. - * //currentStream.add("\033*v0t0n0O"); - * } - */ - } - - private void xferLineBytes(int startpos, int bitcount, List save, - int start2) { - /* - * Not yet implemented - * //System.out.println("TXTRenderer.xferLineBytes(" + startpos + ", " + bitcount + ")"); - * int curbitpos = 0; - * if ( start2 > 0 && start2 <= (startpos + bitcount) ) - * { - * bitcount += (start2 - startpos); - * start2 = 0; - * } - * char bytes[] = new char[((start2>startpos?start2:startpos) + bitcount) / 4 + 2]; - * int dlen = 0; - * byte dbyte = 0; - * int bytepos = 0; - * do - * { - * int bits2set; - * if ( startpos < 0 ) - * { - * bits2set = bitcount + startpos; - * startpos = 0; - * } - * else - * bits2set = bitcount; - * byte bittype = 0; - * do - * { - * if ( bytepos > 0 ) - * { - * int inc = startpos - curbitpos; - * if ( (inc) >= (8 - bytepos) ) - * { - * curbitpos += (8 - bytepos); - * bytepos = 0; - * bytes[dlen++] = (char)0; - * bytes[dlen++] = (char)dbyte; - * dbyte = 0; - * } - * else - * { - * bytepos += inc; - * dbyte = (byte)(dbyte ^ (byte)(Math.pow(2, 8 - bytepos) - 1)); - * curbitpos += inc; - * } - * } - * // Set runs of whole bytes. - * int setbytes = (startpos - curbitpos) / 8; - * if ( setbytes > 0 ) - * { - * curbitpos += setbytes * 8; - * while ( setbytes > 0 ) - * { - * if ( setbytes > 256 ) - * { - * bytes[dlen++] = 0xFF; - * setbytes -= 256; - * } - * else - * { - * bytes[dlen++] = (char)((setbytes - 1) & 0xFF); - * setbytes = 0; - * } - * bytes[dlen++] = (char)bittype; - * } - * } - * // move to position in the first byte. - * if ( curbitpos < startpos ) - * { - * if ( bytepos == 0 ) - * dbyte = bittype; - * bytepos += startpos - curbitpos; - * dbyte = (byte)(dbyte ^ (byte)(Math.pow(2, 8 - bytepos) - 1)); - * curbitpos += bytepos; - * startpos += bits2set; - * } - * else - * { - * startpos += bits2set; - * } - * if ( bittype == 0 ) - * bittype = (byte)0xFF; - * else - * bittype = 7; - * } while ( bittype != 7 ); - * if ( start2 > 0 ) - * { - * startpos = start2; - * start2 = -1; - * } - * else - * startpos = -1; - * } while ( startpos >= 0 ); - * if ( bytepos > 0 ) - * { - * bytes[dlen++] = (char)0; - * bytes[dlen++] = (char)dbyte; - * } - * if ( save == null ) - * { - * //currentStream.add("\033*b" + dlen + "W"); - * //currentStream.add(new String(bytes, 0, dlen)); - * } - * else - * { - * String line = "\033*b" + dlen + "W" + new String(bytes, 0, dlen); - * //currentStream.add(line); - * save.add(line); - * } - */ - } - /** - * add a rectangle to the current stream - * - * @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 stroke the stroke color/gradient + * Add a filled rectangle to the current stream */ - protected void addRect(int x, int y, int w, int h, PDFPathPaint stroke) { - if (h < 0) - h *= -1; - - if (h < 720 || w < 720) { - if (w < 720) - w = 720; - if (h < 720) - h = 720; - addRect(x, y, w, h, stroke, stroke); - } else { - addRect(x, y, w, 720, stroke, stroke); - addRect(x, y, 720, h, stroke, stroke); - addRect(x + w - 720, y, 720, h, stroke, stroke); - addRect(x, y - h + 720, w, 720, stroke, stroke); - } + protected void addFilledRect(int x, int y, int w, int h, PDFPathPaint fill) { + addRect(x, y, w, h, fill, fill); } - + /** - * add a filled rectangle to the current stream + * Add a filled stroked rectangle to the current stream * * @param x the x position of left edge in millipoints * @param y the y position of top edge in millipoints @@ -588,194 +348,6 @@ } } } - - - /** - * add a filled rectangle to the current stream - * - * @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 r the red component of edges - * @param g the green component of edges - * @param b the blue component of edges - * @param fr the red component of the fill - * @param fg the green component of the fill - * @param fb the blue component of the fill - */ - protected void addRect(float x, float y, float w, float h, float rx, - float ry, PDFColor fc, PDFColor sc, float sw) { - /* - * SVG - Not yet implemented - * if ( debug ) - * System.out.println("TXTRenderer.addRect(" + x + ", " + y + ", " + w + ", " + h + ", " + rx + ", " + ry + ", " + fc + ", " + sc + ", " + sw + ")"); - * float sr = 1; - * float sg = 1; - * float sb = 1; - * float fr = 1; - * float fg = 1; - * float fb = 1; - * if ( sc != null && sw > 0 ) - * { - * sr = (float)sc.red(); - * sg = (float)sc.green(); - * sb = (float)sc.blue(); - * } - * if ( fc != null ) - * { - * fr = (float)fc.red(); - * fg = (float)fc.green(); - * fb = (float)fc.blue(); - * } - * addRect((int)(x * 1000), (int)(pageHeight * 100 - y * 1000), (int)(w * 1000), (int)(h * 1000), sr, sg, sb, fr, fg, fb); - * fc = null; - * sc = null; - * if ( rx == 0 || ry == 0 ) - * { - * if ( fc != null ) - * { - * int fillshade = (int)(100 - ((0.3f * fc.red() + 0.59f * fc.green() + 0.11f * fc.blue()) * 100f)); - * currentStream.add("\033*v0n1O\033&a" + (x * 10) + "h" + ((y * 10)) + "V" - * + "\033*c" + (w * 10) + "h" + (h * 10) + "v" + fillshade + "g2P\033*v0n0O"); - * } - * if ( sc != null && sw > 0 ) - * { - * String lend = "v" + String.valueOf((int)(100 - ((0.3f * sc.red() + 0.59f * sc.green() + 0.11f * sc.blue()) * 100f))) + "g2P"; - * currentStream.add("\033*v0n1O"); - * currentStream.add("\033&a" + ((x - sw/2) * 10) + "h" + (((y - sw/2)) * 10) + "V" - * + "\033*c" + ((w + sw) * 10) + "h" + ((sw) * 10) + lend); - * currentStream.add("\033&a" + ((x - sw/2) * 10) + "h" + (((y - sw/2)) * 10) + "V" - * + "\033*c" + ((sw) * 10) + "h" + ((h + sw) * 10) + lend); - * currentStream.add("\033&a" + ((x + w - sw/2) * 10) + "h" + (((y - sw/2)) * 10) + "V" - * + "\033*c" + ((sw) * 10) + "h" + ((h + sw) * 10) + lend); - * currentStream.add("\033&a" + ((x - sw/2) * 10) + "h" + (((y + h - sw/2)) * 10) + "V" - * + "\033*c" + ((w + sw) * 10) + "h" + ((sw) * 10) + lend); - * currentStream.add("\033*v0n0O"); - * } - * } - * else - * { - * // Convert dimensions to pixels. - * float cfact = 300f / 72f; // 300 dpi, 1pt=1/72in - * int ix = (int)(x * cfact); - * int iy = (int)(y * cfact); - * int iw = (int)(w * cfact); - * int ih = (int)(h * cfact); - * int irx = (int)(rx * cfact); - * int iry = (int)(ry * cfact); - * int isw = (int)(sw * cfact); - * int longwidth = 0; - * int pass = 0; - * PDFColor thecolor = null; - * do - * { - * if ( pass == 0 && fc != null ) - * { - * thecolor = fc; - * } - * else if ( pass == 1 && sc != null ) - * { - * int iswdiv2 = isw / 2; - * thecolor = sc; - * ix -= iswdiv2; - * iy -= iswdiv2; - * irx += iswdiv2; - * iry += iswdiv2; - * iw += isw; - * ih += isw; - * longwidth = (int)(isw * 1.414); - * } - * else - * thecolor = null; - * if ( thecolor != null ) - * { - * int tx = 0; - * int ty = iry; - * long a = irx; - * long b = iry; - * long Asquared = (long)Math.pow(a, 2); - * long TwoAsquared = 2 * Asquared; - * long Bsquared = (long)Math.pow(b, 2); - * long TwoBsquared = 2 * Bsquared; - * long d = Bsquared - Asquared * b + Asquared / 4; - * long dx = 0; - * long dy = TwoAsquared * b; - * int rectlen = iw - 2 * irx; - * List bottomlines = new java.util.ArrayList(); - * int x0 = tx; - * // Set Transparency modes and select shading. - * currentStream.add("\033*v0n1O\033*c" + (int)(100 - ((0.3f * thecolor.red() + 0.59f * thecolor.green() + 0.11f * thecolor.blue()) * 100f)) + "G\033*v2T"); - * // Move to starting position. - * currentStream.add("\033*p" + ix + "x" + iy + "Y"); - * // Start raster graphics - * currentStream.add("\033*t300R\033*r" + iw + "s1A\033*b1M"); - * while ( dx < dy ) - * { - * if ( d > 0 ) - * { - * if ( pass == 0 || ty > (iry - isw) ) - * xferLineBytes(irx - x0, rectlen + 2 * x0, bottomlines, -1); - * else - * xferLineBytes(irx - x0, longwidth, bottomlines, iw - irx + x0 - longwidth); - * x0 = tx + 1; - * ty--; - * dy -= TwoAsquared; - * d -= dy; - * } - * tx++; - * dx += TwoBsquared; - * d += Bsquared + dx; - * } - * d += (3 * (Asquared - Bsquared) / 2 - (dx + dy)) / 2; - * while ( ty > 0 ) - * { - * if ( pass == 0 || ty >= (iry - isw) ) - * xferLineBytes(irx - tx, rectlen + 2 * tx, bottomlines, -1); - * else - * xferLineBytes(irx - tx, isw, bottomlines, iw - irx + tx - isw); - * - * if ( d < 0 ) - * { - * tx++; - * dx += TwoBsquared; - * d += dx; - * } - * ty--; - * dy -= TwoAsquared; - * d += Asquared - dy; - * } - * // Draw the middle part of the rectangle - * int midlen = ih - 2 * iry; - * if ( midlen > 0 ) - * { - * if ( pass == 0 ) - * xferLineBytes(0, iw, null, -1); - * else - * xferLineBytes(0, isw, null, iw - isw); - * currentStream.add("\033*b3M"); - * for ( int countr = midlen - 1 ; countr > 0 ; countr-- ) - * currentStream.add("\033*b0W"); - * currentStream.add("\033*b1M"); - * } - * // Draw the bottom. - * for ( int countr = bottomlines.size() - 1 ; countr >= 0 ; countr-- ) - * currentStream.add((String)bottomlines.get(countr)); - * // End raster graphics - * currentStream.add("\033*rB"); - * // Return to regular print mode. - * currentStream.add("\033*v0t0n0O"); - * } - * pass++; - * } while ( pass < 2 ); - * } - */ - } - - // Add a polyline or polygon. Does not support fills yet!!! - protected void addPolyline(List points, int posx, int posy, - PDFColor fc, PDFColor sc, float sw, - boolean close) {} /** * Renders an image, scaling it to the given width and height.