render

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: BSD-3-Clause, Unlicense Imports: 16 Imported by: 0

README

render

A simple rasterising renderer for the go-text project. Draw your text into a draw.Image provided by the developer for caching / overlay opportunities.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Renderer

type Renderer struct {
	// FontSize defines the point size of output text, commonly between 10 and 14 for regular text
	FontSize float32
	// PixScale is used to indicate the pixel density of your output target.
	// For example on a hi-DPI (or "retina") display this may be 2.0.
	// Default value is 1.0, meaning 1 pixel on the image for each render pixel.
	PixScale float32
	// Color is the pen colour for rendering
	Color color.Color
	// contains filtered or unexported fields
}

Renderer defines a type that can render strings to a bitmap canvas. The size and look of output depends on the various fields in this struct. Developers should provide suitable output images for their draw requests. This type is not thread safe so instances should be used from only 1 goroutine.

func (*Renderer) DrawShapedRunAt

func (r *Renderer) DrawShapedRunAt(run shaping.Output, img draw.Image, startX, startY int) int

DrawShapedRunAt will rasterise the given shaper run into the output image using font face referenced in the shaping. The text will be drawn starting at the startX, startY pixel position. Note that startX and startY are not multiplied by the `PixScale` value as they refer to output coordinates. The return value is the X pixel position of the end of the drawn string.

func (*Renderer) DrawString

func (r *Renderer) DrawString(str string, img draw.Image, face font.Face) int

DrawString will rasterise the given string into the output image using the specified font face. The text will be drawn starting at the left edge, down from the image top by the font ascent value, so that the text is all visible. The return value is the X pixel position of the end of the drawn string.

func (*Renderer) DrawStringAt

func (r *Renderer) DrawStringAt(str string, img draw.Image, x, y int, face font.Face) int

DrawStringAt will rasterise the given string into the output image using the specified font face. The text will be drawn starting at the x, y pixel position. Note that x and y are not multiplied by the `PixScale` value as they refer to output coordinates. The return value is the X pixel position of the end of the drawn string.

Jump to

Keyboard shortcuts

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