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

Unified Diff: tools/SkShaper.cpp

Issue 2201153002: SkShaper: optionally disable harfbuzz (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-08-02 (Tuesday) 17:13:48 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.h ('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.cpp
diff --git a/tools/SkShaper.cpp b/tools/SkShaper.cpp
index 44dd8fc7f1bbf0e72c47ffd2c469885ca045d144..93778762c1298e199858788b549dd603cc52adc2 100644
--- a/tools/SkShaper.cpp
+++ b/tools/SkShaper.cpp
@@ -4,14 +4,15 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
-#include <hb-ot.h>
-
#include "SkShaper.h"
#include "SkStream.h"
#include "SkTextBlob.h"
#include "SkTypeface.h"
+#ifdef SK_ENABLE_HARFBUZZ
bungeman-skia 2016/08/02 21:38:36 I know it's a bit more work, but these two impleme
hal.canary 2016/08/02 23:00:45 Done.
+
+#include <hb-ot.h>
+
static const int FONT_SIZE_SCALE = 512;
namespace {
@@ -116,11 +117,56 @@ SkScalar SkShaper::shape(SkTextBlobBuilder* builder,
for (unsigned i = 0; i < len; i++) {
runBuffer.glyphs[i] = info[i].codepoint;
reinterpret_cast<SkPoint*>(runBuffer.pos)[i] =
- SkPoint::Make(x + pos[i].x_offset * textSizeX,
- y - pos[i].y_offset * textSizeY);
+ SkPoint::Make(SkDoubleToScalar(x + pos[i].x_offset * textSizeX),
+ SkDoubleToScalar(y - pos[i].y_offset * textSizeY));
x += pos[i].x_advance * textSizeX;
y += pos[i].y_advance * textSizeY;
}
hb_buffer_clear_contents(buffer);
return (SkScalar)x;
}
+
+#else // !SK_ENABLE_HARFBUZZ
+
+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;
+}
+
+#endif // !SK_ENABLE_HARFBUZZ
« no previous file with comments | « tools/SkShaper.h ('k') | tools/using_skia_and_harfbuzz.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698