001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: LengthBase.java 495371 2007-01-11 21:03:07Z adelmelle $ */
019:
020: package org.apache.fop.datatypes;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.apache.fop.fo.Constants;
025: import org.apache.fop.fo.FObj;
026: import org.apache.fop.fo.PropertyList;
027: import org.apache.fop.fo.expr.PropertyException;
028: import org.apache.fop.fo.flow.Character;
029: import org.apache.fop.fo.flow.ExternalGraphic;
030: import org.apache.fop.fo.flow.InstreamForeignObject;
031: import org.apache.fop.layoutmgr.inline.LeafNodeLayoutManager;
032:
033: /**
034: * Models a length which can be used as a factor in a percentage length
035: * calculation
036: */
037: public class LengthBase implements PercentBase {
038: // Standard kinds of percent-based length
039: /** constant for a custom percent-based length */
040: public static final int CUSTOM_BASE = 0;
041: /** constant for a font-size percent-based length */
042: public static final int FONTSIZE = 1;
043: /** constant for an inh font-size percent-based length */
044: public static final int INH_FONTSIZE = 2;
045: /** constant for a containing box percent-based length */
046: public static final int PARENT_AREA_WIDTH = 3;
047: /** constant for a containing refarea percent-based length */
048: public static final int CONTAINING_REFAREA_WIDTH = 4;
049: /** constant for a containing block percent-based length */
050: public static final int CONTAINING_BLOCK_WIDTH = 5;
051: /** constant for a containing block percent-based length */
052: public static final int CONTAINING_BLOCK_HEIGHT = 6;
053: /** constant for a image intrinsic percent-based length */
054: public static final int IMAGE_INTRINSIC_WIDTH = 7;
055: /** constant for a image intrinsic percent-based length */
056: public static final int IMAGE_INTRINSIC_HEIGHT = 8;
057: /** constant for a image background position horizontal percent-based length */
058: public static final int IMAGE_BACKGROUND_POSITION_HORIZONTAL = 9;
059: /** constant for a image background position vertical percent-based length */
060: public static final int IMAGE_BACKGROUND_POSITION_VERTICAL = 10;
061: /** constant for a table-unit-based length */
062: public static final int TABLE_UNITS = 11;
063: /** constant for a alignment adjust percent-based length */
064: public static final int ALIGNMENT_ADJUST = 12;
065:
066: /**
067: * logging instance
068: */
069: protected static Log log = LogFactory.getLog(LengthBase.class);
070:
071: /**
072: * The FO for which this property is to be calculated.
073: */
074: protected/* final */FObj fobj;
075:
076: /**
077: * One of the defined types of LengthBase
078: */
079: private/* final */int baseType;
080:
081: /** For percentages based on other length properties */
082: private Length baseLength;
083:
084: /**
085: * Constructor
086: * @param parentFO parent FO for this
087: * @param plist property list for this
088: * @param baseType a constant defining the type of teh percent base
089: * @throws PropertyException In case an problem occurs while evaluating values
090: */
091: public LengthBase(PropertyList plist, int baseType)
092: throws PropertyException {
093: this .fobj = plist.getFObj();
094: this .baseType = baseType;
095: switch (baseType) {
096: case FONTSIZE:
097: this .baseLength = plist.get(Constants.PR_FONT_SIZE)
098: .getLength();
099: break;
100: case INH_FONTSIZE:
101: this .baseLength = plist
102: .getInherited(Constants.PR_FONT_SIZE).getLength();
103: break;
104: default:
105: // TODO: pacify CheckStyle
106: // throw new RuntimeException();
107: break;
108: }
109: }
110:
111: /**
112: * @return the dimension of this object (always 1)
113: */
114: public int getDimension() {
115: return 1;
116: }
117:
118: /**
119: * @return the base value of this object (always 1.0)
120: */
121: public double getBaseValue() {
122: return 1.0;
123: }
124:
125: /**
126: * @see org.apache.fop.datatypes.PercentBase#getBaseLength(PercentBaseContext)
127: */
128: public int getBaseLength(PercentBaseContext context)
129: throws PropertyException {
130: int baseLen = 0;
131: if (context != null) {
132: if (baseType == FONTSIZE || baseType == INH_FONTSIZE) {
133: return baseLength.getValue(context);
134: }
135: baseLen = context.getBaseLength(baseType, fobj);
136: } else {
137: log.error("getBaseLength called without context");
138: }
139: return baseLen;
140: }
141:
142: }
|