Avoid potential negative array index access to cached text.
[LibreOffice.git] / vcl / inc / sft.hxx
blob96553ba7d8fa1c1c58b034690bab6adc6fecfda0
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 <rtl/ustring.hxx>
44 #include <vcl/dllapi.h>
45 #include <vcl/fontcapabilities.hxx>
46 #include <vcl/fontcharmap.hxx>
47 #include <i18nlangtag/lang.h>
49 #include "fontsubset.hxx"
50 #include "glyphid.hxx"
52 #include <array>
53 #include <memory>
54 #include <vector>
56 class SvStream;
58 namespace vcl
61 /*@{*/
62 typedef sal_Int32 F16Dot16; /**< fixed: 16.16 */
63 /*@}*/
65 /** Return value of OpenTTFont() */
66 enum class SFErrCodes {
67 Ok, /**< no error */
68 BadFile, /**< file not found */
69 FileIo, /**< file I/O error */
70 Memory, /**< memory allocation error */
71 GlyphNum, /**< incorrect number of glyphs */
72 BadArg, /**< incorrect arguments */
73 TtFormat, /**< incorrect TrueType font format */
74 FontNo /**< incorrect logical font number of a TTC font */
77 #ifndef FW_THIN /* WIN32 compilation would conflict */
78 /** Value of the weight member of the TTGlobalFontInfo struct */
79 enum WeightClass {
80 FW_THIN = 100, /**< Thin */
81 FW_EXTRALIGHT = 200, /**< Extra-light (Ultra-light) */
82 FW_LIGHT = 300, /**< Light */
83 FW_NORMAL = 400, /**< Normal (Regular) */
84 FW_MEDIUM = 500, /**< Medium */
85 FW_SEMIBOLD = 600, /**< Semi-bold (Demi-bold) */
86 FW_BOLD = 700, /**< Bold */
87 FW_EXTRABOLD = 800, /**< Extra-bold (Ultra-bold) */
88 FW_BLACK = 900 /**< Black (Heavy) */
90 #endif /* FW_THIN */
92 /** Value of the width member of the TTGlobalFontInfo struct */
93 enum WidthClass {
94 FWIDTH_ULTRA_CONDENSED = 1, /**< 50% of normal */
95 FWIDTH_EXTRA_CONDENSED = 2, /**< 62.5% of normal */
96 FWIDTH_CONDENSED = 3, /**< 75% of normal */
97 FWIDTH_SEMI_CONDENSED = 4, /**< 87.5% of normal */
98 FWIDTH_NORMAL = 5, /**< Medium, 100% */
99 FWIDTH_SEMI_EXPANDED = 6, /**< 112.5% of normal */
100 FWIDTH_EXPANDED = 7, /**< 125% of normal */
101 FWIDTH_EXTRA_EXPANDED = 8, /**< 150% of normal */
102 FWIDTH_ULTRA_EXPANDED = 9 /**< 200% of normal */
105 /** Composite glyph flags definition */
106 enum CompositeFlags {
107 ARG_1_AND_2_ARE_WORDS = 1,
108 ARGS_ARE_XY_VALUES = 1<<1,
109 ROUND_XY_TO_GRID = 1<<2,
110 WE_HAVE_A_SCALE = 1<<3,
111 MORE_COMPONENTS = 1<<5,
112 WE_HAVE_AN_X_AND_Y_SCALE = 1<<6,
113 WE_HAVE_A_TWO_BY_TWO = 1<<7,
114 WE_HAVE_INSTRUCTIONS = 1<<8,
115 USE_MY_METRICS = 1<<9,
116 OVERLAP_COMPOUND = 1<<10
119 /** Structure used by GetTTSimpleCharMetrics() functions */
120 typedef struct {
121 sal_uInt16 adv; /**< advance width or height */
122 sal_Int16 sb; /**< left or top sidebearing */
123 } TTSimpleGlyphMetrics;
125 /** Structure used by the TrueType Creator and GetRawGlyphData() */
127 typedef struct {
128 sal_uInt32 glyphID; /**< glyph ID */
129 sal_uInt16 nbytes; /**< number of bytes in glyph data */
130 std::unique_ptr<sal_uInt8[]> ptr; /**< pointer to glyph data */
131 sal_uInt16 aw; /**< advance width */
132 sal_Int16 lsb; /**< left sidebearing */
133 bool compflag; /**< false- if non-composite */
134 sal_uInt16 npoints; /**< number of points */
135 sal_uInt16 ncontours; /**< number of contours */
136 /* */
137 sal_uInt32 newID; /**< used internally by the TTCR */
138 } GlyphData;
140 /** Structure used by the TrueType Creator and CreateTTFromTTGlyphs() */
141 struct NameRecord {
142 sal_uInt16 platformID; /**< Platform ID */
143 sal_uInt16 encodingID; /**< Platform-specific encoding ID */
144 LanguageType languageID; /**< Language ID */
145 sal_uInt16 nameID; /**< Name ID */
146 std::vector<sal_uInt8> sptr; /**< string data (not zero-terminated!) */
149 /** Return value of GetTTGlobalFontInfo() */
151 typedef struct TTGlobalFontInfo_ {
152 OString family; /**< family name */
153 OUString ufamily; /**< family name UCS2 */
154 OString subfamily; /**< subfamily name */
155 OUString usubfamily; /**< subfamily name UCS2 */
156 OString psname; /**< PostScript name */
157 sal_uInt16 macStyle = 0; /**< macstyle bits from 'HEAD' table */
158 int weight = 0; /**< value of WeightClass or 0 if can't be determined */
159 int width = 0; /**< value of WidthClass or 0 if can't be determined */
160 int pitch = 0; /**< 0: proportional font, otherwise: monospaced */
161 int italicAngle = 0; /**< in counter-clockwise degrees * 65536 */
162 int xMin = 0; /**< global bounding box: xMin */
163 int yMin = 0; /**< global bounding box: yMin */
164 int xMax = 0; /**< global bounding box: xMax */
165 int yMax = 0; /**< global bounding box: yMax */
166 int ascender = 0; /**< typographic ascent. */
167 int descender = 0; /**< typographic descent. */
168 int linegap = 0; /**< typographic line gap.\ Negative values are treated as
169 zero in Win 3.1, System 6 and System 7. */
170 int typoAscender = 0; /**< OS/2 portable typographic ascender */
171 int typoDescender = 0; /**< OS/2 portable typographic descender */
172 int typoLineGap = 0; /**< OS/2 portable typographic line gap */
173 int winAscent = 0; /**< ascender metric for Windows */
174 int winDescent = 0; /**< descender metric for Windows */
175 bool microsoftSymbolEncoded = false; /**< true: MS symbol encoded */
176 sal_uInt8 panose[10] = {}; /**< PANOSE classification number */
177 sal_uInt32 typeFlags = 0; /**< type flags (copyright bits) */
178 sal_uInt16 fsSelection = 0; /**< OS/2 fsSelection */
179 } TTGlobalFontInfo;
181 /** ControlPoint structure used by GetTTGlyphPoints() */
182 typedef struct {
183 sal_uInt32 flags; /**< 00000000 00000000 e0000000 bbbbbbbb */
184 /**< b - byte flags from the glyf array */
185 /**< e == 0 - regular point */
186 /**< e == 1 - end contour */
187 sal_Int16 x; /**< X coordinate in EmSquare units */
188 sal_Int16 y; /**< Y coordinate in EmSquare units */
189 } ControlPoint;
193 Some table OS/2 consts
194 quick history:
195 OpenType has been created from TrueType
196 - original TrueType had an OS/2 table with a length of 68 bytes
197 (cf https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6OS2.html)
198 - There have been 6 versions (from version 0 to 5)
199 (cf https://docs.microsoft.com/en-us/typography/opentype/otspec140/os2ver0)
201 For the record:
202 // From Initial TrueType version
203 TYPE NAME FROM BYTE
204 uint16 version 0
205 int16 xAvgCharWidth 2
206 uint16 usWeightClass 4
207 uint16 usWidthClass 6
208 uint16 fsType 8
209 int16 ySubscriptXSize 10
210 int16 ySubscriptYSize 12
211 int16 ySubscriptXOffset 14
212 int16 ySubscriptYOffset 16
213 int16 ySuperscriptXSize 18
214 int16 ySuperscriptYSize 20
215 int16 ySuperscriptXOffset 22
216 int16 ySuperscriptYOffset 24
217 int16 yStrikeoutSize 26
218 int16 yStrikeoutPosition 28
219 int16 sFamilyClass 30
220 uint8 panose[10] 32
221 uint32 ulUnicodeRange1 42
222 uint32 ulUnicodeRange2 46
223 uint32 ulUnicodeRange3 50
224 uint32 ulUnicodeRange4 54
225 Tag achVendID 58
226 uint16 fsSelection 62
227 uint16 usFirstCharIndex 64
228 uint16 usLastCharIndex 66
230 // From Version 0 of OpenType
231 int16 sTypoAscender 68
232 int16 sTypoDescender 70
233 int16 sTypoLineGap 72
234 uint16 usWinAscent 74
235 uint16 usWinDescent 76
237 => length for OpenType version 0 = 78 bytes
239 // From Version 1 of OpenType
240 uint32 ulCodePageRange1 78
241 uint32 ulCodePageRange2 82
243 => length for OpenType version 1 = 86 bytes
245 // From Version 2 of OpenType
246 // (idem for Versions 3 and 4)
247 int16 sxHeight 86
248 int16 sCapHeight 88
249 uint16 usDefaultChar 90
250 uint16 usBreakChar 92
251 uint16 usMaxContext 94
253 => length for OpenType version 2, 3 and 4 = 96 bytes
255 // From Version 5 of OpenType
256 uint16 usLowerOpticalPointSize 96
257 uint16 usUpperOpticalPointSize 98
258 END 100
260 => length for OS/2 table version 5 = 100 bytes
263 constexpr int OS2_Legacy_length = 68;
264 constexpr int OS2_V0_length = 78;
265 constexpr int OS2_V1_length = 86;
267 constexpr int OS2_usWeightClass_offset = 4;
268 constexpr int OS2_usWidthClass_offset = 6;
269 constexpr int OS2_fsType_offset = 8;
270 constexpr int OS2_panose_offset = 32;
271 constexpr int OS2_panoseNbBytes_offset = 10;
272 constexpr int OS2_ulUnicodeRange1_offset = 42;
273 constexpr int OS2_ulUnicodeRange2_offset = 46;
274 constexpr int OS2_ulUnicodeRange3_offset = 50;
275 constexpr int OS2_ulUnicodeRange4_offset = 54;
276 constexpr int OS2_fsSelection_offset = 62;
277 constexpr int OS2_typoAscender_offset = 68;
278 constexpr int OS2_typoDescender_offset = 70;
279 constexpr int OS2_typoLineGap_offset = 72;
280 constexpr int OS2_winAscent_offset = 74;
281 constexpr int OS2_winDescent_offset = 76;
282 constexpr int OS2_ulCodePageRange1_offset = 78;
283 constexpr int OS2_ulCodePageRange2_offset = 82;
286 Some table hhea consts
287 cf https://docs.microsoft.com/fr-fr/typography/opentype/spec/hhea
288 TYPE NAME FROM BYTE
289 uint16 majorVersion 0
290 uint16 minorVersion 2
291 FWORD ascender 4
292 FWORD descender 6
293 FWORD lineGap 8
294 UFWORD advanceWidthMax 10
295 FWORD minLeftSideBearing 12
296 FWORD minRightSideBearing 14
297 FWORD xMaxExtent 16
298 int16 caretSlopeRise 18
299 int16 caretSlopeRun 20
300 int16 caretOffset 22
301 int16 (reserved) 24
302 int16 (reserved) 26
303 int16 (reserved) 28
304 int16 (reserved) 30
305 int16 metricDataFormat 32
306 uint16 numberOfHMetrics 34
307 END 36
309 => length for hhea table = 36 bytes
312 constexpr int HHEA_Length = 36;
314 constexpr int HHEA_ascender_offset = 4;
315 constexpr int HHEA_descender_offset = 6;
316 constexpr int HHEA_lineGap_offset = 8;
317 constexpr int HHEA_caretSlopeRise_offset = 18;
318 constexpr int HHEA_caretSlopeRun_offset = 20;
321 Some table post consts
322 cf https://docs.microsoft.com/fr-fr/typography/opentype/spec/post
323 TYPE NAME FROM BYTE
324 Fixed version 0
325 Fixed italicAngle 4
326 FWord underlinePosition 8
327 FWord underlineThickness 10
328 uint32 isFixedPitch 12
332 constexpr int POST_italicAngle_offset = 4;
333 constexpr int POST_underlinePosition_offset = 8;
334 constexpr int POST_underlineThickness_offset = 10;
335 constexpr int POST_isFixedPitch_offset = 12;
338 Some table head consts
339 cf https://docs.microsoft.com/fr-fr/typography/opentype/spec/head
340 TYPE NAME FROM BYTE
341 uit16 majorVersion 0
342 uit16 minorVersion 2
343 Fixed fontRevision 4
344 uint32 checkSumAdjustment 8
345 uint32 magicNumber 12 (= 0x5F0F3CF5)
346 uint16 flags 16
347 uint16 unitsPerEm 18
348 LONGDATETIME created 20
349 LONGDATETIME modified 28
350 int16 xMin 36
351 int16 yMin 38
352 int16 xMax 40
353 int16 yMax 42
354 uint16 macStyle 44
355 uint16 lowestRecPPEM 46
356 int16 fontDirectionHint 48
357 int16 indexToLocFormat 50
358 int16 glyphDataFormat 52
360 END 54
362 => length head table = 54 bytes
364 constexpr int HEAD_Length = 54;
366 constexpr int HEAD_majorVersion_offset = 0;
367 constexpr int HEAD_fontRevision_offset = 4;
368 constexpr int HEAD_magicNumber_offset = 12;
369 constexpr int HEAD_flags_offset = 16;
370 constexpr int HEAD_unitsPerEm_offset = 18;
371 constexpr int HEAD_created_offset = 20;
372 constexpr int HEAD_xMin_offset = 36;
373 constexpr int HEAD_yMin_offset = 38;
374 constexpr int HEAD_xMax_offset = 40;
375 constexpr int HEAD_yMax_offset = 42;
376 constexpr int HEAD_macStyle_offset = 44;
377 constexpr int HEAD_lowestRecPPEM_offset = 46;
378 constexpr int HEAD_fontDirectionHint_offset = 48;
379 constexpr int HEAD_indexToLocFormat_offset = 50;
380 constexpr int HEAD_glyphDataFormat_offset = 52;
383 Some table maxp consts
384 cf https://docs.microsoft.com/fr-fr/typography/opentype/spec/maxp
385 For 0.5 version
386 TYPE NAME FROM BYTE
387 Fixed version 0
388 uint16 numGlyphs 4
390 For 1.0 Version
391 Fixed version 0
392 uint16 numGlyphs 4
393 uint16 maxPoints 6
394 uint16 maxContours 8
395 uint16 maxCompositePoints 10
396 uint16 maxCompositeContours 12
400 constexpr int MAXP_Version1Length = 32;
402 constexpr int MAXP_numGlyphs_offset = 4;
403 constexpr int MAXP_maxPoints_offset = 6;
404 constexpr int MAXP_maxContours_offset = 8;
405 constexpr int MAXP_maxCompositePoints_offset = 10;
406 constexpr int MAXP_maxCompositeContours_offset = 12;
409 Some table glyf consts
410 cf https://docs.microsoft.com/fr-fr/typography/opentype/spec/glyf
411 For 0.5 version
412 TYPE NAME FROM BYTE
413 int16 numberOfContours 0
414 int16 xMin 2
415 int16 yMin 4
416 int16 xMax 6
417 int16 yMax 8
419 END 10
421 => length glyf table = 10 bytes
424 constexpr int GLYF_Length = 10;
426 constexpr int GLYF_numberOfContours_offset = 0;
427 constexpr int GLYF_xMin_offset = 2;
428 constexpr int GLYF_yMin_offset = 4;
429 constexpr int GLYF_xMax_offset = 6;
430 constexpr int GLYF_yMax_offset = 8;
432 constexpr sal_uInt32 T_true = 0x74727565; /* 'true' */
433 constexpr sal_uInt32 T_ttcf = 0x74746366; /* 'ttcf' */
434 constexpr sal_uInt32 T_otto = 0x4f54544f; /* 'OTTO' */
436 // standard TrueType table tags
437 constexpr sal_uInt32 T_maxp = 0x6D617870;
438 constexpr sal_uInt32 T_glyf = 0x676C7966;
439 constexpr sal_uInt32 T_head = 0x68656164;
440 constexpr sal_uInt32 T_loca = 0x6C6F6361;
441 constexpr sal_uInt32 T_name = 0x6E616D65;
442 constexpr sal_uInt32 T_hhea = 0x68686561;
443 constexpr sal_uInt32 T_hmtx = 0x686D7478;
444 constexpr sal_uInt32 T_cmap = 0x636D6170;
445 constexpr sal_uInt32 T_vhea = 0x76686561;
446 constexpr sal_uInt32 T_vmtx = 0x766D7478;
447 constexpr sal_uInt32 T_OS2 = 0x4F532F32;
448 constexpr sal_uInt32 T_post = 0x706F7374;
449 constexpr sal_uInt32 T_cvt = 0x63767420;
450 constexpr sal_uInt32 T_prep = 0x70726570;
451 constexpr sal_uInt32 T_fpgm = 0x6670676D;
452 constexpr sal_uInt32 T_CFF = 0x43464620;
454 class AbstractTrueTypeFont;
455 class TrueTypeFont;
458 * @defgroup sft Sun Font Tools Exported Functions
462 * Get the number of fonts contained in a TrueType collection
463 * @param fname - file name
464 * @return number of fonts or zero, if file is not a TTC file.
465 * @ingroup sft
467 int CountTTCFonts(const char* fname);
470 * TrueTypeFont constructor.
471 * The font file has to be provided as a memory buffer and length
472 * @param pBuffer - memory buffer
473 * @param nLen - size of memory buffer
474 * @param facenum - logical font number within a TTC file. This value is ignored
475 * for TrueType fonts
476 * @param ttf - returns the opened TrueTypeFont
477 * @param xCharMap - optional parsed character map
478 * @return value of SFErrCodes enum
479 * @ingroup sft
481 SFErrCodes VCL_DLLPUBLIC OpenTTFontBuffer(const void* pBuffer, sal_uInt32 nLen, sal_uInt32 facenum,
482 TrueTypeFont** ttf, const FontCharMapRef xCharMap = nullptr);
483 #if !defined(_WIN32)
485 * TrueTypeFont constructor.
486 * Reads the font file and allocates the memory for the structure.
487 * on WIN32 the font has to be provided as a memory buffer and length
488 * @param fname - name of TrueType font file
489 * @param facenum - logical font number within a TTC file. This value is ignored
490 * for TrueType fonts
491 * @param ttf - returns the opened TrueTypeFont
492 * @param xCharMap - optional parsed character map
493 * @return value of SFErrCodes enum
494 * @ingroup sft
496 SFErrCodes VCL_DLLPUBLIC OpenTTFontFile(const char *fname, sal_uInt32 facenum, TrueTypeFont** ttf,
497 const FontCharMapRef xCharMap = nullptr);
498 #endif
500 bool VCL_DLLPUBLIC getTTCoverage(
501 std::optional<std::bitset<UnicodeCoverage::MAX_UC_ENUM>> & rUnicodeCoverage,
502 std::optional<std::bitset<CodePageCoverage::MAX_CP_ENUM>> & rCodePageCoverage,
503 const unsigned char* pTable, size_t nLength);
506 * TrueTypeFont destructor. Deallocates the memory.
507 * @ingroup sft
509 void VCL_DLLPUBLIC CloseTTFont(TrueTypeFont *);
512 * Extracts TrueType control points, and stores them in an allocated array pointed to
513 * by *pointArray. This function returns the number of extracted points.
515 * @param ttf pointer to the TrueTypeFont structure
516 * @param glyphID Glyph ID
517 * @param pointArray Return value - address of the pointer to the first element of the array
518 * of points allocated by the function
519 * @return Returns the number of points in *pointArray or -1 if glyphID is
520 * invalid.
521 * @ingroup sft
524 int GetTTGlyphPoints(AbstractTrueTypeFont *ttf, sal_uInt32 glyphID, std::vector<ControlPoint>& pointArray);
527 * Extracts raw glyph data from the 'glyf' table and returns it in an allocated
528 * GlyphData structure.
530 * @param ttf pointer to the TrueTypeFont structure
531 * @param glyphID Glyph ID
533 * @return pointer to an allocated GlyphData structure or NULL if
534 * glyphID is not present in the font
535 * @ingroup sft
538 std::unique_ptr<GlyphData> GetTTRawGlyphData(AbstractTrueTypeFont *ttf, sal_uInt32 glyphID);
541 * For a specified glyph adds all component glyphs IDs to the list and
542 * return their number. If the glyph is a single glyph it has one component
543 * glyph (which is added to the list) and the function returns 1.
544 * For a composite glyphs it returns the number of component glyphs
545 * and adds all of them to the list.
547 * @param ttf pointer to the TrueTypeFont structure
548 * @param glyphID Glyph ID
549 * @param glyphlist list of glyphs
551 * @return number of component glyphs
552 * @ingroup sft
555 int GetTTGlyphComponents(AbstractTrueTypeFont *ttf, sal_uInt32 glyphID, std::vector< sal_uInt32 >& glyphlist);
558 * Extracts all Name Records from the font and stores them in an allocated
559 * array of NameRecord structs
561 * @param ttf pointer to the TrueTypeFont struct
562 * @param nr reference to the vector of NameRecord structs
564 * @ingroup sft
567 void GetTTNameRecords(AbstractTrueTypeFont const *ttf, std::vector<NameRecord>& nr);
570 * Generates a new TrueType font and dumps it to <b>outf</b> file.
571 * This function substitutes glyph 0 for all glyphIDs that are not found in the font.
572 * @param ttf pointer to the TrueTypeFont structure
573 * @param fname file name for the output TrueType font file
574 * @param glyphArray pointer to an array of glyphs that are to be extracted from ttf. The first
575 * element of this array has to be glyph 0 (default glyph)
576 * @param encoding array of encoding values. encoding[i] specifies character code for
577 * the glyphID glyphArray[i]. Character code 0 usually points to a default
578 * glyph (glyphID 0)
579 * @param nGlyphs number of glyph IDs in glyphArray and encoding values in encoding
580 * @param flags or'ed TTCreationFlags
581 * @return return the value of SFErrCodes enum
582 * @see SFErrCodes
583 * @ingroup sft
586 VCL_DLLPUBLIC SFErrCodes CreateTTFromTTGlyphs(AbstractTrueTypeFont *ttf,
587 std::vector<sal_uInt8>& rOutBuffer,
588 sal_uInt16 const *glyphArray,
589 sal_uInt8 const *encoding,
590 int nGlyphs);
592 VCL_DLLPUBLIC bool CreateTTFfontSubset(AbstractTrueTypeFont& aTTF,
593 std::vector<sal_uInt8>& rOutBuffer,
594 const sal_GlyphId* pGlyphIds,
595 const sal_uInt8* pEncoding,
596 int nGlyphCount, FontSubsetInfo& rInfo);
599 * Returns global font information about the TrueType font.
600 * @see TTGlobalFontInfo
602 * @param ttf pointer to a TrueTypeFont structure
603 * @param info pointer to a TTGlobalFontInfo structure
604 * @ingroup sft
607 VCL_DLLPUBLIC void GetTTGlobalFontInfo(AbstractTrueTypeFont *ttf, TTGlobalFontInfo *info);
610 * Returns part of the head table info, normally collected by GetTTGlobalFontInfo.
612 * Just implemented separate, because this info not available via Qt API.
614 * @param ttf pointer to a AbstractTrueTypeFont structure
615 * @param xMin global glyph bounding box min X
616 * @param yMin global glyph bounding box min Y
617 * @param xMax global glyph bounding box max X
618 * @param yMax global glyph bounding box max Y
619 * @param macStyle encoded Mac style flags of the font
620 * @return true, if table data could be decoded
621 * @ingroup sft
623 VCL_DLLPUBLIC bool GetTTGlobalFontHeadInfo(const AbstractTrueTypeFont *ttf, int& xMin, int& yMin, int& xMax, int& yMax, sal_uInt16& macStyle);
625 /*- private definitions */
627 /* indexes into TrueTypeFont::tables[] and TrueTypeFont::tlens[] */
628 constexpr int O_maxp = 0;
629 constexpr int O_glyf = 1; /* 'glyf' */
630 constexpr int O_head = 2; /* 'head' */
631 constexpr int O_loca = 3; /* 'loca' */
632 constexpr int O_name = 4; /* 'name' */
633 constexpr int O_hhea = 5; /* 'hhea' */
634 constexpr int O_hmtx = 6; /* 'hmtx' */
635 constexpr int O_cmap = 7; /* 'cmap' */
636 constexpr int O_vhea = 8; /* 'vhea' */
637 constexpr int O_vmtx = 9; /* 'vmtx' */
638 constexpr int O_OS2 = 10; /* 'OS/2' */
639 constexpr int O_post = 11; /* 'post' */
640 constexpr int O_cvt = 12; /* 'cvt_' - only used in TT->TT generation */
641 constexpr int O_prep = 13; /* 'prep' - only used in TT->TT generation */
642 constexpr int O_fpgm = 14; /* 'fpgm' - only used in TT->TT generation */
643 constexpr int O_CFF = 15; /* 'CFF' */
644 constexpr int NUM_TAGS = 16;
646 class VCL_DLLPUBLIC AbstractTrueTypeFont
648 std::string m_sFileName;
649 sal_uInt32 m_nGlyphs;
650 sal_uInt32 m_nHorzMetrics;
651 sal_uInt32 m_nVertMetrics; /* if not 0 => font has vertical metrics information */
652 sal_uInt32 m_nUnitsPerEm;
653 std::vector<sal_uInt32> m_aGlyphOffsets;
654 FontCharMapRef m_xCharMap;
655 bool m_bMicrosoftSymbolEncoded;
657 protected:
658 SFErrCodes indexGlyphData();
660 public:
661 AbstractTrueTypeFont(const char* fileName = nullptr, const FontCharMapRef xCharMap = nullptr);
662 virtual ~AbstractTrueTypeFont();
664 SFErrCodes initialize();
666 std::string const & fileName() const { return m_sFileName; }
667 sal_uInt32 glyphCount() const { return m_nGlyphs; }
668 sal_uInt32 glyphOffset(sal_uInt32 glyphID) const;
669 sal_uInt32 horzMetricCount() const { return m_nHorzMetrics; }
670 sal_uInt32 vertMetricCount() const { return m_nVertMetrics; }
671 sal_uInt32 unitsPerEm() const { return m_nUnitsPerEm; }
672 bool IsMicrosoftSymbolEncoded() const { return m_bMicrosoftSymbolEncoded; }
674 virtual bool hasTable(sal_uInt32 ord) const = 0;
675 virtual const sal_uInt8* table(sal_uInt32 ord, sal_uInt32& size) const = 0;
677 OString psname;
678 OString family;
679 OUString ufamily;
680 OString subfamily;
681 OUString usubfamily;
684 class TrueTypeFont final : public AbstractTrueTypeFont
686 struct TTFontTable_
688 const sal_uInt8* pData = nullptr; /* pointer to a raw subtable in the SFNT file */
689 sal_uInt32 nSize = 0; /* table size */
692 std::array<struct TTFontTable_, NUM_TAGS> m_aTableList;
694 public:
695 sal_Int32 fsize;
696 sal_uInt8 *ptr;
697 sal_uInt32 ntables;
699 TrueTypeFont(const char* pFileName = nullptr, const FontCharMapRef xCharMap = nullptr);
700 ~TrueTypeFont() override;
702 SFErrCodes open(sal_uInt32 facenum);
704 bool hasTable(sal_uInt32 ord) const override { return m_aTableList[ord].pData != nullptr; }
705 inline const sal_uInt8* table(sal_uInt32 ord, sal_uInt32& size) const override;
708 const sal_uInt8* TrueTypeFont::table(sal_uInt32 ord, sal_uInt32& size) const
710 if (ord >= NUM_TAGS)
712 size = 0;
713 return nullptr;
716 auto& rTable = m_aTableList[ord];
717 size = rTable.nSize;
718 return rTable.pData;
721 } // namespace vcl
723 #endif // INCLUDED_VCL_INC_SFT_HXX
725 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */