Documentation
¶
Overview ¶
Package raster handles text and image rendering to monochrome bitmaps suitable for the P-Touch raster protocol.
Index ¶
Constants ¶
const ( PrefixTabler = "ti" PrefixBootstrap = "bi" )
Icon providers with their SVG base URLs.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bitmap ¶
type Bitmap struct {
Width int
Height int
Stride int // bytes per row = (Width+7)/8
Data []byte // row-major packed pixel data
}
Bitmap is a 1-bit monochrome image. Pixels are packed MSB-first: bit 7 of byte 0 is the leftmost pixel. 1 = black, 0 = white.
func FromImage ¶
FromImage converts any image.Image to a 1-bit Bitmap using the given luminance threshold (0–255). Pixels darker than threshold become black. Transparent pixels are composited onto a white background.
func (*Bitmap) PadCenter ¶
PadCenter returns a new bitmap of targetWidth, with the receiver's content centered horizontally. Used after transpose to align tape content on the printhead — narrower tapes don't start at pixel 0 of the printhead.
func (*Bitmap) ToRasterRows ¶
ToRasterRows splits the bitmap into byte rows suitable for SendRasterLine. Each row is padded to maxPixels/8 bytes. Returns one []byte per bitmap row.
func (*Bitmap) Transpose ¶
Transpose returns a transposed bitmap (W×H becomes H×W). Maps (x, y) → (y, x) so that:
- each column of the original becomes a raster row (tape feed direction)
- top of the original (y=0) maps to MSB of byte 0 (top edge of tape)
This produces correctly oriented, non-mirrored output on P-Touch printers.
type RenderResult ¶
type RenderResult struct {
Bitmap *Bitmap // transposed bitmap, ready for printing
Preview *Bitmap // human-readable bitmap (before transpose), for preview
RasterRows [][]byte // pre-split rows for SendRasterLine
WidthPx int // label width in pixels (before transpose)
HeightPx int // label height in pixels (before transpose = tape pixels)
}
RenderResult holds the output of a rendering operation.
func LoadImage ¶
func LoadImage(path string, tapePixels, maxPixels, marginPx int) (*RenderResult, error)
LoadImage loads an image file, scales it to fit the tape height, converts to monochrome, rotates for tape orientation, and returns raster rows ready for printing.
Supported formats: PNG, JPEG, GIF. tapePixels is the printable height (from Tape.Pixels). maxPixels is the printhead width for row padding (from Model.MaxPixels). marginPx is the margin in pixels on each side (0 = edge-to-edge).
func RenderImage ¶
func RenderImage(img image.Image, tapePixels, maxPixels, marginPx int) *RenderResult
RenderImage converts an already-decoded image to a print-ready RenderResult. The image is scaled to fit tapePixels height (maintaining aspect ratio), converted to 1-bit monochrome, and transposed for tape orientation. marginPx adds padding on all sides (0 = no margin).
func RenderText ¶
func RenderText(cfg TextConfig, tapePixels, maxPixels int) (*RenderResult, error)
RenderText renders text lines to a 1-bit bitmap suitable for printing. tapePixels is the printable pixel height (from Tape.Pixels). maxPixels is the printhead width for row padding (from Model.MaxPixels).
type TextConfig ¶
type TextConfig struct {
Lines []string // text lines to render
FontData []byte // TTF/OTF data (nil = use embedded Go font)
FontSize float64 // size in points (0 = auto-fit)
Bold bool // use bold variant of embedded font
Align Alignment // horizontal alignment (default: center)
DPI int // dots per inch (0 = 180)
MaxWidthPx int // fixed label width in pixels (0 = auto from text width)
}
TextConfig configures text rendering.