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 * 66 * TrueTypeCreator methods 67 * 68 * ============================================================================ */ 69 70 /** 71 * TrueTypeCreator constructor. 72 * Allocates all internal structures. 73 */ 74 void TrueTypeCreatorNewEmpty(sal_uInt32 tag, TrueTypeCreator **_this); 75 76 /** 77 * Adds a TrueType table to the TrueType creator. 78 * SF_TABLEFORMAT value. 79 * @return value of SFErrCodes type 80 */ 81 int AddTable(TrueTypeCreator *_this, TrueTypeTable *table); 82 83 /** 84 * Removes a TrueType table from the TrueType creator if it is stored there. 85 * It also calls a TrueTypeTable destructor. 86 * Note: all generic tables (with tag 0) will be removed if this function is 87 * called with the second argument of 0. 88 * @return value of SFErrCodes type 89 */ 90 void RemoveTable(TrueTypeCreator *_this, sal_uInt32 tag); 91 92 93 94 /** 95 * Writes a TrueType font generated by the TrueTypeCreator to a segment of 96 * memory that this method allocates. When it is not needed anymore the caller 97 * is supposed to call free() on it. 98 * @return value of SFErrCodes type 99 */ 100 int StreamToMemory(TrueTypeCreator *_this, sal_uInt8 **ptr, sal_uInt32 *length); 101 102 /** 103 * Writes a TrueType font generated by the TrueTypeCreator to a file 104 * @return value of SFErrCodes type 105 */ 106 int StreamToFile(TrueTypeCreator *_this, const char* fname); 107 108 109 /* ============================================================================ 110 * 111 * TrueTypeTable methods 112 * 113 * ============================================================================ */ 114 115 116 /** 117 * This function converts the data of a TrueType table to a raw array of bytes. 118 * It may allocates the memory for it and returns the size of the raw data in bytes. 119 * If memory is allocated it does not need to be freed by the caller of this function, 120 * since the pointer to it is stored in the TrueTypeTable and it is freed by the destructor 121 * @return TTCRErrCode 122 * 123 */ 124 125 int GetRawData(TrueTypeTable *, sal_uInt8 **ptr, sal_uInt32 *len, sal_uInt32 *tag); 126 127 /** 128 * 129 * Creates a new raw TrueType table. The difference between this constructor and 130 * TrueTypeTableNew_tag constructors is that the latter create structured tables 131 * while this constructor just copies memory pointed to by ptr to its buffer 132 * and stores its length. This constructor is suitable for data that is not 133 * supposed to be processed in any way, just written to the resulting TTF file. 134 */ 135 TrueTypeTable *TrueTypeTableNew(sal_uInt32 tag, 136 sal_uInt32 nbytes, 137 const sal_uInt8* ptr); 138 139 /** 140 * Creates a new 'head' table for a TrueType font. 141 * Allocates memory for it. Since a lot of values in the 'head' table depend on the 142 * rest of the tables in the TrueType font this table should be the last one added 143 * to the font. 144 */ 145 TrueTypeTable *TrueTypeTableNew_head(sal_uInt32 fontRevision, 146 sal_uInt16 flags, 147 sal_uInt16 unitsPerEm, 148 const sal_uInt8 *created, 149 sal_uInt16 macStyle, 150 sal_uInt16 lowestRecPPEM, 151 sal_Int16 fontDirectionHint); 152 153 /** 154 * Creates a new 'hhea' table for a TrueType font. 155 * Allocates memory for it and stores it in the hhea pointer. 156 */ 157 TrueTypeTable *TrueTypeTableNew_hhea(sal_Int16 ascender, 158 sal_Int16 descender, 159 sal_Int16 linegap, 160 sal_Int16 caretSlopeRise, 161 sal_Int16 caretSlopeRun); 162 163 /** 164 * Creates a new empty 'loca' table for a TrueType font. 165 * 166 * INTERNAL: gets called only from ProcessTables(); 167 */ 168 TrueTypeTable *TrueTypeTableNew_loca(void); 169 170 /** 171 * Creates a new 'maxp' table based on an existing maxp table. 172 * If maxp is 0, a new empty maxp table is created 173 * size specifies the size of existing maxp table for 174 * error-checking purposes 175 */ 176 TrueTypeTable *TrueTypeTableNew_maxp( const sal_uInt8* maxp, int size); 177 178 /** 179 * Creates a new empty 'glyf' table. 180 */ 181 TrueTypeTable *TrueTypeTableNew_glyf(void); 182 183 /** 184 * Creates a new empty 'cmap' table. 185 */ 186 TrueTypeTable *TrueTypeTableNew_cmap(void); 187 188 /** 189 * Creates a new 'name' table. If n != 0 the table gets populated by 190 * the Name Records stored in the nr array. This function allocates 191 * memory for its own copy of NameRecords, so nr array has to 192 * be explicitly deallocated when it is not needed. 193 */ 194 TrueTypeTable *TrueTypeTableNew_name(int n, NameRecord *nr); 195 196 /** 197 * Creates a new 'post' table of one of the supported formats 198 */ 199 TrueTypeTable *TrueTypeTableNew_post(sal_uInt32 format, 200 sal_uInt32 italicAngle, 201 sal_Int16 underlinePosition, 202 sal_Int16 underlineThickness, 203 sal_uInt32 isFixedPitch); 204 205 206 /*------------------------------------------------------------------------------ 207 * 208 * Table manipulation functions 209 * 210 *------------------------------------------------------------------------------*/ 211 212 213 /** 214 * Add a character/glyph pair to a cmap table 215 */ 216 void cmapAdd(TrueTypeTable *, sal_uInt32 id, sal_uInt32 c, sal_uInt32 g); 217 218 /** 219 * Add a glyph to a glyf table. 220 * 221 * @return glyphID of the glyph in the new font 222 * 223 * NOTE: This function does not duplicate GlyphData, so memory will be 224 * deallocated in the table destructor 225 */ 226 sal_uInt32 glyfAdd(TrueTypeTable *, GlyphData *glyphdata, TrueTypeFont *fnt); 227 228 /** 229 * Query the number of glyphs currently stored in the 'glyf' table 230 * 231 */ 232 sal_uInt32 glyfCount(const TrueTypeTable *); 233 234 /** 235 * Add a Name Record to a name table. 236 * NOTE: This function duplicates NameRecord, so the argument 237 * has to be deallocated by the caller (unlike glyfAdd) 238 */ 239 void nameAdd(TrueTypeTable *, NameRecord *nr); 240 241 } // namespace 242 243 244 extern "C" 245 { 246 /** 247 * Destructor for the TrueTypeTable object. 248 */ 249 void TrueTypeTableDispose(vcl::TrueTypeTable *); 250 251 /** 252 * TrueTypeCreator destructor. It calls destructors for all TrueTypeTables added to it. 253 */ 254 void TrueTypeCreatorDispose(vcl::TrueTypeCreator *_this); 255 } 256 257 #endif /* __TTCR_H */ 258