Chromium Code Reviews| 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, | |
|
mtklein
2015/02/23 17:30:36
funky indent?
herb_g
2015/02/23 23:24:53
Done.
| |
| 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 initWithGlyphIDXY(uint32_t glyph_id, SkFixed x, SkFixed y) { |
|
mtklein
2015/02/23 17:30:36
Huh, unused. Must be only SkGlyphCache does this?
herb_g
2015/02/23 23:24:53
Done.
| |
| 41 fForceBW = 0; | 53 this->initCommon(MakeID(glyph_id, x, y)); |
| 54 } | |
| 55 | |
| 56 void initFromGlyph(const SkGlyph& glyph) { | |
|
mtklein
2015/02/23 17:30:36
maybe copyFrom() ?
herb_g
2015/02/23 23:24:53
This is not really copying the whole structure, bu
| |
| 57 this->initCommon(glyph.fID); | |
| 42 } | 58 } |
| 43 | 59 |
| 44 /** | 60 /** |
| 45 * Compute the rowbytes for the specified width and mask-format. | 61 * Compute the rowbytes for the specified width and mask-format. |
| 46 */ | 62 */ |
| 47 static unsigned ComputeRowBytes(unsigned width, SkMask::Format format) { | 63 static unsigned ComputeRowBytes(unsigned width, SkMask::Format format) { |
| 48 unsigned rb = width; | 64 unsigned rb = width; |
| 49 if (SkMask::kBW_Format == format) { | 65 if (SkMask::kBW_Format == format) { |
| 50 rb = (rb + 7) >> 3; | 66 rb = (rb + 7) >> 3; |
| 51 } else if (SkMask::kARGB32_Format == format) { | 67 } else if (SkMask::kARGB32_Format == format) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 } | 103 } |
| 88 | 104 |
| 89 size_t computeImageSize() const; | 105 size_t computeImageSize() const; |
| 90 | 106 |
| 91 /** Call this to set all of the metrics fields to 0 (e.g. if the scaler | 107 /** 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 | 108 encounters an error measuring a glyph). Note: this does not alter the |
| 93 fImage, fPath, fID, fMaskFormat fields. | 109 fImage, fPath, fID, fMaskFormat fields. |
| 94 */ | 110 */ |
| 95 void zeroMetrics(); | 111 void zeroMetrics(); |
| 96 | 112 |
| 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 | 113 |
| 114 void toMask(SkMask* mask) const; | |
| 115 | |
| 116 private: | |
| 117 // TODO(herb) remove friend statement after SkGlyphCache cleanup. | |
| 118 friend class SkGlyphCache; | |
| 119 | |
| 120 void initCommon(uint32_t id) { | |
| 121 fID = id; | |
| 122 fImage = NULL; | |
| 123 fPath = NULL; | |
| 124 fMaskFormat = MASK_FORMAT_UNKNOWN; | |
| 125 fForceBW = 0; | |
| 126 } | |
| 107 static unsigned ID2Code(uint32_t id) { | 127 static unsigned ID2Code(uint32_t id) { |
| 108 return id & kCodeMask; | 128 return (id & kCodeMask) - 1; |
|
mtklein
2015/02/23 17:30:36
Now that it's clear this is safe, let's undo this
herb_g
2015/02/23 23:24:53
If you use ~0, then one record will always be at t
| |
| 109 } | 129 } |
| 110 | 130 |
| 111 static unsigned ID2SubX(uint32_t id) { | 131 static unsigned ID2SubX(uint32_t id) { |
| 112 return id >> (kSubShift + kSubShiftX); | 132 return id >> (kSubShift + kSubShiftX); |
| 113 } | 133 } |
| 114 | 134 |
| 115 static unsigned ID2SubY(uint32_t id) { | 135 static unsigned ID2SubY(uint32_t id) { |
| 116 return (id >> (kSubShift + kSubShiftY)) & kSubMask; | 136 return (id >> (kSubShift + kSubShiftY)) & kSubMask; |
| 117 } | 137 } |
| 118 | 138 |
| 119 static unsigned FixedToSub(SkFixed n) { | 139 static unsigned FixedToSub(SkFixed n) { |
| 120 return (n >> (16 - kSubBits)) & kSubMask; | 140 return (n >> (16 - kSubBits)) & kSubMask; |
| 121 } | 141 } |
| 122 | 142 |
| 123 static SkFixed SubToFixed(unsigned sub) { | 143 static SkFixed SubToFixed(unsigned sub) { |
| 124 SkASSERT(sub <= kSubMask); | 144 SkASSERT(sub <= kSubMask); |
| 125 return sub << (16 - kSubBits); | 145 return sub << (16 - kSubBits); |
| 126 } | 146 } |
| 127 | 147 |
| 128 static uint32_t MakeID(unsigned code) { | 148 static uint32_t MakeID(unsigned code) { |
| 129 return code; | 149 return code + 1; |
| 130 } | 150 } |
| 131 | 151 |
| 132 static uint32_t MakeID(unsigned code, SkFixed x, SkFixed y) { | 152 static uint32_t MakeID(unsigned code, SkFixed x, SkFixed y) { |
| 133 SkASSERT(code <= kCodeMask); | 153 SkASSERT(code <= kCodeMask); |
| 134 x = FixedToSub(x); | 154 x = FixedToSub(x); |
| 135 y = FixedToSub(y); | 155 y = FixedToSub(y); |
| 136 return (x << (kSubShift + kSubShiftX)) | | 156 return (x << (kSubShift + kSubShiftX)) | |
| 137 (y << (kSubShift + kSubShiftY)) | | 157 (y << (kSubShift + kSubShiftY)) | |
| 138 code; | 158 (code + 1); |
| 139 } | 159 } |
| 140 | 160 |
| 141 void toMask(SkMask* mask) const; | 161 uint32_t fID; |
| 142 }; | 162 }; |
| 143 | 163 |
| 144 #endif | 164 #endif |
| OLD | NEW |