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

Side by Side Diff: tests/TextBlobTest.cpp

Issue 2084533004: SkTextBlob: Begin implementing Extended TextBlob API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 3 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 | « src/core/SkTextBlobRunIterator.h ('k') | tools/SkShaper_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
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkPaint.h" 8 #include "SkPaint.h"
9 #include "SkPoint.h" 9 #include "SkPoint.h"
10 #include "SkTextBlobRunIterator.h" 10 #include "SkTextBlobRunIterator.h"
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 }; 342 };
343 343
344 DEF_TEST(TextBlob_builder, reporter) { 344 DEF_TEST(TextBlob_builder, reporter) {
345 TextBlobTester::TestBuilder(reporter); 345 TextBlobTester::TestBuilder(reporter);
346 TextBlobTester::TestBounds(reporter); 346 TextBlobTester::TestBounds(reporter);
347 } 347 }
348 348
349 DEF_TEST(TextBlob_paint, reporter) { 349 DEF_TEST(TextBlob_paint, reporter) {
350 TextBlobTester::TestPaintProps(reporter); 350 TextBlobTester::TestPaintProps(reporter);
351 } 351 }
352
353 DEF_TEST(TextBlob_extended, reporter) {
354 SkTextBlobBuilder textBlobBuilder;
355 SkPaint paint;
356 const char text1[] = "Foo";
357 const char text2[] = "Bar";
358
359 int glyphCount = paint.textToGlyphs(text1, strlen(text1), nullptr);
360 SkAutoTMalloc<uint16_t> glyphs(glyphCount);
361 (void)paint.textToGlyphs(text1, strlen(text1), glyphs.get());
362 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
363
364 auto run = textBlobBuilder.allocRunText(
365 paint, glyphCount, 0, 0, SkToInt(strlen(text2)), SkString(), nullptr );
366 memcpy(run.glyphs, glyphs.get(), sizeof(uint16_t) * glyphCount);
367 memcpy(run.utf8text, text2, strlen(text2));
368 for (int i = 0; i < glyphCount; ++i) {
369 run.clusters[i] = SkTMin(SkToU32(i), SkToU32(strlen(text2)));
370 }
371 sk_sp<const SkTextBlob> blob(textBlobBuilder.build());
372 REPORTER_ASSERT(reporter, blob);
373
374 for (SkTextBlobRunIterator it(blob.get()); !it.done(); it.next()) {
375 REPORTER_ASSERT(reporter, it.glyphCount() == (uint32_t)glyphCount);
376 for (uint32_t i = 0; i < it.glyphCount(); ++i) {
377 REPORTER_ASSERT(reporter, it.glyphs()[i] == glyphs[i]);
378 }
379 REPORTER_ASSERT(reporter, SkTextBlob::kDefault_Positioning == it.positio ning());
380 REPORTER_ASSERT(reporter, (SkPoint{0.0f, 0.0f}) == it.offset());
381 REPORTER_ASSERT(reporter, it.textSize() > 0);
382 REPORTER_ASSERT(reporter, it.clusters());
383 for (uint32_t i = 0; i < it.glyphCount(); ++i) {
384 REPORTER_ASSERT(reporter, i == it.clusters()[i]);
385 }
386 REPORTER_ASSERT(reporter, 0 == strncmp(text2, it.text(), it.textSize())) ;
387 }
388 }
OLDNEW
« no previous file with comments | « src/core/SkTextBlobRunIterator.h ('k') | tools/SkShaper_harfbuzz.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698