OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #include "gm.h" | 7 #include "gm.h" |
8 #include "SkTypeface.h" | 8 #include "SkTypeface.h" |
| 9 #include <SkFontMgr.h> |
9 | 10 |
10 namespace skiagm { | 11 namespace skiagm { |
11 | 12 |
12 class FontScalerGM : public GM { | 13 class FontScalerGM : public GM { |
13 public: | 14 public: |
14 FontScalerGM() { | 15 FontScalerGM() { |
15 this->setBGColor(0xFFFFFFFF); | 16 this->setBGColor(0xFFFFFFFF); |
16 } | 17 } |
17 | 18 |
18 virtual ~FontScalerGM() { | 19 virtual ~FontScalerGM() { |
(...skipping 18 matching lines...) Expand all Loading... |
37 } | 38 } |
38 | 39 |
39 void onDraw(SkCanvas* canvas) override { | 40 void onDraw(SkCanvas* canvas) override { |
40 SkPaint paint; | 41 SkPaint paint; |
41 | 42 |
42 paint.setAntiAlias(true); | 43 paint.setAntiAlias(true); |
43 paint.setLCDRenderText(true); | 44 paint.setLCDRenderText(true); |
44 //With freetype the default (normal hinting) can be really ugly. | 45 //With freetype the default (normal hinting) can be really ugly. |
45 //Most distros now set slight (vertical hinting only) in any event. | 46 //Most distros now set slight (vertical hinting only) in any event. |
46 paint.setHinting(SkPaint::kSlight_Hinting); | 47 paint.setHinting(SkPaint::kSlight_Hinting); |
47 sk_tool_utils::set_portable_typeface(&paint, "Times Roman", SkTypeface::
kNormal); | 48 //sk_tool_utils::set_portable_typeface(&paint, "Times Roman", SkTypeface
::kNormal); |
| 49 SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromFile("/usr/local
/google/home/bungeman/skia/font/Distortable.ttf")); |
| 50 paint.setTypeface(typeface); |
| 51 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
48 | 52 |
49 const char* text = "Hamburgefons ooo mmm"; | 53 const char* text = "abc"; |
50 const size_t textLen = strlen(text); | 54 const size_t textLen = strlen(text); |
51 | 55 |
52 for (int j = 0; j < 2; ++j) { | 56 for (int j = 0; j < 2; ++j) { |
53 // This used to do 6 iterations but it causes the N4 to crash in the
MSAA4 config. | 57 // This used to do 6 iterations but it causes the N4 to crash in the
MSAA4 config. |
54 for (int i = 0; i < 5; ++i) { | 58 for (int i = 0; i < 5; ++i) { |
55 SkScalar x = SkIntToScalar(10); | 59 SkScalar x = SkIntToScalar(10); |
56 SkScalar y = SkIntToScalar(20); | 60 SkScalar y = SkIntToScalar(20); |
57 | 61 |
| 62 /* Added the following to /system/etc/fonts.xml |
| 63 |
| 64 <family name="mm"> |
| 65 <font weight="100" style="normal" axis="32768">Distortable.ttf</font> |
| 66 <font weight="200" style="normal" axis="40000">Distortable.ttf</font> |
| 67 <font weight="300" style="normal" axis="50000">Distortable.ttf</font> |
| 68 <font weight="400" style="normal" axis="65536">Distortable.ttf</font> |
| 69 <font weight="500" style="normal" axis="80000">Distortable.ttf</font> |
| 70 <font weight="600" style="normal" axis="90000">Distortable.ttf</font> |
| 71 <font weight="700" style="normal" axis="100000">Distortable.ttf</font> |
| 72 <font weight="800" style="normal" axis="110000">Distortable.ttf</font> |
| 73 <font weight="900" style="normal" axis="131072">Distortable.ttf</font> |
| 74 </family> |
| 75 |
| 76 and pushed resources/Distortable.ttf to /system/fonts */ |
| 77 //SkAutoTUnref<SkTypeface> typeface(fm->matchFamilyStyle("mm", S
kFontStyle((100 * i) + (500 * j), SkFontStyle::kNormal_Width, SkFontStyle::kUpri
ght_Slant))); |
| 78 //paint.setTypeface(typeface); |
| 79 |
58 SkAutoCanvasRestore acr(canvas, true); | 80 SkAutoCanvasRestore acr(canvas, true); |
59 canvas->translate(SkIntToScalar(50 + i * 230), | 81 canvas->translate(SkIntToScalar(50 + i * 230), |
60 SkIntToScalar(20)); | 82 SkIntToScalar(20)); |
61 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10); | 83 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10); |
62 | 84 |
63 { | 85 { |
64 SkPaint p; | 86 SkPaint p; |
65 p.setAntiAlias(true); | 87 p.setAntiAlias(true); |
66 SkRect r; | 88 SkRect r; |
67 r.set(x - SkIntToScalar(3), SkIntToScalar(15), | 89 r.set(x - SkIntToScalar(3), SkIntToScalar(15), |
(...skipping 15 matching lines...) Expand all Loading... |
83 private: | 105 private: |
84 typedef GM INHERITED; | 106 typedef GM INHERITED; |
85 }; | 107 }; |
86 | 108 |
87 ////////////////////////////////////////////////////////////////////////////// | 109 ////////////////////////////////////////////////////////////////////////////// |
88 | 110 |
89 static GM* MyFactory(void*) { return new FontScalerGM; } | 111 static GM* MyFactory(void*) { return new FontScalerGM; } |
90 static GMRegistry reg(MyFactory); | 112 static GMRegistry reg(MyFactory); |
91 | 113 |
92 } | 114 } |
OLD | NEW |