compilesvg

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const GoTextFallbackNotice = "Compilação SVG com motor go-text (Chromium não encontrado). Pode haver pequenas diferenças em relação ao preview."

GoTextFallbackNotice is shown in the GUI when the go-text fallback is used.

Variables

This section is empty.

Functions

func BuildPageSVGDefsCSS

func BuildPageSVGDefsCSS(pageSlug string, pageStyle psrt.Style) string

BuildPageSVGDefsCSS returns minimal CSS embedded in compiled SVG (page background only).

func BuildPageStylesheet

func BuildPageStylesheet(
	pageSlug string,
	pageStyle psrt.Style,
	texts []psrt.Text,
	canvasW, canvasH int,
	fontURLs []string,
	assets map[string]compileasset.Asset,
) string

BuildPageStylesheet returns the full CSS for one page (font-face, page class, text classes).

func BuildPageTextStylesheet

func BuildPageTextStylesheet(
	pageSlug string,
	pageStyle psrt.Style,
	texts []psrt.Text,
	canvasW, canvasH int,
	fontURLs []string,
	assets map[string]compileasset.Asset,
) string

BuildPageTextStylesheet returns CSS for headless text layout (font-face + text block rules).

func FormatInt

func FormatInt(n int) string

FormatInt returns decimal string for SVG attributes.

func ImageDimensions

func ImageDimensions(body []byte, mime string) (w, h int)

ImageDimensions returns width and height from image bytes, or defaults on failure.

func IsImageMIME

func IsImageMIME(mime string) bool

IsImageMIME reports whether mime is an image type.

func MaskBlockGeometry

func MaskBlockGeometry(m *psrt.Mask, canvasW, canvasH int) (x, y, width, height int)

MaskBlockGeometry maps mask percent coords to a pixel rect (fixed height, no text metrics).

func PageBgClass

func PageBgClass(slug string) string

PageBgClass returns the background rect class name.

func PageBgID

func PageBgID(slug string) string

PageBgID returns the background rect id.

func PageClass

func PageClass(slug string) string

PageClass returns the standardized page CSS class name (without dot).

func PageID

func PageID(slug string) string

PageID returns the standardized page element id.

func PageImageID

func PageImageID(slug string) string

PageImageID returns the page background image id.

func PageTextsID

func PageTextsID(slug string) string

PageTextsID returns the texts group id.

func PathMaskBlockGeometry

func PathMaskBlockGeometry(m *psrt.PathMask, canvasW, canvasH int) (x, y, width, height int)

