1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 * @brief Sun Font Tools
26 * Generated fonts contain an XUID entry in the form of:
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 <vcl/fontcharmap.hxx>
46 #include <i18nlangtag/lang.h>
53 #include "font/PhysicalFontFace.hxx"
61 typedef sal_Int32 F16Dot16
; /**< fixed: 16.16 */
64 /** Return value of OpenTTFont() and CreateT3FromTTGlyphs() */
65 enum class SFErrCodes
{
67 BadFile
, /**< file not found */
68 FileIo
, /**< file I/O error */
69 Memory
, /**< memory allocation error */
70 GlyphNum
, /**< incorrect number of glyphs */
71 BadArg
, /**< incorrect arguments */
72 TtFormat
, /**< incorrect TrueType font format */
73 FontNo
/**< incorrect logical font number of a TTC font */
76 #ifndef FW_THIN /* WIN32 compilation would conflict */
77 /** Value of the weight member of the TTGlobalFontInfo struct */
79 FW_THIN
= 100, /**< Thin */
80 FW_EXTRALIGHT
= 200, /**< Extra-light (Ultra-light) */
81 FW_LIGHT
= 300, /**< Light */
82 FW_NORMAL
= 400, /**< Normal (Regular) */
83 FW_MEDIUM
= 500, /**< Medium */
84 FW_SEMIBOLD
= 600, /**< Semi-bold (Demi-bold) */
85 FW_BOLD
= 700, /**< Bold */
86 FW_EXTRABOLD
= 800, /**< Extra-bold (Ultra-bold) */
87 FW_BLACK
= 900 /**< Black (Heavy) */
91 /** Value of the width member of the TTGlobalFontInfo struct */
93 FWIDTH_ULTRA_CONDENSED
= 1, /**< 50% of normal */
94 FWIDTH_EXTRA_CONDENSED
= 2, /**< 62.5% of normal */
95 FWIDTH_CONDENSED
= 3, /**< 75% of normal */
96 FWIDTH_SEMI_CONDENSED
= 4, /**< 87.5% of normal */
97 FWIDTH_NORMAL
= 5, /**< Medium, 100% */
98 FWIDTH_SEMI_EXPANDED
= 6, /**< 112.5% of normal */
99 FWIDTH_EXPANDED
= 7, /**< 125% of normal */
100 FWIDTH_EXTRA_EXPANDED
= 8, /**< 150% of normal */
101 FWIDTH_ULTRA_EXPANDED
= 9 /**< 200% of normal */
104 /** Composite glyph flags definition */
105 enum CompositeFlags
{
106 ARG_1_AND_2_ARE_WORDS
= 1,
107 ARGS_ARE_XY_VALUES
= 1<<1,
108 ROUND_XY_TO_GRID
= 1<<2,
109 WE_HAVE_A_SCALE
= 1<<3,
110 MORE_COMPONENTS
= 1<<5,
111 WE_HAVE_AN_X_AND_Y_SCALE
= 1<<6,
112 WE_HAVE_A_TWO_BY_TWO
= 1<<7,
113 WE_HAVE_INSTRUCTIONS
= 1<<8,
114 USE_MY_METRICS
= 1<<9,
115 OVERLAP_COMPOUND
= 1<<10
118 /** Structure used by GetTTSimpleCharMetrics() functions */
120 sal_uInt16 adv
; /**< advance width or height */
121 sal_Int16 sb
; /**< left or top sidebearing */
122 } TTSimpleGlyphMetrics
;
124 /** Structure used by the TrueType Creator and GetRawGlyphData() */
127 sal_uInt32 glyphID
; /**< glyph ID */
128 sal_uInt16 nbytes
; /**< number of bytes in glyph data */
129 std::unique_ptr
<sal_uInt8
[]> ptr
; /**< pointer to glyph data */
130 sal_uInt16 aw
; /**< advance width */
131 sal_Int16 lsb
; /**< left sidebearing */
132 bool compflag
; /**< false- if non-composite */
133 sal_uInt16 npoints
; /**< number of points */
134 sal_uInt16 ncontours
; /**< number of contours */
136 sal_uInt32 newID
; /**< used internally by the TTCR */
139 /** Structure used by the TrueType Creator and CreateTTFromTTGlyphs() */
141 sal_uInt16 platformID
; /**< Platform ID */
142 sal_uInt16 encodingID
; /**< Platform-specific encoding ID */
143 LanguageType languageID
; /**< Language ID */
144 sal_uInt16 nameID
; /**< Name ID */
145 std::vector
<sal_uInt8
> sptr
; /**< string data (not zero-terminated!) */
148 /** Return value of GetTTGlobalFontInfo() */
150 typedef struct TTGlobalFontInfo_
{
151 OString family
; /**< family name */
152 OUString ufamily
; /**< family name UCS2 */
153 OString subfamily
; /**< subfamily name */
154 OUString usubfamily
; /**< subfamily name UCS2 */
155 OString psname
; /**< PostScript name */
156 sal_uInt16 macStyle
= 0; /**< macstyle bits from 'HEAD' table */
157 int weight
= 0; /**< value of WeightClass or 0 if can't be determined */
158 int width
= 0; /**< value of WidthClass or 0 if can't be determined */
159 int pitch
= 0; /**< 0: proportional font, otherwise: monospaced */
160 int italicAngle
= 0; /**< in counter-clockwise degrees * 65536 */
161 int xMin
= 0; /**< global bounding box: xMin */
162 int yMin
= 0; /**< global bounding box: yMin */
163 int xMax
= 0; /**< global bounding box: xMax */
164 int yMax
= 0; /**< global bounding box: yMax */
165 int ascender
= 0; /**< typographic ascent. */
166 int descender
= 0; /**< typographic descent. */
167 int linegap
= 0; /**< typographic line gap.\ Negative values are treated as
168 zero in Win 3.1, System 6 and System 7. */
169 int typoAscender
= 0; /**< OS/2 portable typographic ascender */
170 int typoDescender
= 0; /**< OS/2 portable typographic descender */
171 int typoLineGap
= 0; /**< OS/2 portable typographic line gap */
172 int winAscent
= 0; /**< ascender metric for Windows */
173 int winDescent
= 0; /**< descender metric for Windows */
174 bool microsoftSymbolEncoded
= false; /**< true: MS symbol encoded */
175 sal_uInt8 panose
[10] = {}; /**< PANOSE classification number */
176 sal_uInt32 typeFlags
= 0; /**< type flags (copyright bits) */
177 sal_uInt16 fsSelection
= 0; /**< OS/2 fsSelection */
180 /** ControlPoint structure used by GetTTGlyphPoints() */
182 sal_uInt32 flags
; /**< 00000000 00000000 e0000000 bbbbbbbb */
183 /**< b - byte flags from the glyf array */
184 /**< e == 0 - regular point */
185 /**< e == 1 - end contour */
186 sal_Int16 x
; /**< X coordinate in EmSquare units */
187 sal_Int16 y
; /**< Y coordinate in EmSquare units */
192 Some table OS/2 consts
194 OpenType has been created from TrueType
195 - original TrueType had an OS/2 table with a length of 68 bytes
196 (cf https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6OS2.html)
197 - There have been 6 versions (from version 0 to 5)
198 (cf https://docs.microsoft.com/en-us/typography/opentype/otspec140/os2ver0)
201 // From Initial TrueType version
204 int16 xAvgCharWidth 2
205 uint16 usWeightClass 4
206 uint16 usWidthClass 6
208 int16 ySubscriptXSize 10
209 int16 ySubscriptYSize 12
210 int16 ySubscriptXOffset 14
211 int16 ySubscriptYOffset 16
212 int16 ySuperscriptXSize 18
213 int16 ySuperscriptYSize 20
214 int16 ySuperscriptXOffset 22
215 int16 ySuperscriptYOffset 24
216 int16 yStrikeoutSize 26
217 int16 yStrikeoutPosition 28
218 int16 sFamilyClass 30
220 uint32 ulUnicodeRange1 42
221 uint32 ulUnicodeRange2 46
222 uint32 ulUnicodeRange3 50
223 uint32 ulUnicodeRange4 54
225 uint16 fsSelection 62
226 uint16 usFirstCharIndex 64
227 uint16 usLastCharIndex 66
229 // From Version 0 of OpenType
230 int16 sTypoAscender 68
231 int16 sTypoDescender 70
232 int16 sTypoLineGap 72
233 uint16 usWinAscent 74
234 uint16 usWinDescent 76
236 => length for OpenType version 0 = 78 bytes
238 // From Version 1 of OpenType
239 uint32 ulCodePageRange1 78
240 uint32 ulCodePageRange2 82
242 => length for OpenType version 1 = 86 bytes
244 // From Version 2 of OpenType
245 // (idem for Versions 3 and 4)
248 uint16 usDefaultChar 90
249 uint16 usBreakChar 92
250 uint16 usMaxContext 94
252 => length for OpenType version 2, 3 and 4 = 96 bytes
254 // From Version 5 of OpenType
255 uint16 usLowerOpticalPointSize 96
256 uint16 usUpperOpticalPointSize 98
259 => length for OS/2 table version 5 = 100 bytes
262 constexpr int OS2_Legacy_length
= 68;
263 constexpr int OS2_V0_length
= 78;
264 constexpr int OS2_V1_length
= 86;
266 constexpr int OS2_usWeightClass_offset
= 4;
267 constexpr int OS2_usWidthClass_offset
= 6;
268 constexpr int OS2_fsType_offset
= 8;
269 constexpr int OS2_panose_offset
= 32;
270 constexpr int OS2_panoseNbBytes_offset
= 10;
271 constexpr int OS2_ulUnicodeRange1_offset
= 42;
272 constexpr int OS2_ulUnicodeRange2_offset
= 46;
273 constexpr int OS2_ulUnicodeRange3_offset
= 50;
274 constexpr int OS2_ulUnicodeRange4_offset
= 54;
275 constexpr int OS2_fsSelection_offset
= 62;
276 constexpr int OS2_typoAscender_offset
= 68;
277 constexpr int OS2_typoDescender_offset
= 70;
278 constexpr int OS2_typoLineGap_offset
= 72;
279 constexpr int OS2_winAscent_offset
= 74;
280 constexpr int OS2_winDescent_offset
= 76;
281 constexpr int OS2_ulCodePageRange1_offset
= 78;
282 constexpr int OS2_ulCodePageRange2_offset
= 82;
285 Some table hhea consts
286 cf https://docs.microsoft.com/fr-fr/typography/opentype/spec/hhea
288 uint16 majorVersion 0
289 uint16 minorVersion 2
293 UFWORD advanceWidthMax 10
294 FWORD minLeftSideBearing 12
295 FWORD minRightSideBearing 14
297 int16 caretSlopeRise 18
298 int16 caretSlopeRun 20
304 int16 metricDataFormat 32
305 uint16 numberOfHMetrics 34
308 => length for hhea table = 36 bytes
311 constexpr int HHEA_Length
= 36;
313 constexpr int HHEA_ascender_offset
= 4;
314 constexpr int HHEA_descender_offset
= 6;
315 constexpr int HHEA_lineGap_offset
= 8;
316 constexpr int HHEA_caretSlopeRise_offset
= 18;
317 constexpr int HHEA_caretSlopeRun_offset
= 20;
320 Some table post consts
321 cf https://docs.microsoft.com/fr-fr/typography/opentype/spec/post
325 FWord underlinePosition 8
326 FWord underlineThickness 10
327 uint32 isFixedPitch 12
331 constexpr int POST_italicAngle_offset
= 4;
332 constexpr int POST_underlinePosition_offset
= 8;
333 constexpr int POST_underlineThickness_offset
= 10;
334 constexpr int POST_isFixedPitch_offset
= 12;
337 Some table head consts
338 cf https://docs.microsoft.com/fr-fr/typography/opentype/spec/head
343 uint32 checkSumAdjustment 8
344 uint32 magicNumber 12 (= 0x5F0F3CF5)
347 LONGDATETIME created 20
348 LONGDATETIME modified 28
354 uint16 lowestRecPPEM 46
355 int16 fontDirectionHint 48
356 int16 indexToLocFormat 50
357 int16 glyphDataFormat 52
361 => length head table = 54 bytes
363 constexpr int HEAD_Length
= 54;
365 constexpr int HEAD_majorVersion_offset
= 0;
366 constexpr int HEAD_fontRevision_offset
= 4;
367 constexpr int HEAD_magicNumber_offset
= 12;
368 constexpr int HEAD_flags_offset
= 16;
369 constexpr int HEAD_unitsPerEm_offset
= 18;
370 constexpr int HEAD_created_offset
= 20;
371 constexpr int HEAD_xMin_offset
= 36;
372 constexpr int HEAD_yMin_offset
= 38;
373 constexpr int HEAD_xMax_offset
= 40;
374 constexpr int HEAD_yMax_offset
= 42;
375 constexpr int HEAD_macStyle_offset
= 44;
376 constexpr int HEAD_lowestRecPPEM_offset
= 46;
377 constexpr int HEAD_fontDirectionHint_offset
= 48;
378 constexpr int HEAD_indexToLocFormat_offset
= 50;
379 constexpr int HEAD_glyphDataFormat_offset
= 52;
382 Some table maxp consts
383 cf https://docs.microsoft.com/fr-fr/typography/opentype/spec/maxp
394 uint16 maxCompositePoints 10
395 uint16 maxCompositeContours 12
399 constexpr int MAXP_Version1Length
= 32;
401 constexpr int MAXP_numGlyphs_offset
= 4;
402 constexpr int MAXP_maxPoints_offset
= 6;
403 constexpr int MAXP_maxContours_offset
= 8;
404 constexpr int MAXP_maxCompositePoints_offset
= 10;
405 constexpr int MAXP_maxCompositeContours_offset
= 12;
408 Some table glyf consts
409 cf https://docs.microsoft.com/fr-fr/typography/opentype/spec/glyf
412 int16 numberOfContours 0
420 => length glyf table = 10 bytes
423 constexpr int GLYF_Length
= 10;
425 constexpr int GLYF_numberOfContours_offset
= 0;
426 constexpr int GLYF_xMin_offset
= 2;
427 constexpr int GLYF_yMin_offset
= 4;
428 constexpr int GLYF_xMax_offset
= 6;
429 constexpr int GLYF_yMax_offset
= 8;
431 constexpr sal_uInt32 T_true
= 0x74727565; /* 'true' */
432 constexpr sal_uInt32 T_ttcf
= 0x74746366; /* 'ttcf' */
433 constexpr sal_uInt32 T_otto
= 0x4f54544f; /* 'OTTO' */
435 // standard TrueType table tags
436 constexpr sal_uInt32 T_maxp
= 0x6D617870;
437 constexpr sal_uInt32 T_glyf
= 0x676C7966;
438 constexpr sal_uInt32 T_head
= 0x68656164;
439 constexpr sal_uInt32 T_loca
= 0x6C6F6361;
440 constexpr sal_uInt32 T_name
= 0x6E616D65;
441 constexpr sal_uInt32 T_hhea
= 0x68686561;
442 constexpr sal_uInt32 T_hmtx
= 0x686D7478;
443 constexpr sal_uInt32 T_cmap
= 0x636D6170;
444 constexpr sal_uInt32 T_vhea
= 0x76686561;
445 constexpr sal_uInt32 T_vmtx
= 0x766D7478;
446 constexpr sal_uInt32 T_OS2
= 0x4F532F32;
447 constexpr sal_uInt32 T_post
= 0x706F7374;
448 constexpr sal_uInt32 T_cvt
= 0x63767420;
449 constexpr sal_uInt32 T_prep
= 0x70726570;
450 constexpr sal_uInt32 T_fpgm
= 0x6670676D;
451 constexpr sal_uInt32 T_CFF
= 0x43464620;
453 class AbstractTrueTypeFont
;
457 * @defgroup sft Sun Font Tools Exported Functions
461 * Get the number of fonts contained in a TrueType collection
462 * @param fname - file name
463 * @return number of fonts or zero, if file is not a TTC file.
466 int CountTTCFonts(const char* fname
);
469 * TrueTypeFont constructor.
470 * The font file has to be provided as a memory buffer and length
471 * @param pBuffer - memory buffer
472 * @param nLen - size of memory buffer
473 * @param facenum - logical font number within a TTC file. This value is ignored
475 * @param ttf - returns the opened TrueTypeFont
476 * @param xCharMap - optional parsed character map
477 * @return value of SFErrCodes enum
480 SFErrCodes VCL_DLLPUBLIC
OpenTTFontBuffer(const void* pBuffer
, sal_uInt32 nLen
, sal_uInt32 facenum
,
481 TrueTypeFont
** ttf
, const FontCharMapRef xCharMap
= nullptr);
484 * TrueTypeFont constructor.
485 * Reads the font file and allocates the memory for the structure.
486 * on WIN32 the font has to be provided as a memory buffer and length
487 * @param fname - name of TrueType font file
488 * @param facenum - logical font number within a TTC file. This value is ignored
490 * @param ttf - returns the opened TrueTypeFont
491 * @param xCharMap - optional parsed character map
492 * @return value of SFErrCodes enum
495 SFErrCodes VCL_DLLPUBLIC
OpenTTFontFile(const char *fname
, sal_uInt32 facenum
, TrueTypeFont
** ttf
,
496 const FontCharMapRef xCharMap
= nullptr);
499 bool VCL_DLLPUBLIC
getTTCoverage(
500 std::optional
<std::bitset
<UnicodeCoverage::MAX_UC_ENUM
>> & rUnicodeCoverage
,
501 std::optional
<std::bitset
<CodePageCoverage::MAX_CP_ENUM
>> & rCodePageCoverage
,
502 const unsigned char* pTable
, size_t nLength
);
505 * TrueTypeFont destructor. Deallocates the memory.
508 void VCL_DLLPUBLIC
CloseTTFont(TrueTypeFont
*);
511 * Extracts TrueType control points, and stores them in an allocated array pointed to
512 * by *pointArray. This function returns the number of extracted points.
514 * @param ttf pointer to the TrueTypeFont structure
515 * @param glyphID Glyph ID
516 * @param pointArray Return value - address of the pointer to the first element of the array
517 * of points allocated by the function
518 * @return Returns the number of points in *pointArray or -1 if glyphID is
523 int GetTTGlyphPoints(AbstractTrueTypeFont
*ttf
, sal_uInt32 glyphID
, std::vector
<ControlPoint
>& pointArray
);
526 * Extracts raw glyph data from the 'glyf' table and returns it in an allocated
527 * GlyphData structure.
529 * @param ttf pointer to the TrueTypeFont structure
530 * @param glyphID Glyph ID
532 * @return pointer to an allocated GlyphData structure or NULL if
533 * glyphID is not present in the font
537 std::unique_ptr
<GlyphData
> GetTTRawGlyphData(AbstractTrueTypeFont
*ttf
, sal_uInt32 glyphID
);
540 * For a specified glyph adds all component glyphs IDs to the list and
541 * return their number. If the glyph is a single glyph it has one component
542 * glyph (which is added to the list) and the function returns 1.
543 * For a composite glyphs it returns the number of component glyphs
544 * and adds all of them to the list.
546 * @param ttf pointer to the TrueTypeFont structure
547 * @param glyphID Glyph ID
548 * @param glyphlist list of glyphs
550 * @return number of component glyphs
554 int GetTTGlyphComponents(AbstractTrueTypeFont
*ttf
, sal_uInt32 glyphID
, std::vector
< sal_uInt32
>& glyphlist
);
557 * Extracts all Name Records from the font and stores them in an allocated
558 * array of NameRecord structs
560 * @param ttf pointer to the TrueTypeFont struct
561 * @param nr reference to the vector of NameRecord structs
566 void GetTTNameRecords(AbstractTrueTypeFont
const *ttf
, std::vector
<NameRecord
>& nr
);
569 * Generates a new PostScript Type 3 font and dumps it to <b>outf</b> file.
570 * This function substitutes glyph 0 for all glyphIDs that are not found in the font.
571 * @param ttf pointer to the TrueTypeFont structure
572 * @param outf the resulting font is written to this stream
573 * @param fname font name for the new font. If it is NULL the PostScript name of the
574 * original font will be used
575 * @param glyphArray pointer to an array of glyphs that are to be extracted from ttf
576 * @param encoding array of encoding values. encoding[i] specifies the position of the glyph
577 * glyphArray[i] in the encoding vector of the resulting Type3 font
578 * @param nGlyphs number of glyph IDs in glyphArray and encoding values in encoding
579 * @param wmode writing mode for the output file: 0 - horizontal, 1 - vertical
580 * @return return the value of SFErrCodes enum
585 SFErrCodes
CreateT3FromTTGlyphs(TrueTypeFont
*ttf
, SvStream
*outf
, const char *fname
, sal_uInt16
const *glyphArray
, sal_uInt8
*encoding
, int nGlyphs
, int wmode
);
588 * Generates a new TrueType font and dumps it to <b>outf</b> file.
589 * This function substitutes glyph 0 for all glyphIDs that are not found in the font.
590 * @param ttf pointer to the TrueTypeFont structure
591 * @param fname file name for the output TrueType font file
592 * @param glyphArray pointer to an array of glyphs that are to be extracted from ttf. The first
593 * element of this array has to be glyph 0 (default glyph)
594 * @param encoding array of encoding values. encoding[i] specifies character code for
595 * the glyphID glyphArray[i]. Character code 0 usually points to a default
597 * @param nGlyphs number of glyph IDs in glyphArray and encoding values in encoding
598 * @param flags or'ed TTCreationFlags
599 * @return return the value of SFErrCodes enum
604 VCL_DLLPUBLIC SFErrCodes
CreateTTFromTTGlyphs(AbstractTrueTypeFont
*ttf
,
605 std::vector
<sal_uInt8
>& rOutBuffer
,
606 sal_uInt16
const *glyphArray
,
607 sal_uInt8
const *encoding
,
610 VCL_DLLPUBLIC
bool CreateTTFfontSubset(AbstractTrueTypeFont
& aTTF
,
611 std::vector
<sal_uInt8
>& rOutBuffer
,
612 const sal_GlyphId
* pGlyphIds
,
613 const sal_uInt8
* pEncoding
,
614 int nGlyphCount
, FontSubsetInfo
& rInfo
);
616 * Generates a new PostScript Type42 font and dumps it to <b>outf</b> file.
617 * This function substitutes glyph 0 for all glyphIDs that are not found in the font.
618 * @param ttf pointer to the TrueTypeFont structure
619 * @param outf output stream for a resulting font
620 * @param psname PostScript name of the resulting font
621 * @param glyphArray pointer to an array of glyphs that are to be extracted from ttf. The first
622 * element of this array has to be glyph 0 (default glyph)
623 * @param encoding array of encoding values. encoding[i] specifies character code for
624 * the glyphID glyphArray[i]. Character code 0 usually points to a default
626 * @param nGlyphs number of glyph IDs in glyphArray and encoding values in encoding
627 * @return SFErrCodes::Ok - no errors
628 * SFErrCodes::GlyphNum - too many glyphs (> 255)
629 * SFErrCodes::TtFormat - corrupted TrueType fonts
635 SFErrCodes
CreateT42FromTTGlyphs(TrueTypeFont
*ttf
,
638 sal_uInt16
const *glyphArray
,
643 * Returns global font information about the TrueType font.
644 * @see TTGlobalFontInfo
646 * @param ttf pointer to a TrueTypeFont structure
647 * @param info pointer to a TTGlobalFontInfo structure
651 VCL_DLLPUBLIC
void GetTTGlobalFontInfo(AbstractTrueTypeFont
*ttf
, TTGlobalFontInfo
*info
);
654 * Returns part of the head table info, normally collected by GetTTGlobalFontInfo.
656 * Just implemented separate, because this info not available via Qt API.
658 * @param ttf pointer to a AbstractTrueTypeFont structure
659 * @param xMin global glyph bounding box min X
660 * @param yMin global glyph bounding box min Y
661 * @param xMax global glyph bounding box max X
662 * @param yMax global glyph bounding box max Y
663 * @param macStyle encoded Mac style flags of the font
664 * @return true, if table data could be decoded
667 VCL_DLLPUBLIC
bool GetTTGlobalFontHeadInfo(const AbstractTrueTypeFont
*ttf
, int& xMin
, int& yMin
, int& xMax
, int& yMax
, sal_uInt16
& macStyle
);
669 /*- private definitions */
671 /* indexes into TrueTypeFont::tables[] and TrueTypeFont::tlens[] */
672 constexpr int O_maxp
= 0;
673 constexpr int O_glyf
= 1; /* 'glyf' */
674 constexpr int O_head
= 2; /* 'head' */
675 constexpr int O_loca
= 3; /* 'loca' */
676 constexpr int O_name
= 4; /* 'name' */
677 constexpr int O_hhea
= 5; /* 'hhea' */
678 constexpr int O_hmtx
= 6; /* 'hmtx' */
679 constexpr int O_cmap
= 7; /* 'cmap' */
680 constexpr int O_vhea
= 8; /* 'vhea' */
681 constexpr int O_vmtx
= 9; /* 'vmtx' */
682 constexpr int O_OS2
= 10; /* 'OS/2' */
683 constexpr int O_post
= 11; /* 'post' */
684 constexpr int O_cvt
= 12; /* 'cvt_' - only used in TT->TT generation */
685 constexpr int O_prep
= 13; /* 'prep' - only used in TT->TT generation */
686 constexpr int O_fpgm
= 14; /* 'fpgm' - only used in TT->TT generation */
687 constexpr int O_CFF
= 15; /* 'CFF' */
688 constexpr int NUM_TAGS
= 16;
690 class VCL_DLLPUBLIC AbstractTrueTypeFont
692 std::string m_sFileName
;
693 sal_uInt32 m_nGlyphs
;
694 sal_uInt32 m_nHorzMetrics
;
695 sal_uInt32 m_nVertMetrics
; /* if not 0 => font has vertical metrics information */
696 sal_uInt32 m_nUnitsPerEm
;
697 std::vector
<sal_uInt32
> m_aGlyphOffsets
;
698 FontCharMapRef m_xCharMap
;
699 bool m_bMicrosoftSymbolEncoded
;
702 SFErrCodes
indexGlyphData();
705 AbstractTrueTypeFont(const char* fileName
= nullptr, const FontCharMapRef xCharMap
= nullptr);
706 virtual ~AbstractTrueTypeFont();
708 SFErrCodes
initialize();
710 std::string
const & fileName() const { return m_sFileName
; }
711 sal_uInt32
glyphCount() const { return m_nGlyphs
; }
712 sal_uInt32
glyphOffset(sal_uInt32 glyphID
) const;
713 sal_uInt32
horzMetricCount() const { return m_nHorzMetrics
; }
714 sal_uInt32
vertMetricCount() const { return m_nVertMetrics
; }
715 sal_uInt32
unitsPerEm() const { return m_nUnitsPerEm
; }
716 bool IsMicrosoftSymbolEncoded() const { return m_bMicrosoftSymbolEncoded
; }
718 virtual bool hasTable(sal_uInt32 ord
) const = 0;
719 virtual const sal_uInt8
* table(sal_uInt32 ord
, sal_uInt32
& size
) const = 0;
728 class TrueTypeFont final
: public AbstractTrueTypeFont
732 const sal_uInt8
* pData
= nullptr; /* pointer to a raw subtable in the SFNT file */
733 sal_uInt32 nSize
= 0; /* table size */
736 std::array
<struct TTFontTable_
, NUM_TAGS
> m_aTableList
;
743 TrueTypeFont(const char* pFileName
= nullptr, const FontCharMapRef xCharMap
= nullptr);
744 ~TrueTypeFont() override
;
746 SFErrCodes
open(sal_uInt32 facenum
);
748 bool hasTable(sal_uInt32 ord
) const override
{ return m_aTableList
[ord
].pData
!= nullptr; }
749 inline const sal_uInt8
* table(sal_uInt32 ord
, sal_uInt32
& size
) const override
;
752 const sal_uInt8
* TrueTypeFont::table(sal_uInt32 ord
, sal_uInt32
& size
) const
760 auto& rTable
= m_aTableList
[ord
];
767 #endif // INCLUDED_VCL_INC_SFT_HXX
769 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */