Jump to content

Word wrap algorithm


Tim_S

Recommended Posts

I was working on a user interface and needed to put text in a button. I realized I needed to word wrap the text and couldn't find a VI that already does that. The generic algorithm seems to combine words together and put in line feeds when the length is exceeded. Based on that I put together the attached (please pardon the dust). Then I started wondering if there was a better way.

 

Any thoughts?

 

Tim

Format for word wrap.vi

Link to comment

This is the one that I commonly use.

I like that implementation.

 

I took the first paragraph of text from NI's LabVIEW webpage (115 words) and put it in to a comparison of 10,000 iterations on a fresh load of LabVIEW.

bmoyer's algorithm: 15,028 msec

Tim_S's algorithm: 15,365 msec

 

Then I went tried again with the text "I'm a test":

bmoyer's algorithm: 4,688 msec

Tim_S's algorithm: 617 msec

 

I added more text from the same webpage for 284 words and wound up with:

bmoyer's algorithm: 28,519 msec

Tim_S's algorithm: 38,095 msec

Link to comment

As per text formatting utilities, gnu has fmt. Additionally, there is par. Perhaps you may consider wrapping them. AFAIR, they simply don't cope with multibyte characters (at best they treat them as independent bytes), but alas, neither LV does really.

 

But right, they count characters, they have no notion of font metrics, which is what could be asked for in an UI.

Edited by ensegre
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.