KickJava   Java API By Example, From Geeks To Geeks.

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


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: LineHeightPropertyMaker.java 488960 2006-12-20 08:34:28Z spepping $ */
19
20 package org.apache.fop.fo.properties;
21
22 import org.apache.fop.datatypes.Numeric;
23 import org.apache.fop.fo.Constants;
24 import org.apache.fop.fo.FObj;
25 import org.apache.fop.fo.PropertyList;
26 import org.apache.fop.fo.expr.PropertyException;
27
28 /**
29  * A maker which calculates the line-height property.
30  * This property maker is special because line-height inherits the specified
31  * value, instead of the computed value.
32  * So when a line-height is create based on an attribute, the specified value
33  * is stored in the property and in compute() the stored specified value of
34  * the nearest specified is used to recalculate the line-height.
35  */

36
37 public class LineHeightPropertyMaker extends SpaceProperty.Maker {
38     /**
39      * Create a maker for line-height.
40      * @param propId the is for linehight.
41      */

42     public LineHeightPropertyMaker(int propId) {
43         super(propId);
44     }
45
46     /**
47      * @see PropertyMaker#make(PropertyList, String, FObj)
48      * @throws PropertyException
49      */

50     public Property make(PropertyList propertyList, String JavaDoc value, FObj fo)
51             throws PropertyException {
52         /* if value was specified as a number/length/percentage then
53          * conditionality and precedence components are overridden
54          */

55         Property p = super.make(propertyList, value, fo);
56         p.getSpace().setConditionality(
57                 EnumProperty.getInstance(Constants.EN_RETAIN, "RETAIN"), true);
58         p.getSpace().setPrecedence(
59                 EnumProperty.getInstance(Constants.EN_FORCE, "FORCE"), true);
60         return p;
61     }
62     
63     /**
64      * Recalculate the line-height value based on the nearest specified
65      * value.
66      * @see PropertyMaker#compute(PropertyList)
67      */

68     protected Property compute(PropertyList propertyList) throws PropertyException {
69         // recalculate based on last specified value
70
// Climb up propertylist and find last spec'd value
71
Property specProp = propertyList.getNearestSpecified(propId);
72         if (specProp != null) {
73             String JavaDoc specVal = specProp.getSpecifiedValue();
74             if (specVal != null) {
75                 return make(propertyList, specVal,
76                             propertyList.getParentFObj());
77             }
78         }
79         return null;
80     }
81
82     /**
83      * @see SpaceProperty.Maker#convertProperty(Property, PropertyList, FObj)
84      */

85     public Property convertProperty(Property p,
86             PropertyList propertyList,
87             FObj fo) throws PropertyException {
88         Numeric numval = p.getNumeric();
89         if (numval != null && numval.getDimension() == 0) {
90             p = new PercentLength(numval.getNumericValue(), getPercentBase(fo, propertyList));
91             Property spaceProp = super.convertProperty(p, propertyList, fo);
92             spaceProp.setSpecifiedValue(String.valueOf(numval.getNumericValue()));
93             return spaceProp;
94         }
95         return super.convertProperty(p, propertyList, fo);
96     }
97 }
98
Popular Tags