johnfactotum / foliate

Read e-books in style
https://johnfactotum.github.io/foliate/
GNU General Public License v3.0
6.35k stars 291 forks source link

Wrong font variant rendered #1057

Closed natewind closed 1 year ago

natewind commented 1 year ago

I have the entire Garamond Premier Pro family installed (the OTF versions), and Foliate renders Garamond Premier Pro Regular as Garamond Premier Pro Caption both in the font picker and in the book. (Quick check: Regular has crossed W.)

johnfactotum commented 1 year ago

The font picker is a built-in widget provided by GTK, so if the font doesn't work in the font picker, that would be a GTK bug.

And then it simply takes the font family name provided by the widget and sets it as the value of font-family in CSS. You can inspect this with WebKit's inspector and see if the CSS is correct, and if so, it could be a WebKitGTK bug. If not, then it's probably a Pango/fontconfig bug, as the family name comes directly from Pango.

If the desired rendering cannot be achieved by simply setting font-family, then that means either it's a bug with Pango, etc, or the font itself, or it's because it requires additional font features not available via font-family, in which case it is simply not supported by Foliate. Additionally the book's own stylesheet will also influence the rendering.

natewind commented 1 year ago

I looked at CSS, and the font name is correct, but CSS always messes up optical sizes, unless I overrule it with @font-face, even in Chrome and Firefox. I guess it’s not just a GTK bug; the problem is that CSS doesn’t let you set optical size manually, and web engines don’t know how to do it automatically.

johnfactotum commented 1 year ago

If it's about automatic optical sizing, at least the example from MDN seem to be working in both Firefox and Chromium, but not in WebKitGTK, which isn't really surprising, considering that WebKitGTK doesn't even render small caps properly. But manual sizing works using font-variation-settings.

natewind commented 1 year ago

Those are for variable fonts specifically.

johnfactotum commented 1 year ago

Well, if you're not talking about variable fonts, there's no reason why it wouldn't work. I don't have Garamond Premier Pro, but I installed Source Serif, and Source Serif 4 Regular, Source Serif 4 Caption, Source Serif 4 Display, etc. all work as expected in the font picker and in the book.

natewind commented 1 year ago

When you open those fonts in a font viewer and look at font info, do they all have different names, or the same name, with “Caption”, “Display” etc. specified in the “Style” field?

johnfactotum commented 1 year ago

They are different fonts, indeed.

But if you're saying that the different sizes have the same family name, then I guess it's still a GTK bug, since (1) it's not displayed correctly in the font picker and (2) perhaps I'm wrong, but I don't think Pango has an API for getting the optical size (or whatever feature/property/field or whatever it's called in the font format), i.e. regardless of whether it's supported in CSS or not, it doesn't seem to be supported by GTK.

natewind commented 1 year ago

Yeah, Garamond Premier Pro variations all have the same family name.

I’m not arguing that it’s not a GTK bug, I’m just saying it seems to be an even wider problem for some reason.