Skip to content

Introduce override list to FontInfo - #3228

Merged
laurmaedje merged 7 commits into
typst:mainfrom
peng1999:font-override
Feb 1, 2024
Merged

laurmaedje merged 7 commits into
typst:mainfrom
peng1999:font-override

Conversation

@peng1999

@peng1999 peng1999 commented Jan 19, 2024 •

Copy link
Copy Markdown
Contributor

Introduce font override list described in #3213 (comment). This PR is exploratory. If it gets merged, a subsequent PR can be submitted to immediately solve #3213, #576 and #2098 (comment) by just adding a few more lines to override_list.yml. And after that, further improvements can be made in subsequent PR.

Changed implementation

  • Override list is added.
    • Using postscript name as the key instead of full name, because it has one-to-one relationship to fonts, while a font may contain multiple full name. Furthermore, postscript name consists of only visible ASCII characters and is no more than 63 characters.
  • All NewCM related hack in fn typographic_family and fn from_ttf is removed.

Changed behaviors

This PR is a refactoring and should not change anything other than the name of NewCM08 family. To be specific, typst fonts will have following change in a system with complete NewCM font installed:

 New Computer Modern
+New Computer Modern 08
 New Computer Modern Math
 New Computer Modern Mono
 New Computer Modern Sans
+New Computer Modern Sans 08
 New Computer Modern Uncial
+New Computer Modern Uncial 08
 NewCM08Devanagari
-NewCM10Devanagari
-NewCMUncial08
-NewComputerModern
-NewComputerModern08
-NewComputerModernSans08
+NewComputerModern 10 Devanagari

@Myriad-Dreamin

Myriad-Dreamin commented Jan 22, 2024 •

Copy link
Copy Markdown
Contributor

According to #3213 (comment), both FULL_NAME and checksum matches have pros and cons.

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.

So, is version string also a good matcher to enhance safety of FULL_NAME match? When a font is fixed since some version, we may not need to override the FontInfo anymore. We may safely think of same version implies same checksum, and we can compare version by some rules.

@peng1999

Copy link
Copy Markdown
Contributor Author

So, is version string also a good matcher to enhance safety of FULL_NAME match?

Yes, I can think of some "conditional" addition in the future:

NewCM08-Book:
  family: New Computer Modern 08
  conditional:
    until-version: 5.1
    weight: 450

But that's out of the scope of this PR. It's just an internal refactoring facilitating future improvements, so it's not suitable to add new features here.

@mkroening

Copy link
Copy Markdown
Contributor

Changed behaviors

This PR is a refactoring and should not change anything other than the name of NewCM08 family. To be specific, typst fonts will have following change in a system with complete NewCM font installed:

 New Computer Modern
+New Computer Modern 08
 New Computer Modern Math
 New Computer Modern Mono
 New Computer Modern Sans
+New Computer Modern Sans 08
 New Computer Modern Uncial
+New Computer Modern Uncial 08
 NewCM08Devanagari
-NewCM10Devanagari
-NewCMUncial08
-NewComputerModern
-NewComputerModern08
-NewComputerModernSans08
+NewComputerModern 10 Devanagari

It seems strange to me that there is NewCM08Devanagari (with abbreviation, without spaces) and NewComputerModern 10 Devanagari (without abbreviation, with spaces). Is that on purpose, or is that a copy and paste error?

@peng1999

Copy link
Copy Markdown
Contributor Author

It seems strange to me that there is NewCM08Devanagari (with abbreviation, without spaces) and NewComputerModern 10 Devanagari (without abbreviation, with spaces). Is that on purpose, or is that a copy and paste error?

  • NewCM08Devanagari-Regular.otf has the following metadata:
    • family: NewCM08Devanagari
    • fullname: NewCM10Devanagari-Regular
  • NewCM10Devanagari-Regular.otf has the following metadata:
    • family: NewComputerModern 10 Devanagari
    • fullname: NewComputerModern 10 Regular

It's totally a mess. The typst code do not have any code to correct that, so do this PR. By a side effect of removing all NewCM related code from book.rs, the display name in typst changed from fullname to fmaily name.

@laurmaedje

Copy link
Copy Markdown
Member

I'm not super happy about the fact that we're embedding a yaml file in the binary and lazily deserialize it and runtime. It feels wasteful.

Considering that phf is already in our dependency tree, how about using a phf::Map and defining the list directly in a Rust file? I'd also prefer to rename override_list.rs to just override..

@peng1999

Copy link
Copy Markdown
Contributor Author

I'd also prefer to rename override_list.rs to just override..

I'd like to name the module override too, but unfortunately that's a Rust reserved name and cannot be used here. Do you have any other name idea?

@laurmaedje

Copy link
Copy Markdown
Member

Maybe exceptions?

@laurmaedje

Copy link
Copy Markdown
Member

Let's use the term "exception" across the board then, also struct Exception instead of OverrideEntry and for the variable names.

Comment thread crates/typst/src/text/font/book.rs Resolved
Comment thread crates/typst/src/text/font/book.rs Resolved
Comment thread crates/typst/src/text/font/book.rs Resolved
@laurmaedje
laurmaedje added this pull request to the merge queue Feb 1, 2024
@laurmaedje

Copy link
Copy Markdown
Member

Thank you!

Merged via the queue into typst:main with commit 464a15b Feb 1, 2024
@peng1999
peng1999 deleted the font-override branch February 1, 2024 14:19
Dherse pushed a commit to Dherse/typst that referenced this pull request Feb 4, 2024
Dikluwe pushed a commit to Dikluwe/typst-crystalline that referenced this pull request Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants