Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Justify Text?

Discussion in 'UGUI & TextMesh Pro' started by ATLAS-INTERACTIVE, Apr 19, 2015.

  1. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    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://en.wikipedia.org/wiki/Typographic_alignment#Justified
    http://practicaltypography.com/justified-text.html
    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.
     
  2. Stephan-B

    Stephan-B

    Unity Technologies

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    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.

     
  3. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    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?
     
  4. Romano

    Romano

    Joined:
    Nov 27, 2013
    Posts:
    76
    Hey Labyrinth did you ever figure this out?
     
  5. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    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.
     
  6. Batoust

    Batoust

    Joined:
    Feb 24, 2016
    Posts:
    1
    Hi Labyrith, did you managed to solve your problem?
     
  7. Stephan-B

    Stephan-B

    Unity Technologies

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Updated example of text alignment options including justified text in TextMesh Pro.



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

    smetzzz

    Joined:
    Mar 24, 2014
    Posts:
    145
    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 @Labyrith-Studios@Romano ? Thanks!
     
    Last edited: Jan 20, 2017
  9. Inter-Illusion

    Inter-Illusion

    Joined:
    Jan 5, 2014
    Posts:
    597
    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).

    LineJustification.png

    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
     
  10. smetzzz

    smetzzz

    Joined:
    Mar 24, 2014
    Posts:
    145
    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. http://www.magazinedesigning.com/text-justification/ This would include kerning and hyphenation etc. Cheers.
     
  11. billcousert

    billcousert

    Joined:
    Mar 5, 2015
    Posts:
    16
    Could those who want justified text get together and crowdfund the project?
     
  12. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    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.
     
    billcousert likes this.
  13. billcousert

    billcousert

    Joined:
    Mar 5, 2015
    Posts:
    16
    Thanks!