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

Feature request: Different types of text justification #4361

Closed
jilster opened this issue Sep 29, 2017 · 8 comments
Closed

Feature request: Different types of text justification #4361

jilster opened this issue Sep 29, 2017 · 8 comments

Comments

@jilster
Copy link

jilster commented Sep 29, 2017

With text justification, there are multiple ways to handle the alignment of the last line.

  • Left justify: The last line is aligned left
  • Right justify: The last line is aligned right
  • Center justify: The last line is centered
  • Full justify: The last line is justified

See: https://en.wikipedia.org/wiki/Typographic_alignment#Examples

fabric.js uses full justify, see this example and check the last line:
http://jsfiddle.net/rkuv7my0/1/

Would it be possible to make this a property in fabric.js?

@asturur
Copy link
Member

asturur commented Sep 30, 2017

Is not hard to do.
You can do it overriding a bit the code.
I have actually no time to make a prototype

@jilster
Copy link
Author

jilster commented Sep 30, 2017

I found a pull request covering the same question: #3896

Would you be interested in me continuing this? it would need some changes:

  • Based on Fabric 2 beta instead of 1.x
  • Include SVG export functionality
  • Instead of overwriting default behaviour, adding new options for the textAlign property: 'justify' (current full justify, for backwards compatibility), 'justify-left', 'justify-right' and 'justify-center'

@asturur
Copy link
Member

asturur commented Sep 30, 2017

it mostly depends how much code is. if you want to give a shot do it.

keep it simple, slim, and check current fabricjs lint rules.

I cannot guarantee i ll merge it

@jilster
Copy link
Author

jilster commented Oct 2, 2017

I am a bit stuck, i can't figure out how to find out which linebreaks are inserted by the user, _splitTextIntoLines inserts new lines as well. Do you have any ideas? if not, i'll just carry on trying.

@asturur
Copy link
Member

asturur commented Oct 2, 2017

there are 2 versions of _splitTextIntoLines, one for the text and one for the textbox.
Once splitted you have an array of lines that is called _textLines if i remember good, and they get rendered one by one.

@jilster
Copy link
Author

jilster commented Oct 2, 2017

Thanks, that pushed me in the right direction, i'm nearly done now

@jilster
Copy link
Author

jilster commented Oct 2, 2017

I decided to only add the 'justify-left' option. That and the default justify style are probably the only ones people will be using anyways. This way i was able to keep it very simple, only a couple of lines were added and changed and it is backwards compatible. There was apparently no need to change the toSVG function. I tested it and it already works.

If there are people that would like 'justify-right' or 'justify-center' i am willing to make those as well, but i think it would make the code more complex.

Here is my pull request: #4369

@jilster
Copy link
Author

jilster commented Nov 6, 2017

Continued in #4441

@jilster jilster closed this as completed Nov 6, 2017
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

No branches or pull requests

1 participant