KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > ttf > TrueTypeFont


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.ttf;
32
33 import java.util.Collection JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.Map JavaDoc;
36
37 import java.io.IOException JavaDoc;
38
39 import org.pdfbox.cos.COSStream;
40
41 /**
42  * A class to hold true type font information.
43  *
44  * @author Ben Litchfield (ben@csh.rit.edu)
45  * @version $Revision: 1.3 $
46  */

47 public class TrueTypeFont
48 {
49     private float version;
50     
51     private Map JavaDoc tables = new HashMap JavaDoc();
52     
53     private TTFDataStream data;
54     
55     /**
56      * Constructor. Clients should use the TTFParser to create a new TrueTypeFont object.
57      *
58      * @param fontData The font data.
59      */

60     TrueTypeFont( TTFDataStream fontData )
61     {
62         data = fontData;
63     }
64     
65     /**
66      * Close the underlying resources.
67      *
68      * @throws IOException If there is an error closing the resources.
69      */

70     public void close() throws IOException JavaDoc
71     {
72         data.close();
73     }
74
75     /**
76      * @return Returns the version.
77      */

78     public float getVersion()
79     {
80         return version;
81     }
82     /**
83      * @param versionValue The version to set.
84      */

85     public void setVersion(float versionValue)
86     {
87         version = versionValue;
88     }
89     
90     /**
91      * Add a table definition.
92      *
93      * @param table The table to add.
94      */

95     public void addTable( TTFTable table )
96     {
97         tables.put( table.getTag(), table );
98     }
99     
100     /**
101      * Get all of the tables.
102      *
103      * @return All of the tables.
104      */

105     public Collection JavaDoc getTables()
106     {
107         return tables.values();
108     }
109     
110     /**
111      * This will get the naming table for the true type font.
112      *
113      * @return The naming table.
114      */

115     public NamingTable getNaming()
116     {
117         return (NamingTable)tables.get( NamingTable.TAG );
118     }
119     
120     /**
121      * Get the postscript table for this TTF.
122      *
123      * @return The postscript table.
124      */

125     public PostScriptTable getPostScript()
126     {
127         return (PostScriptTable)tables.get( PostScriptTable.TAG );
128     }
129     
130     /**
131      * Get the OS/2 table for this TTF.
132      *
133      * @return The OS/2 table.
134      */

135     public OS2WindowsMetricsTable getOS2Windows()
136     {
137         return (OS2WindowsMetricsTable)tables.get( OS2WindowsMetricsTable.TAG );
138     }
139     
140     /**
141      * Get the maxp table for this TTF.
142      *
143      * @return The maxp table.
144      */

145     public MaximumProfileTable getMaximumProfile()
146     {
147         return (MaximumProfileTable)tables.get( MaximumProfileTable.TAG );
148     }
149     
150     /**
151      * Get the head table for this TTF.
152      *
153      * @return The head table.
154      */

155     public HeaderTable getHeader()
156     {
157         return (HeaderTable)tables.get( HeaderTable.TAG );
158     }
159     
160     /**
161      * Get the hhea table for this TTF.
162      *
163      * @return The hhea table.
164      */

165     public HorizontalHeaderTable getHorizontalHeader()
166     {
167         return (HorizontalHeaderTable)tables.get( HorizontalHeaderTable.TAG );
168     }
169     
170     /**
171      * Get the hmtx table for this TTF.
172      *
173      * @return The hmtx table.
174      */

175     public HorizontalMetricsTable getHorizontalMetrics()
176     {
177         return (HorizontalMetricsTable)tables.get( HorizontalMetricsTable.TAG );
178     }
179     
180     /**
181      * Get the loca table for this TTF.
182      *
183      * @return The loca table.
184      */

185     public IndexToLocationTable getIndexToLocation()
186     {
187         return (IndexToLocationTable)tables.get( IndexToLocationTable.TAG );
188     }
189     
190     /**
191      * Get the glyf table for this TTF.
192      *
193      * @return The glyf table.
194      */

195     public GlyphTable getGlyph()
196     {
197         return (GlyphTable)tables.get( GlyphTable.TAG );
198     }
199     
200     /**
201      * Get the cmap table for this TTF.
202      *
203      * @return The cmap table.
204      */

205     public CMAPTable getCMAP()
206     {
207         return (CMAPTable)tables.get( CMAPTable.TAG );
208     }
209     
210     /**
211      * This permit to get the COSStream of the True Type Font
212      * program representing the stream used to build this
213      * object (normally from the TTFParser object).
214      *
215      * @return COSStream True type font program stream
216      */

217     public COSStream getCOSStream()
218     {
219        return data.getCOSStream();
220     }
221 }
222
Popular Tags