Let's assume I have a foreign text document I open with a text editing tool that recognizes fonts (e.g. LibreOffice Writer). In this document, there might be some fonts used that are not available on my Ubuntu installation (e.g. Garamond).
The question is: How does Ubuntu decide which one of the installed fonts to use as replacement for the unknown font? Does it read any of the font's characteristics and look for a similar one? Is a default substitution font always used? Does it search for similar font names?
Additional to that, I would like to know if I can somehow change this behavior or set manual font aliases to automatically use e.g. the free font EB-Garamont instead of the non-free Garamont?
I think it is decided not by Ubuntu but by the program (LibreOffice, OpenOffice etc.). I could not see anything related to LibreOffice per se but OpenOffice has a nice wiki with some details on how this "Font Fallback" works. It might be applicable to LibreOffice also, in general.
I am reproducing some sections from the wiki below for clarify. It is hard to explain better than what is in the wiki, so better to read it from there:
What is Font Fallback in OpenOffice.org 2?
Font-Fallback kicks in whenever a font is requested that is not installed on the system. (Not installed means: not available to OOo). OOo then tries to use a different font from the ones that OOo knows about that matches the requested one as close as possible.
How does Font Fallback work?
For font-fallback to produce satisfying results, OOo somehow has to know about similarities of fonts. OOo must know that it can for example substitute Helvetica in place of Arial, but not Comic Sans. This task is not as easy as it sounds, since many fonts exist and OOo cannot know about all of them.
OOo uses several ways to find a suitable replacement:
fonts.dir
file)VCL.xcu
(tried first)if all that fails as well:
Not directly related but this TLDP document is a good read.