Commit graph

106 commits

Author SHA1 Message Date
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
Jeremy Soller
d0b4b4635e Refactor of scroll and shaping
- Scroll is identified by line index and layout index, instead of just
  layout index
- Shaping has the option to prune, where caches outside of the scroll
  view are cleared
- Syntax editor no longer requires layout of all lines, only of lines
  inside scroll
- BufferLine has a metadata field that can be used by other abstractions
  to know when text was changed
2024-01-17 13:31:03 -07:00
David Stern
73acfb0962 Cache rustybuzz shape plans. 2023-12-18 18:19:27 -05:00
hz
ed67add28a Don't use Emoji fonts as monospace fallback 2023-11-04 14:31:18 +01:00
Jeremy Soller
30398c2f0c
Merge pull request #188 from EHfive/use_self_cell
Use self_cell for creating self-referential struct
2023-09-18 12:25:02 -06:00
Huang-Huang Bao
331710a16f
Use self_cell for creating self-referential struct
Remove indigenous unsafe self-referential implemention which has a lesser chance to be audited.
2023-09-19 02:16:23 +08:00
Héctor Ramón Jiménez
9d1d5a54c6
Respect fontconfig font aliases when enabled 2023-09-18 19:59:35 +02:00
John Nunley
64e469718b Use a scratch buffer to reduce allocations
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.
2023-08-16 14:09:54 -07:00
grovesNL
c4d107563a Require either std or no_std to be specified 2023-08-09 11:44:20 -02:30
grovesNL
14d0ceb81b Move hashbrown behind no_std feature 2023-08-09 10:19:24 -02:30
John Nunley
2509fc21e2
Fix a warning 2023-07-24 18:09:31 -07:00
John Nunley
7b289c945b
Fix no_std build 2023-07-24 17:57:46 -07:00
John Nunley
faa1ceafda Unify the no_std and std impls of FontSystem 2023-07-24 08:51:19 -07:00
Jeremy Soller
bd58940c42
Merge pull request #153 from forkgull/more-debug
Add more Debug implementations
2023-07-24 09:45:58 -06:00
John Nunley
e65bcbc4d3
Change to a feature 2023-07-22 08:24:28 -07:00
John Nunley
831e025cb1
Upgrade missing glyphs to a warning
It is annoying to have to grep through DEBUG logs for this.
2023-07-21 18:04:00 -07:00
John Nunley
440d24ffa0
Add more Debug implementations
I generally like to implement Debug on these kind of types.
2023-07-07 21:44:21 -07:00
Jeremy Soller
39895c988a
Merge pull request #132 from trimental/monospaced-fallback
Fallback to monospaced font if Monospace family is not found
2023-06-08 12:38:17 -06:00
Jeremy Soller
f0becfdb54
Fix comment typo 2023-06-08 12:32:34 -06:00
bjorn3
95e36249d5 Remove the dependency on ouroboros
This reduces compilation time by removing a dependency on syn and other
dependencies of ouroboros_macros. In addition it saves a lot of unused
codegened methods.

On my laptop (2 core + HT) this reduces compilation time by ~20%. On a
many core system this doesn't help much though as the critical path path
consists of both ttf-parser -> rustybuzz and swash. Further gains will
likely need to be made by reducing compilation time for these crates.

Benchmark 1: cargo build
  Time (mean ± σ):     25.150 s ±  0.167 s    [User: 84.414 s, System: 7.335 s]
  Range (min … max):   24.909 s … 25.444 s    10 runs

Benchmark 1: cargo build
  Time (mean ± σ):     19.819 s ±  0.226 s    [User: 67.754 s, System: 5.592 s]
  Range (min … max):   19.492 s … 20.140 s    10 runs

The code is based on an expansion of the ouroboros macro, cleaned up to
remove all unused methods and inline most functions that are only called
once.
2023-06-08 18:00:42 +02:00
Lucas Timmins
e1e9fb5215 Fallback to monospaced font if Monospace family is not found 2023-05-20 02:05:52 +08:00
Christopher Serr
71281a5d79 Fix FontSystem::new_with_locale_and_db Signature
It turns out that the `no_std` version of
`FontSystem::new_with_locale_and_db` doesn't match the `std` version.
This fixes that.
2023-03-29 22:36:54 +02:00
Christopher Serr
8a14734033 Expose rustybuzz in the public API
This exposes `rustybuzz` on top of `fontdb`. This is in particular
useful if you want to query the font for additional information. This is
already publically exposed via `Font::rustybuzz()`, but the types were
not re-exported, so it was impossible to properly use that function.
2023-03-27 23:08:32 +02:00
Edgar Geier
d297a6a48a
Call get_font lazily 2023-03-14 00:39:50 +01:00
Edgar Geier
f86acd325c
Lazily call make_shared_face_data 2023-03-13 11:15:36 +01:00
Edgar Geier
af4378d753
Add db_mut method to FontSystem 2023-03-12 10:39:58 +01:00
Edgar Geier
3331f41d7a
Improve documentation 2023-03-12 10:39:57 +01:00
Edgar Geier
384c5c1fdc
Remove Mutex from FontSystem 2023-03-12 10:39:56 +01:00