d2fonts

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MPL-2.0 Imports: 6 Imported by: 10

README

d2fonts

The SVG renderer embeds fonts directly into the SVG as base64 data. This is to give determinstic 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_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 map[Font]string
View Source
var FontFaces map[Font][]byte

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 []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