epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 10 | #ifndef SkAdvancedTypefaceMetrics_DEFINED |
| 11 | #define SkAdvancedTypefaceMetrics_DEFINED |
| 12 | |
| 13 | #include "SkRect.h" |
| 14 | #include "SkRefCnt.h" |
| 15 | #include "SkString.h" |
| 16 | #include "SkTDArray.h" |
| 17 | #include "SkTemplates.h" |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 18 | |
| 19 | /** \class SkAdvancedTypefaceMetrics |
| 20 | |
| 21 | The SkAdvancedTypefaceMetrics class is used by the PDF backend to correctly |
bungeman | 7be2eb8 | 2015-02-23 08:25:00 -0800 | [diff] [blame] | 22 | embed typefaces. This class is created and filled in with information by |
| 23 | SkTypeface::getAdvancedTypefaceMetrics. |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | class SkAdvancedTypefaceMetrics : public SkRefCnt { |
| 27 | public: |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 28 | SK_DECLARE_INST_COUNT(SkAdvancedTypefaceMetrics) |
| 29 | |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 30 | SkString fFontName; |
| 31 | |
| 32 | enum FontType { |
| 33 | kType1_Font, |
| 34 | kType1CID_Font, |
| 35 | kCFF_Font, |
| 36 | kTrueType_Font, |
| 37 | kOther_Font, |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 38 | }; |
| 39 | // The type of the underlying font program. This field determines which |
vandebo | 0f9bad0 | 2014-06-19 11:05:39 -0700 | [diff] [blame] | 40 | // of the following fields are valid. If it is kOther_Font the per glyph |
| 41 | // information will never be populated. |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 42 | FontType fType; |
| 43 | |
vandebo | 0f9bad0 | 2014-06-19 11:05:39 -0700 | [diff] [blame] | 44 | enum FontFlags { |
| 45 | kEmpty_FontFlag = 0x0, //!<No flags set |
bungeman | 05773ed | 2015-05-13 10:57:09 -0700 | [diff] [blame^] | 46 | kMultiMaster_FontFlag = 0x1, //!<May be true for Type1, CFF, or TrueType fonts. |
vandebo | 0f9bad0 | 2014-06-19 11:05:39 -0700 | [diff] [blame] | 47 | kNotEmbeddable_FontFlag = 0x2, //!<May not be embedded. |
| 48 | kNotSubsettable_FontFlag = 0x4, //!<May not be subset. |
| 49 | }; |
| 50 | // Global font flags. |
| 51 | FontFlags fFlags; |
| 52 | |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 53 | uint16_t fLastGlyphID; // The last valid glyph ID in the font. |
| 54 | uint16_t fEmSize; // The size of the em box (defines font units). |
| 55 | |
| 56 | // These enum values match the values used in the PDF file format. |
| 57 | enum StyleFlags { |
| 58 | kFixedPitch_Style = 0x00001, |
| 59 | kSerif_Style = 0x00002, |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 60 | kScript_Style = 0x00008, |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 61 | kItalic_Style = 0x00040, |
| 62 | kAllCaps_Style = 0x10000, |
| 63 | kSmallCaps_Style = 0x20000, |
tomhudson@google.com | 1f90287 | 2012-06-01 13:15:47 +0000 | [diff] [blame] | 64 | kForceBold_Style = 0x40000 |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 65 | }; |
| 66 | uint16_t fStyle; // Font style characteristics. |
| 67 | int16_t fItalicAngle; // Counterclockwise degrees from vertical of the |
| 68 | // dominant vertical stroke for an Italic face. |
| 69 | // The following fields are all in font units. |
| 70 | int16_t fAscent; // Max height above baseline, not including accents. |
| 71 | int16_t fDescent; // Max depth below baseline (negative). |
| 72 | int16_t fStemV; // Thickness of dominant vertical stem. |
| 73 | int16_t fCapHeight; // Height (from baseline) of top of flat capitals. |
| 74 | |
| 75 | SkIRect fBBox; // The bounding box of all glyphs (in font units). |
| 76 | |
| 77 | template <typename Data> |
| 78 | struct AdvanceMetric { |
| 79 | enum MetricType { |
| 80 | kDefault, // Default advance: fAdvance.count = 1 |
| 81 | kRange, // Advances for a range: fAdvance.count = fEndID-fStartID |
tomhudson@google.com | 1f90287 | 2012-06-01 13:15:47 +0000 | [diff] [blame] | 82 | kRun // fStartID-fEndID have same advance: fAdvance.count = 1 |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 83 | }; |
| 84 | MetricType fType; |
| 85 | uint16_t fStartId; |
| 86 | uint16_t fEndId; |
| 87 | SkTDArray<Data> fAdvance; |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 88 | SkAutoTDelete<AdvanceMetric<Data> > fNext; |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | struct VerticalMetric { |
| 92 | int16_t fVerticalAdvance; |
| 93 | int16_t fOriginXDisp; // Horiz. displacement of the secondary origin. |
| 94 | int16_t fOriginYDisp; // Vert. displacement of the secondary origin. |
| 95 | }; |
| 96 | typedef AdvanceMetric<int16_t> WidthRange; |
| 97 | typedef AdvanceMetric<VerticalMetric> VerticalAdvanceRange; |
| 98 | |
| 99 | // This is indexed by glyph id. |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 100 | SkAutoTDelete<WidthRange> fGlyphWidths; |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 101 | // Only used for Vertical CID fonts. |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 102 | SkAutoTDelete<VerticalAdvanceRange> fVerticalMetrics; |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 103 | |
| 104 | // The names of each glyph, only populated for postscript fonts. |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 105 | SkAutoTDelete<SkAutoTArray<SkString> > fGlyphNames; |
vandebo@chromium.org | 6744d49 | 2011-05-09 18:13:47 +0000 | [diff] [blame] | 106 | |
| 107 | // The mapping from glyph to Unicode, only populated if |
| 108 | // kToUnicode_PerGlyphInfo is passed to GetAdvancedTypefaceMetrics. |
| 109 | SkTDArray<SkUnichar> fGlyphToUnicode; |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 110 | |
| 111 | private: |
| 112 | typedef SkRefCnt INHERITED; |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
vandebo@chromium.org | 6f72d1e | 2011-02-14 23:19:59 +0000 | [diff] [blame] | 115 | namespace skia_advanced_typeface_metrics_utils { |
| 116 | |
| 117 | template <typename Data> |
| 118 | void resetRange(SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* range, |
| 119 | int startId); |
| 120 | |
| 121 | template <typename Data> |
| 122 | SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* appendRange( |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 123 | SkAutoTDelete<SkAdvancedTypefaceMetrics::AdvanceMetric<Data> >* nextSlot, |
vandebo@chromium.org | 6f72d1e | 2011-02-14 23:19:59 +0000 | [diff] [blame] | 124 | int startId); |
| 125 | |
| 126 | template <typename Data> |
| 127 | void finishRange( |
| 128 | SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* range, |
| 129 | int endId, |
| 130 | typename SkAdvancedTypefaceMetrics::AdvanceMetric<Data>::MetricType |
| 131 | type); |
| 132 | |
vandebo@chromium.org | 37ad8fb | 2011-08-18 02:38:50 +0000 | [diff] [blame] | 133 | /** Retrieve advance data for glyphs. Used by the PDF backend. It calls |
| 134 | underlying platform dependent API getAdvance to acquire the data. |
| 135 | @param num_glyphs Total number of glyphs in the given font. |
| 136 | @param glyphIDs For per-glyph info, specify subset of the font by |
| 137 | giving glyph ids. Each integer represents a glyph |
| 138 | id. Passing NULL means all glyphs in the font. |
| 139 | @param glyphIDsCount Number of elements in subsetGlyphIds. Ignored if |
| 140 | glyphIDs is NULL. |
| 141 | */ |
vandebo@chromium.org | 6f72d1e | 2011-02-14 23:19:59 +0000 | [diff] [blame] | 142 | template <typename Data, typename FontHandle> |
| 143 | SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* getAdvanceData( |
| 144 | FontHandle fontHandle, |
| 145 | int num_glyphs, |
vandebo@chromium.org | 37ad8fb | 2011-08-18 02:38:50 +0000 | [diff] [blame] | 146 | const uint32_t* glyphIDs, |
| 147 | uint32_t glyphIDsCount, |
vandebo@chromium.org | 6f72d1e | 2011-02-14 23:19:59 +0000 | [diff] [blame] | 148 | bool (*getAdvance)(FontHandle fontHandle, int gId, Data* data)); |
| 149 | |
| 150 | } // namespace skia_advanced_typeface_metrics_utils |
| 151 | |
vandebo@chromium.org | c48b2b3 | 2011-02-02 02:11:22 +0000 | [diff] [blame] | 152 | #endif |