Hi!
I wanted to use stroke fonts with SFML. FreeType
supports stroked glyphs but this is not made available in SFML.
I know it is posible to obtain a similar result by drawing the text several times with small position offsets, but they are several drawbacks to this method:
- for larger borders and font sizes you have to draw more occurences of the text or artefacts will appear
- space between characters does not take account of the border (or you have to draw each character independently, without relying on SFML)
- sharpness of edges is not preserved
- the result is more a "glow effect" than a stroke.
I made a small patch to SFML to add stroked support (feel free to ask if your are interested). Basically it adds:
- m_borderWidth, m_borderColor and m_borderVertices members to Text (with associated constructors)
- a borderWidth parameter (defaulting to 0) to glyph-related methods (ex. Font::loadGlyph()), along the characterSize parameter
API is preserved (new methods for Text, new optional parameter for glyph-related method), but not ABI (especially, glyph pages are now indexed by character size and border width).
Here is a picture showing the difference between FT-based stroke font and the multiple drawing method for 4 configurations (regular and bold font style, border width 3 and 6). For each configuration there are:
- FreeType stroking (using FT_STROKER_LINECAP_BUTT and FT_STROKER_LINEJOIN_MITER_FIXED stroke style)
- stroke by drawing the text 9 times with offsets from (-width,-width) to (width,width) to produce sharp corners
- stroke by drawing the text 8 times around the initial position (at multiples of pi/4 angles)
- stroke by drawing the text 16 times around the initial position (at multiples pi/8 angles)
As you can see, when the border is thick, drawing 8 times is not enough. And even with a small border, artefacts are visible where the FT-based stroking is always clean. FT-based version is larger because character spacing respects the border width.
This is just a proposal. I know that Laurent is very cautious with API changes (and he's right!) and maybe this solution would not fit its requirements, but I think stroke text would be a nice addition to SFML and I'm ready to help.