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 Changes Path 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.java 2001/06/18 08:19:20 1.7 +++ PDFGraphics2D.java 2001/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 <tt>Graphic2D</tt> piece-meal. * * @author <a href="mailto:[EMAIL PROTECTED]">Keiron Liddle</a> - * @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; + +//System.out.println("ffn:" + gFont.getFontName() + "fn:" + gFont.getName() + " ff:" + gFont.getFamily() + " fs:" + fontState.getFontName()); + + if ((!name.equals(this.currentFontName)) || + (size != this.currentFontSize)) { + this.currentFontName = name; + this.currentFontSize = size; + currentStream.write("/" + name + " " + size + " Tf\n"); + + } AffineTransform trans = getTransform(); trans.translate(x, y); double[] vals = new double[6]; trans.getMatrix(vals); currentStream.write(PDFNumber.doubleOut(vals[0]) + " " + PDFNumber.doubleOut(vals[1]) + " " -+ PDFNumber.doubleOut(vals[2]) + " " + PDFNumber.doubleOut(vals[3]) + " " + PDFNumber.doubleOut(vals[4]) -+ " " + PDFNumber.doubleOut(vals[5]) + " " + - PDFNumber.doubleOut(vals[6]) + " Tm [" + s + "]"); ++ PDFNumber.doubleOut(vals[2]) + " " + PDFNumber.doubleOut(-vals[3]) + " " + PDFNumber.doubleOut(vals[4]) ++ " " + PDFNumber.doubleOut(vals[5]) + " Tm (" + s + ") Tj\n"); currentStream.write("ET\n"); } @@ -755,10 +781,19 @@ for(char ch = iterator.first(); ch != CharacterIterator.DONE; ch = iterator.next()) { Map attr = iterator.getAttributes(); + String name = fontState.getFontName(); + int size = fontState.getFontSize(); + if ((!name.equals(this.currentFontName)) || + (size != this.currentFontSize)) { + this.currentFontName = name; + this.currentFontSize = size; + currentStream.write("/" + name + " " + (size / 1000) + " Tf\n"); + + } + currentStream.write(PDFNumber.doubleOut(vals[0]) + " " + PDFNumber.doubleOut(vals[1]) + " " + PDFNumber.doubleOut(vals[2]) + " " + PDFNumber.doubleOut(vals[3]) + " " + PDFNumber.doubleOut(vals[4]) -+ " " + PDFNumber.doubleOut(vals[5]) + " " + - PDFNumber.doubleOut(vals[6]) + " Tm [" + ch + "]"); ++ " " + PDFNumber.doubleOut(vals[5]) + " Tm (" + ch + ") Tj\n"); } currentStream.write("ET\n"); 1.1 xml-fop/src/org/apache/fop/svg/PDFTextPainter.java Index: PDFTextPainter.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.fop.svg; import java.awt.Graphics2D; import java.awt.Shape; import java.text.AttributedCharacterIterator; import java.awt.font.FontRenderContext; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.text.AttributedCharacterIterator; import java.text.AttributedString; import java.text.CharacterIterator; import java.awt.font.TextLayout; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import org.apache.batik.gvt.text.Mark; import org.apache.batik.gvt.*; import org.apache.batik.gvt.text.*; import org.apache.batik.gvt.renderer.*; import org.apache.fop.layout.*; /** * Renders the attributed character iterator of a <tt>TextNode</tt>. * * @author <a href="mailto:[EMAIL PROTECTED]">Keiron Liddle</a> * @version $Id: PDFTextPainter.java,v 1.1 2001/06/26 12:21:45 keiron Exp $ */ public class PDFTextPainter implements TextPainter { FontState fontState; public PDFTextPainter(FontState fs) { fontState = fs; } /** * Paints the specified attributed character iterator using the * specified Graphics2D and context and font context. * @param node the TextNode to paint * @param g2d the Graphics2D to use * @param context the rendering context. */ public void paint(TextNode node, Graphics2D g2d, GraphicsNodeRenderContext context) { System.out.println("PDFText paint"); String txt = node.getText(); Point2D loc = node.getLocation(); g2d.drawString(txt, (float)loc.getX(), (float)loc.getY()); } /** * Initiates a text selection on a particular AttributedCharacterIterator, * using the text/font metrics employed by this TextPainter instance. * @param x the x coordinate, in the text layout's coordinate system, * of the selection event. * @param y the y coordinate, in the text layout's coordinate system, * of the selection event. * @param aci the AttributedCharacterIterator describing the text * @param context the GraphicsNodeRenderContext to use when doing text layout. * @return an instance of Mark which encapsulates the state necessary to * implement hit testing and text selection. */ public Mark selectAt(double x, double y, AttributedCharacterIterator aci, TextNode node, GraphicsNodeRenderContext context) { System.out.println("PDFText selectAt"); return null; } /** * Continues a text selection on a particular AttributedCharacterIterator, * using the text/font metrics employed by this TextPainter instance. * @param x the x coordinate, in the text layout's coordinate system, * of the selection event. * @param y the y coordinate, in the text layout's coordinate system, * of the selection event. * @param aci the AttributedCharacterIterator describing the text * @param context the GraphicsNodeRenderContext to use when doing text layout. * @return an instance of Mark which encapsulates the state necessary to * implement hit testing and text selection. */ public Mark selectTo(double x, double y, Mark beginMark, AttributedCharacterIterator aci, TextNode node, GraphicsNodeRenderContext context) { System.out.println("PDFText selectTo"); return null; } /** * Select all of the text represented by an AttributedCharacterIterator, * using the text/font metrics employed by this TextPainter instance. * @param x the x coordinate, in the text layout's coordinate system, * of the selection event. * @param y the y coordinate, in the text layout's coordinate system, * of the selection event. * @param aci the AttributedCharacterIterator describing the text * @param context the GraphicsNodeRenderContext to use when doing text layout. * @return an instance of Mark which encapsulates the state necessary to * implement hit testing and text selection. */ public Mark selectAll(double x, double y, AttributedCharacterIterator aci, TextNode node, GraphicsNodeRenderContext context) { System.out.println("PDFText selectAll"); return null; } /** * Selects the first glyph in the text node. */ public Mark selectFirst(double x, double y, AttributedCharacterIterator aci, TextNode node, GraphicsNodeRenderContext context) { System.out.println("PDFText selectFirst"); return null; } /** * Selects the last glyph in the text node. */ public Mark selectLast(double x, double y, AttributedCharacterIterator aci, TextNode node, GraphicsNodeRenderContext context) { System.out.println("PDFText selectLast"); return null; } /* * Get an array of index pairs corresponding to the indices within an * AttributedCharacterIterator regions bounded by two Marks. * Note that the instances of Mark passed to this function * <em>must come</em> * from the same TextPainter that generated them via selectAt() and * selectTo(), since the TextPainter implementation may rely on hidden * implementation details of its own Mark implementation. */ public int[] getSelected(AttributedCharacterIterator aci, Mark start, Mark finish) { System.out.println("PDFText getSelected"); return null; } /* * Get a Shape in userspace coords which encloses the textnode * glyphs bounded by two Marks. * Note that the instances of Mark passed to this function * <em>must come</em> * from the same TextPainter that generated them via selectAt() and * selectTo(), since the TextPainter implementation may rely on hidden * implementation details of its own Mark implementation. */ public Shape getHighlightShape(Mark beginMark, Mark endMark) { System.out.println("PDFText getHighlightShape"); return null; } /* * Get a Shape in userspace coords which defines the textnode glyph outlines. * @param node the TextNode to measure * @param frc the font rendering context. * @param includeDecoration whether to include text decoration * outlines. * @param includeStroke whether to create the "stroke shape outlines" * instead of glyph outlines. */ public Shape getShape(TextNode node, FontRenderContext frc) { System.out.println("PDFText getShape"); return null; } /* * Get a Shape in userspace coords which defines the textnode glyph outlines. * @param node the TextNode to measure * @param frc the font rendering context. * @param includeDecoration whether to include text decoration * outlines. * @param includeStroke whether to create the "stroke shape outlines" * instead of glyph outlines. */ public Shape getDecoratedShape(TextNode node, FontRenderContext frc) { System.out.println("PDFText getDecoratedShape"); return null; } /* * Get a Rectangle2D in userspace coords which encloses the textnode * glyphs composed from an AttributedCharacterIterator. * @param node the TextNode to measure * @param g2d the Graphics2D to use * @param context rendering context. */ public Rectangle2D getBounds(TextNode node, FontRenderContext frc) { System.out.println("PDFText getBounds"); return null; } /* * Get a Rectangle2D in userspace coords which encloses the textnode * glyphs composed from an AttributedCharacterIterator, inclusive of * glyph decoration (underline, overline, strikethrough). * @param node the TextNode to measure * @param g2d the Graphics2D to use * @param context rendering context. */ public Rectangle2D getDecoratedBounds(TextNode node, FontRenderContext frc) { System.out.println("PDFText getDecoratedBounds"); return null; } /* * Get a Rectangle2D in userspace coords which encloses the * textnode glyphs (as-painted, inclusive of decoration and stroke, but * exclusive of filters, etc.) composed from an AttributedCharacterIterator. * @param node the TextNode to measure * @param g2d the Graphics2D to use * @param context rendering context. */ public Rectangle2D getPaintedBounds(TextNode node, FontRenderContext frc) { System.out.println("PDFText getPaintedBounds"); return null; } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]