KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > properties > PageDimensionMaker


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: PageDimensionMaker.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.fo.properties;
21
22 import org.apache.fop.fo.Constants;
23 import org.apache.fop.fo.FObj;
24 import org.apache.fop.fo.PropertyList;
25 import org.apache.fop.fo.expr.PropertyException;
26 import org.apache.fop.fo.properties.LengthProperty;
27
28 /**
29  * Custom Maker for page-height / page-width
30  *
31  */

32 public class PageDimensionMaker extends LengthProperty.Maker {
33     
34     /**
35      * Constructor
36      *
37      * @param propId the property Id
38      */

39     public PageDimensionMaker(int propId) {
40         super(propId);
41     }
42     
43     /**
44      * Check the value of the page-width / page-height property.
45      * Return the default or user-defined fallback in case the value
46      * was specified as "auto"
47      *
48      * @see org.apache.fop.fo.properties.PropertyMaker#get(int, PropertyList, boolean, boolean)
49      */

50     public Property get(int subpropId, PropertyList propertyList,
51                         boolean tryInherit, boolean tryDefault)
52             throws PropertyException {
53         
54         Property p = super.get(0, propertyList, tryInherit, tryDefault);
55         FObj fo = propertyList.getFObj();
56         String JavaDoc fallbackValue = (propId == Constants.PR_PAGE_HEIGHT)
57             ? fo.getFOEventHandler().getUserAgent().getPageHeight()
58                     : fo.getFOEventHandler().getUserAgent().getPageWidth();
59         
60         if (p.getEnum() == Constants.EN_INDEFINITE) {
61             int otherId = (propId == Constants.PR_PAGE_HEIGHT)
62                 ? Constants.PR_PAGE_WIDTH : Constants.PR_PAGE_HEIGHT;
63             int writingMode = propertyList.get(Constants.PR_WRITING_MODE).getEnum();
64             int refOrientation = propertyList.get(Constants.PR_REFERENCE_ORIENTATION)
65                         .getNumeric().getValue();
66             if (propertyList.getExplicit(otherId) != null
67                     && propertyList.getExplicit(otherId).getEnum() == Constants.EN_INDEFINITE) {
68                 //both set to "indefinite":
69
//determine which one of the two defines the dimension
70
//in block-progression-direction, and set the other to
71
//"auto"
72
if ((writingMode != Constants.EN_TB_RL
73                         && (refOrientation == 0
74                                 || refOrientation == 180
75                                 || refOrientation == -180))
76                      || (writingMode == Constants.EN_TB_RL
77                              && (refOrientation == 90
78                                      || refOrientation == 270
79                                      || refOrientation == -270))) {
80                     //set page-width to "auto" = use the fallback from FOUserAgent
81
if (propId == Constants.PR_PAGE_WIDTH) {
82                         fo.getLogger().warn("Both page-width and page-height set to "
83                                 + "\"indefinite\". Forcing page-width to \"auto\"");
84                         return make(propertyList, fallbackValue, fo);
85                     }
86                 } else {
87                     //set page-height to "auto" = use fallback from FOUserAgent
88
fo.getLogger().warn("Both page-width and page-height set to "
89                             + "\"indefinite\". Forcing page-height to \"auto\"");
90                     if (propId == Constants.PR_PAGE_HEIGHT) {
91                         return make(propertyList, fallbackValue, fo);
92                     }
93                 }
94             }
95         } else if (p.isAuto()) {
96             return make(propertyList, fallbackValue, fo);
97         }
98         
99         return p;
100     }
101 }
102
Popular Tags