mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-01 10:34:42 +00:00
Revert polygon/polyline points change as it breaks shapes in SVG import section
This commit is contained in:
parent
3eb00518f8
commit
0bf607be2e
3 changed files with 16 additions and 40 deletions
|
|
@ -181,15 +181,16 @@
|
|||
|
||||
var points = fabric.parsePointsAttribute(element.getAttribute('points')),
|
||||
parsedAttributes = fabric.parseAttributes(element, fabric.Polygon.ATTRIBUTE_NAMES),
|
||||
boundingRect = fabric.util.getBoundingRect(points);
|
||||
minX = min(points, 'x'),
|
||||
minY = min(points, 'y');
|
||||
|
||||
options.top = boundingRect.y1 + boundingRect.height / 2;
|
||||
options.left = boundingRect.x1 + boundingRect.width / 2;
|
||||
minX = minX < 0 ? minX : 0;
|
||||
minY = minX < 0 ? minY : 0;
|
||||
|
||||
for (var i = 0, len = points.length; i < len; i++) {
|
||||
// normalize coordinates, according to containing box (dimensions of which are calculated above)
|
||||
points[i].x -= options.left;
|
||||
points[i].y -= options.top;
|
||||
// normalize coordinates, according to containing box (dimensions of which are passed via `options`)
|
||||
points[i].x -= (options.width / 2 + minX) || 0;
|
||||
points[i].y -= (options.height / 2 + minY) || 0;
|
||||
}
|
||||
|
||||
return new fabric.Polygon(points, extend(parsedAttributes, options), true);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
"use strict";
|
||||
|
||||
var fabric = global.fabric || (global.fabric = { }),
|
||||
toFixed = fabric.util.toFixed;
|
||||
toFixed = fabric.util.toFixed,
|
||||
min = fabric.util.array.min;
|
||||
|
||||
if (fabric.Polyline) {
|
||||
fabric.warn('fabric.Polyline is already defined');
|
||||
|
|
@ -151,15 +152,16 @@
|
|||
|
||||
var points = fabric.parsePointsAttribute(element.getAttribute('points')),
|
||||
parsedAttributes = fabric.parseAttributes(element, fabric.Polyline.ATTRIBUTE_NAMES),
|
||||
boundingRect = fabric.util.getBoundingRect(points);
|
||||
minX = min(points, 'x'),
|
||||
minY = min(points, 'y');
|
||||
|
||||
options.top = boundingRect.y1 + boundingRect.height / 2;
|
||||
options.left = boundingRect.x1 + boundingRect.width / 2;
|
||||
minX = minX < 0 ? minX : 0;
|
||||
minY = minX < 0 ? minY : 0;
|
||||
|
||||
for (var i = 0, len = points.length; i < len; i++) {
|
||||
// normalize coordinates, according to containing box (dimensions of which are calculated above)
|
||||
points[i].x -= options.left;
|
||||
points[i].y -= options.top;
|
||||
// normalize coordinates, according to containing box (dimensions of which are passed via `options`)
|
||||
points[i].x -= (options.width / 2 + minX) || 0;
|
||||
points[i].y -= (options.height / 2 + minY) || 0;
|
||||
}
|
||||
|
||||
return new fabric.Polyline(points, fabric.util.object.extend(parsedAttributes, options), true);
|
||||
|
|
|
|||
|
|
@ -432,32 +432,6 @@
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an array of points and returns a bounding rectangle around them
|
||||
* @static
|
||||
* @memberOf fabric.util
|
||||
* @param {Array.<Object>} points An array of objects with x and y properties.
|
||||
* @return {Object} An object with x1, y1, x2, and y2 properties
|
||||
* corresponding to the points of the rect, and
|
||||
* width and height properties.
|
||||
*/
|
||||
function getBoundingRect(points) {
|
||||
var utilMin = fabric.util.array.min,
|
||||
utilMax = fabric.util.array.max;
|
||||
|
||||
var rect = {
|
||||
x1: utilMin(points, 'x'),
|
||||
y1: utilMin(points, 'y'),
|
||||
x2: utilMax(points, 'x'),
|
||||
y2: utilMax(points, 'y')
|
||||
};
|
||||
|
||||
rect.width = rect.x2 - rect.x1;
|
||||
rect.height = rect.y2 - rect.y1;
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
function getFunctionBody(fn) {
|
||||
return (String(fn).match(/function[^{]*\{([\s\S]*)\}/) || {})[1];
|
||||
}
|
||||
|
|
@ -591,7 +565,6 @@
|
|||
fabric.util.createAccessors = createAccessors;
|
||||
fabric.util.clipContext = clipContext;
|
||||
fabric.util.multiplyTransformMatrices = multiplyTransformMatrices;
|
||||
fabric.util.getBoundingRect = getBoundingRect;
|
||||
fabric.util.getFunctionBody = getFunctionBody;
|
||||
fabric.util.drawArc = drawArc;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue