Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codify and Resolve modifiers #46

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

T0mstone
Copy link
Collaborator

@T0mstone T0mstone commented Feb 3, 2025

Closes #30.

The most important idea of this PR is that it codifies what a "modifier" is.
In that aspect, it stands on its own and makes sense even without considering the context of usage in typst.

For this, there is a new ModifierSet type that contains all the logic for comparing and composing modifiers.
This new type is designed to be generic, so that typst can reuse it with EcoString.
(In particular, typst's symbol::Repr::Modified would change to Modified(Arc<(List, ModifierSet<EcoString>)>))
Some private functions from typst-library/src/foundations/symbol.rs are lifted to public methods on ModifierSet:

  • parts becomes ModifierSet::iter
  • contained becomes ModifierSet::contains
  • find becomes ModifierSet::best_match_in (with reversed argument order), which is generic since it was really easy to make it so and this prepares it for when we let symbols have more than one char per variant (cf. Emoji Variation selectors #25)

I've also taken the liberty of consolidating the types from lib.rs and build.rs. It bugged me that they were duplicated and this change didn't really do anything in terms of code size while arguably improving maintainability (unless you don't like macros, but even among macros this one is very tame).

There are some new functions (get, variants and modifiers) on codex::Symbol that somewhat mirror the ones on typst's Symbol, but aren't intended to replace them right now (for why, see the next paragraph). They just made sense to add anyway.
The only changes made to typst would be to start using ModifierSet, which would basically have the effect of having moved the relevant code from typst to codex.

Actually integrating typst's symbol::Repr::Modified into codex proved too complicated, so I left that for later (if we even need it). Further considerations regarding the integrating of this into typst is left to a future PR at typst/typst (only if this one is accepted, of course).

@T0mstone T0mstone changed the title Resolve modifiers Codify and Resolve modifiers Feb 3, 2025
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.

Resolve modifiers
1 participant