From 035c51def40a853895c816d5c7d296f9d715494f Mon Sep 17 00:00:00 2001 From: Peter Bernard West Date: Wed, 8 May 2002 04:17:21 +0000 Subject: [PATCH] Stripped down experimental environment git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@194802 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/pdf/package.html | 8 - src/org/apache/fop/render/package.html | 6 - src/org/apache/fop/render/pdf/CIDFont.java | 45 - src/org/apache/fop/render/pdf/CMap.java | 12 - src/org/apache/fop/render/pdf/Font.java | 54 - src/org/apache/fop/render/pdf/FontReader.java | 296 --- src/org/apache/fop/render/pdf/FontSetup.java | 211 -- .../apache/fop/render/pdf/PDFRenderer.java | 945 --------- .../apache/fop/render/pdf/fonts/BFEntry.java | 26 - .../apache/fop/render/pdf/fonts/LazyFont.java | 176 -- .../fop/render/pdf/fonts/MultiByteFont.java | 347 ---- .../fop/render/pdf/fonts/SingleByteFont.java | 241 --- .../apache/fop/render/pdf/fonts/package.html | 7 - src/org/apache/fop/render/pdf/package.html | 6 - .../fop/render/ps/ASCII85EncodeFilter.java | 159 -- .../fop/render/ps/ASCIIHexEncodeFilter.java | 69 - src/org/apache/fop/render/ps/Filter.java | 18 - .../apache/fop/render/ps/FilterThread.java | 49 - .../fop/render/ps/FlateEncodeFilter.java | 42 - .../apache/fop/render/ps/PSGraphics2D.java | 940 --------- src/org/apache/fop/render/ps/PSRenderer.java | 1073 ----------- src/org/apache/fop/render/ps/PSStream.java | 25 - .../apache/fop/render/txt/TXTRenderer.java | 1707 ----------------- .../apache/fop/render/xml/XMLRenderer.java | 453 ----- src/org/apache/fop/render/xml/package.html | 6 - src/org/apache/fop/svg/PDFAElementBridge.java | 77 - src/org/apache/fop/svg/PDFANode.java | 47 - .../apache/fop/svg/PDFDocumentGraphics2D.java | 176 -- src/org/apache/fop/svg/PDFGraphics2D.java | 1175 ------------ src/org/apache/fop/svg/PDFTextPainter.java | 359 ---- src/org/apache/fop/svg/PDFTranscoder.java | 490 ----- src/org/apache/fop/svg/SVGArea.java | 61 - src/org/apache/fop/svg/SVGElement.java | 148 -- src/org/apache/fop/svg/SVGElementMapping.java | 85 - src/org/apache/fop/svg/SVGObj.java | 34 - src/org/apache/fop/svg/SVGStringProperty.java | 91 - src/org/apache/fop/svg/SVGUtilities.java | 206 -- src/org/apache/fop/svg/XMLObj.java | 159 -- src/org/apache/fop/svg/package.html | 7 - src/org/apache/fop/system/BufferArray.java | 28 - src/org/apache/fop/system/BufferFile.java | 25 - src/org/apache/fop/system/BufferManager.java | 190 -- src/org/apache/fop/tools/TestConverter.java | 307 --- src/org/apache/fop/viewer/Command.java | 66 - src/org/apache/fop/viewer/GoToPageDialog.java | 110 -- src/org/apache/fop/viewer/IconToolBar.java | 43 - src/org/apache/fop/viewer/Images/Print.gif | Bin 992 -> 0 bytes src/org/apache/fop/viewer/Images/firstpg.gif | Bin 885 -> 0 bytes src/org/apache/fop/viewer/Images/lastpg.gif | Bin 889 -> 0 bytes src/org/apache/fop/viewer/Images/nextpg.gif | Bin 869 -> 0 bytes src/org/apache/fop/viewer/Images/prevpg.gif | Bin 867 -> 0 bytes .../apache/fop/viewer/LoadableProperties.java | 87 - .../apache/fop/viewer/MessageException.java | 78 - src/org/apache/fop/viewer/MessagesDialog.java | 265 --- src/org/apache/fop/viewer/PreviewDialog.java | 638 ------ .../fop/viewer/PreviewDialogAboutBox.java | 105 - .../apache/fop/viewer/ProgressListener.java | 23 - .../fop/viewer/SecureResourceBundle.java | 106 - src/org/apache/fop/viewer/Translator.java | 39 - src/org/apache/fop/viewer/UserMessage.java | 429 ----- .../apache/fop/viewer/resources/messages.de | 78 - .../apache/fop/viewer/resources/messages.en | 80 - .../apache/fop/viewer/resources/resources.de | 45 - .../apache/fop/viewer/resources/resources.en | 4 - .../apache/fop/viewer/resources/resources.fi | 16 - .../apache/fop/viewer/resources/resources.fr | 13 - .../apache/fop/viewer/resources/resources.it | 14 - .../apache/fop/viewer/resources/resources.pl | 17 - .../apache/fop/viewer/resources/resources.ru | 38 - 69 files changed, 12880 deletions(-) delete mode 100644 src/org/apache/fop/pdf/package.html delete mode 100644 src/org/apache/fop/render/package.html delete mode 100644 src/org/apache/fop/render/pdf/CIDFont.java delete mode 100644 src/org/apache/fop/render/pdf/CMap.java delete mode 100644 src/org/apache/fop/render/pdf/Font.java delete mode 100644 src/org/apache/fop/render/pdf/FontReader.java delete mode 100644 src/org/apache/fop/render/pdf/FontSetup.java delete mode 100644 src/org/apache/fop/render/pdf/PDFRenderer.java delete mode 100644 src/org/apache/fop/render/pdf/fonts/BFEntry.java delete mode 100644 src/org/apache/fop/render/pdf/fonts/LazyFont.java delete mode 100644 src/org/apache/fop/render/pdf/fonts/MultiByteFont.java delete mode 100644 src/org/apache/fop/render/pdf/fonts/SingleByteFont.java delete mode 100644 src/org/apache/fop/render/pdf/fonts/package.html delete mode 100644 src/org/apache/fop/render/pdf/package.html delete mode 100644 src/org/apache/fop/render/ps/ASCII85EncodeFilter.java delete mode 100644 src/org/apache/fop/render/ps/ASCIIHexEncodeFilter.java delete mode 100644 src/org/apache/fop/render/ps/Filter.java delete mode 100644 src/org/apache/fop/render/ps/FilterThread.java delete mode 100644 src/org/apache/fop/render/ps/FlateEncodeFilter.java delete mode 100644 src/org/apache/fop/render/ps/PSGraphics2D.java delete mode 100644 src/org/apache/fop/render/ps/PSRenderer.java delete mode 100644 src/org/apache/fop/render/ps/PSStream.java delete mode 100755 src/org/apache/fop/render/txt/TXTRenderer.java delete mode 100644 src/org/apache/fop/render/xml/XMLRenderer.java delete mode 100644 src/org/apache/fop/render/xml/package.html delete mode 100644 src/org/apache/fop/svg/PDFAElementBridge.java delete mode 100644 src/org/apache/fop/svg/PDFANode.java delete mode 100644 src/org/apache/fop/svg/PDFDocumentGraphics2D.java delete mode 100644 src/org/apache/fop/svg/PDFGraphics2D.java delete mode 100644 src/org/apache/fop/svg/PDFTextPainter.java delete mode 100644 src/org/apache/fop/svg/PDFTranscoder.java delete mode 100644 src/org/apache/fop/svg/SVGArea.java delete mode 100644 src/org/apache/fop/svg/SVGElement.java delete mode 100644 src/org/apache/fop/svg/SVGElementMapping.java delete mode 100644 src/org/apache/fop/svg/SVGObj.java delete mode 100644 src/org/apache/fop/svg/SVGStringProperty.java delete mode 100644 src/org/apache/fop/svg/SVGUtilities.java delete mode 100644 src/org/apache/fop/svg/XMLObj.java delete mode 100644 src/org/apache/fop/svg/package.html delete mode 100644 src/org/apache/fop/system/BufferArray.java delete mode 100644 src/org/apache/fop/system/BufferFile.java delete mode 100644 src/org/apache/fop/system/BufferManager.java delete mode 100644 src/org/apache/fop/tools/TestConverter.java delete mode 100644 src/org/apache/fop/viewer/Command.java delete mode 100644 src/org/apache/fop/viewer/GoToPageDialog.java delete mode 100644 src/org/apache/fop/viewer/IconToolBar.java delete mode 100644 src/org/apache/fop/viewer/Images/Print.gif delete mode 100644 src/org/apache/fop/viewer/Images/firstpg.gif delete mode 100644 src/org/apache/fop/viewer/Images/lastpg.gif delete mode 100644 src/org/apache/fop/viewer/Images/nextpg.gif delete mode 100644 src/org/apache/fop/viewer/Images/prevpg.gif delete mode 100644 src/org/apache/fop/viewer/LoadableProperties.java delete mode 100644 src/org/apache/fop/viewer/MessageException.java delete mode 100644 src/org/apache/fop/viewer/MessagesDialog.java delete mode 100644 src/org/apache/fop/viewer/PreviewDialog.java delete mode 100644 src/org/apache/fop/viewer/PreviewDialogAboutBox.java delete mode 100644 src/org/apache/fop/viewer/ProgressListener.java delete mode 100644 src/org/apache/fop/viewer/SecureResourceBundle.java delete mode 100644 src/org/apache/fop/viewer/Translator.java delete mode 100644 src/org/apache/fop/viewer/UserMessage.java delete mode 100644 src/org/apache/fop/viewer/resources/messages.de delete mode 100644 src/org/apache/fop/viewer/resources/messages.en delete mode 100644 src/org/apache/fop/viewer/resources/resources.de delete mode 100644 src/org/apache/fop/viewer/resources/resources.en delete mode 100644 src/org/apache/fop/viewer/resources/resources.fi delete mode 100644 src/org/apache/fop/viewer/resources/resources.fr delete mode 100644 src/org/apache/fop/viewer/resources/resources.it delete mode 100644 src/org/apache/fop/viewer/resources/resources.pl delete mode 100644 src/org/apache/fop/viewer/resources/resources.ru diff --git a/src/org/apache/fop/pdf/package.html b/src/org/apache/fop/pdf/package.html deleted file mode 100644 index 1fd09411d..000000000 --- a/src/org/apache/fop/pdf/package.html +++ /dev/null @@ -1,8 +0,0 @@ - -org.apache.fop.pdf Package - -

Classes for handling the low-level creation of PDF documents

-

These classes were developed for FOP, but could be used by other -applications wishing to produce PDF.

- - \ No newline at end of file diff --git a/src/org/apache/fop/render/package.html b/src/org/apache/fop/render/package.html deleted file mode 100644 index 25daa021e..000000000 --- a/src/org/apache/fop/render/package.html +++ /dev/null @@ -1,6 +0,0 @@ - -org.apache.fop.render Package - -

generic renderer interface

- - \ No newline at end of file diff --git a/src/org/apache/fop/render/pdf/CIDFont.java b/src/org/apache/fop/render/pdf/CIDFont.java deleted file mode 100644 index 0e5c089ac..000000000 --- a/src/org/apache/fop/render/pdf/CIDFont.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.pdf; - -import org.apache.fop.pdf.PDFWArray; - -public abstract class CIDFont extends Font { - - // Required - public abstract String getCidBaseFont(); - public abstract byte getCidType(); - public abstract String getCharEncoding(); - public abstract String getRegistry(); - public abstract String getOrdering(); - public abstract int getSupplement(); - // Optional - public int getDefaultWidth() { - return 0; - } - - public PDFWArray getWidths() { - return null; - } - - // public int getWinCharSet() { return 0; } - - // Need For FOP - - /** - * Returns CMap Object . - *

- * If this method does not return null , the mapping from character codes - * to a font number is performed in FOP . When the getCidType() method - * returns CIDFontType2 , this method must not return null . - */ - public CMap getCMap() { - return null; - } - -} diff --git a/src/org/apache/fop/render/pdf/CMap.java b/src/org/apache/fop/render/pdf/CMap.java deleted file mode 100644 index e7e018a50..000000000 --- a/src/org/apache/fop/render/pdf/CMap.java +++ /dev/null @@ -1,12 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.pdf; - -public interface CMap { - public abstract char mapping(char ch); -} diff --git a/src/org/apache/fop/render/pdf/Font.java b/src/org/apache/fop/render/pdf/Font.java deleted file mode 100644 index d0142ef87..000000000 --- a/src/org/apache/fop/render/pdf/Font.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.pdf; - -// FOP -import org.apache.fop.layout.FontMetric; - -/** - * base class for PDF font classes - */ -public abstract class Font implements FontMetric { - - /** - * get the encoding of the font - */ - public abstract String encoding(); - - /** - * get the base font name - */ - public abstract String fontName(); - - /** - * get the subtype of the font, default is TYPE1 - */ - public byte getSubType() { - return org.apache.fop.pdf.PDFFont.TYPE1; - } - - /** - * Provide a default mapping - */ - public char mapChar(char c) { - // Use default CodePointMapping - if (c > 127) { - char d = org.apache.fop.render.pdf.CodePointMapping.map[c]; - if (d != 0) { - c = d; - } else { - c = '#'; - } - } - return c; - } - -} - - - diff --git a/src/org/apache/fop/render/pdf/FontReader.java b/src/org/apache/fop/render/pdf/FontReader.java deleted file mode 100644 index 132030d92..000000000 --- a/src/org/apache/fop/render/pdf/FontReader.java +++ /dev/null @@ -1,296 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.pdf; -import org.apache.fop.render.pdf.fonts.*; -import org.xml.sax.helpers.DefaultHandler; -import org.xml.sax.XMLReader; -import org.xml.sax.SAXException; -import org.xml.sax.InputSource; -import org.xml.sax.Locator; -import org.xml.sax.Attributes; -import java.io.IOException; -import java.util.Enumeration; -import java.util.Vector; -import java.util.Hashtable; -import org.apache.fop.pdf.PDFWArray; -import org.apache.fop.pdf.PDFCIDFont; -import org.apache.fop.configuration.ConfigurationReader; -import org.apache.fop.apps.FOPException; - -/** - * Class for reading a metric.xml file and creating a font object. - * Typical usage: - *

- * FontReader reader = new FontReader();
- * reader.setFontEmbedPath();
- * reader.useKerning(true);
- * Font f = reader.getFont();
- * 
- */ -public class FontReader extends DefaultHandler { - private Locator locator = null; - private boolean isCID = false; - private MultiByteFont multiFont = null; - private SingleByteFont singleFont = null; - private Font returnFont = null; - // private SingleByteFont singleFont = null; - private String text = null; - - private Vector cidWidths = null; - private int cidWidthIndex = 0; - - private Hashtable currentKerning = null; - - private Vector bfranges = null; - - private void createFont(String path) throws FOPException { - XMLReader parser = ConfigurationReader.createParser(); - if (parser == null) - throw new FOPException("Unable to create SAX parser"); - - try { - parser.setFeature("http://xml.org/sax/features/namespace-prefixes", - false); - } catch (SAXException e) { - throw new FOPException("You need a SAX parser which supports SAX version 2", - e); - } - - parser.setContentHandler(this); - - try { - parser.parse(path); - } catch (SAXException e) { - throw new FOPException(e); - } catch (IOException e) { - throw new FOPException(e); - } - - } - - /** - * Sets the path to embed a font. a null value disables font embedding - */ - public void setFontEmbedPath(String path) { - if (isCID) - multiFont.embedFileName = path; - else - singleFont.embedFileName = path; - } - - /** - * Enable/disable use of kerning for the font - */ - public void useKerning(boolean kern) { - if (isCID) - multiFont.useKerning = true; - else - singleFont.useKerning = true; - } - - - /** - * Get the generated font object - */ - public Font getFont() { - return returnFont; - } - - /** - * Construct a FontReader object from a path to a metric.xml file - * and read metric data - */ - public FontReader(String path) throws FOPException { - createFont(path); - } - - public void startDocument() {} - - public void setDocumentLocator(Locator locator) { - this.locator = locator; - } - - public void startElement(String uri, String localName, String qName, - Attributes attributes) { - if (localName.equals("font-metrics")) { - if ("TYPE0".equals(attributes.getValue("type"))) { - multiFont = new MultiByteFont(); - returnFont = multiFont; - isCID = true; - } else if ("TRUETYPE".equals(attributes.getValue("type"))) { - singleFont = new SingleByteFont(); - singleFont.subType = org.apache.fop.pdf.PDFFont.TRUETYPE; - returnFont = singleFont; - isCID = false; - } else { - singleFont = new SingleByteFont(); - singleFont.subType = org.apache.fop.pdf.PDFFont.TYPE1; - returnFont = singleFont; - isCID = false; - } - } else if ("embed".equals(localName)) { - if (isCID) { - // This *is* annoying... should create a common - // interface for sing/multibytefonts... - multiFont.embedFileName = attributes.getValue("file"); - multiFont.embedResourceName = attributes.getValue("class"); - } else { - singleFont.embedFileName = attributes.getValue("file"); - singleFont.embedResourceName = attributes.getValue("class"); - } - } else if ("cid-widths".equals(localName)) { - cidWidthIndex = getInt(attributes.getValue("start-index")); - cidWidths = new Vector(); - } else if ("kerning".equals(localName)) { - currentKerning = new Hashtable(); - if (isCID) - multiFont.kerning.put(new Integer(attributes.getValue("kpx1")), - currentKerning); - else - singleFont.kerning.put(new Integer(attributes.getValue("kpx1")), - currentKerning); - } else if ("bfranges".equals(localName)) { - bfranges = new Vector(); - } else if ("bf".equals(localName)) { - BFEntry entry = new BFEntry(); - entry.unicodeStart = getInt(attributes.getValue("us")); - entry.unicodeEnd = getInt(attributes.getValue("ue")); - entry.glyphStartIndex = getInt(attributes.getValue("gi")); - bfranges.addElement(entry); - } else if ("wx".equals(localName)) { - cidWidths.addElement(new Integer(attributes.getValue("w"))); - } else if ("widths".equals(localName)) { - singleFont.width = new int[256]; - } else if ("char".equals(localName)) { - try { - singleFont.width[Integer.parseInt(attributes.getValue("idx"))] = - Integer.parseInt(attributes.getValue("wdt")); - } catch (NumberFormatException ne) { - System.out.println("Malformed width in metric file: " - + ne.getMessage()); - } - } else if ("pair".equals(localName)) { - currentKerning.put(new Integer(attributes.getValue("kpx2")), - new Integer(attributes.getValue("kern"))); - } - } - - private int getInt(String str) { - int ret = 0; - try { - ret = Integer.parseInt(str); - } catch (Exception e) {} - return ret; - } - - public void endElement(String uri, String localName, String qName) { - if ("font-name".equals(localName)) - if (isCID) - multiFont.fontName = text; - else - singleFont.fontName = text; - if ("ttc-name".equals(localName) && isCID) - multiFont.ttcName = text; - else if ("cap-height".equals(localName)) - if (isCID) - multiFont.capHeight = getInt(text); - else - singleFont.capHeight = getInt(text); - else if ("x-height".equals(localName)) - if (isCID) - multiFont.xHeight = getInt(text); - else - singleFont.xHeight = getInt(text); - else if ("ascender".equals(localName)) - if (isCID) - multiFont.ascender = getInt(text); - else - singleFont.ascender = getInt(text); - else if ("descender".equals(localName)) - if (isCID) - multiFont.descender = getInt(text); - else - singleFont.descender = getInt(text); - else if ("left".equals(localName)) - if (isCID) - multiFont.fontBBox[0] = getInt(text); - else - singleFont.fontBBox[0] = getInt(text); - else if ("bottom".equals(localName)) - if (isCID) - multiFont.fontBBox[1] = getInt(text); - else - singleFont.fontBBox[1] = getInt(text); - else if ("right".equals(localName)) - if (isCID) - multiFont.fontBBox[2] = getInt(text); - else - singleFont.fontBBox[2] = getInt(text); - else if ("first-char".equals(localName)) - singleFont.firstChar = getInt(text); - else if ("last-char".equals(localName)) - singleFont.lastChar = getInt(text); - else if ("top".equals(localName)) - if (isCID) - multiFont.fontBBox[3] = getInt(text); - else - singleFont.fontBBox[3] = getInt(text); - else if ("flags".equals(localName)) - if (isCID) - multiFont.flags = getInt(text); - else - singleFont.flags = getInt(text); - else if ("stemv".equals(localName)) - if (isCID) - multiFont.stemV = getInt(text); - else - singleFont.stemV = getInt(text); - else if ("italic-angle".equals(localName)) - if (isCID) - multiFont.italicAngle = getInt(text); - else - singleFont.italicAngle = getInt(text); - else if ("missing-width".equals(localName)) - if (isCID) - multiFont.missingWidth = getInt(text); - else - singleFont.missingWidth = getInt(text); - else if ("cid-type".equals(localName)) { - if ("CIDFontType2".equals(text)) - multiFont.cidType = PDFCIDFont.CID_TYPE2; - } else if ("default-width".equals(localName)) { - multiFont.defaultWidth = getInt(text); - } else if ("cid-widths".equals(localName)) { - int[] wds = new int[cidWidths.size()]; - int j = 0; - for (Enumeration e = cidWidths.elements(); - e.hasMoreElements(); ) { - Integer i = (Integer)e.nextElement(); - wds[j++] = i.intValue(); - } - - multiFont.warray.addEntry(cidWidthIndex, wds); - multiFont.width = wds; - - } else if ("bfranges".equals(localName)) { - BFEntry[] entries = new BFEntry[bfranges.size()]; - bfranges.copyInto(entries); - multiFont.bfentries = entries; - } - - } - - public void characters(char[] ch, int start, int length) { - char c[] = new char[length]; - System.arraycopy(ch, start, c, 0, length); - text = new String(c); - } - -} - - diff --git a/src/org/apache/fop/render/pdf/FontSetup.java b/src/org/apache/fop/render/pdf/FontSetup.java deleted file mode 100644 index 00a415230..000000000 --- a/src/org/apache/fop/render/pdf/FontSetup.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.pdf; - -// FOP -import org.apache.fop.render.pdf.fonts.*; -import org.apache.fop.messaging.MessageHandler; -import org.apache.fop.layout.FontInfo; -import org.apache.fop.layout.FontDescriptor; -import org.apache.fop.pdf.PDFDocument; -import org.apache.fop.pdf.PDFResources; -import org.apache.fop.configuration.Configuration; -import org.apache.fop.configuration.FontTriplet; - -// Java -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; - -/** - * sets up the PDF fonts. - * - * Assigns the font (with metrics) to internal names like "F1" and - * assigns family-style-weight triplets to the fonts - */ -public class FontSetup { - - /** - * sets up the font info object. - * - * adds metrics for basic fonts and useful family-style-weight - * triplets for lookup - * - * @param fontInfo the font info object to set up - */ - public static void setup(FontInfo fontInfo) { - MessageHandler.logln("setting up fonts"); - - fontInfo.addMetrics("F1", new Helvetica()); - fontInfo.addMetrics("F2", new HelveticaOblique()); - fontInfo.addMetrics("F3", new HelveticaBold()); - fontInfo.addMetrics("F4", new HelveticaBoldOblique()); - fontInfo.addMetrics("F5", new TimesRoman()); - fontInfo.addMetrics("F6", new TimesItalic()); - fontInfo.addMetrics("F7", new TimesBold()); - fontInfo.addMetrics("F8", new TimesBoldItalic()); - fontInfo.addMetrics("F9", new Courier()); - fontInfo.addMetrics("F10", new CourierOblique()); - fontInfo.addMetrics("F11", new CourierBold()); - fontInfo.addMetrics("F12", new CourierBoldOblique()); - fontInfo.addMetrics("F13", new Symbol()); - fontInfo.addMetrics("F14", new ZapfDingbats()); - - // Custom type 1 fonts step 1/2 - // fontInfo.addMetrics("F15", new OMEP()); - // fontInfo.addMetrics("F16", new GaramondLightCondensed()); - // fontInfo.addMetrics("F17", new BauerBodoniBoldItalic()); - - /* any is treated as serif */ - fontInfo.addFontProperties("F5", "any", "normal", "normal"); - fontInfo.addFontProperties("F6", "any", "italic", "normal"); - fontInfo.addFontProperties("F6", "any", "oblique", "normal"); - fontInfo.addFontProperties("F7", "any", "normal", "bold"); - fontInfo.addFontProperties("F8", "any", "italic", "bold"); - fontInfo.addFontProperties("F8", "any", "oblique", "bold"); - - fontInfo.addFontProperties("F1", "sans-serif", "normal", "normal"); - fontInfo.addFontProperties("F2", "sans-serif", "oblique", "normal"); - fontInfo.addFontProperties("F2", "sans-serif", "italic", "normal"); - fontInfo.addFontProperties("F3", "sans-serif", "normal", "bold"); - fontInfo.addFontProperties("F4", "sans-serif", "oblique", "bold"); - fontInfo.addFontProperties("F4", "sans-serif", "italic", "bold"); - fontInfo.addFontProperties("F5", "serif", "normal", "normal"); - fontInfo.addFontProperties("F6", "serif", "oblique", "normal"); - fontInfo.addFontProperties("F6", "serif", "italic", "normal"); - fontInfo.addFontProperties("F7", "serif", "normal", "bold"); - fontInfo.addFontProperties("F8", "serif", "oblique", "bold"); - fontInfo.addFontProperties("F8", "serif", "italic", "bold"); - fontInfo.addFontProperties("F9", "monospace", "normal", "normal"); - fontInfo.addFontProperties("F10", "monospace", "oblique", "normal"); - fontInfo.addFontProperties("F10", "monospace", "italic", "normal"); - fontInfo.addFontProperties("F11", "monospace", "normal", "bold"); - fontInfo.addFontProperties("F12", "monospace", "oblique", "bold"); - fontInfo.addFontProperties("F12", "monospace", "italic", "bold"); - - fontInfo.addFontProperties("F1", "Helvetica", "normal", "normal"); - fontInfo.addFontProperties("F2", "Helvetica", "oblique", "normal"); - fontInfo.addFontProperties("F2", "Helvetica", "italic", "normal"); - fontInfo.addFontProperties("F3", "Helvetica", "normal", "bold"); - fontInfo.addFontProperties("F4", "Helvetica", "oblique", "bold"); - fontInfo.addFontProperties("F4", "Helvetica", "italic", "bold"); - fontInfo.addFontProperties("F5", "Times", "normal", "normal"); - fontInfo.addFontProperties("F6", "Times", "oblique", "normal"); - fontInfo.addFontProperties("F6", "Times", "italic", "normal"); - fontInfo.addFontProperties("F7", "Times", "normal", "bold"); - fontInfo.addFontProperties("F8", "Times", "oblique", "bold"); - fontInfo.addFontProperties("F8", "Times", "italic", "bold"); - fontInfo.addFontProperties("F9", "Courier", "normal", "normal"); - fontInfo.addFontProperties("F10", "Courier", "oblique", "normal"); - fontInfo.addFontProperties("F10", "Courier", "italic", "normal"); - fontInfo.addFontProperties("F11", "Courier", "normal", "bold"); - fontInfo.addFontProperties("F12", "Courier", "oblique", "bold"); - fontInfo.addFontProperties("F12", "Courier", "italic", "bold"); - fontInfo.addFontProperties("F13", "Symbol", "normal", "normal"); - fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", "normal"); - - // Custom type 1 fonts step 2/2 - // fontInfo.addFontProperties("F15", "OMEP", "normal", "normal"); - // fontInfo.addFontProperties("F16", "Garamond-LightCondensed", "normal", "normal"); - // fontInfo.addFontProperties("F17", "BauerBodoni", "italic", "bold"); - - /* for compatibility with PassiveTex */ - fontInfo.addFontProperties("F5", "Times-Roman", "normal", "normal"); - fontInfo.addFontProperties("F6", "Times-Roman", "oblique", "normal"); - fontInfo.addFontProperties("F6", "Times-Roman", "italic", "normal"); - fontInfo.addFontProperties("F7", "Times-Roman", "normal", "bold"); - fontInfo.addFontProperties("F8", "Times-Roman", "oblique", "bold"); - fontInfo.addFontProperties("F8", "Times-Roman", "italic", "bold"); - fontInfo.addFontProperties("F5", "Times Roman", "normal", "normal"); - fontInfo.addFontProperties("F6", "Times Roman", "oblique", "normal"); - fontInfo.addFontProperties("F6", "Times Roman", "italic", "normal"); - fontInfo.addFontProperties("F7", "Times Roman", "normal", "bold"); - fontInfo.addFontProperties("F8", "Times Roman", "oblique", "bold"); - fontInfo.addFontProperties("F8", "Times Roman", "italic", "bold"); - fontInfo.addFontProperties("F9", "Computer-Modern-Typewriter", - "normal", "normal"); - - /* Add configured fonts */ - addConfiguredFonts(fontInfo, 15); - } - - /** - * Add fonts from configuration file starting with - * internalnames F - */ - public static void addConfiguredFonts(FontInfo fontInfo, int num) { - - String internalName = null; - FontReader reader = null; - - Vector fontInfos = Configuration.getFonts(); - if (fontInfos == null) - return; - - for (Enumeration e = fontInfos.elements(); e.hasMoreElements(); ) { - org.apache.fop.configuration.FontInfo configFontInfo = - (org.apache.fop.configuration.FontInfo)e.nextElement(); - - try { - String metricsFile = configFontInfo.getMetricsFile(); - if (metricsFile != null) { - internalName = "F" + num; - num++; - /* - reader = new FontReader(metricsFile); - reader.useKerning(configFontInfo.getKerning()); - reader.setFontEmbedPath(configFontInfo.getEmbedFile()); - fontInfo.addMetrics(internalName, reader.getFont()); - */ - LazyFont font = new LazyFont(configFontInfo.getEmbedFile(), - metricsFile, - configFontInfo.getKerning()); - fontInfo.addMetrics(internalName, font); - - Vector triplets = configFontInfo.getFontTriplets(); - for (Enumeration t = triplets.elements(); - t.hasMoreElements(); ) { - FontTriplet triplet = (FontTriplet)t.nextElement(); - - fontInfo.addFontProperties(internalName, - triplet.getName(), - triplet.getStyle(), - triplet.getWeight()); - } - } - } catch (Exception ex) { - MessageHandler.error("Failed to read font metrics file " - + configFontInfo.getMetricsFile() - + " : " + ex.getMessage()); - } - } - } - - /** - * add the fonts in the font info to the PDF document - * - * @param doc PDF document to add fonts to - * @param fontInfo font info object to get font information from - */ - public static void addToResources(PDFDocument doc, FontInfo fontInfo) { - Hashtable fonts = fontInfo.getUsedFonts(); - Enumeration e = fonts.keys(); - PDFResources resources = doc.getResources(); - while (e.hasMoreElements()) { - String f = (String)e.nextElement(); - Font font = (Font)fonts.get(f); - FontDescriptor desc = null; - if (font instanceof FontDescriptor) { - desc = (FontDescriptor)font; - } - resources.addFont(doc.makeFont(f, font.fontName(), - font.encoding(), font, desc)); - } - } - -} diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java deleted file mode 100644 index ff59db46e..000000000 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ /dev/null @@ -1,945 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.pdf; - -// FOP -import org.apache.fop.render.PrintRenderer; -import org.apache.fop.messaging.MessageHandler; -import org.apache.fop.image.ImageArea; -import org.apache.fop.image.FopImage; -import org.apache.fop.apps.FOPException; -import org.apache.fop.fo.properties.*; -import org.apache.fop.layout.inline.*; -import org.apache.fop.datatypes.*; -import org.apache.fop.svg.*; -import org.apache.fop.pdf.*; -import org.apache.fop.layout.*; -import org.apache.fop.image.*; -import org.apache.fop.extensions.*; -import org.apache.fop.datatypes.IDReferences; -import org.apache.fop.render.pdf.fonts.LazyFont; - -import org.apache.batik.bridge.*; -import org.apache.batik.swing.svg.*; -import org.apache.batik.swing.gvt.*; -import org.apache.batik.gvt.*; -import org.apache.batik.gvt.renderer.*; -import org.apache.batik.gvt.filter.*; -import org.apache.batik.gvt.event.*; - -import org.w3c.dom.*; -import org.w3c.dom.svg.*; -import org.w3c.dom.css.*; -import org.w3c.dom.svg.SVGLength; - -// Java -import java.io.IOException; -import java.io.OutputStream; -import java.util.Enumeration; -import java.util.Vector; -import java.util.Hashtable; -import java.awt.geom.AffineTransform; -import java.awt.geom.Dimension2D; -import java.awt.Point; -import java.awt.RenderingHints; -import java.awt.font.FontRenderContext; -import java.awt.Dimension; - -/** - * Renderer that renders areas to PDF - * - * Modified by Mark Lillywhite, mark-fop@inomial.com to use the - * new Renderer interface. The PDF renderer is by far the trickiest - * renderer and the best supported by FOP. It also required some - * reworking in the way that Pages, Catalogs and the Root object - * were written to the stream. The output document should now still - * be a 100% compatible PDF document, but hte order of the document - * writing is significantly different. See also the changes - * to PDFPage, PDFPages and PDFRoot. - */ -public class PDFRenderer extends PrintRenderer { - - /** - * the PDF Document being created - */ - protected PDFDocument pdfDoc; - - /** - * the /Resources object of the PDF document being created - */ - protected PDFResources pdfResources; - - /** - * the current stream to add PDF commands to - */ - PDFStream currentStream; - - /** - * the current annotation list to add annotations to - */ - PDFAnnotList currentAnnotList; - - /** - * the current page to add annotations to - */ - PDFPage currentPage; - - PDFColor currentColor; - - /** - * true if a TJ command is left to be written - */ - boolean textOpen = false; - - /** - * the previous Y coordinate of the last word written. - * Used to decide if we can draw the next word on the same line. - */ - int prevWordY = 0; - - /** - * the previous X coordinate of the last word written. - * used to calculate how much space between two words - */ - int prevWordX = 0; - - /** - * The width of the previous word. Used to calculate space between - */ - int prevWordWidth = 0; - - /** - * reusable word area string buffer to reduce memory usage - */ - private StringBuffer _wordAreaPDF = new StringBuffer(); - - /** - * options - */ - protected Hashtable options; - - /** - * create the PDF renderer - */ - public PDFRenderer() { - this.pdfDoc = new PDFDocument(); - } - - /** - * set up renderer options - */ - public void setOptions(Hashtable options) { - this.options = options; - } - - /** - * set the PDF document's producer - * - * @param producer string indicating application producing PDF - */ - public void setProducer(String producer) { - this.pdfDoc.setProducer(producer); - } - - public void startRenderer(OutputStream stream) - throws IOException { - pdfDoc.outputHeader(stream); - } - - public void stopRenderer(OutputStream stream) - throws IOException { - pdfDoc.outputTrailer(stream); - } - - /** - * add a line to the current stream - * - * @param x1 the start x location in millipoints - * @param y1 the start y location in millipoints - * @param x2 the end x location in millipoints - * @param y2 the end y location in millipoints - * @param th the thickness in millipoints - * @param r the red component - * @param g the green component - * @param b the blue component - */ - protected void addLine(int x1, int y1, int x2, int y2, int th, - PDFPathPaint stroke) { - closeText(); - - currentStream.add("ET\nq\n" + stroke.getColorSpaceOut(false) - + (x1 / 1000f) + " " + (y1 / 1000f) + " m " - + (x2 / 1000f) + " " + (y2 / 1000f) + " l " - + (th / 1000f) + " w S\n" + "Q\nBT\n"); - } - - /** - * add a line to the current stream - * - * @param x1 the start x location in millipoints - * @param y1 the start y location in millipoints - * @param x2 the end x location in millipoints - * @param y2 the end y location in millipoints - * @param th the thickness in millipoints - * @param rs the rule style - * @param r the red component - * @param g the green component - * @param b the blue component - */ - protected void addLine(int x1, int y1, int x2, int y2, int th, int rs, - PDFPathPaint stroke) { - closeText(); - currentStream.add("ET\nq\n" + stroke.getColorSpaceOut(false) - + setRuleStylePattern(rs) + (x1 / 1000f) + " " - + (y1 / 1000f) + " m " + (x2 / 1000f) + " " - + (y2 / 1000f) + " l " + (th / 1000f) + " w S\n" - + "Q\nBT\n"); - } - - /** - * add a rectangle to the current stream - * - * @param x the x position of left edge in millipoints - * @param y the y position of top edge in millipoints - * @param w the width in millipoints - * @param h the height in millipoints - * @param stroke the stroke color/gradient - */ - protected void addRect(int x, int y, int w, int h, PDFPathPaint stroke) { - closeText(); - currentStream.add("ET\nq\n" + stroke.getColorSpaceOut(false) - + (x / 1000f) + " " + (y / 1000f) + " " - + (w / 1000f) + " " + (h / 1000f) + " re s\n" - + "Q\nBT\n"); - } - - /** - * add a filled rectangle to the current stream - * - * @param x the x position of left edge in millipoints - * @param y the y position of top edge in millipoints - * @param w the width in millipoints - * @param h the height in millipoints - * @param fill the fill color/gradient - * @param stroke the stroke color/gradient - */ - protected void addRect(int x, int y, int w, int h, PDFPathPaint stroke, - PDFPathPaint fill) { - closeText(); - currentStream.add("ET\nq\n" + fill.getColorSpaceOut(true) - + stroke.getColorSpaceOut(false) + (x / 1000f) - + " " + (y / 1000f) + " " + (w / 1000f) + " " - + (h / 1000f) + " re b\n" + "Q\nBT\n"); - } - - /** - * add a filled rectangle to the current stream - * - * @param x the x position of left edge in millipoints - * @param y the y position of top edge in millipoints - * @param w the width in millipoints - * @param h the height in millipoints - * @param fill the fill color/gradient - */ - protected void addFilledRect(int x, int y, int w, int h, - PDFPathPaint fill) { - closeText(); - currentStream.add("ET\nq\n" + fill.getColorSpaceOut(true) - + (x / 1000f) + " " + (y / 1000f) + " " - + (w / 1000f) + " " + (h / 1000f) + " re f\n" - + "Q\nBT\n"); - } - - /** - * render image area to PDF - * - * @param area the image area to render - */ - public void renderImageArea(ImageArea area) { - // adapted from contribution by BoBoGi - int x = this.currentXPosition + area.getXOffset(); - int y = this.currentYPosition; - int w = area.getContentWidth(); - int h = area.getHeight(); - - this.currentYPosition -= h; - - FopImage img = area.getImage(); - if (img instanceof SVGImage) { - try { - closeText(); - - SVGDocument svg = ((SVGImage)img).getSVGDocument(); - currentStream.add("ET\nq\n"); - renderSVGDocument(svg, (int)x, (int)y, area.getFontState()); - currentStream.add("Q\nBT\n"); - } catch (FopImageException e) {} - - } else { - int xObjectNum = this.pdfDoc.addImage(img); - closeText(); - - currentStream.add("ET\nq\n" + (((float)w) / 1000f) + " 0 0 " - + (((float)h) / 1000f) + " " - + (((float)x) / 1000f) + " " - + (((float)(y - h)) / 1000f) + " cm\n" + "/Im" - + xObjectNum + " Do\nQ\nBT\n"); - } - this.currentXPosition += area.getContentWidth(); - } - - /** - * render a foreign object area - */ - public void renderForeignObjectArea(ForeignObjectArea area) { - // if necessary need to scale and align the content - this.currentXPosition = this.currentXPosition + area.getXOffset(); - this.currentYPosition = this.currentYPosition; - switch (area.getAlign()) { - case TextAlign.START: - break; - case TextAlign.END: - break; - case TextAlign.CENTER: - case TextAlign.JUSTIFY: - break; - } - switch (area.getVerticalAlign()) { - case VerticalAlign.BASELINE: - break; - case VerticalAlign.MIDDLE: - break; - case VerticalAlign.SUB: - break; - case VerticalAlign.SUPER: - break; - case VerticalAlign.TEXT_TOP: - break; - case VerticalAlign.TEXT_BOTTOM: - break; - case VerticalAlign.TOP: - break; - case VerticalAlign.BOTTOM: - break; - } - closeText(); - - // in general the content will not be text - currentStream.add("ET\n"); - // align and scale - currentStream.add("q\n"); - switch (area.scalingMethod()) { - case Scaling.UNIFORM: - break; - case Scaling.NON_UNIFORM: - break; - } - // if the overflow is auto (default), scroll or visible - // then the contents should not be clipped, since this - // is considered a printing medium. - switch (area.getOverflow()) { - case Overflow.VISIBLE: - case Overflow.SCROLL: - case Overflow.AUTO: - break; - case Overflow.HIDDEN: - break; - } - - area.getObject().render(this); - currentStream.add("Q\n"); - currentStream.add("BT\n"); - this.currentXPosition += area.getEffectiveWidth(); - // this.currentYPosition -= area.getEffectiveHeight(); - } - - /** - * render SVG area to PDF - * - * @param area the SVG area to render - */ - public void renderSVGArea(SVGArea area) { - // place at the current instream offset - int x = this.currentXPosition; - int y = this.currentYPosition; - renderSVGDocument(area.getSVGDocument(), x, y, area.getFontState()); - } - - protected void renderSVGDocument(Document doc, int x, int y, - FontState fs) { - SVGSVGElement svg = ((SVGDocument)doc).getRootElement(); - int w = (int)(svg.getWidth().getBaseVal().getValue() * 1000); - int h = (int)(svg.getHeight().getBaseVal().getValue() * 1000); - float sx = 1, sy = -1; - int xOffset = x, yOffset = y; - - /* - * Clip to the svg area. - * Note: To have the svg overlay (under) a text area then use - * an fo:block-container - */ - currentStream.add("q\n"); - if (w != 0 && h != 0) { - currentStream.add(x / 1000f + " " + y / 1000f + " m\n"); - currentStream.add((x + w) / 1000f + " " + y / 1000f + " l\n"); - currentStream.add((x + w) / 1000f + " " + (y - h) / 1000f - + " l\n"); - currentStream.add(x / 1000f + " " + (y - h) / 1000f + " l\n"); - currentStream.add("h\n"); - currentStream.add("W\n"); - currentStream.add("n\n"); - } - // transform so that the coordinates (0,0) is from the top left - // and positive is down and to the right. (0,0) is where the - // viewBox puts it. - currentStream.add(sx + " 0 0 " + sy + " " + xOffset / 1000f + " " - + yOffset / 1000f + " cm\n"); - - - UserAgent userAgent = new MUserAgent(new AffineTransform()); - - GVTBuilder builder = new GVTBuilder(); - GraphicsNodeRenderContext rc = getRenderContext(fs); - BridgeContext ctx = new BridgeContext(userAgent, rc); - PDFAElementBridge aBridge = new PDFAElementBridge(); - ctx.putBridge(aBridge); - GraphicsNode root; - PDFGraphics2D graphics = new PDFGraphics2D(true, fs, pdfDoc, - currentFontName, - currentFontSize, - currentXPosition, - currentYPosition); - graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext()); - graphics.setRenderingHints(rc.getRenderingHints()); - aBridge.setPDFGraphics2D(graphics); - try { - root = builder.build(ctx, doc); - root.paint(graphics, rc); - currentStream.add(graphics.getString()); - } catch (Exception e) { - MessageHandler.errorln("Error: svg graphic could not be rendered: " - + e.getMessage()); - } - - currentStream.add("Q\n"); - } - - public GraphicsNodeRenderContext getRenderContext(FontState fs) { - GraphicsNodeRenderContext nodeRenderContext = null; - if (nodeRenderContext == null) { - RenderingHints hints = new RenderingHints(null); - hints.put(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - - hints.put(RenderingHints.KEY_INTERPOLATION, - RenderingHints.VALUE_INTERPOLATION_BILINEAR); - - FontRenderContext fontRenderContext = - new FontRenderContext(new AffineTransform(), true, true); - - 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(); - - nodeRenderContext = - new GraphicsNodeRenderContext(new AffineTransform(), null, - hints, fontRenderContext, - textPainter, gnrFactory); - nodeRenderContext.setTextPainter(textPainter); - } - - return nodeRenderContext; - } - - /** - * render inline area to PDF - * - * @param area inline area to render - */ - public void renderWordArea(WordArea area) { - synchronized (_wordAreaPDF) { - StringBuffer pdf = _wordAreaPDF; - pdf.setLength(0); - - Hashtable kerning = null; - boolean kerningAvailable = false; - - kerning = area.getFontState().getKerning(); - if (kerning != null &&!kerning.isEmpty()) { - kerningAvailable = true; - } - - String name = area.getFontState().getFontName(); - int size = area.getFontState().getFontSize(); - - // This assumes that *all* CIDFonts use a /ToUnicode mapping - boolean useMultiByte = false; - Font f = - (Font)area.getFontState().getFontInfo().getFonts().get(name); - if (f instanceof LazyFont){ - if(((LazyFont) f).getRealFont() instanceof CIDFont){ - useMultiByte = true; - } - }else if (f instanceof CIDFont){ - useMultiByte = true; - } - // String startText = useMultiByte ? " " : ") "; - - if ((!name.equals(this.currentFontName)) - || (size != this.currentFontSize)) { - closeText(); - - this.currentFontName = name; - this.currentFontSize = size; - pdf = pdf.append("/" + name + " " + (size / 1000) + " Tf\n"); - } - - PDFColor areaColor = null; - if (this.currentFill instanceof PDFColor) { - areaColor = (PDFColor)this.currentFill; - } - - if (areaColor == null || areaColor.red() != (double)area.getRed() - || areaColor.green() != (double)area.getGreen() - || areaColor.blue() != (double)area.getBlue()) { - - areaColor = new PDFColor((double)area.getRed(), - (double)area.getGreen(), - (double)area.getBlue()); - - - closeText(); - this.currentFill = areaColor; - pdf.append(this.currentFill.getColorSpaceOut(true)); - } - - - int rx = this.currentXPosition; - int bl = this.currentYPosition; - - addWordLines(area, rx, bl, size, areaColor); - - - if (!textOpen || bl != prevWordY) { - closeText(); - - pdf.append("1 0 0 1 " + (rx / 1000f) + " " + (bl / 1000f) - + " Tm [" + startText); - prevWordY = bl; - textOpen = true; - } else { - // express the space between words in thousandths of an em - int space = prevWordX - rx + prevWordWidth; - float emDiff = (float)space / (float)currentFontSize * 1000f; - // this prevents a problem in Acrobat Reader where large - // numbers cause text to disappear or default to a limit - if (emDiff < -33000) { - closeText(); - - pdf.append("1 0 0 1 " + (rx / 1000f) + " " + (bl / 1000f) - + " Tm [" + startText); - textOpen = true; - } else { - pdf.append(Float.toString(emDiff)); - pdf.append(" "); - pdf.append(startText); - } - } - prevWordWidth = area.getContentWidth(); - prevWordX = rx; - - - String s; - if (area.getPageNumberID() - != null) { // this text is a page number, so resolve it - s = idReferences.getPageNumber(area.getPageNumberID()); - if (s == null) { - s = ""; - } - } else { - s = area.getText(); - } - - int l = s.length(); - - for (int i = 0; i < l; i++) { - char ch = area.getFontState().mapChar(s.charAt(i)); - - if (!useMultiByte) { - if (ch > 127) { - pdf.append("\\"); - pdf.append(Integer.toOctalString((int)ch)); - - } else { - switch (ch) { - case '(': - case ')': - case '\\': - pdf.append("\\"); - break; - } - pdf.append(ch); - } - } else { - pdf.append(getUnicodeString(ch)); - } - - if (kerningAvailable && (i + 1) < l) { - addKerning(pdf, (new Integer((int)ch)), - (new Integer((int)area.getFontState().mapChar(s.charAt(i + 1)))), - kerning, startText, endText); - } - - } - pdf.append(endText); - - currentStream.add(pdf.toString()); - - this.currentXPosition += area.getContentWidth(); - - } - } - - - - /** - * Convert a char to a multibyte hex representation - */ - private String getUnicodeString(char c) { - - StringBuffer buf = new StringBuffer(4); - - byte[] uniBytes = null; - try { - char[] a = { - c - }; - uniBytes = new String(a).getBytes("UnicodeBigUnmarked"); - } catch (Exception e) { - // This should never fail - } - - - for (int i = 0; i < uniBytes.length; i++) { - int b = (uniBytes[i] < 0) ? (int)(256 + uniBytes[i]) - : (int)uniBytes[i]; - - String hexString = Integer.toHexString(b); - if (hexString.length() == 1) - buf = buf.append("0" + hexString); - else - buf = buf.append(hexString); - } - - return buf.toString(); - - } - - - /** - * Checks to see if we have some text rendering commands open - * still and writes out the TJ command to the stream if we do - */ - private void closeText() { - if (textOpen) { - currentStream.add("] TJ\n"); - textOpen = false; - prevWordX = 0; - prevWordY = 0; - } - } - - private void addKerning(StringBuffer buf, Integer ch1, Integer ch2, - Hashtable kerning, String startText, - String endText) { - Hashtable kernPair = (Hashtable)kerning.get(ch1); - - if (kernPair != null) { - Integer width = (Integer)kernPair.get(ch2); - if (width != null) { - buf.append(endText).append(-(width.intValue())).append(' ').append(startText); - } - } - } - - public void render(Page page, OutputStream outputStream) - throws FOPException, IOException { - // MessageHandler.logln("rendering single page to PDF"); - this.idReferences = page.getIDReferences(); - this.pdfResources = this.pdfDoc.getResources(); - this.pdfDoc.setIDReferences(idReferences); - this.renderPage(page); - - FontSetup.addToResources(this.pdfDoc, fontInfo); - - // TODO: this needs to be implemented - renderRootExtensions(page); - - // MessageHandler.logln("writing out PDF"); - this.pdfDoc.output(outputStream); - } - - /** - * render page into PDF - * - * @param page page to render - */ - public void renderPage(Page page) { - BodyAreaContainer body; - AreaContainer before, after, start, end; - - currentStream = this.pdfDoc.makeStream(); - body = page.getBody(); - before = page.getBefore(); - after = page.getAfter(); - start = page.getStart(); - end = page.getEnd(); - - this.currentFontName = ""; - this.currentFontSize = 0; - - currentStream.add("BT\n"); - - renderBodyAreaContainer(body); - - if (before != null) { - renderAreaContainer(before); - } - - if (after != null) { - renderAreaContainer(after); - } - - if (start != null) { - renderAreaContainer(start); - } - - if (end != null) { - renderAreaContainer(end); - } - closeText(); - - currentStream.add("ET\n"); - - currentPage = this.pdfDoc.makePage(this.pdfResources, currentStream, - page.getWidth() / 1000, - page.getHeight() / 1000, page); - - if (page.hasLinks()) { - currentAnnotList = this.pdfDoc.makeAnnotList(); - currentPage.setAnnotList(currentAnnotList); - - Enumeration e = page.getLinkSets().elements(); - while (e.hasMoreElements()) { - LinkSet linkSet = (LinkSet)e.nextElement(); - - linkSet.align(); - String dest = linkSet.getDest(); - int linkType = linkSet.getLinkType(); - Enumeration f = linkSet.getRects().elements(); - while (f.hasMoreElements()) { - LinkedRectangle lrect = (LinkedRectangle)f.nextElement(); - currentAnnotList.addLink(this.pdfDoc.makeLink(lrect.getRectangle(), - dest, linkType)); - } - } - } else { - // just to be on the safe side - currentAnnotList = null; - } - - // ensures that color is properly reset for blocks that carry over pages - this.currentFill = null; - } - - /** - * defines a string containing dashArray and dashPhase for the rule style - */ - private String setRuleStylePattern(int style) { - String rs = ""; - switch (style) { - case org.apache.fop.fo.properties.RuleStyle.SOLID: - rs = "[] 0 d "; - break; - case org.apache.fop.fo.properties.RuleStyle.DASHED: - rs = "[3 3] 0 d "; - break; - case org.apache.fop.fo.properties.RuleStyle.DOTTED: - rs = "[1 3] 0 d "; - break; - case org.apache.fop.fo.properties.RuleStyle.DOUBLE: - rs = "[] 0 d "; - break; - default: - rs = "[] 0 d "; - } - return rs; - } - - protected void renderRootExtensions(Page page) { - Vector v = page.getExtensions(); - if (v != null) { - Enumeration e = v.elements(); - while (e.hasMoreElements()) { - ExtensionObj ext = (ExtensionObj)e.nextElement(); - if (ext instanceof Outline) { - renderOutline((Outline)ext); - } - } - } - - } - - private void renderOutline(Outline outline) { - PDFOutline outlineRoot = pdfDoc.getOutlineRoot(); - PDFOutline pdfOutline = null; - Outline parent = outline.getParentOutline(); - if (parent == null) { - pdfOutline = - this.pdfDoc.makeOutline(outlineRoot, - outline.getLabel().toString(), - outline.getInternalDestination()); - } else { - PDFOutline pdfParentOutline = - (PDFOutline)parent.getRendererObject(); - if (pdfParentOutline == null) { - MessageHandler.errorln("Error: pdfParentOutline is null"); - } else { - pdfOutline = - this.pdfDoc.makeOutline(pdfParentOutline, - outline.getLabel().toString(), - outline.getInternalDestination()); - } - - } - outline.setRendererObject(pdfOutline); - - // handle sub outlines - Vector v = outline.getOutlines(); - Enumeration e = v.elements(); - while (e.hasMoreElements()) { - renderOutline((Outline)e.nextElement()); - } - } - - protected class MUserAgent implements UserAgent { - AffineTransform currentTransform = null; - - /** - * Creates a new SVGUserAgent. - */ - protected MUserAgent(AffineTransform at) { - currentTransform = at; - } - - /** - * Displays an error message. - */ - public void displayError(String message) { - System.err.println(message); - } - - /** - * Displays an error resulting from the specified Exception. - */ - public void displayError(Exception ex) { - ex.printStackTrace(System.err); - } - - /** - * Displays a message in the User Agent interface. - * The given message is typically displayed in a status bar. - */ - public void displayMessage(String message) { - System.out.println(message); - } - - /** - * Returns a customized the pixel to mm factor. - */ - public float getPixelToMM() { - // this is set to 72dpi as the values in fo are 72dpi - return 0.35277777777777777778f; // 72 dpi - // return 0.26458333333333333333333333333333f; // 96dpi - } - - /** - * Returns the language settings. - */ - public String getLanguages() { - return "en"; // userLanguages; - } - - /** - * Returns the user stylesheet uri. - * @return null if no user style sheet was specified. - */ - public String getUserStyleSheetURI() { - return null; // userStyleSheetURI; - } - - /** - * Returns the class name of the XML parser. - */ - public String getXMLParserClassName() { - return org.apache.fop.apps.Driver.getParserClassName(); - } - - /** - * Opens a link in a new component. - * @param doc The current document. - * @param uri The document URI. - */ - public void openLink(SVGAElement elt) { - // application.openLink(uri); - } - - - public Point getClientAreaLocationOnScreen() { - return new Point(0, 0); - } - - public void setSVGCursor(java.awt.Cursor cursor) {} - - - public AffineTransform getTransform() { - return currentTransform; - } - - public Dimension2D getViewportSize() { - return new Dimension(100, 100); - } - - public EventDispatcher getEventDispatcher() { - return null; - } - - public boolean supportExtension(String str) { - return false; - } - - public boolean hasFeature(String str) { - return false; - } - - public void registerExtension(BridgeExtension be) {} - - public void handleElement(Element elt, Object data) {} - - - } -} diff --git a/src/org/apache/fop/render/pdf/fonts/BFEntry.java b/src/org/apache/fop/render/pdf/fonts/BFEntry.java deleted file mode 100644 index 4f3fc2376..000000000 --- a/src/org/apache/fop/render/pdf/fonts/BFEntry.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.pdf.fonts; - -/** - * This is just a holder class for bfentries - not get/put methods provided - */ -public class BFEntry { - public int unicodeStart; - public int unicodeEnd; - public int glyphStartIndex; - - public BFEntry() {} - - public BFEntry(int unicodeStart, int unicodeEnd, int glyphStartIndex) { - this.unicodeStart = unicodeStart; - this.unicodeEnd = unicodeEnd; - this.glyphStartIndex = glyphStartIndex; - } - -} diff --git a/src/org/apache/fop/render/pdf/fonts/LazyFont.java b/src/org/apache/fop/render/pdf/fonts/LazyFont.java deleted file mode 100644 index 80faae2de..000000000 --- a/src/org/apache/fop/render/pdf/fonts/LazyFont.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.pdf.fonts; - -import org.apache.fop.render.pdf.Font; -import org.apache.fop.layout.FontDescriptor; -import org.apache.fop.pdf.PDFStream; -import org.apache.fop.messaging.MessageHandler; -import java.util.Hashtable; - -import org.apache.fop.render.pdf.FontReader; - -public class LazyFont extends Font implements FontDescriptor { - - private String metricsFileName = null; - private String fontEmbedPath = null; - private boolean useKerning = false; - - private boolean isMetricsLoaded = false; - private Font realFont = null; - private FontDescriptor realFontDescriptor = null; - - public LazyFont(String fontEmbedPath, String metricsFileName, boolean useKerning){ - this.metricsFileName = metricsFileName; - this.fontEmbedPath = fontEmbedPath; - this.useKerning = useKerning; - } - - private void load(){ - if(! isMetricsLoaded){ - try{ - FontReader reader = new FontReader(metricsFileName); - reader.useKerning(useKerning); - reader.setFontEmbedPath(fontEmbedPath); - realFont = reader.getFont(); - if(realFont instanceof FontDescriptor){ - realFontDescriptor = (FontDescriptor) realFont; - } - isMetricsLoaded = true; - // System.out.println("Metrics " + metricsFileName + " loaded."); - } catch (Exception ex) { - MessageHandler.error("Failed to read font metrics file " - + metricsFileName - + " : " + ex.getMessage()); - } - } - } - - public Font getRealFont(){ - return realFont; - } - - // Font - public String encoding(){ - load(); - return realFont.encoding(); - } - - public String fontName(){ - load(); - return realFont.fontName(); - } - - public byte getSubType(){ - load(); - return realFont.getSubType(); - } - - public char mapChar(char c){ - load(); - return realFont.mapChar(c); - } - - // FontMetrics - public int getAscender(int size){ - load(); - return realFont.getAscender(size); - } - - public int getCapHeight(int size){ - load(); - return realFont.getCapHeight(size); - } - - public int getDescender(int size){ - load(); - return realFont.getDescender(size); - } - - public int getXHeight(int size){ - load(); - return realFont.getXHeight(size); - } - - public int getFirstChar(){ - load(); - return realFont.getFirstChar(); - } - - public int getLastChar(){ - load(); - return realFont.getLastChar(); - } - - public int width(int i, int size){ - load(); - return realFont.width(i, size); - } - - public int[] getWidths(int size){ - load(); - return realFont.getWidths(size); - } - - // FontDescriptor - public int getCapHeight(){ - load(); - return realFontDescriptor.getCapHeight(); - } - - public int getDescender(){ - load(); - return realFontDescriptor.getDescender(); - } - - public int getAscender(){ - load(); - return realFontDescriptor.getAscender(); - } - - public int getFlags(){ - load(); - return realFontDescriptor.getFlags(); - } - - public int[] getFontBBox(){ - load(); - return realFontDescriptor.getFontBBox(); - } - - public int getItalicAngle(){ - load(); - return realFontDescriptor.getItalicAngle(); - } - - public int getStemV(){ - load(); - return realFontDescriptor.getStemV(); - } - - public boolean hasKerningInfo(){ - load(); - return realFontDescriptor.hasKerningInfo(); - } - - public Hashtable getKerningInfo(){ - load(); - return realFontDescriptor.getKerningInfo(); - } - - public boolean isEmbeddable(){ - load(); - return realFontDescriptor.isEmbeddable(); - } - - public PDFStream getFontFile(int objNum){ - load(); - return realFontDescriptor.getFontFile(objNum); - } -} - diff --git a/src/org/apache/fop/render/pdf/fonts/MultiByteFont.java b/src/org/apache/fop/render/pdf/fonts/MultiByteFont.java deleted file mode 100644 index 7a667d79b..000000000 --- a/src/org/apache/fop/render/pdf/fonts/MultiByteFont.java +++ /dev/null @@ -1,347 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.pdf.fonts; - -import org.apache.fop.render.pdf.Font; -import org.apache.fop.layout.FontDescriptor; -import org.apache.fop.fonts.Glyphs; -import org.apache.fop.fonts.TTFSubSetFile; -import org.apache.fop.fonts.FontFileReader; -import org.apache.fop.pdf.PDFStream; -import org.apache.fop.pdf.PDFWArray; -import org.apache.fop.pdf.PDFCIDFont; -import org.apache.fop.render.pdf.CIDFont; -import org.apache.fop.render.pdf.CMap; -import org.apache.fop.pdf.PDFTTFStream; -import org.apache.fop.messaging.MessageHandler; -import java.io.InputStream; -import java.io.IOException; -import java.io.FileInputStream; -import java.io.File; -import java.io.BufferedInputStream; -import java.util.Hashtable; - -/** - * Generic MultiByte (CID) font - */ -public class MultiByteFont extends CIDFont implements FontDescriptor { - public String fontName = null; - public String ttcName = null; - public String encoding = "Identity-H"; - - public int capHeight = 0; - public int xHeight = 0; - public int ascender = 0; - public int descender = 0; - public int[] fontBBox = { - 0, 0, 0, 0 - }; - - public String embedFileName = null; - public String embedResourceName = null; - public PDFTTFStream embeddedFont = null; - - public int flags = 4; - public int stemV = 0; - public int italicAngle = 0; - public int missingWidth = 0; - public int defaultWidth = 0; - public byte cidType = PDFCIDFont.CID_TYPE2; - - public Hashtable kerning = new Hashtable(); - public boolean useKerning = true; - private String namePrefix = null; // Quasi unique prefix - private static int uniqueCounter = 1; - public PDFWArray warray = new PDFWArray(); - public int width[] = null; - - public BFEntry[] bfentries = null; - - - /** - * usedGlyphs contains orginal, new glyph index - */ - private Hashtable usedGlyphs = new Hashtable(); - - /** - * usedGlyphsIndex contains new glyph, original index - */ - private Hashtable usedGlyphsIndex = new Hashtable(); - int usedGlyphsCount = 0; - - public MultiByteFont() { - // Make sure that the 3 first glyphs are included - usedGlyphs.put(new Integer(0), new Integer(0)); - usedGlyphsIndex.put(new Integer(0), new Integer(0)); - usedGlyphsCount++; - usedGlyphs.put(new Integer(1), new Integer(1)); - usedGlyphsIndex.put(new Integer(1), new Integer(1)); - usedGlyphsCount++; - usedGlyphs.put(new Integer(2), new Integer(2)); - usedGlyphsIndex.put(new Integer(2), new Integer(2)); - usedGlyphsCount++; - - // Create a quasiunique prefix for fontname - int cnt = 0; - synchronized (this.getClass()) { - cnt = uniqueCounter++; - } - int ctm = (int)(System.currentTimeMillis() & 0xffff); - namePrefix = new String(cnt + "E" + Integer.toHexString(ctm)); - } - - public final boolean hasKerningInfo() { - return (useKerning & kerning.isEmpty()); - } - - public final java.util.Hashtable getKerningInfo() { - if (useKerning) - return kerning; - else - return new Hashtable(); - } - - public byte getSubType() { - return org.apache.fop.pdf.PDFFont.TYPE0; - } - - public String getLang() { - return null; - } - - public String getPanose() { - return null; - } - - public int getAvgWidth() { - return -1; - } - - public int getMinWidth() { - return -1; - } - - public int getMaxWidth() { - return -1; - } - - public int getleading() { - return -1; - } - - public int getStemH() { - return 0; - } - - public int getMissingWidth() { - return missingWidth; - } - - public int getDefaultWidth() { - return defaultWidth; - } - - public String getRegistry() { - return "Adobe"; - } - - public String getOrdering() { - return "UCS"; - } - - public int getSupplement() { - return 0; - } - - public byte getCidType() { - return cidType; - } - - public String getCidBaseFont() { - return isEmbeddable() ? namePrefix + fontName : fontName; - } - - public String getCharEncoding() { - return "Identity-H"; - } - - public PDFWArray getWidths() { - if (isEmbeddable()) { - // Create widths for reencoded chars - warray = new PDFWArray(); - int[] tmpWidth = new int[usedGlyphsCount]; - - for (int i = 0; i < usedGlyphsCount; i++) { - Integer nw = (Integer)usedGlyphsIndex.get(new Integer(i)); - int nwx = (nw == null) ? 0 : nw.intValue(); - tmpWidth[i] = width[nwx]; - } - warray.addEntry(0, tmpWidth); - } - return warray; - } - - public boolean isEmbeddable() { - return (embedFileName == null && embedResourceName == null) ? false - : true; - } - - - public PDFStream getFontFile(int i) { - try { - FontFileReader reader = new FontFileReader(embedFileName); - TTFSubSetFile subset = new TTFSubSetFile(); - - byte[] subsetFont = subset.readFont(reader, ttcName, usedGlyphs); - // Only TrueType CID fonts are supported now - - embeddedFont = new PDFTTFStream(i, subsetFont.length); - embeddedFont.addFilter("flate"); - embeddedFont.addFilter("ascii-85"); - embeddedFont.setData(subsetFont, subsetFont.length); - } catch (IOException ioe) { - MessageHandler.errorln("Failed to embed font [" + i + "] " - + fontName + ": " + ioe.getMessage()); - return (PDFStream)null; - } - - return (PDFStream)embeddedFont; - } - - public String encoding() { - return encoding; - } - - public String fontName() { - return isEmbeddable() ? namePrefix + fontName : fontName; - } - - public int getAscender() { - return ascender; - } - - public int getDescender() { - return descender; - } - - public int getCapHeight() { - return capHeight; - } - - public int getAscender(int size) { - return size * ascender; - } - - public int getCapHeight(int size) { - return size * capHeight; - } - - public int getDescender(int size) { - return size * descender; - } - - public int getXHeight(int size) { - return size * xHeight; - } - - public int getFlags() { - return flags; - } - - public int[] getFontBBox() { - return fontBBox; - } - - public int getItalicAngle() { - return italicAngle; - } - - public int getStemV() { - return stemV; - } - - public int getFirstChar() { - return 0; - } - - public int getLastChar() { - return 255; - } - - public int width(int i, int size) { - if (isEmbeddable()) { - Integer idx = (Integer)usedGlyphsIndex.get(new Integer(i)); - return size * width[idx.intValue()]; - } else { - return size * width[i]; - } - } - - public int[] getWidths(int size) { - int[] arr = new int[width.length]; - System.arraycopy(width, 0, arr, 0, width.length - 1); - for (int i = 0; i < arr.length; i++) - arr[i] *= size; - return arr; - } - - public Integer reMap(Integer i) { - if (isEmbeddable()) { - Integer ret = (Integer)usedGlyphsIndex.get(i); - if (ret == null) - ret = i; - return ret; - } else { - return i; - } - - } - - public char mapChar(char c) { - int idx = (int)c; - int retIdx = 0; - - for (int i = 0; (i < bfentries.length) && retIdx == 0; i++) { - if (bfentries[i].unicodeStart <= idx - && bfentries[i].unicodeEnd >= idx) { - retIdx = bfentries[i].glyphStartIndex + idx - - bfentries[i].unicodeStart; - } - } - - if (isEmbeddable()) { - // Reencode to a new subset font or get - // the reencoded value - Integer newIdx = (Integer)usedGlyphs.get(new Integer(retIdx)); - if (newIdx == null) { - usedGlyphs.put(new Integer(retIdx), - new Integer(usedGlyphsCount)); - usedGlyphsIndex.put(new Integer(usedGlyphsCount), - new Integer(retIdx)); - retIdx = usedGlyphsCount; - // System.out.println(c+"("+(int)c+") = "+retIdx); - usedGlyphsCount++; - } else { - retIdx = newIdx.intValue(); - } - } - - return (char)retIdx; - } - -} - - - - - - - - - - diff --git a/src/org/apache/fop/render/pdf/fonts/SingleByteFont.java b/src/org/apache/fop/render/pdf/fonts/SingleByteFont.java deleted file mode 100644 index e780594f0..000000000 --- a/src/org/apache/fop/render/pdf/fonts/SingleByteFont.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.pdf.fonts; - -import org.apache.fop.render.pdf.Font; -import org.apache.fop.layout.FontDescriptor; -import org.apache.fop.fonts.Glyphs; -import org.apache.fop.pdf.PDFStream; -import org.apache.fop.pdf.PDFTTFStream; -import org.apache.fop.pdf.PDFT1Stream; -import java.io.InputStream; -import java.io.FileInputStream; -import java.io.BufferedInputStream; -import java.util.Hashtable; - -/** - * Generic SingleByte font - */ -public class SingleByteFont extends Font implements FontDescriptor { - public String fontName = null; - public String encoding = "WinAnsiEncoding"; - - public int capHeight = 0; - public int xHeight = 0; - public int ascender = 0; - public int descender = 0; - public int[] fontBBox = { - 0, 0, 0, 0 - }; - - public String embedFileName = null; - public String embedResourceName = null; - public PDFStream embeddedFont = null; - - public int firstChar = 0; - public int lastChar = 255; - public int flags = 4; - public int stemV = 0; - public int italicAngle = 0; - public int missingWidth = 0; - - public Hashtable kerning = new Hashtable(); - public boolean useKerning = true; - - public int width[] = null; - public byte subType = 0; - - public final boolean hasKerningInfo() { - return (useKerning & kerning.isEmpty()); - } - - public final java.util.Hashtable getKerningInfo() { - if (useKerning) - return kerning; - else - return new Hashtable(); - } - - public byte getSubType() { - return subType; - } - - public int getAvgWidth() { - return -1; - } - - public int getMinWidth() { - return -1; - } - - public int getMaxWidth() { - return -1; - } - - public int getleading() { - return -1; - } - - public int getStemH() { - return 0; - } - - public int getMissingWidth() { - return missingWidth; - } - - public String getCharEncoding() { - return encoding; - } - - public boolean isEmbeddable() { - return (embedFileName == null && embedResourceName == null) ? false - : true; - } - - - public PDFStream getFontFile(int i) { - InputStream instream = null; - - // Get file first - if (embedFileName != null) - try { - instream = new FileInputStream(embedFileName); - } catch (Exception e) { - System.out.println("Failed to embed fontfile: " - + embedFileName); - } - - // Get resource - if (instream == null && embedResourceName != null) - try { - instream = - new BufferedInputStream(this.getClass().getResourceAsStream(embedResourceName)); - } catch (Exception e) { - System.out.println("Failed to embed fontresource: " - + embedResourceName); - } - - if (instream == null) - return (PDFStream)null; - - // Read fontdata - byte[] file = new byte[128000]; - int fsize = 0; - - try { - int l = instream.read(file, 0, 128000); - fsize += l; - - if (l == 128000) { - // More to read - needs to extend - byte[] tmpbuf; - - while (l > 0) { - tmpbuf = new byte[file.length + 64000]; - System.arraycopy(file, 0, tmpbuf, 0, file.length); - l = instream.read(tmpbuf, file.length, 64000); - fsize += l; - file = tmpbuf; - - if (l < 64000) // whole file read. No need to loop again - l = 0; - } - } - - if (subType == org.apache.fop.pdf.PDFFont.TYPE1) { - embeddedFont = new PDFT1Stream(i, fsize); - ((PDFT1Stream)embeddedFont).setData(file, fsize); - } else { - embeddedFont = new PDFTTFStream(i, fsize); - ((PDFTTFStream)embeddedFont).setData(file, fsize); - } - - embeddedFont.addFilter("flate"); - embeddedFont.addFilter("ascii-85"); - instream.close(); - } catch (Exception e) {} - - return (PDFStream)embeddedFont; - } - - public String encoding() { - return encoding; - } - - public String fontName() { - return fontName; - } - - public int getAscender() { - return ascender; - } - - public int getDescender() { - return descender; - } - - public int getCapHeight() { - return capHeight; - } - - public int getAscender(int size) { - return size * ascender; - } - - public int getCapHeight(int size) { - return size * capHeight; - } - - public int getDescender(int size) { - return size * descender; - } - - public int getXHeight(int size) { - return size * xHeight; - } - - public int getFlags() { - return flags; - } - - public int[] getFontBBox() { - return fontBBox; - } - - public int getItalicAngle() { - return italicAngle; - } - - public int getStemV() { - return stemV; - } - - public int getFirstChar() { - return 0; - // return firstChar; - } - - public int getLastChar() { - return lastChar; - } - - public int width(int i, int size) { - return size * width[i]; - } - - public int[] getWidths(int size) { - int[] arr = new int[width.length]; - System.arraycopy(width, 0, arr, 0, width.length - 1); - for (int i = 0; i < arr.length; i++) - arr[i] *= size; - return arr; - } - -} - diff --git a/src/org/apache/fop/render/pdf/fonts/package.html b/src/org/apache/fop/render/pdf/fonts/package.html deleted file mode 100644 index f3e5c6652..000000000 --- a/src/org/apache/fop/render/pdf/fonts/package.html +++ /dev/null @@ -1,7 +0,0 @@ - -org.apache.fop.render.pdf.fonts Package - -

PDF font information/metrics

-

Generated entirely from XML files.

- - \ No newline at end of file diff --git a/src/org/apache/fop/render/pdf/package.html b/src/org/apache/fop/render/pdf/package.html deleted file mode 100644 index 1bcf2644f..000000000 --- a/src/org/apache/fop/render/pdf/package.html +++ /dev/null @@ -1,6 +0,0 @@ - -org.apache.fop.render.pdf Package - -

classes for rendering to PDF

- - \ No newline at end of file diff --git a/src/org/apache/fop/render/ps/ASCII85EncodeFilter.java b/src/org/apache/fop/render/ps/ASCII85EncodeFilter.java deleted file mode 100644 index 887598868..000000000 --- a/src/org/apache/fop/render/ps/ASCII85EncodeFilter.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.ps; - -import java.io.*; - -public class ASCII85EncodeFilter implements Filter { - - private static final char ASCII85_ZERO = 'z'; - private static final char ASCII85_START = '!'; - private static final char ASCII85_EOL = '\n'; - private static final String ASCII85_EOD = "~>"; - private static final String ENCODING = "US-ASCII"; - - private static final long base85_4 = 85; - private static final long base85_3 = base85_4 * base85_4; - private static final long base85_2 = base85_3 * base85_4; - private static final long base85_1 = base85_2 * base85_4; - - protected ASCII85EncodeFilter() {} - - public long write(OutputStream out, byte[] buf, int len, - long bw) throws IOException { - // Assumption: len<80 - int line = (int)(bw % 80) + len; - if (line >= 80) { - int first = len - (line - 80); - out.write(buf, 0, first); - out.write(ASCII85_EOL); - out.write(buf, first, len - first); - } else { - out.write(buf, 0, len); - } - return bw + len; - } - - public void doFilter(InputStream in, - OutputStream out) throws IOException { - int total = 0; - int diff = 0; - long bw = 0; - - // first encode the majority of the data - // each 4 byte group becomes a 5 byte group - byte[] data = new byte[4]; - int bytes_read; - while ((bytes_read = in.read(data)) == data.length) { - long val = ((data[0] << 24) - & 0xff000000L) // note: must have the L at the - + ((data[1] << 16) & 0xff0000L) // end, otherwise you get into - + ((data[2] << 8) & 0xff00L) // weird signed value problems - + (data[3] & 0xffL); // cause we're using a full 32 bits - byte[] conv = convertWord(val); - - bw = write(out, conv, conv.length, bw); - } - - // now take care of the trailing few bytes. - // with n leftover bytes, we append 0 bytes to make a full group of 4 - // then convert like normal (except not applying the special zero rule) - // and write out the first n+1 bytes from the result - if ((bytes_read < data.length) && (bytes_read >= 0)) { - int n = data.length - bytes_read; - byte[] lastdata = new byte[4]; - int i = 0; - for (int j = 0; j < 4; j++) { - if (j < n) { - lastdata[j] = data[i++]; - } else { - lastdata[j] = 0; - } - } - - long val = ((lastdata[0] << 24) & 0xff000000L) - + ((lastdata[1] << 16) & 0xff0000L) - + ((lastdata[2] << 8) & 0xff00L) - + (lastdata[3] & 0xffL); - - byte[] conv; - // special rule for handling zeros at the end - if (val != 0) { - conv = convertWord(val); - } else { - conv = new byte[5]; - for (int j = 0; j < 5; j++) { - conv[j] = (byte)'!'; - } - } - // assert n+1 <= 5 - bw = write(out, conv, n + 1, bw); - // System.out.println("ASCII85 end of data was "+n+" bytes long"); - - } - // finally write the two character end of data marker - byte[] EOD = ASCII85_EOD.getBytes(); - bw = write(out, EOD, EOD.length, bw); - } - - /** - * This converts a 32 bit value (4 bytes) into 5 bytes using base 85. - * each byte in the result starts with zero at the '!' character so - * the resulting base85 number fits into printable ascii chars - * - * @param word the 32 bit unsigned (hence the long datatype) word - * @return 5 bytes (or a single byte of the 'z' character for word - * values of 0) - */ - private byte[] convertWord(long word) { - word = word & 0xffffffff; - if (word < 0) { - word = -word; - } - - if (word == 0) { - byte[] result = { - (byte)ASCII85_ZERO - }; - return result; - } else { - byte c1 = (byte)((word / base85_1) & 0xFF); - byte c2 = (byte)(((word - (c1 * base85_1)) / base85_2) & 0xFF); - byte c3 = - (byte)(((word - (c1 * base85_1) - (c2 * base85_2)) / base85_3) - & 0xFF); - byte c4 = - (byte)(((word - (c1 * base85_1) - (c2 * base85_2) - (c3 * base85_3)) / base85_4) - & 0xFF); - byte c5 = - (byte)(((word - (c1 * base85_1) - (c2 * base85_2) - (c3 * base85_3) - (c4 * base85_4))) - & 0xFF); - - byte[] ret = { - (byte)(c1 + ASCII85_START), (byte)(c2 + ASCII85_START), - (byte)(c3 + ASCII85_START), (byte)(c4 + ASCII85_START), - (byte)(c5 + ASCII85_START) - }; - - for (int i = 0; i < ret.length; i++) { - if (ret[i] < 33 || ret[i] > 117) { - System.out.println("Illegal char value " - + new Integer(ret[i])); - } - } - return ret; - } - } - - - public static InputStream filter(InputStream in) throws IOException { - ASCII85EncodeFilter myfilter = new ASCII85EncodeFilter(); - return FilterThread.filter(in, myfilter); - } - -} diff --git a/src/org/apache/fop/render/ps/ASCIIHexEncodeFilter.java b/src/org/apache/fop/render/ps/ASCIIHexEncodeFilter.java deleted file mode 100644 index 8a8c2d837..000000000 --- a/src/org/apache/fop/render/ps/ASCIIHexEncodeFilter.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.ps; - -import java.io.*; - -public class ASCIIHexEncodeFilter implements Filter { - - private static final char ASCIIHEX_EOL = '\n'; - private static final String ASCIIHEX_EOD = ">"; - private static final String ENCODING = "US-ASCII"; - - protected ASCIIHexEncodeFilter() {} - - public long write(OutputStream out, byte[] buf, int len, - long bw) throws IOException { - boolean last = false; - int pos = 0; - int rest = len; - while (rest > 0) { - int restofline = 80 - (int)((bw + pos) % 80); - if (rest < restofline) { - // last line - restofline = rest; - last = true; - } - if (restofline > 0) { - out.write(buf, pos, restofline); - pos += restofline; - if (!last) - out.write(ASCIIHEX_EOL); - } - rest = len - pos; - } - return bw + len; - } - - public void doFilter(InputStream in, - OutputStream out) throws IOException { - long bw = 0; - byte[] buf = new byte[2048]; - int bytes_read; - StringBuffer sb = new StringBuffer(2048 * 2); - while ((bytes_read = in.read(buf)) != -1) { - sb.setLength(0); - for (int i = 0; i < bytes_read; i++) { - int val = (int)(buf[i] & 0xFF); - if (val < 16) - sb.append("0"); - sb.append(Integer.toHexString(val)); - } - bw = write(out, sb.toString().getBytes(ENCODING), bytes_read * 2, - bw); - } - byte[] eod = ASCIIHEX_EOD.getBytes(ENCODING); - bw = write(out, eod, eod.length, bw); - } - - public static InputStream filter(InputStream in) throws IOException { - ASCIIHexEncodeFilter myfilter = new ASCIIHexEncodeFilter(); - return FilterThread.filter(in, myfilter); - } - -} diff --git a/src/org/apache/fop/render/ps/Filter.java b/src/org/apache/fop/render/ps/Filter.java deleted file mode 100644 index 3d6f0034c..000000000 --- a/src/org/apache/fop/render/ps/Filter.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.ps; - -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -public interface Filter { - - public void doFilter(InputStream in, OutputStream out) throws IOException; -} - diff --git a/src/org/apache/fop/render/ps/FilterThread.java b/src/org/apache/fop/render/ps/FilterThread.java deleted file mode 100644 index b690c3225..000000000 --- a/src/org/apache/fop/render/ps/FilterThread.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.ps; - -import java.io.*; - -public class FilterThread extends Thread { - - private Filter filter; - private InputStream in; - private OutputStream out; - - private FilterThread(Filter filter, InputStream in, OutputStream out) { - this.filter = filter; - this.in = in; - this.out = out; - } - - public void run() { - try { - try { - this.filter.doFilter(in, out); - this.out.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - finally { - this.filter = null; - this.in = null; - this.out = null; - } - } - - public static InputStream filter(InputStream in, - Filter filter) throws IOException { - PipedInputStream pin = new PipedInputStream(); - PipedOutputStream pout = new PipedOutputStream(pin); - FilterThread thread = new FilterThread(filter, in, pout); - thread.start(); - return pin; - } - -} diff --git a/src/org/apache/fop/render/ps/FlateEncodeFilter.java b/src/org/apache/fop/render/ps/FlateEncodeFilter.java deleted file mode 100644 index bde626713..000000000 --- a/src/org/apache/fop/render/ps/FlateEncodeFilter.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.ps; - -import java.io.*; -import java.util.zip.DeflaterOutputStream; - -public class FlateEncodeFilter implements Filter { - - protected FlateEncodeFilter() {} - - private long copyStream(InputStream in, OutputStream out, - int bufferSize) throws IOException { - long bytes_total = 0; - byte[] buf = new byte[bufferSize]; - int bytes_read; - while ((bytes_read = in.read(buf)) != -1) { - bytes_total += bytes_read; - out.write(buf, 0, bytes_read); - } - return bytes_total; - } - - public void doFilter(InputStream in, - OutputStream out) throws IOException { - DeflaterOutputStream dout = new DeflaterOutputStream(out); - copyStream(in, dout, 2048); - // dout.flush(); - dout.close(); - } - - public static InputStream filter(InputStream in) throws IOException { - FlateEncodeFilter myfilter = new FlateEncodeFilter(); - return FilterThread.filter(in, myfilter); - } - -} diff --git a/src/org/apache/fop/render/ps/PSGraphics2D.java b/src/org/apache/fop/render/ps/PSGraphics2D.java deleted file mode 100644 index 67859e351..000000000 --- a/src/org/apache/fop/render/ps/PSGraphics2D.java +++ /dev/null @@ -1,940 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.ps; - -import org.apache.fop.pdf.*; -import org.apache.fop.layout.*; -import org.apache.fop.fonts.*; -import org.apache.fop.render.pdf.*; -import org.apache.fop.image.*; -import org.apache.fop.datatypes.ColorSpace; - -import org.apache.batik.ext.awt.g2d.*; - -import java.text.AttributedCharacterIterator; -import java.text.CharacterIterator; -import java.awt.*; -import java.awt.Font; -import java.awt.Image; -import java.awt.image.*; -import java.awt.font.*; -import java.awt.geom.*; -import java.awt.image.renderable.*; -import java.io.*; - -import java.util.Map; -import java.util.Vector; - -/** - * This concrete implementation of AbstractGraphics2D is a - * simple help to programmers to get started with their own - * implementation of Graphics2D. - * DefaultGraphics2D implements all the abstract methods - * is AbstractGraphics2D and makes it easy to start - * implementing a Graphic2D piece-meal. - * - * @author Keiron Liddle - * @version $Id$ - * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D - */ -public class PSGraphics2D extends AbstractGraphics2D { - boolean standalone = false; - - /** - * the PDF Document being created - */ - protected PSRenderer psRenderer; - - protected FontState fontState; - - /** - * the current (internal) font name - */ - protected String currentFontName; - - /** - * the current font size in millipoints - */ - protected int currentFontSize; - - /** - * the current vertical position in millipoints from bottom - */ - protected int currentYPosition = 0; - - /** - * the current horizontal position in millipoints from left - */ - protected int currentXPosition = 0; - - /** - * the current colour for use in svg - */ - PDFColor currentColour = new PDFColor(0, 0, 0); - - FontInfo fontInfo; - - /** - * Create a new PDFGraphics2D with the given pdf document info. - * This is used to create a Graphics object for use inside an already - * existing document. - */ - public PSGraphics2D(boolean textAsShapes, FontState fs, PSRenderer ren, - String font, int size, int xpos, int ypos) { - super(textAsShapes); - psRenderer = ren; - currentFontName = font; - currentFontSize = size; - currentYPosition = ypos; - currentXPosition = xpos; - fontState = fs; - } - - public PSGraphics2D(boolean textAsShapes) { - super(textAsShapes); - } - - public void setGraphicContext(GraphicContext c) { - gc = c; - } - - /** - * This constructor supports the create method - */ - public PSGraphics2D(PSGraphics2D g) { - super(g); - } - - /** - * Creates a new Graphics object that is - * a copy of this Graphics object. - * @return a new graphics context that is a copy of - * this graphics context. - */ - public Graphics create() { - return new PSGraphics2D(this); - } - - /** - * Draws as much of the specified image as is currently available. - * The image is drawn with its top-left corner at - * (xy) in this graphics context's coordinate - * space. Transparent pixels in the image do not affect whatever - * pixels are already there. - *

- * This method returns immediately in all cases, even if the - * complete image has not yet been loaded, and it has not been dithered - * and converted for the current output device. - *

- * If the image has not yet been completely loaded, then - * drawImage returns false. As more of - * the image becomes available, the process that draws the image notifies - * the specified image observer. - * @param img the specified image to be drawn. - * @param x the x coordinate. - * @param y the y coordinate. - * @param observer object to be notified as more of - * the image is converted. - * @see java.awt.Image - * @see java.awt.image.ImageObserver - * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int) - */ - public boolean drawImage(Image img, int x, int y, - ImageObserver observer) { - // System.err.println("drawImage:x, y"); - - final int width = img.getWidth(observer); - final int height = img.getHeight(observer); - if (width == -1 || height == -1) { - return false; - } - - Dimension size = new Dimension(width, height); - BufferedImage buf = buildBufferedImage(size); - - java.awt.Graphics2D g = buf.createGraphics(); - g.setComposite(AlphaComposite.SrcOver); - g.setBackground(new Color(1, 1, 1, 0)); - g.setPaint(new Color(1, 1, 1, 0)); - g.fillRect(0, 0, width, height); - g.clip(new Rectangle(0, 0, buf.getWidth(), buf.getHeight())); - - if (!g.drawImage(img, 0, 0, observer)) { - return false; - } - g.dispose(); - - final byte[] result = new byte[buf.getWidth() * buf.getHeight() * 3]; - final byte[] mask = new byte[buf.getWidth() * buf.getHeight()]; - - Raster raster = buf.getData(); - DataBuffer bd = raster.getDataBuffer(); - - int count = 0; - int maskpos = 0; - switch (bd.getDataType()) { - case DataBuffer.TYPE_INT: - int[][] idata = ((DataBufferInt)bd).getBankData(); - for (int i = 0; i < idata.length; i++) { - for (int j = 0; j < idata[i].length; j++) { - // mask[maskpos++] = (byte)((idata[i][j] >> 24) & 0xFF); - if (((idata[i][j] >> 24) & 0xFF) != 255) { - result[count++] = (byte)0xFF; - result[count++] = (byte)0xFF; - result[count++] = (byte)0xFF; - } else { - result[count++] = (byte)((idata[i][j] >> 16) & 0xFF); - result[count++] = (byte)((idata[i][j] >> 8) & 0xFF); - result[count++] = (byte)((idata[i][j]) & 0xFF); - } - } - } - break; - default: - // error - break; - } - - try { - FopImage fopimg = new TempImage(width, height, result, mask); - AffineTransform at = getTransform(); - double[] matrix = new double[6]; - at.getMatrix(matrix); - psRenderer.write("gsave"); - Shape imclip = getClip(); - writeClip(imclip); - // psRenderer.write("" + matrix[0] + " " + matrix[1] + - // " " + matrix[2] + " " + matrix[3] + " " + - // matrix[4] + " " + matrix[5] + " cm\n"); - psRenderer.renderBitmap(fopimg, x, y, width, height); - psRenderer.write("grestore"); - } catch (Exception e) { - e.printStackTrace(); - } - return true; - } - - public BufferedImage buildBufferedImage(Dimension size) { - return new BufferedImage(size.width, size.height, - BufferedImage.TYPE_INT_ARGB); - } - - class TempImage implements FopImage { - int m_height; - int m_width; - int m_bitsPerPixel; - ColorSpace m_colorSpace; - int m_bitmapSiye; - byte[] m_bitmaps; - byte[] m_mask; - PDFColor transparent = new PDFColor(255, 255, 255); - - TempImage(int width, int height, byte[] result, - byte[] mask) throws FopImageException { - this.m_height = height; - this.m_width = width; - this.m_bitsPerPixel = 8; - this.m_colorSpace = new ColorSpace(ColorSpace.DEVICE_RGB); - // this.m_isTransparent = false; - // this.m_bitmapsSize = this.m_width * this.m_height * 3; - this.m_bitmaps = result; - this.m_mask = mask; - } - - public String getURL() { - return "" + m_bitmaps; - } - - // image size - public int getWidth() throws FopImageException { - return m_width; - } - - public int getHeight() throws FopImageException { - return m_height; - } - - // DeviceGray, DeviceRGB, or DeviceCMYK - public ColorSpace getColorSpace() throws FopImageException { - return m_colorSpace; - } - - // bits per pixel - public int getBitsPerPixel() throws FopImageException { - return m_bitsPerPixel; - } - - // For transparent images - public boolean isTransparent() throws FopImageException { - return transparent != null; - } - - public PDFColor getTransparentColor() throws FopImageException { - return transparent; - } - - public byte[] getMask() throws FopImageException { - return m_mask; - } - - // get the image bytes, and bytes properties - - // get uncompressed image bytes - public byte[] getBitmaps() throws FopImageException { - return m_bitmaps; - } - - // width * (bitsPerPixel / 8) * height, no ? - public int getBitmapsSize() throws FopImageException { - return m_width * m_height * 3; - } - - // get compressed image bytes - // I don't know if we really need it, nor if it - // should be changed... - public byte[] getRessourceBytes() throws FopImageException { - return null; - } - - public int getRessourceBytesSize() throws FopImageException { - return 0; - } - - // return null if no corresponding PDFFilter - public PDFFilter getPDFFilter() throws FopImageException { - return null; - } - - // release memory - public void close() {} - - } - - - /** - * Draws as much of the specified image as has already been scaled - * to fit inside the specified rectangle. - *

- * The image is drawn inside the specified rectangle of this - * graphics context's coordinate space, and is scaled if - * necessary. Transparent pixels do not affect whatever pixels - * are already there. - *

- * This method returns immediately in all cases, even if the - * entire image has not yet been scaled, dithered, and converted - * for the current output device. - * If the current output representation is not yet complete, then - * drawImage returns false. As more of - * the image becomes available, the process that draws the image notifies - * the image observer by calling its imageUpdate method. - *

- * A scaled version of an image will not necessarily be - * available immediately just because an unscaled version of the - * image has been constructed for this output device. Each size of - * the image may be cached separately and generated from the original - * data in a separate image production sequence. - * @param img the specified image to be drawn. - * @param x the x coordinate. - * @param y the y coordinate. - * @param width the width of the rectangle. - * @param height the height of the rectangle. - * @param observer object to be notified as more of - * the image is converted. - * @see java.awt.Image - * @see java.awt.image.ImageObserver - * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int) - */ - public boolean drawImage(Image img, int x, int y, int width, int height, - ImageObserver observer) { - System.out.println("drawImage"); - return true; - } - - /** - * Disposes of this graphics context and releases - * any system resources that it is using. - * A Graphics object cannot be used after - * disposehas been called. - *

- * When a Java program runs, a large number of Graphics - * objects can be created within a short time frame. - * Although the finalization process of the garbage collector - * also disposes of the same system resources, it is preferable - * to manually free the associated resources by calling this - * method rather than to rely on a finalization process which - * may not run to completion for a long period of time. - *

- * Graphics objects which are provided as arguments to the - * paint and update methods - * of components are automatically released by the system when - * those methods return. For efficiency, programmers should - * call dispose when finished using - * a Graphics object only if it was created - * directly from a component or another Graphics object. - * @see java.awt.Graphics#finalize - * @see java.awt.Component#paint - * @see java.awt.Component#update - * @see java.awt.Component#getGraphics - * @see java.awt.Graphics#create - */ - public void dispose() { - // System.out.println("dispose"); - psRenderer = null; - fontState = null; - currentFontName = null; - currentColour = null; - fontInfo = null; - } - - /** - * Strokes the outline of a Shape using the settings of the - * current Graphics2D context. The rendering attributes - * applied include the Clip, Transform, - * Paint, Composite and - * Stroke attributes. - * @param s the Shape to be rendered - * @see #setStroke - * @see #setPaint - * @see java.awt.Graphics#setColor - * @see #transform - * @see #setTransform - * @see #clip - * @see #setClip - * @see #setComposite - */ - public void draw(Shape s) { - // System.out.println("draw(Shape)"); - psRenderer.write("gsave"); - Shape imclip = getClip(); - writeClip(imclip); - Color c = getColor(); - psRenderer.write(c.getRed() + " " + c.getGreen() + " " + c.getBlue() - + " setrgbcolor"); - - applyPaint(getPaint(), false); - applyStroke(getStroke()); - - psRenderer.write("newpath"); - PathIterator iter = s.getPathIterator(getTransform()); - while (!iter.isDone()) { - double vals[] = new double[6]; - int type = iter.currentSegment(vals); - switch (type) { - case PathIterator.SEG_CUBICTO: - psRenderer.write(PDFNumber.doubleOut(1000 * vals[0]) + " " - + PDFNumber.doubleOut(1000 * vals[1]) + " " - + PDFNumber.doubleOut(1000 * vals[2]) + " " - + PDFNumber.doubleOut(1000 * vals[3]) + " " - + PDFNumber.doubleOut(1000 * vals[4]) + " " - + PDFNumber.doubleOut(1000 * vals[5]) - + " curveto"); - break; - case PathIterator.SEG_LINETO: - psRenderer.write(PDFNumber.doubleOut(1000 * vals[0]) + " " - + PDFNumber.doubleOut(1000 * vals[1]) - + " lineto"); - break; - case PathIterator.SEG_MOVETO: - psRenderer.write(PDFNumber.doubleOut(1000 * vals[0]) + " " - + PDFNumber.doubleOut(1000 * vals[1]) - + " M"); - break; - case PathIterator.SEG_QUADTO: - // psRenderer.write((1000 * PDFNumber.doubleOut(vals[0])) + - // " " + (1000 * PDFNumber.doubleOut(vals[1])) + " " + - // (1000 * PDFNumber.doubleOut(vals[2])) + " " + - // (1000 * PDFNumber.doubleOut(vals[3])) + " y\n"); - break; - case PathIterator.SEG_CLOSE: - psRenderer.write("closepath"); - break; - default: - break; - } - iter.next(); - } - doDrawing(false, true, false); - psRenderer.write("grestore"); - } - - protected void writeClip(Shape s) { - PathIterator iter = s.getPathIterator(getTransform()); - psRenderer.write("newpath"); - while (!iter.isDone()) { - double vals[] = new double[6]; - int type = iter.currentSegment(vals); - switch (type) { - case PathIterator.SEG_CUBICTO: - psRenderer.write(PDFNumber.doubleOut(1000 * vals[0]) + " " - + PDFNumber.doubleOut(1000 * vals[1]) + " " - + PDFNumber.doubleOut(1000 * vals[2]) + " " - + PDFNumber.doubleOut(1000 * vals[3]) + " " - + PDFNumber.doubleOut(1000 * vals[4]) + " " - + PDFNumber.doubleOut(1000 * vals[5]) - + " curveto"); - break; - case PathIterator.SEG_LINETO: - psRenderer.write(PDFNumber.doubleOut(1000 * vals[0]) + " " - + PDFNumber.doubleOut(1000 * vals[1]) - + " lineto"); - break; - case PathIterator.SEG_MOVETO: - psRenderer.write(PDFNumber.doubleOut(1000 * vals[0]) + " " - + PDFNumber.doubleOut(1000 * vals[1]) - + " M"); - break; - case PathIterator.SEG_QUADTO: - // psRenderer.write(1000 * PDFNumber.doubleOut(vals[0]) + - // " " + 1000 * PDFNumber.doubleOut(vals[1]) + " " + - // 1000 * PDFNumber.doubleOut(vals[2]) + " " + - // 1000 * PDFNumber.doubleOut(vals[3]) + " y\n"); - break; - case PathIterator.SEG_CLOSE: - psRenderer.write("closepath"); - break; - default: - break; - } - iter.next(); - } - // clip area - psRenderer.write("clippath"); - } - - protected void applyPaint(Paint paint, boolean fill) { - if (paint instanceof GradientPaint) { - GradientPaint gp = (GradientPaint)paint; - Color c1 = gp.getColor1(); - Color c2 = gp.getColor2(); - Point2D p1 = gp.getPoint1(); - Point2D p2 = gp.getPoint2(); - boolean cyclic = gp.isCyclic(); - - Vector theCoords = new Vector(); - theCoords.addElement(new Double(p1.getX())); - theCoords.addElement(new Double(p1.getY())); - theCoords.addElement(new Double(p2.getX())); - theCoords.addElement(new Double(p2.getY())); - - Vector theExtend = new Vector(); - theExtend.addElement(new Boolean(true)); - theExtend.addElement(new Boolean(true)); - - Vector theDomain = new Vector(); - theDomain.addElement(new Double(0)); - theDomain.addElement(new Double(1)); - - Vector theEncode = new Vector(); - theEncode.addElement(new Double(0)); - theEncode.addElement(new Double(1)); - theEncode.addElement(new Double(0)); - theEncode.addElement(new Double(1)); - - Vector theBounds = new Vector(); - theBounds.addElement(new Double(0)); - theBounds.addElement(new Double(1)); - - Vector theFunctions = new Vector(); - - Vector someColors = new Vector(); - - PDFColor color1 = new PDFColor(c1.getRed(), c1.getGreen(), - c1.getBlue()); - someColors.addElement(color1); - PDFColor color2 = new PDFColor(c2.getRed(), c2.getGreen(), - c2.getBlue()); - someColors.addElement(color2); - - ColorSpace aColorSpace = new ColorSpace(ColorSpace.DEVICE_RGB); - } else if (paint instanceof TexturePaint) {} - } - - protected void applyStroke(Stroke stroke) { - if (stroke instanceof BasicStroke) { - BasicStroke bs = (BasicStroke)stroke; - - float[] da = bs.getDashArray(); - if (da != null) { - psRenderer.write("["); - for (int count = 0; count < da.length; count++) { - psRenderer.write("" + (1000 * (int)da[count])); - if (count < da.length - 1) { - psRenderer.write(" "); - } - } - psRenderer.write("] "); - float offset = bs.getDashPhase(); - psRenderer.write((1000 * (int)offset) + " setdash"); - } - int ec = bs.getEndCap(); - switch (ec) { - case BasicStroke.CAP_BUTT: - psRenderer.write(0 + " setlinecap"); - break; - case BasicStroke.CAP_ROUND: - psRenderer.write(1 + " setlinecap"); - break; - case BasicStroke.CAP_SQUARE: - psRenderer.write(2 + " setlinecap"); - break; - } - - int lj = bs.getLineJoin(); - switch (lj) { - case BasicStroke.JOIN_MITER: - psRenderer.write(0 + " setlinejoin"); - break; - case BasicStroke.JOIN_ROUND: - psRenderer.write(1 + " setlinejoin"); - break; - case BasicStroke.JOIN_BEVEL: - psRenderer.write(2 + " setlinejoin"); - break; - } - float lw = bs.getLineWidth(); - psRenderer.write(PDFNumber.doubleOut(1000 * lw) - + " setlinewidth"); - - float ml = bs.getMiterLimit(); - psRenderer.write(PDFNumber.doubleOut(1000 * ml) - + " setmiterlimit"); - } - } - - /** - * Renders a {@link RenderedImage}, - * applying a transform from image - * space into user space before drawing. - * The transformation from user space into device space is done with - * the current Transform in the Graphics2D. - * The specified transformation is applied to the image before the - * transform attribute in the Graphics2D context is applied. - * The rendering attributes applied include the Clip, - * Transform, and Composite attributes. Note - * that no rendering is done if the specified transform is - * noninvertible. - * @param img the image to be rendered - * @param xform the transformation from image space into user space - * @see #transform - * @see #setTransform - * @see #setComposite - * @see #clip - * @see #setClip - */ - public void drawRenderedImage(RenderedImage img, AffineTransform xform) { - System.out.println("drawRenderedImage"); - } - - - /** - * Renders a - * {@link RenderableImage}, - * applying a transform from image space into user space before drawing. - * The transformation from user space into device space is done with - * the current Transform in the Graphics2D. - * The specified transformation is applied to the image before the - * transform attribute in the Graphics2D context is applied. - * The rendering attributes applied include the Clip, - * Transform, and Composite attributes. Note - * that no rendering is done if the specified transform is - * noninvertible. - *

- * Rendering hints set on the Graphics2D object might - * be used in rendering the RenderableImage. - * If explicit control is required over specific hints recognized by a - * specific RenderableImage, or if knowledge of which hints - * are used is required, then a RenderedImage should be - * obtained directly from the RenderableImage - * and rendered using - * {@link #drawRenderedImage(RenderedImage, AffineTransform) drawRenderedImage}. - * @param img the image to be rendered - * @param xform the transformation from image space into user space - * @see #transform - * @see #setTransform - * @see #setComposite - * @see #clip - * @see #setClip - * @see #drawRenderedImage - */ - public void drawRenderableImage(RenderableImage img, - AffineTransform xform) { - System.out.println("drawRenderableImage"); - } - - /** - * Renders the text specified by the specified String, - * using the current Font and Paint attributes - * in the Graphics2D context. - * The baseline of the first character is at position - * (xy) in the User Space. - * The rendering attributes applied include the Clip, - * Transform, Paint, Font and - * Composite attributes. For characters in script systems - * such as Hebrew and Arabic, the glyphs can be rendered from right to - * left, in which case the coordinate supplied is the location of the - * leftmost character on the baseline. - * @param s the String to be rendered - * @param x, y the coordinates where the String - * should be rendered - * @see #setPaint - * @see java.awt.Graphics#setColor - * @see java.awt.Graphics#setFont - * @see #setTransform - * @see #setComposite - * @see #setClip - */ - public void drawString(String s, float x, float y) { - System.out.println("drawString(String)"); - psRenderer.write("BT"); - Shape imclip = getClip(); - writeClip(imclip); - Color c = getColor(); - psRenderer.write(c.getRed() + " " + c.getGreen() + " " + c.getBlue() - + " setrgbcolor"); - - AffineTransform trans = getTransform(); - trans.translate(x, y); - double[] vals = new double[6]; - trans.getMatrix(vals); - - psRenderer.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 + "]"); - - psRenderer.write("ET"); - } - - /** - * Renders the text of the specified iterator, using the - * Graphics2D context's current Paint. The - * iterator must specify a font - * for each character. The baseline of the - * first character is at position (xy) in the - * User Space. - * The rendering attributes applied include the Clip, - * Transform, Paint, and - * Composite attributes. - * For characters in script systems such as Hebrew and Arabic, - * the glyphs can be rendered from right to left, in which case the - * coordinate supplied is the location of the leftmost character - * on the baseline. - * @param iterator the iterator whose text is to be rendered - * @param x, y the coordinates where the iterator's text is to be - * rendered - * @see #setPaint - * @see java.awt.Graphics#setColor - * @see #setTransform - * @see #setComposite - * @see #setClip - */ - public void drawString(AttributedCharacterIterator iterator, float x, - float y) { - System.err.println("drawString(AttributedCharacterIterator)"); - - psRenderer.write("BT"); - Shape imclip = getClip(); - writeClip(imclip); - Color c = getColor(); - currentColour = new PDFColor(c.getRed(), c.getGreen(), c.getBlue()); - psRenderer.write(currentColour.getColorSpaceOut(true)); - c = getBackground(); - PDFColor col = new PDFColor(c.getRed(), c.getGreen(), c.getBlue()); - psRenderer.write(col.getColorSpaceOut(false)); - - AffineTransform trans = getTransform(); - trans.translate(x, y); - double[] vals = new double[6]; - trans.getMatrix(vals); - - for (char ch = iterator.first(); ch != CharacterIterator.DONE; - ch = iterator.next()) { - Map attr = iterator.getAttributes(); - - psRenderer.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 - + "]"); - } - - psRenderer.write("ET"); - } - - /** - * Fills the interior of a Shape using the settings of the - * Graphics2D context. The rendering attributes applied - * include the Clip, Transform, - * Paint, and Composite. - * @param s the Shape to be filled - * @see #setPaint - * @see java.awt.Graphics#setColor - * @see #transform - * @see #setTransform - * @see #setComposite - * @see #clip - * @see #setClip - */ - public void fill(Shape s) { - // System.err.println("fill"); - psRenderer.write("gsave"); - Shape imclip = getClip(); - writeClip(imclip); - Color c = getColor(); - psRenderer.write(c.getRed() + " " + c.getGreen() + " " + c.getBlue() - + " setrgbcolor"); - - applyPaint(getPaint(), true); - - psRenderer.write("newpath"); - PathIterator iter = s.getPathIterator(getTransform()); - while (!iter.isDone()) { - double vals[] = new double[6]; - int type = iter.currentSegment(vals); - switch (type) { - case PathIterator.SEG_CUBICTO: - psRenderer.write(PDFNumber.doubleOut(1000 * vals[0]) + " " - + PDFNumber.doubleOut(1000 * vals[1]) + " " - + PDFNumber.doubleOut(1000 * vals[2]) + " " - + PDFNumber.doubleOut(1000 * vals[3]) + " " - + PDFNumber.doubleOut(1000 * vals[4]) + " " - + PDFNumber.doubleOut(1000 * vals[5]) - + " curveto"); - break; - case PathIterator.SEG_LINETO: - psRenderer.write(PDFNumber.doubleOut(1000 * vals[0]) + " " - + PDFNumber.doubleOut(1000 * vals[1]) - + " lineto"); - break; - case PathIterator.SEG_MOVETO: - psRenderer.write(PDFNumber.doubleOut(1000 * vals[0]) + " " - + PDFNumber.doubleOut(1000 * vals[1]) - + " M"); - break; - case PathIterator.SEG_QUADTO: - // psRenderer.write(1000 * PDFNumber.doubleOut(vals[0]) + - // " " + 1000 * PDFNumber.doubleOut(vals[1]) + " " + - // 1000 * PDFNumber.doubleOut(vals[2]) + " " + - // 1000 * PDFNumber.doubleOut(vals[3]) + " y\n"); - break; - case PathIterator.SEG_CLOSE: - psRenderer.write("closepath"); - break; - default: - break; - } - iter.next(); - } - doDrawing(true, false, - iter.getWindingRule() == PathIterator.WIND_EVEN_ODD); - psRenderer.write("grestore"); - } - - protected void doDrawing(boolean fill, boolean stroke, boolean nonzero) { - if (fill) { - if (stroke) { - if (!nonzero) - psRenderer.write("stroke"); - else - psRenderer.write("stroke"); - } else { - if (!nonzero) - psRenderer.write("fill"); - else - psRenderer.write("fill"); - } - } else { - // if(stroke) - psRenderer.write("stroke"); - } - } - - /** - * Returns the device configuration associated with this - * Graphics2D. - */ - public GraphicsConfiguration getDeviceConfiguration() { - // System.out.println("getDeviceConviguration"); - return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); - } - - /** - * Used to create proper font metrics - */ - private Graphics2D fmg; - - { - BufferedImage bi = new BufferedImage(1, 1, - BufferedImage.TYPE_INT_ARGB); - - fmg = bi.createGraphics(); - } - - /** - * Gets the font metrics for the specified font. - * @return the font metrics for the specified font. - * @param f the specified font - * @see java.awt.Graphics#getFont - * @see java.awt.FontMetrics - * @see java.awt.Graphics#getFontMetrics() - */ - public FontMetrics getFontMetrics(Font f) { - return fmg.getFontMetrics(f); - } - - /** - * Sets the paint mode of this graphics context to alternate between - * this graphics context's current color and the new specified color. - * This specifies that logical pixel operations are performed in the - * XOR mode, which alternates pixels between the current color and - * a specified XOR color. - *

- * When drawing operations are performed, pixels which are the - * current color are changed to the specified color, and vice versa. - *

- * Pixels that are of colors other than those two colors are changed - * in an unpredictable but reversible manner; if the same figure is - * drawn twice, then all pixels are restored to their original values. - * @param c1 the XOR alternation color - */ - public void setXORMode(Color c1) { - System.out.println("setXORMode"); - } - - - /** - * Copies an area of the component by a distance specified by - * dx and dy. From the point specified - * by x and y, this method - * copies downwards and to the right. To copy an area of the - * component to the left or upwards, specify a negative value for - * dx or dy. - * If a portion of the source rectangle lies outside the bounds - * of the component, or is obscured by another window or component, - * copyArea will be unable to copy the associated - * pixels. The area that is omitted can be refreshed by calling - * the component's paint method. - * @param x the x coordinate of the source rectangle. - * @param y the y coordinate of the source rectangle. - * @param width the width of the source rectangle. - * @param height the height of the source rectangle. - * @param dx the horizontal distance to copy the pixels. - * @param dy the vertical distance to copy the pixels. - */ - public void copyArea(int x, int y, int width, int height, int dx, - int dy) { - System.out.println("copyArea"); - } - -} diff --git a/src/org/apache/fop/render/ps/PSRenderer.java b/src/org/apache/fop/render/ps/PSRenderer.java deleted file mode 100644 index 5bfcca1a3..000000000 --- a/src/org/apache/fop/render/ps/PSRenderer.java +++ /dev/null @@ -1,1073 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.ps; - -// FOP -import org.apache.fop.messaging.MessageHandler; -import org.apache.fop.svg.SVGArea; -import org.apache.fop.render.Renderer; -import org.apache.fop.image.ImageArea; -import org.apache.fop.image.FopImage; -import org.apache.fop.image.FopImageException; -import org.apache.fop.layout.*; -import org.apache.fop.layout.inline.*; -import org.apache.fop.datatypes.*; -import org.apache.fop.fo.properties.*; -import org.apache.fop.render.pdf.Font; -import org.apache.fop.image.*; - -import org.apache.batik.bridge.*; -import org.apache.batik.swing.svg.*; -import org.apache.batik.swing.gvt.*; -import org.apache.batik.gvt.*; -import org.apache.batik.gvt.renderer.*; -import org.apache.batik.gvt.filter.*; -import org.apache.batik.gvt.event.*; - -// SVG -import org.w3c.dom.svg.SVGSVGElement; -import org.w3c.dom.svg.SVGDocument; -import org.w3c.dom.*; -import org.w3c.dom.svg.*; - -// Java -import java.io.*; -import java.util.*; -import java.io.IOException; -import java.io.OutputStream; -import java.util.Enumeration; -import java.util.Vector; -import java.util.Hashtable; -import java.awt.geom.AffineTransform; -import java.awt.geom.Dimension2D; -import java.awt.Point; -import java.awt.RenderingHints; -import java.awt.font.FontRenderContext; -import java.awt.Dimension; - -/** - * Renderer that renders to PostScript. - *
- * This class currently generates PostScript Level 2 code. The only exception - * is the FlateEncode filter which is a Level 3 feature. The filters in use - * are hardcoded at the moment. - *
- * This class follows the Document Structuring Conventions (DSC) version 3.0 - * (If I did everything right). If anyone modifies this renderer please make - * sure to also follow the DSC to make it simpler to programmatically modify - * the generated Postscript files (ex. extract pages etc.). - *
- * TODO: Character size/spacing, SVG Transcoder for Batik, configuration, move - * to PrintRenderer, maybe improve filters (I'm not very proud of them), add a - * RunLengthEncode filter (useful for Level 2 Postscript), Improve - * DocumentProcessColors stuff (probably needs to be configurable, then maybe - * add a color to grayscale conversion for bitmaps to make output smaller (See - * PCLRenderer), font embedding, support different character encodings, try to - * implement image transparency, positioning of images is wrong etc.

- * - * Modified by Mark Lillywhite mark-fop@inomial.com, to use the new - * Renderer interface. This PostScript renderer appears to be the - * most efficient at producing output. - * - * @author Jeremias Märki - */ -public class PSRenderer implements Renderer { - - /** - * the application producing the PostScript - */ - protected String producer; - - int imagecount = 0; // DEBUG - - private boolean enableComments = true; - - /** - * the stream used to output the PostScript - */ - protected PSStream out; - private boolean ioTrouble = false; - - private String currentFontName; - private int currentFontSize; - private int pageHeight; - private int pageWidth; - private int currentXPosition = 0; - private int currentYPosition = 0; - private int currentAreaContainerXPosition = 0; - private float currRed; - private float currGreen; - private float currBlue; - - private FontInfo fontInfo; - - protected Hashtable options; - - - /** - * set the document's producer - * - * @param producer string indicating application producing the PostScript - */ - public void setProducer(String producer) { - this.producer = producer; - } - - - /** - * set up renderer options - */ - public void setOptions(Hashtable options) { - this.options = options; - } - - /** - * write out a command - */ - protected void write(String cmd) { - try { - out.write(cmd); - } catch (IOException e) { - if (!ioTrouble) - e.printStackTrace(); - ioTrouble = true; - } - } - - - /** - * write out a comment - */ - protected void comment(String comment) { - if (this.enableComments) - write(comment); - } - - - protected void writeFontDict(FontInfo fontInfo) { - write("%%BeginResource: procset FOPFonts"); - write("%%Title: Font setup (shortcuts) for this file"); - write("/FOPFonts 100 dict dup begin"); - write("/bd{bind def}bind def"); - write("/ld{load def}bd"); - write("/M/moveto ld"); - write("/RM/rmoveto ld"); - write("/t/show ld"); - - write("/ux 0.0 def"); - write("/uy 0.0 def"); - // write("/cf /Helvetica def"); - // write("/cs 12000 def"); - - // F - write("/F {"); - write(" /Tp exch def"); - // write(" currentdict exch get"); - write(" /Tf exch def"); - write(" Tf findfont Tp scalefont setfont"); - write(" /cf Tf def /cs Tp def /cw ( ) stringwidth pop def"); - write("} bd"); - - write("/ULS {currentpoint /uy exch def /ux exch def} bd"); - write("/ULE {"); - write(" /Tcx currentpoint pop def"); - write(" gsave"); - write(" newpath"); - write(" cf findfont cs scalefont dup"); - write(" /FontMatrix get 0 get /Ts exch def /FontInfo get dup"); - write(" /UnderlinePosition get Ts mul /To exch def"); - write(" /UnderlineThickness get Ts mul /Tt exch def"); - write(" ux uy To add moveto Tcx uy To add lineto"); - write(" Tt setlinewidth stroke"); - write(" grestore"); - write("} bd"); - - write("/OLE {"); - write(" /Tcx currentpoint pop def"); - write(" gsave"); - write(" newpath"); - write(" cf findfont cs scalefont dup"); - write(" /FontMatrix get 0 get /Ts exch def /FontInfo get dup"); - write(" /UnderlinePosition get Ts mul /To exch def"); - write(" /UnderlineThickness get Ts mul /Tt exch def"); - write(" ux uy To add cs add moveto Tcx uy To add cs add lineto"); - write(" Tt setlinewidth stroke"); - write(" grestore"); - write("} bd"); - - write("/SOE {"); - write(" /Tcx currentpoint pop def"); - write(" gsave"); - write(" newpath"); - write(" cf findfont cs scalefont dup"); - write(" /FontMatrix get 0 get /Ts exch def /FontInfo get dup"); - write(" /UnderlinePosition get Ts mul /To exch def"); - write(" /UnderlineThickness get Ts mul /Tt exch def"); - write(" ux uy To add cs 10 mul 26 idiv add moveto Tcx uy To add cs 10 mul 26 idiv add lineto"); - write(" Tt setlinewidth stroke"); - write(" grestore"); - write("} bd"); - - - - // write("/gfF1{/Helvetica findfont} bd"); - // write("/gfF3{/Helvetica-Bold findfont} bd"); - Hashtable fonts = fontInfo.getFonts(); - Enumeration enum = fonts.keys(); - while (enum.hasMoreElements()) { - String key = (String)enum.nextElement(); - Font fm = (Font)fonts.get(key); - write("/" + key + " /" + fm.fontName() + " def"); - } - write("end def"); - write("%%EndResource"); - enum = fonts.keys(); - while (enum.hasMoreElements()) { - String key = (String)enum.nextElement(); - Font fm = (Font)fonts.get(key); - write("/" + fm.fontName() + " findfont"); - write("dup length dict begin"); - write(" {1 index /FID ne {def} {pop pop} ifelse} forall"); - write(" /Encoding ISOLatin1Encoding def"); - write(" currentdict"); - write("end"); - write("/" + fm.fontName() + " exch definefont pop"); - } - } - - protected void movetoCurrPosition() { - write(this.currentXPosition + " " + this.currentYPosition + " M"); - } - - /** - * set up the font info - * - * @param fontInfo the font info object to set up - */ - public void setupFontInfo(FontInfo fontInfo) { - /* use PDF's font setup to get PDF metrics */ - org.apache.fop.render.pdf.FontSetup.setup(fontInfo); - this.fontInfo = fontInfo; - } - - /** - * render an area container to PostScript - * - * @param area the area container to render - */ - public void renderAreaContainer(AreaContainer area) { - int saveY = this.currentYPosition; - int saveX = this.currentAreaContainerXPosition; - if (area.getPosition() == Position.ABSOLUTE) { - // Y position is computed assuming positive Y axis, adjust for negative postscript one - this.currentYPosition = area.getYPosition() - - 2 * area.getPaddingTop() - - 2 * area.getBorderTopWidth(); - this.currentAreaContainerXPosition = area.getXPosition(); - } else if (area.getPosition() == Position.RELATIVE) { - this.currentYPosition -= area.getYPosition(); - this.currentAreaContainerXPosition += area.getXPosition(); - } else if (area.getPosition() == Position.STATIC) { - this.currentYPosition -= area.getPaddingTop() - + area.getBorderTopWidth(); - this.currentAreaContainerXPosition += area.getPaddingLeft() - + area.getBorderLeftWidth(); - } - - this.currentXPosition = this.currentAreaContainerXPosition; - - // comment("% --- AreaContainer begin"); - doFrame(area); - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box)e.nextElement(); - b.render(this); - } - // comment("% --- AreaContainer end"); - - if (area.getPosition() != Position.STATIC) { - this.currentYPosition = saveY; - this.currentAreaContainerXPosition = saveX; - } else { - this.currentYPosition -= area.getHeight(); - } - } - - /** - * render a body area container to PostScript - * - * @param area the body area container to render - */ - public void renderBodyAreaContainer(BodyAreaContainer area) { - int saveY = this.currentYPosition; - int saveX = this.currentAreaContainerXPosition; - - if (area.getPosition() == Position.ABSOLUTE) { - // Y position is computed assuming positive Y axis, adjust for negative postscript one - this.currentYPosition = area.getYPosition(); - this.currentAreaContainerXPosition = area.getXPosition(); - } else if (area.getPosition() == Position.RELATIVE) { - this.currentYPosition -= area.getYPosition(); - this.currentAreaContainerXPosition += area.getXPosition(); - } - - this.currentXPosition = this.currentAreaContainerXPosition; - int w, h; - int rx = this.currentAreaContainerXPosition; - w = area.getContentWidth(); - h = area.getContentHeight(); - int ry = this.currentYPosition; - - // comment("% --- BodyAreaContainer begin"); - doFrame(area); - // movetoCurrPosition(); - - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box)e.nextElement(); - b.render(this); - } - // comment("% --- BodyAreaContainer end"); - - if (area.getPosition() != Position.STATIC) { - this.currentYPosition = saveY; - this.currentAreaContainerXPosition = saveX; - } else { - this.currentYPosition -= area.getHeight(); - } - } - - /** - * render a span area to PostScript - * - * @param area the span area to render - */ - public void renderSpanArea(SpanArea area) { - // comment("% --- SpanArea begin"); - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box)e.nextElement(); - b.render(this); - } - // comment("% --- SpanArea end"); - } - - /** - * render a block area to PostScript - * - * @param area the block area to render - */ - public void renderBlockArea(BlockArea area) { - // comment("% --- BlockArea begin"); - doFrame(area); - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box)e.nextElement(); - b.render(this); - } - // comment("% --- BlockArea end"); - } - - /** - * render a display space to PostScript - * - * @param space the space to render - */ - public void renderDisplaySpace(DisplaySpace space) { - // write("% --- DisplaySpace size="+space.getSize()); - this.currentYPosition -= space.getSize(); - movetoCurrPosition(); - } - - /** - * render a foreign object area - */ - public void renderForeignObjectArea(ForeignObjectArea area) { - // if necessary need to scale and align the content - area.getObject().render(this); - } - - /** - * render an SVG area to PostScript - * - * @param area the area to render - */ - public void renderSVGArea(SVGArea area) { - int x = this.currentXPosition; - int y = this.currentYPosition; - Document doc = area.getSVGDocument(); - SVGSVGElement svg = ((SVGDocument)doc).getRootElement(); - int w = (int)(svg.getWidth().getBaseVal().getValue() * 1000); - int h = (int)(svg.getHeight().getBaseVal().getValue() * 1000); - float sx = 1, sy = -1; - int xOffset = x, yOffset = y; - - /* - * Clip to the svg area. - * Note: To have the svg overlay (under) a text area then use - * an fo:block-container - */ - comment("% --- SVG Area"); - write("gsave"); - if (w != 0 && h != 0) { - write("newpath"); - write(x / 1000f + " " + y / 1000f + " M"); - write((x + w) / 1000f + " " + y / 1000f + " rlineto"); - write((x + w) / 1000f + " " + (y - h) / 1000f + " rlineto"); - write(x / 1000f + " " + (y - h) / 1000f + " rlineto"); - write("closepath"); - write("clippath"); - } - // transform so that the coordinates (0,0) is from the top left - // and positive is down and to the right. (0,0) is where the - // viewBox puts it. - write(xOffset + " " + yOffset + " translate"); - write(sx + " " + sy + " " + " scale"); - - - UserAgent userAgent = new MUserAgent(new AffineTransform()); - - GVTBuilder builder = new GVTBuilder(); - GraphicsNodeRenderContext rc = getRenderContext(); - BridgeContext ctx = new BridgeContext(userAgent, rc); - GraphicsNode root; - PSGraphics2D graphics = new PSGraphics2D(false, area.getFontState(), - this, currentFontName, - currentFontSize, - currentXPosition, - currentYPosition); - graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext()); - graphics.setRenderingHints(rc.getRenderingHints()); - try { - root = builder.build(ctx, doc); - root.paint(graphics, rc); - } catch (Exception e) { - MessageHandler.errorln("Error: svg graphic could not be rendered: " - + e.getMessage()); - // e.printStackTrace(); - } - - - write("grestore"); - - comment("% --- SVG Area end"); - movetoCurrPosition(); - } - - public GraphicsNodeRenderContext getRenderContext() { - GraphicsNodeRenderContext nodeRenderContext = null; - if (nodeRenderContext == null) { - RenderingHints hints = new RenderingHints(null); - hints.put(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - - hints.put(RenderingHints.KEY_INTERPOLATION, - RenderingHints.VALUE_INTERPOLATION_BILINEAR); - - FontRenderContext fontRenderContext = - new FontRenderContext(new AffineTransform(), true, true); - - TextPainter textPainter = new StrokingTextPainter(); - // TextPainter textPainter = new PDFTextPainter(); - - GraphicsNodeRableFactory gnrFactory = - new ConcreteGraphicsNodeRableFactory(); - - nodeRenderContext = - new GraphicsNodeRenderContext(new AffineTransform(), null, - hints, fontRenderContext, - textPainter, gnrFactory); - nodeRenderContext.setTextPainter(textPainter); - } - - return nodeRenderContext; - } - - public void renderBitmap(FopImage img, int x, int y, int w, int h) { - try { - boolean iscolor = img.getColorSpace().getColorSpace() - != ColorSpace.DEVICE_GRAY; - byte[] imgmap = img.getBitmaps(); - - write("gsave"); - write("/DeviceRGB setcolorspace"); - write(x + " " + (y - h) + " translate"); - write(w + " " + h + " scale"); - write("<<"); - write(" /ImageType 1"); - write(" /Width " + img.getWidth()); - write(" /Height " + img.getHeight()); - write(" /BitsPerComponent 8"); - if (iscolor) { - write(" /Decode [0 1 0 1 0 1]"); - } else { - write(" /Decode [0 1]"); - } - // Setup scanning for left-to-right and top-to-bottom - write(" /ImageMatrix [" + img.getWidth() + " 0 0 -" - + img.getHeight() + " 0 " + img.getHeight() + "]"); - write(" /DataSource currentfile /ASCII85Decode filter /FlateDecode filter"); - // write(" /DataSource currentfile /ASCIIHexDecode filter /FlateDecode filter"); - // write(" /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter"); - // write(" /DataSource currentfile /ASCIIHexDecode filter /RunLengthDecode filter"); - // write(" /DataSource currentfile /ASCIIHexDecode filter"); - // write(" /DataSource currentfile /ASCII85Decode filter"); - // write(" /DataSource currentfile /RunLengthDecode filter"); - write(">>"); - write("image"); - - /* - * for (int y=0; y 127) { - sb = sb.append("\\" + Integer.toOctalString(mch)); - } else { - String escape = "\\()[]{}"; - if (escape.indexOf(mch) >= 0) { - sb.append("\\"); - } - sb = sb.append(mch); - } - } - // System.out.println("["+s+"] --> ["+sb.toString()+"]"); - - // comment("% --- InlineArea font-weight="+fontWeight+": " + sb.toString()); - useFont(fs.getFontName(), fs.getFontSize()); - useColor(area.getRed(), area.getGreen(), area.getBlue()); - if (area.getUnderlined() || area.getLineThrough() - || area.getOverlined()) - write("ULS"); - write("(" + sb.toString() + ") t"); - if (area.getUnderlined()) - write("ULE"); - if (area.getLineThrough()) - write("SOE"); - if (area.getOverlined()) - write("OLE"); - this.currentXPosition += area.getContentWidth(); - } - - public void useFont(String name, int size) { - if ((currentFontName != name) || (currentFontSize != size)) { - write(name + " " + size + " F"); - currentFontName = name; - currentFontSize = size; - } - } - - /** - * render an inline space to PostScript - * - * @param space the space to render - */ - public void renderInlineSpace(InlineSpace space) { - // write("% --- InlineSpace size="+space.getSize()); - this.currentXPosition += space.getSize(); - if (space.getUnderlined() || space.getLineThrough() - || space.getOverlined()) - write("ULS"); - write(space.getSize() + " 0 RM"); - if (space.getUnderlined()) - write("ULE"); - if (space.getLineThrough()) - write("SOE"); - if (space.getOverlined()) - write("OLE"); - } - - /** - * render a line area to PostScript - * - * @param area the area to render - */ - public void renderLineArea(LineArea area) { - int rx = this.currentAreaContainerXPosition + area.getStartIndent(); - int ry = this.currentYPosition; - int w = area.getContentWidth(); - int h = area.getHeight(); - - this.currentYPosition -= area.getPlacementOffset(); - this.currentXPosition = rx; - - int bl = this.currentYPosition; - movetoCurrPosition(); - - String fontWeight = area.getFontState().getFontWeight(); - // comment("% --- LineArea begin font-weight="+fontWeight); - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box)e.nextElement(); - this.currentYPosition = ry - area.getPlacementOffset(); - b.render(this); - } - // comment("% --- LineArea end"); - - this.currentYPosition = ry - h; - this.currentXPosition = rx; - } - - /** - * render a page to PostScript - * - * @param page the page to render - */ - public void renderPage(Page page) { - BodyAreaContainer body; - AreaContainer before, after; - write("%%Page: " + page.getNumber() + " " + page.getNumber()); - write("%%BeginPageSetup"); - write("FOPFonts begin"); - write("0.001 0.001 scale"); - write("%%EndPageSetup"); - body = page.getBody(); - before = page.getBefore(); - after = page.getAfter(); - if (before != null) { - renderAreaContainer(before); - } - renderBodyAreaContainer(body); - if (after != null) { - renderAreaContainer(after); - } - write("showpage"); - write("%%PageTrailer"); - write("%%EndPage"); - } - - /** - * render a leader area to PostScript - * - * @param area the area to render - */ - public void renderLeaderArea(LeaderArea area) { - int rx = this.currentXPosition; - int ry = this.currentYPosition; - int w = area.getContentWidth(); - int th = area.getRuleThickness(); - int th2 = th / 2; - int th3 = th / 3; - int th4 = th / 4; - - switch (area.getLeaderPattern()) { - case LeaderPattern.SPACE: - // NOP - - break; - case LeaderPattern.RULE: - if (area.getRuleStyle() == RuleStyle.NONE) - break; - useColor(area.getRed(), area.getGreen(), area.getBlue()); - write("gsave"); - write("0 setlinecap"); - switch (area.getRuleStyle()) { - case RuleStyle.DOTTED: - write("newpath"); - write("[1000 3000] 0 setdash"); - write(th + " setlinewidth"); - write(rx + " " + ry + " M"); - write(w + " 0 rlineto"); - useColor(area.getRed(), area.getGreen(), area.getBlue()); - write("stroke"); - break; - case RuleStyle.DASHED: - write("newpath"); - write("[3000 3000] 0 setdash"); - write(th + " setlinewidth"); - write(rx + " " + ry + " M"); - write(w + " 0 rlineto"); - useColor(area.getRed(), area.getGreen(), area.getBlue()); - write("stroke"); - break; - case RuleStyle.SOLID: - write("newpath"); - write(th + " setlinewidth"); - write(rx + " " + ry + " M"); - write(w + " 0 rlineto"); - useColor(area.getRed(), area.getGreen(), area.getBlue()); - write("stroke"); - break; - case RuleStyle.DOUBLE: - write("newpath"); - write(th3 + " setlinewidth"); - write(rx + " " + (ry - th3) + " M"); - write(w + " 0 rlineto"); - write(rx + " " + (ry + th3) + " M"); - write(w + " 0 rlineto"); - useColor(area.getRed(), area.getGreen(), area.getBlue()); - write("stroke"); - break; - case RuleStyle.GROOVE: - write(th2 + " setlinewidth"); - write("newpath"); - write(rx + " " + (ry - th4) + " M"); - write(w + " 0 rlineto"); - useColor(area.getRed(), area.getGreen(), area.getBlue()); - write("stroke"); - write("newpath"); - write(rx + " " + (ry + th4) + " M"); - write(w + " 0 rlineto"); - useColor(1, 1, 1); // white - write("stroke"); - break; - case RuleStyle.RIDGE: - write(th2 + " setlinewidth"); - write("newpath"); - write(rx + " " + (ry - th4) + " M"); - write(w + " 0 rlineto"); - useColor(1, 1, 1); // white - write("stroke"); - write("newpath"); - write(rx + " " + (ry + th4) + " M"); - write(w + " 0 rlineto"); - useColor(area.getRed(), area.getGreen(), area.getBlue()); - write("stroke"); - break; - } - write("grestore"); - break; - case LeaderPattern.DOTS: - comment("% --- Leader dots NYI"); - MessageHandler.errorln("Leader dots: Not yet implemented"); - break; - case LeaderPattern.USECONTENT: - comment("% --- Leader use-content NYI"); - MessageHandler.errorln("Leader use-content: Not yet implemented"); - break; - } - this.currentXPosition += area.getContentWidth(); - write(area.getContentWidth() + " 0 RM"); - } - - private void doFrame(Area area) { - int w, h; - int rx = this.currentAreaContainerXPosition; - w = area.getContentWidth(); - BorderAndPadding bap = area.getBorderAndPadding(); - - if (area instanceof BlockArea) - rx += ((BlockArea)area).getStartIndent(); - - h = area.getContentHeight(); - int ry = this.currentYPosition; - - rx = rx - area.getPaddingLeft(); - ry = ry + area.getPaddingTop(); - w = w + area.getPaddingLeft() + area.getPaddingRight(); - h = h + area.getPaddingTop() + area.getPaddingBottom(); - - rx = rx - area.getBorderLeftWidth(); - ry = ry + area.getBorderTopWidth(); - w = w + area.getBorderLeftWidth() + area.getBorderRightWidth(); - h = h + area.getBorderTopWidth() + area.getBorderBottomWidth(); - - // Create a textrect with these dimensions. - // The y co-ordinate is measured +ve downwards so subtract page-height - - ColorType bg = area.getBackgroundColor(); - if ((bg != null) && (bg.alpha() == 0)) { - write("newpath"); - write(rx + " " + ry + " M"); - write(w + " 0 rlineto"); - write("0 " + (-h) + " rlineto"); - write((-w) + " 0 rlineto"); - write("0 " + h + " rlineto"); - write("closepath"); - useColor(bg); - write("fill"); - } - - - if (area.getBorderTopWidth() != 0) { - write("newpath"); - write(rx + " " + ry + " M"); - write(w + " 0 rlineto"); - write(area.getBorderTopWidth() + " setlinewidth"); - write("0 setlinecap"); - useColor(bap.getBorderColor(BorderAndPadding.TOP)); - write("stroke"); - } - if (area.getBorderLeftWidth() != 0) { - write("newpath"); - write(rx + " " + ry + " M"); - write("0 " + (-h) + " rlineto"); - write(area.getBorderLeftWidth() + " setlinewidth"); - write("0 setlinecap"); - useColor(bap.getBorderColor(BorderAndPadding.LEFT)); - write("stroke"); - } - if (area.getBorderRightWidth() != 0) { - write("newpath"); - write((rx + w) + " " + ry + " M"); - write("0 " + (-h) + " rlineto"); - write(area.getBorderRightWidth() + " setlinewidth"); - write("0 setlinecap"); - useColor(bap.getBorderColor(BorderAndPadding.RIGHT)); - write("stroke"); - } - if (area.getBorderBottomWidth() != 0) { - write("newpath"); - write(rx + " " + (ry - h) + " M"); - write(w + " 0 rlineto"); - write(area.getBorderBottomWidth() + " setlinewidth"); - write("0 setlinecap"); - useColor(bap.getBorderColor(BorderAndPadding.BOTTOM)); - write("stroke"); - } - } - - private void useColor(ColorType col) { - useColor(col.red(), col.green(), col.blue()); - } - - private void useColor(float red, float green, float blue) { - if ((red != currRed) || (green != currGreen) || (blue != currBlue)) { - write(red + " " + green + " " + blue + " setrgbcolor"); - currRed = red; - currGreen = green; - currBlue = blue; - } - } - - protected class MUserAgent implements UserAgent { - AffineTransform currentTransform = null; - - /** - * Creates a new SVGUserAgent. - */ - protected MUserAgent(AffineTransform at) { - currentTransform = at; - } - - /** - * Displays an error message. - */ - public void displayError(String message) { - System.err.println(message); - } - - /** - * Displays an error resulting from the specified Exception. - */ - public void displayError(Exception ex) { - ex.printStackTrace(System.err); - } - - /** - * Displays a message in the User Agent interface. - * The given message is typically displayed in a status bar. - */ - public void displayMessage(String message) { - System.out.println(message); - } - - /** - * Returns a customized the pixel to mm factor. - */ - public float getPixelToMM() { - // this is set to 72dpi as the values in fo are 72dpi - return 0.3527777777777777778f; // 72 dpi - // return 0.26458333333333333333333333333333f; // 96dpi - } - - /** - * Returns the language settings. - */ - public String getLanguages() { - return "en"; // userLanguages; - } - - /** - * Returns the user stylesheet uri. - * @return null if no user style sheet was specified. - */ - public String getUserStyleSheetURI() { - return null; // userStyleSheetURI; - } - - /** - * Returns the class name of the XML parser. - */ - public String getXMLParserClassName() { - return org.apache.fop.apps.Driver.getParserClassName(); - } - - /** - * Opens a link in a new component. - * @param doc The current document. - * @param uri The document URI. - */ - public void openLink(SVGAElement elt) { - // application.openLink(uri); - } - - - public Point getClientAreaLocationOnScreen() { - return new Point(0, 0); - } - - public void setSVGCursor(java.awt.Cursor cursor) {} - - - public AffineTransform getTransform() { - return currentTransform; - } - - public Dimension2D getViewportSize() { - return new Dimension(100, 100); - } - - public EventDispatcher getEventDispatcher() { - return null; - } - - public boolean supportExtension(String str) { - return false; - } - - public boolean hasFeature(String str) { - return false; - } - - public void registerExtension(BridgeExtension be) {} - - public void handleElement(Element elt, Object data) {} - - } - - /** - Default start renderer method. This would - normally be overridden. (mark-fop@inomial.com). - */ - public void startRenderer(OutputStream outputStream) - throws IOException { - MessageHandler.logln("rendering areas to PostScript"); - - this.out = new PSStream(outputStream); - write("%!PS-Adobe-3.0"); - write("%%Creator: "+this.producer); - write("%%DocumentProcessColors: Black"); - write("%%DocumentSuppliedResources: procset FOPFonts"); - write("%%EndComments"); - write("%%BeginDefaults"); - write("%%EndDefaults"); - write("%%BeginProlog"); - write("%%EndProlog"); - write("%%BeginSetup"); - writeFontDict(fontInfo); - write("%%EndSetup"); - write("FOPFonts begin"); - } - - /** - Default stop renderer method. This would - normally be overridden. (mark-fop@inomial.com). - */ - public void stopRenderer(OutputStream outputStream) - throws IOException { - write("%%Trailer"); - write("%%EOF"); - this.out.flush(); - MessageHandler.logln("written out PostScript"); - } - - public void render(Page page, OutputStream outputStream) { - this.renderPage(page); - } -} diff --git a/src/org/apache/fop/render/ps/PSStream.java b/src/org/apache/fop/render/ps/PSStream.java deleted file mode 100644 index 9b03c11fd..000000000 --- a/src/org/apache/fop/render/ps/PSStream.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.ps; - -import java.io.*; - -public class PSStream extends FilterOutputStream { - - public PSStream(OutputStream out) { - super(out); - } - - public void write(String cmd) throws IOException { - if (cmd.length() > 255) - throw new RuntimeException("PostScript command exceeded limit of 255 characters"); - write(cmd.getBytes("US-ASCII")); - write('\n'); - } - -} diff --git a/src/org/apache/fop/render/txt/TXTRenderer.java b/src/org/apache/fop/render/txt/TXTRenderer.java deleted file mode 100755 index b173ab03c..000000000 --- a/src/org/apache/fop/render/txt/TXTRenderer.java +++ /dev/null @@ -1,1707 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -// package com.eastpoint.chrysalis; -package org.apache.fop.render.txt; - -// FOP -import org.apache.fop.render.PrintRenderer; -import org.apache.fop.render.pcl.*; -import org.apache.fop.messaging.MessageHandler; -import org.apache.fop.apps.FOPException; -import org.apache.fop.fo.properties.*; -import org.apache.fop.layout.*; -import org.apache.fop.layout.inline.*; -import org.apache.fop.datatypes.*; -import org.apache.fop.pdf.PDFPathPaint; -import org.apache.fop.pdf.PDFColor; -import org.apache.fop.image.*; - -import org.apache.fop.svg.SVGArea; - -import org.w3c.dom.svg.SVGSVGElement; -import org.w3c.dom.svg.SVGDocument; - -// Java -import java.io.IOException; -import java.io.OutputStream; -import java.util.Enumeration; -import java.util.Vector; -import java.util.Hashtable; - -/** - * Renderer that renders areas to plain text - * - * Modified by Mark Lillywhite mark-fop@inomial.com to use the new - * Renderer interface. - */ -public class TXTRenderer extends PrintRenderer { - - /** - * the current stream to add Text commands to - */ - PCLStream currentStream; - - private int pageHeight = 7920; - - // These variables control the virtual paggination functionality. - public int curdiv = 0; - private int divisions = -1; - private int paperheight = -1; // Paper height in decipoints? - public int orientation = - -1; // -1=default/unknown, 0=portrait, 1=landscape. - public int topmargin = -1; // Top margin in decipoints? - public int leftmargin = -1; // Left margin in decipoints? - private int fullmargin = 0; - final boolean debug = false; - - // Variables for rendering text. - StringBuffer charData[]; - StringBuffer decoData[]; - public float textCPI = 16.67f; - public float textLPI = 8; - int maxX = (int)(8.5f * textCPI + 1); - int maxY = (int)(11f * textLPI + 1); - float xFactor; - float yFactor; - public String lineEnding = - "\r\n"; // Every line except the last line on a page (which will end with pageEnding) will be terminated with this string. - public String pageEnding = - "\f"; // Every page except the last one will end with this string. - public boolean suppressGraphics = - false; // If true then graphics/decorations will not be rendered - text only. - boolean firstPage = false; - /** - * options - */ - protected Hashtable options; - - public TXTRenderer() {} - - /** - * set up renderer options - */ - public void setOptions(Hashtable options) { - this.options = options; - } - - /** - * set the TXT document's producer - * - * @param producer string indicating application producing PDF - */ - public void setProducer(String producer) {} - - - void addStr(int row, int col, String str, boolean ischar) { - if (debug) - System.out.println("TXTRenderer.addStr(" + row + ", " + col - + ", \"" + str + "\", " + ischar + ")"); - if (suppressGraphics &&!ischar) - return; - StringBuffer sb; - if (row < 0) - row = 0; - if (ischar) - sb = charData[row]; - else - sb = decoData[row]; - if (sb == null) - sb = new StringBuffer(); - if ((col + str.length()) > maxX) - col = maxX - str.length(); - if (col < 0) { - col = 0; - if (str.length() > maxX) - str = str.substring(0, maxX); - } - // Pad to col - for (int countr = sb.length(); countr < col; countr++) - sb.append(' '); - if (debug) - System.out.println("TXTRenderer.addStr() sb.length()=" - + sb.length()); - for (int countr = col; countr < (col + str.length()); countr++) { - if (countr >= sb.length()) - sb.append(str.charAt(countr - col)); - else { - if (debug) - System.out.println("TXTRenderer.addStr() sb.length()=" - + sb.length() + " countr=" + countr); - sb.setCharAt(countr, str.charAt(countr - col)); - } - } - - if (ischar) - charData[row] = sb; - else - decoData[row] = sb; - } - - /** - * add a line to the current stream - * - * @param x1 the start x location in millipoints - * @param y1 the start y location in millipoints - * @param x2 the end x location in millipoints - * @param y2 the end y location in millipoints - * @param th the thickness in millipoints - * @param stroke the line color - */ - protected void addLine(int x1, int y1, int x2, int y2, int th, - PDFPathPaint stroke) { - if (x1 == x2) { - addRect(x1, y1, th, y2 - y1 + 1, stroke, stroke); - } else if (y1 == y2) { - addRect(x1, y1, x2 - x1 + 1, th, stroke, stroke); - } - } - - /** - * add a line to the current stream - * - * @param x1 the start x location in millipoints - * @param y1 the start y location in millipoints - * @param x2 the end x location in millipoints - * @param y2 the end y location in millipoints - * @param th the thickness in millipoints - * @param rs the rule style - * @param stroke the line color - */ - protected void addLine(int x1, int y1, int x2, int y2, int th, int rs, - PDFPathPaint stroke) { - PDFColor lstroke = null; - if (rs == org.apache.fop.fo.properties.RuleStyle.DOTTED) - lstroke = new PDFColor(0.7f, 0.7f, 0.7f); - else - lstroke = (PDFColor)stroke; - if (x1 == x2) { - addRect(x1, y1, th, y2 - y1 + 1, lstroke, lstroke); - } else if (y1 == y2) { - addRect(x1, y1, x2 - x1 + 1, th, lstroke, lstroke); - } - } - - protected void addLine(float x1, float y1, float x2, float y2, - PDFColor sc, float sw) { - /* - * SVG - Not yet implemented - * if ( debug ) - * System.out.println("TXTRenderer.addLine(" + x1 + ", " + y1 + ", " + x2 + ", " + y2 + ", " + sc + ", " + sw + ")"); - * if ( x1 == x2 ) - * { - * addRect(x1 - sw/2, y1, sw, y2 - y1 + 1, 0, 0, sc, null, 0); - * } - * else if ( y1 == y2 || (Math.abs(y1 - y2) <= 0.24) ) // 72/300=0.24 - * { - * addRect(x1, y1 - sw/2, x2 - x1 + 1, sw, 0, 0, sc, null, 0); - * } - * else if ( sc != null ) - * { - * // Convert dimensions to characters. - * //float cfact = 300f / 72f; // 300 dpi, 1pt=1/72in - * int ix1 = (int)(x1 * xFactor); - * int iy1 = (int)(y1 * yFactor); - * int ix2 = (int)(x2 * xFactor); - * int iy2 = (int)(y2 * yFactor); - * int isw = (int)(sw * xFactor); - * int origix; - * // Normalize - * if ( iy1 > iy2 ) - * { - * int tmp = ix1; - * ix1 = ix2; - * ix2 = tmp; - * tmp = iy1; - * iy1 = iy2; - * iy2 = tmp; - * } - * if ( ix1 > ix2 ) - * { - * origix = ix2; - * ix1 -=ix2; - * ix2 = 0; - * } - * else - * { - * origix = ix1; - * ix2 -= ix1; - * ix1 = 0; - * } - * // Convert line width to a pixel run length. - * //System.out.println("TXTRenderer.addLine(" + ix1 + ", " + iy1 + ", " + ix2 + ", " + iy2 + ", " + isw + ")"); - * int runlen = (int)Math.sqrt(Math.pow(isw, 2) * (1 + Math.pow((ix1 - ix2) / (iy1 - iy2), 2))); - * if ( runlen < 1 ) - * runlen = 1; - * StringBuffer rlbuff = new StringBuffer(); - * for ( int countr = 0 ; countr < runlen ; countr++ ) - * rlbuff.append('*'); - * String rlstr = rlbuff.toString(); - * //System.out.println("TXTRenderer.addLine: runlen = " + runlen); - * // Draw the line. - * int d, dx, dy; - * int Aincr, Bincr; - * int xincr = 1; - * int x, y; - * dx = Math.abs(ix2 - ix1); - * dy = iy2 - iy1; - * if ( dx > dy ) - * { - * xincr = dx / dy; - * // Move to starting position. - * //currentStream.add("\033*p" + origix + "x" + iy1 + "Y"); - * x = ix1 - runlen / 2; - * iy2 += (isw / 2); - * // Start raster graphics - * //currentStream.add("\033*t300R\033*r" + dx + "s1A\033*b1M"); - * } - * else - * { - * // Move to starting position. - * //currentStream.add("\033*p" + (origix - runlen / 2) + "x" + iy1 + "Y"); - * x = ix1; - * // Start raster graphics - * //currentStream.add("\033*t300R\033*r1A\033*b1M"); - * } - * if ( ix1 > ix2 ) - * xincr *= -1; - * d = 2 * dx - dy; - * Aincr = 2 * (dx - dy); - * Bincr = 2 * dx; - * y = iy1; - * xferLineBytes(x, runlen, null, -1); - * - * for ( y = iy1 + 1 ; y <= iy2 ; y++ ) - * { - * if ( d >= 0 ) - * { - * x += xincr; - * d += Aincr; - * } - * else - * d += Bincr; - * xferLineBytes(x, runlen, null, -1); - * } - * // End raster graphics - * //currentStream.add("\033*rB"); - * // Return to regular print mode. - * //currentStream.add("\033*v0t0n0O"); - * } - */ - } - - private void xferLineBytes(int startpos, int bitcount, Vector save, - int start2) { - /* - * Not yet implemented - * //System.out.println("TXTRenderer.xferLineBytes(" + startpos + ", " + bitcount + ")"); - * int curbitpos = 0; - * if ( start2 > 0 && start2 <= (startpos + bitcount) ) - * { - * bitcount += (start2 - startpos); - * start2 = 0; - * } - * char bytes[] = new char[((start2>startpos?start2:startpos) + bitcount) / 4 + 2]; - * int dlen = 0; - * byte dbyte = 0; - * int bytepos = 0; - * do - * { - * int bits2set; - * if ( startpos < 0 ) - * { - * bits2set = bitcount + startpos; - * startpos = 0; - * } - * else - * bits2set = bitcount; - * byte bittype = 0; - * do - * { - * if ( bytepos > 0 ) - * { - * int inc = startpos - curbitpos; - * if ( (inc) >= (8 - bytepos) ) - * { - * curbitpos += (8 - bytepos); - * bytepos = 0; - * bytes[dlen++] = (char)0; - * bytes[dlen++] = (char)dbyte; - * dbyte = 0; - * } - * else - * { - * bytepos += inc; - * dbyte = (byte)(dbyte ^ (byte)(Math.pow(2, 8 - bytepos) - 1)); - * curbitpos += inc; - * } - * } - * // Set runs of whole bytes. - * int setbytes = (startpos - curbitpos) / 8; - * if ( setbytes > 0 ) - * { - * curbitpos += setbytes * 8; - * while ( setbytes > 0 ) - * { - * if ( setbytes > 256 ) - * { - * bytes[dlen++] = 0xFF; - * setbytes -= 256; - * } - * else - * { - * bytes[dlen++] = (char)((setbytes - 1) & 0xFF); - * setbytes = 0; - * } - * bytes[dlen++] = (char)bittype; - * } - * } - * // move to position in the first byte. - * if ( curbitpos < startpos ) - * { - * if ( bytepos == 0 ) - * dbyte = bittype; - * bytepos += startpos - curbitpos; - * dbyte = (byte)(dbyte ^ (byte)(Math.pow(2, 8 - bytepos) - 1)); - * curbitpos += bytepos; - * startpos += bits2set; - * } - * else - * { - * startpos += bits2set; - * } - * if ( bittype == 0 ) - * bittype = (byte)0xFF; - * else - * bittype = 7; - * } while ( bittype != 7 ); - * if ( start2 > 0 ) - * { - * startpos = start2; - * start2 = -1; - * } - * else - * startpos = -1; - * } while ( startpos >= 0 ); - * if ( bytepos > 0 ) - * { - * bytes[dlen++] = (char)0; - * bytes[dlen++] = (char)dbyte; - * } - * if ( save == null ) - * { - * //currentStream.add("\033*b" + dlen + "W"); - * //currentStream.add(new String(bytes, 0, dlen)); - * } - * else - * { - * String line = "\033*b" + dlen + "W" + new String(bytes, 0, dlen); - * //currentStream.add(line); - * save.addElement(line); - * } - */ - } - - /** - * add a rectangle to the current stream - * - * @param x the x position of left edge in millipoints - * @param y the y position of top edge in millipoints - * @param w the width in millipoints - * @param h the height in millipoints - * @param stroke the stroke color/gradient - */ - protected void addRect(int x, int y, int w, int h, PDFPathPaint stroke) { - if (h < 0) - h *= -1; - - if (h < 720 || w < 720) { - if (w < 720) - w = 720; - if (h < 720) - h = 720; - addRect(x, y, w, h, stroke, stroke); - } else { - addRect(x, y, w, 720, stroke, stroke); - addRect(x, y, 720, h, stroke, stroke); - addRect(x + w - 720, y, 720, h, stroke, stroke); - addRect(x, y - h + 720, w, 720, stroke, stroke); - } - } - - /** - * add a filled rectangle to the current stream - * - * @param x the x position of left edge in millipoints - * @param y the y position of top edge in millipoints - * @param w the width in millipoints - * @param h the height in millipoints - * @param fill the fill color/gradient - * @param stroke the stroke color/gradient - */ - protected void addRect(int x, int y, int w, int h, PDFPathPaint stroke, - PDFPathPaint fill) { - // System.out.println("TXTRenderer.addRect(" + x + ", " + y + ", " + w + ", " + h + ", " + r + ", " + g + ", " + b + ", " + fr + ", " + fg + ", " + fb + ")"); - if ((w == 0) || (h == 0)) - return; - if (h < 0) - h *= -1; - - int row = (int)((pageHeight - (y / 100)) * 100 * yFactor); - int col = (int)(x * xFactor); - - PDFColor sc = (PDFColor)stroke; - PDFColor fc = (PDFColor)fill; - - sc.setColorSpace(ColorSpace.DEVICE_RGB); - fc.setColorSpace(ColorSpace.DEVICE_RGB); - - int lineshade = - (int)(100 - - ((0.3f * sc.red() + 0.59f * sc.green() + 0.11f * sc.blue()) - * 100f)); - int fillshade = - (int)(100 - - ((0.3f * fc.red() + 0.59f * fc.green() + 0.11f * fc.blue()) - * 100f)); - if (debug) - System.out.println("TXTRenderer.addRect(" + x + ", " + y + ", " - + w + ", " + h + ", " + stroke + ", " + fill - + ") fillshade=" + fillshade); - char fillchar = ' '; - if (fillshade >= 75) - fillchar = '#'; - else if (fillshade >= 50) - fillchar = '*'; - else if (fillshade >= 25) - fillchar = ':'; - - - if (fillchar != ' ') { - StringBuffer linefill = new StringBuffer(); - int sw = (int)(w * xFactor); - int sh = (int)(h * yFactor); - if (sw == 0 || sh == 0) { - if (fillshade >= 50) { - if (h > w) - fillchar = '|'; - else - fillchar = '-'; - } else { - if (h > w) - fillchar = ':'; - else - fillchar = '.'; - } - } - if (sw == 0) - linefill.append(fillchar); - else - for (int countr = 0; countr < sw; countr++) - linefill.append(fillchar); - if (sh == 0) - addStr(row, col, linefill.toString(), false); - else - for (int countr = 0; countr < sh; countr++) - addStr(row + countr, col, linefill.toString(), false); - } - - if (lineshade >= 25) { - char vlinechar = '|'; - char hlinechar = '-'; - if (lineshade < 50) { - vlinechar = ':'; - hlinechar = '.'; - } - StringBuffer linefill = new StringBuffer(); - int sw = (int)(w * xFactor); - for (int countr = 0; countr < sw; countr++) - linefill.append(hlinechar); - int sh = (int)(h * yFactor); - - if (w > h) { - for (int countr = 1; countr < (sh - 1); countr++) { - addStr(row + countr, col, String.valueOf(vlinechar), - false); - addStr(row + countr, col + sw, String.valueOf(vlinechar), - false); - } - addStr(row, col, linefill.toString(), false); - addStr(row + sh, col, linefill.toString(), false); - - } else { - addStr(row, col, linefill.toString(), false); - addStr(row + sh, col, linefill.toString(), false); - for (int countr = 1; countr < (sh - 1); countr++) { - addStr(row + countr, col, String.valueOf(vlinechar), - false); - addStr(row + countr, col + sw, String.valueOf(vlinechar), - false); - } - - } - } - } - - - /** - * add a filled rectangle to the current stream - * - * @param x the x position of left edge in millipoints - * @param y the y position of top edge in millipoints - * @param w the width in millipoints - * @param h the height in millipoints - * @param r the red component of edges - * @param g the green component of edges - * @param b the blue component of edges - * @param fr the red component of the fill - * @param fg the green component of the fill - * @param fb the blue component of the fill - */ - protected void addRect(float x, float y, float w, float h, float rx, - float ry, PDFColor fc, PDFColor sc, float sw) { - /* - * SVG - Not yet implemented - * if ( debug ) - * System.out.println("TXTRenderer.addRect(" + x + ", " + y + ", " + w + ", " + h + ", " + rx + ", " + ry + ", " + fc + ", " + sc + ", " + sw + ")"); - * float sr = 1; - * float sg = 1; - * float sb = 1; - * float fr = 1; - * float fg = 1; - * float fb = 1; - * if ( sc != null && sw > 0 ) - * { - * sr = (float)sc.red(); - * sg = (float)sc.green(); - * sb = (float)sc.blue(); - * } - * if ( fc != null ) - * { - * fr = (float)fc.red(); - * fg = (float)fc.green(); - * fb = (float)fc.blue(); - * } - * addRect((int)(x * 1000), (int)(pageHeight * 100 - y * 1000), (int)(w * 1000), (int)(h * 1000), sr, sg, sb, fr, fg, fb); - * fc = null; - * sc = null; - * if ( rx == 0 || ry == 0 ) - * { - * if ( fc != null ) - * { - * int fillshade = (int)(100 - ((0.3f * fc.red() + 0.59f * fc.green() + 0.11f * fc.blue()) * 100f)); - * currentStream.add("\033*v0n1O\033&a" + (x * 10) + "h" + ((y * 10)) + "V" - * + "\033*c" + (w * 10) + "h" + (h * 10) + "v" + fillshade + "g2P\033*v0n0O"); - * } - * if ( sc != null && sw > 0 ) - * { - * String lend = "v" + String.valueOf((int)(100 - ((0.3f * sc.red() + 0.59f * sc.green() + 0.11f * sc.blue()) * 100f))) + "g2P"; - * currentStream.add("\033*v0n1O"); - * currentStream.add("\033&a" + ((x - sw/2) * 10) + "h" + (((y - sw/2)) * 10) + "V" - * + "\033*c" + ((w + sw) * 10) + "h" + ((sw) * 10) + lend); - * currentStream.add("\033&a" + ((x - sw/2) * 10) + "h" + (((y - sw/2)) * 10) + "V" - * + "\033*c" + ((sw) * 10) + "h" + ((h + sw) * 10) + lend); - * currentStream.add("\033&a" + ((x + w - sw/2) * 10) + "h" + (((y - sw/2)) * 10) + "V" - * + "\033*c" + ((sw) * 10) + "h" + ((h + sw) * 10) + lend); - * currentStream.add("\033&a" + ((x - sw/2) * 10) + "h" + (((y + h - sw/2)) * 10) + "V" - * + "\033*c" + ((w + sw) * 10) + "h" + ((sw) * 10) + lend); - * currentStream.add("\033*v0n0O"); - * } - * } - * else - * { - * // Convert dimensions to pixels. - * float cfact = 300f / 72f; // 300 dpi, 1pt=1/72in - * int ix = (int)(x * cfact); - * int iy = (int)(y * cfact); - * int iw = (int)(w * cfact); - * int ih = (int)(h * cfact); - * int irx = (int)(rx * cfact); - * int iry = (int)(ry * cfact); - * int isw = (int)(sw * cfact); - * int longwidth = 0; - * int pass = 0; - * PDFColor thecolor = null; - * do - * { - * if ( pass == 0 && fc != null ) - * { - * thecolor = fc; - * } - * else if ( pass == 1 && sc != null ) - * { - * int iswdiv2 = isw / 2; - * thecolor = sc; - * ix -= iswdiv2; - * iy -= iswdiv2; - * irx += iswdiv2; - * iry += iswdiv2; - * iw += isw; - * ih += isw; - * longwidth = (int)(isw * 1.414); - * } - * else - * thecolor = null; - * if ( thecolor != null ) - * { - * int tx = 0; - * int ty = iry; - * long a = irx; - * long b = iry; - * long Asquared = (long)Math.pow(a, 2); - * long TwoAsquared = 2 * Asquared; - * long Bsquared = (long)Math.pow(b, 2); - * long TwoBsquared = 2 * Bsquared; - * long d = Bsquared - Asquared * b + Asquared / 4; - * long dx = 0; - * long dy = TwoAsquared * b; - * int rectlen = iw - 2 * irx; - * Vector bottomlines = new Vector(); - * int x0 = tx; - * // Set Transparency modes and select shading. - * currentStream.add("\033*v0n1O\033*c" + (int)(100 - ((0.3f * thecolor.red() + 0.59f * thecolor.green() + 0.11f * thecolor.blue()) * 100f)) + "G\033*v2T"); - * // Move to starting position. - * currentStream.add("\033*p" + ix + "x" + iy + "Y"); - * // Start raster graphics - * currentStream.add("\033*t300R\033*r" + iw + "s1A\033*b1M"); - * while ( dx < dy ) - * { - * if ( d > 0 ) - * { - * if ( pass == 0 || ty > (iry - isw) ) - * xferLineBytes(irx - x0, rectlen + 2 * x0, bottomlines, -1); - * else - * xferLineBytes(irx - x0, longwidth, bottomlines, iw - irx + x0 - longwidth); - * x0 = tx + 1; - * ty--; - * dy -= TwoAsquared; - * d -= dy; - * } - * tx++; - * dx += TwoBsquared; - * d += Bsquared + dx; - * } - * d += (3 * (Asquared - Bsquared) / 2 - (dx + dy)) / 2; - * while ( ty > 0 ) - * { - * if ( pass == 0 || ty >= (iry - isw) ) - * xferLineBytes(irx - tx, rectlen + 2 * tx, bottomlines, -1); - * else - * xferLineBytes(irx - tx, isw, bottomlines, iw - irx + tx - isw); - * - * if ( d < 0 ) - * { - * tx++; - * dx += TwoBsquared; - * d += dx; - * } - * ty--; - * dy -= TwoAsquared; - * d += Asquared - dy; - * } - * // Draw the middle part of the rectangle - * int midlen = ih - 2 * iry; - * if ( midlen > 0 ) - * { - * if ( pass == 0 ) - * xferLineBytes(0, iw, null, -1); - * else - * xferLineBytes(0, isw, null, iw - isw); - * currentStream.add("\033*b3M"); - * for ( int countr = midlen - 1 ; countr > 0 ; countr-- ) - * currentStream.add("\033*b0W"); - * currentStream.add("\033*b1M"); - * } - * // Draw the bottom. - * for ( int countr = bottomlines.size() - 1 ; countr >= 0 ; countr-- ) - * currentStream.add((String)bottomlines.elementAt(countr)); - * // End raster graphics - * currentStream.add("\033*rB"); - * // Return to regular print mode. - * currentStream.add("\033*v0t0n0O"); - * } - * pass++; - * } while ( pass < 2 ); - * } - */ - } - - // Add a polyline or polygon. Does not support fills yet!!! - protected void addPolyline(Vector points, int posx, int posy, - PDFColor fc, PDFColor sc, float sw, - boolean close) {} - - - boolean printBMP(FopImage img, int x, int y, int w, - int h) throws FopImageException { - if (debug) - System.out.println("TXTRenderer.printBMP(" + img + ", " + x - + ", " + y + ", " + w + ", " + h + ")"); - addRect(x, y, w, h, new PDFColor(1f, 1f, 1f), - new PDFColor(0f, 0f, 0f)); - int nameh = (int)(h * yFactor / 2); - if (nameh > 0) { - int namew = (int)(w * xFactor); - - if (namew > 4) { - String iname = img.getURL(); - if (iname.length() >= namew) - addStr((int)((pageHeight - (y / 100)) * 100 * yFactor) - + nameh, (int)(x * xFactor), - iname.substring(iname.length() - namew), - true); - else - addStr((int)((pageHeight - (y / 100)) * 100 * yFactor) - + nameh, (int)(x * xFactor - + (namew - iname.length()) - / 2), iname, true); - - } - } - return (true); - } - - /** - * render image area to PCL - * - * @param area the image area to render - */ - public void renderImageArea(ImageArea area) { - int x = this.currentAreaContainerXPosition + area.getXOffset(); - int y = this.currentYPosition; - int w = area.getContentWidth(); - int h = area.getHeight(); - - this.currentYPosition -= h; - - FopImage img = area.getImage(); - - try { - printBMP(img, x, y, w, h); - } catch (FopImageException e) { - // e.printStackTrace(System.out); - MessageHandler.errorln("TXTRenderer.renderImageArea() Error printing BMP (" - + e.toString() + ")."); - } - } - - public void renderImage(FontState fontState, String href, float x, - float y, float width, float height) { - try { - if (href.indexOf(":") == -1) - href = "file:" + href; - FopImage img = FopImageFactory.Make(href); - if (img != null) { - if (img instanceof SVGImage) { - SVGSVGElement svg = - ((SVGImage)img).getSVGDocument().getRootElement(); - renderSVG(fontState, svg, (int)x * 1000, (int)y * 1000); - } else { - printBMP(img, (int)x, (int)y, (int)width, (int)height); - } - } - } catch (Exception e) { - MessageHandler.errorln("could not add image to SVG: " + href); - } - } - - /** - * render a foreign object area - */ - public void renderForeignObjectArea(ForeignObjectArea area) { - // if necessary need to scale and align the content - this.currentXPosition = this.currentXPosition + area.getXOffset(); - this.currentYPosition = this.currentYPosition; - switch (area.getAlign()) { - case TextAlign.START: - break; - case TextAlign.END: - break; - case TextAlign.CENTER: - case TextAlign.JUSTIFY: - break; - } - switch (area.getVerticalAlign()) { - case VerticalAlign.BASELINE: - break; - case VerticalAlign.MIDDLE: - break; - case VerticalAlign.SUB: - break; - case VerticalAlign.SUPER: - break; - case VerticalAlign.TEXT_TOP: - break; - case VerticalAlign.TEXT_BOTTOM: - break; - case VerticalAlign.TOP: - break; - case VerticalAlign.BOTTOM: - break; - } - // in general the content will not be text - - // align and scale - - switch (area.scalingMethod()) { - case Scaling.UNIFORM: - break; - case Scaling.NON_UNIFORM: - break; - } - // if the overflow is auto (default), scroll or visible - // then the contents should not be clipped, since this - // is considered a printing medium. - switch (area.getOverflow()) { - case Overflow.VISIBLE: - case Overflow.SCROLL: - case Overflow.AUTO: - break; - case Overflow.HIDDEN: - break; - } - area.getObject().render(this); - - this.currentXPosition += area.getEffectiveWidth(); - // this.currentYPosition -= area.getEffectiveHeight(); - } - - - void renderSVG(FontState fontState, SVGSVGElement svg, int x, int y) { - /* - * SVG - Not yet implemented - * NodeList nl = svg.getChildNodes(); - * for(int count = 0; count < nl.getLength(); count++) { - * Node n = nl.item(count); - * if(n instanceof SVGElement) { - * renderElement(fontState, (SVGElement)n, x, y); - * } - * } - */ - } - - /** - * render SVG area to Text - * - * @param area the SVG area to render - */ - public void renderSVGArea(SVGArea area) { - if (debug) - System.out.println("TXTRenderer.renderSVGArea(" + area + ")"); - int x = this.currentAreaContainerXPosition; - int y = this.currentYPosition; - SVGSVGElement svg = - ((SVGDocument)area.getSVGDocument()).getRootElement(); - int w = (int)(svg.getWidth().getBaseVal().getValue() * 1000); - int h = (int)(svg.getHeight().getBaseVal().getValue() * 1000); - - // currentStream.add("ET\n"); - /* - * Clip to the svg area. - * Note: To have the svg overlay (under) a text area then use - * an fo:block-container - */ - // currentStream.add("q\n"); - // currentStream.add(x / 1000f + " " + y / 1000f + " m\n"); - // currentStream.add((x + w) / 1000f + " " + y / 1000f + " l\n"); - // currentStream.add((x + w) / 1000f + " " + (y - h) / 1000f + " l\n"); - // currentStream.add(x / 1000f + " " + (y - h) / 1000f + " l\n"); - // currentStream.add("h\n"); - // currentStream.add("W\n"); - // currentStream.add("n\n"); - // transform so that the coordinates (0,0) is from the top left - // and positive is down and to the right - // currentStream.add(1 + " " + 0 + " " + 0 + " " + (-1) + " " + x / 1000f + " " + y / 1000f + " cm\n"); - - // TODO - translate and clip to viewbox - - renderSVG(area.getFontState(), svg, x, y); - - // Enumeration e = area.getChildren().elements(); - // while (e.hasMoreElements()) { - // Object o = e.nextElement(); - // if(o instanceof GraphicImpl) { - // renderElement(area, (GraphicImpl)o, x, y); - // } - // } - - // currentStream.add("Q\n"); - // currentStream.add("BT\n"); - // this.currentYPosition -= h; - } - - /* - * SVG - Not yet implemented - * public void renderElement(FontState fontState, SVGElement area, int posx, int posy) - * { - * if ( debug ) - * System.out.println("TXTRenderer.renderElement(" + fontState + ", " + area + ", " + posx + ", " + posy + ")"); - * int x = posx; - * int y = posy; - * CSSStyleDeclaration style = null; - * if ( area instanceof SVGStylable ) - * style = ((SVGStylable)area).getStyle(); - * PDFColor fillColour = null; - * PDFColor strokeColour = null; - * float strokeWidth = 0; - * //currentStream.add("q\n"); - * //if( area instanceof SVGTransformable ) - * //{ - * // SVGTransformable tf = (SVGTransformable)area; - * // SVGAnimatedTransformList trans = tf.getTransform(); - * // SVGRect bbox = tf.getBBox(); - * // if(trans != null) { - * // applyTransform(trans, bbox); - * // } - * //} - * if(style != null) - * { - * CSSValue sp = style.getPropertyCSSValue("fill"); - * if(sp != null) - * { - * if( sp.getValueType() == CSSValue.CSS_PRIMITIVE_VALUE ) - * { - * if( ((CSSPrimitiveValue)sp).getPrimitiveType() == CSSPrimitiveValue.CSS_RGBCOLOR ) - * { - * RGBColor col = ((CSSPrimitiveValue)sp).getRGBColorValue(); - * CSSPrimitiveValue val; - * val = col.getRed(); - * float red = val.getFloatValue(CSSPrimitiveValue.CSS_NUMBER); - * val = col.getGreen(); - * float green = val.getFloatValue(CSSPrimitiveValue.CSS_NUMBER); - * val = col.getBlue(); - * float blue = val.getFloatValue(CSSPrimitiveValue.CSS_NUMBER); - * fillColour = new PDFColor(red, green, blue); - * } - * } - * //if(sp instanceof ColorType) - * //{ - * // ColorType ct = (ColorType)sp; - * // fillColour = new PDFColor(ct.red(), ct.green(), ct.blue()); - * //} - * } - * else - * fillColour = new PDFColor(0, 0, 0); - * sp = style.getPropertyCSSValue("stroke"); - * if(sp != null) - * { - * if( sp.getValueType() == CSSValue.CSS_PRIMITIVE_VALUE ) - * { - * if( ((CSSPrimitiveValue)sp).getPrimitiveType() == CSSPrimitiveValue.CSS_RGBCOLOR ) - * { - * RGBColor col = ((CSSPrimitiveValue)sp).getRGBColorValue(); - * CSSPrimitiveValue val; - * val = col.getRed(); - * float red = val.getFloatValue(CSSPrimitiveValue.CSS_NUMBER); - * val = col.getGreen(); - * float green = val.getFloatValue(CSSPrimitiveValue.CSS_NUMBER); - * val = col.getBlue(); - * float blue = val.getFloatValue(CSSPrimitiveValue.CSS_NUMBER); - * strokeColour = new PDFColor(red, green, blue); - * } - * } - * //if(sp instanceof ColorType) - * //{ - * // ColorType ct = (ColorType)sp; - * // strokeColour = new PDFColor(ct.red(), ct.green(), ct.blue()); - * //} - * } - * sp = style.getPropertyCSSValue("stroke-width"); - * if(sp != null && sp.getValueType() == CSSValue.CSS_PRIMITIVE_VALUE) - * { - * strokeWidth = ((CSSPrimitiveValue)sp).getFloatValue(CSSPrimitiveValue.CSS_PT); - * //PDFNumber pdfNumber = new PDFNumber(); - * //currentStream.add(pdfNumber.doubleOut(width) + " w\n"); - * //strokeWidth = ((SVGLengthImpl)sp).getValue(); - * } - * else - * strokeWidth = 1; - * } - * if (area instanceof SVGRectElement) - * { - * SVGRectElement rg = (SVGRectElement)area; - * float rectx = rg.getX().getBaseVal().getValue() + posx / 1000; - * float recty = ((pageHeight / 10) - posy/1000) + rg.getY().getBaseVal().getValue(); - * float rx = rg.getRx().getBaseVal().getValue(); - * float ry = rg.getRy().getBaseVal().getValue(); - * float rw = rg.getWidth().getBaseVal().getValue(); - * float rh = rg.getHeight().getBaseVal().getValue(); - * addRect(rectx, recty, rw, rh, rx, ry, fillColour, strokeColour, strokeWidth); - * } - * else if (area instanceof SVGLineElement) - * { - * SVGLineElement lg = (SVGLineElement)area; - * float x1 = lg.getX1().getBaseVal().getValue() + posx / 1000; - * float y1 = ((pageHeight / 10) - posy/1000) + lg.getY1().getBaseVal().getValue(); - * float x2 = lg.getX2().getBaseVal().getValue() + posx / 1000; - * float y2 = ((pageHeight / 10) - posy/1000) + lg.getY2().getBaseVal().getValue(); - * addLine(x1,y1,x2,y2, strokeColour, strokeWidth); - * } - * else if (area instanceof SVGTextElementImpl) - * { - * //currentStream.add("BT\n"); - * renderText(fontState, (SVGTextElementImpl)area, posx / 1000f, ((float)(pageHeight / 10) - posy/1000f)); - * //currentStream.add("ET\n"); - * } - * else if (area instanceof SVGCircleElement) - * { - * SVGCircleElement cg = (SVGCircleElement)area; - * float cx = cg.getCx().getBaseVal().getValue() + posx / 1000; - * float cy = ((pageHeight / 10) - posy/1000) + cg.getCy().getBaseVal().getValue(); - * float r = cg.getR().getBaseVal().getValue(); - * //addCircle(cx,cy,r, di); - * addRect(cx - r, cy - r, 2 * r, 2 * r, r, r, fillColour, strokeColour, strokeWidth); - * } - * else if (area instanceof SVGEllipseElement) - * { - * SVGEllipseElement cg = (SVGEllipseElement)area; - * float cx = cg.getCx().getBaseVal().getValue() + posx / 1000; - * float cy = ((pageHeight / 10) - posy/1000) + cg.getCy().getBaseVal().getValue(); - * float rx = cg.getRx().getBaseVal().getValue(); - * float ry = cg.getRy().getBaseVal().getValue(); - * //addEllipse(cx,cy,rx,ry, di); - * addRect(cx - rx, cy - ry, 2 * rx, 2 * ry, rx, ry, fillColour, strokeColour, strokeWidth); - * } - * else if (area instanceof SVGPathElementImpl) - * { - * //addPath(((SVGPathElementImpl)area).pathElements, posx, posy, di); - * } - * else if (area instanceof SVGPolylineElementImpl) - * { - * addPolyline(((SVGPolylineElementImpl)area).points, posx, posy, fillColour, strokeColour, strokeWidth, false); - * } - * else if (area instanceof SVGPolygonElementImpl) - * { - * addPolyline(((SVGPolylineElementImpl)area).points, posx, posy, fillColour, strokeColour, strokeWidth, true); - * } - * else if (area instanceof SVGGElementImpl) - * { - * renderGArea(fontState, (SVGGElementImpl)area, x, y); - * } - * else if(area instanceof SVGUseElementImpl) - * { - * SVGUseElementImpl ug = (SVGUseElementImpl)area; - * String ref = ug.link; - * ref = ref.substring(1, ref.length()); - * SVGElement graph = null; - * //GraphicImpl graph = null; - * //graph = area.locateDef(ref); - * if(graph != null) { - * // probably not the best way to do this, should be able - * // to render without the style being set. - * //GraphicImpl parent = graph.getGraphicParent(); - * //graph.setParent(area); - * // need to clip (if necessary) to the use area - * // the style of the linked element is as if is was - * // a direct descendant of the use element. - * renderElement(fontState, graph, posx, posy); - * //graph.setParent(parent); - * } - * } - * else if (area instanceof SVGImageElementImpl) - * { - * SVGImageElementImpl ig = (SVGImageElementImpl)area; - * renderImage(fontState, ig.link, ig.x, ig.y, ig.width, ig.height); - * } - * else if (area instanceof SVGSVGElement) - * { - * // the x and y pos will be wrong! - * renderSVG(fontState, (SVGSVGElement)area, x, y); - * } - * else if (area instanceof SVGAElement) - * { - * SVGAElement ael = (SVGAElement)area; - * org.w3c.dom.NodeList nl = ael.getChildNodes(); - * for ( int count = 0 ; count < nl.getLength() ; count++ ) - * { - * org.w3c.dom.Node n = nl.item(count); - * if ( n instanceof SVGElement ) - * { - * if ( n instanceof GraphicElement ) - * { - * SVGRect rect = ((GraphicElement)n).getBBox(); - * if ( rect != null ) - * { - * // currentAnnotList = this.pdfDoc.makeAnnotList(); - * // currentPage.setAnnotList(currentAnnotList); - * // String dest = linkSet.getDest(); - * // int linkType = linkSet.getLinkType(); - * // currentAnnotList.addLink( - * // this.pdfDoc.makeLink(lrect.getRectangle(), dest, linkType)); - * // currentAnnotList = null; - * // } - * } - * renderElement(fontState, (SVGElement)n, posx, posy); - * } - * } - * } - * else if ( area instanceof SVGSwitchElement ) - * { - * handleSwitchElement(fontState, posx, posy, (SVGSwitchElement)area); - * } - * // should be done with some cleanup code, so only - * // required values are reset. - * //currentStream.add("Q\n"); - * } - */ - - private void setFont(String name, float size) { - return; - } - - /* - * SVG - Not implemented yet. - * public void renderText(FontState fontState, SVGTextElementImpl tg, float x, float y) - * { - * PDFNumber pdfNumber = new PDFNumber(); - * CSSStyleDeclaration styles; - * styles = tg.getStyle(); - * //applyStyle(tg, styles); - * // apply transform - * // text has a Tm and need to handle each element - * SVGTransformList trans = tg.getTransform().getBaseVal(); - * SVGMatrix matrix = trans.consolidate().getMatrix(); - * String transstr = (pdfNumber.doubleOut(matrix.getA()) - * + " " + pdfNumber.doubleOut(matrix.getB()) - * + " " + pdfNumber.doubleOut(matrix.getC()) - * + " " + pdfNumber.doubleOut(-matrix.getD()) + " "); - * String fontFamily = null; - * CSSValue sp = styles.getPropertyCSSValue("font-family"); - * if ( sp != null && sp.getValueType() == CSSValue.CSS_PRIMITIVE_VALUE ) - * { - * if ( ((CSSPrimitiveValue)sp).getPrimitiveType() == CSSPrimitiveValue.CSS_STRING ) - * fontFamily = sp.getCssText(); - * } - * if ( fontFamily == null ) - * fontFamily = fontState.getFontFamily(); - * String fontStyle = null; - * sp = styles.getPropertyCSSValue("font-style"); - * if ( sp != null && sp.getValueType() == CSSValue.CSS_PRIMITIVE_VALUE ) - * { - * if ( ((CSSPrimitiveValue)sp).getPrimitiveType() == CSSPrimitiveValue.CSS_STRING ) - * fontStyle = sp.getCssText(); - * } - * if ( fontStyle == null ) - * fontStyle = fontState.getFontStyle(); - * String fontWeight = null; - * sp = styles.getPropertyCSSValue("font-weight"); - * if( sp != null && sp.getValueType() == CSSValue.CSS_PRIMITIVE_VALUE ) - * { - * if ( ((CSSPrimitiveValue)sp).getPrimitiveType() == CSSPrimitiveValue.CSS_STRING ) - * fontWeight = sp.getCssText(); - * } - * if( fontWeight == null ) - * fontWeight = fontState.getFontWeight(); - * float fontSize; - * sp = styles.getPropertyCSSValue("font-size"); - * if( sp != null && sp.getValueType() == CSSValue.CSS_PRIMITIVE_VALUE ) - * { - * // if(((CSSPrimitiveValue)sp).getPrimitiveType() == CSSPrimitiveValue.CSS_NUMBER) { - * fontSize = ((CSSPrimitiveValue)sp).getFloatValue(CSSPrimitiveValue.CSS_PT); - * // } - * } - * else - * { - * fontSize = fontState.getFontSize() / 1000f; - * } - * FontState fs = fontState; - * try - * { - * fs = new FontState(fontState.getFontInfo(), fontFamily, fontStyle, - * fontWeight, (int)(fontSize * 1000)); - * } - * catch( Exception fope ) - * { - * // fope.printStackTrace(); - * } - * //currentStream.add("/" + fs.getFontName() + " " + fontSize + " Tf\n"); - * setFont(fs.getFontName(), fontSize * 1000); - * float tx = tg.x; - * float ty = tg.y; - * float currentX = x + tx; - * float currentY = y + ty; - * Vector list = tg.textList; - * for ( Enumeration e = list.elements() ; e.hasMoreElements() ; ) - * { - * Object o = e.nextElement(); - * styles = tg.getStyle(); - * //applyStyle(tg, styles); - * if( o instanceof String ) - * { - * String str = (String)o; - * //currentStream.add(transstr - * // + (currentX + matrix.getE()) + " " - * // + (y+ty + matrix.getF()) + " Tm " - * // + "("); - * boolean spacing = "preserve".equals(tg.getXMLspace()); - * //currentX = addSVGStr(fs, currentX, str, spacing); - * //currentStream.add(") Tj\n"); - * // for(int count = 0; count < str.length(); count++) { - * // } - * // currentX += fs.width(' ') / 1000f; - * currentStream.add("\033&a" + (currentX + matrix.getE())*10 + "h" + (y+ty + matrix.getF())*10 + "V" + str); - * for ( int count = 0; count < str.length(); count++ ) - * { - * currentX += fs.width(str.charAt(count)) / 1000f; - * } - * currentX += fs.width(' ') / 1000f; - * } else if(o instanceof SVGTextPathElementImpl) { - * SVGTextPathElementImpl tpg = (SVGTextPathElementImpl)o; - * String ref = tpg.str; - * SVGElement graph = null; - * // graph = tpg.locateDef(ref); - * if(graph != null && graph instanceof SVGPathElementImpl) { - * // probably not the best way to do this, should be able - * // to render without the style being set. - * // GraphicImpl parent = graph.getGraphicParent(); - * // graph.setParent(tpg); - * // set text path?? - * // how should this work - * // graph.setParent(parent); - * } - * } else if(o instanceof SVGTRefElementImpl) { - * SVGTRefElementImpl trg = (SVGTRefElementImpl)o; - * String ref = trg.ref; - * ref = ref.substring(1, ref.length()); - * SVGElement graph = null; - * // graph = trg.locateDef(ref); - * if(graph != null && graph instanceof SVGTextElementImpl) { - * // GraphicImpl parent = graph.getGraphicParent(); - * // graph.setParent(trg); - * SVGTextElementImpl te = (SVGTextElementImpl)graph; - * renderText(fs, te, (int)(x + tx), (int)(y + ty)); - * // graph.setParent(parent); - * } - * } else if(o instanceof SVGTSpanElementImpl) { - * SVGTSpanElementImpl tsg = (SVGTSpanElementImpl)o; - * styles = tsg.getStyle(); - * //applyStyle(tsg, styles); - * boolean changed = false; - * String newprop = null; - * sp = styles.getPropertyCSSValue("font-family"); - * if(sp != null && sp.getValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - * if(((CSSPrimitiveValue)sp).getPrimitiveType() == CSSPrimitiveValue.CSS_STRING) { - * newprop = sp.getCssText(); - * } - * } - * if(newprop != null && !newprop.equals(fontFamily)) { - * fontFamily = newprop; - * changed = true; - * } - * sp = styles.getPropertyCSSValue("font-style"); - * if(sp != null && sp.getValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - * if(((CSSPrimitiveValue)sp).getPrimitiveType() == CSSPrimitiveValue.CSS_STRING) { - * newprop = sp.getCssText(); - * } - * } - * if(newprop != null && !newprop.equals(fontStyle)) { - * fontStyle = newprop; - * changed = true; - * } - * sp = styles.getPropertyCSSValue("font-weight"); - * if(sp != null && sp.getValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - * if(((CSSPrimitiveValue)sp).getPrimitiveType() == CSSPrimitiveValue.CSS_STRING) { - * newprop = sp.getCssText(); - * } - * } - * if(newprop != null && !newprop.equals(fontWeight)) { - * fontWeight = newprop; - * changed = true; - * } - * float newSize = fontSize; - * sp = styles.getPropertyCSSValue("font-size"); - * if(sp != null && sp.getValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - * // if(((CSSPrimitiveValue)sp).getPrimitiveType() == CSSPrimitiveValue.CSS_NUMBER) { - * newSize = ((CSSPrimitiveValue)sp).getFloatValue(CSSPrimitiveValue.CSS_PT); - * // } - * } - * if ( fontSize != newSize ) - * { - * fontSize = newSize; - * changed = true; - * } - * FontState oldfs = null; - * if ( changed ) - * { - * oldfs = fs; - * try - * { - * fs = new FontState(fontState.getFontInfo(), fontFamily, fontStyle, - * fontWeight, (int)(fontSize * 1000)); - * } - * catch(Exception fope) - * { - * } - * setFont(fs.getFontName(), fontSize * 1000); - * //currentStream.add("/" + fs.getFontName() + " " + fontSize + " Tf\n"); - * } - * float baseX; - * float baseY; - * StringBuffer pdf = new StringBuffer(); - * boolean spacing = "preserve".equals(tsg.getXMLspace()); - * boolean inbetween = false; - * boolean addedspace = false; - * int charPos = 0; - * float xpos = currentX; - * float ypos = currentY; - * for ( int i=0 ; i < tsg.str.length() ; i++ ) - * { - * char ch = tsg.str.charAt(i); - * xpos = currentX; - * ypos = currentY; - * if ( tsg.ylist.size() > charPos ) - * ypos = y + ty + ((Float)tsg.ylist.elementAt(charPos)).floatValue(); - * if ( tsg.dylist.size() > charPos ) - * ypos = ypos + ((Float)tsg.dylist.elementAt(charPos)).floatValue(); - * if ( tsg.xlist.size() > charPos ) - * xpos = x + tx + ((Float)tsg.xlist.elementAt(charPos)).floatValue(); - * if ( tsg.dxlist.size() > charPos ) - * xpos = xpos + ((Float)tsg.dxlist.elementAt(charPos)).floatValue(); - * switch (ch) - * { - * case ' ': - * case ' ': - * if ( spacing ) - * { - * currentX = xpos + fs.width(' ') / 1000f; - * currentY = ypos; - * charPos++; - * } - * else - * { - * if ( inbetween && !addedspace) - * { - * addedspace = true; - * currentX = xpos + fs.width(' ') / 1000f; - * currentY = ypos; - * charPos++; - * } - * } - * break; - * case '\n': - * case '\r': - * if ( spacing ) - * { - * currentX = xpos + fs.width(' ') / 1000f; - * currentY = ypos; - * charPos++; - * } - * break; - * default: - * addedspace = false; - * pdf = pdf.append(transstr - * + (xpos + matrix.getE()) + " " - * + (ypos + matrix.getF()) + " Tm " - * + "(" + ch + ") Tj\n"); - * pdf = pdf.append("\033&a" + (xpos + matrix.getE())*10 + "h" + (ypos + matrix.getF())*10 + "V" + ch); - * currentX = xpos + fs.width(ch) / 1000f; - * currentY = ypos; - * charPos++; - * inbetween = true; - * break; - * } - * //currentStream.add(pdf.toString()); - * } - * // currentX += fs.width(' ') / 1000f; - * if ( changed ) - * { - * fs = oldfs; - * setFont(fs.getFontName(), fs.getFontSize() * 1000); - * //currentStream.add("/" + fs.getFontName() + " " + fs.getFontSize() / 1000f + " Tf\n"); - * } - * } - * else - * { - * System.err.println("Error: unknown text element " + o); - * } - * } - * } - */ - - /* - * SVG - Not yet implemented - * public void renderGArea(FontState fontState, SVGGElement area, int posx, int posy) - * { - * NodeList nl = area.getChildNodes(); - * for ( int count = 0 ; count < nl.getLength() ; count++ ) - * { - * Node n = nl.item(count); - * if ( n instanceof SVGElement ) - * renderElement(fontState, (SVGElement)n, posx, posy); - * } - * } - */ - - /* - * SVG - Not yet implemented - * void handleSwitchElement(FontState fontState, int posx, int posy, SVGSwitchElement ael) - * { - * SVGList relist = ael.getRequiredExtensions(); - * SVGList rflist = ael.getRequiredFeatures(); - * SVGList sllist = ael.getSystemLanguage(); - * org.w3c.dom.NodeList nl = ael.getChildNodes(); - * for(int count = 0; count < nl.getLength(); count++) { - * org.w3c.dom.Node n = nl.item(count); - * // only render the first child that has a valid - * // test data - * if(n instanceof GraphicElement) { - * GraphicElement graphic = (GraphicElement)n; - * SVGList grelist = graphic.getRequiredExtensions(); - * // if null it evaluates to true - * if(grelist != null) { - * for(int i = 0; i < grelist.getNumberOfItems(); i++) { - * String str = (String)grelist.getItem(i); - * if(relist == null) { - * // use default extension set - * // currently no extensions are supported - * // if(!(str.equals("http:// ??"))) { - * continue; - * // } - * } else { - * } - * } - * } - * SVGList grflist = graphic.getRequiredFeatures(); - * if(grflist != null) { - * for(int i = 0; i < grflist.getNumberOfItems(); i++) { - * String str = (String)grflist.getItem(i); - * if(rflist == null) { - * // use default feature set - * if(!(str.equals("org.w3c.svg.static") - * || str.equals("org.w3c.dom.svg.all"))) { - * continue; - * } - * } else { - * boolean found = false; - * for(int j = 0; j < rflist.getNumberOfItems(); j++) { - * if(rflist.getItem(j).equals(str)) { - * found = true; - * break; - * } - * } - * if(!found) - * continue; - * } - * } - * } - * SVGList gsllist = graphic.getSystemLanguage(); - * if(gsllist != null) { - * for(int i = 0; i < gsllist.getNumberOfItems(); i++) { - * String str = (String)gsllist.getItem(i); - * if(sllist == null) { - * // use default feature set - * if(!(str.equals("en"))) { - * continue; - * } - * } else { - * boolean found = false; - * for(int j = 0; j < sllist.getNumberOfItems(); j++) { - * if(sllist.getItem(j).equals(str)) { - * found = true; - * break; - * } - * } - * if(!found) - * continue; - * } - * } - * } - * renderElement(fontState, (SVGElement)n, posx, posy); - * // only render the first valid one - * break; - * } - * } - * } - */ - - /** - * render inline area to Text - * - * @param area inline area to render - */ - public void renderWordArea(WordArea area) { - // System.out.println("TXTRenderer.renderInlineArea: currentXPosition=" + this.currentXPosition + " currentYPosition=" + this.currentYPosition + " text=" + area.getText()); - int rx = this.currentXPosition; - int bl = this.currentYPosition; - - String s; - if (area.getPageNumberID() != null) { - // this text is a page number, so resolve it - s = idReferences.getPageNumber(area.getPageNumberID()); - if (s == null) - s = ""; - } else { - s = area.getText(); - } - - if (debug) - System.out.println("TXTRenderer.renderInlineArea: rx=" + rx - + " bl=" + bl + " pageHeight=" + pageHeight); - addStr((int)((pageHeight - (bl / 100)) * 100 * yFactor) - 1, - (int)(rx * xFactor), s, true); - - this.currentXPosition += area.getContentWidth(); - } - - /** - * render inline space to Text - * - * @param space space to render - */ - public void renderInlineSpace(InlineSpace space) { - this.currentXPosition += space.getSize(); - } - - /** - * render page into Text - * - * @param page page to render - */ - public void renderPage(Page page) { - if (debug) - System.out.println("TXTRenderer.renderPage() page.getHeight() = " - + page.getHeight()); - BodyAreaContainer body; - AreaContainer before, after, start, end; - - maxX = (int)(textCPI * page.getWidth() / 72000 + 1); - maxY = (int)(textLPI * page.getHeight() / 72000 + 1); - xFactor = (float)(maxX - 1) / (float)page.getWidth(); - yFactor = (float)(maxY - 1) / (float)page.getHeight(); - charData = new StringBuffer[maxY + 1]; - decoData = new StringBuffer[maxY + 1]; - - if (paperheight > 0) - pageHeight = paperheight; - else - pageHeight = page.getHeight() / 100; - - if (debug) - System.out.println("TXTRenderer.renderPage() maxX=" + maxX - + " maxY=" + maxY + " xFactor=" + xFactor - + " yFactor=" + yFactor + " paperHeight=" - + pageHeight); - - body = page.getBody(); - before = page.getBefore(); - after = page.getAfter(); - start = page.getStart(); - end = page.getEnd(); - - this.currentFontName = ""; - this.currentFontSize = 0; - - // currentStream.add("BT\n"); - renderBodyAreaContainer(body); - - if (before != null) - renderAreaContainer(before); - - if (after != null) - renderAreaContainer(after); - - if (start != null) - renderAreaContainer(start); - - if (end != null) - renderAreaContainer(end); - - // Write out the buffers. - for (int row = 0; row <= maxY; row++) { - StringBuffer cr = charData[row]; - StringBuffer dr = decoData[row]; - StringBuffer outr = null; - - if (cr != null && dr == null) - outr = cr; - else if (dr != null && cr == null) - outr = dr; - else if (cr != null && dr != null) { - int len = dr.length(); - if (cr.length() > len) - len = cr.length(); - outr = new StringBuffer(); - for (int countr = 0; countr < len; countr++) { - if (countr < cr.length() && cr.charAt(countr) != ' ') - outr.append(cr.charAt(countr)); - else if (countr < dr.length()) - outr.append(dr.charAt(countr)); - else - outr.append(' '); - } - } - - if (outr != null) - currentStream.add(outr.toString()); - if (row < maxY) - currentStream.add(lineEnding); - } - - // End page. - // if ( ++curdiv == divisions || divisions == -1 ) - // { - // curdiv = 0; - // currentStream.add("\f"); - // } - - // Links, etc not implemented... - /* - * currentPage = this.pdfDoc.makePage(this.pdfResources, currentStream, - * page.getWidth()/1000, - * page.getHeight()/1000, page); - * if (page.hasLinks()) { - * currentAnnotList = this.pdfDoc.makeAnnotList(); - * currentPage.setAnnotList(currentAnnotList); - * Enumeration e = page.getLinkSets().elements(); - * while (e.hasMoreElements()) { - * LinkSet linkSet = (LinkSet) e.nextElement(); - * linkSet.align(); - * String dest = linkSet.getDest(); - * int linkType = linkSet.getLinkType(); - * Enumeration f = linkSet.getRects().elements(); - * while (f.hasMoreElements()) { - * LinkedRectangle lrect = (LinkedRectangle) f.nextElement(); - * currentAnnotList.addLink( - * this.pdfDoc.makeLink(lrect.getRectangle(), dest, linkType)); - * } - * } - * } else { - * // just to be on the safe side - * currentAnnotList = null; - * } - */ - } - public void startRenderer(OutputStream outputStream) - throws IOException { - MessageHandler.logln("rendering areas to TEXT"); - currentStream = new PCLStream(outputStream); - firstPage=true; - } - - /** - * In Mark's patch, this is endRenderer - * However, I couldn't see how it builds that way, so - * i changed it. - Steve gears@apache.org - */ - - public void stopRenderer(OutputStream outputStream) - throws IOException { - MessageHandler.logln("writing out TEXT"); - outputStream.flush(); - } - - public void render(Page page, OutputStream outputStream) { - idReferences = page.getIDReferences(); - - if ( firstPage ) - firstPage = false; - else - currentStream.add(pageEnding); - this.renderPage(page); - currentStream.add(lineEnding); - } -} diff --git a/src/org/apache/fop/render/xml/XMLRenderer.java b/src/org/apache/fop/render/xml/XMLRenderer.java deleted file mode 100644 index 487d2c59c..000000000 --- a/src/org/apache/fop/render/xml/XMLRenderer.java +++ /dev/null @@ -1,453 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.render.xml; - -// FOP -import org.apache.fop.svg.*; -import org.apache.fop.messaging.MessageHandler; -import org.apache.fop.render.Renderer; -import org.apache.fop.image.ImageArea; -import org.apache.fop.layout.*; -import org.apache.fop.layout.inline.*; -import org.apache.fop.pdf.*; -import org.apache.fop.fo.properties.LeaderPattern; - -// Java -import java.io.IOException; -import java.io.PrintWriter; -import java.io.OutputStream; -import java.util.Enumeration; -import java.util.Hashtable; - -/** - * Renderer that renders areas to XML for debugging purposes. - * - * Modified by Mark Lillywhite mark-fop@inomial.com to use the - * new renderer interface. Not 100% certain that this is correct. - */ -public class XMLRenderer implements Renderer { - - /** - * indentation to use for pretty-printing the XML - */ - protected int indent = 0; - - /** - * the application producing the XML - */ - protected String producer; - - /** - * the writer used to output the XML - */ - protected PrintWriter writer; - - /** - * options - */ - protected Hashtable options; - - public XMLRenderer() {} - - /** - * set up renderer options - */ - public void setOptions(Hashtable options) { - this.options = options; - } - - /** - * set the document's producer - * - * @param producer string indicating application producing the XML - */ - public void setProducer(String producer) { - this.producer = producer; - } - - - public void render(Page page, OutputStream outputStream) - throws IOException { - this.renderPage(page); - } - - /** - * write out spaces to make indent - */ - protected void writeIndent() { - StringBuffer s = new StringBuffer(); - for (int i = 0; i < this.indent; i++) { - s = s.append(" "); - } - this.writer.write(s.toString()); - } - - /** - * write out an element - * - * @param element the full text of the element including tags - */ - protected void writeElement(String element) { - writeIndent(); - this.writer.write(element + "\n"); - } - - /** - * write out an empty-element-tag - * - * @param tag the text of the tag - */ - protected void writeEmptyElementTag(String tag) { - writeIndent(); - this.writer.write(tag + "\n"); - } - - /** - * write out an end tag - * - * @param tag the text of the tag - */ - protected void writeEndTag(String tag) { - this.indent--; - writeIndent(); - this.writer.write(tag + "\n"); - } - - /** - * write out a start tag - * - * @param tag the text of the tag - */ - protected void writeStartTag(String tag) { - writeIndent(); - this.writer.write(tag + "\n"); - this.indent++; - } - - /** - * set up the font info - * - * @param fontInfo the font info object to set up - */ - public void setupFontInfo(FontInfo fontInfo) { - - /* use PDF's font setup to get PDF metrics */ - org.apache.fop.render.pdf.FontSetup.setup(fontInfo); - } - - /** - * render an area container to XML - * - * @param area the area container to render - */ - public void renderAreaContainer(AreaContainer area) { - writeStartTag(""); - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box)e.nextElement(); - b.render(this); - } - writeEndTag(""); - } - - /** - * render a body area container to XML - * - * @param area the body area container to render - */ - public void renderBodyAreaContainer(BodyAreaContainer area) { - writeStartTag(""); - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box)e.nextElement(); - b.render(this); - } - writeEndTag(""); - } - - /** - * render a span area to XML - * - * @param area the span area to render - */ - public void renderSpanArea(SpanArea area) { - writeStartTag(""); - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box)e.nextElement(); - b.render(this); - } - writeEndTag(""); - } - - /** - * render a block area to XML - * - * @param area the block area to render - */ - public void renderBlockArea(BlockArea area) { - StringBuffer baText = new StringBuffer(); - baText.append(""); - writeStartTag(baText.toString()); - - // write out marker info - java.util.Vector markers = area.getMarkers(); - if (!markers.isEmpty()) { - writeStartTag(""); - for (int m = 0; m < markers.size(); m++) { - org.apache.fop.fo.flow.Marker marker = - (org.apache.fop.fo.flow.Marker)markers.elementAt(m); - StringBuffer maText = new StringBuffer(); - maText.append(""); - writeEmptyElementTag(maText.toString()); - } - writeEndTag(""); - } - - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box)e.nextElement(); - b.render(this); - } - writeEndTag(""); - } - - public void renderInlineArea(InlineArea area) { - StringBuffer iaText = new StringBuffer(); - iaText.append(""); - writeStartTag(iaText.toString()); - - // write out marker info - java.util.Vector markers = area.getMarkers(); - if (!markers.isEmpty()) { - writeStartTag(""); - for (int m = 0; m < markers.size(); m++) { - org.apache.fop.fo.flow.Marker marker = - (org.apache.fop.fo.flow.Marker)markers.elementAt(m); - StringBuffer maText = new StringBuffer(); - maText.append(""); - writeEmptyElementTag(maText.toString()); - } - writeEndTag(""); - } - - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box)e.nextElement(); - b.render(this); - } - writeEndTag(""); - } - - /** - * render a display space to XML - * - * @param space the space to render - */ - public void renderDisplaySpace(DisplaySpace space) { - if (!isCoarseXml()) - writeEmptyElementTag(""); - } - - /** - * render a foreign object area - */ - public void renderForeignObjectArea(ForeignObjectArea area) { - // if necessary need to scale and align the content - area.getObject().render(this); - } - - /** - * render an SVG area to XML - * - * @param area the area to render - */ - public void renderSVGArea(SVGArea area) { - writeEmptyElementTag(""); - } - - /** - * render an image area to XML - * - * @param area the area to render - */ - public void renderImageArea(ImageArea area) { - writeEmptyElementTag(""); - } - - /** - * render an inline area to XML - * - * @param area the area to render - */ - public void renderWordArea(WordArea area) { - String fontWeight = area.getFontState().getFontWeight(); - StringBuffer sb = new StringBuffer(); - String s = area.getText(); - int l = s.length(); - for (int i = 0; i < l; i++) { - char ch = s.charAt(i); - if (ch > 127) - sb = sb.append("&#" + (int)ch + ";"); - else - sb = sb.append(ch); - } - if (!isCoarseXml()) { - writeElement("" - + sb.toString() + ""); - } else { - this.writer.write(sb.toString()); - } - } - - /** - * render an inline space to XML - * - * @param space the space to render - */ - public void renderInlineSpace(InlineSpace space) { - if (!isCoarseXml()) - writeEmptyElementTag(""); - else - this.writer.write(" "); - } - - /** - * render a line area to XML - * - * @param area the area to render - */ - public void renderLineArea(LineArea area) { - if (!isCoarseXml()) { - String fontWeight = area.getFontState().getFontWeight(); - writeStartTag(""); - } - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box)e.nextElement(); - b.render(this); - } - if (!isCoarseXml()) - writeEndTag(""); - else - this.writer.write("\n"); - } - - /** - * render a page to XML - * - * @param page the page to render - */ - public void renderPage(Page page) { - BodyAreaContainer body; - AreaContainer before, after; - writeStartTag(""); - body = page.getBody(); - before = page.getBefore(); - after = page.getAfter(); - if (before != null) { - renderAreaContainer(before); - } - renderBodyAreaContainer(body); - if (after != null) { - renderAreaContainer(after); - } - writeEndTag(""); - } - - /** - * render a leader area to XML - * - * @param area the area to render - */ - public void renderLeaderArea(LeaderArea area) { - if (isCoarseXml()) - return; - String leaderPattern = ""; - switch (area.getLeaderPattern()) { - case LeaderPattern.SPACE: - leaderPattern = "space"; - break; - case LeaderPattern.RULE: - leaderPattern = "rule"; - break; - case LeaderPattern.DOTS: - leaderPattern = "dots"; - break; - case LeaderPattern.USECONTENT: - leaderPattern = "use-content"; - break; - } - - writeEmptyElementTag(""); - } - - private boolean isCoarseXml() { - return ((Boolean)options.get("fineDetail")).booleanValue(); - } - - /** - Default start renderer method. This would - normally be overridden. (mark-fop@inomial.com). - */ - public void startRenderer(OutputStream outputStream) - throws IOException { - MessageHandler.logln("rendering areas to XML"); - this.writer = new PrintWriter(outputStream); - this.writer.write( "\n\n"); - writeStartTag(""); - } - - /** - Default stop renderer method. This would - normally be overridden. (mark-fop@inomial.com). - */ - public void stopRenderer(OutputStream outputStream) - throws IOException { - writeEndTag(""); - this.writer.flush(); - MessageHandler.errorln("written out XML"); - } -} diff --git a/src/org/apache/fop/render/xml/package.html b/src/org/apache/fop/render/xml/package.html deleted file mode 100644 index ecabe3547..000000000 --- a/src/org/apache/fop/render/xml/package.html +++ /dev/null @@ -1,6 +0,0 @@ - -org.apache.fop.render.xml Package - -

classes for rendering to XML for debugging

- - \ No newline at end of file diff --git a/src/org/apache/fop/svg/PDFAElementBridge.java b/src/org/apache/fop/svg/PDFAElementBridge.java deleted file mode 100644 index 560e8fb13..000000000 --- a/src/org/apache/fop/svg/PDFAElementBridge.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.svg; - -import java.awt.Cursor; - -import org.apache.batik.bridge.*; - -import org.apache.batik.css.HiddenChildElementSupport; -import org.apache.batik.gvt.CompositeGraphicsNode; -import org.apache.batik.gvt.GraphicsNode; - -import org.apache.fop.pdf.*; - -import org.w3c.dom.Element; -import org.w3c.dom.events.Event; -import org.w3c.dom.events.EventListener; -import org.w3c.dom.events.EventTarget; -import org.w3c.dom.svg.SVGAElement; - -/** - * Bridge class for the <a> element. - * - * @author Keiron Liddle - */ -public class PDFAElementBridge extends AbstractGraphicsNodeBridge { - PDFGraphics2D pdfDoc; - - /** - * Constructs a new bridge for the <a> element. - */ - public PDFAElementBridge() {} - - public void setPDFGraphics2D(PDFGraphics2D doc) { - this.pdfDoc = doc; - } - - /** - * Returns 'a'. - */ - public String getLocalName() { - return SVG_A_TAG; - } - - /** - * Creates a CompositeGraphicsNode. - */ - protected GraphicsNode instantiateGraphicsNode() { - return new PDFANode(); - } - - /** - * Builds using the specified BridgeContext and element, the - * specified graphics node. - * - * @param ctx the bridge context to use - * @param e the element that describes the graphics node to build - * @param node the graphics node to build - */ - public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) { - PDFANode aNode = (PDFANode)super.createGraphicsNode(ctx, e); - return aNode; - } - - /** - * Returns true as the <a> element is a container. - */ - public boolean isComposite() { - return true; - } - -} diff --git a/src/org/apache/fop/svg/PDFANode.java b/src/org/apache/fop/svg/PDFANode.java deleted file mode 100644 index e604e74d0..000000000 --- a/src/org/apache/fop/svg/PDFANode.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.svg; - -import org.apache.batik.gvt.*; - -import java.awt.Graphics2D; -import java.awt.Shape; -import java.awt.geom.Rectangle2D; -import java.awt.geom.Point2D; -import java.awt.geom.Dimension2D; - -/** - * A graphics node that represents an image described as a graphics node. - * - * @author Keiron Liddle - */ -public class PDFANode extends CompositeGraphicsNode { - - /** - * Constructs a new empty PDFANode. - */ - public PDFANode() {} - - /** - * Paints this node if visible. - * - * @param g2d the Graphics2D to use - * @param rc the GraphicsNodeRenderContext to use - */ - public void paint(Graphics2D g2d, GraphicsNodeRenderContext rc) { - if (isVisible) { - super.paint(g2d, rc); - } - } - - // - // Properties methods - // - -} - diff --git a/src/org/apache/fop/svg/PDFDocumentGraphics2D.java b/src/org/apache/fop/svg/PDFDocumentGraphics2D.java deleted file mode 100644 index 05f230a34..000000000 --- a/src/org/apache/fop/svg/PDFDocumentGraphics2D.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.svg; - -import org.apache.fop.pdf.*; -import org.apache.fop.fonts.*; -import org.apache.fop.render.pdf.FontSetup; -import org.apache.fop.layout.*; -import org.apache.fop.apps.FOPException; - -import java.awt.Graphics; -import java.awt.Font; -import java.awt.Image; -import java.awt.Color; -import java.awt.Shape; -import java.awt.font.FontRenderContext; -import java.awt.font.GlyphVector; -import java.io.OutputStream; -import java.io.IOException; - -import org.apache.batik.ext.awt.g2d.GraphicContext; - -/** - * This class is a wrapper for the PDFGraphics2D that - * is used to create a full document around the pdf rendering from - * PDFGraphics2D. - * - * @author Keiron Liddle - * @version $Id$ - * @see org.apache.fop.svg.PDFGraphics2D - */ -public class PDFDocumentGraphics2D extends PDFGraphics2D { - OutputStream stream; - - PDFStream pdfStream; - int width; - int height; - - FontInfo fontInfo = null; - - /** - * Create a new PDFDocumentGraphics2D. - * This is used to create a new pdf document of the given height - * and width. - * The resulting document is written to the stream after rendering. - * - * @param textAsShapes set this to true so that text will be rendered - * using curves and not the font. - * @param stream the stream that the final document should be written to. - * @param width the width of the document - * @param height the height of the document - */ - public PDFDocumentGraphics2D(boolean textAsShapes, OutputStream stream, - int width, int height) { - super(textAsShapes); - - if (!textAsShapes) { - fontInfo = new FontInfo(); - FontSetup.setup(fontInfo); - try { - fontState = new FontState(fontInfo, "Helvetica", "normal", - "normal", 12, 0); - } catch (FOPException e) {} - } - standalone = true; - this.stream = stream; - this.pdfDoc = new PDFDocument(); - this.pdfDoc.setProducer("FOP SVG Renderer"); - pdfStream = this.pdfDoc.makeStream(); - this.width = width; - this.height = height; - - currentFontName = ""; - currentFontSize = 0; - currentYPosition = 0; - currentXPosition = 0; - - currentStream.write("1 0 0 -1 0 " + height + " cm\n"); - - } - - public FontState getFontState() { - return fontState; - } - - public PDFDocument getPDFDocument() { - return this.pdfDoc; - } - - /** - * Set the dimensions of the svg document that will be drawn. - * This is useful if the dimensions of the svg document are different - * from the pdf document that is to be created. - * The result is scaled so that the svg fits correctly inside the pdf document. - */ - public void setSVGDimension(float w, float h) { - currentStream.write("" + PDFNumber.doubleOut(width / w) + " 0 0 " - + PDFNumber.doubleOut(height / h) + " 0 0 cm\n"); - } - - /** - * Set the background of the pdf document. - * This is used to set the background for the pdf document - * Rather than leaving it as the default white. - */ - public void setBackgroundColor(Color col) { - Color c = col; - currentColour = new PDFColor(c.getRed(), c.getGreen(), c.getBlue()); - currentStream.write("q\n"); - currentStream.write(currentColour.getColorSpaceOut(true)); - - currentStream.write("0 0 " + width + " " + height + " re\n"); - - currentStream.write("f\n"); - currentStream.write("Q\n"); - } - - /** - * The rendering process has finished. - * This should be called after the rendering has completed as there is - * no other indication it is complete. - * This will then write the results to the output stream. - */ - public void finish() throws IOException { - pdfStream.add(getString()); - PDFResources pdfResources = this.pdfDoc.getResources(); - PDFPage currentPage = this.pdfDoc.makePage(pdfResources, pdfStream, - width, height, null); - if (fontInfo != null) { - FontSetup.addToResources(this.pdfDoc, fontInfo); - } - pdfDoc.outputHeader(stream); - this.pdfDoc.output(stream); - pdfDoc.outputTrailer(stream); - } - - public void setGraphicContext(GraphicContext c) { - gc = c; - } - - /** - * This constructor supports the create method - */ - public PDFDocumentGraphics2D(PDFDocumentGraphics2D g) { - super(g); - } - - /** - * Creates a new Graphics object that is - * a copy of this Graphics object. - * @return a new graphics context that is a copy of - * this graphics context. - */ - public Graphics create() { - return new PDFDocumentGraphics2D(this); - } - - public void drawString(String s, float x, float y) { - if (super.textAsShapes) { - Font font = super.getFont(); - FontRenderContext frc = super.getFontRenderContext(); - GlyphVector gv = font.createGlyphVector(frc, s); - Shape glyphOutline = gv.getOutline(x, y); - super.fill(glyphOutline); - } else { - super.drawString(s, x, y); - } - } - -} - diff --git a/src/org/apache/fop/svg/PDFGraphics2D.java b/src/org/apache/fop/svg/PDFGraphics2D.java deleted file mode 100644 index e60c749aa..000000000 --- a/src/org/apache/fop/svg/PDFGraphics2D.java +++ /dev/null @@ -1,1175 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.svg; - -import org.apache.fop.pdf.*; -import org.apache.fop.layout.*; -import org.apache.fop.fonts.*; -import org.apache.fop.render.pdf.*; -import org.apache.fop.image.*; -import org.apache.fop.datatypes.ColorSpace; - -import org.apache.batik.ext.awt.g2d.*; -import org.apache.batik.ext.awt.image.GraphicsUtil; - -import java.text.AttributedCharacterIterator; -import java.text.CharacterIterator; -import java.awt.*; -import java.awt.Font; -import java.awt.Image; -import java.awt.image.*; -import java.awt.font.*; -import java.awt.geom.*; -import java.awt.image.renderable.*; -import java.io.*; - -import java.util.Map; -import java.util.Vector; - -/** - * This concrete implementation of AbstractGraphics2D is a - * simple help to programmers to get started with their own - * implementation of Graphics2D. - * DefaultGraphics2D implements all the abstract methods - * is AbstractGraphics2D and makes it easy to start - * implementing a Graphic2D piece-meal. - * - * @author Keiron Liddle - * @version $Id$ - * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D - */ -public class PDFGraphics2D extends AbstractGraphics2D { - boolean standalone = false; - - /** - * the PDF Document being created - */ - protected PDFDocument pdfDoc; - - protected FontState fontState; - - /** - * the current stream to add PDF commands to - */ - StringWriter currentStream = new StringWriter(); - - /** - * the current (internal) font name - */ - protected String currentFontName; - - /** - * the current font size in millipoints - */ - protected int currentFontSize; - - /** - * the current vertical position in millipoints from bottom - */ - protected int currentYPosition = 0; - - /** - * the current horizontal position in millipoints from left - */ - protected int currentXPosition = 0; - - /** - * the current colour for use in svg - */ - PDFColor currentColour = new PDFColor(0, 0, 0); - - /** - * Create a new PDFGraphics2D with the given pdf document info. - * This is used to create a Graphics object for use inside an already - * existing document. - */ - public PDFGraphics2D(boolean textAsShapes, FontState fs, PDFDocument doc, - String font, int size, int xpos, int ypos) { - super(textAsShapes); - pdfDoc = doc; - currentFontName = font; - currentFontSize = size; - currentYPosition = ypos; - currentXPosition = xpos; - fontState = fs; - } - - public PDFGraphics2D(boolean textAsShapes) { - super(textAsShapes); - } - - public String getString() { - return currentStream.toString(); - } - - public void setGraphicContext(GraphicContext c) { - gc = c; - } - - /** - * This constructor supports the create method - */ - public PDFGraphics2D(PDFGraphics2D g) { - super(g); - } - - /** - * Creates a new Graphics object that is - * a copy of this Graphics object. - * @return a new graphics context that is a copy of - * this graphics context. - */ - public Graphics create() { - return new PDFGraphics2D(this); - } - - /** - * Draws as much of the specified image as is currently available. - * The image is drawn with its top-left corner at - * (xy) in this graphics context's coordinate - * space. Transparent pixels in the image do not affect whatever - * pixels are already there. - *

- * This method returns immediately in all cases, even if the - * complete image has not yet been loaded, and it has not been dithered - * and converted for the current output device. - *

- * If the image has not yet been completely loaded, then - * drawImage returns false. As more of - * the image becomes available, the process that draws the image notifies - * the specified image observer. - * @param img the specified image to be drawn. - * @param x the x coordinate. - * @param y the y coordinate. - * @param observer object to be notified as more of - * the image is converted. - * @see java.awt.Image - * @see java.awt.image.ImageObserver - * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int) - */ - public boolean drawImage(Image img, int x, int y, - ImageObserver observer) { - // System.err.println("drawImage:x, y"); - - final int width = img.getWidth(observer); - final int height = img.getHeight(observer); - if (width == -1 || height == -1) { - return false; - } - - Dimension size = new Dimension(width, height); - BufferedImage buf = buildBufferedImage(size); - - java.awt.Graphics2D g = buf.createGraphics(); - g.setComposite(AlphaComposite.SrcOver); - g.setBackground(new Color(1, 1, 1, 0)); - g.setPaint(new Color(1, 1, 1, 0)); - g.fillRect(0, 0, width, height); - g.clip(new Rectangle(0, 0, buf.getWidth(), buf.getHeight())); - - if (!g.drawImage(img, 0, 0, observer)) { - return false; - } - g.dispose(); - - final byte[] result = new byte[buf.getWidth() * buf.getHeight() * 3]; - final byte[] mask = new byte[buf.getWidth() * buf.getHeight()]; - - Raster raster = buf.getData(); - DataBuffer bd = raster.getDataBuffer(); - - int count = 0; - int maskpos = 0; - int[] iarray; - int i, j, val, alpha, add, mult; - switch (bd.getDataType()) { - case DataBuffer.TYPE_INT: - int[][] idata = ((DataBufferInt)bd).getBankData(); - for (i = 0; i < idata.length; i++) { - iarray = idata[i]; - for (j = 0; j < iarray.length; j++) { - val = iarray[j]; - alpha = val >>> 24; - // mask[maskpos++] = (byte)((idata[i][j] >> 24) & 0xFF); - if (alpha != 255) { - // System.out.println("Alpha: " + alpha); - // Composite with opaque white... - add = (255 - alpha); - mult = (alpha << 16) / 255; - result[count++] = - (byte)(add - + ((((val >> 16) & 0xFF) * mult) >> 16)); - result[count++] = - (byte)(add - + ((((val >> 8) & 0xFF) * mult) >> 16)); - result[count++] = (byte)(add - + ((((val) & 0xFF) * mult) - >> 16)); - } else { - result[count++] = (byte)((val >> 16) & 0xFF); - result[count++] = (byte)((val >> 8) & 0xFF); - result[count++] = (byte)((val) & 0xFF); - } - } - } - break; - default: - // error - break; - } - - try { - FopImage fopimg = new TempImage(width, height, result, mask); - int xObjectNum = this.pdfDoc.addImage(fopimg); - AffineTransform at = getTransform(); - double[] matrix = new double[6]; - at.getMatrix(matrix); - currentStream.write("q\n"); - Shape imclip = getClip(); - writeClip(imclip); - currentStream.write("" + matrix[0] + " " + matrix[1] + " " - + matrix[2] + " " + matrix[3] + " " - + matrix[4] + " " + matrix[5] + " cm\n"); - currentStream.write("" + width + " 0 0 " + (-height) + " " + x - + " " + (y + height) + " cm\n" + "/Im" - + xObjectNum + " Do\nQ\n"); - } catch (Exception e) { - e.printStackTrace(); - } - return true; - } - - public BufferedImage buildBufferedImage(Dimension size) { - return new BufferedImage(size.width, size.height, - BufferedImage.TYPE_INT_ARGB); - } - - class TempImage implements FopImage { - int m_height; - int m_width; - int m_bitsPerPixel; - ColorSpace m_colorSpace; - int m_bitmapSiye; - byte[] m_bitmaps; - byte[] m_mask; - PDFColor transparent = new PDFColor(255, 255, 255); - - TempImage(int width, int height, byte[] result, - byte[] mask) throws FopImageException { - this.m_height = height; - this.m_width = width; - this.m_bitsPerPixel = 8; - this.m_colorSpace = new ColorSpace(ColorSpace.DEVICE_RGB); - // this.m_isTransparent = false; - // this.m_bitmapsSize = this.m_width * this.m_height * 3; - this.m_bitmaps = result; - this.m_mask = mask; - } - - public String getURL() { - return "" + m_bitmaps; - } - - // image size - public int getWidth() throws FopImageException { - return m_width; - } - - public int getHeight() throws FopImageException { - return m_height; - } - - // DeviceGray, DeviceRGB, or DeviceCMYK - public ColorSpace getColorSpace() throws FopImageException { - return m_colorSpace; - } - - // bits per pixel - public int getBitsPerPixel() throws FopImageException { - return m_bitsPerPixel; - } - - // For transparent images - public boolean isTransparent() throws FopImageException { - return transparent != null; - } - - public PDFColor getTransparentColor() throws FopImageException { - return transparent; - } - - public byte[] getMask() throws FopImageException { - return m_mask; - } - - // get the image bytes, and bytes properties - - // get uncompressed image bytes - public byte[] getBitmaps() throws FopImageException { - return m_bitmaps; - } - - // width * (bitsPerPixel / 8) * height, no ? - public int getBitmapsSize() throws FopImageException { - return m_width * m_height * 3; - } - - // get compressed image bytes - // I don't know if we really need it, nor if it - // should be changed... - public byte[] getRessourceBytes() throws FopImageException { - return null; - } - - public int getRessourceBytesSize() throws FopImageException { - return 0; - } - - // return null if no corresponding PDFFilter - public PDFFilter getPDFFilter() throws FopImageException { - return null; - } - - // release memory - public void close() {} - - } - - - /** - * Draws as much of the specified image as has already been scaled - * to fit inside the specified rectangle. - *

- * The image is drawn inside the specified rectangle of this - * graphics context's coordinate space, and is scaled if - * necessary. Transparent pixels do not affect whatever pixels - * are already there. - *

- * This method returns immediately in all cases, even if the - * entire image has not yet been scaled, dithered, and converted - * for the current output device. - * If the current output representation is not yet complete, then - * drawImage returns false. As more of - * the image becomes available, the process that draws the image notifies - * the image observer by calling its imageUpdate method. - *

- * A scaled version of an image will not necessarily be - * available immediately just because an unscaled version of the - * image has been constructed for this output device. Each size of - * the image may be cached separately and generated from the original - * data in a separate image production sequence. - * @param img the specified image to be drawn. - * @param x the x coordinate. - * @param y the y coordinate. - * @param width the width of the rectangle. - * @param height the height of the rectangle. - * @param observer object to be notified as more of - * the image is converted. - * @see java.awt.Image - * @see java.awt.image.ImageObserver - * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int) - */ - public boolean drawImage(Image img, int x, int y, int width, int height, - ImageObserver observer) { - System.out.println("drawImage"); - return true; - } - - /** - * Disposes of this graphics context and releases - * any system resources that it is using. - * A Graphics object cannot be used after - * disposehas been called. - *

- * When a Java program runs, a large number of Graphics - * objects can be created within a short time frame. - * Although the finalization process of the garbage collector - * also disposes of the same system resources, it is preferable - * to manually free the associated resources by calling this - * method rather than to rely on a finalization process which - * may not run to completion for a long period of time. - *

- * Graphics objects which are provided as arguments to the - * paint and update methods - * of components are automatically released by the system when - * those methods return. For efficiency, programmers should - * call dispose when finished using - * a Graphics object only if it was created - * directly from a component or another Graphics object. - * @see java.awt.Graphics#finalize - * @see java.awt.Component#paint - * @see java.awt.Component#update - * @see java.awt.Component#getGraphics - * @see java.awt.Graphics#create - */ - public void dispose() { - // System.out.println("dispose"); - pdfDoc = null; - fontState = null; - currentStream = null; - currentFontName = null; - currentColour = null; - } - - /** - * Strokes the outline of a Shape using the settings of the - * current Graphics2D context. The rendering attributes - * applied include the Clip, Transform, - * Paint, Composite and - * Stroke attributes. - * @param s the Shape to be rendered - * @see #setStroke - * @see #setPaint - * @see java.awt.Graphics#setColor - * @see #transform - * @see #setTransform - * @see #clip - * @see #setClip - * @see #setComposite - */ - public void draw(Shape s) { - // System.out.println("draw(Shape)"); - currentStream.write("q\n"); - Shape imclip = getClip(); - writeClip(imclip); - Color c = getColor(); - applyColor(c, false); - - applyPaint(getPaint(), false); - applyStroke(getStroke()); - - PathIterator iter = s.getPathIterator(getTransform()); - while (!iter.isDone()) { - double vals[] = new double[6]; - int type = iter.currentSegment(vals); - switch (type) { - case PathIterator.SEG_CUBICTO: - 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]) + " c\n"); - break; - case PathIterator.SEG_LINETO: - currentStream.write(PDFNumber.doubleOut(vals[0]) + " " - + PDFNumber.doubleOut(vals[1]) + " l\n"); - break; - case PathIterator.SEG_MOVETO: - currentStream.write(PDFNumber.doubleOut(vals[0]) + " " - + PDFNumber.doubleOut(vals[1]) + " m\n"); - break; - case PathIterator.SEG_QUADTO: - currentStream.write(PDFNumber.doubleOut(vals[0]) + " " - + PDFNumber.doubleOut(vals[1]) + " " - + PDFNumber.doubleOut(vals[2]) + " " - + PDFNumber.doubleOut(vals[3]) + " y\n"); - break; - case PathIterator.SEG_CLOSE: - currentStream.write("h\n"); - break; - default: - break; - } - iter.next(); - } - doDrawing(false, true, false); - currentStream.write("Q\n"); - } - - protected void writeClip(Shape s) { - if (s == null) { - return; - } - PathIterator iter = s.getPathIterator(getTransform()); - while (!iter.isDone()) { - double vals[] = new double[6]; - int type = iter.currentSegment(vals); - switch (type) { - case PathIterator.SEG_CUBICTO: - 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]) + " c\n"); - break; - case PathIterator.SEG_LINETO: - currentStream.write(PDFNumber.doubleOut(vals[0]) + " " - + PDFNumber.doubleOut(vals[1]) + " l\n"); - break; - case PathIterator.SEG_MOVETO: - currentStream.write(PDFNumber.doubleOut(vals[0]) + " " - + PDFNumber.doubleOut(vals[1]) + " m\n"); - break; - case PathIterator.SEG_QUADTO: - currentStream.write(PDFNumber.doubleOut(vals[0]) + " " - + PDFNumber.doubleOut(vals[1]) + " " - + PDFNumber.doubleOut(vals[2]) + " " - + PDFNumber.doubleOut(vals[3]) + " y\n"); - break; - case PathIterator.SEG_CLOSE: - currentStream.write("h\n"); - break; - default: - break; - } - iter.next(); - } - // clip area - currentStream.write("W\n"); - currentStream.write("n\n"); - } - - protected void applyColor(Color col, boolean fill) { - Color c = col; - if (c.getColorSpace().getType() - == java.awt.color.ColorSpace.TYPE_RGB) { - currentColour = new PDFColor(c.getRed(), c.getGreen(), - c.getBlue()); - currentStream.write(currentColour.getColorSpaceOut(fill)); - } else if (c.getColorSpace().getType() - == java.awt.color.ColorSpace.TYPE_CMYK) { - float[] cComps = c.getColorComponents(new float[3]); - double[] cmyk = new double[3]; - for (int i = 0; i < 3; i++) { - // convert the float elements to doubles for pdf - cmyk[i] = cComps[i]; - } - currentColour = new PDFColor(cmyk[0], cmyk[1], cmyk[2], cmyk[3]); - currentStream.write(currentColour.getColorSpaceOut(fill)); - } else if (c.getColorSpace().getType() - == java.awt.color.ColorSpace.TYPE_2CLR) { - // used for black/magenta - float[] cComps = c.getColorComponents(new float[1]); - double[] blackMagenta = new double[1]; - for (int i = 0; i < 1; i++) { - blackMagenta[i] = cComps[i]; - } - // currentColour = new PDFColor(blackMagenta[0], blackMagenta[1]); - currentStream.write(currentColour.getColorSpaceOut(fill)); - } else { - System.err.println("Color Space not supported by PDFGraphics2D"); - } - } - - protected void applyPaint(Paint paint, boolean fill) { - if (paint instanceof GradientPaint) { - GradientPaint gp = (GradientPaint)paint; - Color c1 = gp.getColor1(); - Color c2 = gp.getColor2(); - Point2D p1 = gp.getPoint1(); - Point2D p2 = gp.getPoint2(); - boolean cyclic = gp.isCyclic(); - - Vector theCoords = new Vector(); - theCoords.addElement(new Double(p1.getX())); - theCoords.addElement(new Double(p1.getY())); - theCoords.addElement(new Double(p2.getX())); - theCoords.addElement(new Double(p2.getY())); - - Vector theExtend = new Vector(); - theExtend.addElement(new Boolean(true)); - theExtend.addElement(new Boolean(true)); - - Vector theDomain = new Vector(); - theDomain.addElement(new Double(0)); - theDomain.addElement(new Double(1)); - - Vector theEncode = new Vector(); - theEncode.addElement(new Double(0)); - theEncode.addElement(new Double(1)); - theEncode.addElement(new Double(0)); - theEncode.addElement(new Double(1)); - - Vector theBounds = new Vector(); - theBounds.addElement(new Double(0)); - theBounds.addElement(new Double(1)); - - Vector theFunctions = new Vector(); - - Vector someColors = new Vector(); - - PDFColor color1 = new PDFColor(c1.getRed(), c1.getGreen(), - c1.getBlue()); - someColors.addElement(color1); - PDFColor color2 = new PDFColor(c2.getRed(), c2.getGreen(), - c2.getBlue()); - someColors.addElement(color2); - - PDFFunction myfunc = this.pdfDoc.makeFunction(2, theDomain, null, - color1.getVector(), color2.getVector(), 1.0); - - ColorSpace aColorSpace = new ColorSpace(ColorSpace.DEVICE_RGB); - PDFPattern myPat = this.pdfDoc.createGradient(false, aColorSpace, - someColors, null, theCoords); - currentStream.write(myPat.getColorSpaceOut(fill)); - - } else if (paint instanceof TexturePaint) {} - } - - protected void applyStroke(Stroke stroke) { - if (stroke instanceof BasicStroke) { - BasicStroke bs = (BasicStroke)stroke; - - float[] da = bs.getDashArray(); - if (da != null) { - currentStream.write("["); - for (int count = 0; count < da.length; count++) { - currentStream.write("" + ((int)da[count])); - if (count < da.length - 1) { - currentStream.write(" "); - } - } - currentStream.write("] "); - float offset = bs.getDashPhase(); - currentStream.write(((int)offset) + " d\n"); - } - int ec = bs.getEndCap(); - switch (ec) { - case BasicStroke.CAP_BUTT: - currentStream.write(0 + " J\n"); - break; - case BasicStroke.CAP_ROUND: - currentStream.write(1 + " J\n"); - break; - case BasicStroke.CAP_SQUARE: - currentStream.write(2 + " J\n"); - break; - } - - int lj = bs.getLineJoin(); - switch (lj) { - case BasicStroke.JOIN_MITER: - currentStream.write(0 + " j\n"); - break; - case BasicStroke.JOIN_ROUND: - currentStream.write(1 + " j\n"); - break; - case BasicStroke.JOIN_BEVEL: - currentStream.write(2 + " j\n"); - break; - } - float lw = bs.getLineWidth(); - currentStream.write(PDFNumber.doubleOut(lw) + " w\n"); - - float ml = bs.getMiterLimit(); - currentStream.write(PDFNumber.doubleOut(ml) + " M\n"); - } - } - - /** - * Renders a {@link RenderedImage}, - * applying a transform from image - * space into user space before drawing. - * The transformation from user space into device space is done with - * the current Transform in the Graphics2D. - * The specified transformation is applied to the image before the - * transform attribute in the Graphics2D context is applied. - * The rendering attributes applied include the Clip, - * Transform, and Composite attributes. Note - * that no rendering is done if the specified transform is - * noninvertible. - * @param img the image to be rendered - * @param xform the transformation from image space into user space - * @see #transform - * @see #setTransform - * @see #setComposite - * @see #clip - * @see #setClip - */ - public void drawRenderedImage(RenderedImage img, AffineTransform xform) { - System.out.println("drawRenderedImage"); - } - - - /** - * Renders a - * {@link RenderableImage}, - * applying a transform from image space into user space before drawing. - * The transformation from user space into device space is done with - * the current Transform in the Graphics2D. - * The specified transformation is applied to the image before the - * transform attribute in the Graphics2D context is applied. - * The rendering attributes applied include the Clip, - * Transform, and Composite attributes. Note - * that no rendering is done if the specified transform is - * noninvertible. - *

- * Rendering hints set on the Graphics2D object might - * be used in rendering the RenderableImage. - * If explicit control is required over specific hints recognized by a - * specific RenderableImage, or if knowledge of which hints - * are used is required, then a RenderedImage should be - * obtained directly from the RenderableImage - * and rendered using - * {@link #drawRenderedImage(RenderedImage, AffineTransform) drawRenderedImage}. - * @param img the image to be rendered - * @param xform the transformation from image space into user space - * @see #transform - * @see #setTransform - * @see #setComposite - * @see #clip - * @see #setClip - * @see #drawRenderedImage - */ - public void drawRenderableImage(RenderableImage img, - AffineTransform xform) { - System.out.println("drawRenderableImage"); - } - - /** - * Renders the text specified by the specified String, - * using the current Font and Paint attributes - * in the Graphics2D context. - * The baseline of the first character is at position - * (xy) in the User Space. - * The rendering attributes applied include the Clip, - * Transform, Paint, Font and - * Composite attributes. For characters in script systems - * such as Hebrew and Arabic, the glyphs can be rendered from right to - * left, in which case the coordinate supplied is the location of the - * leftmost character on the baseline. - * @param s the String to be rendered - * @param x, y the coordinates where the String - * should be rendered - * @see #setPaint - * @see java.awt.Graphics#setColor - * @see java.awt.Graphics#setFont - * @see #setTransform - * @see #setComposite - * @see #setClip - */ - public void drawString(String s, float x, float y) { - // System.out.println("drawString(String)"); - - Shape imclip = getClip(); - writeClip(imclip); - Color c = getColor(); - applyColor(c, true); - c = getBackground(); - applyColor(c, false); - - currentStream.write("BT\n"); - - 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]) + " Tm (" + s - + ") Tj\n"); - - currentStream.write("ET\n"); - } - - /** - * Renders the text of the specified iterator, using the - * Graphics2D context's current Paint. The - * iterator must specify a font - * for each character. The baseline of the - * first character is at position (xy) in the - * User Space. - * The rendering attributes applied include the Clip, - * Transform, Paint, and - * Composite attributes. - * For characters in script systems such as Hebrew and Arabic, - * the glyphs can be rendered from right to left, in which case the - * coordinate supplied is the location of the leftmost character - * on the baseline. - * @param iterator the iterator whose text is to be rendered - * @param x, y the coordinates where the iterator's text is to be - * rendered - * @see #setPaint - * @see java.awt.Graphics#setColor - * @see #setTransform - * @see #setComposite - * @see #setClip - */ - public void drawString(AttributedCharacterIterator iterator, float x, - float y) { - System.err.println("drawString(AttributedCharacterIterator)"); - - currentStream.write("BT\n"); - Shape imclip = getClip(); - writeClip(imclip); - Color c = getColor(); - applyColor(c, true); - c = getBackground(); - applyColor(c, false); - - AffineTransform trans = getTransform(); - trans.translate(x, y); - double[] vals = new double[6]; - trans.getMatrix(vals); - - 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]) + " Tm (" + ch - + ") Tj\n"); - } - - currentStream.write("ET\n"); - } - - /** - * Fills the interior of a Shape using the settings of the - * Graphics2D context. The rendering attributes applied - * include the Clip, Transform, - * Paint, and Composite. - * @param s the Shape to be filled - * @see #setPaint - * @see java.awt.Graphics#setColor - * @see #transform - * @see #setTransform - * @see #setComposite - * @see #clip - * @see #setClip - */ - public void fill(Shape s) { - // System.err.println("fill"); - currentStream.write("q\n"); - Shape imclip = getClip(); - writeClip(imclip); - Color c = getColor(); - applyColor(c, true); - c = getBackground(); - applyColor(c, false); - - applyPaint(getPaint(), true); - - PathIterator iter = s.getPathIterator(getTransform()); - while (!iter.isDone()) { - double vals[] = new double[6]; - int type = iter.currentSegment(vals); - switch (type) { - case PathIterator.SEG_CUBICTO: - 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]) + " c\n"); - break; - case PathIterator.SEG_LINETO: - currentStream.write(PDFNumber.doubleOut(vals[0]) + " " - + PDFNumber.doubleOut(vals[1]) + " l\n"); - break; - case PathIterator.SEG_MOVETO: - currentStream.write(PDFNumber.doubleOut(vals[0]) + " " - + PDFNumber.doubleOut(vals[1]) + " m\n"); - break; - case PathIterator.SEG_QUADTO: - currentStream.write(PDFNumber.doubleOut(vals[0]) + " " - + PDFNumber.doubleOut(vals[1]) + " " - + PDFNumber.doubleOut(vals[2]) + " " - + PDFNumber.doubleOut(vals[3]) + " y\n"); - break; - case PathIterator.SEG_CLOSE: - currentStream.write("h\n"); - break; - default: - break; - } - iter.next(); - } - doDrawing(true, false, - iter.getWindingRule() == PathIterator.WIND_EVEN_ODD); - currentStream.write("Q\n"); - } - - protected void doDrawing(boolean fill, boolean stroke, boolean nonzero) { - if (fill) { - if (stroke) { - if (nonzero) - currentStream.write("B*\n"); - else - currentStream.write("B\n"); - } else { - if (nonzero) - currentStream.write("f*\n"); - else - currentStream.write("f\n"); - } - } else { - // if(stroke) - currentStream.write("S\n"); - } - } - - /** - * Returns the device configuration associated with this - * Graphics2D. - */ - public GraphicsConfiguration getDeviceConfiguration() { - return new PDFGraphicsConfiguration(); - } - - /** - * Our implementation of the class that returns information about - * roughly what we can handle and want to see (alpha for example). - */ - static class PDFGraphicsConfiguration extends GraphicsConfiguration { - // We use this to get a good colormodel.. - static BufferedImage BIWithAlpha = new BufferedImage(1, 1, - BufferedImage.TYPE_INT_ARGB); - // We use this to get a good colormodel.. - static BufferedImage BIWithOutAlpha = new BufferedImage(1, 1, - BufferedImage.TYPE_INT_RGB); - - /** - * Construct a buffered image with an alpha channel, unless - * transparencty is OPAQUE (no alpha at all). - */ - public BufferedImage createCompatibleImage(int width, int height, - int transparency) { - if (transparency == Transparency.OPAQUE) - return new BufferedImage(width, height, - BufferedImage.TYPE_INT_RGB); - else - return new BufferedImage(width, height, - BufferedImage.TYPE_INT_ARGB); - } - - /** - * Construct a buffered image with an alpha channel. - */ - public BufferedImage createCompatibleImage(int width, int height) { - return new BufferedImage(width, height, - BufferedImage.TYPE_INT_ARGB); - } - - /** - * FIXX ME: This should return the page bounds in Pts, - * I couldn't figure out how to get this for the current - * page from the PDFDocument (this still works for now, - * but it should be fixed...). - */ - public Rectangle getBounds() { - return null; - } - - /** - * Return a good default color model for this 'device'. - */ - public ColorModel getColorModel() { - return BIWithAlpha.getColorModel(); - } - - /** - * Return a good color model given transparency - */ - public ColorModel getColorModel(int transparency) { - if (transparency == Transparency.OPAQUE) - return BIWithOutAlpha.getColorModel(); - else - return BIWithAlpha.getColorModel(); - } - - /** - * The default transform (1:1). - */ - public AffineTransform getDefaultTransform() { - return new AffineTransform(); - } - - /** - * The normalizing transform (1:1) (since we currently - * render images at 72dpi, which we might want to change - * in the future). - */ - public AffineTransform getNormalizingTransform() { - return new AffineTransform(); - } - - /** - * Return our dummy instance of GraphicsDevice - */ - public GraphicsDevice getDevice() { - return new PDFGraphicsDevice(this); - } - - } - - /** - * This implements the GraphicsDevice interface as appropriate for - * a PDFGraphics2D. This is quite simple since we only have one - * GraphicsConfiguration for now (this might change in the future - * I suppose). - */ - static class PDFGraphicsDevice extends GraphicsDevice { - - /** - * The Graphics Config that created us... - */ - GraphicsConfiguration gc; - - /** - * @param The gc we should reference - */ - PDFGraphicsDevice(PDFGraphicsConfiguration gc) { - this.gc = gc; - } - - /** - * Ignore template and return the only config we have - */ - public GraphicsConfiguration getBestConfiguration(GraphicsConfigTemplate gct) { - return gc; - } - - /** - * Return an array of our one GraphicsConfig - */ - public GraphicsConfiguration[] getConfigurations() { - return new GraphicsConfiguration[] { - gc - }; - } - - /** - * Return out sole GraphicsConfig. - */ - public GraphicsConfiguration getDefaultConfiguration() { - return gc; - } - - /** - * Generate an IdString.. - */ - public String getIDstring() { - return toString(); - } - - /** - * Let the caller know that we are "a printer" - */ - public int getType() { - return GraphicsDevice.TYPE_PRINTER; - } - - } - - /** - * Used to create proper font metrics - */ - private Graphics2D fmg; - - { - BufferedImage bi = new BufferedImage(1, 1, - BufferedImage.TYPE_INT_ARGB); - - fmg = bi.createGraphics(); - } - - /** - * Gets the font metrics for the specified font. - * @return the font metrics for the specified font. - * @param f the specified font - * @see java.awt.Graphics#getFont - * @see java.awt.FontMetrics - * @see java.awt.Graphics#getFontMetrics() - */ - public FontMetrics getFontMetrics(Font f) { - return fmg.getFontMetrics(f); - } - - /** - * Sets the paint mode of this graphics context to alternate between - * this graphics context's current color and the new specified color. - * This specifies that logical pixel operations are performed in the - * XOR mode, which alternates pixels between the current color and - * a specified XOR color. - *

- * When drawing operations are performed, pixels which are the - * current color are changed to the specified color, and vice versa. - *

- * Pixels that are of colors other than those two colors are changed - * in an unpredictable but reversible manner; if the same figure is - * drawn twice, then all pixels are restored to their original values. - * @param c1 the XOR alternation color - */ - public void setXORMode(Color c1) { - System.out.println("setXORMode"); - } - - - /** - * Copies an area of the component by a distance specified by - * dx and dy. From the point specified - * by x and y, this method - * copies downwards and to the right. To copy an area of the - * component to the left or upwards, specify a negative value for - * dx or dy. - * If a portion of the source rectangle lies outside the bounds - * of the component, or is obscured by another window or component, - * copyArea will be unable to copy the associated - * pixels. The area that is omitted can be refreshed by calling - * the component's paint method. - * @param x the x coordinate of the source rectangle. - * @param y the y coordinate of the source rectangle. - * @param width the width of the source rectangle. - * @param height the height of the source rectangle. - * @param dx the horizontal distance to copy the pixels. - * @param dy the vertical distance to copy the pixels. - */ - public void copyArea(int x, int y, int width, int height, int dx, - int dy) { - System.out.println("copyArea"); - } - -} diff --git a/src/org/apache/fop/svg/PDFTextPainter.java b/src/org/apache/fop/svg/PDFTextPainter.java deleted file mode 100644 index db9ed1b92..000000000 --- a/src/org/apache/fop/svg/PDFTextPainter.java +++ /dev/null @@ -1,359 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.svg; - -import java.awt.Graphics2D; -import java.awt.*; -import java.text.AttributedCharacterIterator; -import java.awt.font.FontRenderContext; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.awt.Font; - -import java.text.AttributedCharacterIterator; -import java.text.AttributedString; -import java.text.CharacterIterator; -import java.awt.font.TextLayout; -import java.awt.font.TextAttribute; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.*; -import java.util.Set; - -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.batik.gvt.font.*; - -import org.apache.fop.layout.*; - -/** - * Renders the attributed character iterator of a TextNode. - * - * @author Keiron Liddle - * @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(); - - AttributedCharacterIterator aci = - node.getAttributedCharacterIterator(); - // reset position to start of char iterator - if (aci.getBeginIndex() == aci.getEndIndex()) { - return; - } - char ch = aci.first(); - if (ch == AttributedCharacterIterator.DONE) { - return; - } - TextNode.Anchor anchor = - (TextNode.Anchor)aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.ANCHOR_TYPE); - - Vector gvtFonts = - (Vector)aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.GVT_FONT_FAMILIES); - Paint forg = (Paint)aci.getAttribute(TextAttribute.FOREGROUND); - Float size = (Float)aci.getAttribute(TextAttribute.SIZE); - Stroke stroke = - (Stroke)aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.STROKE); - Float xpos = - (Float)aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.X); - Float ypos = - (Float)aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.Y); - - Float posture = (Float)aci.getAttribute(TextAttribute.POSTURE); - Float taWeight = (Float)aci.getAttribute(TextAttribute.WEIGHT); - - if (forg instanceof Color) { - g2d.setColor((Color)forg); - } - g2d.setPaint(forg); - g2d.setStroke(stroke); - - String style = ((posture != null) && (posture.floatValue() > 0.0)) - ? "italic" : "normal"; - String weight = ((taWeight != null) && (taWeight.floatValue() > 1.0)) - ? "bold" : "normal"; - - FontInfo fi = fontState.getFontInfo(); - boolean found = false; - if (gvtFonts != null) { - for (Enumeration e = gvtFonts.elements(); e.hasMoreElements(); ) { - GVTFontFamily fam = (GVTFontFamily)e.nextElement(); - String name = fam.getFamilyName(); - if (fi.hasFont(name, weight, style)) { - try { - int fsize = (int)size.floatValue(); - fontState = new FontState(fontState.getFontInfo(), - name, style, weight, - fsize * 1000, 0); - } catch (org.apache.fop.apps.FOPException fope) { - fope.printStackTrace(); - } - found = true; - break; - } - } - } - if (!found) { - try { - int fsize = (int)size.floatValue(); - fontState = new FontState(fontState.getFontInfo(), "any", - style, weight, fsize * 1000, 0); - } catch (org.apache.fop.apps.FOPException fope) { - fope.printStackTrace(); - } - } - int fStyle = Font.PLAIN; - if (fontState.getFontWeight().equals("bold")) { - if (fontState.getFontStyle().equals("italic")) { - fStyle = Font.BOLD | Font.ITALIC; - } else { - fStyle = Font.BOLD; - } - } else { - if (fontState.getFontStyle().equals("italic")) { - fStyle = Font.ITALIC; - } else { - fStyle = Font.PLAIN; - } - } - Font font = new Font(fontState.getFontFamily(), fStyle, - (int)(fontState.getFontSize() / 1000)); - - g2d.setFont(font); - - - float advance = getStringWidth(txt); - float tx = 0; - if (anchor != null) { - switch (anchor.getType()) { - case TextNode.Anchor.ANCHOR_MIDDLE: - tx = -advance / 2; - break; - case TextNode.Anchor.ANCHOR_END: - tx = -advance; - } - } - g2d.drawString(txt, (float)(loc.getX() + tx), (float)(loc.getY())); - } - - public float getStringWidth(String str) { - float wordWidth = 0; - float whitespaceWidth = fontState.width(fontState.mapChar(' ')); - - for (int i = 0; i < str.length(); i++) { - float charWidth; - char c = str.charAt(i); - if (!((c == ' ') || (c == '\n') || (c == '\r') || (c == '\t'))) { - charWidth = fontState.width(fontState.mapChar(c)); - if (charWidth <= 0) - charWidth = whitespaceWidth; - } else { - charWidth = whitespaceWidth; - } - wordWidth += charWidth; - } - return wordWidth / 1000f; - } - - /** - * 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 - * must come - * 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 - * must come - * 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 new Rectangle(1, 1); - } - - /* - * 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; - } - -} - diff --git a/src/org/apache/fop/svg/PDFTranscoder.java b/src/org/apache/fop/svg/PDFTranscoder.java deleted file mode 100644 index 1a37558ad..000000000 --- a/src/org/apache/fop/svg/PDFTranscoder.java +++ /dev/null @@ -1,490 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.svg; - -import java.awt.AlphaComposite; -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.Graphics2D; -import java.awt.Paint; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.Shape; - -import java.awt.geom.AffineTransform; -import java.awt.geom.Dimension2D; -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; - -import java.awt.*; -import java.awt.event.*; -import java.awt.geom.*; -import java.awt.font.*; - -import java.net.MalformedURLException; -import java.net.URL; - -import java.util.HashSet; -import java.util.Set; - -import org.apache.batik.transcoder.*; - -import org.apache.batik.bridge.BridgeContext; -import org.apache.batik.bridge.BridgeException; -import org.apache.batik.bridge.GVTBuilder; -import org.apache.batik.bridge.UserAgent; -import org.apache.batik.bridge.ViewBox; - -import org.apache.batik.dom.svg.DefaultSVGContext; -import org.apache.batik.dom.svg.SAXSVGDocumentFactory; -import org.apache.batik.dom.svg.SVGDOMImplementation; -import org.apache.batik.dom.svg.SVGOMDocument; -import org.apache.batik.dom.util.DocumentFactory; - -import org.apache.batik.ext.awt.image.GraphicsUtil; - -import org.apache.batik.gvt.GraphicsNode; -import org.apache.batik.gvt.GraphicsNodeRenderContext; -import org.apache.batik.gvt.event.EventDispatcher; -import org.apache.batik.gvt.renderer.ImageRenderer; -import org.apache.batik.gvt.renderer.ImageRendererFactory; - -import org.apache.batik.transcoder.TranscoderException; -import org.apache.batik.transcoder.TranscoderOutput; -import org.apache.batik.transcoder.TranscodingHints; -import org.apache.batik.transcoder.XMLAbstractTranscoder; -import org.apache.batik.transcoder.image.resources.Messages; - -import org.apache.batik.transcoder.keys.BooleanKey; -import org.apache.batik.transcoder.keys.FloatKey; -import org.apache.batik.transcoder.keys.LengthKey; -import org.apache.batik.transcoder.keys.PaintKey; -import org.apache.batik.transcoder.keys.PaintKey; -import org.apache.batik.transcoder.keys.Rectangle2DKey; -import org.apache.batik.transcoder.keys.StringKey; -import org.apache.batik.transcoder.*; -import org.apache.batik.transcoder.image.*; - -import org.apache.batik.util.SVGConstants; -import org.apache.batik.util.XMLResourceDescriptor; - -import org.apache.batik.bridge.*; -import org.apache.batik.swing.svg.*; -import org.apache.batik.swing.gvt.*; -import org.apache.batik.gvt.*; -import org.apache.batik.gvt.renderer.*; -import org.apache.batik.gvt.filter.*; -import org.apache.batik.gvt.event.*; - -import org.w3c.dom.*; -import org.w3c.dom.svg.*; -import org.w3c.dom.css.*; -import org.w3c.dom.svg.SVGLength; - -import org.apache.fop.svg.*; -import org.apache.fop.pdf.*; - -import org.w3c.dom.DOMException; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.Document; -import org.w3c.dom.svg.SVGAElement; -import org.w3c.dom.svg.SVGDocument; -import org.w3c.dom.svg.SVGSVGElement; - -// FIXME : Those import clauses will change with new design -import org.apache.batik.gvt.renderer.StaticRendererFactory; - -/** - * This class enables to transcode an input to a pdf document. - * - *

Two transcoding hints (KEY_WIDTH and - * KEY_HEIGHT) can be used to respectively specify the image - * width and the image height. If only one of these keys is specified, - * the transcoder preserves the aspect ratio of the original image. - * - *

The KEY_BACKGROUND_COLOR defines the background color - * to use for opaque image formats, or the background color that may - * be used for image formats that support alpha channel. - * - *

The KEY_AOI represents the area of interest to paint - * in device space. - * - *

Three additional transcoding hints that act on the SVG - * processor can be specified: - * - *

KEY_LANGUAGE to set the default language to use (may be - * used by a <switch> SVG element for example), - * KEY_USER_STYLESHEET_URI to fix the URI of a user - * stylesheet, and KEY_PIXEL_TO_MM to specify the pixel to - * millimeter conversion factor. - * - * @author Keiron Liddle - * @version $Id$ - */ -public class PDFTranscoder extends XMLAbstractTranscoder { - - public static final TranscodingHints.Key KEY_STROKE_TEXT = - new StringKey(); - - /** - * The user agent dedicated to an ImageTranscoder. - */ - protected UserAgent userAgent = new ImageTranscoderUserAgent(); - - /** - * Constructs a new ImageTranscoder. - */ - public PDFTranscoder() { - hints.put(KEY_DOCUMENT_ELEMENT_NAMESPACE_URI, - SVGConstants.SVG_NAMESPACE_URI); - hints.put(KEY_DOCUMENT_ELEMENT, SVGConstants.SVG_SVG_TAG); - hints.put(KEY_DOM_IMPLEMENTATION, - SVGDOMImplementation.getDOMImplementation()); - } - - /** - * Transcodes the specified Document as an image in the specified output. - * - * @param document the document to transcode - * @param uri the uri of the document or null if any - * @param output the ouput where to transcode - * @exception TranscoderException if an error occured while transcoding - */ - protected void transcode(Document document, String uri, - TranscoderOutput output) throws TranscoderException { - - if (!(document instanceof SVGOMDocument)) { - throw new TranscoderException(Messages.formatMessage("notsvg", - null)); - } - SVGDocument svgDoc = (SVGDocument)document; - SVGSVGElement root = svgDoc.getRootElement(); - // initialize the SVG document with the appropriate context - String parserClassname = (String)hints.get(KEY_XML_PARSER_CLASSNAME); - DefaultSVGContext svgCtx = new DefaultSVGContext(); - svgCtx.setPixelToMM(userAgent.getPixelToMM()); - ((SVGOMDocument)document).setSVGContext(svgCtx); - - boolean stroke = true; - if (hints.containsKey(KEY_STROKE_TEXT)) { - stroke = ((Boolean)hints.get(KEY_STROKE_TEXT)).booleanValue(); - } - - // build the GVT tree - GVTBuilder builder = new GVTBuilder(); - ImageRendererFactory rendFactory = new StaticRendererFactory(); - GraphicsNodeRenderContext rc = getRenderContext(stroke); - BridgeContext ctx = new BridgeContext(userAgent, rc); - PDFAElementBridge pdfAElementBridge = new PDFAElementBridge(); - ctx.putBridge(pdfAElementBridge); - GraphicsNode gvtRoot; - try { - gvtRoot = builder.build(ctx, svgDoc); - } catch (BridgeException ex) { - throw new TranscoderException(ex); - } - // get the 'width' and 'height' attributes of the SVG document - float docWidth = (float)ctx.getDocumentSize().getWidth(); - float docHeight = (float)ctx.getDocumentSize().getHeight(); - ctx = null; - builder = null; - - // compute the image's width and height according the hints - float imgWidth = -1; - if (hints.containsKey(ImageTranscoder.KEY_WIDTH)) { - imgWidth = - ((Float)hints.get(ImageTranscoder.KEY_WIDTH)).floatValue(); - } - float imgHeight = -1; - if (hints.containsKey(ImageTranscoder.KEY_HEIGHT)) { - imgHeight = - ((Float)hints.get(ImageTranscoder.KEY_HEIGHT)).floatValue(); - } - float width, height; - if (imgWidth > 0 && imgHeight > 0) { - width = imgWidth; - height = imgHeight; - } else if (imgHeight > 0) { - width = (docWidth * imgHeight) / docHeight; - height = imgHeight; - } else if (imgWidth > 0) { - width = imgWidth; - height = (docHeight * imgWidth) / docWidth; - } else { - width = docWidth; - height = docHeight; - } - // compute the preserveAspectRatio matrix - AffineTransform Px; - String ref = null; - try { - ref = new URL(uri).getRef(); - } catch (MalformedURLException ex) { - // nothing to do, catched previously - } - - try { - Px = ViewBox.getViewTransform(ref, root, width, height); - } catch (BridgeException ex) { - throw new TranscoderException(ex); - } - - if (Px.isIdentity() && (width != docWidth || height != docHeight)) { - // The document has no viewBox, we need to resize it by hand. - // we want to keep the document size ratio - float d = Math.max(docWidth, docHeight); - float dd = Math.max(width, height); - float scale = dd / d; - Px = AffineTransform.getScaleInstance(scale, scale); - } - // take the AOI into account if any - if (hints.containsKey(ImageTranscoder.KEY_AOI)) { - Rectangle2D aoi = (Rectangle2D)hints.get(ImageTranscoder.KEY_AOI); - // transform the AOI into the image's coordinate system - aoi = Px.createTransformedShape(aoi).getBounds2D(); - AffineTransform Mx = new AffineTransform(); - double sx = width / aoi.getWidth(); - double sy = height / aoi.getHeight(); - Mx.scale(sx, sy); - double tx = -aoi.getX(); - double ty = -aoi.getY(); - Mx.translate(tx, ty); - // take the AOI transformation matrix into account - // we apply first the preserveAspectRatio matrix - Px.preConcatenate(Mx); - } - // prepare the image to be painted - int w = (int)width; - int h = (int)height; - - PDFDocumentGraphics2D graphics = new PDFDocumentGraphics2D(stroke, - output.getOutputStream(), w, h); - graphics.setSVGDimension(docWidth, docHeight); - - if (!stroke) { - TextPainter textPainter = null; - textPainter = new PDFTextPainter(graphics.getFontState()); - rc.setTextPainter(textPainter); - } - - pdfAElementBridge.setPDFGraphics2D(graphics); - if (hints.containsKey(ImageTranscoder.KEY_BACKGROUND_COLOR)) { - graphics.setBackgroundColor((Color)hints.get(ImageTranscoder.KEY_BACKGROUND_COLOR)); - } - graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext()); - graphics.setRenderingHints(rc.getRenderingHints()); - - gvtRoot.paint(graphics, rc); - - try { - graphics.finish(); - } catch (Exception ex) { - ex.printStackTrace(); - throw new TranscoderException(ex); - } - } - - public GraphicsNodeRenderContext getRenderContext(boolean stroke) { - GraphicsNodeRenderContext nodeRenderContext = null; - if (nodeRenderContext == null) { - RenderingHints hints = new RenderingHints(null); - hints.put(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - - hints.put(RenderingHints.KEY_INTERPOLATION, - RenderingHints.VALUE_INTERPOLATION_BILINEAR); - - FontRenderContext fontRenderContext = - new FontRenderContext(new AffineTransform(), true, true); - - TextPainter textPainter = null; - textPainter = new StrokingTextPainter(); - - GraphicsNodeRableFactory gnrFactory = - new ConcreteGraphicsNodeRableFactory(); - - nodeRenderContext = - new GraphicsNodeRenderContext(new AffineTransform(), null, - hints, fontRenderContext, - textPainter, gnrFactory); - } - - return nodeRenderContext; - } - - /** - * Creates a DocumentFactory that is used to create an SVG DOM - * tree. The specified DOM Implementation is ignored and the Batik - * SVG DOM Implementation is automatically used. - * - * @param domImpl the DOM Implementation (not used) - * @param parserClassname the XML parser classname - */ - protected DocumentFactory createDocumentFactory(DOMImplementation domImpl, - String parserClassname) { - return new SAXSVGDocumentFactory(parserClassname); - } - - // -------------------------------------------------------------------- - // UserAgent implementation - // -------------------------------------------------------------------- - - /** - * A user agent implementation for ImageTranscoder. - */ - protected class ImageTranscoderUserAgent implements UserAgent { - - /** - * Returns the default size of this user agent (400x400). - */ - public Dimension2D getViewportSize() { - return new Dimension(400, 400); - } - - /** - * Displays the specified error message using the ErrorHandler. - */ - public void displayError(String message) { - try { - getErrorHandler().error(new TranscoderException(message)); - } catch (TranscoderException ex) { - throw new RuntimeException(); - } - } - - /** - * Displays the specified error using the ErrorHandler. - */ - public void displayError(Exception e) { - try { - getErrorHandler().error(new TranscoderException(e)); - } catch (TranscoderException ex) { - throw new RuntimeException(); - } - } - - /** - * Displays the specified message using the ErrorHandler. - */ - public void displayMessage(String message) { - try { - getErrorHandler().warning(new TranscoderException(message)); - } catch (TranscoderException ex) { - throw new RuntimeException(); - } - } - - /** - * Returns the pixel to millimeter conversion factor specified in the - * TranscodingHints or 0.3528 if any. - */ - public float getPixelToMM() { - if (getTranscodingHints().containsKey(ImageTranscoder.KEY_PIXEL_TO_MM)) { - return ((Float)getTranscodingHints().get(ImageTranscoder.KEY_PIXEL_TO_MM)).floatValue(); - } else { - // return 0.3528f; // 72 dpi - return 0.26458333333333333333333333333333f; // 96dpi - } - } - - /** - * Returns the user language specified in the - * TranscodingHints or "en" (english) if any. - */ - public String getLanguages() { - if (getTranscodingHints().containsKey(ImageTranscoder.KEY_LANGUAGE)) { - return (String)getTranscodingHints().get(ImageTranscoder.KEY_LANGUAGE); - } else { - return "en"; - } - } - - /** - * Returns the user stylesheet specified in the - * TranscodingHints or null if any. - */ - public String getUserStyleSheetURI() { - return (String)getTranscodingHints().get(ImageTranscoder.KEY_USER_STYLESHEET_URI); - } - - /** - * Returns the XML parser to use from the TranscodingHints. - */ - public String getXMLParserClassName() { - if (getTranscodingHints().containsKey(KEY_XML_PARSER_CLASSNAME)) { - return (String)getTranscodingHints().get(KEY_XML_PARSER_CLASSNAME); - } else { - return XMLResourceDescriptor.getXMLParserClassName(); - } - } - - /** - * Unsupported operation. - */ - public EventDispatcher getEventDispatcher() { - return null; - } - - /** - * Unsupported operation. - */ - public void openLink(SVGAElement elt) {} - - /** - * Unsupported operation. - */ - public void setSVGCursor(Cursor cursor) {} - - /** - * Unsupported operation. - */ - public void runThread(Thread t) {} - - /** - * Unsupported operation. - */ - public AffineTransform getTransform() { - return null; - } - - /** - * Unsupported operation. - */ - public Point getClientAreaLocationOnScreen() { - return new Point(); - } - - /** - * Tells whether the given feature is supported by this - * user agent. - */ - public boolean hasFeature(String s) { - return FEATURES.contains(s); - } - - /** - * Tells whether the given extension is supported by this - * user agent. - */ - public boolean supportExtension(String s) { - return false; - } - - public void registerExtension(BridgeExtension be) {} - - public void handleElement(Element elt, Object data) {} - - } - - protected final static Set FEATURES = new HashSet(); - static { - FEATURES.add(SVGConstants.SVG_ORG_W3C_SVG_FEATURE); - FEATURES.add(SVGConstants.SVG_ORG_W3C_SVG_LANG_FEATURE); - FEATURES.add(SVGConstants.SVG_ORG_W3C_SVG_STATIC_FEATURE); - } -} diff --git a/src/org/apache/fop/svg/SVGArea.java b/src/org/apache/fop/svg/SVGArea.java deleted file mode 100644 index d4845be84..000000000 --- a/src/org/apache/fop/svg/SVGArea.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.svg; - -// FOP -import org.apache.fop.render.Renderer; -import org.apache.fop.layout.FontState; -import org.apache.fop.layout.Area; - -import java.util.*; - -import org.w3c.dom.svg.*; -import org.w3c.dom.*; - -/** - * class representing an SVG area in which the SVG graphics sit - */ -public class SVGArea extends Area { - Document doc; - - /** - * construct an SVG area - * - * @param fontState the font state - * @param width the width of the area - * @param height the height of the area - */ - public SVGArea(FontState fontState, float width, float height) { - super(fontState, (int)width * 1000, (int)height * 1000); - currentHeight = (int)height * 1000; - contentRectangleWidth = (int)width * 1000; - } - - public void setSVGDocument(Document doc) { - this.doc = doc; - } - - public Document getSVGDocument() { - return doc; - } - - public int getWidth() { - // return getSVGDocument().getRootElement().getWidth().getBaseVal().getValue(); - return contentRectangleWidth; - } - - /** - * render the SVG. - * - * @param renderer the Renderer to use - */ - public void render(Renderer renderer) { - renderer.renderSVGArea(this); - } - -} diff --git a/src/org/apache/fop/svg/SVGElement.java b/src/org/apache/fop/svg/SVGElement.java deleted file mode 100644 index 91ef47bb0..000000000 --- a/src/org/apache/fop/svg/SVGElement.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.svg; - -// FOP -import org.apache.fop.fo.*; -import org.apache.fop.fo.properties.*; -import org.apache.fop.layout.Area; -import org.apache.fop.layout.FontState; -import org.apache.fop.apps.FOPException; -import org.apache.fop.layout.inline.*; -import org.apache.fop.configuration.Configuration; - -import org.apache.batik.dom.svg.*; -import org.w3c.dom.*; -import org.w3c.dom.svg.*; -import org.w3c.dom.svg.SVGLength; - -import org.w3c.dom.DOMImplementation; -import org.apache.batik.dom.svg.SVGDOMImplementation; - -import java.io.File; -import java.net.URL; - -/** - * class representing svg:svg pseudo flow object. - */ -public class SVGElement extends Svg { - - /** - * inner class for making SVG objects. - */ - public static class Maker extends FObj.Maker { - - /** - * make an SVG object. - * - * @param parent the parent formatting object - * @param propertyList the explicit properties of this object - * - * @return the SVG object - */ - public FObj make(FObj parent, - PropertyList propertyList) throws FOPException { - return new SVGElement(parent, propertyList); - } - - } - - /** - * returns the maker for this object. - * - * @return the maker for SVG objects - */ - public static FObj.Maker maker() { - return new SVGElement.Maker(); - } - - FontState fs; - - /** - * constructs an SVG object (called by Maker). - * - * @param parent the parent formatting object - * @param propertyList the explicit properties of this object - */ - public SVGElement(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - } - - /** - * layout this formatting object. - * - * @param area the area to layout the object into - * - * @return the status of the layout - */ - public Status layout(Area area) throws FOPException { - - if (!(area instanceof ForeignObjectArea)) { - // this is an error - throw new FOPException("SVG not in fo:instream-foreign-object"); - } - - if (this.marker == START) { - this.fs = area.getFontState(); - - this.marker = 0; - } - - /* create an SVG area */ - /* if width and height are zero, may want to get the bounds of the content. */ - - DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); - String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; - Document doc = impl.createDocument(svgNS, "svg", null); - - Element svgRoot = doc.getDocumentElement(); - - try { - String baseDir = Configuration.getStringValue("baseDir"); - ((SVGOMDocument)doc).setURLObject(new URL(baseDir)); - } catch (Exception e) {} - - DefaultSVGContext dc = new DefaultSVGContext() { - public float getPixelToMM() { - return 0.264583333333333333333f; - // 72 dpi - } - - public float getViewportWidth() { - return 100; - } - - public float getViewportHeight() { - return 100; - } - - }; - ((SVGOMDocument)doc).setSVGContext(dc); - buildTopLevel(doc, svgRoot); - float width = - ((SVGSVGElement)svgRoot).getWidth().getBaseVal().getValue(); - float height = - ((SVGSVGElement)svgRoot).getHeight().getBaseVal().getValue(); - SVGArea svg = new SVGArea(fs, width, height); - svg.setSVGDocument(doc); - svg.start(); - - /* finish off the SVG area */ - svg.end(); - - /* add the SVG area to the containing area */ - ForeignObjectArea foa = (ForeignObjectArea)area; - foa.setObject(svg); - foa.setIntrinsicWidth(svg.getWidth()); - foa.setIntrinsicHeight(svg.getHeight()); - - /* return status */ - return new Status(Status.OK); - } - -} diff --git a/src/org/apache/fop/svg/SVGElementMapping.java b/src/org/apache/fop/svg/SVGElementMapping.java deleted file mode 100644 index c6d876f61..000000000 --- a/src/org/apache/fop/svg/SVGElementMapping.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.svg; - -import java.util.Enumeration; - -import org.apache.fop.fo.properties.SVGPropertyMapping; -import org.apache.fop.fo.TreeBuilder; -import org.apache.fop.fo.FOTreeBuilder; -import org.apache.fop.fo.ElementMapping; - -public class SVGElementMapping implements ElementMapping { - - public void addToBuilder(TreeBuilder builder) { - String uri = "http://www.w3.org/2000/svg"; - builder.addMapping(uri, "svg", SVGElement.maker()); - builder.addMapping(uri, "rect", Rect.maker()); - builder.addMapping(uri, "line", Line.maker()); - builder.addMapping(uri, "text", Text.maker()); - - builder.addMapping(uri, "desc", Desc.maker()); - builder.addMapping(uri, "title", Title.maker()); - builder.addMapping(uri, "circle", Circle.maker()); - builder.addMapping(uri, "ellipse", Ellipse.maker()); - builder.addMapping(uri, "g", G.maker()); - builder.addMapping(uri, "polyline", Polyline.maker()); - builder.addMapping(uri, "polygon", Polygon.maker()); - builder.addMapping(uri, "defs", Defs.maker()); - builder.addMapping(uri, "path", Path.maker()); - builder.addMapping(uri, "use", Use.maker()); - builder.addMapping(uri, "tspan", Tspan.maker()); - builder.addMapping(uri, "tref", Tref.maker()); - builder.addMapping(uri, "image", Image.maker()); - builder.addMapping(uri, "style", Style.maker()); - - builder.addMapping(uri, "textPath", TextPath.maker()); - builder.addMapping(uri, "clipPath", ClipPath.maker()); - builder.addMapping(uri, "mask", Mask.maker()); - builder.addMapping(uri, "linearGradient", LinearGradient.maker()); - builder.addMapping(uri, "radialGradient", RadialGradient.maker()); - builder.addMapping(uri, "stop", Stop.maker()); - builder.addMapping(uri, "a", A.maker()); - builder.addMapping(uri, "switch", Switch.maker()); - builder.addMapping(uri, "symbol", Symbol.maker()); - - builder.addMapping(uri, "pattern", Pattern.maker()); - - builder.addMapping(uri, "marker", Marker.maker()); - builder.addMapping(uri, "animate", Animate.maker()); - builder.addMapping(uri, "altGlyph", AltGlyph.maker()); - builder.addMapping(uri, "font", Font.maker()); - builder.addMapping(uri, "glyph", Glyph.maker()); - builder.addMapping(uri, "missing-glyph", MissingGlyph.maker()); - builder.addMapping(uri, "hkern", Hkern.maker()); - builder.addMapping(uri, "vkern", Vkern.maker()); - builder.addMapping(uri, "set", Set.maker()); - builder.addMapping(uri, "animateMotion", AnimateMotion.maker()); - builder.addMapping(uri, "animateColor", AnimateColor.maker()); - builder.addMapping(uri, "animateTransform", AnimateTransform.maker()); - builder.addMapping(uri, "cursor", Cursor.maker()); - builder.addMapping(uri, "filter", Filter.maker()); - - builder.addMapping(uri, "feFlood", FeFlood.maker()); - builder.addMapping(uri, "feGaussianBlur", FeGaussianBlur.maker()); - builder.addMapping(uri, "feOffset", FeOffset.maker()); - builder.addMapping(uri, "feMerge", FeMerge.maker()); - builder.addMapping(uri, "feMergeNode", FeMergeNode.maker()); - - - builder.addPropertyList(uri, SVGPropertyMapping.getGenericMappings()); - /* Add any element mappings */ - for (Enumeration e = SVGPropertyMapping.getElementMappings(); - e.hasMoreElements(); ) { - String elem = (String)e.nextElement(); - builder.addElementPropertyList(uri, elem, - SVGPropertyMapping.getElementMapping(elem)); - } - } - -} diff --git a/src/org/apache/fop/svg/SVGObj.java b/src/org/apache/fop/svg/SVGObj.java deleted file mode 100644 index 2a215d730..000000000 --- a/src/org/apache/fop/svg/SVGObj.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.svg; - -// FOP -import org.apache.fop.fo.*; - -/** - * Since SVG objects are not layed out then this class checks - * that this element is not being layed out inside some incorrect - * element. - */ -public abstract class SVGObj extends XMLObj { - - /** - * - * @param parent the parent formatting object - * @param propertyList the explicit properties of this object - */ - public SVGObj(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - } - - public String getNameSpace() { - return "http://www.w3.org/2000/svg"; - } - -} - diff --git a/src/org/apache/fop/svg/SVGStringProperty.java b/src/org/apache/fop/svg/SVGStringProperty.java deleted file mode 100644 index c483773f2..000000000 --- a/src/org/apache/fop/svg/SVGStringProperty.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.svg; - -import java.util.*; - -// FOP -import org.apache.fop.fo.*; -import org.apache.fop.apps.FOPException; - -/** - * a class representing all properties in SVG - */ -public class SVGStringProperty extends Property { - - /** - * inner class for making SVG String objects. - */ - public static class Maker extends Property.Maker { - - /** - * whether this property is inherited or not. - * - * @return is this inherited? - */ - public boolean isInherited() { - return false; - } - - /** - * make an SVG String property with the given value. - * - * @param propertyList the property list this is a member of - * @param value the explicit string value of the property - */ - public Property make(PropertyList propertyList, String value, - FObj fo) throws FOPException { - return new SVGStringProperty(propertyList, value); - } - - /** - * make an SVG String property with the default value. - * - * @param propertyList the property list the property is a member of - */ - public Property make(PropertyList propertyList) throws FOPException { - return make(propertyList, null, null); - } - - } - - /** - * returns the maker for this object. - * - * @return the maker for SVG Length objects - */ - public static Property.Maker maker(String name) { - return new SVGStringProperty.Maker(); - } - - /** - * the value - */ - protected String value; - - /** - * construct an SVG String (called by the Maker). - * - * @param propertyList the property list this is a member of - * @param explicitValue the explicit value as a Length object - */ - protected SVGStringProperty(PropertyList propertyList, - String explicitValue) { - this.value = explicitValue; - } - - /** - * get the value - * - * @return the length as a Length object - */ - public String getString() { - return this.value; - } - -} diff --git a/src/org/apache/fop/svg/SVGUtilities.java b/src/org/apache/fop/svg/SVGUtilities.java deleted file mode 100644 index fe854d271..000000000 --- a/src/org/apache/fop/svg/SVGUtilities.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.svg; - -import java.util.*; -import java.text.*; -import java.awt.*; -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; -import java.awt.font.FontRenderContext; - -import org.apache.fop.fo.*; -import org.apache.fop.fo.properties.*; -import org.apache.fop.layout.*; -import org.apache.fop.apps.*; -import org.apache.fop.datatypes.*; -import org.apache.fop.layout.inline.*; -import org.apache.fop.svg.*; -import org.w3c.dom.*; -import org.w3c.dom.svg.*; -import org.w3c.dom.css.*; - -import org.apache.batik.dom.svg.SVGDOMImplementation; - -/** - * Some utilities for creating svg DOM documents and elements. - */ -public class SVGUtilities { - final static String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; - - - public static final Document createSVGDocument(float width, - float height) { - DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); - Document doc = impl.createDocument(svgNS, "svg", null); - - Element svgRoot = doc.getDocumentElement(); - svgRoot.setAttributeNS(null, "width", "" + width); - svgRoot.setAttributeNS(null, "height", "" + height); - return doc; - } - - /** - * Get the string width for a particular string given the font. - */ - public static final float getStringWidth(String str, java.awt.Font font) { - Rectangle2D rect = - font.getStringBounds(str, 0, str.length(), - new FontRenderContext(new AffineTransform(), - true, true)); - return (float)rect.getWidth(); - } - - /** - * Get the string height for a particular string given the font. - */ - public static final float getStringHeight(String str, - java.awt.Font font) { - Rectangle2D rect = - font.getStringBounds(str, 0, str.length(), - new FontRenderContext(new AffineTransform(), - true, true)); - return (float)rect.getHeight(); - } - - /** - * Get the string bounds for a particular string given the font. - */ - public static final Rectangle2D getStringBounds(String str, - java.awt.Font font) { - return font.getStringBounds(str, 0, str.length(), - new FontRenderContext(new AffineTransform(), - true, true)); - } - - /** - * Create an SVG Line - */ - public static final Element createLine(Document doc, float x, float y, - float x2, float y2) { - Element ellipse = doc.createElementNS(svgNS, "line"); - ellipse.setAttributeNS(null, "x1", "" + x); - ellipse.setAttributeNS(null, "x2", "" + x2); - ellipse.setAttributeNS(null, "y1", "" + y); - ellipse.setAttributeNS(null, "y2", "" + y2); - return ellipse; - } - - /** - * Create an SVG Ellipse - */ - public static final Element createEllipse(Document doc, float cx, - float cy, float rx, float ry) { - Element ellipse = doc.createElementNS(svgNS, "ellipse"); - ellipse.setAttributeNS(null, "cx", "" + cx); - ellipse.setAttributeNS(null, "rx", "" + rx); - ellipse.setAttributeNS(null, "cy", "" + cy); - ellipse.setAttributeNS(null, "ry", "" + ry); - return ellipse; - } - - /** - * Create an SVG Path. - */ - public static final Element createPath(Document doc, String str) { - Element path = doc.createElementNS(svgNS, "path"); - path.setAttributeNS(null, "d", str); - return path; - } - - /** - * Create an SVG Text object. - */ - public static final Element createText(Document doc, float x, float y, - String str) { - Element textGraph = doc.createElementNS(svgNS, "text"); - textGraph.setAttributeNS(null, "x", "" + x); - textGraph.setAttributeNS(null, "y", "" + y); - org.w3c.dom.Text text = doc.createTextNode(str); - textGraph.appendChild(text); - return textGraph; - } - - /** - * Create an SVG Rectangle. - */ - public static final Element createRect(Document doc, float x, float y, - float width, float height) { - Element border = doc.createElementNS(svgNS, "rect"); - border.setAttributeNS(null, "x", "" + x); - border.setAttributeNS(null, "y", "" + y); - border.setAttributeNS(null, "width", "" + width); - border.setAttributeNS(null, "height", "" + height); - return border; - } - - /** - * Create an SVG G. - */ - public static final Element createG(Document doc) { - Element border = doc.createElementNS(svgNS, "g"); - return border; - } - - /** - * Create an SVG Clip. - */ - public static final Element createClip(Document doc, Element els, - String id) { - Element border = doc.createElementNS(svgNS, "clipPath"); - border.setAttributeNS(null, "id", id); - border.appendChild(els); - return border; - } - - public static final Element createImage(Document doc, String ref, - float width, float height) { - Element border = doc.createElementNS(svgNS, "image"); - border.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", - ref); - border.setAttributeNS(null, "width", "" + width); - border.setAttributeNS(null, "height", "" + height); - return border; - } - - /** - * Create some SVG text that is wrapped into a specified width.. - */ - public static final Element wrapText(Document doc, String str, - java.awt.Font font, float width) { - Element g = createG(doc); - Element text; - StringTokenizer st = new StringTokenizer(str, " \t\r\n"); - float totalWidth = 0; - String totalStr = ""; - int line = 0; - float height = getStringHeight(str, font); - while (st.hasMoreTokens()) { - String token = st.nextToken(); - float strwidth = getStringWidth(token, font); - totalWidth += strwidth; - if (totalWidth > width) { - if (totalStr.equals("")) { - totalStr = token; - token = ""; - strwidth = 0; - } - text = createText(doc, 0, line * (height + 5), totalStr); - g.appendChild(text); - totalStr = token; - totalWidth = strwidth; - line++; - } else { - totalStr = totalStr + " " + token; - } - } - - return g; - } - -} diff --git a/src/org/apache/fop/svg/XMLObj.java b/src/org/apache/fop/svg/XMLObj.java deleted file mode 100644 index e9b41669b..000000000 --- a/src/org/apache/fop/svg/XMLObj.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.svg; - -// FOP -import org.apache.fop.fo.*; -import org.apache.fop.layout.Area; -import org.apache.fop.layout.FontState; -import org.apache.fop.apps.FOPException; -import org.apache.fop.layout.LinkSet; - -import org.w3c.dom.*; - -import java.util.*; - -/** - * Since SVG objects are not layed out then this class checks - * that this element is not being layed out inside some incorrect - * element. - */ -public abstract class XMLObj extends FObj { - - protected String tagName = ""; - protected String[] props = {}; - - /** - * - * @param parent the parent formatting object - * @param propertyList the explicit properties of this object - */ - public XMLObj(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - } - - public abstract String getNameSpace(); - - protected static Hashtable ns = new Hashtable(); - - public void addGraphic(Document doc, Element parent) { - Element element = doc.createElementNS(getNameSpace(), tagName); - // Element element = doc.createElement(tagName); - for (int count = 0; count < props.length; count++) { - if (this.properties.get(props[count]) != null) { - String rf = this.properties.get(props[count]).getString(); - if (rf != null) { - if (props[count].indexOf(":") == -1) { - element.setAttribute(props[count], rf); - } else { - String pref = - props[count].substring(0, - props[count].indexOf(":")); - if (pref.equals("xmlns")) { - ns.put(props[count].substring(props[count].indexOf(":") - + 1), rf); - } - ns.put("xlink", "http://www.w3.org/1999/xlink"); - element.setAttributeNS((String)ns.get(pref), - props[count], rf); - } - } - } - } - parent.appendChild(element); - int numChildren = this.children.size(); - for (int i = 0; i < numChildren; i++) { - Object child = children.elementAt(i); - if (child instanceof XMLObj) { - ((XMLObj)child).addGraphic(doc, element); - } else if (child instanceof String) { - org.w3c.dom.Text text = doc.createTextNode((String)child); - element.appendChild(text); - } - } - } - - public void buildTopLevel(Document doc, Element svgRoot) { - // build up the info for the top level element - for (int count = 0; count < props.length; count++) { - if (this.properties.get(props[count]) != null) { - String rf = this.properties.get(props[count]).getString(); - if (rf != null) - svgRoot.setAttributeNS(null, props[count], rf); - } - } - // doc.appendChild(topLevel); - int numChildren = this.children.size(); - for (int i = 0; i < numChildren; i++) { - Object child = children.elementAt(i); - if (child instanceof XMLObj) { - ((XMLObj)child).addGraphic(doc, svgRoot); - } else if (child instanceof String) { - org.w3c.dom.Text text = doc.createTextNode((String)child); - svgRoot.appendChild(text); - } - } - } - - public Document createBasicDocument() { - Document doc = null; - - Element svgRoot = null; - try { - // DOMImplementation impl = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation(); - // String ns = GraphElementMapping.URI; - // doc = impl.createDocument(ns, "graph", null); - doc = - javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - Element el = doc.createElement("graph"); - doc.appendChild(el); - - svgRoot = doc.getDocumentElement(); - buildTopLevel(doc, svgRoot); - - } catch (Exception e) { - e.printStackTrace(); - } - return doc; - } - - /** - * layout this formatting object. - * - * @param area the area to layout the object into - * @return the status of the layout - */ - public Status layout(Area area) throws FOPException { - /* generate a warning */ - System.err.println("WARNING: " + this.name + " outside foreign xml"); - - /* return status */ - return new Status(Status.OK); - } - - /** - * These method overrides prevent problems with the different types. - */ - public void setIsInTableCell() {} - - public void forceStartOffset(int offset) {} - - public void forceWidth(int width) {} - - public void resetMarker() {} - - public void setLinkSet(LinkSet linkSet) {} - - public Vector getMarkerSnapshot(Vector snapshot) { - return snapshot; - } - - public void rollback(Vector snapshot) {} - -} - diff --git a/src/org/apache/fop/svg/package.html b/src/org/apache/fop/svg/package.html deleted file mode 100644 index 537adb42d..000000000 --- a/src/org/apache/fop/svg/package.html +++ /dev/null @@ -1,7 +0,0 @@ - -org.apache.fop.svg Package - -

Classes that add basic SVG support to FOP

-

This includes flow objects, areas and properties.

- - \ No newline at end of file diff --git a/src/org/apache/fop/system/BufferArray.java b/src/org/apache/fop/system/BufferArray.java deleted file mode 100644 index a5596dc46..000000000 --- a/src/org/apache/fop/system/BufferArray.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -// Seshadri -/* This package is to be used for all Oeprating System related activities. */ -/* This buffers data into an array in memory */ - -package org.apache.fop.system; - - -// FOP - - - -// Java - - -public class BufferArray { - - - public BufferArray() {} - -} - diff --git a/src/org/apache/fop/system/BufferFile.java b/src/org/apache/fop/system/BufferFile.java deleted file mode 100644 index 370496f4b..000000000 --- a/src/org/apache/fop/system/BufferFile.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -// Seshadri -/* This package is to be used for all Oeprating System related activities. */ -/* This buffers data into a file */ - - - -package org.apache.fop.system; - - -import java.io.*; - - - -public class BufferFile { - - public BufferFile() {} - -} diff --git a/src/org/apache/fop/system/BufferManager.java b/src/org/apache/fop/system/BufferManager.java deleted file mode 100644 index 75959de49..000000000 --- a/src/org/apache/fop/system/BufferManager.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -// Seshadri -/* - * This package is to be used for all Oeprating System related activities. - * This file manages system buffers - */ - -package org.apache.fop.system; - - -// FOP - -import org.apache.fop.fo.FONode; - - -// Java - -import java.io.*; -import java.util.Hashtable; - - -public class BufferManager { - - - protected FileWriter fw; - protected FileReader fr; - protected char cache[]; // Cache - protected long csize; // Cache size - - - protected File buff = null; - - protected long fp = 0; - - protected long markStart = - 0; // used to set the current point in the stream while reading - protected long markEnd = 0; - protected long curMark = 0; - - // Hash of objects and their offsets within - - Hashtable offSetTable = new Hashtable(); - - private class Offset { - - long fp = 0; // File Pointer - int length; - char[] data; // when no buffer is specified - - Offset(long fp, int length, char data[]) { - this.fp = fp; - this.length = length; - this.data = data; - } - - } - - - - public void addBufferFile(File buff) { - - if (buff != null) - try { - fw = new FileWriter(buff); - fr = new FileReader(buff); - csize = 100000; - this.buff = buff; - } catch (Exception e) { - System.out.println(e); - } - - } - - public void writeBuffer(Object obj, char arr[]) { - - int length = arr.length; - - if (buff != null) { - offSetTable.put(obj, new Offset(this.fp, length, null)); - try { - fw.write(arr); - - this.fp += length; - } catch (Exception e) { - System.out.println(e); - } - } else { - // Store the data in memory - offSetTable.put(obj, new Offset(this.fp, length, arr)); - } - - - } - - - public void readComplete() { - - // An indication that manager can close the writable buffers and prepare - // for reading.. - if (buff != null) - try { - - fw.close(); - - cache = new char[(int)csize]; - setupCache(curMark); - - } catch (Exception e) { - System.out.println(e); - } - } - - - - - public char[] readBuffer(Object obj) { - - Offset values = (Offset)offSetTable.get(obj); - - // Was buffering used? - - if (buff != null) { - - - char ca[] = new char[values.length]; - - // Check if csize is too small - - if (csize < values.length) { - System.out.println("Cache size too small"); - System.exit(0); - } - - - // Is the data outside the cache? - - if (!(values.fp >= markStart - && values.fp + values.length <= markEnd)) { - - setupCache(values.fp); - } - - - for (long i = values.fp - markStart, j = 0; j < values.length; - ++i, ++j) { - - ca[(int)j] = cache[(int)i]; - } - - - return ca; - } else { - return values.data; - } - } - - protected void setupCache(long curMark) { - - try { - - FileReader fr = new FileReader(buff); - fr.skip(curMark); - - long rem = buff.length() - curMark; - if (rem > csize) { - - rem = csize; - } - - fr.read(cache, 0, (int)rem); - - - markStart = curMark; - markEnd = rem - 1; - - } catch (Exception e) { - System.out.println(e); - } - - - } - - -} diff --git a/src/org/apache/fop/tools/TestConverter.java b/src/org/apache/fop/tools/TestConverter.java deleted file mode 100644 index c02509566..000000000 --- a/src/org/apache/fop/tools/TestConverter.java +++ /dev/null @@ -1,307 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.tools; - -import org.apache.fop.apps.*; -import org.apache.fop.configuration.*; - -import java.io.*; -import java.util.*; - -import javax.xml.parsers.*; - -import org.w3c.dom.*; -import org.xml.sax.XMLReader; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -/** - * TestConverter is used to process a set of tests specified in - * a testsuite. - * This class retrieves the data in the testsuite and uses FOP - * to convert the xml and xsl file into either an xml representation - * of the area tree or a pdf document. - * The area tree can be used for automatic comparisons between different - * versions of FOP or the pdf can be view for manual checking and - * pdf rendering. - * - * Modified by Mark Lillywhite mark-fop@inomial.com to use the new Driver - * interface. - */ -public class TestConverter { - boolean failOnly = false; - boolean outputPDF = false; - File destdir; - File compare = null; - String baseDir = "./"; - Hashtable differ = new Hashtable(); - - /** - * This main method can be used to run the test converter from - * the command line. - * This will take a specified testsuite xml and process all - * tests in it. - * The command line options are: - * -b to set the base directory for where the testsuite and associated files are - * -failOnly to process only the tests which are specified as fail in the test results - * -pdf to output the result as pdf - */ - public static void main(String[] args) { - if (args == null || args.length == 0) { - System.out.println("test suite file name required"); - } - TestConverter tc = new TestConverter(); - - String testFile = null; - for (int count = 0; count < args.length; count++) { - if (args[count].equals("-failOnly")) { - tc.setFailOnly(true); - } else if (args[count].equals("-pdf")) { - tc.setOutputPDF(true); - } else if (args[count].equals("-b")) { - tc.setBaseDir(args[count + 1]); - } else { - testFile = args[count]; - } - } - if (testFile == null) { - System.out.println("test suite file name required"); - } - - tc.runTests(testFile, "results", null); - } - - public TestConverter() {} - - - public void setOutputPDF(boolean pdf) { - outputPDF = pdf; - } - - public void setFailOnly(boolean fail) { - failOnly = fail; - } - - public void setBaseDir(String str) { - baseDir = str; - } - - /** - * Run the Tests. - * This runs the tests specified in the xml file fname. - * The document is read as a dom and each testcase is covered. - */ - public Hashtable runTests(String fname, String dest, String compDir) { - // System.out.println("running tests in file:" + fname); - try { - if (compDir != null) { - compare = new File(baseDir + "/" + compDir); - } - destdir = new File(baseDir + "/" + dest); - destdir.mkdirs(); - File f = new File(baseDir + "/" + fname); - DocumentBuilderFactory factory = - DocumentBuilderFactory.newInstance(); - DocumentBuilder db = factory.newDocumentBuilder(); - Document doc = db.parse(f); - - NodeList suitelist = doc.getChildNodes(); - if (suitelist.getLength() == 0) { - return differ; - } - - Node testsuite = null; - testsuite = doc.getDocumentElement(); - - if (testsuite.hasAttributes()) { - String profile = - testsuite.getAttributes().getNamedItem("profile").getNodeValue(); - // System.out.println("testing test suite:" + profile); - } - - NodeList testcases = testsuite.getChildNodes(); - for (int count = 0; count < testcases.getLength(); count++) { - Node testcase = testcases.item(count); - if (testcase.getNodeName().equals("testcases")) { - runTestCase(testcase); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return differ; - } - - /** - * Run a test case. - * This goes through a test case in the document. - * A testcase can contain a test, a result or more test cases. - * A test case is handled recursively otherwise the test is run. - */ - protected void runTestCase(Node tcase) { - if (tcase.hasAttributes()) { - String profile = - tcase.getAttributes().getNamedItem("profile").getNodeValue(); - // System.out.println("testing profile:" + profile); - } - - NodeList cases = tcase.getChildNodes(); - for (int count = 0; count < cases.getLength(); count++) { - Node node = cases.item(count); - String nodename = node.getNodeName(); - if (nodename.equals("testcases")) { - runTestCase(node); - } else if (nodename.equals("test")) { - runTest(tcase, node); - } else if (nodename.equals("result")) {} - - } - - } - - /** - * Run a particular test. - * This runs a test defined by the xml and xsl documents. - * If the test has a result specified it is checked. - * This creates an XSLTInputHandler to provide the input - * for FOP and writes the data out to an XML are tree. - */ - protected void runTest(Node testcase, Node test) { - String id = test.getAttributes().getNamedItem("id").getNodeValue(); - Node result = locateResult(testcase, id); - boolean pass = false; - if (result != null) { - String agreement = - result.getAttributes().getNamedItem("agreement").getNodeValue(); - pass = agreement.equals("full"); - } - - if (pass && failOnly) { - return; - } - - String xml = test.getAttributes().getNamedItem("xml").getNodeValue(); - Node xslNode = test.getAttributes().getNamedItem("xsl"); - String xsl = null; - if (xslNode != null) { - xsl = xslNode.getNodeValue(); - } - // System.out.println("converting xml:" + xml + " and xsl:" + - // xsl + " to area tree"); - - try { - File xmlFile = new File(baseDir + "/" + xml); - - try { - Configuration.put("baseDir", - xmlFile.getParentFile().toURL().toExternalForm()); - } catch (Exception e) { - System.err.println("Error setting base directory"); - } - - InputHandler inputHandler = null; - if (xsl == null) { - inputHandler = new FOInputHandler(xmlFile); - } else { - inputHandler = new XSLTInputHandler(xmlFile, - new File(baseDir + "/" - + xsl)); - } - - XMLReader parser = inputHandler.getParser(); - setParserFeatures(parser); - - Driver driver = new Driver(); - if (outputPDF) { - driver.setRenderer(Driver.RENDER_PDF); - } else { - driver.setRenderer(Driver.RENDER_XML); - } - - Hashtable rendererOptions = new Hashtable(); - rendererOptions.put("fineDetail", new Boolean(false)); - driver.getRenderer().setOptions(rendererOptions); - driver.getRenderer().setProducer("Testsuite Converter"); - - String outname = xmlFile.getName(); - if (outname.endsWith(".xml")) { - outname = outname.substring(0, outname.length() - 4); - } - driver.setOutputStream(new FileOutputStream(new File(destdir, - outname + (outputPDF ? ".pdf" : ".at.xml")))); - // System.out.println("ddir:" + destdir + " on:" + outname + ".pdf"); - driver.render(parser, inputHandler.getInputSource()); - - // check difference - if (compare != null) { - File f1 = new File(destdir, outname + ".at.xml"); - File f2 = new File(compare, outname + ".at.xml"); - if (!compareFiles(f1, f2)) { - differ.put(outname + ".at.xml", new Boolean(pass)); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * Compare files. - * Returns true if equal. - */ - protected boolean compareFiles(File f1, File f2) { - if(f1.length() != f2.length()) { - return false; - } - try { - InputStream is1 = new BufferedInputStream(new FileInputStream(f1)); - InputStream is2 = new BufferedInputStream(new FileInputStream(f2)); - while (true) { - int ch1 = is1.read(); - int ch2 = is2.read(); - if (ch1 == ch2) { - if (ch1 == -1) { - return true; - } - } else { - return false; - } - } - } catch (Exception e) {} - - return false; - } - - public void setParserFeatures(XMLReader parser) throws FOPException { - try { - parser.setFeature("http://xml.org/sax/features/namespace-prefixes", - true); - } catch (SAXException e) { - throw new FOPException("Error in setting up parser feature namespace-prefixes\n" - + "You need a parser which supports SAX version 2", e); - } - } - - protected Node locateResult(Node testcase, String id) { - NodeList cases = testcase.getChildNodes(); - for (int count = 0; count < cases.getLength(); count++) { - Node node = cases.item(count); - String nodename = node.getNodeName(); - if (nodename.equals("result")) { - String resultid = - node.getAttributes().getNamedItem("id").getNodeValue(); - if (id.equals(resultid)) { - return node; - } - } - } - return null; - } - -} diff --git a/src/org/apache/fop/viewer/Command.java b/src/org/apache/fop/viewer/Command.java deleted file mode 100644 index d25377a81..000000000 --- a/src/org/apache/fop/viewer/Command.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.viewer; -/* - * Juergen Verwohlt: Juergen.Verwohlt@jcatalog.com, - * Rainer Steinkuhle: Rainer.Steinkuhle@jcatalog.com, - * Stanislav Gorkhover: Stanislav.Gorkhover@jcatalog.com - */ - -import java.awt.event.ActionEvent; -import org.apache.fop.messaging.MessageHandler; -import javax.swing.AbstractAction; -import javax.swing.ImageIcon; -import java.net.*; - - -/** - * Klasse für UI-Kommandos. Die Kommandos können in das Menüsystem oder - * in eine Toolbar eingefügt werden.
- * Commands unterstützen mehrsprachigkeit.
- * Durch überschreiben der Methode doit kann die Klasse customisiert werden. - * Über die Methode undoit kann Undo-Funktionalität unterstützt werden.
- * - * @author Juergen.Verwohlt@jcatalog.com - * @version 1.0 18.03.99 - */ -public class Command extends AbstractAction { - - public static String IMAGE_DIR = "/org/apache/fop/viewer/Images/"; - - public Command(String name) { - this(name, (ImageIcon)null); - } - - public Command(String name, ImageIcon anIcon) { - super(name, anIcon); - } - - public Command(String name, String iconName) { - super(name); - String path = IMAGE_DIR + iconName + ".gif"; - URL url = getClass().getResource(path); - if (url == null) { - MessageHandler.errorln("Icon not found: " + path); - } else - putValue(SMALL_ICON, new ImageIcon(url)); - } - - public void actionPerformed(ActionEvent e) { - doit(); - } - - public void doit() { - MessageHandler.errorln("Not implemented."); - } - - public void undoit() { - MessageHandler.errorln("Not implemented."); - } - -} diff --git a/src/org/apache/fop/viewer/GoToPageDialog.java b/src/org/apache/fop/viewer/GoToPageDialog.java deleted file mode 100644 index f5bce3f66..000000000 --- a/src/org/apache/fop/viewer/GoToPageDialog.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -/* - * originally contributed by - * Juergen Verwohlt: Juergen.Verwohlt@jCatalog.com, - * Rainer Steinkuhle: Rainer.Steinkuhle@jCatalog.com, - * Stanislav Gorkhover: Stanislav.Gorkhover@jCatalog.com - */ - -package org.apache.fop.viewer; - -import java.awt.*; -import javax.swing.*; -import java.awt.event.*; - -import org.apache.fop.messaging.MessageHandler; - -public class GoToPageDialog extends JDialog { - JPanel panel1 = new JPanel(); - GridBagLayout gridBagLayout1 = new GridBagLayout(); - JLabel pgNbLabel = new JLabel(); - JTextField pgNbField = new JTextField(); - JButton okButton = new JButton(); - JButton cancelButton = new JButton(); - - int pageNumber = -1; - - public GoToPageDialog(Frame frame, String title, boolean modal) { - super(frame, title, modal); - try { - jbInit(); - pack(); - } catch (Exception ex) { - MessageHandler.errorln("GoToPageDialog: Konstruktor: " - + ex.getMessage()); - } - } - - public GoToPageDialog() { - this(null, "", false); - } - - void jbInit() throws Exception { - panel1.setLayout(gridBagLayout1); - pgNbLabel.setText("Page number"); - okButton.setText("Ok"); - okButton.addActionListener(new java.awt.event.ActionListener() { - - public void actionPerformed(ActionEvent e) { - okButton_actionPerformed(e); - } - - }); - cancelButton.setText("Cancel"); - cancelButton.addActionListener(new java.awt.event.ActionListener() { - - public void actionPerformed(ActionEvent e) { - cancelButton_actionPerformed(e); - } - - }); - panel1.setMinimumSize(new Dimension(250, 78)); - getContentPane().add(panel1); - panel1.add(pgNbLabel, - new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, - GridBagConstraints.WEST, - GridBagConstraints.NONE, - new Insets(10, 10, 10, 5), 0, 0)); - panel1.add(pgNbField, - new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, - GridBagConstraints.WEST, - GridBagConstraints.BOTH, - new Insets(10, 5, 10, 10), 0, 0)); - panel1.add(okButton, - new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, - GridBagConstraints.EAST, - GridBagConstraints.NONE, - new Insets(0, 0, 10, 5), 0, 0)); - panel1.add(cancelButton, - new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, - GridBagConstraints.WEST, - GridBagConstraints.NONE, - new Insets(0, 10, 10, 10), 0, 0)); - } - - void okButton_actionPerformed(ActionEvent e) { - try { - pageNumber = Integer.parseInt(pgNbField.getText()); - dispose(); - } catch (Exception ex) { - pgNbField.setText("???"); - } - - } - - void cancelButton_actionPerformed(ActionEvent e) { - pageNumber = -1; - dispose(); - } - - public int getPageNumber() { - return pageNumber; - } - -} diff --git a/src/org/apache/fop/viewer/IconToolBar.java b/src/org/apache/fop/viewer/IconToolBar.java deleted file mode 100644 index c67d13eb4..000000000 --- a/src/org/apache/fop/viewer/IconToolBar.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.viewer; - -/* - * originally contributed by - * Juergen Verwohlt: Juergen.Verwohlt@jCatalog.com, - * Rainer Steinkuhle: Rainer.Steinkuhle@jCatalog.com, - * Stanislav Gorkhover: Stanislav.Gorkhover@jCatalog.com - */ - - -import javax.swing.*; -import java.beans.PropertyChangeListener; - -public class IconToolBar extends JToolBar { - - public JButton add(Action a) { - String name = (String)a.getValue(Action.NAME); - Icon icon = (Icon)a.getValue(Action.SMALL_ICON); - return add(a, name, icon); - } - - public JButton add(Action a, String name, Icon icon) { - JButton b = new JButton(icon); - b.setToolTipText(name); - b.setEnabled(a.isEnabled()); - b.addActionListener(a); - add(b); - PropertyChangeListener actionPropertyChangeListener = - createActionChangeListener(b); - a.addPropertyChangeListener(actionPropertyChangeListener); - return b; - } - -} - - diff --git a/src/org/apache/fop/viewer/Images/Print.gif b/src/org/apache/fop/viewer/Images/Print.gif deleted file mode 100644 index e715fe67f5f3d1bcbe5d5c5d3f386cdb3d6c5d10..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 992 zcmXX_Pe_z;5S>(Lvq*)M4U$SFN<5g;!RXLJrs*LOTDnxwWekE29<;#2ia}ywK^+>x zaQj1M9YP}l6O`;wPDv0!&|ZW(6fC4cc$(gPxG?+u=9}NVdGF0`M`wHM;qz%q(?5z& z4xji&Y&>%DE<>3N<(x7&d4&7?{Jawmh>eHG>m2GiJP>HeWs1dOp-?ch+1c5tsVP+* z85tQE7!Z+cHrv+L#>{nfbyZbW?&hxU;?8k2b5l2QLrPImb5&PyWmk%eVlL_;F6=_+ zb2evn7H4(_HFHuYaY6y800j!#kWx%AH4`&7qnL(F)l^K`lwvrFq9$U(CKOz7m(^H| z*_c2Ltww4jhAD)3APX>X1v#)m4O4*)Xkek4LPzAH%BmEaFcX=G3ad~^1O*gXlv$ae z7>saNNt9R#s^9@Qq8k=KGZ;V{C<6?PK@nF$0#ktvXkbye6=mcsLg5^gVJ0$WVS`%5+*^P>_Q3dM=BHFuNwuxvvHQ^op5oyY#=BPHc>%@zRh2hfd{xg%6x48G=YHNLKdDs2xX+AfY z`n+@W+UERZWoKVQ&DD~Q<8LOXA20P(bmVuW_vE_9DtZRDHP1Zh9xBhLs-Lbr>dx2S z9$hTyd9W~gEI)X+@zCmR>yP)_#Vto<_B`Fiz-9WA~5 L_g=qbh>rXR0$R@L diff --git a/src/org/apache/fop/viewer/Images/firstpg.gif b/src/org/apache/fop/viewer/Images/firstpg.gif deleted file mode 100644 index 1d0315d749b6b2e49c93d3b7d088d193cbb5e5f5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 885 zcmV-*1B(1dNk%w1VHf}y0QUd@000010RaL60s{jB1Ox;H1qB8M1_uWR2nYxX2?+`c z3JVJh3=9kn4Gj(s4i66x5D*X%5fKs+5)%^>6ciK{6%`g178e&67#J8C85tTH8XFrM z92^`S9UUGX9v>ecARr(iAt53nA|oRsBqSsyB_$>%CMPE+C@3f?DJd!{Dl021EG#T7 zEiEoCE-x=HFfcGNF)=bSGBYzXG&D3dH8nOiHa9mnI5;>tIXOByIy*Z%JUl!-Jv}}? zK0iM{KtMo2K|w-7LPJACL_|bIMMXwNMn^|SNJvOYNl8jdN=r*iOiWBoO-)WtPESuy zP*6}&QBhJ-Qd3h?R8&+|RaI72R##V7SXfwDSy@_IT3cINTwGjTU0q&YUSD5dU|?Wj zVPRroVq;@tWMpJzWo2e&W@l$-XlQ6@X=!R|YHMq2Y;0_8ZEbFDZf|dIaBy&OadC2T za&vQYbaZreb#-=jc6WDoczAeud3kzzdV70&e0+R;eSLm@et&;|fPjF3fq{a8f`fyD zgoK2Jg@uNOhKGlTh=_=ZiHVAeii?YjjEszpjg5|uj*pLzkdTm(k&%*;l9Q8@l$4Z} zm6ev3mY0{8n3$NEnVFiJnwy)OoSdAUot>VZo}ZteprD|kp`oIpqNAguq@<*!rKP5( zrl+T;sHmu^si~@}s;jH3tgNi9t*x%EuCK4Ju&}VPv9YqUva_?Zw6wIfwY9dkwzs#p zxVX5vxw*Q!y1To(yu7@dCU$jHda z$;ryf%FD~k%*@Qq&CSlv&d<-!(9qD)(b3Y<($mw^)YR0~)z#M4*4Nk9*x1lt)=I7_<=;-L_>FMg~>g((4 z?Ck9A?d|UF?(gsK@bK{Q@$vHV^7Hfa^z`)g_4W4l_V@Sq`1ttw`T6?#`uqF){QUg= z{r&#_{{R2~A^8LW00930EC2ui02lxm06+**0RIUbNU)&6g8~5nD5!8DLWT|rDtt(> zBEpIP8aA}Zv7^U}5hZrSm{H@%kS0H>T*6ciK{6%`g178e&67#J8C85tTH8XFrM z92^`S9UUGX9v>ecARr(iAt53nA|oRsBqSsyB_$>%CMPE+C@3f?DJd!{Dl021EG#T7 zEiEoCE-x=HFfcGNF)=bSGBYzXG&D3dH8nOiHa9mnI5;>tIXOByIy*Z%JUl!-Jv}}? zK0iM{KtMo2K|w-7LPJACL_|bIMMXwNMn^|SNJvOYNl8jdN=r*iOiWBoO-)WtPESuy zP*6}&QBhJ-Qd3h?R8&+|RaI72R##V7SXfwDSy@_IT3cINTwGjTU0q&YUSD5dU|?Wj zVPRroVq;@tWMpJzWo2e&W@l$-XlQ6@X=!R|YHMq2Y;0_8ZEbFDZf|dIaBy&OadC2T za&vQYbaZreb#-=jc6WDoczAeud3kzzdV70&e0+R;eSLm@et&;|fPjF3fq{a8f`fyD zgoK2Jg@uNOhKGlTh=_=ZiHVAeii?YjjEszpjg5|uj*pLzkdTm(k&%*;l9Q8@l$4Z} zm6ev3mY0{8n3$NEnVFiJnwy)OoSdAUot>VZo}ZteprD|kp`oIpqNAguq@<*!rKP5( zrl+T;sHmu^si~@}s;jH3tgNi9t*x%EuCK4Ju&}VPv9YqUva_?Zw6wIfwY9dkwzs#p zxVX5vxw*Q!y1To(yu7@dCU$jHda z$;ryf%FD~k%*@Qq&CSlv&d<-!(9qD)(b3Y<($mw^)YR0~)z#M4*4Nk9*x1lt)=I7_<=;-L_>FMg~>g((4 z?Ck9A?d|UF?(gsK@bK{Q@$vHV^7Hfa^z`)g_4W4l_V@Sq`1ttw`T6?#`uqF){QUg= z{r&#_{{R2~A^8LW006xJEC2ui02lxm06+*<0DB1>NU)&6g98C51VB(BLW2w;Mtn%I zqQr#>CtBRdv137pA2m{3h_M$)izPF9T*6ciK{6%`g178e&67#J8C85tTH8XFrM z92^`S9UUGX9v>ecARr(iAt53nA|oRsBqSsyB_$>%CMPE+C@3f?DJd!{Dl021EG#T7 zEiEoCE-x=HFfcGNF)=bSGBYzXG&D3dH8nOiHa9mnI5;>tIXOByIy*Z%JUl!-Jv}}? zK0iM{KtMo2K|w-7LPJACL_|bIMMXwNMn^|SNJvOYNl8jdN=r*iOiWBoO-)WtPESuy zP*6}&QBhJ-Qd3h?R8&+|RaI72R##V7SXfwDSy@_IT3cINTwGjTU0q&YUSD5dU|?Wj zVPRroVq;@tWMpJzWo2e&W@l$-XlQ6@X=!R|YHMq2Y;0_8ZEbFDZf|dIaBy&OadC2T za&vQYbaZreb#-=jc6WDoczAeud3kzzdV70&e0+R;eSLm@et&;|fPjF3fq{a8f`fyD zgoK2Jg@uNOhKGlTh=_=ZiHVAeii?YjjEszpjg5|uj*pLzkdTm(k&%*;l9Q8@l$4Z} zm6ev3mY0{8n3$NEnVFiJnwy)OoSdAUot>VZo}ZteprD|kp`oIpqNAguq@<*!rKP5( zrl+T;sHmu^si~@}s;jH3tgNi9t*x%EuCK4Ju&}VPv9YqUva_?Zw6wIfwY9dkwzs#p zxVX5vxw*Q!y1To(yu7@dCU$jHda z$;ryf%FD~k%*@Qq&CSlv&d<-!(9qD)(b3Y<($mw^)YR0~)z#M4*4Nk9*x1lt)=I7_<=;-L_>FMg~>g((4 z?Ck9A?d|UF?(gsK@bK{Q@$vHV^7Hfa^z`)g_4W4l_V@Sq`1ttw`T6?#`uqF){QUg= z{r&#_{{R2~A^8LW006xJEC2ui02lxm06+*r0DB1>NU)&6g9QO7M97ff!iEqdMpQ@< vfW(U!Ga|I8F=54yy*`2*NwTELlMNq^6xp$&N{lW+QY6U{rOlfL0|Ed$6HT6| diff --git a/src/org/apache/fop/viewer/Images/prevpg.gif b/src/org/apache/fop/viewer/Images/prevpg.gif deleted file mode 100644 index 3c8cce4b60d5c4c759888928534a1d8c70d446b0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 867 zcmV-p1DyOvNk%w1VHf}y0QUd@000010RaL60s{jB1Ox;H1qB8M1_uWR2nYxX2?+`c z3JVJh3=9kn4Gj(s4i66x5D*X%5fKs+5)%^>6ciK{6%`g178e&67#J8C85tTH8XFrM z92^`S9UUGX9v>ecARr(iAt53nA|oRsBqSsyB_$>%CMPE+C@3f?DJd!{Dl021EG#T7 zEiEoCE-x=HFfcGNF)=bSGBYzXG&D3dH8nOiHa9mnI5;>tIXOByIy*Z%JUl!-Jv}}? zK0iM{KtMo2K|w-7LPJACL_|bIMMXwNMn^|SNJvOYNl8jdN=r*iOiWBoO-)WtPESuy zP*6}&QBhJ-Qd3h?R8&+|RaI72R##V7SXfwDSy@_IT3cINTwGjTU0q&YUSD5dU|?Wj zVPRroVq;@tWMpJzWo2e&W@l$-XlQ6@X=!R|YHMq2Y;0_8ZEbFDZf|dIaBy&OadC2T za&vQYbaZreb#-=jc6WDoczAeud3kzzdV70&e0+R;eSLm@et&;|fPjF3fq{a8f`fyD zgoK2Jg@uNOhKGlTh=_=ZiHVAeii?YjjEszpjg5|uj*pLzkdTm(k&%*;l9Q8@l$4Z} zm6ev3mY0{8n3$NEnVFiJnwy)OoSdAUot>VZo}ZteprD|kp`oIpqNAguq@<*!rKP5( zrl+T;sHmu^si~@}s;jH3tgNi9t*x%EuCK4Ju&}VPv9YqUva_?Zw6wIfwY9dkwzs#p zxVX5vxw*Q!y1To(yu7@dCU$jHda z$;ryf%FD~k%*@Qq&CSlv&d<-!(9qD)(b3Y<($mw^)YR0~)z#M4*4Nk9*x1lt)=I7_<=;-L_>FMg~>g((4 z?Ck9A?d|UF?(gsK@bK{Q@$vHV^7Hfa^z`)g_4W4l_V@Sq`1ttw`T6?#`uqF){QUg= z{r&#_{{R2~A^8LW006xJEC2ui02lxm06+*p0DB1>NU)&6g9ia9M98qPmNwTELlOrF7q_|RKOO-88f<#HPCc%IJ06WFzox1=4 diff --git a/src/org/apache/fop/viewer/LoadableProperties.java b/src/org/apache/fop/viewer/LoadableProperties.java deleted file mode 100644 index 6e00e00bf..000000000 --- a/src/org/apache/fop/viewer/LoadableProperties.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.viewer; - -import java.io.*; -import org.apache.fop.messaging.MessageHandler; -import java.util.*; - -/** - * Erweitert Hashtable um die Methode load. - * Die Zeilen der Textdatei, die mit # oder ! anfangen sind Kommentarzeilen. - * Eine gültige Zeile ist entweder eine Kommentarzeile oder eine Zeile mit dem - * Gleichheitszeichen "in der Mitte". - * Die Klasse LoadableProperties lässt im Gegensatz zu der Klasse Properties die - * Schlüsselwerte mit Leerzeichen zu. - * - * @version 02.12.99 - * @author Stanislav.Gorkhover@jCatalog.com - * - */ -public class LoadableProperties extends Hashtable { - - public LoadableProperties() { - super(); - } - - - public void load(InputStream inStream) throws IOException { - - BufferedReader in = new BufferedReader(new InputStreamReader(inStream, - "8859_1")); - - String aKey; - String aValue; - int index; - String line = getNextLine(in); - while (line != null) { - line = line.trim(); - if (isValid(line)) { - index = line.indexOf("="); - aKey = line.substring(0, index); - aValue = line.substring(index + 1); - put(aKey, aValue); - } - line = getNextLine(in); - } - } - - - private boolean isValid(String str) { - if (str == null) - return false; - if (str.length() > 0) { - if (str.startsWith("#") || str.startsWith("!")) { - return false; - } - } else { - return false; - } - - int index = str.indexOf("="); - if (index > 0 && str.length() > index) { - return true; - } else { - MessageHandler.logln(getClass().getName() - + ": load(): invalid line " + str + "." - + " Character '=' missed."); - return false; - } - } - - private String getNextLine(BufferedReader br) { - try { - return br.readLine(); - } catch (Exception e) { - return null; - } - - } - - -} diff --git a/src/org/apache/fop/viewer/MessageException.java b/src/org/apache/fop/viewer/MessageException.java deleted file mode 100644 index eb9b25c15..000000000 --- a/src/org/apache/fop/viewer/MessageException.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.viewer; - -import java.lang.Exception; - -/** - * Die Klasse MessageException ist eine Exception, die - * mit einer Meldung und deren Parametern versehen werden kann. - * Dadurch kann die Meldung über den Exception-Mechanismus an die - * Aufrufer hochgereicht werden, bis schliesslich ein Aufrufer die - * Meldung zur Anzeige bringt. - * - * @author Juergen.Verwohlt@jCatalog.com - * @version 1.0 28.05.99 - * - */ -public class MessageException extends Exception { - - /** - * Angabe der auslösenden Exception, wie z.B. NullPointerException. - * Dieses Feld ist optional. - */ - protected Exception exception; - - /** - * ID der Meldung, die für diese Exception ausgegeben werden soll - */ - protected String messageId; - - /** - * Parameterliste zur Meldung - */ - protected String[] parameterList; - - - // Konstruktoren - - public MessageException() { - this("UNKNOWN_EXCEPTION"); - } - - public MessageException(String aMessageId) { - this(aMessageId, null); - } - - public MessageException(String aMessageId, String[] aParameterList) { - this(aMessageId, aParameterList, null); - } - - public MessageException(String aMessageId, String[] aParameterList, - Exception anException) { - super(aMessageId); - messageId = aMessageId; - parameterList = aParameterList; - exception = anException; - } - - // Zugriffsmethoden - - public String getMessageId() { - return messageId; - } - - public String[] getParameterList() { - return parameterList; - } - - public Exception getException() { - return exception; - } - -} diff --git a/src/org/apache/fop/viewer/MessagesDialog.java b/src/org/apache/fop/viewer/MessagesDialog.java deleted file mode 100644 index dafcefbff..000000000 --- a/src/org/apache/fop/viewer/MessagesDialog.java +++ /dev/null @@ -1,265 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.viewer; - -import javax.swing.*; - -import java.beans.*; -import java.io.*; -import java.util.*; -import java.awt.*; -import java.awt.event.*; - - -import org.apache.fop.apps.*; - - -/** - * Die Klasse MessagesDialog dient der Anzeige von Meldungen. - * Die Klasse erweitert JOptionPane um die Möglichkeit, auf Knopfdruck - * eine Detailanzeige einzublenden, in der z.B. bei Fehlern der StackTrace ausgegeben - * werden kann. - * - * @author Juergen.Verwohlt@jCatalog.com - * @version 1.0 09.06.99 - */ -public class MessagesDialog extends JOptionPane { - - static Translator res; - - public static void setTranslator(Translator aRes) { - res = aRes; - iniConstants(); - } - - - static String DETAIL_OPTION; - static String YES_OPTION; - static String NO_OPTION; - static String CANCEL_OPTION; - static String OK_OPTION; - - static String[] defaultDetailOption; - static String[] yesNoDetailOption; - static String[] yesNoCancelDetailOption; - static String[] okCancelDetailOption; - - static String[] defaultOption; - static String[] yesNoOption; - static String[] yesNoCancelOption; - static String[] okCancelOption; - - - - private static void iniConstants() { - DETAIL_OPTION = res.getString("Details"); - YES_OPTION = res.getString("Yes"); - NO_OPTION = res.getString("No"); - CANCEL_OPTION = res.getString("Cancel"); - OK_OPTION = res.getString("Ok"); - - defaultDetailOption = new String[] { - OK_OPTION, DETAIL_OPTION - }; - yesNoDetailOption = new String[] { - YES_OPTION, NO_OPTION, DETAIL_OPTION - }; - yesNoCancelDetailOption = new String[] { - YES_OPTION, NO_OPTION, CANCEL_OPTION, DETAIL_OPTION - }; - okCancelDetailOption = new String[] { - OK_OPTION, CANCEL_OPTION, DETAIL_OPTION - }; - - defaultOption = new String[] { - OK_OPTION - }; - yesNoOption = new String[] { - YES_OPTION, NO_OPTION - }; - yesNoCancelOption = new String[] { - YES_OPTION, NO_OPTION, CANCEL_OPTION - }; - okCancelOption = new String[] { - OK_OPTION, CANCEL_OPTION - }; - } - - - protected String detailInformation = null; - protected JDialog dialog = null; - protected boolean showsDetails = false; - - // MessagesDialog.showConfirmDialog(null,preparedMes,title, - // optionTypeIndex,messageTypeIndex); - - public MessagesDialog(Object message, int messageType, int optionType, - Icon icon, Object[] options, Object initialValue) { - super(message, messageType, optionType, icon, options, initialValue); - setMinimumSize(new Dimension(240, 96)); - } - - public static int showConfirmDialog(Component parentComponent, - Object message, String title, - int optionType, int messageType) { - Object[] options; - - switch (optionType) { - case JOptionPane.YES_NO_OPTION: - options = yesNoOption; - break; - case JOptionPane.YES_NO_CANCEL_OPTION: - options = yesNoCancelOption; - break; - case JOptionPane.OK_CANCEL_OPTION: - options = okCancelOption; - break; - default: - options = defaultOption; - } - - MessagesDialog pane = new MessagesDialog(message, messageType, - JOptionPane.DEFAULT_OPTION, - null, options, options[0]); - - pane.setInitialValue(options[0]); - - JDialog dialog = pane.createDialog(parentComponent, title); - - pane.setDialog(dialog); - pane.selectInitialValue(); - - dialog.show(); - - Object selectedValue = pane.getValue(); - - if (selectedValue == null) - return CLOSED_OPTION; - - if (selectedValue.equals(OK_OPTION)) - return JOptionPane.OK_OPTION; - if (selectedValue.equals(CANCEL_OPTION)) - return JOptionPane.CANCEL_OPTION; - if (selectedValue.equals(YES_OPTION)) - return JOptionPane.YES_OPTION; - if (selectedValue.equals(NO_OPTION)) - return JOptionPane.NO_OPTION; - - return CLOSED_OPTION; - } - - /** - * Öffnet ein Dialogfenster, bei dem zusätzlich zu den spez. Buttons noch ein - * 'Detail'-Button erscheint. Wird dieser Knopf vom Benutzer betätigt, erscheint - * die übergebene Detailinformation in einem scrollbaren Bereich des Dialogs. - */ - public static int showDetailDialog(Component parentComponent, - Object message, String title, - int optionType, int messageType, - Icon icon, - String newDetailInformation) { - Object[] options; - - switch (optionType) { - case JOptionPane.YES_NO_OPTION: - options = yesNoDetailOption; - break; - case JOptionPane.YES_NO_CANCEL_OPTION: - options = yesNoCancelDetailOption; - break; - case JOptionPane.OK_CANCEL_OPTION: - options = okCancelDetailOption; - break; - default: - options = defaultDetailOption; - } - - MessagesDialog pane = new MessagesDialog(message, messageType, - JOptionPane.DEFAULT_OPTION, - icon, options, options[0]); - - pane.setDetailInformation(newDetailInformation); - pane.setInitialValue(options[0]); - - JDialog dialog = pane.createDialog(parentComponent, title); - - pane.setDialog(dialog); - pane.selectInitialValue(); - - dialog.show(); - - Object selectedValue = pane.getValue(); - - if (selectedValue == null) - return CLOSED_OPTION; - - if (((String)selectedValue).equals(DETAIL_OPTION)) - return CLOSED_OPTION; - - if (selectedValue.equals(OK_OPTION)) - return JOptionPane.OK_OPTION; - if (selectedValue.equals(CANCEL_OPTION)) - return JOptionPane.CANCEL_OPTION; - if (selectedValue.equals(YES_OPTION)) - return JOptionPane.YES_OPTION; - if (selectedValue.equals(NO_OPTION)) - return JOptionPane.NO_OPTION; - - return CLOSED_OPTION; - } - - /** - * Die Methode fügt in den übergebenen Dialog eine scrollbare Textkomponente ein, - * in der die Detailinformation angezeigt wird. - * - * @param JDialog dialog Der Dialog, in den die Textkomponente eingefügt werden soll - */ - protected void displayDetails(JDialog dialog) { - if (getDetailInformation() != null && dialog != null - && showsDetails == false) { - showsDetails = true; - JScrollPane aScrollPane = new JScrollPane(); - JTextArea aTextArea = new JTextArea(); - StringWriter aStringWriter = new StringWriter(); - - aTextArea.setText(getDetailInformation()); - aTextArea.setEditable(false); - - aScrollPane.getViewport().add(aTextArea, null); - dialog.getContentPane().add(aScrollPane, BorderLayout.SOUTH); - aScrollPane.setPreferredSize(new Dimension(320, 240)); - dialog.pack(); - } - } - - // Zugriff - - public void setValue(Object aValue) { - if (aValue != null && DETAIL_OPTION.equals(aValue)) - displayDetails(getDialog()); - else - super.setValue(aValue); - } - - public String getDetailInformation() { - return detailInformation; - } - - public void setDetailInformation(String aValue) { - detailInformation = aValue; - } - - public JDialog getDialog() { - return dialog; - } - - public void setDialog(JDialog aValue) { - dialog = aValue; - } - -} diff --git a/src/org/apache/fop/viewer/PreviewDialog.java b/src/org/apache/fop/viewer/PreviewDialog.java deleted file mode 100644 index 29ba72a8f..000000000 --- a/src/org/apache/fop/viewer/PreviewDialog.java +++ /dev/null @@ -1,638 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.viewer; - -/* - * originally contributed by - * Juergen Verwohlt: Juergen.Verwohlt@jCatalog.com, - * Rainer Steinkuhle: Rainer.Steinkuhle@jCatalog.com, - * Stanislav Gorkhover: Stanislav.Gorkhover@jCatalog.com - * Doro Wiarda (wiarda@dwiarda.com: - * added MessageListener support and made - * the showing of the progress and error - * messages Swing thread safe. - * This is needed as xml parse errors do not - * necessarily occur in the - * EventDispatchThread. - */ - -import java.awt.*; -import java.awt.print.*; -import java.awt.event.*; -import java.awt.image.BufferedImage; -import java.util.StringTokenizer; -import java.util.Vector; - -import javax.swing.*; - -import org.apache.fop.layout.*; -import org.apache.fop.render.awt.*; -import org.apache.fop.messaging.*; - -/** - * Frame and User Interface for Preview - */ -public class PreviewDialog extends JFrame implements ProgressListener, - MessageListener { - - protected Translator res; - - protected int currentPage = 0; - protected int pageCount = 0; - - protected AWTRenderer renderer; - - protected IconToolBar toolBar = new IconToolBar(); - - protected Command printAction; - protected Command firstPageAction; - protected Command previousPageAction; - protected Command nextPageAction; - protected Command lastPageAction; - - protected JLabel zoomLabel = - new JLabel(); // {public float getAlignmentY() { return 0.0f; }}; - protected JComboBox scale = new JComboBox() { - public float getAlignmentY() { - return 0.5f; - } - - }; - - protected JScrollPane previewArea = new JScrollPane(); - // protected JLabel statusBar = new JLabel(); - protected JPanel statusBar = new JPanel(); - protected GridBagLayout statusBarLayout = new GridBagLayout(); - - protected JLabel statisticsStatus = new JLabel(); - protected JLabel processStatus = new JLabel(); - protected JLabel infoStatus = new JLabel(); - protected JLabel previewImageLabel = new JLabel(); - - /** - * Create a new PreviewDialog that uses the given renderer and translator. - * - * @param aRenderer the to use renderer - * @param aRes the to use translator - */ - public PreviewDialog(AWTRenderer aRenderer, Translator aRes) { - res = aRes; - renderer = aRenderer; - - printAction = new Command(res.getString("Print"), "Print") { - public void doit() { - print(); - } - - }; - firstPageAction = new Command(res.getString("First page"), - "firstpg") { - public void doit() { - goToFirstPage(null); - } - - }; - previousPageAction = new Command(res.getString("Previous page"), - "prevpg") { - public void doit() { - goToPreviousPage(null); - } - - }; - nextPageAction = new Command(res.getString("Next page"), "nextpg") { - public void doit() { - goToNextPage(null); - } - - }; - lastPageAction = new Command(res.getString("Last page"), "lastpg") { - public void doit() { - goToLastPage(null); - } - - }; - - setDefaultCloseOperation(DISPOSE_ON_CLOSE); - this.setSize(new Dimension(379, 476)); - previewArea.setMinimumSize(new Dimension(50, 50)); - - this.setTitle("FOP: AWT-" + res.getString("Preview")); - - scale.addItem("25"); - scale.addItem("50"); - scale.addItem("75"); - scale.addItem("100"); - scale.addItem("150"); - scale.addItem("200"); - - scale.setMaximumSize(new Dimension(80, 24)); - scale.setPreferredSize(new Dimension(80, 24)); - - scale.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - scale_actionPerformed(e); - } - - }); - - scale.setSelectedItem("100"); - renderer.setScaleFactor(100.0); - - zoomLabel.setText(res.getString("Zoom")); - - this.setJMenuBar(setupMenue()); - - this.getContentPane().add(toolBar, BorderLayout.NORTH); - - toolBar.add(printAction); - toolBar.addSeparator(); - toolBar.add(firstPageAction); - toolBar.add(previousPageAction); - toolBar.add(nextPageAction); - toolBar.add(lastPageAction); - toolBar.addSeparator(); - toolBar.add(zoomLabel, null); - toolBar.addSeparator(); - toolBar.add(scale, null); - - this.getContentPane().add(previewArea, BorderLayout.CENTER); - this.getContentPane().add(statusBar, BorderLayout.SOUTH); - - statisticsStatus.setBorder(BorderFactory.createEtchedBorder()); - processStatus.setBorder(BorderFactory.createEtchedBorder()); - infoStatus.setBorder(BorderFactory.createEtchedBorder()); - - statusBar.setLayout(statusBarLayout); - - processStatus.setPreferredSize(new Dimension(200, 21)); - statisticsStatus.setPreferredSize(new Dimension(100, 21)); - infoStatus.setPreferredSize(new Dimension(100, 21)); - processStatus.setMinimumSize(new Dimension(200, 21)); - statisticsStatus.setMinimumSize(new Dimension(100, 21)); - infoStatus.setMinimumSize(new Dimension(100, 21)); - statusBar.add(processStatus, - new GridBagConstraints(0, 0, 2, 1, 2.0, 0.0, - GridBagConstraints.CENTER, - GridBagConstraints.HORIZONTAL, - new Insets(0, 0, 0, 5), 0, 0)); - statusBar.add(statisticsStatus, - new GridBagConstraints(2, 0, 1, 2, 1.0, 0.0, - GridBagConstraints.CENTER, - GridBagConstraints.HORIZONTAL, - new Insets(0, 0, 0, 5), 0, 0)); - statusBar.add(infoStatus, - new GridBagConstraints(3, 0, 1, 1, 1.0, 0.0, - GridBagConstraints.CENTER, - GridBagConstraints.HORIZONTAL, - new Insets(0, 0, 0, 0), 0, 0)); - - previewArea.getViewport().add(previewImageLabel); - showPage(); - } - - /** - * Create a new menubar to be shown in this window. - * - * @return the newly created menubar - */ - private JMenuBar setupMenue() { - JMenuBar menuBar; - JMenuItem menuItem; - JMenu menu; - JMenu subMenu; - - menuBar = new JMenuBar(); - menu = new JMenu(res.getString("File")); - subMenu = new JMenu("OutputFormat"); - subMenu.add(new Command("mHTML")); - subMenu.add(new Command("mPDF")); - subMenu.add(new Command("mRTF")); - subMenu.add(new Command("mTEXT")); - // menu.add(subMenu); - // menu.addSeparator(); - menu.add(new Command(res.getString("Print")) { - public void doit() { - print(); - } - - }); - menu.addSeparator(); - menu.add(new Command(res.getString("Exit")) { - public void doit() { - dispose(); - } - - }); - menuBar.add(menu); - menu = new JMenu(res.getString("View")); - menu.add(new Command(res.getString("First page")) { - public void doit() { - goToFirstPage(null); - } - - }); - menu.add(new Command(res.getString("Previous page")) { - public void doit() { - goToPreviousPage(null); - } - - }); - menu.add(new Command(res.getString("Next page")) { - public void doit() { - goToNextPage(null); - } - - }); - menu.add(new Command(res.getString("Last page")) { - public void doit() { - goToLastPage(null); - } - - }); - menu.add(new Command(res.getString("Go to Page") + " ...") { - public void doit() { - goToPage(null); - } - - }); - menu.addSeparator(); - subMenu = new JMenu(res.getString("Zoom")); - subMenu.add(new Command("25%") { - public void doit() { - setScale(25.0); - } - - }); - subMenu.add(new Command("50%") { - public void doit() { - setScale(50.0); - } - - }); - subMenu.add(new Command("75%") { - public void doit() { - setScale(75.0); - } - - }); - subMenu.add(new Command("100%") { - public void doit() { - setScale(100.0); - } - - }); - subMenu.add(new Command("150%") { - public void doit() { - setScale(150.0); - } - - }); - subMenu.add(new Command("200%") { - public void doit() { - setScale(200.0); - } - - }); - menu.add(subMenu); - menu.addSeparator(); - menu.add(new Command(res.getString("Default zoom")) { - public void doit() { - setScale(100.0); - } - - }); - menuBar.add(menu); - menu = new JMenu(res.getString("Help")); - menu.add(new Command(res.getString("Index"))); - menu.addSeparator(); - menu.add(new Command(res.getString("Introduction"))); - menu.addSeparator(); - menu.add(new Command(res.getString("About")) { - public void doit() { - startHelpAbout(null); - } - - }); - menuBar.add(menu); - return menuBar; - } - - // Aktion Hilfe | Info durchgeführt - - /** - * Show the About box - * - * @param e a value of type 'ActionEvent' - */ - public void startHelpAbout(ActionEvent e) { - PreviewDialogAboutBox dlg = new PreviewDialogAboutBox(this); - Dimension dlgSize = dlg.getPreferredSize(); - Dimension frmSize = getSize(); - Point loc = getLocation(); - dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, - (frmSize.height - dlgSize.height) / 2 + loc.y); - dlg.setModal(true); - dlg.show(); - } - - /** - * Change the current visible page - * - * @param number the page number to go to - */ - private void goToPage(int number) { - currentPage = number; - renderer.setPageNumber(number); - showPage(); - } - - /** - * Shows the previous page. - */ - private void goToPreviousPage(ActionEvent e) { - if (currentPage <= 0) - return; - currentPage--; - goToPage(currentPage); - } - - - /** - * Shows the next page. - */ - private void goToNextPage(ActionEvent e) { - if (currentPage >= pageCount - 1) - return; - currentPage++; - goToPage(currentPage); - } - - /** - * Shows the last page. - */ - private void goToLastPage(ActionEvent e) { - - if (currentPage == pageCount - 1) - return; - currentPage = pageCount - 1; - - goToPage(currentPage); - } - - /** - * Shows a page by number. - */ - private void goToPage(ActionEvent e) { - - GoToPageDialog d = new GoToPageDialog(this, - res.getString("Go to Page"), - true); - d.setLocation((int)getLocation().getX() + 50, - (int)getLocation().getY() + 50); - d.show(); - currentPage = d.getPageNumber(); - - if (currentPage < 1 || currentPage > pageCount) - return; - - currentPage--; - - goToPage(currentPage); - } - - /** - * Shows the first page. - */ - private void goToFirstPage(ActionEvent e) { - if (currentPage == 0) - return; - currentPage = 0; - goToPage(currentPage); - } - - private void print() { - PrinterJob pj = PrinterJob.getPrinterJob(); - // Nicht nötig, Pageable get a Printable. - // pj.setPrintable(renderer); - pj.setPageable(renderer); - - if (pj.printDialog()) { - try { - pj.print(); - } catch (PrinterException pe) { - pe.printStackTrace(); - } - } - } - - public void setScale(double scaleFactor) { - - if (scaleFactor == 25.0) - scale.setSelectedIndex(0); - else if (scaleFactor == 50.0) - scale.setSelectedIndex(1); - else if (scaleFactor == 75.0) - scale.setSelectedIndex(2); - else if (scaleFactor == 100.0) - scale.setSelectedIndex(3); - else if (scaleFactor == 150.0) - scale.setSelectedIndex(4); - else if (scaleFactor == 200.0) - scale.setSelectedIndex(5); - - renderer.setScaleFactor(scaleFactor); - showPage(); - } - - void scale_actionPerformed(ActionEvent e) { - setScale(new Double((String)scale.getSelectedItem()).doubleValue()); - } - - public void progress(int percentage) { - progress(new String(percentage + "%")); - } - - public void progress(int percentage, String message) { - progress(new String(message + " " + percentage + "%")); - } - - - /** - * Setting the text of a JLabel is not thread save, it - * needs to be done in the EventThread. Here we make sure - * it is done. - */ - public void progress(String message) { - SwingUtilities.invokeLater(new showProgress(message, false)); - } - - - /** - * This class is used to show status and error messages in - * a thread safe way. - */ - class showProgress implements Runnable { - - /** - * The message to display - */ - Object message; - - /** - * Is this an errorMessage, i.e. should it be shown in - * an JOptionPane or in the status bar. - */ - boolean isErrorMessage = false; - - /** - * Constructs showProgress thread - * @param message message to display - * @param isErrorMessage show in status bar or in JOptionPane - */ - public showProgress(Object message, boolean isErrorMessage) { - this.message = message; - this.isErrorMessage = isErrorMessage; - } - - public void run() { - if (isErrorMessage) { - JOptionPane.showMessageDialog(null, message, "Error", - JOptionPane.ERROR_MESSAGE); - } else - processStatus.setText(message.toString()); - } - - } - - public void showPage() { - showPageImage viewer = new showPageImage(); - - if (SwingUtilities.isEventDispatchThread()) { - viewer.run(); - } else - SwingUtilities.invokeLater(viewer); - } - - - /** - * This class is used to update the page image - * in a thread safe way. - */ - class showPageImage implements Runnable { - - /** - * The run method that does the actuall updating - */ - public void run() { - BufferedImage pageImage = null; - Graphics graphics = null; - - renderer.render(currentPage); - pageImage = renderer.getLastRenderedPage(); - if (pageImage == null) - return; - graphics = pageImage.getGraphics(); - graphics.setColor(Color.black); - graphics.drawRect(0, 0, pageImage.getWidth() - 1, - pageImage.getHeight() - 1); - - previewImageLabel.setIcon(new ImageIcon(pageImage)); - - pageCount = renderer.getPageCount(); - - statisticsStatus.setText(res.getString("Page") + " " - + (currentPage + 1) + " " - + res.getString("of") + " " + pageCount); - } - - } - - - /** - * Called by MessageHandler if an error message or a - * log message is received. - */ - public void processMessage(MessageEvent event) { - String error = event.getMessage(); - String text = processStatus.getText(); - FontMetrics fmt = - processStatus.getFontMetrics(processStatus.getFont()); - int width = processStatus.getWidth() - fmt.stringWidth("..."); - showProgress showIt; - - if (event.getMessageType() == event.LOG) { - if (!text.endsWith("\n")) { - text = text + error; - while (fmt.stringWidth(text) > width) { - text = text.substring(1); - width = processStatus.getWidth() - fmt.stringWidth("..."); - } - } else - text = error; - progress(text); - } else { - error = error.trim(); - if (error.equals(">")) { - text = text + error; - while (fmt.stringWidth(text) > width) { - text = text.substring(1); - width = processStatus.getWidth() - fmt.stringWidth("..."); - } - progress(processStatus.getText() + error); - return; - } - if (error.equals("")) - return; - if (error.length() < 60) { - showIt = new showProgress(error, true); - } else { - StringTokenizer tok = new StringTokenizer(error, " "); - Vector labels = new Vector(); - StringBuffer buffer = new StringBuffer(); - String tmp, list[]; - - while (tok.hasMoreTokens()) { - tmp = tok.nextToken(); - if ((buffer.length() + tmp.length() + 1) < 60) { - buffer.append(" ").append(tmp); - } else { - labels.add(buffer.toString()); - buffer = new StringBuffer(); - buffer.append(tmp); - } - } - labels.add(buffer.toString()); - list = new String[labels.size()]; - for (int i = 0; i < labels.size(); i++) { - list[i] = labels.elementAt(i).toString(); - } - showIt = new showProgress(list, true); - } - if (SwingUtilities.isEventDispatchThread()) { - showIt.run(); - } else { - try { - SwingUtilities.invokeAndWait(showIt); - } catch (Exception e) { - e.printStackTrace(); - progress(event.getMessage()); - } - } - } - } - - - public void dispose() { - System.exit(0); - } - -} // class PreviewDialog - - - - diff --git a/src/org/apache/fop/viewer/PreviewDialogAboutBox.java b/src/org/apache/fop/viewer/PreviewDialogAboutBox.java deleted file mode 100644 index decee0666..000000000 --- a/src/org/apache/fop/viewer/PreviewDialogAboutBox.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.viewer; - -/* - * originally contributed by - * Juergen Verwohlt: Juergen.Verwohlt@jCatalog.com, - * Rainer Steinkuhle: Rainer.Steinkuhle@jCatalog.com, - * Stanislav Gorkhover: Stanislav.Gorkhover@jCatalog.com - */ - - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.border.*; - -import org.apache.fop.apps.Version; - - - -public class PreviewDialogAboutBox extends Dialog implements ActionListener { - - JPanel panel1 = new JPanel(); - JPanel panel2 = new JPanel(); - JPanel insetsPanel1 = new JPanel(); - JPanel insetsPanel2 = new JPanel(); - JPanel insetsPanel3 = new JPanel(); - JButton button1 = new JButton(); - JLabel imageControl1 = new JLabel(); - ImageIcon imageIcon; - JLabel label1 = new JLabel(); - JLabel label2 = new JLabel(); - JLabel label3 = new JLabel(); - JLabel label4 = new JLabel(); - BorderLayout borderLayout1 = new BorderLayout(); - BorderLayout borderLayout2 = new BorderLayout(); - FlowLayout flowLayout1 = new FlowLayout(); - FlowLayout flowLayout2 = new FlowLayout(); - GridLayout gridLayout1 = new GridLayout(); - String product = "FOP AWT-Preview"; - String version = "Version: " + Version.getVersion(); - String copyright = "See xml.apache.org"; - String comments = ""; // "Print Preview"; - - public PreviewDialogAboutBox(Frame parent) { - super(parent); - enableEvents(AWTEvent.WINDOW_EVENT_MASK); - - // imageIcon = new ImageIcon(getClass().getResource("Hier der Grafikname")); - this.setTitle("Info"); - setResizable(false); - panel1.setLayout(borderLayout1); - panel2.setLayout(borderLayout2); - insetsPanel1.setLayout(flowLayout1); - insetsPanel2.setLayout(flowLayout1); - insetsPanel2.setBorder(new EmptyBorder(10, 10, 10, 10)); - gridLayout1.setRows(4); - gridLayout1.setColumns(1); - label1.setText(product); - label2.setText(version); - label3.setText(copyright); - label4.setText(comments); - insetsPanel3.setLayout(gridLayout1); - insetsPanel3.setBorder(new EmptyBorder(10, 60, 10, 10)); - button1.setText("OK"); - button1.addActionListener(this); - insetsPanel2.add(imageControl1, null); - panel2.add(insetsPanel2, BorderLayout.WEST); - this.add(panel1, null); - insetsPanel3.add(label1, null); - insetsPanel3.add(label2, null); - insetsPanel3.add(label3, null); - insetsPanel3.add(label4, null); - panel2.add(insetsPanel3, BorderLayout.CENTER); - insetsPanel1.add(button1, null); - panel1.add(insetsPanel1, BorderLayout.SOUTH); - panel1.add(panel2, BorderLayout.NORTH); - pack(); - } - - protected void processWindowEvent(WindowEvent e) { - if (e.getID() == WindowEvent.WINDOW_CLOSING) { - cancel(); - } - super.processWindowEvent(e); - } - - void cancel() { - dispose(); - } - - public void actionPerformed(ActionEvent e) { - if (e.getSource() == button1) { - cancel(); - } - } - -} - diff --git a/src/org/apache/fop/viewer/ProgressListener.java b/src/org/apache/fop/viewer/ProgressListener.java deleted file mode 100644 index b72fb7437..000000000 --- a/src/org/apache/fop/viewer/ProgressListener.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.viewer; - -/* - * originally contributed by - * Juergen Verwohlt: Juergen.Verwohlt@jCatalog.com, - * Rainer Steinkuhle: Rainer.Steinkuhle@jCatalog.com, - * Stanislav Gorkhover: Stanislav.Gorkhover@jCatalog.com - */ - - -public interface ProgressListener { - public void progress(int percentage); - public void progress(String message); - public void progress(int percentage, String message); -} - diff --git a/src/org/apache/fop/viewer/SecureResourceBundle.java b/src/org/apache/fop/viewer/SecureResourceBundle.java deleted file mode 100644 index 6ed849ea9..000000000 --- a/src/org/apache/fop/viewer/SecureResourceBundle.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.viewer; - -import java.util.*; -import org.apache.fop.messaging.MessageHandler; -import java.io.*; - - -/** - * Die Klasse SecureResourceBundle ist ein Resourceundle, das im Falle eines fehlenden - * Eintrages keinen Absturz verursacht, sondern die Meldung - * Key key not found zurückgibt. - * @see PropertyResourceBundle - * - * @author Stanislav.Gorkhover@jCatalog.com - * @version 1.0 18.03.1999 - */ -public class SecureResourceBundle extends ResourceBundle - implements Translator { - - // Fehlende keys mit einer Meldung zurückgeben. - private boolean isMissingEmphasized = false; - - // private Properties lookup = new Properties(); - private LoadableProperties lookup = new LoadableProperties(); - - private boolean isSourceFound = true; - - public void setMissingEmphasized(boolean flag) { - isMissingEmphasized = flag; - } - - /** - * Kreiert ein ResourceBundle mit der Quelle in in. - */ - - public SecureResourceBundle(InputStream in) { - try { - lookup.load(in); - } catch (Exception ex) { - MessageHandler.logln("Abgefangene Exception: " + ex.getMessage()); - isSourceFound = false; - } - } - - - - public Enumeration getKeys() { - return lookup.keys(); - } - - - - /** - * Händelt den abgefragten Key, liefert entweder den zugehörigen Wert oder eine Meldung. - * Die null wird nie zurückgegeben. - * Schreibt die fehlenden Suchschlüssel in die Protokoll-Datei. - * @return Object
    - *
  • den zu dem Suchschlüssel key gefundenen Wert, falls vorhanden,
    - *
  • Meldung Key key not found, falls der Suchschlüssel fehlt - * und die Eigenschaft "jCatalog.DevelopmentStartModus" in der ini-Datei aus true gesetzt ist. - *
  • Meldung Key is null, falls der Suchschlüssel null ist. - *
- * - */ - public Object handleGetObject(String key) { - - if (key == null) - return "Key is null"; - - Object obj = lookup.get(key); - if (obj != null) - return obj; - else { - if (isMissingEmphasized) { - MessageHandler.logln(getClass().getName() + ": missing key: " - + key); - return getMissedRepresentation(key.toString()); - } else - return key.toString(); - } - } - - /** - * Stellt fest, ob es den Key gibt. - */ - public boolean contains(String key) { - return (key == null || lookup.get(key) == null) ? false : true; - } - - - private String getMissedRepresentation(String str) { - return ""; - } - - public boolean isSourceFound() { - return isSourceFound; - } - -} diff --git a/src/org/apache/fop/viewer/Translator.java b/src/org/apache/fop/viewer/Translator.java deleted file mode 100644 index 26e2cbaf7..000000000 --- a/src/org/apache/fop/viewer/Translator.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.viewer; - - -/** - * Definition für die Übersetzer-Klassen. - * - * @version 03.12.99 - * @author Stanislav.Gorkhover@jCatalog.com - * - */ -public interface Translator { - - /** - * Übersetzt ein Wort. - */ - public String getString(String key); - - /** - * Ein Translator soll die fehlenden keys hervorheben können. - */ - public void setMissingEmphasized(boolean b); - - /** - * Gibt an ob die Übersetzungsquelle gefunden ist. - */ - public boolean isSourceFound(); - - /** - * Gibt an ob ein Key in der Übersetzungsquelle vorhanden ist. - */ - public boolean contains(String key); -} diff --git a/src/org/apache/fop/viewer/UserMessage.java b/src/org/apache/fop/viewer/UserMessage.java deleted file mode 100644 index ceb1ce0f9..000000000 --- a/src/org/apache/fop/viewer/UserMessage.java +++ /dev/null @@ -1,429 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.viewer; - -import java.awt.*; -import org.apache.fop.messaging.MessageHandler; -import java.io.*; -import java.awt.event.*; -import java.util.*; -import javax.swing.*; -import javax.swing.JComponent.*; - - - -/** - * Klasse UserMessage ist ein utility zum Abfragen oder zum Informieren des Benutzers.
- * Eine Meldung besteht aus dem Identifikator (Suchschlüssel im Meldungspool), einem Dialogtitel, einem Buttonset und - * dem Meldungstext mit eventuellen Platzhaltern für die Parameter. - * - * @author S. Gorkhover - * @version 18.03.1999 - * - * @changed 23.04.99 Juergen.Verwohlt@jCatalog.com - * @subject Weitere Ausgabemethoden: show(String, String) und show(String,String,Frame) - * - * @changed 28.05.99 Juergen.Verwohlt@jCatalog.com - * @subject MessageException unterstützen - * - * @changed 09.06.99 Juergen.Verwohlt@jCatalog.com - * @subject Neue Klasse MessagesException zur Anzeige verwenden - * - * @changed 10.12.00 gears@apache.org - * @subject Unicode - */ -public class UserMessage { - - private static Translator res = null; - - public static void setTranslator(Translator aRes) { - res = aRes; - if (res == null) { - MessageHandler.logln("UserMessage: setTranslator(null) !"); - res = new SecureResourceBundle(null); - } - - MessagesDialog.setTranslator(res); - } - - - // Zulässige Werte für Dialogart: - - /** - * Möglicher Wert des Meldungstypes. Fenster-Title "Info" (de). - */ - private static final int INFO = JOptionPane.PLAIN_MESSAGE; - - /** - * Möglicher Wert des Meldungstypes. Fenster-Title "Warnung" (de). - */ - private static final int WARNING = JOptionPane.WARNING_MESSAGE; - - /** - * Möglicher Wert des Meldungstypes. Fenster-Title "Frage" (de). - */ - private static final int QUESTION = JOptionPane.QUESTION_MESSAGE; - - /** - * Möglicher Wert des Meldungstypes. Fenster-Title "Fehler" (de). - */ - private static final int ERROR = JOptionPane.ERROR_MESSAGE; - - /** - * Möglicher Wert des Meldungstypes. Fenster-Title "Systemfehler" (de). - */ - private static final int SYS_ERROR = JOptionPane.ERROR_MESSAGE; - - - - /* - * Style Constanten orientieren sich auf die - * Constanten der ButtonDialog-Klasse und legen das Dialog-ButtonSet fest. - */ - - /** - * Wert für Setzten keines Buttons - */ - public static final int STYLE_NOBUTTON = -2; - - /** - * Wert für Setzten von nur Ja-Button. - */ - public static final int STYLE_Y = JOptionPane.DEFAULT_OPTION; - // ButtonDialog.YES; // = 1 - - /** - * Wert für Setzten von Ja- und Nein-Buttons. - */ - public static final int STYLE_Y_N = JOptionPane.YES_NO_OPTION; - // ButtonDialog.YES_NO; // = 2; - - /** - * Wert für Setzten von Ja-, Nein-und Abbruch Buttons. - */ - public static final int STYLE_Y_N_C = JOptionPane.YES_NO_CANCEL_OPTION; - // ButtonDialog.YES_NO_CANCEL; // = 3; - - - // Platzhalter für Parameter in der Properties-Datei - private static final String PARAMETER_TAG = "&&&"; - - - /** - * Benutzer-Antwort-Constanten orientieren sich auf die - * Constanten der ButtonDialog-Klasse - */ - - /** - * Möglicher Rückgabewert @see ButtonDialog - */ - public static final int YES = JOptionPane.YES_OPTION; - // ButtonDialog.YES; // = 2 - - /** - * Möglicher Rückgabewert @see ButtonDialog - */ - public static final int NO = JOptionPane.NO_OPTION; - // ButtonDialog.NO; // = 4; - - /** - * Möglicher Rückgabewert @see ButtonDialog - */ - public static final int CANCEL = JOptionPane.CANCEL_OPTION; - // ButtonDialog.CANCEL; // = 8; - - - // Default-Values - private static int buttonType = STYLE_Y; - private static int iconType = WARNING; - private static String currentIconName = ""; - private static String actMessId = null; - // private static MessagesDialog nobuttonDialog = null; - - - /** - * Ersetzt die eventuellen Platzhalter durch die übergebenen Parameter - */ - static String prepareMessage(String rawText, String[] par) { - MessageHandler.logln("prepareMessage(): " + rawText + ", parameter: " - + par); - int index = rawText.indexOf(PARAMETER_TAG); - String composedMess = ""; - if ((index == -1) && (par == null)) - return rawText; - if ((index != -1) && (par == null)) { - MessageHandler.logln("Message " + actMessId - + " erwartet Parameter. Aufgerufen ohne Parameter"); - return rawText; - } - if ((index == -1) && (par != null)) { - MessageHandler.logln("Message " + actMessId - + " erwartet keine Parameter. Aufgerufen mit folgenden Parametern:"); - for (int i = 0; i < par.length; ++i) - MessageHandler.logln(par[i].toString()); - return rawText; - } - int tagCount = 0; - while (rawText.indexOf(PARAMETER_TAG) != -1) { - index = rawText.indexOf(PARAMETER_TAG); - try { - composedMess += rawText.substring(0, index) + par[tagCount]; - } catch (ArrayIndexOutOfBoundsException ex) { - MessageHandler.logln("Anzahl der übergebenen Parameter zu der Meldung " - + actMessId - + " ist weniger als erwartet."); - ex.printStackTrace(); - return composedMess + rawText; - } - rawText = rawText.substring(index + PARAMETER_TAG.length()); - tagCount++; - } - composedMess += rawText; - if (tagCount != par.length) - MessageHandler.logln("Die zu der Meldung " + actMessId - + " übergebenen Parameter sind mehr als die Meldung vorsieht."); - return composedMess; - } - - /** - * Gibt den Title fürs Dialogfenster. - * Dieser wird durch die Dialogart festgelegt - * (erster Teil in der MeldungsDefinition in der Properties-Datei). - */ - static String getTitle(String strVal) { - String title = null; - int choice = getValue(strVal); - switch (choice) { - case INFO: - title = "Info"; - currentIconName = "info.gif"; - break; - case WARNING: - title = "Warning"; - currentIconName = "warn.gif"; - break; - case QUESTION: - title = "Question"; - currentIconName = "quest.gif"; - break; - case ERROR: - title = "Error"; - currentIconName = "error.gif"; - break; - default: - title = - "Ungültiger IonType für diese Meldung. Prüfen in Übersetzungsdatei."; - } - return title; - } - - /** - * Liefert den Wert der über den Nemen übergebenen Klassenvariablen. - */ - static int getValue(String fieldName) { - - int val = -1; - if (fieldName.equals("INFO")) - return INFO; - else if (fieldName.equals("WARNING")) - return WARNING; - else if (fieldName.equals("ERROR")) - return ERROR; - else if (fieldName.equals("SYS_ERROR")) - return SYS_ERROR; - else if (fieldName.equals("QUESTION")) - return QUESTION; - else if (fieldName.equals("STYLE_NOBUTTON")) - return STYLE_NOBUTTON; - else if (fieldName.equals("STYLE_Y")) - return STYLE_Y; - else if (fieldName.equals("STYLE_Y_N")) - return STYLE_Y_N; - else if (fieldName.equals("STYLE_Y_N_C")) - return STYLE_Y_N_C; - return val; - } - - private static String getStackTrace(Exception exception) { - - if (exception == null) - return "null"; - - String stack = ""; - - StringWriter strWriter = new StringWriter(); - exception.printStackTrace(new PrintWriter(strWriter)); - stack = strWriter.toString(); - stack = stack.replace('\r', ' '); - stack = stack.replace('\t', ' '); - return stack; - } - - private static int display(String textID, String[] param, - Exception exception, Frame frame) { - - String translatedMes = ""; - String preparedMes = ""; - String messageType = ""; - String optionType = ""; - String title = ""; - MessagesDialog dialog = null; - actMessId = textID; - - boolean messageFound = res.contains(textID); - translatedMes = res.getString(textID); - - if (messageFound) { - try { - messageType = - translatedMes.substring(0, translatedMes.indexOf(':')); - translatedMes = - translatedMes.substring(translatedMes.indexOf(':') + 1); - - optionType = - translatedMes.substring(0, translatedMes.indexOf(':')); - translatedMes = - translatedMes.substring(translatedMes.indexOf(':') + 1); - - } catch (Exception ex) { - MessageHandler.logln("FALSCHES FORMAT: MESSAGE: " + textID); - } - } else { // Message not found - MessageHandler.logln("UserMessage: textID '" + textID - + "' not found. Return " - + "value 'CANCEL' = " + CANCEL); - - // return CANCEL; - - messageType = "ERROR"; - optionType = "STYLE_Y"; - translatedMes = "textID '" + textID + "' not found." - + "\nIt is possible the message file not found."; - } - - preparedMes = prepareMessage(translatedMes, param); - // Exception exception = getException(param); - - // WARNING -> nach Warnung übersetzen - title = res.getString(getTitle(messageType)); - - // WARNING -> JOptionPane.WARNING_MESSAGE - int messageTypeIndex = getValue(messageType); - - // Button Set idetifizieren - int optionTypeIndex = getValue(optionType); - - int result = CANCEL; - - if (exception != null) { - String str = getStackTrace(exception); - if (exception instanceof MessageException) { - MessageException ex = (MessageException)exception; - if (ex.getException() != null) - str += "\n" + getStackTrace(ex.getException()); - } - result = MessagesDialog.showDetailDialog(null, preparedMes, - title, optionTypeIndex, - messageTypeIndex, null, - str); - } else { - if (optionTypeIndex == STYLE_NOBUTTON) { - // Wird nicht mehr unterstützt - MessageHandler.logln("UserMessage: STYLE_NOBUTTON wird nicht unterstützt"); - return result; - } else { - result = MessagesDialog.showConfirmDialog(null, preparedMes, - title, - optionTypeIndex, - messageTypeIndex); - } - } - return result; - } - - /** - * Öffnet das Dialogfenster mit der Übersetzung der per Suchschlüssel übergebenen Meldung - * mit eingesetzten Parametern. Für die Übersetzung der Parameter trägt die aufrufende Stelle die Sorge. - * Der Dialog ist modal zum Frame frame. - * @param
    - *
  • textID - Suchschlüssel der Meldung im Meldungspool, - *
  • param - Array der in die Meldung einzusetztenden Parameter, - *
  • frame - das Fenster, zu dem der Dialog modal ist. - *
- * @return
    - *
  • -1 wenn keine Rückgabe möglich ist oder Dialog NICHT MODAL ist. - *
  • ButtonDialog.YES = 2 - *
  • ButtonDialog.NO = 4 - *
  • ButtonDialog.CANCEL = 8 - *
  • Wird das Dialog-Fenster ohne Buttonklick geschlossen (Kreuzchen oben rechts), so ist die Rückgabe gleich ButtonDialog.CANCEL. - *
- */ - public static int show(String messageId, String[] parameterList, - Exception anException, Frame parentFrame) { - return display(messageId, parameterList, anException, parentFrame); - } - - public static int show(String messageId, String[] parameterList, - Exception anException) { - return display(messageId, parameterList, anException, (Frame)null); - } - - public static int show(String messageId, String[] parameterList, - Frame parentFrame) { - return display(messageId, parameterList, (Exception)null, - parentFrame); - } - - public static int show(String messageId, String[] parameterList) { - return display(messageId, parameterList, (Exception)null, - (Frame)null); - } - - public static int show(String messageId, String parameter, - Frame parentFrame) { - return display(messageId, new String[] { - parameter - }, (Exception)null, parentFrame); - } - - public static int show(String messageId, String parameter) { - return display(messageId, new String[] { - parameter - }, (Exception)null, (Frame)null); - } - - public static int show(String messageId, Frame parentFrame) { - return display(messageId, (String[])null, (Exception)null, - parentFrame); - } - - public static int show(String messageId) { - return display(messageId, (String[])null, (Exception)null, - (Frame)null); - } - - public static int show(String messageId, Exception anException, - Frame aFrame) { - return display(messageId, (String[])null, anException, aFrame); - } - - public static int show(String messageId, Exception anException) { - return display(messageId, (String[])null, anException, (Frame)null); - } - - public static int show(Exception anException, Frame aFrame) { - if (anException instanceof MessageException) { - MessageException ex = (MessageException)anException; - return show(ex.getMessageId(), ex.getParameterList(), ex, aFrame); - } else - return show("UNHANDLED_EXCEPTION", (String[])null, anException, - aFrame); - } - -} - diff --git a/src/org/apache/fop/viewer/resources/messages.de b/src/org/apache/fop/viewer/resources/messages.de deleted file mode 100644 index 8db0001a8..000000000 --- a/src/org/apache/fop/viewer/resources/messages.de +++ /dev/null @@ -1,78 +0,0 @@ -############################################################################### -# -# In dieser Datei werden im Abschnitt "Messages" Meldungen auf deutsch -# definiert. -# Zu beachten: Beim Definieren einer neuen neuen Meldung, diese soweit möglich -# in allen Sprachen anlegen. -# -# -# -# MELDUNG DEFINIEREN -# ================== -# -# Eine Meldung hat eine eindeutige textuelle ID. Diese steht links vom Gleichheitszeichen. -# Zu jeder Meldung wird angegeben: -# - iconType (Typen siehe unten) -# - buttonType (Typen siehe unten) -# - Meldungstext mit evtl. Platzhaltern für Parameter. -# -# Ein Parameterplatzhalter ist ein dreifaches kaumänisches "und". Siehe Beispielmeldung -# "No_Records_found". -# -# Die Angaben erfolgen in einer Zeile, jeweils durch einen Doppelpunkt getrennt. -# -# Format: -# =:: -# -# Zulässige Werte für: -# iconType: -# INFO -# WARNING -# ERROR -# QUESTION -# -# buttonType: -# STYLE_Y ("yes" Button) -# STYLE_Y_N ("yes" and "no" Buttons) -# STYLE_Y_N_C ("yes", "no" and "cancel" Buttons) -# -# -# Beispiel mit einem String-Array: -# ================================ -# Messagedefinition: -# No_Records_found=WARNING:STYLE_Y:Die Tabelle &&& enthält keinen Eintrag. Erwartet mind. &&&. Weitermachen? -# Aufruf: -# answer = UserMessage.show("No_Records_found", new String[] {"Mitarbeiter", "" + minNumber}, aShowFrame); -# if (answer == UserMessage.NO) -# return; -# -# Beispiel mit einer Exception: -# ============================= -# Messagedefinition: -# UNEXPECTED_EXCEPTION=ERROR:STYLE_Y:Wow! An exception! -# -# Aufruf: -# try { -# String str = null; -# int index = str.indexOf("abc"); -# } catch (Exception ex) { -# UserMessage.show("UNEXPECTED_EXCEPTION", ex); -# } -# -# -# -# -################################################################################################# - - -# Titles -Info=Info -Warning=Warnung -Question=Frage -Error=Fehler - -# Messages -TRANSLATION_SOURCE_NOT_FOUND=WARNING:STYLE_Y:Die Übersetzungsdatei &&& ist nicht gefunden. -UNKNOWN_EXCEPTION=ERROR:STYLE_Y:Unbekannter Fehler -UNHANDLED_EXCEPTION=ERROR:STYLE_Y:Interner Fehler - diff --git a/src/org/apache/fop/viewer/resources/messages.en b/src/org/apache/fop/viewer/resources/messages.en deleted file mode 100644 index 7e8953845..000000000 --- a/src/org/apache/fop/viewer/resources/messages.en +++ /dev/null @@ -1,80 +0,0 @@ -############################################################################### -# -# This file contains the english messages. -# -# NOTICE: When defining a new message it has to be created in message files for each language. -# -# -# -# -# DEFINING A MESSAGE -# ================== -# -# A message has a uinique CHARACTER ID. It is placed on the left hand side of the equation. -# For each message there are additional switches: -# - iconType (see below) -# - buttonType (see below) -# - messageText may contain placeholders for parameters. - -# A placeholder pattern is a "&&&" . See Examplemessage "No_Records_found". -# -# A messsage definition is placed within a single row, its switches are seperated by a colon ":". -# -# Format: -# ======= -# =:: -# -# -# Allowed values for: -# =================== -# iconType: -# INFO -# WARNING -# ERROR -# QUESTION -# -# buttonType: -# STYLE_Y ("yes" Button) -# STYLE_Y_N ("yes" and "no" Buttons) -# STYLE_Y_N_C ("yes", "no" and "cancel" Buttons) -# -# -# Example with a parameter array: -# ================================ -# Message definition: -# No_Records_found=WARNING:STYLE_Y:The Table &&& has no records. Expected at least &&&. Continue? -# Aufruf: -# answer = UserMessage.show("No_Records_found", new String[] {"Employee", "" + minNumber}, aShowFrame); -# if (answer == UserMessage.NO) -# return; -# -# Example with an Exception: -# ============================= -# Message definition: -# UNEXPECTED_EXCEPTION=ERROR:STYLE_Y:Wow! An exception! -# -# Aufruf: -# try { -# String str = null; -# int index = str.indexOf("abc"); -# } catch (Exception ex) { -# UserMessage.show("UNEXPECTED_EXCEPTION", ex); -# } -# -# -# -# -################################################################################################# - - -# Titles -Info=Info -Warning=Warning -Question=Question -Error=Error - -# Messages -TRANSLATION_SOURCE_NOT_FOUND=WARNING:STYLE_Y:The translation file &&& is not found. -UNKNOWN_EXCEPTION=ERROR:STYLE_Y:Unknown error. -UNHANDLED_EXCEPTION=ERROR:STYLE_Y:Internal error. - diff --git a/src/org/apache/fop/viewer/resources/resources.de b/src/org/apache/fop/viewer/resources/resources.de deleted file mode 100644 index 400a326ba..000000000 --- a/src/org/apache/fop/viewer/resources/resources.de +++ /dev/null @@ -1,45 +0,0 @@ -File=Datei - -Exit=Beenden - -View=Anzeige - -Previous page=Vorherige Seite - -Next page=Nächste Seite - -Last page=Letzte Seite - -Help=Hilfe - -Default zoom=Standardzoom - -Introduction=Einleitung - -About=Über - -Show=Anzeigen - -Preview=Vorschau - -First page=Erste Seite - -Print=Drucken - -Page=Seite - -of=von - -Init parser=Initializiere Parser - -Init mappings=Initializiere Abbildung - -Build FO tree=Baue FO-Baum - -Layout FO tree=Formatiere FO-Baum - -Render=Gebe aus - -Close=Schließen - -Go to Page=Gehe zur Seite diff --git a/src/org/apache/fop/viewer/resources/resources.en b/src/org/apache/fop/viewer/resources/resources.en deleted file mode 100644 index acf0ef669..000000000 --- a/src/org/apache/fop/viewer/resources/resources.en +++ /dev/null @@ -1,4 +0,0 @@ -# Diese Datei ist nur dafür da, daß die Warnung -# "Übersetzungsdatei nicht gefunden" nicht hochkommt. -# Die Suchschlüssel für die zu übersetzenden Begriffe sind -# englisch. Daher wäre eine Übersetzung redundant. diff --git a/src/org/apache/fop/viewer/resources/resources.fi b/src/org/apache/fop/viewer/resources/resources.fi deleted file mode 100644 index 97219031d..000000000 --- a/src/org/apache/fop/viewer/resources/resources.fi +++ /dev/null @@ -1,16 +0,0 @@ -File=Tiedosto -Print=Tulosta -Exit=Poistu -View=Näytä -First page=Ensimmäinen sivu -Previous page=Edellinen sivu -Next page=Seuraava sivu -Last page=Viimeinen sivu -Default zoom=Normaali zoom -Help=Ohje -Index=Sisällys -Introduction=Esittely -About=Tietoja -Page=Sivu - - diff --git a/src/org/apache/fop/viewer/resources/resources.fr b/src/org/apache/fop/viewer/resources/resources.fr deleted file mode 100644 index 5287dcbb9..000000000 --- a/src/org/apache/fop/viewer/resources/resources.fr +++ /dev/null @@ -1,13 +0,0 @@ -File=Fichier -Print=Imprimer -Exit=Quitter -View=Affichage -First page=Première page -Previous page=Page précédente -Next page=Page suivante -Last page=Dernière page -Help=Aide -Default zoom=Zoom par défaut -Introduction=Introduction -About=A propos - diff --git a/src/org/apache/fop/viewer/resources/resources.it b/src/org/apache/fop/viewer/resources/resources.it deleted file mode 100644 index 05cdb0a0a..000000000 --- a/src/org/apache/fop/viewer/resources/resources.it +++ /dev/null @@ -1,14 +0,0 @@ -File=File -Exit=Esci -View=Vista -First page=Prima pagina -Previous page=Pagina precedente -Next page=Pagina seguente -Last page=Ultima pagina -Help=Aiuto -Default zoom=Zoom di default -Introduction=Introduzione -About=Riguardo a... -Index=Indice -Print=Stampa - diff --git a/src/org/apache/fop/viewer/resources/resources.pl b/src/org/apache/fop/viewer/resources/resources.pl deleted file mode 100644 index 9b727e151..000000000 --- a/src/org/apache/fop/viewer/resources/resources.pl +++ /dev/null @@ -1,17 +0,0 @@ -File=Plik -Print=Drukuj -Exit=Zakoñcz -View=Widok -First page=Pierwsza strona -Previous page=Poprzednia strona -Next page=Nastêpna strona -Last page=Ostatnia strona -Zoom=Powiêkszenie -Default zoom=Domy¶lne powiekszenie -Help=Pomoc -Index=Indeks -Introduction=Wstêp -About=O programie -Page=Strona - - diff --git a/src/org/apache/fop/viewer/resources/resources.ru b/src/org/apache/fop/viewer/resources/resources.ru deleted file mode 100644 index 84309253e..000000000 --- a/src/org/apache/fop/viewer/resources/resources.ru +++ /dev/null @@ -1,38 +0,0 @@ -File=Ôàéë - -Exit=Çàêîí÷èòü - -View=Âèä - -First page=Ïåðâàÿ ñòðàíèöà - -Previous page=Ïðåäûäóùàÿ ñòðàíèöà - -Next page=Ñëåäóþùàÿ ñòðàíèöà - -Last page=Ïîñëåäíÿÿ ñòðàíèöà - -Go to Page=Èäòè ê ñòðàíèöå - -Help=Ïîìîùü - -Default zoom=Ñòàíäàðòíûé ìàñøòàá - -Introduction=Ââåäåíèå - -About=Î ïðîãðàììå - -Show=Ïîêàç - -Preview=Ïðîñìîòð - -Print=Ïå÷àòàòü - -Page=Ñòðàíèöà - -of=èç - -Zoom=Ìàñøòàá - -Close=Çàêðûòü - -- 2.39.5