Skip to content

Commit f4ae345

Browse files
authored
Merge pull request #149 from adroitwhiz/fix-image-transforms
Revert "Move element categories into own file+correct them"
2 parents 74d7257 + 89abe42 commit f4ae345

File tree

2 files changed

+10
-33
lines changed

2 files changed

+10
-33
lines changed

src/element-categories.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/transform-applier.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const Matrix = require('transformation-matrix');
22
const SvgElement = require('./svg-element');
3-
const {isPaintableElement, isContainerElement} = require('./element-categories');
43
const log = require('./util/log');
54

65
/**
@@ -289,6 +288,14 @@ const _transformPath = function (pathString, transform) {
289288
return result;
290289
};
291290

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+
};
292299
const _isPathWithTransformAndStroke = function (element, strokeWidth) {
293300
if (!element.attributes) return false;
294301
strokeWidth = element.attributes['stroke-width'] ?
@@ -507,7 +514,7 @@ const transformStrokeWidths = function (svgTag, windowRef, bboxForTesting) {
507514
const inherited = Matrix.identity();
508515

509516
const applyTransforms = (element, matrix, strokeWidth, fill, stroke) => {
510-
if (isContainerElement(element)) {
517+
if (_isContainerElement(element)) {
511518
// Push fills and stroke width down to leaves
512519
if (element.attributes['stroke-width']) {
513520
strokeWidth = element.attributes['stroke-width'].value;
@@ -594,7 +601,7 @@ const transformStrokeWidths = function (svgTag, windowRef, bboxForTesting) {
594601
element.setAttribute('stroke-width', _quadraticMean(matrixScale.x, matrixScale.y) * strokeWidth);
595602
if (fill) element.setAttribute('fill', fill);
596603
if (stroke) element.setAttribute('stroke', stroke);
597-
} else if (isPaintableElement(element)) {
604+
} else if (_isGraphicsElement(element)) {
598605
// Push stroke width, fill, and stroke down to leaves
599606
if (strokeWidth && !element.attributes['stroke-width']) {
600607
element.setAttribute('stroke-width', strokeWidth);

0 commit comments

Comments
 (0)