git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@679326 13f79535-47bb-0310-9956-ffa450edef68pull/37/head
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding; | package embedding; | ||||
//Java | //Java |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding; | package embedding; | ||||
// Java | // Java | ||||
// configure fopFactory as desired | // configure fopFactory as desired | ||||
private FopFactory fopFactory = FopFactory.newInstance(); | private FopFactory fopFactory = FopFactory.newInstance(); | ||||
/** xsl-fo namespace URI */ | /** xsl-fo namespace URI */ | ||||
protected static String foNS = "http://www.w3.org/1999/XSL/Format"; | protected static String foNS = "http://www.w3.org/1999/XSL/Format"; | ||||
try { | try { | ||||
FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); | FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); | ||||
// configure foUserAgent as desired | // configure foUserAgent as desired | ||||
// Setup output | // Setup output | ||||
OutputStream out = new java.io.FileOutputStream(pdf); | OutputStream out = new java.io.FileOutputStream(pdf); | ||||
out = new java.io.BufferedOutputStream(out); | out = new java.io.BufferedOutputStream(out); | ||||
try { | try { | ||||
// Construct fop with desired output format and output stream | // Construct fop with desired output format and output stream | ||||
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out); | Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out); | ||||
// Setup Identity Transformer | // Setup Identity Transformer | ||||
TransformerFactory factory = TransformerFactory.newInstance(); | TransformerFactory factory = TransformerFactory.newInstance(); | ||||
Transformer transformer = factory.newTransformer(); // identity transformer | Transformer transformer = factory.newTransformer(); // identity transformer | ||||
// Setup input for XSLT transformation | // Setup input for XSLT transformation | ||||
Source src = new DOMSource(xslfoDoc); | Source src = new DOMSource(xslfoDoc); | ||||
// Resulting SAX events (the generated FO) must be piped through to FOP | // Resulting SAX events (the generated FO) must be piped through to FOP | ||||
Result res = new SAXResult(fop.getDefaultHandler()); | Result res = new SAXResult(fop.getDefaultHandler()); | ||||
// Start XSLT transformation and FOP processing | // Start XSLT transformation and FOP processing | ||||
transformer.transform(src, res); | transformer.transform(src, res); | ||||
} finally { | } finally { | ||||
out.close(); | out.close(); | ||||
} | } | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); | ||||
System.exit(-1); | System.exit(-1); | ||||
public static void main(String[] args) { | public static void main(String[] args) { | ||||
try { | try { | ||||
System.out.println("FOP ExampleDOM2PDF\n"); | System.out.println("FOP ExampleDOM2PDF\n"); | ||||
//Setup directories | //Setup directories | ||||
File baseDir = new File("."); | File baseDir = new File("."); | ||||
File outDir = new File(baseDir, "out"); | File outDir = new File(baseDir, "out"); | ||||
outDir.mkdirs(); | outDir.mkdirs(); | ||||
//Setup output file | //Setup output file | ||||
File pdffile = new File(outDir, "ResultDOM2PDF.pdf"); | File pdffile = new File(outDir, "ResultDOM2PDF.pdf"); | ||||
System.out.println("PDF Output File: " + pdffile); | System.out.println("PDF Output File: " + pdffile); | ||||
System.out.println(); | System.out.println(); | ||||
Document foDoc = buildDOMDocument(); | Document foDoc = buildDOMDocument(); | ||||
ExampleDOM2PDF app = new ExampleDOM2PDF(); | ExampleDOM2PDF app = new ExampleDOM2PDF(); | ||||
app.convertDOM2PDF(foDoc, pdffile); | app.convertDOM2PDF(foDoc, pdffile); | ||||
System.out.println("Success!"); | System.out.println("Success!"); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); | ||||
System.exit(-1); | System.exit(-1); | ||||
// Create a sample XSL-FO DOM document | // Create a sample XSL-FO DOM document | ||||
Document foDoc = null; | Document foDoc = null; | ||||
Element root = null, ele1 = null, ele2 = null, ele3 = null; | Element root = null, ele1 = null, ele2 = null, ele3 = null; | ||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | ||||
dbf.setNamespaceAware(true); | dbf.setNamespaceAware(true); | ||||
DocumentBuilder db = dbf.newDocumentBuilder(); | DocumentBuilder db = dbf.newDocumentBuilder(); | ||||
foDoc = db.newDocument(); | foDoc = db.newDocument(); | ||||
root = foDoc.createElementNS(foNS, "fo:root"); | root = foDoc.createElementNS(foNS, "fo:root"); | ||||
foDoc.appendChild(root); | foDoc.appendChild(root); | ||||
ele1 = foDoc.createElementNS(foNS, "fo:layout-master-set"); | ele1 = foDoc.createElementNS(foNS, "fo:layout-master-set"); | ||||
root.appendChild(ele1); | root.appendChild(ele1); | ||||
ele2 = foDoc.createElementNS(foNS, "fo:simple-page-master"); | ele2 = foDoc.createElementNS(foNS, "fo:simple-page-master"); | ||||
* @param newNodeName name of the new node | * @param newNodeName name of the new node | ||||
* @param textVal content of the element | * @param textVal content of the element | ||||
*/ | */ | ||||
protected static void addElement(Node parent, String newNodeName, | |||||
protected static void addElement(Node parent, String newNodeName, | |||||
String textVal) { | String textVal) { | ||||
if (textVal == null) { | if (textVal == null) { | ||||
return; | return; |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding; | package embedding; | ||||
// Java | // Java | ||||
// configure fopFactory as desired | // configure fopFactory as desired | ||||
private FopFactory fopFactory = FopFactory.newInstance(); | private FopFactory fopFactory = FopFactory.newInstance(); | ||||
private DocPrintJob createDocPrintJob() { | private DocPrintJob createDocPrintJob() { | ||||
PrintService[] services = PrintServiceLookup.lookupPrintServices( | PrintService[] services = PrintServiceLookup.lookupPrintServices( | ||||
DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); | DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); | ||||
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); | PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); | ||||
PrintService printService = ServiceUI.printDialog(null, 50, 50, | |||||
PrintService printService = ServiceUI.printDialog(null, 50, 50, | |||||
services, services[0], null, attributes); | services, services[0], null, attributes); | ||||
if (printService != null) { | if (printService != null) { | ||||
return printService.createPrintJob(); | return printService.createPrintJob(); | ||||
return null; | return null; | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Prints an FO file using JPS. | * Prints an FO file using JPS. | ||||
* @param fo the FO file | * @param fo the FO file | ||||
*/ | */ | ||||
public void printFO(File fo) | public void printFO(File fo) | ||||
throws IOException, FOPException, TransformerException, PrintException { | throws IOException, FOPException, TransformerException, PrintException { | ||||
//Set up DocPrintJob instance | //Set up DocPrintJob instance | ||||
DocPrintJob printJob = createDocPrintJob(); | DocPrintJob printJob = createDocPrintJob(); | ||||
PageableRenderer renderer = new PageableRenderer(); | PageableRenderer renderer = new PageableRenderer(); | ||||
renderer.setUserAgent(userAgent); | renderer.setUserAgent(userAgent); | ||||
userAgent.setRendererOverride(renderer); | userAgent.setRendererOverride(renderer); | ||||
// Construct FOP with desired output format | // Construct FOP with desired output format | ||||
Fop fop = fopFactory.newFop(userAgent); | Fop fop = fopFactory.newFop(userAgent); | ||||
// Setup JAXP using identity transformer | // Setup JAXP using identity transformer | ||||
TransformerFactory factory = TransformerFactory.newInstance(); | TransformerFactory factory = TransformerFactory.newInstance(); | ||||
Transformer transformer = factory.newTransformer(); // identity transformer | Transformer transformer = factory.newTransformer(); // identity transformer | ||||
// Setup input stream | // Setup input stream | ||||
Source src = new StreamSource(fo); | Source src = new StreamSource(fo); | ||||
// Resulting SAX events (the generated FO) must be piped through to FOP | // Resulting SAX events (the generated FO) must be piped through to FOP | ||||
Result res = new SAXResult(fop.getDefaultHandler()); | Result res = new SAXResult(fop.getDefaultHandler()); | ||||
// Start XSLT transformation and FOP processing | // Start XSLT transformation and FOP processing | ||||
transformer.transform(src, res); | transformer.transform(src, res); | ||||
try { | try { | ||||
System.out.println("FOP ExampleFO2JPSPrint\n"); | System.out.println("FOP ExampleFO2JPSPrint\n"); | ||||
System.out.println("Preparing..."); | System.out.println("Preparing..."); | ||||
//Setup directories | //Setup directories | ||||
File baseDir = new File("."); | File baseDir = new File("."); | ||||
File outDir = new File(baseDir, "out"); | File outDir = new File(baseDir, "out"); | ||||
outDir.mkdirs(); | outDir.mkdirs(); | ||||
//Setup input and output files | |||||
//Setup input and output files | |||||
File fofile = new File(baseDir, "xml/fo/helloworld.fo"); | File fofile = new File(baseDir, "xml/fo/helloworld.fo"); | ||||
System.out.println("Input: XSL-FO (" + fofile + ")"); | System.out.println("Input: XSL-FO (" + fofile + ")"); | ||||
System.out.println("Output: JPS (Java Printing System)"); | System.out.println("Output: JPS (Java Printing System)"); | ||||
System.out.println(); | System.out.println(); | ||||
System.out.println("Transforming..."); | System.out.println("Transforming..."); | ||||
ExampleFO2JPSPrint app = new ExampleFO2JPSPrint(); | ExampleFO2JPSPrint app = new ExampleFO2JPSPrint(); | ||||
app.printFO(fofile); | app.printFO(fofile); | ||||
System.out.println("Success!"); | System.out.println("Success!"); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding; | package embedding; | ||||
// Java | // Java | ||||
// configure fopFactory as desired | // configure fopFactory as desired | ||||
private FopFactory fopFactory = FopFactory.newInstance(); | private FopFactory fopFactory = FopFactory.newInstance(); | ||||
/** | /** | ||||
* Prints an FO file using an old-style PrinterJob. | * Prints an FO file using an old-style PrinterJob. | ||||
* @param fo the FO file | * @param fo the FO file | ||||
* @throws FOPException In case of a FOP problem | * @throws FOPException In case of a FOP problem | ||||
*/ | */ | ||||
public void printFO(File fo) throws IOException, FOPException { | public void printFO(File fo) throws IOException, FOPException { | ||||
//Set up PrinterJob instance | //Set up PrinterJob instance | ||||
PrinterJob printerJob = PrinterJob.getPrinterJob(); | PrinterJob printerJob = PrinterJob.getPrinterJob(); | ||||
printerJob.setJobName("FOP Printing Example"); | printerJob.setJobName("FOP Printing Example"); | ||||
// Setup JAXP using identity transformer | // Setup JAXP using identity transformer | ||||
TransformerFactory factory = TransformerFactory.newInstance(); | TransformerFactory factory = TransformerFactory.newInstance(); | ||||
Transformer transformer = factory.newTransformer(); // identity transformer | Transformer transformer = factory.newTransformer(); // identity transformer | ||||
// Setup input stream | // Setup input stream | ||||
Source src = new StreamSource(fo); | Source src = new StreamSource(fo); | ||||
// Resulting SAX events (the generated FO) must be piped through to FOP | // Resulting SAX events (the generated FO) must be piped through to FOP | ||||
Result res = new SAXResult(fop.getDefaultHandler()); | Result res = new SAXResult(fop.getDefaultHandler()); | ||||
// Start XSLT transformation and FOP processing | // Start XSLT transformation and FOP processing | ||||
transformer.transform(src, res); | transformer.transform(src, res); | ||||
try { | try { | ||||
System.out.println("FOP ExampleFO2OldStylePrint\n"); | System.out.println("FOP ExampleFO2OldStylePrint\n"); | ||||
System.out.println("Preparing..."); | System.out.println("Preparing..."); | ||||
//Setup directories | //Setup directories | ||||
File baseDir = new File("."); | File baseDir = new File("."); | ||||
File outDir = new File(baseDir, "out"); | File outDir = new File(baseDir, "out"); | ||||
outDir.mkdirs(); | outDir.mkdirs(); | ||||
//Setup input and output files | |||||
//Setup input and output files | |||||
File fofile = new File(baseDir, "xml/fo/helloworld.fo"); | File fofile = new File(baseDir, "xml/fo/helloworld.fo"); | ||||
System.out.println("Input: XSL-FO (" + fofile + ")"); | System.out.println("Input: XSL-FO (" + fofile + ")"); | ||||
System.out.println("Output: old-style printing using PrinterJob"); | System.out.println("Output: old-style printing using PrinterJob"); | ||||
System.out.println(); | System.out.println(); | ||||
System.out.println("Transforming..."); | System.out.println("Transforming..."); | ||||
ExampleFO2OldStylePrint app = new ExampleFO2OldStylePrint(); | ExampleFO2OldStylePrint app = new ExampleFO2OldStylePrint(); | ||||
app.printFO(fofile); | app.printFO(fofile); | ||||
System.out.println("Success!"); | System.out.println("Success!"); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding; | package embedding; | ||||
// Java | // Java | ||||
* @throws FOPException In case of a FOP problem | * @throws FOPException In case of a FOP problem | ||||
*/ | */ | ||||
public void convertFO2PDF(File fo, File pdf) throws IOException, FOPException { | public void convertFO2PDF(File fo, File pdf) throws IOException, FOPException { | ||||
OutputStream out = null; | OutputStream out = null; | ||||
try { | try { | ||||
FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); | FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); | ||||
// configure foUserAgent as desired | // configure foUserAgent as desired | ||||
// Setup output stream. Note: Using BufferedOutputStream | // Setup output stream. Note: Using BufferedOutputStream | ||||
// for performance reasons (helpful with FileOutputStreams). | // for performance reasons (helpful with FileOutputStreams). | ||||
out = new FileOutputStream(pdf); | out = new FileOutputStream(pdf); | ||||
// Setup JAXP using identity transformer | // Setup JAXP using identity transformer | ||||
TransformerFactory factory = TransformerFactory.newInstance(); | TransformerFactory factory = TransformerFactory.newInstance(); | ||||
Transformer transformer = factory.newTransformer(); // identity transformer | Transformer transformer = factory.newTransformer(); // identity transformer | ||||
// Setup input stream | // Setup input stream | ||||
Source src = new StreamSource(fo); | Source src = new StreamSource(fo); | ||||
// Resulting SAX events (the generated FO) must be piped through to FOP | // Resulting SAX events (the generated FO) must be piped through to FOP | ||||
Result res = new SAXResult(fop.getDefaultHandler()); | Result res = new SAXResult(fop.getDefaultHandler()); | ||||
// Start XSLT transformation and FOP processing | // Start XSLT transformation and FOP processing | ||||
transformer.transform(src, res); | transformer.transform(src, res); | ||||
// Result processing | // Result processing | ||||
FormattingResults foResults = fop.getResults(); | FormattingResults foResults = fop.getResults(); | ||||
java.util.List pageSequences = foResults.getPageSequences(); | java.util.List pageSequences = foResults.getPageSequences(); | ||||
for (java.util.Iterator it = pageSequences.iterator(); it.hasNext();) { | for (java.util.Iterator it = pageSequences.iterator(); it.hasNext();) { | ||||
PageSequenceResults pageSequenceResults = (PageSequenceResults)it.next(); | PageSequenceResults pageSequenceResults = (PageSequenceResults)it.next(); | ||||
System.out.println("PageSequence " | |||||
+ (String.valueOf(pageSequenceResults.getID()).length() > 0 | |||||
? pageSequenceResults.getID() : "<no id>") | |||||
System.out.println("PageSequence " | |||||
+ (String.valueOf(pageSequenceResults.getID()).length() > 0 | |||||
? pageSequenceResults.getID() : "<no id>") | |||||
+ " generated " + pageSequenceResults.getPageCount() + " pages."); | + " generated " + pageSequenceResults.getPageCount() + " pages."); | ||||
} | } | ||||
System.out.println("Generated " + foResults.getPageCount() + " pages in total."); | System.out.println("Generated " + foResults.getPageCount() + " pages in total."); | ||||
try { | try { | ||||
System.out.println("FOP ExampleFO2PDF\n"); | System.out.println("FOP ExampleFO2PDF\n"); | ||||
System.out.println("Preparing..."); | System.out.println("Preparing..."); | ||||
//Setup directories | //Setup directories | ||||
File baseDir = new File("."); | File baseDir = new File("."); | ||||
File outDir = new File(baseDir, "out"); | File outDir = new File(baseDir, "out"); | ||||
outDir.mkdirs(); | outDir.mkdirs(); | ||||
//Setup input and output files | |||||
//Setup input and output files | |||||
File fofile = new File(baseDir, "xml/fo/helloworld.fo"); | File fofile = new File(baseDir, "xml/fo/helloworld.fo"); | ||||
//File fofile = new File(baseDir, "../fo/pagination/franklin_2pageseqs.fo"); | //File fofile = new File(baseDir, "../fo/pagination/franklin_2pageseqs.fo"); | ||||
File pdffile = new File(outDir, "ResultFO2PDF.pdf"); | File pdffile = new File(outDir, "ResultFO2PDF.pdf"); | ||||
System.out.println("Output: PDF (" + pdffile + ")"); | System.out.println("Output: PDF (" + pdffile + ")"); | ||||
System.out.println(); | System.out.println(); | ||||
System.out.println("Transforming..."); | System.out.println("Transforming..."); | ||||
ExampleFO2PDF app = new ExampleFO2PDF(); | ExampleFO2PDF app = new ExampleFO2PDF(); | ||||
app.convertFO2PDF(fofile, pdffile); | app.convertFO2PDF(fofile, pdffile); | ||||
System.out.println("Success!"); | System.out.println("Success!"); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding; | package embedding; | ||||
// Java | // Java | ||||
// configure foUserAgent as desired | // configure foUserAgent as desired | ||||
OutputStream out = null; | OutputStream out = null; | ||||
try { | try { | ||||
// Setup output stream. Note: Using BufferedOutputStream | // Setup output stream. Note: Using BufferedOutputStream | ||||
// for performance reasons (helpful with FileOutputStreams). | // for performance reasons (helpful with FileOutputStreams). | ||||
out = new FileOutputStream(pdf); | out = new FileOutputStream(pdf); | ||||
out = new BufferedOutputStream(out); | out = new BufferedOutputStream(out); | ||||
// Construct fop and setup output format | // Construct fop and setup output format | ||||
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out); | Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out); | ||||
factory.setNamespaceAware(true); | factory.setNamespaceAware(true); | ||||
// throws ParserConfigurationException | // throws ParserConfigurationException | ||||
SAXParser parser = factory.newSAXParser(); | SAXParser parser = factory.newSAXParser(); | ||||
// Obtain FOP's DefaultHandler | // Obtain FOP's DefaultHandler | ||||
// throws FOPException | // throws FOPException | ||||
DefaultHandler dh = fop.getDefaultHandler(); | DefaultHandler dh = fop.getDefaultHandler(); | ||||
try { | try { | ||||
System.out.println("FOP ExampleFO2PDFUsingSAXParser\n"); | System.out.println("FOP ExampleFO2PDFUsingSAXParser\n"); | ||||
System.out.println("Preparing..."); | System.out.println("Preparing..."); | ||||
//Setup directories | //Setup directories | ||||
File baseDir = new File("."); | File baseDir = new File("."); | ||||
File outDir = new File(baseDir, "out"); | File outDir = new File(baseDir, "out"); | ||||
outDir.mkdirs(); | outDir.mkdirs(); | ||||
//Setup input and output files | |||||
//Setup input and output files | |||||
File fofile = new File(baseDir, "xml/fo/helloworld.fo"); | File fofile = new File(baseDir, "xml/fo/helloworld.fo"); | ||||
File pdffile = new File(outDir, "ResultFO2PDFUsingSAXParser.pdf"); | File pdffile = new File(outDir, "ResultFO2PDFUsingSAXParser.pdf"); | ||||
System.out.println("Output: PDF (" + pdffile + ")"); | System.out.println("Output: PDF (" + pdffile + ")"); | ||||
System.out.println(); | System.out.println(); | ||||
System.out.println("Transforming..."); | System.out.println("Transforming..."); | ||||
ExampleFO2PDFUsingSAXParser app = new ExampleFO2PDFUsingSAXParser(); | ExampleFO2PDFUsingSAXParser app = new ExampleFO2PDFUsingSAXParser(); | ||||
app.convertFO2PDF(fofile, pdffile); | app.convertFO2PDF(fofile, pdffile); | ||||
System.out.println("Success!"); | System.out.println("Success!"); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding; | package embedding; | ||||
// Java | // Java | ||||
* @throws FOPException In case of a FOP problem | * @throws FOPException In case of a FOP problem | ||||
*/ | */ | ||||
public void convertFO2RTF(File fo, File rtf) throws IOException, FOPException { | public void convertFO2RTF(File fo, File rtf) throws IOException, FOPException { | ||||
FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); | FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); | ||||
// configure foUserAgent as desired | // configure foUserAgent as desired | ||||
OutputStream out = null; | OutputStream out = null; | ||||
try { | try { | ||||
// Setup output stream. Note: Using BufferedOutputStream | // Setup output stream. Note: Using BufferedOutputStream | ||||
// for performance reasons (helpful with FileOutputStreams). | // for performance reasons (helpful with FileOutputStreams). | ||||
// Construct fop with desired output format | // Construct fop with desired output format | ||||
Fop fop = fopFactory.newFop(MimeConstants.MIME_RTF, foUserAgent, out); | Fop fop = fopFactory.newFop(MimeConstants.MIME_RTF, foUserAgent, out); | ||||
// Setup JAXP using identity transformer | // Setup JAXP using identity transformer | ||||
TransformerFactory factory = TransformerFactory.newInstance(); | TransformerFactory factory = TransformerFactory.newInstance(); | ||||
Transformer transformer = factory.newTransformer(); // identity transformer | Transformer transformer = factory.newTransformer(); // identity transformer | ||||
// Setup input stream | // Setup input stream | ||||
Source src = new StreamSource(fo); | Source src = new StreamSource(fo); | ||||
// Resulting SAX events (the generated FO) must be piped through to FOP | // Resulting SAX events (the generated FO) must be piped through to FOP | ||||
Result res = new SAXResult(fop.getDefaultHandler()); | Result res = new SAXResult(fop.getDefaultHandler()); | ||||
// Start XSLT transformation and FOP processing | // Start XSLT transformation and FOP processing | ||||
transformer.transform(src, res); | transformer.transform(src, res); | ||||
// Please note: getResults() won't work for RTF and other flow formats (like MIF) | // Please note: getResults() won't work for RTF and other flow formats (like MIF) | ||||
// as the layout engine is not involved in the conversion. The page-breaking | // as the layout engine is not involved in the conversion. The page-breaking | ||||
// is done by the application opening the generated file (like MS Word). | // is done by the application opening the generated file (like MS Word). | ||||
//FormattingResults foResults = fop.getResults(); | //FormattingResults foResults = fop.getResults(); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); | ||||
System.exit(-1); | System.exit(-1); | ||||
try { | try { | ||||
System.out.println("FOP ExampleFO2RTF\n"); | System.out.println("FOP ExampleFO2RTF\n"); | ||||
System.out.println("Preparing..."); | System.out.println("Preparing..."); | ||||
//Setup directories | //Setup directories | ||||
File baseDir = new File("."); | File baseDir = new File("."); | ||||
File outDir = new File(baseDir, "out"); | File outDir = new File(baseDir, "out"); | ||||
outDir.mkdirs(); | outDir.mkdirs(); | ||||
//Setup input and output files | |||||
//Setup input and output files | |||||
File fofile = new File(baseDir, "xml/fo/helloworld.fo"); | File fofile = new File(baseDir, "xml/fo/helloworld.fo"); | ||||
File rtffile = new File(outDir, "ResultFO2RTF.rtf"); | File rtffile = new File(outDir, "ResultFO2RTF.rtf"); | ||||
System.out.println("Output: PDF (" + rtffile + ")"); | System.out.println("Output: PDF (" + rtffile + ")"); | ||||
System.out.println(); | System.out.println(); | ||||
System.out.println("Transforming..."); | System.out.println("Transforming..."); | ||||
ExampleFO2RTF app = new ExampleFO2RTF(); | ExampleFO2RTF app = new ExampleFO2RTF(); | ||||
app.convertFO2RTF(fofile, rtffile); | app.convertFO2RTF(fofile, rtffile); | ||||
System.out.println("Success!"); | System.out.println("Success!"); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding; | package embedding; | ||||
// Java | // Java | ||||
import embedding.model.ProjectTeam; | import embedding.model.ProjectTeam; | ||||
/** | /** | ||||
* This class demonstrates the conversion of an arbitrary object file to a | |||||
* This class demonstrates the conversion of an arbitrary object file to a | |||||
* PDF using JAXP (XSLT) and FOP (XSL:FO). | * PDF using JAXP (XSLT) and FOP (XSL:FO). | ||||
*/ | */ | ||||
public class ExampleObj2PDF { | public class ExampleObj2PDF { | ||||
* @throws FOPException In case of a FOP problem | * @throws FOPException In case of a FOP problem | ||||
* @throws TransformerException In case of a XSL transformation problem | * @throws TransformerException In case of a XSL transformation problem | ||||
*/ | */ | ||||
public void convertProjectTeam2PDF(ProjectTeam team, File xslt, File pdf) | |||||
public void convertProjectTeam2PDF(ProjectTeam team, File xslt, File pdf) | |||||
throws IOException, FOPException, TransformerException { | throws IOException, FOPException, TransformerException { | ||||
FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); | FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); | ||||
// configure foUserAgent as desired | // configure foUserAgent as desired | ||||
// Setup XSLT | // Setup XSLT | ||||
TransformerFactory factory = TransformerFactory.newInstance(); | TransformerFactory factory = TransformerFactory.newInstance(); | ||||
Transformer transformer = factory.newTransformer(new StreamSource(xslt)); | Transformer transformer = factory.newTransformer(new StreamSource(xslt)); | ||||
// Setup input for XSLT transformation | // Setup input for XSLT transformation | ||||
Source src = team.getSourceForProjectTeam(); | Source src = team.getSourceForProjectTeam(); | ||||
// Resulting SAX events (the generated FO) must be piped through to FOP | // Resulting SAX events (the generated FO) must be piped through to FOP | ||||
Result res = new SAXResult(fop.getDefaultHandler()); | Result res = new SAXResult(fop.getDefaultHandler()); | ||||
try { | try { | ||||
System.out.println("FOP ExampleObj2PDF\n"); | System.out.println("FOP ExampleObj2PDF\n"); | ||||
System.out.println("Preparing..."); | System.out.println("Preparing..."); | ||||
// Setup directories | // Setup directories | ||||
File baseDir = new File("."); | File baseDir = new File("."); | ||||
File outDir = new File(baseDir, "out"); | File outDir = new File(baseDir, "out"); | ||||
ExampleObj2PDF app = new ExampleObj2PDF(); | ExampleObj2PDF app = new ExampleObj2PDF(); | ||||
app.convertProjectTeam2PDF(ExampleObj2XML.createSampleProjectTeam(), xsltfile, pdffile); | app.convertProjectTeam2PDF(ExampleObj2XML.createSampleProjectTeam(), xsltfile, pdffile); | ||||
System.out.println("Success!"); | System.out.println("Success!"); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding; | package embedding; | ||||
//Hava | //Hava | ||||
/** | /** | ||||
* This class demonstrates the conversion of an arbitrary object file to an | |||||
* This class demonstrates the conversion of an arbitrary object file to an | |||||
* XML file. | * XML file. | ||||
*/ | */ | ||||
public class ExampleObj2XML { | public class ExampleObj2XML { | ||||
* @throws IOException In case of an I/O problem | * @throws IOException In case of an I/O problem | ||||
* @throws TransformerException In case of a XSL transformation problem | * @throws TransformerException In case of a XSL transformation problem | ||||
*/ | */ | ||||
public void convertProjectTeam2XML(ProjectTeam team, File xml) | |||||
public void convertProjectTeam2XML(ProjectTeam team, File xml) | |||||
throws IOException, TransformerException { | throws IOException, TransformerException { | ||||
//Setup XSLT | //Setup XSLT | ||||
TransformerFactory factory = TransformerFactory.newInstance(); | TransformerFactory factory = TransformerFactory.newInstance(); | ||||
Transformer transformer = factory.newTransformer(); | Transformer transformer = factory.newTransformer(); | ||||
/* Note: | /* Note: | ||||
We use the identity transformer, no XSL transformation is done. | We use the identity transformer, no XSL transformation is done. | ||||
The transformer is basically just used to serialize the | |||||
The transformer is basically just used to serialize the | |||||
generated document to XML. */ | generated document to XML. */ | ||||
//Setup input | //Setup input | ||||
Source src = team.getSourceForProjectTeam(); | Source src = team.getSourceForProjectTeam(); | ||||
//Setup output | //Setup output | ||||
Result res = new StreamResult(xml); | Result res = new StreamResult(xml); | ||||
try { | try { | ||||
System.out.println("FOP ExampleObj2XML\n"); | System.out.println("FOP ExampleObj2XML\n"); | ||||
System.out.println("Preparing..."); | System.out.println("Preparing..."); | ||||
//Setup directories | //Setup directories | ||||
File baseDir = new File("."); | File baseDir = new File("."); | ||||
File outDir = new File(baseDir, "out"); | File outDir = new File(baseDir, "out"); | ||||
ExampleObj2XML app = new ExampleObj2XML(); | ExampleObj2XML app = new ExampleObj2XML(); | ||||
app.convertProjectTeam2XML(createSampleProjectTeam(), xmlfile); | app.convertProjectTeam2XML(createSampleProjectTeam(), xmlfile); | ||||
System.out.println("Success!"); | System.out.println("Success!"); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding; | package embedding; | ||||
//Java | //Java | ||||
* @throws TranscoderException In case of a transcoding problem | * @throws TranscoderException In case of a transcoding problem | ||||
*/ | */ | ||||
public void convertSVG2PDF(File svg, File pdf) throws IOException, TranscoderException { | public void convertSVG2PDF(File svg, File pdf) throws IOException, TranscoderException { | ||||
//Create transcoder | //Create transcoder | ||||
Transcoder transcoder = new PDFTranscoder(); | Transcoder transcoder = new PDFTranscoder(); | ||||
//Transcoder transcoder = new org.apache.fop.render.ps.PSTranscoder(); | //Transcoder transcoder = new org.apache.fop.render.ps.PSTranscoder(); | ||||
//Setup input | //Setup input | ||||
InputStream in = new java.io.FileInputStream(svg); | InputStream in = new java.io.FileInputStream(svg); | ||||
try { | try { | ||||
TranscoderInput input = new TranscoderInput(in); | TranscoderInput input = new TranscoderInput(in); | ||||
//Setup output | //Setup output | ||||
OutputStream out = new java.io.FileOutputStream(pdf); | OutputStream out = new java.io.FileOutputStream(pdf); | ||||
out = new java.io.BufferedOutputStream(out); | out = new java.io.BufferedOutputStream(out); | ||||
try { | try { | ||||
TranscoderOutput output = new TranscoderOutput(out); | TranscoderOutput output = new TranscoderOutput(out); | ||||
//Do the transformation | //Do the transformation | ||||
transcoder.transcode(input, output); | transcoder.transcode(input, output); | ||||
} finally { | } finally { | ||||
try { | try { | ||||
System.out.println("FOP ExampleSVG2PDF\n"); | System.out.println("FOP ExampleSVG2PDF\n"); | ||||
System.out.println("Preparing..."); | System.out.println("Preparing..."); | ||||
//Setup directories | //Setup directories | ||||
File baseDir = new File("."); | File baseDir = new File("."); | ||||
File outDir = new File(baseDir, "out"); | File outDir = new File(baseDir, "out"); | ||||
outDir.mkdirs(); | outDir.mkdirs(); | ||||
//Setup input and output files | |||||
//Setup input and output files | |||||
File svgfile = new File(baseDir, "xml/svg/helloworld.svg"); | File svgfile = new File(baseDir, "xml/svg/helloworld.svg"); | ||||
File pdffile = new File(outDir, "ResultSVG2PDF.pdf"); | File pdffile = new File(outDir, "ResultSVG2PDF.pdf"); | ||||
System.out.println("Output: PDF (" + pdffile + ")"); | System.out.println("Output: PDF (" + pdffile + ")"); | ||||
System.out.println(); | System.out.println(); | ||||
System.out.println("Transforming..."); | System.out.println("Transforming..."); | ||||
ExampleSVG2PDF app = new ExampleSVG2PDF(); | ExampleSVG2PDF app = new ExampleSVG2PDF(); | ||||
app.convertSVG2PDF(svgfile, pdffile); | app.convertSVG2PDF(svgfile, pdffile); | ||||
System.out.println("Success!"); | System.out.println("Success!"); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding; | package embedding; | ||||
//Java | //Java | ||||
* @throws IOException In case of an I/O problem | * @throws IOException In case of an I/O problem | ||||
* @throws TransformerException In case of a XSL transformation problem | * @throws TransformerException In case of a XSL transformation problem | ||||
*/ | */ | ||||
public void convertXML2FO(File xml, File xslt, File fo) | |||||
public void convertXML2FO(File xml, File xslt, File fo) | |||||
throws IOException, TransformerException { | throws IOException, TransformerException { | ||||
//Setup output | //Setup output | ||||
OutputStream out = new java.io.FileOutputStream(fo); | OutputStream out = new java.io.FileOutputStream(fo); | ||||
try { | try { | ||||
//Setup XSLT | //Setup XSLT | ||||
TransformerFactory factory = TransformerFactory.newInstance(); | TransformerFactory factory = TransformerFactory.newInstance(); | ||||
Transformer transformer = factory.newTransformer(new StreamSource(xslt)); | Transformer transformer = factory.newTransformer(new StreamSource(xslt)); | ||||
//Setup input for XSLT transformation | //Setup input for XSLT transformation | ||||
Source src = new StreamSource(xml); | Source src = new StreamSource(xml); | ||||
//Resulting SAX events (the generated FO) must be piped through to FOP | //Resulting SAX events (the generated FO) must be piped through to FOP | ||||
Result res = new StreamResult(out); | Result res = new StreamResult(out); | ||||
File outDir = new File(baseDir, "out"); | File outDir = new File(baseDir, "out"); | ||||
outDir.mkdirs(); | outDir.mkdirs(); | ||||
//Setup input and output files | |||||
//Setup input and output files | |||||
File xmlfile = new File(baseDir, "xml/xml/projectteam.xml"); | File xmlfile = new File(baseDir, "xml/xml/projectteam.xml"); | ||||
File xsltfile = new File(baseDir, "xml/xslt/projectteam2fo.xsl"); | File xsltfile = new File(baseDir, "xml/xslt/projectteam2fo.xsl"); | ||||
File fofile = new File(outDir, "ResultXML2FO.fo"); | File fofile = new File(outDir, "ResultXML2FO.fo"); | ||||
System.out.println("Output: XSL-FO (" + fofile + ")"); | System.out.println("Output: XSL-FO (" + fofile + ")"); | ||||
System.out.println(); | System.out.println(); | ||||
System.out.println("Transforming..."); | System.out.println("Transforming..."); | ||||
ExampleXML2FO app = new ExampleXML2FO(); | ExampleXML2FO app = new ExampleXML2FO(); | ||||
app.convertXML2FO(xmlfile, xsltfile, fofile); | app.convertXML2FO(xmlfile, xsltfile, fofile); | ||||
System.out.println("Success!"); | System.out.println("Success!"); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding; | package embedding; | ||||
//Java | //Java | ||||
import org.apache.fop.apps.MimeConstants; | import org.apache.fop.apps.MimeConstants; | ||||
/** | /** | ||||
* This class demonstrates the conversion of an XML file to PDF using | |||||
* This class demonstrates the conversion of an XML file to PDF using | |||||
* JAXP (XSLT) and FOP (XSL-FO). | * JAXP (XSLT) and FOP (XSL-FO). | ||||
*/ | */ | ||||
public class ExampleXML2PDF { | public class ExampleXML2PDF { | ||||
File outDir = new File(baseDir, "out"); | File outDir = new File(baseDir, "out"); | ||||
outDir.mkdirs(); | outDir.mkdirs(); | ||||
// Setup input and output files | |||||
// Setup input and output files | |||||
File xmlfile = new File(baseDir, "xml/xml/projectteam.xml"); | File xmlfile = new File(baseDir, "xml/xml/projectteam.xml"); | ||||
File xsltfile = new File(baseDir, "xml/xslt/projectteam2fo.xsl"); | File xsltfile = new File(baseDir, "xml/xslt/projectteam2fo.xsl"); | ||||
File pdffile = new File(outDir, "ResultXML2PDF.pdf"); | File pdffile = new File(outDir, "ResultXML2PDF.pdf"); | ||||
System.out.println("Output: PDF (" + pdffile + ")"); | System.out.println("Output: PDF (" + pdffile + ")"); | ||||
System.out.println(); | System.out.println(); | ||||
System.out.println("Transforming..."); | System.out.println("Transforming..."); | ||||
// configure fopFactory as desired | // configure fopFactory as desired | ||||
FopFactory fopFactory = FopFactory.newInstance(); | FopFactory fopFactory = FopFactory.newInstance(); | ||||
// Setup output | // Setup output | ||||
OutputStream out = new java.io.FileOutputStream(pdffile); | OutputStream out = new java.io.FileOutputStream(pdffile); | ||||
out = new java.io.BufferedOutputStream(out); | out = new java.io.BufferedOutputStream(out); | ||||
try { | try { | ||||
// Construct fop with desired output format | // Construct fop with desired output format | ||||
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out); | Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out); | ||||
// Setup XSLT | // Setup XSLT | ||||
TransformerFactory factory = TransformerFactory.newInstance(); | TransformerFactory factory = TransformerFactory.newInstance(); | ||||
Transformer transformer = factory.newTransformer(new StreamSource(xsltfile)); | Transformer transformer = factory.newTransformer(new StreamSource(xsltfile)); | ||||
// Set the value of a <param> in the stylesheet | // Set the value of a <param> in the stylesheet | ||||
transformer.setParameter("versionParam", "2.0"); | transformer.setParameter("versionParam", "2.0"); | ||||
// Setup input for XSLT transformation | // Setup input for XSLT transformation | ||||
Source src = new StreamSource(xmlfile); | Source src = new StreamSource(xmlfile); | ||||
// Resulting SAX events (the generated FO) must be piped through to FOP | // Resulting SAX events (the generated FO) must be piped through to FOP | ||||
Result res = new SAXResult(fop.getDefaultHandler()); | Result res = new SAXResult(fop.getDefaultHandler()); | ||||
// Start XSLT transformation and FOP processing | // Start XSLT transformation and FOP processing | ||||
transformer.transform(src, res); | transformer.transform(src, res); | ||||
} finally { | } finally { | ||||
out.close(); | out.close(); | ||||
} | } | ||||
System.out.println("Success!"); | System.out.println("Success!"); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding; | package embedding; | ||||
// Java | // Java | ||||
// JAXP TransformerFactory can be reused, too | // JAXP TransformerFactory can be reused, too | ||||
private TransformerFactory factory = TransformerFactory.newInstance(); | private TransformerFactory factory = TransformerFactory.newInstance(); | ||||
/** | /** | ||||
* Converts an FO file to a PDF file using FOP | * Converts an FO file to a PDF file using FOP | ||||
* @param fo the FO file | * @param fo the FO file | ||||
* @param pdf the target PDF file | * @param pdf the target PDF file | ||||
* @throws TransformerException in case of a transformation problem | |||||
* @throws TransformerException in case of a transformation problem | |||||
* @throws IOException in case of an I/O problem | * @throws IOException in case of an I/O problem | ||||
* @throws FOPException in case of a FOP problem | * @throws FOPException in case of a FOP problem | ||||
* @return the formatting results of the run | * @return the formatting results of the run | ||||
*/ | */ | ||||
public FormattingResults convertFO2PDF(File fo, File pdf) | |||||
public FormattingResults convertFO2PDF(File fo, File pdf) | |||||
throws TransformerException, IOException, FOPException { | throws TransformerException, IOException, FOPException { | ||||
OutputStream out = null; | OutputStream out = null; | ||||
Fop fop; | Fop fop; | ||||
try { | try { | ||||
FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); | FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); | ||||
// configure foUserAgent as desired | // configure foUserAgent as desired | ||||
// Setup output stream. Note: Using BufferedOutputStream | // Setup output stream. Note: Using BufferedOutputStream | ||||
// for performance reasons (helpful with FileOutputStreams). | // for performance reasons (helpful with FileOutputStreams). | ||||
out = new FileOutputStream(pdf); | out = new FileOutputStream(pdf); | ||||
// Setup JAXP using identity transformer | // Setup JAXP using identity transformer | ||||
Transformer transformer = factory.newTransformer(); // identity transformer | Transformer transformer = factory.newTransformer(); // identity transformer | ||||
// Setup input stream | // Setup input stream | ||||
Source src = new StreamSource(fo); | Source src = new StreamSource(fo); | ||||
// Resulting SAX events (the generated FO) must be piped through to FOP | // Resulting SAX events (the generated FO) must be piped through to FOP | ||||
Result res = new SAXResult(fop.getDefaultHandler()); | Result res = new SAXResult(fop.getDefaultHandler()); | ||||
// Start XSLT transformation and FOP processing | // Start XSLT transformation and FOP processing | ||||
transformer.transform(src, res); | transformer.transform(src, res); | ||||
} finally { | } finally { | ||||
return fop.getResults(); | return fop.getResults(); | ||||
} | } | ||||
/** | |||||
/** | |||||
* Listens on standard in for names of fo files to be transformed to pdf. | * Listens on standard in for names of fo files to be transformed to pdf. | ||||
* 'quit' or the null string (for piped input) cause the listener to stop listening. | * 'quit' or the null string (for piped input) cause the listener to stop listening. | ||||
*/ | */ | ||||
File outDir = new File(baseDir, "out"); | File outDir = new File(baseDir, "out"); | ||||
outDir.mkdirs(); | outDir.mkdirs(); | ||||
BufferedReader in = new BufferedReader(new java.io.InputStreamReader(System.in)); | BufferedReader in = new BufferedReader(new java.io.InputStreamReader(System.in)); | ||||
while (true) { | while (true) { | ||||
try { | try { | ||||
// Listen for the input file name | |||||
// Listen for the input file name | |||||
System.out.print("Input XSL-FO file ('quit' to stop): "); | System.out.print("Input XSL-FO file ('quit' to stop): "); | ||||
String foname = in.readLine(); | String foname = in.readLine(); | ||||
if (foname == null) { | if (foname == null) { | ||||
java.util.List pageSequences = foResults.getPageSequences(); | java.util.List pageSequences = foResults.getPageSequences(); | ||||
for (java.util.Iterator it = pageSequences.iterator(); it.hasNext();) { | for (java.util.Iterator it = pageSequences.iterator(); it.hasNext();) { | ||||
PageSequenceResults pageSequenceResults = (PageSequenceResults)it.next(); | PageSequenceResults pageSequenceResults = (PageSequenceResults)it.next(); | ||||
System.out.println("PageSequence " | |||||
+ (String.valueOf(pageSequenceResults.getID()).length() > 0 | |||||
? pageSequenceResults.getID() : "<no id>") | |||||
System.out.println("PageSequence " | |||||
+ (String.valueOf(pageSequenceResults.getID()).length() > 0 | |||||
? pageSequenceResults.getID() : "<no id>") | |||||
+ " generated " + pageSequenceResults.getPageCount() + " pages."); | + " generated " + pageSequenceResults.getPageCount() + " pages."); | ||||
} | } | ||||
System.out.println("Generated " + foResults.getPageCount() + " pages in total."); | System.out.println("Generated " + foResults.getPageCount() + " pages in total."); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Main method. Set up the listener. | * Main method. Set up the listener. | ||||
* @param args command-line arguments | * @param args command-line arguments |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding.events; | package embedding.events; | ||||
import java.io.BufferedOutputStream; | import java.io.BufferedOutputStream; | ||||
*/ | */ | ||||
public void convertFO2PDF(URL fo, File pdf) | public void convertFO2PDF(URL fo, File pdf) | ||||
throws IOException, FOPException, TransformerException { | throws IOException, FOPException, TransformerException { | ||||
OutputStream out = null; | OutputStream out = null; | ||||
try { | try { | ||||
//Create the user agent for this processing run | //Create the user agent for this processing run | ||||
FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); | FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); | ||||
//Adding a simple logging listener that writes to stdout and stderr | //Adding a simple logging listener that writes to stdout and stderr | ||||
foUserAgent.getEventBroadcaster().addEventListener(new SysOutEventListener()); | foUserAgent.getEventBroadcaster().addEventListener(new SysOutEventListener()); | ||||
// Add your own event listener | // Add your own event listener | ||||
foUserAgent.getEventBroadcaster().addEventListener(new MyEventListener()); | foUserAgent.getEventBroadcaster().addEventListener(new MyEventListener()); | ||||
// configure foUserAgent further as desired | // configure foUserAgent further as desired | ||||
// Setup output stream. Note: Using BufferedOutputStream | // Setup output stream. Note: Using BufferedOutputStream | ||||
// for performance reasons (helpful with FileOutputStreams). | // for performance reasons (helpful with FileOutputStreams). | ||||
out = new FileOutputStream(pdf); | out = new FileOutputStream(pdf); | ||||
// Setup JAXP using identity transformer | // Setup JAXP using identity transformer | ||||
TransformerFactory factory = TransformerFactory.newInstance(); | TransformerFactory factory = TransformerFactory.newInstance(); | ||||
Transformer transformer = factory.newTransformer(); // identity transformer | Transformer transformer = factory.newTransformer(); // identity transformer | ||||
// Setup input stream | // Setup input stream | ||||
Source src = new StreamSource(fo.toExternalForm()); | Source src = new StreamSource(fo.toExternalForm()); | ||||
// Resulting SAX events (the generated FO) must be piped through to FOP | // Resulting SAX events (the generated FO) must be piped through to FOP | ||||
Result res = new SAXResult(fop.getDefaultHandler()); | Result res = new SAXResult(fop.getDefaultHandler()); | ||||
// Start XSLT transformation and FOP processing | // Start XSLT transformation and FOP processing | ||||
transformer.transform(src, res); | transformer.transform(src, res); | ||||
public void processEvent(Event event) { | public void processEvent(Event event) { | ||||
if ("org.apache.fop.events.ResourceEventProducer.imageNotFound" | if ("org.apache.fop.events.ResourceEventProducer.imageNotFound" | ||||
.equals(event.getEventID())) { | .equals(event.getEventID())) { | ||||
//Get the FileNotFoundException that's part of the event's parameters | //Get the FileNotFoundException that's part of the event's parameters | ||||
FileNotFoundException fnfe = (FileNotFoundException)event.getParam("fnfe"); | FileNotFoundException fnfe = (FileNotFoundException)event.getParam("fnfe"); | ||||
+ "!!! ===---"); | + "!!! ===---"); | ||||
//Stop processing when an image could not be found. Otherwise, FOP would just | //Stop processing when an image could not be found. Otherwise, FOP would just | ||||
//continue without the image! | //continue without the image! | ||||
System.out.println("Throwing a RuntimeException..."); | System.out.println("Throwing a RuntimeException..."); | ||||
throw new RuntimeException(EventFormatter.format(event), fnfe); | throw new RuntimeException(EventFormatter.format(event), fnfe); | ||||
} else { | } else { | ||||
//ignore all other events | //ignore all other events | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** A simple event listener that writes the events to stdout and sterr. */ | /** A simple event listener that writes the events to stdout and sterr. */ | ||||
private static class SysOutEventListener implements EventListener { | private static class SysOutEventListener implements EventListener { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* This method extracts the original exception from some exception. The exception | * This method extracts the original exception from some exception. The exception | ||||
try { | try { | ||||
System.out.println("FOP ExampleEvents\n"); | System.out.println("FOP ExampleEvents\n"); | ||||
System.out.println("Preparing..."); | System.out.println("Preparing..."); | ||||
//Setup directories | //Setup directories | ||||
File baseDir = new File("."); | File baseDir = new File("."); | ||||
File outDir = new File(baseDir, "out"); | File outDir = new File(baseDir, "out"); | ||||
System.out.println("Output: PDF (" + pdffile + ")"); | System.out.println("Output: PDF (" + pdffile + ")"); | ||||
System.out.println(); | System.out.println(); | ||||
System.out.println("Transforming..."); | System.out.println("Transforming..."); | ||||
ExampleEvents app = new ExampleEvents(); | ExampleEvents app = new ExampleEvents(); | ||||
try { | try { | ||||
app.convertFO2PDF(fo, pdffile); | app.convertFO2PDF(fo, pdffile); | ||||
} catch (TransformerException te) { | } catch (TransformerException te) { | ||||
System.out.println("Aborted!"); | System.out.println("Aborted!"); | ||||
System.exit(-1); | System.exit(-1); | ||||
} | } | ||||
System.out.println("Success!"); | System.out.println("Success!"); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
//Some other error (shouldn't happen in this example) | //Some other error (shouldn't happen in this example) |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding.intermediate; | package embedding.intermediate; | ||||
import java.io.File; | import java.io.File; | ||||
* @throws FOPException In case of a FOP problem | * @throws FOPException In case of a FOP problem | ||||
* @throws TransformerException In case of a XSL transformation problem | * @throws TransformerException In case of a XSL transformation problem | ||||
*/ | */ | ||||
public void convertToIntermediate(Source src, Source xslt, File intermediate) | |||||
public void convertToIntermediate(Source src, Source xslt, File intermediate) | |||||
throws IOException, FOPException, TransformerException { | throws IOException, FOPException, TransformerException { | ||||
//Create a user agent | //Create a user agent | ||||
FOUserAgent userAgent = fopFactory.newFOUserAgent(); | FOUserAgent userAgent = fopFactory.newFOUserAgent(); | ||||
//Create an instance of the target renderer so the XMLRenderer can use its font setup | //Create an instance of the target renderer so the XMLRenderer can use its font setup | ||||
Renderer targetRenderer = userAgent.getRendererFactory().createRenderer( | Renderer targetRenderer = userAgent.getRendererFactory().createRenderer( | ||||
userAgent, MimeConstants.MIME_PDF); | |||||
userAgent, MimeConstants.MIME_PDF); | |||||
//Create the XMLRenderer to create the intermediate format (area tree XML) | //Create the XMLRenderer to create the intermediate format (area tree XML) | ||||
XMLRenderer xmlRenderer = new XMLRenderer(); | XMLRenderer xmlRenderer = new XMLRenderer(); | ||||
xmlRenderer.setUserAgent(userAgent); | xmlRenderer.setUserAgent(userAgent); | ||||
//Tell the XMLRenderer to mimic the target renderer | //Tell the XMLRenderer to mimic the target renderer | ||||
xmlRenderer.mimicRenderer(targetRenderer); | xmlRenderer.mimicRenderer(targetRenderer); | ||||
//Make sure the prepared XMLRenderer is used | //Make sure the prepared XMLRenderer is used | ||||
userAgent.setRendererOverride(xmlRenderer); | userAgent.setRendererOverride(xmlRenderer); | ||||
// Setup output | // Setup output | ||||
OutputStream out = new java.io.FileOutputStream(intermediate); | OutputStream out = new java.io.FileOutputStream(intermediate); | ||||
out = new java.io.BufferedOutputStream(out); | out = new java.io.BufferedOutputStream(out); | ||||
} else { | } else { | ||||
transformer = factory.newTransformer(); | transformer = factory.newTransformer(); | ||||
} | } | ||||
// Resulting SAX events (the generated FO) must be piped through to FOP | // Resulting SAX events (the generated FO) must be piped through to FOP | ||||
Result res = new SAXResult(fop.getDefaultHandler()); | Result res = new SAXResult(fop.getDefaultHandler()); | ||||
* @throws TransformerException In case of a XSL transformation problem | * @throws TransformerException In case of a XSL transformation problem | ||||
* @throws SAXException In case of an XML-related problem | * @throws SAXException In case of an XML-related problem | ||||
*/ | */ | ||||
public void concatToPDF(File[] files, File pdffile) | |||||
public void concatToPDF(File[] files, File pdffile) | |||||
throws IOException, TransformerException, SAXException { | throws IOException, TransformerException, SAXException { | ||||
// Setup output | // Setup output | ||||
OutputStream out = new java.io.FileOutputStream(pdffile); | OutputStream out = new java.io.FileOutputStream(pdffile); | ||||
FOUserAgent userAgent = fopFactory.newFOUserAgent(); | FOUserAgent userAgent = fopFactory.newFOUserAgent(); | ||||
//Construct the AreaTreeModel that will received the individual pages | //Construct the AreaTreeModel that will received the individual pages | ||||
AreaTreeModel treeModel = new RenderPagesModel(userAgent, | |||||
AreaTreeModel treeModel = new RenderPagesModel(userAgent, | |||||
MimeConstants.MIME_PDF, fontInfo, out); | MimeConstants.MIME_PDF, fontInfo, out); | ||||
//Iterate over all intermediate files | //Iterate over all intermediate files | ||||
AreaTreeParser parser = new AreaTreeParser(); | AreaTreeParser parser = new AreaTreeParser(); | ||||
for (int i = 0; i < files.length; i++) { | for (int i = 0; i < files.length; i++) { | ||||
Source src = new StreamSource(files[i]); | Source src = new StreamSource(files[i]); | ||||
parser.parse(src, treeModel, userAgent); | parser.parse(src, treeModel, userAgent); | ||||
} | } | ||||
//Signal the end of the processing. The renderer can finalize the target document. | //Signal the end of the processing. The renderer can finalize the target document. | ||||
treeModel.endDocument(); | treeModel.endDocument(); | ||||
} finally { | } finally { | ||||
out.close(); | out.close(); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Main method. | * Main method. | ||||
* @param args command-line arguments | * @param args command-line arguments | ||||
public static void main(String[] args) { | public static void main(String[] args) { | ||||
try { | try { | ||||
System.out.println("FOP ExampleConcat\n"); | System.out.println("FOP ExampleConcat\n"); | ||||
//Setup directories | //Setup directories | ||||
File baseDir = new File("."); | File baseDir = new File("."); | ||||
File outDir = new File(baseDir, "out"); | File outDir = new File(baseDir, "out"); | ||||
outDir.mkdirs(); | outDir.mkdirs(); | ||||
//Setup output file | //Setup output file | ||||
File xsltfile = new File(baseDir, "xml/xslt/projectteam2fo.xsl"); | File xsltfile = new File(baseDir, "xml/xslt/projectteam2fo.xsl"); | ||||
File[] files = new File[] { | File[] files = new File[] { | ||||
new File(outDir, "team2.at.xml")}; | new File(outDir, "team2.at.xml")}; | ||||
File pdffile = new File(outDir, "ResultConcat.pdf"); | File pdffile = new File(outDir, "ResultConcat.pdf"); | ||||
for (int i = 0; i < files.length; i++) { | for (int i = 0; i < files.length; i++) { | ||||
System.out.println("Intermediate file " + (i + 1) + ": " | |||||
System.out.println("Intermediate file " + (i + 1) + ": " | |||||
+ files[i].getCanonicalPath()); | + files[i].getCanonicalPath()); | ||||
} | } | ||||
System.out.println("PDF Output File: " + pdffile.getCanonicalPath()); | System.out.println("PDF Output File: " + pdffile.getCanonicalPath()); | ||||
System.out.println(); | System.out.println(); | ||||
ProjectTeam team1 = ExampleObj2XML.createSampleProjectTeam(); | ProjectTeam team1 = ExampleObj2XML.createSampleProjectTeam(); | ||||
ProjectTeam team2 = createAnotherProjectTeam(); | ProjectTeam team2 = createAnotherProjectTeam(); | ||||
ExampleConcat app = new ExampleConcat(); | ExampleConcat app = new ExampleConcat(); | ||||
//Create intermediate files | //Create intermediate files | ||||
app.convertToIntermediate( | app.convertToIntermediate( | ||||
team1.getSourceForProjectTeam(), | |||||
team1.getSourceForProjectTeam(), | |||||
new StreamSource(xsltfile), files[0]); | new StreamSource(xsltfile), files[0]); | ||||
app.convertToIntermediate( | app.convertToIntermediate( | ||||
team2.getSourceForProjectTeam(), | |||||
team2.getSourceForProjectTeam(), | |||||
new StreamSource(xsltfile), files[1]); | new StreamSource(xsltfile), files[1]); | ||||
//Concatenate the individual intermediate files to one document | //Concatenate the individual intermediate files to one document | ||||
app.concatToPDF(files, pdffile); | app.concatToPDF(files, pdffile); | ||||
System.out.println("Success!"); | System.out.println("Success!"); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); | ||||
System.exit(-1); | System.exit(-1); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding.intermediate; | package embedding.intermediate; | ||||
import java.io.File; | import java.io.File; | ||||
// configure fopFactory as desired | // configure fopFactory as desired | ||||
private FopFactory fopFactory = FopFactory.newInstance(); | private FopFactory fopFactory = FopFactory.newInstance(); | ||||
/** | /** | ||||
* Stamps an intermediate file and renders it to a PDF file. | * Stamps an intermediate file and renders it to a PDF file. | ||||
* @param atfile the intermediate file (area tree XML) | * @param atfile the intermediate file (area tree XML) | ||||
* @throws TransformerException In case of a XSL transformation problem | * @throws TransformerException In case of a XSL transformation problem | ||||
* @throws SAXException In case of an XML-related problem | * @throws SAXException In case of an XML-related problem | ||||
*/ | */ | ||||
public void stampToPDF(File atfile, File stampSheet, File pdffile) | |||||
public void stampToPDF(File atfile, File stampSheet, File pdffile) | |||||
throws IOException, TransformerException, SAXException { | throws IOException, TransformerException, SAXException { | ||||
// Setup output | // Setup output | ||||
OutputStream out = new java.io.FileOutputStream(pdffile); | OutputStream out = new java.io.FileOutputStream(pdffile); | ||||
FOUserAgent userAgent = fopFactory.newFOUserAgent(); | FOUserAgent userAgent = fopFactory.newFOUserAgent(); | ||||
//Construct the AreaTreeModel that will received the individual pages | //Construct the AreaTreeModel that will received the individual pages | ||||
AreaTreeModel treeModel = new RenderPagesModel(userAgent, | |||||
AreaTreeModel treeModel = new RenderPagesModel(userAgent, | |||||
MimeConstants.MIME_PDF, fontInfo, out); | MimeConstants.MIME_PDF, fontInfo, out); | ||||
//Iterate over all intermediate files | //Iterate over all intermediate files | ||||
AreaTreeParser parser = new AreaTreeParser(); | AreaTreeParser parser = new AreaTreeParser(); | ||||
Source src = new StreamSource(atfile); | Source src = new StreamSource(atfile); | ||||
Source xslt = new StreamSource(stampSheet); | Source xslt = new StreamSource(stampSheet); | ||||
//Setup Transformer for XSLT processing | //Setup Transformer for XSLT processing | ||||
TransformerFactory tFactory = TransformerFactory.newInstance(); | TransformerFactory tFactory = TransformerFactory.newInstance(); | ||||
Transformer transformer = tFactory.newTransformer(xslt); | Transformer transformer = tFactory.newTransformer(xslt); | ||||
//Send XSLT result to AreaTreeParser | //Send XSLT result to AreaTreeParser | ||||
SAXResult res = new SAXResult(parser.getContentHandler(treeModel, userAgent)); | SAXResult res = new SAXResult(parser.getContentHandler(treeModel, userAgent)); | ||||
//Start XSLT transformation and area tree parsing | //Start XSLT transformation and area tree parsing | ||||
transformer.transform(src, res); | transformer.transform(src, res); | ||||
//Signal the end of the processing. The renderer can finalize the target document. | //Signal the end of the processing. The renderer can finalize the target document. | ||||
treeModel.endDocument(); | treeModel.endDocument(); | ||||
} finally { | } finally { | ||||
out.close(); | out.close(); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Main method. | * Main method. | ||||
* @param args command-line arguments | * @param args command-line arguments | ||||
public static void main(String[] args) { | public static void main(String[] args) { | ||||
try { | try { | ||||
System.out.println("FOP ExampleConcat\n"); | System.out.println("FOP ExampleConcat\n"); | ||||
//Setup directories | //Setup directories | ||||
File baseDir = new File("."); | File baseDir = new File("."); | ||||
File outDir = new File(baseDir, "out"); | File outDir = new File(baseDir, "out"); | ||||
outDir.mkdirs(); | outDir.mkdirs(); | ||||
//Setup output file | //Setup output file | ||||
File xsltfile = new File(baseDir, "xml/xslt/projectteam2fo.xsl"); | File xsltfile = new File(baseDir, "xml/xslt/projectteam2fo.xsl"); | ||||
File atfile = new File(outDir, "team.at.xml"); | File atfile = new File(outDir, "team.at.xml"); | ||||
System.out.println(); | System.out.println(); | ||||
ProjectTeam team1 = ExampleObj2XML.createSampleProjectTeam(); | ProjectTeam team1 = ExampleObj2XML.createSampleProjectTeam(); | ||||
//Create intermediate file | //Create intermediate file | ||||
ExampleConcat concatapp = new ExampleConcat(); | ExampleConcat concatapp = new ExampleConcat(); | ||||
concatapp.convertToIntermediate( | concatapp.convertToIntermediate( | ||||
team1.getSourceForProjectTeam(), | |||||
team1.getSourceForProjectTeam(), | |||||
new StreamSource(xsltfile), atfile); | new StreamSource(xsltfile), atfile); | ||||
//Stamp document and produce a PDF from the intermediate format | //Stamp document and produce a PDF from the intermediate format | ||||
ExampleStamp app = new ExampleStamp(); | ExampleStamp app = new ExampleStamp(); | ||||
app.stampToPDF(atfile, stampxsltfile, pdffile); | app.stampToPDF(atfile, stampxsltfile, pdffile); | ||||
System.out.println("Success!"); | System.out.println("Success!"); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); | ||||
System.exit(-1); | System.exit(-1); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding.model; | package embedding.model; | ||||
/** | /** | ||||
*/ | */ | ||||
public ProjectMember() { | public ProjectMember() { | ||||
} | } | ||||
/** | /** | ||||
* Convenience constructor. | * Convenience constructor. | ||||
* @param name name of the project member | * @param name name of the project member |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding.model; | package embedding.model; | ||||
import java.util.List; | import java.util.List; |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding.model; | package embedding.model; | ||||
import org.xml.sax.InputSource; | import org.xml.sax.InputSource; |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding.model; | package embedding.model; | ||||
//Java | //Java | ||||
if (handler == null) { | if (handler == null) { | ||||
throw new IllegalStateException("ContentHandler not set"); | throw new IllegalStateException("ContentHandler not set"); | ||||
} | } | ||||
//Start the document | //Start the document | ||||
handler.startDocument(); | handler.startDocument(); | ||||
//Generate SAX events for the ProjectTeam | //Generate SAX events for the ProjectTeam | ||||
generateFor(projectTeam); | generateFor(projectTeam); | ||||
//End the document | //End the document | ||||
handler.endDocument(); | |||||
handler.endDocument(); | |||||
} | } | ||||
/** | /** | ||||
* Generates SAX events for a ProjectTeam object. | * Generates SAX events for a ProjectTeam object. | ||||
* @param projectTeam ProjectTeam object to use | * @param projectTeam ProjectTeam object to use | ||||
if (handler == null) { | if (handler == null) { | ||||
throw new IllegalStateException("ContentHandler not set"); | throw new IllegalStateException("ContentHandler not set"); | ||||
} | } | ||||
handler.startElement("projectteam"); | handler.startElement("projectteam"); | ||||
handler.element("projectname", projectTeam.getProjectName()); | handler.element("projectname", projectTeam.getProjectName()); | ||||
Iterator i = projectTeam.getMembers().iterator(); | Iterator i = projectTeam.getMembers().iterator(); | ||||
if (handler == null) { | if (handler == null) { | ||||
throw new IllegalStateException("ContentHandler not set"); | throw new IllegalStateException("ContentHandler not set"); | ||||
} | } | ||||
handler.startElement("member"); | handler.startElement("member"); | ||||
handler.element("name", projectMember.getName()); | handler.element("name", projectMember.getName()); | ||||
handler.element("function", projectMember.getFunction()); | handler.element("function", projectMember.getFunction()); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding.tools; | package embedding.tools; | ||||
//Java | //Java | ||||
import org.xml.sax.EntityResolver; | import org.xml.sax.EntityResolver; | ||||
/** | /** | ||||
* This class can be used as base class for XMLReaders that generate SAX | |||||
* This class can be used as base class for XMLReaders that generate SAX | |||||
* events from Java objects. | * events from Java objects. | ||||
*/ | */ | ||||
"http://xml.org/sax/features/namespaces"; | "http://xml.org/sax/features/namespaces"; | ||||
private static final String NS_PREFIXES = | private static final String NS_PREFIXES = | ||||
"http://xml.org/sax/features/namespace-prefixes"; | "http://xml.org/sax/features/namespace-prefixes"; | ||||
private Map features = new java.util.HashMap(); | private Map features = new java.util.HashMap(); | ||||
private ContentHandler orgHandler; | private ContentHandler orgHandler; | ||||
/** Proxy for easy SAX event generation */ | /** Proxy for easy SAX event generation */ | ||||
protected EasyGenerationContentHandlerProxy handler; | protected EasyGenerationContentHandlerProxy handler; | ||||
/** Error handler */ | /** Error handler */ | ||||
setFeature(NAMESPACES, false); | setFeature(NAMESPACES, false); | ||||
setFeature(NS_PREFIXES, false); | setFeature(NS_PREFIXES, false); | ||||
} | } | ||||
/* ============ XMLReader interface ============ */ | /* ============ XMLReader interface ============ */ | ||||
/** | /** |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package embedding.tools; | package embedding.tools; | ||||
//SAX | //SAX | ||||
/** | /** | ||||
* This class is an implementation of ContentHandler which acts as a proxy to | * This class is an implementation of ContentHandler which acts as a proxy to | ||||
* another ContentHandler and has the purpose to provide a few handy methods | |||||
* another ContentHandler and has the purpose to provide a few handy methods | |||||
* that make life easier when generating SAX events. | * that make life easier when generating SAX events. | ||||
* <br> | * <br> | ||||
* Note: This class is only useful for simple cases with no namespaces. | |||||
* Note: This class is only useful for simple cases with no namespaces. | |||||
*/ | */ | ||||
public class EasyGenerationContentHandlerProxy implements ContentHandler { | public class EasyGenerationContentHandlerProxy implements ContentHandler { | ||||
/** | /** | ||||
* Sends the notification of the beginning of an element. | * Sends the notification of the beginning of an element. | ||||
* @param name Name for the element. | * @param name Name for the element. | ||||
* @param atts The attributes attached to the element. If there are no | |||||
* attributes, it shall be an empty Attributes object. | |||||
* @param atts The attributes attached to the element. If there are no | |||||
* attributes, it shall be an empty Attributes object. | |||||
* @throws SAXException Any SAX exception, possibly wrapping another exception. | * @throws SAXException Any SAX exception, possibly wrapping another exception. | ||||
*/ | */ | ||||
public void startElement(String name, Attributes atts) throws SAXException { | public void startElement(String name, Attributes atts) throws SAXException { | ||||
* Sends notifications for a whole element with some String content. | * Sends notifications for a whole element with some String content. | ||||
* @param name Name for the element. | * @param name Name for the element. | ||||
* @param value Content of the element. | * @param value Content of the element. | ||||
* @param atts The attributes attached to the element. If there are no | |||||
* attributes, it shall be an empty Attributes object. | |||||
* @param atts The attributes attached to the element. If there are no | |||||
* attributes, it shall be an empty Attributes object. | |||||
* @throws SAXException Any SAX exception, possibly wrapping another exception. | * @throws SAXException Any SAX exception, possibly wrapping another exception. | ||||
*/ | */ | ||||
public void element(String name, String value, Attributes atts) throws SAXException { | public void element(String name, String value, Attributes atts) throws SAXException { | ||||
/** | /** | ||||
* @see org.xml.sax.ContentHandler#startElement(String, String, String, Attributes) | * @see org.xml.sax.ContentHandler#startElement(String, String, String, Attributes) | ||||
*/ | */ | ||||
public void startElement(String namespaceURI, String localName, | |||||
public void startElement(String namespaceURI, String localName, | |||||
String qName, Attributes atts) throws SAXException { | String qName, Attributes atts) throws SAXException { | ||||
target.startElement(namespaceURI, localName, qName, atts); | target.startElement(namespaceURI, localName, qName, atts); | ||||
} | } | ||||
/** | /** | ||||
* @see org.xml.sax.ContentHandler#endElement(String, String, String) | * @see org.xml.sax.ContentHandler#endElement(String, String, String) | ||||
*/ | */ | ||||
public void endElement(String namespaceURI, String localName, String qName) | |||||
public void endElement(String namespaceURI, String localName, String qName) | |||||
throws SAXException { | throws SAXException { | ||||
target.endElement(namespaceURI, localName, qName); | target.endElement(namespaceURI, localName, qName); | ||||
} | } |
import java.util.zip.ZipEntry; | import java.util.zip.ZipEntry; | ||||
/** | /** | ||||
* This class provides some useful methods to print the structure of a HyphenationTree object | |||||
* This class provides some useful methods to print the structure of a HyphenationTree object | |||||
*/ | */ | ||||
public class HyphenationTreeAnalysis extends TernaryTreeAnalysis { | public class HyphenationTreeAnalysis extends TernaryTreeAnalysis { | ||||
/** | /** | ||||
* The HyphenationTree object to analyse | |||||
* The HyphenationTree object to analyse | |||||
*/ | */ | ||||
protected HyphenationTree ht; | protected HyphenationTree ht; | ||||
/** | /** | ||||
* @param ht the HyphenationTree object | * @param ht the HyphenationTree object | ||||
*/ | */ | ||||
super(ht); | super(ht); | ||||
this.ht = ht; | this.ht = ht; | ||||
} | } | ||||
/** | /** | ||||
* Class representing a node of the HyphenationTree object | * Class representing a node of the HyphenationTree object | ||||
*/ | */ | ||||
value = readValue().toString(); | value = readValue().toString(); | ||||
} | } | ||||
} | } | ||||
private StringBuffer readValue() { | private StringBuffer readValue() { | ||||
StringBuffer s = new StringBuffer(); | StringBuffer s = new StringBuffer(); | ||||
int i = (int) ht.eq[index]; | int i = (int) ht.eq[index]; | ||||
return super.toNodeString(); | return super.toNodeString(); | ||||
} | } | ||||
} | } | ||||
/* (non-Javadoc) | /* (non-Javadoc) | ||||
* @see org.apache.fop.hyphenation.TernaryTreeAnalysis.Node#toCompactString() | * @see org.apache.fop.hyphenation.TernaryTreeAnalysis.Node#toCompactString() | ||||
*/ | */ | ||||
return super.toCompactString(); | return super.toCompactString(); | ||||
} | } | ||||
} | } | ||||
/* (non-Javadoc) | /* (non-Javadoc) | ||||
* @see java.lang.Object#toString() | * @see java.lang.Object#toString() | ||||
*/ | */ | ||||
} | } | ||||
return s.toString(); | return s.toString(); | ||||
} | } | ||||
} | } | ||||
private void addNode(int nodeIndex, List strings, NodeString ns) { | private void addNode(int nodeIndex, List strings, NodeString ns) { | ||||
} | } | ||||
tree.append(indentString); | tree.append(indentString); | ||||
tree.append(ns.string + "\n"); | tree.append(ns.string + "\n"); | ||||
if (i + 1 == strings.size()) { | if (i + 1 == strings.size()) { | ||||
continue; | continue; | ||||
} | } | ||||
} | } | ||||
tree.append(indentString + "\n"); | tree.append(indentString + "\n"); | ||||
} | } | ||||
return tree.toString(); | return tree.toString(); | ||||
} | } | ||||
/** | /** | ||||
* Construct the tree representation of the HyphenationTree object | * Construct the tree representation of the HyphenationTree object | ||||
* @return the string representing the tree | * @return the string representing the tree | ||||
addNode(1, strings, ns); | addNode(1, strings, ns); | ||||
return toTree(strings); | return toTree(strings); | ||||
} | } | ||||
/** | /** | ||||
* Construct the compact node representation of the HyphenationTree object | * Construct the compact node representation of the HyphenationTree object | ||||
* @return the string representing the tree | * @return the string representing the tree | ||||
} | } | ||||
return s.toString(); | return s.toString(); | ||||
} | } | ||||
/** | /** | ||||
* Construct the node representation of the HyphenationTree object | * Construct the node representation of the HyphenationTree object | ||||
* @return the string representing the tree | * @return the string representing the tree | ||||
} | } | ||||
return s.toString(); | return s.toString(); | ||||
} | } | ||||
/** | /** | ||||
* Construct the printed representation of the HyphenationTree object | * Construct the printed representation of the HyphenationTree object | ||||
* @return the string representing the tree | * @return the string representing the tree | ||||
*/ | */ | ||||
public String toString() { | public String toString() { | ||||
StringBuffer s = new StringBuffer(); | StringBuffer s = new StringBuffer(); | ||||
s.append("classes: \n"); | s.append("classes: \n"); | ||||
s.append((new TernaryTreeAnalysis(ht.classmap)).toString()); | s.append((new TernaryTreeAnalysis(ht.classmap)).toString()); | ||||
s.append("\npatterns: \n"); | s.append("\npatterns: \n"); | ||||
s.append(super.toString()); | s.append(super.toString()); | ||||
s.append("vspace: "); | s.append("vspace: "); | ||||
} | } | ||||
} | } | ||||
s.append("\n"); | s.append("\n"); | ||||
return s.toString(); | return s.toString(); | ||||
} | } | ||||
/** | /** | ||||
* Provide interactive access to a HyphenationTree object and its representation methods | |||||
* Provide interactive access to a HyphenationTree object and its representation methods | |||||
* @param args the arguments | * @param args the arguments | ||||
*/ | */ | ||||
public static void main(String[] args) { | public static void main(String[] args) { | ||||
System.out.print("Object file name: "); | System.out.print("Object file name: "); | ||||
token = in.readLine().trim(); | token = in.readLine().trim(); | ||||
try { | try { | ||||
String[] parts = token.split(":"); | |||||
String[] parts = token.split(":"); | |||||
InputStream is = null; | InputStream is = null; | ||||
if (parts.length == 1) { | if (parts.length == 1) { | ||||
is = new FileInputStream(token); | is = new FileInputStream(token); | ||||
try { | try { | ||||
BufferedReader reader = new BufferedReader(new FileReader(token)); | BufferedReader reader = new BufferedReader(new FileReader(token)); | ||||
String line; | String line; | ||||
starttime = System.currentTimeMillis(); | starttime = System.currentTimeMillis(); | ||||
while ((line = reader.readLine()) != null) { | while ((line = reader.readLine()) != null) { | ||||
// System.out.print("\nline: "); | // System.out.print("\nline: "); | ||||
long result = endtime - starttime; | long result = endtime - starttime; | ||||
System.out.println(counter + " words in " + result | System.out.println(counter + " words in " + result | ||||
+ " Milliseconds hyphenated"); | + " Milliseconds hyphenated"); | ||||
} else if (token.equals("q")) { | } else if (token.equals("q")) { | ||||
break; | break; | ||||
} | } |
import java.util.List; | import java.util.List; | ||||
/** | /** | ||||
* This class provides some useful methods to print the structure of a TernaryTree object | |||||
* This class provides some useful methods to print the structure of a TernaryTree object | |||||
*/ | */ | ||||
public class TernaryTreeAnalysis { | public class TernaryTreeAnalysis { | ||||
/** | /** | ||||
* The TernaryTree object to analyse | |||||
* The TernaryTree object to analyse | |||||
*/ | */ | ||||
protected TernaryTree tt; | protected TernaryTree tt; | ||||
/** | /** | ||||
* @param tt the TernaryTree object | * @param tt the TernaryTree object | ||||
*/ | */ | ||||
* Class representing a string of nodes in the tree representation of a TernaryTree | * Class representing a string of nodes in the tree representation of a TernaryTree | ||||
*/ | */ | ||||
public static class NodeString { | public static class NodeString { | ||||
/** | /** | ||||
* The node string being constructed | |||||
* The node string being constructed | |||||
*/ | */ | ||||
public StringBuffer string = new StringBuffer(); | public StringBuffer string = new StringBuffer(); | ||||
/** | /** | ||||
* The indent of the node string | |||||
* The indent of the node string | |||||
*/ | */ | ||||
public int indent; | public int indent; | ||||
/** | /** | ||||
* The list of branchpoints into the high direction | |||||
* The list of branchpoints into the high direction | |||||
*/ | */ | ||||
public List high = new ArrayList(); | public List high = new ArrayList(); | ||||
/** | /** | ||||
* The list of branchpoints into the low direction | |||||
* The list of branchpoints into the low direction | |||||
*/ | */ | ||||
public List low = new ArrayList(); | public List low = new ArrayList(); | ||||
/** | /** | ||||
* @param indent the indent of the nodestring | * @param indent the indent of the nodestring | ||||
*/ | */ | ||||
* Class representing a node of the TernaryTree object | * Class representing a node of the TernaryTree object | ||||
*/ | */ | ||||
protected class Node { | protected class Node { | ||||
/** | /** | ||||
* The index of the node | |||||
* The index of the node | |||||
*/ | */ | ||||
protected int index = 0; | protected int index = 0; | ||||
/** | /** | ||||
* The index of the high node | |||||
* The index of the high node | |||||
*/ | */ | ||||
protected int high = 0; | protected int high = 0; | ||||
/** | /** | ||||
* The index of the high node | |||||
* The index of the high node | |||||
*/ | */ | ||||
protected int low = 0; | protected int low = 0; | ||||
/** | /** | ||||
* The index of the equal node | |||||
* The index of the equal node | |||||
*/ | */ | ||||
protected int equal = 0; | protected int equal = 0; | ||||
/** | /** | ||||
* The key following the node | |||||
* The key following the node | |||||
*/ | */ | ||||
protected String key = null; | protected String key = null; | ||||
/** | /** | ||||
* True if this is a leaf node | |||||
* True if this is a leaf node | |||||
*/ | */ | ||||
protected boolean isLeafNode = false; | protected boolean isLeafNode = false; | ||||
equal = tt.eq[index]; | equal = tt.eq[index]; | ||||
} | } | ||||
} | } | ||||
private StringBuffer readKey() { | private StringBuffer readKey() { | ||||
StringBuffer s = new StringBuffer(); | StringBuffer s = new StringBuffer(); | ||||
int i = (int) tt.lo[index]; | int i = (int) tt.lo[index]; | ||||
} | } | ||||
return s.toString(); | return s.toString(); | ||||
} | } | ||||
/** | /** | ||||
* Construct the compact string representation of the node | * Construct the compact string representation of the node | ||||
* @return the string representing the node | * @return the string representing the node | ||||
} | } | ||||
return s.toString(); | return s.toString(); | ||||
} | } | ||||
/* (non-Javadoc) | /* (non-Javadoc) | ||||
* @see java.lang.Object#toString() | * @see java.lang.Object#toString() | ||||
*/ | */ | ||||
} | } | ||||
return s.toString(); | return s.toString(); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Construct the compact node representation of the TernaryTree object | * Construct the compact node representation of the TernaryTree object | ||||
* @return the string representing the tree | * @return the string representing the tree | ||||
} | } | ||||
return s.toString(); | return s.toString(); | ||||
} | } | ||||
/** | /** | ||||
* Construct the node representation of the TernaryTree object | * Construct the node representation of the TernaryTree object | ||||
* @return the string representing the tree | * @return the string representing the tree | ||||
} | } | ||||
return s.toString(); | return s.toString(); | ||||
} | } | ||||
private static StringBuffer toString(char[] c) { | private static StringBuffer toString(char[] c) { | ||||
StringBuffer s = new StringBuffer(); | StringBuffer s = new StringBuffer(); | ||||
for (int i = 0; i < c.length; ++i) { | for (int i = 0; i < c.length; ++i) { | ||||
s.append(","); | s.append(","); | ||||
} | } | ||||
return s; | return s; | ||||
} | |||||
} | |||||
/* (non-Javadoc) | /* (non-Javadoc) | ||||
* @see java.lang.Object#toString() | * @see java.lang.Object#toString() | ||||
*/ | */ | ||||
s.append("hi: "); | s.append("hi: "); | ||||
s.append(toString(tt.hi)); | s.append(toString(tt.hi)); | ||||
s.append("\n"); | s.append("\n"); | ||||
s.append("eq: "); | s.append("eq: "); | ||||
s.append(toString(tt.eq)); | s.append(toString(tt.eq)); | ||||
s.append("\n"); | s.append("\n"); | ||||
s.append("lo: "); | s.append("lo: "); | ||||
s.append(toString(tt.lo)); | s.append(toString(tt.lo)); | ||||
s.append("\n"); | s.append("\n"); | ||||
s.append("sc: "); | s.append("sc: "); | ||||
for (int i = 0; i < tt.sc.length; ++i) { | for (int i = 0; i < tt.sc.length; ++i) { | ||||
if (tt.sc[i] == 0) { | if (tt.sc[i] == 0) { | ||||
} | } | ||||
} | } | ||||
s.append("\n"); | s.append("\n"); | ||||
s.append("kv: "); | s.append("kv: "); | ||||
for (int i = 0; i < tt.kv.length(); ++i) { | for (int i = 0; i < tt.kv.length(); ++i) { | ||||
if (tt.kv.get(i) == 0) { | if (tt.kv.get(i) == 0) { | ||||
} | } | ||||
} | } | ||||
s.append("\n"); | s.append("\n"); | ||||
s.append("freenode: "); | s.append("freenode: "); | ||||
s.append((int) tt.freenode); | s.append((int) tt.freenode); | ||||
s.append("\n"); | s.append("\n"); | ||||
s.append("root: "); | s.append("root: "); | ||||
s.append((int) tt.root); | s.append((int) tt.root); | ||||
s.append("\n"); | s.append("\n"); | ||||
return s.toString(); | return s.toString(); | ||||
} | } | ||||
} | } |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
/** MathML MIME type */ | /** MathML MIME type */ | ||||
public static final String MIME_MATHML = "text/mathml"; | public static final String MIME_MATHML = "text/mathml"; | ||||
private static final ImageFlavor[] FLAVORS = new ImageFlavor[] { | private static final ImageFlavor[] FLAVORS = new ImageFlavor[] { | ||||
ImageFlavor.GRAPHICS2D}; | ImageFlavor.GRAPHICS2D}; | ||||
private static final String[] MIMES = new String[] { | private static final String[] MIMES = new String[] { | ||||
MIME_MATHML}; | MIME_MATHML}; | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public String[] getSupportedMIMETypes() { | public String[] getSupportedMIMETypes() { | ||||
return MIMES; | return MIMES; | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public ImageFlavor[] getSupportedFlavors(String mime) { | public ImageFlavor[] getSupportedFlavors(String mime) { | ||||
return FLAVORS; | return FLAVORS; | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public ImageLoader newImageLoader(ImageFlavor targetFlavor) { | public ImageLoader newImageLoader(ImageFlavor targetFlavor) { | ||||
return new ImageLoaderMathML(targetFlavor); | return new ImageLoaderMathML(targetFlavor); | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public int getUsagePenalty(String mime, ImageFlavor flavor) { | public int getUsagePenalty(String mime, ImageFlavor flavor) { | ||||
return 0; | return 0; |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
} | } | ||||
this.targetFlavor = targetFlavor; | this.targetFlavor = targetFlavor; | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public ImageFlavor getTargetFlavor() { | public ImageFlavor getTargetFlavor() { | ||||
return this.targetFlavor; | return this.targetFlavor; |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.mathml; | package org.apache.fop.mathml; | ||||
import java.awt.Color; | import java.awt.Color; | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public void processNode(String elementName, | |||||
Locator locator, | |||||
Attributes attlist, | |||||
public void processNode(String elementName, | |||||
Locator locator, | |||||
Attributes attlist, | |||||
PropertyList propertyList) throws FOPException { | PropertyList propertyList) throws FOPException { | ||||
super.processNode(elementName, locator, attlist, propertyList); | super.processNode(elementName, locator, attlist, propertyList); | ||||
createBasicDocument(); | createBasicDocument(); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.mathml; | package org.apache.fop.mathml; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
public class MathMLElementMapping extends ElementMapping { | public class MathMLElementMapping extends ElementMapping { | ||||
/** MathML Namespace */ | /** MathML Namespace */ | ||||
public static final String NAMESPACE = "http://www.w3.org/1998/Math/MathML"; | |||||
public static final String NAMESPACE = "http://www.w3.org/1998/Math/MathML"; | |||||
/** Main constructor. */ | /** Main constructor. */ | ||||
public MathMLElementMapping() { | public MathMLElementMapping() { |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.mathml; | package org.apache.fop.mathml; | ||||
// FOP | // FOP |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.mathml; | package org.apache.fop.mathml; | ||||
import java.awt.Dimension; | import java.awt.Dimension; | ||||
private static Log log = LogFactory.getLog(PreloaderMathML.class); | private static Log log = LogFactory.getLog(PreloaderMathML.class); | ||||
private boolean jeuclidAvailable = true; | private boolean jeuclidAvailable = true; | ||||
/** {@inheritDoc} */ | |||||
/** {@inheritDoc} */ | |||||
public ImageInfo preloadImage(String uri, Source src, ImageContext context) | public ImageInfo preloadImage(String uri, Source src, ImageContext context) | ||||
throws IOException { | throws IOException { | ||||
if (!ImageUtil.hasInputStream(src)) { | if (!ImageUtil.hasInputStream(src)) { | ||||
* class. | * class. | ||||
*/ | */ | ||||
class Loader { | class Loader { | ||||
private ImageInfo getImage(String uri, Source src, ImageContext context) { | private ImageInfo getImage(String uri, Source src, ImageContext context) { | ||||
InputStream in = new UnclosableInputStream(ImageUtil.needInputStream(src)); | InputStream in = new UnclosableInputStream(ImageUtil.needInputStream(src)); | ||||
try { | try { | ||||
int length = in.available(); | int length = in.available(); | ||||
in.mark(length + 1); | in.mark(length + 1); | ||||
TransformerFactory tFactory = TransformerFactory.newInstance(); | TransformerFactory tFactory = TransformerFactory.newInstance(); | ||||
Transformer transformer = tFactory.newTransformer(); | Transformer transformer = tFactory.newTransformer(); | ||||
Source source = new StreamSource(in); | Source source = new StreamSource(in); | ||||
SAXMathBuilder mathBuilder = new SAXMathBuilder(); | SAXMathBuilder mathBuilder = new SAXMathBuilder(); | ||||
SAXResult res = new SAXResult(mathBuilder); | SAXResult res = new SAXResult(mathBuilder); | ||||
transformer.transform(source, res); | transformer.transform(source, res); | ||||
String fontname = "Helvetica"; | String fontname = "Helvetica"; | ||||
int fontstyle = 0; | int fontstyle = 0; | ||||
int displayfontsize = 12; | int displayfontsize = 12; | ||||
mathBuilder.getMathRootElement(), | mathBuilder.getMathRootElement(), | ||||
fontname, fontstyle, inlinefontsize, | fontname, fontstyle, inlinefontsize, | ||||
displayfontsize); | displayfontsize); | ||||
ImageInfo info = new ImageInfo(uri, "text/mathml"); | ImageInfo info = new ImageInfo(uri, "text/mathml"); | ||||
final ImageSize size = new ImageSize(); | final ImageSize size = new ImageSize(); | ||||
size.setSizeInMillipoints( | size.setSizeInMillipoints( | ||||
public void paint(Graphics2D g2d, Rectangle2D area) { | public void paint(Graphics2D g2d, Rectangle2D area) { | ||||
base.paint(g2d); | base.paint(g2d); | ||||
} | } | ||||
}; | }; | ||||
//The whole image had to be loaded for this, so keep it | //The whole image had to be loaded for this, so keep it | ||||
Image image = new ImageGraphics2D(info, painter); | Image image = new ImageGraphics2D(info, painter); | ||||
info.getCustomObjects().put(ImageInfo.ORIGINAL_IMAGE, image); | info.getCustomObjects().put(ImageInfo.ORIGINAL_IMAGE, image); | ||||
return info; | return info; | ||||
} catch (NoClassDefFoundError ncdfe) { | } catch (NoClassDefFoundError ncdfe) { | ||||
try { | try { |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.plan; | package org.apache.fop.plan; | ||||
import java.util.Date; | import java.util.Date; | ||||
public class ActionInfo { | public class ActionInfo { | ||||
public static final int TASK = 1; | public static final int TASK = 1; | ||||
public static final int MILESTONE = 2; | public static final int MILESTONE = 2; | ||||
public static final int GROUPING = 3; | public static final int GROUPING = 3; |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.plan; | package org.apache.fop.plan; | ||||
import java.util.List; | import java.util.List; | ||||
public class EventList { | public class EventList { | ||||
private List data = new java.util.ArrayList(); | private List data = new java.util.ArrayList(); | ||||
public void addGroupInfo(GroupInfo set) { | public void addGroupInfo(GroupInfo set) { |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.plan; | package org.apache.fop.plan; | ||||
import java.util.List; | import java.util.List; | ||||
public class GroupInfo { | public class GroupInfo { | ||||
private String name; | private String name; | ||||
private List actions = new java.util.ArrayList(); | private List actions = new java.util.ArrayList(); | ||||
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.plan; | package org.apache.fop.plan; | ||||
import java.io.InputStream; | import java.io.InputStream; |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.plan; | package org.apache.fop.plan; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
* This interface defines how a plan drawer is converted. | * This interface defines how a plan drawer is converted. | ||||
*/ | */ | ||||
public interface PlanDrawer { | public interface PlanDrawer { | ||||
Document createDocument(EventList data, float w, float h, | Document createDocument(EventList data, float w, float h, | ||||
HashMap hints); | HashMap hints); | ||||
} | } |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.plan; | package org.apache.fop.plan; | ||||
import java.awt.geom.Point2D; | import java.awt.geom.Point2D; | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public void processNode(String elementName, Locator locator, | |||||
public void processNode(String elementName, Locator locator, | |||||
Attributes attlist, PropertyList propertyList) | Attributes attlist, PropertyList propertyList) | ||||
throws FOPException { | throws FOPException { | ||||
super.processNode(elementName, locator, attlist, propertyList); | super.processNode(elementName, locator, attlist, propertyList); | ||||
svgDoc = pr.createSVGDocument(doc); | svgDoc = pr.createSVGDocument(doc); | ||||
width = pr.getWidth(); | width = pr.getWidth(); | ||||
height = pr.getHeight(); | height = pr.getHeight(); | ||||
doc = svgDoc; | doc = svgDoc; | ||||
} | } | ||||
} catch (Throwable t) { | } catch (Throwable t) { |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.plan; | package org.apache.fop.plan; | ||||
import org.w3c.dom.DOMImplementation; | import org.w3c.dom.DOMImplementation; | ||||
public class PlanElementMapping extends ElementMapping { | public class PlanElementMapping extends ElementMapping { | ||||
/** Plan Namespace */ | /** Plan Namespace */ | ||||
public static final String NAMESPACE = "http://xmlgraphics.apache.org/fop/plan"; | |||||
public static final String NAMESPACE = "http://xmlgraphics.apache.org/fop/plan"; | |||||
/** Main constructor. */ | /** Main constructor. */ | ||||
public PlanElementMapping() { | public PlanElementMapping() { |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.plan; | package org.apache.fop.plan; | ||||
/** | /** | ||||
* This interface defines some constants for use in the plan package. | * This interface defines some constants for use in the plan package. | ||||
*/ | */ | ||||
public interface PlanHints { | public interface PlanHints { | ||||
/** Border attribute */ | /** Border attribute */ | ||||
public static final String PLAN_BORDER = "border"; | public static final String PLAN_BORDER = "border"; | ||||
/** Legend attribute */ | /** Legend attribute */ |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.plan; | package org.apache.fop.plan; | ||||
// FOP | // FOP |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.plan; | package org.apache.fop.plan; | ||||
import org.apache.batik.dom.svg.SVGDOMImplementation; | import org.apache.batik.dom.svg.SVGDOMImplementation; | ||||
public class PlanRenderer { | public class PlanRenderer { | ||||
private static final String SVG_NAMESPACE = SVGDOMImplementation.SVG_NAMESPACE_URI; | private static final String SVG_NAMESPACE = SVGDOMImplementation.SVG_NAMESPACE_URI; | ||||
private String fontFamily = "sansserif"; | private String fontFamily = "sansserif"; | ||||
private float fontSize = 12; | private float fontSize = 12; | ||||
private String type = ""; | private String type = ""; |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.plan; | package org.apache.fop.plan; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
/** Logger instance */ | /** Logger instance */ | ||||
private static Log log = LogFactory.getLog(PreloaderPlan.class); | private static Log log = LogFactory.getLog(PreloaderPlan.class); | ||||
/** {@inheritDoc} */ | |||||
/** {@inheritDoc} */ | |||||
public ImageInfo preloadImage(String uri, Source src, ImageContext context) | public ImageInfo preloadImage(String uri, Source src, ImageContext context) | ||||
throws IOException { | throws IOException { | ||||
if (!ImageUtil.hasInputStream(src)) { | if (!ImageUtil.hasInputStream(src)) { | ||||
Source source = new StreamSource(in); | Source source = new StreamSource(in); | ||||
DOMResult res = new DOMResult(); | DOMResult res = new DOMResult(); | ||||
transformer.transform(source, res); | transformer.transform(source, res); | ||||
//Have to render the plan to know its size | //Have to render the plan to know its size | ||||
PlanRenderer pr = new PlanRenderer(); | PlanRenderer pr = new PlanRenderer(); | ||||
Document svgDoc = pr.createSVGDocument((Document)res.getNode()); | Document svgDoc = pr.createSVGDocument((Document)res.getNode()); | ||||
float width = pr.getWidth(); | float width = pr.getWidth(); | ||||
float height = pr.getHeight(); | float height = pr.getHeight(); | ||||
//Return converted SVG image | //Return converted SVG image | ||||
ImageInfo info = new ImageInfo(uri, "image/svg+xml"); | ImageInfo info = new ImageInfo(uri, "image/svg+xml"); | ||||
final ImageSize size = new ImageSize(); | final ImageSize size = new ImageSize(); | ||||
Image image = new ImageXMLDOM(info, svgDoc, | Image image = new ImageXMLDOM(info, svgDoc, | ||||
svgDoc.getDocumentElement().getNamespaceURI()); | svgDoc.getDocumentElement().getNamespaceURI()); | ||||
info.getCustomObjects().put(ImageInfo.ORIGINAL_IMAGE, image); | info.getCustomObjects().put(ImageInfo.ORIGINAL_IMAGE, image); | ||||
return info; | return info; | ||||
} catch (TransformerException e) { | } catch (TransformerException e) { | ||||
try { | try { |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.plan; | package org.apache.fop.plan; | ||||
import java.text.DateFormat; | import java.text.DateFormat; | ||||
* Simple plan drawer implementation. | * Simple plan drawer implementation. | ||||
*/ | */ | ||||
public class SimplePlanDrawer implements PlanDrawer { | public class SimplePlanDrawer implements PlanDrawer { | ||||
private static final String SVG_NAMESPACE = SVGDOMImplementation.SVG_NAMESPACE_URI; | private static final String SVG_NAMESPACE = SVGDOMImplementation.SVG_NAMESPACE_URI; | ||||
private float fontSize; | private float fontSize; | ||||
private HashMap hints; | private HashMap hints; | ||||
private java.awt.Font font = null; | private java.awt.Font font = null; | ||||
svgRoot.setAttributeNS(null, "width", "" + width); | svgRoot.setAttributeNS(null, "width", "" + width); | ||||
svgRoot.setAttributeNS(null, "height", "" + height); | svgRoot.setAttributeNS(null, "height", "" + height); | ||||
svgRoot.setAttributeNS(null, "style", | svgRoot.setAttributeNS(null, "style", | ||||
"font-size:" + 8 | |||||
+ ";font-family:" | |||||
"font-size:" + 8 | |||||
+ ";font-family:" | |||||
+ hints.get(PlanHints.FONT_FAMILY)); | + hints.get(PlanHints.FONT_FAMILY)); | ||||
font = new java.awt.Font((String)hints.get(PlanHints.FONT_FAMILY), | font = new java.awt.Font((String)hints.get(PlanHints.FONT_FAMILY), | ||||
taskGraphic = SVGUtilities.createRect(doc, | taskGraphic = SVGUtilities.createRect(doc, | ||||
left + daysToStart * 300 / (totalDays - 2), | left + daysToStart * 300 / (totalDays - 2), | ||||
topEdge + 2, days * 300 / (totalDays - 2), 10); | topEdge + 2, days * 300 / (totalDays - 2), 10); | ||||
taskGraphic.setAttributeNS(null, | |||||
"style", | |||||
taskGraphic.setAttributeNS(null, | |||||
"style", | |||||
"stroke:black;fill:blue;stroke-width:1;clip-path:url(#clip3)"); | "stroke:black;fill:blue;stroke-width:1;clip-path:url(#clip3)"); | ||||
g.appendChild(taskGraphic); | g.appendChild(taskGraphic); | ||||
break; | break; | ||||
"m " + (left | "m " + (left | ||||
+ daysToStart * 300 / (totalDays - 2) - 6) | + daysToStart * 300 / (totalDays - 2) - 6) | ||||
+ " " + (topEdge + 6) + "l6 6l6-6l-6-6z"); | + " " + (topEdge + 6) + "l6 6l6-6l-6-6z"); | ||||
taskGraphic.setAttributeNS(null, | |||||
"style", | |||||
taskGraphic.setAttributeNS(null, | |||||
"style", | |||||
"stroke:black;fill:black;stroke-width:1;clip-path:url(#clip3)"); | "stroke:black;fill:black;stroke-width:1;clip-path:url(#clip3)"); | ||||
g.appendChild(taskGraphic); | g.appendChild(taskGraphic); | ||||
text = SVGUtilities.createText(doc, | text = SVGUtilities.createText(doc, | ||||
break; | break; | ||||
case ActionInfo.GROUPING: | case ActionInfo.GROUPING: | ||||
taskGraphic = SVGUtilities.createPath(doc, | taskGraphic = SVGUtilities.createPath(doc, | ||||
"m " + (left | |||||
"m " + (left | |||||
+ daysToStart * 300 / (totalDays - 2) - 6) | + daysToStart * 300 / (totalDays - 2) - 6) | ||||
+ " " + (topEdge + 6) + "l6 -6l" | + " " + (topEdge + 6) + "l6 -6l" | ||||
+ (days * 300 / (totalDays - 2)) | + (days * 300 / (totalDays - 2)) | ||||
+ -(days * 300 / (totalDays - 2) - 8) | + -(days * 300 / (totalDays - 2) - 8) | ||||
+ " 0l-4 4l-6-6z"); | + " 0l-4 4l-6-6z"); | ||||
taskGraphic.setAttributeNS(null, | taskGraphic.setAttributeNS(null, | ||||
"style", | |||||
"style", | |||||
"stroke:black;fill:black;stroke-width:1;clip-path:url(#clip3)"); | "stroke:black;fill:black;stroke-width:1;clip-path:url(#clip3)"); | ||||
g.appendChild(taskGraphic); | g.appendChild(taskGraphic); | ||||
break; | break; |
public EventConventionException(String message) { | public EventConventionException(String message) { | ||||
super(message); | super(message); | ||||
} | } | ||||
} | } |
/* | |||||
/* | |||||
* Licensed to the Apache Software Foundation (ASF) under one or more | * Licensed to the Apache Software Foundation (ASF) under one or more | ||||
* contributor license agreements. See the NOTICE file distributed with | * contributor license agreements. See the NOTICE file distributed with | ||||
* this work for additional information regarding copyright ownership. | * this work for additional information regarding copyright ownership. | ||||
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
* table for the table driven line breaking algorithm described in | * table for the table driven line breaking algorithm described in | ||||
* <a href="http://unicode.org/reports/tr14/#PairBasedImplementation">UTR #14</a>. | * <a href="http://unicode.org/reports/tr14/#PairBasedImplementation">UTR #14</a>. | ||||
* TODO: Code points above the base plane are simply ignored. | * TODO: Code points above the base plane are simply ignored. | ||||
* | |||||
* | |||||
* @param lineBreakFileName Name of line break property file (part of Unicode files). | * @param lineBreakFileName Name of line break property file (part of Unicode files). | ||||
* @param propertyValueFileName Name of property values alias file (part of Unicode files). | * @param propertyValueFileName Name of property values alias file (part of Unicode files). | ||||
* @param breakPairFileName Name of pair table file (<i>not</i> part of the unicode files). | * @param breakPairFileName Name of pair table file (<i>not</i> part of the unicode files). | ||||
if (line != null) { | if (line != null) { | ||||
lineTokens = line.split("\\s+"); | lineTokens = line.split("\\s+"); | ||||
byte columnNumber = 0; | byte columnNumber = 0; | ||||
for (int i = 0; i < lineTokens.length; ++i) { | for (int i = 0; i < lineTokens.length; ++i) { | ||||
name = lineTokens[i]; | name = lineTokens[i]; | ||||
if (name.length() > 0) { | if (name.length() > 0) { | ||||
* Read line break property value names and the actual properties for the Unicode | * Read line break property value names and the actual properties for the Unicode | ||||
* characters from the respective Unicode files. | * characters from the respective Unicode files. | ||||
* TODO: Code points above the base plane are simply ignored. | * TODO: Code points above the base plane are simply ignored. | ||||
* | |||||
* | |||||
* @param lineBreakFileName Name of line break property file. | * @param lineBreakFileName Name of line break property file. | ||||
* @param propertyValueFileName Name of property values alias file. | * @param propertyValueFileName Name of property values alias file. | ||||
* @throws Exception in case anything goes wrong. | * @throws Exception in case anything goes wrong. | ||||
* Determine a good block size for the two stage optimized storage of the | * Determine a good block size for the two stage optimized storage of the | ||||
* line breaking properties. Note: the memory utilization calculation is a rule of thumb, | * line breaking properties. Note: the memory utilization calculation is a rule of thumb, | ||||
* don't take it too serious. | * don't take it too serious. | ||||
* | |||||
* | |||||
* @param lineBreakFileName Name of line break property file. | * @param lineBreakFileName Name of line break property file. | ||||
* @param propertyValueFileName Name of property values alias file. | * @param propertyValueFileName Name of property values alias file. | ||||
* @throws Exception in case anything goes wrong. | * @throws Exception in case anything goes wrong. |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
import org.apache.fop.messaging.MessageHandler; | import org.apache.fop.messaging.MessageHandler; | ||||
/** | /** | ||||
* This class converts an XML file to PDF using | |||||
* This class converts an XML file to PDF using | |||||
* JAXP (XSLT) and FOP (XSL:FO). | * JAXP (XSLT) and FOP (XSL:FO). | ||||
*/ | */ | ||||
public class BookMaker implements ErrorHandler { | public class BookMaker implements ErrorHandler { | ||||
throw e; | throw e; | ||||
} | } | ||||
public void makeBook() | |||||
public void makeBook() | |||||
throws IOException, FOPException, TransformerException, | throws IOException, FOPException, TransformerException, | ||||
FactoryConfigurationError, | FactoryConfigurationError, | ||||
ParserConfigurationException, SAXException { | ParserConfigurationException, SAXException { | ||||
+ " as SAX parser"); | + " as SAX parser"); | ||||
xmlReader.setErrorHandler(this); | xmlReader.setErrorHandler(this); | ||||
xmlReader.setEntityResolver(resolver); | xmlReader.setEntityResolver(resolver); | ||||
// Setup SAX source | // Setup SAX source | ||||
fis = new FileInputStream(xmlFile); | fis = new FileInputStream(xmlFile); | ||||
is = new InputSource(fis); | is = new InputSource(fis); | ||||
+ " as SAX parser"); | + " as SAX parser"); | ||||
xmlReader.setErrorHandler(this); | xmlReader.setErrorHandler(this); | ||||
xmlReader.setEntityResolver(resolver); | xmlReader.setEntityResolver(resolver); | ||||
// Setup SAX source | // Setup SAX source | ||||
fis = new FileInputStream(xsltFile); | fis = new FileInputStream(xsltFile); | ||||
is = new InputSource(fis); | is = new InputSource(fis); | ||||
+ " as TrAX transformer"); | + " as TrAX transformer"); | ||||
// Set the value of parameters, if any, defined for stylesheet | // Set the value of parameters, if any, defined for stylesheet | ||||
if (xsltParams != null) { | |||||
if (xsltParams != null) { | |||||
for (int i = 0; i < xsltParams.size(); i += 2) { | for (int i = 0; i < xsltParams.size(); i += 2) { | ||||
transformer.setParameter | transformer.setParameter | ||||
((String) xsltParams.elementAt(i), | ((String) xsltParams.elementAt(i), | ||||
} | } | ||||
if (cl.hasOption("xsl")) { | if (cl.hasOption("xsl")) { | ||||
app.xsltFile = new File(cl.getOptionValue("xsl")); | app.xsltFile = new File(cl.getOptionValue("xsl")); | ||||
} | |||||
} | |||||
if (cl.hasOption("out")) { | if (cl.hasOption("out")) { | ||||
app.outFile = new File(cl.getOptionValue("out")); | app.outFile = new File(cl.getOptionValue("out")); | ||||
} | } | ||||
} | } | ||||
app.logger.info(""); | app.logger.info(""); | ||||
app.logger.info("Transforming..."); | app.logger.info("Transforming..."); | ||||
app.makeBook(); | app.makeBook(); | ||||
app.logger.info("Transforming done"); | app.logger.info("Transforming done"); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
app.logger.error(ExceptionUtil.printStackTrace(e)); | app.logger.error(ExceptionUtil.printStackTrace(e)); |
* as this package equals the one specified in the manifest. | * as this package equals the one specified in the manifest. | ||||
*/ | */ | ||||
public final class Version { | public final class Version { | ||||
private Version() { } | private Version() { } | ||||
/** | /** | ||||
} | } | ||||
if (version == null) { | if (version == null) { | ||||
//Fallback if FOP is used in a development environment | //Fallback if FOP is used in a development environment | ||||
String headURL | |||||
String headURL | |||||
= "$HeadURL$"; | = "$HeadURL$"; | ||||
version = headURL; | version = headURL; | ||||
final String pathPrefix = "/xmlgraphics/fop/"; | final String pathPrefix = "/xmlgraphics/fop/"; | ||||
int pos = version.indexOf(pathPrefix); | |||||
int pos = version.indexOf(pathPrefix); | |||||
if (pos >= 0) { | if (pos >= 0) { | ||||
version = version.substring(pos + pathPrefix.length() - 1, version.length() - 2); | version = version.substring(pos + pathPrefix.length() - 1, version.length() - 2); | ||||
pos = version.indexOf("/src/"); | pos = version.indexOf("/src/"); | ||||
} | } | ||||
return version; | return version; | ||||
} | } | ||||
} | } |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
private String systemId; | private String systemId; | ||||
private int line; | private int line; | ||||
private int column; | private int column; | ||||
private String localizedMessage; | private String localizedMessage; | ||||
/** | /** | ||||
/** | /** | ||||
* Constructs a new exception with the specified detail message and cause. | * Constructs a new exception with the specified detail message and cause. | ||||
* @param message the detail message | * @param message the detail message | ||||
* @param cause the cause | |||||
* @param cause the cause | |||||
*/ | */ | ||||
public FOPException(String message, Exception cause) { | public FOPException(String message, Exception cause) { | ||||
super(message, cause); | super(message, cause); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Sets the localized message for this exception. | * Sets the localized message for this exception. | ||||
* @param msg the localized message | * @param msg the localized message | ||||
} | } | ||||
} | } | ||||
} | } |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
/** | /** | ||||
* Provides FOP specific URI resolution. This is the default URIResolver | * Provides FOP specific URI resolution. This is the default URIResolver | ||||
* {@link FOUserAgent} will use unless overidden. | * {@link FOUserAgent} will use unless overidden. | ||||
* | |||||
* | |||||
* @see javax.xml.transform.URIResolver | * @see javax.xml.transform.URIResolver | ||||
*/ | */ | ||||
public class FOURIResolver implements javax.xml.transform.URIResolver { | public class FOURIResolver implements javax.xml.transform.URIResolver { | ||||
/** | /** | ||||
* Additional constructor | * Additional constructor | ||||
* | |||||
* | |||||
* @param throwExceptions | * @param throwExceptions | ||||
* true if exceptions are to be thrown if the URIs cannot be | * true if exceptions are to be thrown if the URIs cannot be | ||||
* resolved. | * resolved. | ||||
/** | /** | ||||
* Handles resolve exceptions appropriately. | * Handles resolve exceptions appropriately. | ||||
* | |||||
* | |||||
* @param errorStr | * @param errorStr | ||||
* error string | * error string | ||||
* @param strict | * @param strict | ||||
* If the method is successful it will return a Source of type | * If the method is successful it will return a Source of type | ||||
* {@link javax.xml.transform.stream.StreamSource} with its SystemID set to | * {@link javax.xml.transform.stream.StreamSource} with its SystemID set to | ||||
* the resolved URL used to open the underlying InputStream. | * the resolved URL used to open the underlying InputStream. | ||||
* | |||||
* | |||||
* @param href | * @param href | ||||
* An href attribute, which may be relative or absolute. | * An href attribute, which may be relative or absolute. | ||||
* @param base | * @param base | ||||
/* | /* | ||||
* This piece of code is based on the following statement in | * This piece of code is based on the following statement in | ||||
* RFC2396 section 5.2: | * RFC2396 section 5.2: | ||||
* | |||||
* | |||||
* 3) If the scheme component is defined, indicating that | * 3) If the scheme component is defined, indicating that | ||||
* the reference starts with a scheme name, then the | * the reference starts with a scheme name, then the | ||||
* reference is interpreted as an absolute URI and we are | * reference is interpreted as an absolute URI and we are | ||||
* done. Otherwise, the reference URI's scheme is inherited | * done. Otherwise, the reference URI's scheme is inherited | ||||
* from the base URI's scheme component. | * from the base URI's scheme component. | ||||
* | |||||
* | |||||
* Due to a loophole in prior specifications [RFC1630], some | * Due to a loophole in prior specifications [RFC1630], some | ||||
* parsers allow the scheme name to be present in a relative | * parsers allow the scheme name to be present in a relative | ||||
* URI if it is the same as the base URI scheme. | * URI if it is the same as the base URI scheme. | ||||
* removing the scheme if it matches that of the base URI | * removing the scheme if it matches that of the base URI | ||||
* and the scheme is known to always use the <hier_part> | * and the scheme is known to always use the <hier_part> | ||||
* syntax. | * syntax. | ||||
* | |||||
* | |||||
* The URL class does not implement this work around, so we | * The URL class does not implement this work around, so we | ||||
* do. | * do. | ||||
*/ | */ | ||||
* before the connect() method is called. Subclass FOURIResolver and | * before the connect() method is called. Subclass FOURIResolver and | ||||
* override this method to do things like adding the user name and password | * override this method to do things like adding the user name and password | ||||
* for HTTP basic authentication. | * for HTTP basic authentication. | ||||
* | |||||
* | |||||
* @param connection | * @param connection | ||||
* the URLConnection instance | * the URLConnection instance | ||||
* @param href | * @param href | ||||
* This is a convenience method for users who want to override | * This is a convenience method for users who want to override | ||||
* updateURLConnection for HTTP basic authentication. Simply call it using | * updateURLConnection for HTTP basic authentication. Simply call it using | ||||
* the right username and password. | * the right username and password. | ||||
* | |||||
* | |||||
* @param connection | * @param connection | ||||
* the URLConnection to set up for HTTP basic authentication | * the URLConnection to set up for HTTP basic authentication | ||||
* @param username | * @param username | ||||
* Sets the custom URI Resolver. It is used for resolving factory-level URIs like | * Sets the custom URI Resolver. It is used for resolving factory-level URIs like | ||||
* hyphenation patterns and as backup for URI resolution performed during a | * hyphenation patterns and as backup for URI resolution performed during a | ||||
* rendering run. | * rendering run. | ||||
* | |||||
* | |||||
* @param resolver | * @param resolver | ||||
* the new URI resolver | * the new URI resolver | ||||
*/ | */ | ||||
/** | /** | ||||
* Returns the custom URI Resolver. | * Returns the custom URI Resolver. | ||||
* | |||||
* | |||||
* @return the URI Resolver or null, if none is set | * @return the URI Resolver or null, if none is set | ||||
*/ | */ | ||||
public URIResolver getCustomURIResolver() { | public URIResolver getCustomURIResolver() { |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
/** | /** | ||||
* Gets the default page-height to use as fallback, | * Gets the default page-height to use as fallback, | ||||
* in case page-height="auto" | * in case page-height="auto" | ||||
* | |||||
* | |||||
* @return the page-height, as a String | * @return the page-height, as a String | ||||
* @see FopFactory#getPageHeight() | * @see FopFactory#getPageHeight() | ||||
*/ | */ | ||||
/** | /** | ||||
* Gets the default page-width to use as fallback, | * Gets the default page-width to use as fallback, | ||||
* in case page-width="auto" | * in case page-width="auto" | ||||
* | |||||
* | |||||
* @return the page-width, as a String | * @return the page-width, as a String | ||||
* @see FopFactory#getPageWidth() | * @see FopFactory#getPageWidth() | ||||
*/ | */ | ||||
/** | /** | ||||
* Controls the use of SAXLocators to provide location information in error | * Controls the use of SAXLocators to provide location information in error | ||||
* messages. | * messages. | ||||
* | |||||
* | |||||
* @param enableLocator <code>false</code> if SAX Locators should be disabled | * @param enableLocator <code>false</code> if SAX Locators should be disabled | ||||
*/ | */ | ||||
public void setLocatorEnabled(boolean enableLocator) { | public void setLocatorEnabled(boolean enableLocator) { |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
* Primary class that activates the FOP process for embedded usage. | * Primary class that activates the FOP process for embedded usage. | ||||
* <P> | * <P> | ||||
* JAXP is the standard method of embedding FOP in Java programs. | * JAXP is the standard method of embedding FOP in Java programs. | ||||
* Please check our | |||||
* Please check our | |||||
* <a href="http://xmlgraphics.apache.org/fop/trunk/embedding.html">embedding page</a> | * <a href="http://xmlgraphics.apache.org/fop/trunk/embedding.html">embedding page</a> | ||||
* for samples (these are also available within the distribution in | |||||
* for samples (these are also available within the distribution in | |||||
* FOP_DIR\examples\embedding) | * FOP_DIR\examples\embedding) | ||||
* <P> | * <P> | ||||
* Methods within FOUserAgent are available to customize portions of the | * Methods within FOUserAgent are available to customize portions of the | ||||
* process. For example, a specific Renderer object can be specified, | |||||
* process. For example, a specific Renderer object can be specified, | |||||
* also ElementMappings which determine elements in the FO that can be | * also ElementMappings which determine elements in the FO that can be | ||||
* processed) can be added. | * processed) can be added. | ||||
* <P> | * <P> | ||||
private FOTreeBuilder foTreeBuilder = null; | private FOTreeBuilder foTreeBuilder = null; | ||||
/** | /** | ||||
* Constructor for use with already-created FOUserAgents. It uses MIME types to select the | |||||
* Constructor for use with already-created FOUserAgents. It uses MIME types to select the | |||||
* output format (ex. "application/pdf" for PDF). | * output format (ex. "application/pdf" for PDF). | ||||
* @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). | * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). | ||||
* @param ua FOUserAgent object | * @param ua FOUserAgent object | ||||
if (foUserAgent == null) { | if (foUserAgent == null) { | ||||
foUserAgent = FopFactory.newInstance().newFOUserAgent(); | foUserAgent = FopFactory.newInstance().newFOUserAgent(); | ||||
} | } | ||||
this.stream = stream; | this.stream = stream; | ||||
createDefaultHandler(); | createDefaultHandler(); | ||||
} | } | ||||
* page-sequence. Call this method only after the rendering process is | * page-sequence. Call this method only after the rendering process is | ||||
* finished. Note that the results are only available for output formats | * finished. Note that the results are only available for output formats | ||||
* which make use of FOP's layout engine (PDF, PS, etc.). | * which make use of FOP's layout engine (PDF, PS, etc.). | ||||
* @return the results of the rendering process, or null for flow-oriented | |||||
* @return the results of the rendering process, or null for flow-oriented | |||||
* output formats like RTF and MIF. | * output formats like RTF and MIF. | ||||
*/ | */ | ||||
public FormattingResults getResults() { | public FormattingResults getResults() { |
/** | /** | ||||
* Gets the default page-height to use as fallback, | * Gets the default page-height to use as fallback, | ||||
* in case page-height="auto" | * in case page-height="auto" | ||||
* | |||||
* | |||||
* @return the page-height, as a String | * @return the page-height, as a String | ||||
*/ | */ | ||||
public String getPageHeight() { | public String getPageHeight() { | ||||
/** | /** | ||||
* Sets the page-height to use as fallback, in case | * Sets the page-height to use as fallback, in case | ||||
* page-height="auto" | * page-height="auto" | ||||
* | |||||
* | |||||
* @param pageHeight page-height as a String | * @param pageHeight page-height as a String | ||||
*/ | */ | ||||
public void setPageHeight(String pageHeight) { | public void setPageHeight(String pageHeight) { | ||||
/** | /** | ||||
* Gets the default page-width to use as fallback, | * Gets the default page-width to use as fallback, | ||||
* in case page-width="auto" | * in case page-width="auto" | ||||
* | |||||
* | |||||
* @return the page-width, as a String | * @return the page-width, as a String | ||||
*/ | */ | ||||
public String getPageWidth() { | public String getPageWidth() { | ||||
/** | /** | ||||
* Sets the page-width to use as fallback, in case | * Sets the page-width to use as fallback, in case | ||||
* page-width="auto" | * page-width="auto" | ||||
* | |||||
* | |||||
* @param pageWidth page-width as a String | * @param pageWidth page-width as a String | ||||
*/ | */ | ||||
public void setPageWidth(String pageWidth) { | public void setPageWidth(String pageWidth) { | ||||
/** | /** | ||||
* Create (if needed) and return an ICC ColorSpace instance. | * Create (if needed) and return an ICC ColorSpace instance. | ||||
* | |||||
* | |||||
* The ICC profile source is taken from the src attribute of the color-profile FO element. | * The ICC profile source is taken from the src attribute of the color-profile FO element. | ||||
* If the ICC ColorSpace is not yet in the cache a new one is created and stored in the cache. | * If the ICC ColorSpace is not yet in the cache a new one is created and stored in the cache. | ||||
* | |||||
* | |||||
* The FOP URI resolver is used to try and locate the ICC file. | * The FOP URI resolver is used to try and locate the ICC file. | ||||
* If that fails null is returned. | * If that fails null is returned. | ||||
* | |||||
* | |||||
* @param baseUri a base URI to resolve relative URIs | * @param baseUri a base URI to resolve relative URIs | ||||
* @param iccProfileSrc ICC Profile source to return a ColorSpace for | * @param iccProfileSrc ICC Profile source to return a ColorSpace for | ||||
* @return ICC ColorSpace object or null if ColorSpace could not be created | * @return ICC ColorSpace object or null if ColorSpace could not be created |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
/** Portable Document Format */ | /** Portable Document Format */ | ||||
String MIME_PDF = "application/pdf"; | String MIME_PDF = "application/pdf"; | ||||
/** PostScript */ | /** PostScript */ | ||||
String MIME_POSTSCRIPT = "application/postscript"; | String MIME_POSTSCRIPT = "application/postscript"; | ||||
/** Encapsulated PostScript (same MIME type as PostScript) */ | /** Encapsulated PostScript (same MIME type as PostScript) */ | ||||
String MIME_EPS = MIME_POSTSCRIPT; | String MIME_EPS = MIME_POSTSCRIPT; | ||||
/** HP's PCL */ | /** HP's PCL */ | ||||
String MIME_PCL = "application/x-pcl"; | String MIME_PCL = "application/x-pcl"; | ||||
/** HP's PCL (alternative MIME type) */ | /** HP's PCL (alternative MIME type) */ | ||||
String MIME_PCL_ALT = "application/vnd.hp-PCL"; | String MIME_PCL_ALT = "application/vnd.hp-PCL"; | ||||
/** IBM's AFP */ | /** IBM's AFP */ | ||||
String MIME_AFP = "application/x-afp"; | String MIME_AFP = "application/x-afp"; | ||||
/** IBM's AFP (alternative MIME type) */ | /** IBM's AFP (alternative MIME type) */ | ||||
String MIME_AFP_ALT = "application/vnd.ibm.modcap"; | String MIME_AFP_ALT = "application/vnd.ibm.modcap"; | ||||
/** Plain text */ | /** Plain text */ | ||||
String MIME_PLAIN_TEXT = "text/plain"; | String MIME_PLAIN_TEXT = "text/plain"; | ||||
/** Rich text format */ | /** Rich text format */ | ||||
String MIME_RTF = "application/rtf"; | String MIME_RTF = "application/rtf"; | ||||
/** Rich text format (alternative 1) */ | /** Rich text format (alternative 1) */ | ||||
String MIME_RTF_ALT1 = "text/richtext"; | String MIME_RTF_ALT1 = "text/richtext"; | ||||
/** Rich text format (alternative 2) */ | /** Rich text format (alternative 2) */ | ||||
String MIME_RTF_ALT2 = "text/rtf"; | String MIME_RTF_ALT2 = "text/rtf"; | ||||
/** FrameMaker's MIF */ | /** FrameMaker's MIF */ | ||||
String MIME_MIF = "application/mif"; | String MIME_MIF = "application/mif"; | ||||
/** Scalable Vector Graphics */ | /** Scalable Vector Graphics */ | ||||
String MIME_SVG = "image/svg+xml"; | String MIME_SVG = "image/svg+xml"; | ||||
/** GIF images */ | /** GIF images */ | ||||
String MIME_GIF = "image/gif"; | String MIME_GIF = "image/gif"; | ||||
/** PNG images */ | /** PNG images */ | ||||
String MIME_JPEG = "image/jpeg"; | String MIME_JPEG = "image/jpeg"; | ||||
/** TIFF images */ | /** TIFF images */ | ||||
String MIME_TIFF = "image/tiff"; | String MIME_TIFF = "image/tiff"; | ||||
/** Apache FOP's AWT preview (non-standard MIME type) */ | /** Apache FOP's AWT preview (non-standard MIME type) */ | ||||
String MIME_FOP_AWT_PREVIEW = "application/X-fop-awt-preview"; | String MIME_FOP_AWT_PREVIEW = "application/X-fop-awt-preview"; | ||||
/** Apache FOP's Direct Printing (non-standard MIME type) */ | /** Apache FOP's Direct Printing (non-standard MIME type) */ | ||||
/** Proposed but non-registered MIME type for XSL-FO */ | /** Proposed but non-registered MIME type for XSL-FO */ | ||||
String MIME_XSL_FO = "text/xsl"; | String MIME_XSL_FO = "text/xsl"; | ||||
} | } |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area; | package org.apache.fop.area; | ||||
/** | /** | ||||
*/ | */ | ||||
public static final int START_OF_DOC = 2; | public static final int START_OF_DOC = 2; | ||||
/** Indicates in what phase the item should be processed. */ | /** Indicates in what phase the item should be processed. */ | ||||
protected int whenToProcess = IMMEDIATELY; | protected int whenToProcess = IMMEDIATELY; | ||||
/** | /** | ||||
* Get an indicator of when this item should be processed | * Get an indicator of when this item should be processed | ||||
* @return int constant (IMMEDIATELY, AFTER_PAGE, START_OF_DOC, END_OF_DOC) | * @return int constant (IMMEDIATELY, AFTER_PAGE, START_OF_DOC, END_OF_DOC) |
} | } | ||||
/** | /** | ||||
* Get the inline progression dimension of the content rectangle | |||||
* Get the inline progression dimension of the content rectangle | |||||
* for this area. | * for this area. | ||||
* | |||||
* | |||||
* @return the inline progression dimension | * @return the inline progression dimension | ||||
* @see <a href="http://www.w3.org/TR/xsl/slice4.html#area-common">ipd</a> | * @see <a href="http://www.w3.org/TR/xsl/slice4.html#area-common">ipd</a> | ||||
*/ | */ | ||||
* @return the total BPD allocation for this area | * @return the total BPD allocation for this area | ||||
*/ | */ | ||||
public int getAllocBPD() { | public int getAllocBPD() { | ||||
return getSpaceBefore() + getBorderAndPaddingWidthBefore() + getBPD() | |||||
return getSpaceBefore() + getBorderAndPaddingWidthBefore() + getBPD() | |||||
+ getBorderAndPaddingWidthAfter() + getSpaceAfter(); | + getBorderAndPaddingWidthAfter() + getSpaceAfter(); | ||||
} | } | ||||
if (bps != null) { | if (bps != null) { | ||||
margin = bps.width; | margin = bps.width; | ||||
} | } | ||||
Integer padWidth = (Integer) getTrait(Trait.PADDING_BEFORE); | Integer padWidth = (Integer) getTrait(Trait.PADDING_BEFORE); | ||||
if (padWidth != null) { | if (padWidth != null) { | ||||
margin += padWidth.intValue(); | margin += padWidth.intValue(); | ||||
return margin; | return margin; | ||||
} | } | ||||
/** | /** | ||||
* Return the sum of region border- and padding-after | * Return the sum of region border- and padding-after | ||||
* | * | ||||
*/ | */ | ||||
public int getBorderAndPaddingWidthAfter() { | public int getBorderAndPaddingWidthAfter() { | ||||
int margin = 0; | int margin = 0; | ||||
BorderProps bps = (BorderProps) getTrait(Trait.BORDER_AFTER); | BorderProps bps = (BorderProps) getTrait(Trait.BORDER_AFTER); | ||||
if (bps != null) { | if (bps != null) { | ||||
margin = bps.width; | margin = bps.width; | ||||
} | } | ||||
Integer padWidth = (Integer) getTrait(Trait.PADDING_AFTER); | Integer padWidth = (Integer) getTrait(Trait.PADDING_AFTER); | ||||
if (padWidth != null) { | if (padWidth != null) { | ||||
margin += padWidth.intValue(); | margin += padWidth.intValue(); | ||||
if (bps != null) { | if (bps != null) { | ||||
margin = bps.width; | margin = bps.width; | ||||
} | } | ||||
Integer padWidth = (Integer) getTrait(Trait.PADDING_START); | Integer padWidth = (Integer) getTrait(Trait.PADDING_START); | ||||
if (padWidth != null) { | if (padWidth != null) { | ||||
margin += padWidth.intValue(); | margin += padWidth.intValue(); | ||||
if (bps != null) { | if (bps != null) { | ||||
margin = bps.width; | margin = bps.width; | ||||
} | } | ||||
Integer padWidth = (Integer) getTrait(Trait.PADDING_END); | Integer padWidth = (Integer) getTrait(Trait.PADDING_END); | ||||
if (padWidth != null) { | if (padWidth != null) { | ||||
margin += padWidth.intValue(); | margin += padWidth.intValue(); | ||||
} | } | ||||
return margin; | return margin; | ||||
} | } | ||||
/** | /** | ||||
* Returns the space after | * Returns the space after | ||||
* | * | ||||
} | } | ||||
return margin; | return margin; | ||||
} | } | ||||
/** | /** | ||||
* Returns the space start | * Returns the space start | ||||
* | * | ||||
} | } | ||||
return margin; | return margin; | ||||
} | } | ||||
/** | /** | ||||
* Returns the space end | * Returns the space end | ||||
* | * | ||||
} | } | ||||
return margin; | return margin; | ||||
} | } | ||||
/** | /** | ||||
* Add a child to this area. | * Add a child to this area. | ||||
* The default is to do nothing. Subclasses must override | * The default is to do nothing. Subclasses must override | ||||
public boolean hasTraits() { | public boolean hasTraits() { | ||||
return (this.props != null); | return (this.props != null); | ||||
} | } | ||||
/** | /** | ||||
* Get a trait from this area. | * Get a trait from this area. | ||||
* | * | ||||
public Object getTrait(Object oTraitCode) { | public Object getTrait(Object oTraitCode) { | ||||
return (props != null ? props.get(oTraitCode) : null); | return (props != null ? props.get(oTraitCode) : null); | ||||
} | } | ||||
/** | /** | ||||
* Checks whether a certain trait is set on this area. | * Checks whether a certain trait is set on this area. | ||||
* @param oTraitCode the trait key | * @param oTraitCode the trait key | ||||
public boolean hasTrait(Object oTraitCode) { | public boolean hasTrait(Object oTraitCode) { | ||||
return (getTrait(oTraitCode) != null); | return (getTrait(oTraitCode) != null); | ||||
} | } | ||||
/** | /** | ||||
* Get a boolean trait from this area. | * Get a boolean trait from this area. | ||||
* @param oTraitCode the trait key | * @param oTraitCode the trait key | ||||
+ " could not be converted to an integer"); | + " could not be converted to an integer"); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
* @return ipd and bpd of area | |||||
* @return ipd and bpd of area | |||||
* */ | * */ | ||||
public String toString() { | public String toString() { | ||||
StringBuffer sb = new StringBuffer(super.toString()); | StringBuffer sb = new StringBuffer(super.toString()); |
* Provider class for the event producer. | * Provider class for the event producer. | ||||
*/ | */ | ||||
class Provider { | class Provider { | ||||
/** | /** | ||||
* Returns an event producer. | * Returns an event producer. | ||||
* @param broadcaster the event broadcaster to use | * @param broadcaster the event broadcaster to use | ||||
* @event.severity WARN | * @event.severity WARN | ||||
*/ | */ | ||||
void unresolvedIDReference(Object source, String type, String id); | void unresolvedIDReference(Object source, String type, String id); | ||||
/** | /** | ||||
* An unresolved ID reference was encountered on a page. | * An unresolved ID reference was encountered on a page. | ||||
* @param source the event source | * @param source the event source | ||||
* @event.severity WARN | * @event.severity WARN | ||||
*/ | */ | ||||
void unresolvedIDReferenceOnPage(Object source, String page, String id); | void unresolvedIDReferenceOnPage(Object source, String page, String id); | ||||
/** | /** | ||||
* A page could not be loaded/deserialized from a file. | * A page could not be loaded/deserialized from a file. | ||||
* @param source the event source | * @param source the event source | ||||
* @event.severity ERROR | * @event.severity ERROR | ||||
*/ | */ | ||||
void pageLoadError(Object source, String page, Exception e); | void pageLoadError(Object source, String page, Exception e); | ||||
/** | /** | ||||
* A page could not be saved/serialized to a file. | * A page could not be saved/serialized to a file. | ||||
* @param source the event source | * @param source the event source | ||||
* @event.severity ERROR | * @event.severity ERROR | ||||
*/ | */ | ||||
void pageSaveError(Object source, String page, Exception e); | void pageSaveError(Object source, String page, Exception e); | ||||
/** | /** | ||||
* A page could not be rendered. | * A page could not be rendered. | ||||
* @param source the event source | * @param source the event source | ||||
* @event.severity ERROR | * @event.severity ERROR | ||||
*/ | */ | ||||
void pageRenderingError(Object source, String page, Exception e); | void pageRenderingError(Object source, String page, Exception e); | ||||
} | } |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
/** | /** | ||||
* Area tree handler for formatting objects. | * Area tree handler for formatting objects. | ||||
* | |||||
* | |||||
* Concepts: The area tree is to be as small as possible. With minimal classes | * Concepts: The area tree is to be as small as possible. With minimal classes | ||||
* and data to fully represent an area tree for formatting objects. The area | * and data to fully represent an area tree for formatting objects. The area | ||||
* tree needs to be simple to render and follow the spec closely. This area tree | * tree needs to be simple to render and follow the spec closely. This area tree | ||||
* type of renderer. | * type of renderer. | ||||
*/ | */ | ||||
public class AreaTreeHandler extends FOEventHandler { | public class AreaTreeHandler extends FOEventHandler { | ||||
private static Log log = LogFactory.getLog(AreaTreeHandler.class); | private static Log log = LogFactory.getLog(AreaTreeHandler.class); | ||||
// Recorder of debug statistics | // Recorder of debug statistics | ||||
// The fo:root node of the document | // The fo:root node of the document | ||||
private Root rootFObj; | private Root rootFObj; | ||||
// The formatting results to be handed back to the caller. | // The formatting results to be handed back to the caller. | ||||
private FormattingResults results = new FormattingResults(); | private FormattingResults results = new FormattingResults(); | ||||
/** | /** | ||||
* Constructor. | * Constructor. | ||||
* | |||||
* | |||||
* @param userAgent FOUserAgent object for process | * @param userAgent FOUserAgent object for process | ||||
* @param outputFormat the MIME type of the output format to use (ex. | * @param outputFormat the MIME type of the output format to use (ex. | ||||
* "application/pdf"). | * "application/pdf"). | ||||
} | } | ||||
idTracker = new IDTracker(); | idTracker = new IDTracker(); | ||||
if (log.isDebugEnabled()) { | if (log.isDebugEnabled()) { | ||||
statistics = new Statistics(); | statistics = new Statistics(); | ||||
} | } | ||||
/** | /** | ||||
* Sets up the AreaTreeModel instance for use by the AreaTreeHandler. | * Sets up the AreaTreeModel instance for use by the AreaTreeHandler. | ||||
* | |||||
* | |||||
* @param userAgent FOUserAgent object for process | * @param userAgent FOUserAgent object for process | ||||
* @param outputFormat the MIME type of the output format to use (ex. | * @param outputFormat the MIME type of the output format to use (ex. | ||||
* "application/pdf"). | * "application/pdf"). | ||||
/** | /** | ||||
* Get the area tree model for this area tree. | * Get the area tree model for this area tree. | ||||
* | |||||
* | |||||
* @return AreaTreeModel the model being used for this area tree | * @return AreaTreeModel the model being used for this area tree | ||||
*/ | */ | ||||
public AreaTreeModel getAreaTreeModel() { | public AreaTreeModel getAreaTreeModel() { | ||||
/** | /** | ||||
* Get the LayoutManager maker for this area tree. | * Get the LayoutManager maker for this area tree. | ||||
* | |||||
* | |||||
* @return LayoutManagerMaker the LayoutManager maker being used for this | * @return LayoutManagerMaker the LayoutManager maker being used for this | ||||
* area tree | * area tree | ||||
*/ | */ | ||||
/** | /** | ||||
* Get the IDTracker for this area tree. | * Get the IDTracker for this area tree. | ||||
* | |||||
* | |||||
* @return IDTracker used to track reference ids for items in this area tree | * @return IDTracker used to track reference ids for items in this area tree | ||||
*/ | */ | ||||
public IDTracker getIDTracker() { | public IDTracker getIDTracker() { | ||||
/** | /** | ||||
* Get information about the rendered output, like number of pages created. | * Get information about the rendered output, like number of pages created. | ||||
* | |||||
* | |||||
* @return the results structure | * @return the results structure | ||||
*/ | */ | ||||
public FormattingResults getResults() { | public FormattingResults getResults() { | ||||
/** | /** | ||||
* Prepare AreaTreeHandler for document processing This is called from | * Prepare AreaTreeHandler for document processing This is called from | ||||
* FOTreeBuilder.startDocument() | * FOTreeBuilder.startDocument() | ||||
* | |||||
* | |||||
* @throws SAXException | * @throws SAXException | ||||
* if there is an error | * if there is an error | ||||
*/ | */ | ||||
public void startPageSequence(PageSequence pageSequence) { | public void startPageSequence(PageSequence pageSequence) { | ||||
startAbstractPageSequence(pageSequence); | startAbstractPageSequence(pageSequence); | ||||
} | } | ||||
private void startAbstractPageSequence(AbstractPageSequence pageSequence) { | private void startAbstractPageSequence(AbstractPageSequence pageSequence) { | ||||
rootFObj = pageSequence.getRoot(); | rootFObj = pageSequence.getRoot(); | ||||
finishPrevPageSequence(pageSequence.getInitialPageNumber()); | finishPrevPageSequence(pageSequence.getInitialPageNumber()); | ||||
/** | /** | ||||
* End the PageSequence. The PageSequence formats Pages and adds them to the | * End the PageSequence. The PageSequence formats Pages and adds them to the | ||||
* AreaTree. The area tree then handles what happens with the pages. | * AreaTree. The area tree then handles what happens with the pages. | ||||
* | |||||
* | |||||
* @param pageSequence the page sequence ending | * @param pageSequence the page sequence ending | ||||
*/ | */ | ||||
public void endPageSequence(PageSequence pageSequence) { | public void endPageSequence(PageSequence pageSequence) { | ||||
if (statistics != null) { | if (statistics != null) { | ||||
statistics.end(); | statistics.end(); | ||||
} | } | ||||
ExternalDocumentLayoutManager edLM; | ExternalDocumentLayoutManager edLM; | ||||
edLM = getLayoutManagerMaker().makeExternalDocumentLayoutManager(this, document); | edLM = getLayoutManagerMaker().makeExternalDocumentLayoutManager(this, document); | ||||
edLM.activateLayout(); | edLM.activateLayout(); | ||||
// preserve the current PageSequenceLayoutManger for the | // preserve the current PageSequenceLayoutManger for the | ||||
// force-page-count check at the beginning of the next PageSequence | // force-page-count check at the beginning of the next PageSequence | ||||
prevPageSeqLM = edLM; | prevPageSeqLM = edLM; | ||||
} | } | ||||
/** | /** | ||||
* Called by the PageSequenceLayoutManager when it is finished with a | * Called by the PageSequenceLayoutManager when it is finished with a | ||||
* page-sequence. | * page-sequence. | ||||
* | |||||
* | |||||
* @param pageSequence the page-sequence just finished | * @param pageSequence the page-sequence just finished | ||||
* @param pageCount The number of pages generated for the page-sequence | * @param pageCount The number of pages generated for the page-sequence | ||||
*/ | */ | ||||
/** | /** | ||||
* End the document. | * End the document. | ||||
* | |||||
* | |||||
* @throws SAXException if there is some error | * @throws SAXException if there is some error | ||||
*/ | */ | ||||
public void endDocument() throws SAXException { | public void endDocument() throws SAXException { | ||||
* Add a OffDocumentItem to the area tree model. This checks if the | * Add a OffDocumentItem to the area tree model. This checks if the | ||||
* OffDocumentItem is resolvable and attempts to resolve or add the | * OffDocumentItem is resolvable and attempts to resolve or add the | ||||
* resolvable ids for later resolution. | * resolvable ids for later resolution. | ||||
* | |||||
* | |||||
* @param odi the OffDocumentItem to add. | * @param odi the OffDocumentItem to add. | ||||
*/ | */ | ||||
private void addOffDocumentItem(OffDocumentItem odi) { | private void addOffDocumentItem(OffDocumentItem odi) { | ||||
/** | /** | ||||
* Generates and returns a unique key for a page viewport. | * Generates and returns a unique key for a page viewport. | ||||
* | |||||
* | |||||
* @return the generated key. | * @return the generated key. | ||||
*/ | */ | ||||
public String generatePageViewportKey() { | public String generatePageViewportKey() { | ||||
* Tie a PageViewport with an ID found on a child area of the PV. Note that | * Tie a PageViewport with an ID found on a child area of the PV. Note that | ||||
* an area with a given ID may be on more than one PV, hence an ID may have | * an area with a given ID may be on more than one PV, hence an ID may have | ||||
* more than one PV associated with it. | * more than one PV associated with it. | ||||
* | |||||
* | |||||
* @param id the property ID of the area | * @param id the property ID of the area | ||||
* @param pv a page viewport that contains the area with this ID | * @param pv a page viewport that contains the area with this ID | ||||
* @deprecated use getIdTracker().associateIDWithPageViewport(id, pv) instead | * @deprecated use getIdTracker().associateIDWithPageViewport(id, pv) instead | ||||
* This method tie an ID to the areaTreeHandler until this one is ready to | * This method tie an ID to the areaTreeHandler until this one is ready to | ||||
* be processed. This is used in page-number-citation-last processing so we | * be processed. This is used in page-number-citation-last processing so we | ||||
* know when an id can be resolved. | * know when an id can be resolved. | ||||
* | |||||
* | |||||
* @param id the id of the object being processed | * @param id the id of the object being processed | ||||
* @deprecated use getIdTracker().signalPendingID(id) instead | * @deprecated use getIdTracker().signalPendingID(id) instead | ||||
*/ | */ | ||||
* Signals that all areas for the formatting object with the given ID have | * Signals that all areas for the formatting object with the given ID have | ||||
* been generated. This is used to determine when page-number-citation-last | * been generated. This is used to determine when page-number-citation-last | ||||
* ref-ids can be resolved. | * ref-ids can be resolved. | ||||
* | |||||
* | |||||
* @param id the id of the formatting object which was just finished | * @param id the id of the formatting object which was just finished | ||||
* @deprecated use getIdTracker().signalIDProcessed(id) instead | * @deprecated use getIdTracker().signalIDProcessed(id) instead | ||||
*/ | */ | ||||
/** | /** | ||||
* Check if an ID has already been resolved | * Check if an ID has already been resolved | ||||
* | |||||
* | |||||
* @param id the id to check | * @param id the id to check | ||||
* @return true if the ID has been resolved | * @return true if the ID has been resolved | ||||
* @deprecated use getIdTracker().alreadyResolvedID(id) instead | * @deprecated use getIdTracker().alreadyResolvedID(id) instead | ||||
/** | /** | ||||
* Tries to resolve all unresolved ID references on the given page. | * Tries to resolve all unresolved ID references on the given page. | ||||
* | |||||
* | |||||
* @param pv page viewport whose ID refs to resolve | * @param pv page viewport whose ID refs to resolve | ||||
* @deprecated use getIdTracker().tryIDResolution(pv) instead | * @deprecated use getIdTracker().tryIDResolution(pv) instead | ||||
*/ | */ | ||||
/** | /** | ||||
* Get the list of page viewports that have an area with a given id. | * Get the list of page viewports that have an area with a given id. | ||||
* | |||||
* | |||||
* @param id the id to lookup | * @param id the id to lookup | ||||
* @return the list of PageViewports | * @return the list of PageViewports | ||||
* @deprecated use getIdTracker().getPageViewportsContainingID(id) instead | * @deprecated use getIdTracker().getPageViewportsContainingID(id) instead | ||||
/** | /** | ||||
* Add an Resolvable object with an unresolved idref | * Add an Resolvable object with an unresolved idref | ||||
* | |||||
* | |||||
* @param idref the idref whose target id has not yet been located | * @param idref the idref whose target id has not yet been located | ||||
* @param res the Resolvable object needing the idref to be resolved | * @param res the Resolvable object needing the idref to be resolved | ||||
* @deprecated use getIdTracker().addUnresolvedIDRef(idref, res) instead | * @deprecated use getIdTracker().addUnresolvedIDRef(idref, res) instead | ||||
public void addUnresolvedIDRef(String idref, Resolvable res) { | public void addUnresolvedIDRef(String idref, Resolvable res) { | ||||
idTracker.addUnresolvedIDRef(idref, res); | idTracker.addUnresolvedIDRef(idref, res); | ||||
} | } | ||||
private class Statistics { | private class Statistics { | ||||
// for statistics gathering | // for statistics gathering | ||||
private Runtime runtime; | private Runtime runtime; |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area; | package org.apache.fop.area; | ||||
// Java | // Java | ||||
} | } | ||||
/** | /** | ||||
* Handle an OffDocumentItem | |||||
* Handle an OffDocumentItem | |||||
* @param ext the extension to handle | * @param ext the extension to handle | ||||
*/ | */ | ||||
public void handleOffDocumentItem(OffDocumentItem ext) {}; | public void handleOffDocumentItem(OffDocumentItem ext) {}; | ||||
public PageSequence getCurrentPageSequence() { | public PageSequence getCurrentPageSequence() { | ||||
return this.currentPageSequence; | return this.currentPageSequence; | ||||
} | } | ||||
/** | /** | ||||
* Get the page sequence count. | * Get the page sequence count. | ||||
* @return the number of page sequences in the document. | * @return the number of page sequences in the document. |
/** Foreign attributes */ | /** Foreign attributes */ | ||||
protected Map foreignAttributes = null; | protected Map foreignAttributes = null; | ||||
/** | /** | ||||
* Sets a foreign attribute. | * Sets a foreign attribute. | ||||
* @param name the qualified name of the attribute | * @param name the qualified name of the attribute | ||||
} | } | ||||
this.foreignAttributes.put(name, value); | this.foreignAttributes.put(name, value); | ||||
} | } | ||||
/** | /** | ||||
* Set foreign attributes from a Map. | * Set foreign attributes from a Map. | ||||
* @param atts a Map with attributes (keys: QName, values: String) | * @param atts a Map with attributes (keys: QName, values: String) | ||||
while (iter.hasNext()) { | while (iter.hasNext()) { | ||||
Map.Entry entry = (Map.Entry)iter.next(); | Map.Entry entry = (Map.Entry)iter.next(); | ||||
String value = (String)entry.getValue(); | String value = (String)entry.getValue(); | ||||
//The casting is only to ensure type safety (too bad we can't use generics, yet) | |||||
//The casting is only to ensure type safety (too bad we can't use generics, yet) | |||||
setForeignAttribute((QName)entry.getKey(), value); | setForeignAttribute((QName)entry.getKey(), value); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Returns the value of a foreign attribute on the area. | * Returns the value of a foreign attribute on the area. | ||||
* @param name the qualified name of the attribute | * @param name the qualified name of the attribute | ||||
return null; | return null; | ||||
} | } | ||||
} | } | ||||
/** @return the foreign attributes associated with this area */ | /** @return the foreign attributes associated with this area */ | ||||
public Map getForeignAttributes() { | public Map getForeignAttributes() { | ||||
if (this.foreignAttributes != null) { | if (this.foreignAttributes != null) { | ||||
return Collections.EMPTY_MAP; | return Collections.EMPTY_MAP; | ||||
} | } | ||||
} | } | ||||
} | } |
/** Logger instance */ | /** Logger instance */ | ||||
protected static Log log = LogFactory.getLog(AreaTreeParser.class); | protected static Log log = LogFactory.getLog(AreaTreeParser.class); | ||||
private static SAXTransformerFactory tFactory | |||||
private static SAXTransformerFactory tFactory | |||||
= (SAXTransformerFactory)SAXTransformerFactory.newInstance(); | = (SAXTransformerFactory)SAXTransformerFactory.newInstance(); | ||||
/** | /** | ||||
* @param userAgent the user agent | * @param userAgent the user agent | ||||
* @throws TransformerException if an error occurs while parsing the area tree XML | * @throws TransformerException if an error occurs while parsing the area tree XML | ||||
*/ | */ | ||||
public void parse(Source src, AreaTreeModel treeModel, FOUserAgent userAgent) | |||||
public void parse(Source src, AreaTreeModel treeModel, FOUserAgent userAgent) | |||||
throws TransformerException { | throws TransformerException { | ||||
Transformer transformer = tFactory.newTransformer(); | Transformer transformer = tFactory.newTransformer(); | ||||
transformer.setErrorListener(new DefaultErrorListener(log)); | transformer.setErrorListener(new DefaultErrorListener(log)); | ||||
SAXResult res = new SAXResult(getContentHandler(treeModel, userAgent)); | SAXResult res = new SAXResult(getContentHandler(treeModel, userAgent)); | ||||
transformer.transform(src, res); | transformer.transform(src, res); | ||||
private CharBuffer content = CharBuffer.allocate(64); | private CharBuffer content = CharBuffer.allocate(64); | ||||
private boolean ignoreCharacters = true; | private boolean ignoreCharacters = true; | ||||
private PageViewport currentPageViewport; | private PageViewport currentPageViewport; | ||||
private Map pageViewportsByKey = new java.util.HashMap(); | private Map pageViewportsByKey = new java.util.HashMap(); | ||||
// set of "ID firsts" that have already been assigned to a PV: | // set of "ID firsts" that have already been assigned to a PV: | ||||
public void endElement() { | public void endElement() { | ||||
//nop | //nop | ||||
} | } | ||||
public boolean ignoreCharacters() { | public boolean ignoreCharacters() { | ||||
return true; | return true; | ||||
} | } | ||||
currentPageViewport = null; | currentPageViewport = null; | ||||
} | } | ||||
} | } | ||||
private class RegionViewportMaker extends AbstractMaker { | private class RegionViewportMaker extends AbstractMaker { | ||||
public void startElement(Attributes attributes) { | public void startElement(Attributes attributes) { | ||||
setTraits(attributes, rv, SUBSET_COLOR); | setTraits(attributes, rv, SUBSET_COLOR); | ||||
areaStack.push(rv); | areaStack.push(rv); | ||||
} | } | ||||
public void endElement() { | public void endElement() { | ||||
assertObjectOfClass(areaStack.pop(), RegionViewport.class); | assertObjectOfClass(areaStack.pop(), RegionViewport.class); | ||||
} | |||||
} | |||||
} | } | ||||
private class RegionBeforeMaker extends AbstractMaker { | private class RegionBeforeMaker extends AbstractMaker { | ||||
public void startElement(Attributes attributes) { | public void startElement(Attributes attributes) { | ||||
pushNewRegionReference(attributes, Constants.FO_REGION_BEFORE); | pushNewRegionReference(attributes, Constants.FO_REGION_BEFORE); | ||||
} | } | ||||
public void endElement() { | public void endElement() { | ||||
assertObjectOfClass(areaStack.pop(), RegionReference.class); | assertObjectOfClass(areaStack.pop(), RegionReference.class); | ||||
} | } | ||||
assertObjectOfClass(areaStack.pop(), RegionReference.class); | assertObjectOfClass(areaStack.pop(), RegionReference.class); | ||||
} | } | ||||
} | } | ||||
private class RegionEndMaker extends AbstractMaker { | private class RegionEndMaker extends AbstractMaker { | ||||
public void startElement(Attributes attributes) { | public void startElement(Attributes attributes) { | ||||
int columnCount = getAttributeAsInteger(attributes, "columnCount", 1); | int columnCount = getAttributeAsInteger(attributes, "columnCount", 1); | ||||
int columnGap = getAttributeAsInteger(attributes, "columnGap", 0); | int columnGap = getAttributeAsInteger(attributes, "columnGap", 0); | ||||
RegionViewport rv = getCurrentRegionViewport(); | RegionViewport rv = getCurrentRegionViewport(); | ||||
body = new BodyRegion(Constants.FO_REGION_BODY, | |||||
body = new BodyRegion(Constants.FO_REGION_BODY, | |||||
regionName, rv, columnCount, columnGap); | regionName, rv, columnCount, columnGap); | ||||
transferForeignObjects(attributes, body); | transferForeignObjects(attributes, body); | ||||
body.setCTM(getAttributeAsCTM(attributes, "ctm")); | body.setCTM(getAttributeAsCTM(attributes, "ctm")); | ||||
Constants.FO_REGION_BODY, rv); | Constants.FO_REGION_BODY, rv); | ||||
areaStack.push(body); | areaStack.push(body); | ||||
} | } | ||||
public void endElement() { | public void endElement() { | ||||
assertObjectOfClass(areaStack.pop(), BodyRegion.class); | assertObjectOfClass(areaStack.pop(), BodyRegion.class); | ||||
} | |||||
} | |||||
} | } | ||||
private class FlowMaker extends AbstractMaker { | private class FlowMaker extends AbstractMaker { | ||||
setAreaAttributes(attributes, flow); | setAreaAttributes(attributes, flow); | ||||
areaStack.push(flow); | areaStack.push(flow); | ||||
} | } | ||||
public void endElement() { | public void endElement() { | ||||
assertObjectOfClass(areaStack.pop(), NormalFlow.class); | assertObjectOfClass(areaStack.pop(), NormalFlow.class); | ||||
} | |||||
} | |||||
} | } | ||||
private class MainReferenceMaker extends AbstractMaker { | private class MainReferenceMaker extends AbstractMaker { | ||||
public void startElement(Attributes attributes) { | public void startElement(Attributes attributes) { | ||||
int ipd = getAttributeAsInteger(attributes, "ipd", 0); | int ipd = getAttributeAsInteger(attributes, "ipd", 0); | ||||
int columnCount = getAttributeAsInteger(attributes, "columnCount", 1); | int columnCount = getAttributeAsInteger(attributes, "columnCount", 1); | ||||
BodyRegion body = getCurrentBodyRegion(); | BodyRegion body = getCurrentBodyRegion(); | ||||
Span span = new Span(columnCount, | |||||
Span span = new Span(columnCount, | |||||
body.getColumnGap(), ipd); | body.getColumnGap(), ipd); | ||||
transferForeignObjects(attributes, span); | transferForeignObjects(attributes, span); | ||||
setAreaAttributes(attributes, span); | setAreaAttributes(attributes, span); | ||||
fn.setTop(getAttributeAsInteger(attributes, "top-offset", 0)); | fn.setTop(getAttributeAsInteger(attributes, "top-offset", 0)); | ||||
areaStack.push(fn); | areaStack.push(fn); | ||||
} | } | ||||
public void endElement() { | public void endElement() { | ||||
assertObjectOfClass(areaStack.pop(), Footnote.class); | assertObjectOfClass(areaStack.pop(), Footnote.class); | ||||
} | |||||
} | |||||
} | } | ||||
private class BeforeFloatMaker extends AbstractMaker { | private class BeforeFloatMaker extends AbstractMaker { | ||||
public void startElement(Attributes attributes) { | public void startElement(Attributes attributes) { | ||||
BeforeFloat bf = getCurrentBodyRegion().getBeforeFloat(); | |||||
BeforeFloat bf = getCurrentBodyRegion().getBeforeFloat(); | |||||
transferForeignObjects(attributes, bf); | transferForeignObjects(attributes, bf); | ||||
areaStack.push(bf); | areaStack.push(bf); | ||||
} | } | ||||
public void endElement() { | public void endElement() { | ||||
assertObjectOfClass(areaStack.pop(), BeforeFloat.class); | assertObjectOfClass(areaStack.pop(), BeforeFloat.class); | ||||
} | } | ||||
parent.addChildArea(block); | parent.addChildArea(block); | ||||
areaStack.push(block); | areaStack.push(block); | ||||
} | } | ||||
public void endElement() { | public void endElement() { | ||||
assertObjectOfClass(areaStack.pop(), Block.class); | assertObjectOfClass(areaStack.pop(), Block.class); | ||||
} | } | ||||
parent.addChildArea(ibp); | parent.addChildArea(ibp); | ||||
areaStack.push(ibp); | areaStack.push(ibp); | ||||
} | } | ||||
public void endElement() { | public void endElement() { | ||||
assertObjectOfClass(areaStack.pop(), InlineBlockParent.class); | assertObjectOfClass(areaStack.pop(), InlineBlockParent.class); | ||||
} | } | ||||
text.setOffset(getAttributeAsInteger(attributes, "offset", 0)); | text.setOffset(getAttributeAsInteger(attributes, "offset", 0)); | ||||
text.setTextLetterSpaceAdjust(getAttributeAsInteger(attributes, | text.setTextLetterSpaceAdjust(getAttributeAsInteger(attributes, | ||||
"tlsadjust", 0)); | "tlsadjust", 0)); | ||||
text.setTextWordSpaceAdjust(getAttributeAsInteger(attributes, | |||||
text.setTextWordSpaceAdjust(getAttributeAsInteger(attributes, | |||||
"twsadjust", 0)); | "twsadjust", 0)); | ||||
Area parent = (Area)areaStack.peek(); | Area parent = (Area)areaStack.peek(); | ||||
parent.addChildArea(text); | parent.addChildArea(text); | ||||
areaStack.push(text); | areaStack.push(text); | ||||
} | } | ||||
public void endElement() { | public void endElement() { | ||||
assertObjectOfClass(areaStack.pop(), TextArea.class); | assertObjectOfClass(areaStack.pop(), TextArea.class); | ||||
} | } | ||||
public void endElement() { | public void endElement() { | ||||
int offset = getAttributeAsInteger(lastAttributes, "offset", 0); | int offset = getAttributeAsInteger(lastAttributes, "offset", 0); | ||||
int[] letterAdjust | |||||
int[] letterAdjust | |||||
= ConversionUtils.toIntArray( | = ConversionUtils.toIntArray( | ||||
lastAttributes.getValue("letter-adjust"), "\\s"); | lastAttributes.getValue("letter-adjust"), "\\s"); | ||||
content.flip(); | content.flip(); | ||||
word.setParentArea(text); | word.setParentArea(text); | ||||
text.addChildArea(word); | text.addChildArea(word); | ||||
} | } | ||||
public boolean ignoreCharacters() { | public boolean ignoreCharacters() { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
private class SpaceMaker extends AbstractMaker { | private class SpaceMaker extends AbstractMaker { | ||||
public void endElement() { | public void endElement() { | ||||
int offset = getAttributeAsInteger(lastAttributes, "offset", 0); | int offset = getAttributeAsInteger(lastAttributes, "offset", 0); | ||||
//TODO the isAdjustable parameter is currently not used/implemented | //TODO the isAdjustable parameter is currently not used/implemented | ||||
parent.addChildArea(space); | parent.addChildArea(space); | ||||
} | } | ||||
} | } | ||||
public boolean ignoreCharacters() { | public boolean ignoreCharacters() { | ||||
return false; | return false; | ||||
} | } | ||||
parent.addChildArea(viewport); | parent.addChildArea(viewport); | ||||
areaStack.push(viewport); | areaStack.push(viewport); | ||||
} | } | ||||
public void endElement() { | public void endElement() { | ||||
assertObjectOfClass(areaStack.pop(), Viewport.class); | assertObjectOfClass(areaStack.pop(), Viewport.class); | ||||
} | } | ||||
} | } | ||||
private class ImageMaker extends AbstractMaker { | private class ImageMaker extends AbstractMaker { | ||||
public void startElement(Attributes attributes) { | public void startElement(Attributes attributes) { | ||||
getCurrentViewport().setContent(image); | getCurrentViewport().setContent(image); | ||||
} | } | ||||
} | } | ||||
private class ForeignObjectMaker extends AbstractMaker { | private class ForeignObjectMaker extends AbstractMaker { | ||||
public void startElement(Attributes attributes) throws SAXException { | public void startElement(Attributes attributes) throws SAXException { | ||||
String ns = attributes.getValue("ns"); | String ns = attributes.getValue("ns"); | ||||
domImplementation | |||||
domImplementation | |||||
= elementMappingRegistry.getDOMImplementationForNamespace(ns); | = elementMappingRegistry.getDOMImplementationForNamespace(ns); | ||||
if (domImplementation == null) { | if (domImplementation == null) { | ||||
throw new SAXException("No DOMImplementation could be" | throw new SAXException("No DOMImplementation could be" | ||||
private void assertObjectOfClass(Object obj, Class clazz) { | private void assertObjectOfClass(Object obj, Class clazz) { | ||||
if (!clazz.isInstance(obj)) { | if (!clazz.isInstance(obj)) { | ||||
throw new IllegalStateException("Object is not an instance of " | |||||
throw new IllegalStateException("Object is not an instance of " | |||||
+ clazz.getName() + " but of " + obj.getClass().getName()); | + clazz.getName() + " but of " + obj.getClass().getName()); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Handles objects created by "sub-parsers" that implement the ObjectSource interface. | * Handles objects created by "sub-parsers" that implement the ObjectSource interface. | ||||
* An example of object handled here are ExtensionAttachments. | * An example of object handled here are ExtensionAttachments. | ||||
area.setIPD(Integer.parseInt(attributes.getValue("ipd"))); | area.setIPD(Integer.parseInt(attributes.getValue("ipd"))); | ||||
area.setBPD(Integer.parseInt(attributes.getValue("bpd"))); | area.setBPD(Integer.parseInt(attributes.getValue("bpd"))); | ||||
} | } | ||||
private static final Object[] SUBSET_COMMON = new Object[] { | private static final Object[] SUBSET_COMMON = new Object[] { | ||||
Trait.PROD_ID}; | Trait.PROD_ID}; | ||||
private static final Object[] SUBSET_LINK = new Object[] { | private static final Object[] SUBSET_LINK = new Object[] { | ||||
} | } | ||||
} | } | ||||
private static int getAttributeAsInteger(Attributes attributes, String name, | |||||
private static int getAttributeAsInteger(Attributes attributes, String name, | |||||
int defaultValue) { | int defaultValue) { | ||||
String s = attributes.getValue(name); | String s = attributes.getValue(name); | ||||
if (s == null) { | if (s == null) { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public void characters(char[] ch, int start, int length) throws SAXException { | public void characters(char[] ch, int start, int length) throws SAXException { | ||||
if (delegate != null) { | if (delegate != null) { | ||||
int maxLength = this.content.capacity() - this.content.position(); | int maxLength = this.content.capacity() - this.content.position(); | ||||
if (maxLength < length) { | if (maxLength < length) { | ||||
// allocate a larger buffer and transfer content | // allocate a larger buffer and transfer content | ||||
CharBuffer newContent | |||||
CharBuffer newContent | |||||
= CharBuffer.allocate(this.content.position() + length); | = CharBuffer.allocate(this.content.position() + length); | ||||
this.content.flip(); | this.content.flip(); | ||||
newContent.put(this.content); | newContent.put(this.content); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area; | package org.apache.fop.area; | ||||
/** | /** |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area; | package org.apache.fop.area; | ||||
private int positioning = STACK; | private int positioning = STACK; | ||||
protected transient boolean allowBPDUpdate = true; | protected transient boolean allowBPDUpdate = true; | ||||
// a block with may contain the dominant styling info in | // a block with may contain the dominant styling info in | ||||
// terms of most lines or blocks with info | // terms of most lines or blocks with info | ||||
public boolean isStacked() { | public boolean isStacked() { | ||||
return (getPositioning() == Block.STACK || getPositioning() == Block.RELATIVE); | return (getPositioning() == Block.STACK || getPositioning() == Block.RELATIVE); | ||||
} | } | ||||
/** | /** | ||||
* @return the start-indent trait | * @return the start-indent trait | ||||
*/ | */ |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area; | package org.apache.fop.area; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
} | } | ||||
children.add(childArea); | children.add(childArea); | ||||
} | } | ||||
/** | /** | ||||
* Add the block area to this block parent. | * Add the block area to this block parent. | ||||
* | * |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area; | package org.apache.fop.area; | ||||
/** | /** |
* @param columnCount the number of columns | * @param columnCount the number of columns | ||||
* @param columnGap the gap between columns | * @param columnGap the gap between columns | ||||
*/ | */ | ||||
public BodyRegion(int regionClass, String regionName, RegionViewport parent, | |||||
public BodyRegion(int regionClass, String regionName, RegionViewport parent, | |||||
int columnCount, int columnGap) { | int columnCount, int columnGap) { | ||||
super(regionClass, regionName, parent); | super(regionClass, regionName, parent); | ||||
this.columnCount = columnCount; | this.columnCount = columnCount; | ||||
public int getColumnGap() { | public int getColumnGap() { | ||||
return this.columnGap; | return this.columnGap; | ||||
} | } | ||||
/** | /** | ||||
* Get the main reference area. | * Get the main reference area. | ||||
* | * | ||||
} | } | ||||
return getBPD() - usedBPD; | return getBPD() - usedBPD; | ||||
} | } | ||||
/** | /** | ||||
* Clone this object. | * Clone this object. | ||||
* | * | ||||
* @return a shallow copy of this object | * @return a shallow copy of this object | ||||
*/ | */ | ||||
public Object clone() { | public Object clone() { | ||||
BodyRegion br = new BodyRegion(getRegionClass(), getRegionName(), regionViewport, | |||||
BodyRegion br = new BodyRegion(getRegionClass(), getRegionName(), regionViewport, | |||||
getColumnCount(), getColumnGap()); | getColumnCount(), getColumnGap()); | ||||
br.setCTM(getCTM()); | br.setCTM(getCTM()); | ||||
br.setIPD(getIPD()); | br.setIPD(getIPD()); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area; | package org.apache.fop.area; | ||||
import java.util.Collection; | import java.util.Collection; | ||||
* child bookmark-items under it. | * child bookmark-items under it. | ||||
*/ | */ | ||||
public class BookmarkData extends AbstractOffDocumentItem implements Resolvable { | public class BookmarkData extends AbstractOffDocumentItem implements Resolvable { | ||||
private List subData = new java.util.ArrayList(); | private List subData = new java.util.ArrayList(); | ||||
// bookmark-title for this fo:bookmark | // bookmark-title for this fo:bookmark | ||||
} | } | ||||
refs.add(bd); | refs.add(bd); | ||||
} | } | ||||
/** | /** | ||||
* Create a new bookmark data root object. | * Create a new bookmark data root object. | ||||
* This constructor is called by the AreaTreeParser when the | * This constructor is called by the AreaTreeParser when the |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
switch (wm) { | switch (wm) { | ||||
case Constants.EN_LR_TB: | case Constants.EN_LR_TB: | ||||
return new CTM(CTM_LRTB); | return new CTM(CTM_LRTB); | ||||
case Constants.EN_RL_TB: | |||||
case Constants.EN_RL_TB: | |||||
wmctm = new CTM(CTM_RLTB); | wmctm = new CTM(CTM_RLTB); | ||||
wmctm.e = ipd; | wmctm.e = ipd; | ||||
return wmctm; | return wmctm; | ||||
public AffineTransform toAffineTransform() { | public AffineTransform toAffineTransform() { | ||||
return new AffineTransform(toArray()); | return new AffineTransform(toArray()); | ||||
} | } | ||||
/** | /** | ||||
* Construct a coordinate transformation matrix (CTM). | * Construct a coordinate transformation matrix (CTM). | ||||
* @param absRefOrient absolute reference orientation | * @param absRefOrient absolute reference orientation |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area; | package org.apache.fop.area; | ||||
import java.io.BufferedInputStream; | import java.io.BufferedInputStream; | ||||
/** Base directory to save temporary file in, typically points to the user's temp dir. */ | /** Base directory to save temporary file in, typically points to the user's temp dir. */ | ||||
protected File baseDir; | protected File baseDir; | ||||
/** | /** | ||||
* Main Constructor | * Main Constructor | ||||
* @param userAgent FOUserAgent object for process | * @param userAgent FOUserAgent object for process | ||||
* @param stream OutputStream | * @param stream OutputStream | ||||
* @throws FOPException if the renderer cannot be properly initialized | * @throws FOPException if the renderer cannot be properly initialized | ||||
*/ | */ | ||||
public CachedRenderPagesModel (FOUserAgent userAgent, String outputFormat, | |||||
public CachedRenderPagesModel (FOUserAgent userAgent, String outputFormat, | |||||
FontInfo fontInfo, OutputStream stream) throws FOPException { | FontInfo fontInfo, OutputStream stream) throws FOPException { | ||||
super(userAgent, outputFormat, fontInfo, stream); | super(userAgent, outputFormat, fontInfo, stream); | ||||
this.baseDir = new File(System.getProperty("java.io.tmpdir")); | this.baseDir = new File(System.getProperty("java.io.tmpdir")); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | |||||
* {@inheritDoc} | |||||
*/ | */ | ||||
protected boolean checkPreparedPages(PageViewport newpage, boolean renderUnresolved) { | protected boolean checkPreparedPages(PageViewport newpage, boolean renderUnresolved) { | ||||
for (Iterator iter = prepared.iterator(); iter.hasNext();) { | for (Iterator iter = prepared.iterator(); iter.hasNext();) { |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
this.idRef = idRef; | this.idRef = idRef; | ||||
this.idRefs = new String[] {idRef}; | this.idRefs = new String[] {idRef}; | ||||
} | } | ||||
/** | /** | ||||
* Get the idref for this destination | * Get the idref for this destination | ||||
* | * |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area; | package org.apache.fop.area; | ||||
// may combine with before float into a conditional area | // may combine with before float into a conditional area |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
* on a PageViewport level. | * on a PageViewport level. | ||||
*/ | */ | ||||
public class IDTracker { | public class IDTracker { | ||||
private static Log log = LogFactory.getLog(IDTracker.class); | private static Log log = LogFactory.getLog(IDTracker.class); | ||||
// HashMap of ID's whose area is located on one or more consecutive | // HashMap of ID's whose area is located on one or more consecutive | ||||
private Set unfinishedIDs = new HashSet(); | private Set unfinishedIDs = new HashSet(); | ||||
private Set alreadyResolvedIDs = new HashSet(); | private Set alreadyResolvedIDs = new HashSet(); | ||||
/** | /** | ||||
* Tie a PageViewport with an ID found on a child area of the PV. Note that | * Tie a PageViewport with an ID found on a child area of the PV. Note that | ||||
* an area with a given ID may be on more than one PV, hence an ID may have | * an area with a given ID may be on more than one PV, hence an ID may have | ||||
* more than one PV associated with it. | * more than one PV associated with it. | ||||
* | |||||
* | |||||
* @param id the property ID of the area | * @param id the property ID of the area | ||||
* @param pv a page viewport that contains the area with this ID | * @param pv a page viewport that contains the area with this ID | ||||
*/ | */ | ||||
tryIDResolution(id, pv, pvList); | tryIDResolution(id, pv, pvList); | ||||
} | } | ||||
} else { | } else { | ||||
/* TODO: The check is a quick-fix to avoid a waste | |||||
/* TODO: The check is a quick-fix to avoid a waste | |||||
* when adding inline-ids to the page */ | * when adding inline-ids to the page */ | ||||
if (!pvList.contains(pv)) { | if (!pvList.contains(pv)) { | ||||
pvList.add(pv); | pvList.add(pv); | ||||
* This method tie an ID to the areaTreeHandler until this one is ready to | * This method tie an ID to the areaTreeHandler until this one is ready to | ||||
* be processed. This is used in page-number-citation-last processing so we | * be processed. This is used in page-number-citation-last processing so we | ||||
* know when an id can be resolved. | * know when an id can be resolved. | ||||
* | |||||
* | |||||
* @param id the id of the object being processed | * @param id the id of the object being processed | ||||
*/ | */ | ||||
public void signalPendingID(String id) { | public void signalPendingID(String id) { | ||||
* Signals that all areas for the formatting object with the given ID have | * Signals that all areas for the formatting object with the given ID have | ||||
* been generated. This is used to determine when page-number-citation-last | * been generated. This is used to determine when page-number-citation-last | ||||
* ref-ids can be resolved. | * ref-ids can be resolved. | ||||
* | |||||
* | |||||
* @param id the id of the formatting object which was just finished | * @param id the id of the formatting object which was just finished | ||||
*/ | */ | ||||
public void signalIDProcessed(String id) { | public void signalIDProcessed(String id) { | ||||
unresolvedIDRefs.remove(id); | unresolvedIDRefs.remove(id); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Check if an ID has already been resolved | * Check if an ID has already been resolved | ||||
* | |||||
* | |||||
* @param id the id to check | * @param id the id to check | ||||
* @return true if the ID has been resolved | * @return true if the ID has been resolved | ||||
*/ | */ | ||||
public boolean alreadyResolvedID(String id) { | public boolean alreadyResolvedID(String id) { | ||||
return (alreadyResolvedIDs.contains(id)); | return (alreadyResolvedIDs.contains(id)); | ||||
} | } | ||||
/** | /** | ||||
* Tries to resolve all unresolved ID references on the given page. | * Tries to resolve all unresolved ID references on the given page. | ||||
* | |||||
* | |||||
* @param id ID to resolve | * @param id ID to resolve | ||||
* @param pv page viewport whose ID refs to resolve | * @param pv page viewport whose ID refs to resolve | ||||
* @param pvList of PageViewports | * @param pvList of PageViewports | ||||
/** | /** | ||||
* Tries to resolve all unresolved ID references on the given page. | * Tries to resolve all unresolved ID references on the given page. | ||||
* | |||||
* | |||||
* @param pv page viewport whose ID refs to resolve | * @param pv page viewport whose ID refs to resolve | ||||
*/ | */ | ||||
public void tryIDResolution(PageViewport pv) { | public void tryIDResolution(PageViewport pv) { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Get the list of page viewports that have an area with a given id. | * Get the list of page viewports that have an area with a given id. | ||||
* | |||||
* | |||||
* @param id the id to lookup | * @param id the id to lookup | ||||
* @return the list of PageViewports | * @return the list of PageViewports | ||||
*/ | */ | ||||
public List getPageViewportsContainingID(String id) { | public List getPageViewportsContainingID(String id) { | ||||
return (List) idLocations.get(id); | return (List) idLocations.get(id); | ||||
} | } | ||||
/** | /** | ||||
* Add an Resolvable object with an unresolved idref | * Add an Resolvable object with an unresolved idref | ||||
* | |||||
* | |||||
* @param idref the idref whose target id has not yet been located | * @param idref the idref whose target id has not yet been located | ||||
* @param res the Resolvable object needing the idref to be resolved | * @param res the Resolvable object needing the idref to be resolved | ||||
*/ | */ | ||||
} | } | ||||
// add Resolvable object to this HashSet | // add Resolvable object to this HashSet | ||||
todo.add(res); | todo.add(res); | ||||
} | |||||
} | |||||
} | } |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area; | package org.apache.fop.area; | ||||
import org.apache.fop.area.inline.InlineArea; | import org.apache.fop.area.inline.InlineArea; | ||||
private int availableShrink; | private int availableShrink; | ||||
private double variationFactor; | private double variationFactor; | ||||
private boolean bAddedToAreaTree; | private boolean bAddedToAreaTree; | ||||
private LineAdjustingInfo(int alignment, int diff, | private LineAdjustingInfo(int alignment, int diff, | ||||
int stretch, int shrink) { | int stretch, int shrink) { | ||||
lineAlignment = alignment; | lineAlignment = alignment; | ||||
bAddedToAreaTree = false; | bAddedToAreaTree = false; | ||||
} | } | ||||
} | } | ||||
private LineAdjustingInfo adjustingInfo = null; | private LineAdjustingInfo adjustingInfo = null; | ||||
// this class can contain the dominant char styling info | // this class can contain the dominant char styling info | ||||
* default constructor: | * default constructor: | ||||
* nothing to do | * nothing to do | ||||
*/ | */ | ||||
public LineArea() { | |||||
public LineArea() { | |||||
} | } | ||||
/** | /** | ||||
setIPD(ipd); | setIPD(ipd); | ||||
setBPD(bpd); | setBPD(bpd); | ||||
} | } | ||||
/** | /** | ||||
* receive notification about the ipd variation of a descendant area | * receive notification about the ipd variation of a descendant area | ||||
* and perform the needed adjustment, according to the alignment; | * and perform the needed adjustment, according to the alignment; | ||||
* <li>left-aligned text needs no adjustement;</li> | * <li>left-aligned text needs no adjustement;</li> | ||||
* <li>right-aligned text and centered text are handled locally, | * <li>right-aligned text and centered text are handled locally, | ||||
* adjusting the indent of this LineArea;</li> | * adjusting the indent of this LineArea;</li> | ||||
* <li>justified text requires a more complex adjustment, as the | |||||
* <li>justified text requires a more complex adjustment, as the | |||||
* variation factor computed on the basis of the total | * variation factor computed on the basis of the total | ||||
* stretch and shrink of the line must be applied in every | * stretch and shrink of the line must be applied in every | ||||
* descendant leaf areas (text areas and leader areas).</li> | |||||
* descendant leaf areas (text areas and leader areas).</li> | |||||
* </ul> | * </ul> | ||||
* @param ipdVariation the difference between old and new ipd | |||||
* @param ipdVariation the difference between old and new ipd | |||||
*/ | */ | ||||
public void handleIPDVariation(int ipdVariation) { | public void handleIPDVariation(int ipdVariation) { | ||||
switch (adjustingInfo.lineAlignment) { | switch (adjustingInfo.lineAlignment) { | ||||
throw new RuntimeException(); | throw new RuntimeException(); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* apply the variation factor to all descendant areas | * apply the variation factor to all descendant areas | ||||
* and destroy the AdjustingInfo object if there are | * and destroy the AdjustingInfo object if there are |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
/** | /** | ||||
* Resolve by adding an internal link to the first PageViewport in the list. | * Resolve by adding an internal link to the first PageViewport in the list. | ||||
* | * | ||||
* {@inheritDoc} | |||||
* {@inheritDoc} | |||||
*/ | */ | ||||
public void resolveIDRef(String id, List pages) { | public void resolveIDRef(String id, List pages) { | ||||
resolveIDRef(id, (PageViewport)pages.get(0)); | resolveIDRef(id, (PageViewport)pages.get(0)); |
this.parent = parent; | this.parent = parent; | ||||
addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE); | addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE); | ||||
} | } | ||||
/** | /** | ||||
* Add a span area to this area. | * Add a span area to this area. | ||||
* | * | ||||
RegionViewport rv = parent.getRegionViewport(); | RegionViewport rv = parent.getRegionViewport(); | ||||
int ipdWidth = (int) parent.getIPD() | int ipdWidth = (int) parent.getIPD() | ||||
- rv.getBorderAndPaddingWidthStart() - rv.getBorderAndPaddingWidthEnd(); | - rv.getBorderAndPaddingWidthStart() - rv.getBorderAndPaddingWidthEnd(); | ||||
Span newSpan = new Span(((spanAll) ? 1 : getColumnCount()), | |||||
Span newSpan = new Span(((spanAll) ? 1 : getColumnCount()), | |||||
getColumnGap(), ipdWidth); | getColumnGap(), ipdWidth); | ||||
spanAreas.add(newSpan); | spanAreas.add(newSpan); | ||||
return getCurrentSpan(); | |||||
return getCurrentSpan(); | |||||
} | } | ||||
/** | /** |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area; | package org.apache.fop.area; | ||||
/** | /** | ||||
addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE); | addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE); | ||||
setIPD(ipd); | setIPD(ipd); | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public void addBlock(Block block) { | public void addBlock(Block block) { | ||||
super.addBlock(block); | super.addBlock(block); |
public class OffDocumentExtensionAttachment implements OffDocumentItem { | public class OffDocumentExtensionAttachment implements OffDocumentItem { | ||||
private ExtensionAttachment attachment; | private ExtensionAttachment attachment; | ||||
/** | /** | ||||
* Main constructor | * Main constructor | ||||
* @param attachment the extension attachment to wrap. | * @param attachment the extension attachment to wrap. | ||||
public OffDocumentExtensionAttachment(ExtensionAttachment attachment) { | public OffDocumentExtensionAttachment(ExtensionAttachment attachment) { | ||||
this.attachment = attachment; | this.attachment = attachment; | ||||
} | } | ||||
/** @return the extension attachment. */ | /** @return the extension attachment. */ | ||||
public ExtensionAttachment getAttachment() { | public ExtensionAttachment getAttachment() { | ||||
return this.attachment; | return this.attachment; | ||||
public String getName() { | public String getName() { | ||||
return attachment.getCategory(); | return attachment.getCategory(); | ||||
} | } | ||||
} | } |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area; | package org.apache.fop.area; | ||||
/** | /** | ||||
*/ | */ | ||||
int END_OF_DOC = 2; | int END_OF_DOC = 2; | ||||
/** | /** | ||||
* Get an indicator of when this item should be processed | * Get an indicator of when this item should be processed | ||||
* @return int constant (IMMEDIATELY, AFTER_PAGE, END_OF_DOC) | * @return int constant (IMMEDIATELY, AFTER_PAGE, END_OF_DOC) | ||||
* @return String name of ODI | * @return String name of ODI | ||||
*/ | */ | ||||
String getName(); | String getName(); | ||||
} | } |
/** Set to true to make this page behave as if it were not empty. */ | /** Set to true to make this page behave as if it were not empty. */ | ||||
private boolean fakeNonEmpty = false; | private boolean fakeNonEmpty = false; | ||||
/** | /** | ||||
* Empty constructor, for cloning | |||||
* Empty constructor, for cloning | |||||
*/ | */ | ||||
public Page() { | public Page() { | ||||
} | } | ||||
// Get absolute margin properties (top, left, bottom, right) | // Get absolute margin properties (top, left, bottom, right) | ||||
CommonMarginBlock mProps = spm.getCommonMarginBlock(); | CommonMarginBlock mProps = spm.getCommonMarginBlock(); | ||||
/* | /* | ||||
* Create the page reference area rectangle (0,0 is at top left | * Create the page reference area rectangle (0,0 is at top left | ||||
* of the "page media" and y increases | * of the "page media" and y increases | ||||
* That's why we 'cheat' here and setup a context for the height but | * That's why we 'cheat' here and setup a context for the height but | ||||
* use the LengthBase.BLOCK_WIDTH. | * use the LengthBase.BLOCK_WIDTH. | ||||
*/ | */ | ||||
SimplePercentBaseContext pageWidthContext | |||||
SimplePercentBaseContext pageWidthContext | |||||
= new SimplePercentBaseContext(null, LengthBase.CONTAINING_BLOCK_WIDTH | = new SimplePercentBaseContext(null, LengthBase.CONTAINING_BLOCK_WIDTH | ||||
, pageViewPortDims.ipd); | , pageViewPortDims.ipd); | ||||
SimplePercentBaseContext pageHeightContext | SimplePercentBaseContext pageHeightContext | ||||
= new SimplePercentBaseContext(null, LengthBase.CONTAINING_BLOCK_WIDTH | = new SimplePercentBaseContext(null, LengthBase.CONTAINING_BLOCK_WIDTH | ||||
, pageViewPortDims.bpd); | , pageViewPortDims.bpd); | ||||
Rectangle pageRefRect | |||||
Rectangle pageRefRect | |||||
= new Rectangle(mProps.marginLeft.getValue(pageWidthContext) | = new Rectangle(mProps.marginLeft.getValue(pageWidthContext) | ||||
, mProps.marginTop.getValue(pageHeightContext) | , mProps.marginTop.getValue(pageHeightContext) | ||||
, pageViewPortDims.ipd | |||||
- mProps.marginLeft.getValue(pageWidthContext) | |||||
, pageViewPortDims.ipd | |||||
- mProps.marginLeft.getValue(pageWidthContext) | |||||
- mProps.marginRight.getValue(pageWidthContext) | - mProps.marginRight.getValue(pageWidthContext) | ||||
, pageViewPortDims.bpd | |||||
, pageViewPortDims.bpd | |||||
- mProps.marginTop.getValue(pageHeightContext) | - mProps.marginTop.getValue(pageHeightContext) | ||||
- mProps.marginBottom.getValue(pageHeightContext)); | - mProps.marginBottom.getValue(pageHeightContext)); | ||||
public void fakeNonEmpty() { | public void fakeNonEmpty() { | ||||
this.fakeNonEmpty = true; | this.fakeNonEmpty = true; | ||||
} | } | ||||
/** | /** | ||||
* Creates a RegionViewport Area object for this pagination Region. | * Creates a RegionViewport Area object for this pagination Region. | ||||
* @param r the region the viewport is to be created for | * @param r the region the viewport is to be created for | ||||
rv.setBPD((int)relRegionRect.getHeight()); | rv.setBPD((int)relRegionRect.getHeight()); | ||||
rv.setIPD((int)relRegionRect.getWidth()); | rv.setIPD((int)relRegionRect.getWidth()); | ||||
TraitSetter.addBackground(rv, r.getCommonBorderPaddingBackground(), null); | TraitSetter.addBackground(rv, r.getCommonBorderPaddingBackground(), null); | ||||
rv.setClip(r.getOverflow() == Constants.EN_HIDDEN | |||||
rv.setClip(r.getOverflow() == Constants.EN_HIDDEN | |||||
|| r.getOverflow() == Constants.EN_ERROR_IF_OVERFLOW); | || r.getOverflow() == Constants.EN_ERROR_IF_OVERFLOW); | ||||
return rv; | return rv; | ||||
} | } | ||||
/** | /** | ||||
* Set the region reference position within the region viewport. | * Set the region reference position within the region viewport. | ||||
* This sets the transform that is used to place the contents of | * This sets the transform that is used to place the contents of | ||||
* where x=distance from left, y=distance from bottom, width=right-left | * where x=distance from left, y=distance from bottom, width=right-left | ||||
* height=top-bottom | * height=top-bottom | ||||
*/ | */ | ||||
private void setRegionReferencePosition(RegionReference rr, Region r, | |||||
private void setRegionReferencePosition(RegionReference rr, Region r, | |||||
Rectangle2D absRegVPRect) { | Rectangle2D absRegVPRect) { | ||||
FODimension reldims = new FODimension(0, 0); | FODimension reldims = new FODimension(0, 0); | ||||
rr.setCTM(CTM.getCTMandRelDims(r.getReferenceOrientation(), | rr.setCTM(CTM.getCTMandRelDims(r.getReferenceOrientation(), | ||||
r.getWritingMode(), absRegVPRect, reldims)); | r.getWritingMode(), absRegVPRect, reldims)); | ||||
rr.setIPD(reldims.ipd); | rr.setIPD(reldims.ipd); | ||||
rr.setBPD(reldims.bpd); | rr.setBPD(reldims.bpd); | ||||
} | |||||
} | |||||
/** | /** | ||||
* Set the region on this page. | * Set the region on this page. | ||||
* | * | ||||
case Constants.FO_REGION_START: | case Constants.FO_REGION_START: | ||||
return regionStart; | return regionStart; | ||||
case Constants.FO_REGION_BODY: | case Constants.FO_REGION_BODY: | ||||
return regionBody; | |||||
return regionBody; | |||||
case Constants.FO_REGION_END: | case Constants.FO_REGION_END: | ||||
return regionEnd; | return regionEnd; | ||||
case Constants.FO_REGION_AFTER: | case Constants.FO_REGION_AFTER: |
private LineArea title; | private LineArea title; | ||||
private String language; | private String language; | ||||
private String country; | private String country; | ||||
/** | /** | ||||
* Main constructor | * Main constructor | ||||
* @param title the title for the page-sequence, may be null | * @param title the title for the page-sequence, may be null | ||||
public PageSequence(LineArea title) { | public PageSequence(LineArea title) { | ||||
setTitle(title); | setTitle(title); | ||||
} | } | ||||
/** | /** | ||||
* @return the title of the page sequence in form of a line area, or null if there's no title | * @return the title of the page sequence in form of a line area, or null if there's no title | ||||
*/ | */ | ||||
public LineArea getTitle() { | public LineArea getTitle() { | ||||
return this.title; | return this.title; | ||||
} | } | ||||
/** | /** | ||||
* Sets the page sequence's title. | * Sets the page sequence's title. | ||||
* @param title the title | * @param title the title | ||||
public void setTitle(LineArea title) { | public void setTitle(LineArea title) { | ||||
this.title = title; | this.title = title; | ||||
} | } | ||||
/** | /** | ||||
* Adds a new page to the page sequence | * Adds a new page to the page sequence | ||||
* @param page the page to be added | * @param page the page to be added | ||||
public void addPage(PageViewport page) { | public void addPage(PageViewport page) { | ||||
this.pages.add(page); | this.pages.add(page); | ||||
} | } | ||||
/** | /** | ||||
* @return the number of pages currently in this page sequence | * @return the number of pages currently in this page sequence | ||||
*/ | */ | ||||
public PageViewport getPage(int idx) { | public PageViewport getPage(int idx) { | ||||
return (PageViewport)this.pages.get(idx); | return (PageViewport)this.pages.get(idx); | ||||
} | } | ||||
/** | /** | ||||
* Indicates whether a page is the first in this page sequence. | * Indicates whether a page is the first in this page sequence. | ||||
* @param page the page to be inspected | * @param page the page to be inspected | ||||
this.language = language; | this.language = language; | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Returns the country of the page-sequence. | * Returns the country of the page-sequence. | ||||
* @return the country (the value of the country property, "none" is mapped to null) | * @return the country (the value of the country property, "none" is mapped to null) | ||||
this.country = country; | this.country = country; | ||||
} | } | ||||
} | } | ||||
} | } |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
private Page page; | private Page page; | ||||
private Rectangle2D viewArea; | private Rectangle2D viewArea; | ||||
private String simplePageMasterName; | private String simplePageMasterName; | ||||
/** | /** | ||||
* Unique key to identify the page. pageNumberString and pageIndex are both no option | |||||
* Unique key to identify the page. pageNumberString and pageIndex are both no option | |||||
* for this. | * for this. | ||||
*/ | */ | ||||
private String pageKey; | private String pageKey; | ||||
private int pageNumber = -1; | private int pageNumber = -1; | ||||
private String pageNumberString = null; | private String pageNumberString = null; | ||||
private int pageIndex = -1; //-1 = undetermined | private int pageIndex = -1; //-1 = undetermined | ||||
private boolean blank; | private boolean blank; | ||||
private transient PageSequence pageSequence; | private transient PageSequence pageSequence; | ||||
// list of id references and the rectangle on the page | // list of id references and the rectangle on the page | ||||
private Map markerFirstAny = null; | private Map markerFirstAny = null; | ||||
private Map markerLastEnd = null; | private Map markerLastEnd = null; | ||||
private Map markerLastAny = null; | private Map markerLastAny = null; | ||||
//Arbitrary attachments to the page from extensions that need to pass information | //Arbitrary attachments to the page from extensions that need to pass information | ||||
//down to the renderers. | //down to the renderers. | ||||
private List extensionAttachments = null; | private List extensionAttachments = null; | ||||
} | } | ||||
/** | /** | ||||
* Copy constructor. | |||||
* Copy constructor. | |||||
* @param original the original PageViewport to copy from | * @param original the original PageViewport to copy from | ||||
*/ | */ | ||||
public PageViewport(PageViewport original) { | public PageViewport(PageViewport original) { | ||||
* @param simplePageMasterName name of the original simple-page-master that generated this page | * @param simplePageMasterName name of the original simple-page-master that generated this page | ||||
* @param blank true if this is a blank page | * @param blank true if this is a blank page | ||||
*/ | */ | ||||
public PageViewport(Rectangle2D viewArea, int pageNumber, String pageStr, | |||||
public PageViewport(Rectangle2D viewArea, int pageNumber, String pageStr, | |||||
String simplePageMasterName, boolean blank) { | String simplePageMasterName, boolean blank) { | ||||
this.viewArea = viewArea; | this.viewArea = viewArea; | ||||
this.pageNumber = pageNumber; | this.pageNumber = pageNumber; | ||||
this.simplePageMasterName = simplePageMasterName; | this.simplePageMasterName = simplePageMasterName; | ||||
this.blank = blank; | this.blank = blank; | ||||
} | } | ||||
/** | /** | ||||
* Sets the page sequence this page belongs to | * Sets the page sequence this page belongs to | ||||
* @param seq the page sequence | * @param seq the page sequence | ||||
public void setPageSequence(PageSequence seq) { | public void setPageSequence(PageSequence seq) { | ||||
this.pageSequence = seq; | this.pageSequence = seq; | ||||
} | } | ||||
/** @return the page sequence this page belongs to */ | /** @return the page sequence this page belongs to */ | ||||
public PageSequence getPageSequence() { | public PageSequence getPageSequence() { | ||||
return this.pageSequence; | return this.pageSequence; | ||||
} | } | ||||
/** | /** | ||||
* Get the view area rectangle of this viewport. | * Get the view area rectangle of this viewport. | ||||
* @return the rectangle for this viewport | * @return the rectangle for this viewport | ||||
public Page getPage() { | public Page getPage() { | ||||
return page; | return page; | ||||
} | } | ||||
/** | /** | ||||
* Sets the page object for this PageViewport. | * Sets the page object for this PageViewport. | ||||
* @param page the page | * @param page the page | ||||
public void setPageIndex(int index) { | public void setPageIndex(int index) { | ||||
this.pageIndex = index; | this.pageIndex = index; | ||||
} | } | ||||
/** | /** | ||||
* @return the overall page index of the page in this rendering run (zero-based, | |||||
* @return the overall page index of the page in this rendering run (zero-based, | |||||
* -1 if it is undetermined). | * -1 if it is undetermined). | ||||
*/ | */ | ||||
public int getPageIndex() { | public int getPageIndex() { | ||||
return this.pageIndex; | return this.pageIndex; | ||||
} | } | ||||
/** | /** | ||||
* Sets the unique key for this PageViewport that will be used to reference this page. | * Sets the unique key for this PageViewport that will be used to reference this page. | ||||
* @param key the unique key. | * @param key the unique key. | ||||
public void setKey(String key) { | public void setKey(String key) { | ||||
this.pageKey = key; | this.pageKey = key; | ||||
} | } | ||||
/** | /** | ||||
* Get the key for this page viewport. | * Get the key for this page viewport. | ||||
* This is used so that a serializable key can be used to | * This is used so that a serializable key can be used to | ||||
* @return true if the page is resolved and can be rendered | * @return true if the page is resolved and can be rendered | ||||
*/ | */ | ||||
public boolean isResolved() { | public boolean isResolved() { | ||||
return unresolvedIDRefs == null | |||||
return unresolvedIDRefs == null | |||||
|| unresolvedIDRefs.size() == 0; | || unresolvedIDRefs.size() == 0; | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | |||||
* {@inheritDoc} | |||||
*/ | */ | ||||
public void resolveIDRef(String id, List pages) { | public void resolveIDRef(String id, List pages) { | ||||
if (page == null) { | if (page == null) { | ||||
* are starting, replacing earlier markers. | * are starting, replacing earlier markers. | ||||
* For "last-ending-within-page" it adds all markers that | * For "last-ending-within-page" it adds all markers that | ||||
* are ending, replacing earlier markers. | * are ending, replacing earlier markers. | ||||
* | |||||
* | |||||
* Should this logic be placed in the Page layout manager. | * Should this logic be placed in the Page layout manager. | ||||
* | * | ||||
* @param marks the map of markers to add | * @param marks the map of markers to add | ||||
return; | return; | ||||
} | } | ||||
if (log.isDebugEnabled()) { | if (log.isDebugEnabled()) { | ||||
log.debug("--" + marks.keySet() + ": " | |||||
+ (starting ? "starting" : "ending") | |||||
+ (isfirst ? ", first" : "") | |||||
log.debug("--" + marks.keySet() + ": " | |||||
+ (starting ? "starting" : "ending") | |||||
+ (isfirst ? ", first" : "") | |||||
+ (islast ? ", last" : "")); | + (islast ? ", last" : "")); | ||||
} | } | ||||
// at the start of the area, register is-first and any areas | // at the start of the area, register is-first and any areas | ||||
if (starting) { | if (starting) { | ||||
if (isfirst) { | if (isfirst) { | ||||
if (!markerFirstStart.containsKey(key)) { | if (!markerFirstStart.containsKey(key)) { | ||||
markerFirstStart.put(key, marks.get(key)); | markerFirstStart.put(key, marks.get(key)); | ||||
if (log.isTraceEnabled()) { | if (log.isTraceEnabled()) { | ||||
log.trace("page " + pageNumberString + ": " | |||||
log.trace("page " + pageNumberString + ": " | |||||
+ "Adding marker " + key + " to FirstStart"); | + "Adding marker " + key + " to FirstStart"); | ||||
} | } | ||||
} | } | ||||
if (!markerFirstAny.containsKey(key)) { | if (!markerFirstAny.containsKey(key)) { | ||||
markerFirstAny.put(key, marks.get(key)); | markerFirstAny.put(key, marks.get(key)); | ||||
if (log.isTraceEnabled()) { | if (log.isTraceEnabled()) { | ||||
log.trace("page " + pageNumberString + ": " | |||||
log.trace("page " + pageNumberString + ": " | |||||
+ "Adding marker " + key + " to FirstAny"); | + "Adding marker " + key + " to FirstAny"); | ||||
} | } | ||||
} | } | ||||
// last on page: replace all | // last on page: replace all | ||||
markerLastStart.putAll(marks); | markerLastStart.putAll(marks); | ||||
if (log.isTraceEnabled()) { | if (log.isTraceEnabled()) { | ||||
log.trace("page " + pageNumberString + ": " | |||||
log.trace("page " + pageNumberString + ": " | |||||
+ "Adding all markers to LastStart"); | + "Adding all markers to LastStart"); | ||||
} | } | ||||
} else { | } else { | ||||
if (!markerFirstAny.containsKey(key)) { | if (!markerFirstAny.containsKey(key)) { | ||||
markerFirstAny.put(key, marks.get(key)); | markerFirstAny.put(key, marks.get(key)); | ||||
if (log.isTraceEnabled()) { | if (log.isTraceEnabled()) { | ||||
log.trace("page " + pageNumberString + ": " | |||||
log.trace("page " + pageNumberString + ": " | |||||
+ "Adding marker " + key + " to FirstAny"); | + "Adding marker " + key + " to FirstAny"); | ||||
} | } | ||||
} | } | ||||
// last on page: replace all | // last on page: replace all | ||||
markerLastEnd.putAll(marks); | markerLastEnd.putAll(marks); | ||||
if (log.isTraceEnabled()) { | if (log.isTraceEnabled()) { | ||||
log.trace("page " + pageNumberString + ": " | |||||
log.trace("page " + pageNumberString + ": " | |||||
+ "Adding all markers to LastEnd"); | + "Adding all markers to LastEnd"); | ||||
} | } | ||||
} | } | ||||
// last on page: replace all | // last on page: replace all | ||||
markerLastAny.putAll(marks); | markerLastAny.putAll(marks); | ||||
if (log.isTraceEnabled()) { | if (log.isTraceEnabled()) { | ||||
log.trace("page " + pageNumberString + ": " | |||||
log.trace("page " + pageNumberString + ": " | |||||
+ "Adding all markers to LastAny"); | + "Adding all markers to LastAny"); | ||||
} | } | ||||
} | } | ||||
* This will retrieve a marker with the class name | * This will retrieve a marker with the class name | ||||
* and position. | * and position. | ||||
* | * | ||||
* @param name The class name of the marker to retrieve | |||||
* @param name The class name of the marker to retrieve | |||||
* @param pos the position to retrieve | * @param pos the position to retrieve | ||||
* @return Object the marker found or null | * @return Object the marker found or null | ||||
*/ | */ | ||||
throw new RuntimeException(); | throw new RuntimeException(); | ||||
} | } | ||||
if (log.isTraceEnabled()) { | if (log.isTraceEnabled()) { | ||||
log.trace("page " + pageNumberString + ": " + "Retrieving marker " + name | |||||
+ " at position " + posName); | |||||
log.trace("page " + pageNumberString + ": " + "Retrieving marker " + name | |||||
+ " at position " + posName); | |||||
} | } | ||||
return mark; | |||||
return mark; | |||||
} | } | ||||
/** Dumps the current marker data to the logger. */ | /** Dumps the current marker data to the logger. */ | ||||
log.trace("LastStart: " + this.markerLastStart); | log.trace("LastStart: " + this.markerLastStart); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Save the page contents to an object stream. | * Save the page contents to an object stream. | ||||
* The map of unresolved references are set on the page so that | * The map of unresolved references are set on the page so that | ||||
sb.append(getPageNumberString()); | sb.append(getPageNumberString()); | ||||
return sb.toString(); | return sb.toString(); | ||||
} | } | ||||
/** @return the name of the simple-page-master that created this page */ | /** @return the name of the simple-page-master that created this page */ | ||||
public String getSimplePageMasterName() { | public String getSimplePageMasterName() { | ||||
return this.simplePageMasterName; | return this.simplePageMasterName; | ||||
} | } | ||||
/** | /** | ||||
* Adds a new ExtensionAttachment instance to this page. | * Adds a new ExtensionAttachment instance to this page. | ||||
* @param attachment the ExtensionAttachment | * @param attachment the ExtensionAttachment | ||||
} | } | ||||
extensionAttachments.add(attachment); | extensionAttachments.add(attachment); | ||||
} | } | ||||
/** @return the list of extension attachments for this page */ | /** @return the list of extension attachments for this page */ | ||||
public List getExtensionAttachments() { | public List getExtensionAttachments() { | ||||
if (this.extensionAttachments == null) { | if (this.extensionAttachments == null) { | ||||
return this.extensionAttachments; | return this.extensionAttachments; | ||||
} | } | ||||
} | } | ||||
/** @return True if this is a blank page. */ | /** @return True if this is a blank page. */ | ||||
public boolean isBlank() { | public boolean isBlank() { | ||||
return this.blank; | return this.blank; | ||||
} | } | ||||
/** | /** | ||||
* Convenience method to get BodyRegion of this PageViewport | * Convenience method to get BodyRegion of this PageViewport | ||||
* @return BodyRegion object | * @return BodyRegion object | ||||
public BodyRegion getBodyRegion() { | public BodyRegion getBodyRegion() { | ||||
return (BodyRegion) getPage().getRegionViewport( | return (BodyRegion) getPage().getRegionViewport( | ||||
Constants.FO_REGION_BODY).getRegionReference(); | Constants.FO_REGION_BODY).getRegionReference(); | ||||
} | |||||
} | |||||
/** | /** | ||||
* Convenience method to create a new Span for this | * Convenience method to create a new Span for this | ||||
* this PageViewport. | * this PageViewport. | ||||
* | |||||
* | |||||
* @param spanAll whether this is a single-column span | * @param spanAll whether this is a single-column span | ||||
* @return Span object created | * @return Span object created | ||||
*/ | */ | ||||
public Span createSpan(boolean spanAll) { | public Span createSpan(boolean spanAll) { | ||||
return getBodyRegion().getMainReference().createSpan(spanAll); | return getBodyRegion().getMainReference().createSpan(spanAll); | ||||
} | |||||
} | |||||
/** | /** | ||||
* Convenience method to get the span-reference-area currently | * Convenience method to get the span-reference-area currently | ||||
* being processed | * being processed | ||||
* | |||||
* | |||||
* @return span currently being processed. | * @return span currently being processed. | ||||
*/ | */ | ||||
public Span getCurrentSpan() { | public Span getCurrentSpan() { | ||||
return getBodyRegion().getMainReference().getCurrentSpan(); | return getBodyRegion().getMainReference().getCurrentSpan(); | ||||
} | } | ||||
/** | /** | ||||
* Convenience method to get the normal-flow-reference-area | |||||
* Convenience method to get the normal-flow-reference-area | |||||
* currently being processed | * currently being processed | ||||
* | |||||
* | |||||
* @return span currently being processed. | * @return span currently being processed. | ||||
*/ | */ | ||||
public NormalFlow getCurrentFlow() { | public NormalFlow getCurrentFlow() { | ||||
return getCurrentSpan().getCurrentFlow(); | return getCurrentSpan().getCurrentFlow(); | ||||
} | } | ||||
/** | /** | ||||
* Convenience method to increment the Span to the | |||||
* Convenience method to increment the Span to the | |||||
* next NormalFlow to be processed, and to return that flow. | * next NormalFlow to be processed, and to return that flow. | ||||
* | |||||
* | |||||
* @return the next NormalFlow in the Span. | * @return the next NormalFlow in the Span. | ||||
*/ | */ | ||||
public NormalFlow moveToNextFlow() { | public NormalFlow moveToNextFlow() { | ||||
return getCurrentSpan().moveToNextFlow(); | return getCurrentSpan().moveToNextFlow(); | ||||
} | } | ||||
/** | /** | ||||
* Convenience method to return a given region-reference-area, | |||||
* Convenience method to return a given region-reference-area, | |||||
* keyed by the Constants class identifier for the corresponding | * keyed by the Constants class identifier for the corresponding | ||||
* formatting object (ie. Constants.FO_REGION_BODY, FO_REGION_START, | |||||
* formatting object (ie. Constants.FO_REGION_BODY, FO_REGION_START, | |||||
* etc.) | * etc.) | ||||
* | |||||
* | |||||
* @param id the Constants class identifier for the region. | * @param id the Constants class identifier for the region. | ||||
* @return the corresponding region-reference-area for this page. | * @return the corresponding region-reference-area for this page. | ||||
*/ | */ | ||||
public RegionReference getRegionReference(int id) { | public RegionReference getRegionReference(int id) { | ||||
return getPage().getRegionViewport(id).getRegionReference(); | return getPage().getRegionViewport(id).getRegionReference(); | ||||
} | } | ||||
/** @return whether this page viewport has any extension attachments */ | /** @return whether this page viewport has any extension attachments */ | ||||
public boolean hasExtensionAttachments() { | public boolean hasExtensionAttachments() { | ||||
return this.extensionAttachments != null && !this.extensionAttachments.isEmpty(); | return this.extensionAttachments != null && !this.extensionAttachments.isEmpty(); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
* so the page master can make copies from the original page and regions. | * so the page master can make copies from the original page and regions. | ||||
*/ | */ | ||||
public class RegionReference extends Area implements Cloneable { | public class RegionReference extends Area implements Cloneable { | ||||
/** Reference to the region FO. */ | /** Reference to the region FO. */ | ||||
//protected Region regionFO; | //protected Region regionFO; | ||||
private int regionClass; | private int regionClass; | ||||
private String regionName; | private String regionName; | ||||
private CTM ctm; | private CTM ctm; | ||||
// the list of block areas from the static flow | // the list of block areas from the static flow | ||||
private ArrayList blocks = new ArrayList(); | private ArrayList blocks = new ArrayList(); | ||||
/** the parent RegionViewport for this object */ | /** the parent RegionViewport for this object */ | ||||
protected RegionViewport regionViewport; | protected RegionViewport regionViewport; | ||||
// subtract bpd of borders and padding before / after | // subtract bpd of borders and padding before / after | ||||
return super.getBPD() - getBorderAndPaddingWidthBefore() - getBorderAndPaddingWidthAfter(); | return super.getBPD() - getBorderAndPaddingWidthBefore() - getBorderAndPaddingWidthAfter(); | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public int getIPD() { | public int getIPD() { | ||||
// subtract ipd of borders and padding start / end | // subtract ipd of borders and padding start / end | ||||
public void setCTM(CTM ctm) { | public void setCTM(CTM ctm) { | ||||
this.ctm = ctm; | this.ctm = ctm; | ||||
} | } | ||||
/** | /** | ||||
* @return Returns the parent RegionViewport. | * @return Returns the parent RegionViewport. | ||||
*/ | */ | ||||
public String getRegionName() { | public String getRegionName() { | ||||
return this.regionName; | return this.regionName; | ||||
} | } | ||||
/** | /** | ||||
* Add a block area to this region reference area. | * Add a block area to this region reference area. | ||||
* | * | ||||
public void addBlock(Block block) { | public void addBlock(Block block) { | ||||
addChildArea(block); | addChildArea(block); | ||||
} | } | ||||
/** | /** | ||||
* Clone this region. | * Clone this region. | ||||
* This is used when cloning the page by the page master. | * This is used when cloning the page by the page master. |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area; | package org.apache.fop.area; | ||||
import java.awt.geom.Rectangle2D; | import java.awt.geom.Rectangle2D; | ||||
/** | /** | ||||
* Region Viewport area. | * Region Viewport area. | ||||
* This object represents the region-viewport-area. It has a | |||||
* This object represents the region-viewport-area. It has a | |||||
* region-reference-area as its child. These areas are described | * region-reference-area as its child. These areas are described | ||||
* in the fo:region-body description in the XSL Recommendation. | * in the fo:region-body description in the XSL Recommendation. | ||||
*/ | */ | ||||
public boolean isClip() { | public boolean isClip() { | ||||
return this.clip; | return this.clip; | ||||
} | } | ||||
/** | /** | ||||
* Get the view area of this viewport. | * Get the view area of this viewport. | ||||
* | * |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area; | package org.apache.fop.area; | ||||
// Java | // Java | ||||
* The renderer that will render the pages. | * The renderer that will render the pages. | ||||
*/ | */ | ||||
protected Renderer renderer; | protected Renderer renderer; | ||||
/** | /** | ||||
* Pages that have been prepared but not rendered yet. | * Pages that have been prepared but not rendered yet. | ||||
*/ | */ | ||||
* @param stream OutputStream | * @param stream OutputStream | ||||
* @throws FOPException if the renderer cannot be properly initialized | * @throws FOPException if the renderer cannot be properly initialized | ||||
*/ | */ | ||||
public RenderPagesModel (FOUserAgent userAgent, String outputFormat, | |||||
public RenderPagesModel (FOUserAgent userAgent, String outputFormat, | |||||
FontInfo fontInfo, OutputStream stream) throws FOPException { | FontInfo fontInfo, OutputStream stream) throws FOPException { | ||||
super(); | super(); | ||||
try { | try { | ||||
renderer.renderPage(page); | renderer.renderPage(page); | ||||
} catch (RuntimeException re) { | } catch (RuntimeException re) { | ||||
String err = "Error while rendering page " + page.getPageNumberString(); | |||||
String err = "Error while rendering page " + page.getPageNumberString(); | |||||
log.error(err, re); | log.error(err, re); | ||||
throw re; | throw re; | ||||
} catch (IOException ioe) { | } catch (IOException ioe) { | ||||
eventProducer.ioError(this, ioe); | eventProducer.ioError(this, ioe); | ||||
} catch (FOPException e) { | } catch (FOPException e) { | ||||
//TODO use error handler to handle this FOPException or propagate exception | //TODO use error handler to handle this FOPException or propagate exception | ||||
String err = "Error while rendering page " + page.getPageNumberString(); | |||||
String err = "Error while rendering page " + page.getPageNumberString(); | |||||
log.error(err, e); | log.error(err, e); | ||||
throw new IllegalStateException("Fatal error occurred. Cannot continue. " | |||||
throw new IllegalStateException("Fatal error occurred. Cannot continue. " | |||||
+ e.getClass().getName() + ": " + err); | + e.getClass().getName() + ": " + err); | ||||
} | } | ||||
page.clear(); | page.clear(); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area; | package org.apache.fop.area; | ||||
import java.util.List; | import java.util.List; | ||||
* identifies to the AreaTreeHandler which idrefs it needs | * identifies to the AreaTreeHandler which idrefs it needs | ||||
* resolved. After the idrefs are resolved, the ATH calls this | * resolved. After the idrefs are resolved, the ATH calls this | ||||
* method to allow the Resolvable object to update itself with | * method to allow the Resolvable object to update itself with | ||||
* the PageViewport information. | |||||
* the PageViewport information. | |||||
* | * | ||||
* @param id an ID matching one of the Resolvable object's | * @param id an ID matching one of the Resolvable object's | ||||
* unresolved idref's. | * unresolved idref's. |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area; | package org.apache.fop.area; | ||||
import java.util.List; | import java.util.List; | ||||
* within the main-reference-area | * within the main-reference-area | ||||
* This object holds one or more normal-flow-reference-area children | * This object holds one or more normal-flow-reference-area children | ||||
* based on the column-count trait in effect for this span. | * based on the column-count trait in effect for this span. | ||||
* See fo:region-body definition in the XSL Rec for more information. | |||||
* See fo:region-body definition in the XSL Rec for more information. | |||||
*/ | */ | ||||
public class Span extends Area { | public class Span extends Area { | ||||
// the list of flow reference areas in this span area | // the list of flow reference areas in this span area | ||||
private int colGap; | private int colGap; | ||||
private int colWidth; // width for each normal flow, calculated value | private int colWidth; // width for each normal flow, calculated value | ||||
private int curFlowIdx; // n-f-r-a currently being processed, zero-based | private int curFlowIdx; // n-f-r-a currently being processed, zero-based | ||||
/** | /** | ||||
* Create a span area with the number of columns for this span area. | * Create a span area with the number of columns for this span area. | ||||
* | * | ||||
* @param colCount the number of columns in the span | * @param colCount the number of columns in the span | ||||
* @param colGap the column gap between each column | |||||
* @param ipd the total ipd of the span | |||||
* @param colGap the column gap between each column | |||||
* @param ipd the total ipd of the span | |||||
*/ | */ | ||||
public Span(int colCount, int colGap, int ipd) { | public Span(int colCount, int colGap, int ipd) { | ||||
addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE); | addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE); | ||||
* Create the normal flows for this Span | * Create the normal flows for this Span | ||||
*/ | */ | ||||
private void createNormalFlows() { | private void createNormalFlows() { | ||||
flowAreas = new java.util.ArrayList(colCount); | |||||
flowAreas = new java.util.ArrayList(colCount); | |||||
colWidth = (ipd - ((colCount - 1) * colGap)) / colCount; | colWidth = (ipd - ((colCount - 1) * colGap)) / colCount; | ||||
for (int i = 0; i < colCount; i++) { | for (int i = 0; i < colCount; i++) { | ||||
if (colRequested >= 0 && colRequested < colCount) { | if (colRequested >= 0 && colRequested < colCount) { | ||||
return (NormalFlow) flowAreas.get(colRequested); | return (NormalFlow) flowAreas.get(colRequested); | ||||
} else { // internal error | } else { // internal error | ||||
throw new IllegalArgumentException("Invalid column number " | |||||
+ colRequested + " requested; only 0-" + (colCount - 1) | |||||
throw new IllegalArgumentException("Invalid column number " | |||||
+ colRequested + " requested; only 0-" + (colCount - 1) | |||||
+ " available."); | + " available."); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Get the NormalFlow area currently being processed | * Get the NormalFlow area currently being processed | ||||
* | * | ||||
* @return the current NormalFlow | * @return the current NormalFlow | ||||
*/ | */ | ||||
public NormalFlow getCurrentFlow() { | public NormalFlow getCurrentFlow() { | ||||
return getNormalFlow(curFlowIdx); | |||||
return getNormalFlow(curFlowIdx); | |||||
} | } | ||||
/** @return the index of the current normal flow */ | /** @return the index of the current normal flow */ | ||||
public int getCurrentFlowIndex() { | public int getCurrentFlowIndex() { | ||||
return curFlowIdx; | return curFlowIdx; | ||||
} | } | ||||
/** | /** | ||||
* Indicate to the Span that the next column is being | |||||
* Indicate to the Span that the next column is being | |||||
* processed. | * processed. | ||||
* | * | ||||
* @return the new NormalFlow (in the next column) | * @return the new NormalFlow (in the next column) | ||||
throw new IllegalStateException("(Internal error.) No more flows left in span."); | throw new IllegalStateException("(Internal error.) No more flows left in span."); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Indicates if the Span has unprocessed flows. | |||||
* Indicates if the Span has unprocessed flows. | |||||
* | * | ||||
* @return true if Span can increment to the next flow, | |||||
* @return true if Span can increment to the next flow, | |||||
* false otherwise. | * false otherwise. | ||||
*/ | */ | ||||
public boolean hasMoreFlows() { | public boolean hasMoreFlows() { | ||||
return (curFlowIdx < colCount - 1); | |||||
return (curFlowIdx < colCount - 1); | |||||
} | } | ||||
/** | /** | ||||
* Called to notify the span that all its flows have been fully generated so it can update | * Called to notify the span that all its flows have been fully generated so it can update | ||||
* its own BPD extent. | * its own BPD extent. | ||||
} | } | ||||
bpd = maxFlowBPD; | bpd = maxFlowBPD; | ||||
} | } | ||||
/** | /** | ||||
* Indicates whether any child areas have been added to this span area. | * Indicates whether any child areas have been added to this span area. | ||||
* | * | ||||
} | } | ||||
return (areaCount == 0); | return (areaCount == 0); | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public String toString() { | public String toString() { | ||||
StringBuffer sb = new StringBuffer(super.toString()); | StringBuffer sb = new StringBuffer(super.toString()); |
/** The space-before trait. */ | /** The space-before trait. */ | ||||
public static final Integer SPACE_BEFORE = new Integer(29); | public static final Integer SPACE_BEFORE = new Integer(29); | ||||
/** The space-after trait. */ | /** The space-after trait. */ | ||||
public static final Integer SPACE_AFTER = new Integer(30); | public static final Integer SPACE_AFTER = new Integer(30); | ||||
/** The is-reference-area trait. */ | /** The is-reference-area trait. */ | ||||
public static final Integer IS_REFERENCE_AREA = new Integer(31); | public static final Integer IS_REFERENCE_AREA = new Integer(31); | ||||
/** The is-viewport-area trait. */ | /** The is-viewport-area trait. */ | ||||
public static final Integer IS_VIEWPORT_AREA = new Integer(32); | public static final Integer IS_VIEWPORT_AREA = new Integer(32); | ||||
/** Blinking trait used when rendering inline parent. */ | /** Blinking trait used when rendering inline parent. */ | ||||
public static final Integer BLINK = new Integer(33); | public static final Integer BLINK = new Integer(33); | ||||
/** Trait for color of underline decorations when rendering inline parent. */ | /** Trait for color of underline decorations when rendering inline parent. */ | ||||
public static final Integer UNDERLINE_COLOR = new Integer(34); | public static final Integer UNDERLINE_COLOR = new Integer(34); | ||||
/** Trait for color of overline decorations when rendering inline parent. */ | /** Trait for color of overline decorations when rendering inline parent. */ | ||||
/** Maximum value used by trait keys */ | /** Maximum value used by trait keys */ | ||||
public static final int MAX_TRAIT_KEY = 36; | public static final int MAX_TRAIT_KEY = 36; | ||||
private static final TraitInfo[] TRAIT_INFO = new TraitInfo[MAX_TRAIT_KEY + 1]; | private static final TraitInfo[] TRAIT_INFO = new TraitInfo[MAX_TRAIT_KEY + 1]; | ||||
private static class TraitInfo { | private static class TraitInfo { | ||||
private String name; | private String name; | ||||
private Class clazz; // Class of trait data | private Class clazz; // Class of trait data | ||||
private static void put(Integer key, TraitInfo info) { | private static void put(Integer key, TraitInfo info) { | ||||
TRAIT_INFO[key.intValue()] = info; | TRAIT_INFO[key.intValue()] = info; | ||||
} | } | ||||
static { | static { | ||||
// Create a hashmap mapping trait code to name for external representation | // Create a hashmap mapping trait code to name for external representation | ||||
//put(ID_LINK, new TraitInfo("id-link", String.class)); | //put(ID_LINK, new TraitInfo("id-link", String.class)); | ||||
/** The background image url if any. */ | /** The background image url if any. */ | ||||
private String url = null; | private String url = null; | ||||
/** The background image if any. */ | /** The background image if any. */ | ||||
private ImageInfo imageInfo = null; | private ImageInfo imageInfo = null; | ||||
throw new IllegalStateException("Illegal repeat style: " + repeat); | throw new IllegalStateException("Illegal repeat style: " + repeat); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Return the string for debugging. | * Return the string for debugging. | ||||
* {@inheritDoc} | * {@inheritDoc} |
* (this is equivalent to the property word-spacing.optimum) | * (this is equivalent to the property word-spacing.optimum) | ||||
*/ | */ | ||||
protected int spaceDifference = 0; | protected int spaceDifference = 0; | ||||
/** | /** | ||||
* Constructor | * Constructor | ||||
* | * | ||||
public AbstractTextArea(int stretch, int shrink, int adj) { | public AbstractTextArea(int stretch, int shrink, int adj) { | ||||
textAdjustingInfo = new TextAdjustingInfo(stretch, shrink, adj); | textAdjustingInfo = new TextAdjustingInfo(stretch, shrink, adj); | ||||
} | } | ||||
/** | /** | ||||
* Get text word space adjust. | * Get text word space adjust. | ||||
* | * | ||||
} | } | ||||
/** | /** | ||||
* Set the difference between optimal width of a space and | |||||
* Set the difference between optimal width of a space and | |||||
* default width of a space according to the font; this part | * default width of a space according to the font; this part | ||||
* of the space adjustment is fixed and must not be | |||||
* of the space adjustment is fixed and must not be | |||||
* multiplied by the variation factor. | * multiplied by the variation factor. | ||||
* @param spaceDiff the space difference | * @param spaceDiff the space difference | ||||
*/ | */ | ||||
int lineStretch, int lineShrink) { | int lineStretch, int lineShrink) { | ||||
if (textAdjustingInfo != null) { | if (textAdjustingInfo != null) { | ||||
// compute the new adjustments: | // compute the new adjustments: | ||||
// if the variation factor is negative, it means that before | |||||
// if the variation factor is negative, it means that before | |||||
// the ipd variation the line had to stretch and now it has | // the ipd variation the line had to stretch and now it has | ||||
// to shrink (or vice versa); | // to shrink (or vice versa); | ||||
// in this case, if the stretch and shrink are not equally | |||||
// divided among the inline areas, we must compute a | |||||
// in this case, if the stretch and shrink are not equally | |||||
// divided among the inline areas, we must compute a | |||||
// balancing factor | // balancing factor | ||||
double balancingFactor = 1.0; | double balancingFactor = 1.0; | ||||
if (variationFactor < 0) { | if (variationFactor < 0) { | ||||
if (textWordSpaceAdjust < 0) { | if (textWordSpaceAdjust < 0) { | ||||
// from a negative adjustment to a positive one | // from a negative adjustment to a positive one | ||||
balancingFactor | |||||
balancingFactor | |||||
= ((double) textAdjustingInfo.availableStretch / textAdjustingInfo.availableShrink) | = ((double) textAdjustingInfo.availableStretch / textAdjustingInfo.availableShrink) | ||||
* ((double) lineShrink / lineStretch); | * ((double) lineShrink / lineStretch); | ||||
} else { | } else { | ||||
// from a positive adjustment to a negative one | // from a positive adjustment to a negative one | ||||
balancingFactor | |||||
balancingFactor | |||||
= ((double) textAdjustingInfo.availableShrink / textAdjustingInfo.availableStretch) | = ((double) textAdjustingInfo.availableShrink / textAdjustingInfo.availableStretch) | ||||
* ((double) lineStretch / lineShrink); | * ((double) lineStretch / lineShrink); | ||||
} | } |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area.inline; | package org.apache.fop.area.inline; | ||||
/** | /** |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area.inline; | package org.apache.fop.area.inline; | ||||
import org.apache.fop.area.Area; | import org.apache.fop.area.Area; |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area.inline; | package org.apache.fop.area.inline; | ||||
import java.util.List; | import java.util.List; | ||||
*/ | */ | ||||
public class FilledArea extends InlineParent { | public class FilledArea extends InlineParent { | ||||
private int unitWidth; | private int unitWidth; | ||||
/** | /** | ||||
* Create a new filled area. | * Create a new filled area. | ||||
*/ | */ | ||||
} | } | ||||
return bpd; | return bpd; | ||||
} | } | ||||
/** | /** | ||||
* Get the child areas for this filled area. | * Get the child areas for this filled area. | ||||
* This copies the references of the inline areas so that | * This copies the references of the inline areas so that | ||||
} | } | ||||
return newList; | return newList; | ||||
} | } | ||||
/** | /** | ||||
* recursively apply the variation factor to all descendant areas | * recursively apply the variation factor to all descendant areas | ||||
* @param variationFactor the variation factor that must be applied to adjustments | * @param variationFactor the variation factor that must be applied to adjustments |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area.inline; | package org.apache.fop.area.inline; | ||||
import org.apache.fop.area.Area; | import org.apache.fop.area.Area; | ||||
* This holds an xml document and the associated namespace. | * This holds an xml document and the associated namespace. | ||||
*/ | */ | ||||
public class ForeignObject extends Area { | public class ForeignObject extends Area { | ||||
private static final long serialVersionUID = -214947698798577885L; | private static final long serialVersionUID = -214947698798577885L; | ||||
private Document doc; | private Document doc; | ||||
private String namespace; | private String namespace; | ||||
public void setDocument(Document document) { | public void setDocument(Document document) { | ||||
this.doc = document; | this.doc = document; | ||||
} | } | ||||
/** | /** | ||||
* Get the document for this foreign object. | * Get the document for this foreign object. | ||||
* | * |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
*/ | */ | ||||
/* $Id$ */ | /* $Id$ */ | ||||
package org.apache.fop.area.inline; | package org.apache.fop.area.inline; | ||||
import org.apache.fop.area.Area; | import org.apache.fop.area.Area; |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
* in a line area. | * in a line area. | ||||
*/ | */ | ||||
public class InlineArea extends Area { | public class InlineArea extends Area { | ||||
/** | /** | ||||
* this class stores information about potential adjustments | * this class stores information about potential adjustments | ||||
* that can be used in order to re-compute adjustments when a | * that can be used in order to re-compute adjustments when a | ||||
protected int availableShrink; | protected int availableShrink; | ||||
/** total adjustment (= ipd - width of fixed elements) */ | /** total adjustment (= ipd - width of fixed elements) */ | ||||
protected int adjustment; | protected int adjustment; | ||||
/** | /** | ||||
* Constructor | * Constructor | ||||
* | * | ||||
availableShrink = shrink; | availableShrink = shrink; | ||||
adjustment = adj; | adjustment = adj; | ||||
} | } | ||||
/** | /** | ||||
* Apply the variation factor | * Apply the variation factor | ||||
* | |||||
* | |||||
* @param variationFactor the factor by which the adjustment is to be changed | * @param variationFactor the factor by which the adjustment is to be changed | ||||
* @return the IPD increase | * @return the IPD increase | ||||
*/ | */ | ||||
return adjustment - oldAdjustment; | return adjustment - oldAdjustment; | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* offset position from before edge of parent area | * offset position from before edge of parent area | ||||
*/ | */ | ||||
protected int offset = 0; | protected int offset = 0; | ||||
/** | /** | ||||
* parent area | * parent area | ||||
* it is needed in order to recompute adjust ratio and indents | * it is needed in order to recompute adjust ratio and indents | ||||
* when a page-number or a page-number-citation is resolved | * when a page-number or a page-number-citation is resolved | ||||
*/ | */ | ||||
private Area parentArea = null; | private Area parentArea = null; | ||||
/** | /** | ||||
* ipd variation of child areas: if this area has not already | * ipd variation of child areas: if this area has not already | ||||
* been added and cannot notify its parent area, store the variation | * been added and cannot notify its parent area, store the variation | ||||
* The adjustment information object | * The adjustment information object | ||||
*/ | */ | ||||
protected InlineAdjustingInfo adjustingInfo = null; | protected InlineAdjustingInfo adjustingInfo = null; | ||||
/** | /** | ||||
* @return the adjustment information object | * @return the adjustment information object | ||||
*/ | */ | ||||
public void setAdjustingInfo(int stretch, int shrink, int adjustment) { | public void setAdjustingInfo(int stretch, int shrink, int adjustment) { | ||||
adjustingInfo = new InlineAdjustingInfo(stretch, shrink, adjustment); | adjustingInfo = new InlineAdjustingInfo(stretch, shrink, adjustment); | ||||
} | } | ||||
/** | /** | ||||
* Modify the adjustment value in the adjustment information object | * Modify the adjustment value in the adjustment information object | ||||
* @param adjustment the new adjustment value | * @param adjustment the new adjustment value | ||||
adjustingInfo.adjustment = adjustment; | adjustingInfo.adjustment = adjustment; | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Increase the inline progression dimensions of this area. | * Increase the inline progression dimensions of this area. | ||||
* This is used for inline parent areas that contain mulitple child areas. | * This is used for inline parent areas that contain mulitple child areas. | ||||
public Area getParentArea() { | public Area getParentArea() { | ||||
return parentArea; | return parentArea; | ||||
} | } | ||||
/** | /** | ||||
* Set the parent for the child area. | * Set the parent for the child area. | ||||
* | * | ||||
((InlineArea) childArea).setParentArea(this); | ((InlineArea) childArea).setParentArea(this); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
*@return true if the inline area is underlined. | *@return true if the inline area is underlined. | ||||
*/ | */ | ||||
public boolean hasOverline() { | public boolean hasOverline() { | ||||
return getTraitAsBoolean(Trait.OVERLINE); | return getTraitAsBoolean(Trait.OVERLINE); | ||||
} | } | ||||
/** @return true if the inline area has a line through. */ | /** @return true if the inline area has a line through. */ | ||||
public boolean hasLineThrough() { | public boolean hasLineThrough() { | ||||
return getTraitAsBoolean(Trait.LINETHROUGH); | return getTraitAsBoolean(Trait.LINETHROUGH); | ||||
} | } | ||||
/** @return true if the inline area is blinking. */ | /** @return true if the inline area is blinking. */ | ||||
public boolean isBlinking() { | public boolean isBlinking() { | ||||
return getTraitAsBoolean(Trait.BLINK); | return getTraitAsBoolean(Trait.BLINK); | ||||
} | } | ||||
/** | /** | ||||
* recursively apply the variation factor to all descendant areas | * recursively apply the variation factor to all descendant areas | ||||
* @param variationFactor the variation factor that must be applied to adjustments | * @param variationFactor the variation factor that must be applied to adjustments | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
public void handleIPDVariation(int ipdVariation) { | public void handleIPDVariation(int ipdVariation) { | ||||
increaseIPD(ipdVariation); | increaseIPD(ipdVariation); | ||||
notifyIPDVariation(ipdVariation); | notifyIPDVariation(ipdVariation); | ||||
} | } | ||||
/** | /** | ||||
* notify the parent area about the ipd variation of this area | * notify the parent area about the ipd variation of this area | ||||
* or of a descendant area | * or of a descendant area |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
/** Controls whether the IPD is automatically adjusted based on the area's children. */ | /** Controls whether the IPD is automatically adjusted based on the area's children. */ | ||||
protected transient boolean autoSize; | protected transient boolean autoSize; | ||||
/** | /** | ||||
* Create a new inline parent to add areas to. | * Create a new inline parent to add areas to. | ||||
*/ | */ | ||||
public boolean applyVariationFactor(double variationFactor, | public boolean applyVariationFactor(double variationFactor, | ||||
int lineStretch, int lineShrink) { | int lineStretch, int lineShrink) { | ||||
boolean bUnresolvedAreasPresent = false; | boolean bUnresolvedAreasPresent = false; | ||||
// recursively apply variation factor to descendant areas | |||||
// recursively apply variation factor to descendant areas | |||||
for (int i = 0, len = inlines.size(); i < len; i++) { | for (int i = 0, len = inlines.size(); i < len; i++) { | ||||
bUnresolvedAreasPresent |= ((InlineArea)inlines.get(i)) | bUnresolvedAreasPresent |= ((InlineArea)inlines.get(i)) | ||||
.applyVariationFactor(variationFactor, lineStretch, lineShrink); | .applyVariationFactor(variationFactor, lineStretch, lineShrink); |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
setRuleStyle(Constants.EN_NONE); | setRuleStyle(Constants.EN_NONE); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Set the rule thickness of the rule in miilipoints. | * Set the rule thickness of the rule in miilipoints. | ||||
* | * | ||||
throw new IllegalStateException("Unsupported rule style: " + getRuleStyle()); | throw new IllegalStateException("Unsupported rule style: " + getRuleStyle()); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Get the rule thickness of the rule in miilipoints. | * Get the rule thickness of the rule in miilipoints. | ||||
* | * |
* The ASF licenses this file to You under the Apache License, Version 2.0 | * 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 not use this file except in compliance with | ||||
* the License. You may obtain a copy of the License at | * the License. You may obtain a copy of the License at | ||||
* | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |