diff options
author | Keiron Liddle <keiron@apache.org> | 2001-06-26 12:21:45 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2001-06-26 12:21:45 +0000 |
commit | 274457796635ff2e75387080afc3d16c70f32aaf (patch) | |
tree | 7b9b69175e3ea18d6665e38f5aefdd1d786d7d89 /src/org/apache | |
parent | e2f5099ed6725379d33be6bfb0ca517c621cea84 (diff) | |
download | xmlgraphics-fop-274457796635ff2e75387080afc3d16c70f32aaf.tar.gz xmlgraphics-fop-274457796635ff2e75387080afc3d16c70f32aaf.zip |
added initial impl of text painter that uses pdf fonts
rather than stroking
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194317 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache')
-rw-r--r-- | src/org/apache/fop/render/pdf/PDFRenderer.java | 14 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFGraphics2D.java | 45 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFTextPainter.java | 257 |
3 files changed, 306 insertions, 10 deletions
diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index e9d7e4c83..fbb1faebd 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -371,7 +371,7 @@ public class PDFRenderer extends PrintRenderer { 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 @@ public class PDFRenderer extends PrintRenderer { 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 @@ public class PDFRenderer extends PrintRenderer { 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(); diff --git a/src/org/apache/fop/svg/PDFGraphics2D.java b/src/org/apache/fop/svg/PDFGraphics2D.java index e6eab59b8..0993db7f8 100644 --- a/src/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/org/apache/fop/svg/PDFGraphics2D.java @@ -688,6 +688,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { 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 @@ public class PDFGraphics2D extends AbstractGraphics2D { 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 @@ public class PDFGraphics2D extends AbstractGraphics2D { 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"); diff --git a/src/org/apache/fop/svg/PDFTextPainter.java b/src/org/apache/fop/svg/PDFTextPainter.java new file mode 100644 index 000000000..176c8bff8 --- /dev/null +++ b/src/org/apache/fop/svg/PDFTextPainter.java @@ -0,0 +1,257 @@ +/***************************************************************************** + * 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:keiron@aftexsw.com">Keiron Liddle</a> + * @version $Id$ + */ +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; +} + + +} + |