pietsch 2002/07/14 08:34:33 Modified: src/org/apache/fop/apps Tag: fop-0_20_2-maintain CommandLineOptions.java src/org/apache/fop/render/txt Tag: fop-0_20_2-maintain TXTRenderer.java TXTStream.java Log: Command line option for setting encoding of the output file for text renderer. Submitted by: Oleg Tkachenko [EMAIL PROTECTED] Reviewed by: J.Pietschmann Revision Changes Path No revision No revision 1.14.2.5 +17 -4 xml-fop/src/org/apache/fop/apps/CommandLineOptions.java Index: CommandLineOptions.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/apps/CommandLineOptions.java,v retrieving revision 1.14.2.4 retrieving revision 1.14.2.5 diff -u -r1.14.2.4 -r1.14.2.5 --- CommandLineOptions.java 6 Jul 2002 16:43:45 -0000 1.14.2.4 +++ CommandLineOptions.java 14 Jul 2002 15:34:32 -0000 1.14.2.5 @@ -16,6 +16,7 @@ import org.apache.fop.configuration.Configuration; import org.apache.fop.apps.FOPException; import org.apache.fop.messaging.MessageHandler; +import org.apache.fop.render.txt.TXTRenderer; // Avalon import org.apache.avalon.framework.logger.ConsoleLogger; @@ -78,7 +79,7 @@ /* language for user information */ String language = null; - private java.util.Hashtable rendererOptions; + private java.util.HashMap rendererOptions; private Logger log; @@ -88,7 +89,7 @@ setLogger(new ConsoleLogger(ConsoleLogger.LEVEL_INFO)); boolean optionsParsed = true; - rendererOptions = new java.util.Hashtable(); + rendererOptions = new java.util.HashMap(); try { optionsParsed = parseOptions(args); if (optionsParsed) { @@ -252,6 +253,14 @@ outfile = new File(args[i + 1]); i++; } + } else if (args[i].equals("-" + TXTRenderer.encodingOptionName)) { + if ((i + 1 == args.length) + || (args[i + 1].charAt(0) == '-')) { + throw new FOPException("you must specify text renderer encoding"); + } else { + rendererOptions.put(TXTRenderer.encodingOptionName, args[i + 1]); + i++; + } } else { printUsage(); return false; @@ -375,7 +384,7 @@ } } - public java.util.Hashtable getRendererOptions() { + public java.util.HashMap getRendererOptions() { return rendererOptions; } @@ -505,6 +514,8 @@ + " -pcl outfile input will be rendered as pcl file (outfile req'd) \n" + " -ps outfile input will be rendered as PostScript file (outfile req'd) \n" + " -txt outfile input will be rendered as text file (outfile req'd) \n" + + " -"+TXTRenderer.encodingOptionName+" encoding use the encoding for the output file.\n" + + " the encoding must be a valid java encoding.\n" + " -svg outfile input will be rendered as an svg slides file (outfile req'd) \n" + " -at outfile representation of area tree as XML (outfile req'd) \n" + " -print input file will be rendered and sent to the printer \n" @@ -587,6 +598,8 @@ case TXT_OUTPUT: log.debug("txt"); log.debug("output file: " + outfile.toString()); + if (rendererOptions.containsKey(TXTRenderer.encodingOptionName)) + log.debug("output encoding: " + rendererOptions.get(TXTRenderer.encodingOptionName)); break; case SVG_OUTPUT: log.debug("svg"); No revision No revision 1.12.2.3 +10 -1 xml-fop/src/org/apache/fop/render/txt/TXTRenderer.java Index: TXTRenderer.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/txt/TXTRenderer.java,v retrieving revision 1.12.2.2 retrieving revision 1.12.2.3 diff -u -r1.12.2.2 -r1.12.2.3 --- TXTRenderer.java 23 Apr 2002 22:33:40 -0000 1.12.2.2 +++ TXTRenderer.java 14 Jul 2002 15:34:32 -0000 1.12.2.3 @@ -46,6 +46,7 @@ * the current stream to add Text commands to */ TXTStream currentStream; + public static final String encodingOptionName = "txt.encoding"; private int pageHeight = 7920; @@ -1719,6 +1720,14 @@ throws IOException { log.info("rendering areas to TEXT"); currentStream = new TXTStream(outputStream); + String encoding = (String)options.get(encodingOptionName); + try { + byte buff[] = " ".getBytes(encoding); + } catch (java.io.UnsupportedEncodingException uee) { + log.warn("Encoding '"+encoding+"' is not a valid Java encoding. Use UTF-8."); + encoding = "UTF-8"; + } + currentStream.setEncoding(encoding); firstPage=true; } 1.1.4.1 +8 -1 xml-fop/src/org/apache/fop/render/txt/TXTStream.java Index: TXTStream.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/txt/TXTStream.java,v retrieving revision 1.1 retrieving revision 1.1.4.1 diff -u -r1.1 -r1.1.4.1 --- TXTStream.java 31 Jan 2002 18:14:42 -0000 1.1 +++ TXTStream.java 14 Jul 2002 15:34:32 -0000 1.1.4.1 @@ -11,6 +11,7 @@ public class TXTStream { OutputStream out = null; boolean doOutput = true; + private String encoding; public TXTStream(OutputStream os) { out = os; @@ -21,7 +22,7 @@ return; try { - byte buff[] = str.getBytes("UTF-8"); + byte buff[] = str.getBytes(encoding); out.write(buff); } catch (IOException e) { throw new RuntimeException(e.toString()); @@ -32,4 +33,10 @@ doOutput = doout; } + public void setEncoding(String encoding) { + if (encoding != null) + this.encoding = encoding; + else + this.encoding = "UTF-8"; + } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]