OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkGlyph_DEFINED | 8 #ifndef SkGlyph_DEFINED |
9 #define SkGlyph_DEFINED | 9 #define SkGlyph_DEFINED |
10 | 10 |
11 #include "SkTypes.h" | 11 #include "SkTypes.h" |
12 #include "SkFixed.h" | 12 #include "SkFixed.h" |
13 #include "SkMask.h" | 13 #include "SkMask.h" |
14 | 14 |
15 class SkPath; | 15 class SkPath; |
16 class SkGlyphCache; | |
16 | 17 |
17 // needs to be != to any valid SkMask::Format | 18 // needs to be != to any valid SkMask::Format |
18 #define MASK_FORMAT_UNKNOWN (0xFF) | 19 #define MASK_FORMAT_UNKNOWN (0xFF) |
19 #define MASK_FORMAT_JUST_ADVANCE MASK_FORMAT_UNKNOWN | 20 #define MASK_FORMAT_JUST_ADVANCE MASK_FORMAT_UNKNOWN |
20 | 21 |
21 #define kMaxGlyphWidth (1<<13) | 22 #define kMaxGlyphWidth (1<<13) |
22 | 23 |
23 struct SkGlyph { | 24 class SkGlyph { |
25 enum { | |
26 kSubBits = 2, | |
27 kSubMask = ((1 << kSubBits) - 1), | |
28 kSubShift = 24, // must be large enough for glyphs and unichars | |
29 kCodeMask = ((1 << kSubShift) - 1), | |
30 // relative offsets for X and Y subpixel bits | |
31 kSubShiftX = kSubBits, | |
32 kSubShiftY = 0 | |
33 }; | |
34 | |
35 public: | |
36 static const SkFixed kSubpixelRound = SK_FixedHalf >> SkGlyph::kSubBits; | |
24 void* fImage; | 37 void* fImage; |
25 SkPath* fPath; | 38 SkPath* fPath; |
26 SkFixed fAdvanceX, fAdvanceY; | 39 SkFixed fAdvanceX, fAdvanceY; |
27 | 40 |
28 uint32_t fID; | |
29 uint16_t fWidth, fHeight; | 41 uint16_t fWidth, fHeight; |
30 int16_t fTop, fLeft; | 42 int16_t fTop, fLeft; |
31 | 43 |
32 uint8_t fMaskFormat; | 44 uint8_t fMaskFormat; |
33 int8_t fRsbDelta, fLsbDelta; // used by auto-kerning | 45 int8_t fRsbDelta, fLsbDelta; // used by auto-kerning |
34 int8_t fForceBW; | 46 int8_t fForceBW; |
35 | 47 |
36 void init(uint32_t id) { | 48 void initWithGlyphID(uint32_t glyph_id) { |
37 fID = id; | 49 this->initCommon(MakeID(glyph_id)); |
38 fImage = NULL; | 50 } |
39 fPath = NULL; | 51 |
40 fMaskFormat = MASK_FORMAT_UNKNOWN; | 52 void initGlyphIdFrom(const SkGlyph& glyph) { |
41 fForceBW = 0; | 53 this->initCommon(glyph.fID); |
42 } | 54 } |
43 | 55 |
44 /** | 56 /** |
45 * Compute the rowbytes for the specified width and mask-format. | 57 * Compute the rowbytes for the specified width and mask-format. |
46 */ | 58 */ |
47 static unsigned ComputeRowBytes(unsigned width, SkMask::Format format) { | 59 static unsigned ComputeRowBytes(unsigned width, SkMask::Format format) { |
48 unsigned rb = width; | 60 unsigned rb = width; |
49 if (SkMask::kBW_Format == format) { | 61 if (SkMask::kBW_Format == format) { |
50 rb = (rb + 7) >> 3; | 62 rb = (rb + 7) >> 3; |
51 } else if (SkMask::kARGB32_Format == format) { | 63 } else if (SkMask::kARGB32_Format == format) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 } | 99 } |
88 | 100 |
89 size_t computeImageSize() const; | 101 size_t computeImageSize() const; |
90 | 102 |
91 /** Call this to set all of the metrics fields to 0 (e.g. if the scaler | 103 /** Call this to set all of the metrics fields to 0 (e.g. if the scaler |
92 encounters an error measuring a glyph). Note: this does not alter the | 104 encounters an error measuring a glyph). Note: this does not alter the |
93 fImage, fPath, fID, fMaskFormat fields. | 105 fImage, fPath, fID, fMaskFormat fields. |
94 */ | 106 */ |
95 void zeroMetrics(); | 107 void zeroMetrics(); |
96 | 108 |
97 enum { | |
98 kSubBits = 2, | |
99 kSubMask = ((1 << kSubBits) - 1), | |
100 kSubShift = 24, // must be large enough for glyphs and unichars | |
101 kCodeMask = ((1 << kSubShift) - 1), | |
102 // relative offsets for X and Y subpixel bits | |
103 kSubShiftX = kSubBits, | |
104 kSubShiftY = 0 | |
105 }; | |
106 | 109 |
110 void toMask(SkMask* mask) const; | |
111 | |
112 private: | |
113 // TODO(herb) remove friend statement after SkGlyphCache cleanup. | |
114 friend class SkGlyphCache; | |
115 | |
116 void initCommon(uint32_t id) { | |
117 fID = id; | |
118 fImage = NULL; | |
119 fPath = NULL; | |
120 fMaskFormat = MASK_FORMAT_UNKNOWN; | |
121 fForceBW = 0; | |
122 } | |
107 static unsigned ID2Code(uint32_t id) { | 123 static unsigned ID2Code(uint32_t id) { |
108 return id & kCodeMask; | 124 return (id & kCodeMask); |
109 } | 125 } |
110 | 126 |
111 static unsigned ID2SubX(uint32_t id) { | 127 static unsigned ID2SubX(uint32_t id) { |
112 return id >> (kSubShift + kSubShiftX); | 128 return id >> (kSubShift + kSubShiftX); |
113 } | 129 } |
114 | 130 |
115 static unsigned ID2SubY(uint32_t id) { | 131 static unsigned ID2SubY(uint32_t id) { |
116 return (id >> (kSubShift + kSubShiftY)) & kSubMask; | 132 return (id >> (kSubShift + kSubShiftY)) & kSubMask; |
117 } | 133 } |
118 | 134 |
119 static unsigned FixedToSub(SkFixed n) { | 135 static unsigned FixedToSub(SkFixed n) { |
120 return (n >> (16 - kSubBits)) & kSubMask; | 136 return (n >> (16 - kSubBits)) & kSubMask; |
121 } | 137 } |
122 | 138 |
123 static SkFixed SubToFixed(unsigned sub) { | 139 static SkFixed SubToFixed(unsigned sub) { |
124 SkASSERT(sub <= kSubMask); | 140 SkASSERT(sub <= kSubMask); |
125 return sub << (16 - kSubBits); | 141 return sub << (16 - kSubBits); |
126 } | 142 } |
127 | 143 |
128 static uint32_t MakeID(unsigned code) { | 144 static uint32_t MakeID(unsigned code) { |
129 return code; | 145 return code; |
130 } | 146 } |
131 | 147 |
132 static uint32_t MakeID(unsigned code, SkFixed x, SkFixed y) { | 148 static uint32_t MakeID(unsigned code, SkFixed x, SkFixed y) { |
133 SkASSERT(code <= kCodeMask); | 149 SkASSERT(code <= kCodeMask); |
134 x = FixedToSub(x); | 150 x = FixedToSub(x); |
135 y = FixedToSub(y); | 151 y = FixedToSub(y); |
136 return (x << (kSubShift + kSubShiftX)) | | 152 return (x << (kSubShift + kSubShiftX)) | |
137 (y << (kSubShift + kSubShiftY)) | | 153 (y << (kSubShift + kSubShiftY)) | |
138 code; | 154 code; |
139 } | 155 } |
140 | 156 |
141 void toMask(SkMask* mask) const; | 157 // FIXME - This is needed because the Android frame work directly |
158 // accesses fID. Remove when fID accesses are cleaned up. | |
mtklein
2015/02/24 23:33:48
As far as dirty hacks go, I don't think this makes
scroggo
2015/02/25 14:08:00
Android does not need a setter. That seems like th
| |
159 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | |
160 public: | |
161 #endif | |
162 uint32_t fID; | |
142 }; | 163 }; |
143 | 164 |
144 #endif | 165 #endif |
OLD | NEW |