Commit Graph

6 Commits

Author SHA1 Message Date
1vanK
ef1dfe3417
AS Autobindings 2020-10-28 19:18:41 +08:00
Iain Merrick
0450bcd11e Add configurable oversampling to improve subpixel font rendering (#1953)
Subpixel-positioned text looks blurry, due to bilinear filtering of the
underlying texture. The basic idea here is to stretch the font glyphs
horizontally to increase the sharpness at subpixel positions. The
stretched images need to be smoothed to avoid aliasing artifacts; this
is done in FontFaceFreeType::BoxFilter().

Glyphs are always pixel-aligned vertically, so no vertical oversampling
is needed.

To make this feature comprehensible (I hope!) I've removed the
'subpixelGlyphPositions' flag and replaced it with a couple of values:
'fontSubpixelThreshold' sets the point at which subpixel positioning
kicks on, and 'fontOversampling' controls the amount of stretching.

The default values are 12pt text and 2x oversampling. These are fairly
conservative settings, which should improve small text without wasting
a lot of memory.

Note that when the font hint level is NORMAL (the default), subpixel
positioning and oversampling are both disabled. So, this feature doesn't
change any default behavior, and applies some hopefully sensible values
if the hint level is set to LIGHT or NONE.
2017-07-03 11:21:47 -05:00
Iain Merrick
e603eed814 Add a 'subpixel glyph positions' option to UI (#1953)
When this option is enabled, text will be formatted with subpixel
(fractional) positions on the x-axis. Positions on the y-axis are
still pixel-aligned.

Note that this option has no effect if the hinting level is set
to FONT_HINT_LEVEL_NORMAL, as each glyph is rounded to an integral
pixel size by the hinter. It only makes a different if the hinting
mode is LIGHT (vertical hinting only) or NONE.

With subpixel positioning, the output will look blurrier due to
texture filtering. TODO: Add horizontal oversampling to improve
sharpness. That needs extra memory so it should be configurable.
2017-06-20 17:04:56 -05:00
Iain Merrick
1e3a1edd45 Change font size to a float (closes #1952)
This commit changes the 'pointSize' parameter in Font, Text
and Text3D from an int to a float, allowing e.g. 14.5pt text.
Note that when hinting is enabled, font metrics are snapped
to pixel boundaries, so the effect may be hard to see unless
you also set UI.FontHintLevel to LIGHT or NONE.

This is a change to the public API, but existing code (including
scripts) should compile and run as before.
2017-06-18 22:27:59 -05:00
Iain Merrick
282f250e3a Add UI.FontHintLevel property
There are three levels: NORMAL (the default), LIGHT and NONE.
The LIGHT level makes FreeType align font outlines to pixel
boundaries vertically, but not horizontally.
2017-06-15 15:30:28 -05:00
Iain Merrick
db6f4f9029 AngelScript version of Typography sample program 2017-06-13 13:40:31 -05:00