go-text / typesetting

High quality text shaping in pure Go.
Other
88 stars 11 forks source link

Can the font variant be extracted by the metadata package? #57

Closed whereswaldon closed 1 year ago

whereswaldon commented 1 year ago

I think this is mostly a question for @benoitkugler: I'm not sure if there's a standardized name for this concept, but within Gio we track something we call the "Variant" of a font. This is usually "Mono" or "Smallcaps" if it's set at all, and helps select fonts with appropriate characteristics.

Is this kind of typeface information available in a standardized way? If not I guess we'll live, but it's the only font metadata that we aren't able to acquire automatically right now.

benoitkugler commented 1 year ago

If think it is more or less standard, depending on the property.

If we agree on this, we could add two boolean fields IsMono, HasSmallCaps on the metadata.

whereswaldon commented 1 year ago

If think it is more or less standard, depending on the property.

* "Mono" : this is actually quite standard : both Freetype and Fontconfig exposes a flag for it, `true` when the font has glyphs with fixed size.

Excellent, let's export that then!

* "Smallcaps" : this is less clear. The reference here seems to be the [CSS spec](https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant-caps). As you can see, it is related to Opentype features (`smcp`, `c2sc`, `pcap`, `unic`, `titl`), with 'small-caps' property activating the `smcp` feature. So, I think the way to go would be to check if the font provides a `smcp` feature. Do you have some font samples with this variant to check if this is correct ?

I don't actually have a font in mind for this. I only mentioned this because this case is mentioned in Gio's text.Variant documentation. I'm not sure we're using it in the wild.

If we agree on this, we could add two boolean fields IsMono, HasSmallCaps on the metadata.

Let's focus on IsMono for now. I have real use-cases for that. HasSmallCaps is more hypothetical, and would require API support to activate a specific font feature at shaping time (much bigger change). Thank you for providing your expertise here! I didn't know how this worked. :smile:

andydotxyz commented 1 year ago

Just throwing out the question of whether Is and Has prefix are correct given the Go preference for dropping them?

whereswaldon commented 1 year ago

Let's focus on IsMono for now. I have real use-cases for that. HasSmallCaps is more hypothetical, and would require API support to activate a specific font feature at shaping time (much bigger change). Thank you for providing your expertise here! I didn't know how this worked.

I found a font that has a smallcaps separate entry: The Go Font

It would be nice to be able to support that, as it's the default font in Gio.

Just throwing out the question of whether Is and Has prefix are correct given the Go preference for dropping them?

I guess I'm unaware of this convention. Where does it come from? It's not mentioned in "Effective Go," and I can find many counterexamples in the standard library.

andydotxyz commented 1 year ago

Maybe it was my assumption but "Get" is widely discouraged and is/has are just Boolean variants of this verb.

benoitkugler commented 1 year ago

Let's focus on IsMono for now. I have real use-cases for that. HasSmallCaps is more hypothetical, and would require API support to activate a specific font feature at shaping time (much bigger change). Thank you for providing your expertise here! I didn't know how this worked.

I found a font that has a smallcaps separate entry: The Go Font

It would be nice to be able to support that, as it's the default font in Gio.

I've played a bit with this font, but unfortunately, I've found no hint about small caps : it seems that the font only provides one way for caps (small), without any feature. This means that the only way to know this font has small caps is by looking at its family name. We could perhaps check for 'smallcaps' in the family name, but I'm not sure how robust it is.

whereswaldon commented 1 year ago

Let's focus on IsMono for now. I have real use-cases for that. HasSmallCaps is more hypothetical, and would require API support to activate a specific font feature at shaping time (much bigger change). Thank you for providing your expertise here! I didn't know how this worked.

I found a font that has a smallcaps separate entry: The Go Font It would be nice to be able to support that, as it's the default font in Gio.

I've played a bit with this font, but unfortunately, I've found no hint about small caps : it seems that the font only provides one way for caps (small), without any feature. This means that the only way to know this font has small caps is by looking at its family name. We could perhaps check for 'smallcaps' in the family name, but I'm not sure how robust it is.

Yeah, seems like the Go font is making some unfortunate choices. I don't think checking the font family name is super robust, though maybe we could offer some kind of optional "try to infer stuff from the family name" method as an option of last resort? I dunno. Gio can work around this by setting the appropriate variant info ourselves in the package providing the Go font. I just hope this sort of thing isn't prevalent in the wild.

whereswaldon commented 1 year ago

Maybe it was my assumption but "Get" is widely discouraged and is/has are just Boolean variants of this verb.

Totally on the same page about "Get," but I don't know that it generalizes. I think I'd prefer to leave it alone. I can't find evidence online that dropping that prefix is widely considered a good practice.

andydotxyz commented 1 year ago

Maybe it was my assumption but "Get" is widely discouraged and is/has are just Boolean variants of this verb.

Totally on the same page about "Get," but I don't know that it generalizes. I think I'd prefer to leave it alone. I can't find evidence online that dropping that prefix is widely considered a good practice.

That's cool. Will try and update my thinking about this elsewhere too :).

whereswaldon commented 1 year ago

My reason for wanting this feature is addressed, so I think it can be closed for now. If we want to detect specific other variants, we can add them on a case-by-case basis.