scrape_dashing_full.lua 4.5 KB

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