| 1 |
// Copyright 2019 Google LLC. |
| 2 |
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
| 3 |
#include "tools/fiddle/examples.h" |
| 4 |
REG_FIDDLE(Bitmap_pixmap, 256, 256, true, 0) { |
| 5 |
void draw(SkCanvas* canvas) { |
| 6 |
SkBitmap bitmap; |
| 7 |
bitmap.allocPixels(SkImageInfo::MakeN32Premul(10, 11)); |
| 8 |
SkCanvas offscreen(bitmap); |
| 9 |
offscreen.clear(SK_ColorWHITE); |
| 10 |
SkPaint paint; |
| 11 |
SkFont font = SkFont(fontMgr->matchFamilyStyle(nullptr, {})); |
| 12 |
font.setEdging(SkFont::Edging::kAlias); |
| 13 |
offscreen.drawString("&", 0, 10, font, paint); |
| 14 |
const SkPixmap& pixmap = bitmap.pixmap(); |
| 15 |
if (pixmap.addr()) { |
| 16 |
SkPMColor pmWhite = *pixmap.addr32(0, 0); |
| 17 |
for (int y = 0; y < pixmap.height(); ++y) { |
| 18 |
for (int x = 0; x < pixmap.width(); ++x) { |
| 19 |
SkDebugf("%c", *pixmap.addr32(x, y) == pmWhite ? '-' : 'x'); |
| 20 |
} |
| 21 |
SkDebugf("\n"); |
| 22 |
} |
| 23 |
} |
| 24 |
} |
| 25 |
} // END FIDDLE |