Documentation
¶
Overview ¶
Package thermoprint implements printing on a LX-D02 (Dolebo) bluetooth thermal printer.
Index ¶
- Constants
- Variables
- func BufferBinaryPattern(width int) [][]byte
- func TestImgMillimetres(maxX int) image.Image
- func TestImgRunningLines(maxX int) image.Image
- func TestImgSine(maxX int) image.Image
- type GenericRasteriser
- func (r *GenericRasteriser) DPI() int
- func (r *GenericRasteriser) Enumerate(data [][]byte) ([][]byte, error)
- func (r *GenericRasteriser) LineWidth() int
- func (r *GenericRasteriser) ResizeAndDither(src image.Image, gamma float64, autoDither bool) image.Image
- func (r *GenericRasteriser) Serialise(img image.Image) ([][]byte, error)
- func (r *GenericRasteriser) SetDitherFunc(fn bitmap.DitherFunc)
- type LXD02
- func (p *LXD02) Connect(ctx context.Context, adapter *bluetooth.Adapter, sp SearchParameters) error
- func (p *LXD02) DPI() float64
- func (p *LXD02) Disconnect() error
- func (p *LXD02) PrintImage(ctx context.Context, img image.Image) error
- func (p *LXD02) PrintPattern(ctx context.Context, pattern string) error
- func (p *LXD02) PrintRAW(ctx context.Context, data [][]byte) error
- func (p *LXD02) PrintTextTTF(ctx context.Context, text string, face font.Face) error
- func (p *LXD02) SetOptions(opts ...Option) error
- func (p *LXD02) Width() int
- type Option
- type Rasteriser
- type SearchParameters
Constants ¶
const ( // DefaultPrintDelay is the default interval between sending packets to the printer DefaultPrintDelay = 7 * time.Millisecond )
Variables ¶
var LXD02Rasteriser = &GenericRasteriser{ Width: 384, Dpi: 203, LinesPerPacket: 2, PrefixFunc: func(packetIndex int) []byte { m := byte((packetIndex >> 8) & 0xFF) n := byte(packetIndex & 0xFF) return []byte{0x55, m, n} }, Terminator: 0x00, Threshold: bitmap.DefaultThreshold, DitherFunc: bitmap.DitherDefault, }
var TestBufferPatterns = map[string]func(int) [][]byte{ "BinaryPattern": BufferBinaryPattern, }
var TestImagePatterns = map[string]func(int) image.Image{ "RunningLinesImage": TestImgRunningLines, "Millimetres": TestImgMillimetres, "Sine": TestImgSine, }
Functions ¶
func BufferBinaryPattern ¶
func TestImgMillimetres ¶
TestImgMillimetres draws a running pattern of millimeter lines. Each horizontal line is 8 dots wide, and 1 dot high. Each horizontal line is repeated every 40 dots, so that the first line is at 0, the second at 40, the third at 80, and so on, until the maximum X coordinate is reached. THe output looks like this:
0 1 .. 40 .. 80 .. 120 .. 160 .. 200 .. 240 .. 280 .. 320 .. 360 .. 400 -- -- ... -- -- ... -- -- ... -- -- -- -- -- --
etc.
func TestImgRunningLines ¶
TestImgRunningLines generates 8 lines each of which is 2 pixels high shifted by one pixel to the right, so that thermal unit is expected to print 4 times.
The output looks like this:
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
func TestImgSine ¶
Types ¶
type GenericRasteriser ¶
type GenericRasteriser struct {
Width int
Dpi int
LinesPerPacket int
PrefixFunc func(packetIndex int) []byte // returns 55 m n
Terminator byte // 00
DitherFunc bitmap.DitherFunc // optional dither function
Threshold uint8 // threshold for dark pixels, default is 128
}
func (*GenericRasteriser) DPI ¶
func (r *GenericRasteriser) DPI() int
func (*GenericRasteriser) Enumerate ¶
func (r *GenericRasteriser) Enumerate(data [][]byte) ([][]byte, error)
Enumerate converts the raw data to printer specific packets ready to be sent to printer.
func (*GenericRasteriser) LineWidth ¶
func (r *GenericRasteriser) LineWidth() int
func (*GenericRasteriser) ResizeAndDither ¶
func (*GenericRasteriser) Serialise ¶
func (r *GenericRasteriser) Serialise(img image.Image) ([][]byte, error)
func (*GenericRasteriser) SetDitherFunc ¶
func (r *GenericRasteriser) SetDitherFunc(fn bitmap.DitherFunc)
type LXD02 ¶
type LXD02 struct {
// contains filtered or unexported fields
}
LXD02 represents a LX-D02 printer. Instance is not safe for concurrent use. Zero value is unusable, initialise with NewLXD02
func (*LXD02) Connect ¶ added in v0.0.4
Connect connects to the LX-D02 printer using the provided adapter and search parameters.
func (*LXD02) Disconnect ¶
func (*LXD02) PrintImage ¶
PrintImage prints an image on the printer. If dry run is enabled, it saves the preview file to disk and exits.
func (*LXD02) PrintPattern ¶
func (*LXD02) PrintTextTTF ¶
func (*LXD02) SetOptions ¶ added in v0.0.4
SetOptions
type Option ¶
type Option func(*printOptions)
func WithAutoDither ¶
func WithDither ¶
func WithDryRun ¶
func WithEnergy ¶
func WithGamma ¶
WithGamma allows to specify rasteriser gamma correction value. [DefaultGamma] value or 0.0 means use default for the selected dither function.
func WithPrintInterval ¶
type Rasteriser ¶
type Rasteriser interface {
ResizeAndDither(img image.Image, gamma float64, autoDither bool) image.Image
// Serialise should return a slice of byte slices that are sent to printer.
Serialise(src image.Image) ([][]byte, error)
// Enumerate prepares the raw data for printing running the packet func
// for each byte slice and returning the data ready to be sent to printer.
Enumerate(data [][]byte) ([][]byte, error)
// DPI should return the DPI of the rasteriser.
DPI() int
// LineWidth should return the line width in pixels, i.e. for 203 dpi
// thermal printer that uses 58mm paper, it is 384.
LineWidth() int
// SetDitherFunc should set the dither function.
SetDitherFunc(fn bitmap.DitherFunc)
}
type SearchParameters ¶
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package bitmap provides bitmap image manipulation funcitons.
|
Package bitmap provides bitmap image manipulation funcitons. |
|
cmd
|
|
|
tp
command
|
|
|
tp/internal/cfg
Package cfg contains common configuration variables.
|
Package cfg contains common configuration variables. |
|
tp/internal/cmdimage
Package cmdimage provides image printing subcommand.
|
Package cmdimage provides image printing subcommand. |
|
tp/internal/cmdpattern
Package cmdpattern provides pattern printing subcommand.
|
Package cmdpattern provides pattern printing subcommand. |
|
tp/internal/cmdtext
Package cmdtext provides a text printing subcommand.
|
Package cmdtext provides a text printing subcommand. |
|
tp/internal/golang/base
Package base defines shared basic pieces of the tp command.
|
Package base defines shared basic pieces of the tp command. |
|
tp/internal/golang/help
Package help implements "slackdump help" command.
|
Package help implements "slackdump help" command. |
|
Package ippsrv implements an IPP server.
|
Package ippsrv implements an IPP server. |