Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: gm/fontscalerdistortable.cpp

Issue 1027373002: Font variations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gyp/freetype.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 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 #include "gm.h" 7 #include "gm.h"
8 #include "Resources.h"
9 #include "SkFixed.h"
10 #include "SkFontDescriptor.h"
11 #include "SkFontMgr.h"
8 #include "SkTypeface.h" 12 #include "SkTypeface.h"
9 13
10 namespace skiagm { 14 namespace skiagm {
11 15
12 class FontScalerGM : public GM { 16 class FontScalerDistortableGM : public GM {
13 public: 17 public:
14 FontScalerGM() { 18 FontScalerDistortableGM() {
15 this->setBGColor(0xFFFFFFFF); 19 this->setBGColor(0xFFFFFFFF);
16 } 20 }
17 21
18 virtual ~FontScalerGM() { 22 virtual ~FontScalerDistortableGM() { }
19 }
20 23
21 protected: 24 protected:
22 25
23 SkString onShortName() override { 26 SkString onShortName() override {
24 return SkString("fontscaler"); 27 return SkString("fontscalerdistortable");
25 } 28 }
26 29
27 SkISize onISize() override { 30 SkISize onISize() override {
28 return SkISize::Make(1450, 750); 31 return SkISize::Make(550, 700);
29 } 32 }
30 33
31 static void rotate_about(SkCanvas* canvas, 34 static void rotate_about(SkCanvas* canvas, SkScalar degrees, SkScalar px, Sk Scalar py) {
32 SkScalar degrees,
33 SkScalar px, SkScalar py) {
34 canvas->translate(px, py); 35 canvas->translate(px, py);
35 canvas->rotate(degrees); 36 canvas->rotate(degrees);
36 canvas->translate(-px, -py); 37 canvas->translate(-px, -py);
37 } 38 }
38 39
39 void onDraw(SkCanvas* canvas) override { 40 void onDraw(SkCanvas* canvas) override {
40 SkPaint paint; 41 SkPaint paint;
41
42 paint.setAntiAlias(true); 42 paint.setAntiAlias(true);
43 paint.setLCDRenderText(true); 43 paint.setLCDRenderText(true);
44 //With freetype the default (normal hinting) can be really ugly.
45 //Most distros now set slight (vertical hinting only) in any event.
46 paint.setHinting(SkPaint::kSlight_Hinting);
47 sk_tool_utils::set_portable_typeface(&paint, "Times Roman", SkTypeface:: kNormal);
48 44
49 const char* text = "Hamburgefons ooo mmm"; 45 SkAutoTDelete<SkStreamAsset> distortable(GetResourceAsStream("/fonts/Dis tortable.ttf"));
46 if (!distortable) {
47 return;
48 }
49 const char* text = "abc";
50 const size_t textLen = strlen(text); 50 const size_t textLen = strlen(text);
51 51
52 for (int j = 0; j < 2; ++j) { 52 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.
54 for (int i = 0; i < 5; ++i) { 53 for (int i = 0; i < 5; ++i) {
55 SkScalar x = SkIntToScalar(10); 54 SkScalar x = SkIntToScalar(10);
56 SkScalar y = SkIntToScalar(20); 55 SkScalar y = SkIntToScalar(20);
57 56
57 SkFixed axis = SkDoubleToFixed(0.5 + (5*j + i) * ((2.0 - 0.5) / (2 * 5)));
58 SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromFontData (
59 new SkFontData(distortable->duplicate(), 0, &axis, 1)));
60 paint.setTypeface(typeface);
61
58 SkAutoCanvasRestore acr(canvas, true); 62 SkAutoCanvasRestore acr(canvas, true);
59 canvas->translate(SkIntToScalar(50 + i * 230), 63 canvas->translate(SkIntToScalar(30 + i * 100), SkIntToScalar(20) );
60 SkIntToScalar(20));
61 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10); 64 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10);
62 65
63 { 66 {
64 SkPaint p; 67 SkPaint p;
65 p.setAntiAlias(true); 68 p.setAntiAlias(true);
66 SkRect r; 69 SkRect r;
67 r.set(x - SkIntToScalar(3), SkIntToScalar(15), 70 r.set(x - SkIntToScalar(3), SkIntToScalar(15),
68 x - SkIntToScalar(1), SkIntToScalar(280)); 71 x - SkIntToScalar(1), SkIntToScalar(280));
69 canvas->drawRect(r, p); 72 canvas->drawRect(r, p);
70 } 73 }
71 74
72 for (int ps = 6; ps <= 22; ps++) { 75 for (int ps = 6; ps <= 22; ps++) {
73 paint.setTextSize(SkIntToScalar(ps)); 76 paint.setTextSize(SkIntToScalar(ps));
74 canvas->drawText(text, textLen, x, y, paint); 77 canvas->drawText(text, textLen, x, y, paint);
75 y += paint.getFontMetrics(NULL); 78 y += paint.getFontMetrics(NULL);
76 } 79 }
77 } 80 }
78 canvas->translate(0, SkIntToScalar(360)); 81 canvas->translate(0, SkIntToScalar(360));
79 paint.setSubpixelText(true); 82 paint.setSubpixelText(true);
80 } 83 }
81 } 84 }
82 85
83 private: 86 private:
84 typedef GM INHERITED; 87 typedef GM INHERITED;
85 }; 88 };
86 89
87 ////////////////////////////////////////////////////////////////////////////// 90 //////////////////////////////////////////////////////////////////////////////
88 91
89 static GM* MyFactory(void*) { return new FontScalerGM; } 92 static GM* MyFactory(void*) { return new FontScalerDistortableGM; }
90 static GMRegistry reg(MyFactory); 93 static GMRegistry reg(MyFactory);
91 94
92 } 95 }
OLDNEW
« no previous file with comments | « no previous file | gyp/freetype.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698