Chromium Code Reviews| 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 "sk_tool_utils.h" | 8 #include "sk_tool_utils.h" |
| 9 #include "../src/fonts/SkTestScalerContext.h" | 9 #include "sk_tool_utils_flags.h" |
| 10 | 10 |
| 11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
| 12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 13 #include "SkTestScalerContext.h" | |
| 14 | |
| 15 DEFINE_bool(portableFonts, false, "Use portable fonts"); | |
|
mtklein
2014/07/30 15:03:57
What's the end game? Ordinarily bots use --portab
caryclark
2014/07/30 15:45:32
Today, this makes it easier to bring up a new refe
| |
| 16 DEFINE_bool(resourceFonts, false, "Use resource fonts"); | |
| 13 | 17 |
| 14 namespace sk_tool_utils { | 18 namespace sk_tool_utils { |
| 15 | 19 |
| 16 bool gEnablePortableTypeface = false; | |
| 17 | |
| 18 const char* colortype_name(SkColorType ct) { | 20 const char* colortype_name(SkColorType ct) { |
| 19 switch (ct) { | 21 switch (ct) { |
| 20 case kUnknown_SkColorType: return "Unknown"; | 22 case kUnknown_SkColorType: return "Unknown"; |
| 21 case kAlpha_8_SkColorType: return "Alpha_8"; | 23 case kAlpha_8_SkColorType: return "Alpha_8"; |
| 22 case kIndex_8_SkColorType: return "Index_8"; | 24 case kIndex_8_SkColorType: return "Index_8"; |
| 23 case kARGB_4444_SkColorType: return "ARGB_4444"; | 25 case kARGB_4444_SkColorType: return "ARGB_4444"; |
| 24 case kRGB_565_SkColorType: return "RGB_565"; | 26 case kRGB_565_SkColorType: return "RGB_565"; |
| 25 case kRGBA_8888_SkColorType: return "RGBA_8888"; | 27 case kRGBA_8888_SkColorType: return "RGBA_8888"; |
| 26 case kBGRA_8888_SkColorType: return "BGRA_8888"; | 28 case kBGRA_8888_SkColorType: return "BGRA_8888"; |
| 27 default: | 29 default: |
| 28 SkASSERT(false); | 30 SkASSERT(false); |
| 29 return "unexpected colortype"; | 31 return "unexpected colortype"; |
| 30 } | 32 } |
| 31 } | 33 } |
| 32 | 34 |
| 33 SkPaint::FontMetrics create_font(SkTDArray<SkPath*>& , SkTDArray<SkFixed>& ); | 35 SkTypeface* portable_typeface(const char* name, SkTypeface::Style style) { |
| 36 SkTypeface* face; | |
| 37 if (FLAGS_portableFonts) { | |
| 38 face = create_font(name, style); | |
| 39 } else if (FLAGS_resourceFonts) { | |
| 40 face = resource_font(name, style); | |
| 41 } else { | |
| 42 face = SkTypeface::CreateFromName(name, style); | |
| 43 } | |
| 44 return face; | |
| 45 } | |
| 34 | 46 |
| 35 void set_portable_typeface(SkPaint* paint, SkTypeface::Style style) { | 47 void set_portable_typeface(SkPaint* paint, const char* name, SkTypeface::Style s tyle) { |
| 36 if (gEnablePortableTypeface) { | 48 SkTypeface* face = portable_typeface(name, style); |
| 37 SkSafeUnref(paint->setTypeface(CreateTestTypeface(create_font, style))); | 49 SkSafeUnref(paint->setTypeface(face)); |
| 38 } | |
| 39 } | 50 } |
| 40 | 51 |
| 41 void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y, | 52 void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y, |
| 42 SkColorType colorType, SkAlphaType alphaType) { | 53 SkColorType colorType, SkAlphaType alphaType) { |
| 43 SkBitmap tmp(bitmap); | 54 SkBitmap tmp(bitmap); |
| 44 tmp.lockPixels(); | 55 tmp.lockPixels(); |
| 45 | 56 |
| 46 SkImageInfo info = tmp.info(); | 57 SkImageInfo info = tmp.info(); |
| 47 info.fColorType = colorType; | 58 info.fColorType = colorType; |
| 48 info.fAlphaType = alphaType; | 59 info.fAlphaType = alphaType; |
| 49 | 60 |
| 50 canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y); | 61 canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y); |
| 51 } | 62 } |
| 52 | 63 |
| 53 } // namespace sk_tool_utils | 64 } // namespace sk_tool_utils |
| OLD | NEW |