You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
corefonts: black weight font variant is selected when regular weight was requested #3213
FROM ghcr.io/typst/typst:latest
ENV TYPST_FONT_PATHS=/usr/share/fonts/truetype/msttcorefonts
RUN set -eux; \
apk add --no-cache msttcorefonts-installer; \
update-ms-fonts; \
apk del --no-cache msttcorefonts-installer;
Is this a duplicate, though? That issue seems to be about style, mainly, not about weight.
Where can I get ahold of the raw Arial Black ttf file to inspect it?
I think the best way is to build and run the Dockerfile from the issue description and copying /usr/share/fonts/truetype/msttcorefonts to a mounted host path. That's how I did it, anyway.
I suspected something like that, but was not familiar enough with fonts to confirm. I don't think, we should wait for this to be fixed upstream, since this the de-facto standard way of installing MS fonts on Linux since forever. That means an upstream fix would take years to reach users.
I'm not sure. Perhaps there is no way but to ship exceptions, but if so, we should definitely apply them very carefully, e.g. maybe not for any font ending with "black", but rather specifically for Arial Black. I'll discuss this with @reknih.
Typst already have some ad-hoc exceptions for font names. Maybe we can generalize that and introduce a font map mechanism into typst. That can be a mapping embedded into typst binary like this:
NewComputerModern08-Italic:
- family: "New Comupter Modern"NewComputerModern08-BookItalic:
- family: "New Comupter Modern"
- weight: 450
The keys correspond to the FULL_NAME record in the font file. Users encountering fonts with incorrect metadata can simply submit a pull request to update this file accordingly. For instance:
"Arial Black":
- family: Arial
- weight: 900
In the future, we can offer an API that allows users to supply their own fontmap.yaml, which would override the default one built into Typst.
I wonder whether should just decide based on the FULL_NAME or perhaps also on the checksum. The problem with the latter is that some fonts will continue to retain their "wrong" metadata across multiple versions, so FULL_NAME is probably the better albeit less safe choice.
I wonder whether should just decide based on the FULL_NAME or perhaps also on the checksum. The problem with the latter is that some fonts will continue to retain their "wrong" metadata across multiple versions, so FULL_NAME is probably the better albeit less safe choice.
I agree. Can I help with this in any way? Is someone experienced willing to work on this, or should I give this a go?
I'd be happy for you to work on this, but let's first nail down the design.
There are various things going on in FontInfo::from_ttf:
We check italic, oblique and slanted with metadata + fallback to full name (the latter is very hacky)
We have an extra hack for New CM Book weights
Noto & New CM use full name instead of family because of Display variants
We have this very hacky function typographic_family which turns full names into nice names (it has false positives)
1+2 would be easily handled by the exception list. 3 is a little less nice to handle with a list because there are soo many Noto fonts. We'd maybe need a regex or starts_with mechanism to define exceptions for those.
4 is the worst of all hacks imo. Technically, it should be replaced by just using "Typographic Family", but that makes certain variants inaccessible because more than just style/weight/stretch is grouped (e.g. Display). This is related to #2098.
There's been quite some discussion about that issue on Discord.
I think that would should solve all of the problems in one sweep. One possible solution, which is quite close to the latest state of the Discord discussion is to support two ways to select a font:
Typst-prettified: We should move away from the current style trimming as much as possible and just use "Typographic Family" with fallback to "Family". To access some variants that become inaccessible, the Raw ways exist. This is also where we'd use an exception list to get a nice name and correct metadata for the font. I'm not sure how well just a list would suffice for this though. Apart from the Noto stuff, many Apple font names for example randomly start with '.' for some reason, which I'd like to keep getting rid of.
Raw: A user can directly supply the complete FULL_NAME (or FAMILY_NAME, or both) to pick one particular face.
Any font selection will result in a list of candidate font faces. In the first case, there might be multiple and the metadata will be used to find the best pick. In the second case, there will most likely be just one.
While this is sort of a dupe, I've reopened so that we can properly use it for further discussion and close it once we've implemented something to this effect.
Typst uses (family, style, weight, stretch, size) 5-tuple to identify a font. This has many advantages, for example typst can select nearest font in space if the coordinate specified by user not exists. However, the OpenType standard has different coordinate system to select a font. In an OpenType font, a font can be identified by: (I'm using names from ttf_parser)
(The size axis is not really relevant here so I just drop it in the following discussion)
(a: FAMILY, SUBFAMILY). There should be at most 4 SUBFAMILY for a FAMILY. Usually the 4 SUBFAMILY is the same as typst's style, but it's not always the case.
(b: TYPOGRAPHIC_FAMILY, TYPOGRAPHIC_SUBFAMILY)
(c: FULL_NAME)
POST_SCRIPT_NAME and UNIQUE_ID. But these two way is less relevant here since FULL_NAME is usually more nice to read.
OpenType font formats also includes style and weight, but font designers make fonts without aware of the typst coordinate system. That's why typst is using a very hacking algorithm to calculate the correct family-coordinate of a font. This part is described above by @laurmaedje.
Ideally, all information other than italic, weight and stretch should go into the family axis of typst coordinate, and it should only contain information thereof. But that's a rather hard task. For example:
Latin Modern encodes the optical size information into the TYPOGRAPHIC_SUBFAMILY field. (b: Latin Modern Roman, 10 Regular) and (b: Latin Modern Roman, 12 Regular) both be mapped to (Latin Modern Roman, normal, 400, 100%) in typst.
Arial encodes it's weight information only into the FAMILY field. That makes (a: Arial, Regular) and (a: Arial Black, Regular) both be mapped to (Arial, normal, 400, 100%) in typst.
It's clear that the typst coordinate system will not work for all font without some manual intervention.
Proposed solution
In #3213 (comment)@laurmaedje metioned a simpler approach: Do not try very hard to make the typst coordinate working. Just fallback to the OpenType coordinate system (c: FULL_NAME) if the typst coordinate system fails.
I think that is not optimal because when using FULL_NAME, you drop the italic, weight and stretch info. emph and strong will not work. Thus I proposed another approach in #3213 (comment) : Design a systematic approach to map OpenType coordinate to the typst coordinate. This should combine automatic procedure and manual whitelist. This approach has extra future possibilities: We can include small caps in the style axis and map Some Font and Some Font SmallCaps into a single family, to enable smallcaps function to work for more font families.
Typst uses (family, style, weight, stretch, size) 5-tuple to identify a font.
OpenType font formats also includes style and weight, but font designers make fonts without aware of the typst coordinate system. That's why typst is using a very hacking algorithm to calculate the correct family-coordinate of a font.
Typst only uses the first four, not the size for font selection. The family-style-weight-stretch coordinate system is pretty common, e.g. in CSS. It is not Typst-specific. The only thing that's specific is the (hacky) effort Typst makes to have a nicer family name and the few exceptions where Typst patches the metadata based on name.
I think that is not optimal because when using FULL_NAME ... emph and strong will not work.
That's a fair criticism.
Thus I proposed another approach in #3213 (comment): Design a systematic approach to map OpenType coordinate to the typst coordinate.
To be clear: I am not against adding a general exception mechanism. But as you said, it would require not just a list, but also an automatic produce to get a "nice" uniform family consisting of only fonts differing in style/weight/stretch from the available data in the font. In theory, font names could also be selected in such a way that this property is enforced for a given font set, but that might be weird because an existing font name might change when a new font is installed.
That's why I proposed doing something more predictable and mostly relying on TYPOGRAPHIC_FAMILY. I'd be all on board with a more systematic approach to map OpenType coordinate to the CSS coordinate system if we find a good one.
Typst only uses the first four, not the size for font selection.
Wouldn't it make sense for Typst to also use size for font selection? New Computer Modern (and probably others) has different font files optimized for 8 point and 10 point sizes.
Computer Modern is actually pretty unique in that respect. The differences in the two variants are due to the Optical Size difference of the fonts, consisting of small weight and detail differences that make the fonts more legible at their respective sizes. Some modern font families include "Display" variants which are intended for display font sizes (>~18pt) but don't make such a clear distinction. Variable fonts have begun to ship the opsz variation axis for optical sizing. The units on that scale are standardized with regards to point size.
Typst does not yet support variable fonts (#185) but once we do, we should automatically adjust the opsz axis based on font size. In my opinion, support for legacy approaches for optical sizing (dedicated denominated fonts or Display variants) belongs in the same work package instead of here.
Reacted by Martin Kröning, Victor L., Derived Cat, Dave Crossland and Chad Skeeters
changed the title [-]Black weight font variant is selected when regular weight was requested[/-][+]corefonts: black weight font variant is selected when regular weight was requested[/+]on Feb 1, 2024
Ok, I've managed to extract it. The OS/2 table of the font specifies a usWeightClass of 400, which is clearly wrong.
@laurmaedje, can you point me to a tool that can be used to extract such information? I'd like my PR fixing this to be comprehensive for all corefonts.
Activity
Enivex commentedon Jan 17, 2024
Duplicate of #576
laurmaedje commentedon Jan 17, 2024
Where can I get ahold of the raw Arial Black ttf file to inspect it?
mkroening commentedon Jan 17, 2024
Is this a duplicate, though? That issue seems to be about style, mainly, not about weight.
I think the best way is to build and run the Dockerfile from the issue description and copying
/usr/share/fonts/truetype/msttcorefontsto a mounted host path. That's how I did it, anyway.laurmaedje commentedon Jan 17, 2024
Ok, I've managed to extract it. The OS/2 table of the font specifies a usWeightClass of 400, which is clearly wrong.
mkroening commentedon Jan 17, 2024
I suspected something like that, but was not familiar enough with fonts to confirm. I don't think, we should wait for this to be fixed upstream, since this the de-facto standard way of installing MS fonts on Linux since forever. That means an upstream fix would take years to reach users.
What do you think is the best way forward here?
laurmaedje commentedon Jan 17, 2024
I'm not sure. Perhaps there is no way but to ship exceptions, but if so, we should definitely apply them very carefully, e.g. maybe not for any font ending with "black", but rather specifically for Arial Black. I'll discuss this with @reknih.
peng1999 commentedon Jan 18, 2024
Typst already have some ad-hoc exceptions for font names. Maybe we can generalize that and introduce a font map mechanism into typst. That can be a mapping embedded into typst binary like this:
The keys correspond to the
FULL_NAMErecord in the font file. Users encountering fonts with incorrect metadata can simply submit a pull request to update this file accordingly. For instance:In the future, we can offer an API that allows users to supply their own
fontmap.yaml, which would override the default one built into Typst.laurmaedje commentedon Jan 18, 2024
I wonder whether should just decide based on the FULL_NAME or perhaps also on the checksum. The problem with the latter is that some fonts will continue to retain their "wrong" metadata across multiple versions, so FULL_NAME is probably the better albeit less safe choice.
mkroening commentedon Jan 18, 2024
I agree. Can I help with this in any way? Is someone experienced willing to work on this, or should I give this a go?
laurmaedje commentedon Jan 18, 2024
I'd be happy for you to work on this, but let's first nail down the design.
There are various things going on in
FontInfo::from_ttf:typographic_familywhich turns full names into nice names (it has false positives)1+2 would be easily handled by the exception list. 3 is a little less nice to handle with a list because there are soo many Noto fonts. We'd maybe need a regex or starts_with mechanism to define exceptions for those.
4 is the worst of all hacks imo. Technically, it should be replaced by just using "Typographic Family", but that makes certain variants inaccessible because more than just style/weight/stretch is grouped (e.g. Display). This is related to #2098.
There's been quite some discussion about that issue on Discord.
I think that would should solve all of the problems in one sweep. One possible solution, which is quite close to the latest state of the Discord discussion is to support two ways to select a font:
Any font selection will result in a list of candidate font faces. In the first case, there might be multiple and the metadata will be used to find the best pick. In the second case, there will most likely be just one.
laurmaedje commentedon Jan 18, 2024
While this is sort of a dupe, I've reopened so that we can properly use it for further discussion and close it once we've implemented something to this effect.
peng1999 commentedon Jan 18, 2024
The problem
My understanding about the current situation:
Typst uses (family, style, weight, stretch, size) 5-tuple to identify a font. This has many advantages, for example typst can select nearest font in space if the coordinate specified by user not exists. However, the OpenType standard has different coordinate system to select a font. In an OpenType font, a font can be identified by: (I'm using names from ttf_parser)
(The size axis is not really relevant here so I just drop it in the following discussion)
OpenType font formats also includes style and weight, but font designers make fonts without aware of the typst coordinate system. That's why typst is using a very hacking algorithm to calculate the correct family-coordinate of a font. This part is described above by @laurmaedje.
Ideally, all information other than italic, weight and stretch should go into the
familyaxis of typst coordinate, and it should only contain information thereof. But that's a rather hard task. For example:(b: Latin Modern Roman, 10 Regular)and(b: Latin Modern Roman, 12 Regular)both be mapped to(Latin Modern Roman, normal, 400, 100%)in typst.(a: Arial, Regular)and(a: Arial Black, Regular)both be mapped to(Arial, normal, 400, 100%)in typst.It's clear that the typst coordinate system will not work for all font without some manual intervention.
Proposed solution
In #3213 (comment) @laurmaedje metioned a simpler approach: Do not try very hard to make the typst coordinate working. Just fallback to the OpenType coordinate system (c: FULL_NAME) if the typst coordinate system fails.
I think that is not optimal because when using FULL_NAME, you drop the italic, weight and stretch info.
emphandstrongwill not work. Thus I proposed another approach in #3213 (comment) : Design a systematic approach to map OpenType coordinate to the typst coordinate. This should combine automatic procedure and manual whitelist. This approach has extra future possibilities: We can include small caps in the style axis and mapSome FontandSome Font SmallCapsinto a single family, to enablesmallcapsfunction to work for more font families.laurmaedje commentedon Jan 18, 2024
Typst only uses the first four, not the size for font selection. The family-style-weight-stretch coordinate system is pretty common, e.g. in CSS. It is not Typst-specific. The only thing that's specific is the (hacky) effort Typst makes to have a nicer family name and the few exceptions where Typst patches the metadata based on name.
That's a fair criticism.
To be clear: I am not against adding a general exception mechanism. But as you said, it would require not just a list, but also an automatic produce to get a "nice" uniform family consisting of only fonts differing in style/weight/stretch from the available data in the font. In theory, font names could also be selected in such a way that this property is enforced for a given font set, but that might be weird because an existing font name might change when a new font is installed.
That's why I proposed doing something more predictable and mostly relying on TYPOGRAPHIC_FAMILY. I'd be all on board with a more systematic approach to map OpenType coordinate to the CSS coordinate system if we find a good one.
mkroening commentedon Jan 19, 2024
Wouldn't it make sense for Typst to also use size for font selection? New Computer Modern (and probably others) has different font files optimized for 8 point and 10 point sizes.
reknih commentedon Jan 19, 2024
Computer Modern is actually pretty unique in that respect. The differences in the two variants are due to the Optical Size difference of the fonts, consisting of small weight and detail differences that make the fonts more legible at their respective sizes. Some modern font families include "Display" variants which are intended for display font sizes (>~18pt) but don't make such a clear distinction. Variable fonts have begun to ship the
opszvariation axis for optical sizing. The units on that scale are standardized with regards to point size.Typst does not yet support variable fonts (#185) but once we do, we should automatically adjust the
opszaxis based on font size. In my opinion, support for legacy approaches for optical sizing (dedicated denominated fonts or Display variants) belongs in the same work package instead of here.peng1999 commentedon Jan 19, 2024
I implemented #3228. Feedback appreciated!
[-]Black weight font variant is selected when regular weight was requested[/-][+]corefonts: black weight font variant is selected when regular weight was requested[/+]peng1999 commentedon Feb 1, 2024
@mkroening #3228 Has been merged. Would you like to submit a PR to fix your Arial Black font issue?
mkroening commentedon Feb 1, 2024
@laurmaedje, can you point me to a tool that can be used to extract such information? I'd like my PR fixing this to be comprehensive for all corefonts.
laurmaedje commentedon Feb 1, 2024
I use opentype.js.org. You need the font inspector tab rather than the glyph inspector and then check the OS/2 table.
mkroening commentedon Feb 2, 2024
I just opened #3321.