| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 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 SkTextToPathIter_DEFINED | 8 #ifndef SkTextToPathIter_DEFINED |
| 9 #define SkTextToPathIter_DEFINED | 9 #define SkTextToPathIter_DEFINED |
| 10 | 10 |
| 11 #include "SkAutoKern.h" | 11 #include "SkAutoKern.h" |
| 12 #include "SkPaint.h" | 12 #include "SkPaint.h" |
| 13 | 13 |
| 14 class SkGlyphCache; | 14 class SkGlyphCache; |
| 15 | 15 |
| 16 class SkTextBaseIter { | 16 class SkTextBaseIter { |
| 17 protected: | 17 protected: |
| 18 SkTextBaseIter(const char text[], size_t length, const SkPaint& paint, | 18 SkTextBaseIter(const char text[], size_t length, const SkPaint& paint, |
| 19 bool applyStrokeAndPathEffects); | 19 bool applyStrokeAndPathEffects); |
| 20 ~SkTextBaseIter(); | 20 ~SkTextBaseIter(); |
| 21 | 21 |
| 22 SkGlyphCache* fCache; | 22 SkGlyphCache* fCache; |
| 23 SkPaint fPaint; | 23 SkPaint fPaint; |
| 24 SkScalar fScale; | 24 SkScalar fScale; |
| 25 SkFixed fPrevAdvance; | 25 SkScalar fPrevAdvance; |
| 26 const char* fText; | 26 const char* fText; |
| 27 const char* fStop; | 27 const char* fStop; |
| 28 SkPaint::GlyphCacheProc fGlyphCacheProc; | 28 SkPaint::GlyphCacheProc fGlyphCacheProc; |
| 29 | 29 |
| 30 SkScalar fXPos; // accumulated xpos, returned in next | 30 SkScalar fXPos; // accumulated xpos, returned in next |
| 31 SkAutoKern fAutoKern; | 31 SkAutoKern fAutoKern; |
| 32 int fXYIndex; // cache for horizontal -vs- vertical text | 32 int fXYIndex; // cache for horizontal -vs- vertical text |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 class SkTextToPathIter : SkTextBaseIter { | 35 class SkTextToPathIter : SkTextBaseIter { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 * Returns false when all of the text has been consumed | 68 * Returns false when all of the text has been consumed |
| 69 */ | 69 */ |
| 70 bool next(SkScalar* array, int* count); | 70 bool next(SkScalar* array, int* count); |
| 71 | 71 |
| 72 void setPosition(SkScalar x, SkScalar y) { | 72 void setPosition(SkScalar x, SkScalar y) { |
| 73 SkScalar xOffset = TextType::kText == fTextType && fXYIndex ? fXPos : 0; | 73 SkScalar xOffset = TextType::kText == fTextType && fXYIndex ? fXPos : 0; |
| 74 if (TextType::kPosText == fTextType | 74 if (TextType::kPosText == fTextType |
| 75 && fPaint.getTextAlign() != SkPaint::kLeft_Align) { // need to m
easure first | 75 && fPaint.getTextAlign() != SkPaint::kLeft_Align) { // need to m
easure first |
| 76 const char* text = fText; | 76 const char* text = fText; |
| 77 const SkGlyph& glyph = fGlyphCacheProc(fCache, &text); | 77 const SkGlyph& glyph = fGlyphCacheProc(fCache, &text); |
| 78 SkScalar width = SkScalarMul(SkFixedToScalar((&glyph.fAdvanceX)[0]),
fScale); | 78 SkScalar width = SkScalarMul(SkFloatToScalar((&glyph.fAdvanceX)[0]),
fScale); |
| 79 if (fPaint.getTextAlign() == SkPaint::kCenter_Align) { | 79 if (fPaint.getTextAlign() == SkPaint::kCenter_Align) { |
| 80 width = SkScalarHalf(width); | 80 width = SkScalarHalf(width); |
| 81 } | 81 } |
| 82 xOffset = width; | 82 xOffset = width; |
| 83 } | 83 } |
| 84 | 84 |
| 85 for (int i = 0; i < (int) SK_ARRAY_COUNT(fBounds); ++i) { | 85 for (int i = 0; i < (int) SK_ARRAY_COUNT(fBounds); ++i) { |
| 86 SkScalar bound = fBoundsBase[i] - (fXYIndex ? x : y); | 86 SkScalar bound = fBoundsBase[i] - (fXYIndex ? x : y); |
| 87 if (fXYIndex) { | 87 if (fXYIndex) { |
| 88 bound += xOffset; | 88 bound += xOffset; |
| 89 } | 89 } |
| 90 fBounds[i] = bound / fScale; | 90 fBounds[i] = bound / fScale; |
| 91 } | 91 } |
| 92 | 92 |
| 93 fXPos = xOffset + (fXYIndex ? y : x); | 93 fXPos = xOffset + (fXYIndex ? y : x); |
| 94 fPrevAdvance = 0; | 94 fPrevAdvance = 0; |
| 95 } | 95 } |
| 96 | 96 |
| 97 private: | 97 private: |
| 98 SkScalar fBounds[2]; | 98 SkScalar fBounds[2]; |
| 99 SkScalar fBoundsBase[2]; | 99 SkScalar fBoundsBase[2]; |
| 100 TextType fTextType; | 100 TextType fTextType; |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 #endif | 103 #endif |
| OLD | NEW |