| 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/loc
al/google/home/bungeman/skia/font/Distortable.ttf")); |
| 50 SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromName("Skia", Sk
Typeface::kNormal)); |
| 51 paint.setTypeface(typeface); |
| 52 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
| 48 | 53 |
| 49 const char* text = "Hamburgefons ooo mmm"; | 54 const char* text = "abc"; |
| 50 const size_t textLen = strlen(text); | 55 const size_t textLen = strlen(text); |
| 51 | 56 |
| 52 for (int j = 0; j < 2; ++j) { | 57 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. | 58 // 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) { | 59 for (int i = 0; i < 5; ++i) { |
| 55 SkScalar x = SkIntToScalar(10); | 60 SkScalar x = SkIntToScalar(10); |
| 56 SkScalar y = SkIntToScalar(20); | 61 SkScalar y = SkIntToScalar(20); |
| 57 | 62 |
| 63 /* Added the following to /system/etc/fonts.xml |
| 64 |
| 65 <family name="mm"> |
| 66 <font weight="100" style="normal"><axis tag="wght" stylevalue="0.5"/>Dis
tortable.ttf</font> |
| 67 <font weight="200" style="normal"><axis tag="wght" stylevalue="0.7"/>Dis
tortable.ttf</font> |
| 68 <font weight="300" style="normal"><axis tag="wght" stylevalue="0.9"/>Dis
tortable.ttf</font> |
| 69 <font weight="400" style="normal"><axis tag="wght" stylevalue="1.0"/>Dis
tortable.ttf</font> |
| 70 <font weight="500" style="normal"><axis tag="wght" stylevalue="1.2"/>Dis
tortable.ttf</font> |
| 71 <font weight="600" style="normal"><axis tag="wght" stylevalue="1.4"/>Dis
tortable.ttf</font> |
| 72 <font weight="700" style="normal"><axis tag="wght" stylevalue="1.6"/>Dis
tortable.ttf</font> |
| 73 <font weight="800" style="normal"><axis tag="wght" stylevalue="1.8"/>Dis
tortable.ttf</font> |
| 74 <font weight="900" style="normal"><axis tag="wght" stylevalue="2.0"/>Dis
tortable.ttf</font> |
| 75 </family> |
| 76 |
| 77 and pushed resources/Distortable.ttf to /system/fonts */ |
| 78 //SkAutoTUnref<SkTypeface> typeface(fm->matchFamilyStyle("mm", S
kFontStyle((100 * i) + (500 * j), SkFontStyle::kNormal_Width, SkFontStyle::kUpri
ght_Slant))); |
| 79 //paint.setTypeface(typeface); |
| 80 |
| 58 SkAutoCanvasRestore acr(canvas, true); | 81 SkAutoCanvasRestore acr(canvas, true); |
| 59 canvas->translate(SkIntToScalar(50 + i * 230), | 82 canvas->translate(SkIntToScalar(50 + i * 230), |
| 60 SkIntToScalar(20)); | 83 SkIntToScalar(20)); |
| 61 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10); | 84 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10); |
| 62 | 85 |
| 63 { | 86 { |
| 64 SkPaint p; | 87 SkPaint p; |
| 65 p.setAntiAlias(true); | 88 p.setAntiAlias(true); |
| 66 SkRect r; | 89 SkRect r; |
| 67 r.set(x - SkIntToScalar(3), SkIntToScalar(15), | 90 r.set(x - SkIntToScalar(3), SkIntToScalar(15), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 83 private: | 106 private: |
| 84 typedef GM INHERITED; | 107 typedef GM INHERITED; |
| 85 }; | 108 }; |
| 86 | 109 |
| 87 ////////////////////////////////////////////////////////////////////////////// | 110 ////////////////////////////////////////////////////////////////////////////// |
| 88 | 111 |
| 89 static GM* MyFactory(void*) { return new FontScalerGM; } | 112 static GM* MyFactory(void*) { return new FontScalerGM; } |
| 90 static GMRegistry reg(MyFactory); | 113 static GMRegistry reg(MyFactory); |
| 91 | 114 |
| 92 } | 115 } |
| OLD | NEW |