001: /*
002: * $Id: PDFFontDescriptor.java,v 1.2 2007/12/20 18:33:32 rbair Exp $
003: *
004: * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005: * Santa Clara, California 95054, U.S.A. All rights reserved.
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
020: */
021:
022: package com.sun.pdfview.font;
023:
024: import java.awt.geom.Rectangle2D;
025: import java.io.IOException;
026:
027: import com.sun.pdfview.PDFObject;
028:
029: /**
030: *
031: * @author jkaplan
032: */
033: public class PDFFontDescriptor {
034:
035: /** Holds value of property ascent. */
036: private int ascent;
037:
038: /** Holds value of property capHeight. */
039: private int capHeight;
040:
041: /** Holds value of property descent. */
042: private int descent;
043:
044: /** Holds value of property flags. */
045: private int flags;
046:
047: /** Holds value of property fontName. */
048: private String fontName;
049:
050: /** Holds value of property italicAngle. */
051: private int italicAngle;
052:
053: /** Holds value of property stemV. */
054: private int stemV;
055:
056: /** Holds value of property avgWidth. */
057: private int avgWidth = 0;
058:
059: /** Holds value of property fontFile. */
060: private PDFObject fontFile;
061:
062: /** Holds value of property fontFile2. */
063: private PDFObject fontFile2;
064:
065: /** Holds value of property fontFile3. */
066: private PDFObject fontFile3;
067:
068: /** Holds value of property leading. */
069: private int leading = 0;
070:
071: /** Holds value of property maxWidth. */
072: private int maxWidth = 0;
073:
074: /** Holds value of property misingWidth. */
075: private int missingWidth = 0;
076:
077: /** Holds value of property stemH. */
078: private int stemH = 0;
079:
080: /** Holds value of property xHeight. */
081: private int xHeight = 0;
082:
083: /** Holds value of property charSet. */
084: private PDFObject charSet;
085:
086: /** Holds value of property fontBBox. */
087: private Rectangle2D.Float fontBBox;
088:
089: /** Creates a new instance of PDFFontDescriptor */
090: public PDFFontDescriptor(String basefont) {
091: setFontName(basefont);
092: // [[MW TODO: find basefont info and fill in the rest of the
093: // descriptor?]]
094: }
095:
096: /** Creates a new instance of PDFFontDescriptor */
097: public PDFFontDescriptor(PDFObject obj) throws IOException {
098: // required parameters
099: setAscent(obj.getDictRef("Ascent").getIntValue());
100: setCapHeight(obj.getDictRef("CapHeight").getIntValue());
101: setDescent(obj.getDictRef("Descent").getIntValue());
102: setFlags(obj.getDictRef("Flags").getIntValue());
103: setFontName(obj.getDictRef("FontName").getStringValue());
104: setItalicAngle(obj.getDictRef("ItalicAngle").getIntValue());
105: setStemV(obj.getDictRef("StemV").getIntValue());
106:
107: // font bounding box
108: PDFObject[] bboxdef = obj.getDictRef("FontBBox").getArray();
109: float[] bboxfdef = new float[4];
110: for (int i = 0; i < 4; i++) {
111: bboxfdef[i] = bboxdef[i].getFloatValue();
112: }
113: setFontBBox(new Rectangle2D.Float(bboxfdef[0], bboxfdef[1],
114: bboxfdef[2] - bboxfdef[0], bboxfdef[3] - bboxfdef[1]));
115:
116: // optional parameters
117: if (obj.getDictionary().containsKey("AvgWidth")) {
118: setAvgWidth(obj.getDictRef("AvgWidth").getIntValue());
119: }
120: if (obj.getDictionary().containsKey("FontFile")) {
121: setFontFile(obj.getDictRef("FontFile"));
122: }
123: if (obj.getDictionary().containsKey("FontFile2")) {
124: setFontFile2(obj.getDictRef("FontFile2"));
125: }
126: if (obj.getDictionary().containsKey("FontFile3")) {
127: setFontFile3(obj.getDictRef("FontFile3"));
128: }
129: if (obj.getDictionary().containsKey("Leading")) {
130: setLeading(obj.getDictRef("Leading").getIntValue());
131: }
132: if (obj.getDictionary().containsKey("MaxWidth")) {
133: setMaxWidth(obj.getDictRef("MaxWidth").getIntValue());
134: }
135: if (obj.getDictionary().containsKey("MissingWidth")) {
136: setMissingWidth(obj.getDictRef("MissingWidth")
137: .getIntValue());
138: }
139: if (obj.getDictionary().containsKey("StemH")) {
140: setStemH(obj.getDictRef("StemH").getIntValue());
141: }
142: if (obj.getDictionary().containsKey("XHeight")) {
143: setXHeight(obj.getDictRef("XHeight").getIntValue());
144: }
145: if (obj.getDictionary().containsKey("CharSet")) {
146: setCharSet(obj.getDictRef("CharSet"));
147: }
148: }
149:
150: /** Getter for property ascent.
151: * @return Value of property ascent.
152: *
153: */
154: public int getAscent() {
155: return this .ascent;
156: }
157:
158: /** Setter for property ascent.
159: * @param ascent New value of property ascent.
160: *
161: */
162: public void setAscent(int ascent) {
163: this .ascent = ascent;
164: }
165:
166: /** Getter for property capHeight.
167: * @return Value of property capHeight.
168: *
169: */
170: public int getCapHeight() {
171: return this .capHeight;
172: }
173:
174: /** Setter for property capHeight.
175: * @param capHeight New value of property capHeight.
176: *
177: */
178: public void setCapHeight(int capHeight) {
179: this .capHeight = capHeight;
180: }
181:
182: /** Getter for property descent.
183: * @return Value of property descent.
184: *
185: */
186: public int getDescent() {
187: return this .descent;
188: }
189:
190: /** Setter for property descent.
191: * @param descent New value of property descent.
192: *
193: */
194: public void setDescent(int descent) {
195: this .descent = descent;
196: }
197:
198: /** Getter for property flags.
199: * @return Value of property flags.
200: *
201: */
202: public int getFlags() {
203: return this .flags;
204: }
205:
206: /** Setter for property flags.
207: * @param flags New value of property flags.
208: *
209: */
210: public void setFlags(int flags) {
211: this .flags = flags;
212: }
213:
214: /** Getter for property fontName.
215: * @return Value of property fontName.
216: *
217: */
218: public String getFontName() {
219: return this .fontName;
220: }
221:
222: /** Setter for property fontName.
223: * @param fontName New value of property fontName.
224: *
225: */
226: public void setFontName(String fontName) {
227: this .fontName = fontName;
228: }
229:
230: /** Getter for property italicAngle.
231: * @return Value of property italicAngle.
232: *
233: */
234: public int getItalicAngle() {
235: return this .italicAngle;
236: }
237:
238: /** Setter for property italicAngle.
239: * @param italicAngle New value of property italicAngle.
240: *
241: */
242: public void setItalicAngle(int italicAngle) {
243: this .italicAngle = italicAngle;
244: }
245:
246: /** Getter for property stemV.
247: * @return Value of property stemV.
248: *
249: */
250: public int getStemV() {
251: return this .stemV;
252: }
253:
254: /** Setter for property stemV.
255: * @param stemV New value of property stemV.
256: *
257: */
258: public void setStemV(int stemV) {
259: this .stemV = stemV;
260: }
261:
262: /** Getter for property avgWidth.
263: * @return Value of property avgWidth.
264: *
265: */
266: public int getAvgWidth() {
267: return this .avgWidth;
268: }
269:
270: /** Setter for property avgWidth.
271: * @param avgWidth New value of property avgWidth.
272: *
273: */
274: public void setAvgWidth(int avgWidth) {
275: this .avgWidth = avgWidth;
276: }
277:
278: /** Getter for property fontFile.
279: * @return Value of property fontFile.
280: *
281: */
282: public PDFObject getFontFile() {
283: return this .fontFile;
284: }
285:
286: /** Setter for property fontFile.
287: * @param fontFile New value of property fontFile.
288: *
289: */
290: public void setFontFile(PDFObject fontFile) {
291: this .fontFile = fontFile;
292: }
293:
294: /** Getter for property fontFile2.
295: * @return Value of property fontFile2.
296: *
297: */
298: public PDFObject getFontFile2() {
299: return this .fontFile2;
300: }
301:
302: /** Setter for property fontFile2.
303: * @param fontFile2 New value of property fontFile2.
304: *
305: */
306: public void setFontFile2(PDFObject fontFile2) {
307: this .fontFile2 = fontFile2;
308: }
309:
310: /** Getter for property fontFile3.
311: * @return Value of property fontFile3.
312: *
313: */
314: public PDFObject getFontFile3() {
315: return this .fontFile3;
316: }
317:
318: /** Setter for property fontFile3.
319: * @param fontFile3 New value of property fontFile3.
320: *
321: */
322: public void setFontFile3(PDFObject fontFile3) {
323: this .fontFile3 = fontFile3;
324: }
325:
326: /** Getter for property leading.
327: * @return Value of property leading.
328: *
329: */
330: public int getLeading() {
331: return this .leading;
332: }
333:
334: /** Setter for property leading.
335: * @param leading New value of property leading.
336: *
337: */
338: public void setLeading(int leading) {
339: this .leading = leading;
340: }
341:
342: /** Getter for property maxWidth.
343: * @return Value of property maxWidth.
344: *
345: */
346: public int getMaxWidth() {
347: return this .maxWidth;
348: }
349:
350: /** Setter for property maxWidth.
351: * @param maxWidth New value of property maxWidth.
352: *
353: */
354: public void setMaxWidth(int maxWidth) {
355: this .maxWidth = maxWidth;
356: }
357:
358: /** Getter for property misingWidth.
359: * @return Value of property misingWidth.
360: *
361: */
362: public int getMissingWidth() {
363: return this .missingWidth;
364: }
365:
366: /** Setter for property misingWidth.
367: * @param missingWidth New value of property misingWidth.
368: */
369: public void setMissingWidth(int missingWidth) {
370: this .missingWidth = missingWidth;
371: }
372:
373: /** Getter for property stemH.
374: * @return Value of property stemH.
375: *
376: */
377: public int getStemH() {
378: return this .stemH;
379: }
380:
381: /** Setter for property stemH.
382: * @param stemH New value of property stemH.
383: *
384: */
385: public void setStemH(int stemH) {
386: this .stemH = stemH;
387: }
388:
389: /** Getter for property xHeight.
390: * @return Value of property xHeight.
391: *
392: */
393: public int getXHeight() {
394: return this .xHeight;
395: }
396:
397: /** Setter for property xHeight.
398: * @param xHeight New value of property xHeight.
399: *
400: */
401: public void setXHeight(int xHeight) {
402: this .xHeight = xHeight;
403: }
404:
405: /** Getter for property charSet.
406: * @return Value of property charSet.
407: *
408: */
409: public PDFObject getCharSet() {
410: return this .charSet;
411: }
412:
413: /** Setter for property charSet.
414: * @param charSet New value of property charSet.
415: *
416: */
417: public void setCharSet(PDFObject charSet) {
418: this .charSet = charSet;
419: }
420:
421: /** Getter for property fontBBox.
422: * @return Value of property fontBBox.
423: *
424: */
425: public Rectangle2D.Float getFontBBox() {
426: return this .fontBBox;
427: }
428:
429: /** Setter for property fontBBox.
430: * @param fontBBox New value of property fontBBox.
431: *
432: */
433: public void setFontBBox(Rectangle2D.Float fontBBox) {
434: this.fontBBox = fontBBox;
435: }
436:
437: }
|