PathMaskBlockGeometry maps ~~ percent coords to a pixel rect for the nested <svg viewBox="0 0 100 100"> wrapper (same percent->pixel conversion as MaskBlockGeometry; the path's own 0-100 coordinates are left untouched and scaled by the nested viewBox, including non-uniformly when Width != Height).

func PathMaskClipID

func PathMaskClipID(slug string, index int) string

PathMaskClipID returns the clipPath id used to clip a ~~ block's image-ref.

func PathMaskID

func PathMaskID(slug string, index int) string

PathMaskID returns the standardized ~~ block id.

func PathMaskWrapID

func PathMaskWrapID(slug string, index int) string

PathMaskWrapID returns the wrapper group id for a ~~ block.

func RenderPageSVG

func RenderPageSVG(
	p *psrt.Page,
	pageSlug string,
	fontURLs []string,
	assets map[string]compileasset.Asset,
) ([]byte, error)

RenderPageSVG produces a standalone SVG for one page.

func ResolveDocument

func ResolveDocument(doc psrt.Document) psrt.Document

ResolveDocument expands all @const@ placeholders in styles, content, and URLs, collapsing interactive consts to their render text (universal SVG/HTML output).

func ResolveDocumentKeepInteractive added in v1.4.0

func ResolveDocumentKeepInteractive(doc psrt.Document) psrt.Document

ResolveDocumentKeepInteractive expands plain consts but leaves @type:render@ tokens intact, for interactive readers (e.g. react-image) that render them.

func ResolveDocumentStrict

func ResolveDocumentStrict(doc psrt.Document) (psrt.Document, error)

ResolveDocumentStrict is like ResolveDocument but returns an error on invalid style JSON.

func ResolveDocumentStrictKeepInteractive added in v1.4.0

func ResolveDocumentStrictKeepInteractive(doc psrt.Document) (psrt.Document, error)

ResolveDocumentStrictKeepInteractive is ResolveDocumentKeepInteractive with strict style validation.

func Slug

func Slug(name string) string

Slug returns a filesystem- and XML-safe slug from a page name.

func TextA11yID

func TextA11yID(slug string, index int) string

TextA11yID returns the hidden accessibility text element id.

func TextBgClass

func TextBgClass(slug string, index int) string

TextBgClass returns the CSS class for the text background rect.

func TextBgID

func TextBgID(slug string, index int) string

TextBgID returns the SVG background rect id for a text block.

func TextBlockGeometry

func TextBlockGeometry(t *psrt.Text, content string, canvasW, canvasH int) (x, y, width, height int)

TextBlockGeometry maps PSRT percent coords to a pixel rect for layout (SVG foreignObject / HTML text-layer). x, y, width match the editor/web border box (box-sizing: border-box); height includes vertical padding.

func TextClass

func TextClass(slug string, index int) string

TextClass returns the standardized text CSS class name.

func TextClassAttr

func TextClassAttr(pageSlug string, index int) string

TextClassAttr returns both page and text classes for cascade (page first, text second).

func TextGlyphsID

func TextGlyphsID(slug string, index int) string

TextGlyphsID returns the group id wrapping outlined text paths.

func TextID

func TextID(slug string, index int) string

TextID returns the standardized text block id.

func TextInnerClass

func TextInnerClass(slug string, index int) string

TextInnerClass is the inner span that holds inline markup inside a flex foreignObject div.

func TextWrapID

func TextWrapID(slug string, index int) string

TextWrapID returns the wrapper group id (rect + glyph paths).

func UniqueSlugs

func UniqueSlugs(pages []string) []string

UniqueSlugs assigns a unique slug per page name (suffix -2, -3 on collision).

Types

type CompileResult

type CompileResult struct {
	UsedGoTextFallback bool
}

CompileResult holds batch SVG compile output metadata.

func Compile

func Compile(doc psrt.Document, client *http.Client, outDir string) (CompileResult, error)

Compile resolves constants, fetches assets, and writes one SVG per page into outDir.

func CompileWithCache

func CompileWithCache(ctx context.Context, doc psrt.Document, client *http.Client, outDir string, store *cache.Store) (CompileResult, error)

CompileWithCache uses local asset cache when store is non-nil.

func CompileWithOptions

func CompileWithOptions(ctx context.Context, doc psrt.Document, client *http.Client, outDir string, store *cache.Store, opts compileopts.Options) (CompileResult, error)

CompileWithOptions compiles all pages to SVG files with shared compile flags.

type PageSVGResult

type PageSVGResult struct {
	Data               []byte
	UsedGoTextFallback bool
}

PageSVGResult is the output of rendering one page to SVG.

func CompilePageSVG

func CompilePageSVG(ctx context.Context, doc psrt.Document, pageName string, client *http.Client, store *cache.Store) (PageSVGResult, error)

CompilePageSVG returns SVG bytes for a single page by name.

func CompilePageSVGWithOptions

func CompilePageSVGWithOptions(ctx context.Context, doc psrt.Document, pageName string, client *http.Client, store *cache.Store, opts compileopts.Options) (PageSVGResult, error)

CompilePageSVGWithOptions compiles one page to SVG with compile flags.

func RenderPageSVGWithContext

func RenderPageSVGWithContext(
	ctx context.Context,
	p *psrt.Page,
	pageSlug string,
	fontURLs []string,
	assets map[string]compileasset.Asset,
	opts compileopts.Options,
) (PageSVGResult, error)

RenderPageSVGWithContext compiles one page using ctx for text outlining.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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