1// Copyright 2017 The oksvg Authors. All rights reserved.
2// created: 2/12/2017 by S.R.Wiley
3//
4// utils.go implements translation of an SVG2.0 path into a rasterx Path.
5
6package oksvg
7
8import (
9 "github.com/srwiley/rasterx"
10)
11
12// SvgIcon holds data from parsed SVGs.
13type SvgIcon struct {
14 ViewBox struct{ X, Y, W, H float64 }
15 Titles []string // Title elements collect here
16 Descriptions []string // Description elements collect here
17 Grads map[string]*rasterx.Gradient
18 Defs map[string][]definition
19 SVGPaths []SvgPath
20 Transform rasterx.Matrix2D
21 classes map[string]styleAttribute
22}
23
24// Draw the compiled SVG icon into the GraphicContext.
25// All elements should be contained by the Bounds rectangle of the SvgIcon.
26func (s *SvgIcon) Draw(r *rasterx.Dasher, opacity float64) {
27 for _, svgp := range s.SVGPaths {
28 svgp.DrawTransformed(r, opacity, s.Transform)
29 }
30}
31
32// SetTarget sets the Transform matrix to draw within the bounds of the rectangle arguments
33func (s *SvgIcon) SetTarget(x, y, w, h float64) {
34 scaleW := w / s.ViewBox.W
35 scaleH := h / s.ViewBox.H
36 s.Transform = rasterx.Identity.Translate(x-s.ViewBox.X, y-s.ViewBox.Y).Scale(scaleW, scaleH)
37}