|
1 | 1 | const Matrix = require('transformation-matrix'); |
2 | 2 | const SvgElement = require('./svg-element'); |
| 3 | +const {isPaintableElement, isContainerElement} = require('./element-categories'); |
3 | 4 | const log = require('./util/log'); |
4 | 5 |
|
5 | 6 | /** |
@@ -288,14 +289,6 @@ const _transformPath = function (pathString, transform) { |
288 | 289 | return result; |
289 | 290 | }; |
290 | 291 |
|
291 | | -const GRAPHICS_ELEMENTS = ['circle', 'ellipse', 'image', 'line', 'path', 'polygon', 'polyline', 'rect', 'text', 'use']; |
292 | | -const CONTAINER_ELEMENTS = ['a', 'defs', 'g', 'marker', 'glyph', 'missing-glyph', 'pattern', 'svg', 'switch', 'symbol']; |
293 | | -const _isContainerElement = function (element) { |
294 | | - return element.tagName && CONTAINER_ELEMENTS.includes(element.tagName.toLowerCase()); |
295 | | -}; |
296 | | -const _isGraphicsElement = function (element) { |
297 | | - return element.tagName && GRAPHICS_ELEMENTS.includes(element.tagName.toLowerCase()); |
298 | | -}; |
299 | 292 | const _isPathWithTransformAndStroke = function (element, strokeWidth) { |
300 | 293 | if (!element.attributes) return false; |
301 | 294 | strokeWidth = element.attributes['stroke-width'] ? |
@@ -514,7 +507,7 @@ const transformStrokeWidths = function (svgTag, windowRef, bboxForTesting) { |
514 | 507 | const inherited = Matrix.identity(); |
515 | 508 |
|
516 | 509 | const applyTransforms = (element, matrix, strokeWidth, fill, stroke) => { |
517 | | - if (_isContainerElement(element)) { |
| 510 | + if (isContainerElement(element)) { |
518 | 511 | // Push fills and stroke width down to leaves |
519 | 512 | if (element.attributes['stroke-width']) { |
520 | 513 | strokeWidth = element.attributes['stroke-width'].value; |
@@ -601,7 +594,7 @@ const transformStrokeWidths = function (svgTag, windowRef, bboxForTesting) { |
601 | 594 | element.setAttribute('stroke-width', _quadraticMean(matrixScale.x, matrixScale.y) * strokeWidth); |
602 | 595 | if (fill) element.setAttribute('fill', fill); |
603 | 596 | if (stroke) element.setAttribute('stroke', stroke); |
604 | | - } else if (_isGraphicsElement(element)) { |
| 597 | + } else if (isPaintableElement(element)) { |
605 | 598 | // Push stroke width, fill, and stroke down to leaves |
606 | 599 | if (strokeWidth && !element.attributes['stroke-width']) { |
607 | 600 | element.setAttribute('stroke-width', strokeWidth); |
|
0 commit comments