deweese 2005/02/17 03:47:05 Modified: lib pdf-transcoder.jar resources/org/apache/batik/apps/svgbrowser/resources GUI.properties samples starfield.svg sources/org/apache/batik/apps/svgbrowser JSVGViewerFrame.java sources/org/apache/batik/bridge UpdateManager.java sources/org/apache/batik/svggen XmlWriter.java Added: sources/org/apache/batik/apps/svgbrowser SVGOptionPanel.java Log: 1) Can now toggle if xml:base should be added to saved SVG. 2) UpdateManager is now always the 'source' of UpdateManagerEvents previously in some cases it was an inner class. 3) Some refactoring/restructuring of svggen.XmlWriter to potentially make it a pretty printing DOM serializer. 4) Latest pdf-transcoder from FOP which supports '-dpi' switch. PR: 32951, 32435 Revision Changes Path 1.7 +868 -820 xml-batik/lib/pdf-transcoder.jar <<Binary file>> 1.64 +12 -1 xml-batik/resources/org/apache/batik/apps/svgbrowser/resources/GUI.properties Index: GUI.properties =================================================================== RCS file: /home/cvs/xml-batik/resources/org/apache/batik/apps/svgbrowser/resources/GUI.properties,v retrieving revision 1.63 retrieving revision 1.64 diff -u -r1.63 -r1.64 --- GUI.properties 12 Feb 2005 13:04:08 -0000 1.63 +++ GUI.properties 17 Feb 2005 11:47:05 -0000 1.64 @@ -569,6 +569,17 @@ AltFileSystemView.floppy.drive = A: # +# SVGOptionPanel +# +SVGOptionPanel.dialog.title = SVG Save Options +SVGOptionPanel.label = Options for saving SVG +SVGOptionPanel.UseXMLBase = Add "xml:base" attribute to root. +SVGOptionPanel.UseXMLBaseDefault = true +SVGOptionPanel.PrettyPrint = Pretty Print XML (reformats whitespace). +SVGOptionPanel.PrettyPrintDefault = false + + +# # JPEGOptionPanel # 1.8 +3 -2 xml-batik/samples/starfield.svg Index: starfield.svg =================================================================== RCS file: /home/cvs/xml-batik/samples/starfield.svg,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- starfield.svg 18 Aug 2004 07:11:37 -0000 1.7 +++ starfield.svg 17 Feb 2005 11:47:05 -0000 1.8 @@ -195,7 +195,7 @@ } updateText("help", helpText1) - itv = setInterval("animateStars()", 50) + itv = setInterval("animateStars()", 10) startDate = new Date() nframe = 0 @@ -217,6 +217,7 @@ updateText("fps1", val); updateText("fps2", val); + // System.err.println("FPS: " + val); startDate = d nframe = 0 } 1.107 +65 -5 xml-batik/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java Index: JSVGViewerFrame.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java,v retrieving revision 1.106 retrieving revision 1.107 diff -u -r1.106 -r1.107 --- JSVGViewerFrame.java 12 Feb 2005 13:04:08 -0000 1.106 +++ JSVGViewerFrame.java 17 Feb 2005 11:47:05 -0000 1.107 @@ -67,6 +67,7 @@ import javax.swing.Action; import javax.swing.BorderFactory; import javax.swing.ButtonGroup; +import javax.swing.JCheckBox; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JFileChooser; @@ -125,6 +126,8 @@ import org.apache.batik.transcoder.print.PrintTranscoder; import org.apache.batik.util.ParsedURL; import org.apache.batik.util.Service; +import org.apache.batik.util.SVGConstants; +import org.apache.batik.util.XMLConstants; import org.apache.batik.util.gui.DOMViewer; import org.apache.batik.util.gui.JErrorPane; import org.apache.batik.util.gui.LocationBar; @@ -160,6 +163,14 @@ LinkActivationListener, UpdateManagerListener { + static private String EOL; + static { + String temp; + try { temp = System.getProperty ("line.separator", "\n"); } + catch (SecurityException e) { temp = "\n"; } + EOL = temp; + } + /** * Kind of ugly, but we need to know if we are running before * or after 1.4... @@ -1254,23 +1265,32 @@ return; final File f = fileChooser.getSelectedFile(); + + SVGOptionPanel sop; + sop = SVGOptionPanel.showDialog(JSVGViewerFrame.this); + + final boolean useXMLBase = sop.getUseXMLBase(); + final boolean prettyPrint = sop.getPrettyPrint(); + sop = null; + final SVGDocument svgDoc = svgCanvas.getSVGDocument(); if (svgDoc == null) return; statusBar.setMessage(resources.getString("Message.saveAs")); currentSavePath = f; - Writer w = null; + OutputStreamWriter w = null; try { OutputStream tos = null; tos = new FileOutputStream(f); tos = new BufferedOutputStream(tos); - w = new OutputStreamWriter(tos); + w = new OutputStreamWriter(tos, "utf-8"); } catch (Exception ex) { userAgent.displayError(ex); return; } - final Writer writer = w; + final OutputStreamWriter writer = w; + final Runnable doneRun = new Runnable() { public void run() { String doneStr = resources.getString("Message.done"); @@ -1280,8 +1300,48 @@ Runnable r = new Runnable() { public void run() { try { - DOMUtilities.writeDocument(svgDoc, writer); + // Write standard XML header. + writer.write + ("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); + writer.write (EOL); + + Node fc = svgDoc.getFirstChild(); + if (fc.getNodeType() != Node.DOCUMENT_TYPE_NODE) { + // Not DT node in Document, so + // provide Document Type dec. + writer.write ("<!DOCTYPE svg PUBLIC '"); + writer.write (SVGConstants.SVG_PUBLIC_ID); + writer.write ("' '"); + writer.write (SVGConstants.SVG_SYSTEM_ID); + writer.write ("'>"); + writer.write (EOL); + writer.write (EOL); + } + Element root = svgDoc.getRootElement(); + boolean doXMLBase = useXMLBase; + if (root.hasAttributeNS + (XMLConstants.XML_NAMESPACE_URI, "base")) + doXMLBase = false; + + if (doXMLBase) { + root.setAttributeNS + (XMLConstants.XML_NAMESPACE_URI, + "xml:base", + svgDoc.getURL()); + } + + // if (prettyPrint) { + // } else { + DOMUtilities.writeDocument(svgDoc, writer); + // } + writer.close(); + + if (doXMLBase) + root.removeAttributeNS + (XMLConstants.XML_NAMESPACE_URI, + "xml:base"); + if (EventQueue.isDispatchThread()) { doneRun.run(); } else { 1.1 xml-batik/sources/org/apache/batik/apps/svgbrowser/SVGOptionPanel.java Index: SVGOptionPanel.java =================================================================== /* Copyright 2001-2003 The Apache Software Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package org.apache.batik.apps.svgbrowser; import java.awt.Component; import java.awt.BorderLayout; import javax.swing.JLabel; import javax.swing.JCheckBox; /** * This class represents a panel to control svg encoding options. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @version $Id: SVGOptionPanel.java,v 1.1 2005/02/17 11:47:05 deweese Exp $ */ public class SVGOptionPanel extends OptionPanel { /** * The svg encoding options. */ protected JCheckBox xmlbaseCB; protected JCheckBox prettyPrintCB; /** * Creates a new panel. */ public SVGOptionPanel() { super(new BorderLayout()); add(new JLabel(resources.getString("SVGOptionPanel.label")), BorderLayout.NORTH); xmlbaseCB = new JCheckBox (resources.getString("SVGOptionPanel.UseXMLBase")); xmlbaseCB.setSelected (resources.getBoolean("SVGOptionPanel.UseXMLBaseDefault")); add(xmlbaseCB, BorderLayout.CENTER); prettyPrintCB = new JCheckBox (resources.getString("SVGOptionPanel.PrettyPrint")); prettyPrintCB.setSelected (resources.getBoolean("SVGOptionPanel.PrettyPrintDefault")); prettyPrintCB.setEnabled(false); // not supported yet. add(prettyPrintCB, BorderLayout.SOUTH); } /** * Returns true if the output should use xml:base. */ public boolean getUseXMLBase() { return xmlbaseCB.isSelected(); } /** * Returns true if the output should use xml:base. */ public boolean getPrettyPrint() { return prettyPrintCB.isSelected(); } /** * Shows a dialog to choose the jpeg encoding quality and return * the quality as a float. */ public static SVGOptionPanel showDialog(Component parent) { String title = resources.getString("SVGOptionPanel.dialog.title"); SVGOptionPanel panel = new SVGOptionPanel(); Dialog dialog = new Dialog(parent, title, panel); dialog.pack(); dialog.show(); return panel; } } 1.36 +30 -21 xml-batik/sources/org/apache/batik/bridge/UpdateManager.java Index: UpdateManager.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/UpdateManager.java,v retrieving revision 1.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- UpdateManager.java 18 Nov 2004 01:46:54 -0000 1.35 +++ UpdateManager.java 17 Feb 2005 11:47:05 -0000 1.36 @@ -187,11 +187,12 @@ (updateTracker); } - repaintManager = - new RepaintManager(r); + repaintManager = new RepaintManager(r); - fireEvent(startedDispatcher, - new UpdateManagerEvent(this, null, null)); + // Send the UpdateManagerStarted event. + UpdateManagerEvent ev = new UpdateManagerEvent + (UpdateManager.this, null, null); + fireEvent(startedDispatcher, ev); started = true; } } @@ -321,8 +322,9 @@ bridgeContext.dispose(); // Send the UpdateManagerStopped event. - fireEvent(stoppedDispatcher, - new UpdateManagerEvent(this, null, null)); + UpdateManagerEvent ev = new UpdateManagerEvent + (UpdateManager.this, null, null); + fireEvent(stoppedDispatcher, ev); } } }); @@ -377,21 +379,26 @@ protected void updateRendering(List areas, boolean clearPaintingTransform) { try { - fireEvent(updateStartedDispatcher,new UpdateManagerEvent - (this, repaintManager.getOffScreen(), null)); + UpdateManagerEvent ev = new UpdateManagerEvent + (this, repaintManager.getOffScreen(), null); + fireEvent(updateStartedDispatcher, ev); Collection c = repaintManager.updateRendering(areas); List l = new ArrayList(c); - fireEvent(updateCompletedDispatcher,new UpdateManagerEvent - (this, repaintManager.getOffScreen(), l, - clearPaintingTransform)); + + ev = new UpdateManagerEvent + (this, repaintManager.getOffScreen(), + l, clearPaintingTransform); + fireEvent(updateCompletedDispatcher, ev); } catch (ThreadDeath td) { - fireEvent(updateFailedDispatcher, - new UpdateManagerEvent(this, null, null)); + UpdateManagerEvent ev = new UpdateManagerEvent + (this, null, null); + fireEvent(updateFailedDispatcher, ev); throw td; } catch (Throwable t) { - fireEvent(updateFailedDispatcher, - new UpdateManagerEvent(this, null, null)); + UpdateManagerEvent ev = new UpdateManagerEvent + (this, null, null); + fireEvent(updateFailedDispatcher, ev); } } @@ -571,8 +578,9 @@ public void executionSuspended(RunnableQueue rq) { if (suspendCalled) { running = false; - fireEvent(suspendedDispatcher, - new UpdateManagerEvent(this, null, null)); + UpdateManagerEvent ev = new UpdateManagerEvent + (this, null, null); + fireEvent(suspendedDispatcher, ev); } } @@ -582,10 +590,11 @@ public void executionResumed(RunnableQueue rq) { if (suspendCalled && !running) { running = true; - suspendCalled = false; - fireEvent(resumedDispatcher, - new UpdateManagerEvent(this, null, null)); + + UpdateManagerEvent ev = new UpdateManagerEvent + (this, null, null); + fireEvent(resumedDispatcher, ev); } } } 1.11 +150 -45 xml-batik/sources/org/apache/batik/svggen/XmlWriter.java Index: XmlWriter.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/XmlWriter.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- XmlWriter.java 30 Oct 2004 18:38:05 -0000 1.10 +++ XmlWriter.java 17 Feb 2005 11:47:05 -0000 1.11 @@ -50,6 +50,11 @@ static private final String TAG_START = "</"; static private final String SPACE = " "; + static private final char[] SPACES = + { ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' }; + static private final int SPACES_LEN = SPACES.length; + static { String temp; try { temp = System.getProperty ("line.separator", "\n"); } @@ -58,8 +63,9 @@ } static class IndentWriter extends Writer { - private Writer proxied; - private int indentLevel; + protected Writer proxied; + protected int indentLevel; + protected int column; public IndentWriter(Writer proxied){ if (proxied == null) @@ -80,32 +86,45 @@ proxied.write(EOL); int temp = indentLevel; while(temp > 0){ - proxied.write(' '); - temp--; + if (temp > SPACES_LEN) { + proxied.write(SPACES, 0, SPACES_LEN); + temp -= SPACES_LEN; + } else { + proxied.write(SPACES, 0, temp); + break; + } } + column = indentLevel; } public Writer getProxied(){ return proxied; } + public int getColumn() { return column; } + public void write(int c) throws IOException { + column++; proxied.write(c); } public void write(char cbuf[]) throws IOException { + column+=cbuf.length; proxied.write(cbuf); } public void write(char cbuf[], int off, int len) throws IOException{ + column+=len; proxied.write(cbuf, off, len); } public void write(String str) throws IOException { + column+=str.length(); proxied.write(str); } public void write(String str, int off, int len) throws IOException { + column+=len; proxied.write(str, off, len); } @@ -114,11 +133,13 @@ } public void close() throws IOException{ + column = -1; proxied.close(); } } - private static void writeXml(Attr attr, IndentWriter out) throws IOException{ + private static void writeXml(Attr attr, IndentWriter out) + throws IOException{ String name = attr.getName(); out.write (name); out.write ("=\""); @@ -131,18 +152,44 @@ */ private static void writeChildrenXml(Attr attr, IndentWriter out) throws IOException { - String value = attr.getValue(); - for (int i = 0; i < value.length (); i++) { - int c = value.charAt (i); + char data[] = attr.getValue().toCharArray(); + if (data == null) return; + + int length = data.length; + int start=0, last=0; + while (last < length) { + char c = data[last]; switch (c) { - case '<': out.write ("<"); continue; - case '>': out.write (">"); continue; - case '&': out.write ("&"); continue; - case '\'': out.write ("'"); continue; - case '"': out.write ("""); continue; - default: out.write (c); continue; + case '<': + out.write (data, start, last - start); + start = last + 1; + out.write ("<"); + break; + case '>': + out.write (data, start, last - start); + start = last + 1; + out.write (">"); + break; + case '&': + out.write (data, start, last - start); + start = last + 1; + out.write ("&"); + break; + case '\'': + out.write (data, start, last - start); + start = last + 1; + out.write ("'"); + break; + case '"': + out.write (data, start, last - start); + start = last + 1; + out.write ("""); + break; + default: } + last++; } + out.write (data, start, last - start); } /** @@ -152,45 +199,70 @@ */ private static void writeXml(Comment comment, IndentWriter out) throws IOException { + char data[] = comment.getData().toCharArray(); + + if (data == null) { + out.write("<!---->"); + return; + } + out.write ("<!--"); - if (data != null) { - boolean sawDash = false; - int length = data.length; - - // "--" illegal in comments, expand it - for (int i = 0; i < length; i++) { - if (data [i] == '-') { - if (sawDash) - out.write (' '); - else { - sawDash = true; - out.write ('-'); - continue; - } + boolean sawDash = false; + int length = data.length; + int start=0, last=0; + + // "--" illegal in comments, insert a space. + while (last < length) { + char c = data[last]; + if (c == '-') { + if (sawDash) { + out.write (data, start, last - start); + start = last; + out.write (' '); } + sawDash = true; + } else { sawDash = false; - out.write (data [i]); } - if (data [data.length - 1] == '-') - out.write (' '); + last++; } + out.write (data, start, last - start); + if (sawDash) + out.write (' '); out.write ("-->"); } - private static void writeXml(Text text, IndentWriter out) + private static void writeXml(Text text, IndentWriter out) + throws IOException { + writeXml(text, out, false); + } + + private static void writeXml(Text text, IndentWriter out, boolean trimWS) throws IOException { char data[] = text.getData().toCharArray(); - int start = 0, last = 0; // XXX saw this once -- being paranoid if (data == null) { System.err.println ("Null text data??"); return; } - while (last < data.length) { + int length = data.length; + int start = 0, last = 0; + if (trimWS) { + while (last < length) { + char c = data[last]; + switch (c) { + case ' ': case '\t': case '\n': case '\r': last++; continue; + default: break; + } + break; + } + start = last; + } + + while (last < length) { char c = data [last]; - // // escape markup delimiters only ... and do bulk // writes wherever possible, for best performance // @@ -199,18 +271,41 @@ // doing it very generally helps simple parsers // that may not be quite correct. // - if (c == '<') { // not legal in char data + switch(c) { + case ' ': case '\t': case '\n': case '\r': + if (trimWS) { + int wsStart = last; last++; + while (last < length) { + switch(data[last]) { + case ' ': case '\t': case '\n': case '\r': + last++; continue; + default: break; + } + break; + } + if (last == length) { + out.write(data, start, wsStart-start); + return; + } else { + continue; + } + } + break; + case '<': // not legal in char data out.write (data, start, last - start); start = last + 1; out.write ("<"); - } else if (c == '>') { // see above + break; + case '>': // see above out.write (data, start, last - start); start = last + 1; out.write (">"); - } else if (c == '&') { // not legal in char data + break; + case '&': // not legal in char data out.write (data, start, last - start); start = last + 1; out.write ("&"); + break; } last++; } @@ -220,22 +315,32 @@ private static void writeXml(CDATASection cdataSection, IndentWriter out) throws IOException { char[] data = cdataSection.getData().toCharArray(); + if (data == null) { + out.write ("<![CDATA[]]>"); + return; + } + out.write ("<![CDATA["); - for (int i = 0; i < data.length; i++) { - char c = data [i]; + int length = data.length; + int start = 0, last = 0; + while (last < length) { + char c = data [last]; // embedded "]]>" needs to be split into adjacent // CDATA blocks ... can be split at either point if (c == ']') { - if ((i + 2) < data.length - && data [i + 1] == ']' - && data [i + 2] == '>') { + if (((last + 2) < data.length) && + (data [last + 1] == ']') && + (data [last + 2] == '>')) { + out.write (data, start, last - start); + start = last + 1; out.write ("]]]]><![CDATA[>"); continue; } } - out.write (c); + last++; } + out.write (data, start, last - start); out.write ("]]>"); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]