1 17 18 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 27 30 public class FontShorthandProperty extends ListProperty { 31 32 35 public static class Maker extends PropertyMaker { 36 37 private static final int[] PROP_IDS = { 38 Constants.PR_FONT_SIZE, Constants.PR_FONT_FAMILY, 39 Constants.PR_LINE_HEIGHT, Constants.PR_FONT_STYLE, 40 Constants.PR_FONT_VARIANT, Constants.PR_FONT_WEIGHT 41 }; 42 43 46 public Maker(int propId) { 47 super(propId); 48 } 49 50 53 public Property make(PropertyList propertyList, 54 String value, FObj fo) throws PropertyException { 55 56 try { 57 FontShorthandProperty newProp = new FontShorthandProperty(); 58 newProp.setSpecifiedValue(value); 59 60 String specVal = value; 61 Property prop = null; 62 if ("inherit".equals(specVal)) { 63 64 for (int i = PROP_IDS.length; --i >= 0;) { 65 prop = propertyList.getFromParent(PROP_IDS[i]); 66 newProp.addProperty(prop, i); 67 } 68 } else { 69 70 for (int pos = PROP_IDS.length; --pos >= 0;) { 71 newProp.addProperty(null, pos); 72 } 73 prop = checkEnumValues(specVal); 74 if (prop == null) { 75 80 int spaceIndex = value.indexOf(' '); 81 int quoteIndex = (value.indexOf('\'') == -1) 82 ? value.indexOf('\"') : value.indexOf('\''); 83 if (spaceIndex == -1 84 || (quoteIndex != -1 && spaceIndex > quoteIndex)) { 85 88 throw new PropertyException("Invalid property value: " 89 + "font=\"" + value + "\""); 90 } 91 PropertyMaker m = null; 92 int fromIndex = spaceIndex + 1; 93 int toIndex = specVal.length(); 94 97 boolean fontFamilyParsed = false; 98 int commaIndex = value.indexOf(','); 99 while (!fontFamilyParsed) { 100 103 if (commaIndex == -1) { 104 107 if (quoteIndex != -1) { 108 110 fromIndex = quoteIndex; 111 } 112 m = FObj.getPropertyMakerFor(PROP_IDS[1]); 113 prop = m.make(propertyList, specVal.substring(fromIndex), fo); 114 newProp.addProperty(prop, 1); 115 fontFamilyParsed = true; 116 } else { 117 if (quoteIndex != -1 && quoteIndex < commaIndex) { 118 122 fromIndex = quoteIndex; 123 quoteIndex = -1; 124 } else { 125 fromIndex = value.lastIndexOf(' ', commaIndex) + 1; 126 } 127 commaIndex = -1; 128 } 129 } 130 toIndex = fromIndex - 1; 131 fromIndex = value.lastIndexOf(' ', toIndex - 1) + 1; 132 value = specVal.substring(fromIndex, toIndex); 133 int slashIndex = value.indexOf('/'); 134 String fontSize = value.substring(0, 135 (slashIndex == -1) ? value.length() : slashIndex); 136 m = FObj.getPropertyMakerFor(PROP_IDS[0]); 137 prop = m.make(propertyList, fontSize, fo); 138 141 propertyList.putExplicit(PROP_IDS[0], prop); 142 newProp.addProperty(prop, 0); 143 if (slashIndex != -1) { 144 145 String lineHeight = value.substring(slashIndex + 1); 146 m = FObj.getPropertyMakerFor(PROP_IDS[2]); 147 prop = m.make(propertyList, lineHeight, fo); 148 newProp.addProperty(prop, 2); 149 } 150 if (fromIndex != 0) { 151 toIndex = fromIndex - 1; 152 value = specVal.substring(0, toIndex); 153 fromIndex = 0; 154 spaceIndex = value.indexOf(' '); 155 do { 156 toIndex = (spaceIndex == -1) ? value.length() : spaceIndex; 157 String val = value.substring(fromIndex, toIndex); 158 for (int i = 6; --i >= 3;) { 159 if (newProp.list.get(i) == null) { 160 161 m = FObj.getPropertyMakerFor(PROP_IDS[i]); 162 val = m.checkValueKeywords(val); 163 prop = m.checkEnumValues(val); 164 if (prop != null) { 165 newProp.addProperty(prop, i); 166 } 167 } 168 } 169 fromIndex = toIndex + 1; 170 spaceIndex = value.indexOf(' ', fromIndex); 171 } while (toIndex != value.length()); 172 } 173 } else { 174 log.warn("Enum values other than \"inherit\"" 176 + " not yet supported for the font shorthand."); 177 return null; 178 } 179 } 180 if (newProp.list.get(0) == null || newProp.list.get(1) == null) { 181 throw new PropertyException("Invalid property value: " 182 + "font-size and font-family are required for the font shorthand" 183 + "\nfont=\"" + value + "\""); 184 } 185 return newProp; 186 } catch (PropertyException pe) { 187 pe.setLocator(propertyList.getFObj().getLocator()); 188 pe.setPropertyName(getName()); 189 throw pe; 190 } 191 } 192 } 193 194 private void addProperty(Property prop, int pos) { 195 while (list.size() < (pos + 1)) { 196 list.add(null); 197 } 198 list.set(pos, prop); 199 } 200 } 201 | Popular Tags |