10d63794cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 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 100d63794cSAndrew Rist * 110d63794cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 120d63794cSAndrew Rist * 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. 190d63794cSAndrew Rist * 200d63794cSAndrew Rist *************************************************************/ 210d63794cSAndrew Rist 220d63794cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir /** 25cdf0e10cSrcweir * @file sft.h 26cdf0e10cSrcweir * @brief Sun Font Tools 27cdf0e10cSrcweir * @author Alexander Gelfenbain 28cdf0e10cSrcweir */ 29cdf0e10cSrcweir 30cdf0e10cSrcweir /* 31cdf0e10cSrcweir * If NO_MAPPERS is defined, MapChar() and MapString() and consequently GetTTSimpleCharMetrics() 32cdf0e10cSrcweir * don't get compiled in. This is done to avoid including a large chunk of code (TranslateXY() from 33cdf0e10cSrcweir * xlat.c in the projects that don't require it. 34cdf0e10cSrcweir * 35cdf0e10cSrcweir * If NO_TYPE3 is defined CreateT3FromTTGlyphs() does not get compiled in. 36cdf0e10cSrcweir * If NO_TYPE42 is defined Type42-related code is excluded 37cdf0e10cSrcweir * If NO_TTCR is defined TrueType creation related code is excluded\ 38cdf0e10cSrcweir */ 39cdf0e10cSrcweir 40cdf0e10cSrcweir /* 41cdf0e10cSrcweir * Generated fonts contain an XUID entry in the form of: 42cdf0e10cSrcweir * 43cdf0e10cSrcweir * 103 0 T C1 N C2 C3 44cdf0e10cSrcweir * 45cdf0e10cSrcweir * 103 - Sun's Adobe assigned XUID number. Contact person: Alexander Gelfenbain <gelf@eng.sun.com> 46cdf0e10cSrcweir * 47cdf0e10cSrcweir * T - font type. 0: Type 3, 1: Type 42 48cdf0e10cSrcweir * C1 - CRC-32 of the entire source TrueType font 49cdf0e10cSrcweir * N - number of glyphs in the subset 50cdf0e10cSrcweir * C2 - CRC-32 of the array of glyph IDs used to generate the subset 51cdf0e10cSrcweir * C3 - CRC-32 of the array of encoding numbers used to generate the subset 52cdf0e10cSrcweir * 53cdf0e10cSrcweir */ 54cdf0e10cSrcweir 55cdf0e10cSrcweir 56cdf0e10cSrcweir #ifndef __SUBFONT_H 57cdf0e10cSrcweir #define __SUBFONT_H 58cdf0e10cSrcweir 59cdf0e10cSrcweir #ifdef UNX 60cdf0e10cSrcweir #include <sys/types.h> 61cdf0e10cSrcweir #include <unistd.h> 62cdf0e10cSrcweir #endif 63cdf0e10cSrcweir #include <stdio.h> 64cdf0e10cSrcweir 65cdf0e10cSrcweir #include <sal/types.h> 66cdf0e10cSrcweir 67cdf0e10cSrcweir #include "vcl/dllapi.h" 68cdf0e10cSrcweir 69cdf0e10cSrcweir #include <vector> 70cdf0e10cSrcweir 71cdf0e10cSrcweir namespace vcl 72cdf0e10cSrcweir { 73cdf0e10cSrcweir 74cdf0e10cSrcweir /*@{*/ 75cdf0e10cSrcweir typedef sal_Int16 F2Dot14; /**< fixed: 2.14 */ 76cdf0e10cSrcweir typedef sal_Int32 F16Dot16; /**< fixed: 16.16 */ 77cdf0e10cSrcweir /*@}*/ 78cdf0e10cSrcweir 79cdf0e10cSrcweir typedef struct { 80cdf0e10cSrcweir sal_uInt16 s; 81cdf0e10cSrcweir sal_uInt16 d; 82cdf0e10cSrcweir } sal_uInt16pair; 83cdf0e10cSrcweir 84cdf0e10cSrcweir /** Return value of OpenTTFont() and CreateT3FromTTGlyphs() */ 85cdf0e10cSrcweir enum SFErrCodes { 86cdf0e10cSrcweir SF_OK, /**< no error */ 87cdf0e10cSrcweir SF_BADFILE, /**< file not found */ 88cdf0e10cSrcweir SF_FILEIO, /**< file I/O error */ 89cdf0e10cSrcweir SF_MEMORY, /**< memory allocation error */ 90cdf0e10cSrcweir SF_GLYPHNUM, /**< incorrect number of glyphs */ 91cdf0e10cSrcweir SF_BADARG, /**< incorrect arguments */ 92cdf0e10cSrcweir SF_TTFORMAT, /**< incorrect TrueType font format */ 93cdf0e10cSrcweir SF_TABLEFORMAT, /**< incorrect format of a TrueType table */ 94cdf0e10cSrcweir SF_FONTNO /**< incorrect logical font number of a TTC font */ 95cdf0e10cSrcweir }; 96cdf0e10cSrcweir 97cdf0e10cSrcweir #ifndef FW_THIN /* WIN32 compilation would conflict */ 98cdf0e10cSrcweir /** Value of the weight member of the TTGlobalFontInfo struct */ 99cdf0e10cSrcweir enum WeightClass { 100cdf0e10cSrcweir FW_THIN = 100, /**< Thin */ 101cdf0e10cSrcweir FW_EXTRALIGHT = 200, /**< Extra-light (Ultra-light) */ 102cdf0e10cSrcweir FW_LIGHT = 300, /**< Light */ 103cdf0e10cSrcweir FW_NORMAL = 400, /**< Normal (Regular) */ 104cdf0e10cSrcweir FW_MEDIUM = 500, /**< Medium */ 105cdf0e10cSrcweir FW_SEMIBOLD = 600, /**< Semi-bold (Demi-bold) */ 106cdf0e10cSrcweir FW_BOLD = 700, /**< Bold */ 107cdf0e10cSrcweir FW_EXTRABOLD = 800, /**< Extra-bold (Ultra-bold) */ 108cdf0e10cSrcweir FW_BLACK = 900 /**< Black (Heavy) */ 109cdf0e10cSrcweir }; 110cdf0e10cSrcweir 111cdf0e10cSrcweir /** Value of the width member of the TTGlobalFontInfo struct */ 112*fc9fd3f1SPedro Giffuni #ifndef FWIDTH_DONT_CARE // OS2 113cdf0e10cSrcweir enum WidthClass { 114cdf0e10cSrcweir FWIDTH_ULTRA_CONDENSED = 1, /**< 50% of normal */ 115cdf0e10cSrcweir FWIDTH_EXTRA_CONDENSED = 2, /**< 62.5% of normal */ 116cdf0e10cSrcweir FWIDTH_CONDENSED = 3, /**< 75% of normal */ 117cdf0e10cSrcweir FWIDTH_SEMI_CONDENSED = 4, /**< 87.5% of normal */ 118cdf0e10cSrcweir FWIDTH_NORMAL = 5, /**< Medium, 100% */ 119cdf0e10cSrcweir FWIDTH_SEMI_EXPANDED = 6, /**< 112.5% of normal */ 120cdf0e10cSrcweir FWIDTH_EXPANDED = 7, /**< 125% of normal */ 121cdf0e10cSrcweir FWIDTH_EXTRA_EXPANDED = 8, /**< 150% of normal */ 122cdf0e10cSrcweir FWIDTH_ULTRA_EXPANDED = 9 /**< 200% of normal */ 123cdf0e10cSrcweir }; 124*fc9fd3f1SPedro Giffuni #endif // FWIDTH_DONT_CARE 125cdf0e10cSrcweir #endif /* FW_THIN */ 126cdf0e10cSrcweir 127cdf0e10cSrcweir /** Type of the 'kern' table, stored in _TrueTypeFont::kerntype */ 128cdf0e10cSrcweir enum KernType { 129cdf0e10cSrcweir KT_NONE = 0, /**< no kern table */ 130cdf0e10cSrcweir KT_APPLE_NEW = 1, /**< new Apple kern table */ 131cdf0e10cSrcweir KT_MICROSOFT = 2 /**< Microsoft table */ 132cdf0e10cSrcweir }; 133cdf0e10cSrcweir 134cdf0e10cSrcweir /* Composite glyph flags definition */ 135cdf0e10cSrcweir enum CompositeFlags { 136cdf0e10cSrcweir ARG_1_AND_2_ARE_WORDS = 1, 137cdf0e10cSrcweir ARGS_ARE_XY_VALUES = 1<<1, 138cdf0e10cSrcweir ROUND_XY_TO_GRID = 1<<2, 139cdf0e10cSrcweir WE_HAVE_A_SCALE = 1<<3, 140cdf0e10cSrcweir MORE_COMPONENTS = 1<<5, 141cdf0e10cSrcweir WE_HAVE_AN_X_AND_Y_SCALE = 1<<6, 142cdf0e10cSrcweir WE_HAVE_A_TWO_BY_TWO = 1<<7, 143cdf0e10cSrcweir WE_HAVE_INSTRUCTIONS = 1<<8, 144cdf0e10cSrcweir USE_MY_METRICS = 1<<9, 145cdf0e10cSrcweir OVERLAP_COMPOUND = 1<<10 146cdf0e10cSrcweir }; 147cdf0e10cSrcweir 148cdf0e10cSrcweir #ifndef NO_TTCR 149cdf0e10cSrcweir /** Flags for TrueType generation */ 150cdf0e10cSrcweir enum TTCreationFlags { 151cdf0e10cSrcweir TTCF_AutoName = 1, /**< Automatically generate a compact 'name' table. 152cdf0e10cSrcweir If this flag is not set, name table is generated 153cdf0e10cSrcweir either from an array of NameRecord structs passed as 154cdf0e10cSrcweir arguments or if the array is NULL, 'name' table 155cdf0e10cSrcweir of the generated TrueType file will be a copy 156cdf0e10cSrcweir of the name table of the original file. 157cdf0e10cSrcweir If this flag is set the array of NameRecord structs 158cdf0e10cSrcweir is ignored and a very compact 'name' table is automatically 159cdf0e10cSrcweir generated. */ 160cdf0e10cSrcweir 161cdf0e10cSrcweir TTCF_IncludeOS2 = 2 /** If this flag is set OS/2 table from the original font will be 162cdf0e10cSrcweir copied to the subset */ 163cdf0e10cSrcweir }; 164cdf0e10cSrcweir #endif 165cdf0e10cSrcweir 166cdf0e10cSrcweir 167cdf0e10cSrcweir 168cdf0e10cSrcweir 169cdf0e10cSrcweir /** Structure used by GetTTSimpleGlyphMetrics() and GetTTSimpleCharMetrics() functions */ 170cdf0e10cSrcweir typedef struct { 171cdf0e10cSrcweir sal_uInt16 adv; /**< advance width or height */ 172cdf0e10cSrcweir sal_Int16 sb; /**< left or top sidebearing */ 173cdf0e10cSrcweir } TTSimpleGlyphMetrics; 174cdf0e10cSrcweir 175cdf0e10cSrcweir 176cdf0e10cSrcweir 177cdf0e10cSrcweir /** Structure used by the TrueType Creator and GetRawGlyphData() */ 178cdf0e10cSrcweir 179cdf0e10cSrcweir typedef struct { 180cdf0e10cSrcweir sal_uInt32 glyphID; /**< glyph ID */ 181cdf0e10cSrcweir sal_uInt16 nbytes; /**< number of bytes in glyph data */ 182cdf0e10cSrcweir sal_uInt8 *ptr; /**< pointer to glyph data */ 183cdf0e10cSrcweir sal_uInt16 aw; /**< advance width */ 184cdf0e10cSrcweir sal_Int16 lsb; /**< left sidebearing */ 185cdf0e10cSrcweir sal_uInt16 compflag; /**< 0- if non-composite, 1- otherwise */ 186cdf0e10cSrcweir sal_uInt16 npoints; /**< number of points */ 187cdf0e10cSrcweir sal_uInt16 ncontours; /**< number of contours */ 188cdf0e10cSrcweir /* */ 189cdf0e10cSrcweir sal_uInt32 newID; /**< used internally by the TTCR */ 190cdf0e10cSrcweir } GlyphData; 191cdf0e10cSrcweir 192cdf0e10cSrcweir /** Structure used by the TrueType Creator and CreateTTFromTTGlyphs() */ 193cdf0e10cSrcweir typedef struct { 194cdf0e10cSrcweir sal_uInt16 platformID; /**< Platform ID */ 195cdf0e10cSrcweir sal_uInt16 encodingID; /**< Platform-specific encoding ID */ 196cdf0e10cSrcweir sal_uInt16 languageID; /**< Language ID */ 197cdf0e10cSrcweir sal_uInt16 nameID; /**< Name ID */ 198cdf0e10cSrcweir sal_uInt16 slen; /**< String length in bytes */ 199cdf0e10cSrcweir sal_uInt8 *sptr; /**< Pointer to string data (not zero-terminated!) */ 200cdf0e10cSrcweir } NameRecord; 201cdf0e10cSrcweir 202cdf0e10cSrcweir 203cdf0e10cSrcweir 204cdf0e10cSrcweir /** Return value of GetTTGlobalFontInfo() */ 205cdf0e10cSrcweir 206cdf0e10cSrcweir typedef struct { 207cdf0e10cSrcweir char *family; /**< family name */ 208cdf0e10cSrcweir sal_uInt16 *ufamily; /**< family name UCS2 */ 209cdf0e10cSrcweir char *subfamily; /**< subfamily name */ 210cdf0e10cSrcweir sal_uInt16 *usubfamily; /**< subfamily name UCS2 */ 211cdf0e10cSrcweir char *psname; /**< PostScript name */ 212cdf0e10cSrcweir sal_uInt16 macStyle; /**< macstyle bits from 'HEAD' table */ 213cdf0e10cSrcweir int weight; /**< value of WeightClass or 0 if can't be determined */ 214cdf0e10cSrcweir int width; /**< value of WidthClass or 0 if can't be determined */ 215cdf0e10cSrcweir int pitch; /**< 0: proportianal font, otherwise: monospaced */ 216cdf0e10cSrcweir int italicAngle; /**< in counter-clockwise degrees * 65536 */ 217cdf0e10cSrcweir int xMin; /**< global bounding box: xMin */ 218cdf0e10cSrcweir int yMin; /**< global bounding box: yMin */ 219cdf0e10cSrcweir int xMax; /**< global bounding box: xMax */ 220cdf0e10cSrcweir int yMax; /**< global bounding box: yMax */ 221cdf0e10cSrcweir int ascender; /**< typographic ascent. */ 222cdf0e10cSrcweir int descender; /**< typographic descent. */ 223cdf0e10cSrcweir int linegap; /**< typographic line gap.\ Negative values are treated as 224cdf0e10cSrcweir zero in Win 3.1, System 6 and System 7. */ 225cdf0e10cSrcweir int vascent; /**< typographic ascent for vertical writing mode */ 226cdf0e10cSrcweir int vdescent; /**< typographic descent for vertical writing mode */ 227cdf0e10cSrcweir int typoAscender; /**< OS/2 portable typographic ascender */ 228cdf0e10cSrcweir int typoDescender; /**< OS/2 portable typographic descender */ 229cdf0e10cSrcweir int typoLineGap; /**< OS/2 portable typographc line gap */ 230cdf0e10cSrcweir int winAscent; /**< ascender metric for Windows */ 231cdf0e10cSrcweir int winDescent; /**< descender metric for Windows */ 232cdf0e10cSrcweir int symbolEncoded; /**< 1: MS symbol encoded 0: not symbol encoded */ 233cdf0e10cSrcweir int rangeFlag; /**< if set to 1 Unicode Range flags are applicable */ 234cdf0e10cSrcweir sal_uInt32 ur1; /**< bits 0 - 31 of Unicode Range flags */ 235cdf0e10cSrcweir sal_uInt32 ur2; /**< bits 32 - 63 of Unicode Range flags */ 236cdf0e10cSrcweir sal_uInt32 ur3; /**< bits 64 - 95 of Unicode Range flags */ 237cdf0e10cSrcweir sal_uInt32 ur4; /**< bits 96 - 127 of Unicode Range flags */ 238cdf0e10cSrcweir sal_uInt8 panose[10]; /**< PANOSE classification number */ 239cdf0e10cSrcweir sal_uInt32 typeFlags; /**< type flags (copyright bits + PS-OpenType flag) */ 240cdf0e10cSrcweir } TTGlobalFontInfo; 241cdf0e10cSrcweir 242cdf0e10cSrcweir #define TYPEFLAG_INVALID 0x8000000 243cdf0e10cSrcweir #define TYPEFLAG_COPYRIGHT_MASK 0x000000E 244cdf0e10cSrcweir #define TYPEFLAG_PS_OPENTYPE 0x0010000 245cdf0e10cSrcweir 246cdf0e10cSrcweir /** Structure used by KernGlyphs() */ 247cdf0e10cSrcweir typedef struct { 248cdf0e10cSrcweir int x; /**< positive: right, negative: left */ 249cdf0e10cSrcweir int y; /**< positive: up, negative: down */ 250cdf0e10cSrcweir } KernData; 251cdf0e10cSrcweir 252cdf0e10cSrcweir 253cdf0e10cSrcweir /** ControlPoint structure used by GetTTGlyphPoints() */ 254cdf0e10cSrcweir typedef struct { 255cdf0e10cSrcweir sal_uInt32 flags; /**< 00000000 00000000 e0000000 bbbbbbbb */ 256cdf0e10cSrcweir /**< b - byte flags from the glyf array */ 257cdf0e10cSrcweir /**< e == 0 - regular point */ 258cdf0e10cSrcweir /**< e == 1 - end contour */ 259cdf0e10cSrcweir sal_Int16 x; /**< X coordinate in EmSquare units */ 260cdf0e10cSrcweir sal_Int16 y; /**< Y coordinate in EmSquare units */ 261cdf0e10cSrcweir } ControlPoint; 262cdf0e10cSrcweir 263cdf0e10cSrcweir typedef struct _TrueTypeFont TrueTypeFont; 264cdf0e10cSrcweir 265cdf0e10cSrcweir /** 266cdf0e10cSrcweir * @defgroup sft Sun Font Tools Exported Functions 267cdf0e10cSrcweir */ 268cdf0e10cSrcweir 269cdf0e10cSrcweir 270cdf0e10cSrcweir /** 271cdf0e10cSrcweir * Get the number of fonts contained in a TrueType collection 272cdf0e10cSrcweir * @param fname - file name 273cdf0e10cSrcweir * @return number of fonts or zero, if file is not a TTC file. 274cdf0e10cSrcweir * @ingroup sft 275cdf0e10cSrcweir */ 276cdf0e10cSrcweir int CountTTCFonts(const char* fname); 277cdf0e10cSrcweir 278cdf0e10cSrcweir 279cdf0e10cSrcweir /** 280cdf0e10cSrcweir * TrueTypeFont constructor. 281cdf0e10cSrcweir * The font file has to be provided as a memory buffer and length 282cdf0e10cSrcweir * @param facenum - logical font number within a TTC file. This value is ignored 283cdf0e10cSrcweir * for TrueType fonts 284cdf0e10cSrcweir * @return value of SFErrCodes enum 285cdf0e10cSrcweir * @ingroup sft 286cdf0e10cSrcweir */ 287cdf0e10cSrcweir int VCL_DLLPUBLIC OpenTTFontBuffer(void* pBuffer, sal_uInt32 nLen, sal_uInt32 facenum, TrueTypeFont** ttf); /*FOLD01*/ 288cdf0e10cSrcweir #if !defined(WIN32) && !defined(OS2) 289cdf0e10cSrcweir /** 290cdf0e10cSrcweir * TrueTypeFont constructor. 291cdf0e10cSrcweir * Reads the font file and allocates the memory for the structure. 292cdf0e10cSrcweir * on WIN32 the font has to be provided as a memory buffer and length 293cdf0e10cSrcweir * @param facenum - logical font number within a TTC file. This value is ignored 294cdf0e10cSrcweir * for TrueType fonts 295cdf0e10cSrcweir * @return value of SFErrCodes enum 296cdf0e10cSrcweir * @ingroup sft 297cdf0e10cSrcweir */ 298cdf0e10cSrcweir int VCL_DLLPUBLIC OpenTTFontFile(const char *fname, sal_uInt32 facenum, TrueTypeFont** ttf); 299cdf0e10cSrcweir #endif 300cdf0e10cSrcweir 301cdf0e10cSrcweir /** 302cdf0e10cSrcweir * TrueTypeFont destructor. Deallocates the memory. 303cdf0e10cSrcweir * @ingroup sft 304cdf0e10cSrcweir */ 305cdf0e10cSrcweir void VCL_DLLPUBLIC CloseTTFont(TrueTypeFont *); 306cdf0e10cSrcweir 307cdf0e10cSrcweir /** 308cdf0e10cSrcweir * Extracts TrueType control points, and stores them in an allocated array pointed to 309cdf0e10cSrcweir * by *pointArray. This function returns the number of extracted points. 310cdf0e10cSrcweir * 311cdf0e10cSrcweir * @param ttf pointer to the TrueTypeFont structure 312cdf0e10cSrcweir * @param glyphID Glyph ID 313cdf0e10cSrcweir * @param pointArray Return value - address of the pointer to the first element of the array 314cdf0e10cSrcweir * of points allocated by the function 315cdf0e10cSrcweir * @return Returns the number of points in *pointArray or -1 if glyphID is 316cdf0e10cSrcweir * invalid. 317cdf0e10cSrcweir * @ingroup sft 318cdf0e10cSrcweir * 319cdf0e10cSrcweir */ 320cdf0e10cSrcweir int GetTTGlyphPoints(TrueTypeFont *ttf, sal_uInt32 glyphID, ControlPoint **pointArray); 321cdf0e10cSrcweir 322cdf0e10cSrcweir /** 323cdf0e10cSrcweir * Extracts raw glyph data from the 'glyf' table and returns it in an allocated 324cdf0e10cSrcweir * GlyphData structure. 325cdf0e10cSrcweir * 326cdf0e10cSrcweir * @param ttf pointer to the TrueTypeFont structure 327cdf0e10cSrcweir * @param glyphID Glyph ID 328cdf0e10cSrcweir * 329cdf0e10cSrcweir * @return pointer to an allocated GlyphData structure or NULL if 330cdf0e10cSrcweir * glyphID is not present in the font 331cdf0e10cSrcweir * @ingroup sft 332cdf0e10cSrcweir * 333cdf0e10cSrcweir */ 334cdf0e10cSrcweir GlyphData *GetTTRawGlyphData(TrueTypeFont *ttf, sal_uInt32 glyphID); 335cdf0e10cSrcweir 336cdf0e10cSrcweir /** 337cdf0e10cSrcweir * For a specified glyph adds all component glyphs IDs to the list and 338cdf0e10cSrcweir * return their number. If the glyph is a single glyph it has one component 339cdf0e10cSrcweir * glyph (which is added to the list) and the function returns 1. 340cdf0e10cSrcweir * For a composite glyphs it returns the number of component glyphs 341cdf0e10cSrcweir * and adds all of them to the list. 342cdf0e10cSrcweir * 343cdf0e10cSrcweir * @param ttf pointer to the TrueTypeFont structure 344cdf0e10cSrcweir * @param glyphID Glyph ID 345cdf0e10cSrcweir * @param glyphlist list of glyphs 346cdf0e10cSrcweir * 347cdf0e10cSrcweir * @return number of component glyphs 348cdf0e10cSrcweir * @ingroup sft 349cdf0e10cSrcweir * 350cdf0e10cSrcweir */ 351cdf0e10cSrcweir int GetTTGlyphComponents(TrueTypeFont *ttf, sal_uInt32 glyphID, std::vector< sal_uInt32 >& glyphlist); 352cdf0e10cSrcweir 353cdf0e10cSrcweir /** 354cdf0e10cSrcweir * Extracts all Name Records from the font and stores them in an allocated 355cdf0e10cSrcweir * array of NameRecord structs 356cdf0e10cSrcweir * 357cdf0e10cSrcweir * @param ttf pointer to the TrueTypeFont struct 358cdf0e10cSrcweir * @param nr pointer to the array of NameRecord structs 359cdf0e10cSrcweir * 360cdf0e10cSrcweir * @return number of NameRecord structs 361cdf0e10cSrcweir * @ingroup sft 362cdf0e10cSrcweir */ 363cdf0e10cSrcweir 364cdf0e10cSrcweir int GetTTNameRecords(TrueTypeFont *ttf, NameRecord **nr); 365cdf0e10cSrcweir 366cdf0e10cSrcweir /** 367cdf0e10cSrcweir * Deallocates previously allocated array of NameRecords. 368cdf0e10cSrcweir * 369cdf0e10cSrcweir * @param nr array of NameRecord structs 370cdf0e10cSrcweir * @param n number of elements in the array 371cdf0e10cSrcweir * 372cdf0e10cSrcweir * @ingroup sft 373cdf0e10cSrcweir */ 374cdf0e10cSrcweir void DisposeNameRecords(NameRecord* nr, int n); 375cdf0e10cSrcweir 376cdf0e10cSrcweir 377cdf0e10cSrcweir #ifndef NO_TYPE3 378cdf0e10cSrcweir /** 379cdf0e10cSrcweir * Generates a new PostScript Type 3 font and dumps it to <b>outf</b> file. 380cdf0e10cSrcweir * This functions subsititues glyph 0 for all glyphIDs that are not found in the font. 381cdf0e10cSrcweir * @param ttf pointer to the TrueTypeFont structure 382cdf0e10cSrcweir * @param outf the resulting font is written to this stream 383cdf0e10cSrcweir * @param fname font name for the new font. If it is NULL the PostScript name of the 384cdf0e10cSrcweir * original font will be used 385cdf0e10cSrcweir * @param glyphArray pointer to an array of glyphs that are to be extracted from ttf 386cdf0e10cSrcweir * @param encoding array of encoding values. encoding[i] specifies the position of the glyph 387cdf0e10cSrcweir * glyphArray[i] in the encoding vector of the resulting Type3 font 388cdf0e10cSrcweir * @param nGlyphs number of glyph IDs in glyphArray and encoding values in encoding 389cdf0e10cSrcweir * @param wmode writing mode for the output file: 0 - horizontal, 1 - vertical 390cdf0e10cSrcweir * @return return the value of SFErrCodes enum 391cdf0e10cSrcweir * @see SFErrCodes 392cdf0e10cSrcweir * @ingroup sft 393cdf0e10cSrcweir * 394cdf0e10cSrcweir */ 395cdf0e10cSrcweir int CreateT3FromTTGlyphs(TrueTypeFont *ttf, FILE *outf, const char *fname, sal_uInt16 *glyphArray, sal_uInt8 *encoding, int nGlyphs, int wmode); 396cdf0e10cSrcweir #endif 397cdf0e10cSrcweir 398cdf0e10cSrcweir #ifndef NO_TTCR 399cdf0e10cSrcweir /** 400cdf0e10cSrcweir * Generates a new TrueType font and dumps it to <b>outf</b> file. 401cdf0e10cSrcweir * This functions subsititues glyph 0 for all glyphIDs that are not found in the font. 402cdf0e10cSrcweir * @param ttf pointer to the TrueTypeFont structure 403cdf0e10cSrcweir * @param fname file name for the output TrueType font file 404cdf0e10cSrcweir * @param glyphArray pointer to an array of glyphs that are to be extracted from ttf. The first 405cdf0e10cSrcweir * element of this array has to be glyph 0 (default glyph) 406cdf0e10cSrcweir * @param encoding array of encoding values. encoding[i] specifies character code for 407cdf0e10cSrcweir * the glyphID glyphArray[i]. Character code 0 usually points to a default 408cdf0e10cSrcweir * glyph (glyphID 0) 409cdf0e10cSrcweir * @param nGlyphs number of glyph IDs in glyphArray and encoding values in encoding 410cdf0e10cSrcweir * @param nNameRecs number of NameRecords for the font, if 0 the name table from the 411cdf0e10cSrcweir * original font will be used 412cdf0e10cSrcweir * @param nr array of NameRecords 413cdf0e10cSrcweir * @param flags or'ed TTCreationFlags 414cdf0e10cSrcweir * @return return the value of SFErrCodes enum 415cdf0e10cSrcweir * @see SFErrCodes 416cdf0e10cSrcweir * @ingroup sft 417cdf0e10cSrcweir * 418cdf0e10cSrcweir */ 419cdf0e10cSrcweir int CreateTTFromTTGlyphs(TrueTypeFont *ttf, 420cdf0e10cSrcweir const char *fname, 421cdf0e10cSrcweir sal_uInt16 *glyphArray, 422cdf0e10cSrcweir sal_uInt8 *encoding, 423cdf0e10cSrcweir int nGlyphs, 424cdf0e10cSrcweir int nNameRecs, 425cdf0e10cSrcweir NameRecord *nr, 426cdf0e10cSrcweir sal_uInt32 flags); 427cdf0e10cSrcweir #endif 428cdf0e10cSrcweir 429cdf0e10cSrcweir #ifndef NO_TYPE42 430cdf0e10cSrcweir /** 431cdf0e10cSrcweir * Generates a new PostScript Type42 font and dumps it to <b>outf</b> file. 432cdf0e10cSrcweir * This functions subsititues glyph 0 for all glyphIDs that are not found in the font. 433cdf0e10cSrcweir * @param ttf pointer to the TrueTypeFont structure 434cdf0e10cSrcweir * @param outf output stream for a resulting font 435cdf0e10cSrcweir * @param psname PostScript name of the resulting font 436cdf0e10cSrcweir * @param glyphArray pointer to an array of glyphs that are to be extracted from ttf. The first 437cdf0e10cSrcweir * element of this array has to be glyph 0 (default glyph) 438cdf0e10cSrcweir * @param encoding array of encoding values. encoding[i] specifies character code for 439cdf0e10cSrcweir * the glyphID glyphArray[i]. Character code 0 usually points to a default 440cdf0e10cSrcweir * glyph (glyphID 0) 441cdf0e10cSrcweir * @param nGlyphs number of glyph IDs in glyphArray and encoding values in encoding 442cdf0e10cSrcweir * @return SF_OK - no errors 443cdf0e10cSrcweir * SF_GLYPHNUM - too many glyphs (> 255) 444cdf0e10cSrcweir * SF_TTFORMAT - corrupted TrueType fonts 445cdf0e10cSrcweir * 446cdf0e10cSrcweir * @see SFErrCodes 447cdf0e10cSrcweir * @ingroup sft 448cdf0e10cSrcweir * 449cdf0e10cSrcweir */ 450cdf0e10cSrcweir int CreateT42FromTTGlyphs(TrueTypeFont *ttf, 451cdf0e10cSrcweir FILE *outf, 452cdf0e10cSrcweir const char *psname, 453cdf0e10cSrcweir sal_uInt16 *glyphArray, 454cdf0e10cSrcweir sal_uInt8 *encoding, 455cdf0e10cSrcweir int nGlyphs); 456cdf0e10cSrcweir #endif 457cdf0e10cSrcweir 458cdf0e10cSrcweir 459cdf0e10cSrcweir /** 460cdf0e10cSrcweir * Queries glyph metrics. Allocates an array of TTSimpleGlyphMetrics structs and returns it. 461cdf0e10cSrcweir * 462cdf0e10cSrcweir * @param ttf pointer to the TrueTypeFont structure 463cdf0e10cSrcweir * @param glyphArray pointer to an array of glyphs that are to be extracted from ttf 464cdf0e10cSrcweir * @param nGlyphs number of glyph IDs in glyphArray and encoding values in encoding 465cdf0e10cSrcweir * @param mode writing mode: 0 - horizontal, 1 - vertical 466cdf0e10cSrcweir * @ingroup sft 467cdf0e10cSrcweir * 468cdf0e10cSrcweir */ 469cdf0e10cSrcweir TTSimpleGlyphMetrics *GetTTSimpleGlyphMetrics(TrueTypeFont *ttf, sal_uInt16 *glyphArray, int nGlyphs, int mode); 470cdf0e10cSrcweir 471cdf0e10cSrcweir #ifndef NO_MAPPERS 472cdf0e10cSrcweir /** 473cdf0e10cSrcweir * Queries glyph metrics. Allocates an array of TTSimpleGlyphMetrics structs and returns it. 474cdf0e10cSrcweir * This function behaves just like GetTTSimpleGlyphMetrics() but it takes a range of Unicode 475cdf0e10cSrcweir * characters instead of an array of glyphs. 476cdf0e10cSrcweir * 477cdf0e10cSrcweir * @param ttf pointer to the TrueTypeFont structure 478cdf0e10cSrcweir * @param firstChar Unicode value of the first character in the range 479cdf0e10cSrcweir * @param nChars number of Unicode characters in the range 480cdf0e10cSrcweir * @param mode writing mode: 0 - horizontal, 1 - vertical 481cdf0e10cSrcweir * 482cdf0e10cSrcweir * @see GetTTSimpleGlyphMetrics 483cdf0e10cSrcweir * @ingroup sft 484cdf0e10cSrcweir * 485cdf0e10cSrcweir */ 486cdf0e10cSrcweir TTSimpleGlyphMetrics *GetTTSimpleCharMetrics(TrueTypeFont *ttf, sal_uInt16 firstChar, int nChars, int mode); 487cdf0e10cSrcweir 488cdf0e10cSrcweir /** 489cdf0e10cSrcweir * Maps a Unicode (UCS-2) string to a glyph array. Returns the number of glyphs in the array, 490cdf0e10cSrcweir * which for TrueType fonts is always the same as the number of input characters. 491cdf0e10cSrcweir * 492cdf0e10cSrcweir * @param ttf pointer to the TrueTypeFont structure 493cdf0e10cSrcweir * @param str pointer to a UCS-2 string 494cdf0e10cSrcweir * @param nchars number of characters in <b>str</b> 495cdf0e10cSrcweir * @param glyphArray pointer to the glyph array where glyph IDs are to be recorded. 496cdf0e10cSrcweir * 497cdf0e10cSrcweir * @return MapString() returns -1 if the TrueType font has no usable 'cmap' tables. 498cdf0e10cSrcweir * Otherwise it returns the number of characters processed: <b>nChars</b> 499cdf0e10cSrcweir * 500cdf0e10cSrcweir * glyphIDs of TrueType fonts are 2 byte positive numbers. glyphID of 0 denotes a missing 501cdf0e10cSrcweir * glyph and traditionally defaults to an empty square. 502cdf0e10cSrcweir * glyphArray should be at least sizeof(sal_uInt16) * nchars bytes long. If glyphArray is NULL 503cdf0e10cSrcweir * MapString() replaces the UCS-2 characters in str with glyphIDs. 504cdf0e10cSrcweir * @ingroup sft 505cdf0e10cSrcweir */ 506cdf0e10cSrcweir int VCL_DLLPUBLIC MapString(TrueTypeFont *ttf, sal_uInt16 *str, int nchars, sal_uInt16 *glyphArray, int bvertical); 507cdf0e10cSrcweir 508cdf0e10cSrcweir /** 509cdf0e10cSrcweir * Maps a Unicode (UCS-2) character to a glyph ID and returns it. Missing glyph has 510cdf0e10cSrcweir * a glyphID of 0 so this function can be used to test if a character is encoded in the font. 511cdf0e10cSrcweir * 512cdf0e10cSrcweir * @param ttf pointer to the TrueTypeFont structure 513cdf0e10cSrcweir * @param ch Unicode (UCS-2) character 514cdf0e10cSrcweir * @return glyph ID, if the character is missing in the font, the return value is 0. 515cdf0e10cSrcweir * @ingroup sft 516cdf0e10cSrcweir */ 517cdf0e10cSrcweir sal_uInt16 MapChar(TrueTypeFont *ttf, sal_uInt16 ch, int bvertical); 518cdf0e10cSrcweir 519cdf0e10cSrcweir /** 520cdf0e10cSrcweir * Returns 0 when the font does not substitute vertical glyphs 521cdf0e10cSrcweir * 522cdf0e10cSrcweir * @param ttf pointer to the TrueTypeFont structure 523cdf0e10cSrcweir */ 524cdf0e10cSrcweir int DoesVerticalSubstitution( TrueTypeFont *ttf, int bvertical); 525cdf0e10cSrcweir 526cdf0e10cSrcweir #endif 527cdf0e10cSrcweir 528cdf0e10cSrcweir /** 529cdf0e10cSrcweir * Returns global font information about the TrueType font. 530cdf0e10cSrcweir * @see TTGlobalFontInfo 531cdf0e10cSrcweir * 532cdf0e10cSrcweir * @param ttf pointer to a TrueTypeFont structure 533cdf0e10cSrcweir * @param info pointer to a TTGlobalFontInfo structure 534cdf0e10cSrcweir * @ingroup sft 535cdf0e10cSrcweir * 536cdf0e10cSrcweir */ 537cdf0e10cSrcweir void GetTTGlobalFontInfo(TrueTypeFont *ttf, TTGlobalFontInfo *info); 538cdf0e10cSrcweir 539cdf0e10cSrcweir #ifdef TEST5 540cdf0e10cSrcweir /** 541cdf0e10cSrcweir * Returns kerning information for an array of glyphs. 542cdf0e10cSrcweir * Kerning is not cumulative. 543cdf0e10cSrcweir * kern[i] contains kerning information for a pair of glyphs at positions i and i+1 544cdf0e10cSrcweir * 545cdf0e10cSrcweir * @param ttf pointer to a TrueTypeFont structure 546cdf0e10cSrcweir * @param glyphs array of source glyphs 547cdf0e10cSrcweir * @param nglyphs number of glyphs in the array 548cdf0e10cSrcweir * @param wmode writing mode: 0 - horizontal, 1 - vertical 549cdf0e10cSrcweir * @param kern array of KernData structures. It should contain nglyphs-1 elements 550cdf0e10cSrcweir * @see KernData 551cdf0e10cSrcweir * @ingroup sft 552cdf0e10cSrcweir * 553cdf0e10cSrcweir */ 554cdf0e10cSrcweir void KernGlyphs(TrueTypeFont *ttf, sal_uInt16 *glyphs, int nglyphs, int wmode, KernData *kern); 555cdf0e10cSrcweir #endif 556cdf0e10cSrcweir 557cdf0e10cSrcweir /** 558cdf0e10cSrcweir * Returns nonzero if font is a symbol encoded font 559cdf0e10cSrcweir */ 560cdf0e10cSrcweir int CheckSymbolEncoding(TrueTypeFont* ttf); 561cdf0e10cSrcweir 562cdf0e10cSrcweir /** 563cdf0e10cSrcweir * returns the number of glyphs in a font 564cdf0e10cSrcweir */ 565cdf0e10cSrcweir int GetTTGlyphCount( TrueTypeFont* ttf ); 566cdf0e10cSrcweir 567cdf0e10cSrcweir /** 568cdf0e10cSrcweir * provide access to the raw data of a SFNT-container's subtable 569cdf0e10cSrcweir */ 570cdf0e10cSrcweir bool GetSfntTable( TrueTypeFont* ttf, int nSubtableIndex, 571cdf0e10cSrcweir const sal_uInt8** ppRawBytes, int* pRawLength ); 572cdf0e10cSrcweir 573cdf0e10cSrcweir /*- private definitions */ /*FOLD00*/ 574cdf0e10cSrcweir 575cdf0e10cSrcweir struct _TrueTypeFont { 576cdf0e10cSrcweir sal_uInt32 tag; 577cdf0e10cSrcweir 578cdf0e10cSrcweir char *fname; 579cdf0e10cSrcweir sal_Int32 fsize; 580cdf0e10cSrcweir sal_uInt8 *ptr; 581cdf0e10cSrcweir 582cdf0e10cSrcweir char *psname; 583cdf0e10cSrcweir char *family; 584cdf0e10cSrcweir sal_uInt16 *ufamily; 585cdf0e10cSrcweir char *subfamily; 586cdf0e10cSrcweir sal_uInt16 *usubfamily; 587cdf0e10cSrcweir 588cdf0e10cSrcweir sal_uInt32 ntables; 589cdf0e10cSrcweir sal_uInt32 *goffsets; 590cdf0e10cSrcweir sal_uInt32 nglyphs; 591cdf0e10cSrcweir sal_uInt32 unitsPerEm; 592cdf0e10cSrcweir sal_uInt32 numberOfHMetrics; 593cdf0e10cSrcweir sal_uInt32 numOfLongVerMetrics; /* if this number is not 0, font has vertical metrics information */ 594cdf0e10cSrcweir const sal_uInt8* cmap; 595cdf0e10cSrcweir int cmapType; 596cdf0e10cSrcweir sal_uInt32 (*mapper)(const sal_uInt8 *, sal_uInt32); /* character to glyphID translation function */ 597cdf0e10cSrcweir const sal_uInt8 **tables; /* array of pointers to raw subtables in SFNT file */ 598cdf0e10cSrcweir sal_uInt32 *tlens; /* array of table lengths */ 599cdf0e10cSrcweir int kerntype; /* Defined in the KernType enum */ 600cdf0e10cSrcweir sal_uInt32 nkern; /* number of kern subtables */ 601cdf0e10cSrcweir const sal_uInt8** kerntables; /* array of pointers to kern subtables */ 602cdf0e10cSrcweir void *pGSubstitution; /* info provided by GSUB for UseGSUB() */ 603cdf0e10cSrcweir }; 604cdf0e10cSrcweir 605cdf0e10cSrcweir /* indexes into _TrueTypeFont::tables[] and _TrueTypeFont::tlens[] */ 606cdf0e10cSrcweir #define O_maxp 0 /* 'maxp' */ 607cdf0e10cSrcweir #define O_glyf 1 /* 'glyf' */ 608cdf0e10cSrcweir #define O_head 2 /* 'head' */ 609cdf0e10cSrcweir #define O_loca 3 /* 'loca' */ 610cdf0e10cSrcweir #define O_name 4 /* 'name' */ 611cdf0e10cSrcweir #define O_hhea 5 /* 'hhea' */ 612cdf0e10cSrcweir #define O_hmtx 6 /* 'hmtx' */ 613cdf0e10cSrcweir #define O_cmap 7 /* 'cmap' */ 614cdf0e10cSrcweir #define O_vhea 8 /* 'vhea' */ 615cdf0e10cSrcweir #define O_vmtx 9 /* 'vmtx' */ 616cdf0e10cSrcweir #define O_OS2 10 /* 'OS/2' */ 617cdf0e10cSrcweir #define O_post 11 /* 'post' */ 618cdf0e10cSrcweir #define O_kern 12 /* 'kern' */ 619cdf0e10cSrcweir #define O_cvt 13 /* 'cvt_' - only used in TT->TT generation */ 620cdf0e10cSrcweir #define O_prep 14 /* 'prep' - only used in TT->TT generation */ 621cdf0e10cSrcweir #define O_fpgm 15 /* 'fpgm' - only used in TT->TT generation */ 622cdf0e10cSrcweir #define O_gsub 16 /* 'GSUB' */ 623cdf0e10cSrcweir #define O_CFF 17 /* 'CFF' */ 624cdf0e10cSrcweir #define NUM_TAGS 18 625cdf0e10cSrcweir 626cdf0e10cSrcweir } // namespace vcl 627cdf0e10cSrcweir 628cdf0e10cSrcweir #endif /* __SUBFONT_H */ 629