| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "GrFontScaler.h" | 9 #include "GrFontScaler.h" |
| 10 #include "SkDescriptor.h" | 10 #include "SkDescriptor.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 const GrFontDescKey* GrFontScaler::getKey() { | 42 const GrFontDescKey* GrFontScaler::getKey() { |
| 43 if (NULL == fKey) { | 43 if (NULL == fKey) { |
| 44 fKey = SkNEW_ARGS(GrFontDescKey, (fStrike->getDescriptor())); | 44 fKey = SkNEW_ARGS(GrFontDescKey, (fStrike->getDescriptor())); |
| 45 } | 45 } |
| 46 return fKey; | 46 return fKey; |
| 47 } | 47 } |
| 48 | 48 |
| 49 GrMaskFormat GrFontScaler::getPackedGlyphMaskFormat(GrGlyph::PackedID packed) co
nst { | 49 GrMaskFormat GrFontScaler::getPackedGlyphMaskFormat(const SkGlyph& glyph) const
{ |
| 50 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), | |
| 51 GrGlyph::UnpackFixedX(pack
ed), | |
| 52 GrGlyph::UnpackFixedY(pack
ed)); | |
| 53 SkMask::Format format = static_cast<SkMask::Format>(glyph.fMaskFormat); | 50 SkMask::Format format = static_cast<SkMask::Format>(glyph.fMaskFormat); |
| 54 switch (format) { | 51 switch (format) { |
| 55 case SkMask::kBW_Format: | 52 case SkMask::kBW_Format: |
| 56 // fall through to kA8 -- we store BW glyphs in our 8-bit cache | 53 // fall through to kA8 -- we store BW glyphs in our 8-bit cache |
| 57 case SkMask::kA8_Format: | 54 case SkMask::kA8_Format: |
| 58 return kA8_GrMaskFormat; | 55 return kA8_GrMaskFormat; |
| 59 case SkMask::kLCD16_Format: | 56 case SkMask::kLCD16_Format: |
| 60 return kA565_GrMaskFormat; | 57 return kA565_GrMaskFormat; |
| 61 case SkMask::kARGB32_Format: | 58 case SkMask::kARGB32_Format: |
| 62 return kARGB_GrMaskFormat; | 59 return kARGB_GrMaskFormat; |
| 63 default: | 60 default: |
| 64 SkDEBUGFAIL("unsupported SkMask::Format"); | 61 SkDEBUGFAIL("unsupported SkMask::Format"); |
| 65 return kA8_GrMaskFormat; | 62 return kA8_GrMaskFormat; |
| 66 } | 63 } |
| 67 } | 64 } |
| 68 | 65 |
| 69 bool GrFontScaler::getPackedGlyphBounds(GrGlyph::PackedID packed, SkIRect* bound
s) { | 66 bool GrFontScaler::getPackedGlyphBounds(const SkGlyph& glyph, SkIRect* bounds) { |
| 70 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), | |
| 71 GrGlyph::UnpackFixedX(pack
ed), | |
| 72 GrGlyph::UnpackFixedY(pack
ed)); | |
| 73 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight); | 67 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight); |
| 74 | 68 |
| 75 return true; | 69 return true; |
| 76 } | 70 } |
| 77 | 71 |
| 78 bool GrFontScaler::getPackedGlyphDFBounds(GrGlyph::PackedID packed, SkIRect* bou
nds) { | 72 bool GrFontScaler::getPackedGlyphDFBounds(const SkGlyph& glyph, SkIRect* bounds)
{ |
| 79 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), | |
| 80 GrGlyph::UnpackFixedX(pack
ed), | |
| 81 GrGlyph::UnpackFixedY(pack
ed)); | |
| 82 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight); | 73 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight); |
| 83 bounds->outset(SK_DistanceFieldPad, SK_DistanceFieldPad); | 74 bounds->outset(SK_DistanceFieldPad, SK_DistanceFieldPad); |
| 84 | 75 |
| 85 return true; | 76 return true; |
| 86 } | 77 } |
| 87 | 78 |
| 88 namespace { | 79 namespace { |
| 89 // expands each bit in a bitmask to 0 or ~0 of type INT_TYPE. Used to expand a B
W glyph mask to | 80 // expands each bit in a bitmask to 0 or ~0 of type INT_TYPE. Used to expand a B
W glyph mask to |
| 90 // A8, RGB565, or RGBA8888. | 81 // A8, RGB565, or RGBA8888. |
| 91 template <typename INT_TYPE> | 82 template <typename INT_TYPE> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 104 for (int i = 7; i >= 0 && rowWritesLeft; --i, --rowWritesLeft) { | 95 for (int i = 7; i >= 0 && rowWritesLeft; --i, --rowWritesLeft) { |
| 105 *d++ = (mask & (1 << i)) ? (INT_TYPE)(~0UL) : 0; | 96 *d++ = (mask & (1 << i)) ? (INT_TYPE)(~0UL) : 0; |
| 106 } | 97 } |
| 107 } | 98 } |
| 108 dst = reinterpret_cast<INT_TYPE*>(reinterpret_cast<intptr_t>(dst) + dstR
owBytes); | 99 dst = reinterpret_cast<INT_TYPE*>(reinterpret_cast<intptr_t>(dst) + dstR
owBytes); |
| 109 src += srcRowBytes; | 100 src += srcRowBytes; |
| 110 } | 101 } |
| 111 } | 102 } |
| 112 } | 103 } |
| 113 | 104 |
| 114 bool GrFontScaler::getPackedGlyphImage(GrGlyph::PackedID packed, | 105 bool GrFontScaler::getPackedGlyphImage(const SkGlyph& glyph, int width, int heig
ht, int dstRB, |
| 115 int width, int height, | 106 void* dst) { |
| 116 int dstRB, void* dst) { | |
| 117 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), | |
| 118 GrGlyph::UnpackFixedX(pack
ed), | |
| 119 GrGlyph::UnpackFixedY(pack
ed)); | |
| 120 SkASSERT(glyph.fWidth == width); | 107 SkASSERT(glyph.fWidth == width); |
| 121 SkASSERT(glyph.fHeight == height); | 108 SkASSERT(glyph.fHeight == height); |
| 122 const void* src = fStrike->findImage(glyph); | 109 const void* src = fStrike->findImage(glyph); |
| 123 if (NULL == src) { | 110 if (NULL == src) { |
| 124 return false; | 111 return false; |
| 125 } | 112 } |
| 126 | 113 |
| 127 int srcRB = glyph.rowBytes(); | 114 int srcRB = glyph.rowBytes(); |
| 128 // The windows font host sometimes has BW glyphs in a non-BW strike. So it i
s important here to | 115 // The windows font host sometimes has BW glyphs in a non-BW strike. So it i
s important here to |
| 129 // check the glyph's format, not the strike's format, and to be able to conv
ert to any of the | 116 // check the glyph's format, not the strike's format, and to be able to conv
ert to any of the |
| (...skipping 21 matching lines...) Expand all Loading... |
| 151 const int bbp = GrMaskFormatBytesPerPixel(this->getMaskFormat()); | 138 const int bbp = GrMaskFormatBytesPerPixel(this->getMaskFormat()); |
| 152 for (int y = 0; y < height; y++) { | 139 for (int y = 0; y < height; y++) { |
| 153 memcpy(dst, src, width * bbp); | 140 memcpy(dst, src, width * bbp); |
| 154 src = (const char*)src + srcRB; | 141 src = (const char*)src + srcRB; |
| 155 dst = (char*)dst + dstRB; | 142 dst = (char*)dst + dstRB; |
| 156 } | 143 } |
| 157 } | 144 } |
| 158 return true; | 145 return true; |
| 159 } | 146 } |
| 160 | 147 |
| 161 bool GrFontScaler::getPackedGlyphDFImage(GrGlyph::PackedID packed, | 148 bool GrFontScaler::getPackedGlyphDFImage(const SkGlyph& glyph, int width, int he
ight, void* dst) { |
| 162 int width, int height, | |
| 163 void* dst) { | |
| 164 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), | |
| 165 GrGlyph::UnpackFixedX(pack
ed), | |
| 166 GrGlyph::UnpackFixedY(pack
ed)); | |
| 167 SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width); | 149 SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width); |
| 168 SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height); | 150 SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height); |
| 169 const void* image = fStrike->findImage(glyph); | 151 const void* image = fStrike->findImage(glyph); |
| 170 if (NULL == image) { | 152 if (NULL == image) { |
| 171 return false; | 153 return false; |
| 172 } | 154 } |
| 173 // now generate the distance field | 155 // now generate the distance field |
| 174 SkASSERT(dst); | 156 SkASSERT(dst); |
| 175 SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); | 157 SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); |
| 176 if (SkMask::kA8_Format == maskFormat) { | 158 if (SkMask::kA8_Format == maskFormat) { |
| 177 // make the distance field from the image | 159 // make the distance field from the image |
| 178 SkGenerateDistanceFieldFromA8Image((unsigned char*)dst, | 160 SkGenerateDistanceFieldFromA8Image((unsigned char*)dst, |
| 179 (unsigned char*)image, | 161 (unsigned char*)image, |
| 180 glyph.fWidth, glyph.fHeight, | 162 glyph.fWidth, glyph.fHeight, |
| 181 glyph.rowBytes()); | 163 glyph.rowBytes()); |
| 182 } else if (SkMask::kBW_Format == maskFormat) { | 164 } else if (SkMask::kBW_Format == maskFormat) { |
| 183 // make the distance field from the image | 165 // make the distance field from the image |
| 184 SkGenerateDistanceFieldFromBWImage((unsigned char*)dst, | 166 SkGenerateDistanceFieldFromBWImage((unsigned char*)dst, |
| 185 (unsigned char*)image, | 167 (unsigned char*)image, |
| 186 glyph.fWidth, glyph.fHeight, | 168 glyph.fWidth, glyph.fHeight, |
| 187 glyph.rowBytes()); | 169 glyph.rowBytes()); |
| 188 } else { | 170 } else { |
| 189 return false; | 171 return false; |
| 190 } | 172 } |
| 191 | 173 |
| 192 return true; | 174 return true; |
| 193 } | 175 } |
| 194 | 176 |
| 195 // we should just return const SkPath* (NULL means false) | 177 const SkPath* GrFontScaler::getGlyphPath(const SkGlyph& glyph) { |
| 196 bool GrFontScaler::getGlyphPath(uint16_t glyphID, SkPath* path) { | 178 return fStrike->findPath(glyph); |
| 179 } |
| 197 | 180 |
| 198 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(glyphID); | 181 const SkGlyph& GrFontScaler::grToSkGlyph(GrGlyph::PackedID id) { |
| 199 const SkPath* skPath = fStrike->findPath(glyph); | 182 return fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(id), |
| 200 if (skPath) { | 183 GrGlyph::UnpackFixedX(id), |
| 201 *path = *skPath; | 184 GrGlyph::UnpackFixedY(id)); |
| 202 return true; | |
| 203 } | |
| 204 return false; | |
| 205 } | 185 } |
| OLD | NEW |