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

Side by Side Diff: gm/fontscalerdistortable.cpp

Issue 1590223003: Expose API for gx font variation axes. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix FontConfig and Android. Created 4 years, 11 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 | include/ports/SkFontMgr.h » ('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 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 #include "gm.h" 7 #include "gm.h"
8 #include "Resources.h" 8 #include "Resources.h"
9 #include "SkFixed.h" 9 #include "SkFixed.h"
10 #include "SkFontDescriptor.h" 10 #include "SkFontDescriptor.h"
(...skipping 23 matching lines...) Expand all
34 static void rotate_about(SkCanvas* canvas, SkScalar degrees, SkScalar px, Sk Scalar py) { 34 static void rotate_about(SkCanvas* canvas, SkScalar degrees, SkScalar px, Sk Scalar py) {
35 canvas->translate(px, py); 35 canvas->translate(px, py);
36 canvas->rotate(degrees); 36 canvas->rotate(degrees);
37 canvas->translate(-px, -py); 37 canvas->translate(-px, -py);
38 } 38 }
39 39
40 void onDraw(SkCanvas* canvas) override { 40 void onDraw(SkCanvas* canvas) override {
41 SkPaint paint; 41 SkPaint paint;
42 paint.setAntiAlias(true); 42 paint.setAntiAlias(true);
43 paint.setLCDRenderText(true); 43 paint.setLCDRenderText(true);
44 SkAutoTUnref<SkFontMgr> fontMgr(SkFontMgr::RefDefault());
44 45
45 SkAutoTDelete<SkStreamAsset> distortable(GetResourceAsStream("/fonts/Dis tortable.ttf")); 46 SkAutoTDelete<SkStreamAsset> distortable(GetResourceAsStream("/fonts/Dis tortable.ttf"));
46 if (!distortable) { 47 if (!distortable) {
47 return; 48 return;
48 } 49 }
49 const char* text = "abc"; 50 const char* text = "abc";
50 const size_t textLen = strlen(text); 51 const size_t textLen = strlen(text);
51 52
52 for (int j = 0; j < 2; ++j) { 53 for (int j = 0; j < 2; ++j) {
53 for (int i = 0; i < 5; ++i) { 54 for (int i = 0; i < 5; ++i) {
54 SkScalar x = SkIntToScalar(10); 55 SkScalar x = SkIntToScalar(10);
55 SkScalar y = SkIntToScalar(20); 56 SkScalar y = SkIntToScalar(20);
56 57
57 SkFixed axis = SkDoubleToFixed(0.5 + (5*j + i) * ((2.0 - 0.5) / (2 * 5))); 58 SkFourByteTag tag = SkSetFourByteTag('w','g','h','t');
58 SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromFontData ( 59 SkScalar styleValue = SkDoubleToScalar(0.5 + (5*j + i) * ((2.0 - 0.5) / (2 * 5)));
59 new SkFontData(distortable->duplicate(), 0, &axis, 1))); 60 SkFontMgr::FontParameters::Axis axes[] = { { tag, styleValue } } ;
61 SkAutoTUnref<SkTypeface> typeface(fontMgr->createFromStream(
62 distortable->duplicate(), SkFontMgr::FontParameters().setAxe s(axes, 1)));
60 paint.setTypeface(typeface); 63 paint.setTypeface(typeface);
61 64
62 SkAutoCanvasRestore acr(canvas, true); 65 SkAutoCanvasRestore acr(canvas, true);
63 canvas->translate(SkIntToScalar(30 + i * 100), SkIntToScalar(20) ); 66 canvas->translate(SkIntToScalar(30 + i * 100), SkIntToScalar(20) );
64 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10); 67 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10);
65 68
66 { 69 {
67 SkPaint p; 70 SkPaint p;
68 p.setAntiAlias(true); 71 p.setAntiAlias(true);
69 SkRect r; 72 SkRect r;
(...skipping 16 matching lines...) Expand all
86 private: 89 private:
87 typedef GM INHERITED; 90 typedef GM INHERITED;
88 }; 91 };
89 92
90 ////////////////////////////////////////////////////////////////////////////// 93 //////////////////////////////////////////////////////////////////////////////
91 94
92 static GM* MyFactory(void*) { return new FontScalerDistortableGM; } 95 static GM* MyFactory(void*) { return new FontScalerDistortableGM; }
93 static GMRegistry reg(MyFactory); 96 static GMRegistry reg(MyFactory);
94 97
95 } 98 }
OLDNEW
« no previous file with comments | « no previous file | include/ports/SkFontMgr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698