Documentation ¶
Overview ¶
Package linebreak collects types for line-breaking.
BSD License ¶
Copyright (c) 2017–20, Norbert Pillmayer ¶
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 ¶
const InfinityDemerits int32 = 10000
InfinityDemerits is the worst demerit value possible.
const InfinityMerits int32 = -10000
InfinityMerits is the best (most desirable) demerit value possible.
Variables ¶
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 ¶
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.
type ParShape ¶
ParShape is a type to return the line length for a given line number.
func RectangularParShape ¶
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 ¶
WSS (width stretch & shrink) is a type to hold an elastic width (of text).
func (WSS) SetFromKnot ¶
SetFromKnot sets the width's of an elastic WSS from a knot.
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. |