[SDL] [SDL_ttf] disable kerning or provide a function
Christian Walther
cwalther at gmx.ch
Sun Sep 23 00:52:11 PDT 2007
William Konopka wrote:
> I've been trying to use SDL_ttf for my project. I'm designing a lightweight
> widget tool set for SDL. I've run into a problem during implementation of a text
> editing widget. The thing is that I'm trying to calculate the position (in the
> string) of a character under a mouse pointer (to allow text selection)
>
> I see two solutions to the problem. Either you provide an option to disable
> kerning for a font (the quick and dirty solution), or a function that takes the
> relative coordinates of mouse pointer and returns the string position of an
> element pointed by the pointer. Whadda ya say?
In my experience it is perfectly doable to implement a text editing
widget using SDL_ttf, even if some things are done less efficiently than
they could be done with direct access to freetype. Kerning is too nice a
feature to turn off!
See
<http://pipmak.svn.sourceforge.net/viewvc/pipmak/trunk/pipmak/source/textedit.c?view=markup>
for the code. For mapping from mouse coordinates to character offsets
(and vice versa to draw the insertion point) I keep around an array of
the advance widths of each character (always a whole number of pixels, I
don't know if freetype could even do subpixel kerning). To update this
when the text has changed, taking into account kerning, I use
TTF_SizeUNICODE() over prefixes of the changed substring plus one
character on either end. (Without kerning, TTF_GlyphMetrics() could be
used.)
> such functions as SDL_AllocSurface are undocumented
SDL_AllocSurface is #defined as SDL_CreateRGBSurface, which is documented.
-Christian
More information about the SDL
mailing list