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: CommonTextDecoration.java 474225 2006-11-13 10:08:19Z jeremias $ */
019:
020: package org.apache.fop.fo.properties;
021:
022: import java.util.Iterator;
023: import java.util.List;
024:
025: import java.awt.Color;
026:
027: import org.apache.fop.apps.FOUserAgent;
028: import org.apache.fop.fo.Constants;
029: import org.apache.fop.fo.PropertyList;
030: import org.apache.fop.fo.expr.PropertyException;
031:
032: /**
033: * Stores all information concerning text-decoration.
034: */
035: public class CommonTextDecoration {
036:
037: //using a bit-mask here
038: private static final int UNDERLINE = 1;
039: private static final int OVERLINE = 2;
040: private static final int LINE_THROUGH = 4;
041: private static final int BLINK = 8;
042:
043: private int decoration;
044: private Color underColor;
045: private Color overColor;
046: private Color throughColor;
047:
048: /**
049: * Creates a new CommonTextDecoration object with default values.
050: */
051: public CommonTextDecoration() {
052: }
053:
054: /**
055: * Creates a CommonTextDecoration object from a property list.
056: * @param pList the property list to build the object for
057: * @return a CommonTextDecoration object or null if the obj would only have default values
058: * @throws PropertyException if there's a problem while processing the property
059: */
060: public static CommonTextDecoration createFromPropertyList(
061: PropertyList pList) throws PropertyException {
062: return calcTextDecoration(pList);
063: }
064:
065: private static CommonTextDecoration calcTextDecoration(
066: PropertyList pList) throws PropertyException {
067: CommonTextDecoration deco = null;
068: PropertyList parentList = pList.getParentPropertyList();
069: if (parentList != null) {
070: //Parent is checked first
071: deco = calcTextDecoration(parentList);
072: }
073: //For rules, see XSL 1.0, chapters 5.5.6 and 7.16.4
074: Property textDecoProp = pList
075: .getExplicit(Constants.PR_TEXT_DECORATION);
076: if (textDecoProp != null) {
077: List list = textDecoProp.getList();
078: Iterator i = list.iterator();
079: while (i.hasNext()) {
080: Property prop = (Property) i.next();
081: int propEnum = prop.getEnum();
082: FOUserAgent ua = (pList == null) ? null : (pList
083: .getFObj() == null ? null : pList.getFObj()
084: .getUserAgent());
085: if (propEnum == Constants.EN_NONE) {
086: if (deco != null) {
087: deco.decoration = 0;
088: }
089: return deco;
090: } else if (propEnum == Constants.EN_UNDERLINE) {
091: if (deco == null) {
092: deco = new CommonTextDecoration();
093: }
094: deco.decoration |= UNDERLINE;
095: deco.underColor = pList.get(Constants.PR_COLOR)
096: .getColor(ua);
097: } else if (propEnum == Constants.EN_NO_UNDERLINE) {
098: if (deco != null) {
099: deco.decoration &= OVERLINE | LINE_THROUGH
100: | BLINK;
101: deco.underColor = pList.get(Constants.PR_COLOR)
102: .getColor(ua);
103: }
104: } else if (propEnum == Constants.EN_OVERLINE) {
105: if (deco == null) {
106: deco = new CommonTextDecoration();
107: }
108: deco.decoration |= OVERLINE;
109: deco.overColor = pList.get(Constants.PR_COLOR)
110: .getColor(ua);
111: } else if (propEnum == Constants.EN_NO_OVERLINE) {
112: if (deco != null) {
113: deco.decoration &= UNDERLINE | LINE_THROUGH
114: | BLINK;
115: deco.overColor = pList.get(Constants.PR_COLOR)
116: .getColor(ua);
117: }
118: } else if (propEnum == Constants.EN_LINE_THROUGH) {
119: if (deco == null) {
120: deco = new CommonTextDecoration();
121: }
122: deco.decoration |= LINE_THROUGH;
123: deco.throughColor = pList.get(Constants.PR_COLOR)
124: .getColor(ua);
125: } else if (propEnum == Constants.EN_NO_LINE_THROUGH) {
126: if (deco != null) {
127: deco.decoration &= UNDERLINE | OVERLINE | BLINK;
128: deco.throughColor = pList.get(
129: Constants.PR_COLOR).getColor(ua);
130: }
131: } else if (propEnum == Constants.EN_BLINK) {
132: if (deco == null) {
133: deco = new CommonTextDecoration();
134: }
135: deco.decoration |= BLINK;
136: } else if (propEnum == Constants.EN_NO_BLINK) {
137: if (deco != null) {
138: deco.decoration &= UNDERLINE | OVERLINE
139: | LINE_THROUGH;
140: }
141: } else {
142: throw new PropertyException(
143: "Illegal value encountered: "
144: + prop.getString());
145: }
146: }
147: }
148: return deco;
149: }
150:
151: /** @return true if underline is active */
152: public boolean hasUnderline() {
153: return (this .decoration & UNDERLINE) != 0;
154: }
155:
156: /** @return true if overline is active */
157: public boolean hasOverline() {
158: return (this .decoration & OVERLINE) != 0;
159: }
160:
161: /** @return true if line-through is active */
162: public boolean hasLineThrough() {
163: return (this .decoration & LINE_THROUGH) != 0;
164: }
165:
166: /** @return true if blink is active */
167: public boolean isBlinking() {
168: return (this .decoration & BLINK) != 0;
169: }
170:
171: /** @return the color of the underline mark */
172: public Color getUnderlineColor() {
173: return this .underColor;
174: }
175:
176: /** @return the color of the overline mark */
177: public Color getOverlineColor() {
178: return this .overColor;
179: }
180:
181: /** @return the color of the line-through mark */
182: public Color getLineThroughColor() {
183: return this.throughColor;
184: }
185:
186: }
|