···
···
-
// DrawSVGIcon draws an SVG icon from the embedded files at the specified position
-
func (c *Card) DrawSVGIcon(svgPath string, x, y, size int, iconColor color.Color) error {
-
svgData, err := pages.Files.ReadFile(svgPath)
-
return fmt.Errorf("failed to read SVG file %s: %w", svgPath, err)
// Convert color to hex string for SVG
rgba, isRGBA := iconColor.(color.RGBA)
···
icon, err := oksvg.ReadIconStream(strings.NewReader(svgString))
-
return fmt.Errorf("failed to parse SVG %s: %w", svgPath, err)
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
···
···
+
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))
+
return nil, fmt.Errorf("failed to parse SVG: %w", err)
+
func BuildSVGIconFromPath(svgPath string, iconColor color.Color) (*oksvg.SvgIcon, error) {
+
svgData, err := pages.Files.ReadFile(svgPath)
+
return nil, fmt.Errorf("failed to read SVG file %s: %w", svgPath, err)
+
icon, err := BuildSVGIconFromData(svgData, iconColor)
+
return nil, fmt.Errorf("failed to build SVG icon %s: %w", svgPath, err)
+
func BuildLucideIcon(name string, iconColor color.Color) (*oksvg.SvgIcon, error) {
+
return BuildSVGIconFromPath(fmt.Sprintf("static/icons/%s.svg", name), iconColor)
+
func (c *Card) DrawLucideIcon(name string, x, y, size int, iconColor color.Color) error {
+
icon, err := BuildSVGIconFromPath(fmt.Sprintf("static/icons/%s.svg", name), iconColor)
+
c.DrawSVGIcon(icon, x, y, size)
+
func (c *Card) DrawDollySilhouette(x, y, size int, iconColor color.Color) error {
+
tpl, err := template.New("dolly").
+
ParseFS(pages.Files, "templates/fragments/dolly/silhouette.html")
+
return fmt.Errorf("failed to read dolly silhouette template: %w", err)
+
var svgData bytes.Buffer
+
if err = tpl.ExecuteTemplate(&svgData, "fragments/dolly/silhouette", nil); err != nil {
+
return fmt.Errorf("failed to execute dolly silhouette template: %w", err)
+
icon, err := BuildSVGIconFromData(svgData.Bytes(), iconColor)
+
c.DrawSVGIcon(icon, x, y, size)
+
// DrawSVGIcon draws an SVG icon from the embedded files at the specified position
+
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