001: package com.etymon.pj.object;
002:
003: import java.io.*;
004: import java.util.*;
005: import com.etymon.pj.*;
006: import com.etymon.pj.exception.*;
007:
008: /**
009: A representation of a PDF font descriptor (abstract base class).
010: @author Carl Scholz (Texterity Inc.)
011: @author Nassib Nassar (Etymon Systems, Inc.)
012: */
013: public class PjFontDescriptor extends PjDictionary {
014:
015: /**
016: @deprecated
017: */
018: private static String[] PjFDFlagBitNames = { "FixedWidth", // (2)
019: "Serif", // (2^2)
020: "Symbolic", // (2^3)
021: "Script", // (2^4)
022: "Reserved5", // (2^5)
023: "RomanCharSet", // (2^6)
024: "Italic", // (2^7)
025: "Reserved8", // (2^8)
026: "Reserved9", // (2^9)
027: "Reserved10", // (2^10)
028: "Reserved11", // (2^11)
029: "Reserved12", // (2^12)
030: "Reserved13", // (2^13)
031: "Reserved14", // (2^14)
032: "Reserved15", // (2^15)
033: "Reserved16", // (2^16)
034: "AllCap", // (2^17)
035: "SmallCap", // (2^18)
036: "ForceBoldAtSmallSizes", // (2^19)
037: "Reserved20", // (2^20)
038: "Reserved21", // (2^21)
039: "Reserved22", // (2^22)
040: "Reserved23", // (2^23)
041: "Reserved24", // (2^24)
042: "Reserved25", // (2^25)
043: "Reserved26", // (2^26)
044: "Reserved27", // (2^27)
045: "Reserved28", // (2^28)
046: "Reserved29", // (2^29)
047: "Reserved30", // (2^30)
048: "Reserved31", // (2^31)
049: "Reserved32" // (2^32)
050: };
051:
052: /**
053: Creates a new font descriptor dictionary.
054: */
055: public PjFontDescriptor() {
056: super ();
057: _h.put(PjName.TYPE, PjName.FONTDESCRIPTOR);
058: }
059:
060: /**
061: Creates a font descriptor dictionary as a wrapper around a Hashtable.
062: @param h the Hashtable to use for this dictionary.
063: */
064: public PjFontDescriptor(Hashtable h) {
065: super (h);
066: _h.put(PjName.TYPE, PjName.FONTDESCRIPTOR);
067: }
068:
069: /* Required --------------------------------------- */
070:
071: public void setAscent(PjNumber ascent) {
072: _h.put(PjName.ASCENT, ascent);
073: }
074:
075: public PjObject getAscent() throws InvalidPdfObjectException {
076: return hget(PjName.ASCENT);
077: }
078:
079: public void setCapHeight(PjNumber capheight) {
080: _h.put(PjName.CAPHEIGHT, capheight);
081: }
082:
083: public PjObject getCapHeight() throws InvalidPdfObjectException {
084: return hget(PjName.CAPHEIGHT);
085: }
086:
087: public void setDescent(PjNumber descent) {
088: _h.put(PjName.DESCENT, descent);
089: }
090:
091: public PjObject getDescent() throws InvalidPdfObjectException {
092: return hget(PjName.DESCENT);
093: }
094:
095: public void setFlags(PjNumber flags) {
096: _h.put(PjName.FLAGS, flags);
097: }
098:
099: public PjObject getFlags() throws InvalidPdfObjectException {
100: return hget(PjName.FLAGS);
101: }
102:
103: public static boolean flagsFixedWidth(int flags) {
104: return ((flags & (1 << 0)) != 0);
105: }
106:
107: public static boolean flagsSerif(int flags) {
108: return ((flags & (1 << 1)) != 0);
109: }
110:
111: public static boolean flagsSymbolic(int flags) {
112: return ((flags & (1 << 2)) != 0);
113: }
114:
115: public static boolean flagsScript(int flags) {
116: return ((flags & (1 << 3)) != 0);
117: }
118:
119: public static boolean flagsRomanCharSet(int flags) {
120: return ((flags & (1 << 5)) != 0);
121: }
122:
123: public static boolean flagsItalic(int flags) {
124: return ((flags & (1 << 6)) != 0);
125: }
126:
127: public static boolean flagsAllCap(int flags) {
128: return ((flags & (1 << 16)) != 0);
129: }
130:
131: public static boolean flagsSmallCap(int flags) {
132: return ((flags & (1 << 17)) != 0);
133: }
134:
135: public static boolean flagsForceBoldAtSmallSizes(int flags) {
136: return ((flags & (2 << 18)) != 0);
137: }
138:
139: /**
140: @deprecated
141: */
142: public String getFlagBits() throws InvalidPdfObjectException {
143: int _flags = ((PjNumber) hget(PjName.FLAGS)).getInt();
144: StringBuffer buf = new StringBuffer();
145:
146: for (int i = 0; i <= 31; i++) {
147: // bit range is 1 to 32 in spec, so that's a loop from 0 to
148: // 31 here.
149:
150: if ((_flags & 1) == 1) {
151: buf.append(PjFDFlagBitNames[i] + " ");
152: }
153: _flags = _flags >> 1;
154: }
155: if (buf.length() > 0) {
156: return buf.toString();
157: } else {
158: return null;
159: }
160: }
161:
162: public void setFontBBox(PjRectangle fontbbox) {
163: _h.put(PjName.FONTBBOX, fontbbox);
164: }
165:
166: public PjObject getFontBBox() throws InvalidPdfObjectException {
167: return hget(PjName.FONTBBOX);
168: }
169:
170: public void setFontName(PjName fontname) {
171: _h.put(PjName.FONTNAME, fontname);
172: }
173:
174: public PjObject getFontName() throws InvalidPdfObjectException {
175: return hget(PjName.FONTNAME);
176: }
177:
178: public void setItalicAngle(PjNumber italicangle) {
179: _h.put(PjName.ITALICANGLE, italicangle);
180: }
181:
182: public PjObject getItalicAngle() throws InvalidPdfObjectException {
183: return hget(PjName.ITALICANGLE);
184: }
185:
186: public void setStemV(PjNumber stemv) {
187: _h.put(PjName.STEMV, stemv);
188: }
189:
190: public PjObject getStemV() throws InvalidPdfObjectException {
191: return hget(PjName.STEMV);
192: }
193:
194: /* Optional --------------------------------------- */
195:
196: public void setAvgWidth(PjNumber avgWidth) {
197: _h.put(PjName.AVGWIDTH, avgWidth);
198: }
199:
200: public PjObject getAvgWidth() throws InvalidPdfObjectException {
201: return hget(PjName.AVGWIDTH);
202: }
203:
204: public void setCharSet(PjString charSet) {
205: _h.put(PjName.CHARSET, charSet);
206: }
207:
208: public PjObject getCharSet() throws InvalidPdfObjectException {
209: return hget(PjName.CHARSET);
210: }
211:
212: public void setFontFile(PjStream fontFile) {
213: _h.put(PjName.FONTFILE, fontFile);
214: }
215:
216: public PjObject getFontFile() throws InvalidPdfObjectException {
217: return hget(PjName.FONTFILE);
218: }
219:
220: public void setFontFile2(PjStream fontFile2) {
221: _h.put(PjName.FONTFILE2, fontFile2);
222: }
223:
224: public PjObject getFontFile2() throws InvalidPdfObjectException {
225: return hget(PjName.FONTFILE2);
226: }
227:
228: public void setFontFile3(PjStream fontFile3) {
229: _h.put(PjName.FONTFILE3, fontFile3);
230: }
231:
232: public PjObject getFontFile3() throws InvalidPdfObjectException {
233: return hget(PjName.FONTFILE3);
234: }
235:
236: public void setLeading(PjNumber leading) {
237: _h.put(PjName.LEADING, leading);
238: }
239:
240: public PjObject getLeading() throws InvalidPdfObjectException {
241: return hget(PjName.LEADING);
242: }
243:
244: public void setMaxWidth(PjNumber maxWidth) {
245: _h.put(PjName.MAXWIDTH, maxWidth);
246: }
247:
248: public PjObject getMaxWidth() throws InvalidPdfObjectException {
249: return hget(PjName.MAXWIDTH);
250: }
251:
252: public void setMissingWidth(PjNumber missingWidth) {
253: _h.put(PjName.MISSINGWIDTH, missingWidth);
254: }
255:
256: public PjObject getMissingWidth() throws InvalidPdfObjectException {
257: return hget(PjName.MISSINGWIDTH);
258: }
259:
260: public void setStemH(PjNumber stemH) {
261: _h.put(PjName.STEMH, stemH);
262: }
263:
264: public PjObject getStemH() throws InvalidPdfObjectException {
265: return hget(PjName.STEMH);
266: }
267:
268: public void setXHeight(PjNumber xHeight) {
269: _h.put(PjName.XHEIGHT, xHeight);
270: }
271:
272: public PjObject getXHeight() throws InvalidPdfObjectException {
273: return hget(PjName.XHEIGHT);
274: }
275:
276: /**
277: Examines a dictionary to see if it is a PDF font descriptor.
278: @param dictionary the dictionary to examine.
279: @return true if the dictionary could be interpreted as a
280: valid PjFontDescriptor object.
281: */
282: public static boolean isLike(PjDictionary dictionary) {
283: Hashtable h = dictionary.getHashtable();
284: // check if the Type is FontDescriptor
285: try {
286: PjName type = (PjName) (h.get(PjName.TYPE));
287: if (type == null) {
288: return false;
289: }
290: if (!type.equals(PjName.FONTDESCRIPTOR)) {
291: return false;
292: }
293: } catch (ClassCastException e) {
294: return false;
295: }
296: return true;
297: }
298:
299: }
|