KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * Copyright (c) 2003-2006, 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.awt.Graphics JavaDoc;
34
35 import org.pdfbox.cos.COSArray;
36 import org.pdfbox.cos.COSDictionary;
37 import org.pdfbox.cos.COSName;
38 import org.pdfbox.pdmodel.common.PDRectangle;
39
40 import java.io.IOException JavaDoc;
41
42 /**
43  * This is implementation of the Type0 Font.
44  *
45  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
46  * @version $Revision: 1.9 $
47  */

48 public class PDType0Font extends PDFont
49 {
50     /**
51      * Constructor.
52      */

53     public PDType0Font()
54     {
55         super();
56         font.setItem( COSName.SUBTYPE, COSName.getPDFName( "Type0" ) );
57     }
58
59     /**
60      * Constructor.
61      *
62      * @param fontDictionary The font dictionary according to the PDF specification.
63      */

64     public PDType0Font( COSDictionary fontDictionary )
65     {
66         super( fontDictionary );
67     }
68
69     /**
70      * {@inheritDoc}
71      */

72     public void drawString( String JavaDoc string, Graphics JavaDoc g, float fontSize,
73         float xScale, float yScale, float x, float y )
74     {
75         throw new RuntimeException JavaDoc( "Not yet implemented" );
76     }
77     
78     /**
79      * This will get the fonts bouding box.
80      *
81      * @return The fonts bouding box.
82      *
83      * @throws IOException If there is an error getting the bounding box.
84      */

85     public PDRectangle getFontBoundingBox() throws IOException JavaDoc
86     {
87         throw new RuntimeException JavaDoc( "Not yet implemented" );
88     }
89
90     /**
91      * This will get the font width for a character.
92      *
93      * @param c The character code to get the width for.
94      * @param offset The offset into the array.
95      * @param length The length of the data.
96      *
97      * @return The width is in 1000 unit of text space, ie 333 or 777
98      *
99      * @throws IOException If an error occurs while parsing.
100      */

101     public float getFontWidth( byte[] c, int offset, int length ) throws IOException JavaDoc
102     {
103         COSArray descendantFontArray =
104             (COSArray)font.getDictionaryObject( COSName.getPDFName( "DescendantFonts" ) );
105
106         COSDictionary descendantFontDictionary = (COSDictionary)descendantFontArray.getObject( 0 );
107         PDFont descendentFont = PDFontFactory.createFont( descendantFontDictionary );
108
109         return descendentFont.getFontWidth( c, offset, length );
110     }
111     
112     /**
113      * This will get the font height for a character.
114      *
115      * @param c The character code to get the height for.
116      * @param offset The offset into the array.
117      * @param length The length of the data.
118      *
119      * @return The width is in 1000 unit of text space, ie 333 or 777
120      *
121      * @throws IOException If an error occurs while parsing.
122      */

123     public float getFontHeight( byte[] c, int offset, int length ) throws IOException JavaDoc
124     {
125         COSArray descendantFontArray =
126             (COSArray)font.getDictionaryObject( COSName.getPDFName( "DescendantFonts" ) );
127
128         COSDictionary descendantFontDictionary = (COSDictionary)descendantFontArray.getObject( 0 );
129         PDFont descendentFont = PDFontFactory.createFont( descendantFontDictionary );
130
131         return descendentFont.getFontHeight( c, offset, length );
132     }
133
134     /**
135      * This will get the average font width for all characters.
136      *
137      * @return The width is in 1000 unit of text space, ie 333 or 777
138      *
139      * @throws IOException If an error occurs while parsing.
140      */

141     public float getAverageFontWidth() throws IOException JavaDoc
142     {
143         COSArray descendantFontArray =
144             (COSArray)font.getDictionaryObject( COSName.getPDFName( "DescendantFonts" ) );
145
146         COSDictionary descendantFontDictionary = (COSDictionary)descendantFontArray.getObject( 0 );
147         PDFont descendentFont = PDFontFactory.createFont( descendantFontDictionary );
148
149         return descendentFont.getAverageFontWidth();
150     }
151 }
Popular Tags