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

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

Issue 1514933002: Create GrTextUtils (Closed) Base URL: https://skia.googlesource.com/skia.git@cleanuptext9
Patch Set: Created 5 years 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/GrTextUtils.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
(Empty)
1 /*
2 * Copyright 2015 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 #include "GrTextUtils.h"
9
10 #include "GrBlurUtils.h"
11 #include "GrContext.h"
12 #include "GrDrawContext.h"
13 #include "SkDrawProcs.h"
14 #include "SkGlyphCache.h"
15 #include "SkPaint.h"
16 #include "SkRect.h"
17 #include "SkTextMapStateProc.h"
18 #include "SkTextToPathIter.h"
19
20 void GrTextUtils::DrawTextAsPath(GrContext* context, GrDrawContext* dc,
21 const GrClip& clip,
22 const SkPaint& skPaint, const SkMatrix& viewMat rix,
23 const char text[], size_t byteLength, SkScalar x, SkScalar y,
24 const SkIRect& clipBounds) {
25 SkTextToPathIter iter(text, byteLength, skPaint, true);
26
27 SkMatrix matrix;
28 matrix.setScale(iter.getPathScale(), iter.getPathScale());
29 matrix.postTranslate(x, y);
30
31 const SkPath* iterPath;
32 SkScalar xpos, prevXPos = 0;
33
34 while (iter.next(&iterPath, &xpos)) {
35 matrix.postTranslate(xpos - prevXPos, 0);
36 if (iterPath) {
37 const SkPaint& pnt = iter.getPaint();
38 GrBlurUtils::drawPathWithMaskFilter(context, dc, clip, *iterPath,
39 pnt, viewMatrix, &matrix, clipBo unds, false);
40 }
41 prevXPos = xpos;
42 }
43 }
44
45 void GrTextUtils::DrawPosTextAsPath(GrContext* context,
46 GrDrawContext* dc,
47 const SkSurfaceProps& props,
48 const GrClip& clip,
49 const SkPaint& origPaint, const SkMatrix& vi ewMatrix,
50 const char text[], size_t byteLength,
51 const SkScalar pos[], int scalarsPerPosition ,
52 const SkPoint& offset, const SkIRect& clipBo unds) {
53 // setup our std paint, in hopes of getting hits in the cache
54 SkPaint paint(origPaint);
55 SkScalar matrixScale = paint.setupForAsPaths();
56
57 SkMatrix matrix;
58 matrix.setScale(matrixScale, matrixScale);
59
60 // Temporarily jam in kFill, so we only ever ask for the raw outline from th e cache.
61 paint.setStyle(SkPaint::kFill_Style);
62 paint.setPathEffect(nullptr);
63
64 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc();
65 SkAutoGlyphCache autoCache(paint, &props, nullptr);
66 SkGlyphCache* cache = autoCache.getCache();
67
68 const char* stop = text + byteLength;
69 SkTextAlignProc alignProc(paint.getTextAlign());
70 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition);
71
72 // Now restore the original settings, so we "draw" with whatever style/strok ing.
73 paint.setStyle(origPaint.getStyle());
74 paint.setPathEffect(origPaint.getPathEffect());
75
76 while (text < stop) {
77 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
78 if (glyph.fWidth) {
79 const SkPath* path = cache->findPath(glyph);
80 if (path) {
81 SkPoint tmsLoc;
82 tmsProc(pos, &tmsLoc);
83 SkPoint loc;
84 alignProc(tmsLoc, glyph, &loc);
85
86 matrix[SkMatrix::kMTransX] = loc.fX;
87 matrix[SkMatrix::kMTransY] = loc.fY;
88 GrBlurUtils::drawPathWithMaskFilter(context, dc, clip, *path, pa int,
89 viewMatrix, &matrix, clipBou nds, false);
90 }
91 }
92 pos += scalarsPerPosition;
93 }
94 }
OLDNEW
« no previous file with comments | « src/gpu/GrTextUtils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698