text,widget{,/material}: [API] move all shaping parameters into text.Parameters

This commit moves the min/max width of shaped text and the text's Locale into
text.Parameters. They were previously passed as separate function parameters to
the shaper, but this made little sense and added visual noise. This is a breaking
change, but only if you previously invoked the shaping API directly.

Callers of text.(*Shaper).LayoutString should change:

    shaper.LayoutString(params, minWidth, maxWidth, locale, "string")

to

    params.MinWidth=minWidth
    params.MaxWidth=maxWidth
    params.Locale=locale
    shaper.LayoutString(params, "string")

Callers of text.(*Shaper).Layout should do likewise.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
Chris Waldon
2023-03-27 16:23:44 -04:00
committed by Elias Naur
parent 9d0a53fc9f
commit 7e8c10927b
10 changed files with 191 additions and 90 deletions
+31 -8
View File
@@ -32,17 +32,30 @@ func makePosTestText(fontSize, lineWidth int, alignOpposite bool) (source string
// bidiSource is crafted to contain multiple consecutive RTL runs (by
// changing scripts within the RTL).
bidiSource := "The quick سماء שלום لا fox تمط שלום غير the lazy dog."
ltrParams := text.Parameters{Font: text.Font{Typeface: "LTR"}, PxPerEm: fixed.I(fontSize)}
rtlParams := text.Parameters{Alignment: text.End, Font: text.Font{Typeface: "RTL"}, PxPerEm: fixed.I(fontSize)}
ltrParams := text.Parameters{
Font: text.Font{Typeface: "LTR"},
PxPerEm: fixed.I(fontSize),
MaxWidth: lineWidth,
MinWidth: lineWidth,
Locale: english,
}
rtlParams := text.Parameters{
Alignment: text.End,
Font: text.Font{Typeface: "RTL"},
PxPerEm: fixed.I(fontSize),
MaxWidth: lineWidth,
MinWidth: lineWidth,
Locale: arabic,
}
if alignOpposite {
ltrParams.Alignment = text.End
rtlParams.Alignment = text.Start
}
shaper.LayoutString(ltrParams, lineWidth, lineWidth, english, bidiSource)
shaper.LayoutString(ltrParams, bidiSource)
for g, ok := shaper.NextGlyph(); ok; g, ok = shaper.NextGlyph() {
bidiLTR = append(bidiLTR, g)
}
shaper.LayoutString(rtlParams, lineWidth, lineWidth, arabic, bidiSource)
shaper.LayoutString(rtlParams, bidiSource)
for g, ok := shaper.NextGlyph(); ok; g, ok = shaper.NextGlyph() {
bidiRTL = append(bidiRTL, g)
}
@@ -64,8 +77,12 @@ func makeAccountingTestText(str string, fontSize, lineWidth int) (txt []text.Gly
Face: rtlFace,
},
})
params := text.Parameters{PxPerEm: fixed.I(fontSize)}
shaper.LayoutString(params, 0, lineWidth, english, str)
params := text.Parameters{
PxPerEm: fixed.I(fontSize),
MaxWidth: lineWidth,
Locale: english,
}
shaper.LayoutString(params, str)
for g, ok := shaper.NextGlyph(); ok; g, ok = shaper.NextGlyph() {
txt = append(txt, g)
}
@@ -86,8 +103,14 @@ func getGlyphs(fontSize, minWidth, lineWidth int, align text.Alignment, str stri
Face: rtlFace,
},
})
params := text.Parameters{PxPerEm: fixed.I(fontSize), Alignment: align}
shaper.LayoutString(params, minWidth, lineWidth, english, str)
params := text.Parameters{
PxPerEm: fixed.I(fontSize),
Alignment: align,
MinWidth: minWidth,
MaxWidth: lineWidth,
Locale: english,
}
shaper.LayoutString(params, str)
for g, ok := shaper.NextGlyph(); ok; g, ok = shaper.NextGlyph() {
txt = append(txt, g)
}