Justify Text?

I have never needed this function until now, but I have just realised there is no Justify in the Unity UI for Text.
I may be wrong about this and have just not found it but I was hoping someone would be able to shed some light onto this, whether there is in fact a Justify Text setting or not, or if there is any workaround to trigger it.

For those who do not know what Text Justification is, please read here:

http://www.w3schools.com/cssref/css3_pr_text-justify.asp

Text Justification is the ability to automatically add spaces to text, allowing it to “block” itself out, making a paragraph appear more square.

UI.Text does not support Justfied text.

Justified text is one of the many additional text layout features offered in TextMesh Pro. TextMesh Pro even gives you the ability to control the blend between word spacing and character spacing which provides even greater control of the Justified text. This feature can been seen at 10:30 sec into this video.

TextMesh Pro also gives you the ability to use different text alignment within the same block of text using the <align=xx> tag.

Thanks, but I would rather achieve this using Built-in things, this may be a feature I want to include in an asset in the future, is there any basic script I can attach to a UI Text component/object for doing this?

Hey Labyrinth did you ever figure this out?

Unfortunately not.
I am hoping the good people at UT will add this eventually but for now I can’t see any easy way of doing it.

Hi Labyrith, did you managed to solve your problem?

Updated example of text alignment options including justified text in TextMesh Pro.

The title line is done using the <align=center>Title text rich text tag option which provides control over alignment of individual lines or paragraphs of text within the same text object.

Hi, I am looking for a simple script to justify text using the TextMesh. I bought @Stephan-B 's TextMeshPro but it has too many features for my lightweight build. How would I write a script to split a block of text into a varied line width while aligning the text to be neatly justified. I’ve been experimenting all day. Did you find a solution @ATLAS-INTERACTIVE @Romano ? Thanks!

Hi,
Coincidentally, I just finished the Text Justification, Wrapping and Overflowing for my new plugin I2 SmartEdge.

This plugin is not a replacement of the Text object, so it works as a VertexModifier and adds lots of the missing things (like animation, justification, deforms, pixel perfect, etc).

The way I do it for I2 SmartEdge, was to access the result of the textGenerator from the UI.Text.

That gave me info about each line (specially, in which character they start).
You can then parse the text, to see where the whiteSpaces are, so you could separate the words.
Because this is a VertexModifier, you have access to all the vertices, so you know where each character is located. (Every 4 vertices is a character).

With that information, you know where you lines start and end. And how many words are in each line.
You can find the min and max x of each line and you will know how much space you need to add.

Then, its just dividing it against the number of words and voila! Justification!

It can be a bit better if you also allow the characters to move a bit. That’s why in my implementation I added a factor to know how much to move the characters compared to the whole words. Also, you don’t want to move the characters at all if the space is small, so a minimum space value comes handy.

There are a few more small details you have to deal with if you are working on a unity before 5.3, but its essentially the same process.

Hope that helps you implementing your own.
Frank

Thanks for the reply @Inter-Illusion I am really looking for something simple that goes beyond just letter and word spacing. I would really need a pro level justification that you would find in a layout program like PhotoShop or InDesign. Here is what I mean. magazinedesigning.com This would include kerning and hyphenation etc. Cheers.

Could those who want justified text get together and crowdfund the project?

If you need text justification, I would suggest you take a look at TextMesh Pro which is now available from Unity and free on the Asset Store.

1 Like

Thanks!