Documentation
¶
Overview ¶
Package tm2 reads and writes .tm2 files, the labels of TEPRA LINK 2.
TEPRA LINK 2 is KING JIM's app for the "TEPRA" PRO label printers. A .tm2 file is one line of JSON. This package builds such files, so a label can be made elsewhere, opened in the app and printed from there. It does not talk to a printer.
The format is not documented. This package follows files the app wrote, and writes every key they have. The keys of an object come in the order of the fields of its type, not of those files.
Lengths are in points (1/72 inch), as in the file, unless a name says mm.
Index ¶
- Constants
- Variables
- func MMToPoints(mm float64) float64
- func PointsToMM(pt float64) float64
- type Align
- type BaseDrawer
- type BorderType
- type CodeKind
- type Color
- type Document
- type Drawer
- type Drawers
- type File
- func NewPages(tape Tape, texts []string, opts ...TextOption) (*File, error)
- func NewPour(tape Tape, column string, values []string, opts ...PourOption) (*File, error)
- func NewText(tape Tape, text string, opts ...TextOption) (*File, error)
- func ParseFile(r io.Reader) (*File, error)
- func ReadFile(path string) (*File, error)
- type FillMode
- type ImageDrawer
- type ImageMode
- type Option
- func WithAlign(a Align) Option
- func WithBackground(picture []byte) Option
- func WithBold() Option
- func WithBorder(b BorderType) Option
- func WithBorderWidth(w float64) Option
- func WithFill(m FillMode) Option
- func WithFontSize(pt float64) Option
- func WithIcon(picture []byte) Option
- func WithImageMode(m ImageMode) Option
- func WithImageThreshold(level int) Option
- func WithLengthMM(mm float64) Option
- func WithMarginMM(mm float64) Option
- func WithName(name string) Option
- func WithPaddingMM(mm float64) Option
- func WithRotation(r Rotation) Option
- func WithTime(t time.Time) Option
- func WithVertical() Option
- func WithVerticalAlign(a VerticalAlign) Option
- type PatchOp
- type PourDrawer
- type PourOnlyOption
- type PourOption
- type RawDrawer
- type Rect
- type Rotation
- type Tape
- type TextDrawer
- type TextOption
- type VerticalAlign
Constants ¶
const ( DrawerTypeText = "text" DrawerTypePour = "pour" DrawerTypeImage = "image" )
The drawer types this package knows.
const ( PourMaxRows = 1000 PourMaxCellRunes = 1000 )
The limits of the app's pour data.
const ( FontGothic = "OTBGoStdR-Normal" FontGothicBold = "OTBGoStdB-Normal" )
The fonts of TEPRA LINK 2, by the names the app writes.
const DefaultBorderPaddingMM = 1.5
DefaultBorderPaddingMM is the padding of a label with a border and no WithPaddingMM, in mm.
const DefaultBorderWidth = 0.7
DefaultBorderWidth is the width of a border as the app writes it. In the app, 0.35 showed thinner, and 1.4 and 2.8 wider.
const DefaultImageThreshold = 128
DefaultImageThreshold is the threshold of a picture of a template of the app.
const DefaultMarginMM = 1.0
DefaultMarginMM is the blank tape before and after a label as the app sets it, in mm.
const FileTableColumns = 50
FileTableColumns is how many columns the app writes in the table, used or not.
const FileVersion = "2.0.0"
FileVersion is the "version" TEPRA LINK 2 writes.
Variables ¶
var ( // ErrTapeNotSupported is a tape width whose sizes are not known. ErrTapeNotSupported = errors.New("tm2: tape width not supported") // ErrUnknownName is a name ParseFillMode, ParseBorderType, ParseAlign, // ParseVerticalAlign, ParseRotation, ParseCodeKind or ParseImageMode // does not know. ErrUnknownName = errors.New("tm2: unknown name") // ErrInvalidOptions is an Option, or options together, that NewText, // NewPages or NewPour cannot use. ErrInvalidOptions = errors.New("tm2: invalid options") // ErrCrashesApp is a value TEPRA LINK 2 crashes on. It is not written. ErrCrashesApp = errors.New("tm2: the app crashes on it") // ErrBadFile is a file that is not a .tm2 file this package can read, or // one it cannot encode. It wraps the JSON error. ErrBadFile = errors.New("tm2: bad .tm2 file") // ErrBadText is text that is not UTF-8, which a file cannot hold. ErrBadText = errors.New("tm2: text is not UTF-8") // ErrNoText is a label with no text: an empty text, or no values to // pour. ErrNoText = errors.New("tm2: no text") // ErrOverLimit is more than the app takes: rows, characters in a cell, // columns, or a label over 3000 mm. ErrOverLimit = errors.New("tm2: over the app's limit") // ErrNoRoom is no room on the tape for what is on a label: padding that // takes it, too many lines, a line too long to run across the tape, a // font size too large, or a fixed length too short. ErrNoRoom = errors.New("tm2: no room on the tape") // ErrBadImage is a picture that cannot be read as PNG, JPEG or GIF. ErrBadImage = errors.New("tm2: bad picture") // ErrBadCode is a value that cannot be shown as the kind of code asked // for. ErrBadCode = errors.New("tm2: bad value for a code") // ErrBadPatch is an operation File.Patch cannot apply, or a file the // operations make that is no .tm2 file. ErrBadPatch = errors.New("tm2: bad patch") )
The errors of this package. Each error it returns wraps one or more of these, to test with errors.Is. Errors of the file system, and of a reader or a writer, are returned as they are, to test with errors.Is too.
var ( Tape4mm = Tape{WidthMM: 4, PrintableHeight: 8.8, FrameHeight: 12} Tape6mm = Tape{WidthMM: 6, PrintableHeight: 14.400001, FrameHeight: 18} Tape9mm = Tape{WidthMM: 9, PrintableHeight: 21.6, FrameHeight: 26} Tape12mm = Tape{WidthMM: 12, PrintableHeight: 28.800001, FrameHeight: 35} Tape18mm = Tape{WidthMM: 18, PrintableHeight: 43.2, FrameHeight: 52} Tape24mm = Tape{WidthMM: 24, PrintableHeight: 51.2, FrameHeight: 69} Tape36mm = Tape{WidthMM: 36, PrintableHeight: 76.8, FrameHeight: 103} Tape50mm = Tape{WidthMM: 50, PrintableHeight: 135.8, FrameHeight: 142} )
The tapes whose sizes are known. Each one's sizes come from a file the app wrote for it, in testdata.
var ( Black = Color{0, 0, 0, 1} White = Color{1, 1, 1, 1} )
The colors the app writes for black text on a white tape.
var Tapes = []Tape{Tape4mm, Tape6mm, Tape9mm, Tape12mm, Tape18mm, Tape24mm, Tape36mm, Tape50mm}
Tapes are the tapes whose sizes are known, narrowest first. Other widths need a file the app wrote for them.
Functions ¶
Types ¶
type Align ¶
type Align int
Align is where a text box puts each line across its frame. Each value was seen in TEPRA LINK 2 for Android, opening a file this package wrote. The app crashes on a file with 3.
func ParseAlign ¶
ParseAlign returns the alignment of a name: left, center or right.
type BaseDrawer ¶
type BaseDrawer struct {
// Identifier is a UUID, unique in the file.
Identifier string `json:"-"`
// Rotate turns the drawer in Frame.
Rotate Rotation `json:"Rotate"`
// TapeForegroundColor is the color the app shows the text in, Black as
// it writes it. White showed white text on the white tape.
TapeForegroundColor Color `json:"tapeForegroundColor"`
// Frame is where the drawer is in the document's frame. A text box fits
// its text to it unless SizePriority is set. A picture fits in it,
// keeping its shape, centred.
Frame Rect `json:"frame"`
// BIType is the line drawn on the edges of Frame.
BIType BorderType `json:"BIType"`
// BILineWidthValue is the width of the BIType line, DefaultBorderWidth
// as the app writes it. It is spelled "BILineWidhValue" in the file.
BILineWidthValue float64 `json:"BILineWidhValue"`
// Below: written as the app writes them. Values tried showed no change
// in the app, or none were tried.
// TapeBackgroundColor: Black did not fill the box behind the text.
TapeBackgroundColor Color `json:"tapeBackgroundColor"`
// BILineThickness, BILineStyle and BILineWidth: thickness 1 to 3, style
// 0 to 4 and width 0.5 to 2, with box and rounded borders.
BILineThickness int `json:"BILineThickness"`
BILineStyle int `json:"BILineStyle"`
BILineWidth float64 `json:"BILineWidth"`
// TapeVertical, TapeTapeFrame and FrameTop: set, and a frame of
// [0, 0, 40, 20].
TapeVertical bool `json:"tapeVertical"`
TapeTapeFrame Rect `json:"tapeTapeFrame"`
FrameTop bool `json:"frameTop"`
// Unknown holds the keys this package does not know, as they were read,
// and writes them back after the others. A newer app may write keys a
// file read and written here must not lose.
Unknown jsontext.Value `json:",embed"`
}
BaseDrawer holds the fields every drawer has.
type BorderType ¶
type BorderType int
BorderType is the line a drawer draws around its frame. Each type was seen in the app, opening a file this package wrote. Values from 6 up drew no line.
const ( BorderNone BorderType = 0 BorderBox BorderType = 1 BorderRounded BorderType = 2 BorderTopBottom BorderType = 3 BorderTop BorderType = 4 BorderBottom BorderType = 5 )
The border types.
func ParseBorderType ¶
func ParseBorderType(name string) (BorderType, error)
ParseBorderType returns the border type of a name: none, box, rounded, top-bottom, top or bottom.
func (BorderType) String ¶
func (b BorderType) String() string
String returns the name of b, as ParseBorderType takes it.
func (BorderType) Valid ¶
func (b BorderType) Valid() bool
Valid reports whether b is one of the border types known to draw.
type CodeKind ¶
type CodeKind int
CodeKind is what a PourDrawer shows its column as: text, or a code made of it. 1 showed a QR code in the app, and 2 and 3 barcodes. That 2 and 3 are CODE39 and CODE128, and 4 JAN-13, follows the order of the app's manual.
const ( CodeText CodeKind = 0 CodeQR CodeKind = 1 CodeCODE39 CodeKind = 2 CodeCODE128 CodeKind = 3 // CodeJAN13 takes 12 digits. The app adds the check digit. CodeJAN13 CodeKind = 4 )
The kinds of code.
func ParseCodeKind ¶
ParseCodeKind returns the kind of code of a name: text, qr, code39, code128 or jan13.
type Document ¶
type Document struct {
// Drawers are drawn in order, each over the ones before.
Drawers Drawers `json:"drawers"`
// Frame is the label without its margins. Its width is the label's
// length, as the app showed it.
Frame Rect `json:"frame"`
// TapeWidthMM is the tape's width in mm. The app shows the label on a
// tape of this width.
TapeWidthMM int `json:"SettingsTapeWidth"`
// PrintableArea is the height of the band the app prints on, in points.
// It is the tape's PrintableHeight. A smaller value showed a smaller
// band.
PrintableArea float64 `json:"SettingsPrintableArea"`
// AutoLength makes the label as long as Frame. Unset, the label is
// FixedLength long.
AutoLength bool `json:"SettingsAutoLength"`
FixedLength float64 `json:"SettingsFixedLength"`
// Margin is the blank tape before and after Frame, in points.
Margin float64 `json:"SettingsMargin"`
// ForegroundColor and BackgroundColor are the colors of the tape's ink
// and of the tape, as the app shows the label. Swapped, the whole label
// showed black.
ForegroundColor Color `json:"SettingsForegroundColor"`
BackgroundColor Color `json:"SettingsBackgroundColor"`
// TapeVertical turns the whole label to run down the tape.
TapeVertical bool `json:"SettingsTapeVertical"`
// MultiplePage shows the app's controls for more than one page. The app
// sets it on a pour label.
MultiplePage bool `json:"MultiplePage"`
// PourMode shows the label in the app's pour form (流し込み), filled
// from the file's TableData. Unset, it is a plain label (一般).
PourMode bool `json:"PourMode"`
// Below: written as the app writes them. Values tried showed no change
// in the app, or none were tried.
// Name and PrintableFrame: another name, and half the width.
Name string `json:"name"`
PrintableFrame Rect `json:"printableFrame"`
Identifier string `json:"identifier"`
ForegroundColorName string `json:"SettingsForegroundColorName"`
BackgroundColorName string `json:"SettingsBackgroundColorName"`
// Unknown holds the keys this package does not know, as they were read,
// and writes them back after the others. A newer app may write keys a
// file read and written here must not lose.
Unknown jsontext.Value `json:",embed"`
}
Document is one label of a file: the tape settings and its drawers.
type Drawer ¶
type Drawer interface {
// DrawerType is the drawer's "type" in the file.
DrawerType() string
// Base returns the fields every drawer has.
Base() *BaseDrawer
}
Drawer is an object on a label: a TextDrawer, PourDrawer, ImageDrawer, or a RawDrawer for a type this package does not know.
type Drawers ¶
type Drawers []Drawer
Drawers are the objects of a Document, drawn in order.
func (Drawers) MarshalJSON ¶
MarshalJSON is MarshalJSONTo, for encoding/json version 1. encoding/json escapes <, > and & in what it returns, which the app does not.
func (Drawers) MarshalJSONTo ¶
MarshalJSONTo writes each drawer as the app does: "type", "identifier" and an empty key come first, then the drawer's fields.
func (*Drawers) UnmarshalJSON ¶
UnmarshalJSON is UnmarshalJSONFrom, for encoding/json version 1.
type File ¶
type File struct {
// Documents are the pages of the file, a label each. The app lists them
// when the first has MultiplePage set, and prints them together.
Documents []Document `json:"documents"`
// CurrentPage is the document the app opens, from 0. The app crashes on
// a file whose CurrentPage has no document.
CurrentPage int `json:"currentPage"`
// FileName is the name the app shows the label by, with ".tm2". It is
// not the name of the file the app opened.
FileName string `json:"fileName"`
// TableData is the data a PourDrawer fills from: one row, and one label,
// per value, of FileTableColumns cells each.
TableData [][]string `json:"tableData"`
// TableHeader is the title of each column of TableData, shown in the
// app's pour data editor.
TableHeader []string `json:"tableHeader"`
// Below: written as the app writes them. Values tried showed no change
// in the app, or none were tried.
// SavedLength and Version: 999 or left out, and "1.0.0". Date,
// TextWords, Category, Keywords and the catalog titles do not show where
// the app edits a label.
SavedLength *float64 `json:"savedLength,omitzero"`
Version string `json:"version"`
Date string `json:"date"`
TextWords string `json:"textWords"`
Category string `json:"category"`
Keywords string `json:"keywords"`
CatalogTitle string `json:"CatalogTitle"`
CatalogTitleEN string `json:"CatalogTitleEN"`
KeywordsEN string `json:"keywordsEN"`
// Unknown holds the keys this package does not know, as they were read,
// and writes them back after the others. A newer app may write keys a
// file read and written here must not lose.
Unknown jsontext.Value `json:",embed"`
}
File is a .tm2 file.
func NewPages ¶
func NewPages(tape Tape, texts []string, opts ...TextOption) (*File, error)
NewPages returns a file of one page per text, each laid out as NewText lays out its label. So each label has a font size and a length of its own, unlike the labels of NewPour. The app lists the pages, and prints them together. A text may hold line breaks ("\n").
func NewPour ¶
NewPour returns a file that prints one label per value, with the column titled column. A value may hold line breaks ("\n"). All the labels share one frame, sized for the longest value.
Inverted text of more than one line is poured from a column per line: column, then column 2, column 3 and on.
The text keeps its font size on every label. The app would otherwise fit each value to the shared frame: a value of fewer lines would grow to its height, and run past its sides.
func NewText ¶
func NewText(tape Tape, text string, opts ...TextOption) (*File, error)
NewText returns a file of one label that prints text. text may hold line breaks ("\n").
func (*File) MarshalJSON ¶
MarshalJSON is MarshalJSONTo, for encoding/json version 1. encoding/json escapes <, > and & in what it returns, which the app does not.
func (*File) MarshalJSONTo ¶
MarshalJSONTo writes f, unless the app would crash on it.
func (*File) Patch ¶ added in v0.4.0
Patch applies ops to f in order, as a JSON Patch (RFC 6902) on the file as WriteTo writes it. Either every operation applies, or f is left as it was.
It keeps to what the app writes:
- A key is not added to an object, nor removed from one. The app writes every key, so a key's value is replaced instead. Items of an array are added and removed freely.
- An object put in place of the file, a document or a drawer, by any operation, has every key tm2 writes for it, and no other key but those the file had there. So a drawer's "type" changes only with its keys. A drawer of a type tm2 does not know is one the file had. It may move, but not be copied: it is written as it was read, so its identifier cannot change.
- A drawer added to a document's drawers starts as the app sets a new one of its "type" (text, pour or image), in the document's frame. The keys given replace its values. A key it does not have is an error.
- The empty key after a drawer's identifier stays as the app writes it.
- A document or a drawer with no identifier, or one that another before it has, as a copy has, gets a new one.
- A text box with text shows it, not its placeholder. A box with no text keeps its HasPlaceholder: tm2's own border box is empty, with no placeholder.
- With more than one document, each has MultiplePage set, as NewPages sets it: the app lists the pages only then. A CurrentPage past the last document is the last.
- Each row of tableData, and tableHeader, gets empty cells up to FileTableColumns.
- A picture the patch gives is checked as NewText checks an icon. It may be a JPEG or a GIF, and is made a PNG, as the app stores pictures.
Patch does not lay the label out again. A drawer moved or a text made longer keeps the frames it was given.
type FillMode ¶
type FillMode int
FillMode is how a text box fills the box behind its text. Each mode was seen in TEPRA LINK 2 for Android, opening a file this package wrote. The app crashes on a file with any other value, from 3 up.
const ( // FillNone is black text on the tape. FillNone FillMode = 0 // FillInverted is white text on a black box the size of the frame. The // app shows only the last line of such a box, so NewPour and NewText // give each line a box of its own. FillInverted FillMode = 1 // FillShaded is black text on a light, dotted box the size of the frame. FillShaded FillMode = 2 )
The fill modes.
func ParseFillMode ¶
ParseFillMode returns the fill mode of a name: none, inverted or shaded.
type ImageDrawer ¶
type ImageDrawer struct {
BaseDrawer
// Image is a PNG, base64 in the file. The app fits it in Frame, keeping
// its shape, centred.
Image []byte `json:"image"`
// ImageKind is 3 as the app writes it. 1 showed the picture in grey,
// not turned to black and white. 0 and 2 showed no change.
ImageKind int `json:"imageKind"`
// ImageMode is how the picture turns to black and white.
ImageMode ImageMode `json:"imageMode"`
// ImageThreshold is the grey level, from 0 to 255, below which a pixel
// is black, with ImageModeThreshold.
ImageThreshold int `json:"imageThreshold"`
// Below: written as the app writes them. Values tried showed no change
// in the app, or none were tried.
// ImageBlock and ImageOffset: 50, and 0.
ImageBlock int `json:"imageBlock"`
ImageOffset int `json:"imageOffset"`
}
ImageDrawer is a picture.
func NewImageDrawer ¶
func NewImageDrawer(png []byte, frame Rect) *ImageDrawer
NewImageDrawer returns a picture in frame, set as in a file the app wrote. The app fits png in frame, keeping its shape, centred. It turns it to black and white at ImageThreshold.
func (*ImageDrawer) DrawerType ¶
func (*ImageDrawer) DrawerType() string
DrawerType returns DrawerTypeImage.
type ImageMode ¶
type ImageMode int
ImageMode is how the app turns a picture to black and white. Each mode was seen in the app, opening a file this package wrote. 0 and 4 showed as ImageModeThreshold does.
const ( // ImageModeDiffusion spreads the error of each pixel to the next ones: // grey shows as scattered dots. ImageModeDiffusion ImageMode = 1 // ImageModeThreshold makes each pixel black below ImageThreshold. It is // the mode of a picture of a template of the app. ImageModeThreshold ImageMode = 2 // ImageModeScreen shows grey as a regular screen of dots. ImageModeScreen ImageMode = 3 )
The modes the app showed differently.
func ParseImageMode ¶
ParseImageMode returns the mode of a name: diffusion, threshold or screen.
type Option ¶
type Option func(*optionConfig)
Option sets something every kind of label has. NewText, NewPages and NewPour all take it: it is a TextOption and a PourOption. Each With function returns one, but WithCode. What no option sets is as the app sets it.
func WithAlign ¶
WithAlign sets where each line of text goes across its frame. It is AlignLeft by default, as the app sets it.
func WithBackground ¶
WithBackground stretches a PNG, JPEG or GIF picture under the whole label.
func WithBorder ¶
func WithBorder(b BorderType) Option
WithBorder draws a line around the label, on a box of its own. The text keeps DefaultBorderPaddingMM from it, unless WithPaddingMM is given.
func WithBorderWidth ¶
WithBorderWidth sets the width of the border. It is DefaultBorderWidth by default.
func WithFontSize ¶
WithFontSize sets the size of the text, in points. By default it is the size at which the text fills the tape.
func WithIcon ¶
WithIcon puts a PNG, JPEG or GIF picture before the text, as high as the tape prints, keeping its shape.
func WithImageMode ¶
WithImageMode sets how the app turns the icon and the background to black and white. It is ImageModeThreshold by default.
func WithImageThreshold ¶
WithImageThreshold sets the grey level, from 0 to 255, below which a pixel of the icon and the background is black, with ImageModeThreshold. It is DefaultImageThreshold by default.
func WithLengthMM ¶
WithLengthMM makes the label this long, margins included, in mm, from 10 to 3000 as the app takes it. By default the label is as long as what is on it. Text that does not fit gets smaller, unless WithFontSize is given, and what is on the label is centred.
func WithMarginMM ¶
WithMarginMM sets the blank tape before and after the label, in mm, from 1 to 500 as the app takes it. It is DefaultMarginMM by default.
func WithPaddingMM ¶
WithPaddingMM sets the blank between the label's edges and what is on it, in mm: room for a border, or for the frame of a background.
func WithRotation ¶
WithRotation turns the text. Rotation90 and Rotation270 run its lines across the tape.
func WithVertical ¶
func WithVertical() Option
WithVertical writes the text top to bottom, each line to the left of the one before. Its lines run across the tape, as with Rotation90.
func WithVerticalAlign ¶
func WithVerticalAlign(a VerticalAlign) Option
WithVerticalAlign sets where the text goes down its frame. It is VerticalAlignMiddle by default, as the app sets it.
type PatchOp ¶ added in v0.4.0
type PatchOp struct {
// Op is add, remove, replace, move, copy or test.
Op string `json:"op"`
Path string `json:"path"`
// From is the value that move and copy take.
From string `json:"from,omitzero"`
// Value is the value that add, replace and test take.
Value jsontext.Value `json:"value,omitzero"`
}
PatchOp is one operation of a JSON Patch (RFC 6902), as File.Patch applies it. Path and From are JSON Pointers (RFC 6901) into the file as WriteTo writes it, such as "/documents/0/drawers/1/TIText".
type PourDrawer ¶
type PourDrawer struct {
TextDrawer
// ColumnNumber is the column of the file's TableData the box shows, from
// 0.
ColumnNumber int `json:"ColumnNumber"`
// Attribute is what the column shows as: text, or a code made of it.
Attribute CodeKind `json:"Attribute"`
}
PourDrawer is a text box filled from a column of the file's table, one label per row.
func NewPourDrawer ¶
func NewPourDrawer(column int, text string, frame Rect) *PourDrawer
NewPourDrawer returns a text box in frame for column, showing text in the editor.
func (*PourDrawer) DrawerType ¶
func (*PourDrawer) DrawerType() string
DrawerType returns DrawerTypePour.
type PourOnlyOption ¶
type PourOnlyOption func(*optionConfig)
PourOnlyOption sets what only the labels of NewPour have. It is not a TextOption, so NewText and NewPages do not compile with it.
func WithCode ¶
func WithCode(k CodeKind) PourOnlyOption
WithCode shows each value of NewPour as a code instead of text. The app shows codes in pour data only, so NewText and NewPages do not take it.
type PourOption ¶
type PourOption interface {
// contains filtered or unexported methods
}
PourOption sets something of the labels NewPour makes. An Option is one, and so is a PourOnlyOption.
type RawDrawer ¶
type RawDrawer struct {
// BaseDrawer holds the fields every drawer has, as read. Changing them
// does not change what is written.
BaseDrawer
// Type is the drawer's "type".
Type string
// JSON is the drawer as read.
JSON jsontext.Value
}
RawDrawer is a drawer of a type this package does not know. It is written back as it was read.
type Rect ¶
type Rect [4]float64
Rect is a frame: x, y, width and height, in points. y grows down the tape.
type Rotation ¶
type Rotation int
Rotation turns a drawer in its frame, by a quarter turn or a half turn. Each value was seen in TEPRA LINK 2 for Android, opening a file this package wrote. The app crashes on a file with 90, and so on any value it does not know.
const ( RotationNone Rotation = 0 Rotation180 Rotation = 1 // Rotation270 turns the text a quarter turn left: it reads bottom to // top. Rotation270 Rotation = 2 // Rotation90 turns the text a quarter turn right: it reads top to // bottom. Rotation90 Rotation = 3 )
The rotations, clockwise.
func ParseRotation ¶
ParseRotation returns the rotation of a name, in degrees clockwise: 0, 90, 180 or 270.
type Tape ¶
type Tape struct {
// WidthMM is the tape's width in mm, as in SettingsTapeWidth.
WidthMM int
// PrintableHeight is the height the printer can print on, in points.
PrintableHeight float64
// FrameHeight is the height of the label's frame, in points. The
// printable band sits in its middle.
FrameHeight float64
}
Tape is a tape width and the sizes the app writes for it.
func LookupTape ¶
LookupTape returns the tape of a width in mm.
func (Tape) PrintableTop ¶
PrintableTop is the y of the printable band in the frame, in points.
type TextDrawer ¶
type TextDrawer struct {
BaseDrawer
// Text is what the box shows. "\n" breaks a line.
Text string `json:"TIText"`
// FontName is FontGothic or FontGothicBold. Other fonts were not tried.
FontName string `json:"TIFontName"`
// FontSize is the size of the text, in points. The app uses it only with
// SizePriority. Otherwise it fits the text to Frame.
FontSize float64 `json:"TIFontSize"`
// Alignment is where each line goes across Frame.
Alignment Align `json:"TIAlignment"`
// VerticalAlignment is where the lines go down Frame.
VerticalAlignment VerticalAlign `json:"TIVerticalAlignment"`
// FillMode is the box behind the text.
FillMode FillMode `json:"TIFillMode"`
// FontFace is 1 as the app writes it. 0 showed no change. The app
// crashes on 2, so other values are not written.
FontFace int `json:"TIFontFace"`
// TextVertical writes the lines top to bottom, each to the left of the
// one before.
TextVertical bool `json:"textVertical"`
// HasPlaceholder shows "未入力のテキストボックス" in grey instead of
// Text. The app sets it on a box with no text.
HasPlaceholder bool `json:"hasPlaceholder"`
// HoldAspect, set as the app sets it, fits the text to Frame, unless
// SizePriority is set. Unset, the text keeps FontSize, its lines close
// up, and the app marks the box 固.
HoldAspect bool `json:"holdAspect"`
// SizePriority keeps FontSize instead of fitting the text to Frame.
SizePriority bool `json:"sizePriority"`
// Below: written as the app writes them. Values tried showed no change
// in the app, or none were tried.
// Color: grey, red and white. TapeForegroundColor is the color shown.
Color Color `json:"TIColor"`
// Bold and Italic: set. FontGothicBold is how the app writes bold.
Bold bool `json:"TIBold"`
Italic bool `json:"TIItalic"`
// LineBreak: 0, 1 and 3, on text of two lines broken by "\n".
LineBreak int `json:"TILineBreak"`
// TextMargin: up to [3, 3], fitted to Frame and with SizePriority.
TextMargin [2]float64 `json:"textMargin"`
}
TextDrawer is a text box.
func NewTextDrawer ¶
func NewTextDrawer(text string, frame Rect) *TextDrawer
NewTextDrawer returns a text box in frame, set as the app sets a new one.
func (*TextDrawer) DrawerType ¶
func (*TextDrawer) DrawerType() string
DrawerType returns DrawerTypeText.
type TextOption ¶
type TextOption interface {
// contains filtered or unexported methods
}
TextOption sets something of the labels NewText and NewPages make. An Option is one.
type VerticalAlign ¶
type VerticalAlign int
VerticalAlign is where a text box puts its lines down its frame. Each value was seen in the app, opening a file this package wrote. The app opened 3, and showed it as VerticalAlignMiddle, so it is not offered.
const ( VerticalAlignTop VerticalAlign = 0 VerticalAlignMiddle VerticalAlign = 1 VerticalAlignBottom VerticalAlign = 2 )
The alignments down.
func ParseVerticalAlign ¶
func ParseVerticalAlign(name string) (VerticalAlign, error)
ParseVerticalAlign returns the alignment of a name: top, middle or bottom.
func (VerticalAlign) String ¶
func (a VerticalAlign) String() string
String returns the name of a, as ParseVerticalAlign takes it.
func (VerticalAlign) Valid ¶
func (a VerticalAlign) Valid() bool
Valid reports whether a is one of the alignments seen in the app.