Graphics

 View Only
  • 1.  Assigning a font to a textobject

    Posted 03-15-2012 11:07
    Hi,

    I would like to do a stupid thing by API : Change the font (wich already exist in my project) of a textobject.

    Actually, I'm doing that :

    Dim fontrouge As New XPression.xpFont

    Dim Cagnotte As New XPression.xpTextObject

    Engine.GetFontByName("Cagnotte_en_jeu_neg", fontrouge)

    Scene.GetObjectByName("Cagnotte", Cagnotte)

    Cagnotte.CurrentFont = fontrouge

    MsgBox(Cagnotte.CurrentFont.Name)


    But this not works, currentfont.name is always returning my old font name before assignement.

    Thank you.


  • 2.  RE: Assigning a font to a textobject

    Posted 03-15-2012 14:09
    No matter, I find the pb...

    You have to do Cagnotte.Text = "", then assign font, and put in your value again...

    But whyyy ?! ;)

    #XPression


  • 3.  RE: Assigning a font to a textobject

    Posted 03-16-2012 18:38
    Hi Vincent, when replace a font for text in an object you must first capture the existing text in a temporary variable and then "empty" the text in the object, set your new font and then "paste" the text back in the object.

    Here is an example of how to change the font:

    'Define temp text container

    Dim strTemp As String

    'Define a text object

    Dim TextObj As xpTextObject

    'Define Font object

    Dim FontObj As xpFont

    ' ************* FONT COLOUR CHANGE ****************************

    'Get the text object you want to change colour

    self.GetObjectByName("text", TextObj)

    'Capture current text

    strTemp = TextObj.Text

    'Get New font defined

    Engine.GetFontByName("fontrouge", FontObj)

    'Clear text in text object

    TextObj.Text = ""

    'Set new font on text object

    TextObj.CurrentFont = FontObj

    'Re-enter text in textobject

    TextObj.Text = strTemp

    'end of code

    Regards

    Jim

    #XPression