diff options
author | 2013-05-31 19:46:02 +0000 | |
---|---|---|
committer | 2013-05-31 19:46:02 +0000 | |
commit | e2aad27c5f02e375077ed605738c65009ba0644c (patch) | |
tree | d4361b1b24262c188acae352a0ad0943cd62dfe9 /tools/lua/glyph-usage.lua | |
parent | a20e42c08b6b92c1022e5b27da3f92a429d0c815 (diff) |
sort the glyphID arrays
add head/tail code
git-svn-id: http://skia.googlecode.com/svn/trunk@9376 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools/lua/glyph-usage.lua')
-rw-r--r-- | tools/lua/glyph-usage.lua | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/tools/lua/glyph-usage.lua b/tools/lua/glyph-usage.lua index 2b0c0e12a0..8715f726fe 100644 --- a/tools/lua/glyph-usage.lua +++ b/tools/lua/glyph-usage.lua @@ -52,6 +52,15 @@ function round(x, mul) return math.floor(x * mul + 0.5) / mul end +dump_glyph_array_p = false + +function dump_array_as_C(array) + for k, v in next, array do + io.write(tostring(v), ", "); + end + io.write("-1,\n") +end + local strikes = {} -- [fontID_pointsize] = [] unique glyphs function make_strike_key(paint) @@ -66,6 +75,16 @@ function array_union(array, other) end end +-- take a table of bools, indexed by values, and return a sorted table of values +function bools_to_values(t) + local array = {} + for k, v in next, t do + array[#array + 1] = k + end + table.sort(array) + return array +end + function array_count(array) local n = 0 for k in next, array do @@ -81,6 +100,10 @@ function sk_scrape_accumulate(t) local key = make_strike_key(t.paint) strikes[key] = strikes[key] or {} array_union(strikes[key], t.glyphs) + + if dump_glyph_array_p then + dump_array_as_C(t.glyphs) + end end end end @@ -94,20 +117,41 @@ function sk_scrape_summarize() local strikeCount = 0 local min, max = 0, 0 + local histogram = {} + 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"); +-- 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 + + histogram[count] = (histogram[count] or 0) + 1 end local ave = round(totalCount / strikeCount) io.write("\n", "unique glyphs: min = ", min, ", max = ", max, ", ave = ", ave, "\n"); + + for k, v in next, histogram do + io.write("glyph_count,", k, ",frequency,", v, "\n") + end +end + +function test_summary() + io.write("just testing test_summary\n") +end + +function summarize_unique_glyphIDs() + io.write("/* runs of unique glyph IDs, with a -1 sentinel between different runs */\n") + io.write("static const int gUniqueGlyphIDs[] = {\n"); + for k, v in next, strikes do + dump_array_as_C(bools_to_values(v)) + end + io.write("-1 };\n") end |