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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/SkShaper_harfbuzz.cpp ('k') | tools/using_skia_and_harfbuzz.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/SkShaper_primitive.cpp
diff --git a/tools/SkShaper_primitive.cpp b/tools/SkShaper_primitive.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..65081b3447ac342e05a485282439f01353928e0c
--- /dev/null
+++ b/tools/SkShaper_primitive.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkShaper.h"
+#include "SkStream.h"
+#include "SkTextBlob.h"
+#include "SkTypeface.h"
+
+struct SkShaper::Impl {
+ sk_sp<SkTypeface> fTypeface;
+};
+
+SkShaper::SkShaper(sk_sp<SkTypeface> tf) : fImpl(new Impl) {
+ fImpl->fTypeface = tf ? std::move(tf) : SkTypeface::MakeDefault();
+}
+
+SkShaper::~SkShaper() {}
+
+bool SkShaper::good() const { return true; }
+
+SkScalar SkShaper::shape(SkTextBlobBuilder* builder,
+ const SkPaint& srcPaint,
+ const char* utf8text,
+ size_t textBytes,
+ SkPoint point) const {
+ SkPaint paint(srcPaint);
+ paint.setTypeface(fImpl->fTypeface);
+ paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
+ int glyphCount = paint.countText(utf8text, textBytes);
+ if (glyphCount <= 0) {
+ return 0;
+ }
+ SkRect bounds;
+ (void)paint.measureText(utf8text, textBytes, &bounds);
+ paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+ const SkTextBlobBuilder::RunBuffer& runBuffer = builder->allocRunPosH(
+ paint, glyphCount, point.y(), &bounds);
+ paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
+ (void)paint.textToGlyphs(utf8text, textBytes, runBuffer.glyphs);
+ (void)paint.getTextWidths(utf8text, textBytes, runBuffer.pos);
+ SkScalar x = point.x();
+ for (int i = 0; i < glyphCount; ++i) {
+ SkScalar w = runBuffer.pos[i];
+ runBuffer.pos[i] = x;
+ x += w;
+ }
+ return (SkScalar)x;
+}
« 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