How to render text documents with SDL_TTF?

What could be the general recommendations to render text like this?
[Image: https://dl.dropboxusercontent.com/u/9515547/dev/bb_fonts.JPG ]

As you can see, many font faces and many font sizes used in this text. So, if SDL_TTF powerful enough, which a primary algorythm should I use? Enumerate all the fonts used by a text document and apply TTF_OpenFont for every of them?

Bring any idea, please.

If you dont want to create a text editor, like editing and selecting, only
display, you can keep the different fonts on a separate array and split the
char* text of the whole thing according to its style, and then apply every
font to each chunk of strings. You will need some kind of word wraper
algorithm to go along this thing that works with the sizes of the surfaces
that are gonna be rendered, you are talking about a RichText entitie. No
sure what else to say.

2014-05-22 14:09 GMT-06:00 akastargazer :> What could be the general recommendations to render text like this?

As you can see, many font faces and many font sizes used in this text. So,
if SDL_TTF powerful enough, which a primary algorythm should I use?
Enumerate all the fonts used by a text document and apply TTF_OpenFont for
every of them?

Bring any idea, please.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Javier Flores

javierecf wrote:

If you dont want to create a text editor, like editing and selecting, only display, you can keep the different fonts on a separate array and split the char* text of the whole thing according to its style, and then apply every font to each chunk of strings. You will need some kind of word wraper algorithm to go along this thing that works with the sizes of the surfaces that are gonna be rendered, you are talking about a RichText entitie. No sure what else to say.
Thank you for response! Yes, a text editor is a main goal. I already have all of the necessary text processing facilites like text wraping, editing and others, and new rendering engine based on SDL. So I’d like to realize how to obtain maximum text rendering performance.

Maybe the best will be to use bitmap files for the fonts and selecting each
glyph from the image according the the words and its style.

2014-05-22 14:32 GMT-06:00 akastargazer :>

javierecf wrote:

If you dont want to create a text editor, like editing and selecting,
only display, you can keep the different fonts on a separate array and
split the char* text of the whole thing according to its style, and then
apply every font to each chunk of strings. You will need some kind of word
wraper algorithm to go along this thing that works with the sizes of the
surfaces that are gonna be rendered, you are talking about a RichText
entitie. No sure what else to say.

Thank you for response! Yes, a text editor is a main goal. I already have
all of the necessary text processing facilites like text wraping, editing
and others, and new rendering engine based on SDL. So I’d like to realize
how to obtain maximum text rendering performance.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Javier Flores

I wonder what is the status or worth working on, SDL_rtf Rich Text Format
:-).

I think it’s probably easier to go straigh to use freetype with SDL, rather than using SDL_ttf.

Hi there,

SDL_TTF is certainly powerful enough, and can be thought of as a lightweight wrapper for the FreeType2 API. If you can get away with simply caching every font used in the text document, I’d say that you can call it good there, but in any regard, the answer is yes to caching (loading) the fonts ahead of time.

For high performance text rendering, you could create a texture atlas (think: sprite sheet) composed of every glyph in the font(s) loaded, and render text strings from the coordinates of the texture atlas. The performance is great (hundreds of FPS), and the only time that you incur performance hits is when the font’s point size (text size) is changed – you must regenerate the glyph atlas, but you can cache this, too, if necessary. (I don’t since I can get away with it). Changing the font’s style (bold, italics, underlined) can also incur a small performance penalty, but these can be cached as well.

For an example of using SDL_TTF for generating a texture atlas, check out:

  1. https://github.com/i8degrees/nomlib/blob/dev/src/graphics/fonts/TrueTypeFont.cpp#L229
  2. https://github.com/i8degrees/nomlib/blob/dev/src/graphics/Text.cpp#L402

I wish you luck! :slight_smile:

Cheers,
Jeffrey Carpenter
<@Jeffrey_Carpenter>On 2014/05/ 22, at 15:09, akastargazer wrote:

What could be the general recommendations to render text like this?

As you can see, many font faces and many font sizes used in this text. So, if SDL_TTF powerful enough, which a primary algorythm should I use? Enumerate all the fonts used by a text document and apply TTF_OpenFont for every of them?

