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

Side by Side Diff: gm/fontmgr.cpp

Issue 666303002: add getBounds to SkTypeface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 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/core/SkLazyPtr.h » ('j') | include/core/SkTypeface.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "SkFontMgr.h" 10 #include "SkFontMgr.h"
11 #include "SkGraphics.h" 11 #include "SkGraphics.h"
12 #include "SkTypeface.h" 12 #include "SkTypeface.h"
13 13
14 #ifdef SK_BUILD_FOR_WIN 14 #ifdef SK_BUILD_FOR_WIN
15 #include "SkTypeface_win.h" 15 #include "SkTypeface_win.h"
16 #endif 16 #endif
17 17
18 static void scale(SkRect* rect, SkScalar scale) {
19 rect->fLeft *= scale;
20 rect->fTop *= scale;
21 rect->fRight *= scale;
22 rect->fBottom *= scale;
23 }
24
18 // limit this just so we don't take too long to draw 25 // limit this just so we don't take too long to draw
19 #define MAX_FAMILIES 30 26 #define MAX_FAMILIES 30
20 27
21 static SkScalar drawString(SkCanvas* canvas, const SkString& text, SkScalar x, 28 static SkScalar drawString(SkCanvas* canvas, const SkString& text, SkScalar x,
22 SkScalar y, const SkPaint& paint) { 29 SkScalar y, const SkPaint& paint) {
23 canvas->drawText(text.c_str(), text.size(), x, y, paint); 30 canvas->drawText(text.c_str(), text.size(), x, y, paint);
24 return x + paint.measureText(text.c_str(), text.size()); 31 return x + paint.measureText(text.c_str(), text.size());
25 } 32 }
26 33
27 static SkScalar drawCharacter(SkCanvas* canvas, uint32_t character, SkScalar x, 34 static SkScalar drawCharacter(SkCanvas* canvas, uint32_t character, SkScalar x,
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 virtual uint32_t onGetFlags() const SK_OVERRIDE { 220 virtual uint32_t onGetFlags() const SK_OVERRIDE {
214 // fontdescriptors (and therefore serialization) don't yet understand 221 // fontdescriptors (and therefore serialization) don't yet understand
215 // these new styles, so skip tests that exercise that for now. 222 // these new styles, so skip tests that exercise that for now.
216 return kSkipPicture_Flag | kSkipPipe_Flag; 223 return kSkipPicture_Flag | kSkipPipe_Flag;
217 } 224 }
218 225
219 private: 226 private:
220 typedef GM INHERITED; 227 typedef GM INHERITED;
221 }; 228 };
222 229
230 class FontMgrBoundsGM : public skiagm::GM {
231 public:
232 FontMgrBoundsGM() {
233 fName.set("fontmgr_bounds");
234 fFM.reset(SkFontMgr::RefDefault());
235 }
236
237 static void show_bounds(SkCanvas* canvas, const SkPaint& paint, SkScalar x, SkScalar y) {
238 const char str[] = "jyHO[]{}@-_&%$";
239
240 const SkTypeface* tf = paint.getTypeface();
241 for (int i = 0; str[i]; ++i) {
242 canvas->drawText(&str[i], 1, x, y, paint);
243 }
244
245 SkRect r = tf->getBounds();
246 scale(&r, paint.getTextSize());
247 r.offset(x, y);
248 SkPaint p(paint);
249 p.setColor(SK_ColorRED);
mtklein 2014/10/22 14:46:19 Might be nice to alternate red and another color s
reed1 2014/10/22 20:09:28 Done.
250 canvas->drawRect(r, p);
251 }
252
253 protected:
254 virtual SkString onShortName() {
255 return fName;
256 }
257
258 virtual SkISize onISize() {
259 return SkISize::Make(1024, 850);
260 }
261
262 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
263 SkPaint paint;
264 paint.setAntiAlias(true);
265 paint.setSubpixelText(true);
266 paint.setTextSize(100);
267 paint.setStyle(SkPaint::kStroke_Style);
268
269 SkFontMgr* fm = fFM;
270 int count = SkMin32(fm->countFamilies(), 32);
271
272 int index = 0;
273 SkScalar x = 0, y = 0;
274
275 canvas->translate(80, 120);
276
277 for (int i = 0; i < count; ++i) {
278 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i));
279 for (int j = 0; j < set->count(); ++j) {
280 SkSafeUnref(paint.setTypeface(set->createTypeface(j)));
281 if (paint.getTypeface()) {
282 show_bounds(canvas, paint, x, y);
283 index += 1;
284 x += 160;
285 if (0 == (index % 6)) {
286 x = 0;
287 y += 160;
288 }
289 if (index >= 30) {
290 return;
291 }
292 }
293 }
294 }
295 }
296
297 virtual uint32_t onGetFlags() const SK_OVERRIDE {
298 // fontdescriptors (and therefore serialization) don't yet understand
299 // these new styles, so skip tests that exercise that for now.
300
301 // If certain fonts are picked up (e.g. Microsoft Jhenghei 20MB for Regu lar, 12MB for Bold),
302 // the resulting pdf can be ~700MB and crashes Chrome's PDF viewer.
303
304 return kSkipPicture_Flag | kSkipPipe_Flag | kSkipPDF_Flag;
305 }
306
307 private:
308 SkAutoTUnref<SkFontMgr> fFM;
309 SkString fName;
310 typedef GM INHERITED;
311 };
312
223 ////////////////////////////////////////////////////////////////////////////// 313 //////////////////////////////////////////////////////////////////////////////
224 314
225 DEF_GM( return SkNEW(FontMgrGM); ) 315 DEF_GM( return SkNEW(FontMgrGM); )
316 DEF_GM( return SkNEW(FontMgrBoundsGM); )
226 DEF_GM( return SkNEW(FontMgrMatchGM); ) 317 DEF_GM( return SkNEW(FontMgrMatchGM); )
227 318
228 #ifdef SK_BUILD_FOR_WIN 319 #ifdef SK_BUILD_FOR_WIN
229 DEF_GM( return SkNEW_ARGS(FontMgrGM, (SkFontMgr_New_DirectWrite())); ) 320 DEF_GM( return SkNEW_ARGS(FontMgrGM, (SkFontMgr_New_DirectWrite())); )
230 #endif 321 #endif
OLDNEW
« no previous file with comments | « no previous file | include/core/SkLazyPtr.h » ('j') | include/core/SkTypeface.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698