Documentation
¶
Overview ¶
Package d2fonts holds the fonts used to measure and render diagrams.
Package d2fonts provides D2's embedded font families and bounded native fallback resolution for renderer text.
Index ¶
- Constants
- Variables
- func AddFontStyle(f Font, style FontStyle, ttf []byte) error
- func AppendixEncoding(style FontStyle) string
- type BundledFallbackLimits
- type BundledFallbackResolver
- type FallbackFont
- type FallbackRequest
- type FallbackResolver
- type Font
- type FontFamily
- type FontStyle
- type SystemFallbackLimits
- type SystemFallbackResolver
Constants ¶
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 ¶
var D2_FONT_TO_FAMILY = map[string]FontFamily{ "default": SourceSansPro, "mono": SourceCodePro, }
var FontEncodings syncmap.SyncMap[Font, string]
var FontFaces syncmap.SyncMap[Font, []byte]
var FontFamilies = []FontFamily{ SourceSansPro, SourceCodePro, HandDrawn, }
var FontFamiliesMu sync.Mutex
var FontSizes = []int{ FONT_SIZE_XS, FONT_SIZE_S, FONT_SIZE_M, FONT_SIZE_L, FONT_SIZE_XL, FONT_SIZE_XXL, FONT_SIZE_XXXL, }
var FontStyles = []FontStyle{ FONT_STYLE_REGULAR, FONT_STYLE_BOLD, FONT_STYLE_SEMIBOLD, FONT_STYLE_ITALIC, }
Functions ¶
func AppendixEncoding ¶ added in v0.10.1
AppendixEncoding supplies the regular face for ASCII footnotes or the bold face for their numbers. Callers decide whether their text fits that range. An application that registered its own encoding still gets that exact face.
Types ¶
type BundledFallbackLimits ¶ added in v0.9.0
type BundledFallbackLimits struct {
MaxRequestedRunes int
// MaxBundledBytes defaults to MaxResolvedBytes when zero.
MaxBundledBytes int64
MaxResolvedBytes int64
}
BundledFallbackLimits bound all requests and returned bytes over the lifetime of one composite resolver. MaxBundledBytes reserves an explicit sub-budget for owned copies of D2's trusted font; MaxResolvedBytes bounds those copies plus downstream results. The downstream resolver remains responsible for its own discovery and coverage-work limits.
type BundledFallbackResolver ¶ added in v0.9.0
type BundledFallbackResolver struct {
// contains filtered or unexported fields
}
BundledFallbackResolver resolves supported symbols and emoji from D2's pinned Noto Color Emoji face before consulting the host. This makes those glyphs deterministic across machines while leaving other scripts to a bounded downstream resolver. On js/wasm the bundled face is absent and all requests pass through to downstream.
func NewBundledFallbackResolver ¶ added in v0.9.0
func NewBundledFallbackResolver(next FallbackResolver, limits BundledFallbackLimits) (*BundledFallbackResolver, error)
func (*BundledFallbackResolver) ResolveFallbacks ¶ added in v0.9.0
func (r *BundledFallbackResolver) ResolveFallbacks(ctx context.Context, request FallbackRequest) ([]FallbackFont, error)
type FallbackFont ¶ added in v0.9.0
FallbackFont is one fully resolved host font face. Data is owned by the result and may be retained in a network-free renderer scene. FaceIndex selects a face when Data contains an OpenType collection.
type FallbackRequest ¶ added in v0.9.0
FallbackRequest carries both missing code points and the source text style. Resolvers may ignore style when a face is intrinsically universal, but must preserve it when delegating so bold, italic, semibold, and monospace text do not silently fall back to an unrelated regular proportional face.
type FallbackResolver ¶ added in v0.9.0
type FallbackResolver interface {
ResolveFallbacks(context.Context, FallbackRequest) ([]FallbackFont, error)
}
FallbackResolver resolves an ordered set of font faces covering runes not present in a D2 label's configured primary font. An empty or partial result means the remaining runes have no available face; it is not an error. Implementations must return owned immutable bytes and must honor context cancellation between bounded I/O operations. Malformed resources and work or byte limit violations remain errors.
type Font ¶
type Font struct {
Family FontFamily
Style FontStyle
Size int
}
func (Font) GetEncodedFull ¶ added in v0.10.0
GetEncodedFull returns the complete embedded face, including its shaping tables, in a compressed WOFF when one is available.
func (Font) GetEncodedSubset ¶
func (Font) GetSVGEncodedSubset ¶ added in v0.10.1
GetSVGEncodedSubset returns a data URL for a font embedded by the SVG renderer.
type FontFamily ¶
type FontFamily string
func AddFontFamily ¶
func AddFontFamily(name string, regularTTF, italicTTF, boldTTF, semiboldTTF []byte) (*FontFamily, error)
type SystemFallbackLimits ¶ added in v0.9.0
type SystemFallbackLimits struct {
MaxDirectoryEntries int
MaxFiles int
MaxFaces int
MaxRequestedRunes int
MaxCoverageChecks int64
MaxFileBytes int64
MaxScannedBytes int64
MaxResolvedBytes int64
}
SystemFallbackLimits bounds deterministic host-font discovery for the lifetime of one resolver. FileBytes bounds one candidate; every other work/byte limit is cumulative across indexing attempts and ResolveFallbacks calls. A CLI export owns one resolver, so these are operation-wide ceilings rather than per-board or per-style allowances.
type SystemFallbackResolver ¶ added in v0.9.0
type SystemFallbackResolver struct {
// contains filtered or unexported fields
}
SystemFallbackResolver discovers fonts only under the operating system's conventional system font roots. It does not follow symlinks or consult a platform API, keeping discovery CGO-free and auditable. User-installed D2 primary fonts continue to flow through AddFontFamily and do not need this resolver.
func NewSystemFallbackResolver ¶ added in v0.9.0
func NewSystemFallbackResolver(limits SystemFallbackLimits) (*SystemFallbackResolver, error)
func (*SystemFallbackResolver) ResolveFallbacks ¶ added in v0.9.0
func (r *SystemFallbackResolver) ResolveFallbacks(ctx context.Context, request FallbackRequest) ([]FallbackFont, error)