OLD | NEW |
1 function tostr(t) | 1 function tostr(t) |
2 local str = "" | 2 local str = "" |
3 for k, v in next, t do | 3 for k, v in next, t do |
4 if #str > 0 then | 4 if #str > 0 then |
5 str = str .. ", " | 5 str = str .. ", " |
6 end | 6 end |
7 if type(k) == "number" then | 7 if type(k) == "number" then |
8 str = str .. "[" .. k .. "] = " | 8 str = str .. "[" .. k .. "] = " |
9 else | 9 else |
10 str = str .. tostring(k) .. " = " | 10 str = str .. tostring(k) .. " = " |
11 end | 11 end |
12 if type(v) == "table" then | 12 if type(v) == "table" then |
13 str = str .. "{ " .. tostr(v) .. " }" | 13 str = str .. "{ " .. tostr(v) .. " }" |
14 else | 14 else |
15 str = str .. tostring(v) | 15 str = str .. tostring(v) |
16 end | 16 end |
17 end | 17 end |
18 return str | 18 return str |
19 end | 19 end |
20 | 20 |
21 local total = {} -- accumulate() stores its data in here | |
22 local canvas -- holds the current canvas (from startcanvas()) | 21 local canvas -- holds the current canvas (from startcanvas()) |
23 | 22 |
24 --[[ | 23 --[[ |
25 startcanvas() is called at the start of each picture file, passing the | 24 startcanvas() is called at the start of each picture file, passing the |
26 canvas that we will be drawing into, and the name of the file. | 25 canvas that we will be drawing into, and the name of the file. |
27 | 26 |
28 Following this call, there will be some number of calls to accumulate(t) | 27 Following this call, there will be some number of calls to accumulate(t) |
29 where t is a table of parameters that were passed to that draw-op. | 28 where t is a table of parameters that were passed to that draw-op. |
30 | 29 |
31 t.verb is a string holding the name of the draw-op (e.g. "drawRect") | 30 t.verb is a string holding the name of the draw-op (e.g. "drawRect") |
32 | 31 |
33 when a given picture is done, we call endcanvas(canvas, fileName) | 32 when a given picture is done, we call endcanvas(canvas, fileName) |
34 ]] | 33 ]] |
35 function sk_scrape_startcanvas(c, fileName) | 34 function sk_scrape_startcanvas(c, fileName) |
36 canvas = c | 35 canvas = c |
37 end | 36 end |
38 | 37 |
39 --[[ | 38 --[[ |
40 Called when the current canvas is done drawing. | 39 Called when the current canvas is done drawing. |
41 ]] | 40 ]] |
42 function sk_scrape_endcanvas(c, fileName) | 41 function sk_scrape_endcanvas(c, fileName) |
43 canvas = nil | 42 canvas = nil |
44 end | 43 end |
45 | 44 |
46 --[[ | 45 --[[ |
47 Called with the parameters to each canvas.draw call, where canvas is the | 46 Called with the parameters to each canvas.draw call, where canvas is the |
48 current canvas as set by startcanvas() | 47 current canvas as set by startcanvas() |
49 ]] | 48 ]] |
| 49 |
| 50 local gCounts = {} -- [fontID_pointsize] = [] unique glyphs |
| 51 local gFirstGlyphs = {} |
| 52 local gTotalCount = 0 |
| 53 |
| 54 function array_count(array) |
| 55 local n = 0 |
| 56 for k in next, array do |
| 57 n = n + 1 |
| 58 end |
| 59 return n |
| 60 end |
| 61 |
50 function sk_scrape_accumulate(t) | 62 function sk_scrape_accumulate(t) |
51 local n = total[t.verb] or 0 | 63 verb = t.verb; |
52 total[t.verb] = n + 1 | 64 if verb == "drawPosText" or verb == "drawPosTextH" then |
| 65 if t.glyphs then |
| 66 local key = array_count(t.glyphs) |
| 67 local n = gCounts[key] |
| 68 if n then |
| 69 gCounts[key] = n + 1 |
| 70 else |
| 71 gCounts[key] = 1 |
| 72 end |
| 73 |
| 74 if key == 1 then |
| 75 local first = t.glyphs[1]; |
| 76 local n = gFirstGlyphs[first] |
| 77 if n then |
| 78 n = n + 1 |
| 79 else |
| 80 n = 0 |
| 81 end |
| 82 gFirstGlyphs[first] = n |
| 83 end |
53 | 84 |
54 if false and t.verb == "drawRect" and t.paint:isAntiAlias() then | 85 gTotalCount = gTotalCount + 1 |
55 local r = t.rect; | |
56 local p = t.paint; | |
57 local c = p:getColor(); | |
58 print("drawRect ", tostr(r), tostr(c), "\n") | |
59 end | |
60 | |
61 if false and t.verb == "drawPath" then | |
62 local pred, r1, r2, d1, d2 = t.path:isNestedRects() | |
63 | |
64 if pred then | |
65 print("drawRect_Nested", tostr(r1), tostr(r2), d1, d2) | |
66 else | |
67 print("drawPath", "isEmpty", tostring(t.path:isEmpty()), | |
68 "isRect", tostring(t.path:isRect()), tostr(t.path:getBounds(
))) | |
69 end | 86 end |
70 end | 87 end |
71 end | 88 end |
72 | 89 |
73 --[[ | 90 --[[ |
74 lua_pictures will call this function after all of the pictures have been | 91 lua_pictures will call this function after all of the pictures have been |
75 "accumulated". | 92 "accumulated". |
76 ]] | 93 ]] |
77 function sk_scrape_summarize() | 94 function sk_scrape_summarize() |
78 io.write("\n{ ", tostr(total), " }\n") | 95 for k, v in next, gCounts do |
| 96 io.write("glyph_count ", k, ",frequency ", v * 100 / gTotalCount, "\n") |
| 97 end |
| 98 |
| 99 --[[ |
| 100 io.write("\n\nFirst glyph spread\n\n") |
| 101 for k, v in next, gFirstGlyphs do |
| 102 io.write("glyph, ", k, ",count, ", v, "\n") |
| 103 end |
| 104 ]] |
79 end | 105 end |
80 | 106 |
| 107 function test_summary() |
| 108 io.write("just testing test_summary\n") |
| 109 end |
| 110 |
OLD | NEW |