• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SkBitmaskEnum.h"
12 #include "SkRect.h"
13 #include "SkRefCnt.h"
14 #include "SkString.h"
15 #include "SkTDArray.h"
16 
17 /** \class SkAdvancedTypefaceMetrics
18 
19     The SkAdvancedTypefaceMetrics class is used by the PDF backend to correctly
20     embed typefaces. This class is created and filled in with information by
21     SkTypeface::getAdvancedMetrics.
22 */
23 struct SkAdvancedTypefaceMetrics {
SkAdvancedTypefaceMetricsSkAdvancedTypefaceMetrics24     SkAdvancedTypefaceMetrics() {}
25     SkAdvancedTypefaceMetrics(const SkAdvancedTypefaceMetrics&) = delete;
26     SkAdvancedTypefaceMetrics& operator=(const SkAdvancedTypefaceMetrics&) = delete;
~SkAdvancedTypefaceMetricsSkAdvancedTypefaceMetrics27     ~SkAdvancedTypefaceMetrics() {}
28 
29     SkString fFontName;
30 
31     // These enum values match the values used in the PDF file format.
32     enum StyleFlags : uint32_t {
33         kFixedPitch_Style  = 0x00000001,
34         kSerif_Style       = 0x00000002,
35         kScript_Style      = 0x00000008,
36         kItalic_Style      = 0x00000040,
37         kAllCaps_Style     = 0x00010000,
38         kSmallCaps_Style   = 0x00020000,
39         kForceBold_Style   = 0x00040000
40     };
41     StyleFlags fStyle = (StyleFlags)0;        // Font style characteristics.
42 
43     enum FontType : uint8_t {
44         kType1_Font,
45         kType1CID_Font,
46         kCFF_Font,
47         kTrueType_Font,
48         kOther_Font,
49     };
50     // The type of the underlying font program.  This field determines which
51     // of the following fields are valid.  If it is kOther_Font the per glyph
52     // information will never be populated.
53     FontType fType = kOther_Font;
54 
55     enum FontFlags : uint8_t {
56         kMultiMaster_FontFlag    = 0x01,  //!<May be true for Type1, CFF, or TrueType fonts.
57         kNotEmbeddable_FontFlag  = 0x02,  //!<May not be embedded.
58         kNotSubsettable_FontFlag = 0x04,  //!<May not be subset.
59     };
60     FontFlags fFlags = (FontFlags)0;  // Global font flags.
61 
62     int16_t fItalicAngle = 0;  // Counterclockwise degrees from vertical of the
63                                // dominant vertical stroke for an Italic face.
64     // The following fields are all in font units.
65     int16_t fAscent = 0;       // Max height above baseline, not including accents.
66     int16_t fDescent = 0;      // Max depth below baseline (negative).
67     int16_t fStemV = 0;        // Thickness of dominant vertical stem.
68     int16_t fCapHeight = 0;    // Height (from baseline) of top of flat capitals.
69 
70     SkIRect fBBox = {0, 0, 0, 0};  // The bounding box of all glyphs (in font units).
71 
72     // The names of each glyph, only populated for postscript fonts.
73     SkTArray<SkString> fGlyphNames;
74 
75     // The mapping from glyph to Unicode; array indices are glyph ids.
76     SkTDArray<SkUnichar> fGlyphToUnicode;
77 };
78 
79 namespace skstd {
80 template <> struct is_bitmask_enum<SkAdvancedTypefaceMetrics::FontFlags> : std::true_type {};
81 template <> struct is_bitmask_enum<SkAdvancedTypefaceMetrics::StyleFlags> : std::true_type {};
82 }
83 
84 #endif
85