latex3 / luaotfload

OpenType font loader for LuaTeX
Other
60 stars 7 forks source link

luaotfload-tool: results of `--find` could be better #78

Open u-fischer opened 5 years ago

u-fischer commented 5 years ago

From the dante mailing list:

Why is Latin Modern Roman found but not "Latin Modern Roman Slanted?

$ fc-cache -r

$ fc-match "Latin Modern Roman"
lmroman10-regular.otf: "Latin Modern Roman" "10 Regular"

$ fc-match "Latin Modern Roman Slanted"
lmromanslant10-regular.otf: "Latin Modern Roman Slanted" "10 Regular"

$ luaotfload-tool -u -f

$ luaotfload-tool --find="Latin Modern Roman"
luaotfload | resolve : Font "Latin Modern Roman" found!
luaotfload | resolve : Resolved file name
"/usr/local/texlive/2019/texmf-dist/fonts/opentype/public/lm/lmroman10-regular.otf"

$ luaotfload-tool --find="Latin Modern Roman Slanted"
luaotfload | db : Reload initiated (formats: otf,ttf,ttc); reason: "Font
Latin Modern Roman Slanted not found.".
luaotfload | resolve : sequence of 3 lookups yielded nothing appropriate.
luaotfload | resolve : Cannot find "Latin Modern Roman Slanted" in index.
luaotfload | resolve : Hint: use the --fuzzy option to display suggestions.
zauguin commented 5 years ago

Latin Modern Roman and Latin Modern Roman Slanted are names of font families, not individual fonts ads far as luaotfload is concerned. Loading a font by family name loads the regular version of the font. Now luaotfload decides that lmromanslant10-regular.otf isn't really all that regular, it is more like a italic version. So the font family Latin Modern Roman Slanted does not contain any regular fonts, only italic ones. Therefore searching for the regular one yields no results.

The same thing can be seen from LuaTeX: Asking for a regular font fails:

\input luaotfload.sty
\font\myfont"Latin Modern Roman Slanted"\myfont
Hallo
\bye

luaotfload | db : Reload initiated (formats: otf,ttf,ttc); reason: "Font Latin Modern Roman Slanted not found.". luaotfload | resolve : sequence of 3 lookups yielded nothing appropriate. ! Font \myfont=Latin Modern Roman Slanted not loadable: metric data not found or bad.

\myfont l.2 \font\myfont"Latin Modern Roman Slanted"\myfont

On the other hand, asking for a italic font works fine:

\input luaotfload.sty
\font\myfont"Latin Modern Roman Slanted/I"\myfont
Hallo
\bye

image

Now there already is a fallback mechanism to add a last resort regular font: Even if loaotfload decides that a font does not look like a regular one but there is no other regular font and the font claims to be regular, then this claim is accepted. This doesn't trigger here because for example lmromanslant10-regular.otf only claims to be 10 Regular (regular for optical size 10), which is not regular enough for the fallback.

u-fischer commented 5 years ago

Yes that is quite understable and luaotfload-tool --find="Latin Modern Roman Slanted/I" gives a hit.

But I think in the long run there is room for improvement here (if I add --fuzzy then the match is CMU Serif Roman Slanted). We should perhaps look at the search tools of context and consider what could be useful (and understable for the users).

zauguin commented 5 years ago

@u-fischer I don't know which search tools you are referring to, but I think the behaviour could be improved by adding some "regular priority" system which ensures that we always have some regular font, even if it is just less non-regular than the other ones. Then we could also allow a font to be found by multiple kinds of family names which would further help to avoid problems when fontconfig etc. names are not found by luaotfload.

But currently the luaotfload-database.lua is almost 4000 lines of code and especially the regular font detection is split into multiple pieces, so it might be best to split and clean this up first. The problem is that lot's of workarounds are necessary for odd fonts, so any rewrites or even refactoring risk introducing hard to detect incompatibilities.

Also, especially given the work on HarfBuzz based loaders, I would like this stuff to be more interdependent from the ConTeXt loader, but I can't say which impact this would have on the performance.

u-fischer commented 5 years ago

@zauguin if you run in context mtxrun --scripts fonts you get a long list of possible ways to search and list (and convert) fonts (not everything works as expected, but it is nevertheless quite powerful).

Imho it would be good to clean up the code and I think I have an idea how to set it up and allow people to test without breaking existing documents. I guess it would be easy to change the name or the location of the cache-file(s) for such a development version?