Home | History | Annotate | Download | only in gm
      1 /*
      2  * Copyright 2011 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 #include "gm.h"
      8 #include "SkTypeface.h"
      9 
     10 namespace skiagm {
     11 
     12 class FontScalerGM : public GM {
     13 public:
     14     FontScalerGM() {
     15         this->setBGColor(0xFFFFFFFF);
     16     }
     17 
     18     virtual ~FontScalerGM() {
     19     }
     20 
     21 protected:
     22     virtual uint32_t onGetFlags() const SK_OVERRIDE {
     23         return kSkipTiled_Flag;
     24     }
     25 
     26     virtual SkString onShortName() {
     27         return SkString("fontscaler");
     28     }
     29 
     30     virtual SkISize onISize() {
     31         return SkISize::Make(1450, 750);
     32     }
     33 
     34     static void rotate_about(SkCanvas* canvas,
     35                              SkScalar degrees,
     36                              SkScalar px, SkScalar py) {
     37         canvas->translate(px, py);
     38         canvas->rotate(degrees);
     39         canvas->translate(-px, -py);
     40     }
     41 
     42     virtual void onDraw(SkCanvas* canvas) {
     43         SkPaint paint;
     44 
     45         paint.setAntiAlias(true);
     46         paint.setLCDRenderText(true);
     47         //With freetype the default (normal hinting) can be really ugly.
     48         //Most distros now set slight (vertical hinting only) in any event.
     49         paint.setHinting(SkPaint::kSlight_Hinting);
     50         sk_tool_utils::set_portable_typeface(&paint, "Times Roman", SkTypeface::kNormal);
     51 
     52         const char* text = "Hamburgefons ooo mmm";
     53         const size_t textLen = strlen(text);
     54 
     55         for (int j = 0; j < 2; ++j) {
     56             // This used to do 6 iterations but it causes the N4 to crash in the MSAA4 config.
     57             for (int i = 0; i < 5; ++i) {
     58                 SkScalar x = SkIntToScalar(10);
     59                 SkScalar y = SkIntToScalar(20);
     60 
     61                 SkAutoCanvasRestore acr(canvas, true);
     62                 canvas->translate(SkIntToScalar(50 + i * 230),
     63                                   SkIntToScalar(20));
     64                 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10);
     65 
     66                 {
     67                     SkPaint p;
     68                     p.setAntiAlias(true);
     69                     SkRect r;
     70                     r.set(x - SkIntToScalar(3), SkIntToScalar(15),
     71                           x - SkIntToScalar(1), SkIntToScalar(280));
     72                     canvas->drawRect(r, p);
     73                 }
     74 
     75                 for (int ps = 6; ps <= 22; ps++) {
     76                     paint.setTextSize(SkIntToScalar(ps));
     77                     canvas->drawText(text, textLen, x, y, paint);
     78                     y += paint.getFontMetrics(NULL);
     79                 }
     80             }
     81             canvas->translate(0, SkIntToScalar(360));
     82             paint.setSubpixelText(true);
     83         }
     84     }
     85 
     86 private:
     87     typedef GM INHERITED;
     88 };
     89 
     90 //////////////////////////////////////////////////////////////////////////////
     91 
     92 static GM* MyFactory(void*) { return new FontScalerGM; }
     93 static GMRegistry reg(MyFactory);
     94 
     95 }
     96