1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "path_utils.h"
#include "SkPath.h"
#include "SkStream.h"
namespace sk_tools {
static int gCurPathID = 0;
void dump_path_prefix(SkFILEWStream* pathStream) {
if (NULL == pathStream) {
return;
}
pathStream->writeText("#include \"SkScalar.h\"\n");
pathStream->writeText("#include \"SkPoint.h\"\n");
pathStream->writeText("#include \"SkBitmap.h\"\n");
pathStream->writeText("#include \"SkDevice.h\"\n");
pathStream->writeText("#include \"SkString.h\"\n");
pathStream->writeText("#include \"SkImageEncoder.h\"\n");
}
void dump_path(SkFILEWStream* pathStream, const SkPath& path) {
if (NULL == pathStream) {
return;
}
static const int kMaxPts = 200;
static const int kMaxVerbs = 200;
int numPts = path.countPoints();
int numVerbs = path.countVerbs();
SkASSERT(numPts <= kMaxPts);
SkASSERT(numVerbs <= kMaxVerbs);
SkPoint pts[kMaxPts];
uint8_t verbs[kMaxVerbs];
path.getPoints(pts, kMaxPts);
path.getVerbs(verbs, kMaxVerbs);
const char* gStrs[] = {
"kMove_Verb",
"kLine_Verb",
"kQuad_Verb",
"kCubic_Verb",
"kClose_Verb",
"kDone_Verb"
};
pathStream->writeText("static const int numPts");
pathStream->writeDecAsText(gCurPathID);
pathStream->writeText(" = ");
pathStream->writeDecAsText(numPts);
pathStream->writeText(";\n");
pathStream->writeText("SkPoint pts");
pathStream->writeDecAsText(gCurPathID);
pathStream->writeText("[] = {\n");
for (int i = 0; i < numPts; ++i) {
SkString temp;
pathStream->writeText(" { ");
temp.appendScalar(pts[i].fX);
temp.append("f, ");
temp.appendScalar(pts[i].fY);
temp.append("f },\n");
pathStream->writeText(temp.c_str());
}
pathStream->writeText("};\n");
pathStream->writeText("static const int numVerbs");
pathStream->writeDecAsText(gCurPathID);
pathStream->writeText(" = ");
pathStream->writeDecAsText(numVerbs);
pathStream->writeText(";\n");
pathStream->writeText("uint8_t verbs");
pathStream->writeDecAsText(gCurPathID);
pathStream->writeText("[] = {\n");
for (int i = 0; i < numVerbs; ++i) {
pathStream->writeText("\tSkPath::");
pathStream->writeText(gStrs[verbs[i]]);
pathStream->writeText(",\n");
}
pathStream->writeText("};\n");
gCurPathID++;
}
void dump_path_suffix(SkFILEWStream* pathStream) {
if (NULL == pathStream) {
return;
}
pathStream->writeText("int numPaths = ");
pathStream->writeDecAsText(gCurPathID);
pathStream->writeText(";\n");
pathStream->writeText("int sizes[] = {\n");
for (int i = 0; i < gCurPathID; ++i) {
pathStream->writeText("\t numPts");
pathStream->writeDecAsText(i);
pathStream->writeText(", numVerbs");
pathStream->writeDecAsText(i);
pathStream->writeText(",\n");
}
pathStream->writeText("};\n");
pathStream->writeText("const SkPoint* points[] = {\n");
for (int i = 0; i < gCurPathID; ++i) {
pathStream->writeText("\tpts");
pathStream->writeDecAsText(i);
pathStream->writeText(",\n");
}
pathStream->writeText("};\n");
pathStream->writeText("const uint8_t* verbs[] = {\n");
for (int i = 0; i < gCurPathID; ++i) {
pathStream->writeText("\t(const uint8_t*)verbs");
pathStream->writeDecAsText(i);
pathStream->writeText(",\n");
}
pathStream->writeText("};\n");
}
}
|