Commit graph

133 commits

Author SHA1 Message Date
Wren [Undefined]
a03faa654d
Variable font support (#400)
* Variable font support

Here's a pretty naïve solution for variable fonts.

The iterator doesn't use the match keys' weight, but instead tries to
get the requested ideal weight, if the font is variable, otherwise it is
ignored and the actual (non-variable) weight is used. This is because I
didn't implement finding variable weight support for match keys; doing
so would be impossible without parsing TTF files when matching and I
didn't want to add that potentially expensive infrastructure if not
entirely necessary.

This is a breaking change, and I'm open for ideas on how to fix that
if it's an issue.

* cargo fmt

* Add variable font example to rich-text example
2025-07-07 08:50:40 -06:00
Joshix-1
6b3f6cb95e
Fix #386 do not ignore font family (#399)
Font family know gets used when querying the font.
Not sure if this solution is good, if the old code is even needed.
This works for me, which makes it good enough for me.
2025-07-02 10:32:01 -06:00
tigregalis
b347487712
use BuildHasher::default() not BuildHasher::new() (#381) 2025-04-14 08:55:16 -06:00
Taj Pereira
695745ac4f
Store font as peniko::Font behind feature flag (#375)
* Allow exposing Peniko font from cosmic text

* .

* .

* .

* .
2025-04-04 11:19:45 -06:00
Stewart Connor
e828131c92 fix for test.sh 2025-03-31 17:03:51 +11:00
Jeremy Soller
64fd3481f1
Require Fallback implementations to be Send + Sync 2025-03-28 10:33:40 -06:00
tigregalis
b027bab538 use alloc ToOwned and String 2025-03-28 15:57:33 +00:00
tigregalis
35eda69cb1 formatting 2025-03-28 15:57:33 +00:00
tigregalis
16015d7ea6 Document Fallback trait 2025-03-28 15:57:33 +00:00
tigregalis
bdd7882a94 set visibility of Fallbacks to pub(crate) 2025-03-28 15:57:33 +00:00
tigregalis
fb3a7c1a1c Reuse fallbacks 2025-03-28 15:57:33 +00:00
tigregalis
7fb685fa13 Pre-compute the fallbacks on FontFallbackIter::new 2025-03-28 15:57:33 +00:00
tigregalis
ae0fb9b561 Support non-static list of fallbacks 2025-03-28 15:57:33 +00:00
tigregalis
9a4d80d116 derive Debug on PlatformFallback 2025-03-28 15:57:33 +00:00
tigregalis
b32c831f1b export Fallback, PlatformFallback 2025-03-28 15:57:33 +00:00
tigregalis
a67dded054 Use fallback list via dyn trait in FontSystem 2025-03-28 15:57:33 +00:00
Rob Parrett
813b350563 Fix android build 2025-03-11 09:44:15 -06:00
Jeremy Soller
974ddaed96
Update default fonts 2025-02-26 07:57:29 -07:00
Jeremy Soller
f3ba8ec8bb
Load fonts prior to setting defaults 2025-01-27 15:33:46 -07:00
Jeremy Soller
1f97cbd747
Use FreeMono as Braille script fallback, workaround for #237 2025-01-27 12:17:51 -07:00
dsgallups
f05a69a9d9 resolve all lints, update MSRV 2025-01-22 17:00:01 -07:00
HoldMyBeer
166b59f560 Reduce memory usage and loading time of FontSystem 2025-01-10 09:38:43 -07:00
Jan Beich
829a59bd95 Apply fallback font to more Unices
- DragonFly, FreeBSD, NetBSD, OpenBSD all use fontconfig
- Solaris-based systems use fontconfig
2024-12-21 19:16:14 -07:00
Jeremy Soller
1f4065c1c3
Drop ShapePlanCache
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.
2024-11-06 18:59:56 -07:00
Mohammad AlSaleh
e8f567cf5b Fix typo in fallback font name
The font name is "Noto Sans CJK JP", not "Noto Sans CJK JA".

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
2024-09-09 13:43:16 -06:00
koe
9d132f8ebd cache the monospace fallbacks buffer in FontSystem 2024-09-05 07:57:55 -06:00
koe
9dc024616b move ShapeBuffer to FontSystem 2024-09-03 15:59:15 -06:00
Jeremy Soller
58c2ccd1fb
0.12.1: Make collection of monospace fallback information optional 2024-07-31 10:02:11 -06:00
Jeremy Soller
7677ba388c Revert "Promote Noto Color Emoji fallback"
This reverts commit 5e82de11cf.
2024-06-17 17:20:34 -06:00
Kristoffer Ödmark
542b20ca43 Upgrade dependencies, and re-export ttf-parser so that dependents can verify fonts using the same ttf-parser version 2024-06-15 06:05:18 -06:00
Jeremy Soller
89503b254f
Fix compilation without std feature 2024-06-05 08:19:34 -06:00
Itsusinn
39c4e3e02b refactor: move "rayon" feature under "std" 2024-06-05 08:15:51 -06:00
Itsusinn
1f52b5211c fix: no redundant load 2024-06-05 08:15:51 -06:00
Itsusinn
658025314c feat: concurrently load & parse fonts 2024-06-05 08:15:51 -06:00
apricotbucket28
5e82de11cf Promote Noto Color Emoji fallback 2024-06-04 17:51:21 -06:00
Mohammad AlSaleh
18c3d2acec Skip trying monospace fallbacks if default font supports all codepoints
Instead of blindly pushing default font to the start of the monospace
 fallbacks map. Actually collect codepoint support info for it, and if
 it supports all codepoints, skip collecting that info from other
 monospace fonts. If it doesn't, push it to the start of the map as
 before.

 This actually provides a big performance boost, while the sophisticated
 monospace fallback process is still done whenever needed.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
2024-03-10 15:05:07 -06:00
Mohammad AlSaleh
729dc868c2 Only try monospace fonts that support at least one requested script
When font fallback involves monospace fonts, and if word has known
 scripts, limit the fonts tried for fallback to ones that support at
 least one requested script.

 Codepoint support info is still collected for these fonts to guide
 the fallback order selection process.

 A map of per-script monospace font-ids is pre-populated in font system
 to acquire lists of wanted font ids efficiently.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
2024-03-10 15:05:07 -06:00
Mohammad AlSaleh
59ac0b824c Store a sorted list of monospace font ids in font system
Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
2024-03-10 15:05:07 -06:00
Mohammad AlSaleh
3e02ae1ea6 Cache codepoint support info for monospace fonts
For the simplest case of " " words, a quick binary search in
 `supported` vec will suffice, instead of using `slice::contains()`
 for all monospace fonts, where some of them may support thousands of
 codepoints.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
2024-03-10 15:05:07 -06:00
Christopher Serr
8582173128 Fix no_std build
This fixes the `no_std` build and also makes sure it's tested properly
in the CI workflow.
2024-02-12 10:37:49 -07:00
Jeremy Soller
1eb3233373
Add shape-run-cache feature, that can significantly improve shaping performance 2024-02-08 11:12:41 -07:00
Mohammad AlSaleh
0cea55630c Use weight absolute difference in monospace fallback matching
When matching on weights smaller than normal, "equal or smaller"
 weight restriction may cause monospace fallback to fail, depending
 on font support at such weights for the text to be shaped.

 So remove that restriction, and calculate weight differences instead
 of offsets.

 In case of no exact weight match, and with all other factors being
 equal, smaller weights will be picked before bigger ones. So, this
 should generally not cause any behavioral changes when matching on
 normal weight or bigger.

 Should fix pop-os/cosmic-term#104.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
2024-01-31 06:32:37 -07:00
Mohammad AlSaleh
e0ae465f91 Only use relevant info from Attrs as a key in font_matches_cache
`Attrs` contains info like color and metadata which are not relevant
 to font matching.

 So, add a new struct `FontMatchAttrs` which only contains the relevant
 info, and use it as a key in `FontSystem`'s `font_matches_cache`.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
2024-01-23 23:05:52 -07:00
Mohammad AlSaleh
235ec02a20 Add a size limit to font_matches_cache and clear it when it's reached
In `FontSystem`, `font_matches_cache` is an ever growing cache.

 It can also be a fast growing one in stress tests like running this
 in `cosmic-term`:

     mpv -speed 3 -vo tct <some_video>

 So this commit adds a size limit to that cache, and clears the cache
 when that limit is reached, which shouldn't be a common occurrence in
 normal usage.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
2024-01-23 23:05:52 -07:00
Mohammad AlSaleh
db1530c4ec Use supported codepoints instead of scripts in Monospace fallback
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>
2024-01-19 09:37:11 -07:00
Jeremy Soller
6aadfaddac
Fix subtraction overflow when comparing weights 2024-01-18 06:58:47 -07:00
Jeremy Soller
8457e68d98 Fix tests 2024-01-17 13:31:03 -07:00
Jeremy Soller
a11f68f13d Format 2024-01-17 13:31:03 -07:00
Mohammad AlSaleh
329941c4a6 Try harder to succeed at fall-backing to a Monospace font
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>
2024-01-17 13:31:03 -07:00
Jeremy Soller
5f4bc87ccf Remove patch to load Redox system fonts, as fontdb does it now 2024-01-17 13:31:03 -07:00