linebreak

package
v0.0.0-...-ae32867 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2020 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package linebreak collects types for line-breaking.

BSD License

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of this software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Index

Constants

View Source
const InfinityDemerits int32 = 10000

InfinityDemerits is the worst demerit value possible.

View Source
const InfinityMerits int32 = -10000

InfinityMerits is the best (most desirable) demerit value possible.

Variables

View Source
var DefaultParameters = &Parameters{
	Tolerance:            5000,
	PreTolerance:         100,
	LinePenalty:          10,
	HyphenPenalty:        50,
	ExHyphenPenalty:      50,
	DoubleHyphenDemerits: 0,
	FinalHyphenDemerits:  50,
	EmergencyStretch:     dimen.Dimen(dimen.BP * 50),
	LeftSkip:             khipu.NewGlue(0, 0, 0),
	RightSkip:            khipu.NewGlue(0, 0, 0),
	ParFillSkip:          khipu.NewGlue(0, 0, 0),
}

DefaultParameters are the standard line-breaking parameters. The promote a tolerant configuration, suitable for almost always finding an acceptable set of linebreaks.

Functions

func CapDemerits

func CapDemerits(d int32) int32

CapDemerits caps a demerit value at infinity.

func T

func T() tracing.Trace

T traces to the core tracer.

Types

type Cursor

type Cursor interface {
	Next() bool
	Knot() khipu.Knot
	Peek() (khipu.Knot, bool)
	Mark() khipu.Mark
	Khipu() *khipu.Khipu
}

Cursor is a type to iterate over a khipu.

type FixedWidthCursor

type FixedWidthCursor struct {
	// contains filtered or unexported fields
}

FixedWidthCursor is a linebreak-cursor for assigning a fixed width to letters and spaces. It is intended to wrap a khipu.Cursor or another linebreak.Cursor.

func NewFixedWidthCursor

func NewFixedWidthCursor(cursor Cursor, glyphWidth dimen.Dimen, stretchFactor int) FixedWidthCursor

NewFixedWidthCursor creates a FixedWidthCursor, given a width dimension for every glyph it will read.

func (FixedWidthCursor) Khipu

func (fwc FixedWidthCursor) Khipu() *khipu.Khipu

Khipu is part of interface Cursor.

func (FixedWidthCursor) Knot

func (fwc FixedWidthCursor) Knot() khipu.Knot

Knot is part of interface Cursor.

func (FixedWidthCursor) Mark

func (fwc FixedWidthCursor) Mark() khipu.Mark

Mark is part of interface Cursor.

func (FixedWidthCursor) Next

func (fwc FixedWidthCursor) Next() bool

Next is part of interface Cursor.

func (FixedWidthCursor) Peek

func (fwc FixedWidthCursor) Peek() (khipu.Knot, bool)

Peek is part of interface Cursor.

type ParShape

type ParShape interface {
	LineLength(int) dimen.Dimen
}

ParShape is a type to return the line length for a given line number.

func RectangularParShape

func RectangularParShape(linelen dimen.Dimen) ParShape

RectangularParShape returns a Parshape for paragraphs of constant line length.

type Parameters

type Parameters struct {
	Tolerance            int32       // acceptable demerits
	PreTolerance         int32       // acceptabale demerits for first (rough) pass
	LinePenalty          int32       // penalty for an additional line
	HyphenPenalty        int32       // penalty for hyphenating words
	ExHyphenPenalty      int32       // penalty for explicit words
	DoubleHyphenDemerits int32       // demerits for consecutive hyphens
	FinalHyphenDemerits  int32       // demerits for hyphen in the last line
	EmergencyStretch     dimen.Dimen // stretching acceptable when desperate
	LeftSkip             khipu.Glue  // glue at left edge of paragraphs
	RightSkip            khipu.Glue  // glue at right edge of paragraphs
	ParFillSkip          khipu.Glue  // glue at the end of a paragraph
}

Parameters is a collection of configuration parameters for line-breaking.

type WSS

type WSS struct {
	W   dimen.Dimen
	Min dimen.Dimen
	Max dimen.Dimen
}

WSS (width stretch & shrink) is a type to hold an elastic width (of text).

func (WSS) Add

func (wss WSS) Add(other WSS) WSS

Add adds dimensions from a given WSS to wss, returning a new WSS.

func (WSS) Copy

func (wss WSS) Copy() WSS

Copy copies a WSS.

func (WSS) SetFromKnot

func (wss WSS) SetFromKnot(knot khipu.Knot) WSS

SetFromKnot sets the width's of an elastic WSS from a knot.

func (WSS) Spread

func (wss WSS) Spread() (w dimen.Dimen, min dimen.Dimen, max dimen.Dimen)

Spread returns the width's of an elastic WSS.

func (WSS) String

func (wss WSS) String() string

func (WSS) Subtract

func (wss WSS) Subtract(other WSS) WSS

Subtract subtracts dimensions from a given WSS from wss, returning a new WSS.

Directories

Path Synopsis
Package firstfit implements a straightforward line-breaking algorithm where lines are broken at the first suitable breakpoint.
Package firstfit implements a straightforward line-breaking algorithm where lines are broken at the first suitable breakpoint.
Package knuthplass implements (in an early draft) a line breaking algorithm described by D.E. Knuth and M.F. Plass.
Package knuthplass implements (in an early draft) a line breaking algorithm described by D.E. Knuth and M.F. Plass.

Jump to

Keyboard shortcuts

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