xref: /aosp_15_r20/external/skia/src/core/SkAdvancedTypefaceMetrics.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkAdvancedTypefaceMetrics_DEFINED
9 #define SkAdvancedTypefaceMetrics_DEFINED
10 
11 #include "include/core/SkRect.h"
12 #include "include/core/SkString.h"
13 #include "src/base/SkBitmaskEnum.h"  // IWYU pragma: keep
14 
15 #include <cstdint>
16 #include <type_traits>
17 
18 /** \class SkAdvancedTypefaceMetrics
19 
20     The SkAdvancedTypefaceMetrics class is used by the PDF backend to correctly
21     embed typefaces. This class is created and filled in with information by
22     SkTypeface::getAdvancedMetrics.
23 */
24 struct SkAdvancedTypefaceMetrics {
25     // The PostScript name of the font. See `FontName` and `BaseFont` in PDF standard.
26     SkString fPostScriptName;
27 
28     // These enum values match the values used in the PDF file format.
29     enum StyleFlags : uint32_t {
30         kFixedPitch_Style  = 0x00000001,
31         kSerif_Style       = 0x00000002,
32         kScript_Style      = 0x00000008,
33         kItalic_Style      = 0x00000040,
34         kAllCaps_Style     = 0x00010000,
35         kSmallCaps_Style   = 0x00020000,
36         kForceBold_Style   = 0x00040000
37     };
38     StyleFlags fStyle = (StyleFlags)0;        // Font style characteristics.
39 
40     enum FontType : uint8_t {
41         kType1_Font,
42         kType1CID_Font,
43         kCFF_Font,
44         kTrueType_Font,
45         kOther_Font,
46     };
47     // The type of the underlying font program.  This field determines which
48     // of the following fields are valid.  If it is kOther_Font the per glyph
49     // information will never be populated.
50     FontType fType = kOther_Font;
51 
52     enum FontFlags : uint8_t {
53         kVariable_FontFlag       = 1 << 0,  //!<May be true for Type1, CFF, or TrueType fonts.
54         kNotEmbeddable_FontFlag  = 1 << 1,  //!<May not be embedded.
55         kNotSubsettable_FontFlag = 1 << 2,  //!<May not be subset.
56         kAltDataFormat_FontFlag  = 1 << 3,  //!<Data compressed. Table access may still work.
57     };
58     FontFlags fFlags = (FontFlags)0;  // Global font flags.
59 
60     int16_t fItalicAngle = 0;  // Counterclockwise degrees from vertical of the
61                                // dominant vertical stroke for an Italic face.
62     // The following fields are all in font units.
63     int16_t fAscent = 0;       // Max height above baseline, not including accents.
64     int16_t fDescent = 0;      // Max depth below baseline (negative).
65     int16_t fStemV = 0;        // Thickness of dominant vertical stem.
66     int16_t fCapHeight = 0;    // Height (from baseline) of top of flat capitals.
67 
68     SkIRect fBBox = {0, 0, 0, 0};  // The bounding box of all glyphs (in font units).
69 };
70 
71 namespace sknonstd {
72 template <> struct is_bitmask_enum<SkAdvancedTypefaceMetrics::FontFlags> : std::true_type {};
73 template <> struct is_bitmask_enum<SkAdvancedTypefaceMetrics::StyleFlags> : std::true_type {};
74 }  // namespace sknonstd
75 
76 #endif
77