Commit graph

75 commits

Author SHA1 Message Date
Dov Reshef
ba96cceacc Fix rendering of RTL words 2023-09-23 17:13:03 +03: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
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
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
Héctor Ramón Jiménez
eb09cf0259
Introduce PhysicalGlyph for offsetting and scaling 2023-06-20 06:07:24 +02:00
Héctor Ramón Jiménez
2fbd65a64f
Compute ascent and descent only once in shape_skip 2023-06-16 02:39:54 +02:00
Héctor Ramón Jiménez
ffa08d2da1
Use rustybuzz in shape_fallback instead of swash 2023-06-16 02:38:00 +02:00
Héctor Ramón Jiménez
c2bef6a345
Align glyphs in a LayoutRun to baseline 2023-06-16 02:15:44 +02:00
Jeremy Soller
9062cce140
Merge pull request #122 from hecrj/feature/shaping-switch
`Shaping` strategy selection
2023-06-08 12:47:04 -06:00
Nico Burns
8d37da51b9 Fix non-wrapped alignment 2023-05-19 02:45:35 +01:00
Héctor Ramón Jiménez
b85d6a4f23
Use Vec::new instead of vec! macro 2023-04-21 20:56:11 +02:00
Héctor Ramón Jiménez
87d75531b7
Allow Shaping::Basic only if swash feature is enabled 2023-04-21 20:47:02 +02:00
Héctor Ramón Jiménez
9e559e150d
Write docs for Shaping enum 2023-04-21 20:27:00 +02:00
Héctor Ramón Jiménez
0f055c0a13
Replace skip_shaping boolean with Shaping enum 2023-04-21 20:24:44 +02:00
Héctor Ramón Jiménez
ad111a1df1
Add skip_shaping flag to avoid expensive shaping when not needed 2023-04-19 00:24:43 +02:00
Jeremy Soller
9ebbc33792 Merge branch 'mut-font-system' of https://github.com/geieredgar/cosmic-text into geieredgar-mut-font-system 2023-03-17 18:15:45 -06:00
Edgar Geier
d297a6a48a
Call get_font lazily 2023-03-14 00:39:50 +01:00
Hojjat
05b069911a Fix indices (suggestions by geieredgar) 2023-03-13 13:08:35 -06:00
Hojjat
7fa51c6404 Fixed some typos 2023-03-13 08:50:24 -06:00
Hojjat
8d503af956 bugfix: mixed ltr+rtl overflow 2023-03-12 21:37:10 -06:00
Edgar Geier
384c5c1fdc
Remove Mutex from FontSystem 2023-03-12 10:39:56 +01:00
Edgar Geier
46e9ef0246
Make BorrowedWithFontSystem borrow FontSystem mutably 2023-03-12 10:39:56 +01:00
Edgar Geier
bff5aaaea3
Make FontSystem not self-referencing 2023-03-12 10:23:54 +01:00
Edgar Geier
2c1d564d62
Update fontdb dependency to version 0.13 2023-03-03 13:07:49 +01:00
Jeremy Soller
eca804c732
Revert "Make FontSystem not self-referencing and update fontdb and rustybuzz" 2023-03-02 18:16:57 -07:00
Edgar Geier
f8bc71af0a
Update fontdb dependency to version 0.13 2023-03-03 00:53:00 +01:00
Edgar Geier
506a4194be
Make FontSystem not self-referencing 2023-03-03 00:53:00 +01:00
Edgar Geier
6c501c6640
Fix clippy warnings 2023-03-01 22:58:41 +01:00
Héctor Ramón Jiménez
4320ae6329
Use f32 instead of i32 for lengths
This allows users to use logical coordinates instead of physical ones.
2023-02-28 03:39:31 +01:00
Hojjat
fdd3ee83a5 Fix selection highlighting when paragraph is justified 2023-02-24 13:00:25 -07:00
Hojjat
d313713f44 Removed alignment from Buffer, added alignment per Bufferline to editor-libcosmic 2023-02-23 14:23:56 -07:00
Hojjat
27d52a12e9 Fix the trailing space 2023-02-23 13:26:21 -07:00
Hojjat
59e89bdbaa Justified 2023-02-22 20:48:57 -07:00
Hojjat
00ff5b72f3 Align Left, Right, and Center works 2023-02-22 18:31:49 -07:00
Jeremy Soller
8cc988d374 Run cargo fmt 2023-01-04 20:03:03 -07:00
Hojjat
b9fef72f76 Added an enum with the option for "No Wraping" 2022-12-20 13:38:34 -07:00
Hojjat
1454a53b21 Glyph based wrapping implemeted 2022-12-20 04:48:53 -07:00
Hojjat
a4ed73b664 Simplify the layout algorithm 2022-12-20 04:48:53 -07:00
Hojjat
1bc476c06e This solves a few bugs:
Fixes long words in BiDi text.
Fixes issues with small text area and large font (no duplicates)
But I feel I need to rewirte this function. It's too convluted and ugly
2022-12-20 04:48:53 -07:00
Hojjat
499e6ccb06 Bug fix: duplicate lines in specific conditions. 2022-12-20 04:48:53 -07:00
Hojjat
8beeca2822 Fix duplicate visual lines when a word is too long
Words longer than the linewidth used to show up duplicated
2022-12-20 04:48:53 -07:00
Hojjat
e38a302599 Make ShapeWord::x/y_advance pub 2022-12-20 04:48:53 -07:00
Hojjat
25a3367ef9 Turn a consequtive whitespaces into separate words
Currently a sequence like this "hello      " (a word followed by
6 spaces). Would be shaped into two words: ["hello     " , " "]
This causes issues, since the first word is only 5 letters long,  not 10
This commit will break this sequence into:
["hello", " ", " ", " ", " ", " ", " "]
This helps with correct line wrappipng
2022-12-20 04:48:53 -07:00