1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 /** 25 * 26 * @file ttcr.h 27 * @brief TrueType font creator 28 * @author Alexander Gelfenbain 29 */ 30 31 #ifndef __TTCR_H 32 #define __TTCR_H 33 34 #include "sft.hxx" 35 36 namespace vcl 37 { 38 typedef struct _TrueTypeCreator TrueTypeCreator; 39 40 /* TrueType data types */ 41 typedef struct { 42 sal_uInt16 aw; 43 sal_Int16 lsb; 44 } longHorMetrics; 45 46 /* A generic base class for all TrueType tables */ 47 struct TrueTypeTable { 48 sal_uInt32 tag; /* table tag */ 49 sal_uInt8 *rawdata; /* raw data allocated by GetRawData_*() */ 50 void *data; /* table specific data */ 51 }; 52 53 /** Error codes for most functions */ 54 enum TTCRErrCodes { 55 TTCR_OK = 0, /**< no error */ 56 TTCR_ZEROGLYPHS = 1, /**< At least one glyph should be defined */ 57 TTCR_UNKNOWN = 2, /**< Unknown TrueType table */ 58 TTCR_GLYPHSEQ = 3, /**< Glyph IDs are not sequential in the glyf table */ 59 TTCR_NONAMES = 4, /**< 'name' table does not contain any names */ 60 TTCR_NAMETOOLONG = 5, /**< 'name' table is too long (string data > 64K) */ 61 TTCR_POSTFORMAT = 6 /**< unsupported format of a 'post' table */ 62 }; 63 64 /* ============================================================================ 65 * TrueTypeCreator methods 66 * ============================================================================ */ 67 68 /** 69 * TrueTypeCreator constructor. 70 * Allocates all internal structures. 71 */ 72 void TrueTypeCreatorNewEmpty(sal_uInt32 tag, TrueTypeCreator **_this); 73 74 /** 75 * Adds a TrueType table to the TrueType creator. 76 * SF_TABLEFORMAT value. 77 * @return value of SFErrCodes type 78 */ 79 int AddTable(TrueTypeCreator *_this, TrueTypeTable *table); 80 81 /** 82 * Removes a TrueType table from the TrueType creator if it is stored there. 83 * It also calls a TrueTypeTable destructor. 84 * Note: all generic tables (with tag 0) will be removed if this function is 85 * called with the second argument of 0. 86 * @return value of SFErrCodes type 87 */ 88 void RemoveTable(TrueTypeCreator *_this, sal_uInt32 tag); 89 90 91 92 /** 93 * Writes a TrueType font generated by the TrueTypeCreator to a segment of 94 * memory that this method allocates. When it is not needed anymore the caller 95 * is supposed to call free() on it. 96 * @return value of SFErrCodes type 97 */ 98 int StreamToMemory(TrueTypeCreator *_this, sal_uInt8 **ptr, sal_uInt32 *length); 99 100 /** 101 * Writes a TrueType font generated by the TrueTypeCreator to a file 102 * @return value of SFErrCodes type 103 */ 104 int StreamToFile(TrueTypeCreator *_this, const char* fname); 105 106 107 /* ============================================================================ 108 * TrueTypeTable methods 109 * ============================================================================ */ 110 111 112 /** 113 * This function converts the data of a TrueType table to a raw array of bytes. 114 * It may allocates the memory for it and returns the size of the raw data in bytes. 115 * If memory is allocated it does not need to be freed by the caller of this function, 116 * since the pointer to it is stored in the TrueTypeTable and it is freed by the destructor 117 * @return TTCRErrCode 118 * 119 */ 120 121 int GetRawData(TrueTypeTable *, sal_uInt8 **ptr, sal_uInt32 *len, sal_uInt32 *tag); 122 123 /** 124 * 125 * Creates a new raw TrueType table. The difference between this constructor and 126 * TrueTypeTableNew_tag constructors is that the latter create structured tables 127 * while this constructor just copies memory pointed to by ptr to its buffer 128 * and stores its length. This constructor is suitable for data that is not 129 * supposed to be processed in any way, just written to the resulting TTF file. 130 */ 131 TrueTypeTable *TrueTypeTableNew(sal_uInt32 tag, 132 sal_uInt32 nbytes, 133 const sal_uInt8* ptr); 134 135 /** 136 * Creates a new 'head' table for a TrueType font. 137 * Allocates memory for it. Since a lot of values in the 'head' table depend on the 138 * rest of the tables in the TrueType font this table should be the last one added 139 * to the font. 140 */ 141 TrueTypeTable *TrueTypeTableNew_head(sal_uInt32 fontRevision, 142 sal_uInt16 flags, 143 sal_uInt16 unitsPerEm, 144 const sal_uInt8 *created, 145 sal_uInt16 macStyle, 146 sal_uInt16 lowestRecPPEM, 147 sal_Int16 fontDirectionHint); 148 149 /** 150 * Creates a new 'hhea' table for a TrueType font. 151 * Allocates memory for it and stores it in the hhea pointer. 152 */ 153 TrueTypeTable *TrueTypeTableNew_hhea(sal_Int16 ascender, 154 sal_Int16 descender, 155 sal_Int16 linegap, 156 sal_Int16 caretSlopeRise, 157 sal_Int16 caretSlopeRun); 158 159 /** 160 * Creates a new empty 'loca' table for a TrueType font. 161 * 162 * INTERNAL: gets called only from ProcessTables(); 163 */ 164 TrueTypeTable *TrueTypeTableNew_loca(void); 165 166 /** 167 * Creates a new 'maxp' table based on an existing maxp table. 168 * If maxp is 0, a new empty maxp table is created 169 * size specifies the size of existing maxp table for 170 * error-checking purposes 171 */ 172 TrueTypeTable *TrueTypeTableNew_maxp( const sal_uInt8* maxp, int size); 173 174 /** 175 * Creates a new empty 'glyf' table. 176 */ 177 TrueTypeTable *TrueTypeTableNew_glyf(void); 178 179 /** 180 * Creates a new empty 'cmap' table. 181 */ 182 TrueTypeTable *TrueTypeTableNew_cmap(void); 183 184 /** 185 * Creates a new 'name' table. If n != 0 the table gets populated by 186 * the Name Records stored in the nr array. This function allocates 187 * memory for its own copy of NameRecords, so nr array has to 188 * be explicitly deallocated when it is not needed. 189 */ 190 TrueTypeTable *TrueTypeTableNew_name(int n, NameRecord *nr); 191 192 /** 193 * Creates a new 'post' table of one of the supported formats 194 */ 195 TrueTypeTable *TrueTypeTableNew_post(sal_uInt32 format, 196 sal_uInt32 italicAngle, 197 sal_Int16 underlinePosition, 198 sal_Int16 underlineThickness, 199 sal_uInt32 isFixedPitch); 200 201 202 /*------------------------------------------------------------------------------ 203 * Table manipulation functions 204 *------------------------------------------------------------------------------*/ 205 206 207 /** 208 * Add a character/glyph pair to a cmap table 209 */ 210 void cmapAdd(TrueTypeTable *, sal_uInt32 id, sal_uInt32 c, sal_uInt32 g); 211 212 /** 213 * Add a glyph to a glyf table. 214 * 215 * @return glyphID of the glyph in the new font 216 * 217 * NOTE: This function does not duplicate GlyphData, so memory will be 218 * deallocated in the table destructor 219 */ 220 sal_uInt32 glyfAdd(TrueTypeTable *, GlyphData *glyphdata, TrueTypeFont *fnt); 221 222 /** 223 * Query the number of glyphs currently stored in the 'glyf' table 224 * 225 */ 226 sal_uInt32 glyfCount(const TrueTypeTable *); 227 228 /** 229 * Add a Name Record to a name table. 230 * NOTE: This function duplicates NameRecord, so the argument 231 * has to be deallocated by the caller (unlike glyfAdd) 232 */ 233 void nameAdd(TrueTypeTable *, NameRecord *nr); 234 235 } // namespace 236 237 238 extern "C" 239 { 240 /** 241 * Destructor for the TrueTypeTable object. 242 */ 243 void TrueTypeTableDispose(vcl::TrueTypeTable *); 244 245 /** 246 * TrueTypeCreator destructor. It calls destructors for all TrueTypeTables added to it. 247 */ 248 void TrueTypeCreatorDispose(vcl::TrueTypeCreator *_this); 249 } 250 251 #endif /* __TTCR_H */ 252 253 /* vim: set noet sw=4 ts=4: */ 254