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 2002/07/23 12:57:57 UTC

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

keiron      2002/07/23 03:57:57

  Modified:    src/org/apache/fop/svg PDFDocumentGraphics2D.java
                        PDFGraphics2D.java PDFTextElementBridge.java
                        PDFTextPainter.java PDFTranscoder.java
  Added:       src/org/apache/fop/svg PDFGraphicsConfiguration.java
                        PDFGraphicsDevice.java
  Log:
  spearated GraphicsConfiguration classes
  handles the text painting better using the stroke painter as
  a proxy for bounds etc.
  
  Revision  Changes    Path
  1.20      +8 -11     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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- PDFDocumentGraphics2D.java	9 Jul 2002 14:59:03 -0000	1.19
  +++ PDFDocumentGraphics2D.java	23 Jul 2002 10:57:57 -0000	1.20
  @@ -11,7 +11,6 @@
   import org.apache.fop.fonts.*;
   import org.apache.fop.render.pdf.FontSetup;
   import org.apache.fop.layout.*;
  -import org.apache.fop.apps.FOPException;
   
   import java.awt.Graphics;
   import java.awt.Font;
  @@ -44,8 +43,6 @@
       int width;
       int height;
   
  -    FontInfo fontInfo = null;
  -
       /**
        * Create a new PDFDocumentGraphics2D.
        * This is used to create a new pdf document, the height,
  @@ -63,10 +60,8 @@
           if(!textAsShapes) {
               fontInfo = new FontInfo();
               FontSetup.setup(fontInfo);
  -            try {
  -                fontState = new FontState(fontInfo, "Helvetica", "normal",
  -                                          "normal", 12, 0);
  -            } catch (FOPException e) {}
  +            //FontState fontState = new FontState("Helvetica", "normal",
  +            //                          FontInfo.NORMAL, 12, 0);
           }
   
           standalone = true;
  @@ -117,8 +112,8 @@
           setupDocument(stream, width, height);
       }
   
  -    public FontState getFontState() {
  -        return fontState;
  +    public FontInfo getFontInfo() {
  +        return fontInfo;
       }
   
       public PDFDocument getPDFDocument() {
  @@ -160,6 +155,8 @@
        * This will then write the results to the output stream.
        */
       public void finish() throws IOException {
  +        // restorePDFState();
  +
           pdfStream.add(getString());
           this.pdfDoc.addStream(pdfStream);
           currentPage.setContents(pdfStream);
  
  
  
  1.38      +92 -188   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.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- PDFGraphics2D.java	10 Jul 2002 08:22:24 -0000	1.37
  +++ PDFGraphics2D.java	23 Jul 2002 10:57:57 -0000	1.38
  @@ -65,8 +65,9 @@
        * the current state of the pdf graphics
        */
       PDFState graphicsState;
  +    int baseLevel = 0;
   
  -    protected FontState fontState;
  +    protected FontInfo fontInfo;
       protected FontState ovFontState = null;
   
       /**
  @@ -107,7 +108,7 @@
        * This is used to create a Graphics object for use inside an already
        * existing document.
        */
  -    public PDFGraphics2D(boolean textAsShapes, FontState fs, PDFDocument doc,
  +    public PDFGraphics2D(boolean textAsShapes, FontInfo fi, PDFDocument doc,
                            PDFResourceContext page, String pref, String font, float size, int xpos, int ypos) {
           super(textAsShapes);
           pdfDoc = doc;
  @@ -116,7 +117,7 @@
           currentFontSize = size;
           currentYPosition = ypos;
           currentXPosition = xpos;
  -        fontState = fs;
  +        fontInfo = fi;
           pageRef = pref;
           graphicsState = new PDFState();
       }
  @@ -127,6 +128,7 @@
   
       public void setPDFState(PDFState state) {
           graphicsState = state;
  +        baseLevel = graphicsState.getStackLevel();
       }
   
       public void setOutputStream(OutputStream os) {
  @@ -162,6 +164,13 @@
           return new PDFGraphics2D(this);
       }
   
  +    public void restorePDFState() {
  +        for(int count = graphicsState.getStackLevel(); count > baseLevel; count--) {
  +            currentStream.write("Q\n");
  +        }
  +        graphicsState.restoreLevel(baseLevel);
  +    }
  +
       /**
        * This is a pdf specific method used to add a link to the
        * pdf document.
  @@ -192,9 +201,11 @@
           currentStream.write("q\n");
           Shape imclip = getClip();
           writeClip(imclip);
  -        currentStream.write("" + matrix[0] + " " + matrix[1] + " "
  -                            + matrix[2] + " " + matrix[3] + " "
  -                            + matrix[4] + " " + matrix[5] + " cm\n");
  +        if(!at.isIdentity()) {
  +            currentStream.write("" + matrix[0] + " " + matrix[1] + " "
  +                                + matrix[2] + " " + matrix[3] + " "
  +                                + matrix[4] + " " + matrix[5] + " cm\n");
  +        }
   
           currentStream.write("" + width + " 0 0 "
                             + (-height) + " "
  @@ -365,9 +376,11 @@
           currentStream.write("q\n");
           Shape imclip = getClip();
           writeClip(imclip);
  -        currentStream.write("" + matrix[0] + " " + matrix[1] + " "
  -                            + matrix[2] + " " + matrix[3] + " "
  -                            + matrix[4] + " " + matrix[5] + " cm\n");
  +        if(!at.isIdentity()) {
  +            currentStream.write("" + matrix[0] + " " + matrix[1] + " "
  +                                + matrix[2] + " " + matrix[3] + " "
  +                                + matrix[4] + " " + matrix[5] + " cm\n");
  +        }
           currentStream.write("" + width + " 0 0 " + (-height) + " " + x
                               + " " + (y + height) + " cm\n" + "/Im"
                               + imageInfo.getXNumber() + " Do\nQ\n");
  @@ -448,7 +461,7 @@
       public void dispose() {
           // System.out.println("dispose");
           pdfDoc = null;
  -        fontState = null;
  +        fontInfo = null;
           currentStream = null;
           currentFontName = null;
       }
  @@ -558,6 +571,43 @@
           }
       }
   
  +/*
  +    // in theory we could set the clip using these methods
  +    // it doesn't seem to improve the file sizes much
  +    // and makes everything more complicated
  +
  +    Shape lastClip = null;
  +
  +    public void clip(Shape cl) {
  +        super.clip(cl);
  +        Shape newClip = getClip();
  +        if(newClip == null || lastClip == null || !(new Area(newClip).equals(new Area(lastClip)))) {
  +        graphicsState.setClip(newClip);
  +        writeClip(newClip);
  +        }
  +
  +        lastClip = newClip;
  +    }
  +
  +    public void setClip(Shape cl) {
  +        super.setClip(cl);
  +        Shape newClip = getClip();
  +        if(newClip == null || lastClip == null || !(new Area(newClip).equals(new Area(lastClip)))) {
  +        for(int count = graphicsState.getStackLevel(); count > baseLevel; count--) {
  +            currentStream.write("Q\n");
  +        }
  +        graphicsState.restoreLevel(baseLevel);
  +        currentStream.write("q\n");
  +        graphicsState.push();
  +        if(newClip != null) {
  +            graphicsState.setClip(newClip);
  +        }
  +        writeClip(newClip);
  +        }
  +
  +        lastClip = newClip;
  +    }
  +*/
       protected void writeClip(Shape s) {
           if (s == null) {
               return;
  @@ -742,16 +792,10 @@
   
               FontInfo fi = new FontInfo();
               FontSetup.setup(fi);
  -            FontState fs = null;
  -            try {
  -                fs = new FontState(fi, "sans-serif", "normal",
  -                                          "normal", 1, 0);
  -            } catch (org.apache.fop.apps.FOPException fope) {
  -                fope.printStackTrace();
  -            }
  +
               PDFResources res = pdfDoc.makeResources();
               PDFResourceContext context = new PDFResourceContext(0, pdfDoc, res);
  -            PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fs,
  +            PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fi,
                                               pdfDoc, context, pageRef,
                                               currentFontName, currentFontSize,
                                               currentYPosition, currentXPosition);
  @@ -950,6 +994,7 @@
       public void drawString(String s, float x, float y) {
           // System.out.println("drawString(String)");
   
  +        FontState fontState;
           if(ovFontState == null) {
               Font gFont = getFont();
               String n = gFont.getFamily();
  @@ -958,13 +1003,10 @@
               }
               int siz = gFont.getSize();
               String style = gFont.isItalic() ? "italic" : "normal";
  -            String weight = gFont.isBold() ? "bold" : "normal";
  -            try {
  -                fontState = new FontState(fontState.getFontInfo(), n, style,
  -                                          weight, siz * 1000, 0);
  -            } catch (org.apache.fop.apps.FOPException fope) {
  -                fope.printStackTrace();
  -            }
  +            int weight = gFont.isBold() ? FontInfo.BOLD : FontInfo.NORMAL;
  +            String fname = fontInfo.fontLookup(n, style, weight);
  +            FontMetric metrics = fontInfo.getMetricsFor(fname);
  +            fontState = new FontState(fname, metrics, siz * 1000);
           } else {
               fontState = ovFontState;
               ovFontState = null;
  @@ -990,12 +1032,9 @@
           applyColor(c, true);
           int salpha = c.getAlpha();
   
  -        c = getBackground();
  -        applyColor(c, false);
  -        if(salpha != 255/* || c.getAlpha() != 255*/) {
  +        if(salpha != 255) {
               HashMap vals = new HashMap();
               vals.put(PDFGState.ca, new Float(salpha / 255f));
  -            //vals.put(PDFGState.CA, new Float(c.getAlpha() / 255f));
               PDFGState gstate = pdfDoc.makeGState(vals, graphicsState.getGState());
               resourceContext.addGState(gstate); 
               currentStream.write("/" + gstate.getName() + " gs\n");
  @@ -1014,7 +1053,7 @@
           // This assumes that *all* CIDFonts use a /ToUnicode mapping
           boolean useMultiByte = false;
           org.apache.fop.render.pdf.Font f =
  -            (org.apache.fop.render.pdf.Font)fontState.getFontInfo().getFonts().get(name);
  +            (org.apache.fop.render.pdf.Font)fontInfo.getFonts().get(name);
           if (f instanceof LazyFont){
               if(((LazyFont) f).getRealFont() instanceof CIDFont){
                   useMultiByte = true;
  @@ -1149,15 +1188,34 @@
                              float y) {
           System.err.println("drawString(AttributedCharacterIterator)");
   
  +        FontState fontState = null;
  +
           Shape imclip = getClip();
           writeClip(imclip);
           Color c = getColor();
           applyColor(c, true);
  -        c = getBackground();
  -        applyColor(c, false);
  +
  +        boolean fill = true;
  +        boolean stroke = false;
  +        if(true) {
  +            Stroke currentStroke = getStroke();
  +            stroke = true;
  +            applyStroke(currentStroke);
  +            applyColor(c, false);
  +        }
   
           currentStream.write("BT\n");
   
  +        // set text rendering mode:
  +        // 0 - fill, 1 - stroke, 2 - fill then stroke
  +        int textr = 0;
  +        if(fill && stroke) {
  +            textr = 2;
  +        } else if(stroke) {
  +            textr = 1;
  +        }
  +        currentStream.write(textr + " Tr\n");
  +
           AffineTransform trans = getTransform();
           trans.translate(x, y);
           double[] vals = new double[6];
  @@ -1314,160 +1372,6 @@
        */
       public GraphicsConfiguration getDeviceConfiguration() {
           return new PDFGraphicsConfiguration();
  -    }
  -
  -    /**
  -     * Our implementation of the class that returns information about
  -     * roughly what we can handle and want to see (alpha for example).
  -     */
  -    static class PDFGraphicsConfiguration extends GraphicsConfiguration {
  -        // We use this to get a good colormodel..
  -        static BufferedImage BIWithAlpha = new BufferedImage(1, 1,
  -                BufferedImage.TYPE_INT_ARGB);
  -        // We use this to get a good colormodel..
  -        static BufferedImage BIWithOutAlpha = new BufferedImage(1, 1,
  -                BufferedImage.TYPE_INT_RGB);
  -
  -        /**
  -         * Construct a buffered image with an alpha channel, unless
  -         * transparencty is OPAQUE (no alpha at all).
  -         */
  -        public BufferedImage createCompatibleImage(int width, int height,
  -                                                   int transparency) {
  -            if (transparency == Transparency.OPAQUE)
  -                return new BufferedImage(width, height,
  -                                         BufferedImage.TYPE_INT_RGB);
  -            else
  -                return new BufferedImage(width, height,
  -                                         BufferedImage.TYPE_INT_ARGB);
  -        }
  -
  -        /**
  -         * Construct a buffered image with an alpha channel.
  -         */
  -        public BufferedImage createCompatibleImage(int width, int height) {
  -            return new BufferedImage(width, height,
  -                                     BufferedImage.TYPE_INT_ARGB);
  -        }
  -
  -        /**
  -         * FIXX ME: This should return the page bounds in Pts,
  -         * I couldn't figure out how to get this for the current
  -         * page from the PDFDocument (this still works for now,
  -         * but it should be fixed...).
  -         */
  -        public Rectangle getBounds() {
  -System.out.println("getting getBounds");
  -            return null;
  -        }
  -
  -        /**
  -         * Return a good default color model for this 'device'.
  -         */
  -        public ColorModel getColorModel() {
  -            return BIWithAlpha.getColorModel();
  -        }
  -
  -        /**
  -         * Return a good color model given <tt>transparency</tt>
  -         */
  -        public ColorModel getColorModel(int transparency) {
  -            if (transparency == Transparency.OPAQUE)
  -                return BIWithOutAlpha.getColorModel();
  -            else
  -                return BIWithAlpha.getColorModel();
  -        }
  -
  -        /**
  -         * The default transform (1:1).
  -         */
  -        public AffineTransform getDefaultTransform() {
  -System.out.println("getting getDefaultTransform");
  -            return new AffineTransform();
  -        }
  -
  -        /**
  -         * The normalizing transform (1:1) (since we currently
  -         * render images at 72dpi, which we might want to change
  -         * in the future).
  -         */
  -        public AffineTransform getNormalizingTransform() {
  -System.out.println("getting getNormalizingTransform");
  -            return new AffineTransform(2, 0, 0, 2, 0, 0);
  -        }
  -
  -        /**
  -         * Return our dummy instance of GraphicsDevice
  -         */
  -        public GraphicsDevice getDevice() {
  -            return new PDFGraphicsDevice(this);
  -        }
  -
  -/*
  -// for jdk1.4
  -public java.awt.image.VolatileImage createCompatibleVolatileImage(int width, int height) {
  -return null;
  -}
  -*/
  -    }
  -
  -    /**
  -     * This implements the GraphicsDevice interface as appropriate for
  -     * a PDFGraphics2D.  This is quite simple since we only have one
  -     * GraphicsConfiguration for now (this might change in the future
  -     * I suppose).
  -     */
  -    static class PDFGraphicsDevice extends GraphicsDevice {
  -
  -        /**
  -         * The Graphics Config that created us...
  -         */
  -        GraphicsConfiguration gc;
  -
  -        /**
  -         * @param The gc we should reference
  -         */
  -        PDFGraphicsDevice(PDFGraphicsConfiguration gc) {
  -            this.gc = gc;
  -        }
  -
  -        /**
  -         * Ignore template and return the only config we have
  -         */
  -        public GraphicsConfiguration getBestConfiguration(GraphicsConfigTemplate gct) {
  -            return gc;
  -        }
  -
  -        /**
  -         * Return an array of our one GraphicsConfig
  -         */
  -        public GraphicsConfiguration[] getConfigurations() {
  -            return new GraphicsConfiguration[] {
  -                gc
  -            };
  -        }
  -
  -        /**
  -         * Return out sole GraphicsConfig.
  -         */
  -        public GraphicsConfiguration getDefaultConfiguration() {
  -            return gc;
  -        }
  -
  -        /**
  -         * Generate an IdString..
  -         */
  -        public String getIDstring() {
  -            return toString();
  -        }
  -
  -        /**
  -         * Let the caller know that we are "a printer"
  -         */
  -        public int getType() {
  -            return GraphicsDevice.TYPE_PRINTER;
  -        }
  -
       }
   
       /**
  
  
  
  1.9       +4 -4      xml-fop/src/org/apache/fop/svg/PDFTextElementBridge.java
  
  Index: PDFTextElementBridge.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFTextElementBridge.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- PDFTextElementBridge.java	4 Jul 2002 07:30:01 -0000	1.8
  +++ PDFTextElementBridge.java	23 Jul 2002 10:57:57 -0000	1.9
  @@ -13,7 +13,7 @@
   import org.apache.batik.gvt.CompositeGraphicsNode;
   import org.apache.batik.gvt.GraphicsNode;
   
  -import org.apache.fop.layout.FontState;
  +import org.apache.fop.layout.FontInfo;
   
   import org.w3c.dom.Element;
   import org.w3c.dom.Node;
  @@ -33,8 +33,8 @@
       /**
        * Constructs a new bridge for the &lt;text> element.
        */
  -    public PDFTextElementBridge(FontState fs) {
  -        pdfTextPainter = new PDFTextPainter(fs);
  +    public PDFTextElementBridge(FontInfo fi) {
  +        pdfTextPainter = new PDFTextPainter(fi);
       }
   
       public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
  
  
  
  1.12      +51 -42    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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- PDFTextPainter.java	4 Jul 2002 14:08:20 -0000	1.11
  +++ PDFTextPainter.java	23 Jul 2002 10:57:57 -0000	1.12
  @@ -32,8 +32,6 @@
   
   import org.apache.fop.layout.*;
   
  -// TODO properly calculate bounds for links etc.
  -
   /**
    * Renders the attributed character iterator of a <tt>TextNode</tt>.
    *
  @@ -41,10 +39,12 @@
    * @version $Id$
    */
   public class PDFTextPainter implements TextPainter {
  -    FontState fontState;
  +    FontInfo fontInfo;
  +    protected final static TextPainter proxyPainter
  +                                 = StrokingTextPainter.getInstance();
   
  -    public PDFTextPainter(FontState fs) {
  -        fontState = fs;
  +    public PDFTextPainter(FontInfo fi) {
  +        fontInfo = fi;
       }
   
       /**
  @@ -75,6 +75,7 @@
           Vector gvtFonts =
               (Vector)aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.GVT_FONT_FAMILIES);
           Paint forg = (Paint)aci.getAttribute(TextAttribute.FOREGROUND);
  +        Paint strokePaint = (Paint)aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.STROKE_PAINT);
           Float size = (Float)aci.getAttribute(TextAttribute.SIZE);
           if(size == null) {
               return;
  @@ -89,71 +90,81 @@
           Float posture = (Float)aci.getAttribute(TextAttribute.POSTURE);
           Float taWeight = (Float)aci.getAttribute(TextAttribute.WEIGHT);
   
  +        boolean useStrokePainter = false;
  +
           if (forg instanceof Color) {
  -            g2d.setColor((Color)forg);
  +            Color col = (Color)forg;
  +            if(col.getAlpha() != 255) {
  +                useStrokePainter = true;
  +            }
  +            g2d.setColor(col);
           }
           g2d.setPaint(forg);
           g2d.setStroke(stroke);
   
  +        if(strokePaint != null) {
  +            // need to draw using AttributedCharacterIterator
  +            useStrokePainter = true;
  +        }
  +
  +        if(useStrokePainter) {
  +            proxyPainter.paint(node, g2d);
  +            return;
  +        }
  +
           String style = ((posture != null) && (posture.floatValue() > 0.0))
                          ? "italic" : "normal";
  -        String weight = ((taWeight != null) && (taWeight.floatValue() > 1.0))
  -                        ? "bold" : "normal";
  +        int weight = ((taWeight != null) && (taWeight.floatValue() > 1.0))
  +                        ? FontInfo.BOLD : FontInfo.NORMAL;
   
  -        FontInfo fi = fontState.getFontInfo();
  +        FontState fontState = null;
  +        FontInfo fi = fontInfo;
           boolean found = false;
  +        String fontFamily = null;
           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() * 1000);
  -                        fontState = new FontState(fontState.getFontInfo(),
  -                                                  name, style, weight,
  -                                                  fsize, 0);
  -                    } catch (org.apache.fop.apps.FOPException fope) {
  -                        fope.printStackTrace();
  -                    }
  +                fontFamily = fam.getFamilyName();
  +                if (fi.hasFont(fontFamily, style, weight)) {
  +                    String fname = fontInfo.fontLookup(fontFamily, style, weight);
  +                    FontMetric metrics = fontInfo.getMetricsFor(fname);
  +                    int fsize = (int)(size.floatValue() * 1000);
  +                    fontState = new FontState(fname, metrics, fsize);
                       found = true;
                       break;
                   }
               }
           }
           if (!found) {
  -            try {
  -                int fsize = (int)(size.floatValue() * 1000);
  -                fontState = new FontState(fontState.getFontInfo(), "any",
  -                                          style, weight, fsize, 0);
  -            } catch (org.apache.fop.apps.FOPException fope) {
  -                fope.printStackTrace();
  -            }
  +            String fname = fontInfo.fontLookup("any", style, FontInfo.NORMAL);
  +            FontMetric metrics = fontInfo.getMetricsFor(fname);
  +            int fsize = (int)(size.floatValue() * 1000);
  +            fontState = new FontState(fname, metrics, fsize);
           } else {
               if(g2d instanceof PDFGraphics2D) {
                   ((PDFGraphics2D)g2d).setOverrideFontState(fontState);
               }
           }
           int fStyle = Font.PLAIN;
  -        if (fontState.getFontWeight().equals("bold")) {
  -            if (fontState.getFontStyle().equals("italic")) {
  +        if (weight == FontInfo.BOLD) {
  +            if (style.equals("italic")) {
                   fStyle = Font.BOLD | Font.ITALIC;
               } else {
                   fStyle = Font.BOLD;
               }
           } else {
  -            if (fontState.getFontStyle().equals("italic")) {
  +            if (style.equals("italic")) {
                   fStyle = Font.ITALIC;
               } else {
                   fStyle = Font.PLAIN;
               }
           }
  -        Font font = new Font(fontState.getFontFamily(), fStyle,
  +        Font font = new Font(fontFamily, fStyle,
                                (int)(fontState.getFontSize() / 1000));
   
           g2d.setFont(font);
   
  -
  -        float advance = getStringWidth(txt);
  +        float advance = getStringWidth(txt, fontState);
           float tx = 0;
           if (anchor != null) {
               switch (anchor.getType()) {
  @@ -167,7 +178,7 @@
           g2d.drawString(txt, (float)(loc.getX() + tx), (float)(loc.getY()));
       }
   
  -    public float getStringWidth(String str) {
  +    public float getStringWidth(String str, FontState fontState) {
           float wordWidth = 0;
           float whitespaceWidth = fontState.width(fontState.mapChar(' '));
   
  @@ -231,29 +242,27 @@
   
       public Shape getShape(TextNode node) {
           System.out.println("PDFText getShape");
  -        return null;
  +        return proxyPainter.getShape(node);
       }
   
       public Shape getDecoratedShape(TextNode node) {
           //System.out.println("PDFText getDecoratedShape");
  -        return new Rectangle(1, 1);
  +        return proxyPainter.getDecoratedShape(node);
       }
   
       public Rectangle2D getBounds(TextNode node) {
           //System.out.println("PDFText getBounds");
  -        Rectangle2D bounds = new Rectangle2D.Float(0, 0, 100, 12);
  -        return bounds;
  +        return proxyPainter.getBounds(node);
       }
   
       public Rectangle2D getDecoratedBounds(TextNode node) {
           System.out.println("PDFText getDecoratedBounds");
  -        return null;
  +        return proxyPainter.getDecoratedBounds(node);
       }
   
       public Rectangle2D getPaintedBounds(TextNode node) {
           // System.out.println("PDFText getPaintedBounds");
  -        Point2D loc = node.getLocation();
  -        return new Rectangle2D.Double(loc.getX(), loc.getY(), 100, 12);
  +        return proxyPainter.getPaintedBounds(node);
       }
   
   }
  
  
  
  1.21      +5 -5      xml-fop/src/org/apache/fop/svg/PDFTranscoder.java
  
  Index: PDFTranscoder.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFTranscoder.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- PDFTranscoder.java	5 Jul 2002 09:59:38 -0000	1.20
  +++ PDFTranscoder.java	23 Jul 2002 10:57:57 -0000	1.21
  @@ -88,7 +88,7 @@
   import org.w3c.dom.css.*;
   import org.w3c.dom.svg.SVGLength;
   
  -import org.apache.fop.svg.*;
  +//import org.apache.fop.layout.FontInfo;
   import org.apache.fop.pdf.*;
   
   import org.w3c.dom.DOMException;
  @@ -180,7 +180,7 @@
           textPainter = new StrokingTextPainter();
           ctx.setTextPainter(textPainter);
   
  -        PDFTextElementBridge pdfTextElementBridge = new PDFTextElementBridge(graphics.getFontState());
  +        PDFTextElementBridge pdfTextElementBridge = new PDFTextElementBridge(graphics.getFontInfo());
           ctx.putBridge(pdfTextElementBridge);
   
           PDFAElementBridge pdfAElementBridge = new PDFAElementBridge();
  @@ -276,7 +276,7 @@
           graphics.setSVGDimension(docWidth, docHeight);
           currentTransform.setTransform(1, 0, 0, -1, 0, height);
           /*if (!stroke) {
  -            textPainter = new PDFTextPainter(graphics.getFontState());
  +            textPainter = new PDFTextPainter(graphics.getFontInfo());
               ctx.setTextPainter(textPainter);
           }*/
   
  
  
  
  1.1                  xml-fop/src/org/apache/fop/svg/PDFGraphicsConfiguration.java
  
  Index: PDFGraphicsConfiguration.java
  ===================================================================
  /*
   * $Id: PDFGraphicsConfiguration.java,v 1.1 2002/07/23 10:57:57 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.
   */
  
  package org.apache.fop.svg;
  
  import java.awt.*;
  import java.awt.Font;
  import java.awt.Image;
  import java.awt.image.*;
  import java.awt.font.*;
  import java.awt.geom.*;
  import java.awt.color.ColorSpace;
  import java.awt.image.renderable.*;
  
  /**
   * Our implementation of the class that returns information about
   * roughly what we can handle and want to see (alpha for example).
   */
  class PDFGraphicsConfiguration extends GraphicsConfiguration {
      // We use this to get a good colormodel..
      static BufferedImage BIWithAlpha =
          new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
      // We use this to get a good colormodel..
      static BufferedImage BIWithOutAlpha =
          new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
  
      /**
       * Construct a buffered image with an alpha channel, unless
       * transparencty is OPAQUE (no alpha at all).
       */
      public BufferedImage createCompatibleImage(int width, int height,
              int transparency) {
          if (transparency == Transparency.OPAQUE)
              return new BufferedImage(width, height,
                                       BufferedImage.TYPE_INT_RGB);
          else
              return new BufferedImage(width, height,
                                       BufferedImage.TYPE_INT_ARGB);
      }
  
      /**
       * Construct a buffered image with an alpha channel.
       */
      public BufferedImage createCompatibleImage(int width, int height) {
          return new BufferedImage(width, height,
                                   BufferedImage.TYPE_INT_ARGB);
      }
  
      /**
       * FIXX ME: This should return the page bounds in Pts,
       * I couldn't figure out how to get this for the current
       * page from the PDFDocument (this still works for now,
       * but it should be fixed...).
       */
      public Rectangle getBounds() {
          System.out.println("getting getBounds");
          return null;
      }
  
      /**
       * Return a good default color model for this 'device'.
       */
      public ColorModel getColorModel() {
          return BIWithAlpha.getColorModel();
      }
  
      /**
       * Return a good color model given <tt>transparency</tt>
       */
      public ColorModel getColorModel(int transparency) {
          if (transparency == Transparency.OPAQUE)
              return BIWithOutAlpha.getColorModel();
          else
              return BIWithAlpha.getColorModel();
      }
  
      /**
       * The default transform (1:1).
       */
      public AffineTransform getDefaultTransform() {
          System.out.println("getting getDefaultTransform");
          return new AffineTransform();
      }
  
      /**
       * The normalizing transform (1:1) (since we currently
       * render images at 72dpi, which we might want to change
       * in the future).
       */
      public AffineTransform getNormalizingTransform() {
          System.out.println("getting getNormalizingTransform");
          return new AffineTransform(2, 0, 0, 2, 0, 0);
      }
  
      /**
       * Return our dummy instance of GraphicsDevice
       */
      public GraphicsDevice getDevice() {
          return new PDFGraphicsDevice(this);
      }
  
      /*
       // for jdk1.4
       public java.awt.image.VolatileImage createCompatibleVolatileImage(int width, int height) {
       return null;
       }
       */
  }
  
  
  
  
  1.1                  xml-fop/src/org/apache/fop/svg/PDFGraphicsDevice.java
  
  Index: PDFGraphicsDevice.java
  ===================================================================
  /*
   * $Id: PDFGraphicsDevice.java,v 1.1 2002/07/23 10:57:57 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.
   */
  
  package org.apache.fop.svg;
  
  import java.awt.*;
  import java.awt.Image;
  import java.awt.image.*;
  import java.awt.image.renderable.*;
  
  /**
   * This implements the GraphicsDevice interface as appropriate for
   * a PDFGraphics2D.  This is quite simple since we only have one
   * GraphicsConfiguration for now (this might change in the future
   * I suppose).
   */
  class PDFGraphicsDevice extends GraphicsDevice {
  
      /**
       * The Graphics Config that created us...
       */
      GraphicsConfiguration gc;
  
      /**
       * @param The gc we should reference
       */
      PDFGraphicsDevice(PDFGraphicsConfiguration gc) {
          this.gc = gc;
      }
  
      /**
       * Ignore template and return the only config we have
       */
      public GraphicsConfiguration getBestConfiguration(
        GraphicsConfigTemplate gct) {
          return gc;
      }
  
      /**
       * Return an array of our one GraphicsConfig
       */
      public GraphicsConfiguration[] getConfigurations() {
          return new GraphicsConfiguration[]{ gc };
      }
  
      /**
       * Return out sole GraphicsConfig.
       */
      public GraphicsConfiguration getDefaultConfiguration() {
          return gc;
      }
  
      /**
       * Generate an IdString..
       */
      public String getIDstring() {
          return toString();
      }
  
      /**
       * Let the caller know that we are "a printer"
       */
      public int getType() {
          return GraphicsDevice.TYPE_PRINTER;
      }
  
  }
  
  
  
  

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