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