Skip to content
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

Added a justify-left option for text alignment #4369

Closed
wants to merge 2 commits into from
Closed

Added a justify-left option for text alignment #4369

wants to merge 2 commits into from

Conversation

jilster
Copy link

@jilster jilster commented Oct 2, 2017

textAlign: 'justify' gives the default style for justified text, textAlign: 'justify-left' aligns the lines with breaks and the final line to the left.

Replaces #3896, which was based on 1.x

@jilster
Copy link
Author

jilster commented Oct 2, 2017

Hm, apparently i nested too deeply in enlargeSpaces. I don't know how to fix this though, i needed the extra if statement for it to work

@blobinabottle
Copy link
Contributor

Would be awesome to get this. Will make justify useful :-)

@asturur
Copy link
Member

asturur commented Oct 5, 2017

I see i see... so now is useless ... :suspect:

@blobinabottle
Copy link
Contributor

😇 Let say it has potential

@asturur
Copy link
Member

asturur commented Oct 5, 2017

Jokes apart, i see in the code you are sort of introducing the concept of paragraph in textbox. that iText does not have.

So you are detecting the hard new lines in textbox and skip justification for them.

I have some thought about that.

  1. line that do not wrap will never justify?. How IText will behave?
  2. would be better to call it justify-wrapped because this is just justifying the wrapped lines?
    In that case Itext do not wrap will not justify but the name would sort of suggest it by itself

@jilster
Copy link
Author

jilster commented Oct 5, 2017

@asturur Thanks for preventing me from breaking our beloved fabric.js 🙏
@blobinabottle Thanks for still believing in me 😊

I forgot to check how IText would behave, and i'll admit that using this feature on IText broke it. You are right, it should be called justify-wrapped because now there are 2 options that are more logical:

  1. justify - justify all lines
  2. justify-wrapped - justify only wrapped lines

In enlargeSpaces i changed the if statement to:
if (this.textAlign === 'justify' || !this.hasOwnProperty('_textLineBreaks') || this._textLineBreaks.indexOf(i) === -1) {

Here are the scenarios i tested after my second commit:

Textbox
Lines are wrapped by _WrapText, the _textLineBreaks property is set here.
If textAlign is 'justify', all lines are justified.
If textAlign is 'justify-wrapped', lines except the ones in _textLineBreaks are justified.

IText & Text
Lines are not wrapped.
If textAlign is 'justify', all lines are justified.
If textAlign is 'justify-wrapped', all lines are still justified.

Is this ok? I don't see an easy way to determine where the user is using a linebreak manually, because IText and Text insert newlines after each line in their version of _splitTextIntoLines. This means we can only justify all lines, or none of the lines.

By the way, what can i do to stop the integration test from failing? I have to nest this deeply.

@asturur
Copy link
Member

asturur commented Oct 6, 2017

Need to download the code and give it a shot, i guess with the current code there is anyway a method to figure out what lines are hard breaked by \n without collecting them at wrap time. We have a styleMap feature that should provide this information anyway.

I'll try to find time tomorrow.

@jilster
Copy link
Author

jilster commented Oct 6, 2017

That would be great, thanks

@jilster
Copy link
Author

jilster commented Oct 18, 2017

I guess there was no time to be found haha. Is there anything i can do? Like looking into the styleMap for example?

@asturur
Copy link
Member

asturur commented Oct 18, 2017

Yes i m very loaded with things to do at work and in private life. Is a couple of weeks i m not working that much on fabricjs.
I'll be back

@jilster
Copy link
Author

jilster commented Oct 18, 2017

Ok, no rush

@jilster
Copy link
Author

jilster commented Nov 6, 2017

Continued in #4441

@jilster jilster closed this Nov 6, 2017
@jilster jilster deleted the textalign-justify branch November 6, 2017 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants