convertEllipseToCircle.js 895 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. exports.type = 'perItem';
  3. exports.active = true;
  4. exports.description = 'converts non-eccentric <ellipse>s to <circle>s';
  5. /**
  6. * Converts non-eccentric <ellipse>s to <circle>s.
  7. *
  8. * @see http://www.w3.org/TR/SVG/shapes.html
  9. *
  10. * @param {Object} item current iteration item
  11. * @return {Boolean} if false, item will be filtered out
  12. *
  13. * @author Taylor Hunt
  14. */
  15. exports.fn = function(item) {
  16. if (item.isElem('ellipse')) {
  17. var rx = item.attr('rx').value || 0;
  18. var ry = item.attr('ry').value || 0;
  19. if (rx === ry ||
  20. rx === 'auto' || ry === 'auto' // SVG2
  21. ) {
  22. var radius = rx !== 'auto' ? rx : ry;
  23. item.renameElem('circle');
  24. item.removeAttr(['rx', 'ry']);
  25. item.addAttr({
  26. name: 'r',
  27. value: radius,
  28. prefix: '',
  29. local: 'r',
  30. });
  31. }
  32. }
  33. return;
  34. };