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

Unified Diff: gm/fontmgr.cpp

Issue 676523002: Add SkTypeface::getBounds() (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | include/core/SkLazyPtr.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/fontmgr.cpp
diff --git a/gm/fontmgr.cpp b/gm/fontmgr.cpp
index 79868982f4a25854a5d7b4bee1aa498b3188438d..a1e7ff2a6861cf27b608d4aa687548c51350cd05 100644
--- a/gm/fontmgr.cpp
+++ b/gm/fontmgr.cpp
@@ -15,6 +15,13 @@
#include "SkTypeface_win.h"
#endif
+static void scale(SkRect* rect, SkScalar scale) {
+ rect->fLeft *= scale;
+ rect->fTop *= scale;
+ rect->fRight *= scale;
+ rect->fBottom *= scale;
+}
+
// limit this just so we don't take too long to draw
#define MAX_FAMILIES 30
@@ -220,9 +227,96 @@ private:
typedef GM INHERITED;
};
+class FontMgrBoundsGM : public skiagm::GM {
+public:
+ FontMgrBoundsGM() {
+ fName.set("fontmgr_bounds");
+ fFM.reset(SkFontMgr::RefDefault());
+ }
+
+ static void show_bounds(SkCanvas* canvas, const SkPaint& paint, SkScalar x, SkScalar y,
+ SkColor boundsColor) {
+ const char str[] = "jyHO[]{}@-_&%$";
+
+ const SkTypeface* tf = paint.getTypeface();
+ for (int i = 0; str[i]; ++i) {
+ canvas->drawText(&str[i], 1, x, y, paint);
+ }
+
+ SkRect r = tf->getBounds();
+ scale(&r, paint.getTextSize());
+ r.offset(x, y);
+ SkPaint p(paint);
+ p.setColor(boundsColor);
+ canvas->drawRect(r, p);
+ }
+
+protected:
+ virtual SkString onShortName() {
+ return fName;
+ }
+
+ virtual SkISize onISize() {
+ return SkISize::Make(1024, 850);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setSubpixelText(true);
+ paint.setTextSize(100);
+ paint.setStyle(SkPaint::kStroke_Style);
+
+ const SkColor boundsColors[2] = { SK_ColorRED, SK_ColorBLUE };
+
+ SkFontMgr* fm = fFM;
+ int count = SkMin32(fm->countFamilies(), 32);
+
+ int index = 0;
+ SkScalar x = 0, y = 0;
+
+ canvas->translate(80, 120);
+
+ for (int i = 0; i < count; ++i) {
+ SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i));
+ for (int j = 0; j < set->count(); ++j) {
+ SkSafeUnref(paint.setTypeface(set->createTypeface(j)));
+ if (paint.getTypeface()) {
+ show_bounds(canvas, paint, x, y, boundsColors[index & 1]);
+ index += 1;
+ x += 160;
+ if (0 == (index % 6)) {
+ x = 0;
+ y += 160;
+ }
+ if (index >= 30) {
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ virtual uint32_t onGetFlags() const SK_OVERRIDE {
+ // fontdescriptors (and therefore serialization) don't yet understand
+ // these new styles, so skip tests that exercise that for now.
+
+ // If certain fonts are picked up (e.g. Microsoft Jhenghei 20MB for Regular, 12MB for Bold),
+ // the resulting pdf can be ~700MB and crashes Chrome's PDF viewer.
+
+ return kSkipPicture_Flag | kSkipPipe_Flag | kSkipPDF_Flag;
+ }
+
+private:
+ SkAutoTUnref<SkFontMgr> fFM;
+ SkString fName;
+ typedef GM INHERITED;
+};
+
//////////////////////////////////////////////////////////////////////////////
DEF_GM( return SkNEW(FontMgrGM); )
+DEF_GM( return SkNEW(FontMgrBoundsGM); )
DEF_GM( return SkNEW(FontMgrMatchGM); )
#ifdef SK_BUILD_FOR_WIN
« no previous file with comments | « no previous file | include/core/SkLazyPtr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698