Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: tools/skhello.cpp

Issue 12381087: Convert skhello tool to SkFlags API. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: review Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gyp/tools.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkFlags.h"
9 #include "SkGraphics.h" 10 #include "SkGraphics.h"
10 #include "SkImageEncoder.h" 11 #include "SkImageEncoder.h"
11 #include "SkString.h" 12 #include "SkString.h"
12 13
13 static void show_help() { 14 DEFINE_string(o, "skhello.png", "The filename to write the image.");
14 SkDebugf("usage: skhello [-o out-dir] [-t 'hello']\n default output: skhell o.png\n"); 15 DEFINE_string(t, "Hello", "The string to write.");
15 }
16 16
17 int tool_main(int argc, char** argv); 17 int tool_main(int argc, char** argv);
18 int tool_main(int argc, char** argv) { 18 int tool_main(int argc, char** argv) {
19 SkFlags::SetUsage("");
20 SkFlags::ParseCommandLine(argc, argv);
21
19 SkAutoGraphics ag; 22 SkAutoGraphics ag;
20 SkString path("skhello.png"); 23 SkString path("skhello.png");
21 SkString text("Hello"); 24 SkString text("Hello");
22 25
23 for (int i = 1; i < argc; i++) { 26 if (!FLAGS_o.isEmpty()) {
24 if (!strcmp(argv[i], "--help")) { 27 path.set(FLAGS_o[0]);
25 show_help(); 28 }
26 return 0; 29 if (!FLAGS_t.isEmpty()) {
27 } 30 text.set(FLAGS_t[0]);
28 if (!strcmp(argv[i], "-o")) {
29 if (i == argc-1) {
30 SkDebugf("ERROR: -o needs a following filename\n");
31 return -1;
32 }
33 path.set(argv[i+1]);
34 i += 1; // skip the out dir name
35 } else if (!strcmp(argv[i], "-t")) {
36 if (i == argc-1) {
37 SkDebugf("ERROR: -t needs a following string\n");
38 return -1;
39 }
40 text.set(argv[i+1]);
41 i += 1; // skip the text string
42 }
43 } 31 }
44 32
45 SkPaint paint; 33 SkPaint paint;
46 paint.setAntiAlias(true); 34 paint.setAntiAlias(true);
47 paint.setTextSize(SkIntToScalar(30)); 35 paint.setTextSize(SkIntToScalar(30));
48 SkScalar width = paint.measureText(text.c_str(), text.size()); 36 SkScalar width = paint.measureText(text.c_str(), text.size());
49 SkScalar spacing = paint.getFontSpacing(); 37 SkScalar spacing = paint.getFontSpacing();
50 38
51 int w = SkScalarRound(width) + 30; 39 int w = SkScalarRound(width) + 30;
52 int h = SkScalarRound(spacing) + 30; 40 int h = SkScalarRound(spacing) + 30;
(...skipping 15 matching lines...) Expand all
68 SkDebugf("--- failed to write %s\n", path.c_str()); 56 SkDebugf("--- failed to write %s\n", path.c_str());
69 } 57 }
70 return !success; 58 return !success;
71 } 59 }
72 60
73 #if !defined SK_BUILD_FOR_IOS 61 #if !defined SK_BUILD_FOR_IOS
74 int main(int argc, char * const argv[]) { 62 int main(int argc, char * const argv[]) {
75 return tool_main(argc, (char**) argv); 63 return tool_main(argc, (char**) argv);
76 } 64 }
77 #endif 65 #endif
OLDNEW
« no previous file with comments | « gyp/tools.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698