aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/fop/Version.java2
-rw-r--r--src/java/org/apache/fop/cli/CommandLineOptions.java61
-rw-r--r--src/java/org/apache/fop/cli/Main.java5
-rw-r--r--src/java/org/apache/fop/render/PrintRendererConfigurator.java2
-rw-r--r--src/java/org/apache/fop/render/awt/AWTRenderer.java4
-rw-r--r--src/java/org/apache/fop/render/java2d/Java2DRenderer.java7
-rw-r--r--src/java/org/apache/fop/render/print/PagesMode.java69
-rw-r--r--src/java/org/apache/fop/render/print/PrintRenderer.java153
8 files changed, 257 insertions, 46 deletions
diff --git a/src/java/org/apache/fop/Version.java b/src/java/org/apache/fop/Version.java
index 4545d071e..7e421ad29 100644
--- a/src/java/org/apache/fop/Version.java
+++ b/src/java/org/apache/fop/Version.java
@@ -41,7 +41,7 @@ public final class Version {
if (version == null) {
//Fallback if FOP is used in a development environment
String headURL
- = "$HeadURL: http://svn.apache.org/repos/asf/xmlgraphics/fop/trunk/src/java/org/apache/fop/Version.java $";
+ = "$HeadURL$";
version = headURL;
final String pathPrefix = "/xmlgraphics/fop/";
int pos = version.indexOf(pathPrefix);
diff --git a/src/java/org/apache/fop/cli/CommandLineOptions.java b/src/java/org/apache/fop/cli/CommandLineOptions.java
index 3bb0aae7f..4e5c8ae44 100644
--- a/src/java/org/apache/fop/cli/CommandLineOptions.java
+++ b/src/java/org/apache/fop/cli/CommandLineOptions.java
@@ -46,6 +46,8 @@ import org.apache.fop.pdf.PDFXMode;
import org.apache.fop.render.Renderer;
import org.apache.fop.render.awt.AWTRenderer;
import org.apache.fop.render.pdf.PDFRenderer;
+import org.apache.fop.render.print.PagesMode;
+import org.apache.fop.render.print.PrintRenderer;
import org.apache.fop.render.xml.XMLRenderer;
import org.apache.fop.util.CommandLineLogger;
@@ -133,8 +135,9 @@ public class CommandLineOptions {
* @throws FOPException for general errors
* @throws FileNotFoundException if an input file wasn't found
* @throws IOException if the the configuration file could not be loaded
+ * @return true if the processing can continue, false to abort
*/
- public void parse(String[] args)
+ public boolean parse(String[] args)
throws FOPException, IOException {
boolean optionsParsed = true;
@@ -155,6 +158,8 @@ public class CommandLineOptions {
}
addXSLTParameter("fop-output-format", getOutputFormat());
addXSLTParameter("fop-version", Version.getVersion());
+ } else {
+ return false;
}
} catch (FOPException e) {
printUsage();
@@ -193,6 +198,7 @@ public class CommandLineOptions {
//Make sure the prepared XMLRenderer is used
foUserAgent.setRendererOverride(xmlRenderer);
}
+ return true;
}
/**
@@ -268,7 +274,6 @@ public class CommandLineOptions {
} else if (args[i].equals("-png")) {
i = i + parsePNGOutputOption(args, i);
} else if (args[i].equals("-print")) {
- i = i + parsePrintOutputOption(args, i);
// show print help
if (i + 1 < args.length) {
if (args[i + 1].equals("help")) {
@@ -276,6 +281,9 @@ public class CommandLineOptions {
return false;
}
}
+ i = i + parsePrintOutputOption(args, i);
+ } else if (args[i].equals("-copies")) {
+ i = i + parseCopiesOption(args, i);
} else if (args[i].equals("-pcl")) {
i = i + parsePCLOutputOption(args, i);
} else if (args[i].equals("-ps")) {
@@ -302,7 +310,7 @@ public class CommandLineOptions {
String expression = args[++i];
addXSLTParameter(name, expression);
} else {
- throw new FOPException("invalid param usage: use -param <name> <value>");
+ throw new FOPException("invalid param usage: use -param <name> <value>");
}
} else if (args[i].equals("-o")) {
i = i + parsePDFOwnerPassword(args, i);
@@ -461,7 +469,37 @@ public class CommandLineOptions {
private int parsePrintOutputOption(String[] args, int i) throws FOPException {
setOutputMode(MimeConstants.MIME_FOP_PRINT);
- return 0;
+ if ((i + 1 <= args.length)
+ && (args[i + 1].charAt(0) != '-')) {
+ String arg = args[i + 1];
+ String[] parts = arg.split(",");
+ for (int j = 0; j < parts.length; j++) {
+ String s = parts[j];
+ if (s.matches("\\d+")) {
+ renderingOptions.put(PrintRenderer.START_PAGE, new Integer(s));
+ } else if (s.matches("\\d+-\\d+")) {
+ String[] startend = s.split("-");
+ renderingOptions.put(PrintRenderer.START_PAGE, new Integer(startend[0]));
+ renderingOptions.put(PrintRenderer.END_PAGE, new Integer(startend[1]));
+ } else {
+ PagesMode mode = PagesMode.byName(s);
+ renderingOptions.put(PrintRenderer.PAGES_MODE, mode);
+ }
+ }
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+
+ private int parseCopiesOption(String[] args, int i) throws FOPException {
+ if ((i + 1 == args.length)
+ || (args[i + 1].charAt(0) == '-')) {
+ throw new FOPException("you must specify the number of copies");
+ } else {
+ renderingOptions.put(PrintRenderer.COPIES, new Integer(args[i + 1]));
+ return 1;
+ }
}
private int parsePCLOutputOption(String[] args, int i) throws FOPException {
@@ -991,18 +1029,21 @@ public class CommandLineOptions {
+ " Fop -xml foo.xml -xsl foo.xsl -foout foo.fo\n"
+ " Fop foo.fo -mif foo.mif\n"
+ " Fop foo.fo -rtf foo.rtf\n"
- + " Fop foo.fo -print or Fop -print foo.fo \n"
- + " Fop foo.fo -awt \n");
+ + " Fop foo.fo -print\n"
+ + " Fop foo.fo -awt\n");
}
/**
* shows the options for print output
*/
private void printUsagePrintOutput() {
- System.err.println("USAGE: -print [-Dstart=i] [-Dend=i] [-Dcopies=i] [-Deven=true|false] "
- + " org.apache.fop.apps.Fop (..) -print \n"
- + "Example:\n"
- + "java -Dstart=1 -Dend=2 org.apache.Fop.apps.Fop infile.fo -print ");
+ System.err.println("USAGE: -print [from[-to][,even|odd]] [-copies numCopies]\n\n"
+ + "Example:\n"
+ + "all pages: Fop infile.fo -print\n"
+ + "all pages with two copies: Fop infile.fo -print -copies 2\n"
+ + "all pages starting with page 7: Fop infile.fo -print 7\n"
+ + "pages 2 to 3: Fop infile.fo -print 2-3\n"
+ + "only even page between 10 and 20: Fop infile.fo -print 10-20,even\n");
}
/**
diff --git a/src/java/org/apache/fop/cli/Main.java b/src/java/org/apache/fop/cli/Main.java
index e2297380d..43da8d966 100644
--- a/src/java/org/apache/fop/cli/Main.java
+++ b/src/java/org/apache/fop/cli/Main.java
@@ -28,6 +28,7 @@ import java.net.URL;
import java.util.List;
import org.apache.commons.io.IOUtils;
+
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
@@ -151,7 +152,9 @@ public class Main {
try {
options = new CommandLineOptions();
- options.parse(args);
+ if (!options.parse(args)) {
+ System.exit(1);
+ }
foUserAgent = options.getFOUserAgent();
String outputFormat = options.getOutputFormat();
diff --git a/src/java/org/apache/fop/render/PrintRendererConfigurator.java b/src/java/org/apache/fop/render/PrintRendererConfigurator.java
index ccff3baa1..674c357df 100644
--- a/src/java/org/apache/fop/render/PrintRendererConfigurator.java
+++ b/src/java/org/apache/fop/render/PrintRendererConfigurator.java
@@ -236,7 +236,7 @@ public class PrintRendererConfigurator extends AbstractRendererConfigurator
EmbedFontInfo[] embedFontInfos = finder.find(fontUrl, resolver, fontCache);
if (embedFontInfos == null) {
- return;
+ continue;
}
for (int i = 0, c = embedFontInfos.length; i < c; i++) {
diff --git a/src/java/org/apache/fop/render/awt/AWTRenderer.java b/src/java/org/apache/fop/render/awt/AWTRenderer.java
index e646f9b9c..2f2631786 100644
--- a/src/java/org/apache/fop/render/awt/AWTRenderer.java
+++ b/src/java/org/apache/fop/render/awt/AWTRenderer.java
@@ -43,8 +43,8 @@ import org.apache.fop.apps.MimeConstants;
import org.apache.fop.area.Area;
import org.apache.fop.area.PageViewport;
import org.apache.fop.render.awt.viewer.PreviewDialog;
-import org.apache.fop.render.awt.viewer.StatusListener;
import org.apache.fop.render.awt.viewer.Renderable;
+import org.apache.fop.render.awt.viewer.StatusListener;
import org.apache.fop.render.java2d.Java2DRenderer;
/**
@@ -202,7 +202,7 @@ public class AWTRenderer extends Java2DRenderer implements Pageable {
/** {@inheritDoc} */
public boolean supportsOutOfOrder() {
- return true; // TODO true?
+ return false;
}
/** {@inheritDoc} */
diff --git a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
index 0ffe3307a..1f3194949 100644
--- a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
+++ b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
@@ -121,9 +121,6 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
/** The 0-based current page number */
private int currentPageNumber = 0;
- /** The 0-based total number of rendered pages */
- private int numberOfPages;
-
/** true if antialiasing is set */
protected boolean antialiasing = true;
@@ -208,7 +205,7 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
public void stopRenderer() throws IOException {
log.debug("Java2DRenderer stopped");
renderingDone = true;
- numberOfPages = currentPageNumber;
+ int numberOfPages = currentPageNumber;
// TODO set all vars to null for gc
if (numberOfPages == 0) {
new FOPException("No page could be rendered");
@@ -238,7 +235,7 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
* @return The 0-based total number of rendered pages
*/
public int getNumberOfPages() {
- return numberOfPages;
+ return pageViewportList.size();
}
/**
diff --git a/src/java/org/apache/fop/render/print/PagesMode.java b/src/java/org/apache/fop/render/print/PagesMode.java
new file mode 100644
index 000000000..6879aa68d
--- /dev/null
+++ b/src/java/org/apache/fop/render/print/PagesMode.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.print;
+
+/** Enum class for pages mode (all, even, odd pages). */
+public final class PagesMode {
+
+ /** the all pages mode */
+ public static final PagesMode ALL = new PagesMode("all");
+ /** the even pages mode */
+ public static final PagesMode EVEN = new PagesMode("even");
+ /** the odd pages mode */
+ public static final PagesMode ODD = new PagesMode("odd");
+
+ private String name;
+
+ /**
+ * Constructor to add a new named item.
+ * @param name Name of the item.
+ */
+ private PagesMode(String name) {
+ this.name = name;
+ }
+
+ /** @return the name of the enum */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * Returns a PagesMode instance by name.
+ * @param name the name of the pages mode
+ * @return the pages mode
+ */
+ public static PagesMode byName(String name) {
+ if (PagesMode.ALL.getName().equalsIgnoreCase(name)) {
+ return PagesMode.ALL;
+ } else if (PagesMode.EVEN.getName().equalsIgnoreCase(name)) {
+ return PagesMode.EVEN;
+ } else if (PagesMode.ODD.getName().equalsIgnoreCase(name)) {
+ return PagesMode.ODD;
+ } else {
+ throw new IllegalArgumentException("Invalid value for PagesMode: " + name);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return "PagesMode:" + name;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/print/PrintRenderer.java b/src/java/org/apache/fop/render/print/PrintRenderer.java
index e4c159815..2774b5373 100644
--- a/src/java/org/apache/fop/render/print/PrintRenderer.java
+++ b/src/java/org/apache/fop/render/print/PrintRenderer.java
@@ -27,9 +27,11 @@ import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.IOException;
+import java.util.Map;
import java.util.Vector;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.render.java2d.Java2DRenderer;
/**
@@ -40,59 +42,155 @@ import org.apache.fop.render.java2d.Java2DRenderer;
*/
public class PrintRenderer extends Java2DRenderer implements Pageable {
- private static final int EVEN_AND_ALL = 0;
-
- private static final int EVEN = 1;
+ /**
+ * Printing parameter: the preconfigured PrinterJob to use,
+ * datatype: java.awt.print.PrinterJob
+ */
+ public static final String PRINTER_JOB = "printerjob";
+
+ /**
+ * Printing parameter: the pages to be printed (all, even or odd),
+ * datatype: the strings "all", "even" or "odd" or one of PagesMode.*
+ */
+ public static final String PAGES_MODE = "even-odd";
- private static final int ODD = 2;
+ /**
+ * Printing parameter: the page number (1-based) of the first page to be printed,
+ * datatype: a positive Integer
+ */
+ public static final String START_PAGE = "start-page";
+ /**
+ * Printing parameter: the page number (1-based) of the last page to be printed,
+ * datatype: a positive Integer
+ */
+ public static final String END_PAGE = "end-page";
+
+ /**
+ * Printing parameter: the number of copies of the document to be printed,
+ * datatype: a positive Integer
+ */
+ public static final String COPIES = "copies";
+
+
private int startNumber = 0;
-
private int endNumber = -1;
- private int mode = EVEN_AND_ALL;
+ private PagesMode mode = PagesMode.ALL;
private int copies = 1;
private PrinterJob printerJob;
/**
- * Creates a new PrintRenderer with the options set from system properties.
+ * Creates a new PrintRenderer with the options set from system properties if a custom
+ * PrinterJob is not given in FOUserAgent's renderer options.
*/
public PrintRenderer() {
- initializePrinterJob();
+ setupFromSystemProperties();
}
-
+
/**
* Creates a new PrintRenderer and allows you to pass in a specific PrinterJob instance
* that this renderer should work with.
* @param printerJob the PrinterJob instance
+ * @deprecated Please use the rendering options on the user agent to pass in the PrinterJob!
*/
public PrintRenderer(PrinterJob printerJob) {
+ this();
this.printerJob = printerJob;
printerJob.setPageable(this);
}
- private void initializePrinterJob() throws IllegalArgumentException {
+ private void initializePrinterJob() {
+ if (this.printerJob == null) {
+ printerJob = PrinterJob.getPrinterJob();
+ printerJob.setJobName("FOP Document");
+ printerJob.setCopies(copies);
+ if (System.getProperty("dialog") != null) {
+ if (!printerJob.printDialog()) {
+ throw new RuntimeException(
+ "Printing cancelled by operator");
+ }
+ }
+ printerJob.setPageable(this);
+ }
+ }
+
+ private void setupFromSystemProperties() {
+ //TODO Remove me! This is not a beautiful way to do this.
// read from command-line options
copies = getIntProperty("copies", 1);
- startNumber = getIntProperty("start", 1) - 1;
+ startNumber = getIntProperty("start", 1);
endNumber = getIntProperty("end", -1);
String str = System.getProperty("even");
if (str != null) {
- mode = Boolean.valueOf(str).booleanValue() ? EVEN : ODD;
+ mode = Boolean.valueOf(str).booleanValue() ? PagesMode.EVEN : PagesMode.ODD;
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void setUserAgent(FOUserAgent agent) {
+ super.setUserAgent(agent);
+
+ Map rendererOptions = agent.getRendererOptions();
+
+ Object printerJobO = rendererOptions.get(PrintRenderer.PRINTER_JOB);
+ if (printerJobO != null) {
+ if (!(printerJobO instanceof PrinterJob)) {
+ throw new IllegalArgumentException(
+ "Renderer option " + PrintRenderer.PRINTER_JOB
+ + " must be an instance of java.awt.print.PrinterJob, but an instance of "
+ + printerJobO.getClass().getName() + " was given.");
+ }
+ printerJob = (PrinterJob)printerJobO;
+ printerJob.setPageable(this);
+ }
+ Object o = rendererOptions.get(PrintRenderer.PAGES_MODE);
+ if (o != null) {
+ if (o instanceof PagesMode) {
+ this.mode = (PagesMode)o;
+ } else if (o instanceof String) {
+ this.mode = PagesMode.byName((String)o);
+ } else {
+ throw new IllegalArgumentException(
+ "Renderer option " + PrintRenderer.PAGES_MODE
+ + " must be an 'all', 'even', 'odd' or a PagesMode instance.");
+ }
}
+
+ o = rendererOptions.get(PrintRenderer.START_PAGE);
+ if (o != null) {
+ this.startNumber = getPositiveInteger(o);
+ }
+ o = rendererOptions.get(PrintRenderer.END_PAGE);
+ if (o != null) {
+ this.endNumber = getPositiveInteger(o);
+ }
+ if (this.endNumber >= 0 && this.endNumber < this.endNumber) {
+ this.endNumber = this.startNumber;
+ }
+ o = rendererOptions.get(PrintRenderer.COPIES);
+ if (o != null) {
+ this.copies = getPositiveInteger(o);
+ }
+ initializePrinterJob();
+ }
- printerJob = PrinterJob.getPrinterJob();
- printerJob.setJobName("FOP Document");
- printerJob.setCopies(copies);
- if (System.getProperty("dialog") != null) {
- if (!printerJob.printDialog()) {
+ private int getPositiveInteger(Object o) {
+ if (o instanceof Integer) {
+ Integer i = (Integer)o;
+ if (i.intValue() < 1) {
throw new IllegalArgumentException(
- "Printing cancelled by operator");
+ "Value must be a positive Integer");
}
+ return i.intValue();
+ } else if (o instanceof String) {
+ return Integer.parseInt((String)o);
+ } else {
+ throw new IllegalArgumentException(
+ "Value must be a positive integer");
}
- printerJob.setPageable(this);
}
/** @return the PrinterJob instance that this renderer prints to */
@@ -126,6 +224,7 @@ public class PrintRenderer extends Java2DRenderer implements Pageable {
this.startNumber = start;
}
+ /** {@inheritDoc} */
public void stopRenderer() throws IOException {
super.stopRenderer();
@@ -136,7 +235,8 @@ public class PrintRenderer extends Java2DRenderer implements Pageable {
Vector numbers = getInvalidPageNumbers();
for (int i = numbers.size() - 1; i > -1; i--) {
- // removePage(Integer.parseInt((String)numbers.elementAt(i)));
+ int page = ((Integer)numbers.elementAt(i)).intValue();
+ pageViewportList.remove(page - 1);
}
try {
@@ -149,7 +249,7 @@ public class PrintRenderer extends Java2DRenderer implements Pageable {
clearViewportList();
}
- public static int getIntProperty(String name, int def) {
+ private static int getIntProperty(String name, int def) {
String propValue = System.getProperty(name);
if (propValue != null) {
try {
@@ -166,20 +266,20 @@ public class PrintRenderer extends Java2DRenderer implements Pageable {
Vector vec = new Vector();
int max = getNumberOfPages();
boolean isValid;
- for (int i = 0; i < max; i++) {
+ for (int i = 1; i <= max; i++) {
isValid = true;
if (i < startNumber || i > endNumber) {
isValid = false;
- } else if (mode != EVEN_AND_ALL) {
- if (mode == EVEN && ((i + 1) % 2 != 0)) {
+ } else if (mode != PagesMode.ALL) {
+ if (mode == PagesMode.EVEN && (i % 2 != 0)) {
isValid = false;
- } else if (mode == ODD && ((i + 1) % 2 != 1)) {
+ } else if (mode == PagesMode.ODD && (i % 2 == 0)) {
isValid = false;
}
}
if (!isValid) {
- vec.add(Integer.toString(i));
+ vec.add(new Integer(i));
}
}
return vec;
@@ -219,6 +319,7 @@ public class PrintRenderer extends Java2DRenderer implements Pageable {
}
}
+ /** {@inheritDoc} */
public Printable getPrintable(int pageIndex)
throws IndexOutOfBoundsException {
return this;