mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-04-25 16:04:42 +00:00
Allow to opt out from the viewport transformation of the SVG output.
This commit is contained in:
parent
307dcb3ebf
commit
7db0fe0aa2
2 changed files with 26 additions and 3 deletions
|
|
@ -48,7 +48,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
|
|||
if (this.group) return '';
|
||||
var toFixed = fabric.util.toFixed,
|
||||
angle = this.getAngle(),
|
||||
vpt = this.getViewportTransform(),
|
||||
vpt = !this.canvas || this.canvas.svgViewportTransformation ? this.getViewportTransform() : [1, 0, 0, 1, 0, 0],
|
||||
center = fabric.util.transformPoint(this.getCenterPoint(), vpt),
|
||||
|
||||
NUM_FRACTION_DIGITS = fabric.Object.NUM_FRACTION_DIGITS,
|
||||
|
|
|
|||
|
|
@ -1115,6 +1115,14 @@
|
|||
},
|
||||
|
||||
/* _TO_SVG_START_ */
|
||||
/**
|
||||
* When true, getSvgTransform() will apply the StaticCanvas.viewportTransform to the SVG transformation. When true,
|
||||
* a zoomed canvas will then produce zoomed SVG output.
|
||||
* @type Boolean
|
||||
* @default
|
||||
*/
|
||||
svgViewportTransformation: true,
|
||||
|
||||
/**
|
||||
* Returns SVG representation of canvas
|
||||
* @function
|
||||
|
|
@ -1188,13 +1196,28 @@
|
|||
* @private
|
||||
*/
|
||||
_setSVGHeader: function(markup, options) {
|
||||
var width, height, vpt;
|
||||
|
||||
if (options.viewBox) {
|
||||
width = options.viewBox.width;
|
||||
height = options.viewBox.height;
|
||||
} else {
|
||||
width = this.width;
|
||||
height = this.height;
|
||||
if (!this.svgViewportTransformation) {
|
||||
vpt = this.viewportTransform;
|
||||
width /= vpt[0];
|
||||
height /= vpt[3];
|
||||
}
|
||||
}
|
||||
|
||||
markup.push(
|
||||
'<svg ',
|
||||
'xmlns="http://www.w3.org/2000/svg" ',
|
||||
'xmlns:xlink="http://www.w3.org/1999/xlink" ',
|
||||
'version="1.1" ',
|
||||
'width="', (options.viewBox ? options.viewBox.width : this.width), '" ',
|
||||
'height="', (options.viewBox ? options.viewBox.height : this.height), '" ',
|
||||
'width="', width, '" ',
|
||||
'height="', height, '" ',
|
||||
(this.backgroundColor && !this.backgroundColor.toLive
|
||||
? 'style="background-color: ' + this.backgroundColor + '" '
|
||||
: null),
|
||||
|
|
|
|||
Loading…
Reference in a new issue