From 9373d427c43ec6be2fa35f199f26292fa9f05f5a Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Wed, 9 Nov 2005 21:17:38 +0000 Subject: [PATCH] Reintroduce encoding feature for Text Renderer that was in the maintenance branch. Configuration layout for the text renderer is: US-ASCII git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@332144 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/render/txt/TXTRenderer.java | 24 +++++++++++++++++++ .../org/apache/fop/render/txt/TXTStream.java | 17 +++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/fop/render/txt/TXTRenderer.java b/src/java/org/apache/fop/render/txt/TXTRenderer.java index a06c815ea..85236a822 100644 --- a/src/java/org/apache/fop/render/txt/TXTRenderer.java +++ b/src/java/org/apache/fop/render/txt/TXTRenderer.java @@ -24,6 +24,8 @@ import java.io.IOException; import java.io.OutputStream; import java.util.List; +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.fop.apps.FOPException; import org.apache.fop.area.Area; import org.apache.fop.area.CTM; @@ -99,12 +101,33 @@ public class TXTRenderer extends AbstractPathOrientedRenderer { /** Saves current coordinate transformation. */ private TXTState currentState = new TXTState(); + private String encoding; + /** * Constructs a newly allocated TXTRenderer object. */ public TXTRenderer() { } + /** @see org.apache.fop.render.AbstractRenderer#getMimeType() */ + public String getMimeType() { + return "text/plain"; + } + + /** @see org.apache.fop.render.AbstractRenderer */ + public void configure(Configuration conf) throws ConfigurationException { + super.configure(conf); + this.encoding = conf.getChild("encoding", true).getValue(null); + } + + /** + * Sets the encoding of the target file. + * @param encoding the encoding, null to select the default encoding (UTF-8) + */ + public void setEncoding(String encoding) { + this.encoding = encoding; + } + /** * Indicates if point (x, y) lay inside currentPage. * @@ -271,6 +294,7 @@ public class TXTRenderer extends AbstractPathOrientedRenderer { log.info("Rendering areas to TEXT."); this.outputStream = os; currentStream = new TXTStream(os); + currentStream.setEncoding(this.encoding); firstPage = true; } diff --git a/src/java/org/apache/fop/render/txt/TXTStream.java b/src/java/org/apache/fop/render/txt/TXTStream.java index f3dc9e194..617acd2a7 100644 --- a/src/java/org/apache/fop/render/txt/TXTStream.java +++ b/src/java/org/apache/fop/render/txt/TXTStream.java @@ -26,8 +26,11 @@ import java.io.OutputStream; */ public class TXTStream { + private static final String DEFAULT_ENCODING = "UTF-8"; + private OutputStream out = null; private boolean doOutput = true; + private String encoding = DEFAULT_ENCODING; /** * Main constructor. @@ -47,7 +50,7 @@ public class TXTStream { } try { - byte[] buff = str.getBytes("UTF-8"); + byte[] buff = str.getBytes(encoding); out.write(buff); } catch (IOException e) { throw new RuntimeException(e.toString()); @@ -61,6 +64,16 @@ public class TXTStream { public void setDoOutput(boolean doout) { doOutput = doout; } - + + /** + * Set the encoding for the text stream. + * @param encoding the encoding, if null, "UTF-8" is chosen as default + */ + public void setEncoding(String encoding) { + if (encoding != null) + this.encoding = encoding; + else + this.encoding = DEFAULT_ENCODING; + } } -- 2.39.5