| Index: tools/lua/glyph-counts.lua
|
| diff --git a/tools/lua/scrape.lua b/tools/lua/glyph-counts.lua
|
| similarity index 55%
|
| copy from tools/lua/scrape.lua
|
| copy to tools/lua/glyph-counts.lua
|
| index 627018800acb2839f2b6be47dc63c4a1e2391bc7..553e9e38e415ed7a8771983e2e4dfe416011bb22 100644
|
| --- a/tools/lua/scrape.lua
|
| +++ b/tools/lua/glyph-counts.lua
|
| @@ -18,7 +18,6 @@ function tostr(t)
|
| return str
|
| end
|
|
|
| -local total = {} -- accumulate() stores its data in here
|
| local canvas -- holds the current canvas (from startcanvas())
|
|
|
| --[[
|
| @@ -47,25 +46,43 @@ end
|
| Called with the parameters to each canvas.draw call, where canvas is the
|
| current canvas as set by startcanvas()
|
| ]]
|
| -function sk_scrape_accumulate(t)
|
| - local n = total[t.verb] or 0
|
| - total[t.verb] = n + 1
|
|
|
| - if false and t.verb == "drawRect" and t.paint:isAntiAlias() then
|
| - local r = t.rect;
|
| - local p = t.paint;
|
| - local c = p:getColor();
|
| - print("drawRect ", tostr(r), tostr(c), "\n")
|
| +local gCounts = {} -- [fontID_pointsize] = [] unique glyphs
|
| +local gFirstGlyphs = {}
|
| +local gTotalCount = 0
|
| +
|
| +function array_count(array)
|
| + local n = 0
|
| + for k in next, array do
|
| + n = n + 1
|
| end
|
| + return n
|
| +end
|
|
|
| - if false and t.verb == "drawPath" then
|
| - local pred, r1, r2, d1, d2 = t.path:isNestedRects()
|
| -
|
| - if pred then
|
| - print("drawRect_Nested", tostr(r1), tostr(r2), d1, d2)
|
| - else
|
| - print("drawPath", "isEmpty", tostring(t.path:isEmpty()),
|
| - "isRect", tostring(t.path:isRect()), tostr(t.path:getBounds()))
|
| +function sk_scrape_accumulate(t)
|
| + verb = t.verb;
|
| + if verb == "drawPosText" or verb == "drawPosTextH" then
|
| + if t.glyphs then
|
| + local key = array_count(t.glyphs)
|
| + local n = gCounts[key]
|
| + if n then
|
| + gCounts[key] = n + 1
|
| + else
|
| + gCounts[key] = 1
|
| + end
|
| +
|
| + if key == 1 then
|
| + local first = t.glyphs[1];
|
| + local n = gFirstGlyphs[first]
|
| + if n then
|
| + n = n + 1
|
| + else
|
| + n = 0
|
| + end
|
| + gFirstGlyphs[first] = n
|
| + end
|
| +
|
| + gTotalCount = gTotalCount + 1
|
| end
|
| end
|
| end
|
| @@ -75,6 +92,19 @@ end
|
| "accumulated".
|
| ]]
|
| function sk_scrape_summarize()
|
| - io.write("\n{ ", tostr(total), " }\n")
|
| + for k, v in next, gCounts do
|
| + io.write("glyph_count ", k, ",frequency ", v * 100 / gTotalCount, "\n")
|
| + end
|
| +
|
| +--[[
|
| + io.write("\n\nFirst glyph spread\n\n")
|
| + for k, v in next, gFirstGlyphs do
|
| + io.write("glyph, ", k, ",count, ", v, "\n")
|
| + end
|
| +]]
|
| +end
|
| +
|
| +function test_summary()
|
| + io.write("just testing test_summary\n")
|
| end
|
|
|
|
|