d2fonts

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MPL-2.0 Imports: 7 Imported by: 5 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

d2fonts

The SVG renderer embeds fonts directly into the SVG as base64 data. This is to give deterministic outputs and load without a network call.

To include your own font, e.g. Helvetica, you must include the Truetype glyphs:

  • ./ttf/Helvetica-Bold.ttf
  • ./ttf/Helvetica-Italic.ttf
  • ./ttf/Helvetica-Regular.ttf

You must also include an encoded version of these of mimetype application/font-woff:

  • ./ttf/Helvetica-Bold.txt
  • ./ttf/Helvetica-Italic.txt
  • ./ttf/Helvetica-Regular.txt

If you include a font to contribute, it must have an open license.

Documentation

Overview

TODO write a script to do this as part of CI Currently using an online converter: https://dopiaza.org/tools/datauri/index.php

Index

Constants

View Source
const (
	FONT_SIZE_XS   = 13
	FONT_SIZE_S    = 14
	FONT_SIZE_M    = 16
	FONT_SIZE_L    = 20
	FONT_SIZE_XL   = 24
	FONT_SIZE_XXL  = 28
	FONT_SIZE_XXXL = 32

	FONT_STYLE_REGULAR  FontStyle = "regular"
	FONT_STYLE_BOLD     FontStyle = "bold"
	FONT_STYLE_SEMIBOLD FontStyle = "semibold"
	FONT_STYLE_ITALIC   FontStyle = "italic"

	SourceSansPro FontFamily = "SourceSansPro"
	SourceCodePro FontFamily = "SourceCodePro"
	HandDrawn     FontFamily = "HandDrawn"
)

Variables

View Source
var D2_FONT_TO_FAMILY = map[string]FontFamily{
	"default": SourceSansPro,
	"mono":    SourceCodePro,
}
View Source
var FontEncodings syncmap.SyncMap[Font, string]
View Source
var FontFaces syncmap.SyncMap[Font, []byte]
View Source
var FontFamiliesMu sync.Mutex

Functions

func AddFontStyle

func AddFontStyle(font Font, style FontStyle, ttf []byte) error

Types

type Font

type Font struct {
	Family FontFamily
	Style  FontStyle
	Size   int
}

func (Font) GetEncodedSubset

func (f Font) GetEncodedSubset(corpus string) string

type FontFamily

type FontFamily string

func AddFontFamily

func AddFontFamily(name string, regularTTF, italicTTF, boldTTF, semiboldTTF []byte) (*FontFamily, error)

func (FontFamily) Font

func (f FontFamily) Font(size int, style FontStyle) Font

type FontStyle

type FontStyle string

Jump to

Keyboard shortcuts

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