use font for measuring
Bug: skia:
Change-Id: I451c61d5b98cb42440a4eaa889d9404638a72f5c
Reviewed-on: https://skia-review.googlesource.com/c/179980
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/samplecode/SampleChineseFling.cpp b/samplecode/SampleChineseFling.cpp
index b8110f3..3b73bb2 100644
--- a/samplecode/SampleChineseFling.cpp
+++ b/samplecode/SampleChineseFling.cpp
@@ -20,16 +20,6 @@
#include "GrContextPriv.h"
#endif
-static void make_paint(SkPaint* paint, sk_sp<SkTypeface> typeface) {
- static const int kTextSize = 56;
-
- paint->setAntiAlias(true);
- paint->setColor(0xDE000000);
- paint->setTypeface(typeface);
- paint->setTextSize(kTextSize);
- paint->setTextEncoding(kUTF32_SkTextEncoding);
-}
-
static sk_sp<SkTypeface> chinese_typeface() {
#ifdef SK_BUILD_FOR_ANDROID
return MakeResourceAsTypeface("fonts/NotoSansCJK-Regular.ttc");
@@ -68,7 +58,7 @@
canvas->clear(0xFFDDDDDD);
SkPaint paint;
- make_paint(&paint, fTypeface);
+ paint.setColor(0xDE000000);
// draw a consistent run of the 'words' - one word per line
int index = fIndex;
@@ -93,10 +83,8 @@
void init() {
fTypeface = chinese_typeface();
- SkPaint paint;
- make_paint(&paint, fTypeface);
-
- paint.getFontMetrics(&fMetrics);
+ SkFont font(fTypeface, 56);
+ font.getMetrics(&fMetrics);
SkUnichar glyphs[kWordLength];
for (int32_t i = 0; i < kNumBlobs; ++i) {
@@ -104,7 +92,7 @@
SkTextBlobBuilder builder;
sk_tool_utils::add_to_text_blob_w_len(&builder, (const char*) glyphs, kWordLength*4,
- paint, 0, 0);
+ kUTF32_SkTextEncoding, font, 0, 0);
fBlobs.emplace_back(builder.make());
}
@@ -215,14 +203,11 @@
void init() {
fTypeface = chinese_typeface();
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setColor(0xDE000000);
- paint.setTypeface(fTypeface);
- paint.setTextSize(11);
- paint.setTextEncoding(kUTF32_SkTextEncoding);
+ SkFont font(fTypeface, 11);
+ font.getMetrics(&fMetrics);
- paint.getFontMetrics(&fMetrics);
+ SkPaint paint;
+ paint.setColor(0xDE000000);
SkUnichar glyphs[45];
for (int32_t i = 0; i < kNumBlobs; ++i) {
@@ -234,7 +219,8 @@
this->createRandomLine(glyphs, currentLineLength);
sk_tool_utils::add_to_text_blob_w_len(&builder, (const char*) glyphs,
- currentLineLength*4, paint, 0, y);
+ currentLineLength*4, kUTF32_SkTextEncoding,
+ font, 0, y);
y += fMetrics.fDescent - fMetrics.fAscent + fMetrics.fLeading;
paragraphLength -= 45;
}