Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions internal/svg/svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/hex"
"encoding/xml"
"errors"
"fmt"
"image"
"image/color"
Expand Down Expand Up @@ -83,12 +82,7 @@ func (d *Decoder) Draw(width, height int) (*image.NRGBA, error) {
img := image.NewNRGBA(image.Rect(0, 0, imgW, imgH))
scanner := rasterx.NewScannerGV(config.Width, config.Height, img, img.Bounds())
raster := rasterx.NewDasher(width, height, scanner)

err := drawSVGSafely(d.icon, raster)
if err != nil {
err = fmt.Errorf("SVG render error: %w", err)
return nil, err
}
d.icon.Draw(raster, 1)
return img, nil
}

Expand Down Expand Up @@ -316,15 +310,3 @@ func colorToHexAndOpacity(color color.Color) (hexStr, aStr string) {
hexStr, aStr = "#"+hex.EncodeToString(cBytes), strconv.FormatFloat(float64(a)/0xff, 'f', 6, 64)
return hexStr, aStr
}

func drawSVGSafely(icon *oksvg.SvgIcon, raster *rasterx.Dasher) error {
var err error
defer func() {
if r := recover(); r != nil {
err = errors.New("crash when rendering svg")
}
}()
icon.Draw(raster, 1)

return err
}
2 changes: 2 additions & 0 deletions widget/card_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

func TestCard_SetImage(t *testing.T) {
c := widget.NewCard("Title", "sub", widget.NewLabel("Content"))
test.NewTempWindow(t, c)

r := test.TempWidgetRenderer(t, c)
assert.Len(t, r.Objects(), 4) // the 3 above plus shadow

Expand Down
Loading