You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2008/03/06 14:34:59 UTC
svn commit: r634267 [15/39] - in
/xmlgraphics/fop/branches/Temp_ProcessingFeedback: ./ examples/embedding/
examples/embedding/java/embedding/
examples/embedding/java/embedding/intermediate/ examples/embedding/xml/xml/
examples/fo/ examples/fo/advanced/...
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/pdf/PDFRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/pdf/PDFRenderer.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/pdf/PDFRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/pdf/PDFRenderer.java Thu Mar 6 05:33:44 2008
@@ -23,11 +23,11 @@
import java.awt.Color;
import java.awt.Point;
import java.awt.Rectangle;
-import java.awt.color.ColorSpace;
import java.awt.color.ICC_Profile;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -61,6 +61,7 @@
import org.apache.fop.area.LineArea;
import org.apache.fop.area.OffDocumentExtensionAttachment;
import org.apache.fop.area.OffDocumentItem;
+import org.apache.fop.area.PageSequence;
import org.apache.fop.area.PageViewport;
import org.apache.fop.area.RegionViewport;
import org.apache.fop.area.Trait;
@@ -147,6 +148,11 @@
public static final String PDF_X_MODE = "pdf-x-mode";
/** Rendering Options key for the ICC profile for the output intent. */
public static final String KEY_OUTPUT_PROFILE = "output-profile";
+ /**
+ * Rendering Options key for disabling the sRGB color space (only possible if no PDF/A or
+ * PDF/X profile is active).
+ */
+ public static final String KEY_DISABLE_SRGB_COLORSPACE = "disable-srgb-colorspace";
/** Controls whether comments are written to the PDF stream. */
protected static final boolean WRITE_COMMENTS = true;
@@ -233,10 +239,10 @@
/** the ICC stream used as output profile by this document for PDF/A and PDF/X functionality. */
protected PDFICCStream outputProfile;
- /** the ICC stream for the sRGB color space. */
- //protected PDFICCStream sRGBProfile;
/** the default sRGB color space. */
protected PDFICCBasedColorSpace sRGBColorSpace;
+ /** controls whether the sRGB color space should be installed */
+ protected boolean disableSRGBColorSpace = false;
/** Optional URI to an output profile to be used. */
protected String outputProfileURI;
@@ -344,6 +350,10 @@
if (s != null) {
this.outputProfileURI = s;
}
+ setting = agent.getRendererOptions().get(KEY_DISABLE_SRGB_COLORSPACE);
+ if (setting != null) {
+ this.disableSRGBColorSpace = booleanValueOf(setting);
+ }
}
/**
@@ -387,27 +397,21 @@
}
private void addsRGBColorSpace() throws IOException {
- if (this.sRGBColorSpace != null) {
- return;
- }
- ICC_Profile profile;
- PDFICCStream sRGBProfile = pdfDoc.getFactory().makePDFICCStream();
- InputStream in = PDFDocument.class.getResourceAsStream("sRGB Color Space Profile.icm");
- if (in != null) {
- try {
- profile = ICC_Profile.getInstance(in);
- } finally {
- IOUtils.closeQuietly(in);
+ if (disableSRGBColorSpace) {
+ if (this.pdfAMode != PDFAMode.DISABLED
+ || this.pdfXMode != PDFXMode.DISABLED
+ || this.outputProfileURI != null) {
+ throw new IllegalStateException("It is not possible to disable the sRGB color"
+ + " space if PDF/A or PDF/X functionality is enabled or an"
+ + " output profile is set!");
}
} else {
- //Fallback: Use the sRGB profile from the JRE (about 140KB)
- profile = ICC_Profile.getInstance(ColorSpace.CS_sRGB);
+ if (this.sRGBColorSpace != null) {
+ return;
+ }
+ //Map sRGB as default RGB profile for DeviceRGB
+ this.sRGBColorSpace = PDFICCBasedColorSpace.setupsRGBAsDefaultRGBColorSpace(pdfDoc);
}
- sRGBProfile.setColorSpace(profile, null);
-
- //Map sRGB as default RGB profile for DeviceRGB
- this.sRGBColorSpace = pdfDoc.getFactory().makeICCBasedColorSpace(
- null, "DefaultRGB", sRGBProfile);
}
private void addDefaultOutputProfile() throws IOException {
@@ -611,7 +615,7 @@
private void renderXMPMetadata(XMPMetadata metadata) {
Metadata docXMP = metadata.getMetadata();
- Metadata fopXMP = PDFMetadata.createXMPFromUserAgent(pdfDoc);
+ Metadata fopXMP = PDFMetadata.createXMPFromPDFDocument(pdfDoc);
//Merge FOP's own metadata into the one from the XSL-FO document
fopXMP.mergeInto(docXMP);
XMPBasicAdapter xmpBasic = XMPBasicSchema.getAdapter(docXMP);
@@ -679,13 +683,15 @@
/**
* Start the next page sequence.
- * For the pdf renderer there is no concept of page sequences
+ * For the PDF renderer there is no concept of page sequences
* but it uses the first available page sequence title to set
- * as the title of the pdf document.
- *
- * @param seqTitle the title of the page sequence
- */
- public void startPageSequence(LineArea seqTitle) {
+ * as the title of the PDF document, and the language of the
+ * document.
+ * @param pageSequence the page sequence
+ */
+ public void startPageSequence(PageSequence pageSequence) {
+ super.startPageSequence(pageSequence);
+ LineArea seqTitle = pageSequence.getTitle();
if (seqTitle != null) {
String str = convertTitleToString(seqTitle);
PDFInfo info = this.pdfDoc.getInfo();
@@ -693,10 +699,20 @@
info.setTitle(str);
}
}
+ if (pageSequence.getLanguage() != null) {
+ String lang = pageSequence.getLanguage();
+ String country = pageSequence.getCountry();
+ String langCode = lang + (country != null ? "-" + country : "");
+ if (pdfDoc.getRoot().getLanguage() == null) {
+ //Only set if not set already (first non-null is used)
+ //Note: No checking is performed whether the values are valid!
+ pdfDoc.getRoot().setLanguage(langCode);
+ }
+ }
if (pdfDoc.getRoot().getMetadata() == null) {
//If at this time no XMP metadata for the overall document has been set, create it
//from the PDFInfo object.
- Metadata xmp = PDFMetadata.createXMPFromUserAgent(pdfDoc);
+ Metadata xmp = PDFMetadata.createXMPFromPDFDocument(pdfDoc);
PDFMetadata pdfMetadata = pdfDoc.getFactory().makeMetadata(
xmp, true);
pdfDoc.getRoot().setMetadata(pdfMetadata);
@@ -1550,7 +1566,7 @@
startPending = false;
}
if (!useMultiByte) {
- if (ch > 127) {
+ if (ch < 32 || ch > 127) {
pdf.append("\\");
pdf.append(Integer.toOctalString((int) ch));
} else {
@@ -1739,6 +1755,8 @@
} catch (ImageException ie) {
log.error("Error while processing image: "
+ (info != null ? info.toString() : uri), ie);
+ } catch (FileNotFoundException fnfe) {
+ log.error(fnfe.getMessage());
} catch (IOException ioe) {
log.error("I/O error while processing image: "
+ (info != null ? info.toString() : uri), ioe);
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java Thu Mar 6 05:33:44 2008
@@ -24,6 +24,7 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.pdf.PDFAMode;
@@ -80,6 +81,10 @@
s = cfg.getChild(PDFRenderer.KEY_OUTPUT_PROFILE, true).getValue(null);
if (s != null) {
pdfRenderer.setOutputProfileURI(s);
+ }
+ Configuration child = cfg.getChild(PDFRenderer.KEY_DISABLE_SRGB_COLORSPACE, false);
+ if (child != null) {
+ pdfRenderer.disableSRGBColorSpace = child.getValueAsBoolean(false);
}
}
}
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/pdf/PDFRendererMaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/pdf/PDFRendererMaker.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/pdf/PDFRendererMaker.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/pdf/PDFRendererMaker.java Thu Mar 6 05:33:44 2008
@@ -1,55 +1,55 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.render.pdf;
-
-import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.render.AbstractRendererMaker;
-import org.apache.fop.render.Renderer;
-import org.apache.fop.render.RendererConfigurator;
-
-/**
- * RendererMaker for the PDF Renderer.
- */
-public class PDFRendererMaker extends AbstractRendererMaker {
-
- private static final String[] MIMES = new String[] {MimeConstants.MIME_PDF};
-
- /** {@inheritDoc} */
- public Renderer makeRenderer(FOUserAgent userAgent) {
- return new PDFRenderer();
- }
-
- /** {@inheritDoc} */
- public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
- return new PDFRendererConfigurator(userAgent);
- }
-
- /** {@inheritDoc} */
- public boolean needsOutputStream() {
- return true;
- }
-
- /** {@inheritDoc} */
- public String[] getSupportedMimeTypes() {
- return MIMES;
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.pdf;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+import org.apache.fop.render.RendererConfigurator;
+
+/**
+ * RendererMaker for the PDF Renderer.
+ */
+public class PDFRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_PDF};
+
+ /** {@inheritDoc} */
+ public Renderer makeRenderer(FOUserAgent userAgent) {
+ return new PDFRenderer();
+ }
+
+ /** {@inheritDoc} */
+ public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
+ return new PDFRendererConfigurator(userAgent);
+ }
+
+ /** {@inheritDoc} */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/pdf/PDFRendererMaker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/print/PrintRenderer.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/print/PrintRendererMaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/print/PrintRendererMaker.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/print/PrintRendererMaker.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/print/PrintRendererMaker.java Thu Mar 6 05:33:44 2008
@@ -1,56 +1,56 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.render.print;
-
-import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.render.AbstractRendererMaker;
-import org.apache.fop.render.PrintRendererConfigurator;
-import org.apache.fop.render.Renderer;
-import org.apache.fop.render.RendererConfigurator;
-
-/**
- * RendererMaker for the Print Renderer.
- */
-public class PrintRendererMaker extends AbstractRendererMaker {
-
- private static final String[] MIMES = new String[] {MimeConstants.MIME_FOP_PRINT};
-
- /**{@inheritDoc} */
- public Renderer makeRenderer(FOUserAgent userAgent) {
- return new PrintRenderer();
- }
-
- /** {@inheritDoc} */
- public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
- return new PrintRendererConfigurator(userAgent);
- }
-
- /** {@inheritDoc} */
- public boolean needsOutputStream() {
- return false;
- }
-
- /** {@inheritDoc} */
- public String[] getSupportedMimeTypes() {
- return MIMES;
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.print;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.PrintRendererConfigurator;
+import org.apache.fop.render.Renderer;
+import org.apache.fop.render.RendererConfigurator;
+
+/**
+ * RendererMaker for the Print Renderer.
+ */
+public class PrintRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_FOP_PRINT};
+
+ /**{@inheritDoc} */
+ public Renderer makeRenderer(FOUserAgent userAgent) {
+ return new PrintRenderer();
+ }
+
+ /** {@inheritDoc} */
+ public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
+ return new PrintRendererConfigurator(userAgent);
+ }
+
+ /** {@inheritDoc} */
+ public boolean needsOutputStream() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/print/PrintRendererMaker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/AbstractPSTranscoder.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/EPSTranscoder.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/NativeTextHandler.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSDictionary.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSDictionary.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSDictionary.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSDictionary.java Thu Mar 6 05:33:44 2008
@@ -1,312 +1,312 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id: $ */
-
-package org.apache.fop.render.ps;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.StringTokenizer;
-
-/**
- * This class is used to encapsulate postscript dictionary objects.
- */
-public class PSDictionary extends java.util.HashMap {
-
- private static final long serialVersionUID = 815367222496219197L;
-
- /**
- * This class is used to parse dictionary strings.
- */
- private static class Maker {
-
- /**
- * Simple token holding class
- */
- private class Token {
- /**
- * start index in string
- */
- private int startIndex = -1;
-
- /**
- * end index in string
- */
- private int endIndex = -1;
-
- /**
- * token string value
- */
- private String value;
- }
-
- private static final String[][] BRACES = {
- {"<<", ">>"},
- {"[", "]"},
- {"{", "}"}
- };
-
- private static final int OPENING = 0;
- private static final int CLOSING = 1;
- private static final int DICTIONARY = 0;
- private static final int ARRAY = 1;
- private static final int PROCEDURE = 2;
-
- /**
- * Returns a Token containing the start, end index and value of the next token
- * found in a given string
- *
- * @param str
- * string to search
- * @param fromIndex
- * search from index
- * @return Token containing the start, end index and value of the next token
- */
- protected Token nextToken(String str, int fromIndex) {
- Token t = null;
- for (int i = fromIndex; i < str.length(); i++) {
- boolean isWhitespace = Character.isWhitespace(str.charAt(i));
- // start index found
- if (t == null && !isWhitespace) {
- t = new Token();
- t.startIndex = i;
- // end index found
- } else if (t != null && isWhitespace) {
- t.endIndex = i;
- break;
- }
- }
- // start index found
- if (t != null) {
- // end index not found so take end of string
- if (t.endIndex == -1) {
- t.endIndex = str.length();
- }
- t.value = str.substring(t.startIndex, t.endIndex);
- }
- return t;
- }
-
- /**
- * Returns the closing brace index from a given string searches from a
- * given index
- *
- * @param str
- * string to search
- * @param braces
- * string array of opening and closing brace
- * @param fromIndex
- * searches from index
- * @return matching brace index
- * @throws org.apache.fop.render.ps.PSDictionaryFormatException
- * thrown in the event that a parsing error occurred
- */
- private int indexOfMatchingBrace(String str, String[] braces,
- int fromIndex) throws PSDictionaryFormatException {
- final int len = str.length();
- if (braces.length != 2) {
- throw new PSDictionaryFormatException("Wrong number of braces");
- }
- for (int openCnt = 0, closeCnt = 0; fromIndex < len; fromIndex++) {
- if (str.startsWith(braces[OPENING], fromIndex)) {
- openCnt++;
- } else if (str.startsWith(braces[CLOSING], fromIndex)) {
- closeCnt++;
- if (openCnt > 0 && openCnt == closeCnt) {
- return fromIndex; // found
- }
- }
- }
- return -1; // not found
- }
-
- /**
- * Strips braces from complex object string
- *
- * @param str
- * String to parse
- * @param braces
- * String array containing opening and closing braces
- * @return String with braces stripped
- * @throws
- * org.apache.fop.render.ps.PSDictionaryFormatException object format exception
- */
- private String stripBraces(String str, String[] braces) throws PSDictionaryFormatException {
- // find first opening brace
- int firstIndex = str.indexOf(braces[OPENING]);
- if (firstIndex == -1) {
- throw new PSDictionaryFormatException(
- "Failed to find opening parameter '" + braces[OPENING]
- + "");
- }
-
- // find last matching brace
- int lastIndex = indexOfMatchingBrace(str, braces, firstIndex);
- if (lastIndex == -1) {
- throw new PSDictionaryFormatException(
- "Failed to find matching closing parameter '"
- + braces[CLOSING] + "'");
- }
-
- // strip brace and trim
- int braceLen = braces[OPENING].length();
- str = str.substring(firstIndex + braceLen, lastIndex).trim();
- return str;
- }
-
- /**
- * Parses a dictionary string and provides a dictionary object
- *
- * @param str a dictionary string
- * @return A postscript dictionary object
- * @throws
- * PSDictionaryFormatException thrown if a dictionary format exception occurs
- */
- public PSDictionary parseDictionary(String str) throws PSDictionaryFormatException {
- PSDictionary dictionary = new PSDictionary();
- str = stripBraces(str.trim(), BRACES[DICTIONARY]);
- // length of dictionary string
- final int len = str.length();
-
- Token keyToken;
- for (int currIndex = 0; (keyToken = nextToken(str, currIndex)) != null
- && currIndex <= len;) {
- if (keyToken.value == null) {
- throw new PSDictionaryFormatException("Failed to parse object key");
- }
- Token valueToken = nextToken(str, keyToken.endIndex + 1);
- String[] braces = null;
- for (int i = 0; i < BRACES.length; i++) {
- if (valueToken.value.startsWith(BRACES[i][OPENING])) {
- braces = BRACES[i];
- break;
- }
- }
- Object obj = null;
- if (braces != null) {
- // find closing brace
- valueToken.endIndex = indexOfMatchingBrace(str, braces,
- valueToken.startIndex)
- + braces[OPENING].length();
- if (valueToken.endIndex < 0) {
- throw new PSDictionaryFormatException("Closing value brace '"
- + braces[CLOSING] + "' not found for key '"
- + keyToken.value + "'");
- }
- valueToken.value = str.substring(valueToken.startIndex, valueToken.endIndex);
- }
- if (braces == null || braces == BRACES[PROCEDURE]) {
- obj = valueToken.value;
- } else if (BRACES[ARRAY] == braces) {
- List objList = new java.util.ArrayList();
- String objString = stripBraces(valueToken.value, braces);
- StringTokenizer tokenizer = new StringTokenizer(objString, ",");
- while (tokenizer.hasMoreTokens()) {
- objList.add(tokenizer.nextToken());
- }
- obj = objList;
- } else if (BRACES[DICTIONARY] == braces) {
- obj = parseDictionary(valueToken.value);
- }
- dictionary.put(keyToken.value, obj);
- currIndex = valueToken.endIndex + 1;
- }
- return dictionary;
- }
- }
-
- /**
- * Parses a given a dictionary string and returns an object
- *
- * @param str dictionary string
- * @return dictionary object
- * @throws PSDictionaryFormatException object format exception
- */
- public static PSDictionary valueOf(String str) throws PSDictionaryFormatException {
- return (new Maker()).parseDictionary(str);
- }
-
- /**
- * @param obj object to test equality against
- * @return whether a given object is equal to this dictionary object
- * @see java.lang.Object#equals(Object)
- */
- public boolean equals(Object obj) {
- if (!(obj instanceof PSPageDeviceDictionary)) {
- return false;
- }
- PSDictionary dictionaryObj = (PSDictionary) obj;
- if (dictionaryObj.size() != size()) {
- return false;
- }
- for (Iterator it = keySet().iterator(); it.hasNext();) {
- String key = (String) it.next();
- if (!dictionaryObj.containsKey(key)) {
- return false;
- }
- if (!dictionaryObj.get(key).equals(get(key))) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * @return a hash code value for this object.
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- int hashCode = 7;
- for (Iterator it = values().iterator(); it.hasNext();) {
- Object value = it.next();
- hashCode += value.hashCode();
- }
- return hashCode;
- }
-
- /**
- * @return a string representation of this dictionary
- * @see java.lang.String#toString()
- */
- public String toString() {
- if (isEmpty()) {
- return "";
- }
- StringBuffer sb = new StringBuffer("<<\n");
- for (Iterator it = super.keySet().iterator(); it.hasNext();) {
- String key = (String) it.next();
- sb.append(" " + key + " ");
- Object obj = super.get(key);
- if (obj instanceof java.util.ArrayList) {
- List array = (List)obj;
- String str = "[";
- for (int i = 0; i < array.size(); i++) {
- Object element = array.get(i);
- str += element + " ";
- }
- str = str.trim();
- str += "]";
- sb.append(str + "\n");
- } else {
- sb.append(obj.toString() + "\n");
- }
- }
- sb.append(">>");
- return sb.toString();
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.ps;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+/**
+ * This class is used to encapsulate postscript dictionary objects.
+ */
+public class PSDictionary extends java.util.HashMap {
+
+ private static final long serialVersionUID = 815367222496219197L;
+
+ /**
+ * This class is used to parse dictionary strings.
+ */
+ private static class Maker {
+
+ /**
+ * Simple token holding class
+ */
+ private class Token {
+ /**
+ * start index in string
+ */
+ private int startIndex = -1;
+
+ /**
+ * end index in string
+ */
+ private int endIndex = -1;
+
+ /**
+ * token string value
+ */
+ private String value;
+ }
+
+ private static final String[][] BRACES = {
+ {"<<", ">>"},
+ {"[", "]"},
+ {"{", "}"}
+ };
+
+ private static final int OPENING = 0;
+ private static final int CLOSING = 1;
+ private static final int DICTIONARY = 0;
+ private static final int ARRAY = 1;
+ private static final int PROCEDURE = 2;
+
+ /**
+ * Returns a Token containing the start, end index and value of the next token
+ * found in a given string
+ *
+ * @param str
+ * string to search
+ * @param fromIndex
+ * search from index
+ * @return Token containing the start, end index and value of the next token
+ */
+ protected Token nextToken(String str, int fromIndex) {
+ Token t = null;
+ for (int i = fromIndex; i < str.length(); i++) {
+ boolean isWhitespace = Character.isWhitespace(str.charAt(i));
+ // start index found
+ if (t == null && !isWhitespace) {
+ t = new Token();
+ t.startIndex = i;
+ // end index found
+ } else if (t != null && isWhitespace) {
+ t.endIndex = i;
+ break;
+ }
+ }
+ // start index found
+ if (t != null) {
+ // end index not found so take end of string
+ if (t.endIndex == -1) {
+ t.endIndex = str.length();
+ }
+ t.value = str.substring(t.startIndex, t.endIndex);
+ }
+ return t;
+ }
+
+ /**
+ * Returns the closing brace index from a given string searches from a
+ * given index
+ *
+ * @param str
+ * string to search
+ * @param braces
+ * string array of opening and closing brace
+ * @param fromIndex
+ * searches from index
+ * @return matching brace index
+ * @throws org.apache.fop.render.ps.PSDictionaryFormatException
+ * thrown in the event that a parsing error occurred
+ */
+ private int indexOfMatchingBrace(String str, String[] braces,
+ int fromIndex) throws PSDictionaryFormatException {
+ final int len = str.length();
+ if (braces.length != 2) {
+ throw new PSDictionaryFormatException("Wrong number of braces");
+ }
+ for (int openCnt = 0, closeCnt = 0; fromIndex < len; fromIndex++) {
+ if (str.startsWith(braces[OPENING], fromIndex)) {
+ openCnt++;
+ } else if (str.startsWith(braces[CLOSING], fromIndex)) {
+ closeCnt++;
+ if (openCnt > 0 && openCnt == closeCnt) {
+ return fromIndex; // found
+ }
+ }
+ }
+ return -1; // not found
+ }
+
+ /**
+ * Strips braces from complex object string
+ *
+ * @param str
+ * String to parse
+ * @param braces
+ * String array containing opening and closing braces
+ * @return String with braces stripped
+ * @throws
+ * org.apache.fop.render.ps.PSDictionaryFormatException object format exception
+ */
+ private String stripBraces(String str, String[] braces) throws PSDictionaryFormatException {
+ // find first opening brace
+ int firstIndex = str.indexOf(braces[OPENING]);
+ if (firstIndex == -1) {
+ throw new PSDictionaryFormatException(
+ "Failed to find opening parameter '" + braces[OPENING]
+ + "");
+ }
+
+ // find last matching brace
+ int lastIndex = indexOfMatchingBrace(str, braces, firstIndex);
+ if (lastIndex == -1) {
+ throw new PSDictionaryFormatException(
+ "Failed to find matching closing parameter '"
+ + braces[CLOSING] + "'");
+ }
+
+ // strip brace and trim
+ int braceLen = braces[OPENING].length();
+ str = str.substring(firstIndex + braceLen, lastIndex).trim();
+ return str;
+ }
+
+ /**
+ * Parses a dictionary string and provides a dictionary object
+ *
+ * @param str a dictionary string
+ * @return A postscript dictionary object
+ * @throws
+ * PSDictionaryFormatException thrown if a dictionary format exception occurs
+ */
+ public PSDictionary parseDictionary(String str) throws PSDictionaryFormatException {
+ PSDictionary dictionary = new PSDictionary();
+ str = stripBraces(str.trim(), BRACES[DICTIONARY]);
+ // length of dictionary string
+ final int len = str.length();
+
+ Token keyToken;
+ for (int currIndex = 0; (keyToken = nextToken(str, currIndex)) != null
+ && currIndex <= len;) {
+ if (keyToken.value == null) {
+ throw new PSDictionaryFormatException("Failed to parse object key");
+ }
+ Token valueToken = nextToken(str, keyToken.endIndex + 1);
+ String[] braces = null;
+ for (int i = 0; i < BRACES.length; i++) {
+ if (valueToken.value.startsWith(BRACES[i][OPENING])) {
+ braces = BRACES[i];
+ break;
+ }
+ }
+ Object obj = null;
+ if (braces != null) {
+ // find closing brace
+ valueToken.endIndex = indexOfMatchingBrace(str, braces,
+ valueToken.startIndex)
+ + braces[OPENING].length();
+ if (valueToken.endIndex < 0) {
+ throw new PSDictionaryFormatException("Closing value brace '"
+ + braces[CLOSING] + "' not found for key '"
+ + keyToken.value + "'");
+ }
+ valueToken.value = str.substring(valueToken.startIndex, valueToken.endIndex);
+ }
+ if (braces == null || braces == BRACES[PROCEDURE]) {
+ obj = valueToken.value;
+ } else if (BRACES[ARRAY] == braces) {
+ List objList = new java.util.ArrayList();
+ String objString = stripBraces(valueToken.value, braces);
+ StringTokenizer tokenizer = new StringTokenizer(objString, ",");
+ while (tokenizer.hasMoreTokens()) {
+ objList.add(tokenizer.nextToken());
+ }
+ obj = objList;
+ } else if (BRACES[DICTIONARY] == braces) {
+ obj = parseDictionary(valueToken.value);
+ }
+ dictionary.put(keyToken.value, obj);
+ currIndex = valueToken.endIndex + 1;
+ }
+ return dictionary;
+ }
+ }
+
+ /**
+ * Parses a given a dictionary string and returns an object
+ *
+ * @param str dictionary string
+ * @return dictionary object
+ * @throws PSDictionaryFormatException object format exception
+ */
+ public static PSDictionary valueOf(String str) throws PSDictionaryFormatException {
+ return (new Maker()).parseDictionary(str);
+ }
+
+ /**
+ * @param obj object to test equality against
+ * @return whether a given object is equal to this dictionary object
+ * @see java.lang.Object#equals(Object)
+ */
+ public boolean equals(Object obj) {
+ if (!(obj instanceof PSPageDeviceDictionary)) {
+ return false;
+ }
+ PSDictionary dictionaryObj = (PSDictionary) obj;
+ if (dictionaryObj.size() != size()) {
+ return false;
+ }
+ for (Iterator it = keySet().iterator(); it.hasNext();) {
+ String key = (String) it.next();
+ if (!dictionaryObj.containsKey(key)) {
+ return false;
+ }
+ if (!dictionaryObj.get(key).equals(get(key))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * @return a hash code value for this object.
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ int hashCode = 7;
+ for (Iterator it = values().iterator(); it.hasNext();) {
+ Object value = it.next();
+ hashCode += value.hashCode();
+ }
+ return hashCode;
+ }
+
+ /**
+ * @return a string representation of this dictionary
+ * @see java.lang.String#toString()
+ */
+ public String toString() {
+ if (isEmpty()) {
+ return "";
+ }
+ StringBuffer sb = new StringBuffer("<<\n");
+ for (Iterator it = super.keySet().iterator(); it.hasNext();) {
+ String key = (String) it.next();
+ sb.append(" " + key + " ");
+ Object obj = super.get(key);
+ if (obj instanceof java.util.ArrayList) {
+ List array = (List)obj;
+ String str = "[";
+ for (int i = 0; i < array.size(); i++) {
+ Object element = array.get(i);
+ str += element + " ";
+ }
+ str = str.trim();
+ str += "]";
+ sb.append(str + "\n");
+ } else {
+ sb.append(obj.toString() + "\n");
+ }
+ }
+ sb.append(">>");
+ return sb.toString();
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSDictionary.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSDictionary.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSDictionaryFormatException.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSDictionaryFormatException.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSDictionaryFormatException.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSDictionaryFormatException.java Thu Mar 6 05:33:44 2008
@@ -1,37 +1,37 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id: $ */
-
-package org.apache.fop.render.ps;
-
-/**
- * Thrown to indicate that a formatting error has occured when
- * trying to parse a postscript dictionary object
- */
-public class PSDictionaryFormatException extends Exception {
-
- private static final long serialVersionUID = 6492321557297860931L;
-
- /**
- * Default constructor
- * @param string error message
- */
- public PSDictionaryFormatException(String string) {
- super(string);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.ps;
+
+/**
+ * Thrown to indicate that a formatting error has occured when
+ * trying to parse a postscript dictionary object
+ */
+public class PSDictionaryFormatException extends Exception {
+
+ private static final long serialVersionUID = 6492321557297860931L;
+
+ /**
+ * Default constructor
+ * @param string error message
+ */
+ public PSDictionaryFormatException(String string) {
+ super(string);
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSDictionaryFormatException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSDictionaryFormatException.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSFontUtils.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSFontUtils.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSFontUtils.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSFontUtils.java Thu Mar 6 05:33:44 2008
@@ -31,16 +31,18 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
+import org.apache.xmlgraphics.ps.DSCConstants;
+import org.apache.xmlgraphics.ps.PSGenerator;
+import org.apache.xmlgraphics.ps.PSResource;
+import org.apache.xmlgraphics.ps.dsc.ResourceTracker;
+
import org.apache.fop.fonts.CustomFont;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontType;
import org.apache.fop.fonts.LazyFont;
import org.apache.fop.fonts.Typeface;
-import org.apache.xmlgraphics.ps.DSCConstants;
-import org.apache.xmlgraphics.ps.PSGenerator;
-import org.apache.xmlgraphics.ps.PSResource;
-import org.apache.xmlgraphics.ps.dsc.ResourceTracker;
/**
* Utility code for font handling in PostScript.
@@ -108,8 +110,10 @@
} else if ("WinAnsiEncoding".equals(fm.getEncoding())) {
redefineFontEncoding(gen, fm.getFontName(), fm.getEncoding());
} else {
+ /* Don't complain anymore, just use the font's default encoding.
gen.commentln("%WARNING: Only WinAnsiEncoding is supported. Font '"
+ fm.getFontName() + "' asks for: " + fm.getEncoding());
+ */
}
}
gen.commentln("%FOPEndFontReencode");
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java Thu Mar 6 05:33:44 2008
@@ -1,105 +1,105 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.render.ps;
-
-import java.awt.Dimension;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
-import java.io.IOException;
-
-import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
-import org.apache.xmlgraphics.java2d.ps.PSGraphics2D;
-import org.apache.xmlgraphics.ps.PSGenerator;
-
-import org.apache.fop.render.Graphics2DAdapter;
-import org.apache.fop.render.RendererContext;
-
-/**
- * Graphics2DAdapter implementation for PostScript.
- */
-public class PSGraphics2DAdapter implements Graphics2DAdapter {
-
- private PSGenerator gen;
- private boolean clip = true;
-
- /**
- * Main constructor
- * @param renderer the Renderer instance to which this instance belongs
- */
- public PSGraphics2DAdapter(PSRenderer renderer) {
- this(renderer.gen, true);
- }
-
- /**
- * Constructor for use without a PSRenderer instance.
- * @param gen the PostScript generator
- * @param clip true if the image should be clipped
- */
- public PSGraphics2DAdapter(PSGenerator gen, boolean clip) {
- this.gen = gen;
- this.clip = clip;
- }
-
- /** {@inheritDoc} */
- public void paintImage(Graphics2DImagePainter painter,
- RendererContext context,
- int x, int y, int width, int height) throws IOException {
- float fwidth = width / 1000f;
- float fheight = height / 1000f;
- float fx = x / 1000f;
- float fy = y / 1000f;
-
- // get the 'width' and 'height' attributes of the SVG document
- Dimension dim = painter.getImageSize();
- float imw = (float)dim.getWidth() / 1000f;
- float imh = (float)dim.getHeight() / 1000f;
-
- float sx = fwidth / (float)imw;
- float sy = fheight / (float)imh;
-
- gen.commentln("%FOPBeginGraphics2D");
- gen.saveGraphicsState();
- if (clip) {
- // Clip to the image area.
- gen.writeln("newpath");
- gen.defineRect(fx, fy, fwidth, fheight);
- gen.writeln("clip");
- }
-
- // 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.
- gen.concatMatrix(sx, 0, 0, sy, fx, fy);
-
- final boolean textAsShapes = false;
- PSGraphics2D graphics = new PSGraphics2D(textAsShapes, gen);
- graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
- AffineTransform transform = new AffineTransform();
- // scale to viewbox
- transform.translate(fx, fy);
- gen.getCurrentState().concatMatrix(transform);
- Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
- painter.paint(graphics, area);
-
- gen.restoreGraphicsState();
- gen.commentln("%FOPEndGraphics2D");
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.ps;
+
+import java.awt.Dimension;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.io.IOException;
+
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+import org.apache.xmlgraphics.java2d.ps.PSGraphics2D;
+import org.apache.xmlgraphics.ps.PSGenerator;
+
+import org.apache.fop.render.Graphics2DAdapter;
+import org.apache.fop.render.RendererContext;
+
+/**
+ * Graphics2DAdapter implementation for PostScript.
+ */
+public class PSGraphics2DAdapter implements Graphics2DAdapter {
+
+ private PSGenerator gen;
+ private boolean clip = true;
+
+ /**
+ * Main constructor
+ * @param renderer the Renderer instance to which this instance belongs
+ */
+ public PSGraphics2DAdapter(PSRenderer renderer) {
+ this(renderer.gen, true);
+ }
+
+ /**
+ * Constructor for use without a PSRenderer instance.
+ * @param gen the PostScript generator
+ * @param clip true if the image should be clipped
+ */
+ public PSGraphics2DAdapter(PSGenerator gen, boolean clip) {
+ this.gen = gen;
+ this.clip = clip;
+ }
+
+ /** {@inheritDoc} */
+ public void paintImage(Graphics2DImagePainter painter,
+ RendererContext context,
+ int x, int y, int width, int height) throws IOException {
+ float fwidth = width / 1000f;
+ float fheight = height / 1000f;
+ float fx = x / 1000f;
+ float fy = y / 1000f;
+
+ // get the 'width' and 'height' attributes of the SVG document
+ Dimension dim = painter.getImageSize();
+ float imw = (float)dim.getWidth() / 1000f;
+ float imh = (float)dim.getHeight() / 1000f;
+
+ float sx = fwidth / (float)imw;
+ float sy = fheight / (float)imh;
+
+ gen.commentln("%FOPBeginGraphics2D");
+ gen.saveGraphicsState();
+ if (clip) {
+ // Clip to the image area.
+ gen.writeln("newpath");
+ gen.defineRect(fx, fy, fwidth, fheight);
+ gen.writeln("clip");
+ }
+
+ // 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.
+ gen.concatMatrix(sx, 0, 0, sy, fx, fy);
+
+ final boolean textAsShapes = false;
+ PSGraphics2D graphics = new PSGraphics2D(textAsShapes, gen);
+ graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
+ AffineTransform transform = new AffineTransform();
+ // scale to viewbox
+ transform.translate(fx, fy);
+ gen.getCurrentState().concatMatrix(transform);
+ Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
+ painter.paint(graphics, area);
+
+ gen.restoreGraphicsState();
+ gen.commentln("%FOPEndGraphics2D");
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSImageFormResource.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSImageUtils.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSPageDeviceDictionary.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSPageDeviceDictionary.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSPageDeviceDictionary.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSPageDeviceDictionary.java Thu Mar 6 05:33:44 2008
@@ -1,110 +1,110 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id: $ */
-
-package org.apache.fop.render.ps;
-
-/**
- * Postscript page device dictionary object
- *
- * This object is used by the postscript renderer to hold postscript page device
- * values. It can also be used to minimize the number of setpagedevice calls when
- * DSC compliance is false.
- */
-public class PSPageDeviceDictionary extends PSDictionary {
-
- private static final long serialVersionUID = 845943256485806509L;
-
- /**
- * Whether or not the contents of the dictionary are flushed on retrieval
- */
- private boolean flushOnRetrieval = false;
-
- /**
- * Dictionary content that has not been output/written yet
- */
- private PSDictionary unRetrievedContentDictionary;
-
- /**
- * @param key key with which the specified value is to be associated.
- * @param value value to be associated with the specified key.
- * @return the previous value associated with the key or null
- * @see java.util.Map#put(Object, Object)
- */
- public Object put(Object key, Object value) {
- Object previousValue = super.put(key, value);
- if (flushOnRetrieval) {
- if (previousValue == null || !previousValue.equals(value)) {
- unRetrievedContentDictionary.put(key, value);
- }
- }
- return previousValue;
- }
-
- /**
- * @see java.util.Map#clear()
- */
- public void clear() {
- super.clear();
- if (unRetrievedContentDictionary != null) {
- unRetrievedContentDictionary.clear();
- }
- }
-
- /**
- * Returns <tt>true</tt> if this map contains no key-value mappings.
- *
- * @return <tt>true</tt> if this map contains no key-value mappings.
- */
- public boolean isEmpty() {
- if (flushOnRetrieval) {
- return unRetrievedContentDictionary.isEmpty();
- }
- return super.isEmpty();
- }
-
- /**
- * The contents of the dictionary are flushed when written
- * @param flushOnRetrieval boolean value
- */
- public void setFlushOnRetrieval(boolean flushOnRetrieval) {
- this.flushOnRetrieval = flushOnRetrieval;
- if (flushOnRetrieval) {
- unRetrievedContentDictionary = new PSDictionary();
- }
- }
-
- /**
- * Returns a dictionary string with containing all unwritten content note:
- * unnecessary writes are important as there is a device specific
- * initgraphics call by the underlying postscript interpreter on every
- * setpagedevice call which can result in blank pages etc.
- *
- * @return unwritten content dictionary string
- */
- public String getContent() {
- String content;
- if (flushOnRetrieval) {
- content = unRetrievedContentDictionary.toString();
- unRetrievedContentDictionary.clear();
- } else {
- content = super.toString();
- }
- return content;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.ps;
+
+/**
+ * Postscript page device dictionary object
+ *
+ * This object is used by the postscript renderer to hold postscript page device
+ * values. It can also be used to minimize the number of setpagedevice calls when
+ * DSC compliance is false.
+ */
+public class PSPageDeviceDictionary extends PSDictionary {
+
+ private static final long serialVersionUID = 845943256485806509L;
+
+ /**
+ * Whether or not the contents of the dictionary are flushed on retrieval
+ */
+ private boolean flushOnRetrieval = false;
+
+ /**
+ * Dictionary content that has not been output/written yet
+ */
+ private PSDictionary unRetrievedContentDictionary;
+
+ /**
+ * @param key key with which the specified value is to be associated.
+ * @param value value to be associated with the specified key.
+ * @return the previous value associated with the key or null
+ * @see java.util.Map#put(Object, Object)
+ */
+ public Object put(Object key, Object value) {
+ Object previousValue = super.put(key, value);
+ if (flushOnRetrieval) {
+ if (previousValue == null || !previousValue.equals(value)) {
+ unRetrievedContentDictionary.put(key, value);
+ }
+ }
+ return previousValue;
+ }
+
+ /**
+ * @see java.util.Map#clear()
+ */
+ public void clear() {
+ super.clear();
+ if (unRetrievedContentDictionary != null) {
+ unRetrievedContentDictionary.clear();
+ }
+ }
+
+ /**
+ * Returns <tt>true</tt> if this map contains no key-value mappings.
+ *
+ * @return <tt>true</tt> if this map contains no key-value mappings.
+ */
+ public boolean isEmpty() {
+ if (flushOnRetrieval) {
+ return unRetrievedContentDictionary.isEmpty();
+ }
+ return super.isEmpty();
+ }
+
+ /**
+ * The contents of the dictionary are flushed when written
+ * @param flushOnRetrieval boolean value
+ */
+ public void setFlushOnRetrieval(boolean flushOnRetrieval) {
+ this.flushOnRetrieval = flushOnRetrieval;
+ if (flushOnRetrieval) {
+ unRetrievedContentDictionary = new PSDictionary();
+ }
+ }
+
+ /**
+ * Returns a dictionary string with containing all unwritten content note:
+ * unnecessary writes are important as there is a device specific
+ * initgraphics call by the underlying postscript interpreter on every
+ * setpagedevice call which can result in blank pages etc.
+ *
+ * @return unwritten content dictionary string
+ */
+ public String getContent() {
+ String content;
+ if (flushOnRetrieval) {
+ content = unRetrievedContentDictionary.toString();
+ unRetrievedContentDictionary.clear();
+ } else {
+ content = super.toString();
+ }
+ return content;
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSPageDeviceDictionary.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSPageDeviceDictionary.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSRenderer.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSRenderer.java Thu Mar 6 05:33:44 2008
@@ -72,7 +72,6 @@
import org.apache.fop.area.Area;
import org.apache.fop.area.BlockViewport;
import org.apache.fop.area.CTM;
-import org.apache.fop.area.LineArea;
import org.apache.fop.area.OffDocumentExtensionAttachment;
import org.apache.fop.area.OffDocumentItem;
import org.apache.fop.area.PageViewport;
@@ -1080,11 +1079,6 @@
}
}
super.processOffDocumentItem(oDI);
- }
-
- /** {@inheritDoc} */
- public void startPageSequence(LineArea seqTitle) {
- super.startPageSequence(seqTitle);
}
/**
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSRendererConfigurator.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSRendererConfigurator.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSRendererConfigurator.java Thu Mar 6 05:33:44 2008
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-/* $Id: $ */
+/* $Id$ */
package org.apache.fop.render.ps;
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSRendererConfigurator.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSRendererMaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSRendererMaker.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSRendererMaker.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSRendererMaker.java Thu Mar 6 05:33:44 2008
@@ -1,54 +1,54 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.render.ps;
-
-import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.render.AbstractRendererMaker;
-import org.apache.fop.render.Renderer;
-import org.apache.fop.render.RendererConfigurator;
-
-/**
- * RendererMaker for the PostScript Renderer.
- */
-public class PSRendererMaker extends AbstractRendererMaker {
-
- private static final String[] MIMES = new String[] {MimeConstants.MIME_POSTSCRIPT};
-
- /** {@inheritDoc} */
- public Renderer makeRenderer(FOUserAgent userAgent) {
- return new PSRenderer();
- }
-
- /** {@inheritDoc} */
- public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
- return new PSRendererConfigurator(userAgent);
- }
-
- /** {@inheritDoc} */
- public boolean needsOutputStream() {
- return true;
- }
-
- /** {@inheritDoc} */
- public String[] getSupportedMimeTypes() {
- return MIMES;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.ps;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+import org.apache.fop.render.RendererConfigurator;
+
+/**
+ * RendererMaker for the PostScript Renderer.
+ */
+public class PSRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_POSTSCRIPT};
+
+ /** {@inheritDoc} */
+ public Renderer makeRenderer(FOUserAgent userAgent) {
+ return new PSRenderer();
+ }
+
+ /** {@inheritDoc} */
+ public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
+ return new PSRendererConfigurator(userAgent);
+ }
+
+ /** {@inheritDoc} */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/PSRendererMaker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/ResourceHandler.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/extensions/AbstractPSExtensionElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/extensions/AbstractPSExtensionElement.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/extensions/AbstractPSExtensionElement.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/extensions/AbstractPSExtensionElement.java Thu Mar 6 05:33:44 2008
@@ -1,133 +1,133 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id: AbstractPSExtensionObject.java 426576 2006-07-28 15:44:37Z jeremias $ */
-
-package org.apache.fop.render.ps.extensions;
-
-// FOP
-import org.apache.fop.apps.FOPException;
-import org.apache.fop.fo.FONode;
-import org.apache.fop.fo.PropertyList;
-import org.apache.fop.fo.ValidationException;
-import org.apache.fop.fo.extensions.ExtensionAttachment;
-
-import org.xml.sax.Locator;
-
-/**
- * Base class for the PostScript-specific extension elements.
- */
-public abstract class AbstractPSExtensionElement extends FONode {
-
- /**
- * extension attachment
- */
- protected PSExtensionAttachment attachment;
-
- /**
- * Default constructor
- *
- * @param parent parent of this node
- * @see org.apache.fop.fo.FONode#FONode(FONode)
- */
- public AbstractPSExtensionElement(FONode parent) {
- super(parent);
- }
-
- /**
- * Blocks XSL FO's from having non-FO parents.
- *
- * @param loc location in the FO source file
- * @param nsURI namespace of incoming node
- * @param localName (e.g. "table" for "fo:table")
- * @throws ValidationException if incoming node not valid for parent
- * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
- */
- protected void validateChildNode(Locator loc, String nsURI, String localName)
- throws ValidationException {
- if (FO_URI.equals(nsURI)) {
- invalidChildError(loc, nsURI, localName);
- }
- }
-
- /**
- * Adds characters (does nothing here)
- * @param data array of characters containing text to be added
- * @param start starting array element to add
- * @param length of data array to add
- * @param pList currently applicable PropertyList
- * @param locator location in fo source file.
- * @see org.apache.fop.fo.FONode#addCharacters(char[], int, int, PropertyList, Locator)
- */
- protected void addCharacters(char[] data, int start, int length,
- PropertyList pList, Locator locator) {
- PSExtensionAttachment a = (PSExtensionAttachment)getExtensionAttachment();
- if (a.getContent() != null) {
- StringBuffer sb = new StringBuffer(a.getContent());
- sb.append(data, start, length - start);
- a.setContent(sb.toString());
- } else {
- a.setContent(new String(data, start, length - start));
- }
- }
-
- /**
- * @return a String representation of this object
- * @see org.apache.fop.fo.FONode#getNamespaceURI()
- */
- public String getNamespaceURI() {
- return PSExtensionElementMapping.NAMESPACE;
- }
-
- /**
- * @return a String representation of this object
- * @see org.apache.fop.fo.FONode#getNormalNamespacePrefix()
- */
- public String getNormalNamespacePrefix() {
- return "fox";
- }
-
- /**
- * @see org.apache.fop.fo.FONode#endOfNode()
- * @throws FOPException if there's a problem during processing
- */
- protected void endOfNode() throws FOPException {
- super.endOfNode();
- String s = ((PSExtensionAttachment)getExtensionAttachment()).getContent();
- if (s == null || s.length() == 0) {
- missingChildElementError("#PCDATA");
- }
- }
-
- /**
- * @return the extension attachment if one is created by the extension element, null otherwise.
- * @see org.apache.fop.fo.FONode#getExtensionAttachment()
- */
- public ExtensionAttachment getExtensionAttachment() {
- if (attachment == null) {
- this.attachment = (PSExtensionAttachment)instantiateExtensionAttachment();
- }
- return this.attachment;
- }
-
- /**
- * Instantiates extension attachment object
- * @return extension attachment
- */
- protected abstract ExtensionAttachment instantiateExtensionAttachment();
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.ps.extensions;
+
+// FOP
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.ValidationException;
+import org.apache.fop.fo.extensions.ExtensionAttachment;
+
+import org.xml.sax.Locator;
+
+/**
+ * Base class for the PostScript-specific extension elements.
+ */
+public abstract class AbstractPSExtensionElement extends FONode {
+
+ /**
+ * extension attachment
+ */
+ protected PSExtensionAttachment attachment;
+
+ /**
+ * Default constructor
+ *
+ * @param parent parent of this node
+ * @see org.apache.fop.fo.FONode#FONode(FONode)
+ */
+ public AbstractPSExtensionElement(FONode parent) {
+ super(parent);
+ }
+
+ /**
+ * Blocks XSL FO's from having non-FO parents.
+ *
+ * @param loc location in the FO source file
+ * @param nsURI namespace of incoming node
+ * @param localName (e.g. "table" for "fo:table")
+ * @throws ValidationException if incoming node not valid for parent
+ * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
+ */
+ protected void validateChildNode(Locator loc, String nsURI, String localName)
+ throws ValidationException {
+ if (FO_URI.equals(nsURI)) {
+ invalidChildError(loc, nsURI, localName);
+ }
+ }
+
+ /**
+ * Adds characters (does nothing here)
+ * @param data array of characters containing text to be added
+ * @param start starting array element to add
+ * @param length of data array to add
+ * @param pList currently applicable PropertyList
+ * @param locator location in fo source file.
+ * @see org.apache.fop.fo.FONode#addCharacters(char[], int, int, PropertyList, Locator)
+ */
+ protected void addCharacters(char[] data, int start, int length,
+ PropertyList pList, Locator locator) {
+ PSExtensionAttachment a = (PSExtensionAttachment)getExtensionAttachment();
+ if (a.getContent() != null) {
+ StringBuffer sb = new StringBuffer(a.getContent());
+ sb.append(data, start, length - start);
+ a.setContent(sb.toString());
+ } else {
+ a.setContent(new String(data, start, length - start));
+ }
+ }
+
+ /**
+ * @return a String representation of this object
+ * @see org.apache.fop.fo.FONode#getNamespaceURI()
+ */
+ public String getNamespaceURI() {
+ return PSExtensionElementMapping.NAMESPACE;
+ }
+
+ /**
+ * @return a String representation of this object
+ * @see org.apache.fop.fo.FONode#getNormalNamespacePrefix()
+ */
+ public String getNormalNamespacePrefix() {
+ return "fox";
+ }
+
+ /**
+ * @see org.apache.fop.fo.FONode#endOfNode()
+ * @throws FOPException if there's a problem during processing
+ */
+ protected void endOfNode() throws FOPException {
+ super.endOfNode();
+ String s = ((PSExtensionAttachment)getExtensionAttachment()).getContent();
+ if (s == null || s.length() == 0) {
+ missingChildElementError("#PCDATA");
+ }
+ }
+
+ /**
+ * @return the extension attachment if one is created by the extension element, null otherwise.
+ * @see org.apache.fop.fo.FONode#getExtensionAttachment()
+ */
+ public ExtensionAttachment getExtensionAttachment() {
+ if (attachment == null) {
+ this.attachment = (PSExtensionAttachment)instantiateExtensionAttachment();
+ }
+ return this.attachment;
+ }
+
+ /**
+ * Instantiates extension attachment object
+ * @return extension attachment
+ */
+ protected abstract ExtensionAttachment instantiateExtensionAttachment();
+}
+
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/extensions/AbstractPSExtensionElement.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/render/ps/extensions/AbstractPSExtensionElement.java
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org