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