Commit graph

140 commits

Author SHA1 Message Date
Todd York
ee702e5090 Reorder fields in FontMatchKey to fix fallback logic; Add comments 2026-01-20 08:40:39 -07:00
Todd York
a288f1d775 Shape as fake italic if no matching italic font exists 2026-01-16 10:43:22 -07:00
Todd York
e9075aeae8 Allow fallback to fonts with mismatched stretch or style 2026-01-16 10:43:22 -07:00
Nico Burns
e04bfd098f
Use linebender_resource_handle instead of peniko (#424)
Signed-off-by: Nico Burns <nico@nicoburns.com>
2025-09-21 06:45:37 -06:00
valadaptive
2610c869f6
Replace rustybuzz with HarfRust (#417)
* Use HarfRust for shaping

* Replace ttf-parser with skrifa entirely

* Fix clippy lints

* Add shape plan cache

* Bump harfrust and skrifa

* Fix no_std build

* Simplify the shape plan cache

* Please the paperclip

* Cache font ID with plan

* Tune shape plan cache for "BiDi Processing" bench
2025-09-08 21:15:27 -06:00
romanstingler
a2f1f4b2a0
refactor: address clippy warnings and improve code quality (#409)
- Fix string formatting with modern interpolation syntax
- Improve Debug implementation with finish_non_exhaustive()
- Fix function placement in shape.rs to avoid items_after_statements warning
- Use more idiomatic Rust patterns (map_or_else, next_back)
- Clean up conditional imports in vi.rs
- Convert multiple methods to `const` functions for optimization and consistency
- Introduce `core_maths` for enhanced no-std compatibility
- Update `Cargo.toml` for the new optional dependency and feature adjustments
2025-08-11 13:58:59 -06:00
romanstingler
e80dbc3607
Optimize BidiParagraphs with ASCII fast path (#408)
* Optimize BidiParagraphs with ASCII fast path - Added fast path for ASCII text that avoids BidiInfo allocation - Added some text shaping benchmarks

* refactor: fix clippy warnings and cleanup imports
2025-08-11 13:15:09 -06:00
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