layla

package module
v0.0.0-...-d153ec4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: BSD-2-Clause Imports: 12 Imported by: 0

README

layla

layla is a layout and template language based using the xelf project.

It is primarily used as an exploration into the feasibility of the xelf for templates, but should also provides a simple layout templates for thermal label printers and html previews.

Layout definitions using the xelf as declaration format are already templates with expressions. Reusing the std lib and some custom specs we can build the layout node tree. The nodes proxy to custom go structs, making it easy to work with even without using xelf.

Layla supports these layout elements: text, block, rect, ellipse, qrcode, barcode elements markup with for simple styled text blocks stage, group, vbox, hbox and table layouts page with extra, cover, header and footer elements for paged documents

There will someday be render packages for: tsc Taiwan Semiconductor (TSC) label printer, specifically for the DA-200 printer html preview in HTML with barcode rendering using boombuler/barcode pdf renderer using jung-kurt/gofpdf

License

Copyright (c) Martin Schnabel. All rights reserved. Use of the source code is governed by a BSD-style license that can found in the LICENSE file.

This project uses BSD licensed Go fonts for testing (see testdata/README for more info) with Copyright (c) 2016 Bigelow & Holmes Inc. All rights reserved.

Documentation

Index

Constants

View Source
const (
	AlignLeft = iota
	AlignRight
	AlignCenter
)

Variables

This section is empty.

Functions

func FakeBoldStyler

func FakeBoldStyler(m *font.Manager, f Font, t mark.Tag) (*font.Face, error)

func Specs

func Specs(reg *lit.Reg) lib.Specs

func ZeroStyler

func ZeroStyler(m *font.Manager, f Font, t mark.Tag) (*font.Face, error)

Types

type Border

type Border struct {
	W Dot `json:"w,omitempty"`
	L Dot `json:"l,omitempty"`
	T Dot `json:"t,omitempty"`
	R Dot `json:"r,omitempty"`
	B Dot `json:"b,omitempty"`
}

func (Border) Default

func (b Border) Default(w Dot) Border

type Box

type Box struct {
	Pos
	Dim
}

Box is a simple box consisting of a position and dimension.

type Code

type Code struct {
	Name  string `json:"name,omitempty"`
	Human int    `json:"human,omitempty"`
	Wide  Dot    `json:"wide,omitempty"`
}

Code holds all qr and barcode related node data

type Color

type Color struct {
	R int `json:"r,omitempty"`
	G int `json:"g,omitempty"`
	B int `json:"b,omitempty"`
}

type Dim

type Dim struct {
	W Dot `json:"w,omitempty"`
	H Dot `json:"h,omitempty"`
}

Dim is a simple dimension consisting of width and height in dots.

type Dot

type Dot = font.Dot

type Font

type Font struct {
	Name   string   `json:"name,omitempty"`
	Size   float64  `json:"size,omitempty"`
	Line   Dot      `json:"line,omitempty"`
	Style  mark.Tag `json:"-"`
	Height font.Pt  `json:"-"`
}

Font holds all font related node data

type Layouter

type Layouter struct {
	*font.Manager
	Spacer rune
	Styler
}

Layouter implements the layout routine and holds required context

func (*Layouter) Layout

func (l *Layouter) Layout(n *Node) error

Layout measures and sets the nodes dimensions and position or returns an error

func (*Layouter) LayoutAndPage

func (l *Layouter) LayoutAndPage(n *Node) ([]*Node, error)

LayoutAndPage layouts the node and returns a slice of nodes to draw or an error

type Node

type Node struct {
	Kind string `json:"kind"`
	Box
	NodeLayout
	Font   *Font   `json:"font,omitempty"`
	Border Border  `json:"border,omitempty"`
	List   []*Node `json:"list,omitempty"`
	Table
	Code *Code  `json:"code,omitempty"`
	Data string `json:"data,omitempty"`
	Calc Box    `json:"-"`
}

Node is a part of the display tree and can represent any element.

func Eval

func Eval(ctx context.Context, reg *lit.Reg, env exp.Env, rr io.Reader, name string) (*Node, error)

Eval parses and evaluates the label from reader r and returns a node or an error.

func LayoutAndPage

func LayoutAndPage(m *font.Manager, n *Node) ([]*Node, error)

func Page

func Page(n *Node) ([]*Node, error)

func ValNode

func ValNode(v lit.Val) *Node

type NodeLayout

type NodeLayout struct {
	Mar   *Off `json:"mar,omitempty"`
	Pad   *Off `json:"pad,omitempty"`
	Rot   int  `json:"rot,omitempty"`
	Align int  `json:"align,omitempty"`
	Gap   Dot  `json:"gap,omitempty"`
	Sub   Dim  `json:"sub,omitempty"`
}

NodeLayout holds all layout related node data

type Off

type Off struct {
	L Dot `json:"l,omitempty"`
	T Dot `json:"t,omitempty"`
	R Dot `json:"r,omitempty"`
	B Dot `json:"b,omitempty"`
}

Off is a box offset consisting of left, top, right and bottom offsets in dot.

func (*Off) Inset

func (o *Off) Inset(b Box) Box

Inset returns a box result of b with o substracted.

func (*Off) Outset

func (o *Off) Outset(b Box) Box

Outset returns a box result of b with o added.

type Pos

type Pos struct {
	X Dot `json:"x,omitempty"`
	Y Dot `json:"y,omitempty"`
}

Pos is a simple position consisting of x and y coordinates in dots.

type Styler

type Styler func(*font.Manager, Font, mark.Tag) (*font.Face, error)

type Table

type Table struct {
	Cols []Dot `json:"cols,omitempty"`
	Head bool  `json:"head,omitempty"`
	Nobr bool  `json:"nobr,omitempty"`
}

Directories

Path Synopsis
cmd
Package html implements a layla renderer for html previews.
Package html implements a layla renderer for html previews.
Package tsc provides helper functions to work with TSC label printers.
Package tsc provides helper functions to work with TSC label printers.
Package tspl implements a renderer for TSPL format used by TSC thermal label printer.
Package tspl implements a renderer for TSPL format used by TSC thermal label printer.

Jump to

Keyboard shortcuts

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