jeremias    2003/01/08 06:03:55

  Modified:    src/org/apache/fop/svg PDFTextPainter.java
                        PDFGraphics2D.java
  Log:
  Adjustments for font refactoring
  Lots of Javadocs
  Fixed Checkstyle errors
  
  Revision  Changes    Path
  1.15      +17 -15    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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- PDFTextPainter.java       10 Sep 2002 15:07:13 -0000      1.14
  +++ PDFTextPainter.java       8 Jan 2003 14:03:55 -0000       1.15
  @@ -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.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.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 @@
           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 @@
           }
           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 @@
           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 @@
                   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 @@
           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 @@
   
       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;
                   }
  
  
  
  1.47      +40 -41    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.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- PDFGraphics2D.java        29 Nov 2002 23:18:58 -0000      1.46
  +++ PDFGraphics2D.java        8 Jan 2003 14:03:55 -0000       1.47
  @@ -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.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.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.OutputStream;
   
   import java.util.Map;
  -import java.util.ArrayList;
  -import java.util.HashMap;
  +import java.util.List;
   
   /**
    * PDF Graphics 2D.
  @@ -390,7 +388,7 @@
               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 @@
                           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 @@
                                             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 @@
           }
   
           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 @@
               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 @@
               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 @@
               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 @@
           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 @@
               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 @@
           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 @@
   
           currentStream.write("BT\n");
   
  -        HashMap kerning = null;
  +        Map kerning = null;
           boolean kerningAvailable = false;
   
           kerning = fontState.getKerning();
  @@ -1209,8 +1208,8 @@
   
           // 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 @@
       }
   
       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 @@
   
           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 @@
           }
   
           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 @@
        * @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);
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to