Multiple fonts in a text object

I am reading some text from a SQlite database and I want some words in that text rendered with a different font on the user screen. I digged all the places, but couldn’t find a practical solution for this. What I want is something so simple like:

These are words in Helvetica --otherfont begins-- whereas these are Arial --otherfont ends-- and I can continue my sentence in Helvetica.

It is so sad that some easy things become such a nightmare whereas some difficult tasks take only a couple of lines to code with Corona.

Thanks in advance. [import]uid: 192663 topic_id: 34788 reply_id: 334788[/import]

Well i think the easiest way would be to create mutiple text objects with different fonts, I suppose you could build a function to do that for you…if you need that on lots of places.

OR you could do a html file and have a webview in your app

:slight_smile: [import]uid: 134049 topic_id: 34788 reply_id: 138281[/import]

Anakta thanks for your reply.
Generating a html was my first choice, but as webview doesn’t work on the simulator I skipped that.

Building a function to divide the text into its every single word seems the only solution for me. I have to split the sentence word by word so that I can find the x,y coordinates of the last word where I will change the font.

Also I am giving all these efforts to underline a specific word in a text object, which would also be so simple with html code. [import]uid: 192663 topic_id: 34788 reply_id: 138289[/import]

The thing about display objects is that they only support one set of options. This makes them really simple to use (a plus!) but it also makes them a building block (which means you need code to make them do complicated things)

Multifont support may sound easy if you’re using Word every day, but in any programming language, let alone Lua, it’s actually a complex interpreter that needs to look for control codes in your text to figure out when to change options and how.

That being said, take a look at Text Candy; I think they may have a solution? [import]uid: 41884 topic_id: 34788 reply_id: 138290[/import]

Yes richard9 you are right.

Anyway it took my whole day, but now complete.
What I did was:

  • create a new font which is already underlined using “Type Light” font editor
  • break down the sentence into words by modifying the code provided at:
    http://developer.coronalabs.com/code/simple-string-split-function-method
  • find the x,y coordinates of each word by a method like:
    lastX = lastX + object.contentWidth
  • do whatever I do with each word, like changing the font, color or underlining
  • add each text object into a display group and show it on the screen

Thanks guys for your help. [import]uid: 192663 topic_id: 34788 reply_id: 138445[/import]

Well i think the easiest way would be to create mutiple text objects with different fonts, I suppose you could build a function to do that for you…if you need that on lots of places.

OR you could do a html file and have a webview in your app

:slight_smile: [import]uid: 134049 topic_id: 34788 reply_id: 138281[/import]

Anakta thanks for your reply.
Generating a html was my first choice, but as webview doesn’t work on the simulator I skipped that.

Building a function to divide the text into its every single word seems the only solution for me. I have to split the sentence word by word so that I can find the x,y coordinates of the last word where I will change the font.

Also I am giving all these efforts to underline a specific word in a text object, which would also be so simple with html code. [import]uid: 192663 topic_id: 34788 reply_id: 138289[/import]

The thing about display objects is that they only support one set of options. This makes them really simple to use (a plus!) but it also makes them a building block (which means you need code to make them do complicated things)

Multifont support may sound easy if you’re using Word every day, but in any programming language, let alone Lua, it’s actually a complex interpreter that needs to look for control codes in your text to figure out when to change options and how.

That being said, take a look at Text Candy; I think they may have a solution? [import]uid: 41884 topic_id: 34788 reply_id: 138290[/import]

Yes richard9 you are right.

Anyway it took my whole day, but now complete.
What I did was:

  • create a new font which is already underlined using “Type Light” font editor
  • break down the sentence into words by modifying the code provided at:
    http://developer.coronalabs.com/code/simple-string-split-function-method
  • find the x,y coordinates of each word by a method like:
    lastX = lastX + object.contentWidth
  • do whatever I do with each word, like changing the font, color or underlining
  • add each text object into a display group and show it on the screen

Thanks guys for your help. [import]uid: 192663 topic_id: 34788 reply_id: 138445[/import]