mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
text: allow disabling space trimming
This commit adds a shaping parameter that disables the trimming of trailing whitespace from lines. Text editors and similar use-cases want trailing whitspace glyphs to be selectable, which means they must occupy space. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
+5
-4
@@ -490,10 +490,11 @@ func wrapPolicyToGoText(p WrapPolicy) shaping.LineBreakPolicy {
|
|||||||
// shapeAndWrapText invokes the text shaper and returns wrapped lines in the shaper's native format.
|
// shapeAndWrapText invokes the text shaper and returns wrapped lines in the shaper's native format.
|
||||||
func (s *shaperImpl) shapeAndWrapText(params Parameters, txt []rune) (_ []shaping.Line, truncated int) {
|
func (s *shaperImpl) shapeAndWrapText(params Parameters, txt []rune) (_ []shaping.Line, truncated int) {
|
||||||
wc := shaping.WrapConfig{
|
wc := shaping.WrapConfig{
|
||||||
Direction: mapDirection(params.Locale.Direction),
|
Direction: mapDirection(params.Locale.Direction),
|
||||||
TruncateAfterLines: params.MaxLines,
|
TruncateAfterLines: params.MaxLines,
|
||||||
TextContinues: params.forceTruncate,
|
TextContinues: params.forceTruncate,
|
||||||
BreakPolicy: wrapPolicyToGoText(params.WrapPolicy),
|
BreakPolicy: wrapPolicyToGoText(params.WrapPolicy),
|
||||||
|
DisableTrailingWhitespaceTrim: params.DisableSpaceTrim,
|
||||||
}
|
}
|
||||||
families := s.defaultFaces
|
families := s.defaultFaces
|
||||||
if params.Font.Typeface != "" {
|
if params.Font.Typeface != "" {
|
||||||
|
|||||||
@@ -76,6 +76,11 @@ type Parameters struct {
|
|||||||
// text with a MaxLines. It is unexported because this behavior only makes sense for the
|
// text with a MaxLines. It is unexported because this behavior only makes sense for the
|
||||||
// shaper to control when it iterates paragraphs of text.
|
// shaper to control when it iterates paragraphs of text.
|
||||||
forceTruncate bool
|
forceTruncate bool
|
||||||
|
|
||||||
|
// DisableSpaceTrim prevents the width of the final whitespace glyph on a line from being zeroed.
|
||||||
|
// This is desirable for text editors (so that the whitespace can be selected), but is undesirable
|
||||||
|
// for ordinary display text.
|
||||||
|
DisableSpaceTrim bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type FontFace = giofont.FontFace
|
type FontFace = giofont.FontFace
|
||||||
|
|||||||
Reference in New Issue
Block a user