renderSVG renders the [Icon.svg] if necessary.
()
| 75 | |
| 76 | // renderSVG renders the [Icon.svg] if necessary. |
| 77 | func (ic *Icon) renderSVG() { |
| 78 | if ic.svg.Root == nil || !ic.svg.Root.HasChildren() { |
| 79 | return |
| 80 | } |
| 81 | |
| 82 | sv := &ic.svg |
| 83 | sz := ic.Geom.Size.Actual.Content.ToPoint() |
| 84 | clr := gradient.ApplyOpacity(ic.Styles.Color, ic.Styles.Opacity) |
| 85 | if !ic.NeedsRebuild() && sv.Pixels != nil { // if rebuilding then rebuild |
| 86 | isz := sv.Pixels.Bounds().Size() |
| 87 | // if nothing has changed, we don't need to re-render |
| 88 | if isz == sz && sv.Name == string(ic.Icon) && sv.Color == clr { |
| 89 | return |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if sz == (image.Point{}) { |
| 94 | return |
| 95 | } |
| 96 | // ensure that we have new pixels to render to in order to prevent |
| 97 | // us from rendering over ourself |
| 98 | sv.Pixels = image.NewRGBA(image.Rectangle{Max: sz}) |
| 99 | sv.RenderState.Init(sz.X, sz.Y, sv.Pixels) |
| 100 | sv.Geom.Size = sz // make sure |
| 101 | |
| 102 | sv.Resize(sz) // does Config if needed |
| 103 | |
| 104 | sv.Color = clr |
| 105 | |
| 106 | sv.Scale = 1 |
| 107 | sv.Render() |
| 108 | sv.Name = string(ic.Icon) |
| 109 | } |
| 110 | |
| 111 | func (ic *Icon) Render() { |
| 112 | ic.renderSVG() |
no test coverage detected