Re: Question about Library Design

Alexei Podtelezhnikov <[email protected]> Thu, 2 Jan 2025 17:52:30 -0500
Newsgroups gmane.comp.fonts.freetype.devel
Message-ID <CAJU=AjUmiMKRBKNQRzMbVAEUxq54ftRsriuTpkJdztiisoObjg@mail.gmail.com>
Hi Ian

> Recently, I was looking at the source code for the SDF rendering portion of FreeType, and I was surprised to see that all the math is done using fixed point numbers. Looking further, the library does not use floating point at all. What are the primary reasons for this? Is it just a relic of the original library design when fixed point numbers were significantly than floating point numbers? Do they allow for slightly more precision when working at a certain scale? Are there separate compatibility reasons? I am sorry if there is an explanation somewhere on the FreeType website; I was not able to find anything. Thank you in advance for any explanation.

The short answer is all of the above. Perhaps, the ultra-portability
was one of the original goals making the library useful on many
platforms including embedded devices. It still provides certain
performance benefits by avoiding the register conversions, after all
common fort formats do not use floating point data. The target
surfaces (screens) are also discreet. Finally, avoiding the
temptations of floating functions (sqrt and trigonometry) forces
better code design.

Alexei