| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 #include "GrBitmapTextContext.h" | 8 #include "GrBitmapTextContext.h" |
| 9 #include "GrAtlas.h" | 9 #include "GrAtlas.h" |
| 10 #include "GrDrawTarget.h" | 10 #include "GrDrawTarget.h" |
| 11 #include "GrFontScaler.h" | 11 #include "GrFontScaler.h" |
| 12 #include "GrIndexBuffer.h" | 12 #include "GrIndexBuffer.h" |
| 13 #include "GrStrokeInfo.h" | 13 #include "GrStrokeInfo.h" |
| 14 #include "GrTexturePriv.h" | 14 #include "GrTexturePriv.h" |
| 15 #include "GrTextStrike.h" | 15 #include "GrTextStrike.h" |
| 16 #include "GrTextStrike_impl.h" | 16 #include "GrTextStrike_impl.h" |
| 17 #include "effects/GrCustomCoordsTextureEffect.h" | 17 #include "effects/GrCustomCoordsTextureEffect.h" |
| 18 | 18 |
| 19 #include "SkAutoKern.h" | |
| 20 #include "SkColorPriv.h" | 19 #include "SkColorPriv.h" |
| 21 #include "SkDraw.h" | 20 #include "SkDraw.h" |
| 22 #include "SkDrawProcs.h" | 21 #include "SkDrawProcs.h" |
| 23 #include "SkGlyphCache.h" | 22 #include "SkGlyphCache.h" |
| 24 #include "SkGpuDevice.h" | 23 #include "SkGpuDevice.h" |
| 25 #include "SkGr.h" | 24 #include "SkGr.h" |
| 26 #include "SkPath.h" | 25 #include "SkPath.h" |
| 27 #include "SkRTConf.h" | 26 #include "SkRTConf.h" |
| 28 #include "SkStrokeRec.h" | 27 #include "SkStrokeRec.h" |
| 29 #include "SkTextMapStateProc.h" | 28 #include "SkTextMapStateProc.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 83 |
| 85 fStrike = NULL; | 84 fStrike = NULL; |
| 86 | 85 |
| 87 fCurrTexture = NULL; | 86 fCurrTexture = NULL; |
| 88 fCurrVertex = 0; | 87 fCurrVertex = 0; |
| 89 | 88 |
| 90 fVertices = NULL; | 89 fVertices = NULL; |
| 91 fMaxVertices = 0; | 90 fMaxVertices = 0; |
| 92 } | 91 } |
| 93 | 92 |
| 94 void GrBitmapTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPain
t, | |
| 95 const char text[], size_t byteLength, | |
| 96 SkScalar x, SkScalar y) { | |
| 97 SkASSERT(byteLength == 0 || text != NULL); | |
| 98 | |
| 99 // nothing to draw | |
| 100 if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) { | |
| 101 return; | |
| 102 } | |
| 103 | |
| 104 this->init(paint, skPaint); | |
| 105 | |
| 106 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | |
| 107 | |
| 108 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa
trix()); | |
| 109 SkGlyphCache* cache = autoCache.getCache(); | |
| 110 GrFontScaler* fontScaler = GetGrFontScaler(cache); | |
| 111 | |
| 112 // transform our starting point | |
| 113 { | |
| 114 SkPoint loc; | |
| 115 fContext->getMatrix().mapXY(x, y, &loc); | |
| 116 x = loc.fX; | |
| 117 y = loc.fY; | |
| 118 } | |
| 119 | |
| 120 // need to measure first | |
| 121 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { | |
| 122 SkVector stop; | |
| 123 | |
| 124 MeasureText(cache, glyphCacheProc, text, byteLength, &stop); | |
| 125 | |
| 126 SkScalar stopX = stop.fX; | |
| 127 SkScalar stopY = stop.fY; | |
| 128 | |
| 129 if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) { | |
| 130 stopX = SkScalarHalf(stopX); | |
| 131 stopY = SkScalarHalf(stopY); | |
| 132 } | |
| 133 x -= stopX; | |
| 134 y -= stopY; | |
| 135 } | |
| 136 | |
| 137 const char* stop = text + byteLength; | |
| 138 | |
| 139 SkAutoKern autokern; | |
| 140 | |
| 141 SkFixed fxMask = ~0; | |
| 142 SkFixed fyMask = ~0; | |
| 143 SkFixed halfSampleX, halfSampleY; | |
| 144 if (cache->isSubpixel()) { | |
| 145 halfSampleX = halfSampleY = (SK_FixedHalf >> SkGlyph::kSubBits); | |
| 146 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(fContext->getM
atrix()); | |
| 147 if (kX_SkAxisAlignment == baseline) { | |
| 148 fyMask = 0; | |
| 149 halfSampleY = SK_FixedHalf; | |
| 150 } else if (kY_SkAxisAlignment == baseline) { | |
| 151 fxMask = 0; | |
| 152 halfSampleX = SK_FixedHalf; | |
| 153 } | |
| 154 } else { | |
| 155 halfSampleX = halfSampleY = SK_FixedHalf; | |
| 156 } | |
| 157 | |
| 158 SkFixed fx = SkScalarToFixed(x) + halfSampleX; | |
| 159 SkFixed fy = SkScalarToFixed(y) + halfSampleY; | |
| 160 | |
| 161 GrContext::AutoMatrix autoMatrix; | |
| 162 autoMatrix.setIdentity(fContext, &fPaint); | |
| 163 | |
| 164 while (text < stop) { | |
| 165 const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fy
Mask); | |
| 166 | |
| 167 fx += autokern.adjust(glyph); | |
| 168 | |
| 169 if (glyph.fWidth) { | |
| 170 this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), | |
| 171 glyph.getSubXFixed(), | |
| 172 glyph.getSubYFixed()), | |
| 173 SkFixedFloorToFixed(fx), | |
| 174 SkFixedFloorToFixed(fy), | |
| 175 fontScaler); | |
| 176 } | |
| 177 | |
| 178 fx += glyph.fAdvanceX; | |
| 179 fy += glyph.fAdvanceY; | |
| 180 } | |
| 181 | |
| 182 this->finish(); | |
| 183 } | |
| 184 | |
| 185 void GrBitmapTextContext::onDrawPosText(const GrPaint& paint, const SkPaint& skP
aint, | 93 void GrBitmapTextContext::onDrawPosText(const GrPaint& paint, const SkPaint& skP
aint, |
| 186 const char text[], size_t byteLength, | 94 const char text[], size_t byteLength, |
| 187 const SkScalar pos[], int scalarsPerPositi
on, | 95 const SkScalar pos[], int scalarsPerPositi
on, |
| 188 const SkPoint& offset) { | 96 const SkPoint& offset) { |
| 189 SkASSERT(byteLength == 0 || text != NULL); | 97 SkASSERT(byteLength == 0 || text != NULL); |
| 190 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 98 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 191 | 99 |
| 192 // nothing to draw | 100 // nothing to draw |
| 193 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) { | 101 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) { |
| 194 return; | 102 return; |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 SkSafeSetNull(fCurrTexture); | 519 SkSafeSetNull(fCurrTexture); |
| 612 } | 520 } |
| 613 } | 521 } |
| 614 | 522 |
| 615 inline void GrBitmapTextContext::finish() { | 523 inline void GrBitmapTextContext::finish() { |
| 616 this->flush(); | 524 this->flush(); |
| 617 | 525 |
| 618 GrTextContext::finish(); | 526 GrTextContext::finish(); |
| 619 } | 527 } |
| 620 | 528 |
| OLD | NEW |