mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-12 15:53:10 +00:00
Fix Safari svg whitespace (#4294)
* fix-whitespace * fixed tests * fixed doc
This commit is contained in:
parent
0d36e565a9
commit
545686ed96
3 changed files with 11 additions and 5 deletions
|
|
@ -87,7 +87,7 @@
|
|||
* @private
|
||||
*/
|
||||
_createTextCharSpan: function(_char, styleDecl, left, top) {
|
||||
var styleProps = this.getSvgSpanStyles(styleDecl, false),
|
||||
var styleProps = this.getSvgSpanStyles(styleDecl, _char !== _char.trim()),
|
||||
fillStyles = styleProps ? 'style="' + styleProps + '"' : '';
|
||||
|
||||
return [
|
||||
|
|
@ -212,8 +212,12 @@
|
|||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns styles-string for svg-export
|
||||
* @param {Boolean} skipShadow a boolean to skip shadow filter output
|
||||
* @return {String}
|
||||
*/
|
||||
getSvgStyles: function(skipShadow) {
|
||||
|
||||
var svgStyle = fabric.Object.prototype.getSvgStyles.call(this, skipShadow);
|
||||
return svgStyle + ' white-space: pre;';
|
||||
},
|
||||
|
|
|
|||
|
|
@ -60,10 +60,11 @@
|
|||
|
||||
/**
|
||||
* Returns styles-string for svg-export
|
||||
* @param {Boolean} skipShadow a boolean to skip shadow filter output
|
||||
* @param {Object} style style properties for the span a boolean to skip shadow filter output
|
||||
* @param {Boolean} useWhiteSpace a boolean to include an additional attribute in the style.
|
||||
* @return {String}
|
||||
*/
|
||||
getSvgSpanStyles: function(style) {
|
||||
getSvgSpanStyles: function(style, useWhiteSpace) {
|
||||
var strokeWidth = style.strokeWidth ? 'stroke-width: ' + style.strokeWidth + '; ' : '',
|
||||
fontFamily = style.fontFamily ? 'font-family: ' + style.fontFamily.replace(/"/g, '\'') + '; ' : '',
|
||||
fontSize = style.fontSize ? 'font-size: ' + style.fontSize + '; ' : '',
|
||||
|
|
@ -82,6 +83,7 @@
|
|||
fontWeight,
|
||||
textDecoration,
|
||||
fill,
|
||||
useWhiteSpace ? 'white-space: pre; ' : ''
|
||||
].join('');
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
};
|
||||
|
||||
var TEXT_SVG = '\t<g transform="translate(10.5 26.72)">\n\t\t<text xml:space="preserve" font-family="Times New Roman" font-size="40" font-style="normal" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1; white-space: pre;" >\n\t\t\t<tspan x="-10" y="12.57" >x</tspan>\n\t\t</text>\n\t</g>\n';
|
||||
var TEXT_SVG_JUSTIFIED = '\t<g transform="translate(50.5 26.72)">\n\t\t<text xml:space="preserve" font-family="Times New Roman" font-size="40" font-style="normal" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1; white-space: pre;" >\n\t\t\t<tspan x=\"-60\" y=\"-13.65\" >xxxxxx</tspan>\n\t\t\t<tspan x=\"-60\" y=\"38.78\" >x </tspan>\n\t\t\t<tspan x=\"40\" y=\"38.78\" >y</tspan>\n\t\t</text>\n\t</g>\n';
|
||||
var TEXT_SVG_JUSTIFIED = '\t<g transform="translate(50.5 26.72)">\n\t\t<text xml:space="preserve" font-family="Times New Roman" font-size="40" font-style="normal" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1; white-space: pre;" >\n\t\t\t<tspan x="-60" y="-13.65" >xxxxxx</tspan>\n\t\t\t<tspan x="-60" y="38.78" style="white-space: pre; ">x </tspan>\n\t\t\t<tspan x=\"40\" y=\"38.78\" >y</tspan>\n\t\t</text>\n\t</g>\n';
|
||||
|
||||
test('constructor', function() {
|
||||
ok(fabric.Text);
|
||||
|
|
|
|||
Loading…
Reference in a new issue