OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "gm.h" | 8 #include "gm.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkString.h" | 10 #include "SkString.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 { "serif", SkTypeface::kBoldItalic }, | 83 { "serif", SkTypeface::kBoldItalic }, |
84 { "monospace", SkTypeface::kNormal }, | 84 { "monospace", SkTypeface::kNormal }, |
85 { "monospace", SkTypeface::kBold }, | 85 { "monospace", SkTypeface::kBold }, |
86 { "monospace", SkTypeface::kItalic }, | 86 { "monospace", SkTypeface::kItalic }, |
87 { "monospace", SkTypeface::kBoldItalic }, | 87 { "monospace", SkTypeface::kBoldItalic }, |
88 }; | 88 }; |
89 | 89 |
90 static const int gFaceStylesCount = SK_ARRAY_COUNT(gFaceStyles); | 90 static const int gFaceStylesCount = SK_ARRAY_COUNT(gFaceStyles); |
91 | 91 |
92 class TypefaceStylesGM : public skiagm::GM { | 92 class TypefaceStylesGM : public skiagm::GM { |
93 sk_sp<SkTypeface> fFaces[gFaceStylesCount]; | 93 SkTypeface* fFaces[gFaceStylesCount]; |
94 bool fApplyKerning; | 94 bool fApplyKerning; |
95 | 95 |
96 public: | 96 public: |
97 TypefaceStylesGM(bool applyKerning) | 97 TypefaceStylesGM(bool applyKerning) |
98 : fApplyKerning(applyKerning) { | 98 : fApplyKerning(applyKerning) { |
99 memset(fFaces, 0, sizeof(fFaces)); | 99 memset(fFaces, 0, sizeof(fFaces)); |
100 } | 100 } |
101 | 101 |
| 102 virtual ~TypefaceStylesGM() { |
| 103 for (int i = 0; i < gFaceStylesCount; i++) { |
| 104 SkSafeUnref(fFaces[i]); |
| 105 } |
| 106 } |
| 107 |
102 protected: | 108 protected: |
103 void onOnceBeforeDraw() override { | 109 void onOnceBeforeDraw() override { |
104 for (int i = 0; i < gFaceStylesCount; i++) { | 110 for (int i = 0; i < gFaceStylesCount; i++) { |
105 fFaces[i] = SkTypeface::MakeFromName( | 111 fFaces[i] = SkTypeface::CreateFromName( |
106 sk_tool_utils::platform_font_name(gFaceStyles[i].fName), gFa
ceStyles[i].fStyle); | 112 sk_tool_utils::platform_font_name(gFaceStyles[i].fName), gFa
ceStyles[i].fStyle); |
107 } | 113 } |
108 } | 114 } |
109 | 115 |
110 SkString onShortName() override { | 116 SkString onShortName() override { |
111 SkString name("typefacestyles"); | 117 SkString name("typefacestyles"); |
112 if (fApplyKerning) { | 118 if (fApplyKerning) { |
113 name.append("_kerning"); | 119 name.append("_kerning"); |
114 } | 120 } |
115 name.append(sk_tool_utils::major_platform_os_name()); | 121 name.append(sk_tool_utils::major_platform_os_name()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 154 } |
149 | 155 |
150 private: | 156 private: |
151 typedef skiagm::GM INHERITED; | 157 typedef skiagm::GM INHERITED; |
152 }; | 158 }; |
153 | 159 |
154 /////////////////////////////////////////////////////////////////////////////// | 160 /////////////////////////////////////////////////////////////////////////////// |
155 | 161 |
156 DEF_GM( return new TypefaceStylesGM(false); ) | 162 DEF_GM( return new TypefaceStylesGM(false); ) |
157 DEF_GM( return new TypefaceStylesGM(true); ) | 163 DEF_GM( return new TypefaceStylesGM(true); ) |
OLD | NEW |