Graphics

 View Only
  • 1.  Scripting Font Changes

    Posted 10-01-2012 22:55
    As one who likes to automate most small tasks without OverDrive, one of them has stumped me. We're building election results templates, and I would like the fonts to change based on certain factors.

    First, if a candidate is republican, the text object for their name should be red instead of white, blue for demos, yellow for I's, etc...

    If a race has a declared winner, a "winner tag" is given to a candidate via our xml DataLinq. That already enables a checkmark image, but I would like to to change their percentage image to green. I.E., they win with 55% of the votes, the visual "55%" changes from white to green.

    I haven't found a "SetFont" function yet in the SDK help file, and I'm not sure one exists. I see it playing out one of two ways. One, the "if R, then SetFont.CandidateR." The other, "if R, then SetFontMaterial(0, Red Material)." Not sure which way would be more feasible, but I have all of the fonts made for color, as well as materials that can be set. I just don't know the script.

    Here's how I see it in my head:

    dim Name as xpTextObject

    dim Party as xpTextObject

    dim WinTag as xpTextObject

    dim Perc as xpTextObject

    dim RFont as xpFont

    dim BFont as xpFont

    dim YFont as xpFont

    dim GFont as xpFont

    dim WFont as xpFont

    dim i as Integer

    for i = 1 to 5

    Self.GetObjectByName("Candidate " & i, Name)

    Self.GetObjectByName("Party " & i, Party)

    Self.GetObjectByName("Winner " & i, WinTag)

    Self.GetOBjectByName("Perc Total " & i, Perc)

    Self.GetFontByName("Red Font", RFont)

    Self.GetFontByName("Blue Font", BFont)

    Self.GetFontByName("Yellow Font", YFont)

    Self.GetFontByName("Green Font," GFont)

    Self.GetFontByName("White Font," WFont)

    If InStr(Party.Text, "R") = 1 then

    Candidate.SetFont(RFont)

    End If

    'etc for the other party colors

    If Len(WinTag.Text) > 0 then

    Perc.SetFont(GFont)

    else

    Perc.SetFont(WFont)

    End If

    next i


    Thoughts on how this script (which compiles perfectly in my head ;) ) would work in the real world?


  • 2.  RE: Scripting Font Changes

    Posted 10-02-2012 22:19
    Hi,

    First of all, do Engine.GetFontByName("Red Font", RFont) instead of Self.GetFontByName("Red Font", RFont) and move this portion of code above the for loop.

    Because fonts are globals to the project.

    And for colors do :

    Dim temp as string = nothing

    If InStr(Party.Text, "R") = 1 then

    temp = Candidat.Text

    Candidate.Text = ""

    Candidate.CurrentFont = RFont

    Candidat.Text = temp

    End If


    #XPression


  • 3.  RE: Scripting Font Changes

    Posted 10-04-2012 22:10
    Thanks for your help! It works great, and I was able to adapt it to a few other things we've been looking to do font-wise.

    #XPression


  • 4.  RE: Scripting Font Changes

    Posted 04-02-2013 17:39
    I know this post is rather old but I'd like to add that you can use TextWithTags to change the fonts as well. It's really easy. The tags look like {FONT NAME} or {FONT INDEX}.

    examples:

    yourTextObject.textwithtags="{Red Font} (R) {White Font} Jack Jornson"

    yourTextObject.textwithtags="{1} (R) {0} Jack Jornson"

    #XPression


  • 5.  RE: Scripting Font Changes

    Posted 06-07-2015 07:05
    Try to format the colors as descirbed in this thread, but it does not work for me this way:

    dim PlusMinus as xpTextObject

    dim RED as xpFont

    dim GREEN as xpFont

    dim BLACK as xpFont

    dim i as Integer

    for i = 1 to 10

    Self.GetObjectByName("PlusMinus " & i, PlusMinus)

    Engine.GetFontByName("PLUS_MINUS_UNDER", RED)

    Engine.GetFontByName("PLUS_MINUS_OVER", GREEN)

    Engine.GetFontByName("PLUS_MINUS", BLACK)

    if cInt(PlusMinus.text) >= 0 then

    PlusMinus.CurrentFont = GREEN

    else if cInt(PlusMinus.text) = 0 then

    text = "{PLUS_MINUS_OVER}" & text

    else if cInt(text)
    #XPression


  • 6.  RE: Scripting Font Changes

    Posted 06-07-2015 07:13
    Look at my first answer of this thread... You have to empty your text, change the current font and after, set your text again in the textobject.

    #XPression


  • 7.  RE: Scripting Font Changes

    Posted 06-07-2015 10:13
    Then it nearly works:

    dim PlusMinus as xpTextObject

    dim RED as xpFont

    dim GREEN as xpFont

    dim BLACK as xpFont

    dim i as Integer

    for i = 1 to 10

    Self.GetObjectByName("PlusMinus " & i, PlusMinus)

    Engine.GetFontByName("PLUS_MINUS_UNDER", RED)

    Engine.GetFontByName("PLUS_MINUS_OVER", GREEN)

    Engine.GetFontByName("PLUS_MINUS", BLACK)

    dim temp as string = nothing

    if cInt(PlusMinus.text) >= 0 then

    temp = PlusMinus.text

    PlusMinus.text = ""

    PlusMinus.CurrentFont = GREEN

    PlusMinus.text = "" & temp

    else if cInt(PlusMinus.text) = 0 then

    temp = PlusMinus.text

    PlusMinus.text = ""

    PlusMinus.CurrentFont = GREEN

    PlusMinus.text = "" & temp


    #XPression


  • 8.  RE: Scripting Font Changes

    Posted 06-08-2015 14:28
    [QUOTE]just need to get a + sign in before the green text

    if cInt(PlusMinus.text) >= 0 then

    temp = PlusMinus.text

    PlusMinus.text = ""

    PlusMinus.CurrentFont = GREEN

    PlusMinus.text = "" & temp

    Simple fix. You're setting the text in the final line PlusMinus.text = "" & temp

    Change that to PlusMinus.text = "" & "+ " & temp

    #XPression


  • 9.  RE: Scripting Font Changes

    Posted 06-08-2015 15:18
    [QUOTE]Change that to PlusMinus.text = "" & "+ " & temp

    If I change to "+", I get lots of + signs and if I use "+ " I get af space between the + sign and the number.

    Can I get rid of that space between or how do I just insert 1 + sign?

    #XPression


  • 10.  RE: Scripting Font Changes

    Posted 06-09-2015 06:43
    Try this :

    PlusMinus.text = Chr(43) & temp

    #XPression