Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
|
robertphillips
2015/05/11 18:34:41
timewarp
joshualitt
2015/05/11 19:07:47
Acknowledged.
| |
| 2 * Copyright 2013 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "gm.h" | |
| 9 | |
| 10 #include "Resources.h" | |
| 11 #include "SkCanvas.h" | |
|
robertphillips
2015/05/11 18:34:41
Do we need gradient shader ?
joshualitt
2015/05/11 19:07:47
Acknowledged.
| |
| 12 #include "SkGradientShader.h" | |
| 13 #include "SkStream.h" | |
| 14 #include "SkSurface.h" | |
| 15 #include "SkTextBlob.h" | |
| 16 #include "SkTypeface.h" | |
| 17 | |
| 18 namespace skiagm { | |
|
robertphillips
2015/05/11 18:34:41
// informative comment ?
// link to Chrome bug ?
joshualitt
2015/05/11 19:07:47
Acknowledged.
| |
| 19 class TextBlobGeometryChange : public GM { | |
| 20 public: | |
| 21 TextBlobGeometryChange() { } | |
| 22 | |
| 23 protected: | |
|
robertphillips
2015/05/11 18:34:41
rm this ?
joshualitt
2015/05/11 19:07:47
Acknowledged.
| |
| 24 void onOnceBeforeDraw() override { | |
| 25 } | |
| 26 | |
| 27 SkString onShortName() override { | |
| 28 return SkString("textblobgeometrychange"); | |
| 29 } | |
| 30 | |
| 31 SkISize onISize() override { | |
| 32 return SkISize::Make(kWidth, kHeight); | |
| 33 } | |
| 34 | |
| 35 void onDraw(SkCanvas* canvas) override { | |
| 36 SkPaint paint; | |
| 37 | |
| 38 canvas->clear(0x00ffffff); | |
|
bsalomon
2015/05/11 18:33:13
Do we really want the bad looking LCD text on tran
joshualitt
2015/05/11 19:07:47
Acknowledged.
| |
| 39 | |
|
robertphillips
2015/05/11 18:34:41
Maybe a build_lcd_blob helper ?
joshualitt
2015/05/11 19:07:47
Acknowledged.
| |
| 40 const char text[] = "Hamburgefons"; | |
| 41 SkTDArray<uint16_t> glyphs; | |
| 42 size_t len = strlen(text); | |
| 43 glyphs.append(paint.textToGlyphs(text, len, NULL)); | |
| 44 paint.textToGlyphs(text, len, glyphs.begin()); | |
| 45 paint.setTextSize(20); | |
| 46 paint.setAntiAlias(true); | |
| 47 paint.setLCDRenderText(true); | |
| 48 | |
| 49 SkTextBlobBuilder builder; | |
| 50 | |
| 51 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | |
|
robertphillips
2015/05/11 18:34:41
overlength
joshualitt
2015/05/11 19:07:47
Acknowledged.
| |
| 52 const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(paint, glyphs .count(), 10, 10, NULL); | |
|
bsalomon
2015/05/11 18:33:13
wrap?
joshualitt
2015/05/11 19:07:47
Acknowledged.
| |
| 53 memcpy(run.glyphs, glyphs.begin(), glyphs.count() * sizeof(uint16_t)); | |
| 54 | |
| 55 SkAutoTUnref<const SkTextBlob> blob(builder.build()); | |
| 56 | |
| 57 SkImageInfo info = SkImageInfo::MakeN32Premul(200, 200); | |
| 58 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); | |
| 59 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info, &props)); | |
| 60 SkCanvas* c = surface->getCanvas(); | |
| 61 | |
| 62 // LCD text on white background | |
| 63 SkRect rect = SkRect::MakeLTRB(0, 0, kWidth, kHeight / 2); | |
| 64 SkPaint rectPaint; | |
| 65 rectPaint.setColor(0xffffffff); | |
| 66 canvas->drawRect(rect, rectPaint); | |
| 67 canvas->drawTextBlob(blob.get(), 10, 50, paint); | |
| 68 | |
| 69 // This should not look garbled | |
| 70 rect = SkRect::MakeLTRB(0, kHeight / 2, kWidth, kHeight); | |
| 71 rectPaint.setColor(0x00ffffff); | |
| 72 c->drawRect(rect, rectPaint); | |
| 73 c->drawTextBlob(blob.get(), 10, 150, paint); | |
| 74 surface->draw(canvas, 0, 0, nullptr); | |
| 75 } | |
| 76 | |
| 77 private: | |
| 78 static const int kWidth = 200; | |
| 79 static const int kHeight = 200; | |
| 80 | |
| 81 typedef GM INHERITED; | |
| 82 }; | |
| 83 | |
| 84 ////////////////////////////////////////////////////////////////////////////// | |
| 85 | |
| 86 DEF_GM( return SkNEW(TextBlobGeometryChange); ) | |
| 87 } | |
| OLD | NEW |