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