Bring any idea, please.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi. You said that you have wrapping algortihms in place already, but you
may want to consider the _Wrapped versions of the usual TTF render calls.
They return a single surface. Those methods are not on the docs (I wonder
when they’ll be documented :slight_smile:

Creating a texture atlas of the glyphs may not be what you want if you’re
creating a text editor because there is a lot going on that is handled by
freetype (and hence by SDL_ttf), such as hinting, kerning. For instance, in
some fonts, you can see that the when you type the char V and A together
(having VA), they may overlap each other (see
http://en.wikipedia.org/wiki/Kerning). This is all done by freetype for
you. If you’re ok with not having kerning, then its ok to have an atlas, I
guess.

2014-05-22 18:13 GMT-03:00 Jeffrey Carpenter :> Hi there,

SDL_TTF is certainly powerful enough, and can be thought of as a
lightweight wrapper for the FreeType2 API. If you can get away with simply
caching every font used in the text document, I’d say that you can call it
good there, but in any regard, the answer is yes to caching (loading) the
fonts ahead of time.

For high performance text rendering, you could create a texture atlas
(think: sprite sheet) composed of every glyph in the font(s) loaded, and
render text strings from the coordinates of the texture atlas. The
performance is great (hundreds of FPS), and the only time that you incur
performance hits is when the font’s point size (text size) is changed –
you must regenerate the glyph atlas, but you can cache this, too, if
necessary. (I don’t since I can get away with it). Changing the font’s
style (bold, italics, underlined) can also incur a small performance
penalty, but these can be cached as well.

For an example of using SDL_TTF for generating a texture atlas, check out:

https://github.com/i8degrees/nomlib/blob/dev/src/graphics/fonts/TrueTypeFont.cpp#L229
2. https://github.com/i8degrees/nomlib/blob/dev/src/graphics/Text.cpp#L402

I wish you luck! :slight_smile:

Cheers,
Jeffrey Carpenter

On 2014/05/ 22, at 15:09, akastargazer wrote:

What could be the general recommendations to render text like this?

As you can see, many font faces and many font sizes used in this text.
So, if SDL_TTF powerful enough, which a primary algorythm should I use?
Enumerate all the fonts used by a text document and apply TTF_OpenFont for
every of them?

Bring any idea, please.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Leonardo,

You remind me of a curious question I have with SDL_ttf. There exists a TTF_GetKerningSize function as of the last release, although I have yet to ever see a non-zero value from it, from any of the fonts that I’ve tried (admittedly, only Minion Pro, Arial and Times New Roman), with kerning explicitly enabled, rendering the whole ASCII glyph set. I suppose that my real question might be, what fonts should I expect to see a non-zero kerning value?

Glancing through the SDL_ttf.c, it would lead me to believe that kerning is supported, but my tests seem to say otherwise. So, either my testing methodology is flawed, or SDL_ttf does not support kerning (possible bug within the API?)

If the kerning API in SDL_ttf does work, then applying kerning to the rendered string of glyphs is trivial.

Cheers,
Jeffrey Carpenter
<@Jeffrey_Carpenter>

The backend is FreeType,
http://www.freetype.org/freetype2/docs/glyphs/glyphs-4.html , look at the
BRAVO example.
http://www.freetype.org/freetype2/docs/tutorial/step2.html, simple
kerning, then, advaced. This corner of the Internet explains text
composition very detailedly; from implentators.

Again, makes more sense to me to use SDL_rtf, else, for the work and
benefits you might as well program a GTK or QT,… SDL backend ;-).

Look at this! I’m very happy to show results of work. SDL + SDL_TTF + BlackBox Component Builder.

[Image: https://dl.dropboxusercontent.com/u/9515547/dev/sdl/sdl_two_documents.PNG ]

And screencast here: http://youtu.be/Sn1rEmwHX5U

Beautiful! :smiley:

Cheers,
Jeffrey Carpenter
<@Jeffrey_Carpenter>On 2014/09/ 23, at 8:02, akastargazer wrote:

Look at this! I’m very happy to show results of work. SDL + SDL_TTF + BlackBox Component Builder.

And screencast here: http://youtu.be/Sn1rEmwHX5U


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org