OLD | NEW |
(Empty) | |
| 1 -- |
| 2 -- Copyright 2016 Google Inc. |
| 3 -- |
| 4 -- Use of this source code is governed by a BSD-style license that can be |
| 5 -- found in the LICENSE file. |
| 6 -- |
| 7 |
| 8 -- Dashed path scraping script. |
| 9 -- This script is designed to count the total number of dashes in a dashed path |
| 10 -- by computing the fill path and then counting how many individual segments are |
| 11 -- inside the resulting fill path. |
| 12 |
| 13 dashes = 0 |
| 14 |
| 15 pathPieces = {} |
| 16 |
| 17 function sk_scrape_startcanvas(c, fileName) |
| 18 end |
| 19 |
| 20 function sk_scrape_endcanvas(c, fileName) |
| 21 end |
| 22 |
| 23 function sk_scrape_accumulate(t) |
| 24 local paint = t.paint |
| 25 if paint then |
| 26 local pe = paint:getPathEffect() |
| 27 if pe then |
| 28 if t.verb == "drawPath" and pe:asADash() then |
| 29 dashes = dashes + 1 |
| 30 pathPieces[dashes] = 0 |
| 31 |
| 32 local path = t.path |
| 33 local fillpath = paint:getFillPath(path) |
| 34 local verbs = fillpath:getVerbs() |
| 35 for _, verb in ipairs(verbs) do |
| 36 if verb == "move" then |
| 37 pathPieces[dashes] = pathPieces[dashes] + 1 |
| 38 end |
| 39 end |
| 40 end |
| 41 end |
| 42 end |
| 43 end |
| 44 |
| 45 -- We mulitply by two because for each segment of the dash, we do two measuremen
ts: |
| 46 -- One for the beginning and one for the end of each dash. |
| 47 function sk_scrape_summarize() |
| 48 local pieces5 = 0; |
| 49 local pieces10 = 0; |
| 50 for _, p in ipairs(pathPieces) do |
| 51 local pieces = 2*p |
| 52 if pieces < 5 then |
| 53 pieces5 = pieces5 + 1 |
| 54 end |
| 55 if pieces > 5 and pieces < 10 then |
| 56 pieces10 = pieces10 + 1 |
| 57 end |
| 58 end |
| 59 io.write(string.format("%d %d %d\n", 2*dashes, pieces5, pieces10)) |
| 60 end |
OLD | NEW |