Skip to content

Commit daaa859

Browse files
committed
vg/vgsvg: prepare for stricter sprintf
Go-1.24's govet will reject fmt.Xprintf calls with a non-constant formatting string and no extra argument. e.g.: `foo(str)` instead of `foo(str, arg1)` Signed-off-by: Sebastien Binet <[email protected]>
1 parent faa1a29 commit daaa859

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

vg/vgsvg/vgsvg.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ func (c *Canvas) Stroke(path vg.Path) {
213213
style(elm("fill", "#000000", "none"),
214214
elm("stroke", "none", colorString(c.context().color)),
215215
elm("stroke-opacity", "1", opacityString(c.context().color)),
216-
elm("stroke-width", "1", "%.*g", pr, c.context().lineWidth.Points()),
216+
elmf("stroke-width", "1", "%.*g", pr, c.context().lineWidth.Points()),
217217
elm("stroke-dasharray", "none", dashArrayString(c)),
218-
elm("stroke-dashoffset", "0", "%.*g", pr, c.context().dashOffset.Points())))
218+
elmf("stroke-dashoffset", "0", "%.*g", pr, c.context().dashOffset.Points())))
219219
}
220220

221221
func (c *Canvas) Fill(path vg.Path) {
@@ -351,7 +351,7 @@ func (c *Canvas) FillString(font font.Face, pt vg.Point, str string) {
351351
name := svgFontDescr(font)
352352
sty := style(
353353
name,
354-
elm("font-size", "medium", "%.*gpx", pr, font.Font.Size.Points()),
354+
elmf("font-size", "medium", "%.*gpx", pr, font.Font.Size.Points()),
355355
elm("fill", "#000000", colorString(c.context().color)),
356356
)
357357
if sty != "" {
@@ -605,7 +605,18 @@ func style(elms ...string) string {
605605
// elm returns a style element string with the
606606
// given key and value. If the value matches
607607
// default then the empty string is returned.
608-
func elm(key, def, f string, vls ...interface{}) string {
608+
func elm(key, def, f string) string {
609+
val := f
610+
if val == def {
611+
return ""
612+
}
613+
return key + ":" + val
614+
}
615+
616+
// elmf returns a style element string with the
617+
// given key and value. If the value matches
618+
// default then the empty string is returned.
619+
func elmf(key, def, f string, vls ...interface{}) string {
609620
value := fmt.Sprintf(f, vls...)
610621
if value == def {
611622
return ""

0 commit comments

Comments
 (0)