1local canvas -- holds the current canvas (from startcanvas()) 2 3--[[ 4 startcanvas() is called at the start of each picture file, passing the 5 canvas that we will be drawing into, and the name of the file. 6 7 Following this call, there will be some number of calls to accumulate(t) 8 where t is a table of parameters that were passed to that draw-op. 9 10 t.verb is a string holding the name of the draw-op (e.g. "drawRect") 11 12 when a given picture is done, we call endcanvas(canvas, fileName) 13]] 14function sk_scrape_startcanvas(c, fileName) 15 canvas = c 16end 17 18--[[ 19 Called when the current canvas is done drawing. 20]] 21function sk_scrape_endcanvas(c, fileName) 22 canvas = nil 23end 24 25--[[ 26 Use to initialize all keys passed in keyTable to zero in table. 27 Useful so that keys that are never get incremented still output zero at end 28]] 29function resetTableKeys(table, keyTable) 30 for k, v in next, keyTable do 31 table[v] = 0 32 end 33end 34 35function increment(table, key) 36 table[key] = (table[key] or 0) + 1 37end 38 39local dashCount = 0 40 41local total_found = {} 42local drawPoints_count = {} 43local drawPoints_direction = {} 44resetTableKeys(drawPoints_direction, {"hori", "vert", "other"}) 45local dashInterval_count = {} 46local dashInterval_pattern = {} 47resetTableKeys(dashInterval_pattern, {"one_one", "zero_on", "other"}) 48local dash_phase = {} 49resetTableKeys(dash_phase, {"zero", "other"}) 50local dash_cap = {} 51resetTableKeys(dash_cap, {"butt", "round", "square"}) 52 53local dashTable = {} 54dashTable.total_found = total_found 55dashTable.drawPoints_count = drawPoints_count 56dashTable.drawPoints_direction = drawPoints_direction 57dashTable.dashInterval_count = dashInterval_count 58dashTable.dashInterval_pattern = dashInterval_pattern 59dashTable.dash_phase = dash_phase 60dashTable.dash_cap = dash_cap 61 62function sk_scrape_accumulate(t) 63 local p = t.paint 64 if p then 65 local pe = p:getPathEffect() 66 if pe then 67 local de = pe:asADash() 68 if de then 69 dashCount = dashCount + 1 70 increment(total_found, t.verb); 71 increment(dashInterval_count, #de.intervals) 72 if 2 == #de.intervals then 73 if 1 == de.intervals[1] and 1 == de.intervals[2] then 74 increment(dashInterval_pattern, "one_one") 75 elseif 0 == de.intervals[1] then 76 increment(dashInterval_pattern, "zero_on") 77 else 78 increment(dashInterval_pattern, "other") 79 end 80 end 81 82 if 0 == de.phase then 83 increment(dash_phase, "zero") 84 else 85 increment(dash_phase, "other") 86 end 87 88 local cap = p:getStrokeCap() 89 if 0 == cap then 90 increment(dash_cap, "butt") 91 elseif 1 == cap then 92 increment(dash_cap, "round") 93 else 94 increment(dash_cap, "square") 95 end 96 97 if "drawPoints" == t.verb then 98 local points = t.points 99 increment(drawPoints_count, #points) 100 if 2 == #points then 101 if points[1].y == points[2].y then 102 increment(drawPoints_direction, "hori") 103 elseif points[1].x == points[2].x then 104 increment(drawPoints_direction, "vert") 105 else 106 increment(drawPoints_direction, "other") 107 end 108 end 109 end 110 111 --[[ 112 eventually would like to print out info on drawPath verbs with dashed effect 113 ]] 114 if "drawPath" == t.verb then 115 end 116 117 end 118 end 119 end 120end 121 122--[[ 123 lua_pictures will call this function after all of the pictures have been 124 "accumulated". 125]] 126function sk_scrape_summarize() 127-- use for non telemetry 128--[[ 129 io.write("Total dashed effects is: ", dashCount, "\n"); 130 for k1, v1 in next, dashTable do 131 io.write("\nTable: ", k1, "\n") 132 for k, v in next, v1 do 133 io.write("\"", k, "\": ", v, "\n") 134 end 135 end 136]] 137 138-- use for telemetry 139 io.write("\ndashCount = dashCount + ", tostring(dashCount), "\n") 140 for k1, v1 in next, dashTable do 141 for k, v in next, v1 do 142 io.write("\nincrement(dashTable, \"", k1, "\", \"", k, "\", ", v, ")\n") 143 end 144 end 145end 146 147