git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@627367 13f79535-47bb-0310-9956-ffa450edef68tags/fop-0_95beta
@@ -1,113 +1,113 @@ | |||
/* | |||
* 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 embedding; | |||
//Java | |||
import java.io.File; | |||
import java.io.IOException; | |||
//JAXP | |||
import javax.xml.transform.Transformer; | |||
import javax.xml.transform.TransformerFactory; | |||
import javax.xml.transform.TransformerException; | |||
import javax.xml.transform.Source; | |||
import javax.xml.transform.Result; | |||
import javax.xml.transform.stream.StreamSource; | |||
import javax.xml.transform.sax.SAXResult; | |||
//Avalon | |||
import org.apache.avalon.framework.ExceptionUtil; | |||
//FOP | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.apps.Fop; | |||
import org.apache.fop.apps.FopFactory; | |||
import org.apache.fop.apps.MimeConstants; | |||
/** | |||
* This class demonstrates the use of the AWT Viewer. | |||
*/ | |||
public class ExampleAWTViewer { | |||
// configure fopFactory as desired | |||
private FopFactory fopFactory = FopFactory.newInstance(); | |||
/** | |||
* Display an FO file in the AWT Preview. | |||
* @param fo the FO file | |||
* @throws IOException In case of an I/O problem | |||
* @throws FOPException In case of a problem during layout | |||
* @throws TransformerException In case of a problem during XML processing | |||
*/ | |||
public void viewFO(File fo) | |||
throws IOException, FOPException, TransformerException { | |||
//Setup FOP | |||
Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_AWT_PREVIEW); | |||
try { | |||
//Load XSL-FO file (you can also do an XSL transformation here) | |||
TransformerFactory factory = TransformerFactory.newInstance(); | |||
Transformer transformer = factory.newTransformer(); | |||
Source src = new StreamSource(fo); | |||
Result res = new SAXResult(fop.getDefaultHandler()); | |||
transformer.transform(src, res); | |||
} catch (Exception e) { | |||
if (e instanceof FOPException) { | |||
throw (FOPException)e; | |||
} | |||
throw new FOPException(e); | |||
} | |||
} | |||
/** | |||
* Main method. | |||
* @param args the command-line arguments | |||
*/ | |||
public static void main(String[] args) { | |||
try { | |||
System.out.println("FOP ExampleAWTViewer\n"); | |||
System.out.println("Preparing..."); | |||
//Setup directories | |||
File baseDir = new File("."); | |||
File outDir = new File(baseDir, "out"); | |||
outDir.mkdirs(); | |||
//Setup input and output files | |||
File fofile = new File(baseDir, "xml/fo/helloworld.fo"); | |||
System.out.println("Input: XSL-FO (" + fofile + ")"); | |||
System.out.println("Output: AWT Viewer"); | |||
System.out.println(); | |||
System.out.println("Starting AWT Viewer..."); | |||
ExampleAWTViewer app = new ExampleAWTViewer(); | |||
app.viewFO(fofile); | |||
System.out.println("Success!"); | |||
} catch (Exception e) { | |||
System.err.println(ExceptionUtil.printStackTrace(e)); | |||
System.exit(-1); | |||
} | |||
} | |||
} | |||
/* | |||
* 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 embedding; | |||
//Java | |||
import java.io.File; | |||
import java.io.IOException; | |||
//JAXP | |||
import javax.xml.transform.Transformer; | |||
import javax.xml.transform.TransformerFactory; | |||
import javax.xml.transform.TransformerException; | |||
import javax.xml.transform.Source; | |||
import javax.xml.transform.Result; | |||
import javax.xml.transform.stream.StreamSource; | |||
import javax.xml.transform.sax.SAXResult; | |||
//Avalon | |||
import org.apache.avalon.framework.ExceptionUtil; | |||
//FOP | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.apps.Fop; | |||
import org.apache.fop.apps.FopFactory; | |||
import org.apache.fop.apps.MimeConstants; | |||
/** | |||
* This class demonstrates the use of the AWT Viewer. | |||
*/ | |||
public class ExampleAWTViewer { | |||
// configure fopFactory as desired | |||
private FopFactory fopFactory = FopFactory.newInstance(); | |||
/** | |||
* Display an FO file in the AWT Preview. | |||
* @param fo the FO file | |||
* @throws IOException In case of an I/O problem | |||
* @throws FOPException In case of a problem during layout | |||
* @throws TransformerException In case of a problem during XML processing | |||
*/ | |||
public void viewFO(File fo) | |||
throws IOException, FOPException, TransformerException { | |||
//Setup FOP | |||
Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_AWT_PREVIEW); | |||
try { | |||
//Load XSL-FO file (you can also do an XSL transformation here) | |||
TransformerFactory factory = TransformerFactory.newInstance(); | |||
Transformer transformer = factory.newTransformer(); | |||
Source src = new StreamSource(fo); | |||
Result res = new SAXResult(fop.getDefaultHandler()); | |||
transformer.transform(src, res); | |||
} catch (Exception e) { | |||
if (e instanceof FOPException) { | |||
throw (FOPException)e; | |||
} | |||
throw new FOPException(e); | |||
} | |||
} | |||
/** | |||
* Main method. | |||
* @param args the command-line arguments | |||
*/ | |||
public static void main(String[] args) { | |||
try { | |||
System.out.println("FOP ExampleAWTViewer\n"); | |||
System.out.println("Preparing..."); | |||
//Setup directories | |||
File baseDir = new File("."); | |||
File outDir = new File(baseDir, "out"); | |||
outDir.mkdirs(); | |||
//Setup input and output files | |||
File fofile = new File(baseDir, "xml/fo/helloworld.fo"); | |||
System.out.println("Input: XSL-FO (" + fofile + ")"); | |||
System.out.println("Output: AWT Viewer"); | |||
System.out.println(); | |||
System.out.println("Starting AWT Viewer..."); | |||
ExampleAWTViewer app = new ExampleAWTViewer(); | |||
app.viewFO(fofile); | |||
System.out.println("Success!"); | |||
} catch (Exception e) { | |||
System.err.println(ExceptionUtil.printStackTrace(e)); | |||
System.exit(-1); | |||
} | |||
} | |||
} |
@@ -1,127 +1,127 @@ | |||
/* | |||
* 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 embedding; | |||
// Java | |||
import java.awt.print.PrinterJob; | |||
import java.io.File; | |||
import java.io.IOException; | |||
//JAXP | |||
import javax.xml.transform.Transformer; | |||
import javax.xml.transform.TransformerFactory; | |||
import javax.xml.transform.Source; | |||
import javax.xml.transform.Result; | |||
import javax.xml.transform.stream.StreamSource; | |||
import javax.xml.transform.sax.SAXResult; | |||
// FOP | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.apps.Fop; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.apps.FopFactory; | |||
import org.apache.fop.render.print.PrintRenderer; | |||
/** | |||
* This class demonstrates printing an FO file to a PrinterJob instance. | |||
*/ | |||
public class ExampleFO2OldStylePrint { | |||
// configure fopFactory as desired | |||
private FopFactory fopFactory = FopFactory.newInstance(); | |||
/** | |||
* Prints an FO file using an old-style PrinterJob. | |||
* @param fo the FO file | |||
* @throws IOException In case of an I/O problem | |||
* @throws FOPException In case of a FOP problem | |||
*/ | |||
public void printFO(File fo) throws IOException, FOPException { | |||
//Set up PrinterJob instance | |||
PrinterJob printerJob = PrinterJob.getPrinterJob(); | |||
printerJob.setJobName("FOP Printing Example"); | |||
try { | |||
//Set up a custom user agent so we can supply our own renderer instance | |||
FOUserAgent userAgent = fopFactory.newFOUserAgent(); | |||
//Set up our own PrintRenderer instance so we can supply a special PrinterJob instance. | |||
PrintRenderer renderer = new PrintRenderer(printerJob); | |||
renderer.setUserAgent(userAgent); | |||
userAgent.setRendererOverride(renderer); | |||
// Construct fop with desired output format (here, it is set through the user agent) | |||
Fop fop = fopFactory.newFop(userAgent); | |||
// Setup JAXP using identity transformer | |||
TransformerFactory factory = TransformerFactory.newInstance(); | |||
Transformer transformer = factory.newTransformer(); // identity transformer | |||
// Setup input stream | |||
Source src = new StreamSource(fo); | |||
// Resulting SAX events (the generated FO) must be piped through to FOP | |||
Result res = new SAXResult(fop.getDefaultHandler()); | |||
// Start XSLT transformation and FOP processing | |||
transformer.transform(src, res); | |||
} catch (Exception e) { | |||
e.printStackTrace(System.err); | |||
System.exit(-1); | |||
} | |||
} | |||
/** | |||
* Main method. | |||
* @param args command-line arguments | |||
*/ | |||
public static void main(String[] args) { | |||
try { | |||
System.out.println("FOP ExampleFO2OldStylePrint\n"); | |||
System.out.println("Preparing..."); | |||
//Setup directories | |||
File baseDir = new File("."); | |||
File outDir = new File(baseDir, "out"); | |||
outDir.mkdirs(); | |||
//Setup input and output files | |||
File fofile = new File(baseDir, "xml/fo/helloworld.fo"); | |||
System.out.println("Input: XSL-FO (" + fofile + ")"); | |||
System.out.println("Output: old-style printing using PrinterJob"); | |||
System.out.println(); | |||
System.out.println("Transforming..."); | |||
ExampleFO2OldStylePrint app = new ExampleFO2OldStylePrint(); | |||
app.printFO(fofile); | |||
System.out.println("Success!"); | |||
} catch (Exception e) { | |||
e.printStackTrace(System.err); | |||
System.exit(-1); | |||
} | |||
} | |||
} | |||
/* | |||
* 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 embedding; | |||
// Java | |||
import java.awt.print.PrinterJob; | |||
import java.io.File; | |||
import java.io.IOException; | |||
//JAXP | |||
import javax.xml.transform.Transformer; | |||
import javax.xml.transform.TransformerFactory; | |||
import javax.xml.transform.Source; | |||
import javax.xml.transform.Result; | |||
import javax.xml.transform.stream.StreamSource; | |||
import javax.xml.transform.sax.SAXResult; | |||
// FOP | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.apps.Fop; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.apps.FopFactory; | |||
import org.apache.fop.render.print.PrintRenderer; | |||
/** | |||
* This class demonstrates printing an FO file to a PrinterJob instance. | |||
*/ | |||
public class ExampleFO2OldStylePrint { | |||
// configure fopFactory as desired | |||
private FopFactory fopFactory = FopFactory.newInstance(); | |||
/** | |||
* Prints an FO file using an old-style PrinterJob. | |||
* @param fo the FO file | |||
* @throws IOException In case of an I/O problem | |||
* @throws FOPException In case of a FOP problem | |||
*/ | |||
public void printFO(File fo) throws IOException, FOPException { | |||
//Set up PrinterJob instance | |||
PrinterJob printerJob = PrinterJob.getPrinterJob(); | |||
printerJob.setJobName("FOP Printing Example"); | |||
try { | |||
//Set up a custom user agent so we can supply our own renderer instance | |||
FOUserAgent userAgent = fopFactory.newFOUserAgent(); | |||
//Set up our own PrintRenderer instance so we can supply a special PrinterJob instance. | |||
PrintRenderer renderer = new PrintRenderer(printerJob); | |||
renderer.setUserAgent(userAgent); | |||
userAgent.setRendererOverride(renderer); | |||
// Construct fop with desired output format (here, it is set through the user agent) | |||
Fop fop = fopFactory.newFop(userAgent); | |||
// Setup JAXP using identity transformer | |||
TransformerFactory factory = TransformerFactory.newInstance(); | |||
Transformer transformer = factory.newTransformer(); // identity transformer | |||
// Setup input stream | |||
Source src = new StreamSource(fo); | |||
// Resulting SAX events (the generated FO) must be piped through to FOP | |||
Result res = new SAXResult(fop.getDefaultHandler()); | |||
// Start XSLT transformation and FOP processing | |||
transformer.transform(src, res); | |||
} catch (Exception e) { | |||
e.printStackTrace(System.err); | |||
System.exit(-1); | |||
} | |||
} | |||
/** | |||
* Main method. | |||
* @param args command-line arguments | |||
*/ | |||
public static void main(String[] args) { | |||
try { | |||
System.out.println("FOP ExampleFO2OldStylePrint\n"); | |||
System.out.println("Preparing..."); | |||
//Setup directories | |||
File baseDir = new File("."); | |||
File outDir = new File(baseDir, "out"); | |||
outDir.mkdirs(); | |||
//Setup input and output files | |||
File fofile = new File(baseDir, "xml/fo/helloworld.fo"); | |||
System.out.println("Input: XSL-FO (" + fofile + ")"); | |||
System.out.println("Output: old-style printing using PrinterJob"); | |||
System.out.println(); | |||
System.out.println("Transforming..."); | |||
ExampleFO2OldStylePrint app = new ExampleFO2OldStylePrint(); | |||
app.printFO(fofile); | |||
System.out.println("Success!"); | |||
} catch (Exception e) { | |||
e.printStackTrace(System.err); | |||
System.exit(-1); | |||
} | |||
} | |||
} |
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: ExampleDOM2PDF.java 332791 2005-11-12 15:58:07Z jeremias $ */ | |||
/* $Id$ */ | |||
package embedding.intermediate; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: ExampleDOM2PDF.java 332791 2005-11-12 15:58:07Z jeremias $ */ | |||
/* $Id$ */ | |||
package embedding.intermediate; | |||
@@ -1,4 +1,7 @@ | |||
#!/bin/sh | |||
find . -name \*.java -or -name \*.xml -exec svn ps svn:keywords "Revision Id" '{}' \; | |||
find . -name \*.java -or -name \*.xml -exec svn ps svn:eol-style native '{}' \; | |||
find . -name \*.java -exec svn ps svn:keywords "Id" '{}' \; | |||
find . -name \*.xml -exec svn ps svn:keywords "Revision Id" '{}' \; | |||
find . -name \*.java -exec svn ps svn:eol-style native '{}' \; | |||
find . -name \*.xml -exec svn ps svn:eol-style native '{}' \; | |||
@@ -41,7 +41,7 @@ public final class Version { | |||
if (version == null) { | |||
//Fallback if FOP is used in a development environment | |||
String headURL | |||
= "$HeadURL$"; | |||
= "$HeadURL: http://svn.apache.org/repos/asf/xmlgraphics/fop/trunk/src/java/org/apache/fop/Version.java $"; | |||
version = headURL; | |||
final String pathPrefix = "/xmlgraphics/fop/"; | |||
int pos = version.indexOf(pathPrefix); |
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.apps; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.apps; | |||
@@ -1,85 +1,85 @@ | |||
/* | |||
* 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.apps; | |||
import java.util.List; | |||
import org.apache.fop.fo.pagination.AbstractPageSequence; | |||
/** | |||
* Class for reporting back formatting results to the calling application. | |||
*/ | |||
public class FormattingResults { | |||
private int pageCount = 0; | |||
private List pageSequences = null; | |||
/** | |||
* Constructor for the FormattingResults object | |||
*/ | |||
public FormattingResults() { | |||
} | |||
/** | |||
* Gets the number of pages rendered | |||
* | |||
* @return The number of pages overall | |||
*/ | |||
public int getPageCount() { | |||
return this.pageCount; | |||
} | |||
/** | |||
* Gets the results for the individual page-sequences. | |||
* | |||
* @return A List with PageSequenceResults objects | |||
*/ | |||
public List getPageSequences() { | |||
return this.pageSequences; | |||
} | |||
/** | |||
* Resets this object | |||
*/ | |||
public void reset() { | |||
this.pageCount = 0; | |||
if (this.pageSequences != null) { | |||
this.pageSequences.clear(); | |||
} | |||
} | |||
/** | |||
* Reports the result of one page sequence rendering | |||
* back into this object. | |||
* | |||
* @param pageSequence the page sequence which just completed rendering | |||
* @param pageCount the number of pages rendered for that PageSequence | |||
*/ | |||
public void haveFormattedPageSequence(AbstractPageSequence pageSequence, int pageCount) { | |||
this.pageCount += pageCount; | |||
if (this.pageSequences == null) { | |||
this.pageSequences = new java.util.ArrayList(); | |||
} | |||
this.pageSequences.add( | |||
new PageSequenceResults(pageSequence.getId(), | |||
pageCount)); | |||
} | |||
} | |||
/* | |||
* 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.apps; | |||
import java.util.List; | |||
import org.apache.fop.fo.pagination.AbstractPageSequence; | |||
/** | |||
* Class for reporting back formatting results to the calling application. | |||
*/ | |||
public class FormattingResults { | |||
private int pageCount = 0; | |||
private List pageSequences = null; | |||
/** | |||
* Constructor for the FormattingResults object | |||
*/ | |||
public FormattingResults() { | |||
} | |||
/** | |||
* Gets the number of pages rendered | |||
* | |||
* @return The number of pages overall | |||
*/ | |||
public int getPageCount() { | |||
return this.pageCount; | |||
} | |||
/** | |||
* Gets the results for the individual page-sequences. | |||
* | |||
* @return A List with PageSequenceResults objects | |||
*/ | |||
public List getPageSequences() { | |||
return this.pageSequences; | |||
} | |||
/** | |||
* Resets this object | |||
*/ | |||
public void reset() { | |||
this.pageCount = 0; | |||
if (this.pageSequences != null) { | |||
this.pageSequences.clear(); | |||
} | |||
} | |||
/** | |||
* Reports the result of one page sequence rendering | |||
* back into this object. | |||
* | |||
* @param pageSequence the page sequence which just completed rendering | |||
* @param pageCount the number of pages rendered for that PageSequence | |||
*/ | |||
public void haveFormattedPageSequence(AbstractPageSequence pageSequence, int pageCount) { | |||
this.pageCount += pageCount; | |||
if (this.pageSequences == null) { | |||
this.pageSequences = new java.util.ArrayList(); | |||
} | |||
this.pageSequences.add( | |||
new PageSequenceResults(pageSequence.getId(), | |||
pageCount)); | |||
} | |||
} | |||
@@ -1,80 +1,80 @@ | |||
/* | |||
* 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.apps; | |||
/** | |||
* Frequently used MIME types for various file formats used when working with Apache FOP. | |||
*/ | |||
public interface MimeConstants { | |||
/** Portable Document Format */ | |||
String MIME_PDF = "application/pdf"; | |||
/** PostScript */ | |||
String MIME_POSTSCRIPT = "application/postscript"; | |||
/** Encapsulated PostScript (same MIME type as PostScript) */ | |||
String MIME_EPS = MIME_POSTSCRIPT; | |||
/** HP's PCL */ | |||
String MIME_PCL = "application/x-pcl"; | |||
/** HP's PCL (alternative MIME type) */ | |||
String MIME_PCL_ALT = "application/vnd.hp-PCL"; | |||
/** IBM's AFP */ | |||
String MIME_AFP = "application/x-afp"; | |||
/** IBM's AFP (alternative MIME type) */ | |||
String MIME_AFP_ALT = "application/vnd.ibm.modcap"; | |||
/** Plain text */ | |||
String MIME_PLAIN_TEXT = "text/plain"; | |||
/** Rich text format */ | |||
String MIME_RTF = "application/rtf"; | |||
/** Rich text format (alternative 1) */ | |||
String MIME_RTF_ALT1 = "text/richtext"; | |||
/** Rich text format (alternative 2) */ | |||
String MIME_RTF_ALT2 = "text/rtf"; | |||
/** FrameMaker's MIF */ | |||
String MIME_MIF = "application/mif"; | |||
/** Structured Vector Graphics */ | |||
String MIME_SVG = "image/svg+xml"; | |||
/** GIF images */ | |||
String MIME_GIF = "image/gif"; | |||
/** PNG images */ | |||
String MIME_PNG = "image/png"; | |||
/** JPEG images */ | |||
String MIME_JPEG = "image/jpeg"; | |||
/** TIFF images */ | |||
String MIME_TIFF = "image/tiff"; | |||
/** Apache FOP's AWT preview (non-standard MIME type) */ | |||
String MIME_FOP_AWT_PREVIEW = "application/X-fop-awt-preview"; | |||
/** Apache FOP's Direct Printing (non-standard MIME type) */ | |||
String MIME_FOP_PRINT = "application/X-fop-print"; | |||
/** Apache FOP's area tree XML */ | |||
String MIME_FOP_AREA_TREE = "application/X-fop-areatree"; | |||
/** Proposed but non-registered MIME type for XSL-FO */ | |||
String MIME_XSL_FO = "text/xsl"; | |||
} | |||
/* | |||
* 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.apps; | |||
/** | |||
* Frequently used MIME types for various file formats used when working with Apache FOP. | |||
*/ | |||
public interface MimeConstants { | |||
/** Portable Document Format */ | |||
String MIME_PDF = "application/pdf"; | |||
/** PostScript */ | |||
String MIME_POSTSCRIPT = "application/postscript"; | |||
/** Encapsulated PostScript (same MIME type as PostScript) */ | |||
String MIME_EPS = MIME_POSTSCRIPT; | |||
/** HP's PCL */ | |||
String MIME_PCL = "application/x-pcl"; | |||
/** HP's PCL (alternative MIME type) */ | |||
String MIME_PCL_ALT = "application/vnd.hp-PCL"; | |||
/** IBM's AFP */ | |||
String MIME_AFP = "application/x-afp"; | |||
/** IBM's AFP (alternative MIME type) */ | |||
String MIME_AFP_ALT = "application/vnd.ibm.modcap"; | |||
/** Plain text */ | |||
String MIME_PLAIN_TEXT = "text/plain"; | |||
/** Rich text format */ | |||
String MIME_RTF = "application/rtf"; | |||
/** Rich text format (alternative 1) */ | |||
String MIME_RTF_ALT1 = "text/richtext"; | |||
/** Rich text format (alternative 2) */ | |||
String MIME_RTF_ALT2 = "text/rtf"; | |||
/** FrameMaker's MIF */ | |||
String MIME_MIF = "application/mif"; | |||
/** Structured Vector Graphics */ | |||
String MIME_SVG = "image/svg+xml"; | |||
/** GIF images */ | |||
String MIME_GIF = "image/gif"; | |||
/** PNG images */ | |||
String MIME_PNG = "image/png"; | |||
/** JPEG images */ | |||
String MIME_JPEG = "image/jpeg"; | |||
/** TIFF images */ | |||
String MIME_TIFF = "image/tiff"; | |||
/** Apache FOP's AWT preview (non-standard MIME type) */ | |||
String MIME_FOP_AWT_PREVIEW = "application/X-fop-awt-preview"; | |||
/** Apache FOP's Direct Printing (non-standard MIME type) */ | |||
String MIME_FOP_PRINT = "application/X-fop-print"; | |||
/** Apache FOP's area tree XML */ | |||
String MIME_FOP_AREA_TREE = "application/X-fop-areatree"; | |||
/** Proposed but non-registered MIME type for XSL-FO */ | |||
String MIME_XSL_FO = "text/xsl"; | |||
} |
@@ -1,59 +1,59 @@ | |||
/* | |||
* 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.apps; | |||
/** | |||
* Class for reporting back formatting results to the calling application. This | |||
* particular class is used to report the results of a single page-sequence. | |||
*/ | |||
public class PageSequenceResults { | |||
private String id; | |||
private int pageCount; | |||
/** | |||
* Constructor for the PageSequenceResults object | |||
* | |||
* @param id ID of the page-sequence, if available | |||
* @param pageCount The number of resulting pages | |||
*/ | |||
public PageSequenceResults(String id, int pageCount) { | |||
this.id = id; | |||
this.pageCount = pageCount; | |||
} | |||
/** | |||
* Gets the ID of the page-sequence if one was specified. | |||
* | |||
* @return The ID | |||
*/ | |||
public String getID() { | |||
return this.id; | |||
} | |||
/** | |||
* Gets the number of pages that resulted by processing the page-sequence. | |||
* | |||
* @return The number of pages generated | |||
*/ | |||
public int getPageCount() { | |||
return this.pageCount; | |||
} | |||
} | |||
/* | |||
* 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.apps; | |||
/** | |||
* Class for reporting back formatting results to the calling application. This | |||
* particular class is used to report the results of a single page-sequence. | |||
*/ | |||
public class PageSequenceResults { | |||
private String id; | |||
private int pageCount; | |||
/** | |||
* Constructor for the PageSequenceResults object | |||
* | |||
* @param id ID of the page-sequence, if available | |||
* @param pageCount The number of resulting pages | |||
*/ | |||
public PageSequenceResults(String id, int pageCount) { | |||
this.id = id; | |||
this.pageCount = pageCount; | |||
} | |||
/** | |||
* Gets the ID of the page-sequence if one was specified. | |||
* | |||
* @return The ID | |||
*/ | |||
public String getID() { | |||
return this.id; | |||
} | |||
/** | |||
* Gets the number of pages that resulted by processing the page-sequence. | |||
* | |||
* @return The number of pages generated | |||
*/ | |||
public int getPageCount() { | |||
return this.pageCount; | |||
} | |||
} |
@@ -1,59 +1,59 @@ | |||
/* | |||
* 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.area.inline; | |||
/** | |||
* A space | |||
*/ | |||
public class SpaceArea extends InlineArea { | |||
/** | |||
* The space for this space area | |||
*/ | |||
protected String space; | |||
/** | |||
* Is this space adjustable? | |||
*/ | |||
protected boolean isAdjustable; | |||
/** | |||
* Create a space area | |||
* @param s the space character | |||
* @param o the offset for the next area | |||
* @param a is this space adjustable? | |||
*/ | |||
public SpaceArea(char s, int o, boolean a) { | |||
space = new String() + s; | |||
offset = o; | |||
isAdjustable = a; | |||
} | |||
/** | |||
* @return Returns the space. | |||
*/ | |||
public String getSpace() { | |||
return new String(space); | |||
} | |||
/** @return true if the space is adjustable (WRT word-space processing) */ | |||
public boolean isAdjustable() { | |||
return this.isAdjustable; | |||
} | |||
} | |||
/* | |||
* 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.area.inline; | |||
/** | |||
* A space | |||
*/ | |||
public class SpaceArea extends InlineArea { | |||
/** | |||
* The space for this space area | |||
*/ | |||
protected String space; | |||
/** | |||
* Is this space adjustable? | |||
*/ | |||
protected boolean isAdjustable; | |||
/** | |||
* Create a space area | |||
* @param s the space character | |||
* @param o the offset for the next area | |||
* @param a is this space adjustable? | |||
*/ | |||
public SpaceArea(char s, int o, boolean a) { | |||
space = new String() + s; | |||
offset = o; | |||
isAdjustable = a; | |||
} | |||
/** | |||
* @return Returns the space. | |||
*/ | |||
public String getSpace() { | |||
return new String(space); | |||
} | |||
/** @return true if the space is adjustable (WRT word-space processing) */ | |||
public boolean isAdjustable() { | |||
return this.isAdjustable; | |||
} | |||
} |
@@ -1,72 +1,72 @@ | |||
/* | |||
* 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.area.inline; | |||
/** | |||
* A string of characters without spaces | |||
*/ | |||
public class WordArea extends InlineArea { | |||
/** The text for this word area */ | |||
protected String word; | |||
/** The correction offset for the next area */ | |||
protected int offset = 0; | |||
/** An array of width for adjusting the individual letters (optional) */ | |||
protected int[] letterAdjust; | |||
/** | |||
* Create a word area | |||
* @param w the word string | |||
* @param o the offset for the next area | |||
* @param la the letter adjust array (may be null) | |||
*/ | |||
public WordArea(String w, int o, int[] la) { | |||
word = w; | |||
offset = o; | |||
this.letterAdjust = la; | |||
} | |||
/** | |||
* @return Returns the word. | |||
*/ | |||
public String getWord() { | |||
return word; | |||
} | |||
/** | |||
* @return Returns the offset. | |||
*/ | |||
public int getOffset() { | |||
return offset; | |||
} | |||
/** | |||
* @param o The offset to set. | |||
*/ | |||
public void setOffset(int o) { | |||
offset = o; | |||
} | |||
/** @return the array of letter adjust widths */ | |||
public int[] getLetterAdjustArray() { | |||
return this.letterAdjust; | |||
} | |||
} | |||
/* | |||
* 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.area.inline; | |||
/** | |||
* A string of characters without spaces | |||
*/ | |||
public class WordArea extends InlineArea { | |||
/** The text for this word area */ | |||
protected String word; | |||
/** The correction offset for the next area */ | |||
protected int offset = 0; | |||
/** An array of width for adjusting the individual letters (optional) */ | |||
protected int[] letterAdjust; | |||
/** | |||
* Create a word area | |||
* @param w the word string | |||
* @param o the offset for the next area | |||
* @param la the letter adjust array (may be null) | |||
*/ | |||
public WordArea(String w, int o, int[] la) { | |||
word = w; | |||
offset = o; | |||
this.letterAdjust = la; | |||
} | |||
/** | |||
* @return Returns the word. | |||
*/ | |||
public String getWord() { | |||
return word; | |||
} | |||
/** | |||
* @return Returns the offset. | |||
*/ | |||
public int getOffset() { | |||
return offset; | |||
} | |||
/** | |||
* @param o The offset to set. | |||
*/ | |||
public void setOffset(int o) { | |||
offset = o; | |||
} | |||
/** @return the array of letter adjust widths */ | |||
public int[] getLetterAdjustArray() { | |||
return this.letterAdjust; | |||
} | |||
} |
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: ColorTypeProperty.java 377045 2006-02-11 20:23:47Z jeremias $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.fo.properties; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.fonts; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.fonts; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.fonts.autodetect; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.fonts.autodetect; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.fonts.autodetect; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.fonts.autodetect; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.fonts.autodetect; | |||
@@ -1,129 +1,129 @@ | |||
/* | |||
* 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.fonts.truetype; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.Map; | |||
import org.apache.fop.fonts.BFEntry; | |||
import org.apache.fop.fonts.CIDFontType; | |||
import org.apache.fop.fonts.FontLoader; | |||
import org.apache.fop.fonts.FontResolver; | |||
import org.apache.fop.fonts.MultiByteFont; | |||
/** | |||
* Loads a font into memory directly from the original font file. | |||
*/ | |||
public class TTFFontLoader extends FontLoader { | |||
private MultiByteFont multiFont; | |||
/** | |||
* Default constructor | |||
* @param fontFileURI the URI representing the font file | |||
* @param in the InputStream to load the font from | |||
* @param resolver the FontResolver for font URI resolution | |||
*/ | |||
public TTFFontLoader(String fontFileURI, InputStream in, FontResolver resolver) { | |||
super(fontFileURI, in, resolver); | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
protected void read() throws IOException { | |||
TTFFile ttf = new TTFFile(); | |||
FontFileReader reader = new FontFileReader(in); | |||
boolean supported = ttf.readFont(reader, null); | |||
if (!supported) { | |||
throw new IOException("Could not load TrueType font: " + fontFileURI); | |||
} | |||
if (ttf.isCFF()) { | |||
throw new UnsupportedOperationException( | |||
"OpenType fonts with CFF data are not supported, yet"); | |||
} | |||
multiFont = new MultiByteFont(); | |||
multiFont.setResolver(this.resolver); | |||
returnFont = multiFont; | |||
returnFont.setFontName(ttf.getPostScriptName()); | |||
returnFont.setFullName(ttf.getFullName()); | |||
returnFont.setFamilyNames(ttf.getFamilyNames()); | |||
returnFont.setFontSubFamilyName(ttf.getSubFamilyName()); | |||
//multiFont.setTTCName(ttcName) | |||
returnFont.setCapHeight(ttf.getCapHeight()); | |||
returnFont.setXHeight(ttf.getXHeight()); | |||
returnFont.setAscender(ttf.getLowerCaseAscent()); | |||
returnFont.setDescender(ttf.getLowerCaseDescent()); | |||
returnFont.setFontBBox(ttf.getFontBBox()); | |||
//returnFont.setFirstChar(ttf.getFirstChar();) | |||
returnFont.setFlags(ttf.getFlags()); | |||
returnFont.setStemV(Integer.parseInt(ttf.getStemV())); //not used for TTF | |||
returnFont.setItalicAngle(Integer.parseInt(ttf.getItalicAngle())); | |||
returnFont.setMissingWidth(0); | |||
multiFont.setCIDType(CIDFontType.CIDTYPE2); | |||
int[] wx = ttf.getWidths(); | |||
multiFont.setWidthArray(wx); | |||
List entries = ttf.getCMaps(); | |||
BFEntry[] bfentries = new BFEntry[entries.size()]; | |||
int pos = 0; | |||
Iterator iter = ttf.getCMaps().listIterator(); | |||
while (iter.hasNext()) { | |||
TTFCmapEntry ce = (TTFCmapEntry)iter.next(); | |||
bfentries[pos] = new BFEntry(ce.getUnicodeStart(), ce.getUnicodeEnd(), | |||
ce.getGlyphStartIndex()); | |||
pos++; | |||
} | |||
multiFont.setBFEntries(bfentries); | |||
copyKerning(ttf, true); | |||
multiFont.setEmbedFileName(this.fontFileURI); | |||
loaded = true; | |||
} | |||
/** | |||
* Copy kerning information. | |||
*/ | |||
private void copyKerning(TTFFile ttf, boolean isCid) { | |||
// Get kerning | |||
Iterator iter; | |||
if (isCid) { | |||
iter = ttf.getKerning().keySet().iterator(); | |||
} else { | |||
iter = ttf.getAnsiKerning().keySet().iterator(); | |||
} | |||
while (iter.hasNext()) { | |||
Integer kpx1 = (Integer)iter.next(); | |||
Map h2; | |||
if (isCid) { | |||
h2 = (Map)ttf.getKerning().get(kpx1); | |||
} else { | |||
h2 = (Map)ttf.getAnsiKerning().get(kpx1); | |||
} | |||
returnFont.putKerningEntry(kpx1, h2); | |||
} | |||
} | |||
} | |||
/* | |||
* 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.fonts.truetype; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.Map; | |||
import org.apache.fop.fonts.BFEntry; | |||
import org.apache.fop.fonts.CIDFontType; | |||
import org.apache.fop.fonts.FontLoader; | |||
import org.apache.fop.fonts.FontResolver; | |||
import org.apache.fop.fonts.MultiByteFont; | |||
/** | |||
* Loads a font into memory directly from the original font file. | |||
*/ | |||
public class TTFFontLoader extends FontLoader { | |||
private MultiByteFont multiFont; | |||
/** | |||
* Default constructor | |||
* @param fontFileURI the URI representing the font file | |||
* @param in the InputStream to load the font from | |||
* @param resolver the FontResolver for font URI resolution | |||
*/ | |||
public TTFFontLoader(String fontFileURI, InputStream in, FontResolver resolver) { | |||
super(fontFileURI, in, resolver); | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
protected void read() throws IOException { | |||
TTFFile ttf = new TTFFile(); | |||
FontFileReader reader = new FontFileReader(in); | |||
boolean supported = ttf.readFont(reader, null); | |||
if (!supported) { | |||
throw new IOException("Could not load TrueType font: " + fontFileURI); | |||
} | |||
if (ttf.isCFF()) { | |||
throw new UnsupportedOperationException( | |||
"OpenType fonts with CFF data are not supported, yet"); | |||
} | |||
multiFont = new MultiByteFont(); | |||
multiFont.setResolver(this.resolver); | |||
returnFont = multiFont; | |||
returnFont.setFontName(ttf.getPostScriptName()); | |||
returnFont.setFullName(ttf.getFullName()); | |||
returnFont.setFamilyNames(ttf.getFamilyNames()); | |||
returnFont.setFontSubFamilyName(ttf.getSubFamilyName()); | |||
//multiFont.setTTCName(ttcName) | |||
returnFont.setCapHeight(ttf.getCapHeight()); | |||
returnFont.setXHeight(ttf.getXHeight()); | |||
returnFont.setAscender(ttf.getLowerCaseAscent()); | |||
returnFont.setDescender(ttf.getLowerCaseDescent()); | |||
returnFont.setFontBBox(ttf.getFontBBox()); | |||
//returnFont.setFirstChar(ttf.getFirstChar();) | |||
returnFont.setFlags(ttf.getFlags()); | |||
returnFont.setStemV(Integer.parseInt(ttf.getStemV())); //not used for TTF | |||
returnFont.setItalicAngle(Integer.parseInt(ttf.getItalicAngle())); | |||
returnFont.setMissingWidth(0); | |||
multiFont.setCIDType(CIDFontType.CIDTYPE2); | |||
int[] wx = ttf.getWidths(); | |||
multiFont.setWidthArray(wx); | |||
List entries = ttf.getCMaps(); | |||
BFEntry[] bfentries = new BFEntry[entries.size()]; | |||
int pos = 0; | |||
Iterator iter = ttf.getCMaps().listIterator(); | |||
while (iter.hasNext()) { | |||
TTFCmapEntry ce = (TTFCmapEntry)iter.next(); | |||
bfentries[pos] = new BFEntry(ce.getUnicodeStart(), ce.getUnicodeEnd(), | |||
ce.getGlyphStartIndex()); | |||
pos++; | |||
} | |||
multiFont.setBFEntries(bfentries); | |||
copyKerning(ttf, true); | |||
multiFont.setEmbedFileName(this.fontFileURI); | |||
loaded = true; | |||
} | |||
/** | |||
* Copy kerning information. | |||
*/ | |||
private void copyKerning(TTFFile ttf, boolean isCid) { | |||
// Get kerning | |||
Iterator iter; | |||
if (isCid) { | |||
iter = ttf.getKerning().keySet().iterator(); | |||
} else { | |||
iter = ttf.getAnsiKerning().keySet().iterator(); | |||
} | |||
while (iter.hasNext()) { | |||
Integer kpx1 = (Integer)iter.next(); | |||
Map h2; | |||
if (isCid) { | |||
h2 = (Map)ttf.getKerning().get(kpx1); | |||
} else { | |||
h2 = (Map)ttf.getAnsiKerning().get(kpx1); | |||
} | |||
returnFont.putKerningEntry(kpx1, h2); | |||
} | |||
} | |||
} |
@@ -1,92 +1,92 @@ | |||
/* | |||
* 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.fonts.type1; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.util.Set; | |||
import org.apache.fop.fonts.FontLoader; | |||
import org.apache.fop.fonts.FontResolver; | |||
import org.apache.fop.fonts.FontType; | |||
import org.apache.fop.fonts.SingleByteFont; | |||
/** | |||
* Loads a Type 1 font into memory directly from the original font file. | |||
*/ | |||
public class Type1FontLoader extends FontLoader { | |||
private PFMFile pfm; | |||
private SingleByteFont singleFont; | |||
/** | |||
* Constructs a new Type 1 font loader. | |||
* @param fontFileURI the URI to the PFB file of a Type 1 font | |||
* @param in the InputStream reading the PFM file of a Type 1 font | |||
* @param resolver the font resolver used to resolve URIs | |||
* @throws IOException In case of an I/O error | |||
*/ | |||
public Type1FontLoader(String fontFileURI, InputStream in, FontResolver resolver) | |||
throws IOException { | |||
super(fontFileURI, in, resolver); | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
protected void read() throws IOException { | |||
pfm = new PFMFile(); | |||
pfm.load(in); | |||
singleFont = new SingleByteFont(); | |||
singleFont.setFontType(FontType.TYPE1); | |||
if (pfm.getCharSet() >= 0 && pfm.getCharSet() <= 2) { | |||
singleFont.setEncoding(pfm.getCharSetName() + "Encoding"); | |||
} else { | |||
log.warn("The PFM reports an unsupported encoding (" | |||
+ pfm.getCharSetName() + "). The font may not work as expected."); | |||
singleFont.setEncoding("WinAnsiEncoding"); //Try fallback, no guarantees! | |||
} | |||
singleFont.setResolver(this.resolver); | |||
returnFont = singleFont; | |||
returnFont.setFontName(pfm.getPostscriptName()); | |||
String fullName = pfm.getPostscriptName(); | |||
fullName = fullName.replace('-', ' '); //Hack! Try to emulate full name | |||
returnFont.setFullName(fullName); //should be afm.getFullName()!! | |||
//TODO not accurate: we need FullName from the AFM file but we don't have an AFM parser | |||
Set names = new java.util.HashSet(); | |||
names.add(pfm.getWindowsName()); //should be afm.getFamilyName()!! | |||
returnFont.setFamilyNames(names); | |||
returnFont.setCapHeight(pfm.getCapHeight()); | |||
returnFont.setXHeight(pfm.getXHeight()); | |||
returnFont.setAscender(pfm.getLowerCaseAscent()); | |||
returnFont.setDescender(pfm.getLowerCaseDescent()); | |||
returnFont.setFontBBox(pfm.getFontBBox()); | |||
returnFont.setFirstChar(pfm.getFirstChar()); | |||
returnFont.setLastChar(pfm.getLastChar()); | |||
returnFont.setFlags(pfm.getFlags()); | |||
returnFont.setStemV(pfm.getStemV()); | |||
returnFont.setItalicAngle(pfm.getItalicAngle()); | |||
returnFont.setMissingWidth(0); | |||
for (short i = pfm.getFirstChar(); i <= pfm.getLastChar(); i++) { | |||
singleFont.setWidth(i, pfm.getCharWidth(i)); | |||
} | |||
singleFont.setEmbedFileName(this.fontFileURI); | |||
} | |||
} | |||
/* | |||
* 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.fonts.type1; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.util.Set; | |||
import org.apache.fop.fonts.FontLoader; | |||
import org.apache.fop.fonts.FontResolver; | |||
import org.apache.fop.fonts.FontType; | |||
import org.apache.fop.fonts.SingleByteFont; | |||
/** | |||
* Loads a Type 1 font into memory directly from the original font file. | |||
*/ | |||
public class Type1FontLoader extends FontLoader { | |||
private PFMFile pfm; | |||
private SingleByteFont singleFont; | |||
/** | |||
* Constructs a new Type 1 font loader. | |||
* @param fontFileURI the URI to the PFB file of a Type 1 font | |||
* @param in the InputStream reading the PFM file of a Type 1 font | |||
* @param resolver the font resolver used to resolve URIs | |||
* @throws IOException In case of an I/O error | |||
*/ | |||
public Type1FontLoader(String fontFileURI, InputStream in, FontResolver resolver) | |||
throws IOException { | |||
super(fontFileURI, in, resolver); | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
protected void read() throws IOException { | |||
pfm = new PFMFile(); | |||
pfm.load(in); | |||
singleFont = new SingleByteFont(); | |||
singleFont.setFontType(FontType.TYPE1); | |||
if (pfm.getCharSet() >= 0 && pfm.getCharSet() <= 2) { | |||
singleFont.setEncoding(pfm.getCharSetName() + "Encoding"); | |||
} else { | |||
log.warn("The PFM reports an unsupported encoding (" | |||
+ pfm.getCharSetName() + "). The font may not work as expected."); | |||
singleFont.setEncoding("WinAnsiEncoding"); //Try fallback, no guarantees! | |||
} | |||
singleFont.setResolver(this.resolver); | |||
returnFont = singleFont; | |||
returnFont.setFontName(pfm.getPostscriptName()); | |||
String fullName = pfm.getPostscriptName(); | |||
fullName = fullName.replace('-', ' '); //Hack! Try to emulate full name | |||
returnFont.setFullName(fullName); //should be afm.getFullName()!! | |||
//TODO not accurate: we need FullName from the AFM file but we don't have an AFM parser | |||
Set names = new java.util.HashSet(); | |||
names.add(pfm.getWindowsName()); //should be afm.getFamilyName()!! | |||
returnFont.setFamilyNames(names); | |||
returnFont.setCapHeight(pfm.getCapHeight()); | |||
returnFont.setXHeight(pfm.getXHeight()); | |||
returnFont.setAscender(pfm.getLowerCaseAscent()); | |||
returnFont.setDescender(pfm.getLowerCaseDescent()); | |||
returnFont.setFontBBox(pfm.getFontBBox()); | |||
returnFont.setFirstChar(pfm.getFirstChar()); | |||
returnFont.setLastChar(pfm.getLastChar()); | |||
returnFont.setFlags(pfm.getFlags()); | |||
returnFont.setStemV(pfm.getStemV()); | |||
returnFont.setItalicAngle(pfm.getItalicAngle()); | |||
returnFont.setMissingWidth(0); | |||
for (short i = pfm.getFirstChar(); i <= pfm.getLastChar(); i++) { | |||
singleFont.setWidth(i, pfm.getCharWidth(i)); | |||
} | |||
singleFont.setEmbedFileName(this.fontFileURI); | |||
} | |||
} |
@@ -1,51 +1,51 @@ | |||
/* | |||
* 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.image; | |||
/** | |||
* Enhanced metafile image. | |||
* This supports loading a EMF image. | |||
* | |||
* @see AbstractFopImage | |||
* @see FopImage | |||
*/ | |||
public class EmfImage extends AbstractFopImage { | |||
/** | |||
* Create a bitmap image with the image data. | |||
* | |||
* @param imgInfo the image information | |||
*/ | |||
public EmfImage(FopImage.ImageInfo imgInfo) { | |||
super(imgInfo); | |||
} | |||
/** | |||
* Load the original EMF data. | |||
* This loads the original EMF data and reads the color space, | |||
* and icc profile if any. | |||
* | |||
* @return true if loaded false for any error | |||
*/ | |||
protected boolean loadOriginalData() { | |||
return loadDefaultOriginalData(); | |||
} | |||
} | |||
/* | |||
* 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.image; | |||
/** | |||
* Enhanced metafile image. | |||
* This supports loading a EMF image. | |||
* | |||
* @see AbstractFopImage | |||
* @see FopImage | |||
*/ | |||
public class EmfImage extends AbstractFopImage { | |||
/** | |||
* Create a bitmap image with the image data. | |||
* | |||
* @param imgInfo the image information | |||
*/ | |||
public EmfImage(FopImage.ImageInfo imgInfo) { | |||
super(imgInfo); | |||
} | |||
/** | |||
* Load the original EMF data. | |||
* This loads the original EMF data and reads the color space, | |||
* and icc profile if any. | |||
* | |||
* @return true if loaded false for any error | |||
*/ | |||
protected boolean loadOriginalData() { | |||
return loadDefaultOriginalData(); | |||
} | |||
} | |||
@@ -1,162 +1,162 @@ | |||
/* | |||
* 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.image.analyser; | |||
// Java | |||
import java.io.InputStream; | |||
import java.io.IOException; | |||
// FOP | |||
import org.apache.fop.image.FopImage; | |||
import org.apache.fop.apps.FOUserAgent; | |||
/** | |||
* ImageReader object for EMF image type. | |||
* | |||
* @author Peter Herweg | |||
*/ | |||
public class EMFReader implements ImageReader { | |||
/** Length of the EMF header */ | |||
protected static final int EMF_SIG_LENGTH = 88; | |||
/** offset to signature */ | |||
private static final int SIGNATURE_OFFSET = 40; | |||
/** offset to width */ | |||
private static final int WIDTH_OFFSET = 32; | |||
/** offset to height */ | |||
private static final int HEIGHT_OFFSET = 36; | |||
/** offset to horizontal resolution in pixel */ | |||
private static final int HRES_PIXEL_OFFSET = 72; | |||
/** offset to vertical resolution in pixel */ | |||
private static final int VRES_PIXEL_OFFSET = 76; | |||
/** offset to horizontal resolution in mm */ | |||
private static final int HRES_MM_OFFSET = 80; | |||
/** offset to vertical resolution in mm */ | |||
private static final int VRES_MM_OFFSET = 84; | |||
/** {@inheritDoc} */ | |||
public FopImage.ImageInfo verifySignature(String uri, InputStream bis, | |||
FOUserAgent ua) throws IOException { | |||
byte[] header = getDefaultHeader(bis); | |||
boolean supported | |||
= ( (header[SIGNATURE_OFFSET + 0] == (byte) 0x20) | |||
&& (header[SIGNATURE_OFFSET + 1] == (byte) 0x45) | |||
&& (header[SIGNATURE_OFFSET + 2] == (byte) 0x4D) | |||
&& (header[SIGNATURE_OFFSET + 3] == (byte) 0x46) ); | |||
if (supported) { | |||
FopImage.ImageInfo info = getDimension(header); | |||
info.originalURI = uri; | |||
info.mimeType = getMimeType(); | |||
info.inputStream = bis; | |||
return info; | |||
} else { | |||
return null; | |||
} | |||
} | |||
/** | |||
* Returns the MIME type supported by this implementation. | |||
* | |||
* @return The MIME type | |||
*/ | |||
public String getMimeType() { | |||
return "image/emf"; | |||
} | |||
private FopImage.ImageInfo getDimension(byte[] header) { | |||
FopImage.ImageInfo info = new FopImage.ImageInfo(); | |||
long value = 0; | |||
int byte1; | |||
int byte2; | |||
int byte3; | |||
int byte4; | |||
// little endian notation | |||
//resolution | |||
byte1 = header[HRES_MM_OFFSET] & 0xff; | |||
byte2 = header[HRES_MM_OFFSET + 1] & 0xff; | |||
byte3 = header[HRES_MM_OFFSET + 2] & 0xff; | |||
byte4 = header[HRES_MM_OFFSET + 3] & 0xff; | |||
long hresMM = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1); | |||
byte1 = header[VRES_MM_OFFSET] & 0xff; | |||
byte2 = header[VRES_MM_OFFSET + 1] & 0xff; | |||
byte3 = header[VRES_MM_OFFSET + 2] & 0xff; | |||
byte4 = header[VRES_MM_OFFSET + 3] & 0xff; | |||
long vresMM = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1); | |||
byte1 = header[HRES_PIXEL_OFFSET] & 0xff; | |||
byte2 = header[HRES_PIXEL_OFFSET + 1] & 0xff; | |||
byte3 = header[HRES_PIXEL_OFFSET + 2] & 0xff; | |||
byte4 = header[HRES_PIXEL_OFFSET + 3] & 0xff; | |||
long hresPixel = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1); | |||
byte1 = header[VRES_PIXEL_OFFSET] & 0xff; | |||
byte2 = header[VRES_PIXEL_OFFSET + 1] & 0xff; | |||
byte3 = header[VRES_PIXEL_OFFSET + 2] & 0xff; | |||
byte4 = header[VRES_PIXEL_OFFSET + 3] & 0xff; | |||
long vresPixel = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1); | |||
info.dpiHorizontal = hresPixel / (hresMM / 25.4f); | |||
info.dpiVertical = vresPixel / (vresMM / 25.4f); | |||
//width | |||
byte1 = header[WIDTH_OFFSET] & 0xff; | |||
byte2 = header[WIDTH_OFFSET + 1] & 0xff; | |||
byte3 = header[WIDTH_OFFSET + 2] & 0xff; | |||
byte4 = header[WIDTH_OFFSET + 3] & 0xff; | |||
value = (long) ((byte4 << 24) | (byte3 << 16) | |||
| (byte2 << 8) | byte1); | |||
value = Math.round(value / 100f / 25.4f * info.dpiHorizontal); | |||
info.width = (int) (value & 0xffffffff); | |||
//height | |||
byte1 = header[HEIGHT_OFFSET] & 0xff; | |||
byte2 = header[HEIGHT_OFFSET + 1] & 0xff; | |||
byte3 = header[HEIGHT_OFFSET + 2] & 0xff; | |||
byte4 = header[HEIGHT_OFFSET + 3] & 0xff; | |||
value = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1); | |||
value = Math.round(value / 100f / 25.4f * info.dpiVertical); | |||
info.height = (int) (value & 0xffffffff); | |||
return info; | |||
} | |||
private byte[] getDefaultHeader(InputStream imageStream) | |||
throws IOException { | |||
byte[] header = new byte[EMF_SIG_LENGTH]; | |||
try { | |||
imageStream.mark(EMF_SIG_LENGTH + 1); | |||
imageStream.read(header); | |||
imageStream.reset(); | |||
} catch (IOException ex) { | |||
try { | |||
imageStream.reset(); | |||
} catch (IOException exbis) { | |||
// throw the original exception, not this one | |||
} | |||
throw ex; | |||
} | |||
return header; | |||
} | |||
} | |||
/* | |||
* 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.image.analyser; | |||
// Java | |||
import java.io.InputStream; | |||
import java.io.IOException; | |||
// FOP | |||
import org.apache.fop.image.FopImage; | |||
import org.apache.fop.apps.FOUserAgent; | |||
/** | |||
* ImageReader object for EMF image type. | |||
* | |||
* @author Peter Herweg | |||
*/ | |||
public class EMFReader implements ImageReader { | |||
/** Length of the EMF header */ | |||
protected static final int EMF_SIG_LENGTH = 88; | |||
/** offset to signature */ | |||
private static final int SIGNATURE_OFFSET = 40; | |||
/** offset to width */ | |||
private static final int WIDTH_OFFSET = 32; | |||
/** offset to height */ | |||
private static final int HEIGHT_OFFSET = 36; | |||
/** offset to horizontal resolution in pixel */ | |||
private static final int HRES_PIXEL_OFFSET = 72; | |||
/** offset to vertical resolution in pixel */ | |||
private static final int VRES_PIXEL_OFFSET = 76; | |||
/** offset to horizontal resolution in mm */ | |||
private static final int HRES_MM_OFFSET = 80; | |||
/** offset to vertical resolution in mm */ | |||
private static final int VRES_MM_OFFSET = 84; | |||
/** {@inheritDoc} */ | |||
public FopImage.ImageInfo verifySignature(String uri, InputStream bis, | |||
FOUserAgent ua) throws IOException { | |||
byte[] header = getDefaultHeader(bis); | |||
boolean supported | |||
= ( (header[SIGNATURE_OFFSET + 0] == (byte) 0x20) | |||
&& (header[SIGNATURE_OFFSET + 1] == (byte) 0x45) | |||
&& (header[SIGNATURE_OFFSET + 2] == (byte) 0x4D) | |||
&& (header[SIGNATURE_OFFSET + 3] == (byte) 0x46) ); | |||
if (supported) { | |||
FopImage.ImageInfo info = getDimension(header); | |||
info.originalURI = uri; | |||
info.mimeType = getMimeType(); | |||
info.inputStream = bis; | |||
return info; | |||
} else { | |||
return null; | |||
} | |||
} | |||
/** | |||
* Returns the MIME type supported by this implementation. | |||
* | |||
* @return The MIME type | |||
*/ | |||
public String getMimeType() { | |||
return "image/emf"; | |||
} | |||
private FopImage.ImageInfo getDimension(byte[] header) { | |||
FopImage.ImageInfo info = new FopImage.ImageInfo(); | |||
long value = 0; | |||
int byte1; | |||
int byte2; | |||
int byte3; | |||
int byte4; | |||
// little endian notation | |||
//resolution | |||
byte1 = header[HRES_MM_OFFSET] & 0xff; | |||
byte2 = header[HRES_MM_OFFSET + 1] & 0xff; | |||
byte3 = header[HRES_MM_OFFSET + 2] & 0xff; | |||
byte4 = header[HRES_MM_OFFSET + 3] & 0xff; | |||
long hresMM = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1); | |||
byte1 = header[VRES_MM_OFFSET] & 0xff; | |||
byte2 = header[VRES_MM_OFFSET + 1] & 0xff; | |||
byte3 = header[VRES_MM_OFFSET + 2] & 0xff; | |||
byte4 = header[VRES_MM_OFFSET + 3] & 0xff; | |||
long vresMM = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1); | |||
byte1 = header[HRES_PIXEL_OFFSET] & 0xff; | |||
byte2 = header[HRES_PIXEL_OFFSET + 1] & 0xff; | |||
byte3 = header[HRES_PIXEL_OFFSET + 2] & 0xff; | |||
byte4 = header[HRES_PIXEL_OFFSET + 3] & 0xff; | |||
long hresPixel = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1); | |||
byte1 = header[VRES_PIXEL_OFFSET] & 0xff; | |||
byte2 = header[VRES_PIXEL_OFFSET + 1] & 0xff; | |||
byte3 = header[VRES_PIXEL_OFFSET + 2] & 0xff; | |||
byte4 = header[VRES_PIXEL_OFFSET + 3] & 0xff; | |||
long vresPixel = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1); | |||
info.dpiHorizontal = hresPixel / (hresMM / 25.4f); | |||
info.dpiVertical = vresPixel / (vresMM / 25.4f); | |||
//width | |||
byte1 = header[WIDTH_OFFSET] & 0xff; | |||
byte2 = header[WIDTH_OFFSET + 1] & 0xff; | |||
byte3 = header[WIDTH_OFFSET + 2] & 0xff; | |||
byte4 = header[WIDTH_OFFSET + 3] & 0xff; | |||
value = (long) ((byte4 << 24) | (byte3 << 16) | |||
| (byte2 << 8) | byte1); | |||
value = Math.round(value / 100f / 25.4f * info.dpiHorizontal); | |||
info.width = (int) (value & 0xffffffff); | |||
//height | |||
byte1 = header[HEIGHT_OFFSET] & 0xff; | |||
byte2 = header[HEIGHT_OFFSET + 1] & 0xff; | |||
byte3 = header[HEIGHT_OFFSET + 2] & 0xff; | |||
byte4 = header[HEIGHT_OFFSET + 3] & 0xff; | |||
value = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1); | |||
value = Math.round(value / 100f / 25.4f * info.dpiVertical); | |||
info.height = (int) (value & 0xffffffff); | |||
return info; | |||
} | |||
private byte[] getDefaultHeader(InputStream imageStream) | |||
throws IOException { | |||
byte[] header = new byte[EMF_SIG_LENGTH]; | |||
try { | |||
imageStream.mark(EMF_SIG_LENGTH + 1); | |||
imageStream.read(header); | |||
imageStream.reset(); | |||
} catch (IOException ex) { | |||
try { | |||
imageStream.reset(); | |||
} catch (IOException exbis) { | |||
// throw the original exception, not this one | |||
} | |||
throw ex; | |||
} | |||
return header; | |||
} | |||
} |
@@ -1,107 +1,107 @@ | |||
/* | |||
* 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.layoutmgr; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogFactory; | |||
import org.apache.fop.traits.MinOptMax; | |||
/** | |||
* This is a the breaking algorithm that is responsible for balancing columns in multi-column | |||
* layout. | |||
*/ | |||
public class BalancingColumnBreakingAlgorithm extends PageBreakingAlgorithm { | |||
private Log log = LogFactory.getLog(BalancingColumnBreakingAlgorithm.class); | |||
private int columnCount; | |||
private int fullLen; | |||
private int idealPartLen; | |||
public BalancingColumnBreakingAlgorithm(LayoutManager topLevelLM, | |||
PageProvider pageProvider, | |||
PageBreakingLayoutListener layoutListener, | |||
int alignment, int alignmentLast, | |||
MinOptMax footnoteSeparatorLength, | |||
boolean partOverflowRecovery, | |||
int columnCount) { | |||
super(topLevelLM, pageProvider, layoutListener, | |||
alignment, alignmentLast, | |||
footnoteSeparatorLength, partOverflowRecovery, false, false); | |||
this.columnCount = columnCount; | |||
this.considerTooShort = true; //This is important! | |||
} | |||
/** {@inheritDoc} */ | |||
protected double computeDemerits(KnuthNode activeNode, | |||
KnuthElement element, int fitnessClass, double r) { | |||
double dem = super.computeDemerits(activeNode, element, fitnessClass, r); | |||
if (log.isTraceEnabled()) { | |||
log.trace("original demerit=" + dem + " " + totalWidth | |||
+ " line=" + activeNode.line + "/" + columnCount | |||
+ " pos=" + activeNode.position + "/" + (par.size() - 1)); | |||
} | |||
int remParts = columnCount - activeNode.line; | |||
int curPos = par.indexOf(element); | |||
if (fullLen == 0) { | |||
fullLen = ElementListUtils.calcContentLength(par, activeNode.position, par.size() - 1); | |||
this.idealPartLen = (fullLen / columnCount); | |||
} | |||
int partLen = ElementListUtils.calcContentLength(par, activeNode.position, curPos - 1); | |||
int restLen = ElementListUtils.calcContentLength(par, curPos - 1, par.size() - 1); | |||
int avgRestLen = 0; | |||
if (remParts > 0) { | |||
avgRestLen = restLen / remParts; | |||
} | |||
if (log.isTraceEnabled()) { | |||
log.trace("remaining parts: " + remParts + " rest len: " + restLen | |||
+ " avg=" + avgRestLen); | |||
} | |||
double balance = (idealPartLen - partLen) / 1000f; | |||
if (log.isTraceEnabled()) { | |||
log.trace("balance=" + balance); | |||
} | |||
double absBalance = Math.abs(balance); | |||
dem = absBalance; | |||
//Step 1: This does the rough balancing | |||
if (columnCount > 2) { | |||
if (balance > 0) { | |||
//shorter parts are less desired than longer ones | |||
dem = dem * 1.2f; | |||
} | |||
} else { | |||
if (balance < 0) { | |||
//shorter parts are less desired than longer ones | |||
dem = dem * 1.2f; | |||
} | |||
} | |||
//Step 2: This helps keep the trailing parts shorter than the previous ones | |||
dem += (avgRestLen) / 1000f; | |||
if (activeNode.line >= columnCount) { | |||
//We don't want more columns than available | |||
dem = Double.MAX_VALUE; | |||
} | |||
if (log.isTraceEnabled()) { | |||
log.trace("effective dem=" + dem + " " + totalWidth); | |||
} | |||
return dem; | |||
} | |||
} | |||
/* | |||
* 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.layoutmgr; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogFactory; | |||
import org.apache.fop.traits.MinOptMax; | |||
/** | |||
* This is a the breaking algorithm that is responsible for balancing columns in multi-column | |||
* layout. | |||
*/ | |||
public class BalancingColumnBreakingAlgorithm extends PageBreakingAlgorithm { | |||
private Log log = LogFactory.getLog(BalancingColumnBreakingAlgorithm.class); | |||
private int columnCount; | |||
private int fullLen; | |||
private int idealPartLen; | |||
public BalancingColumnBreakingAlgorithm(LayoutManager topLevelLM, | |||
PageProvider pageProvider, | |||
PageBreakingLayoutListener layoutListener, | |||
int alignment, int alignmentLast, | |||
MinOptMax footnoteSeparatorLength, | |||
boolean partOverflowRecovery, | |||
int columnCount) { | |||
super(topLevelLM, pageProvider, layoutListener, | |||
alignment, alignmentLast, | |||
footnoteSeparatorLength, partOverflowRecovery, false, false); | |||
this.columnCount = columnCount; | |||
this.considerTooShort = true; //This is important! | |||
} | |||
/** {@inheritDoc} */ | |||
protected double computeDemerits(KnuthNode activeNode, | |||
KnuthElement element, int fitnessClass, double r) { | |||
double dem = super.computeDemerits(activeNode, element, fitnessClass, r); | |||
if (log.isTraceEnabled()) { | |||
log.trace("original demerit=" + dem + " " + totalWidth | |||
+ " line=" + activeNode.line + "/" + columnCount | |||
+ " pos=" + activeNode.position + "/" + (par.size() - 1)); | |||
} | |||
int remParts = columnCount - activeNode.line; | |||
int curPos = par.indexOf(element); | |||
if (fullLen == 0) { | |||
fullLen = ElementListUtils.calcContentLength(par, activeNode.position, par.size() - 1); | |||
this.idealPartLen = (fullLen / columnCount); | |||
} | |||
int partLen = ElementListUtils.calcContentLength(par, activeNode.position, curPos - 1); | |||
int restLen = ElementListUtils.calcContentLength(par, curPos - 1, par.size() - 1); | |||
int avgRestLen = 0; | |||
if (remParts > 0) { | |||
avgRestLen = restLen / remParts; | |||
} | |||
if (log.isTraceEnabled()) { | |||
log.trace("remaining parts: " + remParts + " rest len: " + restLen | |||
+ " avg=" + avgRestLen); | |||
} | |||
double balance = (idealPartLen - partLen) / 1000f; | |||
if (log.isTraceEnabled()) { | |||
log.trace("balance=" + balance); | |||
} | |||
double absBalance = Math.abs(balance); | |||
dem = absBalance; | |||
//Step 1: This does the rough balancing | |||
if (columnCount > 2) { | |||
if (balance > 0) { | |||
//shorter parts are less desired than longer ones | |||
dem = dem * 1.2f; | |||
} | |||
} else { | |||
if (balance < 0) { | |||
//shorter parts are less desired than longer ones | |||
dem = dem * 1.2f; | |||
} | |||
} | |||
//Step 2: This helps keep the trailing parts shorter than the previous ones | |||
dem += (avgRestLen) / 1000f; | |||
if (activeNode.line >= columnCount) { | |||
//We don't want more columns than available | |||
dem = Double.MAX_VALUE; | |||
} | |||
if (log.isTraceEnabled()) { | |||
log.trace("effective dem=" + dem + " " + totalWidth); | |||
} | |||
return dem; | |||
} | |||
} |
@@ -1,81 +1,81 @@ | |||
/* | |||
* 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.layoutmgr.inline; | |||
import org.apache.fop.area.inline.InlineArea; | |||
import org.apache.fop.fo.flow.Wrapper; | |||
import org.apache.fop.layoutmgr.LayoutContext; | |||
import org.apache.fop.layoutmgr.PositionIterator; | |||
import org.apache.fop.layoutmgr.TraitSetter; | |||
/** | |||
* This is the layout manager for the fo:wrapper formatting object. | |||
*/ | |||
public class WrapperLayoutManager extends LeafNodeLayoutManager { | |||
private Wrapper fobj; | |||
/** | |||
* Creates a new LM for fo:wrapper. | |||
* @param node the fo:wrapper | |||
*/ | |||
public WrapperLayoutManager(Wrapper node) { | |||
super(node); | |||
fobj = node; | |||
} | |||
/** {@inheritDoc} */ | |||
public InlineArea get(LayoutContext context) { | |||
// Create a zero-width, zero-height dummy area so this node can | |||
// participate in the ID handling. Otherwise, addId() wouldn't | |||
// be called. The area must also be added to the tree, because | |||
// determination of the X,Y position is done in the renderer. | |||
InlineArea area = new InlineArea(); | |||
if (fobj.hasId()) { | |||
TraitSetter.setProducerID(area, fobj.getId()); | |||
} | |||
return area; | |||
} | |||
/** | |||
* Add the area for this layout manager. | |||
* This adds the dummy area to the parent, *if* it has an id | |||
* - otherwise it serves no purpose. | |||
* | |||
* @param posIter the position iterator | |||
* @param context the layout context for adding the area | |||
*/ | |||
public void addAreas(PositionIterator posIter, LayoutContext context) { | |||
if (fobj.hasId()) { | |||
addId(); | |||
InlineArea area = getEffectiveArea(); | |||
parentLM.addChildArea(area); | |||
} | |||
while (posIter.hasNext()) { | |||
posIter.next(); | |||
} | |||
} | |||
/** {@inheritDoc} */ | |||
protected void addId() { | |||
getPSLM().addIDToPage(fobj.getId()); | |||
} | |||
} | |||
/* | |||
* 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.layoutmgr.inline; | |||
import org.apache.fop.area.inline.InlineArea; | |||
import org.apache.fop.fo.flow.Wrapper; | |||
import org.apache.fop.layoutmgr.LayoutContext; | |||
import org.apache.fop.layoutmgr.PositionIterator; | |||
import org.apache.fop.layoutmgr.TraitSetter; | |||
/** | |||
* This is the layout manager for the fo:wrapper formatting object. | |||
*/ | |||
public class WrapperLayoutManager extends LeafNodeLayoutManager { | |||
private Wrapper fobj; | |||
/** | |||
* Creates a new LM for fo:wrapper. | |||
* @param node the fo:wrapper | |||
*/ | |||
public WrapperLayoutManager(Wrapper node) { | |||
super(node); | |||
fobj = node; | |||
} | |||
/** {@inheritDoc} */ | |||
public InlineArea get(LayoutContext context) { | |||
// Create a zero-width, zero-height dummy area so this node can | |||
// participate in the ID handling. Otherwise, addId() wouldn't | |||
// be called. The area must also be added to the tree, because | |||
// determination of the X,Y position is done in the renderer. | |||
InlineArea area = new InlineArea(); | |||
if (fobj.hasId()) { | |||
TraitSetter.setProducerID(area, fobj.getId()); | |||
} | |||
return area; | |||
} | |||
/** | |||
* Add the area for this layout manager. | |||
* This adds the dummy area to the parent, *if* it has an id | |||
* - otherwise it serves no purpose. | |||
* | |||
* @param posIter the position iterator | |||
* @param context the layout context for adding the area | |||
*/ | |||
public void addAreas(PositionIterator posIter, LayoutContext context) { | |||
if (fobj.hasId()) { | |||
addId(); | |||
InlineArea area = getEffectiveArea(); | |||
parentLM.addChildArea(area); | |||
} | |||
while (posIter.hasNext()) { | |||
posIter.next(); | |||
} | |||
} | |||
/** {@inheritDoc} */ | |||
protected void addId() { | |||
getPSLM().addIDToPage(fobj.getId()); | |||
} | |||
} |
@@ -1,69 +1,69 @@ | |||
/* | |||
* 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; | |||
import java.io.OutputStream; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.fo.FOEventHandler; | |||
/** | |||
* Base class for factory classes which instantiate FOEventHandlers and provide information | |||
* about them. | |||
*/ | |||
public abstract class AbstractFOEventHandlerMaker { | |||
/** | |||
* Instantiates a new FOEventHandler. | |||
* @param ua the user agent | |||
* @param out OutputStream for the FOEventHandler to use | |||
* @return the newly instantiated FOEventHandler | |||
* @throws FOPException if a problem occurs while creating the event handler | |||
*/ | |||
public abstract FOEventHandler makeFOEventHandler(FOUserAgent ua, OutputStream out) | |||
throws FOPException; | |||
/** | |||
* @return Indicates whether this renderer requires an OutputStream to work with. | |||
*/ | |||
public abstract boolean needsOutputStream(); | |||
/** | |||
* @return an array of MIME types the renderer supports. | |||
*/ | |||
public abstract String[] getSupportedMimeTypes(); | |||
/** | |||
* Indicates whether a specific MIME type is supported by this renderer. | |||
* @param mimeType the MIME type (ex. "application/rtf") | |||
* @return true if the MIME type is supported | |||
*/ | |||
public boolean isMimeTypeSupported(String mimeType) { | |||
String[] mimes = getSupportedMimeTypes(); | |||
for (int i = 0; i < mimes.length; i++) { | |||
if (mimes[i].equals(mimeType)) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
} | |||
/* | |||
* 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; | |||
import java.io.OutputStream; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.fo.FOEventHandler; | |||
/** | |||
* Base class for factory classes which instantiate FOEventHandlers and provide information | |||
* about them. | |||
*/ | |||
public abstract class AbstractFOEventHandlerMaker { | |||
/** | |||
* Instantiates a new FOEventHandler. | |||
* @param ua the user agent | |||
* @param out OutputStream for the FOEventHandler to use | |||
* @return the newly instantiated FOEventHandler | |||
* @throws FOPException if a problem occurs while creating the event handler | |||
*/ | |||
public abstract FOEventHandler makeFOEventHandler(FOUserAgent ua, OutputStream out) | |||
throws FOPException; | |||
/** | |||
* @return Indicates whether this renderer requires an OutputStream to work with. | |||
*/ | |||
public abstract boolean needsOutputStream(); | |||
/** | |||
* @return an array of MIME types the renderer supports. | |||
*/ | |||
public abstract String[] getSupportedMimeTypes(); | |||
/** | |||
* Indicates whether a specific MIME type is supported by this renderer. | |||
* @param mimeType the MIME type (ex. "application/rtf") | |||
* @return true if the MIME type is supported | |||
*/ | |||
public boolean isMimeTypeSupported(String mimeType) { | |||
String[] mimes = getSupportedMimeTypes(); | |||
for (int i = 0; i < mimes.length; i++) { | |||
if (mimes[i].equals(mimeType)) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
} |
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render; | |||
@@ -1,71 +1,71 @@ | |||
/* | |||
* 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; | |||
import org.apache.fop.apps.FOUserAgent; | |||
/** | |||
* Base class for factory classes which instantiate Renderers and provide information | |||
* about them. | |||
*/ | |||
public abstract class AbstractRendererMaker { | |||
/** | |||
* Instantiates a new renderer. | |||
* @param userAgent the user agent | |||
* @return the newly instantiated renderer | |||
*/ | |||
public abstract Renderer makeRenderer(FOUserAgent userAgent); | |||
/** | |||
* @return Indicates whether this renderer requires an OutputStream to work with. | |||
*/ | |||
public abstract boolean needsOutputStream(); | |||
/** | |||
* @return an array of MIME types the renderer supports. | |||
*/ | |||
public abstract String[] getSupportedMimeTypes(); | |||
/** | |||
* Returns a renderer config object that can be used to | |||
* configure the renderer. | |||
* @param userAgent user agent | |||
* @return a config object that can be used to configure the renderer | |||
*/ | |||
public RendererConfigurator getConfigurator(FOUserAgent userAgent) { | |||
return null; | |||
} | |||
/** | |||
* Indicates whether a specific MIME type is supported by this renderer. | |||
* @param mimeType the MIME type (ex. "application/pdf") | |||
* @return true if the MIME type is supported | |||
*/ | |||
public boolean isMimeTypeSupported(String mimeType) { | |||
String[] mimes = getSupportedMimeTypes(); | |||
for (int i = 0; i < mimes.length; i++) { | |||
if (mimes[i].equals(mimeType)) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
} | |||
/* | |||
* 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; | |||
import org.apache.fop.apps.FOUserAgent; | |||
/** | |||
* Base class for factory classes which instantiate Renderers and provide information | |||
* about them. | |||
*/ | |||
public abstract class AbstractRendererMaker { | |||
/** | |||
* Instantiates a new renderer. | |||
* @param userAgent the user agent | |||
* @return the newly instantiated renderer | |||
*/ | |||
public abstract Renderer makeRenderer(FOUserAgent userAgent); | |||
/** | |||
* @return Indicates whether this renderer requires an OutputStream to work with. | |||
*/ | |||
public abstract boolean needsOutputStream(); | |||
/** | |||
* @return an array of MIME types the renderer supports. | |||
*/ | |||
public abstract String[] getSupportedMimeTypes(); | |||
/** | |||
* Returns a renderer config object that can be used to | |||
* configure the renderer. | |||
* @param userAgent user agent | |||
* @return a config object that can be used to configure the renderer | |||
*/ | |||
public RendererConfigurator getConfigurator(FOUserAgent userAgent) { | |||
return null; | |||
} | |||
/** | |||
* Indicates whether a specific MIME type is supported by this renderer. | |||
* @param mimeType the MIME type (ex. "application/pdf") | |||
* @return true if the MIME type is supported | |||
*/ | |||
public boolean isMimeTypeSupported(String mimeType) { | |||
String[] mimes = getSupportedMimeTypes(); | |||
for (int i = 0; i < mimes.length; i++) { | |||
if (mimes[i].equals(mimeType)) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
} |
@@ -1,50 +1,50 @@ | |||
/* | |||
* 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; | |||
import java.io.IOException; | |||
/** | |||
* This interface represents an optional feature that can be provided by | |||
* a renderer. It is exposed by calling the getGraphics2DAdapter() method | |||
* on the renderer. Renderers that support this feature allow painting | |||
* of arbitrary images through a Graphics2D instance. | |||
*/ | |||
public interface Graphics2DAdapter { | |||
/** | |||
* Paints an arbitrary images on a given Graphics2D instance. The renderer | |||
* providing this functionality must set up a Graphics2D instance so that | |||
* the image with the given extents (in mpt) can be painted by the painter | |||
* passed to this method. The Graphics2DImagePainter is then passed this | |||
* Graphics2D instance so the image can be painted. | |||
* @param painter the painter which will paint the actual image | |||
* @param context the renderer context for the current renderer | |||
* @param x X position of the image | |||
* @param y Y position of the image | |||
* @param width width of the image | |||
* @param height height of the image | |||
* @throws IOException In case of an I/O error while writing the output format | |||
*/ | |||
void paintImage(org.apache.xmlgraphics.java2d.Graphics2DImagePainter painter, | |||
RendererContext context, | |||
int x, int y, int width, int height) throws IOException; | |||
} | |||
/* | |||
* 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; | |||
import java.io.IOException; | |||
/** | |||
* This interface represents an optional feature that can be provided by | |||
* a renderer. It is exposed by calling the getGraphics2DAdapter() method | |||
* on the renderer. Renderers that support this feature allow painting | |||
* of arbitrary images through a Graphics2D instance. | |||
*/ | |||
public interface Graphics2DAdapter { | |||
/** | |||
* Paints an arbitrary images on a given Graphics2D instance. The renderer | |||
* providing this functionality must set up a Graphics2D instance so that | |||
* the image with the given extents (in mpt) can be painted by the painter | |||
* passed to this method. The Graphics2DImagePainter is then passed this | |||
* Graphics2D instance so the image can be painted. | |||
* @param painter the painter which will paint the actual image | |||
* @param context the renderer context for the current renderer | |||
* @param x X position of the image | |||
* @param y Y position of the image | |||
* @param width width of the image | |||
* @param height height of the image | |||
* @throws IOException In case of an I/O error while writing the output format | |||
*/ | |||
void paintImage(org.apache.xmlgraphics.java2d.Graphics2DImagePainter painter, | |||
RendererContext context, | |||
int x, int y, int width, int height) throws IOException; | |||
} |
@@ -1,30 +1,30 @@ | |||
/* | |||
* 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; | |||
/** | |||
* This interface is used by the Graphics2DAdapter. Components that can paint using | |||
* a Graphics2D instance can implement this interface to paint themselves. | |||
* @deprecated use {@link org.apache.xmlgraphics.java2d.Graphics2DImagePainter} directly! | |||
*/ | |||
public interface Graphics2DImagePainter | |||
extends org.apache.xmlgraphics.java2d.Graphics2DImagePainter { | |||
/* | |||
* 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; | |||
/** | |||
* This interface is used by the Graphics2DAdapter. Components that can paint using | |||
* a Graphics2D instance can implement this interface to paint themselves. | |||
* @deprecated use {@link org.apache.xmlgraphics.java2d.Graphics2DImagePainter} directly! | |||
*/ | |||
public interface Graphics2DImagePainter | |||
extends org.apache.xmlgraphics.java2d.Graphics2DImagePainter { | |||
} |
@@ -1,47 +1,47 @@ | |||
/* | |||
* 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; | |||
import java.awt.image.RenderedImage; | |||
import java.io.IOException; | |||
/** | |||
* This interface represents an optional feature that can be provided by | |||
* a renderer. It is exposed by calling the getImageAdapter() method | |||
* on the renderer. Renderers that support this feature allow painting | |||
* of images (RendererImage instances). | |||
*/ | |||
public interface ImageAdapter { | |||
/** | |||
* Paints an image at the given position. | |||
* @param image the image which will be painted | |||
* @param context the renderer context for the current renderer | |||
* @param x X position of the image | |||
* @param y Y position of the image | |||
* @param width width of the image | |||
* @param height height of the image | |||
* @throws IOException In case of an I/O error while writing the output format | |||
*/ | |||
void paintImage(RenderedImage image, | |||
RendererContext context, | |||
int x, int y, int width, int height) throws IOException; | |||
} | |||
/* | |||
* 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; | |||
import java.awt.image.RenderedImage; | |||
import java.io.IOException; | |||
/** | |||
* This interface represents an optional feature that can be provided by | |||
* a renderer. It is exposed by calling the getImageAdapter() method | |||
* on the renderer. Renderers that support this feature allow painting | |||
* of images (RendererImage instances). | |||
*/ | |||
public interface ImageAdapter { | |||
/** | |||
* Paints an image at the given position. | |||
* @param image the image which will be painted | |||
* @param context the renderer context for the current renderer | |||
* @param x X position of the image | |||
* @param y Y position of the image | |||
* @param width width of the image | |||
* @param height height of the image | |||
* @throws IOException In case of an I/O error while writing the output format | |||
*/ | |||
void paintImage(RenderedImage image, | |||
RendererContext context, | |||
int x, int y, int width, int height) throws IOException; | |||
} |
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render; | |||
@@ -1,166 +1,166 @@ | |||
/* | |||
* 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; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.Map; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogFactory; | |||
import org.apache.xmlgraphics.util.Service; | |||
/** | |||
* This class holds references to various XML handlers used by FOP. It also | |||
* supports automatic discovery of additional XML handlers available through | |||
* the class path. | |||
*/ | |||
public class XMLHandlerRegistry { | |||
/** the logger */ | |||
private static Log log = LogFactory.getLog(XMLHandlerRegistry.class); | |||
/** Map containing XML handlers for various document types */ | |||
private Map handlers = new java.util.HashMap(); | |||
/** | |||
* Default constructor. | |||
*/ | |||
public XMLHandlerRegistry() { | |||
discoverXMLHandlers(); | |||
} | |||
/** | |||
* Add a default XML handler which is able to handle any namespace. | |||
* @param handler XMLHandler to use | |||
*/ | |||
private void setDefaultXMLHandler(XMLHandler handler) { | |||
addXMLHandler(XMLHandler.HANDLE_ALL, handler); | |||
} | |||
/** | |||
* Add an XML handler. The handler itself is inspected to find out what it supports. | |||
* @param classname the fully qualified class name | |||
*/ | |||
public void addXMLHandler(String classname) { | |||
try { | |||
XMLHandler handlerInstance = (XMLHandler)Class.forName(classname).newInstance(); | |||
addXMLHandler(handlerInstance); | |||
} catch (ClassNotFoundException e) { | |||
throw new IllegalArgumentException("Could not find " | |||
+ classname); | |||
} catch (InstantiationException e) { | |||
throw new IllegalArgumentException("Could not instantiate " | |||
+ classname); | |||
} catch (IllegalAccessException e) { | |||
throw new IllegalArgumentException("Could not access " | |||
+ classname); | |||
} catch (ClassCastException e) { | |||
throw new IllegalArgumentException(classname | |||
+ " is not an " | |||
+ XMLHandler.class.getName()); | |||
} | |||
} | |||
/** | |||
* Add an XML handler. The handler itself is inspected to find out what it supports. | |||
* @param handler the XMLHandler instance | |||
*/ | |||
public void addXMLHandler(XMLHandler handler) { | |||
String ns = handler.getNamespace(); | |||
if (ns == null) { | |||
setDefaultXMLHandler(handler); | |||
} else { | |||
addXMLHandler(ns, handler); | |||
} | |||
} | |||
/** | |||
* Add an XML handler for the given MIME type and XML namespace. | |||
* @param ns Namespace URI | |||
* @param handler XMLHandler to use | |||
*/ | |||
private void addXMLHandler(String ns, | |||
XMLHandler handler) { | |||
List lst = (List)handlers.get(ns); | |||
if (lst == null) { | |||
lst = new java.util.ArrayList(); | |||
handlers.put(ns, lst); | |||
} | |||
lst.add(handler); | |||
} | |||
/** | |||
* Returns an XMLHandler which handles an XML dialect of the given namespace and for | |||
* a specified output format defined by its MIME type. | |||
* @param renderer the Renderer for which to retrieve a Renderer | |||
* @param ns the XML namespace associated with the XML to be rendered | |||
* @return the XMLHandler responsible for handling the XML or null if none is available | |||
*/ | |||
public XMLHandler getXMLHandler(Renderer renderer, String ns) { | |||
XMLHandler handler; | |||
List lst = (List)handlers.get(ns); | |||
handler = getXMLHandler(renderer, lst); | |||
if (handler == null) { | |||
lst = (List)handlers.get(XMLHandler.HANDLE_ALL); | |||
handler = getXMLHandler(renderer, lst); | |||
} | |||
return handler; | |||
} | |||
private XMLHandler getXMLHandler(Renderer renderer, List lst) { | |||
XMLHandler handler; | |||
if (lst != null) { | |||
for (int i = 0, c = lst.size(); i < c; i++) { | |||
//TODO Maybe add priorities later | |||
handler = (XMLHandler)lst.get(i); | |||
if (handler.supportsRenderer(renderer)) { | |||
return handler; | |||
} | |||
} | |||
} | |||
return null; //No handler found | |||
} | |||
/** | |||
* Discovers XMLHandler implementations through the classpath and dynamically | |||
* registers them. | |||
*/ | |||
private void discoverXMLHandlers() { | |||
// add mappings from available services | |||
Iterator providers = Service.providers(XMLHandler.class); | |||
if (providers != null) { | |||
while (providers.hasNext()) { | |||
XMLHandler handler = (XMLHandler)providers.next(); | |||
try { | |||
if (log.isDebugEnabled()) { | |||
log.debug("Dynamically adding XMLHandler: " + handler.getClass().getName()); | |||
} | |||
addXMLHandler(handler); | |||
} catch (IllegalArgumentException e) { | |||
log.error("Error while adding XMLHandler", e); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
/* | |||
* 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; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.Map; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogFactory; | |||
import org.apache.xmlgraphics.util.Service; | |||
/** | |||
* This class holds references to various XML handlers used by FOP. It also | |||
* supports automatic discovery of additional XML handlers available through | |||
* the class path. | |||
*/ | |||
public class XMLHandlerRegistry { | |||
/** the logger */ | |||
private static Log log = LogFactory.getLog(XMLHandlerRegistry.class); | |||
/** Map containing XML handlers for various document types */ | |||
private Map handlers = new java.util.HashMap(); | |||
/** | |||
* Default constructor. | |||
*/ | |||
public XMLHandlerRegistry() { | |||
discoverXMLHandlers(); | |||
} | |||
/** | |||
* Add a default XML handler which is able to handle any namespace. | |||
* @param handler XMLHandler to use | |||
*/ | |||
private void setDefaultXMLHandler(XMLHandler handler) { | |||
addXMLHandler(XMLHandler.HANDLE_ALL, handler); | |||
} | |||
/** | |||
* Add an XML handler. The handler itself is inspected to find out what it supports. | |||
* @param classname the fully qualified class name | |||
*/ | |||
public void addXMLHandler(String classname) { | |||
try { | |||
XMLHandler handlerInstance = (XMLHandler)Class.forName(classname).newInstance(); | |||
addXMLHandler(handlerInstance); | |||
} catch (ClassNotFoundException e) { | |||
throw new IllegalArgumentException("Could not find " | |||
+ classname); | |||
} catch (InstantiationException e) { | |||
throw new IllegalArgumentException("Could not instantiate " | |||
+ classname); | |||
} catch (IllegalAccessException e) { | |||
throw new IllegalArgumentException("Could not access " | |||
+ classname); | |||
} catch (ClassCastException e) { | |||
throw new IllegalArgumentException(classname | |||
+ " is not an " | |||
+ XMLHandler.class.getName()); | |||
} | |||
} | |||
/** | |||
* Add an XML handler. The handler itself is inspected to find out what it supports. | |||
* @param handler the XMLHandler instance | |||
*/ | |||
public void addXMLHandler(XMLHandler handler) { | |||
String ns = handler.getNamespace(); | |||
if (ns == null) { | |||
setDefaultXMLHandler(handler); | |||
} else { | |||
addXMLHandler(ns, handler); | |||
} | |||
} | |||
/** | |||
* Add an XML handler for the given MIME type and XML namespace. | |||
* @param ns Namespace URI | |||
* @param handler XMLHandler to use | |||
*/ | |||
private void addXMLHandler(String ns, | |||
XMLHandler handler) { | |||
List lst = (List)handlers.get(ns); | |||
if (lst == null) { | |||
lst = new java.util.ArrayList(); | |||
handlers.put(ns, lst); | |||
} | |||
lst.add(handler); | |||
} | |||
/** | |||
* Returns an XMLHandler which handles an XML dialect of the given namespace and for | |||
* a specified output format defined by its MIME type. | |||
* @param renderer the Renderer for which to retrieve a Renderer | |||
* @param ns the XML namespace associated with the XML to be rendered | |||
* @return the XMLHandler responsible for handling the XML or null if none is available | |||
*/ | |||
public XMLHandler getXMLHandler(Renderer renderer, String ns) { | |||
XMLHandler handler; | |||
List lst = (List)handlers.get(ns); | |||
handler = getXMLHandler(renderer, lst); | |||
if (handler == null) { | |||
lst = (List)handlers.get(XMLHandler.HANDLE_ALL); | |||
handler = getXMLHandler(renderer, lst); | |||
} | |||
return handler; | |||
} | |||
private XMLHandler getXMLHandler(Renderer renderer, List lst) { | |||
XMLHandler handler; | |||
if (lst != null) { | |||
for (int i = 0, c = lst.size(); i < c; i++) { | |||
//TODO Maybe add priorities later | |||
handler = (XMLHandler)lst.get(i); | |||
if (handler.supportsRenderer(renderer)) { | |||
return handler; | |||
} | |||
} | |||
} | |||
return null; //No handler found | |||
} | |||
/** | |||
* Discovers XMLHandler implementations through the classpath and dynamically | |||
* registers them. | |||
*/ | |||
private void discoverXMLHandlers() { | |||
// add mappings from available services | |||
Iterator providers = Service.providers(XMLHandler.class); | |||
if (providers != null) { | |||
while (providers.hasNext()) { | |||
XMLHandler handler = (XMLHandler)providers.next(); | |||
try { | |||
if (log.isDebugEnabled()) { | |||
log.debug("Dynamically adding XMLHandler: " + handler.getClass().getName()); | |||
} | |||
addXMLHandler(handler); | |||
} catch (IllegalArgumentException e) { | |||
log.error("Error while adding XMLHandler", e); | |||
} | |||
} | |||
} | |||
} | |||
} |
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: PSTextElementBridge.java 426576 2006-07-28 15:44:37Z jeremias $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: PSTextPainter.java 542237 2007-05-28 14:31:24Z jeremias $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp; | |||
@@ -1,121 +1,121 @@ | |||
/* | |||
* 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.afp.extensions; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogFactory; | |||
import org.apache.fop.util.ContentHandlerFactory; | |||
import org.apache.fop.util.ContentHandlerFactory.ObjectBuiltListener; | |||
import org.xml.sax.Attributes; | |||
import org.xml.sax.SAXException; | |||
import org.xml.sax.helpers.DefaultHandler; | |||
/** | |||
* ContentHandler (parser) for restoring AFPExtension objects from XML. | |||
*/ | |||
public class AFPExtensionHandler extends DefaultHandler | |||
implements ContentHandlerFactory.ObjectSource { | |||
/** Logger instance */ | |||
protected static Log log = LogFactory.getLog(AFPExtensionHandler.class); | |||
private StringBuffer content = new StringBuffer(); | |||
private Attributes lastAttributes; | |||
private AFPPageSetup returnedObject; | |||
private ObjectBuiltListener listener; | |||
/** {@inheritDoc} */ | |||
public void startElement(String uri, String localName, String qName, Attributes attributes) | |||
throws SAXException { | |||
boolean handled = false; | |||
if (AFPPageSetup.CATEGORY.equals(uri)) { | |||
lastAttributes = attributes; | |||
handled = true; | |||
if (localName.equals(AFPElementMapping.NO_OPERATION) | |||
|| localName.equals(AFPElementMapping.TAG_LOGICAL_ELEMENT) | |||
|| localName.equals(AFPElementMapping.INCLUDE_PAGE_OVERLAY) | |||
|| localName.equals(AFPElementMapping.INCLUDE_PAGE_SEGMENT) | |||
|| localName.equals(AFPElementMapping.PAGE) | |||
|| localName.equals(AFPElementMapping.PAGE_GROUP)) { | |||
//handled in endElement | |||
} else { | |||
handled = false; | |||
} | |||
} | |||
if (!handled) { | |||
if (AFPPageSetup.CATEGORY.equals(uri)) { | |||
throw new SAXException("Unhandled element " + localName | |||
+ " in namespace: " + uri); | |||
} else { | |||
log.warn("Unhandled element " + localName | |||
+ " in namespace: " + uri); | |||
} | |||
} | |||
} | |||
/** {@inheritDoc} */ | |||
public void endElement(String uri, String localName, String qName) throws SAXException { | |||
if (AFPPageSetup.CATEGORY.equals(uri)) { | |||
this.returnedObject = new AFPPageSetup(localName); | |||
String name = lastAttributes.getValue("name"); | |||
if (name != null) { | |||
returnedObject.setName(name); | |||
} | |||
String value = lastAttributes.getValue("value"); | |||
if (value != null) { | |||
returnedObject.setValue(value); | |||
} | |||
if (content.length() > 0) { | |||
returnedObject.setContent(content.toString()); | |||
content.setLength(0); //Reset text buffer (see characters()) | |||
} | |||
} | |||
} | |||
/** {@inheritDoc} */ | |||
public void characters(char[] ch, int start, int length) throws SAXException { | |||
content.append(ch, start, length); | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public void endDocument() throws SAXException { | |||
if (listener != null) { | |||
listener.notifyObjectBuilt(getObject()); | |||
} | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public Object getObject() { | |||
return returnedObject; | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public void setObjectBuiltListener(ObjectBuiltListener listen) { | |||
this.listener = listen; | |||
} | |||
} | |||
/* | |||
* 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.afp.extensions; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogFactory; | |||
import org.apache.fop.util.ContentHandlerFactory; | |||
import org.apache.fop.util.ContentHandlerFactory.ObjectBuiltListener; | |||
import org.xml.sax.Attributes; | |||
import org.xml.sax.SAXException; | |||
import org.xml.sax.helpers.DefaultHandler; | |||
/** | |||
* ContentHandler (parser) for restoring AFPExtension objects from XML. | |||
*/ | |||
public class AFPExtensionHandler extends DefaultHandler | |||
implements ContentHandlerFactory.ObjectSource { | |||
/** Logger instance */ | |||
protected static Log log = LogFactory.getLog(AFPExtensionHandler.class); | |||
private StringBuffer content = new StringBuffer(); | |||
private Attributes lastAttributes; | |||
private AFPPageSetup returnedObject; | |||
private ObjectBuiltListener listener; | |||
/** {@inheritDoc} */ | |||
public void startElement(String uri, String localName, String qName, Attributes attributes) | |||
throws SAXException { | |||
boolean handled = false; | |||
if (AFPPageSetup.CATEGORY.equals(uri)) { | |||
lastAttributes = attributes; | |||
handled = true; | |||
if (localName.equals(AFPElementMapping.NO_OPERATION) | |||
|| localName.equals(AFPElementMapping.TAG_LOGICAL_ELEMENT) | |||
|| localName.equals(AFPElementMapping.INCLUDE_PAGE_OVERLAY) | |||
|| localName.equals(AFPElementMapping.INCLUDE_PAGE_SEGMENT) | |||
|| localName.equals(AFPElementMapping.PAGE) | |||
|| localName.equals(AFPElementMapping.PAGE_GROUP)) { | |||
//handled in endElement | |||
} else { | |||
handled = false; | |||
} | |||
} | |||
if (!handled) { | |||
if (AFPPageSetup.CATEGORY.equals(uri)) { | |||
throw new SAXException("Unhandled element " + localName | |||
+ " in namespace: " + uri); | |||
} else { | |||
log.warn("Unhandled element " + localName | |||
+ " in namespace: " + uri); | |||
} | |||
} | |||
} | |||
/** {@inheritDoc} */ | |||
public void endElement(String uri, String localName, String qName) throws SAXException { | |||
if (AFPPageSetup.CATEGORY.equals(uri)) { | |||
this.returnedObject = new AFPPageSetup(localName); | |||
String name = lastAttributes.getValue("name"); | |||
if (name != null) { | |||
returnedObject.setName(name); | |||
} | |||
String value = lastAttributes.getValue("value"); | |||
if (value != null) { | |||
returnedObject.setValue(value); | |||
} | |||
if (content.length() > 0) { | |||
returnedObject.setContent(content.toString()); | |||
content.setLength(0); //Reset text buffer (see characters()) | |||
} | |||
} | |||
} | |||
/** {@inheritDoc} */ | |||
public void characters(char[] ch, int start, int length) throws SAXException { | |||
content.append(ch, start, length); | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public void endDocument() throws SAXException { | |||
if (listener != null) { | |||
listener.notifyObjectBuilt(getObject()); | |||
} | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public Object getObject() { | |||
return returnedObject; | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public void setObjectBuiltListener(ObjectBuiltListener listen) { | |||
this.listener = listen; | |||
} | |||
} |
@@ -1,41 +1,41 @@ | |||
/* | |||
* 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.afp.extensions; | |||
import org.apache.fop.util.ContentHandlerFactory; | |||
import org.xml.sax.ContentHandler; | |||
/** | |||
* Factory for the ContentHandler that handles serialized AFPPageSetup instances. | |||
*/ | |||
public class AFPExtensionHandlerFactory implements ContentHandlerFactory { | |||
private static final String[] NAMESPACES = new String[] {AFPPageSetup.CATEGORY}; | |||
/** {@inheritDoc} */ | |||
public String[] getSupportedNamespaces() { | |||
return NAMESPACES; | |||
} | |||
/** {@inheritDoc} */ | |||
public ContentHandler createContentHandler() { | |||
return new AFPExtensionHandler(); | |||
} | |||
} | |||
/* | |||
* 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.afp.extensions; | |||
import org.apache.fop.util.ContentHandlerFactory; | |||
import org.xml.sax.ContentHandler; | |||
/** | |||
* Factory for the ContentHandler that handles serialized AFPPageSetup instances. | |||
*/ | |||
public class AFPExtensionHandlerFactory implements ContentHandlerFactory { | |||
private static final String[] NAMESPACES = new String[] {AFPPageSetup.CATEGORY}; | |||
/** {@inheritDoc} */ | |||
public String[] getSupportedNamespaces() { | |||
return NAMESPACES; | |||
} | |||
/** {@inheritDoc} */ | |||
public ContentHandler createContentHandler() { | |||
return new AFPExtensionHandler(); | |||
} | |||
} |
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp.modca.goca; | |||
@@ -1,50 +1,50 @@ | |||
/* | |||
* 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.awt; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.apps.MimeConstants; | |||
import org.apache.fop.render.AbstractRendererMaker; | |||
import org.apache.fop.render.Renderer; | |||
/** | |||
* RendererMaker for the AWT Preview Renderer. | |||
*/ | |||
public class AWTRendererMaker extends AbstractRendererMaker { | |||
private static final String[] MIMES = new String[] {MimeConstants.MIME_FOP_AWT_PREVIEW}; | |||
/** {@inheritDoc} */ | |||
public Renderer makeRenderer(FOUserAgent ua) { | |||
return new AWTRenderer(); | |||
} | |||
/** {@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.awt; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.apps.MimeConstants; | |||
import org.apache.fop.render.AbstractRendererMaker; | |||
import org.apache.fop.render.Renderer; | |||
/** | |||
* RendererMaker for the AWT Preview Renderer. | |||
*/ | |||
public class AWTRendererMaker extends AbstractRendererMaker { | |||
private static final String[] MIMES = new String[] {MimeConstants.MIME_FOP_AWT_PREVIEW}; | |||
/** {@inheritDoc} */ | |||
public Renderer makeRenderer(FOUserAgent ua) { | |||
return new AWTRenderer(); | |||
} | |||
/** {@inheritDoc} */ | |||
public boolean needsOutputStream() { | |||
return false; | |||
} | |||
/** {@inheritDoc} */ | |||
public String[] getSupportedMimeTypes() { | |||
return MIMES; | |||
} | |||
} |
@@ -1,75 +1,75 @@ | |||
package org.apache.fop.render.bitmap; | |||
import java.io.BufferedOutputStream; | |||
import java.io.File; | |||
import java.io.FileOutputStream; | |||
import java.io.IOException; | |||
import java.io.OutputStream; | |||
/** | |||
* This utility class helps renderers who generate one file per page, | |||
* like the PNG renderer. | |||
*/ | |||
public class MultiFileRenderingUtil { | |||
/** The file syntax prefix, eg. "page" will output "page1.png" etc */ | |||
private String filePrefix; | |||
private String fileExtension; | |||
/** The output directory where images are to be written */ | |||
private File outputDir; | |||
/** | |||
* Creates a new instance. | |||
* <p> | |||
* The file name must not have an extension, or must have extension "png", | |||
* and its last period must not be at the start (empty file prefix). | |||
* @param ext the extension to be used | |||
* @param outputFile the output file or null if there's no such information | |||
*/ | |||
public MultiFileRenderingUtil(String ext, File outputFile) { | |||
this.fileExtension = ext; | |||
// the file provided on the command line | |||
if (outputFile == null) { | |||
//No filename information available. Only the first page will be rendered. | |||
outputDir = null; | |||
filePrefix = null; | |||
} else { | |||
outputDir = outputFile.getParentFile(); | |||
// extracting file name syntax | |||
String s = outputFile.getName(); | |||
int i = s.lastIndexOf("."); | |||
if (i > 0) { | |||
// Make sure that the file extension was "png" | |||
String extension = s.substring(i + 1).toLowerCase(); | |||
if (!ext.equals(extension)) { | |||
throw new IllegalArgumentException("Invalid file extension ('" | |||
+ extension + "') specified"); | |||
} | |||
} else if (i == -1) { | |||
i = s.length(); | |||
} else { // i == 0 | |||
throw new IllegalArgumentException("Invalid file name ('" | |||
+ s + "') specified"); | |||
} | |||
if (s.charAt(i - 1) == '1') { | |||
i--; // getting rid of the "1" | |||
} | |||
filePrefix = s.substring(0, i); | |||
} | |||
} | |||
public OutputStream createOutputStream(int pageNumber) throws IOException { | |||
if (filePrefix == null) { | |||
return null; | |||
} else { | |||
File f = new File(outputDir, | |||
filePrefix + (pageNumber + 1) + "." + fileExtension); | |||
OutputStream os = new BufferedOutputStream(new FileOutputStream(f)); | |||
return os; | |||
} | |||
} | |||
} | |||
package org.apache.fop.render.bitmap; | |||
import java.io.BufferedOutputStream; | |||
import java.io.File; | |||
import java.io.FileOutputStream; | |||
import java.io.IOException; | |||
import java.io.OutputStream; | |||
/** | |||
* This utility class helps renderers who generate one file per page, | |||
* like the PNG renderer. | |||
*/ | |||
public class MultiFileRenderingUtil { | |||
/** The file syntax prefix, eg. "page" will output "page1.png" etc */ | |||
private String filePrefix; | |||
private String fileExtension; | |||
/** The output directory where images are to be written */ | |||
private File outputDir; | |||
/** | |||
* Creates a new instance. | |||
* <p> | |||
* The file name must not have an extension, or must have extension "png", | |||
* and its last period must not be at the start (empty file prefix). | |||
* @param ext the extension to be used | |||
* @param outputFile the output file or null if there's no such information | |||
*/ | |||
public MultiFileRenderingUtil(String ext, File outputFile) { | |||
this.fileExtension = ext; | |||
// the file provided on the command line | |||
if (outputFile == null) { | |||
//No filename information available. Only the first page will be rendered. | |||
outputDir = null; | |||
filePrefix = null; | |||
} else { | |||
outputDir = outputFile.getParentFile(); | |||
// extracting file name syntax | |||
String s = outputFile.getName(); | |||
int i = s.lastIndexOf("."); | |||
if (i > 0) { | |||
// Make sure that the file extension was "png" | |||
String extension = s.substring(i + 1).toLowerCase(); | |||
if (!ext.equals(extension)) { | |||
throw new IllegalArgumentException("Invalid file extension ('" | |||
+ extension + "') specified"); | |||
} | |||
} else if (i == -1) { | |||
i = s.length(); | |||
} else { // i == 0 | |||
throw new IllegalArgumentException("Invalid file name ('" | |||
+ s + "') specified"); | |||
} | |||
if (s.charAt(i - 1) == '1') { | |||
i--; // getting rid of the "1" | |||
} | |||
filePrefix = s.substring(0, i); | |||
} | |||
} | |||
public OutputStream createOutputStream(int pageNumber) throws IOException { | |||
if (filePrefix == null) { | |||
return null; | |||
} else { | |||
File f = new File(outputDir, | |||
filePrefix + (pageNumber + 1) + "." + fileExtension); | |||
OutputStream os = new BufferedOutputStream(new FileOutputStream(f)); | |||
return os; | |||
} | |||
} | |||
} |
@@ -1,57 +1,57 @@ | |||
/* | |||
* 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.bitmap; | |||
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; | |||
import org.apache.fop.render.java2d.Java2DRendererConfigurator; | |||
/** | |||
* RendererMaker for the PNG Renderer. | |||
*/ | |||
public class PNGRendererMaker extends AbstractRendererMaker { | |||
private static final String[] MIMES = new String[] {MimeConstants.MIME_PNG}; | |||
/** {@inheritDoc} */ | |||
public Renderer makeRenderer(FOUserAgent ua) { | |||
return new PNGRenderer(); | |||
} | |||
/** {@inheritDoc} */ | |||
public RendererConfigurator getConfigurator(FOUserAgent userAgent) { | |||
return new Java2DRendererConfigurator(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.bitmap; | |||
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; | |||
import org.apache.fop.render.java2d.Java2DRendererConfigurator; | |||
/** | |||
* RendererMaker for the PNG Renderer. | |||
*/ | |||
public class PNGRendererMaker extends AbstractRendererMaker { | |||
private static final String[] MIMES = new String[] {MimeConstants.MIME_PNG}; | |||
/** {@inheritDoc} */ | |||
public Renderer makeRenderer(FOUserAgent ua) { | |||
return new PNGRenderer(); | |||
} | |||
/** {@inheritDoc} */ | |||
public RendererConfigurator getConfigurator(FOUserAgent userAgent) { | |||
return new Java2DRendererConfigurator(userAgent); | |||
} | |||
/** {@inheritDoc} */ | |||
public boolean needsOutputStream() { | |||
return true; | |||
} | |||
/** {@inheritDoc} */ | |||
public String[] getSupportedMimeTypes() { | |||
return MIMES; | |||
} | |||
} |
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.bitmap; | |||
@@ -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.bitmap; | |||
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 TIFF Renderer. | |||
*/ | |||
public class TIFFRendererMaker extends AbstractRendererMaker { | |||
private static final String[] MIMES = new String[] {MimeConstants.MIME_TIFF}; | |||
/** {@inheritDoc} */ | |||
public Renderer makeRenderer(FOUserAgent userAgent) { | |||
return new TIFFRenderer(); | |||
} | |||
/** {@inheritDoc} */ | |||
public RendererConfigurator getConfigurator(FOUserAgent userAgent) { | |||
return new TIFFRendererConfigurator(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.bitmap; | |||
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 TIFF Renderer. | |||
*/ | |||
public class TIFFRendererMaker extends AbstractRendererMaker { | |||
private static final String[] MIMES = new String[] {MimeConstants.MIME_TIFF}; | |||
/** {@inheritDoc} */ | |||
public Renderer makeRenderer(FOUserAgent userAgent) { | |||
return new TIFFRenderer(); | |||
} | |||
/** {@inheritDoc} */ | |||
public RendererConfigurator getConfigurator(FOUserAgent userAgent) { | |||
return new TIFFRendererConfigurator(userAgent); | |||
} | |||
/** {@inheritDoc} */ | |||
public boolean needsOutputStream() { | |||
return true; | |||
} | |||
/** {@inheritDoc} */ | |||
public String[] getSupportedMimeTypes() { | |||
return MIMES; | |||
} | |||
} |
@@ -1,82 +1,82 @@ | |||
/* | |||
* 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.java2d; | |||
import java.awt.Color; | |||
import java.awt.Dimension; | |||
import java.awt.Graphics2D; | |||
import java.awt.geom.AffineTransform; | |||
import java.awt.geom.Rectangle2D; | |||
import java.io.IOException; | |||
import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; | |||
import org.apache.fop.render.Graphics2DAdapter; | |||
import org.apache.fop.render.RendererContext; | |||
/** | |||
* Graphics2DAdapter implementation for Java2D. | |||
*/ | |||
public class Java2DGraphics2DAdapter implements Graphics2DAdapter { | |||
/** {@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; | |||
Java2DRenderer renderer = (Java2DRenderer)context.getRenderer(); | |||
Java2DGraphicsState state = renderer.state; | |||
//Create copy and paint on that | |||
Graphics2D g2d = (Graphics2D)state.getGraph().create(); | |||
g2d.setColor(Color.black); | |||
g2d.setBackground(Color.black); | |||
//TODO Clip to the image area. | |||
// 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. | |||
g2d.translate(fx, fy); | |||
AffineTransform at = AffineTransform.getScaleInstance(sx, sy); | |||
if (!at.isIdentity()) { | |||
g2d.transform(at); | |||
} | |||
Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh); | |||
painter.paint(g2d, area); | |||
g2d.dispose(); | |||
} | |||
} | |||
/* | |||
* 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.java2d; | |||
import java.awt.Color; | |||
import java.awt.Dimension; | |||
import java.awt.Graphics2D; | |||
import java.awt.geom.AffineTransform; | |||
import java.awt.geom.Rectangle2D; | |||
import java.io.IOException; | |||
import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; | |||
import org.apache.fop.render.Graphics2DAdapter; | |||
import org.apache.fop.render.RendererContext; | |||
/** | |||
* Graphics2DAdapter implementation for Java2D. | |||
*/ | |||
public class Java2DGraphics2DAdapter implements Graphics2DAdapter { | |||
/** {@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; | |||
Java2DRenderer renderer = (Java2DRenderer)context.getRenderer(); | |||
Java2DGraphicsState state = renderer.state; | |||
//Create copy and paint on that | |||
Graphics2D g2d = (Graphics2D)state.getGraph().create(); | |||
g2d.setColor(Color.black); | |||
g2d.setBackground(Color.black); | |||
//TODO Clip to the image area. | |||
// 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. | |||
g2d.translate(fx, fy); | |||
AffineTransform at = AffineTransform.getScaleInstance(sx, sy); | |||
if (!at.isIdentity()) { | |||
g2d.transform(at); | |||
} | |||
Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh); | |||
painter.paint(g2d, area); | |||
g2d.dispose(); | |||
} | |||
} |
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.java2d; | |||
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.pcl; | |||
@@ -1,57 +1,57 @@ | |||
/* | |||
* 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.pcl; | |||
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 PCL Renderer. | |||
*/ | |||
public class PCLRendererMaker extends AbstractRendererMaker { | |||
private static final String[] MIMES = new String[] { | |||
MimeConstants.MIME_PCL, | |||
MimeConstants.MIME_PCL_ALT | |||
}; | |||
/**{@inheritDoc} */ | |||
public Renderer makeRenderer(FOUserAgent userAgent) { | |||
return new PCLRenderer(); | |||
} | |||
/** {@inheritDoc} */ | |||
public RendererConfigurator getConfigurator(FOUserAgent userAgent) { | |||
return new PCLRendererConfigurator(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.pcl; | |||
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 PCL Renderer. | |||
*/ | |||
public class PCLRendererMaker extends AbstractRendererMaker { | |||
private static final String[] MIMES = new String[] { | |||
MimeConstants.MIME_PCL, | |||
MimeConstants.MIME_PCL_ALT | |||
}; | |||
/**{@inheritDoc} */ | |||
public Renderer makeRenderer(FOUserAgent userAgent) { | |||
return new PCLRenderer(); | |||
} | |||
/** {@inheritDoc} */ | |||
public RendererConfigurator getConfigurator(FOUserAgent userAgent) { | |||
return new PCLRendererConfigurator(userAgent); | |||
} | |||
/** {@inheritDoc} */ | |||
public boolean needsOutputStream() { | |||
return true; | |||
} | |||
/** {@inheritDoc} */ | |||
public String[] getSupportedMimeTypes() { | |||
return MIMES; | |||
} | |||
} |
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: AFPElementMapping.java 397875 2006-04-28 11:58:33Z manuel $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.pcl.extensions; | |||
@@ -1,130 +1,130 @@ | |||
/* | |||
* 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 java.awt.Color; | |||
import java.awt.Dimension; | |||
import java.awt.Graphics2D; | |||
import java.awt.RenderingHints; | |||
import java.awt.geom.AffineTransform; | |||
import java.awt.geom.Rectangle2D; | |||
import java.awt.image.BufferedImage; | |||
import java.io.IOException; | |||
import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; | |||
import org.apache.fop.render.AbstractGraphics2DAdapter; | |||
import org.apache.fop.render.RendererContext; | |||
import org.apache.fop.render.RendererContext.RendererContextWrapper; | |||
import org.apache.fop.svg.PDFGraphics2D; | |||
/** | |||
* Graphics2DAdapter implementation for PDF. | |||
*/ | |||
public class PDFGraphics2DAdapter extends AbstractGraphics2DAdapter { | |||
private PDFRenderer renderer; | |||
/** | |||
* Main constructor | |||
* @param renderer the Renderer instance to which this instance belongs | |||
*/ | |||
public PDFGraphics2DAdapter(PDFRenderer renderer) { | |||
this.renderer = renderer; | |||
} | |||
/** {@inheritDoc} */ | |||
public void paintImage(Graphics2DImagePainter painter, | |||
RendererContext context, | |||
int x, int y, int width, int height) throws IOException { | |||
PDFSVGHandler.PDFInfo pdfInfo = PDFSVGHandler.getPDFInfo(context); | |||
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; | |||
renderer.saveGraphicsState(); | |||
renderer.setColor(Color.black, false, null); | |||
renderer.setColor(Color.black, true, null); | |||
//TODO Clip to the image area. | |||
// 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. | |||
renderer.currentStream.add(sx + " 0 0 " + sy + " " + fx + " " | |||
+ fy + " cm\n"); | |||
final boolean textAsShapes = false; | |||
if (pdfInfo.pdfContext == null) { | |||
pdfInfo.pdfContext = pdfInfo.pdfPage; | |||
} | |||
PDFGraphics2D graphics = new PDFGraphics2D(textAsShapes, | |||
pdfInfo.fi, pdfInfo.pdfDoc, | |||
pdfInfo.pdfContext, pdfInfo.pdfPage.referencePDF(), | |||
renderer.currentFontName, | |||
renderer.currentFontSize); | |||
graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); | |||
AffineTransform transform = new AffineTransform(); | |||
transform.translate(fx, fy); | |||
pdfInfo.pdfState.concatenate(transform); | |||
graphics.setPDFState(pdfInfo.pdfState); | |||
graphics.setOutputStream(pdfInfo.outputStream); | |||
if (pdfInfo.paintAsBitmap) { | |||
//Fallback solution: Paint to a BufferedImage | |||
int resolution = (int)Math.round(context.getUserAgent().getTargetResolution()); | |||
RendererContextWrapper ctx = RendererContext.wrapRendererContext(context); | |||
BufferedImage bi = paintToBufferedImage(painter, ctx, resolution, false, false); | |||
float scale = PDFRenderer.NORMAL_PDF_RESOLUTION | |||
/ context.getUserAgent().getTargetResolution(); | |||
graphics.drawImage(bi, new AffineTransform(scale, 0, 0, scale, 0, 0), null); | |||
} else { | |||
Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh); | |||
painter.paint(graphics, area); | |||
} | |||
pdfInfo.currentStream.add(graphics.getString()); | |||
renderer.restoreGraphicsState(); | |||
pdfInfo.pdfState.pop(); | |||
} | |||
/** {@inheritDoc} */ | |||
protected void setRenderingHintsForBufferedImage(Graphics2D g2d) { | |||
super.setRenderingHintsForBufferedImage(g2d); | |||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, | |||
RenderingHints.VALUE_ANTIALIAS_ON); | |||
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, | |||
RenderingHints.VALUE_TEXT_ANTIALIAS_ON); | |||
} | |||
} | |||
/* | |||
* 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 java.awt.Color; | |||
import java.awt.Dimension; | |||
import java.awt.Graphics2D; | |||
import java.awt.RenderingHints; | |||
import java.awt.geom.AffineTransform; | |||
import java.awt.geom.Rectangle2D; | |||
import java.awt.image.BufferedImage; | |||
import java.io.IOException; | |||
import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; | |||
import org.apache.fop.render.AbstractGraphics2DAdapter; | |||
import org.apache.fop.render.RendererContext; | |||
import org.apache.fop.render.RendererContext.RendererContextWrapper; | |||
import org.apache.fop.svg.PDFGraphics2D; | |||
/** | |||
* Graphics2DAdapter implementation for PDF. | |||
*/ | |||
public class PDFGraphics2DAdapter extends AbstractGraphics2DAdapter { | |||
private PDFRenderer renderer; | |||
/** | |||
* Main constructor | |||
* @param renderer the Renderer instance to which this instance belongs | |||
*/ | |||
public PDFGraphics2DAdapter(PDFRenderer renderer) { | |||
this.renderer = renderer; | |||
} | |||
/** {@inheritDoc} */ | |||
public void paintImage(Graphics2DImagePainter painter, | |||
RendererContext context, | |||
int x, int y, int width, int height) throws IOException { | |||
PDFSVGHandler.PDFInfo pdfInfo = PDFSVGHandler.getPDFInfo(context); | |||
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; | |||
renderer.saveGraphicsState(); | |||
renderer.setColor(Color.black, false, null); | |||
renderer.setColor(Color.black, true, null); | |||
//TODO Clip to the image area. | |||
// 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. | |||
renderer.currentStream.add(sx + " 0 0 " + sy + " " + fx + " " | |||
+ fy + " cm\n"); | |||
final boolean textAsShapes = false; | |||
if (pdfInfo.pdfContext == null) { | |||
pdfInfo.pdfContext = pdfInfo.pdfPage; | |||
} | |||
PDFGraphics2D graphics = new PDFGraphics2D(textAsShapes, | |||
pdfInfo.fi, pdfInfo.pdfDoc, | |||
pdfInfo.pdfContext, pdfInfo.pdfPage.referencePDF(), | |||
renderer.currentFontName, | |||
renderer.currentFontSize); | |||
graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); | |||
AffineTransform transform = new AffineTransform(); | |||
transform.translate(fx, fy); | |||
pdfInfo.pdfState.concatenate(transform); | |||
graphics.setPDFState(pdfInfo.pdfState); | |||
graphics.setOutputStream(pdfInfo.outputStream); | |||
if (pdfInfo.paintAsBitmap) { | |||
//Fallback solution: Paint to a BufferedImage | |||
int resolution = (int)Math.round(context.getUserAgent().getTargetResolution()); | |||
RendererContextWrapper ctx = RendererContext.wrapRendererContext(context); | |||
BufferedImage bi = paintToBufferedImage(painter, ctx, resolution, false, false); | |||
float scale = PDFRenderer.NORMAL_PDF_RESOLUTION | |||
/ context.getUserAgent().getTargetResolution(); | |||
graphics.drawImage(bi, new AffineTransform(scale, 0, 0, scale, 0, 0), null); | |||
} else { | |||
Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh); | |||
painter.paint(graphics, area); | |||
} | |||
pdfInfo.currentStream.add(graphics.getString()); | |||
renderer.restoreGraphicsState(); | |||
pdfInfo.pdfState.pop(); | |||
} | |||
/** {@inheritDoc} */ | |||
protected void setRenderingHintsForBufferedImage(Graphics2D g2d) { | |||
super.setRenderingHintsForBufferedImage(g2d); | |||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, | |||
RenderingHints.VALUE_ANTIALIAS_ON); | |||
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, | |||
RenderingHints.VALUE_TEXT_ANTIALIAS_ON); | |||
} | |||
} |
@@ -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; | |||
} | |||
} |
@@ -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; | |||
} | |||
} |
@@ -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(); | |||
} | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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"); | |||
} | |||
} |
@@ -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; | |||
} | |||
} |
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.ps; | |||
@@ -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; | |||
} | |||
} |
@@ -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(); | |||
} | |||
@@ -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.extensions; | |||
import org.xml.sax.ContentHandler; | |||
import org.xml.sax.SAXException; | |||
import org.xml.sax.helpers.AttributesImpl; | |||
import org.apache.xmlgraphics.util.XMLizable; | |||
import org.apache.fop.fo.extensions.ExtensionAttachment; | |||
/** | |||
* This is the pass-through value object for the PostScript extension. | |||
*/ | |||
public abstract class PSExtensionAttachment implements ExtensionAttachment, XMLizable { | |||
/** extension node content */ | |||
protected String content; | |||
/** The category URI for this extension attachment. */ | |||
public static final String CATEGORY = "apache:fop:extensions:postscript"; | |||
/** | |||
* Default constructor. | |||
* @param content the content of the setup code object | |||
*/ | |||
public PSExtensionAttachment(String content) { | |||
this.content = content; | |||
} | |||
/** | |||
* No-argument contructor. | |||
*/ | |||
public PSExtensionAttachment() { | |||
} | |||
/** | |||
* @return the category URI | |||
* @see org.apache.fop.fo.extensions.ExtensionAttachment#getCategory() | |||
*/ | |||
public String getCategory() { | |||
return CATEGORY; | |||
} | |||
/** @return the content */ | |||
public String getContent() { | |||
return content; | |||
} | |||
/** | |||
* Sets the content for the setup code object. | |||
* @param content The content to set. | |||
*/ | |||
public void setContent(String content) { | |||
this.content = content; | |||
} | |||
/** | |||
* Generates SAX events representing the object's state. | |||
* | |||
* @param handler ContentHandler instance to send the SAX events to | |||
* @throws SAXException if there's a problem generating the SAX events | |||
* @see org.apache.fop.util.XMLizable#toSAX(org.xml.sax.ContentHandler) | |||
*/ | |||
public void toSAX(ContentHandler handler) throws SAXException { | |||
AttributesImpl atts = new AttributesImpl(); | |||
String element = getElement(); | |||
handler.startElement(CATEGORY, element, element, atts); | |||
if (content != null && content.length() > 0) { | |||
char[] chars = content.toCharArray(); | |||
handler.characters(chars, 0, chars.length); | |||
} | |||
handler.endElement(CATEGORY, element, element); | |||
} | |||
/** @return type name */ | |||
public String getType() { | |||
String className = getClass().getName(); | |||
return className.substring(className.lastIndexOf('.') + 3); | |||
} | |||
/** | |||
* @return a string representation of this object | |||
* @see java.lang.Object#toString() | |||
*/ | |||
public String toString() { | |||
return getType() + ": content=" + content; | |||
} | |||
/** @return element */ | |||
protected abstract String getElement(); | |||
} | |||
/* | |||
* 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; | |||
import org.xml.sax.ContentHandler; | |||
import org.xml.sax.SAXException; | |||
import org.xml.sax.helpers.AttributesImpl; | |||
import org.apache.xmlgraphics.util.XMLizable; | |||
import org.apache.fop.fo.extensions.ExtensionAttachment; | |||
/** | |||
* This is the pass-through value object for the PostScript extension. | |||
*/ | |||
public abstract class PSExtensionAttachment implements ExtensionAttachment, XMLizable { | |||
/** extension node content */ | |||
protected String content; | |||
/** The category URI for this extension attachment. */ | |||
public static final String CATEGORY = "apache:fop:extensions:postscript"; | |||
/** | |||
* Default constructor. | |||
* @param content the content of the setup code object | |||
*/ | |||
public PSExtensionAttachment(String content) { | |||
this.content = content; | |||
} | |||
/** | |||
* No-argument contructor. | |||
*/ | |||
public PSExtensionAttachment() { | |||
} | |||
/** | |||
* @return the category URI | |||
* @see org.apache.fop.fo.extensions.ExtensionAttachment#getCategory() | |||
*/ | |||
public String getCategory() { | |||
return CATEGORY; | |||
} | |||
/** @return the content */ | |||
public String getContent() { | |||
return content; | |||
} | |||
/** | |||
* Sets the content for the setup code object. | |||
* @param content The content to set. | |||
*/ | |||
public void setContent(String content) { | |||
this.content = content; | |||
} | |||
/** | |||
* Generates SAX events representing the object's state. | |||
* | |||
* @param handler ContentHandler instance to send the SAX events to | |||
* @throws SAXException if there's a problem generating the SAX events | |||
* @see org.apache.fop.util.XMLizable#toSAX(org.xml.sax.ContentHandler) | |||
*/ | |||
public void toSAX(ContentHandler handler) throws SAXException { | |||
AttributesImpl atts = new AttributesImpl(); | |||
String element = getElement(); | |||
handler.startElement(CATEGORY, element, element, atts); | |||
if (content != null && content.length() > 0) { | |||
char[] chars = content.toCharArray(); | |||
handler.characters(chars, 0, chars.length); | |||
} | |||
handler.endElement(CATEGORY, element, element); | |||
} | |||
/** @return type name */ | |||
public String getType() { | |||
String className = getClass().getName(); | |||
return className.substring(className.lastIndexOf('.') + 3); | |||
} | |||
/** | |||
* @return a string representation of this object | |||
* @see java.lang.Object#toString() | |||
*/ | |||
public String toString() { | |||
return getType() + ": content=" + content; | |||
} | |||
/** @return element */ | |||
protected abstract String getElement(); | |||
} |
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id: $ */ | |||
/* $Id$ */ | |||
package org.apache.fop.render.ps.extensions; | |||
@@ -1,114 +1,114 @@ | |||
/* | |||
* 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; | |||
import org.xml.sax.ContentHandler; | |||
import org.xml.sax.SAXException; | |||
import org.xml.sax.helpers.AttributesImpl; | |||
/** | |||
* Element for postscript setpagedevice instruction | |||
* This is a an extension which provides a pass-through value | |||
* dictionary object for the postscript setpagedevice instruction. | |||
*/ | |||
public class PSSetPageDevice extends PSExtensionAttachment { | |||
/** element name */ | |||
protected static final String ELEMENT = "ps-setpagedevice"; | |||
private static final String ATT_NAME = "name"; | |||
/** | |||
* name attribute | |||
*/ | |||
protected String name = null; | |||
/** | |||
* default constructor | |||
* @param content set page device dictionary | |||
*/ | |||
public PSSetPageDevice(String content) { | |||
super(content); | |||
} | |||
/** | |||
* constructor | |||
* @param name name attribute of this setpagedevice content | |||
* @param content set page device dictionary | |||
*/ | |||
public PSSetPageDevice(String name, String content) { | |||
this(content); | |||
this.name = name; | |||
} | |||
/** | |||
* constructor | |||
*/ | |||
public PSSetPageDevice() { | |||
} | |||
/** @return the name */ | |||
public String getName() { | |||
return name; | |||
} | |||
/** | |||
* Sets the name of the setup code object. | |||
* @param name The name to set. | |||
*/ | |||
public void setName(String name) { | |||
this.name = name; | |||
} | |||
/** | |||
* @return a string representation of this object | |||
* @see java.lang.Object#toString() | |||
*/ | |||
public String toString() { | |||
return "PSSetPageDevice(name=" + getName() + ", content='" + getContent() + "')"; | |||
} | |||
/** | |||
* @return a string representation of this object | |||
* @see org.apache.fop.render.ps.extensions.PSExtensionAttachment#getElement() | |||
*/ | |||
protected String getElement() { | |||
return ELEMENT; | |||
} | |||
/** | |||
* Generates SAX events representing the object's state. | |||
* @param handler ContentHandler instance to send the SAX events to | |||
* @throws SAXException if there's a problem generating the SAX events | |||
* @see org.apache.xmlgraphics.util.XMLizable#toSAX(org.xml.sax.ContentHandler) | |||
*/ | |||
public void toSAX(ContentHandler handler) throws SAXException { | |||
AttributesImpl atts = new AttributesImpl(); | |||
if (name != null && name.length() > 0) { | |||
atts.addAttribute(null, ATT_NAME, ATT_NAME, "CDATA", name); | |||
} | |||
String element = getElement(); | |||
handler.startElement(CATEGORY, element, element, atts); | |||
if (content != null && content.length() > 0) { | |||
char[] chars = content.toCharArray(); | |||
handler.characters(chars, 0, chars.length); | |||
} | |||
handler.endElement(CATEGORY, element, element); | |||
} | |||
} | |||
/* | |||
* 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; | |||
import org.xml.sax.ContentHandler; | |||
import org.xml.sax.SAXException; | |||
import org.xml.sax.helpers.AttributesImpl; | |||
/** | |||
* Element for postscript setpagedevice instruction | |||
* This is a an extension which provides a pass-through value | |||
* dictionary object for the postscript setpagedevice instruction. | |||
*/ | |||
public class PSSetPageDevice extends PSExtensionAttachment { | |||
/** element name */ | |||
protected static final String ELEMENT = "ps-setpagedevice"; | |||
private static final String ATT_NAME = "name"; | |||
/** | |||
* name attribute | |||
*/ | |||
protected String name = null; | |||
/** | |||
* default constructor | |||
* @param content set page device dictionary | |||
*/ | |||
public PSSetPageDevice(String content) { | |||
super(content); | |||
} | |||
/** | |||
* constructor | |||
* @param name name attribute of this setpagedevice content | |||
* @param content set page device dictionary | |||
*/ | |||
public PSSetPageDevice(String name, String content) { | |||
this(content); | |||
this.name = name; | |||
} | |||
/** | |||
* constructor | |||
*/ | |||
public PSSetPageDevice() { | |||
} | |||
/** @return the name */ | |||
public String getName() { | |||
return name; | |||
} | |||
/** | |||
* Sets the name of the setup code object. | |||
* @param name The name to set. | |||
*/ | |||
public void setName(String name) { | |||
this.name = name; | |||
} | |||
/** | |||
* @return a string representation of this object | |||
* @see java.lang.Object#toString() | |||
*/ | |||
public String toString() { | |||
return "PSSetPageDevice(name=" + getName() + ", content='" + getContent() + "')"; | |||
} | |||
/** | |||
* @return a string representation of this object | |||
* @see org.apache.fop.render.ps.extensions.PSExtensionAttachment#getElement() | |||
*/ | |||
protected String getElement() { | |||
return ELEMENT; | |||
} | |||
/** | |||
* Generates SAX events representing the object's state. | |||
* @param handler ContentHandler instance to send the SAX events to | |||
* @throws SAXException if there's a problem generating the SAX events | |||
* @see org.apache.xmlgraphics.util.XMLizable#toSAX(org.xml.sax.ContentHandler) | |||
*/ | |||
public void toSAX(ContentHandler handler) throws SAXException { | |||
AttributesImpl atts = new AttributesImpl(); | |||
if (name != null && name.length() > 0) { | |||
atts.addAttribute(null, ATT_NAME, ATT_NAME, "CDATA", name); | |||
} | |||
String element = getElement(); | |||
handler.startElement(CATEGORY, element, element, atts); | |||
if (content != null && content.length() > 0) { | |||
char[] chars = content.toCharArray(); | |||
handler.characters(chars, 0, chars.length); | |||
} | |||
handler.endElement(CATEGORY, element, element); | |||
} | |||
} |
@@ -1,95 +1,95 @@ | |||
/* | |||
* 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; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.fo.Constants; | |||
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.Attributes; | |||
import org.xml.sax.Locator; | |||
/** | |||
* Extension element for ps:ps-setpagedevice. | |||
*/ | |||
public class PSSetPageDeviceElement extends AbstractPSExtensionElement { | |||
protected static final String ELEMENT = "ps-setpagedevice"; | |||
/** | |||
* Main constructor | |||
* @param parent parent FO node | |||
*/ | |||
protected PSSetPageDeviceElement(FONode parent) { | |||
super(parent); | |||
} | |||
/** | |||
* Called after processNode() is called. Subclasses can do additional processing. | |||
* @throws FOPException if there's a problem during processing | |||
* @see org.apache.fop.fo.FONode#startOfNode() | |||
*/ | |||
protected void startOfNode() throws FOPException { | |||
super.startOfNode(); | |||
if ( !((parent.getNameId() == Constants.FO_DECLARATIONS) | |||
|| (parent.getNameId() == Constants.FO_SIMPLE_PAGE_MASTER)) ) { | |||
throw new ValidationException( getName() | |||
+ " must be a child of fo:declarations or fo:simple-page-master."); | |||
} | |||
} | |||
/** | |||
* Initialize the node with its name, location information, and attributes | |||
* The attributes must be used immediately as the sax attributes | |||
* will be altered for the next element. | |||
* @param elementName element name (e.g., "fo:block") | |||
* @param locator Locator object (ignored by default) | |||
* @param attlist Collection of attributes passed to us from the parser. | |||
* @param propertyList property list | |||
* @throws FOPException if there's a problem during processing | |||
* @see org.apache.fop.fo.FONode#processNode | |||
*/ | |||
public void processNode(String elementName, Locator locator, | |||
Attributes attlist, PropertyList propertyList) | |||
throws FOPException { | |||
String name = attlist.getValue("name"); | |||
if (name != null && name.length() > 0) { | |||
((PSSetPageDevice)getExtensionAttachment()).setName(name); | |||
} | |||
} | |||
/** | |||
* @return local name | |||
* @see org.apache.fop.fo.FONode#getLocalName() */ | |||
public String getLocalName() { | |||
return ELEMENT; | |||
} | |||
/** | |||
* @return a new PSSetPageDevice object | |||
* @see org.apache.fop.render.ps.extensions.AbstractPSExtensionElement | |||
* #instantiateExtensionAttachment() | |||
*/ | |||
protected ExtensionAttachment instantiateExtensionAttachment() { | |||
return new PSSetPageDevice(); | |||
} | |||
} | |||
/* | |||
* 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; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.fo.Constants; | |||
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.Attributes; | |||
import org.xml.sax.Locator; | |||
/** | |||
* Extension element for ps:ps-setpagedevice. | |||
*/ | |||
public class PSSetPageDeviceElement extends AbstractPSExtensionElement { | |||
protected static final String ELEMENT = "ps-setpagedevice"; | |||
/** | |||
* Main constructor | |||
* @param parent parent FO node | |||
*/ | |||
protected PSSetPageDeviceElement(FONode parent) { | |||
super(parent); | |||
} | |||
/** | |||
* Called after processNode() is called. Subclasses can do additional processing. | |||
* @throws FOPException if there's a problem during processing | |||
* @see org.apache.fop.fo.FONode#startOfNode() | |||
*/ | |||
protected void startOfNode() throws FOPException { | |||
super.startOfNode(); | |||
if ( !((parent.getNameId() == Constants.FO_DECLARATIONS) | |||
|| (parent.getNameId() == Constants.FO_SIMPLE_PAGE_MASTER)) ) { | |||
throw new ValidationException( getName() | |||
+ " must be a child of fo:declarations or fo:simple-page-master."); | |||
} | |||
} | |||
/** | |||
* Initialize the node with its name, location information, and attributes | |||
* The attributes must be used immediately as the sax attributes | |||
* will be altered for the next element. | |||
* @param elementName element name (e.g., "fo:block") | |||
* @param locator Locator object (ignored by default) | |||
* @param attlist Collection of attributes passed to us from the parser. | |||
* @param propertyList property list | |||
* @throws FOPException if there's a problem during processing | |||
* @see org.apache.fop.fo.FONode#processNode | |||
*/ | |||
public void processNode(String elementName, Locator locator, | |||
Attributes attlist, PropertyList propertyList) | |||
throws FOPException { | |||
String name = attlist.getValue("name"); | |||
if (name != null && name.length() > 0) { | |||
((PSSetPageDevice)getExtensionAttachment()).setName(name); | |||
} | |||
} | |||
/** | |||
* @return local name | |||
* @see org.apache.fop.fo.FONode#getLocalName() */ | |||
public String getLocalName() { | |||
return ELEMENT; | |||
} | |||
/** | |||
* @return a new PSSetPageDevice object | |||
* @see org.apache.fop.render.ps.extensions.AbstractPSExtensionElement | |||
* #instantiateExtensionAttachment() | |||
*/ | |||
protected ExtensionAttachment instantiateExtensionAttachment() { | |||
return new PSSetPageDevice(); | |||
} | |||
} |