You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ad...@apache.org on 2005/09/25 00:00:11 UTC

svn commit: r291338 - in /xmlgraphics/fop/trunk: conf/ src/java/org/apache/fop/apps/ src/java/org/apache/fop/fo/ src/java/org/apache/fop/fo/properties/ test/fotree/testcases/

Author: adelmelle
Date: Sat Sep 24 15:00:02 2005
New Revision: 291338

URL: http://svn.apache.org/viewcvs?rev=291338&view=rev
Log:
Added custom Maker for page-height and page-width; use fallback values in case value is auto

Added:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PageDimensionMaker.java   (with props)
    xmlgraphics/fop/trunk/test/fotree/testcases/page-dimension_auto_fallback.fo   (with props)
Modified:
    xmlgraphics/fop/trunk/conf/fop.xconf
    xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOPropertyMapping.java

Modified: xmlgraphics/fop/trunk/conf/fop.xconf
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/conf/fop.xconf?rev=291338&r1=291337&r2=291338&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/conf/fop.xconf (original)
+++ xmlgraphics/fop/trunk/conf/fop.xconf Sat Sep 24 15:00:02 2005
@@ -18,6 +18,10 @@
     <base url="./"/>
     <!-- pixel to millimeter to specify dpi, 72dpi -->
     <pixelToMillimeter value="0.35277777777777777778"/>
+    <!-- default page-height and page-width, in case
+         value is specified as auto -->
+    <pageHeight value="11in"/>
+    <pageWidth value="8.26in"/>
   </userAgent>
 
   <!-- Information for specific renderers -->

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java?rev=291338&r1=291337&r2=291338&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java Sat Sep 24 15:00:02 2005
@@ -66,7 +66,11 @@
 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 @@
     
     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 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

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOPropertyMapping.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOPropertyMapping.java?rev=291338&r1=291337&r2=291338&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOPropertyMapping.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOPropertyMapping.java Sat Sep 24 15:00:02 2005
@@ -44,6 +44,7 @@
 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 @@
         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 @@
         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

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PageDimensionMaker.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PageDimensionMaker.java?rev=291338&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PageDimensionMaker.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PageDimensionMaker.java Sat Sep 24 15:00:02 2005
@@ -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;
+    }
+    
+}

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PageDimensionMaker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PageDimensionMaker.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: xmlgraphics/fop/trunk/test/fotree/testcases/page-dimension_auto_fallback.fo
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/test/fotree/testcases/page-dimension_auto_fallback.fo?rev=291338&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/fotree/testcases/page-dimension_auto_fallback.fo (added)
+++ xmlgraphics/fop/trunk/test/fotree/testcases/page-dimension_auto_fallback.fo Sat Sep 24 15:00:02 2005
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+  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:$ -->
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
+         xmlns:test="http://xmlgraphics.apache.org/fop/test">
+  <fo:layout-master-set>
+    <fo:simple-page-master master-name="normal" page-width="auto" page-height="auto" 
+          margin="20pt">
+      <!-- page-width should properly fall back to 8.26 * 72000 -->
+      <test:assert property="page-width" expected="594720mpt" />
+      <!-- page-height should properly fall back to 11 * 72000 -->
+      <test:assert property="page-height" expected="792000mpt" />
+      <fo:region-body />
+    </fo:simple-page-master>
+  </fo:layout-master-set>
+  <fo:page-sequence master-reference="normal">
+    <fo:flow flow-name="xsl-region-body">
+      <fo:block>Testing page-height="auto" / page-width="auto"</fo:block>
+    </fo:flow>
+  </fo:page-sequence>
+</fo:root>

Propchange: xmlgraphics/fop/trunk/test/fotree/testcases/page-dimension_auto_fallback.fo
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org