KickJava   Java API By Example, From Geeks To Geeks.

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


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.fontbox.afm.FontMetric;
36
37 import org.pdfbox.pdmodel.common.PDRectangle;
38
39 import org.fontbox.util.BoundingBox;
40
41 /**
42  * This class represents the font descriptor when the font information
43  * is coming from an AFM file.
44  *
45  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
46  * @version $Revision: 1.3 $
47  */

48 public class PDFontDescriptorAFM extends PDFontDescriptor
49 {
50     private FontMetric afm;
51
52     /**
53      * Constructor.
54      *
55      * @param afmFile The AFM file.
56      */

57     public PDFontDescriptorAFM( FontMetric afmFile )
58     {
59         afm = afmFile;
60     }
61
62     /**
63      * Get the font name.
64      *
65      * @return The name of the font.
66      */

67     public String JavaDoc getFontName()
68     {
69         return afm.getFontName();
70     }
71
72     /**
73      * This will set the font name.
74      *
75      * @param fontName The new name for the font.
76      */

77     public void setFontName( String JavaDoc fontName )
78     {
79         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
80     }
81
82     /**
83      * A string representing the preferred font family.
84      *
85      * @return The font family.
86      */

87     public String JavaDoc getFontFamily()
88     {
89         return afm.getFamilyName();
90     }
91
92     /**
93      * This will set the font family.
94      *
95      * @param fontFamily The font family.
96      */

97     public void setFontFamily( String JavaDoc fontFamily )
98     {
99         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
100     }
101
102     /**
103      * The weight of the font. According to the PDF spec "possible values are
104      * 100, 200, 300, 400, 500, 600, 700, 800 or 900" Where a higher number is
105      * more weight and appears to be more bold.
106      *
107      * @return The font weight.
108      */

109     public float getFontWeight()
110     {
111         String JavaDoc weight = afm.getWeight();
112         float retval = 500;
113         if( weight != null && weight.equalsIgnoreCase( "bold" ) )
114         {
115             retval = 900;
116         }
117         else if( weight != null && weight.equalsIgnoreCase( "light" ) )
118         {
119             retval = 100;
120         }
121         return retval;
122     }
123
124     /**
125      * Set the weight of the font.
126      *
127      * @param fontWeight The new weight of the font.
128      */

129     public void setFontWeight( float fontWeight )
130     {
131         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
132     }
133
134     /**
135      * A string representing the preferred font stretch.
136      *
137      * @return The font stretch.
138      */

139     public String JavaDoc getFontStretch()
140     {
141         return null;
142     }
143
144     /**
145      * This will set the font stretch.
146      *
147      * @param fontStretch The font stretch
148      */

149     public void setFontStretch( String JavaDoc fontStretch )
150     {
151         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
152     }
153
154     /**
155      * This will get the font flags.
156      *
157      * @return The font flags.
158      */

159     public int getFlags()
160     {
161         //I believe that the only flag that AFM supports is the is fixed pitch
162
return afm.isFixedPitch() ? 1 : 0;
163     }
164
165     /**
166      * This will set the font flags.
167      *
168      * @param flags The new font flags.
169      */

170     public void setFlags( int flags )
171     {
172         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
173     }
174
175     /**
176      * This will get the fonts bouding box.
177      *
178      * @return The fonts bouding box.
179      */

180     public PDRectangle getFontBoundingBox()
181     {
182         BoundingBox box = afm.getFontBBox();
183         PDRectangle retval = null;
184         if( box != null )
185         {
186             retval = new PDRectangle( box );
187         }
188         return retval;
189     }
190
191     /**
192      * Set the fonts bounding box.
193      *
194      * @param rect The new bouding box.
195      */

196     public void setFontBoundingBox( PDRectangle rect )
197     {
198         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
199     }
200
201     /**
202      * This will get the italic angle for the font.
203      *
204      * @return The italic angle.
205      */

206     public float getItalicAngle()
207     {
208         return afm.getItalicAngle();
209     }
210
211     /**
212      * This will set the italic angle for the font.
213      *
214      * @param angle The new italic angle for the font.
215      */

216     public void setItalicAngle( float angle )
217     {
218         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
219     }
220
221     /**
222      * This will get the ascent for the font.
223      *
224      * @return The ascent.
225      */

226     public float getAscent()
227     {
228         return afm.getAscender();
229     }
230
231     /**
232      * This will set the ascent for the font.
233      *
234      * @param ascent The new ascent for the font.
235      */

236     public void setAscent( float ascent )
237     {
238         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
239     }
240
241     /**
242      * This will get the descent for the font.
243      *
244      * @return The descent.
245      */

246     public float getDescent()
247     {
248         return afm.getDescender();
249     }
250
251     /**
252      * This will set the descent for the font.
253      *
254      * @param descent The new descent for the font.
255      */

256     public void setDescent( float descent )
257     {
258         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
259     }
260
261     /**
262      * This will get the leading for the font.
263      *
264      * @return The leading.
265      */

266     public float getLeading()
267     {
268         //AFM does not support setting the leading so we will just ignore it.
269
return 0f;
270     }
271
272     /**
273      * This will set the leading for the font.
274      *
275      * @param leading The new leading for the font.
276      */

277     public void setLeading( float leading )
278     {
279         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
280     }
281
282     /**
283      * This will get the CapHeight for the font.
284      *
285      * @return The cap height.
286      */

287     public float getCapHeight()
288     {
289         return afm.getCapHeight();
290     }
291
292     /**
293      * This will set the cap height for the font.
294      *
295      * @param capHeight The new cap height for the font.
296      */

297     public void setCapHeight( float capHeight )
298     {
299         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
300     }
301
302     /**
303      * This will get the x height for the font.
304      *
305      * @return The x height.
306      */

307     public float getXHeight()
308     {
309         return afm.getXHeight();
310     }
311
312     /**
313      * This will set the x height for the font.
314      *
315      * @param xHeight The new x height for the font.
316      */

317     public void setXHeight( float xHeight )
318     {
319         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
320     }
321
322     /**
323      * This will get the stemV for the font.
324      *
325      * @return The stem v value.
326      */

327     public float getStemV()
328     {
329         //afm does not have a stem v
330
return 0;
331     }
332
333     /**
334      * This will set the stem V for the font.
335      *
336      * @param stemV The new stem v for the font.
337      */

338     public void setStemV( float stemV )
339     {
340         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
341     }
342
343     /**
344      * This will get the stemH for the font.
345      *
346      * @return The stem h value.
347      */

348     public float getStemH()
349     {
350         //afm does not have a stem h
351
return 0;
352     }
353
354     /**
355      * This will set the stem H for the font.
356      *
357      * @param stemH The new stem h for the font.
358      */

359     public void setStemH( float stemH )
360     {
361         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
362     }
363
364     /**
365      * This will get the average width for the font.
366      *
367      * @return The average width value.
368      *
369      * @throws IOException If there is an error calculating the average width.
370      */

371     public float getAverageWidth() throws IOException JavaDoc
372     {
373         return afm.getAverageCharacterWidth();
374     }
375
376     /**
377      * This will set the average width for the font.
378      *
379      * @param averageWidth The new average width for the font.
380      */

381     public void setAverageWidth( float averageWidth )
382     {
383         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
384     }
385
386     /**
387      * This will get the max width for the font.
388      *
389      * @return The max width value.
390      */

391     public float getMaxWidth()
392     {
393         //afm does not support max width;
394
return 0;
395     }
396
397     /**
398      * This will set the max width for the font.
399      *
400      * @param maxWidth The new max width for the font.
401      */

402     public void setMaxWidth( float maxWidth )
403     {
404         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
405     }
406
407     /**
408      * This will get the missing width for the font.
409      *
410      * @return The missing width value.
411      */

412     public float getMissingWidth()
413     {
414         return 0;
415     }
416
417     /**
418      * This will set the missing width for the font.
419      *
420      * @param missingWidth The new missing width for the font.
421      */

422     public void setMissingWidth( float missingWidth )
423     {
424         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
425     }
426
427     /**
428      * This will get the character set for the font.
429      *
430      * @return The character set value.
431      */

432     public String JavaDoc getCharSet()
433     {
434         return afm.getCharacterSet();
435     }
436
437     /**
438      * This will set the character set for the font.
439      *
440      * @param charSet The new character set for the font.
441      */

442     public void setCharacterSet( String JavaDoc charSet )
443     {
444         throw new UnsupportedOperationException JavaDoc( "The AFM Font descriptor is immutable" );
445     }
446 }
Popular Tags