Graphics

 View Only
Expand all | Collapse all

changing a '#hastag' font in a single text object

Ross Blank

Ross Blank11-18-2015 22:35

  • 1.  changing a '#hastag' font in a single text object

    Posted 10-27-2015 23:19
    Hey Yall,

    I've been playing around with this for a while and still no luck : / I would like to replace a #hashtag in a tweet to a different color. I have been playing around in Visual logic but can only get the whole text object to change. I have tried defining string positions, based on # position and space after, but it has been inconsistent. I swear I had seen a visual basic code for this, but can't seem to find it going though the old posts. Anyone have any ideas? Visual Logic or Basic?


  • 2.  RE: changing a '#hastag' font in a single text object

    Posted 10-28-2015 01:10

    I don't think it's possible to achieve this with visual logic. With Visual Basic it is quite easy to do.

    I'm not used to programming VB anymore but from the top of my head this would be the syntax.



    dim objTxt as xpTextObject

    dim fntNormal as xpFont

    dim fntHashtag as xpFont

    ' GET THE FONT WHICH WILL BE USED FOR THE NORMAL TEXT

    engine.getFontByName("messageFont", fntNormal)

    engine.getFontByName("hashtagFont", fntHashtag)

    ' SPLIT THE MESSAGE UP USING THE SPACE

    Dim message As String() = s.Split(New Char() {" "c})

    ' CLEAR THE TEXTFIELD

    scnSelected.getObjectByName("txtTweet", objTxt)

    objTxt.Clear()

    for i=0 to message.count

    if message(i).Substring(0, 1) = "#" then

    objTxt.CurrentFont = fntHashtag

    else

    objTxt.CurrentFont = fntNormal

    end if

    next

    objTxt.AppendToLine(0, message(i) + " ")



    There might be some syntax errors in the above code but this is the theory.

    Unfortunately XPression doesn't support C# so it's a bit difficult for me.

    Hope this helps!

    Cheers,

    Kenneth


    #XPression


  • 3.  RE: changing a '#hastag' font in a single text object

    Posted 10-28-2015 22:54

    hmm got the green checkmark with some changes, but started crashing xpression if i tried to change font names, here is how i mutilated your code:



    dim Tweet as xpTextObject

    dim fntNormal as xpFont

    dim fntHashtag as xpFont

    dim i as Integer

    engine.getFontByName("Tweet Name1"�, fntNormal)

    engine.getFontByName("Tweet Name"�, fntHashtag)

    Dim message As String() = Split(New Char() {"� "c})

    Self.GetObjectByName("Tweet"�, Tweet)

    Tweet.Clear()

    for i = 0 to 140

    if message(i).Substring(0, 1) = "#"� then

    Tweet.CurrentFont = fntHashtag

    else

    Tweet.CurrentFont = fntNormal

    end if

    next

    Tweet.AppendToLine(0, message(i) + "� ")



    I got it to go green, and was able to play out the scene, but nothing changed.

    Thx again for the help, and sorry if i made some rookie changes,, I'm by no means a good coder!


    #XPression


  • 4.  RE: changing a '#hastag' font in a single text object

    Posted 10-29-2015 00:23
    I took Kenneth's idea and simplified it a bit.. Here is my script which i put in the OnSetText script event for the text object. Create two fonts, and name one HashTag and name the other NormalFont.

    `dim i as Integer

    dim str as String

    Dim message As String() = Split(Text, " ")

    for i = LBound(Message) to UBound(Message)

    if Left(message(i),1) = "#" then

    Str = Str + "{HashTag}" + Message(i) + "{NormalFont}"

    else

    Str = Str + Message(i)

    end if

    Str = Str + " "

    next

    Text = Str

    `

    #XPression


  • 5.  RE: changing a '#hastag' font in a single text object

    Posted 10-29-2015 16:35
    This works! Thanks Brian and Kenneth for the magic!

    #XPression


  • 6.  RE: changing a '#hastag' font in a single text object

    Posted 11-09-2015 23:53
    another quick update, Is it possible to also turn @user blue? when there is an @ sign? I tried, but keep doubling the text or it takes everything but the hashtags and users out

    #XPression


  • 7.  RE: changing a '#hastag' font in a single text object

    Posted 11-10-2015 13:51
    This should do it:

    `

    dim i as Integer

    dim str as String

    Dim message As String() = Split(Text, " ")

    for i = LBound(Message) to UBound(Message)

    if Left(message(i),1) = "#" then

    Str = Str + "{HashTag}" + Message(i) + "{NormalFont}"

    elseif Left(message(i),1) = "@" then

    Str = Str + "{UserName}" + Message(i) + "{NormalFont}"

    else

    Str = Str + Message(i)

    end if

    Str = Str + " "

    next

    Text = Str

    `

    #XPression


  • 8.  RE: changing a '#hastag' font in a single text object

    Posted 11-10-2015 18:51
    ahhh else if!!! I'm learning this slowly.. Thanks Brian!

    #XPression


  • 9.  RE: changing a '#hastag' font in a single text object

    Posted 11-17-2015 18:25
    So this works great, mostly. It's acting a little strange sometimes.

    It seems to be deleting the space before the hashtag and username, but only sometimes.

    Besides the spaces it works great in sequencer, but when i check the different datalinq keys in layout, if there is a hashtag or @ at the start of the tweet, it changes the default font to the blue. Any ideas? and thx again!

    #XPression


  • 10.  RE: changing a '#hastag' font in a single text object

    Posted 11-18-2015 01:42
    so it deletes the space, only after a period,, i think

    #XPression


  • 11.  RE: changing a '#hastag' font in a single text object

    Posted 11-18-2015 22:21
    I'm not seeing the issue with the period. Maybe you could paste an example string that produces the issue to the forum?

    #XPression


  • 12.  RE: changing a '#hastag' font in a single text object

    Posted 11-18-2015 22:27
    dim i as Integer

    dim str as String

    Dim message As String() = Split(Text, " ")

    for i = LBound(Message) to UBound(Message)

    if Left(message(i),1) = "#" then

    Str = Str + "{FSTWEETBLUE}" + Message(i) + "{FSTWEET}"

    else

    Str = Str + Message(i)

    end if

    Str = Str + " "

    next

    Text = Str

    #XPression


  • 13.  RE: changing a '#hastag' font in a single text object

    Posted 11-18-2015 22:35


  • 14.  RE: changing a '#hastag' font in a single text object

    Posted 11-20-2015 02:40
    Sorry Ross, I still haven't been able to reproduce this.. Even tried using the same tweet shown in your image.

    #XPression


  • 15.  RE: changing a '#hastag' font in a single text object

    Posted 11-20-2015 02:45


    Here is a better example of my error, It breaks the bounding box, and i think it has something to do with the deleted space. cause in the mdb file it has a space. I might have been wrong about it being only after a period.

    #XPression


  • 16.  RE: changing a '#hastag' font in a single text object

    Posted 11-20-2015 02:47
    Can you post the actual text of the tweet as it is in your mdb file?

    #XPression


  • 17.  RE: changing a '#hastag' font in a single text object

    Posted 11-20-2015 02:48
    Could there be a carriage return in the tweet? Maybe the carriage returns are being stripped out..

    #XPression


  • 18.  RE: changing a '#hastag' font in a single text object

    Posted 11-23-2015 02:54




    Here it is breaking after a space. The second Image is our MDB with the actual text. I checked and there is no carriage return. :(

    #XPression


  • 19.  RE: changing a '#hastag' font in a single text object

    Posted 11-23-2015 11:41
    Do you have the Word-Wrap enabled in your textfield?

    Because I have had issues too when trying to do more or less the same with the wordwrap enabled. But in my case it was putting the words somewhere else in the textfield.

    I would have to look how I solved that.

    #XPression


  • 20.  RE: changing a '#hastag' font in a single text object

    Posted 11-24-2015 00:37
    yeah i need the word-wrap : (

    #XPression