]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Adjustments for font refactoring
authorJeremias Maerki <jeremias@apache.org>
Wed, 8 Jan 2003 14:05:11 +0000 (14:05 +0000)
committerJeremias Maerki <jeremias@apache.org>
Wed, 8 Jan 2003 14:05:11 +0000 (14:05 +0000)
Lots of Javadocs
Fixed Checkstyle errors

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195824 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/render/ps/PSGraphics2D.java
src/org/apache/fop/render/ps/PSRenderer.java
src/org/apache/fop/svg/PDFGraphics2D.java
src/org/apache/fop/svg/PDFTextPainter.java
src/org/apache/fop/tools/AreaTreeBuilder.java
src/org/apache/fop/util/CharUtilities.java

index cd04f21db53a25176e412188c5d5ecb4eb02e871..58d732f2590fb5ca0979c4e690921014f1db428a 100644 (file)
@@ -1,34 +1,54 @@
 /*
  * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2003 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.render.ps;
 
-import org.apache.fop.pdf.*;
-import org.apache.fop.layout.*;
-import org.apache.fop.fonts.*;
-import org.apache.fop.render.pdf.*;
-import org.apache.fop.image.*;
-import org.apache.fop.fo.FOUserAgent;
-
-import org.apache.batik.ext.awt.g2d.*;
-
+//Java
+import java.util.List;
 import java.text.AttributedCharacterIterator;
 import java.text.CharacterIterator;
-import java.awt.*;
+import java.awt.AlphaComposite;
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Dimension;
 import java.awt.Font;
+import java.awt.GradientPaint;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsEnvironment;
 import java.awt.Image;
-import java.awt.image.*;
-import java.awt.font.*;
-import java.awt.geom.*;
-import java.awt.image.renderable.*;
-import java.io.*;
+import java.awt.Paint;
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.awt.Stroke;
+import java.awt.TexturePaint;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.PathIterator;
+import java.awt.geom.Point2D;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBuffer;
+import java.awt.image.DataBufferInt;
+import java.awt.image.ImageObserver;
+import java.awt.image.Raster;
+import java.awt.image.RenderedImage;
+import java.awt.image.renderable.RenderableImage;
+
+// FOP
+import org.apache.fop.layout.FontInfo;
+import org.apache.fop.layout.FontState;
+import org.apache.fop.pdf.PDFColor;
+//import org.apache.fop.pdf.PDFColorSpace;
+import org.apache.fop.pdf.PDFNumber;
+
+// Batik
+import org.apache.batik.ext.awt.g2d.AbstractGraphics2D;
+import org.apache.batik.ext.awt.g2d.GraphicContext;
 
-import java.util.Map;
-import java.util.ArrayList;
 
 /**
  * This concrete implementation of <tt>AbstractGraphics2D</tt> is a
@@ -43,13 +63,15 @@ import java.util.ArrayList;
  * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D
  */
 public class PSGraphics2D extends AbstractGraphics2D {
-    boolean standalone = false;
+
+    private boolean standalone = false;
 
     /**
      * the PDF Document being created
      */
     protected PSRenderer psRenderer;
 
+    /** Currently valid FontState */
     protected FontState fontState;
 
     /**
@@ -75,14 +97,21 @@ public class PSGraphics2D extends AbstractGraphics2D {
     /**
      * the current colour for use in svg
      */
-    PDFColor currentColour = new PDFColor(0, 0, 0);
+    protected PDFColor currentColour = new PDFColor(0, 0, 0);
 
-    FontInfo fontInfo;
+    /** FontInfo containing all available fonts */
+    protected FontInfo fontInfo;
 
     /**
-     * Create a new PDFGraphics2D with the given pdf document info.
-     * This is used to create a Graphics object for use inside an already
-     * existing document.
+     * Create a new Graphics2D that generates PostScript code.
+     * @param textAsShapes True if text should be rendered as graphics
+     * @param fs currently valid FontState object
+     * @param ren PostScript renderer
+     * @param font current font name
+     * @param size current font size
+     * @param xpos current x pos
+     * @param ypos current y pos
+     * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D#AbstractGraphics2D(boolean)
      */
     public PSGraphics2D(boolean textAsShapes, FontState fs, PSRenderer ren,
                         String font, int size, int xpos, int ypos) {
@@ -95,21 +124,30 @@ public class PSGraphics2D extends AbstractGraphics2D {
         fontState = fs;
     }
 
+    /**
+     * Create a new Graphics2D that generates PostScript code.
+     * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D#AbstractGraphics2D(boolean)
+     */
     public PSGraphics2D(boolean textAsShapes) {
         super(textAsShapes);
     }
 
-    public void setGraphicContext(GraphicContext c) {
-        gc = c;
-    }
-
     /**
-     * This constructor supports the create method
+     * Constructor for creating copies
+     * @param g parent PostScript Graphics2D
      */
     public PSGraphics2D(PSGraphics2D g) {
         super(g);
     }
 
+    /**
+     * Sets the GraphicContext
+     * @param c GraphicContext to use
+     */
+    public void setGraphicContext(GraphicContext c) {
+        gc = c;
+    }
+
     /**
      * Creates a new <code>Graphics</code> object that is
      * a copy of this <code>Graphics</code> object.
@@ -140,6 +178,7 @@ public class PSGraphics2D extends AbstractGraphics2D {
      * @param    y   the <i>y</i> coordinate.
      * @param    observer    object to be notified as more of
      * the image is converted.
+     * @return True if the image has been fully drawn/loaded
      * @see      java.awt.Image
      * @see      java.awt.image.ImageObserver
      * @see      java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
@@ -170,13 +209,13 @@ public class PSGraphics2D extends AbstractGraphics2D {
         g.dispose();
 
         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();
 
         int count = 0;
-        int maskpos = 0;
+        //int maskpos = 0;
         switch (bd.getDataType()) {
         case DataBuffer.TYPE_INT:
             int[][] idata = ((DataBufferInt)bd).getBankData();
@@ -219,6 +258,11 @@ public class PSGraphics2D extends AbstractGraphics2D {
         return true;
     }
 
+    /**
+     * Creates a buffered image.
+     * @param size dimensions of the image to be created
+     * @return the buffered image
+     */
     public BufferedImage buildBufferedImage(Dimension size) {
         return new BufferedImage(size.width, size.height,
                                  BufferedImage.TYPE_INT_ARGB);
@@ -357,6 +401,7 @@ public class PSGraphics2D extends AbstractGraphics2D {
      * @param    height the height of the rectangle.
      * @param    observer    object to be notified as more of
      * the image is converted.
+     * @return   True if the image has been fully loaded/drawn
      * @see      java.awt.Image
      * @see      java.awt.image.ImageObserver
      * @see      java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
@@ -474,6 +519,10 @@ public class PSGraphics2D extends AbstractGraphics2D {
         psRenderer.write("grestore");
     }
 
+    /**
+     * Establishes a clipping region
+     * @param s Shape defining the clipping region
+     */
     protected void writeClip(Shape s) {
         PathIterator iter = s.getPathIterator(getTransform());
         psRenderer.write("newpath");
@@ -518,6 +567,11 @@ public class PSGraphics2D extends AbstractGraphics2D {
         psRenderer.write("clippath");
     }
 
+    /**
+     * Applies a new Paint object.
+     * @param paint Paint object to use
+     * @param fill True if to be applied for filling
+     */
     protected void applyPaint(Paint paint, boolean fill) {
         if (paint instanceof GradientPaint) {
             GradientPaint gp = (GradientPaint)paint;
@@ -525,35 +579,35 @@ public class PSGraphics2D extends AbstractGraphics2D {
             Color c2 = gp.getColor2();
             Point2D p1 = gp.getPoint1();
             Point2D p2 = gp.getPoint2();
-            boolean cyclic = gp.isCyclic();
+            //boolean cyclic = gp.isCyclic();
 
-            ArrayList theCoords = new ArrayList();
+            List theCoords = new java.util.ArrayList();
             theCoords.add(new Double(p1.getX()));
             theCoords.add(new Double(p1.getY()));
             theCoords.add(new Double(p2.getX()));
             theCoords.add(new Double(p2.getY()));
 
-            ArrayList theExtend = new ArrayList();
+            List theExtend = new java.util.ArrayList();
             theExtend.add(new Boolean(true));
             theExtend.add(new Boolean(true));
 
-            ArrayList theDomain = new ArrayList();
+            List theDomain = new java.util.ArrayList();
             theDomain.add(new Double(0));
             theDomain.add(new Double(1));
 
-            ArrayList theEncode = new ArrayList();
+            List theEncode = new java.util.ArrayList();
             theEncode.add(new Double(0));
             theEncode.add(new Double(1));
             theEncode.add(new Double(0));
             theEncode.add(new Double(1));
 
-            ArrayList theBounds = new ArrayList();
+            List theBounds = new java.util.ArrayList();
             theBounds.add(new Double(0));
             theBounds.add(new Double(1));
 
-            ArrayList theFunctions = new ArrayList();
+            //List theFunctions = new java.util.ArrayList();
 
-            ArrayList someColors = new ArrayList();
+            List someColors = new java.util.ArrayList();
 
             PDFColor color1 = new PDFColor(c1.getRed(), c1.getGreen(),
                                            c1.getBlue());
@@ -562,10 +616,16 @@ public class PSGraphics2D extends AbstractGraphics2D {
                                            c2.getBlue());
             someColors.add(color2);
 
-            PDFColorSpace aColorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
-        } else if (paint instanceof TexturePaint) {}
+            //PDFColorSpace aColorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
+        } else if (paint instanceof TexturePaint) {
+            //nop
+        }
     }
 
+    /**
+     * Applies a new Stroke object.
+     * @param stroke Stroke object to use
+     */
     protected void applyStroke(Stroke stroke) {
         if (stroke instanceof BasicStroke) {
             BasicStroke bs = (BasicStroke)stroke;
@@ -691,7 +751,9 @@ public class PSGraphics2D extends AbstractGraphics2D {
      * left, in which case the coordinate supplied is the location of the
      * leftmost character on the baseline.
      * @param s the <code>String</code> to be rendered
-     * @param x,&nbsp;y the coordinates where the <code>String</code>
+     * @param x the x-coordinate where the <code>String</code>
+     * should be rendered
+     * @param y the y-coordinate where the <code>String</code>
      * should be rendered
      * @see #setPaint
      * @see java.awt.Graphics#setColor
@@ -740,7 +802,9 @@ public class PSGraphics2D extends AbstractGraphics2D {
      * coordinate supplied is the location of the leftmost character
      * on the baseline.
      * @param iterator the iterator whose text is to be rendered
-     * @param x,&nbsp;y the coordinates where the iterator's text is to be
+     * @param x the x-coordinate where the iterator's text is to be
+     * rendered
+     * @param y the y-coordinate where the iterator's text is to be
      * rendered
      * @see #setPaint
      * @see java.awt.Graphics#setColor
@@ -769,7 +833,7 @@ public class PSGraphics2D extends AbstractGraphics2D {
 
         for (char ch = iterator.first(); ch != CharacterIterator.DONE;
                 ch = iterator.next()) {
-            Map attr = iterator.getAttributes();
+            //Map attr = iterator.getAttributes();
 
             psRenderer.write(PDFNumber.doubleOut(vals[0]) + " "
                              + PDFNumber.doubleOut(vals[1]) + " "
@@ -853,18 +917,25 @@ public class PSGraphics2D extends AbstractGraphics2D {
         psRenderer.write("grestore");
     }
 
+    /**
+     * Commits a painting operation.
+     * @param fill filling
+     * @param stroke stroking
+     */
     protected void doDrawing(boolean fill, boolean stroke, boolean nonzero) {
         if (fill) {
             if (stroke) {
-                if (!nonzero)
+                if (!nonzero) {
                     psRenderer.write("stroke");
-                else
+                } else {
                     psRenderer.write("stroke");
+                }
             } else {
-                if (!nonzero)
+                if (!nonzero) {
                     psRenderer.write("fill");
-                else
+                } else {
                     psRenderer.write("fill");
+                }
             }
         } else {
             // if(stroke)
@@ -875,10 +946,12 @@ public class PSGraphics2D extends AbstractGraphics2D {
     /**
      * Returns the device configuration associated with this
      * <code>Graphics2D</code>.
+     * @return the device configuration
      */
     public GraphicsConfiguration getDeviceConfiguration() {
         // System.out.println("getDeviceConviguration");
-        return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
+        return GraphicsEnvironment.getLocalGraphicsEnvironment().
+                getDefaultScreenDevice().getDefaultConfiguration();
     }
 
     /**
@@ -901,7 +974,7 @@ public class PSGraphics2D extends AbstractGraphics2D {
      * @see       java.awt.FontMetrics
      * @see       java.awt.Graphics#getFontMetrics()
      */
-    public FontMetrics getFontMetrics(Font f) {
+    public java.awt.FontMetrics getFontMetrics(Font f) {
         return fmg.getFontMetrics(f);
     }
 
index 3234bba2df6883979b787c8504d3d974c2378ed4..9a84a08c63f78d3381d9061fc93f70f2eb501799 100644 (file)
@@ -1,48 +1,24 @@
 /*
  * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2003 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.render.ps;
 
-// FOP
-import org.apache.fop.render.AbstractRenderer;
-import org.apache.fop.render.Renderer;
-import org.apache.fop.image.FopImage;
-import org.apache.fop.layout.*;
-import org.apache.fop.datatypes.*;
-import org.apache.fop.fo.properties.*;
-import org.apache.fop.render.pdf.Font;
-import org.apache.fop.image.*;
-
-import org.apache.batik.bridge.*;
-import org.apache.batik.swing.svg.*;
-import org.apache.batik.swing.gvt.*;
-import org.apache.batik.gvt.*;
-import org.apache.batik.gvt.renderer.*;
-import org.apache.batik.gvt.filter.*;
-import org.apache.batik.gvt.event.*;
-
-// SVG
-import org.w3c.dom.svg.SVGSVGElement;
-import org.w3c.dom.svg.SVGDocument;
-import org.w3c.dom.*;
-import org.w3c.dom.svg.*;
-
 // Java
-import java.io.*;
-import java.util.*;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Iterator;
-import java.util.HashMap;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Dimension2D;
-import java.awt.Point;
-import java.awt.RenderingHints;
-import java.awt.Dimension;
+import java.util.Map;
+
+// FOP
+import org.apache.fop.datatypes.ColorType;
+import org.apache.fop.fonts.Font;
+import org.apache.fop.layout.FontInfo;
+import org.apache.fop.render.AbstractRenderer;
+
 
 /**
  * Renderer that renders to PostScript.
@@ -51,24 +27,12 @@ import java.awt.Dimension;
  * is the FlateEncode filter which is a Level 3 feature. The filters in use
  * are hardcoded at the moment.
  * <br>
- * This class follows the Document Structuring Conventions (DSC) version 3.0
- * (If I did everything right). If anyone modifies this renderer please make
+ * This class follows the Document Structuring Conventions (DSC) version 3.0.
+ * If anyone modifies this renderer please make
  * sure to also follow the DSC to make it simpler to programmatically modify
  * the generated Postscript files (ex. extract pages etc.).
  * <br>
- * TODO: Character size/spacing, SVG Transcoder for Batik, configuration, move
- * to PrintRenderer, maybe improve filters (I'm not very proud of them), add a
- * RunLengthEncode filter (useful for Level 2 Postscript), Improve
- * DocumentProcessColors stuff (probably needs to be configurable, then maybe
- * add a color to grayscale conversion for bitmaps to make output smaller (See
- * PCLRenderer), font embedding, support different character encodings, try to
- * implement image transparency, positioning of images is wrong etc. <P>
- *
- * Modified by Mark Lillywhite mark-fop@inomial.com, to use the new
- * Renderer interface. This PostScript renderer appears to be the
- * most efficient at producing output.
- *
- * @author Jeremias Märki
+ * @todo Rebuild the PostScript renderer
  */
 public class PSRenderer extends AbstractRenderer {
 
@@ -77,8 +41,6 @@ public class PSRenderer extends AbstractRenderer {
      */
     protected String producer;
 
-    int imagecount = 0;    // DEBUG
-
     private boolean enableComments = true;
 
     /**
@@ -98,7 +60,7 @@ public class PSRenderer extends AbstractRenderer {
     private FontInfo fontInfo;
 
     /**
-     * set the document's producer
+     * Set the document's producer
      *
      * @param producer string indicating application producing the PostScript
      */
@@ -107,26 +69,34 @@ public class PSRenderer extends AbstractRenderer {
     }
 
     /**
-     * write out a command
+     * Write out a command
+     * @param cmd PostScript command
      */
     protected void write(String cmd) {
         try {
             out.write(cmd);
         } catch (IOException e) {
-            if (!ioTrouble)
+            if (!ioTrouble) {
                 e.printStackTrace();
+            }
             ioTrouble = true;
         }
     }
 
     /**
-     * write out a comment
+     * Write out a comment
+     * @param comment Comment to write
      */
     protected void comment(String comment) {
-        if (this.enableComments)
+        if (this.enableComments) {
             write(comment);
+        }
     }
 
+    /**
+     * Generates the PostScript code for the font dictionary.
+     * @param fontInfo available fonts
+     */
     protected void writeFontDict(FontInfo fontInfo) {
         write("%%BeginResource: procset FOPFonts");
         write("%%Title: Font setup (shortcuts) for this file");
@@ -186,7 +156,8 @@ public class PSRenderer extends AbstractRenderer {
         write("  /FontMatrix get 0 get /Ts exch def /FontInfo get dup");
         write("  /UnderlinePosition get Ts mul /To exch def");
         write("  /UnderlineThickness get Ts mul /Tt exch def");
-        write("  ux uy To add cs 10 mul 26 idiv add moveto Tcx uy To add cs 10 mul 26 idiv add lineto");
+        write("  ux uy To add cs 10 mul 26 idiv add moveto "
+                    + "Tcx uy To add cs 10 mul 26 idiv add lineto");
         write("  Tt setlinewidth stroke");
         write("  grestore");
         write("} bd");
@@ -195,12 +166,12 @@ public class PSRenderer extends AbstractRenderer {
 
         // write("/gfF1{/Helvetica findfont} bd");
         // write("/gfF3{/Helvetica-Bold findfont} bd");
-        HashMap fonts = fontInfo.getFonts();
+        Map fonts = fontInfo.getFonts();
         Iterator enum = fonts.keySet().iterator();
         while (enum.hasNext()) {
             String key = (String)enum.next();
             Font fm = (Font)fonts.get(key);
-            write("/" + key + " /" + fm.fontName() + " def");
+            write("/" + key + " /" + fm.getFontName() + " def");
         }
         write("end def");
         write("%%EndResource");
@@ -208,22 +179,25 @@ public class PSRenderer extends AbstractRenderer {
         while (enum.hasNext()) {
             String key = (String)enum.next();
             Font fm = (Font)fonts.get(key);
-            write("/" + fm.fontName() + " findfont");
+            write("/" + fm.getFontName() + " findfont");
             write("dup length dict begin");
             write("  {1 index /FID ne {def} {pop pop} ifelse} forall");
             write("  /Encoding ISOLatin1Encoding def");
             write("  currentdict");
             write("end");
-            write("/" + fm.fontName() + " exch definefont pop");
+            write("/" + fm.getFontName() + " exch definefont pop");
         }
     }
 
+    /**
+     * Make sure the cursor is in the right place.
+     */
     protected void movetoCurrPosition() {
         write(this.currentIPPosition + " " + this.currentBPPosition + " M");
     }
 
     /**
-     * set up the font info
+     * Set up the font info
      *
      * @param fontInfo the font info object to set up
      */
@@ -233,37 +207,32 @@ public class PSRenderer extends AbstractRenderer {
         this.fontInfo = fontInfo;
     }
 
+    /**
+     * Draws a filled rectangle.
+     * @param x x-coordinate
+     * @param y y-coordinate
+     * @param w width
+     * @param h height
+     * @param col color to fill with
+     */
     protected void addFilledRect(int x, int y, int w, int h,
                                  ColorType col) {
-            write("newpath");
-            write(x + " " + y + " M");
-            write(w + " 0 rlineto");
-            write("0 " + (-h) + " rlineto");
-            write((-w) + " 0 rlineto");
-            write("0 " + h + " rlineto");
-            write("closepath");
-            useColor(col);
-            write("fill");
-    }
-
-    private long copyStream(InputStream in, OutputStream out,
-                            int bufferSize) throws IOException {
-        long bytes_total = 0;
-        byte[] buf = new byte[bufferSize];
-        int bytes_read;
-        while ((bytes_read = in.read(buf)) != -1) {
-            bytes_total += bytes_read;
-            out.write(buf, 0, bytes_read);
-        }
-        return bytes_total;
-    }
-
-
-    private long copyStream(InputStream in,
-                            OutputStream out) throws IOException {
-        return copyStream(in, out, 4096);
+        write("newpath");
+        write(x + " " + y + " M");
+        write(w + " 0 rlineto");
+        write("0 " + (-h) + " rlineto");
+        write((-w) + " 0 rlineto");
+        write("0 " + h + " rlineto");
+        write("closepath");
+        useColor(col);
+        write("fill");
     }
 
+    /**
+     * Changes the currently used font.
+     * @param name name of the font
+     * @param size font size
+     */
     public void useFont(String name, int size) {
         if ((currentFontName != name) || (currentFontSize != size)) {
             write(name + " " + size + " F");
@@ -286,14 +255,15 @@ public class PSRenderer extends AbstractRenderer {
     }
 
     /**
-    */
+     * @see org.apache.fop.render.Renderer#startRenderer(OutputStream)
+     */
     public void startRenderer(OutputStream outputStream)
     throws IOException {
         getLogger().debug("rendering areas to PostScript");
 
         this.out = new PSStream(outputStream);
         write("%!PS-Adobe-3.0");
-        write("%%Creator: "+this.producer);
+        write("%%Creator: " + this.producer);
         write("%%DocumentProcessColors: Black");
         write("%%DocumentSuppliedResources: procset FOPFonts");
         write("%%EndComments");
@@ -337,9 +307,9 @@ public class PSRenderer extends AbstractRenderer {
     }
 
     /**
-    */
-    public void stopRenderer()
-    throws IOException {
+     * @see org.apache.fop.render.Renderer#stopRenderer()
+     */
+    public void stopRenderer() throws IOException {
         write("%%Trailer");
         write("%%EOF");
         this.out.flush();
index 35417856501a00db1ea1060b96095e2e22ad25d7..19c6bb82ad2f2fa35d03b04eeeb14119823043a3 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * $Id$
- * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
  * For details on use and redistribution please refer to the
  * LICENSE file included with these sources.
  */
@@ -22,16 +22,16 @@ import org.apache.fop.pdf.PDFAnnotList;
 import org.apache.fop.pdf.BitmapImage;
 import org.apache.fop.layout.FontInfo;
 import org.apache.fop.layout.FontState;
-import org.apache.fop.layout.FontMetric;
 import org.apache.fop.render.pdf.FontSetup;
+import org.apache.fop.fonts.FontMetrics;
+import org.apache.fop.fonts.LazyFont;
 import org.apache.fop.image.JpegImage;
-import org.apache.fop.render.pdf.CIDFont;
-import org.apache.fop.render.pdf.fonts.LazyFont;
+import org.apache.fop.fonts.CIDFont;
 import org.apache.fop.render.pdf.FopPDFImage;
 
 import org.apache.batik.ext.awt.g2d.AbstractGraphics2D;
 import org.apache.batik.ext.awt.g2d.GraphicContext;
-import org.apache.batik.ext.awt.MultipleGradientPaint;
+//import org.apache.batik.ext.awt.MultipleGradientPaint;
 import org.apache.batik.ext.awt.RadialGradientPaint;
 import org.apache.batik.ext.awt.LinearGradientPaint;
 import org.apache.batik.gvt.PatternPaint;
@@ -60,7 +60,6 @@ import java.awt.image.ImageObserver;
 import java.awt.image.RenderedImage;
 import java.awt.image.Raster;
 import java.awt.image.renderable.RenderableImage;
-import java.awt.FontMetrics;
 import java.awt.geom.PathIterator;
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
@@ -70,8 +69,7 @@ import java.io.IOException;
 import java.io.OutputStream;
 
 import java.util.Map;
-import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.List;
 
 /**
  * PDF Graphics 2D.
@@ -390,7 +388,7 @@ public class PDFGraphics2D extends AbstractGraphics2D {
             final byte[] result = new byte[buf.getWidth() * buf.getHeight() * 3];
             byte[] mask = new byte[buf.getWidth() * buf.getHeight()];
             boolean hasMask = false;
-            boolean binaryMask = true;
+            //boolean binaryMask = true;
 
             Raster raster = buf.getData();
             DataBuffer bd = raster.getDataBuffer();
@@ -410,9 +408,10 @@ public class PDFGraphics2D extends AbstractGraphics2D {
                         mask[maskpos++] = (byte)(alpha & 0xFF);
                         if (alpha != 255) {
                             hasMask = true;
+                            /*
                             if (alpha != 0) {
                                 binaryMask = false;
-                            }
+                            }*/
 
                             // System.out.println("Alpha: " + alpha);
                             // Composite with opaque white...
@@ -465,7 +464,7 @@ public class PDFGraphics2D extends AbstractGraphics2D {
                                           buf.getHeight(), result, ref);
             fopimg.setTransparent(new PDFColor(255, 255, 255));
             imageInfo = pdfDoc.addImage(resourceContext, fopimg);
-            int xObjectNum = imageInfo.getXNumber();
+            //int xObjectNum = imageInfo.getXNumber();
 
             if (outputStream != null) {
                 try {
@@ -627,8 +626,8 @@ public class PDFGraphics2D extends AbstractGraphics2D {
         }
 
         if (c.getAlpha() != 255) {
-            HashMap vals = new HashMap();
-            vals.put(PDFGState.CA, new Float(c.getAlpha() / 255f));
+            Map vals = new java.util.HashMap();
+            vals.put(PDFGState.GSTATE_ALPHA_STROKE, new Float(c.getAlpha() / 255f));
             PDFGState gstate = pdfDoc.makeGState(vals, graphicsState.getGState());
             //gstate.setAlpha(c.getAlpha() / 255f, false);
             resourceContext.addGState(gstate);
@@ -830,37 +829,37 @@ public class PDFGraphics2D extends AbstractGraphics2D {
             float[] fractions = gp.getFractions();
             Point2D p1 = gp.getStartPoint();
             Point2D p2 = gp.getEndPoint();
-            MultipleGradientPaint.CycleMethodEnum cycenum = gp.getCycleMethod();
-            boolean cyclic = cycenum == MultipleGradientPaint.REPEAT;
+            //MultipleGradientPaint.CycleMethodEnum cycenum = gp.getCycleMethod();
+            //boolean cyclic = (cycenum == MultipleGradientPaint.REPEAT);
             AffineTransform transform = graphicsState.getTransform();
             transform.concatenate(gp.getTransform());
 
             p1 = transform.transform(p1, null);
             p2 = transform.transform(p2, null);
 
-            ArrayList theCoords = new ArrayList();
+            List theCoords = new java.util.ArrayList();
             theCoords.add(new Double(p1.getX()));
             theCoords.add(new Double(p1.getY()));
             theCoords.add(new Double(p2.getX()));
             theCoords.add(new Double(p2.getY()));
 
-            ArrayList theExtend = new ArrayList();
+            List theExtend = new java.util.ArrayList();
             theExtend.add(new Boolean(true));
             theExtend.add(new Boolean(true));
 
-            ArrayList theDomain = new ArrayList();
+            List theDomain = new java.util.ArrayList();
             theDomain.add(new Double(0));
             theDomain.add(new Double(1));
 
-            ArrayList theEncode = new ArrayList();
+            List theEncode = new java.util.ArrayList();
             theEncode.add(new Double(0));
             theEncode.add(new Double(1));
             theEncode.add(new Double(0));
             theEncode.add(new Double(1));
 
-            ArrayList theBounds = new ArrayList();
+            List theBounds = new java.util.ArrayList();
 
-            ArrayList someColors = new ArrayList();
+            List someColors = new java.util.ArrayList();
 
             for (int count = 0; count < cols.length; count++) {
                 Color c1 = cols[count];
@@ -896,7 +895,7 @@ public class PDFGraphics2D extends AbstractGraphics2D {
             ac = transform.transform(ac, null);
             af = transform.transform(af, null);
 
-            ArrayList theCoords = new ArrayList();
+            List theCoords = new java.util.ArrayList();
             // the center point af must be within the circle with
             // radius ar centered at ac
             theCoords.add(new Double(af.getX()));
@@ -907,14 +906,14 @@ public class PDFGraphics2D extends AbstractGraphics2D {
             theCoords.add(new Double(ar));
 
             Color[] cols = rgp.getColors();
-            ArrayList someColors = new ArrayList();
+            List someColors = new java.util.ArrayList();
             for (int count = 0; count < cols.length; count++) {
                 Color cc = cols[count];
                 someColors.add(new PDFColor(cc.getRed(), cc.getGreen(), cc.getBlue()));
             }
 
             float[] fractions = rgp.getFractions();
-            ArrayList theBounds = new ArrayList();
+            List theBounds = new java.util.ArrayList();
             for (int count = 1; count < fractions.length - 1; count++) {
                 float offset = fractions[count];
                 theBounds.add(new Double(offset));
@@ -960,13 +959,13 @@ public class PDFGraphics2D extends AbstractGraphics2D {
         pattStream.write(pattGraphic.getString());
         pattStream.write("Q");
 
-        ArrayList bbox = new ArrayList();
+        List bbox = new java.util.ArrayList();
         bbox.add(new Double(0));
         bbox.add(new Double(0));
         bbox.add(new Double(rect.getWidth() + rect.getX()));
         bbox.add(new Double(rect.getHeight() + rect.getY()));
 
-        ArrayList translate = new ArrayList();
+        List translate = new java.util.ArrayList();
         AffineTransform pattt = pp.getPatternTransform();
         pattt.translate(rect.getWidth() + rect.getX(), rect.getHeight() + rect.getY());
         double[] flatmatrix = new double[6];
@@ -1160,10 +1159,10 @@ public class PDFGraphics2D extends AbstractGraphics2D {
             String style = gFont.isItalic() ? "italic" : "normal";
             int weight = gFont.isBold() ? FontInfo.BOLD : FontInfo.NORMAL;
             String fname = fontInfo.fontLookup(n, style, weight);
-            FontMetric metrics = fontInfo.getMetricsFor(fname);
+            FontMetrics metrics = fontInfo.getMetricsFor(fname);
             fontState = new FontState(fname, metrics, siz * 1000);
         } else {
-            FontMetric metrics = fontInfo.getMetricsFor(ovFontState.getFontName());
+            FontMetrics metrics = fontInfo.getMetricsFor(ovFontState.getFontName());
             fontState = new FontState(ovFontState.getFontName(),
                                       metrics, ovFontState.getFontSize());
             ovFontState = null;
@@ -1190,8 +1189,8 @@ public class PDFGraphics2D extends AbstractGraphics2D {
         int salpha = c.getAlpha();
 
         if (salpha != 255) {
-            HashMap vals = new HashMap();
-            vals.put(PDFGState.ca, new Float(salpha / 255f));
+            Map vals = new java.util.HashMap();
+            vals.put(PDFGState.GSTATE_ALPHA_NONSTROKE, new Float(salpha / 255f));
             PDFGState gstate = pdfDoc.makeGState(vals, graphicsState.getGState());
             resourceContext.addGState(gstate);
             currentStream.write("/" + gstate.getName() + " gs\n");
@@ -1199,7 +1198,7 @@ public class PDFGraphics2D extends AbstractGraphics2D {
 
         currentStream.write("BT\n");
 
-        HashMap kerning = null;
+        Map kerning = null;
         boolean kerningAvailable = false;
 
         kerning = fontState.getKerning();
@@ -1209,8 +1208,8 @@ public class PDFGraphics2D extends AbstractGraphics2D {
 
         // 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)fontInfo.getFonts().get(name);
+        org.apache.fop.fonts.Font f =
+            (org.apache.fop.fonts.Font)fontInfo.getFonts().get(name);
         if (f instanceof LazyFont) {
             if (((LazyFont) f).getRealFont() instanceof CIDFont) {
                 useMultiByte = true;
@@ -1276,9 +1275,9 @@ public class PDFGraphics2D extends AbstractGraphics2D {
     }
 
     private void addKerning(StringWriter buf, Integer ch1, Integer ch2,
-                            HashMap kerning, String startText,
+                            Map kerning, String startText,
                             String endText) {
-        HashMap kernPair = (HashMap)kerning.get(ch1);
+        Map kernPair = (Map)kerning.get(ch1);
 
         if (kernPair != null) {
             Integer width = (Integer)kernPair.get(ch2);
@@ -1383,7 +1382,7 @@ public class PDFGraphics2D extends AbstractGraphics2D {
 
         for (char ch = iterator.first(); ch != CharacterIterator.DONE;
                 ch = iterator.next()) {
-            Map attr = iterator.getAttributes();
+            //Map attr = iterator.getAttributes();
 
             String name = fontState.getFontName();
             int size = fontState.getFontSize();
@@ -1443,8 +1442,8 @@ public class PDFGraphics2D extends AbstractGraphics2D {
         }
 
         if (c.getAlpha() != 255) {
-            HashMap vals = new HashMap();
-            vals.put(PDFGState.ca, new Float(c.getAlpha() / 255f));
+            Map vals = new java.util.HashMap();
+            vals.put(PDFGState.GSTATE_ALPHA_NONSTROKE, new Float(c.getAlpha() / 255f));
             PDFGState gstate = pdfDoc.makeGState(vals, graphicsState.getGState());
             resourceContext.addGState(gstate);
             currentStream.write("/" + gstate.getName() + " gs\n");
@@ -1567,7 +1566,7 @@ public class PDFGraphics2D extends AbstractGraphics2D {
      * @see       java.awt.FontMetrics
      * @see       java.awt.Graphics#getFontMetrics()
      */
-    public FontMetrics getFontMetrics(Font f) {
+    public java.awt.FontMetrics getFontMetrics(Font f) {
         return fmg.getFontMetrics(f);
     }
 
index 989c504f1e8f4f5fba7c73f0d6537a7be790165b..f431040c12f3c4abee06b4d63520480866b5dc2a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * $Id$
- * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
  * For details on use and redistribution please refer to the
  * LICENSE file included with these sources.
  */
@@ -18,8 +18,8 @@ import java.awt.Shape;
 import java.awt.Paint;
 import java.awt.Stroke;
 import java.awt.Color;
-import java.util.Vector;
-import java.util.Enumeration;
+import java.util.List;
+import java.util.Iterator;
 
 import org.apache.batik.gvt.text.Mark;
 import org.apache.batik.gvt.TextPainter;
@@ -29,9 +29,9 @@ import org.apache.batik.gvt.font.GVTFontFamily;
 import org.apache.batik.bridge.SVGFontFamily;
 import org.apache.batik.gvt.renderer.StrokingTextPainter;
 
+import org.apache.fop.fonts.FontMetrics;
 import org.apache.fop.layout.FontState;
 import org.apache.fop.layout.FontInfo;
-import org.apache.fop.layout.FontMetric;
 
 /**
  * Renders the attributed character iterator of a <tt>TextNode</tt>.
@@ -90,8 +90,8 @@ public class PDFTextPainter implements TextPainter {
         anchor = (TextNode.Anchor) aci.getAttribute(
                       GVTAttributedCharacterIterator.TextAttribute.ANCHOR_TYPE);
 
-        Vector gvtFonts;
-        gvtFonts = (Vector) aci.getAttribute(
+        List gvtFonts;
+        gvtFonts = (List) aci.getAttribute(
                       GVTAttributedCharacterIterator.TextAttribute.GVT_FONT_FAMILIES);
         Paint forg = (Paint) aci.getAttribute(TextAttribute.FOREGROUND);
         Paint strokePaint;
@@ -103,10 +103,12 @@ public class PDFTextPainter implements TextPainter {
         }
         Stroke stroke = (Stroke) aci.getAttribute(
                           GVTAttributedCharacterIterator.TextAttribute.STROKE);
+        /*
         Float xpos = (Float) aci.getAttribute(
                        GVTAttributedCharacterIterator.TextAttribute.X);
         Float ypos = (Float) aci.getAttribute(
                        GVTAttributedCharacterIterator.TextAttribute.Y);
+        */
 
         Float posture = (Float) aci.getAttribute(TextAttribute.POSTURE);
         Float taWeight = (Float) aci.getAttribute(TextAttribute.WEIGHT);
@@ -149,9 +151,9 @@ public class PDFTextPainter implements TextPainter {
         boolean found = false;
         String fontFamily = null;
         if (gvtFonts != null) {
-            for (Enumeration e = gvtFonts.elements();
-                    e.hasMoreElements();) {
-                GVTFontFamily fam = (GVTFontFamily) e.nextElement();
+            Iterator i = gvtFonts.iterator();
+            while (i.hasNext()) {
+                GVTFontFamily fam = (GVTFontFamily) i.next();
                 if (fam instanceof SVGFontFamily) {
                     PROXY_PAINTER.paint(node, g2d);
                     return;
@@ -160,7 +162,7 @@ public class PDFTextPainter implements TextPainter {
                 if (fi.hasFont(fontFamily, style, weight)) {
                     String fname = fontInfo.fontLookup(fontFamily, style,
                                                        weight);
-                    FontMetric metrics = fontInfo.getMetricsFor(fname);
+                    FontMetrics metrics = fontInfo.getMetricsFor(fname);
                     int fsize = (int)(size.floatValue() * 1000);
                     fontState = new FontState(fname, metrics, fsize);
                     found = true;
@@ -171,7 +173,7 @@ public class PDFTextPainter implements TextPainter {
         if (!found) {
             String fname =
               fontInfo.fontLookup("any", style, FontInfo.NORMAL);
-            FontMetric metrics = fontInfo.getMetricsFor(fname);
+            FontMetrics metrics = fontInfo.getMetricsFor(fname);
             int fsize = (int)(size.floatValue() * 1000);
             fontState = new FontState(fname, metrics, fsize);
         } else {
@@ -245,13 +247,13 @@ public class PDFTextPainter implements TextPainter {
 
     private float getStringWidth(String str, FontState fontState) {
         float wordWidth = 0;
-        float whitespaceWidth = fontState.width(fontState.mapChar(' '));
+        float whitespaceWidth = fontState.getWidth(fontState.mapChar(' '));
 
         for (int i = 0; i < str.length(); i++) {
             float charWidth;
             char c = str.charAt(i);
             if (!((c == ' ') || (c == '\n') || (c == '\r') || (c == '\t'))) {
-                charWidth = fontState.width(fontState.mapChar(c));
+                charWidth = fontState.getWidth(fontState.mapChar(c));
                 if (charWidth <= 0) {
                     charWidth = whitespaceWidth;
                 }
index ce7d67199f2430af96bca89221228f534f75a5a7..8e87f024504af09f6a6bfcfd6b378ffd0eb4c1fd 100644 (file)
@@ -1,45 +1,76 @@
 /*
  * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2003 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.tools;
 
-// FOP
-import org.apache.fop.area.*;
-import org.apache.fop.area.inline.*;
-import org.apache.fop.area.inline.Character;
-import org.apache.fop.render.*;
-import org.apache.fop.render.pdf.*;
-import org.apache.fop.render.svg.*;
-import org.apache.fop.render.xml.*;
-import org.apache.fop.layout.FontInfo;
-import org.apache.fop.layout.FontState;
-import org.apache.fop.layout.FontMetric;
-import org.apache.fop.fo.FOUserAgent;
-import org.apache.fop.fo.properties.RuleStyle;
-
-// Avalon
-import org.apache.avalon.framework.logger.ConsoleLogger;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-
 // Java
-import java.io.*;
-import java.util.*;
 import java.awt.geom.Rectangle2D;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
 import java.util.StringTokenizer;
 
 // JAXP
 import javax.xml.parsers.DocumentBuilderFactory;
 
 // DOM
-import org.w3c.dom.*;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
 
 // Batik
 import org.apache.batik.dom.svg.SVGDOMImplementation;
 
+// FOP
+import org.apache.fop.area.Area;
+import org.apache.fop.area.AreaTree;
+import org.apache.fop.area.AreaTreeModel;
+import org.apache.fop.area.BeforeFloat;
+import org.apache.fop.area.Block;
+import org.apache.fop.area.BodyRegion;
+import org.apache.fop.area.CTM;
+import org.apache.fop.area.Flow;
+import org.apache.fop.area.Footnote;
+import org.apache.fop.area.LineArea;
+import org.apache.fop.area.MainReference;
+import org.apache.fop.area.Page;
+import org.apache.fop.area.PageViewport;
+import org.apache.fop.area.RegionReference;
+import org.apache.fop.area.RegionViewport;
+import org.apache.fop.area.Span;
+import org.apache.fop.area.StorePagesModel;
+import org.apache.fop.area.Title;
+import org.apache.fop.area.Trait;
+import org.apache.fop.area.inline.Character;
+import org.apache.fop.area.inline.Container;
+import org.apache.fop.area.inline.ForeignObject;
+import org.apache.fop.area.inline.Image;
+import org.apache.fop.area.inline.InlineArea;
+import org.apache.fop.area.inline.Leader;
+import org.apache.fop.area.inline.Space;
+import org.apache.fop.area.inline.Viewport;
+import org.apache.fop.area.inline.Word;
+import org.apache.fop.layout.FontInfo;
+import org.apache.fop.layout.FontState;
+import org.apache.fop.render.Renderer;
+import org.apache.fop.render.pdf.PDFRenderer;
+import org.apache.fop.render.svg.SVGRenderer;
+import org.apache.fop.render.xml.XMLRenderer;
+import org.apache.fop.fo.FOUserAgent;
+import org.apache.fop.fo.properties.RuleStyle;
+import org.apache.fop.fonts.FontMetrics;
+
+// Avalon
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+
+
 /**
  * Area tree tester.
  * The purpose of this class is to create and render an area tree
@@ -55,6 +86,8 @@ import org.apache.batik.dom.svg.SVGDOMImplementation;
 public class AreaTreeBuilder extends AbstractLogEnabled {
 
     /**
+     * Main method
+     * @param args command line arguments
      */
     public static void main(String[] args) {
         AreaTreeBuilder atb = new AreaTreeBuilder();
@@ -65,7 +98,10 @@ public class AreaTreeBuilder extends AbstractLogEnabled {
     }
 
     /**
-     *
+     * Run the tests.
+     * @param in input filename
+     * @param type output format
+     * @param out output filename
      */
     protected void runTests(String in, String type, String out) {
         getLogger().debug("Starting tests");
@@ -74,6 +110,10 @@ public class AreaTreeBuilder extends AbstractLogEnabled {
     }
 
     /**
+     * Run a test.
+     * @param in input filename
+     * @param type output format
+     * @param out output filename
      */
     protected void runTest(String in, String type, String out) {
         Renderer rend = null;
@@ -93,10 +133,11 @@ public class AreaTreeBuilder extends AbstractLogEnabled {
 
         StorePagesModel sm = AreaTree.createStorePagesModel();
         TreeLoader tl = new TreeLoader(fi);
+        setupLogger(tl);
         tl.setTreeModel(sm);
         try {
             InputStream is =
-              new BufferedInputStream(new FileInputStream(in));
+              new java.io.BufferedInputStream(new java.io.FileInputStream(in));
             tl.buildAreaTree(is);
             renderAreaTree(sm, rend, out);
         } catch (IOException e) {
@@ -104,11 +145,17 @@ public class AreaTreeBuilder extends AbstractLogEnabled {
         }
     }
 
+    /**
+     * Renders an area tree to a target format using a renderer.
+     * @param sm area tree pages
+     * @param rend renderer to use for output
+     * @param out target filename
+     */
     protected void renderAreaTree(StorePagesModel sm,
                                   Renderer rend, String out) {
         try {
             OutputStream os =
-              new BufferedOutputStream(new FileOutputStream(out));
+              new java.io.BufferedOutputStream(new java.io.FileOutputStream(out));
 
             rend.startRenderer(os);
 
@@ -154,11 +201,11 @@ public class AreaTreeBuilder extends AbstractLogEnabled {
 
 // this loads an area tree from an xml file
 // the xml format is the same as the xml renderer output
-class TreeLoader {
-    AreaTree areaTree;
-    AreaTreeModel model;
-    FontInfo fontInfo;
-    FontState currentFontState;
+class TreeLoader extends AbstractLogEnabled {
+    private AreaTree areaTree;
+    private AreaTreeModel model;
+    private FontInfo fontInfo;
+    private FontState currentFontState;
 
     TreeLoader(FontInfo fi) {
         fontInfo = fi;
@@ -248,7 +295,7 @@ class TreeLoader {
     }
 
     public Page readPage(Element root) {
-        String bounds = root.getAttribute("bounds");
+        //String bounds = root.getAttribute("bounds");
         Page page = new Page();
         NodeList childs = root.getChildNodes();
         for (int i = 0; i < childs.getLength(); i++) {
@@ -362,7 +409,7 @@ class TreeLoader {
     }
 
     List getSpans(Element root) {
-        ArrayList list = new ArrayList();
+        List list = new java.util.ArrayList();
         NodeList childs = root.getChildNodes();
         for (int i = 0; i < childs.getLength(); i++) {
             Node obj = childs.item(i);
@@ -380,7 +427,7 @@ class TreeLoader {
     }
 
     List getFlows(Element root) {
-        ArrayList list = new ArrayList();
+        List list = new java.util.ArrayList();
         NodeList childs = root.getChildNodes();
         for (int i = 0; i < childs.getLength(); i++) {
             Node obj = childs.item(i);
@@ -409,7 +456,7 @@ class TreeLoader {
 
 
     List getBlocks(Element root) {
-        ArrayList list = new ArrayList();
+        List list = new java.util.ArrayList();
         NodeList childs = root.getChildNodes();
         for (int i = 0; i < childs.getLength(); i++) {
             Node obj = childs.item(i);
@@ -460,7 +507,7 @@ class TreeLoader {
 
     // children of element are inline areas
     List getInlineAreas(Element root) {
-        ArrayList list = new ArrayList();
+        List list = new java.util.ArrayList();
         NodeList childs = root.getChildNodes();
         for (int i = 0; i < childs.getLength(); i++) {
             Node obj = childs.item(i);
@@ -469,11 +516,11 @@ class TreeLoader {
                   new Character(getString((Element) obj).charAt(0));
                 addTraits((Element) obj, ch);
                 String fname = fontInfo.fontLookup("sans-serif", "normal", FontInfo.NORMAL);
-                FontMetric metrics = fontInfo.getMetricsFor(fname);
+                FontMetrics metrics = fontInfo.getMetricsFor(fname);
                 currentFontState =
                     new FontState(fname, metrics, 12000);
 
-                ch.setWidth(currentFontState.width(ch.getChar()));
+                ch.setWidth(currentFontState.getWidth(ch.getChar()));
                 ch.setOffset(currentFontState.getCapHeight());
                 list.add(ch);
             } else if (obj.getNodeName().equals("space")) {
@@ -494,7 +541,7 @@ class TreeLoader {
                 }
             } else if (obj.getNodeName().equals("word")) {
                 String fname = fontInfo.fontLookup("sans-serif", "normal", FontInfo.NORMAL);
-                FontMetric metrics = fontInfo.getMetricsFor(fname);
+                FontMetrics metrics = fontInfo.getMetricsFor(fname);
                 currentFontState =
                     new FontState(fname, metrics, 12000);
                 Word word = getWord((Element) obj);
@@ -563,11 +610,11 @@ class TreeLoader {
                           DocumentBuilderFactory.newInstance();
                         fact.setNamespaceAware(true);
 
-                        doc = fact. newDocumentBuilder().newDocument();
+                        doc = fact.newDocumentBuilder().newDocument();
                         Node node = doc.importNode(obj, true);
                         doc.appendChild(node);
-                        DOMImplementation impl =
-                          SVGDOMImplementation.getDOMImplementation();
+                        //DOMImplementation impl =
+                        //  SVGDOMImplementation.getDOMImplementation();
                         // due to namespace problem attributes are not cloned
                         // serializing causes an npe
                         //doc = DOMUtilities.deepCloneDocument(doc, impl);
@@ -582,7 +629,7 @@ class TreeLoader {
                         DocumentBuilderFactory fact =
                           DocumentBuilderFactory.newInstance();
                         fact.setNamespaceAware(true);
-                        doc = fact. newDocumentBuilder().newDocument();
+                        doc = fact.newDocumentBuilder().newDocument();
                         Node node = doc.importNode(obj, true);
                         doc.appendChild(node);
                         ForeignObject fo = new ForeignObject(doc, space);
@@ -638,7 +685,7 @@ class TreeLoader {
         addTraits(root, word);
         int width = 0;
         for (int count = 0; count < str.length(); count++) {
-            width += currentFontState.width(str.charAt(count));
+            width += currentFontState.getWidth(str.charAt(count));
         }
         word.setWidth(width);
         word.setOffset(currentFontState.getCapHeight());
@@ -654,24 +701,23 @@ class TreeLoader {
             String tok = st.nextToken();
             int index = tok.indexOf(":");
             String id = tok.substring(0, index);
-        Object traitCode = Trait.getTraitCode(id);
-        if (traitCode != null) {
-        area.addTrait(traitCode,
-                  Trait.makeTraitValue(traitCode,
-                           tok.substring(index + 1)));
-        }
-        else {
-        System.err.println("Unknown trait: " + id );
-        }
+            Object traitCode = Trait.getTraitCode(id);
+            if (traitCode != null) {
+                area.addTrait(traitCode,
+                      Trait.makeTraitValue(traitCode,
+                               tok.substring(index + 1)));
+            } else {
+                getLogger().error("Unknown trait: " + id);
+            }
         }
     }
 
     public List getRanges(Element ele) {
-        ArrayList list = new ArrayList();
+        List list = new java.util.ArrayList();
         String str = ele.getAttribute("ranges");
         StringTokenizer st = new StringTokenizer(str, ";");
         while (st.hasMoreTokens()) {
-            String tok = st.nextToken();
+            /*String tok =*/ st.nextToken();
         }
         return list;
     }
index 318aee67ecf361739f19551ec38fb28a460fb7ac..4e9078323420f6e7a4b2724d4a58fec7b1a7c08a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * $Id$
- * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
  * For details on use and redistribution please refer to the
  * LICENSE file included with these sources.
  */
@@ -21,21 +21,38 @@ public class CharUtilities {
      */
     public static final char CODE_EOT = 0;
 
-    public static final int UCWHITESPACE = 0; // unicode white space
+    /**
+     * Character class: Unicode white space
+     */
+    public static final int UCWHITESPACE = 0;
+    /**
+     * Character class: Line feed
+     */
     public static final int LINEFEED = 1;
-    public static final int EOT = 2; // Boundary beteween text runs
+    /**
+     * Character class: Boundary between text runs
+     */
+    public static final int EOT = 2;
+    /**
+     * Character class: non-whitespace
+     */
     public static final int NONWHITESPACE = 3;
+    /**
+     * Character class: XML whitespace
+     */
     public static final int XMLWHITESPACE = 4;
 
 
     /**
      * Return the appropriate CharClass constant for the type
      * of the passed character.
+     * @param c character to inspect
+     * @return int the determined character class
      */
     public static int classOf(char c) {
         if (c == CODE_EOT) { return EOT; }
         if (c == '\n') { return LINEFEED; }
-        if (c == ' '|| c == '\r' || c == '\t' ) { return XMLWHITESPACE; }
+        if (c == ' ' || c == '\r' || c == '\t') { return XMLWHITESPACE; }
         if (isAnySpace(c)) { return UCWHITESPACE; }
         return NONWHITESPACE;
     }
@@ -45,6 +62,9 @@ public class CharUtilities {
      * from the current fontstate.
      * This also performs some guessing on widths on various
      * versions of space that might not exists in the font.
+     * @param c character to inspect
+     * @param fs FontState to use
+     * @return int the width of the character
      */
     public static int getCharWidth(char c, FontState fs) {
         int width;
@@ -52,12 +72,12 @@ public class CharUtilities {
         if ((c == '\n') || (c == '\r') || (c == '\t') || (c == '\u00A0')) {
             width = getCharWidth(' ', fs);
         } else {
-            width = fs.width(fs.mapChar(c));
+            width = fs.getWidth(fs.mapChar(c));
             if (width <= 0) {
                 // Estimate the width of spaces not represented in
                 // the font
-                int em = fs.width(fs.mapChar('m'));
-                int en = fs.width(fs.mapChar('n'));
+                int em = fs.getWidth(fs.mapChar('m'));
+                int en = fs.getWidth(fs.mapChar('n'));
                 if (em <= 0) {
                     em = 500 * fs.getFontSize();
                 }
@@ -119,7 +139,9 @@ public class CharUtilities {
     /**
      * Helper method to determine if the character is a
      * space with normal behaviour. Normal behaviour means that
-     * it's not non-breaking
+     * it's not non-breaking.
+     * @param c character to inspect
+     * @return boolean True if the character is a normal space
      */
     public static boolean isSpace(char c) {
         return (c == ' '
@@ -141,6 +163,8 @@ public class CharUtilities {
     /**
      * Method to determine if the character is a nonbreaking
      * space.
+     * @param c character to check
+     * @return boolean True if the character is a nbsp
      */
     public static boolean isNBSP(char c) {
         if (c == '\u00A0' || c == '\u202F'    // narrow no-break space
@@ -153,7 +177,9 @@ public class CharUtilities {
     }
 
     /**
-     * @return true if the character represents any kind of space
+     * Determines if the character represents any kind of space.
+     * @param c character to check
+     * @return True if the character represents any kind of space
      */
     public static boolean isAnySpace(char c) {
         boolean ret = (isSpace(c) || isNBSP(c));