1 package com.etymon.pj.object; 2 3 import java.io.*; 4 import java.util.*; 5 import com.etymon.pj.*; 6 import com.etymon.pj.exception.*; 7 8 13 public class PjFontDescriptor 14 extends PjDictionary { 15 16 19 private static String [] PjFDFlagBitNames = { 20 "FixedWidth", "Serif", "Symbolic", "Script", "Reserved5", "RomanCharSet", "Italic", "Reserved8", "Reserved9", "Reserved10", "Reserved11", "Reserved12", "Reserved13", "Reserved14", "Reserved15", "Reserved16", "AllCap", "SmallCap", "ForceBoldAtSmallSizes", "Reserved20", "Reserved21", "Reserved22", "Reserved23", "Reserved24", "Reserved25", "Reserved26", "Reserved27", "Reserved28", "Reserved29", "Reserved30", "Reserved31", "Reserved32" }; 53 54 57 public PjFontDescriptor() { 58 super(); 59 _h.put(PjName.TYPE, PjName.FONTDESCRIPTOR); 60 } 61 62 66 public PjFontDescriptor(Hashtable h) { 67 super(h); 68 _h.put(PjName.TYPE, PjName.FONTDESCRIPTOR); 69 } 70 71 72 73 public void setAscent(PjNumber ascent) { 74 _h.put(PjName.ASCENT, ascent); 75 } 76 77 public PjObject getAscent() throws InvalidPdfObjectException { 78 return hget(PjName.ASCENT); 79 } 80 81 public void setCapHeight(PjNumber capheight) { 82 _h.put(PjName.CAPHEIGHT, capheight); 83 } 84 85 public PjObject getCapHeight() throws InvalidPdfObjectException { 86 return hget(PjName.CAPHEIGHT); 87 } 88 89 public void setDescent(PjNumber descent) { 90 _h.put(PjName.DESCENT, descent); 91 } 92 93 public PjObject getDescent() throws InvalidPdfObjectException { 94 return hget(PjName.DESCENT); 95 } 96 97 public void setFlags(PjNumber flags) { 98 _h.put(PjName.FLAGS, flags); 99 } 100 101 public PjObject getFlags() throws InvalidPdfObjectException { 102 return hget(PjName.FLAGS); 103 } 104 105 public static boolean flagsFixedWidth(int flags) { 106 return ((flags & (1 << 0)) != 0); 107 } 108 109 public static boolean flagsSerif(int flags) { 110 return ((flags & (1 << 1)) != 0); 111 } 112 113 public static boolean flagsSymbolic(int flags) { 114 return ((flags & (1 << 2)) != 0); 115 } 116 117 public static boolean flagsScript(int flags) { 118 return ((flags & (1 << 3)) != 0); 119 } 120 121 public static boolean flagsRomanCharSet(int flags) { 122 return ((flags & (1 << 5)) != 0); 123 } 124 125 public static boolean flagsItalic(int flags) { 126 return ((flags & (1 << 6)) != 0); 127 } 128 129 public static boolean flagsAllCap(int flags) { 130 return ((flags & (1 << 16)) != 0); 131 } 132 133 public static boolean flagsSmallCap(int flags) { 134 return ((flags & (1 << 17)) != 0); 135 } 136 137 public static boolean flagsForceBoldAtSmallSizes(int flags) { 138 return ((flags & (2 << 18)) != 0); 139 } 140 141 144 public String getFlagBits() throws InvalidPdfObjectException { 145 int _flags = ((PjNumber)hget(PjName.FLAGS)).getInt(); 146 StringBuffer buf = new StringBuffer (); 147 148 for (int i = 0; i <= 31; i++) { 149 152 if ((_flags & 1) == 1) { 153 buf.append(PjFDFlagBitNames[i] + " "); 154 } 155 _flags = _flags >> 1; 156 } 157 if (buf.length() > 0) { 158 return buf.toString(); 159 } else { 160 return null; 161 } 162 } 163 164 public void setFontBBox(PjRectangle fontbbox) { 165 _h.put(PjName.FONTBBOX, fontbbox); 166 } 167 168 public PjObject getFontBBox() throws InvalidPdfObjectException { 169 return hget(PjName.FONTBBOX); 170 } 171 172 public void setFontName(PjName fontname) { 173 _h.put(PjName.FONTNAME, fontname); 174 } 175 176 public PjObject getFontName() throws InvalidPdfObjectException { 177 return hget(PjName.FONTNAME); 178 } 179 180 public void setItalicAngle(PjNumber italicangle) { 181 _h.put(PjName.ITALICANGLE, italicangle); 182 } 183 184 public PjObject getItalicAngle() throws InvalidPdfObjectException { 185 return hget(PjName.ITALICANGLE); 186 } 187 188 public void setStemV(PjNumber stemv) { 189 _h.put(PjName.STEMV, stemv); 190 } 191 192 public PjObject getStemV() throws InvalidPdfObjectException { 193 return hget(PjName.STEMV); 194 } 195 196 197 198 public void setAvgWidth(PjNumber avgWidth) { 199 _h.put(PjName.AVGWIDTH, avgWidth); 200 } 201 202 public PjObject getAvgWidth() throws InvalidPdfObjectException { 203 return hget(PjName.AVGWIDTH); 204 } 205 206 public void setCharSet(PjString charSet) { 207 _h.put(PjName.CHARSET, charSet); 208 } 209 210 public PjObject getCharSet() throws InvalidPdfObjectException { 211 return hget(PjName.CHARSET); 212 } 213 214 public void setFontFile(PjStream fontFile) { 215 _h.put(PjName.FONTFILE, fontFile); 216 } 217 218 public PjObject getFontFile() throws InvalidPdfObjectException { 219 return hget(PjName.FONTFILE); 220 } 221 222 public void setFontFile2(PjStream fontFile2) { 223 _h.put(PjName.FONTFILE2, fontFile2); 224 } 225 226 public PjObject getFontFile2() throws InvalidPdfObjectException { 227 return hget(PjName.FONTFILE2); 228 } 229 230 public void setFontFile3(PjStream fontFile3) { 231 _h.put(PjName.FONTFILE3, fontFile3); 232 } 233 234 public PjObject getFontFile3() throws InvalidPdfObjectException { 235 return hget(PjName.FONTFILE3); 236 } 237 238 public void setLeading(PjNumber leading) { 239 _h.put(PjName.LEADING, leading); 240 } 241 242 public PjObject getLeading() throws InvalidPdfObjectException { 243 return hget(PjName.LEADING); 244 } 245 246 public void setMaxWidth(PjNumber maxWidth) { 247 _h.put(PjName.MAXWIDTH, maxWidth); 248 } 249 250 public PjObject getMaxWidth() throws InvalidPdfObjectException { 251 return hget(PjName.MAXWIDTH); 252 } 253 254 public void setMissingWidth(PjNumber missingWidth) { 255 _h.put(PjName.MISSINGWIDTH, missingWidth); 256 } 257 258 public PjObject getMissingWidth() throws InvalidPdfObjectException { 259 return hget(PjName.MISSINGWIDTH); 260 } 261 262 public void setStemH(PjNumber stemH) { 263 _h.put(PjName.STEMH, stemH); 264 } 265 266 public PjObject getStemH() throws InvalidPdfObjectException { 267 return hget(PjName.STEMH); 268 } 269 270 public void setXHeight(PjNumber xHeight) { 271 _h.put(PjName.XHEIGHT, xHeight); 272 } 273 274 public PjObject getXHeight() throws InvalidPdfObjectException { 275 return hget(PjName.XHEIGHT); 276 } 277 278 284 public static boolean isLike(PjDictionary dictionary) { 285 Hashtable h = dictionary.getHashtable(); 286 try { 288 PjName type = (PjName)(h.get(PjName.TYPE)); 289 if (type == null) { 290 return false; 291 } 292 if ( ! type.equals(PjName.FONTDESCRIPTOR) ) { 293 return false; 294 } 295 } 296 catch (ClassCastException e) { 297 return false; 298 } 299 return true; 300 } 301 302 } 303 | Popular Tags |