1 2function sk_scrape_startcanvas(c, fileName) end 3 4function sk_scrape_endcanvas(c, fileName) end 5 6function classify_rrect(rrect) 7 if (rrect:type() == "simple") then 8 local x, y = rrect:radii(0) 9 if (x == y) then 10 return "simple_circle" 11 else 12 return "simple_oval" 13 end 14 elseif (rrect:type() == "complex") then 15 local numNotSquare = 0 16 local rx, ry 17 local same = true; 18 local first_not_square_corner 19 local last_not_square_corner 20 for i = 1, 4 do 21 local x, y = rrect:radii(i-1) 22 if (x ~= 0 and y ~= 0) then 23 if (numNotSquare == 0) then 24 rx = x 25 ry = y 26 first_not_square_corner = i 27 else 28 last_not_square_corner = i 29 if (rx ~= x or ry ~=y) then 30 same = false 31 end 32 end 33 numNotSquare = numNotSquare + 1 34 end 35 end 36 local numSquare = 4 - numNotSquare 37 if (numSquare > 0 and same) then 38 local corners = "corners" 39 if (numSquare == 2) then 40 if ((last_not_square_corner - 1 == first_not_square_corner) or 41 (1 == first_not_square_corner and 4 == last_not_square_corner )) then 42 corners = "adjacent_" .. corners 43 else 44 corners = "opposite_" .. corners 45 end 46 elseif (1 == numSquare) then 47 corners = "corner" 48 end 49 if (rx == ry) then 50 return "circles_with_" .. numSquare .. "_square_" .. corners 51 else 52 return "ovals_with_" .. numSquare .. "_square_" .. corners 53 end 54 end 55 return "complex_unclassified" 56 elseif (rrect:type() == "rect") then 57 return "rect" 58 elseif (rrect:type() == "oval") then 59 local x, y = rrect:radii(0) 60 if (x == y) then 61 return "circle" 62 else 63 return "oval" 64 end 65 elseif (rrect:type() == "empty") then 66 return "empty" 67 else 68 return "unknown" 69 end 70end 71 72function print_classes(class_table) 73 function sort_classes(a, b) 74 return a.count > b.count 75 end 76 array = {} 77 for k, v in pairs(class_table) do 78 if (type(v) == "number") then 79 array[#array + 1] = {class = k, count = v}; 80 end 81 end 82 table.sort(array, sort_classes) 83 local i 84 for i = 1, #array do 85 io.write(array[i].class, ": ", array[i].count, " (", array[i].count/class_table["total"] * 100, "%)\n"); 86 end 87end 88 89function sk_scrape_accumulate(t) 90 if (t.verb == "clipRRect") then 91 local rrect = t.rrect 92 table["total"] = (table["total"] or 0) + 1 93 local class = classify_rrect(rrect) 94 table[class] = (table[class] or 0) + 1 95 end 96end 97 98function sk_scrape_summarize() 99 print_classes(table) 100 --[[ To use the web scraper comment out the above call to print_classes, run the code below, 101 and in the aggregator pass agg_table to print_classes. 102 for k, v in pairs(table) do 103 if (type(v) == "number") then 104 local t = "agg_table[\"" .. k .. "\"]" 105 io.write(t, " = (", t, " or 0) + ", table[k], "\n" ); 106 end 107 end 108 --]] 109end 110