| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "Resources.h" | 8 #include "Resources.h" |
| 9 #include "SkTypeface.h" | 9 #include "SkTypeface.h" |
| 10 #include "gm.h" | 10 #include "gm.h" |
| 11 | 11 |
| 12 static void excercise_draw_pos_text(SkCanvas* canvas, | 12 static void excercise_draw_pos_text(SkCanvas* canvas, |
| 13 const char* text, | 13 const char* text, |
| 14 SkScalar x, SkScalar y, | 14 SkScalar x, SkScalar y, |
| 15 const SkPaint& paint) { | 15 const SkPaint& paint) { |
| 16 size_t textLen = strlen(text); | 16 size_t textLen = strlen(text); |
| 17 SkAutoTArray<SkScalar> widths(SkToInt(textLen)); | 17 SkAutoTArray<SkScalar> widths(SkToInt(textLen)); |
| 18 paint.getTextWidths(text, textLen, &widths[0]); | 18 paint.getTextWidths(text, textLen, &widths[0]); |
| 19 SkAutoTArray<SkPoint> pos(SkToInt(textLen)); | 19 SkAutoTArray<SkPoint> pos(SkToInt(textLen)); |
| 20 for (int i = 0; i < SkToInt(textLen); ++i) { | 20 for (int i = 0; i < SkToInt(textLen); ++i) { |
| 21 pos[i].set(x, y); | 21 pos[i].set(x, y); |
| 22 x += widths[i]; | 22 x += widths[i]; |
| 23 } | 23 } |
| 24 canvas->drawPosText(text, textLen, &pos[0], paint); | 24 canvas->drawPosText(text, textLen, &pos[0], paint); |
| 25 } | 25 } |
| 26 | 26 |
| 27 DEF_SIMPLE_GM(pdf_never_embed, canvas, 512, 512) { | 27 DEF_SIMPLE_GM(pdf_never_embed, canvas, 512, 512) { |
| 28 const char resource[] = "fonts/Roboto2-Regular_NoEmbed.ttf"; | 28 SkPaint p; |
| 29 SkAutoTUnref<SkTypeface> typeface(GetResourceAsTypeface(resource)); | 29 p.setTextSize(60); |
| 30 if (!typeface) { | 30 p.setTypeface(MakeResourceAsTypeface("fonts/Roboto2-Regular_NoEmbed.ttf")); |
| 31 p.setAntiAlias(true); |
| 32 |
| 33 if (!p.getTypeface()) { |
| 31 return; | 34 return; |
| 32 } | 35 } |
| 33 SkPaint p; | |
| 34 p.setTextSize(60); | |
| 35 p.setTypeface(typeface); | |
| 36 p.setAntiAlias(true); | |
| 37 | 36 |
| 38 const char text[] = "HELLO, WORLD!"; | 37 const char text[] = "HELLO, WORLD!"; |
| 39 | 38 |
| 40 canvas->drawColor(SK_ColorWHITE); | 39 canvas->drawColor(SK_ColorWHITE); |
| 41 excercise_draw_pos_text(canvas, text, 30, 90, p); | 40 excercise_draw_pos_text(canvas, text, 30, 90, p); |
| 42 | 41 |
| 43 canvas->save(); | 42 canvas->save(); |
| 44 canvas->rotate(45.0f); | 43 canvas->rotate(45.0f); |
| 45 p.setColor(0xF0800000); | 44 p.setColor(0xF0800000); |
| 46 excercise_draw_pos_text(canvas, text, 30, 45, p); | 45 excercise_draw_pos_text(canvas, text, 30, 45, p); |
| 47 canvas->restore(); | 46 canvas->restore(); |
| 48 | 47 |
| 49 canvas->save(); | 48 canvas->save(); |
| 50 canvas->scale(1, 4.0); | 49 canvas->scale(1, 4.0); |
| 51 p.setColor(0xF0008000); | 50 p.setColor(0xF0008000); |
| 52 excercise_draw_pos_text(canvas, text, 15, 70, p); | 51 excercise_draw_pos_text(canvas, text, 15, 70, p); |
| 53 canvas->restore(); | 52 canvas->restore(); |
| 54 | 53 |
| 55 canvas->scale(1.0, 0.5); | 54 canvas->scale(1.0, 0.5); |
| 56 p.setColor(0xF0000080); | 55 p.setColor(0xF0000080); |
| 57 canvas->drawText(text, strlen(text), 30, 700, p); | 56 canvas->drawText(text, strlen(text), 30, 700, p); |
| 58 } | 57 } |
| OLD | NEW |