···
···
282
-
// DrawSVGIcon draws an SVG icon from the embedded files at the specified position
283
-
func (c *Card) DrawSVGIcon(svgPath string, x, y, size int, iconColor color.Color) error {
284
-
svgData, err := pages.Files.ReadFile(svgPath)
286
-
return fmt.Errorf("failed to read SVG file %s: %w", svgPath, err)
283
+
func BuildSVGIconFromData(svgData []byte, iconColor color.Color) (*oksvg.SvgIcon, error) {
// Convert color to hex string for SVG
rgba, isRGBA := iconColor.(color.RGBA)
···
icon, err := oksvg.ReadIconStream(strings.NewReader(svgString))
307
-
return fmt.Errorf("failed to parse SVG %s: %w", svgPath, err)
302
+
return nil, fmt.Errorf("failed to parse SVG: %w", err)
308
+
func BuildSVGIconFromPath(svgPath string, iconColor color.Color) (*oksvg.SvgIcon, error) {
309
+
svgData, err := pages.Files.ReadFile(svgPath)
311
+
return nil, fmt.Errorf("failed to read SVG file %s: %w", svgPath, err)
314
+
icon, err := BuildSVGIconFromData(svgData, iconColor)
316
+
return nil, fmt.Errorf("failed to build SVG icon %s: %w", svgPath, err)
322
+
func BuildLucideIcon(name string, iconColor color.Color) (*oksvg.SvgIcon, error) {
323
+
return BuildSVGIconFromPath(fmt.Sprintf("static/icons/%s.svg", name), iconColor)
326
+
func (c *Card) DrawLucideIcon(name string, x, y, size int, iconColor color.Color) error {
327
+
icon, err := BuildSVGIconFromPath(fmt.Sprintf("static/icons/%s.svg", name), iconColor)
332
+
c.DrawSVGIcon(icon, x, y, size)
337
+
func (c *Card) DrawDollySilhouette(x, y, size int, iconColor color.Color) error {
338
+
tpl, err := template.New("dolly").
339
+
ParseFS(pages.Files, "templates/fragments/dolly/silhouette.html")
341
+
return fmt.Errorf("failed to read dolly silhouette template: %w", err)
344
+
var svgData bytes.Buffer
345
+
if err = tpl.ExecuteTemplate(&svgData, "fragments/dolly/silhouette", nil); err != nil {
346
+
return fmt.Errorf("failed to execute dolly silhouette template: %w", err)
349
+
icon, err := BuildSVGIconFromData(svgData.Bytes(), iconColor)
354
+
c.DrawSVGIcon(icon, x, y, size)
359
+
// DrawSVGIcon draws an SVG icon from the embedded files at the specified position
360
+
func (c *Card) DrawSVGIcon(icon *oksvg.SvgIcon, x, y, size int) {
w, h := float64(size), float64(size)
icon.SetTarget(0, 0, w, h)
···
draw.Draw(c.Img, destRect, iconImg, image.Point{}, draw.Over)
// DrawImage fills the card with an image, scaled to maintain the original aspect ratio and centered with respect to the non-filled dimension