Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various small svg fixes #5424

Merged
merged 6 commits into from
Dec 9, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion src/elements_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
var _options;
_this.resolveGradient(obj, 'fill');
_this.resolveGradient(obj, 'stroke');
if (obj instanceof fabric.Image) {
if (obj instanceof fabric.Image && obj._originalElement) {
_options = obj.parsePreserveAspectRatioAttribute(el);
}
obj._removeTransformMatrix(_options);
Expand Down
15 changes: 9 additions & 6 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@
value = null;
}
else {
value = value.replace(/,/g, ' ').split(/\s+/).map(function(n) {
return parseFloat(n);
});
value = value.replace(/,/g, ' ').split(/\s+/).map(parseFloat);
}
}
else if (attr === 'transformMatrix') {
Expand Down Expand Up @@ -130,6 +128,9 @@
value = 'stroke';
}
}
else if (attr === 'href' || attr === 'xlink:href') {
return value;
}
else {
parsed = isArray ? value.map(parseUnit) : parseUnit(value, fontSize);
}
Expand Down Expand Up @@ -821,7 +822,7 @@

var value,
parentAttributes = { },
fontSize;
fontSize, parentFontSize;

if (typeof svgUid === 'undefined') {
svgUid = element.getAttribute('svgUid');
Expand All @@ -843,8 +844,10 @@
ownAttributes = extend(ownAttributes,
extend(getGlobalStylesForElement(element, svgUid), fabric.parseStyleAttribute(element)));

fontSize = (parentAttributes && parentAttributes.fontSize ) ||
ownAttributes['font-size'] || fabric.Text.DEFAULT_SVG_FONT_SIZE;
fontSize = parentFontSize = parentAttributes.fontSize || fabric.Text.DEFAULT_SVG_FONT_SIZE;
if (ownAttributes['font-size']) {
fontSize = parseUnit(ownAttributes['font-size'], parentFontSize);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rikkarv the idea here is that

  • parseUnit should be used always.
  • if the current fontSize is specified in EM ( i think is sort of legit ) we must reference the parent fontsize

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok this is not good needs additional tweaking as per the uploaded test.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have already tested your changes and

ownAttributes['font-size'] = fontSize = parseUnit(ownAttributes['font-size'], parentFontSize);

is really doing his job. Now i have fontSize as a number instead of a string and the following maths doesn't break.

Thank you very much for your effort


var normalizedAttr, normalizedValue, normalizedStyle = {};
for (var attr in ownAttributes) {
Expand Down
8 changes: 3 additions & 5 deletions src/shapes/path.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,15 +471,13 @@
* of the instance
*/
_toSVG: function() {
var specificTransform = this._getOffsetTransform(),
path = this.path.map(function(path) {
return path.join(' ');
}).join(' ');
var path = this.path.map(function(path) {
return path.join(' ');
}).join(' ');
return [
'<path ', 'COMMON_PARTS',
'd="', path,
'" stroke-linecap="round" ',
'transform="' + specificTransform + '" ',
'/>\n'
];
},
Expand Down
6 changes: 3 additions & 3 deletions src/static_canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@
* crossOrigin: 'anonymous'
* });
*/
// TODO: fix stretched examples
setBackgroundImage: function (image, callback, options) {
return this.__setBgOverlayImage('backgroundImage', image, callback, options);
},
Expand Down Expand Up @@ -1293,12 +1294,11 @@

this._setSVGPreamble(markup, options);
this._setSVGHeader(markup, options);

this._setSVGBgOverlayColor(markup, 'backgroundColor');
this._setSVGBgOverlayImage(markup, 'backgroundImage', reviver);
if (this.clipPath) {
markup.push('<g clip-path="url(#' + this.clipPath.clipPathId + ')" >\n');
}
this._setSVGBgOverlayColor(markup, 'backgroundColor');
this._setSVGBgOverlayImage(markup, 'backgroundImage', reviver);
this._setSVGObjects(markup, reviver);
if (this.clipPath) {
markup.push('</g>\n');
Expand Down