Commit graph

319 commits

Author SHA1 Message Date
Jeremy Soller
db0883b525 Editor: add GotoLine action 2023-11-07 15:56:31 -07:00
Jeremy Soller
e62fea5efd
SyntaxEditor: Support using two-face syntax definitions 2023-11-02 13:38:25 -06:00
Jeremy Soller
ac389d9eeb
SyntaxEditor: Allow retrieving syntax theme, optimize updates to theme 2023-11-02 12:55:45 -06:00
Jeremy Soller
241c4ca357
Buffer::set_rich_text: Only add attrs if they don't match the defaults 2023-11-02 10:24:28 -06:00
Jeremy Soller
6196d72266
Syntax highlight on demand 2023-11-02 09:57:24 -06:00
Jeremy Soller
ca35e1f429
ViEditor: redraw when passthrough mode changed 2023-11-01 14:17:37 -06:00
Jeremy Soller
7855dce09d
Add indent action and tab width 2023-11-01 13:31:53 -06:00
Jeremy Soller
d53932bd7c Add function to set metrics and size simultaneously 2023-10-31 20:40:46 -06:00
Jeremy Soller
423fc22439
ViEditor: fix cursor and select positions 2023-10-27 13:17:56 -06:00
Jeremy Soller
ad10e7373b
Require default Attrs to be specified in set_rich_text 2023-10-27 13:08:27 -06:00
Jeremy Soller
c1e40363ab
ViEditor: implement search, capture commands 2023-10-20 14:11:18 -06:00
Jeremy Soller
7526fa9726
Editor: Request redraw/scroll on set_cursor 2023-10-20 13:54:54 -06:00
Jeremy Soller
37789ccdf7
ViEditor: expose current mode, add word stubs 2023-10-20 12:34:03 -06:00
Jeremy Soller
a29eefca5a
ViEditor: implement I and ^ using SoftHome 2023-10-20 10:26:17 -06:00
Jeremy Soller
4adcbf6784
Editor: add SoftHome action to skip blank space 2023-10-20 10:25:46 -06:00
Jeremy Soller
c6e4f9d04c
ViEditor: add passthrough mode (disables vi features) 2023-10-20 09:46:21 -06:00
Jeremy Soller
6d59885200
ViEditor: draw syntax background color 2023-10-20 09:45:25 -06:00
Dov Reshef
ba96cceacc Fix rendering of RTL words 2023-09-23 17:13:03 +03: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
Héctor Ramón Jiménez
0bb02227de
Use attributes at cursor position for insertions in Editor 2023-09-17 22:37:18 +02:00
Héctor Ramón Jiménez
cb83458e7d
Rewrite PreviousWord logic in Editor with iterators 2023-09-16 16:18:58 +02:00
Héctor Ramón Jiménez
4aacd436c3
Fix NextWord action in Editor when line ends with word boundaries 2023-09-16 16:18:58 +02:00
Héctor Ramón Jiménez
797f1c7941
Set cursor_moved to true in Editor::insert_string 2023-09-16 16:18:58 +02:00
Héctor Ramón Jiménez
6235716beb
Make Edit::copy_selection immutable 2023-09-16 16:18:56 +02:00
Jeremy Soller
1eab951e27
Merge pull request #149 from tigregalis/set-rich-text
Add `Buffer::set_rich_text` method
2023-09-11 10:58:39 -06:00
Imbris
5f28feef1f Move variables down that are only used when creating LayoutLines and replaced used of push_line bool with checking is layout_lines is empty 2023-08-28 16:09:07 -04:00
Imbris
ae96bf26d1 Deduplicate / reorganize / clarify code for creating LayoutLines
* 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`.
2023-08-28 16:05:48 -04:00
Imbris
24ef4e2fd9 Small code organization changes in ShapeLine::layout: move some variables declarations down closer to where they are used, move variables that are reset every loop down to be declared in the loop, replace Vec::new + mem::swap with mem::take 2023-08-28 15:54:22 -04:00
Imbris
13664ef86e Comment typo fix 2023-08-25 21:17:56 -04:00
Imbris
91674d5a49 Fix #134 and include a test for it.
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.
2023-08-25 21:00:46 -04:00
John Nunley
8d6a5b41fb
Fix debug error
Signed-off-by: John Nunley <dev@notgull.net>
2023-08-16 14:13:36 -07: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
Jeremy Soller
0476d7cdbb
Merge pull request #160 from forkgull/changable-fallback
Unify the no_std and std impls of FontSystem
2023-08-06 16:03:50 -06: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
Imbris
9d2d2dd7a6
Remove shape reset from BufferLine::set_align docs since that isn't performed 2023-08-02 00:15:46 -04:00
John Nunley
84b6a4e086
Derive Clone for AttrsList 2023-07-24 22:13:34 -07:00
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
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
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
John Nunley
aa1b37aede
Add Align::End for end-based alignment
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.
2023-07-07 21:31:17 -07:00
Jeremy Soller
edd9eb8b23
Merge branch 'offsetting-and-scaling' 2023-07-06 06:47:34 -06:00