KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
34
35 import org.pdfbox.cos.COSName;
36
37 import org.pdfbox.encoding.MacRomanEncoding;
38
39 /**
40  * A table in a true type font.
41  *
42  * @author Ben Litchfield (ben@csh.rit.edu)
43  * @version $Revision: 1.1 $
44  */

45 public class PostScriptTable extends TTFTable
46 {
47     private float formatType;
48     private float italicAngle;
49     private short underlinePosition;
50     private short underlineThickness;
51     private long isFixedPitch;
52     private long minMemType42;
53     private long maxMemType42;
54     private long mimMemType1;
55     private long maxMemType1;
56     private String JavaDoc[] glyphNames = null;
57     
58     /**
59      * A tag that identifies this table type.
60      */

61     public static final String JavaDoc TAG = "post";
62     
63     /**
64      * This will read the required data from the stream.
65      *
66      * @param ttf The font that is being read.
67      * @param data The stream to read the data from.
68      * @throws IOException If there is an error reading the data.
69      */

70     public void initData( TrueTypeFont ttf, TTFDataStream data ) throws IOException JavaDoc
71     {
72         MaximumProfileTable maxp = ttf.getMaximumProfile();
73         formatType = data.read32Fixed();
74         italicAngle = data.read32Fixed();
75         underlinePosition = data.readSignedShort();
76         underlineThickness = data.readSignedShort();
77         isFixedPitch = data.readUnsignedInt();
78         minMemType42 = data.readUnsignedInt();
79         maxMemType42 = data.readUnsignedInt();
80         mimMemType1 = data.readUnsignedInt();
81         maxMemType1 = data.readUnsignedInt();
82         MacRomanEncoding encoding = new MacRomanEncoding();
83         
84         
85         if( formatType == 1.0f )
86         {
87             /*
88              * This TrueType font file contains exactly the 258 glyphs in the standard
89              * Macintosh TrueType.
90              */

91             glyphNames = new String JavaDoc[258];
92             for( int i=0; i<glyphNames.length; i++)
93             {
94                 COSName name = encoding.getName( i );
95                 if( name != null )
96                 {
97                     glyphNames[i] = name.getName();
98                 }
99             }
100         }
101         else if( formatType == 2.0f )
102         {
103             int numGlyphs = data.readUnsignedShort();
104             int[] glyphNameIndex = new int[numGlyphs];
105             glyphNames = new String JavaDoc[ numGlyphs ];
106             int maxIndex = Integer.MIN_VALUE;
107             for( int i=0; i<numGlyphs; i++ )
108             {
109                 int index = data.readUnsignedShort();
110                 glyphNameIndex[i] = index;
111                 maxIndex = Math.max( maxIndex, index );
112             }
113             String JavaDoc[] nameArray = null;
114             if( maxIndex >= 258 )
115             {
116                 nameArray = new String JavaDoc[ maxIndex-258 +1 ];
117                 for( int i=0; i<maxIndex-258+1; i++ )
118                 {
119                     int numberOfChars = data.read();
120                     nameArray[i]=data.readString( numberOfChars );
121                 }
122             }
123             for( int i=0; i<numGlyphs; i++ )
124             {
125                 int index = glyphNameIndex[i];
126                 if( index < 258 )
127                 {
128                     glyphNames[i] = encoding.getName( index ).getName();
129                 }
130                 else if( index >= 258 && index <= 32767 )
131                 {
132                     glyphNames[i] = nameArray[index-258];
133                 }
134                 else
135                 {
136                     throw new IOException JavaDoc( "Unknown glyph name index:" + index );
137                 }
138             }
139         }
140         else if( formatType == 2.5f )
141         {
142             int[] glyphNameIndex = new int[maxp.getNumGlyphs()];
143             for( int i=0; i<glyphNameIndex.length; i++)
144             {
145                 int offset = data.readSignedByte();
146                 glyphNameIndex[i] = i+1+offset;
147             }
148             glyphNames = new String JavaDoc[glyphNameIndex.length];
149             for( int i=0; i<glyphNames.length; i++)
150             {
151                 COSName name = encoding.getName( glyphNameIndex[i] );
152                 if( name != null )
153                 {
154                     glyphNames[i] = name.getName();
155                 }
156             }
157             
158         }
159         else if( formatType == 3.0f )
160         {
161             //no postscript information is provided.
162
}
163     }
164     /**
165      * @return Returns the formatType.
166      */

167     public float getFormatType()
168     {
169         return formatType;
170     }
171     /**
172      * @param formatTypeValue The formatType to set.
173      */

174     public void setFormatType(float formatTypeValue)
175     {
176         this.formatType = formatTypeValue;
177     }
178     /**
179      * @return Returns the isFixedPitch.
180      */

181     public long getIsFixedPitch()
182     {
183         return isFixedPitch;
184     }
185     /**
186      * @param isFixedPitchValue The isFixedPitch to set.
187      */

188     public void setIsFixedPitch(long isFixedPitchValue)
189     {
190         this.isFixedPitch = isFixedPitchValue;
191     }
192     /**
193      * @return Returns the italicAngle.
194      */

195     public float getItalicAngle()
196     {
197         return italicAngle;
198     }
199     /**
200      * @param italicAngleValue The italicAngle to set.
201      */

202     public void setItalicAngle(float italicAngleValue)
203     {
204         this.italicAngle = italicAngleValue;
205     }
206     /**
207      * @return Returns the maxMemType1.
208      */

209     public long getMaxMemType1()
210     {
211         return maxMemType1;
212     }
213     /**
214      * @param maxMemType1Value The maxMemType1 to set.
215      */

216     public void setMaxMemType1(long maxMemType1Value)
217     {
218         this.maxMemType1 = maxMemType1Value;
219     }
220     /**
221      * @return Returns the maxMemType42.
222      */

223     public long getMaxMemType42()
224     {
225         return maxMemType42;
226     }
227     /**
228      * @param maxMemType42Value The maxMemType42 to set.
229      */

230     public void setMaxMemType42(long maxMemType42Value)
231     {
232         this.maxMemType42 = maxMemType42Value;
233     }
234     /**
235      * @return Returns the mimMemType1.
236      */

237     public long getMimMemType1()
238     {
239         return mimMemType1;
240     }
241     /**
242      * @param mimMemType1Value The mimMemType1 to set.
243      */

244     public void setMimMemType1(long mimMemType1Value)
245     {
246         this.mimMemType1 = mimMemType1Value;
247     }
248     /**
249      * @return Returns the minMemType42.
250      */

251     public long getMinMemType42()
252     {
253         return minMemType42;
254     }
255     /**
256      * @param minMemType42Value The minMemType42 to set.
257      */

258     public void setMinMemType42(long minMemType42Value)
259     {
260         this.minMemType42 = minMemType42Value;
261     }
262     /**
263      * @return Returns the underlinePosition.
264      */

265     public short getUnderlinePosition()
266     {
267         return underlinePosition;
268     }
269     /**
270      * @param underlinePositionValue The underlinePosition to set.
271      */

272     public void setUnderlinePosition(short underlinePositionValue)
273     {
274         this.underlinePosition = underlinePositionValue;
275     }
276     /**
277      * @return Returns the underlineThickness.
278      */

279     public short getUnderlineThickness()
280     {
281         return underlineThickness;
282     }
283     /**
284      * @param underlineThicknessValue The underlineThickness to set.
285      */

286     public void setUnderlineThickness(short underlineThicknessValue)
287     {
288         this.underlineThickness = underlineThicknessValue;
289     }
290     /**
291      * @return Returns the glyphNames.
292      */

293     public String JavaDoc[] getGlyphNames()
294     {
295         return glyphNames;
296     }
297     /**
298      * @param glyphNamesValue The glyphNames to set.
299      */

300     public void setGlyphNames(String JavaDoc[] glyphNamesValue)
301     {
302         this.glyphNames = glyphNamesValue;
303     }
304 }
305
Popular Tags