git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@291338 13f79535-47bb-0310-9956-ffa450edef68pull/31/head
@@ -18,6 +18,10 @@ the location of this file. | |||
<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 --> |
@@ -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 |
@@ -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 |
@@ -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; | |||
} | |||
} |
@@ -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> |