2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "sk_tool_utils.h"
9 #include "sk_tool_utils_flags.h"
13 #include "SkTestScalerContext.h"
15 DEFINE_bool(portableFonts, false, "Use portable fonts");
16 DEFINE_bool(resourceFonts, false, "Use resource fonts");
18 namespace sk_tool_utils {
20 const char* colortype_name(SkColorType ct) {
22 case kUnknown_SkColorType: return "Unknown";
23 case kAlpha_8_SkColorType: return "Alpha_8";
24 case kIndex_8_SkColorType: return "Index_8";
25 case kARGB_4444_SkColorType: return "ARGB_4444";
26 case kRGB_565_SkColorType: return "RGB_565";
27 case kRGBA_8888_SkColorType: return "RGBA_8888";
28 case kBGRA_8888_SkColorType: return "BGRA_8888";
31 return "unexpected colortype";
35 SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style) {
37 if (FLAGS_portableFonts) {
38 face = create_font(name, style);
39 } else if (FLAGS_resourceFonts) {
40 face = resource_font(name, style);
42 face = SkTypeface::CreateFromName(name, style);
47 void set_portable_typeface(SkPaint* paint, const char* name, SkTypeface::Style style) {
48 SkTypeface* face = create_portable_typeface(name, style);
49 SkSafeUnref(paint->setTypeface(face));
52 void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y,
53 SkColorType colorType, SkAlphaType alphaType) {
57 const SkImageInfo info = SkImageInfo::Make(tmp.width(), tmp.height(), colorType, alphaType);
59 canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y);
62 } // namespace sk_tool_utils