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

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: 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, "", "The filename to write the image.");
scroggo 2013/03/04 20:40:31 Why not set "skhello.png" as the default value?
tfarina 2013/03/04 20:46:10 Done.
14 SkDebugf("usage: skhello [-o out-dir] [-t 'hello']\n default output: skhell o.png\n"); 15 DEFINE_string(t, "", "The string to write.");
scroggo 2013/03/04 20:40:31 Why not set "Hello" as the default value?
tfarina 2013/03/04 20:46:10 Done.
15 }
16 16
17 int tool_main(int argc, char** argv);
scroggo 2013/03/04 20:40:31 I think this prevents a warning on certain platfor
tfarina 2013/03/04 20:46:10 Done.
18 int tool_main(int argc, char** argv) { 17 int tool_main(int argc, char** argv) {
18 SkFlags::SetUsage("");
19 SkFlags::ParseCommandLine(argc, argv);
20
19 SkAutoGraphics ag; 21 SkAutoGraphics ag;
20 SkString path("skhello.png"); 22 SkString path("skhello.png");
21 SkString text("Hello"); 23 SkString text("Hello");
22 24
23 for (int i = 1; i < argc; i++) { 25 if (!FLAGS_o.isEmpty()) {
24 if (!strcmp(argv[i], "--help")) { 26 path.set(FLAGS_o[0]);
25 show_help(); 27 }
26 return 0; 28 if (!FLAGS_t.isEmpty()) {
27 } 29 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 } 30 }
44 31
45 SkPaint paint; 32 SkPaint paint;
46 paint.setAntiAlias(true); 33 paint.setAntiAlias(true);
47 paint.setTextSize(SkIntToScalar(30)); 34 paint.setTextSize(SkIntToScalar(30));
48 SkScalar width = paint.measureText(text.c_str(), text.size()); 35 SkScalar width = paint.measureText(text.c_str(), text.size());
49 SkScalar spacing = paint.getFontSpacing(); 36 SkScalar spacing = paint.getFontSpacing();
50 37
51 int w = SkScalarRound(width) + 30; 38 int w = SkScalarRound(width) + 30;
52 int h = SkScalarRound(spacing) + 30; 39 int h = SkScalarRound(spacing) + 30;
(...skipping 15 matching lines...) Expand all
68 SkDebugf("--- failed to write %s\n", path.c_str()); 55 SkDebugf("--- failed to write %s\n", path.c_str());
69 } 56 }
70 return !success; 57 return !success;
71 } 58 }
72 59
73 #if !defined SK_BUILD_FOR_IOS 60 #if !defined SK_BUILD_FOR_IOS
74 int main(int argc, char * const argv[]) { 61 int main(int argc, char * const argv[]) {
75 return tool_main(argc, (char**) argv); 62 return tool_main(argc, (char**) argv);
76 } 63 }
77 #endif 64 #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