Graphics

 View Only
  • 1.  Set 2 line text limit with word wrap enabled

    Posted 07-04-2018 23:55
    Hello!

    I am trying to make a lower third in which there is a text field that expands to the right with word wrap enabled and I need it to autosqueeze text after the second line has reached the word wrap bounds.

    Any help would be appreciated!

    Running Xpression 7.0 Build 3820


  • 2.  RE: Set 2 line text limit with word wrap enabled

    Posted 07-06-2018 18:29

    Surprisingly tricky! Here's a sample project that I think does what you need: https://drive.google.com/open?id=1g7l-nBuXYvadIjtVStZEtX3EORbW-7_a

    The formatting is done with a script on the scene's OnOnline/OnPreviewRender events. It's a little bulky, so hopefully anyone that knows a cleaner way to do this will chime in. Below is the script itself -- you'd just want to enter the name of the text object you want in the first line and how long your word wrap/autosqueeze limit is in the second.

    '***ENTER INFO HERE***
    dim textName as string = "Text"
    dim textWidth as decimal = 1000
    '***ENTER INFO HERE***

    'Gets text object
    dim text as xpBaseObject
    self.getObjectByName(textName,text)

    'Turns off limits during process
    text.autoSqueeze = false
    text.wordWrap = false

    'Does nothing if short, single line of text
    if text.boundingBox.width < textWidth then

    'Turns on word wrap for two lines
    elseif text.boundingBox.width > textWidth and text.boundingBox.width < textWidth*2 then
    text.wordWrap = true
    text.wordWrapWidth = textWidth

    'Handles text that would be longer than two lines
    elseif text.boundingBox.width > textWidth*2 then
    'Gets info on text string and splits it up in to each word
    dim maxWid as decimal = text.boundingBox.width
    dim splits() as string = split(text.text," ")
    text.text = ""
    dim currentText as string = ""
    dim index as integer = 0

    'Rebuilds text string in to two roughly equal lines
    for i as integer = 0 to splits.length - 1
    currentText = text.text

    text.text = text.text & splits(i) & " "
    if text.boundingBox.width > maxWid * .5 then
    text.text = currentText
    index = i
    exit for
    end if
    next

    text.text = text.text & vbCrLf

    for i as integer = index to splits.length - 1
    text.text = text.text & splits(i) & " "
    next

    'Sets autoSqueeze for new text
    text.autoSqueeze = true
    text.autoSqueezeWidth = textWidth
    end if


    #XPression


  • 3.  RE: Set 2 line text limit with word wrap enabled

    Posted 07-08-2018 16:03

    Thank you Greg for sharing this script.

    It works well, although sometimes the text extends to more than 2 lines.

    Here is a modified version of your script that :
    - Check that the maximum number of lines don't overflow
    - Allow to input the maximum number of lines the user want to apply


    '***ENTER INFO HERE***
    dim textName as string = "Text"
    dim textWidth as decimal = 1000
    dim maxNbLines as integer = 2
    '***ENTER INFO HERE***

    'Gets text object
    dim text as xpBaseObject
    self.getObjectByName(textName,text)

    'Turns off limits during process
    text.autoSqueeze = false
    text.wordWrap = false

    'Does nothing if short, single line of text
    if text.boundingBox.width < textWidth then return

    'Handles text that would be longer than maxNbLines lines

    'Gets info on text string and splits it up in to each word
    dim maxWid as decimal = text.boundingBox.width
    dim splits() as string = split(text.text," ")
    text.text = ""
    dim currentText as string = ""
    dim nbLines as integer = 0
    dim indexLine as integer = 1

    'Rebuilds text string in to "equal" lines and no more than maxNbLines Lines
    for i as integer = 0 to (splits.length - 1)

    dim t as string = splits(i)
    text.text = text.text & t & " "
    if text.boundingBox.width > math.max(maxWid/maxNbLines, textWidth) then

    if indexLine < maxNbLines then
    text.text = currentText & vbCrLf & t & " "
    indexLine = indexLine + 1
    end if
    end if

    currentText = text.text
    next

    if text.boundingBox.width > textWidth then
    'Sets autoSqueeze for new text
    text.autoSqueeze = true
    text.autoSqueezeWidth = textWidth
    end if



    With this new script, there is a glitch : first lines are often smaller than the last ones , that's not very natural or pleasant to read .
    Example with 3 lines of text :


    Before applying text.autoSqueeze = true , if we can parse again the text with the new current boxingbox.width , this seems to be better most of the time :




    See project sample with this method implemented , where user can input the maximum number of lines used : [ATTACH]n16509[/ATTACH]
    It requires Xpression version 6.7 since part of the code has been put into global functions .

    Sure this can be improved , any suggestions are welcome .


    #XPression


  • 4.  RE: Set 2 line text limit with word wrap enabled

    Posted 01-09-2020 21:01

    I know this is a old thread, but I have been trying to implement a similar script to solve an issue and am running into problems.

    I have a significant amount of visual logic running, and as a result, this script doesn't work for (in part because the context of the text field I need to wrap is dynamically set via visual logic). I have tried to replicate the script, or my own variant of it in visual logic, but have encountered other issues, such as using the logic block to find a " " character to split lines doesn't return correctly if the start point if after the last space character. Also, the concatenate block does not allow me to add a CR/LF code into the text.

    Is there an easier way to constrain a text box to two lines high? Or does someone have a good example of a visual logic approach to this?

    In terms of pseudo code, I see it like this:

    If text.width < box.width, exit

    If text.width < box.wdth * 1.1, autosqueeze = true  'allows a small amount of squeeze on one line

    If text.width > box.width * 1.1, find split point at first line length or midpoint depending on length, insert a CR to make it two lines

    Any help appreciated!

    Thanks, Dave


    #XPression