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

Unified Diff: tests/ExtendedTextBlob.cpp

Issue 2084533004: SkTextBlob: Begin implementing Extended TextBlob API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-06-24 (Friday) 17:22:15 EDT Created 4 years, 6 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
Index: tests/ExtendedTextBlob.cpp
diff --git a/tests/ExtendedTextBlob.cpp b/tests/ExtendedTextBlob.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5f975a7b9ede9332d4a0d315f61ce28b54ee1403
--- /dev/null
+++ b/tests/ExtendedTextBlob.cpp
@@ -0,0 +1,48 @@
+/*
+ * 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 "Test.h"
+#include "SkTextBlob.h"
+
+#include "SkTextBlobRunIterator.h"
+
+DEF_TEST(ExtendedTextBlob, reporter) {
f(malita) 2016/06/27 20:21:56 This could be added to TextBlobTest.cpp instead of
hal.canary 2016/06/28 15:39:13 Done.
+ SkTextBlobBuilder textBlobBuilder;
+ SkPaint paint;
+ const char text1[] = "Foo";
+ const char text2[] = "Bar";
+
+ int glyphCount = paint.textToGlyphs(text1, strlen(text1), nullptr);
+ SkAutoTMalloc<uint16_t> glyphs(glyphCount);
+ (void)paint.textToGlyphs(text1, strlen(text1), glyphs.get());
+ paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+
+ auto run = textBlobBuilder.allocRunText(
+ paint, glyphCount, 0, 0, strlen(text2), SkString(), nullptr);
+ memcpy(run.glyphs, glyphs.get(), sizeof(uint16_t) * glyphCount);
+ memcpy(run.utf8text, text2, strlen(text2));
+ for (int i = 0; i < glyphCount; ++i) {
+ run.clusters[i] = SkTMin<uint32_t>(i, strlen(text2));
+ }
+ sk_sp<const SkTextBlob> blob(textBlobBuilder.build());
+ REPORTER_ASSERT(reporter, blob);
+
+ for (SkTextBlobRunIterator it(blob.get()); !it.done(); it.next()) {
+ REPORTER_ASSERT(reporter, it.glyphCount() == (uint32_t)glyphCount);
+ for (uint32_t i = 0; i < it.glyphCount(); ++i) {
+ REPORTER_ASSERT(reporter, it.glyphs()[i] == glyphs[i]);
+ }
+ REPORTER_ASSERT(reporter, SkTextBlob::kDefault_Positioning == it.positioning());
+ REPORTER_ASSERT(reporter, (SkPoint{0.0f, 0.0f}) == it.offset());
+ REPORTER_ASSERT(reporter, it.isExtended());
+ REPORTER_ASSERT(reporter, it.clusterBuffer());
+ for (uint32_t i = 0; i < it.glyphCount(); ++i) {
+ REPORTER_ASSERT(reporter, i == it.clusterBuffer()[i]);
+ }
+ REPORTER_ASSERT(reporter, 0 == strncmp(text2, it.textBuffer(), it.textSize()));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698