Quellcode durchsuchen

TextHandler interface changes, the Graphics2D implementation is now passed to drawString().


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@718591 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-1_0
Adrian Cumiskey vor 15 Jahren
Ursprung
Commit
3c666992c4

BIN
lib/xmlgraphics-commons-1.4svn.jar Datei anzeigen


+ 8
- 8
src/java/org/apache/fop/render/ps/AbstractPSTranscoder.java Datei anzeigen

import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;


import org.w3c.dom.Document;
import org.w3c.dom.svg.SVGLength;

import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.Configuration;
import org.apache.batik.bridge.BridgeContext; import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.bridge.UnitProcessor; import org.apache.batik.bridge.UnitProcessor;
import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderOutput; import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.transcoder.image.ImageTranscoder; import org.apache.batik.transcoder.image.ImageTranscoder;
import org.apache.xmlgraphics.java2d.ps.AbstractPSDocumentGraphics2D;
import org.apache.xmlgraphics.java2d.TextHandler;

import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontSetup; import org.apache.fop.fonts.FontSetup;
import org.apache.fop.svg.AbstractFOPTranscoder; import org.apache.fop.svg.AbstractFOPTranscoder;
import org.apache.xmlgraphics.java2d.TextHandler;
import org.apache.xmlgraphics.java2d.ps.AbstractPSDocumentGraphics2D;
import org.apache.xmlgraphics.ps.PSGenerator;
import org.w3c.dom.Document;
import org.w3c.dom.svg.SVGLength;


