Documentation
¶
Index ¶
- func AssetRef(resolvedURL string, asset Asset, linksOnly bool) string
- func BackgroundColorFromStyle(style psrt.Style) string
- func BorderRadiusCSS(c BorderRadiusCorners) string
- func BorderRadiusHasValue(c BorderRadiusCorners) bool
- func BorderRadiusIsUniform(c BorderRadiusCorners) bool
- func BorderRadiusNeedsInnerBoxDecoration(c BorderRadiusCorners) bool
- func CSSBoxFromStyleJSON(style psrt.Style) string
- func CSSBoxFromStyleJSONForCanvas(style psrt.Style, canvasW, canvasH int, fontPx float64) string
- func CSSBoxFromStyleJSONNoBackground(style psrt.Style) string
- func CSSBoxFromStyleJSONNoBackgroundForCanvas(style psrt.Style, canvasW, canvasH int, fontPx float64) string
- func CSSFromStyleJSON(raw []byte) string
- func CollectAssetURLs(doc psrt.Document) []string
- func EncodeDataURI(mime string, b []byte) string
- func ExpandFontURLsForFetch(ctx context.Context, client *http.Client, fontURLs []string) (fetchURLs []string, assetKeys map[string]string, err error)
- func ExplicitHeightPx(style psrt.Style, canvasW, canvasH int, fontPx float64) (int, bool)
- func FetchFontAssets(ctx context.Context, client *http.Client, fontURLs []string) (map[string]Asset, error)
- func FetchURLs(client *http.Client, urls []string) (map[string]Asset, error)
- func FontFamilyNameForURL(fontURL string, index int) string
- func FontFetchURL(ctx context.Context, client *http.Client, fontURL string) (string, error)
- func FontSrcURL(fontURL string, asset Asset, linksOnly bool) string
- func FontWeightIsBold(style psrt.Style) bool
- func FormatFloatCSS(v float64) string
- func IsAssetReference(raw string) bool
- func IsGoogleFontsCSSURL(raw string) bool
- func IsLocalAssetRef(raw string) bool
- func LineHeightMultiplier(style psrt.Style, fontSizePx float64) float64
- func LooksLikeHTTPURL(raw string) bool
- func MergeFontAssets(assets map[string]Asset, fonts map[string]Asset)
- func ParseGoogleFontFamilies(cssURL string) []string
- func PartitionAssetURLs(fonts, urls []string) (pageURLs, fontURLs []string)
- func ResolveAssetPath(raw string) (string, error)
- func ResolveAssetPathRelative(raw, baseDir string) (string, error)
- func ResolveAssetReference(raw string, consts map[string]string) string
- func ResolveGoogleFontsWoff2URLs(ctx context.Context, client *http.Client, cssURL string) ([]string, error)
- func SanitizeCSSValue(s string) string
- func StyleJSONWithoutBackground(style psrt.Style) []byte
- func StyleJSONWithoutBox(style psrt.Style) []byte
- func StyleResolvedForCanvas(style psrt.Style, canvasW, canvasH int, fontPx float64) psrt.Style
- func TextAlignFromStyle(style psrt.Style) string
- func TextBlockDisplayCSS(style psrt.Style) string
- func TextLayerNeedsComputedHeight(style psrt.Style, canvasW, canvasH int, textSize float64) bool
- func VerticalAlignFromStyle(style psrt.Style) string
- type Asset
- type BorderRadiusCorners
- type PaddingInsets
- func ParseBorderInsets(style psrt.Style, refFontPx float64) PaddingInsets
- func ParsePaddingInsets(style psrt.Style, refFontPx float64) PaddingInsets
- func TextBoxInsets(style psrt.Style, refFontPx float64) PaddingInsets
- func TextBoxInsetsForCanvas(style psrt.Style, refFontPx float64, canvasW, canvasH int) PaddingInsets
- type TextBox
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssetRef ¶
AssetRef returns either the resolved URL (linksOnly) or a data URI for embedded assets.
func BackgroundColorFromStyle ¶
BackgroundColorFromStyle extracts a CSS color from page style background keys.
func BorderRadiusCSS ¶
func BorderRadiusCSS(c BorderRadiusCorners) string
BorderRadiusCSS returns border-radius shorthand or longhands for CSS.
func BorderRadiusHasValue ¶
func BorderRadiusHasValue(c BorderRadiusCorners) bool
BorderRadiusHasValue reports whether any corner has a positive radius.
func BorderRadiusIsUniform ¶
func BorderRadiusIsUniform(c BorderRadiusCorners) bool
BorderRadiusIsUniform reports whether all corners share the same radius.
func BorderRadiusNeedsInnerBoxDecoration ¶
func BorderRadiusNeedsInnerBoxDecoration(c BorderRadiusCorners) bool
BorderRadiusNeedsInnerBoxDecoration is true when the SVG background rect cannot represent the corner radii (e.g. only bottom corners rounded). In that case background + radius must live on the foreignObject inner div via CSS.
func CSSBoxFromStyleJSON ¶
CSSBoxFromStyleJSON returns CSS declarations for text box decoration (background, border, etc.).
func CSSBoxFromStyleJSONForCanvas ¶
CSSBoxFromStyleJSONForCanvas emits full box CSS (background, border, radius, padding) with % resolved to px.
func CSSBoxFromStyleJSONNoBackground ¶
CSSBoxFromStyleJSONNoBackground returns box CSS without background (use SVG rect instead).
func CSSBoxFromStyleJSONNoBackgroundForCanvas ¶
func CSSBoxFromStyleJSONNoBackgroundForCanvas(style psrt.Style, canvasW, canvasH int, fontPx float64) string
CSSBoxFromStyleJSONNoBackgroundForCanvas emits box CSS with % lengths resolved to px.
func CSSFromStyleJSON ¶
CSSFromStyleJSON converts PSRT style JSON to CSS declarations (no selector).
func CollectAssetURLs ¶
CollectAssetURLs gathers unique URLs in deterministic order: pages in order (image then text ImageRefs), then document fonts.
func EncodeDataURI ¶
EncodeDataURI returns a data URI for the given MIME type and bytes.
func ExpandFontURLsForFetch ¶
func ExpandFontURLsForFetch(ctx context.Context, client *http.Client, fontURLs []string) (fetchURLs []string, assetKeys map[string]string, err error)
ExpandFontURLsForFetch replaces Google Fonts CSS links with downloadable woff2 URLs. assetKeys maps each fetch URL to the original document font URL (for assets map lookup).
func ExplicitHeightPx ¶
ExplicitHeightPx returns the outer box height in pixels from style "height" when set.
func FetchFontAssets ¶
func FetchFontAssets(ctx context.Context, client *http.Client, fontURLs []string) (map[string]Asset, error)
FetchFontAssets downloads font files; map keys are the original $FONTS URLs from the document.
func FontFamilyNameForURL ¶
FontFamilyNameForURL returns the CSS font-family name for a $FONTS entry.
func FontFetchURL ¶
FontFetchURL returns the URL to download for a document font entry (resolves Google CSS to woff2).
func FontSrcURL ¶
FontSrcURL returns a CSS url(...) value for @font-face src.
func FontWeightIsBold ¶
FontWeightIsBold reports whether the style requests a bold or semibold weight.
func FormatFloatCSS ¶
FormatFloatCSS formats a float for use in CSS.
func IsAssetReference ¶
IsAssetReference reports whether raw is an http(s) URL or a local file reference.
func IsGoogleFontsCSSURL ¶
IsGoogleFontsCSSURL reports Google Fonts CSS API links (not direct .woff2 files).
func IsLocalAssetRef ¶
IsLocalAssetRef reports file:// URLs and filesystem paths (not http).
func LineHeightMultiplier ¶
LineHeightMultiplier returns a unitless line-height factor for layout (default 1.2, matching compilehtml).
func LooksLikeHTTPURL ¶
LooksLikeHTTPURL reports whether raw is an http(s) URL.
func MergeFontAssets ¶
MergeFontAssets copies font assets into the main assets map (document font URL keys).
func ParseGoogleFontFamilies ¶
ParseGoogleFontFamilies extracts family names from a Google Fonts CSS API URL.
func PartitionAssetURLs ¶
PartitionAssetURLs splits collected URLs into page/image refs vs document font entries.
func ResolveAssetPath ¶
ResolveAssetPath turns a PSRT asset reference into an absolute filesystem path.
func ResolveAssetPathRelative ¶
ResolveAssetPathRelative resolves raw against baseDir when raw is not absolute.
func ResolveAssetReference ¶
ResolveAssetReference expands @name@ placeholders in raw using consts, then trims.
func ResolveGoogleFontsWoff2URLs ¶
func ResolveGoogleFontsWoff2URLs(ctx context.Context, client *http.Client, cssURL string) ([]string, error)
ResolveGoogleFontsWoff2URLs fetches the CSS API response and returns woff2 file URLs to download.
func SanitizeCSSValue ¶
SanitizeCSSValue strips characters that break CSS declarations.
func StyleJSONWithoutBackground ¶
StyleJSONWithoutBackground returns style JSON without box/background keys (typography only).
func StyleJSONWithoutBox ¶
StyleJSONWithoutBox returns typography-only style JSON (no box properties).
func StyleResolvedForCanvas ¶
StyleResolvedForCanvas applies percent handlers (padding, border-width, etc.) for render-time CSS/layout.
func TextAlignFromStyle ¶
TextAlignFromStyle returns the text-align value from style JSON, if any.
func TextBlockDisplayCSS ¶
TextBlockDisplayCSS returns display/flex rules for SVG foreignObject inner blocks. foreignObject renderers often ignore % padding and block text-align without a flex formatting context.
func TextLayerNeedsComputedHeight ¶
TextLayerNeedsComputedHeight reports whether a text layer needs an explicit outer height (explicit height in style or vertical padding/border) for flex vertical alignment to apply.
func VerticalAlignFromStyle ¶
VerticalAlignFromStyle maps align-items / vertical-align to a flex justify-content keyword.
Types ¶
type Asset ¶
Asset holds downloaded bytes with a MIME type suitable for data URIs.
func ReadAssetFile ¶
ReadAssetFile reads a local file and detects MIME type.
type BorderRadiusCorners ¶
type BorderRadiusCorners struct {
TopLeft, TopRight, BottomRight, BottomLeft float64
}
BorderRadiusCorners holds four corner radii in pixels (after % resolution when applicable).
func ParseBorderRadiusCorners ¶
func ParseBorderRadiusCorners(style psrt.Style, canvasW, canvasH int, fontPx float64) BorderRadiusCorners
ParseBorderRadiusCorners reads border-radius from style (resolved for canvas when needed).
type PaddingInsets ¶
type PaddingInsets struct {
Top, Right, Bottom, Left float64
}
PaddingInsets holds resolved padding in pixels (top, right, bottom, left).
func ParseBorderInsets ¶
func ParseBorderInsets(style psrt.Style, refFontPx float64) PaddingInsets
ParseBorderInsets resolves uniform border width in pixels for layout expansion.
func ParsePaddingInsets ¶
func ParsePaddingInsets(style psrt.Style, refFontPx float64) PaddingInsets
ParsePaddingInsets resolves padding from PSRT style JSON (px, em).
func TextBoxInsets ¶
func TextBoxInsets(style psrt.Style, refFontPx float64) PaddingInsets
TextBoxInsets combines padding and border for foreignObject sizing.
func TextBoxInsetsForCanvas ¶
func TextBoxInsetsForCanvas(style psrt.Style, refFontPx float64, canvasW, canvasH int) PaddingInsets
TextBoxInsetsForCanvas resolves % padding/border against canvas size, then returns pixel insets.
func (PaddingInsets) Add ¶
func (p PaddingInsets) Add(o PaddingInsets) PaddingInsets
func (PaddingInsets) Horizontal ¶
func (p PaddingInsets) Horizontal() float64
func (PaddingInsets) Vertical ¶
func (p PaddingInsets) Vertical() float64
type TextBox ¶
type TextBox struct {
Background string
BorderCSS string
BorderWidth string
BorderColor string
RadiusCSS string
RadiusPx float64
BoxShadowCSS string
PaddingCSS string
HasRect bool
}
TextBox describes background/border decoration for a text block.
func ParseTextBox ¶
ParseTextBox reads box-related properties from PSRT style JSON (camelCase or kebab-case).