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

2003-01-08 Thread jeremias
jeremias2003/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  ChangesPath
  1.15  +17 -15xml-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 -  1.14
  +++ PDFTextPainter.java   8 Jan 2003 14:03:55 -   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 TextNode.
  @@ -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));
  +  

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

2001-06-26 Thread keiron

keiron  01/06/26 05:21:47

  Modified:src/org/apache/fop/render/pdf PDFRenderer.java
   src/org/apache/fop/svg PDFGraphics2D.java
  Added:   src/org/apache/fop/svg PDFTextPainter.java
  Log:
  added initial impl of text painter that uses pdf fonts
  rather than stroking
  
  Revision  ChangesPath
  1.71  +10 -6 xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java
  
  Index: PDFRenderer.java
  ===
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java,v
  retrieving revision 1.70
  retrieving revision 1.71
  diff -u -r1.70 -r1.71
  --- PDFRenderer.java  2001/06/25 14:15:45 1.70
  +++ PDFRenderer.java  2001/06/26 12:21:34 1.71
  @@ -1,4 +1,4 @@
  -/* $Id: PDFRenderer.java,v 1.70 2001/06/25 14:15:45 keiron Exp $
  +/* $Id: PDFRenderer.java,v 1.71 2001/06/26 12:21:34 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."
  @@ -371,7 +371,7 @@
   UserAgent userAgent = new MUserAgent(new AffineTransform());
   
   GVTBuilder builder = new GVTBuilder();
  -GraphicsNodeRenderContext rc = getRenderContext();
  +GraphicsNodeRenderContext rc = getRenderContext(fs);
   BridgeContext ctx = new BridgeContext(userAgent, rc);
   GraphicsNode root;
   PDFGraphics2D graphics =
  @@ -392,7 +392,7 @@
   currentStream.add("Q\n");
   }
   
  -public GraphicsNodeRenderContext getRenderContext() {
  +public GraphicsNodeRenderContext getRenderContext(FontState fs) {
   GraphicsNodeRenderContext nodeRenderContext = null;
   if (nodeRenderContext == null) {
   RenderingHints hints = new RenderingHints(null);
  @@ -406,9 +406,13 @@
 new FontRenderContext(new AffineTransform(), true,
   true);
   
  -TextPainter textPainter = new StrokingTextPainter();
  -//TextPainter textPainter = new PDFTextPainter();
  -
  +TextPainter textPainter = null;
  +Boolean bl = 
org.apache.fop.configuration.Configuration.getBooleanValue("strokeSVGText");
  +if(bl == null || bl.booleanValue()) {
  +textPainter = new StrokingTextPainter();
  +} else {
  +textPainter = new PDFTextPainter(fs);
  +}
   GraphicsNodeRableFactory gnrFactory =
 new ConcreteGraphicsNodeRableFactory();
   
  
  
  
  1.8   +42 -7 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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- PDFGraphics2D.java2001/06/18 08:19:20 1.7
  +++ PDFGraphics2D.java2001/06/26 12:21:43 1.8
  @@ -1,4 +1,4 @@
  -/* $Id: PDFGraphics2D.java,v 1.7 2001/06/18 08:19:20 keiron Exp $
  +/* $Id: PDFGraphics2D.java,v 1.8 2001/06/26 12:21:43 keiron Exp $
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources."
  @@ -38,7 +38,7 @@
* implementing a Graphic2D piece-meal.
*
* @author mailto:[EMAIL PROTECTED]";>Keiron Liddle
  - * @version $Id: PDFGraphics2D.java,v 1.7 2001/06/18 08:19:20 keiron Exp $
  + * @version $Id: PDFGraphics2D.java,v 1.8 2001/06/26 12:21:43 keiron Exp $
* @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D
*/
   public class PDFGraphics2D extends AbstractGraphics2D {
  @@ -688,6 +688,7 @@
   public void drawString(String s, float x, float y) {
   System.out.println("drawString(String)");
   currentStream.write("BT\n");
  +
 Shape imclip = getClip();
 writeClip(imclip);
   Color c = getColor();
  @@ -697,15 +698,40 @@
   PDFColor col = new PDFColor(c.getRed(), c.getGreen(), c.getBlue());
   currentStream.write(col.getColorSpaceOut(false));
   
  +Font gFont = getFont();
  +String name = gFont.getName();
  +if(name.equals("sanserif")) {
  +name = "sans-serif";
  +}
  +int size = gFont.getSize();
  +String style = gFont.isItalic() ? "italic" : "normal";
  +String weight = gFont.isBold() ? "bold" : "normal";
  +try {
  +fontState = new FontState(fontState.getFontInfo(), name,
  +  style, weight, size * 1000, 0);
  +} catch(org.apache.fop.apps.FOPException fope) {
  +fope.printStackTrace();
  +}
  +name = fontState.getFontName();
  +size = fontState.getFontSize() / 1000;