Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: src/gpu/GrTextContext.cpp

Issue 653133004: Change drawText() to generate positions and send to drawPosText() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add ignored GMs Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrTextContext.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2010 Google Inc. 2 * Copyright 2010 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 "GrTextContext.h" 8 #include "GrTextContext.h"
9 #include "GrContext.h" 9 #include "GrContext.h"
10 10
(...skipping 26 matching lines...) Expand all
37 fDrawTarget = fContext->getTextTarget(); 37 fDrawTarget = fContext->getTextTarget();
38 38
39 fPaint = grPaint; 39 fPaint = grPaint;
40 fSkPaint = skPaint; 40 fSkPaint = skPaint;
41 } 41 }
42 42
43 bool GrTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint, 43 bool GrTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
44 const char text[], size_t byteLength, 44 const char text[], size_t byteLength,
45 SkScalar x, SkScalar y) { 45 SkScalar x, SkScalar y) {
46 46
47 GrTextContext* textContext = this; 47 SkASSERT(byteLength == 0 || text != NULL);
48 do {
49 if (textContext->canDraw(skPaint)) {
50 textContext->onDrawText(paint, skPaint, text, byteLength, x, y);
51 return true;
52 }
53 textContext = textContext->fFallbackTextContext;
54 } while (textContext);
55 48
56 return false; 49 // nothing to draw
50 if (text == NULL || byteLength == 0) {
51 return true;
52 }
53
54 SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc();
55 SkAutoGlyphCache autoCache(skPaint, &fDeviceProperties, NULL);
56 SkGlyphCache* cache = autoCache.getCache();
57
58 SkTArray<SkScalar> positions;
59
60 const char* textPtr = text;
61 SkFixed stopX = 0;
62 SkFixed stopY = 0;
63 SkFixed origin;
64 switch (skPaint.getTextAlign()) {
65 case SkPaint::kRight_Align: origin = SK_Fixed1; break;
66 case SkPaint::kCenter_Align: origin = SK_FixedHalf; break;
67 case SkPaint::kLeft_Align: origin = 0; break;
68 default: SkFAIL("Invalid paint origin"); return false;
69 }
70
71 SkAutoKern autokern;
72 const char* stop = text + byteLength;
73 while (textPtr < stop) {
74 // don't need x, y here, since all subpixel variants will have the
75 // same advance
76 const SkGlyph& glyph = glyphCacheProc(cache, &textPtr, 0, 0);
77
78 SkFixed width = glyph.fAdvanceX + autokern.adjust(glyph);
79 positions.push_back(SkFixedToScalar(stopX + SkFixedMul_portable(origin, width)));
80
81 SkFixed height = glyph.fAdvanceY;
82 positions.push_back(SkFixedToScalar(stopY + SkFixedMul_portable(origin, height)));
83
84 stopX += width;
85 stopY += height;
86 }
87 SkASSERT(textPtr == stop);
88
89 // now adjust starting point depending on alignment
90 SkScalar alignX = SkFixedToScalar(stopX);
91 SkScalar alignY = SkFixedToScalar(stopY);
92 if (skPaint.getTextAlign() == SkPaint::kCenter_Align) {
93 alignX = SkScalarHalf(alignX);
94 alignY = SkScalarHalf(alignY);
95 } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) {
96 alignX = 0;
97 alignY = 0;
98 }
99 x -= alignX;
100 y -= alignY;
101 SkPoint offset = SkPoint::Make(x, y);
102
103 return this->drawPosText(paint, skPaint, text, byteLength, positions.begin() , 2, offset);
57 } 104 }
58 105
59 bool GrTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint, 106 bool GrTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint,
60 const char text[], size_t byteLength, 107 const char text[], size_t byteLength,
61 const SkScalar pos[], int scalarsPerPosition, 108 const SkScalar pos[], int scalarsPerPosition,
62 const SkPoint& offset) { 109 const SkPoint& offset) {
63 110
64 GrTextContext* textContext = this; 111 GrTextContext* textContext = this;
65 do { 112 do {
66 if (textContext->canDraw(skPaint)) { 113 if (textContext->canDraw(skPaint)) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { 155 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) {
109 scaler = (GrFontScaler*)auxData; 156 scaler = (GrFontScaler*)auxData;
110 } 157 }
111 if (NULL == scaler) { 158 if (NULL == scaler) {
112 scaler = SkNEW_ARGS(GrFontScaler, (cache)); 159 scaler = SkNEW_ARGS(GrFontScaler, (cache));
113 cache->setAuxProc(GlyphCacheAuxProc, scaler); 160 cache->setAuxProc(GlyphCacheAuxProc, scaler);
114 } 161 }
115 162
116 return scaler; 163 return scaler;
117 } 164 }
OLDNEW
« no previous file with comments | « src/gpu/GrTextContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698