We want byte indices, not code point indices. Fixes a panic when
selecting the mixed-language text at the bottom of the rich-text example
when the shaping mode is set to "Basic".
The ShapePlanCache was added to improve performance when shaping the same
strings over and over. However, it never had the ability to be trimmed
and when it was moved to FontSystem, this created a permanently growing
allocation. It is recommended to instead use the shape-run-cache feature
which supports trimming if it is desired to have higher performance for
repeated shaping, at the cost of manually specifying when to trim.
This should/could improve fallback order.
This could also probably be utilized for non-Monospace fallback too.
But I didn't want to touch that code to avoid accidentally breaking
anything.
Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
When matching to a default monospace width, big fonts like those
containing symbols and emojis got too small from font resizing.
Adding a glyph-to-default rounded factor to the calculation should fix
that issue without losing monospatiality.
Fixespop-os/cosmic-term#69.
Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
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>
* max_ascent and max_descent declarations moved into loop since they are
reset each iteration and the one spot where they are used outside the
loop for pushing an empty line is if all items are empty (so they
would always be 0.0 there).
* For `Align::Justified`, instead of repurposing `alignment_correction`
variable for expanding blank spaces, there is a new
`justification_expansion` variable. This helps clarify the code.
* Common code for processing ranges factored out section where ranges
are iterated in opposite orders for RTL vs LTR.
* We don't need to use `take_mut` on `glyphs` since the variable is not
used afterwards (i.e. we can just move out of `glyphs`).
* Fix bug where `scratch.scripts` was being used for logging info
instead of `scripts`.
Try to ensure that using "the width computed during an unconstrained
layout" as the width constraint during a relayout produces the same
layout. This is useful for certain UI layout algorithms.
See https://github.com/pop-os/cosmic-text/issues/134
* Instead of computing the LayoutLine width from the positioned and
aligned glyphs, we pass through width computed during line wrapping
(unless justified alignment is used, in this case we use the old
approach because the use case for measuring the width isn't really
applicable to justified text since that will just expand to the
provided width). For the produced width to later give the same
wrapping results when passed in as the `line_width` it needs to use
the same exact float arithmatic that was used to compute the width
that is compared against `line_width` when making line wrapping
choices. Passing this width through as the LayoutLine width is the
most covenient option without making more major changse to the API.
Nevertheless, I am imagining that if we get a dedicated measurement
method (i.e. that doesn't do the final positioning and alignment of
glyphs and which caches `Vec<VisualLine>`), then this width can just
be exposed there instead of preservering it in LayoutLine.
* Incidentally, this fixes
https://github.com/pop-os/cosmic-text/issues/169.
* Switch substraction from `fit_x` to checking whether potential
addition to the current line width would exceed the `line_width`. This
avoids the float error being dependent on the provided `line_width`
value.
* When eliminating trailing space from the line width, we avoid
backtracking with subtraction (which would not give the same exact
value due to float error) and instead save the previous width and use
that.
* If the previous word did not exceed the line_width, we now include a
single blank word even if it would cross the width limit since its
width won't be counted. This is necessary to get the same wrapping
behavior when re-using the measured width (which doesn't count a
single trailing blank word). Note, this whitespace logic may be
reworked anyway if <https://github.com/pop-os/cosmic-text/issues/155>
is addressed.
* Change tests to use `opt-level=1` to keep test runtime down.
* Add `fonts` folder for fonts used in tests.
* Fix an issue where a non-breaking whitespace was assumed to be the
start of a section of spaces which included characters that weren't
even whitespace.
* Add some TODOs about incongruencies between `is_whitespace`,
justification, and line breaks.
This commit adds a new ShapeBuffer type, which contains some buffers tha
are commonly re-created during the shaping process. New APIs are added
that take this structure, and old APIs are turned into wrappers around
the new API.
The goal is to reduce the number of per-layout allocations that happen
in a typical layout call.
For use cases that want to reverse the alignment of RTL
lines, this avoids needing to check the RTL status of every line
manually.
This is a breaking change.