KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > etymon > pj > object > PjFontDescriptor


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 /**
9    A representation of a PDF font descriptor (abstract base class).
10    @author Carl Scholz (Texterity Inc.)
11    @author Nassib Nassar (Etymon Systems, Inc.)
12 */

13 public class PjFontDescriptor
14     extends PjDictionary {
15
16     /**
17        @deprecated
18     */

19     private static String JavaDoc[] PjFDFlagBitNames = {
20         "FixedWidth", // (2)
21
"Serif", // (2^2)
22
"Symbolic", // (2^3)
23
"Script", // (2^4)
24
"Reserved5", // (2^5)
25
"RomanCharSet", // (2^6)
26
"Italic", // (2^7)
27
"Reserved8", // (2^8)
28
"Reserved9", // (2^9)
29
"Reserved10", // (2^10)
30
"Reserved11", // (2^11)
31
"Reserved12", // (2^12)
32
"Reserved13", // (2^13)
33
"Reserved14", // (2^14)
34
"Reserved15", // (2^15)
35
"Reserved16", // (2^16)
36
"AllCap", // (2^17)
37
"SmallCap", // (2^18)
38
"ForceBoldAtSmallSizes", // (2^19)
39
"Reserved20", // (2^20)
40
"Reserved21", // (2^21)
41
"Reserved22", // (2^22)
42
"Reserved23", // (2^23)
43
"Reserved24", // (2^24)
44
"Reserved25", // (2^25)
45
"Reserved26", // (2^26)
46
"Reserved27", // (2^27)
47
"Reserved28", // (2^28)
48
"Reserved29", // (2^29)
49
"Reserved30", // (2^30)
50
"Reserved31", // (2^31)
51
"Reserved32" // (2^32)
52
};
53
54     /**
55        Creates a new font descriptor dictionary.
56     */

57     public PjFontDescriptor() {
58         super();
59         _h.put(PjName.TYPE, PjName.FONTDESCRIPTOR);
60     }
61     
62     /**
63        Creates a font descriptor dictionary as a wrapper around a Hashtable.
64        @param h the Hashtable to use for this dictionary.
65     */

66     public PjFontDescriptor(Hashtable h) {
67         super(h);
68         _h.put(PjName.TYPE, PjName.FONTDESCRIPTOR);
69     }
70
71     /* Required --------------------------------------- */
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     /**
142        @deprecated
143     */

144     public String JavaDoc getFlagBits() throws InvalidPdfObjectException {
145         int _flags = ((PjNumber)hget(PjName.FLAGS)).getInt();
146         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
147         
148         for (int i = 0; i <= 31; i++) {
149             // bit range is 1 to 32 in spec, so that's a loop from 0 to
150
// 31 here.
151

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     /* Optional --------------------------------------- */
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     /**
279        Examines a dictionary to see if it is a PDF font descriptor.
280        @param dictionary the dictionary to examine.
281        @return true if the dictionary could be interpreted as a
282        valid PjFontDescriptor object.
283     */

284     public static boolean isLike(PjDictionary dictionary) {
285         Hashtable h = dictionary.getHashtable();
286         // check if the Type is FontDescriptor
287
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 JavaDoc e) {
297             return false;
298         }
299         return true;
300     }
301
302 }
303
Popular Tags