1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.fontbox.ttf; 18 19 import java.util.Collection; 20 import java.util.HashMap; 21 import java.util.Map; 22 23 import java.io.IOException; 24 import java.io.InputStream; 25 26 /** 27 * A class to hold true type font information. 28 * 29 * @author Ben Litchfield (ben@benlitchfield.com) 30 * @version $Revision: 1.2 $ 31 */ 32 public class TrueTypeFont 33 { 34 private float version; 35 36 private Map<String,TTFTable> tables = new HashMap<String,TTFTable>(); 37 38 private TTFDataStream data; 39 40 /** 41 * Constructor. Clients should use the TTFParser to create a new TrueTypeFont object. 42 * 43 * @param fontData The font data. 44 */ 45 TrueTypeFont( TTFDataStream fontData ) 46 { 47 data = fontData; 48 } 49 50 /** 51 * Close the underlying resources. 52 * 53 * @throws IOException If there is an error closing the resources. 54 */ 55 public void close() throws IOException 56 { 57 data.close(); 58 } 59 60 /** 61 * @return Returns the version. 62 */ 63 public float getVersion() 64 { 65 return version; 66 } 67 /** 68 * @param versionValue The version to set. 69 */ 70 public void setVersion(float versionValue) 71 { 72 version = versionValue; 73 } 74 75 /** 76 * Add a table definition. 77 * 78 * @param table The table to add. 79 */ 80 public void addTable( TTFTable table ) 81 { 82 tables.put( table.getTag(), table ); 83 } 84 85 /** 86 * Get all of the tables. 87 * 88 * @return All of the tables. 89 */ 90 public Collection<TTFTable> getTables() 91 { 92 return tables.values(); 93 } 94 95 /** 96 * This will get the naming table for the true type font. 97 * 98 * @return The naming table. 99 */ 100 public NamingTable getNaming() 101 { 102 return (NamingTable)tables.get( NamingTable.TAG ); 103 } 104 105 /** 106 * Get the postscript table for this TTF. 107 * 108 * @return The postscript table. 109 */ 110 public PostScriptTable getPostScript() 111 { 112 return (PostScriptTable)tables.get( PostScriptTable.TAG ); 113 } 114 115 /** 116 * Get the OS/2 table for this TTF. 117 * 118 * @return The OS/2 table. 119 */ 120 public OS2WindowsMetricsTable getOS2Windows() 121 { 122 return (OS2WindowsMetricsTable)tables.get( OS2WindowsMetricsTable.TAG ); 123 } 124 125 /** 126 * Get the maxp table for this TTF. 127 * 128 * @return The maxp table. 129 */ 130 public MaximumProfileTable getMaximumProfile() 131 { 132 return (MaximumProfileTable)tables.get( MaximumProfileTable.TAG ); 133 } 134 135 /** 136 * Get the head table for this TTF. 137 * 138 * @return The head table. 139 */ 140 public HeaderTable getHeader() 141 { 142 return (HeaderTable)tables.get( HeaderTable.TAG ); 143 } 144 145 /** 146 * Get the hhea table for this TTF. 147 * 148 * @return The hhea table. 149 */ 150 public HorizontalHeaderTable getHorizontalHeader() 151 { 152 return (HorizontalHeaderTable)tables.get( HorizontalHeaderTable.TAG ); 153 } 154 155 /** 156 * Get the hmtx table for this TTF. 157 * 158 * @return The hmtx table. 159 */ 160 public HorizontalMetricsTable getHorizontalMetrics() 161 { 162 return (HorizontalMetricsTable)tables.get( HorizontalMetricsTable.TAG ); 163 } 164 165 /** 166 * Get the loca table for this TTF. 167 * 168 * @return The loca table. 169 */ 170 public IndexToLocationTable getIndexToLocation() 171 { 172 return (IndexToLocationTable)tables.get( IndexToLocationTable.TAG ); 173 } 174 175 /** 176 * Get the glyf table for this TTF. 177 * 178 * @return The glyf table. 179 */ 180 public GlyphTable getGlyph() 181 { 182 return (GlyphTable)tables.get( GlyphTable.TAG ); 183 } 184 185 /** 186 * Get the cmap table for this TTF. 187 * 188 * @return The cmap table. 189 */ 190 public CMAPTable getCMAP() 191 { 192 return (CMAPTable)tables.get( CMAPTable.TAG ); 193 } 194 195 /** 196 * This permit to get the data of the True Type Font 197 * program representing the stream used to build this 198 * object (normally from the TTFParser object). 199 * 200 * @return COSStream True type font program stream 201 * 202 * @throws IOException If there is an error getting the font data. 203 */ 204 public InputStream getOriginalData() throws IOException 205 { 206 return data.getOriginalData(); 207 } 208 }