Author Topic: Font Word Wrapping Chopping up Words  (Read 11459 times)

NaxIonz

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 70
    • View Profile
Font Word Wrapping Chopping up Words
« on: October 21, 2013, 04:32:05 PM »
Is there a way to prevent the word wrapping from chopping a word up? I have a shrink to fit UILabel, and sometimes, it thinks I'd want the last letter of the word to be on a second line.

Not Helpful.

Sometimes I have two words, so it works, sometimes I have one word that does not get chopped.
But sometimes, I have a word that has it's last letter severed from it, and toss down below :-(

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Font Word Wrapping Chopping up Words
« Reply #1 on: October 21, 2013, 04:50:00 PM »
If it's a long word and it doesn't fit onto a single line, then it will be split up into two based on what actually fits. You can always change the label to Shrink Content instead.

NaxIonz

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: Font Word Wrapping Chopping up Words
« Reply #2 on: October 22, 2013, 08:40:21 AM »
If it's a long word and it doesn't fit onto a single line, then it will be split up into two based on what actually fits. You can always change the label to Shrink Content instead.

It already is on Shrink to Fit.
As mentioned above, for 98% of the text put into the UILabel it works perfect. It either shrinks the text just enough to place on one line, or it splits the two words onto two lines.

But in some cases, it starts chopping up the word. I am not sure when I actually would ever want/need a word to be split up. (And if I did, even in literature, there are many guidelines as to how/when a word should ever be split across lines)

I guess if this is expected behavior, I can dig into the font code and see if I can prevent this.

MrTact

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 32
    • View Profile
Re: Font Word Wrapping Chopping up Words
« Reply #3 on: February 27, 2014, 12:12:07 PM »
This is still occurring as of 3.5. I spent some time digging into it but was not able to suss it out.

Some observations:
  • Interestingly, the only difference between these two labels is the one that wraps incorrectly is wider. Both are set to ShrinkContent and MaxLines = 0
  • Seems to happen more with wider typefaces. (This one is Orbitron Black, an open-source typeface from The League of Movable Type
  • It appears that the problem is with NGUIText.WrapText returning true because offset has reached textLength. It should have returned false, so the UILabel would ratchet the point size down and try to measure the text again.

I can make this test scene showing the issue available as a unity package, if that would be helpful.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Font Word Wrapping Chopping up Words
« Reply #4 on: February 27, 2014, 04:56:47 PM »
I would very much appreciate a repro case for this one, yes. :)

Please send a download link to support at tasharen.com.

tranvv

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Font Word Wrapping Chopping up Words
« Reply #5 on: April 02, 2014, 03:46:35 PM »
I just ran into this problem as well, has there been a fix for it yet?
My UILabel is set to ShrinkContent with Max Lines set to 0.

My label contains a single word and the last character has been moved to the 2nd line with these settings.

If I set Max Lines to 1, then all of it fits on 1 line correctly. However, I really want to have multiple lines.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Font Word Wrapping Chopping up Words
« Reply #6 on: April 02, 2014, 03:50:26 PM »
I never got a repro case.

tranvv

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Font Word Wrapping Chopping up Words
« Reply #7 on: April 02, 2014, 04:13:30 PM »
I'll try to make one for you real quick

tranvv

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Font Word Wrapping Chopping up Words
« Reply #8 on: April 02, 2014, 04:26:34 PM »
In an empty scene, create a new 2d ui.
Add a new label via NGUI Create menu option
Set Font to Unity Arial
Set Dimensions Y value to 100
Erase 'New Label' and just type a single long word in.

Notice it starts to wrap to the 2nd line.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Font Word Wrapping Chopping up Words
« Reply #9 on: April 02, 2014, 06:00:36 PM »
No issues following your instructions. It never wraps to the 2nd line. It shrinks the text instead. What version are you on?

sjsivak

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Font Word Wrapping Chopping up Words
« Reply #10 on: April 04, 2014, 02:12:59 PM »
I am seeing this as well. It seems that the UILabel will just not shrink it beyond a certain amount and it just spills over the remaining into the next line. We are using Unity 4.3.2f1 and NGUI 3.0.5.

I was able to fix it by making sure the max lines was set to 1, but for anything over a line it is still a problem.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Font Word Wrapping Chopping up Words
« Reply #11 on: April 04, 2014, 10:32:19 PM »
Well that would be why.

Please always update to the latest version before posting about issues. You will save us both time.

AlexGav

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Font Word Wrapping Chopping up Words
« Reply #12 on: May 01, 2014, 11:29:52 AM »
I am having the same problem and am using NGUI 3.5.8 and Unity 4.3.4f1.
After debugging the NGUIText script a bit I noticed that the following method:
static void ReplaceSpaceWithNewline (ref StringBuilder s)
is only adding the end line character if the last character in the StringBuilder is an empty space character.
And that was not the case because when a new word was added to the builder it contained a space in front of it, not in the back. Thus at the end of the builder, when there was no more space on the respective line, the last character was a letter and not an empty space character.
So, as a quick fix I have shifted the start and end indexes when creating the substring used to put into the builder by 1 through the offset. And therefore had a space at the end always, which in turn could be replaced by a new line character when needed.
In short, I added 1 to the "offset" at line 861 and 868.
My post is not meant to be a final solution to the problem, just a suggestion to where to dig in a bit.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Font Word Wrapping Chopping up Words
« Reply #13 on: May 02, 2014, 08:15:37 AM »
Line 861 for me already has +1:
  1. int end = offset - start + 1;
Same with line 868:
  1. start = offset + 1;

AlexGav

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Font Word Wrapping Chopping up Words
« Reply #14 on: May 02, 2014, 08:21:59 AM »
That's interesting, mine did not, but I am glad that I've reached the same solution :)
Perhaps some of the other guys that have complained could look into it as well.