You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ke...@apache.org on 2001/07/10 13:59:28 UTC

cvs commit: xml-fop/src/org/apache/fop/svg PDFDocumentGraphics2D.java PDFGraphics2D.java PDFTextPainter.java

keiron      01/07/10 04:59:27

  Modified:    src/org/apache/fop/svg PDFDocumentGraphics2D.java
                        PDFGraphics2D.java PDFTextPainter.java
  Log:
  should handle colour space a bit better
  writes fonts to resources in PDFDocument
  cleaned up a bit
  
  Revision  Changes    Path
  1.7       +8 -9      xml-fop/src/org/apache/fop/svg/PDFDocumentGraphics2D.java
  
  Index: PDFDocumentGraphics2D.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFDocumentGraphics2D.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PDFDocumentGraphics2D.java	2001/07/09 08:14:44	1.6
  +++ PDFDocumentGraphics2D.java	2001/07/10 11:59:23	1.7
  @@ -1,4 +1,4 @@
  -/* $Id: PDFDocumentGraphics2D.java,v 1.6 2001/07/09 08:14:44 keiron Exp $
  +/* $Id: PDFDocumentGraphics2D.java,v 1.7 2001/07/10 11:59:23 keiron 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.
  @@ -27,7 +27,7 @@
    * <tt>PDFGraphics2D</tt>.
    *
    * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
  - * @version $Id: PDFDocumentGraphics2D.java,v 1.6 2001/07/09 08:14:44 keiron Exp $
  + * @version $Id: PDFDocumentGraphics2D.java,v 1.7 2001/07/10 11:59:23 keiron Exp $
    * @see org.apache.fop.svg.PDFGraphics2D
    */
   public class PDFDocumentGraphics2D extends PDFGraphics2D {
  @@ -37,6 +37,8 @@
       int width;
       int height;
   
  +    FontInfo fontInfo = null;
  +
       /**
        * Create a new PDFDocumentGraphics2D.
        * This is used to create a new pdf document of the given height
  @@ -54,7 +56,7 @@
           super(textAsShapes);
   
           if(!textAsShapes) {
  -            FontInfo fontInfo = new FontInfo();
  +            fontInfo = new FontInfo();
               FontSetup.setup(fontInfo);
               try {
                   fontState = new FontState(fontInfo, "Helvetica", "normal", "normal", 12, 0);
  @@ -73,15 +75,9 @@
           currentFontSize = 0;
           currentYPosition = 0;
           currentXPosition = 0;
  -        //				fontState = fs;
   
           currentStream.write("1 0 0 -1 0 " + height + " cm\n");
   
  -        // end part
  -        /*
  -        FontSetup.addToResources(this.pdfDoc, fontInfo);
  -         */
  -
       }
   
       /**
  @@ -123,6 +119,9 @@
           PDFPage currentPage =
             this.pdfDoc.makePage(pdfResources, pdfStream, width,
                                  height, null);
  +        if(fontInfo != null) {
  +            FontSetup.addToResources(this.pdfDoc, fontInfo);
  +        }
           this.pdfDoc.output(stream);
   
       }
  
  
  
  1.10      +149 -112  xml-fop/src/org/apache/fop/svg/PDFGraphics2D.java
  
  Index: PDFGraphics2D.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFGraphics2D.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PDFGraphics2D.java	2001/07/09 08:17:57	1.9
  +++ PDFGraphics2D.java	2001/07/10 11:59:24	1.10
  @@ -1,4 +1,4 @@
  -/* $Id: PDFGraphics2D.java,v 1.9 2001/07/09 08:17:57 keiron Exp $
  +/* $Id: PDFGraphics2D.java,v 1.10 2001/07/10 11:59:24 keiron 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."
  @@ -38,7 +38,7 @@
    * implementing a <tt>Graphic2D</tt> piece-meal.
    *
    * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
  - * @version $Id: PDFGraphics2D.java,v 1.9 2001/07/09 08:17:57 keiron Exp $
  + * @version $Id: PDFGraphics2D.java,v 1.10 2001/07/10 11:59:24 keiron Exp $
    * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D
    */
   public class PDFGraphics2D extends AbstractGraphics2D {
  @@ -163,8 +163,7 @@
   
           final byte[] result =
             new byte[buf.getWidth() * buf.getHeight() * 3];
  -        final byte[] mask =
  -          new byte[buf.getWidth() * buf.getHeight()];
  +        final byte[] mask = new byte[buf.getWidth() * buf.getHeight()];
   
           Raster raster = buf.getData();
           DataBuffer bd = raster.getDataBuffer();
  @@ -177,10 +176,10 @@
                   for (int i = 0; i < idata.length; i++) {
                       for (int j = 0; j < idata[i].length; j++) {
                           //mask[maskpos++] = (byte)((idata[i][j] >> 24) & 0xFF);
  -                        if(((idata[i][j] >> 24) & 0xFF) != 255) {
  -                            result[count++] = (byte)0xFF;
  -                            result[count++] = (byte)0xFF;
  -                            result[count++] = (byte)0xFF;
  +                        if (((idata[i][j] >> 24) & 0xFF) != 255) {
  +                            result[count++] = (byte) 0xFF;
  +                            result[count++] = (byte) 0xFF;
  +                            result[count++] = (byte) 0xFF;
                           } else {
                               result[count++] =
                                 (byte)((idata[i][j] >> 16) & 0xFF);
  @@ -199,17 +198,12 @@
           try {
               FopImage fopimg = new TempImage(width, height, result, mask);
               int xObjectNum = this.pdfDoc.addImage(fopimg);
  -            /*currentStream.write("q\n" + (((float) width)) +
  -                                     " 0 0 " + (((float) height)) + " " +
  -                                     x + " " +
  -                                     ((float)(y - height)) + " cm\n" + "/Im" +
  -                                     xObjectNum + " Do\nQ\n");*/
               AffineTransform at = getTransform();
               double[] matrix = new double[6];
               at.getMatrix(matrix);
               currentStream.write("q\n");
  -			Shape imclip = getClip();
  -			writeClip(imclip);
  +            Shape imclip = getClip();
  +            writeClip(imclip);
               currentStream.write("" + matrix[0] + " " + matrix[1] +
                                   " " + matrix[2] + " " + matrix[3] + " " +
                                   matrix[4] + " " + matrix[5] + " cm\n");
  @@ -237,8 +231,8 @@
           byte[] m_mask;
           PDFColor transparent = new PDFColor(255, 255, 255);
   
  -        TempImage(int width, int height,
  -                  byte[] result, byte[] mask) throws FopImageException {
  +        TempImage(int width, int height, byte[] result,
  +                  byte[] mask) throws FopImageException {
               this.m_height = height;
               this.m_width = width;
               this.m_bitsPerPixel = 8;
  @@ -279,7 +273,7 @@
           public PDFColor getTransparentColor() throws FopImageException {
               return transparent;
           }
  -        public byte[] getMask()  throws FopImageException {
  +        public byte[] getMask() throws FopImageException {
               return m_mask;
           }
           // get the image bytes, and bytes properties
  @@ -406,12 +400,11 @@
        */
       public void draw(Shape s) {
           //System.out.println("draw(Shape)");
  -            currentStream.write("q\n");
  -			Shape imclip = getClip();
  -			writeClip(imclip);
  +        currentStream.write("q\n");
  +        Shape imclip = getClip();
  +        writeClip(imclip);
           Color c = getColor();
  -        currentColour = new PDFColor(c.getRed(), c.getGreen(), c.getBlue());
  -        currentStream.write(currentColour.getColorSpaceOut(false));
  +        applyColor(c, false);
   
           applyPaint(getPaint(), false);
           applyStroke(getStroke());
  @@ -452,10 +445,13 @@
               iter.next();
           }
           doDrawing(false, true, false);
  -            currentStream.write("Q\n");
  +        currentStream.write("Q\n");
       }
   
       protected void writeClip(Shape s) {
  +        if (s == null) {
  +            return;
  +        }
           PathIterator iter = s.getPathIterator(getTransform());
           while (!iter.isDone()) {
               double vals[] = new double[6];
  @@ -492,110 +488,149 @@
               iter.next();
           }
           // clip area
  -		currentStream.write("W\n");
  -		currentStream.write("n\n");
  +        currentStream.write("W\n");
  +        currentStream.write("n\n");
  +    }
  +
  +    protected void applyColor(Color col, boolean fill) {
  +        Color c = col;
  +        if (c.getColorSpace().getType() ==
  +                java.awt.color.ColorSpace.TYPE_RGB) {
  +            currentColour =
  +              new PDFColor(c.getRed(), c.getGreen(), c.getBlue());
  +            currentStream.write(currentColour.getColorSpaceOut(fill));
  +        } else if (c.getColorSpace().getType() ==
  +            java.awt.color.ColorSpace.TYPE_CMYK) {
  +            float[] cComps = c.getColorComponents(new float[3]);
  +            double[] cmyk = new double[3];
  +            for (int i = 0; i < 3; i++) {
  +                // convert the float elements to doubles for pdf
  +                cmyk[i] = cComps[i];
  +            }
  +            currentColour =
  +              new PDFColor(cmyk[0], cmyk[1], cmyk[2], cmyk[3]);
  +            currentStream.write(currentColour.getColorSpaceOut(fill));
  +        } else if (c.getColorSpace().getType() ==
  +            java.awt.color.ColorSpace.TYPE_2CLR) {
  +            // used for black/magenta
  +            float[] cComps = c.getColorComponents(new float[1]);
  +            double[] blackMagenta = new double[1];
  +            for (int i = 0; i < 1; i++) {
  +                blackMagenta[i] = cComps[i];
  +            }
  +            //currentColour = new PDFColor(blackMagenta[0], blackMagenta[1]);
  +            currentStream.write(currentColour.getColorSpaceOut(fill));
  +        }
  +        else {
  +            System.err.println("Color Space not supported by PDFGraphics2D");
  +        }
       }
   
       protected void applyPaint(Paint paint, boolean fill) {
  -        if(paint instanceof GradientPaint) {
  -            GradientPaint gp = (GradientPaint)paint;
  +        if (paint instanceof GradientPaint) {
  +            GradientPaint gp = (GradientPaint) paint;
               Color c1 = gp.getColor1();
               Color c2 = gp.getColor2();
               Point2D p1 = gp.getPoint1();
               Point2D p2 = gp.getPoint2();
               boolean cyclic = gp.isCyclic();
   
  -			Vector theCoords = new Vector();
  -						theCoords.addElement( new Double(p1.getX()));
  -            theCoords.addElement( new Double(p1.getY()));
  -            theCoords.addElement( new Double(p2.getX()));
  -            theCoords.addElement( new Double(p2.getY()));
  -
  -				Vector theExtend = new Vector();
  -				theExtend.addElement(new Boolean(true));
  -				theExtend.addElement(new Boolean(true));
  -
  -				Vector theDomain = new Vector();
  -				theDomain.addElement(new Double(0));
  -				theDomain.addElement(new Double(1));
  -
  -				Vector theEncode = new Vector();
  -				theEncode.addElement(new Double(0));
  -				theEncode.addElement(new Double(1));
  -				theEncode.addElement(new Double(0));
  -				theEncode.addElement(new Double(1));
  -
  -				Vector theBounds = new Vector();
  -				theBounds.addElement(new Double(0));
  -				theBounds.addElement(new Double(1));
  +            Vector theCoords = new Vector();
  +            theCoords.addElement(new Double(p1.getX()));
  +            theCoords.addElement(new Double(p1.getY()));
  +            theCoords.addElement(new Double(p2.getX()));
  +            theCoords.addElement(new Double(p2.getY()));
  +
  +            Vector theExtend = new Vector();
  +            theExtend.addElement(new Boolean(true));
  +            theExtend.addElement(new Boolean(true));
  +
  +            Vector theDomain = new Vector();
  +            theDomain.addElement(new Double(0));
  +            theDomain.addElement(new Double(1));
  +
  +            Vector theEncode = new Vector();
  +            theEncode.addElement(new Double(0));
  +            theEncode.addElement(new Double(1));
  +            theEncode.addElement(new Double(0));
  +            theEncode.addElement(new Double(1));
  +
  +            Vector theBounds = new Vector();
  +            theBounds.addElement(new Double(0));
  +            theBounds.addElement(new Double(1));
   
  -				Vector theFunctions = new Vector();
  +            Vector theFunctions = new Vector();
   
               Vector someColors = new Vector();
   
  -            PDFColor color1 = new PDFColor(c1.getRed(), c1.getGreen(), c1.getBlue());
  +            PDFColor color1 = new PDFColor(c1.getRed(), c1.getGreen(),
  +                                           c1.getBlue());
               someColors.addElement(color1);
  -            PDFColor color2 = new PDFColor(c2.getRed(), c2.getGreen(), c2.getBlue());
  +            PDFColor color2 = new PDFColor(c2.getRed(), c2.getGreen(),
  +                                           c2.getBlue());
               someColors.addElement(color2);
   
  -            PDFFunction myfunc = this.pdfDoc.makeFunction(2, theDomain, null, color1.getVector(), color2.getVector(), 1.0);
  +            PDFFunction myfunc =
  +              this.pdfDoc.makeFunction(2, theDomain, null,
  +                                       color1.getVector(), color2.getVector(), 1.0);
   
               ColorSpace aColorSpace = new ColorSpace(ColorSpace.DEVICE_RGB);
  -            PDFPattern myPat = this.pdfDoc.createGradient(false, aColorSpace,
  -													 someColors, null, theCoords);
  -				    currentStream.write(myPat.getColorSpaceOut(fill));
  +            PDFPattern myPat =
  +              this.pdfDoc.createGradient(false, aColorSpace,
  +                                         someColors, null, theCoords);
  +            currentStream.write(myPat.getColorSpaceOut(fill));
   
  -        } else if(paint instanceof TexturePaint) {
  +        } else if (paint instanceof TexturePaint) {
           }
       }
   
       protected void applyStroke(Stroke stroke) {
  -        if(stroke instanceof BasicStroke) {
  -            BasicStroke bs = (BasicStroke)stroke;
  +        if (stroke instanceof BasicStroke) {
  +            BasicStroke bs = (BasicStroke) stroke;
   
               float[] da = bs.getDashArray();
  -            if(da != null) {
  +            if (da != null) {
                   currentStream.write("[");
  -                for(int count = 0; count < da.length; count++) {
  -                    currentStream.write("" + ((int)da[count]));
  -                    if(count < da.length - 1) {
  +                for (int count = 0; count < da.length; count++) {
  +                    currentStream.write("" + ((int) da[count]));
  +                    if (count < da.length - 1) {
                           currentStream.write(" ");
                       }
                   }
                   currentStream.write("] ");
                   float offset = bs.getDashPhase();
  -                currentStream.write(((int)offset) + " d\n");
  +                currentStream.write(((int) offset) + " d\n");
               }
               int ec = bs.getEndCap();
  -            switch(ec) {
  +            switch (ec) {
                   case BasicStroke.CAP_BUTT:
                       currentStream.write(0 + " J\n");
  -                break;
  +                    break;
                   case BasicStroke.CAP_ROUND:
                       currentStream.write(1 + " J\n");
  -                break;
  +                    break;
                   case BasicStroke.CAP_SQUARE:
                       currentStream.write(2 + " J\n");
  -                break;
  +                    break;
               }
   
               int lj = bs.getLineJoin();
  -            switch(lj) {
  +            switch (lj) {
                   case BasicStroke.JOIN_MITER:
                       currentStream.write(0 + " j\n");
  -                break;
  +                    break;
                   case BasicStroke.JOIN_ROUND:
                       currentStream.write(1 + " j\n");
  -                break;
  +                    break;
                   case BasicStroke.JOIN_BEVEL:
                       currentStream.write(2 + " j\n");
  -                break;
  +                    break;
               }
               float lw = bs.getLineWidth();
               currentStream.write(PDFNumber.doubleOut(lw) + " w\n");
   
               float ml = bs.getMiterLimit();
  -            currentStream.write(PDFNumber.doubleOut(ml) + " M\n");  
  +            currentStream.write(PDFNumber.doubleOut(ml) + " M\n");
           }
       }
   
  @@ -686,18 +721,16 @@
           //System.out.println("drawString(String)");
           currentStream.write("BT\n");
   
  -      Shape imclip = getClip();
  -      writeClip(imclip);
  +        Shape imclip = getClip();
  +        writeClip(imclip);
           Color c = getColor();
  -        currentColour = new PDFColor(c.getRed(), c.getGreen(), c.getBlue());
  -        currentStream.write(currentColour.getColorSpaceOut(true));
  +        applyColor(c, true);
           c = getBackground();
  -        PDFColor col = new PDFColor(c.getRed(), c.getGreen(), c.getBlue());
  -        currentStream.write(col.getColorSpaceOut(false));
  +        applyColor(c, false);
   
           Font gFont = getFont();
           String name = gFont.getName();
  -        if(name.equals("sanserif")) {
  +        if (name.equals("sanserif")) {
               name = "sans-serif";
           }
           int size = gFont.getSize();
  @@ -706,29 +739,32 @@
           try {
               fontState = new FontState(fontState.getFontInfo(), name,
                                         style, weight, size * 1000, 0);
  -        } catch(org.apache.fop.apps.FOPException fope) {
  +        } catch (org.apache.fop.apps.FOPException fope) {
               fope.printStackTrace();
           }
           name = fontState.getFontName();
           size = fontState.getFontSize() / 1000;
   
  -//System.out.println("ffn:" + gFont.getFontName() + "fn:" + gFont.getName() + " ff:" + gFont.getFamily() + " fs:" + fontState.getFontName());
  +        //System.out.println("ffn:" + gFont.getFontName() + "fn:" + gFont.getName() + " ff:" + gFont.getFamily() + " fs:" + fontState.getFontName());
   
  -            if ((!name.equals(this.currentFontName)) ||
  -                    (size != this.currentFontSize)) {
  -                this.currentFontName = name;
  -                this.currentFontSize = size;
  -                currentStream.write("/" + name + " " + size + " Tf\n");
  +        if ((!name.equals(this.currentFontName)) ||
  +                (size != this.currentFontSize)) {
  +            this.currentFontName = name;
  +            this.currentFontSize = size;
  +            currentStream.write("/" + name + " " + size + " Tf\n");
   
  -            }
  +        }
           AffineTransform trans = getTransform();
           trans.translate(x, y);
           double[] vals = new double[6];
           trans.getMatrix(vals);
   
  -        currentStream.write(PDFNumber.doubleOut(vals[0]) + " " + PDFNumber.doubleOut(vals[1]) + " "
  -+ PDFNumber.doubleOut(vals[2]) + " " + PDFNumber.doubleOut(-vals[3]) + " " + PDFNumber.doubleOut(vals[4])
  -+ " " + PDFNumber.doubleOut(vals[5]) + " Tm (" + s + ") Tj\n");
  +        currentStream.write(PDFNumber.doubleOut(vals[0]) + " " +
  +                            PDFNumber.doubleOut(vals[1]) + " " +
  +                            PDFNumber.doubleOut(vals[2]) + " " +
  +                            PDFNumber.doubleOut(-vals[3]) + " " +
  +                            PDFNumber.doubleOut(vals[4]) + " " +
  +                            PDFNumber.doubleOut(vals[5]) + " Tm (" + s + ") Tj\n");
   
           currentStream.write("ET\n");
       }
  @@ -761,21 +797,20 @@
           System.err.println("drawString(AttributedCharacterIterator)");
   
           currentStream.write("BT\n");
  -      Shape imclip = getClip();
  -      writeClip(imclip);
  +        Shape imclip = getClip();
  +        writeClip(imclip);
           Color c = getColor();
  -        currentColour = new PDFColor(c.getRed(), c.getGreen(), c.getBlue());
  -        currentStream.write(currentColour.getColorSpaceOut(true));
  +        applyColor(c, true);
           c = getBackground();
  -        PDFColor col = new PDFColor(c.getRed(), c.getGreen(), c.getBlue());
  -        currentStream.write(col.getColorSpaceOut(false));
  +        applyColor(c, false);
   
           AffineTransform trans = getTransform();
           trans.translate(x, y);
           double[] vals = new double[6];
           trans.getMatrix(vals);
   
  -        for(char ch = iterator.first(); ch != CharacterIterator.DONE; ch = iterator.next()) {
  +        for (char ch = iterator.first(); ch != CharacterIterator.DONE;
  +                ch = iterator.next()) {
               Map attr = iterator.getAttributes();
   
               String name = fontState.getFontName();
  @@ -784,13 +819,17 @@
                       (size != this.currentFontSize)) {
                   this.currentFontName = name;
                   this.currentFontSize = size;
  -                currentStream.write("/" + name + " " + (size / 1000) + " Tf\n");
  +                currentStream.write("/" + name + " " + (size / 1000) +
  +                                    " Tf\n");
   
               }
   
  -            currentStream.write(PDFNumber.doubleOut(vals[0]) + " " + PDFNumber.doubleOut(vals[1]) + " "
  -+ PDFNumber.doubleOut(vals[2]) + " " + PDFNumber.doubleOut(vals[3]) + " " + PDFNumber.doubleOut(vals[4])
  -+ " " + PDFNumber.doubleOut(vals[5]) + " Tm (" + ch + ") Tj\n");
  +            currentStream.write(PDFNumber.doubleOut(vals[0]) + " " +
  +                                PDFNumber.doubleOut(vals[1]) + " " +
  +                                PDFNumber.doubleOut(vals[2]) + " " +
  +                                PDFNumber.doubleOut(vals[3]) + " " +
  +                                PDFNumber.doubleOut(vals[4]) + " " +
  +                                PDFNumber.doubleOut(vals[5]) + " Tm (" + ch + ") Tj\n");
           }
   
           currentStream.write("ET\n");
  @@ -812,15 +851,13 @@
        */
       public void fill(Shape s) {
           //System.err.println("fill");
  -            currentStream.write("q\n");
  -			Shape imclip = getClip();
  -			writeClip(imclip);
  +        currentStream.write("q\n");
  +        Shape imclip = getClip();
  +        writeClip(imclip);
           Color c = getColor();
  -        currentColour = new PDFColor(c.getRed(), c.getGreen(), c.getBlue());
  -        currentStream.write(currentColour.getColorSpaceOut(true));
  +        applyColor(c, true);
           c = getBackground();
  -        PDFColor col = new PDFColor(c.getRed(), c.getGreen(), c.getBlue());
  -        currentStream.write(col.getColorSpaceOut(false));
  +        applyColor(c, false);
   
           applyPaint(getPaint(), true);
   
  @@ -861,7 +898,7 @@
           }
           doDrawing(true, false,
                     iter.getWindingRule() == PathIterator.WIND_EVEN_ODD);
  -            currentStream.write("Q\n");
  +        currentStream.write("Q\n");
       }
   
       protected void doDrawing(boolean fill, boolean stroke,
  
  
  
  1.3       +29 -26    xml-fop/src/org/apache/fop/svg/PDFTextPainter.java
  
  Index: PDFTextPainter.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFTextPainter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PDFTextPainter.java	2001/06/27 16:13:27	1.2
  +++ PDFTextPainter.java	2001/07/10 11:59:24	1.3
  @@ -38,7 +38,7 @@
    * Renders the attributed character iterator of a <tt>TextNode</tt>.
    *
    * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
  - * @version $Id: PDFTextPainter.java,v 1.2 2001/06/27 16:13:27 keiron Exp $
  + * @version $Id: PDFTextPainter.java,v 1.3 2001/07/10 11:59:24 keiron Exp $
    */
   public class PDFTextPainter implements TextPainter {
       FontState fontState;
  @@ -56,14 +56,20 @@
        */
       public void paint(TextNode node, Graphics2D g2d,
                         GraphicsNodeRenderContext context) {
  -        System.out.println("PDFText paint");
  +        //System.out.println("PDFText paint");
           String txt = node.getText();
           Point2D loc = node.getLocation();
   
           AttributedCharacterIterator aci =
             node.getAttributedCharacterIterator();
           // reset position to start of char iterator
  -        aci.first();
  +        if (aci.getBeginIndex() == aci.getEndIndex()) {
  +            return;
  +        }
  +        char ch = aci.first();
  +        if (ch == AttributedCharacterIterator.DONE) {
  +            return;
  +        }
           TextNode.Anchor anchor = (TextNode.Anchor) aci.getAttribute(
                                      GVTAttributedCharacterIterator.TextAttribute.ANCHOR_TYPE);
   
  @@ -81,36 +87,35 @@
           Float posture = (Float) aci.getAttribute(TextAttribute.POSTURE);
           Float taWeight = (Float) aci.getAttribute(TextAttribute.WEIGHT);
   
  -        Set set = aci.getAllAttributeKeys();
  -        for (Iterator iter = set.iterator(); iter.hasNext();) {
  -            System.out.println(iter.next());
  -        }
  -
           if (forg instanceof Color) {
               g2d.setColor((Color) forg);
           }
           g2d.setPaint(forg);
           g2d.setStroke(stroke);
   
  -        String style = posture.floatValue() > 0.0 ? "italic" : "normal";
  -        String weight = taWeight.floatValue() > 1.0 ? "bold" : "normal";
  +        String style = ((posture != null) && (posture.floatValue() > 0.0)) ?
  +                       "italic" : "normal";
  +        String weight = ((taWeight != null) &&
  +                         (taWeight.floatValue() > 1.0)) ? "bold" : "normal";
   
           FontInfo fi = fontState.getFontInfo();
           boolean found = false;
  -        for (Enumeration e = gvtFonts.elements(); e.hasMoreElements();) {
  -            GVTFontFamily fam = (GVTFontFamily) e.nextElement();
  -            String name = fam.getFamilyName();
  -            System.out.println(name);
  -            if (fi.hasFont(name, weight, style)) {
  -                try {
  -                    int fsize = (int) size.floatValue();
  -                    fontState = new FontState(fontState.getFontInfo(),
  -                                              name, style, weight, fsize * 1000, 0);
  -                } catch (org.apache.fop.apps.FOPException fope) {
  -                    fope.printStackTrace();
  +        if (gvtFonts != null) {
  +            for (Enumeration e = gvtFonts.elements();
  +                    e.hasMoreElements();) {
  +                GVTFontFamily fam = (GVTFontFamily) e.nextElement();
  +                String name = fam.getFamilyName();
  +                if (fi.hasFont(name, weight, style)) {
  +                    try {
  +                        int fsize = (int) size.floatValue();
  +                        fontState = new FontState(fontState.getFontInfo(),
  +                                                  name, style, weight, fsize * 1000, 0);
  +                    } catch (org.apache.fop.apps.FOPException fope) {
  +                        fope.printStackTrace();
  +                    }
  +                    found = true;
  +                    break;
                   }
  -                found = true;
  -                break;
               }
           }
           if (!found) {
  @@ -143,8 +148,6 @@
   
   
           float advance = getStringWidth(txt);
  -        System.out.println("ad:" + advance + " a:" + anchor + " ind:" +
  -                           aci.getIndex());
           float tx = 0;
           if (anchor != null) {
               switch (anchor.getType()) {
  @@ -350,7 +353,7 @@
        */
       public Rectangle2D getPaintedBounds(TextNode node,
                                           FontRenderContext frc) {
  -        System.out.println("PDFText getPaintedBounds");
  +        //System.out.println("PDFText getPaintedBounds");
           return null;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org