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

Refactor #206

Merged
merged 21 commits into from
Jan 17, 2024
Merged

Refactor #206

merged 21 commits into from
Jan 17, 2024

Conversation

jackpot51
Copy link
Member

@jackpot51 jackpot51 commented Dec 15, 2023

Includes various performance improvements, refactor of cursor motion so it can be done outside of Editor, refactoring of scroll so that previous lines do not have to be shaped, and the ability to prune caches to reduce memory usage.

The most important change is to allow shaping parts of a buffer, by changing scroll to include both an index in Buffer::lines and the layout line. This lets only the part currently within the scrolled view of the buffer to be shaped and laid out. This greatly improves performance when scrolling as it does not have to shape and lay out lines that were never shown.

The shaping functions for Buffer and Editor now take a prune parameter, which when set to true, will drop the shaping and layout information of all lines outside of the scrolled view. This greatly decreases memory usage at the cost of reshaping when scrolling.

@nicoburns
Copy link
Contributor

Ah, it's just clicked for me that "scrolling" in cosmic text is supposed to be understood in the context of something like an editor where you have a fixed-sized area (not dependent on the content) and you can approximate scroll height without shaping by counting newlines. It previously hadn't made any sense to me why you'd only want to shape until scroll, or why cosmic text was involved with scrolling at all.

Somewhat relatedly to this, I've been thinking about what it would take to implement support for CSS floats on top of cosmic-text (on the assumption that cosmic-text would be unlikely to want to support them itself). And my conclusion so far is that it would require the following:

  1. The ability to layout around excluded areas (rectangles)
  2. An incremental/resumable text layout API where you can:
    • Layout up to a point (character index)
    • Yield to the caller and allow them to mutate both the layout generated so far and the input parameters (with them being required to only modify inputs that haven't been consumed so far if they want a sensible resulting layout)
    • Resume layout passing the mutated layout and inputs

This would allow yielding at the locations of floated content, running some external logic to insert a new excluded area and move placed text runs so that they do not overlap this area, and then resuming text layout from that point.

jackpot51 and others added 6 commits January 2, 2024 11:42
A combination of some ideas:

 * Try all Monospace fonts before giving up.
 * Relax exact weight restriction on font matching when trying Monospace
   fall-back. Try smaller weights if needed.
 * Make the fall-back try order weight-offset aware, AND script-aware.
 * And finally, add the option to adjust the font size of glyphs using
   fall-back Monospace fonts, so the width of them matches the default
   font width.

   For my use-case, the current fall-back attempt always fails with
   Arabic script. And none of the Arabic-supporting Monospace fonts in
   my system also support medium weight. So, if my default font is set
   to medium weight, script-aware fall-back alone will still not work.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
@jackpot51 jackpot51 marked this pull request as ready for review January 17, 2024 20:27
@jackpot51 jackpot51 merged commit 8457e68 into main Jan 17, 2024
1 of 2 checks passed
@jackpot51 jackpot51 deleted the refactor branch January 17, 2024 20:37
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.

3 participants