| OLD | NEW |
| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 97 } |
| 98 | 98 |
| 99 // This unit test verifies blob bounds computation. | 99 // This unit test verifies blob bounds computation. |
| 100 static void TestBounds(skiatest::Reporter* reporter) { | 100 static void TestBounds(skiatest::Reporter* reporter) { |
| 101 SkTextBlobBuilder builder; | 101 SkTextBlobBuilder builder; |
| 102 SkPaint font; | 102 SkPaint font; |
| 103 font.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 103 font.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 104 | 104 |
| 105 // Explicit bounds. | 105 // Explicit bounds. |
| 106 { | 106 { |
| 107 SkAutoTUnref<const SkTextBlob> blob(builder.build()); | 107 sk_sp<SkTextBlob> blob(builder.make()); |
| 108 REPORTER_ASSERT(reporter, blob->bounds().isEmpty()); | 108 REPORTER_ASSERT(reporter, blob->bounds().isEmpty()); |
| 109 } | 109 } |
| 110 | 110 |
| 111 { | 111 { |
| 112 SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20); | 112 SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20); |
| 113 builder.allocRun(font, 16, 0, 0, &r1); | 113 builder.allocRun(font, 16, 0, 0, &r1); |
| 114 SkAutoTUnref<const SkTextBlob> blob(builder.build()); | 114 sk_sp<SkTextBlob> blob(builder.make()); |
| 115 REPORTER_ASSERT(reporter, blob->bounds() == r1); | 115 REPORTER_ASSERT(reporter, blob->bounds() == r1); |
| 116 } | 116 } |
| 117 | 117 |
| 118 { | 118 { |
| 119 SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20); | 119 SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20); |
| 120 builder.allocRunPosH(font, 16, 0, &r1); | 120 builder.allocRunPosH(font, 16, 0, &r1); |
| 121 SkAutoTUnref<const SkTextBlob> blob(builder.build()); | 121 sk_sp<SkTextBlob> blob(builder.make()); |
| 122 REPORTER_ASSERT(reporter, blob->bounds() == r1); | 122 REPORTER_ASSERT(reporter, blob->bounds() == r1); |
| 123 } | 123 } |
| 124 | 124 |
| 125 { | 125 { |
| 126 SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20); | 126 SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20); |
| 127 builder.allocRunPos(font, 16, &r1); | 127 builder.allocRunPos(font, 16, &r1); |
| 128 SkAutoTUnref<const SkTextBlob> blob(builder.build()); | 128 sk_sp<SkTextBlob> blob(builder.make()); |
| 129 REPORTER_ASSERT(reporter, blob->bounds() == r1); | 129 REPORTER_ASSERT(reporter, blob->bounds() == r1); |
| 130 } | 130 } |
| 131 | 131 |
| 132 { | 132 { |
| 133 SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20); | 133 SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20); |
| 134 SkRect r2 = SkRect::MakeXYWH(15, 20, 50, 50); | 134 SkRect r2 = SkRect::MakeXYWH(15, 20, 50, 50); |
| 135 SkRect r3 = SkRect::MakeXYWH(0, 5, 10, 5); | 135 SkRect r3 = SkRect::MakeXYWH(0, 5, 10, 5); |
| 136 | 136 |
| 137 builder.allocRun(font, 16, 0, 0, &r1); | 137 builder.allocRun(font, 16, 0, 0, &r1); |
| 138 builder.allocRunPosH(font, 16, 0, &r2); | 138 builder.allocRunPosH(font, 16, 0, &r2); |
| 139 builder.allocRunPos(font, 16, &r3); | 139 builder.allocRunPos(font, 16, &r3); |
| 140 | 140 |
| 141 SkAutoTUnref<const SkTextBlob> blob(builder.build()); | 141 sk_sp<SkTextBlob> blob(builder.make()); |
| 142 REPORTER_ASSERT(reporter, blob->bounds() == SkRect::MakeXYWH(0, 5, 6
5, 65)); | 142 REPORTER_ASSERT(reporter, blob->bounds() == SkRect::MakeXYWH(0, 5, 6
5, 65)); |
| 143 } | 143 } |
| 144 | 144 |
| 145 { | 145 { |
| 146 // Verify empty blob bounds after building some non-empty blobs. | 146 // Verify empty blob bounds after building some non-empty blobs. |
| 147 SkAutoTUnref<const SkTextBlob> blob(builder.build()); | 147 sk_sp<SkTextBlob> blob(builder.make()); |
| 148 REPORTER_ASSERT(reporter, blob->bounds().isEmpty()); | 148 REPORTER_ASSERT(reporter, blob->bounds().isEmpty()); |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Implicit bounds | 151 // Implicit bounds |
| 152 | 152 |
| 153 { | 153 { |
| 154 // Exercise the empty bounds path, and ensure that RunRecord-aligned
pos buffers | 154 // Exercise the empty bounds path, and ensure that RunRecord-aligned
pos buffers |
| 155 // don't trigger asserts (http://crbug.com/542643). | 155 // don't trigger asserts (http://crbug.com/542643). |
| 156 SkPaint p; | 156 SkPaint p; |
| 157 p.setTextSize(0); | 157 p.setTextSize(0); |
| 158 p.setTextEncoding(SkPaint::kUTF8_TextEncoding); | 158 p.setTextEncoding(SkPaint::kUTF8_TextEncoding); |
| 159 | 159 |
| 160 const char* txt = "BOOO"; | 160 const char* txt = "BOOO"; |
| 161 const size_t txtLen = strlen(txt); | 161 const size_t txtLen = strlen(txt); |
| 162 const int glyphCount = p.textToGlyphs(txt, txtLen, nullptr); | 162 const int glyphCount = p.textToGlyphs(txt, txtLen, nullptr); |
| 163 | 163 |
| 164 p.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 164 p.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 165 const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(p,
glyphCount); | 165 const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(p,
glyphCount); |
| 166 | 166 |
| 167 p.setTextEncoding(SkPaint::kUTF8_TextEncoding); | 167 p.setTextEncoding(SkPaint::kUTF8_TextEncoding); |
| 168 p.textToGlyphs(txt, txtLen, buffer.glyphs); | 168 p.textToGlyphs(txt, txtLen, buffer.glyphs); |
| 169 | 169 |
| 170 memset(buffer.pos, 0, sizeof(SkScalar) * glyphCount * 2); | 170 memset(buffer.pos, 0, sizeof(SkScalar) * glyphCount * 2); |
| 171 SkAutoTUnref<const SkTextBlob> blob(builder.build()); | 171 sk_sp<SkTextBlob> blob(builder.make()); |
| 172 REPORTER_ASSERT(reporter, blob->bounds().isEmpty()); | 172 REPORTER_ASSERT(reporter, blob->bounds().isEmpty()); |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 | 175 |
| 176 // Verify that text-related properties are captured in run paints. | 176 // Verify that text-related properties are captured in run paints. |
| 177 static void TestPaintProps(skiatest::Reporter* reporter) { | 177 static void TestPaintProps(skiatest::Reporter* reporter) { |
| 178 SkPaint font; | 178 SkPaint font; |
| 179 font.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 179 font.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 180 | 180 |
| 181 // Kitchen sink font. | 181 // Kitchen sink font. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 REPORTER_ASSERT(reporter, defaultPaint.isEmbeddedBitmapText() != font.is
EmbeddedBitmapText()); | 217 REPORTER_ASSERT(reporter, defaultPaint.isEmbeddedBitmapText() != font.is
EmbeddedBitmapText()); |
| 218 REPORTER_ASSERT(reporter, defaultPaint.isAutohinted() != font.isAutohint
ed()); | 218 REPORTER_ASSERT(reporter, defaultPaint.isAutohinted() != font.isAutohint
ed()); |
| 219 REPORTER_ASSERT(reporter, defaultPaint.isVerticalText() != font.isVertic
alText()); | 219 REPORTER_ASSERT(reporter, defaultPaint.isVerticalText() != font.isVertic
alText()); |
| 220 REPORTER_ASSERT(reporter, (defaultPaint.getFlags() & SkPaint::kGenA8From
LCD_Flag) != | 220 REPORTER_ASSERT(reporter, (defaultPaint.getFlags() & SkPaint::kGenA8From
LCD_Flag) != |
| 221 (font.getFlags() & SkPaint::kGenA8FromLCD_Flag
)); | 221 (font.getFlags() & SkPaint::kGenA8FromLCD_Flag
)); |
| 222 | 222 |
| 223 SkTextBlobBuilder builder; | 223 SkTextBlobBuilder builder; |
| 224 AddRun(font, 1, SkTextBlob::kDefault_Positioning, SkPoint::Make(0, 0), b
uilder); | 224 AddRun(font, 1, SkTextBlob::kDefault_Positioning, SkPoint::Make(0, 0), b
uilder); |
| 225 AddRun(font, 1, SkTextBlob::kHorizontal_Positioning, SkPoint::Make(0, 0)
, builder); | 225 AddRun(font, 1, SkTextBlob::kHorizontal_Positioning, SkPoint::Make(0, 0)
, builder); |
| 226 AddRun(font, 1, SkTextBlob::kFull_Positioning, SkPoint::Make(0, 0), buil
der); | 226 AddRun(font, 1, SkTextBlob::kFull_Positioning, SkPoint::Make(0, 0), buil
der); |
| 227 SkAutoTUnref<const SkTextBlob> blob(builder.build()); | 227 sk_sp<SkTextBlob> blob(builder.make()); |
| 228 | 228 |
| 229 SkTextBlobRunIterator it(blob); | 229 SkTextBlobRunIterator it(blob.get()); |
| 230 while (!it.done()) { | 230 while (!it.done()) { |
| 231 SkPaint paint; | 231 SkPaint paint; |
| 232 it.applyFontToPaint(&paint); | 232 it.applyFontToPaint(&paint); |
| 233 | 233 |
| 234 REPORTER_ASSERT(reporter, paint.getTextSize() == font.getTextSize())
; | 234 REPORTER_ASSERT(reporter, paint.getTextSize() == font.getTextSize())
; |
| 235 REPORTER_ASSERT(reporter, paint.getTextScaleX() == font.getTextScale
X()); | 235 REPORTER_ASSERT(reporter, paint.getTextScaleX() == font.getTextScale
X()); |
| 236 REPORTER_ASSERT(reporter, paint.getTypeface() == font.getTypeface())
; | 236 REPORTER_ASSERT(reporter, paint.getTypeface() == font.getTypeface())
; |
| 237 REPORTER_ASSERT(reporter, paint.getTextSkewX() == font.getTextSkewX(
)); | 237 REPORTER_ASSERT(reporter, paint.getTextSkewX() == font.getTextSkewX(
)); |
| 238 REPORTER_ASSERT(reporter, paint.getTextAlign() == font.getTextAlign(
)); | 238 REPORTER_ASSERT(reporter, paint.getTextAlign() == font.getTextAlign(
)); |
| 239 REPORTER_ASSERT(reporter, paint.getHinting() == font.getHinting()); | 239 REPORTER_ASSERT(reporter, paint.getHinting() == font.getHinting()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 271 |
| 272 unsigned glyphCount = 0; | 272 unsigned glyphCount = 0; |
| 273 unsigned posCount = 0; | 273 unsigned posCount = 0; |
| 274 | 274 |
| 275 for (unsigned i = 0; i < inCount; ++i) { | 275 for (unsigned i = 0; i < inCount; ++i) { |
| 276 AddRun(font, in[i].count, in[i].pos, SkPoint::Make(in[i].x, in[i].y)
, builder); | 276 AddRun(font, in[i].count, in[i].pos, SkPoint::Make(in[i].x, in[i].y)
, builder); |
| 277 glyphCount += in[i].count; | 277 glyphCount += in[i].count; |
| 278 posCount += in[i].count * in[i].pos; | 278 posCount += in[i].count * in[i].pos; |
| 279 } | 279 } |
| 280 | 280 |
| 281 SkAutoTUnref<const SkTextBlob> blob(builder.build()); | 281 sk_sp<SkTextBlob> blob(builder.make()); |
| 282 | 282 |
| 283 SkTextBlobRunIterator it(blob); | 283 SkTextBlobRunIterator it(blob.get()); |
| 284 for (unsigned i = 0; i < outCount; ++i) { | 284 for (unsigned i = 0; i < outCount; ++i) { |
| 285 REPORTER_ASSERT(reporter, !it.done()); | 285 REPORTER_ASSERT(reporter, !it.done()); |
| 286 REPORTER_ASSERT(reporter, out[i].pos == it.positioning()); | 286 REPORTER_ASSERT(reporter, out[i].pos == it.positioning()); |
| 287 REPORTER_ASSERT(reporter, out[i].count == it.glyphCount()); | 287 REPORTER_ASSERT(reporter, out[i].count == it.glyphCount()); |
| 288 if (SkTextBlob::kDefault_Positioning == out[i].pos) { | 288 if (SkTextBlob::kDefault_Positioning == out[i].pos) { |
| 289 REPORTER_ASSERT(reporter, out[i].x == it.offset().x()); | 289 REPORTER_ASSERT(reporter, out[i].x == it.offset().x()); |
| 290 REPORTER_ASSERT(reporter, out[i].y == it.offset().y()); | 290 REPORTER_ASSERT(reporter, out[i].y == it.offset().y()); |
| 291 } else if (SkTextBlob::kHorizontal_Positioning == out[i].pos) { | 291 } else if (SkTextBlob::kHorizontal_Positioning == out[i].pos) { |
| 292 REPORTER_ASSERT(reporter, out[i].y == it.offset().y()); | 292 REPORTER_ASSERT(reporter, out[i].y == it.offset().y()); |
| 293 } | 293 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 (void)paint.textToGlyphs(text1, strlen(text1), glyphs.get()); | 361 (void)paint.textToGlyphs(text1, strlen(text1), glyphs.get()); |
| 362 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 362 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 363 | 363 |
| 364 auto run = textBlobBuilder.allocRunText( | 364 auto run = textBlobBuilder.allocRunText( |
| 365 paint, glyphCount, 0, 0, SkToInt(strlen(text2)), SkString(), nullptr
); | 365 paint, glyphCount, 0, 0, SkToInt(strlen(text2)), SkString(), nullptr
); |
| 366 memcpy(run.glyphs, glyphs.get(), sizeof(uint16_t) * glyphCount); | 366 memcpy(run.glyphs, glyphs.get(), sizeof(uint16_t) * glyphCount); |
| 367 memcpy(run.utf8text, text2, strlen(text2)); | 367 memcpy(run.utf8text, text2, strlen(text2)); |
| 368 for (int i = 0; i < glyphCount; ++i) { | 368 for (int i = 0; i < glyphCount; ++i) { |
| 369 run.clusters[i] = SkTMin(SkToU32(i), SkToU32(strlen(text2))); | 369 run.clusters[i] = SkTMin(SkToU32(i), SkToU32(strlen(text2))); |
| 370 } | 370 } |
| 371 sk_sp<const SkTextBlob> blob(textBlobBuilder.build()); | 371 sk_sp<SkTextBlob> blob(textBlobBuilder.make()); |
| 372 REPORTER_ASSERT(reporter, blob); | 372 REPORTER_ASSERT(reporter, blob); |
| 373 | 373 |
| 374 for (SkTextBlobRunIterator it(blob.get()); !it.done(); it.next()) { | 374 for (SkTextBlobRunIterator it(blob.get()); !it.done(); it.next()) { |
| 375 REPORTER_ASSERT(reporter, it.glyphCount() == (uint32_t)glyphCount); | 375 REPORTER_ASSERT(reporter, it.glyphCount() == (uint32_t)glyphCount); |
| 376 for (uint32_t i = 0; i < it.glyphCount(); ++i) { | 376 for (uint32_t i = 0; i < it.glyphCount(); ++i) { |
| 377 REPORTER_ASSERT(reporter, it.glyphs()[i] == glyphs[i]); | 377 REPORTER_ASSERT(reporter, it.glyphs()[i] == glyphs[i]); |
| 378 } | 378 } |
| 379 REPORTER_ASSERT(reporter, SkTextBlob::kDefault_Positioning == it.positio
ning()); | 379 REPORTER_ASSERT(reporter, SkTextBlob::kDefault_Positioning == it.positio
ning()); |
| 380 REPORTER_ASSERT(reporter, (SkPoint{0.0f, 0.0f}) == it.offset()); | 380 REPORTER_ASSERT(reporter, (SkPoint{0.0f, 0.0f}) == it.offset()); |
| 381 REPORTER_ASSERT(reporter, it.textSize() > 0); | 381 REPORTER_ASSERT(reporter, it.textSize() > 0); |
| 382 REPORTER_ASSERT(reporter, it.clusters()); | 382 REPORTER_ASSERT(reporter, it.clusters()); |
| 383 for (uint32_t i = 0; i < it.glyphCount(); ++i) { | 383 for (uint32_t i = 0; i < it.glyphCount(); ++i) { |
| 384 REPORTER_ASSERT(reporter, i == it.clusters()[i]); | 384 REPORTER_ASSERT(reporter, i == it.clusters()[i]); |
| 385 } | 385 } |
| 386 REPORTER_ASSERT(reporter, 0 == strncmp(text2, it.text(), it.textSize()))
; | 386 REPORTER_ASSERT(reporter, 0 == strncmp(text2, it.text(), it.textSize()))
; |
| 387 } | 387 } |
| 388 } | 388 } |
| OLD | NEW |