d2fonts

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MPL-2.0 Imports: 7 Imported by: 10

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 added in v0.3.0

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

Types

type Font

type Font struct {
	Family FontFamily
	Style  FontStyle
	Size   int
}

func (Font) GetEncodedSubset added in v0.3.0

func (f Font) GetEncodedSubset(corpus string) string

type FontFamily

type FontFamily string

func AddFontFamily added in v0.3.0

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