blob: 891677e6ba73f1452c28bb0cfb2bab4aa80af040 [file] [log] [blame]
vandebo@chromium.orgc48b2b32011-02-02 02:11:22 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2011 Google Inc.
vandebo@chromium.orgc48b2b32011-02-02 02:11:22 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
vandebo@chromium.orgc48b2b32011-02-02 02:11:22 +00006 */
7
8#ifndef SkAdvancedTypefaceMetrics_DEFINED
9#define SkAdvancedTypefaceMetrics_DEFINED
10
halcanary32875882016-08-16 09:36:23 -070011#include "SkBitmaskEnum.h"
vandebo@chromium.orgc48b2b32011-02-02 02:11:22 +000012#include "SkRect.h"
13#include "SkRefCnt.h"
14#include "SkString.h"
15#include "SkTDArray.h"
mtklein5f939ab2016-03-16 10:28:35 -070016
vandebo@chromium.orgc48b2b32011-02-02 02:11:22 +000017/** \class SkAdvancedTypefaceMetrics
18
19 The SkAdvancedTypefaceMetrics class is used by the PDF backend to correctly
bungeman7be2eb82015-02-23 08:25:00 -080020 embed typefaces. This class is created and filled in with information by
Hal Canary209e4b12017-05-04 14:23:55 -040021 SkTypeface::getAdvancedMetrics.
vandebo@chromium.orgc48b2b32011-02-02 02:11:22 +000022*/
Hal Canary209e4b12017-05-04 14:23:55 -040023struct SkAdvancedTypefaceMetrics {
24 SkAdvancedTypefaceMetrics() {}
25 SkAdvancedTypefaceMetrics(const SkAdvancedTypefaceMetrics&) = delete;
26 SkAdvancedTypefaceMetrics& operator=(const SkAdvancedTypefaceMetrics&) = delete;
halcanary8b1d32c2016-08-08 09:09:59 -070027 ~SkAdvancedTypefaceMetrics() {}
halcanarye20a8752016-05-08 18:47:16 -070028
Hal Canarye1fec192018-03-29 10:59:02 -070029 // The PostScript name of the font. See `FontName` and `BaseFont` in PDF standard.
30 SkString fPostScriptName;
vandebo@chromium.orgc48b2b32011-02-02 02:11:22 +000031 SkString fFontName;
32
Hal Canary9e146962017-05-08 14:16:06 -040033 // These enum values match the values used in the PDF file format.
34 enum StyleFlags : uint32_t {
35 kFixedPitch_Style = 0x00000001,
36 kSerif_Style = 0x00000002,
37 kScript_Style = 0x00000008,
38 kItalic_Style = 0x00000040,
39 kAllCaps_Style = 0x00010000,
40 kSmallCaps_Style = 0x00020000,
41 kForceBold_Style = 0x00040000
42 };
43 StyleFlags fStyle = (StyleFlags)0; // Font style characteristics.
44
halcanary32875882016-08-16 09:36:23 -070045 enum FontType : uint8_t {
vandebo@chromium.orgc48b2b32011-02-02 02:11:22 +000046 kType1_Font,
47 kType1CID_Font,
48 kCFF_Font,
49 kTrueType_Font,
50 kOther_Font,
vandebo@chromium.orgc48b2b32011-02-02 02:11:22 +000051 };
52 // The type of the underlying font program. This field determines which
vandebo0f9bad02014-06-19 11:05:39 -070053 // of the following fields are valid. If it is kOther_Font the per glyph
54 // information will never be populated.
Hal Canary209e4b12017-05-04 14:23:55 -040055 FontType fType = kOther_Font;
vandebo@chromium.orgc48b2b32011-02-02 02:11:22 +000056
halcanary32875882016-08-16 09:36:23 -070057 enum FontFlags : uint8_t {
58 kMultiMaster_FontFlag = 0x01, //!<May be true for Type1, CFF, or TrueType fonts.
59 kNotEmbeddable_FontFlag = 0x02, //!<May not be embedded.
60 kNotSubsettable_FontFlag = 0x04, //!<May not be subset.
vandebo0f9bad02014-06-19 11:05:39 -070061 };
Hal Canary209e4b12017-05-04 14:23:55 -040062 FontFlags fFlags = (FontFlags)0; // Global font flags.
vandebo0f9bad02014-06-19 11:05:39 -070063
Hal Canary209e4b12017-05-04 14:23:55 -040064 int16_t fItalicAngle = 0; // Counterclockwise degrees from vertical of the
65 // dominant vertical stroke for an Italic face.
vandebo@chromium.orgc48b2b32011-02-02 02:11:22 +000066 // The following fields are all in font units.
Hal Canary209e4b12017-05-04 14:23:55 -040067 int16_t fAscent = 0; // Max height above baseline, not including accents.
68 int16_t fDescent = 0; // Max depth below baseline (negative).
69 int16_t fStemV = 0; // Thickness of dominant vertical stem.
70 int16_t fCapHeight = 0; // Height (from baseline) of top of flat capitals.
Hal Canary9c6f6a52018-03-29 10:15:16 -070071 int16_t fXHeight = 0; // Height (from baseline) of the top of lowercase letter x.
vandebo@chromium.orgc48b2b32011-02-02 02:11:22 +000072
Hal Canary209e4b12017-05-04 14:23:55 -040073 SkIRect fBBox = {0, 0, 0, 0}; // The bounding box of all glyphs (in font units).
vandebo@chromium.orgc48b2b32011-02-02 02:11:22 +000074
vandebo@chromium.orgc48b2b32011-02-02 02:11:22 +000075 // The names of each glyph, only populated for postscript fonts.
halcanary8b1d32c2016-08-08 09:09:59 -070076 SkTArray<SkString> fGlyphNames;
vandebo@chromium.org6744d492011-05-09 18:13:47 +000077
Hal Canary209e4b12017-05-04 14:23:55 -040078 // The mapping from glyph to Unicode; array indices are glyph ids.
vandebo@chromium.org6744d492011-05-09 18:13:47 +000079 SkTDArray<SkUnichar> fGlyphToUnicode;
vandebo@chromium.orgc48b2b32011-02-02 02:11:22 +000080};
81
halcanary32875882016-08-16 09:36:23 -070082namespace skstd {
83template <> struct is_bitmask_enum<SkAdvancedTypefaceMetrics::FontFlags> : std::true_type {};
84template <> struct is_bitmask_enum<SkAdvancedTypefaceMetrics::StyleFlags> : std::true_type {};
85}
vandebo@chromium.org6f72d1e2011-02-14 23:19:59 +000086
vandebo@chromium.orgc48b2b32011-02-02 02:11:22 +000087#endif