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; | |
17 | 16 |
18 // needs to be != to any valid SkMask::Format | 17 // needs to be != to any valid SkMask::Format |
19 #define MASK_FORMAT_UNKNOWN (0xFF) | 18 #define MASK_FORMAT_UNKNOWN (0xFF) |
20 #define MASK_FORMAT_JUST_ADVANCE MASK_FORMAT_UNKNOWN | 19 #define MASK_FORMAT_JUST_ADVANCE MASK_FORMAT_UNKNOWN |
21 | 20 |
22 #define kMaxGlyphWidth (1<<13) | 21 #define kMaxGlyphWidth (1<<13) |
23 | 22 |
24 class SkGlyph { | 23 struct 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; | |
37 void* fImage; | 24 void* fImage; |
38 SkPath* fPath; | 25 SkPath* fPath; |
39 SkFixed fAdvanceX, fAdvanceY; | 26 SkFixed fAdvanceX, fAdvanceY; |
40 | 27 |
| 28 uint32_t fID; |
41 uint16_t fWidth, fHeight; | 29 uint16_t fWidth, fHeight; |
42 int16_t fTop, fLeft; | 30 int16_t fTop, fLeft; |
43 | 31 |
44 uint8_t fMaskFormat; | 32 uint8_t fMaskFormat; |
45 int8_t fRsbDelta, fLsbDelta; // used by auto-kerning | 33 int8_t fRsbDelta, fLsbDelta; // used by auto-kerning |
46 int8_t fForceBW; | 34 int8_t fForceBW; |
47 | 35 |
48 void initWithGlyphID(uint32_t glyph_id) { | 36 void init(uint32_t id) { |
49 this->initCommon(MakeID(glyph_id)); | 37 fID = id; |
50 } | 38 fImage = NULL; |
51 | 39 fPath = NULL; |
52 void initGlyphIdFrom(const SkGlyph& glyph) { | 40 fMaskFormat = MASK_FORMAT_UNKNOWN; |
53 this->initCommon(glyph.fID); | 41 fForceBW = 0; |
54 } | 42 } |
55 | 43 |
56 /** | 44 /** |
57 * Compute the rowbytes for the specified width and mask-format. | 45 * Compute the rowbytes for the specified width and mask-format. |
58 */ | 46 */ |
59 static unsigned ComputeRowBytes(unsigned width, SkMask::Format format) { | 47 static unsigned ComputeRowBytes(unsigned width, SkMask::Format format) { |
60 unsigned rb = width; | 48 unsigned rb = width; |
61 if (SkMask::kBW_Format == format) { | 49 if (SkMask::kBW_Format == format) { |
62 rb = (rb + 7) >> 3; | 50 rb = (rb + 7) >> 3; |
63 } else if (SkMask::kARGB32_Format == format) { | 51 } else if (SkMask::kARGB32_Format == format) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 87 } |
100 | 88 |
101 size_t computeImageSize() const; | 89 size_t computeImageSize() const; |
102 | 90 |
103 /** Call this to set all of the metrics fields to 0 (e.g. if the scaler | 91 /** Call this to set all of the metrics fields to 0 (e.g. if the scaler |
104 encounters an error measuring a glyph). Note: this does not alter the | 92 encounters an error measuring a glyph). Note: this does not alter the |
105 fImage, fPath, fID, fMaskFormat fields. | 93 fImage, fPath, fID, fMaskFormat fields. |
106 */ | 94 */ |
107 void zeroMetrics(); | 95 void zeroMetrics(); |
108 | 96 |
| 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 }; |
109 | 106 |
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 } | |
123 static unsigned ID2Code(uint32_t id) { | 107 static unsigned ID2Code(uint32_t id) { |
124 return (id & kCodeMask); | 108 return id & kCodeMask; |
125 } | 109 } |
126 | 110 |
127 static unsigned ID2SubX(uint32_t id) { | 111 static unsigned ID2SubX(uint32_t id) { |
128 return id >> (kSubShift + kSubShiftX); | 112 return id >> (kSubShift + kSubShiftX); |
129 } | 113 } |
130 | 114 |
131 static unsigned ID2SubY(uint32_t id) { | 115 static unsigned ID2SubY(uint32_t id) { |
132 return (id >> (kSubShift + kSubShiftY)) & kSubMask; | 116 return (id >> (kSubShift + kSubShiftY)) & kSubMask; |
133 } | 117 } |
134 | 118 |
135 static unsigned FixedToSub(SkFixed n) { | 119 static unsigned FixedToSub(SkFixed n) { |
136 return (n >> (16 - kSubBits)) & kSubMask; | 120 return (n >> (16 - kSubBits)) & kSubMask; |
137 } | 121 } |
138 | 122 |
139 static SkFixed SubToFixed(unsigned sub) { | 123 static SkFixed SubToFixed(unsigned sub) { |
140 SkASSERT(sub <= kSubMask); | 124 SkASSERT(sub <= kSubMask); |
141 return sub << (16 - kSubBits); | 125 return sub << (16 - kSubBits); |
142 } | 126 } |
143 | 127 |
144 static uint32_t MakeID(unsigned code) { | 128 static uint32_t MakeID(unsigned code) { |
145 return code; | 129 return code; |
146 } | 130 } |
147 | 131 |
148 static uint32_t MakeID(unsigned code, SkFixed x, SkFixed y) { | 132 static uint32_t MakeID(unsigned code, SkFixed x, SkFixed y) { |
149 SkASSERT(code <= kCodeMask); | 133 SkASSERT(code <= kCodeMask); |
150 x = FixedToSub(x); | 134 x = FixedToSub(x); |
151 y = FixedToSub(y); | 135 y = FixedToSub(y); |
152 return (x << (kSubShift + kSubShiftX)) | | 136 return (x << (kSubShift + kSubShiftX)) | |
153 (y << (kSubShift + kSubShiftY)) | | 137 (y << (kSubShift + kSubShiftY)) | |
154 code; | 138 code; |
155 } | 139 } |
156 | 140 |
157 uint32_t fID; | 141 void toMask(SkMask* mask) const; |
158 }; | 142 }; |
159 | 143 |
160 #endif | 144 #endif |
OLD | NEW |