iconoir

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2026 License: BSD-3-Clause Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-iconoir/iconoir

iconoir

CI Go Reference

Idiomatic, pure-Go (CGO_ENABLED=0) access to the Iconoir icon set — ~1600 hand-crafted 24×24 icons in a regular (1.5-unit stroked) and a solid (filled) variant — rendered to anti-aliased alpha coverage masks by a small self-contained SVG-path rasterizer, ready to blit through the go-widgets painter or straight into an *image.RGBA.

The icon artwork is bundled verbatim and embedded with //go:embed; the only third-party dependencies are golang.org/x/image (the anti-aliasing rasterizer, already used across the fleet for font glyphs) and github.com/go-widgets/painter (the lightweight primitive-set interface — this package deliberately does not depend on go-widgets/toolkit, to keep the layering clean).

Install

go get github.com/go-iconoir/iconoir

Rendering approach

The go-widgets painter.Painter interface draws only rectangles and rounded-rects — it has no arbitrary-path primitive. So, exactly like the way go-widgets blits TrueType glyph coverage, an icon is first rasterized to an anti-aliased *image.Alpha coverage mask, then blitted with the ink colour modulated by each pixel's coverage (painter.PutPixel, which src-over blends).

The rasterizer is self-contained (no third-party SVG library):

  1. Parse the SVG (encoding/xml): read the viewBox and stroke-width, collect every <path>'s d.
  2. Flatten each d to polylines. Supported commands: M/L/H/V/C/S/Q/T/A/Z and their lowercase relative forms, with scientific-notation numbers. Cubic and quadratic Béziers are adaptively subdivided; elliptical arcs are converted to centre form and sampled — all to a tolerance tied to the target pixel size.
  3. Stroke (regular variant): every subpath is rendered as the union — in one golang.org/x/image/vector rasterizer — of a round-capped thick quad per segment plus a filled disc at every vertex. That yields correct round-join/round-cap strokes without a general stroke-to-outline algorithm. All shapes are wound consistently so nonzero-winding accumulation unions them.
  4. Fill (solid variant): the path is filled directly with nonzero winding.
  5. Scale from the 24-unit viewBox to the requested pixel size (stroke width scaled proportionally) and emit an anti-aliased *image.Alpha.

Masks are cached per (size, stroke) key behind a mutex, so repeated draws of the same icon at the same size are free.

Usage

import "github.com/go-iconoir/iconoir"

// Look one up (regular / stroked).
ic, ok := iconoir.Get("menu")     // or iconoir.MustGet("menu")
mask := ic.Rasterize(48)          // *image.Alpha coverage mask, 48×48

// Draw into a standard image with any colour.
ic.DrawInto(dst, image.Rect(0, 0, 48, 48), color.RGBA{0x0d, 0x94, 0x88, 0xff})

// Solid variant.
heart, _ := iconoir.GetSolid("heart")
go-widgets painter adapter

Draw / DrawIcon have exactly the signature a go-widgets/toolkit icon-drawing callback expects (func(p painter.Painter, r painter.Rect, ink painter.RGBA)), so an Iconoir icon drops straight into a Banner.Icon, IconButton.Icon, … slot:

iconoir.Draw(p, painter.Rect{X: 0, Y: 0, W: 24, H: 24}, "settings",
    painter.RGB(0x0d, 0x94, 0x88))

API

Function / method Purpose
Get(name) (*Icon, bool) / GetSolid(name) look up a regular / solid icon
MustGet(name) *Icon like Get, panics if absent
Names() []string / SolidNames() sorted lists of available names
(*Icon).Rasterize(sizePx) *image.Alpha cached coverage mask (own stroke width)
(*Icon).RasterizeStroke(sizePx, strokePx) force a device stroke width
(*Icon).DrawInto(dst *image.RGBA, r, col) composite into an image
DrawIcon(p, r, *Icon, ink) / Draw(p, r, name, ink) blit through a painter.Painter

Licensing

This repository has a dual origin, and both licences apply:

  • The Go source code in this package is BSD-3-Clause — see LICENSE, copyright the go-iconoir/iconoir authors.
  • The Iconoir icon artwork under assets/ is bundled verbatim from iconoir-icons/iconoir and is MIT-licensed, © 2021 Luca Burgio — the upstream licence is reproduced verbatim as LICENSE-ICONOIR. If you redistribute the embedded icons (including inside a compiled binary) keep that attribution.

Iconoir is a trademark of its authors; this is an independent, unofficial Go binding.

Documentation

Overview

Package iconoir provides idiomatic, pure-Go (CGO=0) access to the Iconoir icon set (https://iconoir.com). Every icon is a 24×24 SVG that this package rasterizes to an anti-aliased alpha coverage mask with a small self-contained SVG-path renderer (no third-party SVG library), then blits through the go-widgets painter or any *image.RGBA.

The Iconoir artwork is MIT-licensed (see LICENSE-ICONOIR); the Go code in this package is BSD-3-Clause (see LICENSE).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Draw

func Draw(p painter.Painter, r painter.Rect, name string, ink painter.RGBA) bool

Draw looks the Regular icon up by name and blits it via DrawIcon. It reports whether the icon exists; an unknown name draws nothing.

func DrawIcon

func DrawIcon(p painter.Painter, r painter.Rect, ic *Icon, ink painter.RGBA)

DrawIcon rasterizes ic at r's (square, centered) size and blits it through the painter, modulating ink's alpha by each pixel's coverage. Its signature matches the icon-drawing callback that go-widgets/toolkit widgets (Banner.Icon, IconButton.Icon, …) expect, so it composes directly as one of those callbacks.

func Names

func Names() []string

Names returns the sorted names of every Regular icon.

func SolidNames

func SolidNames() []string

SolidNames returns the sorted names of every Solid icon.

Types

type Icon

type Icon struct {
	// contains filtered or unexported fields
}

Icon is a single, lazily-parsed Iconoir glyph. Rasterized masks are cached per (size, stroke) key; an Icon is safe for concurrent use.

func Get

func Get(name string) (*Icon, bool)

Get returns the Regular (stroked) icon with the given name.

func GetSolid

func GetSolid(name string) (*Icon, bool)

GetSolid returns the Solid (filled) icon with the given name.

func MustGet

func MustGet(name string) *Icon

MustGet is Get but panics if the icon does not exist. Handy for package-level icon references that must exist.

func (*Icon) DrawInto

func (ic *Icon) DrawInto(dst *image.RGBA, r image.Rectangle, col color.Color)

DrawInto composites the icon into dst, fitted (centered) inside r and tinted with col. Coverage from the anti-aliased mask modulates col's alpha, and the result is src-over blended onto dst.

func (*Icon) Name

func (ic *Icon) Name() string

Name returns the icon's kebab-case identifier (e.g. "arrow-up").

func (*Icon) Rasterize

func (ic *Icon) Rasterize(sizePx int) *image.Alpha

Rasterize returns the icon's anti-aliased coverage mask at sizePx×sizePx using the icon's own stroke width(s). The result is cached and must not be mutated by the caller.

func (*Icon) RasterizeStroke

func (ic *Icon) RasterizeStroke(sizePx int, strokePx float64) *image.Alpha

RasterizeStroke is like Rasterize but forces every stroke to strokePx device pixels wide (ignored for Solid icons, which are filled).

func (*Icon) Variant

func (ic *Icon) Variant() Variant

Variant returns whether the icon renders Regular (stroked) or Solid.

type Variant

type Variant int

Variant selects which Iconoir style an Icon renders in.

const (
	// Regular is the stroked, 1.5-unit outline style.
	Regular Variant = iota
	// Solid is the filled style.
	Solid
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址