/** /**
* This class enables to transcode an input to a PostScript document. * This class enables to transcode an input to a PostScript document.
*/ */
public abstract class AbstractPSTranscoder extends AbstractFOPTranscoder { public abstract class AbstractPSTranscoder extends AbstractFOPTranscoder {


private Configuration cfg = null;
private final Configuration cfg = null;
protected AbstractPSDocumentGraphics2D graphics = null; protected AbstractPSDocumentGraphics2D graphics = null;


/** /**
FontInfo fontInfo = new FontInfo(); FontInfo fontInfo = new FontInfo();
//TODO Do custom font configuration here somewhere/somehow //TODO Do custom font configuration here somewhere/somehow
FontSetup.setup(fontInfo); FontSetup.setup(fontInfo);
graphics.setCustomTextHandler(new NativeTextHandler(graphics, fontInfo));
PSGenerator generator = graphics.getPSGenerator();
graphics.setCustomTextHandler(new NativeTextHandler(generator, fontInfo));
} }


super.transcode(document, uri, output); super.transcode(document, uri, output);

+ 13
- 5
src/java/org/apache/fop/render/ps/NativeTextHandler.java Datei anzeigen



package org.apache.fop.render.ps; package org.apache.fop.render.ps;


import java.awt.Graphics2D;
import java.awt.Shape; import java.awt.Shape;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import java.io.IOException; import java.io.IOException;
*/ */
public class NativeTextHandler implements PSTextHandler { public class NativeTextHandler implements PSTextHandler {


private PSGraphics2D g2d;
private final PSGenerator gen;


/** FontInfo containing all available fonts */ /** FontInfo containing all available fonts */
protected FontInfo fontInfo; protected FontInfo fontInfo;
* @param g2d the PSGraphics2D instance this instances is used by * @param g2d the PSGraphics2D instance this instances is used by
* @param fontInfo the FontInfo object with all available fonts * @param fontInfo the FontInfo object with all available fonts
*/ */
public NativeTextHandler(PSGraphics2D g2d, FontInfo fontInfo) {
this.g2d = g2d;
public NativeTextHandler(PSGenerator gen, FontInfo fontInfo) {
this.gen = gen;
if (fontInfo != null) { if (fontInfo != null) {
this.fontInfo = fontInfo; this.fontInfo = fontInfo;
} else { } else {
} }


private PSGenerator getPSGenerator() { private PSGenerator getPSGenerator() {
return this.g2d.getPSGenerator();
return this.gen;
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
//nop //nop
} }


/** {@inheritDoc} */
public void drawString(String text, float x, float y) throws IOException {
// TODO Remove me after removing the deprecated method in TextHandler.
throw new UnsupportedOperationException("Deprecated method!");
}

/** /**
* Draw a string to the PostScript document. The text is painted using * Draw a string to the PostScript document. The text is painted using
* text operations. * text operations.
* {@inheritDoc} * {@inheritDoc}
*/ */
public void drawString(String s, float x, float y) throws IOException {
public void drawString(Graphics2D g, String s, float x, float y) throws IOException {
PSGraphics2D g2d = (PSGraphics2D)g;
g2d.preparePainting(); g2d.preparePainting();
if (this.overrideFont == null) { if (this.overrideFont == null) {
java.awt.Font awtFont = g2d.getFont(); java.awt.Font awtFont = g2d.getFont();

+ 8
- 9
src/java/org/apache/fop/render/ps/PSSVGHandler.java Datei anzeigen

import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;


import org.w3c.dom.Document;

import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.Configuration;
import org.apache.batik.bridge.BridgeContext; import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.bridge.GVTBuilder; import org.apache.batik.bridge.GVTBuilder;
import org.apache.batik.gvt.GraphicsNode; import org.apache.batik.gvt.GraphicsNode;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;

import org.apache.xmlgraphics.java2d.ps.PSGraphics2D;
import org.apache.xmlgraphics.ps.PSGenerator;

import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.FontInfo;
import org.apache.fop.render.AbstractGenericSVGHandler; import org.apache.fop.render.AbstractGenericSVGHandler;
import org.apache.fop.render.Renderer; import org.apache.fop.render.Renderer;
import org.apache.fop.render.RendererContextConstants; import org.apache.fop.render.RendererContextConstants;
import org.apache.fop.svg.SVGEventProducer; import org.apache.fop.svg.SVGEventProducer;
import org.apache.fop.svg.SVGUserAgent; import org.apache.fop.svg.SVGUserAgent;
import org.apache.xmlgraphics.java2d.ps.PSGraphics2D;
import org.apache.xmlgraphics.ps.PSGenerator;
import org.w3c.dom.Document;


/** /**
* PostScript XML handler for SVG. Uses Apache Batik for SVG processing. * PostScript XML handler for SVG. Uses Apache Batik for SVG processing.
NativeTextHandler nativeTextHandler = null; NativeTextHandler nativeTextHandler = null;
BridgeContext ctx = new BridgeContext(ua); BridgeContext ctx = new BridgeContext(ua);
if (!strokeText) { if (!strokeText) {
nativeTextHandler = new NativeTextHandler(graphics, psInfo.getFontInfo());
PSGenerator generator = graphics.getPSGenerator();
FontInfo fontInfo = psInfo.getFontInfo();
nativeTextHandler = new NativeTextHandler(generator, fontInfo);
graphics.setCustomTextHandler(nativeTextHandler); graphics.setCustomTextHandler(nativeTextHandler);
PSTextPainter textPainter = new PSTextPainter(nativeTextHandler); PSTextPainter textPainter = new PSTextPainter(nativeTextHandler);
ctx.setTextPainter(textPainter); ctx.setTextPainter(textPainter);
float w = (float)ctx.getDocumentSize().getWidth() * 1000f; float w = (float)ctx.getDocumentSize().getWidth() * 1000f;
float h = (float)ctx.getDocumentSize().getHeight() * 1000f; float h = (float)ctx.getDocumentSize().getHeight() * 1000f;


float sx = psInfo.getWidth() / (float)w;
float sy = psInfo.getHeight() / (float)h;
float sx = psInfo.getWidth() / w;
float sy = psInfo.getHeight() / h;


ctx = null; ctx = null;
builder = null; builder = null;

Laden…
Abbrechen
Speichern