Merged
Conversation
Myriad-Dreamin
pushed a commit
to Myriad-Dreamin/typst
that referenced
this pull request
Jul 9, 2024
1 task
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR refactors line building in paragraphs and adjacent code to improve correctness and maintainability. The code is now much simpler to follow and a few bugs have been fixed as a result.
The
Linestruct doesn't use thefirst, inner, lastsetup anymore. Instead it holds aVecofCow-like items. This enables various simplifications in the code. I also experimented with smallvec, but it didn't actually give any gains. Allocations do not seem to be the bottleneck here.The reshaping code has gotten much simpler. Previously it was riddled with endless hard-to-follow conditions. Now all line-intersecting paragraph items are just iterated and everything that's split is reshaped. The line-intersecting was made much more efficient in the worst case. Previously, it was$O(n^2)$ with $n$ being the number of items, now it's $O(n)$ . This doesn't make a big difference for normal paragraphs, but very long raw blocks, for example, do profit from it. And it's just good to not have accidental quadratic runtime.
BiDi reordering now happens eagerly in
fn lineinstead of infn commit. This means that line boundaries are actually properly known while the line is measured, improving correctness. BiDi reordering is now also fully skipped if the paragraph is mono-directional.Line trimming was improved so that paragraphs with explicit trailing whitespace layout as intended (fixes Paragraphs with explicit trailing whitespace don't layout as intended #597). Also fixes a bug with equations (fixes Extra space is added when a line is broken at the beginning of an inline equation #4278). Trimming now also works in front of tags (there was no issue for this, but it was a bug).
A few bugs related to empty paragraphs (
#"") have been fixed.