Graphics

 View Only
  • 1.  An elegant way to deal with font resizing?

    Posted 06-20-2018 00:16
    Right, so... throughout this package I am working on, the request is to have text sizes increase as the number of rows decreases, to help fill the newly negative space. The only way I have been able to do this (since scaling a text object does not yield an attractive result) is to make duplicate text objects with different size fonts assigned to them, and toggle their visibility as the number of rows in a graphic changes.

    This works, but MAN is it a ton of work to set up, as I have to link the original published text to each of its unpublished duplicates, assign text highlighting logic to the lot, and so forth. When I need 4 different text sizes on an element with 2-8 lines of text, it gets tedious pretty fast. I had one element that scaled from 10 rows / 6 columns. to 4 rows / 1 column, and everything in between, and THAT took me days to configure.

    I have to believe there is an easier way... there just has to be. I already made a suggestion for how this could be implemented in VL - (Scene fonts would need to made available as function blocks one could feed into an input selector) though that never received any feedback, but for the moment, I can find no other way to do this. I imagine there is some way to script it, but I my scripting skills / knowledge is precisely 0, and TBH, I greatly prefer the immediate feedback and ease of troubleshooting VL offers. Still, I'd love to know how the rest of you lot tackle this kind of thing, as I am sure it's a fairly common functionality request.

    Cheers
    - Willie


  • 2.  RE: An elegant way to deal with font resizing?

    Posted 06-20-2018 01:34
    I feel for you Willie. It would be nice if they added a TEXT FIELD object where you could define the area of the TEXT FIELD and then when the text reaches the limit it would automatically start to get smaller. This would be a wonderful addition to future versions of Xpression.
    #XPression


  • 3.  RE: An elegant way to deal with font resizing?

    Posted 06-20-2018 14:27

    Since version 6.7, TextWithTags is available in VL : you won't need to duplicate text for each different size of fonts .

    Here is an example where font :
    - "Font_Big" is used for 1 or 2 lines of text
    - "Font_Normal" is used for 3 or 4 lines of text
    - "Font_Small" is used for 5 or 5 lines of text




    Text "TextPublished" is hidden and is the original published text object to fill text with (can be multi line).
    "Text_OneLine" is hidden too, has the same font as "TextPublished" and is filled with some text (one line only) .

    To get the number of lines in the text : divide the bounding height of the two text objects
    This number is used to select font tag name to send to "TextWithFlags" property


    Same behavior can be done with script (with no need to duplicate text object at all ) .
    See OnSetText event :
    Dim parts As String() = Text.Split(vbnewline)
    ' parts.Length is the number of lines

    Dim fontName as string


    select case parts.Length
    case 1 to 2
    fontName = "Font_Big"
    case 3 to 4
    fontName = "Font_Normal"
    case else
    fontName = "Font_Small"
    End Select

    Self.TextWithTags = "{" + fontName + "}" + Text



    If you have more than one text that should have the same behavior, you can use global script methods [ from menu · Edit | Scripting | Global Scripts Method Editor ]
    This is usefull when you do the same kind of things multiple times.
    This make easier to maintain, and can be reusable.

    Here : we define a global method :
    sub ChangeFontFromRowCount(Self as xpTextObject, Byref Text as String)

    Dim parts As String() = Text.Split(vbnewline)

    Dim fontName as string


    select case parts.Length
    case 1 to 2
    fontName = "Font_Big"
    case 3 to 4
    fontName = "Font_Normal"
    case else
    fontName = "Font_Small"
    End Select



    Self.TextWithTags = "{" + fontName + "}" + Text
    end sub


    On each text object that need this script , OnSetText event will be :
    ChangeFontFromRowCount(Self, Text)

    Global methods are available since version 6.7 too.

    Hope it helps.


    #XPression


  • 4.  RE: An elegant way to deal with font resizing?

    Posted 06-20-2018 17:57

    Your VL setup is interesting, but I don't understand how those 3 string blocks are linked to different point sizes of font, is it as simple as putting the name of the desired font in curly brackets for the block's value? Also, in my setup the functionality (per client request) is to have the number of stat rows driven by numerical input from the operator through a published text object. So my logic evaluates this number, and feeds input selectors which re-position the rows accordingly, which looks like the first attached image, You can see here too I control the visibility of the duplicated text objects, what I would love to ultimately do is replace that with some variation of your example, so I can avoid things like the second uploaded image.


    #XPression


  • 5.  RE: An elegant way to deal with font resizing?

    Posted 06-20-2018 20:30
    Oh my ! How can you deal with so much items !

    Your VL setup is interesting, but I don't understand how those 3 string blocks are linked to different point sizes of font, is it as simple as putting the name of the desired font in curly brackets for the block's value?
    Almost : when you assign TextWithTag = "{fontname}my text to display" : it will display the text "my text to display" using the font named fontname
    In my example i've got 3 fonts named Font_Big , Font_Normal and Font_Small each of them has different predefined size.

    I think you should use some script to change size of a global font that is used for all your text , this will avoid you all the pain of Visual Logic and it's hundreds of blocks.
    on the OnSetText event of your numerical input try something like :
    Dim myfont as xpFont

    if Engine.GetFontByName("Font_Common", myFont) then
    select case Text ' Text contains the number of rows
    case "1"
    myFont.Size = 90
    case "2"
    myFont.Size = 80
    case "3"
    myFont.Size = 70
    case "4"
    myFont.Size = 50
    case else
    myFont.Size = 30
    end select

    end if

    Where Font_Common is the name of the font

    See a minimal project attached : [ATTACH]n16379[/ATTACH]

    #XPression


  • 6.  RE: An elegant way to deal with font resizing?

    Posted 06-20-2018 20:53
    The problem with changing the fonts globally would be the properties of a font being changed on an instance of one scene making that change to the same font in another scene in which that change is not needed.

    So then, in your VL example, it's not pure VL, but a combination of VL and script? I have zero scripting skills, and until I acquire some, I want to minimize its usage in my scenes, as I will be unable to troubleshoot and could paint myself into a corner.

    I'll D/L your project now and have a look in a few.

    Thanks for you help!
    #XPression


  • 7.  RE: An elegant way to deal with font resizing?

    Posted 06-27-2018 18:25

    Hey Willie, would something like this work for you? It could be expanded further of course.


    #XPression


  • 8.  RE: An elegant way to deal with font resizing?

    Posted 06-28-2018 22:02
    I don't think it would, Simon, unless I'm missing something... that looks to be making changes according to the length of text, where as I am looking to increase the font size of a given text based on the number of rows present. So, a template at maximum has 8 rows, and the user elects to only have 6 rows present or 5 or 4, I want the font size of the still visible text to increase in order to help fill the newly negative space.

    You know how you can change the material of an object by connecting its 'faces' value to the out of an Input Selector, and have materials assigned to that selectors inputs, with the index being fed by (for example) a text object? I want to do something along those lines, but with with fonts in place of materials.
    #XPression


  • 9.  RE: An elegant way to deal with font resizing?

    Posted 06-30-2018 14:27
    So then, in your VL example, it's not pure VL, but a combination of VL and script?

    it's pure VL.

    See another project sample where user select the number of rows to display : [ATTACH]n16449[/ATTACH]

    With 1 row :


    With 4 rows :


    #XPression


  • 10.  RE: An elegant way to deal with font resizing?

    Posted 07-02-2018 17:17
    Ahh got it, that makes sense. It will be a HUGE timesaver in the future
    #XPression