mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-04-18 05:00:58 +00:00
Merge pull request #424 from Kienz/svgoutput
fabric.StaticCanvas.toSVG() + fabric.StaticCanvas.setBackgroundColor
This commit is contained in:
commit
6aa9bf691b
2 changed files with 55 additions and 19 deletions
|
|
@ -695,13 +695,37 @@
|
|||
|
||||
if (markup) {
|
||||
markup = [
|
||||
'<defs>',
|
||||
'<style type="text/css">',
|
||||
'<![CDATA[',
|
||||
markup,
|
||||
']]>',
|
||||
'</style>',
|
||||
'</defs>'
|
||||
'<style type="text/css">',
|
||||
'<![CDATA[',
|
||||
markup,
|
||||
']]>',
|
||||
'</style>',
|
||||
].join('');
|
||||
}
|
||||
|
||||
return markup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates markup containing SVG referenced elements like patterns, gradients etc.
|
||||
* @method createSVGRefElementsMarkup
|
||||
* @param {fabric.Canvas} canvas instance of fabric.Canvas
|
||||
* @return {String}
|
||||
*/
|
||||
function createSVGRefElementsMarkup(canvas) {
|
||||
var markup = '';
|
||||
|
||||
if (canvas.backgroundColor && canvas.backgroundColor.source) {
|
||||
markup = [
|
||||
'<pattern x="0" y="0" id="backgroundColorPattern" ',
|
||||
'width="', canvas.backgroundColor.source.width,
|
||||
'" height="', canvas.backgroundColor.source.height,
|
||||
'" patternUnits="userSpaceOnUse">',
|
||||
'<image x="0" y="0" ',
|
||||
'width="', canvas.backgroundColor.source.width,
|
||||
'" height="', canvas.backgroundColor.source.height,
|
||||
'" xlink:href="', canvas.backgroundColor.source.src,
|
||||
'"></image></pattern>'
|
||||
].join('');
|
||||
}
|
||||
|
||||
|
|
@ -710,16 +734,17 @@
|
|||
|
||||
extend(fabric, {
|
||||
|
||||
parseAttributes: parseAttributes,
|
||||
parseElements: parseElements,
|
||||
parseStyleAttribute: parseStyleAttribute,
|
||||
parsePointsAttribute: parsePointsAttribute,
|
||||
getCSSRules: getCSSRules,
|
||||
parseAttributes: parseAttributes,
|
||||
parseElements: parseElements,
|
||||
parseStyleAttribute: parseStyleAttribute,
|
||||
parsePointsAttribute: parsePointsAttribute,
|
||||
getCSSRules: getCSSRules,
|
||||
|
||||
loadSVGFromURL: loadSVGFromURL,
|
||||
loadSVGFromString: loadSVGFromString,
|
||||
loadSVGFromURL: loadSVGFromURL,
|
||||
loadSVGFromString: loadSVGFromString,
|
||||
|
||||
createSVGFontFacesMarkup: createSVGFontFacesMarkup
|
||||
createSVGFontFacesMarkup: createSVGFontFacesMarkup,
|
||||
createSVGRefElementsMarkup: createSVGRefElementsMarkup
|
||||
});
|
||||
|
||||
})(typeof exports !== 'undefined' ? exports : this);
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@
|
|||
fabric.util.loadImage(backgroundColor.source, function(img) {
|
||||
_this.backgroundColor = new fabric.Pattern({
|
||||
source: img,
|
||||
pattern: backgroundColor.pattern
|
||||
repeat: backgroundColor.repeat
|
||||
});
|
||||
callback && callback();
|
||||
});
|
||||
|
|
@ -951,16 +951,27 @@
|
|||
'version="1.1" ',
|
||||
'width="', this.width, '" ',
|
||||
'height="', this.height, '" ',
|
||||
(this.backgroundColor && !this.backgroundColor.source) ? 'style="background-color: ' + this.backgroundColor +'" ' : null,
|
||||
'xml:space="preserve">',
|
||||
'<desc>Created with Fabric.js ', fabric.version, '</desc>',
|
||||
fabric.createSVGFontFacesMarkup(this.getObjects())
|
||||
'<defs>', fabric.createSVGFontFacesMarkup(this.getObjects()), fabric.createSVGRefElementsMarkup(this), '</defs>'
|
||||
);
|
||||
|
||||
if (this.backgroundColor && this.backgroundColor.source) {
|
||||
markup.push(
|
||||
'<rect x="0" y="0" ',
|
||||
'width="', (this.backgroundColor.repeat !== 'repeat-y' ? this.width : this.backgroundColor.source.width),
|
||||
'" height="', (this.backgroundColor.repeat !== 'repeat-x' ? this.height : this.backgroundColor.source.height),
|
||||
'" fill="url(#backgroundColorPattern)"',
|
||||
'></rect>'
|
||||
);
|
||||
}
|
||||
|
||||
if (this.backgroundImage) {
|
||||
markup.push(
|
||||
'<image x="0" y="0" ',
|
||||
'width="', this.width,
|
||||
'" height="', this.height,
|
||||
'width="', (this.backgroundImageStretch ? this.width : this.backgroundImage.width),
|
||||
'" height="', (this.backgroundImageStretch ? this.height : this.backgroundImage.height),
|
||||
'" preserveAspectRatio="', (this.backgroundImageStretch ? 'none' : 'defer'),
|
||||
'" xlink:href="', this.backgroundImage.src,
|
||||
'" style="opacity:', this.backgroundImageOpacity,
|
||||
|
|
|
|||
Loading…
Reference in a new issue