KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > pdmodel > font > PDFontDescriptor


1 /**
2  * Copyright (c) 2004, www.pdfbox.org
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. Neither the name of pdfbox; nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * http://www.pdfbox.org
29  *
30  */

31 package org.pdfbox.pdmodel.font;
32
33 import java.io.IOException JavaDoc;
34
35 import org.pdfbox.pdmodel.common.PDRectangle;
36
37 /**
38  * This class represents an interface to the font description. This will depend
39  * on the font type for the actual implementation. If it is a AFM/cmap/or embedded font.
40  *
41  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
42  * @version $Revision: 1.2 $
43  */

44 public abstract class PDFontDescriptor
45 {
46     /**
47      * A font descriptor flag. See PDF Reference for description.
48      */

49     private static final int FLAG_FIXED_PITCH = 1;
50     /**
51      * A font descriptor flag. See PDF Reference for description.
52      */

53     private static final int FLAG_SERIF = 2;
54     /**
55      * A font descriptor flag. See PDF Reference for description.
56      */

57     private static final int FLAG_SYMBOLIC = 3;
58     /**
59      * A font descriptor flag. See PDF Reference for description.
60      */

61     private static final int FLAG_SCRIPT = 4;
62     /**
63      * A font descriptor flag. See PDF Reference for description.
64      */

65     private static final int FLAG_NON_SYMBOLIC = 6;
66     /**
67      * A font descriptor flag. See PDF Reference for description.
68      */

69     private static final int FLAG_ITALIC = 7;
70     /**
71      * A font descriptor flag. See PDF Reference for description.
72      */

73     private static final int FLAG_ALL_CAP = 17;
74     /**
75      * A font descriptor flag. See PDF Reference for description.
76      */

77     private static final int FLAG_SMALL_CAP = 18;
78     /**
79      * A font descriptor flag. See PDF Reference for description.
80      */

81     private static final int FLAG_FORCE_BOLD = 19;
82
83
84     /**
85      * Get the font name.
86      *
87      * @return The name of the font.
88      */

89     public abstract String JavaDoc getFontName();
90
91     /**
92      * This will set the font name.
93      *
94      * @param fontName The new name for the font.
95      */

96     public abstract void setFontName( String JavaDoc fontName );
97
98     /**
99      * A string representing the preferred font family.
100      *
101      * @return The font family.
102      */

103     public abstract String JavaDoc getFontFamily();
104
105     /**
106      * This will set the font family.
107      *
108      * @param fontFamily The font family.
109      */

110     public abstract void setFontFamily( String JavaDoc fontFamily );
111
112     /**
113      * A string representing the preferred font stretch.
114      * According to the PDF Spec:
115      * The font stretch value; it must be one of the following (ordered from
116      * narrowest to widest): UltraCondensed, ExtraCondensed, Condensed, SemiCondensed,
117      * Normal, SemiExpanded, Expanded, ExtraExpanded or UltraExpanded.
118      *
119      * @return The font stretch.
120      */

121     public abstract String JavaDoc getFontStretch();
122
123     /**
124      * This will set the font stretch.
125      *
126      * @param fontStretch The font stretch
127      */

128     public abstract void setFontStretch( String JavaDoc fontStretch );
129
130     /**
131      * The weight of the font. According to the PDF spec "possible values are
132      * 100, 200, 300, 400, 500, 600, 700, 800 or 900" Where a higher number is
133      * more weight and appears to be more bold.
134      *
135      * @return The font weight.
136      */

137     public abstract float getFontWeight();
138
139     /**
140      * Set the weight of the font.
141      *
142      * @param fontWeight The new weight of the font.
143      */

144     public abstract void setFontWeight( float fontWeight );
145
146     /**
147      * This will get the font flags.
148      *
149      * @return The font flags.
150      */

151     public abstract int getFlags();
152
153     /**
154      * This will set the font flags.
155      *
156      * @param flags The new font flags.
157      */

158     public abstract void setFlags( int flags );
159
160     /**
161      * A convenience method that checks the flag bit.
162      *
163      * @return The flag value.
164      */

165     public boolean isFixedPitch()
166     {
167         return isFlagBitOn( FLAG_FIXED_PITCH );
168     }
169
170     /**
171      * A convenience method that sets the flag bit.
172      *
173      * @param flag The flag value.
174      */

175     public void setFixedPitch( boolean flag )
176     {
177         setFlagBit( FLAG_FIXED_PITCH, flag );
178     }
179
180     /**
181      * A convenience method that checks the flag bit.
182      *
183      * @return The flag value.
184      */

185     public boolean isSerif()
186     {
187         return isFlagBitOn( FLAG_SERIF );
188     }
189
190     /**
191      * A convenience method that sets the flag bit.
192      *
193      * @param flag The flag value.
194      */

195     public void setSerif( boolean flag )
196     {
197         setFlagBit( FLAG_SERIF, flag );
198     }
199
200     /**
201      * A convenience method that checks the flag bit.
202      *
203      * @return The flag value.
204      */

205     public boolean isSymbolic()
206     {
207         return isFlagBitOn( FLAG_SYMBOLIC );
208     }
209
210     /**
211      * A convenience method that sets the flag bit.
212      *
213      * @param flag The flag value.
214      */

215     public void setSymbolic( boolean flag )
216     {
217         setFlagBit( FLAG_SYMBOLIC, flag );
218     }
219
220     /**
221      * A convenience method that checks the flag bit.
222      *
223      * @return The flag value.
224      */

225     public boolean isScript()
226     {
227         return isFlagBitOn( FLAG_SCRIPT );
228     }
229
230     /**
231      * A convenience method that sets the flag bit.
232      *
233      * @param flag The flag value.
234      */

235     public void setScript( boolean flag )
236     {
237         setFlagBit( FLAG_SCRIPT, flag );
238     }
239
240     /**
241      * A convenience method that checks the flag bit.
242      *
243      * @return The flag value.
244      */

245     public boolean isNonSymbolic()
246     {
247         return isFlagBitOn( FLAG_NON_SYMBOLIC );
248     }
249
250     /**
251      * A convenience method that sets the flag bit.
252      *
253      * @param flag The flag value.
254      */

255     public void setNonSymbolic( boolean flag )
256     {
257         setFlagBit( FLAG_NON_SYMBOLIC, flag );
258     }
259
260     /**
261      * A convenience method that checks the flag bit.
262      *
263      * @return The flag value.
264      */

265     public boolean isItalic()
266     {
267         return isFlagBitOn( FLAG_ITALIC );
268     }
269
270     /**
271      * A convenience method that sets the flag bit.
272      *
273      * @param flag The flag value.
274      */

275     public void setItalic( boolean flag )
276     {
277         setFlagBit( FLAG_ITALIC, flag );
278     }
279
280     /**
281      * A convenience method that checks the flag bit.
282      *
283      * @return The flag value.
284      */

285     public boolean isAllCap()
286     {
287         return isFlagBitOn( FLAG_ALL_CAP);
288     }
289
290     /**
291      * A convenience method that sets the flag bit.
292      *
293      * @param flag The flag value.
294      */

295     public void setAllCap( boolean flag )
296     {
297         setFlagBit( FLAG_ALL_CAP, flag );
298     }
299
300     /**
301      * A convenience method that checks the flag bit.
302      *
303      * @return The flag value.
304      */

305     public boolean isSmallCap()
306     {
307         return isFlagBitOn( FLAG_SMALL_CAP );
308     }
309
310     /**
311      * A convenience method that sets the flag bit.
312      *
313      * @param flag The flag value.
314      */

315     public void setSmallCap( boolean flag )
316     {
317         setFlagBit( FLAG_SMALL_CAP, flag );
318     }
319
320     /**
321      * A convenience method that checks the flag bit.
322      *
323      * @return The flag value.
324      */

325     public boolean isForceBold()
326     {
327         return isFlagBitOn( FLAG_FORCE_BOLD );
328     }
329
330     /**
331      * A convenience method that sets the flag bit.
332      *
333      * @param flag The flag value.
334      */

335     public void setForceBold( boolean flag )
336     {
337         setFlagBit( FLAG_FORCE_BOLD, flag );
338     }
339
340     private boolean isFlagBitOn( int bit )
341     {
342         return (getFlags() & (1 << (bit-1))) != 0;
343     }
344
345     private void setFlagBit( int bit, boolean value )
346     {
347         int flags = getFlags();
348         if( value )
349         {
350             flags = flags| (1 << (bit-1));
351         }
352         else
353         {
354             flags = flags & (0xFFFFFFFF ^ (1 << (bit-1)));
355         }
356         setFlags( flags );
357     }
358
359     /**
360      * This will get the fonts bouding box.
361      *
362      * @return The fonts bouding box.
363      */

364     public abstract PDRectangle getFontBoundingBox();
365
366     /**
367      * Set the fonts bounding box.
368      *
369      * @param rect The new bouding box.
370      */

371     public abstract void setFontBoundingBox( PDRectangle rect );
372
373     /**
374      * This will get the italic angle for the font.
375      *
376      * @return The italic angle.
377      */

378     public abstract float getItalicAngle();
379
380     /**
381      * This will set the italic angle for the font.
382      *
383      * @param angle The new italic angle for the font.
384      */

385     public abstract void setItalicAngle( float angle );
386
387     /**
388      * This will get the ascent for the font.
389      *
390      * @return The ascent.
391      */

392     public abstract float getAscent();
393
394     /**
395      * This will set the ascent for the font.
396      *
397      * @param ascent The new ascent for the font.
398      */

399     public abstract void setAscent( float ascent );
400
401     /**
402      * This will get the descent for the font.
403      *
404      * @return The descent.
405      */

406     public abstract float getDescent();
407
408     /**
409      * This will set the descent for the font.
410      *
411      * @param descent The new descent for the font.
412      */

413     public abstract void setDescent( float descent );
414
415     /**
416      * This will get the leading for the font.
417      *
418      * @return The leading.
419      */

420     public abstract float getLeading();
421
422     /**
423      * This will set the leading for the font.
424      *
425      * @param leading The new leading for the font.
426      */

427     public abstract void setLeading( float leading );
428
429     /**
430      * This will get the CapHeight for the font.
431      *
432      * @return The cap height.
433      */

434     public abstract float getCapHeight();
435
436     /**
437      * This will set the cap height for the font.
438      *
439      * @param capHeight The new cap height for the font.
440      */

441     public abstract void setCapHeight( float capHeight );
442
443     /**
444      * This will get the x height for the font.
445      *
446      * @return The x height.
447      */

448     public abstract float getXHeight();
449
450     /**
451      * This will set the x height for the font.
452      *
453      * @param xHeight The new x height for the font.
454      */

455     public abstract void setXHeight( float xHeight );
456
457     /**
458      * This will get the stemV for the font.
459      *
460      * @return The stem v value.
461      */

462     public abstract float getStemV();
463
464     /**
465      * This will set the stem V for the font.
466      *
467      * @param stemV The new stem v for the font.
468      */

469     public abstract void setStemV( float stemV );
470
471     /**
472      * This will get the stemH for the font.
473      *
474      * @return The stem h value.
475      */

476     public abstract float getStemH();
477
478     /**
479      * This will set the stem H for the font.
480      *
481      * @param stemH The new stem h for the font.
482      */

483     public abstract void setStemH( float stemH );
484
485     /**
486      * This will get the average width for the font. This is part of the
487      * definition in the font description. If it is not present then PDFBox
488      * will make an attempt to calculate it.
489      *
490      * @return The average width value.
491      *
492      * @throws IOException If there is an error calculating the average width.
493      */

494     public abstract float getAverageWidth() throws IOException JavaDoc;
495
496     /**
497      * This will set the average width for the font.
498      *
499      * @param averageWidth The new average width for the font.
500      */

501     public abstract void setAverageWidth( float averageWidth );
502
503     /**
504      * This will get the max width for the font.
505      *
506      * @return The max width value.
507      */

508     public abstract float getMaxWidth();
509
510     /**
511      * This will set the max width for the font.
512      *
513      * @param maxWidth The new max width for the font.
514      */

515     public abstract void setMaxWidth( float maxWidth );
516
517     /**
518      * This will get the character set for the font.
519      *
520      * @return The character set value.
521      */

522     public abstract String JavaDoc getCharSet();
523
524     /**
525      * This will set the character set for the font.
526      *
527      * @param charSet The new character set for the font.
528      */

529     public abstract void setCharacterSet( String JavaDoc charSet );
530 }
Popular Tags