From 78a328cba576a8857eb4a299741b7568736f075d Mon Sep 17 00:00:00 2001 From: "Andreas L. Delmelle" Date: Sat, 24 Sep 2005 22:00:02 +0000 Subject: [PATCH] Added custom Maker for page-height and page-width; use fallback values in case value is auto git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@291338 13f79535-47bb-0310-9956-ffa450edef68 --- conf/fop.xconf | 4 ++ src/java/org/apache/fop/apps/FOUserAgent.java | 50 ++++++++++++- .../org/apache/fop/fo/FOPropertyMapping.java | 11 ++- .../fop/fo/properties/PageDimensionMaker.java | 70 +++++++++++++++++++ .../testcases/page-dimension_auto_fallback.fo | 35 ++++++++++ 5 files changed, 162 insertions(+), 8 deletions(-) create mode 100644 src/java/org/apache/fop/fo/properties/PageDimensionMaker.java create mode 100644 test/fotree/testcases/page-dimension_auto_fallback.fo diff --git a/conf/fop.xconf b/conf/fop.xconf index db50f5ac4..d3fc5794b 100644 --- a/conf/fop.xconf +++ b/conf/fop.xconf @@ -18,6 +18,10 @@ the location of this file. + + + diff --git a/src/java/org/apache/fop/apps/FOUserAgent.java b/src/java/org/apache/fop/apps/FOUserAgent.java index d84715ba4..7a620deb5 100644 --- a/src/java/org/apache/fop/apps/FOUserAgent.java +++ b/src/java/org/apache/fop/apps/FOUserAgent.java @@ -66,7 +66,11 @@ import org.apache.fop.render.XMLHandlerRegistry; public class FOUserAgent { /** Defines the default resolution (72dpi) for FOP */ - public static final float DEFAULT_PX2MM = (25.4f / 72); //dpi (=25.4/dpi) + public static final float DEFAULT_PX2MM = (25.4f / 72); //dpi (=25.4/dpi) + /** Defines the default page-height */ + public static final String DEFAULT_PAGE_HEIGHT = "11in"; + /** Defines the default page-width */ + public static final String DEFAULT_PAGE_WIDTH = "8.26in"; /** Registry for XML handlers */ private XMLHandlerRegistry xmlHandlers = new XMLHandlerRegistry(); @@ -80,6 +84,8 @@ public class FOUserAgent { private PDFEncryptionParams pdfEncryptionParams; private float px2mm = DEFAULT_PX2MM; + private String pageHeight = DEFAULT_PAGE_HEIGHT; + private String pageWidth = DEFAULT_PAGE_WIDTH; private Map rendererOptions = new java.util.HashMap(); private File outputFile = null; private Renderer rendererOverride = null; @@ -471,7 +477,47 @@ public class FOUserAgent { public void setResolution(int dpi) { this.px2mm = (float)(25.4 / dpi); } - + + /** + * Gets the default page-height to use as fallback, + * in case page-height="auto" + * + * @return the page-height, as a String + */ + public String getPageHeight() { + return this.pageHeight; + } + + /** + * Sets the page-height to use as fallback, in case + * page-height="auto" + * + * @param pageHeight page-height as a String + */ + public void setPageHeight(String pageHeight) { + this.pageHeight = pageHeight; + } + + /** + * Gets the default page-width to use as fallback, + * in case page-width="auto" + * + * @return the page-width, as a String + */ + public String getPageWidth() { + return this.pageWidth; + } + + /** + * Sets the page-width to use as fallback, in case + * page-width="auto" + * + * @param pageWidth page-width as a String + */ + public void setPageWidth(String pageWidth) { + this.pageWidth = pageWidth; + } + /** * If to create hot links to footnotes and before floats. * @return True if hot links should be created diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java index 348f486a0..f60bbafbb 100644 --- a/src/java/org/apache/fop/fo/FOPropertyMapping.java +++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java @@ -44,6 +44,7 @@ import org.apache.fop.fo.properties.LengthRangeProperty; import org.apache.fop.fo.properties.LineHeightPropertyMaker; import org.apache.fop.fo.properties.ListProperty; import org.apache.fop.fo.properties.NumberProperty; +import org.apache.fop.fo.properties.PageDimensionMaker; import org.apache.fop.fo.properties.PositionShorthandParser; import org.apache.fop.fo.properties.Property; import org.apache.fop.fo.properties.PropertyMaker; @@ -2278,12 +2279,11 @@ public class FOPropertyMapping implements Constants { addPropertyMaker("odd-or-even", m); // page-height - l = new LengthProperty.Maker(PR_PAGE_HEIGHT); + l = new PageDimensionMaker(PR_PAGE_HEIGHT); l.setInherited(false); l.addEnum("auto", getEnumProperty(EN_AUTO, "AUTO")); l.addEnum("indefinite", getEnumProperty(EN_INDEFINITE, "INDEFINITE")); - // TODO: default should be 'auto' - l.setDefault("11in"); + l.setDefault("auto"); addPropertyMaker("page-height", l); // page-position @@ -2297,12 +2297,11 @@ public class FOPropertyMapping implements Constants { addPropertyMaker("page-position", m); // page-width - l = new LengthProperty.Maker(PR_PAGE_WIDTH); + l = new PageDimensionMaker(PR_PAGE_WIDTH); l.setInherited(false); l.addEnum("auto", getEnumProperty(EN_AUTO, "AUTO")); l.addEnum("indefinite", getEnumProperty(EN_INDEFINITE, "INDEFINITE")); - // TODO: default should be 'auto' - l.setDefault("8in"); + l.setDefault("auto"); addPropertyMaker("page-width", l); // precedence diff --git a/src/java/org/apache/fop/fo/properties/PageDimensionMaker.java b/src/java/org/apache/fop/fo/properties/PageDimensionMaker.java new file mode 100644 index 000000000..cf50fc41f --- /dev/null +++ b/src/java/org/apache/fop/fo/properties/PageDimensionMaker.java @@ -0,0 +1,70 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.fo.properties; + +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.properties.LengthProperty; + +/** + * Custom Maker for page-height / page-width + * + */ +public class PageDimensionMaker extends LengthProperty.Maker { + + /** + * Constructor + * + * @param propId the property Id + */ + public PageDimensionMaker(int propId) { + super(propId); + } + + /** + * Check the value of the page-width / page-height property. + * Return the default or user-defined fallback in case the value + * was specified as "auto" + * + * @see org.apache.fop.fo.properties.PropertyMaker#get(int, PropertyList, boolean, boolean) + */ + public Property get(int subpropId, PropertyList propertyList, + boolean tryInherit, boolean tryDefault) + throws PropertyException { + + Property p = super.get(0, propertyList, tryInherit, tryDefault); + + //TODO: add check for both height and width being specified as indefinite + // and use the fallback value (= set to "auto") + + if (p.isAuto()) { + FObj fo = propertyList.getFObj(); + + String fallbackValue = (propId == Constants.PR_PAGE_HEIGHT) + ? fo.getFOEventHandler().getUserAgent().getPageHeight() + : fo.getFOEventHandler().getUserAgent().getPageWidth(); + return make(propertyList, fallbackValue, fo); + } + + return p; + } + +} diff --git a/test/fotree/testcases/page-dimension_auto_fallback.fo b/test/fotree/testcases/page-dimension_auto_fallback.fo new file mode 100644 index 000000000..a0dcc7188 --- /dev/null +++ b/test/fotree/testcases/page-dimension_auto_fallback.fo @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + Testing page-height="auto" / page-width="auto" + + + -- 2.39.5