Refactor frame metadata into tags #4212
Merged
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 replaces the
MetaElem
with a newTagElem
that fills a similar role, but works a bit differently. The purpose of both is to hold elements that will become available through introspection. However, theMetaElem
did this via the style chain, by attaching a style to the full subtree of content resulting from a locatable element, which resulted in lots of redundantFrameItem::Meta(Meta::Elem(_), ..)
in the frames.The new
TagElem
is generated exactly once per locatable element and holds the element directly. The challenge here is that the tag still needs to stick to the element so that if e.g. a heading moves to another page, the page number in the outline is still correct. To that extent, the flow layouter has gained a newpending_tags
array and the tags are only flushed into the frames when something proper is layouted. Overall, the new mechanism is much more efficient. The old thing was actually so bad that the famous thesis benchmark improves by ~14% with this PR.The old
FrameItem::Meta
was also used for hiding and links. These usages have been replaced by a completely internal mechanism for hiding and a new top-levelFrameItem::Link
for links.This PR is only a first small step in an incremental refactor of realization and flow layout. The
TagElem
andpending_tags
aren't necessarily the best way to implement tags in realization and layout, rather they are the least intrusive ones in the current setup. Things will change further as the refactoring progresses. The exact semantics of how tags will stick to elements are also still somewhat in-flux and will likely a change a bit in later refactor phases. These rules affect the results of.page()
and.position()
calls onlocation
s. With this PR, things should mostly be the same as on main, though there will be edge cases where things changed a bit. They might change again with further refactoring.