This patch allows us to print text in bold or italics (or both) when desired. It synthesizes these variations from a single UI font file, using Freetype's "embolden" routine for bold and obliquing transform (slanting) to simulate italics. The results aren't //quite// as good as if we used separate font files made specifically as bold or italic variations, but it is definitely good enough for occasional emphasis. Without requiring us to quadruple the number of fonts we maintain (four variations of each of our two fonts), since each of our fonts contains more than 58,000 characters.
Note the following sample is taken from the blender Text Editor and is therefore **monospaced** so ignore the kerning as there is none. First column is what we have now. Second column is the //typographical ideal//, which uses separate font files for each variation. **The third column is the result of this patch**. It looks almost identical except for the slightly wider advance (letter spacing) only because our monospaced UI font is not properly informing FreeType that it is fixed-pitch.
{F8570903}
In a comparison of variable-spaced text, the following shows two examples of the UI with bold text. The top is when using a dedicated bold font - DejaVuSans-Bold.ttf - while the bottom is using our regular font set to bold and with this patch applied. It is very hard to tell the two apart:
{F8570923}
In order to do this there are some changes to our blf_glyph code to correct problems with our caching. Currently we have the parts in place that could cache nicely. A FontBLF has a listbase of caches and a pointer to the current one. And we can search for caches that match our intended use. But none of it is actually set right and we always just use the first cache. So in effect we only have caching the drawing of text while using a single size. Changes of size always rebuild the cache. This patch fixes that so that a font can properly cache glpyhs as they change in size or bold and italic state.
Note that I have not allowed the emboldening of fonts that are made to be bold. Nor will it oblique a font specifically made to be italic. So if you replace the UI font with some bold font you wouldn't get super-bold. Nor will an italic font show you over-italicized text.
Bold will add a bit of extra space to the glyph's advance, so slightly widening the character because of the widened features. But will not do so for fixed-pitch (monospaced) fonts, so they will still line up.
This patch slightly refactors some code in blf_glyph.c near the added code, but just to make that section a bit more readable.
In order to quickly see some changes,To test this you can just set the **existing** "bold" and "italic" boolean members of the uiFontStyle struct, that currently do nothing. Or if you are dealing with a FontBLF you can BLF_enable(font_id, BLF_BOLD), etc.
For example, the following is with some parts of the tooltips window in bold. But this patch makes some parts of tooltips bold.only illustrates what this patch can do, Butas this is not an actual proposed change,change is not included here. just a way to see the potential of thisBut it is something that could be added in a later patch:.
{F8570938}
To test this further you can just set the **existing** "bold" and "italic" boolean members of the uiFontStyle struct, that currently do nothing. Or if you are dealing with a FontBLF you can BLF_enable(font_id, BLF_BOLD), etc