1 31 package org.pdfbox.ttf; 32 33 import java.io.IOException ; 34 35 import org.pdfbox.cos.COSName; 36 37 import org.pdfbox.encoding.MacRomanEncoding; 38 39 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 [] glyphNames = null; 57 58 61 public static final String TAG = "post"; 62 63 70 public void initData( TrueTypeFont ttf, TTFDataStream data ) throws IOException 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 91 glyphNames = new String [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 [ 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 [] nameArray = null; 114 if( maxIndex >= 258 ) 115 { 116 nameArray = new String [ 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 ( "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 [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 } 163 } 164 167 public float getFormatType() 168 { 169 return formatType; 170 } 171 174 public void setFormatType(float formatTypeValue) 175 { 176 this.formatType = formatTypeValue; 177 } 178 181 public long getIsFixedPitch() 182 { 183 return isFixedPitch; 184 } 185 188 public void setIsFixedPitch(long isFixedPitchValue) 189 { 190 this.isFixedPitch = isFixedPitchValue; 191 } 192 195 public float getItalicAngle() 196 { 197 return italicAngle; 198 } 199 202 public void setItalicAngle(float italicAngleValue) 203 { 204 this.italicAngle = italicAngleValue; 205 } 206 209 public long getMaxMemType1() 210 { 211 return maxMemType1; 212 } 213 216 public void setMaxMemType1(long maxMemType1Value) 217 { 218 this.maxMemType1 = maxMemType1Value; 219 } 220 223 public long getMaxMemType42() 224 { 225 return maxMemType42; 226 } 227 230 public void setMaxMemType42(long maxMemType42Value) 231 { 232 this.maxMemType42 = maxMemType42Value; 233 } 234 237 public long getMimMemType1() 238 { 239 return mimMemType1; 240 } 241 244 public void setMimMemType1(long mimMemType1Value) 245 { 246 this.mimMemType1 = mimMemType1Value; 247 } 248 251 public long getMinMemType42() 252 { 253 return minMemType42; 254 } 255 258 public void setMinMemType42(long minMemType42Value) 259 { 260 this.minMemType42 = minMemType42Value; 261 } 262 265 public short getUnderlinePosition() 266 { 267 return underlinePosition; 268 } 269 272 public void setUnderlinePosition(short underlinePositionValue) 273 { 274 this.underlinePosition = underlinePositionValue; 275 } 276 279 public short getUnderlineThickness() 280 { 281 return underlineThickness; 282 } 283 286 public void setUnderlineThickness(short underlineThicknessValue) 287 { 288 this.underlineThickness = underlineThicknessValue; 289 } 290 293 public String [] getGlyphNames() 294 { 295 return glyphNames; 296 } 297 300 public void setGlyphNames(String [] glyphNamesValue) 301 { 302 this.glyphNames = glyphNamesValue; 303 } 304 } 305 | Popular Tags |