| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 | 9 |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 unsigned count; | 24 unsigned count; |
| 25 Pos pos; | 25 Pos pos; |
| 26 SkScalar scale; | 26 SkScalar scale; |
| 27 } blobConfigs[][3][3] = { | 27 } blobConfigs[][3][3] = { |
| 28 { | 28 { |
| 29 { { 1024, kDefault_Pos, 1 }, { 0, kDefault_Pos, 0 }, { 0, kDefault_Pos,
0 } }, | 29 { { 1024, kDefault_Pos, 1 }, { 0, kDefault_Pos, 0 }, { 0, kDefault_Pos,
0 } }, |
| 30 { { 1024, kScalar_Pos, 1 }, { 0, kScalar_Pos, 0 }, { 0, kScalar_Pos,
0 } }, | 30 { { 1024, kScalar_Pos, 1 }, { 0, kScalar_Pos, 0 }, { 0, kScalar_Pos,
0 } }, |
| 31 { { 1024, kPoint_Pos, 1 }, { 0, kPoint_Pos, 0 }, { 0, kPoint_Pos,
0 } }, | 31 { { 1024, kPoint_Pos, 1 }, { 0, kPoint_Pos, 0 }, { 0, kPoint_Pos,
0 } }, |
| 32 }, | 32 }, |
| 33 { | 33 { |
| 34 { { 4, kDefault_Pos, 1}, { 4, kDefault_Pos, 1}, { 4, kDefault_Pos,
1} }, | 34 { { 4, kDefault_Pos, 1 }, { 4, kDefault_Pos, 1 }, { 4, kDefault_Pos
, 1 } }, |
| 35 { { 4, kScalar_Pos, 1}, { 4, kScalar_Pos, 1}, { 4, kScalar_Pos,
1} }, | 35 { { 4, kScalar_Pos, 1 }, { 4, kScalar_Pos, 1 }, { 4, kScalar_Pos
, 1 } }, |
| 36 { { 4, kPoint_Pos, 1}, { 4, kPoint_Pos, 1}, { 4, kPoint_Pos,
1} }, | 36 { { 4, kPoint_Pos, 1 }, { 4, kPoint_Pos, 1 }, { 4, kPoint_Pos
, 1 } }, |
| 37 }, | 37 }, |
| 38 | 38 |
| 39 { | 39 { |
| 40 { { 4, kDefault_Pos, 1}, { 4, kDefault_Pos, 1}, { 4, kScalar_Pos,
1} }, | 40 { { 4, kDefault_Pos, 1 }, { 4, kDefault_Pos, 1 }, { 4, kScalar_Pos
, 1 } }, |
| 41 { { 4, kScalar_Pos, 1}, { 4, kScalar_Pos, 1}, { 4, kPoint_Pos,
1} }, | 41 { { 4, kScalar_Pos, 1 }, { 4, kScalar_Pos, 1 }, { 4, kPoint_Pos
, 1 } }, |
| 42 { { 4, kPoint_Pos, 1}, { 4, kPoint_Pos, 1}, { 4, kDefault_Pos,
1} }, | 42 { { 4, kPoint_Pos, 1 }, { 4, kPoint_Pos, 1 }, { 4, kDefault_Pos
, 1 } }, |
| 43 }, | 43 }, |
| 44 | 44 |
| 45 { | 45 { |
| 46 { { 4, kDefault_Pos, 1}, { 4, kScalar_Pos, 1}, { 4, kPoint_Pos,
1} }, | 46 { { 4, kDefault_Pos, 1 }, { 4, kScalar_Pos, 1 }, { 4, kPoint_Pos
, 1 } }, |
| 47 { { 4, kScalar_Pos, 1}, { 4, kPoint_Pos, 1}, { 4, kDefault_Pos,
1} }, | 47 { { 4, kScalar_Pos, 1 }, { 4, kPoint_Pos, 1 }, { 4, kDefault_Pos
, 1 } }, |
| 48 { { 4, kPoint_Pos, 1}, { 4, kDefault_Pos, 1}, { 4, kScalar_Pos,
1} }, | 48 { { 4, kPoint_Pos, 1 }, { 4, kDefault_Pos, 1 }, { 4, kScalar_Pos
, 1 } }, |
| 49 }, |
| 50 |
| 51 { |
| 52 { { 4, kDefault_Pos, .75f }, { 4, kDefault_Pos, 1 }, { 4, kScalar_
Pos, 1.25f } }, |
| 53 { { 4, kScalar_Pos, .75f }, { 4, kScalar_Pos, 1 }, { 4, kPoint_
Pos, 1.25f } }, |
| 54 { { 4, kPoint_Pos, .75f }, { 4, kPoint_Pos, 1 }, { 4, kDefault_
Pos, 1.25f } }, |
| 55 }, |
| 56 |
| 57 { |
| 58 { { 4, kDefault_Pos, 1 }, { 4, kScalar_Pos, .75f }, { 4, kPoint_
Pos, 1.25f } }, |
| 59 { { 4, kScalar_Pos, 1 }, { 4, kPoint_Pos, .75f }, { 4, kDefault_
Pos, 1.25f } }, |
| 60 { { 4, kPoint_Pos, 1 }, { 4, kDefault_Pos, .75f }, { 4, kScalar_
Pos, 1.25f } }, |
| 49 }, | 61 }, |
| 50 }; | 62 }; |
| 51 | 63 |
| 52 const SkScalar kFontSize = 16; | 64 const SkScalar kFontSize = 16; |
| 53 } | 65 } |
| 54 | 66 |
| 55 class TextBlobGM : public skiagm::GM { | 67 class TextBlobGM : public skiagm::GM { |
| 56 public: | 68 public: |
| 57 TextBlobGM(const char* txt) { | 69 TextBlobGM(const char* txt) { |
| 58 SkPaint p; | 70 SkPaint p; |
| 59 size_t txtLen = strlen(txt); | 71 size_t txtLen = strlen(txt); |
| 60 int glyphCount = p.textToGlyphs(txt, txtLen, NULL); | 72 int glyphCount = p.textToGlyphs(txt, txtLen, NULL); |
| 61 | 73 |
| 62 fGlyphs.append(glyphCount); | 74 fGlyphs.append(glyphCount); |
| 63 p.textToGlyphs(txt, txtLen, fGlyphs.begin()); | 75 p.textToGlyphs(txt, txtLen, fGlyphs.begin()); |
| 64 } | 76 } |
| 65 | 77 |
| 66 protected: | 78 protected: |
| 67 virtual SkString onShortName() SK_OVERRIDE { | 79 virtual SkString onShortName() SK_OVERRIDE { |
| 68 return SkString("textblob"); | 80 return SkString("textblob"); |
| 69 } | 81 } |
| 70 | 82 |
| 71 virtual SkISize onISize() SK_OVERRIDE { | 83 virtual SkISize onISize() SK_OVERRIDE { |
| 72 return SkISize::Make(640, 480); | 84 return SkISize::Make(640, 480); |
| 73 } | 85 } |
| 74 | 86 |
| 75 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 87 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 76 for (unsigned b = 0; b < SK_ARRAY_COUNT(blobConfigs); ++b) { | 88 for (unsigned b = 0; b < SK_ARRAY_COUNT(blobConfigs); ++b) { |
| 77 SkAutoTUnref<const SkTextBlob> blob(makeBlob(b)); | 89 SkAutoTUnref<const SkTextBlob> blob(this->makeBlob(b)); |
| 78 | 90 |
| 79 SkPaint p; | 91 SkPaint p; |
| 80 p.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | |
| 81 p.setTextSize(kFontSize); | |
| 82 p.setAntiAlias(true); | |
| 83 p.setSubpixelText(true); | |
| 84 | |
| 85 SkPoint offset = SkPoint::Make(SkIntToScalar(10 + 300 * (b % 2)), | 92 SkPoint offset = SkPoint::Make(SkIntToScalar(10 + 300 * (b % 2)), |
| 86 SkIntToScalar(20 + 150 * (b / 2))); | 93 SkIntToScalar(20 + 150 * (b / 2))); |
| 87 | 94 |
| 88 canvas->drawTextBlob(blob, offset.x(), offset.y(), p); | 95 canvas->drawTextBlob(blob, offset.x(), offset.y(), p); |
| 89 | 96 |
| 90 p.setColor(SK_ColorBLUE); | 97 p.setColor(SK_ColorBLUE); |
| 91 p.setStyle(SkPaint::kStroke_Style); | 98 p.setStyle(SkPaint::kStroke_Style); |
| 92 SkRect box = blob->bounds(); | 99 SkRect box = blob->bounds(); |
| 93 box.offset(offset); | 100 box.offset(offset); |
| 94 canvas->drawRect(box, p); | 101 canvas->drawRect(box, p); |
| 95 | 102 |
| 96 } | 103 } |
| 97 } | 104 } |
| 98 | 105 |
| 99 private: | 106 private: |
| 100 const SkTextBlob* makeBlob(unsigned blobIndex) { | 107 const SkTextBlob* makeBlob(unsigned blobIndex) { |
| 101 SkTextBlobBuilder builder; | 108 SkTextBlobBuilder builder; |
| 102 | 109 |
| 103 SkPaint font; | 110 SkPaint font; |
| 104 font.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 111 font.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 112 font.setAntiAlias(true); |
| 113 font.setSubpixelText(true); |
| 105 | 114 |
| 106 for (unsigned l = 0; l < SK_ARRAY_COUNT(blobConfigs[blobIndex]); ++l) { | 115 for (unsigned l = 0; l < SK_ARRAY_COUNT(blobConfigs[blobIndex]); ++l) { |
| 107 unsigned currentGlyph = 0; | 116 unsigned currentGlyph = 0; |
| 108 | 117 |
| 109 for (unsigned c = 0; c < SK_ARRAY_COUNT(blobConfigs[blobIndex][l]);
++c) { | 118 for (unsigned c = 0; c < SK_ARRAY_COUNT(blobConfigs[blobIndex][l]);
++c) { |
| 110 const BlobCfg* cfg = &blobConfigs[blobIndex][l][c]; | 119 const BlobCfg* cfg = &blobConfigs[blobIndex][l][c]; |
| 111 unsigned count = cfg->count; | 120 unsigned count = cfg->count; |
| 112 | 121 |
| 113 if (count > fGlyphs.count() - currentGlyph) { | 122 if (count > fGlyphs.count() - currentGlyph) { |
| 114 count = fGlyphs.count() - currentGlyph; | 123 count = fGlyphs.count() - currentGlyph; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 172 |
| 164 return builder.build(); | 173 return builder.build(); |
| 165 } | 174 } |
| 166 | 175 |
| 167 SkTDArray<uint16_t> fGlyphs; | 176 SkTDArray<uint16_t> fGlyphs; |
| 168 | 177 |
| 169 typedef skiagm::GM INHERITED; | 178 typedef skiagm::GM INHERITED; |
| 170 }; | 179 }; |
| 171 | 180 |
| 172 DEF_GM( return SkNEW_ARGS(TextBlobGM, ("hamburgefons")); ) | 181 DEF_GM( return SkNEW_ARGS(TextBlobGM, ("hamburgefons")); ) |
| OLD | NEW |