1 /* 2 * Copyright 2012 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkTextToPathIter_DEFINED 9 #define SkTextToPathIter_DEFINED 10 11 #include "SkFontPriv.h" 12 #include "SkPaint.h" 13 #include "SkStrikeCache.h" 14 15 class SkTextBaseIter { 16 public: getFont()17 const SkFont& getFont() const { return fFont; } getPaint()18 const SkPaint& getPaint() const { return fPaint; } getPathScale()19 SkScalar getPathScale() const { return fScale; } 20 21 protected: 22 SkTextBaseIter(const SkGlyphID glyphs[], int count, const SkFont&, const SkPaint*); 23 24 SkExclusiveStrikePtr fCache; 25 SkFont fFont; 26 SkPaint fPaint; 27 SkScalar fScale; 28 SkScalar fPrevAdvance; 29 const SkGlyphID* fGlyphs; 30 const SkGlyphID* fStop; 31 32 SkScalar fXPos; // accumulated xpos, returned in next 33 }; 34 35 class SkTextInterceptsIter : SkTextBaseIter { 36 public: 37 enum class TextType { 38 kText, 39 kPosText 40 }; 41 SkTextInterceptsIter(const SkGlyphID glyphs[],int count,const SkFont & font,const SkPaint * paint,const SkScalar bounds[2],SkScalar x,SkScalar y,TextType textType)42 SkTextInterceptsIter(const SkGlyphID glyphs[], int count, const SkFont& font, 43 const SkPaint* paint, const SkScalar bounds[2], SkScalar x, SkScalar y, 44 TextType textType) 45 : SkTextBaseIter(glyphs, count, font, paint) 46 { 47 fBoundsBase[0] = bounds[0]; 48 fBoundsBase[1] = bounds[1]; 49 this->setPosition(x, y); 50 } 51 52 /** 53 * Returns false when all of the text has been consumed 54 */ 55 bool next(SkScalar* array, int* count); 56 setPosition(SkScalar x,SkScalar y)57 void setPosition(SkScalar x, SkScalar y) { 58 SkScalar xOffset = 0; 59 for (int i = 0; i < (int) SK_ARRAY_COUNT(fBounds); ++i) { 60 SkScalar bound = fBoundsBase[i] - y; 61 fBounds[i] = bound / fScale; 62 } 63 64 fXPos = xOffset + x; 65 fPrevAdvance = 0; 66 } 67 68 private: 69 SkScalar fBounds[2]; 70 SkScalar fBoundsBase[2]; 71 }; 72 73 #endif 74