Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions src/element-categories.js

This file was deleted.

13 changes: 10 additions & 3 deletions src/transform-applier.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const Matrix = require('transformation-matrix');
const SvgElement = require('./svg-element');
const {isPaintableElement, isContainerElement} = require('./element-categories');
const log = require('./util/log');

/**
Expand Down Expand Up @@ -289,6 +288,14 @@ const _transformPath = function (pathString, transform) {
return result;
};

const GRAPHICS_ELEMENTS = ['circle', 'ellipse', 'image', 'line', 'path', 'polygon', 'polyline', 'rect', 'text', 'use'];
const CONTAINER_ELEMENTS = ['a', 'defs', 'g', 'marker', 'glyph', 'missing-glyph', 'pattern', 'svg', 'switch', 'symbol'];
const _isContainerElement = function (element) {
return element.tagName && CONTAINER_ELEMENTS.includes(element.tagName.toLowerCase());
};
const _isGraphicsElement = function (element) {
return element.tagName && GRAPHICS_ELEMENTS.includes(element.tagName.toLowerCase());
};
const _isPathWithTransformAndStroke = function (element, strokeWidth) {
if (!element.attributes) return false;
strokeWidth = element.attributes['stroke-width'] ?
Expand Down Expand Up @@ -507,7 +514,7 @@ const transformStrokeWidths = function (svgTag, windowRef, bboxForTesting) {
const inherited = Matrix.identity();

const applyTransforms = (element, matrix, strokeWidth, fill, stroke) => {
if (isContainerElement(element)) {
if (_isContainerElement(element)) {
// Push fills and stroke width down to leaves
if (element.attributes['stroke-width']) {
strokeWidth = element.attributes['stroke-width'].value;
Expand Down Expand Up @@ -594,7 +601,7 @@ const transformStrokeWidths = function (svgTag, windowRef, bboxForTesting) {
element.setAttribute('stroke-width', _quadraticMean(matrixScale.x, matrixScale.y) * strokeWidth);
if (fill) element.setAttribute('fill', fill);
if (stroke) element.setAttribute('stroke', stroke);
} else if (isPaintableElement(element)) {
} else if (_isGraphicsElement(element)) {
// Push stroke width, fill, and stroke down to leaves
if (strokeWidth && !element.attributes['stroke-width']) {
element.setAttribute('stroke-width', strokeWidth);
Expand Down