breakUncontinuous.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding:utf-8 -*-
  2. ##
  3. # This file is part of connectSVG.
  4. #
  5. # connectSVG is free software: you can redistribute it and/or modify it
  6. # under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License,
  8. # or (at your option) any later version.
  9. #
  10. # connectSVG is distributed in the hope that it will be useful, but WITHOUT ANY
  11. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  13. # details.
  14. #
  15. # You should have received a copy of the GNU General Public License along
  16. # with connectSVG. If not, see <https://www.gnu.org/licenses/>.
  17. ##
  18. import logging
  19. log = logging.getLogger("connectsvg")
  20. def breakUncontinuous(paths, attributes) :
  21. log.info("Starting with %d paths", len(paths))
  22. i = 0
  23. while i < len(paths) :
  24. path = paths[i]
  25. pathAttributes = attributes[i]
  26. log.debug("Processing path "+str(i))
  27. if not path.iscontinuous() :
  28. replacePaths = path.continuous_subpaths()
  29. paths.pop(i)
  30. attributes.pop(i)
  31. i -= 1
  32. for replacePath in replacePaths :
  33. paths.insert(i, replacePath)
  34. attributes.insert(i, pathAttributes)
  35. i += 1
  36. log.debug("Replaced by %d paths", len(replacePaths))
  37. i += 1
  38. log.info("Ending with %d paths", len(paths))
  39. return paths, attributes