1 17 18 19 20 package org.apache.fop.fo.properties; 21 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import java.awt.Color ; 26 27 import org.apache.fop.apps.FOUserAgent; 28 import org.apache.fop.fo.Constants; 29 import org.apache.fop.fo.PropertyList; 30 import org.apache.fop.fo.expr.PropertyException; 31 32 35 public class CommonTextDecoration { 36 37 private static final int UNDERLINE = 1; 39 private static final int OVERLINE = 2; 40 private static final int LINE_THROUGH = 4; 41 private static final int BLINK = 8; 42 43 private int decoration; 44 private Color underColor; 45 private Color overColor; 46 private Color throughColor; 47 48 51 public CommonTextDecoration() { 52 } 53 54 60 public static CommonTextDecoration createFromPropertyList(PropertyList pList) 61 throws PropertyException { 62 return calcTextDecoration(pList); 63 } 64 65 private static CommonTextDecoration calcTextDecoration(PropertyList pList) 66 throws PropertyException { 67 CommonTextDecoration deco = null; 68 PropertyList parentList = pList.getParentPropertyList(); 69 if (parentList != null) { 70 deco = calcTextDecoration(parentList); 72 } 73 Property textDecoProp = pList.getExplicit(Constants.PR_TEXT_DECORATION); 75 if (textDecoProp != null) { 76 List list = textDecoProp.getList(); 77 Iterator i = list.iterator(); 78 while (i.hasNext()) { 79 Property prop = (Property)i.next(); 80 int propEnum = prop.getEnum(); 81 FOUserAgent ua = (pList == null) 82 ? null 83 : (pList.getFObj() == null ? null : pList.getFObj().getUserAgent()); 84 if (propEnum == Constants.EN_NONE) { 85 if (deco != null) { 86 deco.decoration = 0; 87 } 88 return deco; 89 } else if (propEnum == Constants.EN_UNDERLINE) { 90 if (deco == null) { 91 deco = new CommonTextDecoration(); 92 } 93 deco.decoration |= UNDERLINE; 94 deco.underColor = pList.get(Constants.PR_COLOR).getColor(ua); 95 } else if (propEnum == Constants.EN_NO_UNDERLINE) { 96 if (deco != null) { 97 deco.decoration &= OVERLINE | LINE_THROUGH | BLINK; 98 deco.underColor = pList.get(Constants.PR_COLOR).getColor(ua); 99 } 100 } else if (propEnum == Constants.EN_OVERLINE) { 101 if (deco == null) { 102 deco = new CommonTextDecoration(); 103 } 104 deco.decoration |= OVERLINE; 105 deco.overColor = pList.get(Constants.PR_COLOR).getColor(ua); 106 } else if (propEnum == Constants.EN_NO_OVERLINE) { 107 if (deco != null) { 108 deco.decoration &= UNDERLINE | LINE_THROUGH | BLINK; 109 deco.overColor = pList.get(Constants.PR_COLOR).getColor(ua); 110 } 111 } else if (propEnum == Constants.EN_LINE_THROUGH) { 112 if (deco == null) { 113 deco = new CommonTextDecoration(); 114 } 115 deco.decoration |= LINE_THROUGH; 116 deco.throughColor = pList.get(Constants.PR_COLOR).getColor(ua); 117 } else if (propEnum == Constants.EN_NO_LINE_THROUGH) { 118 if (deco != null) { 119 deco.decoration &= UNDERLINE | OVERLINE | BLINK; 120 deco.throughColor = pList.get(Constants.PR_COLOR).getColor(ua); 121 } 122 } else if (propEnum == Constants.EN_BLINK) { 123 if (deco == null) { 124 deco = new CommonTextDecoration(); 125 } 126 deco.decoration |= BLINK; 127 } else if (propEnum == Constants.EN_NO_BLINK) { 128 if (deco != null) { 129 deco.decoration &= UNDERLINE | OVERLINE | LINE_THROUGH; 130 } 131 } else { 132 throw new PropertyException("Illegal value encountered: " + prop.getString()); 133 } 134 } 135 } 136 return deco; 137 } 138 139 140 public boolean hasUnderline() { 141 return (this.decoration & UNDERLINE) != 0; 142 } 143 144 145 public boolean hasOverline() { 146 return (this.decoration & OVERLINE) != 0; 147 } 148 149 150 public boolean hasLineThrough() { 151 return (this.decoration & LINE_THROUGH) != 0; 152 } 153 154 155 public boolean isBlinking() { 156 return (this.decoration & BLINK) != 0; 157 } 158 159 160 public Color getUnderlineColor() { 161 return this.underColor; 162 } 163 164 165 public Color getOverlineColor() { 166 return this.overColor; 167 } 168 169 170 public Color getLineThroughColor() { 171 return this.throughColor; 172 } 173 174 } 175 | Popular Tags |