-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal for different lineJustify. #4437
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -334,7 +334,7 @@ | |
this._splitText(); | ||
this._clearCache(); | ||
this.width = this.calcTextWidth() || this.cursorWidth || MIN_TEXT_WIDTH; | ||
if (this.textAlign === 'justify') { | ||
if (this.textAlign.indexOf('justify') !== -1) { | ||
// once text is misured we need to make space fatter to make justified text. | ||
this.enlargeSpaces(); | ||
} | ||
|
@@ -348,6 +348,9 @@ | |
enlargeSpaces: function() { | ||
var diffSpace, currentLineWidth, numberOfSpaces, accumulatedSpace, line, charBound, spaces; | ||
for (var i = 0, len = this._textLines.length; i < len; i++) { | ||
if (i === len - 1 || this.isEndOfWrapping(i)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok here needs a this.textAlign !== 'justify' && ( ..... ) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i still think this change is needed. justify-left, jsutify-right, justify-center, this thing here should change that we do not want the old plain Who built an app over 2.0b7 or earlier, does not want to see old JSON saved with plain justify loaded differently just because we think is better to have last line not justified. In this way we give an option to everyone at expense of littled added complexity, and we do not break old stuff. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the late response. Yes, i agree, backwards compatibility is important. Will you change it or should i? |
||
continue; | ||
} | ||
accumulatedSpace = 0; | ||
line = this._textLines[i]; | ||
currentLineWidth = this.getLineWidth(i); | ||
|
@@ -370,6 +373,15 @@ | |
} | ||
}, | ||
|
||
/** | ||
* Detect if the text line is ended with an hard break | ||
* text and itext do not have wrapping, return false | ||
* @return {Boolean} | ||
*/ | ||
isEndOfWrapping: function(/* lineIndex */) { | ||
return false; | ||
}, | ||
|
||
/** | ||
* Returns string representation of an instance | ||
* @return {String} String representation of text object | ||
|
@@ -855,7 +867,7 @@ | |
left += charBox.kernedWidth - charBox.width; | ||
} | ||
boxWidth += charBox.kernedWidth; | ||
if (this.textAlign === 'justify' && !timeToRender) { | ||
if (this.textAlign.indexOf('justify') !== -1 && !timeToRender) { | ||
if (this._reSpaceAndTab.test(line[i])) { | ||
timeToRender = true; | ||
} | ||
|
@@ -938,6 +950,12 @@ | |
if (this.textAlign === 'right') { | ||
return this.width - lineWidth; | ||
} | ||
if (this.textAlign === 'justify-center' && this.isEndOfWrapping(lineIndex)) { | ||
return (this.width - lineWidth) / 2; | ||
} | ||
if (this.textAlign === 'justify-right' && this.isEndOfWrapping(lineIndex)) { | ||
return this.width - lineWidth; | ||
} | ||
return 0; | ||
}, | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was not replaced in the whole code in the other PR,