Documentation ¶
Overview ¶
Package fontpic is a package for rendering fonts to images.
Index ¶
- Constants
- Variables
- func RenderCharAt(img draw.Image, at image.Point, width, height int, bits []byte, hi color.Color, ...)
- type Canvas
- func (c *Canvas) CalcSize(lines [][]byte) *Canvas
- func (c *Canvas) Image() draw.Image
- func (c *Canvas) Render(lines [][]byte) *Canvas
- func (c *Canvas) RenderAt(lines [][]byte, at image.Point) *Canvas
- func (c *Canvas) RenderText(text []byte) *Canvas
- func (c *Canvas) RenderTextAt(text []byte, at image.Point) *Canvas
- func (c *Canvas) WithBackground(bg color.Color) *Canvas
- func (c *Canvas) WithFont(font *Font) *Canvas
- func (c *Canvas) WithForeground(fg color.Color) *Canvas
- func (c *Canvas) WithImage(img draw.Image) *Canvas
- func (c *Canvas) WithSize(w, h int) *Canvas
- func (c *Canvas) WithSpacing(x, y int) *Canvas
- type Font
Constants ¶
const ( DefaultWidth = 720 DefaultHeight = 540 )
const ( // CharsetSz is the number of characters in a font file. It is unlikely to // ever change. CharsetSz = 256 )
Variables ¶
var ( // FontDefault is the default font. Font8x8 = Must(ToFontCharset(kr8x8, "866")) Font8x14 = Must(ToFontCharset(kr8x14, "866")) Font8x16 = Must(ToFontCharset(kr8x16, "866")) FontDefault = Font8x16 )
Functions ¶
func RenderCharAt ¶
func RenderCharAt(img draw.Image, at image.Point, width, height int, bits []byte, hi color.Color, lo color.Color)
RenderCharAt is a low level function that renders a character, defined in bits, at the given position on the image. It uses width and height to know how to render the character in bits.
Types ¶
type Canvas ¶
type Canvas struct { Width int Height int Background color.Color Foreground color.Color // Color to use for the font Font *Font // Font to use Spacing image.Point // Spacing between characters. Scale image.Point // scaling factor (not used yet) // contains filtered or unexported fields }
Canvas is a canvas that can be rendered to.
The member function naming convention is the following:
- Render* - renders text or lines of text to the canvas
- With* - sets a property
Render functions, that have Text in the name do the minimum amount of transformations to the text to make it renderable. For example, tabs are replaced with spaces, and newlines are treated as line separators.
Render functions without Text in the name, render the provided lines of text verbatim, so any \n or \t characters will be rendered as a characters from the supplied font.
Render functions, that have At in the name, render the text at the specified location.
Zero canvas value is usable. It will use the default font, and will render the text in Grey (0xa8) on Black background, just like the good old days.
func (*Canvas) CalcSize ¶
CalcSize calculates the size of the canvas based on the provided lines of text.
func (*Canvas) RenderText ¶
RenderText renders the text to the canvas.
func (*Canvas) RenderTextAt ¶
RenderTextAt renders the text at the specified location.
func (*Canvas) WithSpacing ¶
type Font ¶
func ToFont ¶
ToFont8 converts byte data to a Font structure. It detects the font height based on the slice size.
func ToFont8 ¶
ToFont8 is a shortcut for calling ToFont(b, 8).
Usual slice sizes for 8-bit wide fonts:
- 8x8 font: 2048 bytes (1x8bytes x 256)
- 8x14 font: 3584 bytes (1x14bytes x 256)
- 8x16 font: 4096 bytes (1x16bytes x 256)
func (*Font) Sample ¶
Sample renders a sample of the font. The font is rendered in a grid of perLine characters. The sx and sy parameters are space between characters in pixels