layla

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

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

Go to latest
Published: Jan 12, 2021 License: BSD-2-Clause Imports: 14 Imported by: 0

README

layla

layla is a layout and template language based on the xelf language framework.

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

The idea is that layout definitions using the xelf are already templates. Reusing the std tools and some custom expression we can build the layout node tree. The nodes proxy to custom go structs, making it easy to work with.

Layla should grow to a useful (for me at least) package of its own. I would like it to support text, block, rect, ellipse, qrcode, barcode and image elements group, vbox, hbox and table layouts

There will someday be render packages for: tsc Taiwan Semiconductor (TSC) label printer, specifically for the DA-200 printer t88 Epson receipt printer, specifically the TM-T88III 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

View Source
var Env = exp.Builtin{
	NodeLookup,
	utl.StrLib.Lookup(),
	utl.TimeLib.Lookup(),
	std.Core, std.Decl,
}

Env is the default resolver environment for layla.

Functions

func FakeBoldStyler

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

func NodeLookup

func NodeLookup(sym string) *exp.Spec

NodeLookup is the resolver lookup for layla node resolvers

func ZeroStyler

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

Types

type Border

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

func (Border) Default

func (b Border) Default(w float64) 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  float64 `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 float64 `json:"w,omitempty"`
	H float64 `json:"h,omitempty"`
}

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

type Font

type Font struct {
	Name   string   `json:"name,omitempty"`
	Size   float64  `json:"size,omitempty"`
	Line   float64  `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 represents all display elements.

func Execute

func Execute(env exp.Env, rr io.Reader) (*Node, error)

Execute parses and executes the expression from reader r and returns a node or error.

func ExecuteString

func ExecuteString(env exp.Env, s string) (*Node, error)

ExecuteString parses and executes the expression string s and returns a node or error.

func LayoutAndPage

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

func Page

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

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   float64 `json:"gap,omitempty"`
	Sub   Dim     `json:"sub,omitempty"`
}

NodeLayout holds all layout related node data

type Off

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

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

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 float64 `json:"x,omitempty"`
	Y float64 `json:"y,omitempty"`
}

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

type Styler

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

type Table

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

Directories

Path Synopsis
Package html implements a layla renderer for html previews.
Package html implements a layla renderer for html previews.
Package mark provides a simple markdown text format.
Package mark provides a simple markdown text format.
Package pdf implements a layla renderer for PDF using the jung-kurt/gofpdf package.
Package pdf implements a layla renderer for PDF using the jung-kurt/gofpdf package.
Package tspl implements a layla renderer for TSC thermal label printer using TSPL.
Package tspl implements a layla renderer for TSC thermal label printer using TSPL.

Jump to

Keyboard shortcuts

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