Fix text insert on null, give default style to text (#4166)

* text style error
* change text init
* fixes
This commit is contained in:
Andrea Bogazzi 2017-08-03 23:23:42 +02:00 committed by GitHub
parent c705c6b4d8
commit 068c815340
7 changed files with 10 additions and 12 deletions

View file

@ -762,7 +762,9 @@
* @param {Array} copiedStyle array of style objecs
*/
insertCharStyleObject: function(lineIndex, charIndex, quantity, copiedStyle) {
if (!this.styles) {
this.styles = {};
}
var currentLineStyles = this.styles[lineIndex],
currentLineStylesCloned = clone(currentLineStyles);
@ -780,15 +782,15 @@
}
}
this._forceClearCache = true;
if (!currentLineStyles) {
return;
}
if (copiedStyle) {
while (quantity--) {
this.styles[lineIndex][charIndex + quantity] = clone(copiedStyle[quantity]);
}
return;
}
if (!currentLineStyles) {
return;
}
var newStyle = currentLineStyles[charIndex ? charIndex - 1 : 1];
while (newStyle && quantity--) {
this.styles[lineIndex][charIndex + quantity] = clone(newStyle);

View file

@ -31,8 +31,7 @@
* @return {Object} thisArg
*/
initialize: function(objects, options) {
options = options || { };
options = options || {};
this._objects = objects || [];
for (var i = this._objects.length; i--; ) {
this._objects[i].group = this;

View file

@ -66,8 +66,7 @@
* @return {Object} thisArg
*/
initialize: function(objects, options, isAlreadyGrouped) {
options = options || { };
options = options || {};
this._objects = [];
// if objects enclosed in a group have been grouped already,
// we cannot change properties of objects.

View file

@ -179,7 +179,6 @@
* @return {fabric.IText} thisArg
*/
initialize: function(text, options) {
this.styles = options ? (options.styles || { }) : { };
this.callSuper('initialize', text, options);
this.initBehavior();
},

View file

@ -572,7 +572,6 @@
* @param {Object} [options] Options object
*/
initialize: function(options) {
options = options || { };
if (options) {
this.setOptions(options);
}

View file

@ -282,7 +282,7 @@
* @return {fabric.Text} thisArg
*/
initialize: function(text, options) {
options = options || { };
this.styles = options ? (options.styles || { }) : { };
this.text = text;
this.__skipDimension = true;
this.callSuper('initialize', options);

View file

@ -54,7 +54,7 @@
'skewY': 0,
'transformMatrix': null,
'charSpacing': 0,
'styles': null
'styles': {}
};
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';