Commit graph

54 commits

Author SHA1 Message Date
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
Stewart Connor
e828131c92 fix for test.sh 2025-03-31 17:03:51 +11:00
Stewart Connor
53763c157b Merge branch 'refs/heads/main' into stewart-add-kerning-ligatures
# Conflicts:
#	src/attrs.rs
2025-03-31 13:42:12 +11:00
Stewart Connor
4e6d5d731b rm std 2025-03-28 15:55:47 +00:00
Stewart Connor
08822cac2e add letter spacing 2025-03-28 15:55:47 +00:00
Stewart Connor
03180dd9ee nits 2025-03-26 17:45:21 +11:00
Stewart Connor
dc03df8986 Add comments 2025-03-26 17:43:13 +11:00
Stewart Connor
71b0680e6f revert the references 2025-03-26 17:06:24 +11:00
Stewart Connor
fb852d3ab5 changes before ref 2025-03-26 14:48:54 +11:00
Stewart Connor
1d7850099f pre-removing copy 2025-03-26 14:31:37 +11:00
Stewart Connor
f5879b3425 add contextual alternatives 2025-03-21 18:24:32 +11:00
Stewart Connor
4b3a6e84ac better defaults 2025-03-21 17:13:24 +11:00
Stewart Connor
d071d1a1c3 add kerning ligatures 2025-03-19 17:45:30 +11:00
dsgallups
f05a69a9d9 resolve all lints, update MSRV 2025-01-22 17:00:01 -07:00
koe
b68f4ad5c6 Optimize Buffer::set_rich_text for when the buffer is reconstructed 2024-09-01 15:00:17 -06:00
koe
c751217020 Add AttrsList::spans_iter and use it in Buffer::append 2024-09-01 07:20:07 -06:00
koe
caa214a755 Use SmolStr in FamilyOwned instead of String 2024-09-01 07:20:07 -06:00
Jeremy Soller
020701734e Address review 2024-06-06 19:38:40 -06:00
Jeremy Soller
8638ec29bb Add metrics to attributes 2024-06-06 19:38:40 -06:00
Aapo Alasuutari
2766961af6 Handle inverted Ranges in add_span 2024-02-22 10:06:50 -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
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
bd5f2f95e8 Add capability to synthesize italic 2024-01-17 13:31:03 -07:00
Jeremy Soller
381b9ed87b
Merge pull request #158 from forkgull/comp-color
Add easy conversions for tuples/arrays for Color
2023-08-04 07:36:27 -06:00
John Nunley
84b6a4e086
Derive Clone for AttrsList 2023-07-24 22:13:34 -07:00
John Nunley
13146f65cc
Add easy conversions for tuples/arrays for Color
This makes it somewhat easier to convert Color to other color types,
such as piet::Color.
2023-07-21 18:41:49 -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
Dima Rets
0eb08d218c allow setting cursor color 2023-06-08 20:04:56 +01:00
Jeremy Soller
3c7dc1f657
Remove monospaced from attrs 2023-03-30 08:04:52 -06:00
grovesNL
a3e035881b Fill out some more docs 2023-01-29 22:29:17 -03:30
Jeremy Soller
8cc988d374 Run cargo fmt 2023-01-04 20:03:03 -07:00
Andrew Wheeler
8614a7a398 Updated RangeMap to Add Clear(). 2022-12-30 08:33:00 -07:00
Jeremy Soller
8bf0032974
Add custom metadata to Attrs, copied to ShapeGlyph and LayoutGlyph 2022-12-14 09:19:03 -07:00
Jeremy Soller
ee54e7626b
Vi-style editor and other editor improvements (#40)
* WIP VI wrapper for editor

* WIP: block cursor

* Create Edit trait, run CI on all feature options

* Add prints describing build steps to ci.sh

* Custom rendering for Vi editor

* Clippy fixes

* More clippy fixes

* Show clippy results in CI

* Fix for Redox

* Fix clippy lint

* Add vi feature to enable vi-style editor

* Add escape to libcosmic text box
2022-11-15 12:26:59 -07:00
Andrew Wheeler(Genusis)
271ca5cf7a
Converted attr range to use RangeMap BTree (#41)
* Converted attr range to use RangeMap BTree

* Change get_span() to use First index instead of range.

* update doc comment
2022-11-14 11:05:34 -07:00
Jeremy Soller
268805ba0c no_std support 2022-11-08 13:24:14 -07:00
Jeremy Soller
ac354c3a2a
Remove AttrsList lifetime bound 2022-11-04 09:44:54 -06:00
Jeremy Soller
26c83be35a
Combine spans in add_span if possible 2022-10-31 10:25:08 -06:00
Andrew Wheeler(Genusis)
f2a60a8dcc
Rework add_span (#25)
* Rework Ranges to split and change or overwrite based on old ranges to new range

* set array size to 3 instead of 5. added some comments

* Avoid adding ranges that the start and end == each other

* actually remove the start != end requirement since get_span doesnt care and would work for single characters.

* Add 1 to forward map so it cant overlap ranges like 11..11

* optimize the span lookup so if it is outside the search parameters it doesnt keep looping. update get span to iterate normally since there should be no duplicates. Maybe optimize this to a btree now instead?

* make the range changes for front to end have the end -1 so as to not overlap since get span is <=

* Readded block for ranges like 1..1
Moved rework ranges into the first loop.
Removed the -1 and +1 from the range clips.
2022-10-29 17:56:14 -06:00
Jeremy Soller
cce821e99f
Adjust attribute spans when buffer lines change 2022-10-27 14:51:46 -06:00
Jeremy Soller
e2b9aa77b9
Iterate attr spans in reverse for efficiency 2022-10-27 13:50:14 -06:00
Jeremy Soller
e4c8d4ba6b
Make attribute spans use ranges and update docs 2022-10-27 09:56:53 -06:00
Jeremy Soller
3ece9236b3
Use Color in more places 2022-10-27 09:07:47 -06:00
Jeremy Soller
40175aac10
Always match emoji regardless of attributes 2022-10-27 08:25:30 -06:00
Jeremy Soller
f85223b376 Only reset lines where highlight changes 2022-10-26 21:27:29 -06:00
Jeremy Soller
ea64291abb
Make it possible to set attributes per glyph 2022-10-26 15:16:06 -06:00
Jeremy Soller
4798c7ee1a
Add initial rich text example 2022-10-26 14:16:48 -06:00
Jeremy Soller
119a570ee9
Cache font matches, use usize for line index, use font system for swash 2022-10-26 12:23:03 -06:00