aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/lua/scrape_dashing_full.lua
blob: 5719e261274b34a2f3521bf77819a7b45271ac54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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

--[[
    Use to initialize all keys passed in keyTable to zero in table.
    Useful so that keys that are never get incremented still output zero at end
]]
function resetTableKeys(table, keyTable)
    for k, v in next, keyTable do
        table[v] = 0
    end
end

function increment(table, key)
    table[key] = (table[key] or 0) + 1
end

local dashCount = 0

local total_found = {}
local drawPoints_count = {}
local drawPoints_direction = {}
resetTableKeys(drawPoints_direction, {"hori", "vert", "other"})
local dashInterval_count = {}
local dashInterval_pattern = {}
resetTableKeys(dashInterval_pattern, {"one_one", "zero_on", "other"})
local dash_phase = {}
resetTableKeys(dash_phase, {"zero", "other"})
local dash_cap = {}
resetTableKeys(dash_cap, {"butt", "round", "square"})

local dashTable = {}
dashTable.total_found = total_found
dashTable.drawPoints_count = drawPoints_count
dashTable.drawPoints_direction = drawPoints_direction
dashTable.dashInterval_count = dashInterval_count
dashTable.dashInterval_pattern = dashInterval_pattern
dashTable.dash_phase = dash_phase
dashTable.dash_cap = dash_cap

function sk_scrape_accumulate(t)
    local p = t.paint
    if p then
        local pe = p:getPathEffect()
        if pe then
            local de = pe:asADash()
            if de then
                dashCount = dashCount + 1
                increment(total_found, t.verb);
                increment(dashInterval_count, #de.intervals)
                if 2 == #de.intervals then
		    if 1 == de.intervals[1] and 1 == de.intervals[2] then
                        increment(dashInterval_pattern, "one_one")
                    elseif 0 == de.intervals[1] then
                        increment(dashInterval_pattern, "zero_on")
                    else
                        increment(dashInterval_pattern, "other")
                    end
                end

                if 0 == de.phase then
                    increment(dash_phase, "zero")
                else
                    increment(dash_phase, "other")
                end

                local cap = p:getStrokeCap()
                if 0 == cap then
                    increment(dash_cap, "butt")
                elseif 1 == cap then
                    increment(dash_cap, "round")
                else
                    increment(dash_cap, "square")
                end

                if "drawPoints" == t.verb then
                    local points = t.points
                    increment(drawPoints_count, #points)
                    if 2 == #points then
                        if points[1].y == points[2].y then
                            increment(drawPoints_direction, "hori")
                        elseif points[1].x == points[2].x then
                            increment(drawPoints_direction, "vert")
                        else
                            increment(drawPoints_direction, "other")
                        end
                    end
                end

                --[[
                    eventually would like to print out info on drawPath verbs with dashed effect
                ]]
                if "drawPath" == t.verb then
                end

            end
        end
    end
end

--[[
    lua_pictures will call this function after all of the pictures have been
    "accumulated".
]]
function sk_scrape_summarize()
-- use for non telemetry
--[[
    io.write("Total dashed effects is: ", dashCount, "\n");
    for k1, v1 in next, dashTable do
        io.write("\nTable: ", k1, "\n") 
        for k, v in next, v1 do
            io.write("\"", k, "\": ", v, "\n")
        end
    end
]]

-- use for telemetry
    io.write("\ndashCount = dashCount + ", tostring(dashCount), "\n")
    for k1, v1 in next, dashTable do
        for k, v in next, v1 do
            io.write("\nincrement(dashTable, \"", k1, "\", \"", k, "\", ", v, ")\n")
        end
    end
end