mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-04-11 09:50:59 +00:00
Fix viewBox parsing
This commit is contained in:
parent
64a09c6f7d
commit
cfd71e9550
6 changed files with 91 additions and 37 deletions
38
dist/fabric.js
vendored
38
dist/fabric.js
vendored
|
|
@ -3034,27 +3034,37 @@ if (typeof console !== 'undefined') {
|
|||
if (!elements || (elements && !elements.length)) return;
|
||||
|
||||
var viewBoxAttr = doc.getAttribute('viewBox'),
|
||||
widthAttr = doc.getAttribute('width'),
|
||||
heightAttr = doc.getAttribute('height'),
|
||||
widthAttr = parseFloat(doc.getAttribute('width')),
|
||||
heightAttr = parseFloat(doc.getAttribute('height')),
|
||||
width = null,
|
||||
height = null,
|
||||
viewBoxWidth,
|
||||
viewBoxHeight,
|
||||
minX,
|
||||
minY;
|
||||
|
||||
if (viewBoxAttr && (viewBoxAttr = viewBoxAttr.match(reViewBoxAttrValue))) {
|
||||
minX = parseInt(viewBoxAttr[1], 10);
|
||||
minY = parseInt(viewBoxAttr[2], 10);
|
||||
width = parseInt(viewBoxAttr[3], 10);
|
||||
height = parseInt(viewBoxAttr[4], 10);
|
||||
minX = parseFloat(viewBoxAttr[1]);
|
||||
minY = parseFloat(viewBoxAttr[2]);
|
||||
viewBoxWidth = parseFloat(viewBoxAttr[3]);
|
||||
viewBoxHeight = parseFloat(viewBoxAttr[4]);
|
||||
}
|
||||
|
||||
// values of width/height attributes overwrite those extracted from viewbox attribute
|
||||
width = widthAttr ? parseFloat(widthAttr) : width;
|
||||
height = heightAttr ? parseFloat(heightAttr) : height;
|
||||
if (viewBoxWidth && widthAttr && viewBoxWidth !== widthAttr) {
|
||||
width = viewBoxWidth;
|
||||
height = viewBoxHeight;
|
||||
}
|
||||
else {
|
||||
// values of width/height attributes overwrite those extracted from viewbox attribute
|
||||
width = widthAttr ? widthAttr : viewBoxWidth;
|
||||
height = heightAttr ? heightAttr : viewBoxHeight;
|
||||
}
|
||||
|
||||
var options = {
|
||||
width: width,
|
||||
height: height
|
||||
height: height,
|
||||
widthAttr: widthAttr,
|
||||
heightAttr: heightAttr
|
||||
};
|
||||
|
||||
fabric.gradientDefs = fabric.getGradientDefs(doc);
|
||||
|
|
@ -15083,6 +15093,14 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
|
|||
}
|
||||
|
||||
this.setOptions(options);
|
||||
|
||||
if (options.widthAttr) {
|
||||
this.scaleX = options.widthAttr / options.width;
|
||||
}
|
||||
if (options.heightAttr) {
|
||||
this.scaleY = options.heightAttr / options.height;
|
||||
}
|
||||
|
||||
this.setCoords();
|
||||
|
||||
if (options.sourcePath) {
|
||||
|
|
|
|||
14
dist/fabric.min.js
vendored
14
dist/fabric.min.js
vendored
File diff suppressed because one or more lines are too long
BIN
dist/fabric.min.js.gz
vendored
BIN
dist/fabric.min.js.gz
vendored
Binary file not shown.
38
dist/fabric.require.js
vendored
38
dist/fabric.require.js
vendored
|
|
@ -3034,27 +3034,37 @@ if (typeof console !== 'undefined') {
|
|||
if (!elements || (elements && !elements.length)) return;
|
||||
|
||||
var viewBoxAttr = doc.getAttribute('viewBox'),
|
||||
widthAttr = doc.getAttribute('width'),
|
||||
heightAttr = doc.getAttribute('height'),
|
||||
widthAttr = parseFloat(doc.getAttribute('width')),
|
||||
heightAttr = parseFloat(doc.getAttribute('height')),
|
||||
width = null,
|
||||
height = null,
|
||||
viewBoxWidth,
|
||||
viewBoxHeight,
|
||||
minX,
|
||||
minY;
|
||||
|
||||
if (viewBoxAttr && (viewBoxAttr = viewBoxAttr.match(reViewBoxAttrValue))) {
|
||||
minX = parseInt(viewBoxAttr[1], 10);
|
||||
minY = parseInt(viewBoxAttr[2], 10);
|
||||
width = parseInt(viewBoxAttr[3], 10);
|
||||
height = parseInt(viewBoxAttr[4], 10);
|
||||
minX = parseFloat(viewBoxAttr[1]);
|
||||
minY = parseFloat(viewBoxAttr[2]);
|
||||
viewBoxWidth = parseFloat(viewBoxAttr[3]);
|
||||
viewBoxHeight = parseFloat(viewBoxAttr[4]);
|
||||
}
|
||||
|
||||
// values of width/height attributes overwrite those extracted from viewbox attribute
|
||||
width = widthAttr ? parseFloat(widthAttr) : width;
|
||||
height = heightAttr ? parseFloat(heightAttr) : height;
|
||||
if (viewBoxWidth && widthAttr && viewBoxWidth !== widthAttr) {
|
||||
width = viewBoxWidth;
|
||||
height = viewBoxHeight;
|
||||
}
|
||||
else {
|
||||
// values of width/height attributes overwrite those extracted from viewbox attribute
|
||||
width = widthAttr ? widthAttr : viewBoxWidth;
|
||||
height = heightAttr ? heightAttr : viewBoxHeight;
|
||||
}
|
||||
|
||||
var options = {
|
||||
width: width,
|
||||
height: height
|
||||
height: height,
|
||||
widthAttr: widthAttr,
|
||||
heightAttr: heightAttr
|
||||
};
|
||||
|
||||
fabric.gradientDefs = fabric.getGradientDefs(doc);
|
||||
|
|
@ -15083,6 +15093,14 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
|
|||
}
|
||||
|
||||
this.setOptions(options);
|
||||
|
||||
if (options.widthAttr) {
|
||||
this.scaleX = options.widthAttr / options.width;
|
||||
}
|
||||
if (options.heightAttr) {
|
||||
this.scaleY = options.heightAttr / options.height;
|
||||
}
|
||||
|
||||
this.setCoords();
|
||||
|
||||
if (options.sourcePath) {
|
||||
|
|
|
|||
|
|
@ -410,27 +410,37 @@
|
|||
if (!elements || (elements && !elements.length)) return;
|
||||
|
||||
var viewBoxAttr = doc.getAttribute('viewBox'),
|
||||
widthAttr = doc.getAttribute('width'),
|
||||
heightAttr = doc.getAttribute('height'),
|
||||
widthAttr = parseFloat(doc.getAttribute('width')),
|
||||
heightAttr = parseFloat(doc.getAttribute('height')),
|
||||
width = null,
|
||||
height = null,
|
||||
viewBoxWidth,
|
||||
viewBoxHeight,
|
||||
minX,
|
||||
minY;
|
||||
|
||||
if (viewBoxAttr && (viewBoxAttr = viewBoxAttr.match(reViewBoxAttrValue))) {
|
||||
minX = parseInt(viewBoxAttr[1], 10);
|
||||
minY = parseInt(viewBoxAttr[2], 10);
|
||||
width = parseInt(viewBoxAttr[3], 10);
|
||||
height = parseInt(viewBoxAttr[4], 10);
|
||||
minX = parseFloat(viewBoxAttr[1]);
|
||||
minY = parseFloat(viewBoxAttr[2]);
|
||||
viewBoxWidth = parseFloat(viewBoxAttr[3]);
|
||||
viewBoxHeight = parseFloat(viewBoxAttr[4]);
|
||||
}
|
||||
|
||||
// values of width/height attributes overwrite those extracted from viewbox attribute
|
||||
width = widthAttr ? parseFloat(widthAttr) : width;
|
||||
height = heightAttr ? parseFloat(heightAttr) : height;
|
||||
if (viewBoxWidth && widthAttr && viewBoxWidth !== widthAttr) {
|
||||
width = viewBoxWidth;
|
||||
height = viewBoxHeight;
|
||||
}
|
||||
else {
|
||||
// values of width/height attributes overwrite those extracted from viewbox attribute
|
||||
width = widthAttr ? widthAttr : viewBoxWidth;
|
||||
height = heightAttr ? heightAttr : viewBoxHeight;
|
||||
}
|
||||
|
||||
var options = {
|
||||
width: width,
|
||||
height: height
|
||||
height: height,
|
||||
widthAttr: widthAttr,
|
||||
heightAttr: heightAttr
|
||||
};
|
||||
|
||||
fabric.gradientDefs = fabric.getGradientDefs(doc);
|
||||
|
|
|
|||
|
|
@ -51,6 +51,14 @@
|
|||
}
|
||||
|
||||
this.setOptions(options);
|
||||
|
||||
if (options.widthAttr) {
|
||||
this.scaleX = options.widthAttr / options.width;
|
||||
}
|
||||
if (options.heightAttr) {
|
||||
this.scaleY = options.heightAttr / options.height;
|
||||
}
|
||||
|
||||
this.setCoords();
|
||||
|
||||
if (options.sourcePath) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue