draw2dsvg/gc.go
func (gc *GraphicContext) embedSvgFont(text string) *Font {
	fontName := gc.Current.FontData.Name
	gc.loadCurrentFont()

	// find or create font Element
	svgFont := (*Font)(nil)
	for _, font := range gc.svg.Fonts {
		if font.Name == fontName {
			svgFont = font
			break
		}
	}
	if svgFont == nil {
		// create new
		svgFont = &Font{}
		// and attach
		gc.svg.Fonts = append(gc.svg.Fonts, svgFont)
	}

	// fill with glyphs

	gc.Save()
	defer gc.Restore()
	gc.SetFontSize(2048)
	defer gc.SetDPI(gc.GetDPI())
	gc.SetDPI(92)
filling:
	for _, rune := range text {
		for _, g := range svgFont.Glyphs {
			if g.Rune == Rune(rune) {
				continue filling
			}
		}
		glyph := gc.glyphCache.Fetch(gc, gc.GetFontName(), rune)
		// glyphCache.Load indirectly calls CreateStringPath for single rune string

		glypPath := glyph.Path.VerticalFlip() // svg font glyphs have oposite y axe
		svgFont.Glyphs = append(svgFont.Glyphs, &Glyph{
			Rune:      Rune(rune),
			Desc:      toSvgPathDesc(glypPath),
			HorizAdvX: glyph.Width,
		})
	}

	// set attrs
	svgFont.Id = "font-" + strconv.Itoa(len(gc.svg.Fonts))
	svgFont.Name = fontName

	// TODO use css @font-face with id instead of this
	svgFont.Face = &Face{Family: fontName, Units: 2048, HorizAdvX: 2048}
	return svgFont
}
func (gc *GraphicContext) embedSvgFont(text string) *Font {
	fontName := gc.Current.FontData.Name
	gc.loadCurrentFont()

	// find or create font Element
	svgFont := (*Font)(nil)
	for _, font := range gc.svg.Fonts {
		if font.Name == fontName {
			svgFont = font
			break
		}
	}
	if svgFont == nil {
		// create new
		svgFont = &Font{}
		// and attach
		gc.svg.Fonts = append(gc.svg.Fonts, svgFont)
	}

	// fill with glyphs

	gc.Save()
	defer gc.Restore()
	gc.SetFontSize(2048)
	defer gc.SetDPI(gc.GetDPI())
	gc.SetDPI(92)
filling:
	for _, rune := range text {
		for _, g := range svgFont.Glyphs {
			if g.Rune == Rune(rune) {
				continue filling
			}
		}
		glyph := gc.glyphCache.Fetch(gc, gc.GetFontName(), rune)
		// glyphCache.Load indirectly calls CreateStringPath for single rune string

		glypPath := glyph.Path.VerticalFlip() // svg font glyphs have oposite y axe
		svgFont.Glyphs = append(svgFont.Glyphs, &Glyph{
			Rune:      Rune(rune),
			Desc:      toSvgPathDesc(glypPath),
			HorizAdvX: glyph.Width,
		})
	}

	// set attrs
	svgFont.Id = "font-" + strconv.Itoa(len(gc.svg.Fonts))
	svgFont.Name = fontName

	// TODO use css @font-face with id instead of this
	svgFont.Face = &Face{Family: fontName, Units: 2048, HorizAdvX: 2048}
	return svgFont
}
// Embed svg font definition to svg tree itself
// Or update existing if already exists for curent font data