bump product version to 6.4.0.3
[LibreOffice.git] / vcl / inc / sft.hxx
blob8c7e4aaa8711e2c1f693bd6ec80a2b9dbdc4e352
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 /**
21 * @file sft.hxx
22 * @brief Sun Font Tools
26 * Generated fonts contain an XUID entry in the form of:
28 * 103 0 T C1 N C2 C3
30 * 103 - Sun's Adobe assigned XUID number. Contact person: Alexander Gelfenbain <gelf@eng.sun.com>
32 * T - font type. 0: Type 3, 1: Type 42
33 * C1 - CRC-32 of the entire source TrueType font
34 * N - number of glyphs in the subset
35 * C2 - CRC-32 of the array of glyph IDs used to generate the subset
36 * C3 - CRC-32 of the array of encoding numbers used to generate the subset
40 #ifndef INCLUDED_VCL_INC_SFT_HXX
41 #define INCLUDED_VCL_INC_SFT_HXX
43 #include <vcl/dllapi.h>
44 #include <vcl/fontcapabilities.hxx>
45 #include <i18nlangtag/lang.h>
47 #include <array>
48 #include <memory>
49 #include <vector>
50 #include <cstdint>
52 namespace vcl
55 /*@{*/
56 typedef sal_Int32 F16Dot16; /**< fixed: 16.16 */
57 /*@}*/
59 /** Return value of OpenTTFont() and CreateT3FromTTGlyphs() */
60 enum class SFErrCodes {
61 Ok, /**< no error */
62 BadFile, /**< file not found */
63 FileIo, /**< file I/O error */
64 Memory, /**< memory allocation error */
65 GlyphNum, /**< incorrect number of glyphs */
66 BadArg, /**< incorrect arguments */
67 TtFormat, /**< incorrect TrueType font format */
68 FontNo /**< incorrect logical font number of a TTC font */
71 #ifndef FW_THIN /* WIN32 compilation would conflict */
72 /** Value of the weight member of the TTGlobalFontInfo struct */
73 enum WeightClass {
74 FW_THIN = 100, /**< Thin */
75 FW_EXTRALIGHT = 200, /**< Extra-light (Ultra-light) */
76 FW_LIGHT = 300, /**< Light */
77 FW_NORMAL = 400, /**< Normal (Regular) */
78 FW_MEDIUM = 500, /**< Medium */
79 FW_SEMIBOLD = 600, /**< Semi-bold (Demi-bold) */
80 FW_BOLD = 700, /**< Bold */
81 FW_EXTRABOLD = 800, /**< Extra-bold (Ultra-bold) */
82 FW_BLACK = 900 /**< Black (Heavy) */
84 #endif /* FW_THIN */
86 /** Value of the width member of the TTGlobalFontInfo struct */
87 enum WidthClass {
88 FWIDTH_ULTRA_CONDENSED = 1, /**< 50% of normal */
89 FWIDTH_EXTRA_CONDENSED = 2, /**< 62.5% of normal */
90 FWIDTH_CONDENSED = 3, /**< 75% of normal */
91 FWIDTH_SEMI_CONDENSED = 4, /**< 87.5% of normal */
92 FWIDTH_NORMAL = 5, /**< Medium, 100% */
93 FWIDTH_SEMI_EXPANDED = 6, /**< 112.5% of normal */
94 FWIDTH_EXPANDED = 7, /**< 125% of normal */
95 FWIDTH_EXTRA_EXPANDED = 8, /**< 150% of normal */
96 FWIDTH_ULTRA_EXPANDED = 9 /**< 200% of normal */
99 /** Composite glyph flags definition */
100 enum CompositeFlags {
101 ARG_1_AND_2_ARE_WORDS = 1,
102 ARGS_ARE_XY_VALUES = 1<<1,
103 ROUND_XY_TO_GRID = 1<<2,
104 WE_HAVE_A_SCALE = 1<<3,
105 MORE_COMPONENTS = 1<<5,
106 WE_HAVE_AN_X_AND_Y_SCALE = 1<<6,
107 WE_HAVE_A_TWO_BY_TWO = 1<<7,
108 WE_HAVE_INSTRUCTIONS = 1<<8,
109 USE_MY_METRICS = 1<<9,
110 OVERLAP_COMPOUND = 1<<10
113 /** Structure used by GetTTSimpleCharMetrics() functions */
114 typedef struct {
115 sal_uInt16 adv; /**< advance width or height */
116 sal_Int16 sb; /**< left or top sidebearing */
117 } TTSimpleGlyphMetrics;
119 /** Structure used by the TrueType Creator and GetRawGlyphData() */
121 typedef struct {
122 sal_uInt32 glyphID; /**< glyph ID */
123 sal_uInt16 nbytes; /**< number of bytes in glyph data */
124 sal_uInt8 *ptr; /**< pointer to glyph data */
125 sal_uInt16 aw; /**< advance width */
126 sal_Int16 lsb; /**< left sidebearing */
127 bool compflag; /**< false- if non-composite */
128 sal_uInt16 npoints; /**< number of points */
129 sal_uInt16 ncontours; /**< number of contours */
130 /* */
131 sal_uInt32 newID; /**< used internally by the TTCR */
132 } GlyphData;
134 /** Structure used by the TrueType Creator and CreateTTFromTTGlyphs() */
135 typedef struct {
136 sal_uInt16 platformID; /**< Platform ID */
137 sal_uInt16 encodingID; /**< Platform-specific encoding ID */
138 LanguageType languageID; /**< Language ID */
139 sal_uInt16 nameID; /**< Name ID */
140 sal_uInt16 slen; /**< String length in bytes */
141 sal_uInt8 *sptr; /**< Pointer to string data (not zero-terminated!) */
142 } NameRecord;
144 /** Return value of GetTTGlobalFontInfo() */
146 typedef struct {
147 char *family; /**< family name */
148 sal_Unicode *ufamily; /**< family name UCS2 */
149 char *subfamily; /**< subfamily name */
150 sal_Unicode *usubfamily; /**< subfamily name UCS2 */
151 char *psname; /**< PostScript name */
152 sal_uInt16 macStyle; /**< macstyle bits from 'HEAD' table */
153 int weight; /**< value of WeightClass or 0 if can't be determined */
154 int width; /**< value of WidthClass or 0 if can't be determined */
155 int pitch; /**< 0: proportional font, otherwise: monospaced */
156 int italicAngle; /**< in counter-clockwise degrees * 65536 */
157 int xMin; /**< global bounding box: xMin */
158 int yMin; /**< global bounding box: yMin */
159 int xMax; /**< global bounding box: xMax */
160 int yMax; /**< global bounding box: yMax */
161 int ascender; /**< typographic ascent. */
162 int descender; /**< typographic descent. */
163 int linegap; /**< typographic line gap.\ Negative values are treated as
164 zero in Win 3.1, System 6 and System 7. */
165 int typoAscender; /**< OS/2 portable typographic ascender */
166 int typoDescender; /**< OS/2 portable typographic descender */
167 int typoLineGap; /**< OS/2 portable typographic line gap */
168 int winAscent; /**< ascender metric for Windows */
169 int winDescent; /**< descender metric for Windows */
170 bool symbolEncoded; /**< true: MS symbol encoded */
171 sal_uInt8 panose[10]; /**< PANOSE classification number */
172 sal_uInt32 typeFlags; /**< type flags (copyright bits) */
173 sal_uInt16 fsSelection; /**< OS/2 fsSelection */
174 } TTGlobalFontInfo;
176 /** ControlPoint structure used by GetTTGlyphPoints() */
177 typedef struct {
178 sal_uInt32 flags; /**< 00000000 00000000 e0000000 bbbbbbbb */
179 /**< b - byte flags from the glyf array */
180 /**< e == 0 - regular point */
181 /**< e == 1 - end contour */
182 sal_Int16 x; /**< X coordinate in EmSquare units */
183 sal_Int16 y; /**< Y coordinate in EmSquare units */
184 } ControlPoint;
186 struct TrueTypeFont;
189 Some table OS/2 consts
190 quick history:
191 OpenType has been created from TrueType
192 - original TrueType had an OS/2 table with a length of 68 bytes
193 (cf https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6OS2.html)
194 - There have been 6 versions (from version 0 to 5)
195 (cf https://docs.microsoft.com/en-us/typography/opentype/otspec140/os2ver0)
197 For the record:
198 // From Initial TrueType version
199 TYPE NAME FROM BYTE
200 uint16 version 0
201 int16 xAvgCharWidth 2
202 uint16 usWeightClass 4
203 uint16 usWidthClass 6
204 uint16 fsType 8
205 int16 ySubscriptXSize 10
206 int16 ySubscriptYSize 12
207 int16 ySubscriptXOffset 14
208 int16 ySubscriptYOffset 16
209 int16 ySuperscriptXSize 18
210 int16 ySuperscriptYSize 20
211 int16 ySuperscriptXOffset 22
212 int16 ySuperscriptYOffset 24
213 int16 yStrikeoutSize 26
214 int16 yStrikeoutPosition 28
215 int16 sFamilyClass 30
216 uint8 panose[10] 32
217 uint32 ulUnicodeRange1 42
218 uint32 ulUnicodeRange2 46
219 uint32 ulUnicodeRange3 50
220 uint32 ulUnicodeRange4 54
221 Tag achVendID 58
222 uint16 fsSelection 62
223 uint16 usFirstCharIndex 64
224 uint16 usLastCharIndex 66
226 // From Version 0 of OpenType
227 int16 sTypoAscender 68
228 int16 sTypoDescender 70
229 int16 sTypoLineGap 72
230 uint16 usWinAscent 74
231 uint16 usWinDescent 76
233 => length for OpenType version 0 = 78 bytes
235 // From Version 1 of OpenType
236 uint32 ulCodePageRange1 78
237 uint32 ulCodePageRange2 82
239 => length for OpenType version 1 = 86 bytes
241 // From Version 2 of OpenType
242 // (idem for Versions 3 and 4)
243 int16 sxHeight 86
244 int16 sCapHeight 88
245 uint16 usDefaultChar 90
246 uint16 usBreakChar 92
247 uint16 usMaxContext 94
249 => length for OpenType version 2, 3 and 4 = 96 bytes
251 // From Version 5 of OpenType
252 uint16 usLowerOpticalPointSize 96
253 uint16 usUpperOpticalPointSize 98
254 END 100
256 => length for OS/2 table version 5 = 100 bytes
259 constexpr int OS2_Legacy_length = 68;
260 constexpr int OS2_V0_length = 78;
261 constexpr int OS2_V1_length = 86;
263 constexpr int OS2_usWeightClass_offset = 4;
264 constexpr int OS2_usWidthClass_offset = 6;
265 constexpr int OS2_fsType_offset = 8;
266 constexpr int OS2_panose_offset = 32;
267 constexpr int OS2_panoseNbBytes_offset = 10;
268 constexpr int OS2_ulUnicodeRange1_offset = 42;
269 constexpr int OS2_ulUnicodeRange2_offset = 46;
270 constexpr int OS2_ulUnicodeRange3_offset = 50;
271 constexpr int OS2_ulUnicodeRange4_offset = 54;
272 constexpr int OS2_fsSelection_offset = 62;
273 constexpr int OS2_typoAscender_offset = 68;
274 constexpr int OS2_typoDescender_offset = 70;
275 constexpr int OS2_typoLineGap_offset = 72;
276 constexpr int OS2_winAscent_offset = 74;
277 constexpr int OS2_winDescent_offset = 76;
278 constexpr int OS2_ulCodePageRange1_offset = 78;
279 constexpr int OS2_ulCodePageRange2_offset = 82;
282 Some table hhea consts
283 cf https://docs.microsoft.com/fr-fr/typography/opentype/spec/hhea
284 TYPE NAME FROM BYTE
285 uint16 majorVersion 0
286 uint16 minorVersion 2
287 FWORD ascender 4
288 FWORD descender 6
289 FWORD lineGap 8
290 UFWORD advanceWidthMax 10
291 FWORD minLeftSideBearing 12
292 FWORD minRightSideBearing 14
293 FWORD xMaxExtent 16
294 int16 caretSlopeRise 18
295 int16 caretSlopeRun 20
296 int16 caretOffset 22
297 int16 (reserved) 24
298 int16 (reserved) 26
299 int16 (reserved) 28
300 int16 (reserved) 30
301 int16 metricDataFormat 32
302 uint16 numberOfHMetrics 34
303 END 36
305 => length for hhea table = 36 bytes
308 constexpr int HHEA_Length = 36;
310 constexpr int HHEA_ascender_offset = 4;
311 constexpr int HHEA_descender_offset = 6;
312 constexpr int HHEA_lineGap_offset = 8;
313 constexpr int HHEA_caretSlopeRise_offset = 18;
314 constexpr int HHEA_caretSlopeRun_offset = 20;
317 Some table post consts
318 cf https://docs.microsoft.com/fr-fr/typography/opentype/spec/post
319 TYPE NAME FROM BYTE
320 Fixed version 0
321 Fixed italicAngle 4
322 FWord underlinePosition 8
323 FWord underlineThickness 10
324 uint32 isFixedPitch 12
328 constexpr int POST_italicAngle_offset = 4;
329 constexpr int POST_underlinePosition_offset = 8;
330 constexpr int POST_underlineThickness_offset = 10;
331 constexpr int POST_isFixedPitch_offset = 12;
334 Some table head consts
335 cf https://docs.microsoft.com/fr-fr/typography/opentype/spec/head
336 TYPE NAME FROM BYTE
337 uit16 majorVersion 0
338 uit16 minorVersion 2
339 Fixed fontRevision 4
340 uint32 checkSumAdjustment 8
341 uint32 magicNumber 12 (= 0x5F0F3CF5)
342 uint16 flags 16
343 uint16 unitsPerEm 18
344 LONGDATETIME created 20
345 LONGDATETIME modified 28
346 int16 xMin 36
347 int16 yMin 38
348 int16 xMax 40
349 int16 yMax 42
350 uint16 macStyle 44
351 uint16 lowestRecPPEM 46
352 int16 fontDirectionHint 48
353 int16 indexToLocFormat 50
354 int16 glyphDataFormat 52
356 END 54
358 => length head table = 54 bytes
360 constexpr int HEAD_Length = 54;
362 constexpr int HEAD_majorVersion_offset = 0;
363 constexpr int HEAD_fontRevision_offset = 4;
364 constexpr int HEAD_magicNumber_offset = 12;
365 constexpr int HEAD_flags_offset = 16;
366 constexpr int HEAD_unitsPerEm_offset = 18;
367 constexpr int HEAD_created_offset = 20;
368 constexpr int HEAD_xMin_offset = 36;
369 constexpr int HEAD_yMin_offset = 38;
370 constexpr int HEAD_xMax_offset = 40;
371 constexpr int HEAD_yMax_offset = 42;
372 constexpr int HEAD_macStyle_offset = 44;
373 constexpr int HEAD_lowestRecPPEM_offset = 46;
374 constexpr int HEAD_fontDirectionHint_offset = 48;
375 constexpr int HEAD_indexToLocFormat_offset = 50;
376 constexpr int HEAD_glyphDataFormat_offset = 52;
379 Some table maxp consts
380 cf https://docs.microsoft.com/fr-fr/typography/opentype/spec/maxp
381 For 0.5 version
382 TYPE NAME FROM BYTE
383 Fixed version 0
384 uint16 numGlyphs 4
386 For 1.0 Version
387 Fixed version 0
388 uint16 numGlyphs 4
389 uint16 maxPoints 6
390 uint16 maxContours 8
391 uint16 maxCompositePoints 10
392 uint16 maxCompositeContours 12
396 constexpr int MAXP_Version1Length = 32;
398 constexpr int MAXP_numGlyphs_offset = 4;
399 constexpr int MAXP_maxPoints_offset = 6;
400 constexpr int MAXP_maxContours_offset = 8;
401 constexpr int MAXP_maxCompositePoints_offset = 10;
402 constexpr int MAXP_maxCompositeContours_offset = 12;
405 Some table glyf consts
406 cf https://docs.microsoft.com/fr-fr/typography/opentype/spec/glyf
407 For 0.5 version
408 TYPE NAME FROM BYTE
409 int16 numberOfContours 0
410 int16 xMin 2
411 int16 yMin 4
412 int16 xMax 6
413 int16 yMax 8
415 END 10
417 => length glyf table = 10 bytes
420 constexpr int GLYF_Length = 10;
422 constexpr int GLYF_numberOfContours_offset = 0;
423 constexpr int GLYF_xMin_offset = 2;
424 constexpr int GLYF_yMin_offset = 4;
425 constexpr int GLYF_xMax_offset = 6;
426 constexpr int GLYF_yMax_offset = 8;
428 constexpr sal_uInt32 T_true = 0x74727565; /* 'true' */
429 constexpr sal_uInt32 T_ttcf = 0x74746366; /* 'ttcf' */
430 constexpr sal_uInt32 T_otto = 0x4f54544f; /* 'OTTO' */
432 // standard TrueType table tags
433 constexpr sal_uInt32 T_maxp = 0x6D617870;
434 constexpr sal_uInt32 T_glyf = 0x676C7966;
435 constexpr sal_uInt32 T_head = 0x68656164;
436 constexpr sal_uInt32 T_loca = 0x6C6F6361;
437 constexpr sal_uInt32 T_name = 0x6E616D65;
438 constexpr sal_uInt32 T_hhea = 0x68686561;
439 constexpr sal_uInt32 T_hmtx = 0x686D7478;
440 constexpr sal_uInt32 T_cmap = 0x636D6170;
441 constexpr sal_uInt32 T_vhea = 0x76686561;
442 constexpr sal_uInt32 T_vmtx = 0x766D7478;
443 constexpr sal_uInt32 T_OS2 = 0x4F532F32;
444 constexpr sal_uInt32 T_post = 0x706F7374;
445 constexpr sal_uInt32 T_cvt = 0x63767420;
446 constexpr sal_uInt32 T_prep = 0x70726570;
447 constexpr sal_uInt32 T_fpgm = 0x6670676D;
448 constexpr sal_uInt32 T_gsub = 0x47535542;
449 constexpr sal_uInt32 T_CFF = 0x43464620;
453 * @defgroup sft Sun Font Tools Exported Functions
457 * Get the number of fonts contained in a TrueType collection
458 * @param fname - file name
459 * @return number of fonts or zero, if file is not a TTC file.
460 * @ingroup sft
462 int CountTTCFonts(const char* fname);
465 * TrueTypeFont constructor.
466 * The font file has to be provided as a memory buffer and length
467 * @param pBuffer - memory buffer
468 * @param nLen - size of memory buffer
469 * @param facenum - logical font number within a TTC file. This value is ignored
470 * for TrueType fonts
471 * @param ttf - array of TrueTypeFonts
472 * @return value of SFErrCodes enum
473 * @ingroup sft
475 SFErrCodes VCL_DLLPUBLIC OpenTTFontBuffer(const void* pBuffer, sal_uInt32 nLen, sal_uInt32 facenum, TrueTypeFont** ttf);
476 #if !defined(_WIN32)
478 * TrueTypeFont constructor.
479 * Reads the font file and allocates the memory for the structure.
480 * on WIN32 the font has to be provided as a memory buffer and length
481 * @param fname - name of TrueType font file
482 * @param facenum - logical font number within a TTC file. This value is ignored
483 * for TrueType fonts
484 * @param ttf - array of TrueTypeFonts
485 * @return value of SFErrCodes enum
486 * @ingroup sft
488 SFErrCodes VCL_DLLPUBLIC OpenTTFontFile(const char *fname, sal_uInt32 facenum, TrueTypeFont** ttf);
489 #endif
491 bool VCL_DLLPUBLIC getTTCoverage(
492 boost::optional<std::bitset<UnicodeCoverage::MAX_UC_ENUM>> & rUnicodeCoverage,
493 boost::optional<std::bitset<CodePageCoverage::MAX_CP_ENUM>> & rCodePageCoverage,
494 const unsigned char* pTable, size_t nLength);
497 * TrueTypeFont destructor. Deallocates the memory.
498 * @ingroup sft
500 void VCL_DLLPUBLIC CloseTTFont(TrueTypeFont *);
503 * Extracts TrueType control points, and stores them in an allocated array pointed to
504 * by *pointArray. This function returns the number of extracted points.
506 * @param ttf pointer to the TrueTypeFont structure
507 * @param glyphID Glyph ID
508 * @param pointArray Return value - address of the pointer to the first element of the array
509 * of points allocated by the function
510 * @return Returns the number of points in *pointArray or -1 if glyphID is
511 * invalid.
512 * @ingroup sft
515 int GetTTGlyphPoints(TrueTypeFont *ttf, sal_uInt32 glyphID, ControlPoint **pointArray);
518 * Extracts raw glyph data from the 'glyf' table and returns it in an allocated
519 * GlyphData structure.
521 * @param ttf pointer to the TrueTypeFont structure
522 * @param glyphID Glyph ID
524 * @return pointer to an allocated GlyphData structure or NULL if
525 * glyphID is not present in the font
526 * @ingroup sft
529 GlyphData *GetTTRawGlyphData(TrueTypeFont *ttf, sal_uInt32 glyphID);
532 * For a specified glyph adds all component glyphs IDs to the list and
533 * return their number. If the glyph is a single glyph it has one component
534 * glyph (which is added to the list) and the function returns 1.
535 * For a composite glyphs it returns the number of component glyphs
536 * and adds all of them to the list.
538 * @param ttf pointer to the TrueTypeFont structure
539 * @param glyphID Glyph ID
540 * @param glyphlist list of glyphs
542 * @return number of component glyphs
543 * @ingroup sft
546 int GetTTGlyphComponents(TrueTypeFont *ttf, sal_uInt32 glyphID, std::vector< sal_uInt32 >& glyphlist);
549 * Extracts all Name Records from the font and stores them in an allocated
550 * array of NameRecord structs
552 * @param ttf pointer to the TrueTypeFont struct
553 * @param nr pointer to the array of NameRecord structs
555 * @return number of NameRecord structs
556 * @ingroup sft
559 int GetTTNameRecords(TrueTypeFont const *ttf, NameRecord **nr);
562 * Deallocates previously allocated array of NameRecords.
564 * @param nr array of NameRecord structs
565 * @param n number of elements in the array
567 * @ingroup sft
569 void DisposeNameRecords(NameRecord* nr, int n);
572 * Generates a new PostScript Type 3 font and dumps it to <b>outf</b> file.
573 * This function substitutes glyph 0 for all glyphIDs that are not found in the font.
574 * @param ttf pointer to the TrueTypeFont structure
575 * @param outf the resulting font is written to this stream
576 * @param fname font name for the new font. If it is NULL the PostScript name of the
577 * original font will be used
578 * @param glyphArray pointer to an array of glyphs that are to be extracted from ttf
579 * @param encoding array of encoding values. encoding[i] specifies the position of the glyph
580 * glyphArray[i] in the encoding vector of the resulting Type3 font
581 * @param nGlyphs number of glyph IDs in glyphArray and encoding values in encoding
582 * @param wmode writing mode for the output file: 0 - horizontal, 1 - vertical
583 * @return return the value of SFErrCodes enum
584 * @see SFErrCodes
585 * @ingroup sft
588 SFErrCodes CreateT3FromTTGlyphs(TrueTypeFont *ttf, FILE *outf, const char *fname, sal_uInt16 const *glyphArray, sal_uInt8 *encoding, int nGlyphs, int wmode);
591 * Generates a new TrueType font and dumps it to <b>outf</b> file.
592 * This function substitutes glyph 0 for all glyphIDs that are not found in the font.
593 * @param ttf pointer to the TrueTypeFont structure
594 * @param fname file name for the output TrueType font file
595 * @param glyphArray pointer to an array of glyphs that are to be extracted from ttf. The first
596 * element of this array has to be glyph 0 (default glyph)
597 * @param encoding array of encoding values. encoding[i] specifies character code for
598 * the glyphID glyphArray[i]. Character code 0 usually points to a default
599 * glyph (glyphID 0)
600 * @param nGlyphs number of glyph IDs in glyphArray and encoding values in encoding
601 * @param flags or'ed TTCreationFlags
602 * @return return the value of SFErrCodes enum
603 * @see SFErrCodes
604 * @ingroup sft
607 VCL_DLLPUBLIC SFErrCodes CreateTTFromTTGlyphs(TrueTypeFont *ttf,
608 const char *fname,
609 sal_uInt16 const *glyphArray,
610 sal_uInt8 const *encoding,
611 int nGlyphs);
614 * Generates a new PostScript Type42 font and dumps it to <b>outf</b> file.
615 * This function substitutes glyph 0 for all glyphIDs that are not found in the font.
616 * @param ttf pointer to the TrueTypeFont structure
617 * @param outf output stream for a resulting font
618 * @param psname PostScript name of the resulting font
619 * @param glyphArray pointer to an array of glyphs that are to be extracted from ttf. The first
620 * element of this array has to be glyph 0 (default glyph)
621 * @param encoding array of encoding values. encoding[i] specifies character code for
622 * the glyphID glyphArray[i]. Character code 0 usually points to a default
623 * glyph (glyphID 0)
624 * @param nGlyphs number of glyph IDs in glyphArray and encoding values in encoding
625 * @return SFErrCodes::Ok - no errors
626 * SFErrCodes::GlyphNum - too many glyphs (> 255)
627 * SFErrCodes::TtFormat - corrupted TrueType fonts
629 * @see SFErrCodes
630 * @ingroup sft
633 SFErrCodes CreateT42FromTTGlyphs(TrueTypeFont *ttf,
634 FILE *outf,
635 const char *psname,
636 sal_uInt16 const *glyphArray,
637 sal_uInt8 *encoding,
638 int nGlyphs);
641 * Queries glyph metrics. Allocates an array of advance width/height values and returns it.
643 * @param ttf pointer to the TrueTypeFont structure
644 * @param glyphArray pointer to an array of glyphs that are to be extracted from ttf
645 * @param nGlyphs number of glyph IDs in glyphArray and encoding values in encoding
646 * @param vertical writing mode: false - horizontal, true - vertical
647 * @ingroup sft
650 VCL_DLLPUBLIC std::unique_ptr<sal_uInt16[]> GetTTSimpleGlyphMetrics(TrueTypeFont const *ttf, const sal_uInt16 *glyphArray, int nGlyphs, bool vertical);
652 #if defined(_WIN32) || defined(MACOSX) || defined(IOS)
654 * Maps a Unicode (UCS-2) character to a glyph ID and returns it. Missing glyph has
655 * a glyphID of 0 so this function can be used to test if a character is encoded in the font.
657 * @param ttf pointer to the TrueTypeFont structure
658 * @param ch Unicode (UCS-2) character
659 * @return glyph ID, if the character is missing in the font, the return value is 0.
660 * @ingroup sft
662 VCL_DLLPUBLIC sal_uInt16 MapChar(TrueTypeFont const *ttf, sal_uInt16 ch);
663 #endif
666 * Returns global font information about the TrueType font.
667 * @see TTGlobalFontInfo
669 * @param ttf pointer to a TrueTypeFont structure
670 * @param info pointer to a TTGlobalFontInfo structure
671 * @ingroup sft
674 VCL_DLLPUBLIC void GetTTGlobalFontInfo(TrueTypeFont *ttf, TTGlobalFontInfo *info);
677 * Returns fonts metrics.
678 * @see TTGlobalFontInfo
680 * @param hhea hhea table data
681 * @param os2 OS/2 table data
682 * @param info pointer to a TTGlobalFontInfo structure
683 * @ingroup sft
686 void GetTTFontMetrics(const uint8_t *pHhea, size_t nHhea,
687 const uint8_t *pOs2, size_t nOs2,
688 TTGlobalFontInfo *info);
691 * returns the number of glyphs in a font
693 VCL_DLLPUBLIC int GetTTGlyphCount( TrueTypeFont const * ttf );
696 * provide access to the raw data of a SFNT-container's subtable
698 bool GetSfntTable( TrueTypeFont const * ttf, int nSubtableIndex,
699 const sal_uInt8** ppRawBytes, int* pRawLength );
701 /*- private definitions */
703 /* indexes into TrueTypeFont::tables[] and TrueTypeFont::tlens[] */
704 constexpr int O_maxp = 0;
705 constexpr int O_glyf = 1; /* 'glyf' */
706 constexpr int O_head = 2; /* 'head' */
707 constexpr int O_loca = 3; /* 'loca' */
708 constexpr int O_name = 4; /* 'name' */
709 constexpr int O_hhea = 5; /* 'hhea' */
710 constexpr int O_hmtx = 6; /* 'hmtx' */
711 constexpr int O_cmap = 7; /* 'cmap' */
712 constexpr int O_vhea = 8; /* 'vhea' */
713 constexpr int O_vmtx = 9; /* 'vmtx' */
714 constexpr int O_OS2 = 10; /* 'OS/2' */
715 constexpr int O_post = 11; /* 'post' */
716 constexpr int O_cvt = 12; /* 'cvt_' - only used in TT->TT generation */
717 constexpr int O_prep = 13; /* 'prep' - only used in TT->TT generation */
718 constexpr int O_fpgm = 14; /* 'fpgm' - only used in TT->TT generation */
719 constexpr int O_gsub = 15; /* 'GSUB' */
720 constexpr int O_CFF = 16; /* 'CFF' */
721 constexpr int NUM_TAGS = 17;
723 struct TrueTypeFont {
724 char *fname;
725 sal_Int32 fsize;
726 sal_uInt8 *ptr;
728 char *psname;
729 char *family;
730 sal_Unicode *ufamily;
731 char *subfamily;
732 sal_Unicode *usubfamily;
734 sal_uInt32 ntables;
735 sal_uInt32 *goffsets;
736 sal_uInt32 nglyphs;
737 sal_uInt32 unitsPerEm;
738 sal_uInt32 numberOfHMetrics;
739 sal_uInt32 numOfLongVerMetrics; /* if this number is not 0, font has vertical metrics information */
740 const sal_uInt8* cmap;
741 int cmapType;
742 sal_uInt32 (*mapper)(const sal_uInt8 *, sal_uInt32, sal_uInt32); /* character to glyphID translation function */
743 std::array<const sal_uInt8 *, NUM_TAGS> tables; /* array of pointers to raw subtables in SFNT file */
744 std::array<sal_uInt32, NUM_TAGS> tlens; /* array of table lengths */
748 } // namespace vcl
750 #endif // INCLUDED_VCL_INC_SFT_HXX
752 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */