genpdf

package
v0.0.0-...-b62e637 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DejaVuSansMono = Config{
	TabLen:  4,
	LineLen: 75,
	PageLen: 53,
	Font:    dejaVuSansMonoFont,

	FontSize:    12,
	FontName:    "DejaVuSansMono",
	RuneReplace: '�',
	LineBreak:   0.49,
	MarginH:     0.9,
	MarginV:     2.0,
	HeadRune:    '━',
	BeginLine:   BeginLineNone,
}

A Generator with the font DejaVu Sans Mono.

Functions

func BeginLineNone

func BeginLineNone() func(first bool) string

Do nothing at begin line

func BeginLineNumber

func BeginLineNumber() func(first bool) string

Write the line number or a ' if it's a multiple line.

Types

type Builder

type Builder struct {
	Lines []string

	// Config
	TabLen  int // width of a tabulation
	LineLen int // max line size
	PageLen int // The number of line into a page

	// Return true if the rune is invalid (For example: the rune desn't have
	// a glyph in the font). Can be nil.
	RuneCheck func(rune) bool
	// The rune to replace unchecked rune
	RuneReplace rune

	// Add a string at the begin of each line.
	BeginLine func(first bool) string
	// contains filtered or unexported fields
}

A buffer to split a text into several lines. TabLen and LineLen must be set before use. Do not use it in concurence.

func (*Builder) AddLine

func (b *Builder) AddLine(line string)

Add one line.

func (*Builder) AddLines

func (b *Builder) AddLines(lines ...string)

Add miltiples lines.

func (*Builder) CommitLine

func (b *Builder) CommitLine()

Commit the word and create a new line if not empty

func (*Builder) Map

func (b *Builder) Map(r rune)

Check the rune of map it the add it to the builder.

func (*Builder) NewLine

func (b *Builder) NewLine()

Commit current line and add a new line

func (*Builder) UncheckedRunes

func (b *Builder) UncheckedRunes() []rune

func (*Builder) Write

func (b *Builder) Write(text []byte) (int, error)

Like WriteString

func (*Builder) WriteString

func (b *Builder) WriteString(text string)

Add the text to the buffer. No new line at the end. If it's the last line of the document, call Builder.CommitLine()

type Config

type Config struct {
	Font     []byte
	FontSize int

	FontName    string
	RuneReplace rune
	TabLen      int     // width of a tabulation
	LineLen     int     // max line size
	PageLen     int     // The number of line into a page
	LineBreak   float64 // Line size
	HeadRune    rune    // The rune line to separate head and body.

	// The margins
	MarginH, MarginV float64

	// This function it's called in CreatePDF() and the result at each line
	// begin.
	BeginLine func() func(first bool) string
	// contains filtered or unexported fields
}

All Public fields are required.

func (*Config) CreatePDF

func (c *Config) CreatePDF() Generator

Create Create a PDF.

func (*Config) Init

func (c *Config) Init() error

Init the list of runes into the font. And headLine.

type Generator

type Generator struct {
	Builder
	Title string
	Date  time.Time
	// contains filtered or unexported fields
}

Used to write text then generate the PDF. Zero value is not ready to use.

func (*Generator) PDF

func (g *Generator) PDF() ([]byte, error)

Jump to

Keyboard shortcuts

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