1 17 18 19 20 package org.apache.fop.fo.properties; 21 22 import java.util.List ; 24 25 import org.apache.fop.datatypes.Length; 26 import org.apache.fop.datatypes.Numeric; 27 import org.apache.fop.datatypes.PercentBaseContext; 28 import org.apache.fop.fo.Constants; 29 import org.apache.fop.fo.PropertyList; 30 import org.apache.fop.fo.expr.PropertyException; 31 import org.apache.fop.fonts.Font; 32 import org.apache.fop.fonts.FontInfo; 33 import org.apache.fop.fonts.FontMetrics; 34 import org.apache.fop.fonts.FontTriplet; 35 36 39 public class CommonFont { 40 41 44 private String [] fontFamily; 45 46 49 public int fontSelectionStrategy; 50 51 54 public Length fontSize; 55 56 59 public int fontStretch; 60 61 64 public Numeric fontSizeAdjust; 65 66 69 public int fontStyle; 70 71 74 public int fontVariant; 75 76 79 public int fontWeight; 80 81 private Font fontState; 82 83 87 public CommonFont(PropertyList pList) throws PropertyException { 88 List lst = pList.get(Constants.PR_FONT_FAMILY).getList(); 89 fontFamily = new String [lst.size()]; 90 for (int i = 0, c = lst.size(); i < c; i++) { 91 fontFamily[i] = ((Property)lst.get(i)).getString(); 92 } 93 if (fontFamily.length == 0) { 94 fontFamily = new String [] {"any"}; 96 } 97 fontSelectionStrategy = pList.get(Constants.PR_FONT_SELECTION_STRATEGY).getEnum(); 98 fontSize = pList.get(Constants.PR_FONT_SIZE).getLength(); 99 fontStretch = pList.get(Constants.PR_FONT_STRETCH).getEnum(); 100 fontSizeAdjust = pList.get(Constants.PR_FONT_SIZE_ADJUST).getNumeric(); 101 fontStyle = pList.get(Constants.PR_FONT_STYLE).getEnum(); 102 fontVariant = pList.get(Constants.PR_FONT_VARIANT).getEnum(); 103 fontWeight = pList.get(Constants.PR_FONT_WEIGHT).getEnum(); 104 } 105 106 107 public String getFirstFontFamily() { 108 return this.fontFamily[0]; 109 } 110 111 112 public String [] getFontFamily() { 113 return this.fontFamily; 114 } 115 116 120 public void overrideFontFamily(String value) { 121 this.fontFamily = new String [] {value}; 122 123 } 124 125 131 public Font getFontState(FontInfo fontInfo, PercentBaseContext context) { 132 if (fontState == null) { 133 134 135 int font_weight = 400; 136 if (fontWeight == Constants.EN_BOLDER) { 137 } else if (fontWeight == Constants.EN_LIGHTER) { 139 } else { 141 switch (fontWeight) { 142 case Constants.EN_100: font_weight = 100; break; 143 case Constants.EN_200: font_weight = 200; break; 144 case Constants.EN_300: font_weight = 300; break; 145 case Constants.EN_400: font_weight = 400; break; 146 case Constants.EN_500: font_weight = 500; break; 147 case Constants.EN_600: font_weight = 600; break; 148 case Constants.EN_700: font_weight = 700; break; 149 case Constants.EN_800: font_weight = 800; break; 150 case Constants.EN_900: font_weight = 900; break; 151 } 152 } 153 154 String style; 155 switch (fontStyle) { 156 case Constants.EN_ITALIC: 157 style = "italic"; 158 break; 159 case Constants.EN_OBLIQUE: 160 style = "oblique"; 161 break; 162 case Constants.EN_BACKSLANT: 163 style = "backslant"; 164 break; 165 default: 166 style = "normal"; 167 } 168 FontTriplet triplet = fontInfo.fontLookup(getFontFamily(), style, 172 font_weight); 173 fontState = fontInfo.getFontInstance(triplet, fontSize.getValue(context)); 174 } 175 return fontState; 176 } 177 178 } 179 | Popular Tags |