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

Side by Side Diff: tools/SkShaper_primitive.cpp

Issue 2201153002: SkShaper: optionally disable harfbuzz (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-08-02 (Tuesday) 18:27:47 EDT Created 4 years, 4 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 | « tools/SkShaper_harfbuzz.cpp ('k') | tools/using_skia_and_harfbuzz.cpp » ('j') | 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 2016 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 #include "SkShaper.h"
8 #include "SkStream.h"
9 #include "SkTextBlob.h"
10 #include "SkTypeface.h"
11
12 struct SkShaper::Impl {
13 sk_sp<SkTypeface> fTypeface;
14 };
15
16 SkShaper::SkShaper(sk_sp<SkTypeface> tf) : fImpl(new Impl) {
17 fImpl->fTypeface = tf ? std::move(tf) : SkTypeface::MakeDefault();
18 }
19
20 SkShaper::~SkShaper() {}
21
22 bool SkShaper::good() const { return true; }
23
24 SkScalar SkShaper::shape(SkTextBlobBuilder* builder,
25 const SkPaint& srcPaint,
26 const char* utf8text,
27 size_t textBytes,
28 SkPoint point) const {
29 SkPaint paint(srcPaint);
30 paint.setTypeface(fImpl->fTypeface);
31 paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
32 int glyphCount = paint.countText(utf8text, textBytes);
33 if (glyphCount <= 0) {
34 return 0;
35 }
36 SkRect bounds;
37 (void)paint.measureText(utf8text, textBytes, &bounds);
38 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
39 const SkTextBlobBuilder::RunBuffer& runBuffer = builder->allocRunPosH(
40 paint, glyphCount, point.y(), &bounds);
41 paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
42 (void)paint.textToGlyphs(utf8text, textBytes, runBuffer.glyphs);
43 (void)paint.getTextWidths(utf8text, textBytes, runBuffer.pos);
44 SkScalar x = point.x();
45 for (int i = 0; i < glyphCount; ++i) {
46 SkScalar w = runBuffer.pos[i];
47 runBuffer.pos[i] = x;
48 x += w;
49 }
50 return (SkScalar)x;
51 }
OLDNEW
« no previous file with comments | « tools/SkShaper_harfbuzz.cpp ('k') | tools/using_skia_and_harfbuzz.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698