aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/lua/glyph-usage.lua
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-05-30 18:55:14 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-05-30 18:55:14 +0000
commite3823fd901674e22269637a669ac2b3e2667dc9c (patch)
treef0fa592ea719f95b3ec38a766fab61019d57494c /tools/lua/glyph-usage.lua
parent9166bf57d89b9c2cd2c6f8b7dd99a50bf1f01f81 (diff)
add script to scrape glyph usage in drawText calls
git-svn-id: http://skia.googlecode.com/svn/trunk@9353 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools/lua/glyph-usage.lua')
-rw-r--r--tools/lua/glyph-usage.lua113
1 files changed, 113 insertions, 0 deletions
diff --git a/tools/lua/glyph-usage.lua b/tools/lua/glyph-usage.lua
new file mode 100644
index 0000000000..2b0c0e12a0
--- /dev/null
+++ b/tools/lua/glyph-usage.lua
@@ -0,0 +1,113 @@
+function tostr(t)
+ local str = ""
+ for k, v in next, t do
+ if #str > 0 then
+ str = str .. ", "
+ end
+ if type(k) == "number" then
+ str = str .. "[" .. k .. "] = "
+ else
+ str = str .. tostring(k) .. " = "
+ end
+ if type(v) == "table" then
+ str = str .. "{ " .. tostr(v) .. " }"
+ else
+ str = str .. tostring(v)
+ end
+ end
+ return str
+end
+
+local canvas -- holds the current canvas (from startcanvas())
+
+--[[
+ startcanvas() is called at the start of each picture file, passing the
+ canvas that we will be drawing into, and the name of the file.
+
+ Following this call, there will be some number of calls to accumulate(t)
+ where t is a table of parameters that were passed to that draw-op.
+
+ t.verb is a string holding the name of the draw-op (e.g. "drawRect")
+
+ when a given picture is done, we call endcanvas(canvas, fileName)
+]]
+function sk_scrape_startcanvas(c, fileName)
+ canvas = c
+end
+
+--[[
+ Called when the current canvas is done drawing.
+]]
+function sk_scrape_endcanvas(c, fileName)
+ canvas = nil
+end
+
+--[[
+ Called with the parameters to each canvas.draw call, where canvas is the
+ current canvas as set by startcanvas()
+]]
+
+function round(x, mul)
+ mul = mul or 1
+ return math.floor(x * mul + 0.5) / mul
+end
+
+local strikes = {} -- [fontID_pointsize] = [] unique glyphs
+
+function make_strike_key(paint)
+ return paint:getFontID() * 1000 + paint:getTextSize()
+end
+
+-- array is an array of bools (true), using glyphID as the index
+-- other is just an array[1...N] of numbers (glyphIDs)
+function array_union(array, other)
+ for k, v in next, other do
+ array[v] = true;
+ end
+end
+
+function array_count(array)
+ local n = 0
+ for k in next, array do
+ n = n + 1
+ end
+ return n
+end
+
+function sk_scrape_accumulate(t)
+ verb = t.verb;
+ if verb == "drawPosText" or verb == "drawPosTextH" then
+ if t.glyphs then
+ local key = make_strike_key(t.paint)
+ strikes[key] = strikes[key] or {}
+ array_union(strikes[key], t.glyphs)
+ end
+ end
+end
+
+--[[
+ lua_pictures will call this function after all of the pictures have been
+ "accumulated".
+]]
+function sk_scrape_summarize()
+ local totalCount = 0
+ local strikeCount = 0
+ local min, max = 0, 0
+
+ for k, v in next, strikes do
+ local fontID = round(k / 1000)
+ local size = k - fontID * 1000
+ local count = array_count(v)
+
+ io.write("fontID = ", fontID, ", size = ", size, ", entries = ", count, "\n");
+
+ min = math.min(min, count)
+ max = math.max(max, count)
+ totalCount = totalCount + count
+ strikeCount = strikeCount + 1
+ end
+ local ave = round(totalCount / strikeCount)
+
+ io.write("\n", "unique glyphs: min = ", min, ", max = ", max, ", ave = ", ave, "\n");
+end
+