textoutline

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: 23 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultFontFamily = "PSRTDefault"
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 AddChromeSearchRoots

func AddChromeSearchRoots(roots ...string)

AddChromeSearchRoots registers extra directories checked for bundled Chrome.

func BuildSnapshotHTML

func BuildSnapshotHTML(in PageInput) string

BuildSnapshotHTML returns a self-contained HTML document for headless layout.

func BundledChromeInDir

func BundledChromeInDir(dir string) string

BundledChromeInDir returns a Chrome/Chromium executable next to dir, if any.

func CloseBrowser

func CloseBrowser()

CloseBrowser releases the shared Chromium allocator.

func CloseDefault

func CloseDefault()

CloseDefault releases shared browser state (tests).

func DefaultFontBytes

func DefaultFontBytes() []byte

DefaultFontBytes returns the embedded fallback font for outlining.

func ResolveChromeExec

func ResolveChromeExec() string

ResolveChromeExec returns a Chromium/Edge executable path, or "" if none found.

Types

type BlockInput

type BlockInput struct {
	Index      int
	X, Y       int
	Width      int
	Height     int
	ClassAttr  string
	InnerClass string
	TextHTML   string
	PlainText  string
	FilterID   string
	Transform  string
	Style      BlockStyle
}

BlockInput describes one text block in the layout snapshot.

type BlockStyle

type BlockStyle struct {
	FontSizePx  float64
	LineHeight  float64
	Color       string
	Stroke      string
	StrokeWidth string
	TextAlign   string
	PadTop      int
	PadLeft     int
	ContentW    int
	FontFamily  string
	Bold        bool
}

BlockStyle carries layout hints for the go-text fallback.

type FontBytes

type FontBytes struct {
	MIME  string
	Bytes []byte
}

FontBytes wraps font file bytes for embedding.

type OutlinedBlock

type OutlinedBlock struct {
	Index     int            `json:"index"`
	Paths     []OutlinedPath `json:"paths"`
	PlainText string         `json:"plainText"`
	FilterID  string         `json:"filterId,omitempty"`
	Transform string         `json:"transform,omitempty"`
}

OutlinedBlock holds vector paths and metadata for one PSRT text block.

type OutlinedPath

type OutlinedPath struct {
	D           string `json:"d"`
	Fill        string `json:"fill,omitempty"`
	Stroke      string `json:"stroke,omitempty"`
	StrokeWidth string `json:"strokeWidth,omitempty"`
	Opacity     string `json:"opacity,omitempty"`
	PaintOrder  string `json:"paintOrder,omitempty"`
}

OutlinedPath is one SVG path for a text run.

type Outliner

type Outliner struct {
	// contains filtered or unexported fields
}

Outliner runs headless Chromium to convert laid-out text to SVG paths.

func NewOutliner

func NewOutliner(parent context.Context, execPath string) (*Outliner, error)

NewOutliner starts a headless browser using the given Chromium executable.

func (*Outliner) Close

func (o *Outliner) Close()

Close shuts down the browser allocator.

func (*Outliner) OutlinePage

func (o *Outliner) OutlinePage(ctx context.Context, in PageInput) ([]OutlinedBlock, error)

OutlinePage layouts texts in Chromium and returns vector paths per block.

type PageInput

type PageInput struct {
	CanvasW int
	CanvasH int
	CSS     string
	Blocks  []BlockInput
	Fonts   map[string]FontBytes // family name -> raw font bytes
}

PageInput is the layout snapshot for one page.

type Result

type Result struct {
	Blocks             []OutlinedBlock
	UsedGoTextFallback bool
}

Result is returned by Outline.

func Outline

func Outline(ctx context.Context, in PageInput) (Result, error)

Outline layouts text blocks with Chromium when available, otherwise go-text.

Jump to

Keyboard shortcuts

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