Documentation
¶
Overview ¶
Package render implements the rendering engine for the browser. It converts layout boxes into visual output (PNG images).
Spec references: - CSS 2.1 §14 Colors and backgrounds: https://www.w3.org/TR/CSS21/colors.html - CSS 2.1 §15 Fonts: https://www.w3.org/TR/CSS21/fonts.html - CSS 2.1 §16 Text: https://www.w3.org/TR/CSS21/text.html - CSS 2.1 §8.5 Border properties: https://www.w3.org/TR/CSS21/box.html#border-properties - HTML5 §4.8.2 The img element: https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element
Implemented features: - Canvas-based raster rendering - Background colors (CSS 2.1 §14.2) - Border rendering with solid style (CSS 2.1 §8.5) - Text rendering with TrueType fonts (Go fonts) - Font styling: size, weight (bold), style (italic) per CSS 2.1 §15 - Text decoration: underline (CSS 2.1 §16.3.1) - Color parsing: named colors and hex colors (CSS 2.1 §4.3.6) - Image rendering: PNG, JPEG, GIF formats (HTML5 §4.8.2) - SVG rendering via custom parser (SVG 1.1 subset) - Data URL support for inline resources (RFC 2397) - Background images (CSS 2.1 §14.2.1) - PNG output via image/png
Not yet implemented (would require additional work): - Font family selection (CSS 2.1 §15.3) - uses Go fonts only - Text alignment within boxes (CSS 2.1 §16.2) - handled at layout level - Line height control (CSS 2.1 §10.8.1) - uses font metrics - Text decoration: overline, line-through (CSS 2.1 §16.3.1) - Border styles: dashed, dotted, etc. (CSS 2.1 §8.5.3) - solid only - Border radius (CSS3) - Box shadows (CSS3) - Gradients (CSS3) - Transforms and transitions (CSS3)
Index ¶
- type Canvas
- func (c *Canvas) Clear(bg color.RGBA)
- func (c *Canvas) DrawImage(img image.Image, x, y, width, height int)
- func (c *Canvas) DrawRect(x, y, width, height int, col color.RGBA, thickness int)
- func (c *Canvas) DrawSVG(svgData []byte, x, y, width, height int) error
- func (c *Canvas) DrawStyledText(text string, x, y int, col color.RGBA, style FontStyle)
- func (c *Canvas) DrawText(text string, x, y int, col color.RGBA)
- func (c *Canvas) FillRect(x, y, width, height int, col color.RGBA)
- func (c *Canvas) LoadImage(path string) (image.Image, error)
- func (c *Canvas) SavePNG(filename string) error
- func (c *Canvas) SetPixel(x, y int, col color.RGBA)
- func (c *Canvas) ToImage() *image.RGBA
- type FontStyle
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Canvas ¶
type Canvas struct {
Width int
Height int
Pixels []color.RGBA
ImageCache map[string]image.Image // Cache for loaded images
}
Canvas represents the rendering surface.
func (*Canvas) DrawImage ¶
DrawImage draws an image onto the canvas at the specified position. HTML5 §4.8.2 The img element
func (*Canvas) DrawRect ¶
DrawRect draws a rectangle outline with the given color and thickness. CSS 2.1 §8.5 Border properties
func (*Canvas) DrawSVG ¶
DrawSVG renders an SVG image onto the canvas at the specified position. Uses the svg package for parsing and rasterization per SVG 1.1 spec.
func (*Canvas) DrawStyledText ¶
DrawStyledText draws text with font styling at the given position. CSS 2.1 §15 Fonts and §16 Text CSS 2.1 §15.6 Font boldness: font-weight CSS 2.1 §15.7 Font style: font-style CSS 2.1 §16.3.1 Underlining, overlining, striking: text-decoration
Text is rendered directly at 1x resolution using TrueType fonts with built-in antialiasing.
func (*Canvas) DrawText ¶
DrawText draws text at the given position with the given color. CSS 2.1 §16 Text Uses default font style for backward compatibility with code that doesn't specify font properties.
func (*Canvas) FillRect ¶
FillRect fills a rectangle with the given color. CSS 2.1 §14.2 The background
func (*Canvas) LoadImage ¶
LoadImage loads an image from an absolute file path or URL. Supports PNG, JPEG, and GIF formats. The path should be already resolved (absolute) before calling this method.
Uses dom.ResourceLoader for consistent resource fetching across the browser.
type FontStyle ¶
type FontStyle = browserfont.Style
FontStyle represents text rendering options. CSS 2.1 §16 Text and §15 Fonts This is a local alias for browserfont.Style to maintain backward compatibility with existing render code.