|
1 | 1 | const Matrix = require('transformation-matrix'); |
2 | 2 | const SvgElement = require('./svg-element'); |
3 | | -const {isPaintableElement, isContainerElement} = require('./element-categories'); |
4 | 3 | const log = require('./util/log'); |
5 | 4 |
|
6 | 5 | /** |
@@ -289,6 +288,14 @@ const _transformPath = function (pathString, transform) { |
289 | 288 | return result; |
290 | 289 | }; |
291 | 290 |
|
| 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 | +}; |
292 | 299 | const _isPathWithTransformAndStroke = function (element, strokeWidth) { |
293 | 300 | if (!element.attributes) return false; |
294 | 301 | strokeWidth = element.attributes['stroke-width'] ? |
@@ -507,7 +514,7 @@ const transformStrokeWidths = function (svgTag, windowRef, bboxForTesting) { |
507 | 514 | const inherited = Matrix.identity(); |
508 | 515 |
|
509 | 516 | const applyTransforms = (element, matrix, strokeWidth, fill, stroke) => { |
510 | | - if (isContainerElement(element)) { |
| 517 | + if (_isContainerElement(element)) { |
511 | 518 | // Push fills and stroke width down to leaves |
512 | 519 | if (element.attributes['stroke-width']) { |
513 | 520 | strokeWidth = element.attributes['stroke-width'].value; |
@@ -594,7 +601,7 @@ const transformStrokeWidths = function (svgTag, windowRef, bboxForTesting) { |
594 | 601 | element.setAttribute('stroke-width', _quadraticMean(matrixScale.x, matrixScale.y) * strokeWidth); |
595 | 602 | if (fill) element.setAttribute('fill', fill); |
596 | 603 | if (stroke) element.setAttribute('stroke', stroke); |
597 | | - } else if (isPaintableElement(element)) { |
| 604 | + } else if (_isGraphicsElement(element)) { |
598 | 605 | // Push stroke width, fill, and stroke down to leaves |
599 | 606 | if (strokeWidth && !element.attributes['stroke-width']) { |
600 | 607 | element.setAttribute('stroke-width', strokeWidth); |
|
0 commit comments