mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-04-20 06:00:59 +00:00
Merge pull request #1770 from asturur/fix-text-toSVG
Fix text top position in svg export
This commit is contained in:
commit
efbb3e40b3
2 changed files with 7 additions and 8 deletions
|
|
@ -533,9 +533,6 @@
|
|||
* @return {Number} Left offset
|
||||
*/
|
||||
_getLeftOffset: function() {
|
||||
if (fabric.isLikelyNode) {
|
||||
return 0;
|
||||
}
|
||||
return -this.width / 2;
|
||||
},
|
||||
|
||||
|
|
@ -850,7 +847,7 @@
|
|||
|
||||
textLeft = -(this.width/2),
|
||||
textTop = this.useNative
|
||||
? this.fontSize - 1
|
||||
? (this.fontSize * this.lineHeight - 0.25 * this.fontSize) // to lift by 1 / 4 of font height.
|
||||
: (this.height/2) - (textLines.length * this.fontSize) - this._totalLineHeight;
|
||||
|
||||
return {
|
||||
|
|
@ -1095,6 +1092,8 @@
|
|||
var parsedAttributes = fabric.parseAttributes(element, fabric.Text.ATTRIBUTE_NAMES);
|
||||
options = fabric.util.object.extend((options ? fabric.util.object.clone(options) : { }), parsedAttributes);
|
||||
|
||||
options.top = options.top || 0;
|
||||
options.left = options.left || 0;
|
||||
if ('dx' in parsedAttributes) {
|
||||
options.left += parsedAttributes.dx;
|
||||
}
|
||||
|
|
@ -1108,7 +1107,7 @@
|
|||
if (!options.originX) {
|
||||
options.originX = 'left';
|
||||
}
|
||||
|
||||
options.top += options.fontSize / 4;
|
||||
var text = new fabric.Text(element.textContent, options),
|
||||
/*
|
||||
Adjust positioning:
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@
|
|||
'globalCompositeOperation': 'source-over'
|
||||
};
|
||||
|
||||
var TEXT_SVG = '<g transform="translate(10 26)">\n<text font-family="Times New Roman" font-size="40" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform="translate(-10 39)"><tspan x="0" y="-26" fill="rgb(0,0,0)">x</tspan></text>\n</g>\n';
|
||||
var TEXT_SVG = '<g transform="translate(10 26)">\n<text font-family="Times New Roman" font-size="40" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform="translate(-10 42)"><tspan x="0" y="-26" fill="rgb(0,0,0)">x</tspan></text>\n</g>\n';
|
||||
|
||||
test('constructor', function() {
|
||||
ok(fabric.Text);
|
||||
|
|
@ -156,7 +156,7 @@
|
|||
|
||||
var expectedObject = fabric.util.object.extend(fabric.util.object.clone(REFERENCE_TEXT_OBJECT), {
|
||||
left: 4,
|
||||
top: -10.4,
|
||||
top: -6.4,
|
||||
width: 8,
|
||||
height: 20.8,
|
||||
fontSize: 16,
|
||||
|
|
@ -197,7 +197,7 @@
|
|||
var expectedObject = fabric.util.object.extend(fabric.util.object.clone(REFERENCE_TEXT_OBJECT), {
|
||||
/* left varies slightly due to node-canvas rendering */
|
||||
left: fabric.util.toFixed(textWithAttrs.left + '', 2),
|
||||
top: -59.95,
|
||||
top: -29.2,
|
||||
width: CHAR_WIDTH,
|
||||
height: 159.9,
|
||||
fill: 'rgb(255,255,255)',
|
||||
|
|
|
|||
Loading…
Reference in a new issue