forked from joejulian/gio
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.
|
||||
func (s *shaperImpl) shapeAndWrapText(params Parameters, txt []rune) (_ []shaping.Line, truncated int) {
|
||||
wc := shaping.WrapConfig{
|
||||
Direction: mapDirection(params.Locale.Direction),
|
||||
TruncateAfterLines: params.MaxLines,
|
||||
TextContinues: params.forceTruncate,
|
||||
BreakPolicy: wrapPolicyToGoText(params.WrapPolicy),
|
||||
Direction: mapDirection(params.Locale.Direction),
|
||||
TruncateAfterLines: params.MaxLines,
|
||||
TextContinues: params.forceTruncate,
|
||||
BreakPolicy: wrapPolicyToGoText(params.WrapPolicy),
|
||||
DisableTrailingWhitespaceTrim: params.DisableSpaceTrim,
|
||||
}
|
||||
families := s.defaultFaces
|
||||
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
|
||||
// shaper to control when it iterates paragraphs of text.
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user