wordwrap

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 10 Imported by: 2

README

golang-wrapper

This is a library to provide positional and rendering word wrapping of text any arbitrary rectangle. It is capable of giving you the positions of each individual word, as well as rendering it to an image if desired.

To

It is technically capable of handling rich text and non-text objects; adding them can be done manually as a library user.

Part of the goal of the library was to:

  • Provide just positioning details without drawing
  • Be as simple as necessary
  • Be usable with the image package and not provide too much of a framework
  • Support rich text eventually
  • Support arbitrary locations provided as a image.Rectangle or image.Image

Concept

Box

The basics of the library is that it first breaks up the line in to "boxes" boxes can essentially be anything however in the 'simple' implementation here they are assumed to be a set of characters, spaces, or a control character (essentially a new line) A box can be thought of the lowest level representation that the library is willing to dea with.

This is created by a boxer a standard iterator like component:

type Boxer interface {
    Next() (Box, int, error)
    SetFontDrawer(face *font.Drawer)
    FontDrawer() *font.Drawer
    Back(i int)
}

For simple uses of the wrapping library you shouldn't need to worry about this. But you might care if you want to insert your box, which can be done provided it implements the: Box interface. But basically a box interface tells the size of the object, the baseline, and a mechanism for drawing it.

The baseline is probably the most important part, it is the "line" which the character is positioned. If you were to mix multiple font sizes you would want a consistent baseline so they all appear on the same level:

Line

A line is just that a line of boxes that fit in the given space (provided in a rect). A line is produced by a Liner. Such as a simple liner. Line does the real folding work; in the 'simple' version it calls the boxer (subject to change) for the next element. Then stops when it runs out of space. If it ends on a space it will return a new line character instead.

Simple

Simple basically is the first iteration which is simple enough to be used. I have used it as I intend to add versions which work differently. Simple makes many assumptions such as language assumptions.

Wrap

Wrap is just a container object for ease of use.

Usage

How do I use this to draw text in the simplest possible way?

    i := image.NewRGBA(image.Rect(0, 0, *width, *height))
    gr, err := OpenFont(*fontname)
    if err != nil {
        log.Panicf("Error opening font %s: %s", *fontname, err)
    }
    grf := GetFontFace(*fontsize, *dpi, gr)
    text, err := GetText(*textsource)
    if err != nil {
        log.Panicf("Text fetch error: %s", err)
    }
    if err := wordwrap.SimpleWrapTextToImage(text, i, grf, options); err != nil {
        log.Panicf("Text wrap and draw error: %s", err)
    }

Note:

  • OpenFont - left to an exercise for the user
  • GetFontFace - left to an exercise for the user
  • GetText - left to an exercise for the user

You could also do it in 2 steps, this provides the rectangles incase you wanted to make a word clickable.

    i := image.NewRGBA(image.Rect(0, 0, *width, *height))
    gr, err := OpenFont(*fontname)
    if err != nil {
        log.Panicf("Error opening font %s: %s", *fontname, err)
    }
    grf := GetFontFace(*fontsize, *dpi, gr)
    text, err := GetText(*textsource)
    if err != nil {
        log.Panicf("Text fetch error: %s", err)
    }
    target := image.Rect(350,44,592, 209)
    sw, lines, _, err := wordwrap.SimpleWrapTextToRect(text, target, grf)
    if err != nil {
    log.Panicf("Text wrap error: %s", err)
    }
    if err := sw.RenderLines(i, lines, target.Min); err != nil {
    log.Panicf("Text draw error: %s", err)
    }

Options

There will be more options but some are:

WordWrap/Line Option: wordwrap.BoxLine

Using the option BoxLine will cause the image to draw a box around the lines of boxes. Like such

Usage:

wordwrap.SimpleWrapTextToImage(text, i, grf, wordwrap.BoxLine)
WordWrap/Box Option: wordwrap.BoxBox

Using the option BoxLine will cause the image to draw a box around the boxes. Like such

Usage:

wordwrap.SimpleWrapTextToImage(text, i, grf, wordwrap.BoxBox)
wordwrap.NewPageBreakBox

Adds a box that will be put at the end of every "page" of the word wrap. For instance a "more text" option used in: https://github.com/arran4/golang-rpg-textbox

Usage:

wordwrap.SimpleWrapTextToImage(text, i, grf, wordwrap.NewPageBreakBox(NewImageBox(image)))
wordwrap.ImageBoxMetricAboveTheLine (default)

Puts the image above the line as you would expect on a modern word processor

Usage:

wordwrap.SimpleWrapTextToImage(text, i, grf, wordwrap.NewPageBreakBox(wordwrap.NewImageBox(chevronImage, wordwrap.ImageBoxMetricAboveTheLine), wordwrap.BoxBox))
wordwrap.ImageBoxMetricBelowTheLine (default)

Puts the image below the line as you would expect on a modern word processor

Usage:

wordwrap.SimpleWrapTextToImage(text, i, grf, wordwrap.NewPageBreakBox(wordwrap.NewImageBox(chevronImage, wordwrap.ImageBoxMetricBelowTheLine), wordwrap.BoxBox))
wordwrap.ImageBoxMetricCenterLine

Vertically centers the box line

Usage:

wordwrap.SimpleWrapTextToImage(text, i, grf, wordwrap.NewPageBreakBox(wordwrap.NewImageBox(chevronImage, wordwrap.ImageBoxMetricCenter(fontDrawer)), wordwrap.BoxBox))
wordwrap.SourceImageMapper

This allows you to substitute the source image for a box. Such as the source image for text is a color.Uniform image, so it allows you to change the color, or apply some other effect such as a pattern or fade it out.

For an image you can use proxy / interceptor pattern draw.Image structure to modify the source image as you want.

wordwrap.BoxDrawMap

Is a function to the form:

func(box Box, drawOps *DrawConfig, bps *BoxPositionStats) Box

Which is executed just before each box is drawn if provided. This allows you to substitute a box, such as with an empty box if you don't wish for it to be drawn, or you could use it to mask input.

Positioning functions: wordwrap.HorizontalCenterLines wordwrap.RightLines wordwrap.HorizontalCenterBlock wordwrap.RightBlock wordwrap.VerticalCenterBlock wordwrap.BottomBlock

Vertical or horizontally justifies or positions the lines or block, as per below.

Block is the entire block of text, while the line is just each line individually.

Option Result Usage
wordwrap.HorizontalCenterLines wordwrap.SimpleWrapTextToImage(text, i, grf, wordwrap.HorizontalCenterLines)
wordwrap.RightLines wordwrap.SimpleWrapTextToImage(text, i, grf, wordwrap.RightLines)
wordwrap.HorizontalCenterBlock wordwrap.SimpleWrapTextToImage(text, i, grf, wordwrap.HorizontalCenterBlock)
wordwrap.RightBlock wordwrap.SimpleWrapTextToImage(text, i, grf, wordwrap.RightBlock)
wordwrap.VerticalCenterBlock wordwrap.SimpleWrapTextToImage(text, i, grf, wordwrap.VerticalCenterBlock)
wordwrap.BottomBlock wordwrap.SimpleWrapTextToImage(text, i, grf, wordwrap.BottomBlock)

CLI app

For demo purposes there is a CLI app in cmd/simplewraptoimage

  -boxbox
    	Box the box
  -boxline
    	Box the line
  -dpi float
    	Doc dpi (default 180)
  -font string
    	Text font (default "goregular")
  -height int
    	Doc height (default 600)
  -out string
    	file to write to, in some cases this is ignored (default "out.png")
  -size float
    	font size (default 16)
  -text string
    	File in, or - for std input (default "-")
  -width int
    	Doc width (default 400)

Only font that is supported is "goregular" as this is only a demo. Happy to accept PRs to expand the util package to make it more general. (Or to include more cli.)

The contents of the images directory are outputs from this using the test data from the folder testdata

Advanced Layout System

The library now supports a flexible, 2-pass (or 3-pass) layout system via the TextToSpecs method on SimpleWrapper. This allows for complex constraints like "A4 Width", "Minimum Width but Unbounded Height", or "Auto-sizing with a Max Width".

Core Concepts

  • TextToSpecs: The main entry point. It calculates the layout without rendering, returning a LayoutResult.
  • SpecOption: Functional options to define constraints (Width, Height, Padding, PageBackground).
  • SizeFunction: Functions that determine size based on content measurements (Fixed, Auto/Unbounded, Min, Max, A4Width, etc).

Examples

Simple Fixed Width

Constrain the text to a fixed width of 200px.

func ExampleSimpleWrapper_TextToSpecs_simple() {
	// Standard Wrapper Args
	args := []interface{}{
		font,
		"Simple Text wrapping example.",
	}
	
	// Create Wrapper
	wrapper := wordwrap.NewRichWrapper(args...)
	
	// Layout with Constraint: Fixed Width 200px
	result, err := wrapper.TextToSpecs(wordwrap.Width(wordwrap.Fixed(200)))
	if err != nil {
		log.Fatal(err)
	}

	// Render
	img := image.NewRGBA(image.Rect(0, 0, result.PageSize.X, result.PageSize.Y))
	if err := wrapper.RenderLines(img, result.Lines, result.ContentStart); err != nil {
		log.Fatal(err)
	}
	
	saveDocImage("simple_example.png", img)
}

A4 Document Layout

Create a standard A4 document layout (at 96 DPI) with padding and a white background.

func ExampleSimpleWrapper_TextToSpecs_a4() {
	// ... load font ...
	text := "This is an example of an A4 document layout..."

	wrapper := wordwrap.NewRichWrapper(font, text)

	// Layout Specs: A4 Width (96 DPI), 20px Padding, White Background
	result, err := wrapper.TextToSpecs(
		wordwrap.Width(wordwrap.A4Width(96)),
		wordwrap.Padding(20, color.Black),
		wordwrap.PageBackground(color.White),
	)
	if err != nil {
		log.Fatal(err)
	}

	img := image.NewRGBA(image.Rect(0, 0, result.PageSize.X, result.PageSize.Y))
	
	// Draw Background
	if result.PageBackground != nil {
		draw.Draw(img, img.Bounds(), &image.Uniform{result.PageBackground}, image.Point{}, draw.Src)
	}

	if err := wrapper.RenderLines(img, result.Lines, result.ContentStart); err != nil {
		log.Fatal(err)
	}
	// ...
}

A4 Document Layout (Full Page)

Create a standard A4 document layout with both fixed width and height. Note that A4Width and A4Height require the target DPI (e.g., 96) to calculate the correct pixel dimensions.

func ExampleSimpleWrapper_TextToSpecs_a4_full() {
	// ... load font ...
	text := "This is an example of a full A4 document layout..."

	wrapper := wordwrap.NewRichWrapper(font, text)

	// Layout Specs: A4 Width & Height (96 DPI), 20px Padding, White Background
	result, err := wrapper.TextToSpecs(
		wordwrap.Width(wordwrap.A4Width(96)),
		wordwrap.Height(wordwrap.A4Height(96)),
		wordwrap.Padding(20, color.Black),
		wordwrap.PageBackground(color.White),
	)
	if err != nil {
		log.Fatal(err)
	}

	// ... Render same as included in the examples ...
	// saveDocImage("a4_full_example.png", img)
}

Flexible Constraints (Min/Max/Auto)

Use Min and Max to create flexible layouts. For example, Min(A4, Unbounded) effectively means "Auto width, but capped at A4 width" (logic: min(A4, natural)).

func ExampleSimpleWrapper_TextToSpecs_flexible() {
	// ...
	wrapper := wordwrap.NewRichWrapper(font, "This text will wrap at A4 width...")

	result, err := wrapper.TextToSpecs(
		wordwrap.Width(wordwrap.Min(wordwrap.A4Width(96), wordwrap.Unbounded())),
		wordwrap.PageBackground(color.White),
	)
	// ...
}

Rich Text Support

The library supports rich text including colors, fonts, inline images, backgrounds, and text effects (underline, strikethrough, highlight). These are composed using NewRichWrapper and functional options.

Comprehensive Example
func Example_richTextComprehensive() {
	// ... Setup resources (fonts, images) ...

	args := []interface{}{
		fontRegular,
		"Standard text. ",
		
		// Text Color
		wordwrap.TextColor(color.RGBA{0, 0, 255, 255}), 
		"Blue Text. ",
		wordwrap.TextColor(color.Black), // Reset
		
		// Background Color (Highlight)
		wordwrap.BgColor(color.RGBA{255, 255, 0, 255}),
		"Yellow Background. ",
		
		// Scoped Styles using Group
		wordwrap.Group{
			Args: []interface{}{
				wordwrap.TextColor(color.RGBA{0, 100, 0, 255}),
				"Scoped Green Text. ",
				wordwrap.BgColor(color.RGBA{220, 255, 220, 255}),
				"Green on Light Green. ",
			},
		},
		"Back to Normal. ",
		"\n\n",

		// Font Size Changes
		fontLarge, "Large Text. ",
		fontRegular, "Normal Text. ",
		"\n\n",

		// Effects: Underline, Strikethrough
		"Text with ",
		wordwrap.Group{
			Args: []interface{}{
				wordwrap.Underline(color.RGBA{255, 0, 0, 255}),
				"Red Underline",
			},
		},
		" and ",
		wordwrap.Group{
			Args: []interface{}{
				wordwrap.Strikethrough(color.Black),
				"Strikethrough",
			},
		},
		".\n\n",

		// Inline Images and Alignment
		"Image aligned baseline: ",
		wordwrap.ImageContent{Image: redBox},
		" Text after.",
		"\n",
		"Image aligned Top: ",
		wordwrap.Group{
			Args: []interface{}{
				wordwrap.Alignment(wordwrap.AlignTop),
				wordwrap.ImageContent{Image: redBox},
			},
		},
		" (Text Top).",
		"\n",
		
		// Background Image Pattern
		wordwrap.Group{
			Args: []interface{}{
				wordwrap.BgImage(pattern),
				"Text on Pattern Background. ",
				fontLarge, "Even Large Text on Pattern.",
			},
		},
	}

	wrapper := wordwrap.NewRichWrapper(args...)
	// ... Layout and Render ...
	saveDocImage("richtext_comprehensive.png", img)
}

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, See the License for the specific language governing permissions and limitations under the License.

Container & Constraint System

The library now supports advanced value-based constraint systems allowing for powerful nested layouts found in modern web/UI frameworks.

Nested Containers

You can create Container groups that act as distinct layout units. These allow for:

  • Nested padding and margins.
  • Backgrounds that wrap specific blocks of content.
  • Grouping elements for alignment.
  • Applying constraints to entire blocks.
content := wordwrap.Container(
    wordwrap.Margin(fixed.R(0, 5, 0, 5)),
    wordwrap.FixedBackground(
        wordwrap.BgImage(pattern,
            wordwrap.BoxPadding(fixed.R(10, 10, 10, 10),
                wordwrap.Container(
                    wordwrap.Color(color.Black, "Text inside container"),
                ),
            ),
        ),
    ),
)

Minimum Size Constraints

You can enforce strict minimum sizes on containers or elements using MinSize or MinWidth. This is useful for creating buttons or layout blocks that must maintain a certain presence regardless of content size.

// Force a button container to be at least 450px wide
button := wordwrap.Container(
    wordwrap.MinWidth(450),
    wordwrap.BgColor(color.Yellow, "Wide Button"),
)

Alignment Helpers

The Align helper simplifies vertical alignment within a line or container (Top, Middle, Bottom, Baseline).

wordwrap.Align(wordwrap.AlignMiddle, myImage)

Documentation

Overview

Example (RichTextComprehensive)
// 1. Setup Resources
gr, err := util.OpenFont("goregular")
if err != nil {
	log.Fatal(err)
}
fontRegular := util.GetFontFace(24, 96, gr)
fontLarge := util.GetFontFace(40, 96, gr)

// Create a simple red box image for inline image demo
redBox := image.NewRGBA(image.Rect(0, 0, 30, 30))
draw.Draw(redBox, redBox.Bounds(), &image.Uniform{color.RGBA{255, 0, 0, 255}}, image.Point{}, draw.Src)

// Create a pebbles pattern for background demo using go-pattern
// Using Scatter for true overlapping geometry.
pat := pattern.NewScatter(
	pattern.SetBounds(image.Rect(-100000, -100000, 100000, 100000)),
	pattern.SetScatterFrequency(0.04), // Size control
	pattern.SetScatterDensity(1.0),    // Packed tight
	pattern.SetScatterMaxOverlap(1),
	pattern.SetSpaceColor(color.Transparent), // Transparent background!
	pattern.SetScatterGenerator(func(u, v float64, hash uint64) (color.Color, float64) {
		// Randomize size slightly
		rSize := float64(hash&0xFF) / 255.0
		radius := 12.0 + rSize*6.0 // 12 to 18 pixels radius

		// Perturb the shape using simple noise (simulated by sin/cos of hash+angle)
		// to make it "chipped" or irregular.
		angle := math.Atan2(v, u)
		dist := math.Sqrt(u*u + v*v)

		// Simple radial noise
		noise := math.Sin(angle*5+float64(hash%10)) * 0.1
		noise += math.Cos(angle*13+float64(hash%7)) * 0.05

		effectiveRadius := radius * (1.0 + noise)

		if dist > effectiveRadius {
			return color.Transparent, 0
		}

		// Stone Color: Lighter variations for readability
		grey := 220 + int(hash%35)
		col := color.RGBA{uint8(grey), uint8(grey), uint8(grey), 255}

		// Shading (diffuse)
		// Normal estimation for a flattened spheroid
		nx := u / effectiveRadius
		ny := v / effectiveRadius
		nz := math.Sqrt(math.Max(0, 1.0-nx*nx-ny*ny))

		// Light dir
		lx, ly, lz := -0.5, -0.5, 0.7
		lLen := math.Sqrt(lx*lx + ly*ly + lz*lz)
		lx, ly, lz = lx/lLen, ly/lLen, lz/lLen

		diffuse := math.Max(0, nx*lx+ny*ly+nz*lz)

		// Apply shading
		r := float64(col.R) * (0.1 + 0.9*diffuse)
		g := float64(col.G) * (0.1 + 0.9*diffuse)
		b := float64(col.B) * (0.1 + 0.9*diffuse)

		// Soft edge anti-aliasing
		alpha := 1.0
		edgeDist := effectiveRadius - dist
		if edgeDist < 1.0 {
			alpha = edgeDist
		}

		// Use hash for random Z-ordering
		z := float64(hash) / 18446744073709551615.0

		return color.RGBA{
			R: uint8(math.Min(255, r)),
			G: uint8(math.Min(255, g)),
			B: uint8(math.Min(255, b)),
			A: uint8(alpha * 255),
		}, z
	}),
)

// Create a paper-like pattern for the page background
paper := image.NewRGBA(image.Rect(0, 0, 100, 100))
draw.Draw(paper, paper.Bounds(), &image.Uniform{color.RGBA{250, 250, 245, 255}}, image.Point{}, draw.Src)
// Add some noise/lines to make it obvious
for y := 0; y < 100; y += 20 {
	draw.Draw(paper, image.Rect(0, y, 100, y+1), &image.Uniform{color.RGBA{220, 220, 210, 255}}, image.Point{}, draw.Over)
}

// 2. Build Rich Content
// We mix strings with option structs. The order matters (state machine).
args := []interface{}{
	fontRegular,
	"Standard text. ",

	// Text Color
	wordwrap.TextColor(color.RGBA{0, 0, 255, 255}),
	"Blue Text. ",
	wordwrap.TextColor(color.Black), // Reset

	// Background Color (Highlight)
	wordwrap.BgColor(color.RGBA{255, 255, 0, 255}),
	"Yellow Background. ",
	// Demonstrate Resetting Background to Transparent (should show paper pattern)
	wordwrap.BgColor(color.Transparent),
	"Back to Normal (should see paper). ",
	// Optional: We can adds a helper for this later if needed
	// wordwrap.NoBackground(),

	// Scoped Styles using Group
	wordwrap.Group{
		Args: []interface{}{
			wordwrap.TextColor(color.RGBA{0, 100, 0, 255}),
			"Scoped Green Text. ",
			wordwrap.BgColor(color.RGBA{220, 255, 220, 255}),
			"Green on Light Green. ",
		},
	},
	"Back to Normal. ",
	"\n\n",

	// Font Size Changes
	fontLarge, "Large Text. ",
	fontRegular, "Normal Text. ",
	"\n\n",

	// Effects: Underline, Strikethrough
	"Text with ",
	wordwrap.Group{
		Args: []interface{}{
			wordwrap.Underline(color.RGBA{255, 0, 0, 255}),
			"Red Underline",
		},
	},
	" and ",
	wordwrap.Group{
		Args: []interface{}{
			wordwrap.Strikethrough(color.Black),
			"Strikethrough",
		},
	},
	".\n\n",

	// Inline Images and Alignment
	"Image aligned baseline: ",
	wordwrap.ImageContent{Image: redBox},
	" Text after.",
	"\n",
	"Image aligned Top: ",
	wordwrap.Group{
		Args: []interface{}{
			wordwrap.Alignment(wordwrap.AlignTop),
			wordwrap.ImageContent{Image: redBox},
		},
	},
	" (Text Top).",
	"\n",
	"Image aligned Bottom: ",
	wordwrap.Group{
		Args: []interface{}{
			wordwrap.Alignment(wordwrap.AlignBottom),
			wordwrap.ImageContent{Image: redBox},
		},
	},
	" (Text Bottom).",
	"\n\n",

	// Background Image Pattern
	wordwrap.Group{
		Args: []interface{}{
			wordwrap.BgImage(pat, wordwrap.BgPositioningPassThrough),
			"Text on Pattern Background. ",
			fontLarge, "Even Large Text on Pattern.",
		},
	},
}

wrapper := wordwrap.NewRichWrapper(args...)

// 3. Layout with standard page constraints
result, err := wrapper.TextToSpecs(
	wordwrap.Width(wordwrap.Fixed(800)), // Wider width as requested
	wordwrap.Padding(20, color.Black),
	// We don't set PageBackground here to avoid it overriding our manual draw if we relied on internal logic,
	// but since we draw manually below, it's fine.
)
if err != nil {
	log.Fatal(err)
}

// 4. Render
img := image.NewRGBA(image.Rect(0, 0, result.PageSize.X, result.PageSize.Y))

// Draw Paper Pattern as background (Tiled)
for y := 0; y < img.Bounds().Dy(); y += paper.Bounds().Dy() {
	for x := 0; x < img.Bounds().Dx(); x += paper.Bounds().Dx() {
		r := image.Rect(x, y, x+paper.Bounds().Dx(), y+paper.Bounds().Dy())
		draw.Draw(img, r, paper, image.Point{}, draw.Src)
	}
}

if err := wrapper.RenderLines(img, result.Lines, result.ContentStart); err != nil {
	log.Fatal(err)
}

saveDocImage("richtext_comprehensive.png", img)
Output:

Generated doc/richtext_comprehensive.png

Index

Examples

Constants

View Source
const (
	RSimpleBox = iota
	RCRLF
	RNIL
)

Matches objects

Variables

View Source
var BoxBox = boxerOptionFunc(func(f interface{}) {
	bf := func(box Box) {
		switch box := box.(type) {
		case interface{ turnOnBox() }:
			box.turnOnBox()
		}
	}
	switch f := f.(type) {
	case *SimpleBoxer:
		f.postBoxOptions = append(f.postBoxOptions, bf)

	case Box:
		bf(f)
	}
})

BoxBox is a BoxerOption that tells the Box to draw a box around itself mostly for debugging purposes but will be the basis of how select and highlighting could work, such as the cursor

View Source
var BoxLine = folderOptionFunc(func(f interface{}) {
	if f, ok := f.(*SimpleFolder); ok {
		f.lineOptions = append(f.lineOptions, func(line Line) {
			switch line := line.(type) {
			case interface{ turnOnBox() }:
				line.turnOnBox()
			default:
				log.Printf("can't apply")
			}
		})
	}
})

BoxLine is a FolderOption that tells the Liner to draw a box around the line mostly for debugging purposes but will be the basis of how select and highlighting could work

View Source
var ImageBoxMetricAboveTheLine imageBoxOptionMetricCalcFunc = func(ib *ImageBox) font.Metrics {
	return font.Metrics{
		Height: fixed.I(ib.I.Bounds().Dy()),
		Ascent: fixed.I(ib.I.Bounds().Dy()),
	}
}

ImageBoxMetricAboveTheLine Puts the image above the baseline as you would expect if you were using a word processor

View Source
var ImageBoxMetricBelowTheLine imageBoxOptionMetricCalcFunc = func(ib *ImageBox) font.Metrics {
	return font.Metrics{
		Height:  fixed.I(ib.I.Bounds().Dy()),
		Ascent:  fixed.I(ib.I.Bounds().Dy()) / 2,
		Descent: fixed.I(ib.I.Bounds().Dy()) - fixed.I(ib.I.Bounds().Dy())/2,
	}
}

ImageBoxMetricBelowTheLine Puts the image above the baseline. Rarely done

View Source
var ImageBoxMetricCenter = func(fd *font.Drawer) imageBoxOptionMetricCalcFunc {
	return func(ib *ImageBox) font.Metrics {
		if fd == nil {
			fd = ib.fontDrawer
		}
		if fd == nil {
			return ImageBoxMetricBelowTheLine(ib)
		}
		m := fd.Face.Metrics()
		return font.Metrics{
			Height:  fixed.I(ib.I.Bounds().Dy()),
			Descent: fixed.I(ib.I.Bounds().Dy())/2 - m.Descent/2,
			Ascent:  fixed.I(ib.I.Bounds().Dy())/2 + m.Descent/2,
		}
	}
}

ImageBoxMetricCenter Puts the image running from the top down

View Source
var LatinTokenizer = SimpleBoxerGrab

LatinTokenizer is the default tokenizer for latin languages

Functions

func Align added in v0.0.4

func Align(a BaselineAlignment, args ...interface{}) interface{}

Align returns a Group with BaselineAlignmentOption applied

func BackgroundColor added in v0.0.4

func BackgroundColor(c color.Color, args ...interface{}) interface{}

BackgroundColor returns a Group with BackgroundColor applied, or the Option if no args

func BgColor added in v0.0.4

func BgColor(c color.Color, args ...interface{}) interface{}

BgColor returns a Group with BackgroundColor applied, or the Option if no args

func BgImage added in v0.0.4

func BgImage(i image.Image, args ...interface{}) interface{}

BgImage returns a Group with BackgroundImage applied, or the Option if no args

func BgPosition added in v0.0.4

func BgPosition(p BackgroundPositioning) interface{}

BgPosition returns a BackgroundPositioningOption

func Border added in v0.0.4

func Border(rect fixed.Rectangle26_6, args ...interface{}) interface{}

Border returns a BorderGroup with Border applied

func BoxPadding added in v0.0.4

func BoxPadding(rect fixed.Rectangle26_6, args ...interface{}) interface{}

BoxPadding returns a Group with Padding applied, or the Option if no args

func Color added in v0.0.4

func Color(c color.Color, args ...interface{}) interface{}

Color returns a Group with FontColor applied, or the Option if no args

func Container added in v0.0.4

func Container(args ...interface{}) interface{}

Container returns a ContainerGroup.

func DPI added in v0.0.4

func DPI(dpi float64) func(float64) int

DPI helper

func DrawBox

func DrawBox(i draw.Image, s image.Rectangle, dc *DrawConfig)

DrawBox literally draws a simple box

func FixedBackground added in v0.0.4

func FixedBackground(args ...interface{}) interface{}

FixedBackground returns a Group with FixedBackground applied, or the Option if no args

func Highlight added in v0.0.4

func Highlight(c color.Color, args ...interface{}) interface{}

Highlight returns a Group with BackgroundColor applied (Alias for BgColor)

func ID added in v0.0.4

func ID(id interface{}, args ...interface{}) interface{}

ID returns a Group with ID applied, or the Option if no args

func IsCR

func IsCR(r rune) bool

IsCR Is a carriage return

func IsLF

func IsLF(r rune) bool

IsLF is a line feed

func IsSpaceButNotCRLF

func IsSpaceButNotCRLF(r rune) bool

IsSpaceButNotCRLF Because spaces are different to CR and LF for word wrapping

func Margin added in v0.0.4

func Margin(rect fixed.Rectangle26_6, args ...interface{}) interface{}

Margin returns a Group with Margin applied, or the Option if no args

func MinWidth added in v0.0.4

func MinWidth(w int) interface{}

MinWidth returns a MinSizeOption

func Once

func Once(f func(r rune) bool) func(rune) bool

Once counts matches

func ProcessRichArgs added in v0.0.4

func ProcessRichArgs(args ...interface{}) ([]*Content, *font.Drawer, []WrapperOption, []BoxerOption, Boxer, Tokenizer)

ProcessRichArgs parses variadic arguments into standard components

func Px added in v0.0.4

func Px(v int) int

Pixels helper

func Reset added in v0.0.4

func Reset() interface{}

Reset returns a ResetOption to revert to plain style.

func SimpleBoxerGrab

func SimpleBoxerGrab(text []rune) (int, []rune, int)

SimpleBoxerGrab Consumer of characters until change. Could be made to conform to strings.Scanner

func SimpleWrapTextToImage

func SimpleWrapTextToImage(text string, i Image, grf font.Face, opts ...WrapperOption) error

SimpleWrapTextToImage all in one helper function to wrap text onto an image. Use image.Image's SubImage() to specify the exact location to render:

SimpleWrapTextToImage("text", i.SubImage(image.Rect(30,30,400,400)), font)

func SimpleWrapTextToRect

func SimpleWrapTextToRect(text string, r image.Rectangle, grf font.Face, opts ...WrapperOption) (*SimpleWrapper, []Line, image.Point, error)

SimpleWrapTextToRect calculates and returns the position of each box and the image.Point it would end.

func StarTokenizer added in v0.0.4

func StarTokenizer(text []rune) (int, []rune, int)

StarTokenizer is a demo tokenizer that splits on stars

func TextColor added in v0.0.4

func TextColor(c color.Color, args ...interface{}) interface{}

TextColor returns a Group with FontColor applied, or the Option if no args

func TextImage added in v0.0.4

func TextImage(i image.Image, args ...interface{}) interface{}

TextImage returns a Group with FontImage applied, or the Option if no args

func Tiled added in v0.0.4

func Tiled(img image.Image) image.Image

Tiled creates a TiledImage that tiles the source image

Types

type AlignedBox added in v0.0.4

type AlignedBox struct {
	Box
	Alignment BaselineAlignment
}

AlignedBox wraps a box with alignment information

func (*AlignedBox) DrawBox added in v0.0.4

func (ab *AlignedBox) DrawBox(i Image, y fixed.Int26_6, dc *DrawConfig)

func (*AlignedBox) MaxSize added in v0.0.4

func (b *AlignedBox) MaxSize() (fixed.Int26_6, fixed.Int26_6)

func (*AlignedBox) MinSize added in v0.0.4

func (b *AlignedBox) MinSize() (fixed.Int26_6, fixed.Int26_6)

type BackgroundBox added in v0.0.4

type BackgroundBox struct {
	Box
	Background    image.Image
	BgPositioning BackgroundPositioning
	// contains filtered or unexported fields
}

BackgroundBox is a box that has a background

func (*BackgroundBox) DrawBox added in v0.0.4

func (bb *BackgroundBox) DrawBox(i Image, y fixed.Int26_6, dc *DrawConfig)

func (*BackgroundBox) MaxSize added in v0.0.4

func (b *BackgroundBox) MaxSize() (fixed.Int26_6, fixed.Int26_6)

func (*BackgroundBox) MinSize added in v0.0.4

func (b *BackgroundBox) MinSize() (fixed.Int26_6, fixed.Int26_6)

type BackgroundImage added in v0.0.4

type BackgroundImage struct {
	image.Image
	Positioning *BackgroundPositioning
	Fixed       *bool
}

BackgroundImage defines the background

type BackgroundPositioning added in v0.0.4

type BackgroundPositioning int

BackgroundPositioning defines how the background is positioned

const (
	BgPositioningSection5Zeroed BackgroundPositioning = iota // Aligned to content (inner) box 0,0
	BgPositioningZeroed                                      // Aligned to box 0,0 (Frame)
	BgPositioningPassThrough                                 // Absolute Coordinates (matches dst)
)

type BackgroundPositioningOption added in v0.0.4

type BackgroundPositioningOption BackgroundPositioning

type BaselineAlignment added in v0.0.4

type BaselineAlignment int

BaselineAlignment defines how content is aligned relative to the baseline.

const (
	AlignBaseline BaselineAlignment = iota
	AlignTop
	AlignMiddle
	AlignBottom
)

type BaselineAlignmentOption added in v0.0.4

type BaselineAlignmentOption BaselineAlignment

BaselineAlignmentOption wraps a BaselineAlignment.

func Alignment added in v0.0.4

Alignment returns a BaselineAlignmentOption.

type BorderGroup added in v0.0.4

type BorderGroup Group

BorderGroup implies args apply to Border

type BorderOption added in v0.0.4

type BorderOption fixed.Rectangle26_6

type Box

type Box interface {
	// AdvanceRect returns the width of the content.
	AdvanceRect() fixed.Int26_6
	// MetricsRect returns the font metrics of the content.
	MetricsRect() font.Metrics
	// Whitespace returns true if the content is whitespace.
	Whitespace() bool
	// DrawBox renders the content into the given image at the specified Y offset.
	DrawBox(i Image, y fixed.Int26_6, dc *DrawConfig)
	// FontDrawer returns the font face used for this box.
	FontDrawer() *font.Drawer
	// Len returns the length of the content (e.g. rune count).
	Len() int
	// TextValue returns the text string content of the box.
	TextValue() string
	// MinSize returns the minimum required size for the box (width, height).
	MinSize() (fixed.Int26_6, fixed.Int26_6)
	// MaxSize returns the maximum allowed size for the box (width, height).
	MaxSize() (fixed.Int26_6, fixed.Int26_6)
}

Box represents a non-divisible unit of content (e.g., a word or image), which can be nested.

func NewSimpleTextBox

func NewSimpleTextBox(drawer *font.Drawer, t string) (Box, error)

NewSimpleTextBox constructor

type BoxDrawMap

type BoxDrawMap func(box Box, drawOps *DrawConfig, bps *BoxPositionStats) Box

BoxDrawMap allows the modification of boxes

func (BoxDrawMap) Apply

func (s BoxDrawMap) Apply(config *DrawConfig)

Apply installs the image source mapper

type BoxEffect added in v0.0.4

type BoxEffect struct {
	Func func(Image, Box, *DrawConfig)
	Type EffectType
}

BoxEffect defines a graphical effect applied to a box

func Strikethrough added in v0.0.4

func Strikethrough(c color.Color) BoxEffect

Strikethrough returns a Post effect

func Underline added in v0.0.4

func Underline(c color.Color) BoxEffect

Underline returns a Post effect

type BoxPositionStats

type BoxPositionStats struct {
	*LinePositionStats
	NumberInLine  int
	PageBoxOffset int
	WordOffset    int
}

BoxPositionStats Box position stats

type BoxRecorder added in v0.0.4

type BoxRecorder func(box Box, min, max image.Point, bps *BoxPositionStats)

BoxRecorder allows recording of the box's position

func (BoxRecorder) Apply added in v0.0.4

func (s BoxRecorder) Apply(config *DrawConfig)

Apply installs the image source mapper

type Boxer

type Boxer interface {
	// Next returns the next Box.
	Next() (Box, int, error)
	// SetFontDrawer sets the default font for the boxer.
	SetFontDrawer(face *font.Drawer)
	// FontDrawer returns the default font drawer.
	FontDrawer() *font.Drawer
	// Back unreads the last i atoms/boxes.
	Back(i int)
	// HasNext returns true if there is more content to process.
	HasNext() bool
	// Push returns boxes to the front of the queue (stack behavior).
	Push(box ...Box)
	// Pos returns the current cursor position in the input.
	Pos() int
	// Unshift adds boxes to the beginning of the internal buffer.
	Unshift(b ...Box)
	// Shift removes and returns the first Box from the internal buffer.
	Shift() Box
	// Reset restarts the tokenization
	Reset()
}

Boxer splits a line of text (or other content) into indivisible Box components.

type BoxerOption

type BoxerOption interface {
	// WrapperOption Allows you to pass the option to a Wrapper and assume it gets passed to the constructor of the
	// Boxer
	WrapperOption
	// ApplyBoxConfig applies the config.
	ApplyBoxConfig(interface{})
}

BoxerOption for folders

type ContainerGroup added in v0.0.4

type ContainerGroup struct {
	Options []interface{}
	Args    []interface{}
}

ContainerGroup represents a group rendered as a separate container box.

type Content added in v0.0.4

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

Content represents a piece of text or an image with associated styling.

func NewContainerContent added in v0.0.4

func NewContainerContent(children []*Content, opts ...ContentOption) *Content

NewContainerContent creates a new container Content object.

func NewContent added in v0.0.4

func NewContent(text string, opts ...ContentOption) *Content

NewContent creates a new Content object with the given text and options.

func NewImageContent added in v0.0.4

func NewImageContent(i image.Image, opts ...ContentOption) *Content

NewImageContent creates a new Content object with the given image and options.

func (*Content) ID added in v0.0.4

func (c *Content) ID() interface{}

ID returns the ID of the content

type ContentOption added in v0.0.4

type ContentOption func(*Content)

ContentOption is a function that can be used to configure a Content object.

func WithAlignment added in v0.0.4

func WithAlignment(a BaselineAlignment) ContentOption

WithAlignment sets the vertical alignment of a Content object.

func WithBackendImage added in v0.0.4

func WithBackendImage(i image.Image) ContentOption

WithBackendImage sets the background image of a Content object.

func WithBackgroundColor added in v0.0.4

func WithBackgroundColor(col color.Color) ContentOption

WithBackgroundColor sets the background color of a Content object.

func WithBoxEffects added in v0.0.4

func WithBoxEffects(e []BoxEffect) ContentOption

WithBoxEffects sets the effects

func WithDecorators added in v0.0.4

func WithDecorators(ds ...func(Box) Box) ContentOption

WithDecorators adds decorators to the content

func WithFixedBackground added in v0.0.4

func WithFixedBackground(fixed bool) ContentOption

WithFixedBackground sets whether the background is "fixed" (global coordinates)

func WithFont added in v0.0.4

func WithFont(font font.Face) ContentOption

WithFont sets the font of a Content object.

func WithFontColor added in v0.0.4

func WithFontColor(col color.Color) ContentOption

WithFontColor sets the font color of a Content object.

func WithFontImage added in v0.0.4

func WithFontImage(i image.Image) ContentOption

WithFontImage sets the font image of a Content object.

func WithID added in v0.0.4

func WithID(id interface{}) ContentOption

WithID sets the ID of a Content object.

func WithImageScale added in v0.0.4

func WithImageScale(s float64) ContentOption

WithImageScale sets the scale of an image Content object.

func WithMargin added in v0.0.4

func WithMargin(m fixed.Rectangle26_6) ContentOption

WithMargin sets the margin of a Content object.

func WithMinSize added in v0.0.4

func WithMinSize(size fixed.Point26_6) ContentOption

WithMinSize sets the minimum size of the content

func WithPadding added in v0.0.4

func WithPadding(p fixed.Rectangle26_6) ContentOption

WithPadding sets the padding of a Content object.

type DecorationBox added in v0.0.4

type DecorationBox struct {
	Box
	Padding       fixed.Rectangle26_6
	Margin        fixed.Rectangle26_6
	Background    image.Image
	BgPositioning BackgroundPositioning
}

DecorationBox is a box that adds padding and margin around another box

func NewDecorationBox added in v0.0.4

func NewDecorationBox(b Box, padding, margin fixed.Rectangle26_6, bg image.Image, bgPos BackgroundPositioning) *DecorationBox

NewDecorationBox constructor

func (*DecorationBox) DrawBox added in v0.0.4

func (db *DecorationBox) DrawBox(i Image, y fixed.Int26_6, dc *DrawConfig)

DrawBox renders the box with decorations.

func (*DecorationBox) MaxSize added in v0.0.4

func (db *DecorationBox) MaxSize() (fixed.Int26_6, fixed.Int26_6)

func (*DecorationBox) MinSize added in v0.0.4

func (db *DecorationBox) MinSize() (fixed.Int26_6, fixed.Int26_6)

type DrawConfig

type DrawConfig struct {
	SourceImageMapper SourceImageMapper
	BoxDrawMap        BoxDrawMap
	BoxRecorder       BoxRecorder
}

DrawConfig options for the drawer

func NewDrawConfig

func NewDrawConfig(options ...DrawOption) *DrawConfig

NewDrawConfig construct a draw config from DrawOptions

func (*DrawConfig) ApplyMap

func (c *DrawConfig) ApplyMap(b Box, bps *BoxPositionStats) Box

ApplyMap applies the box mapping function used for conditionally rendering or modifying the object being rendered

type DrawOption

type DrawOption interface {
	Apply(*DrawConfig)
}

DrawOption options applied and passed down the drawing functions

type EffectBox added in v0.0.4

type EffectBox struct {
	Box
	Effects []BoxEffect
	// contains filtered or unexported fields
}

EffectBox wraps a box with effects

func (*EffectBox) DrawBox added in v0.0.4

func (eb *EffectBox) DrawBox(i Image, y fixed.Int26_6, dc *DrawConfig)

func (*EffectBox) MaxSize added in v0.0.4

func (b *EffectBox) MaxSize() (fixed.Int26_6, fixed.Int26_6)

func (*EffectBox) MinSize added in v0.0.4

func (b *EffectBox) MinSize() (fixed.Int26_6, fixed.Int26_6)

type EffectType added in v0.0.4

type EffectType int

EffectType defines when the effect is applied

const (
	EffectPre EffectType = iota
	EffectPost
)

type FitterConfig

type FitterConfig struct {
	IgnoreY bool
}

type FitterIgnoreY

type FitterIgnoreY struct{}

func (FitterIgnoreY) Apply

func (fiy FitterIgnoreY) Apply(c *FitterConfig)

type FitterOption

type FitterOption interface {
	Apply(*FitterConfig)
}

type FixedBackgroundOption added in v0.0.4

type FixedBackgroundOption bool

type Folder

type Folder interface {
	// Next line
	Next(yspace int) (Line, error)
}

Folder is the literal line sizer & producer function

type FolderOption

type FolderOption interface {
	// WrapperOption Allows you to pass the option to a Wrapper and assume it gets passed to the constructor of the
	// Folder
	WrapperOption
	// ApplyFoldConfig applies the config.
	ApplyFoldConfig(interface{})
}

FolderOption for folders

type FontColor added in v0.0.4

type FontColor struct {
	color.Color
}

FontColor defines the text color

type FontDrawer

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

FontDrawer a wrapper around *font.Draw used to set the font

func NewFontDrawer

func NewFontDrawer(d *font.Drawer) *FontDrawer

NewFontDrawer a wrapper around *font.Draw used to set the font mostly for image

type FontImage added in v0.0.4

type FontImage struct {
	image.Image
}

FontImage represents an image used as a text fill pattern.

type Group added in v0.0.4

type Group struct {
	Args []interface{}
}

Group collects arguments to be processed together.

type HeightOption added in v0.0.4

type HeightOption SizeFunction

HeightOption configures the height constraint

func Height added in v0.0.4

func Height(f SizeFunction) HeightOption

Height sets the height constraint

func (HeightOption) ApplySpec added in v0.0.4

func (f HeightOption) ApplySpec(c *SpecConfig)

type HorizontalBlockPosition

type HorizontalBlockPosition int

HorizontalBlockPosition information about how to position the entire block of text rather than just the line horizontally

const (
	// LeftBLock positions the entire block of text left rather than just the line horizontally (default)
	LeftBLock HorizontalBlockPosition = iota
	// HorizontalCenterBlock positions the entire block of text center rather than just the line horizontally
	HorizontalCenterBlock
	// RightBlock positions the entire block of text right rather than just the line horizontally
	RightBlock
)

func (HorizontalBlockPosition) ApplyWrapperConfig

func (hp HorizontalBlockPosition) ApplyWrapperConfig(wr interface{})

ApplyWrapperConfig Stores the position against the wrapper object

type HorizontalLinePosition

type HorizontalLinePosition int

HorizontalLinePosition is the type for per-line level alignment.

const (
	// LeftLines default, produces lines that are individually left justified.
	LeftLines HorizontalLinePosition = iota
	// HorizontalCenterLines produces lines that are individually center justified.
	HorizontalCenterLines
	// RightLines produces lines that are individually right justified.
	RightLines
)

func (HorizontalLinePosition) ApplyFoldConfig

func (hp HorizontalLinePosition) ApplyFoldConfig(f interface{})

ApplyFoldConfig applies the configuration to the wrapper where it will be stored in the line.

func (HorizontalLinePosition) ApplyWrapperConfig

func (hp HorizontalLinePosition) ApplyWrapperConfig(wr interface{})

ApplyWrapperConfig Is required to pass the configuration through to the appropriate level -- Hopefully will be refactored

type HorizontalLinePositioner

type HorizontalLinePositioner interface {
	// contains filtered or unexported methods
}

HorizontalLinePositioner is a simple interface denoting a getter

type IDBox added in v0.0.4

type IDBox struct {
	Box
	// contains filtered or unexported fields
}

IDBox wrapper for box with ID

func (*IDBox) DrawBox added in v0.0.4

func (ib *IDBox) DrawBox(i Image, y fixed.Int26_6, dc *DrawConfig)

func (*IDBox) ID added in v0.0.4

func (ib *IDBox) ID() interface{}

ID returns the ID

func (*IDBox) MaxSize added in v0.0.4

func (b *IDBox) MaxSize() (fixed.Int26_6, fixed.Int26_6)

func (*IDBox) MinSize added in v0.0.4

func (b *IDBox) MinSize() (fixed.Int26_6, fixed.Int26_6)

type IDOption added in v0.0.4

type IDOption struct{ ID interface{} }

type Identifier added in v0.0.4

type Identifier interface {
	ID() interface{}
}

Identifier is a interface for reporting IDs

type Image

type Image interface {
	draw.Image
	SubImage(image.Rectangle) image.Image
}

Image because image.Image / draw.Image should really have SubImage as part of it.

type ImageBox

type ImageBox struct {
	I     image.Image
	Scale float64
	M     font.Metrics
	// contains filtered or unexported fields
}

ImageBox is a box that contains an image

func NewImageBox

func NewImageBox(i image.Image, options ...ImageBoxOption) *ImageBox

NewImageBox constructs a new ImageBox

func (*ImageBox) AdvanceRect

func (ib *ImageBox) AdvanceRect() fixed.Int26_6

AdvanceRect width of text

func (*ImageBox) CalculateMetrics

func (ib *ImageBox) CalculateMetrics()

CalculateMetrics calculate dimension and positioning

func (*ImageBox) DrawBox

func (ib *ImageBox) DrawBox(i Image, y fixed.Int26_6, dc *DrawConfig)

DrawBox renders object

func (*ImageBox) FontDrawer

func (ib *ImageBox) FontDrawer() *font.Drawer

FontDrawer font used

func (*ImageBox) Len

func (ib *ImageBox) Len() int

func (*ImageBox) MaxSize added in v0.0.4

func (ib *ImageBox) MaxSize() (fixed.Int26_6, fixed.Int26_6)

func (*ImageBox) MetricsRect

func (ib *ImageBox) MetricsRect() font.Metrics

MetricsRect all other font details of text

func (*ImageBox) MinSize added in v0.0.4

func (ib *ImageBox) MinSize() (fixed.Int26_6, fixed.Int26_6)

func (*ImageBox) TextValue

func (ib *ImageBox) TextValue() string

TextValue returns the text suppressed by the line break (probably a white space including a \r\n)

func (*ImageBox) Whitespace

func (ib *ImageBox) Whitespace() bool

Whitespace if this is a white space or not

type ImageBoxOption

type ImageBoxOption interface {
	// contains filtered or unexported methods
}

ImageBoxOption modifiers for the ImageBox

type ImageContent added in v0.0.4

type ImageContent struct {
	Image image.Image
	Scale float64 // 0 or 1 = original size
}

ImageContent represents an inline image.

type LayoutResult added in v0.0.4

type LayoutResult struct {
	Lines          []Line
	PageSize       image.Point
	ContentStart   image.Point
	Margin         SpecMargin
	PageBackground color.Color
}

LayoutResult holds the result of the text layout

type Line

type Line interface {
	// Size the line consumes
	Size() image.Rectangle
	// DrawLine draws the line
	DrawLine(i Image, options ...DrawOption) error
	// Boxes are the lines contents
	Boxes() []Box
	// TextValue extracts the text value
	TextValue() string
	// YValue where the baseline is
	YValue() int
	// PopSpaceFor will push box at the end, if there isn't enough width, it will make width space.
	PopSpaceFor(sf *SimpleFolder, r image.Rectangle, box Box) (int, error)
	// contains filtered or unexported methods
}

Line refers to a literal line of text

type LineBreakBox

type LineBreakBox struct {
	// Box is the box that linebreak contains if any
	Box
}

LineBreakBox represents a natural or an effective line break

func (*LineBreakBox) AdvanceRect

func (sb *LineBreakBox) AdvanceRect() fixed.Int26_6

func (*LineBreakBox) MaxSize added in v0.0.4

func (sb *LineBreakBox) MaxSize() (fixed.Int26_6, fixed.Int26_6)

func (*LineBreakBox) MinSize added in v0.0.4

func (sb *LineBreakBox) MinSize() (fixed.Int26_6, fixed.Int26_6)

type LinePositionStats

type LinePositionStats struct {
	LineNumber    int
	PageBoxOffset int
	WordOffset    int
	PageNumber    int
}

LinePositionStats numbers to use for pin pointing location

func (*LinePositionStats) BoxPositionStats

func (lps *LinePositionStats) BoxPositionStats(numberInLine int) *BoxPositionStats

BoxPositionStats generates object of same name

type MarginOption added in v0.0.4

type MarginOption fixed.Rectangle26_6

type MinSizeBox added in v0.0.4

type MinSizeBox struct {
	Box
	MinSizeVal fixed.Point26_6
}

MinSizeBox ensures the box has a minimum size

func (*MinSizeBox) AdvanceRect added in v0.0.4

func (msb *MinSizeBox) AdvanceRect() fixed.Int26_6

func (*MinSizeBox) DrawBox added in v0.0.4

func (msb *MinSizeBox) DrawBox(i Image, y fixed.Int26_6, dc *DrawConfig)

func (*MinSizeBox) MaxSize added in v0.0.4

func (msb *MinSizeBox) MaxSize() (fixed.Int26_6, fixed.Int26_6)

func (*MinSizeBox) MetricsRect added in v0.0.4

func (msb *MinSizeBox) MetricsRect() font.Metrics

func (*MinSizeBox) MinSize added in v0.0.4

func (msb *MinSizeBox) MinSize() (fixed.Int26_6, fixed.Int26_6)

type MinSizeOption added in v0.0.4

type MinSizeOption fixed.Point26_6

type OverflowMode

type OverflowMode int

OverflowMode Ways of describing overflow

const (
	// StrictBorders default overflow mode. Do not allow
	StrictBorders OverflowMode = iota
	// DescentOverflow Allow some decent overflow. Characters such as yjqp will overflow
	DescentOverflow
	// FullOverflowDuplicate Will allow the full line to overflow, and duplicate line next run
	FullOverflowDuplicate
)

type PaddingOption added in v0.0.4

type PaddingOption fixed.Rectangle26_6

type PageBackgroundOption added in v0.0.4

type PageBackgroundOption struct {
	Color color.Color
}

PageBackgroundOption sets the page background color

func PageBackground added in v0.0.4

func PageBackground(c color.Color) PageBackgroundOption

func (PageBackgroundOption) ApplySpec added in v0.0.4

func (o PageBackgroundOption) ApplySpec(c *SpecConfig)

type PageBreakBox

type PageBreakBox struct {
	// VisualBox is the box to render and use
	VisualBox Box
	// ContainerBox is the box that linebreak contains if any
	ContainerBox Box
}

PageBreakBox represents a natural or an effective page break

func NewPageBreak

func NewPageBreak(pbb Box) *PageBreakBox

NewPageBreak basic constructor for a page break.

func (*PageBreakBox) AdvanceRect

func (p *PageBreakBox) AdvanceRect() fixed.Int26_6

AdvanceRect width of text

func (*PageBreakBox) DrawBox

func (p *PageBreakBox) DrawBox(i Image, y fixed.Int26_6, dc *DrawConfig)

DrawBox renders object

func (*PageBreakBox) FontDrawer

func (p *PageBreakBox) FontDrawer() *font.Drawer

FontDrawer font used

func (*PageBreakBox) Len

func (p *PageBreakBox) Len() int

Len the length of the buffer represented by the box

func (*PageBreakBox) MaxSize added in v0.0.4

func (p *PageBreakBox) MaxSize() (fixed.Int26_6, fixed.Int26_6)

func (*PageBreakBox) MetricsRect

func (p *PageBreakBox) MetricsRect() font.Metrics

MetricsRect all other font details of text

func (*PageBreakBox) MinSize added in v0.0.4

func (p *PageBreakBox) MinSize() (fixed.Int26_6, fixed.Int26_6)

func (*PageBreakBox) TextValue

func (p *PageBreakBox) TextValue() string

TextValue returns the text suppressed by the line break (probably a white space including a \r\n)

func (*PageBreakBox) Whitespace

func (p *PageBreakBox) Whitespace() bool

Whitespace if contains a white space or not

type PageMarginOption added in v0.0.4

type PageMarginOption struct {
	Margin int
	Color  color.Color
}

PageMargin sets the margin option

func Padding added in v0.0.4

func Padding(margin int, c color.Color) PageMarginOption

Padding sets the margin option (Alias for PageMargin)

func (PageMarginOption) ApplySpec added in v0.0.4

func (o PageMarginOption) ApplySpec(c *SpecConfig)

type ResetOption added in v0.0.4

type ResetOption struct{}

type RichBoxer added in v0.0.4

type RichBoxer = SimpleBoxer

RichBoxer alias for backward compatibility

type RowBox added in v0.0.4

type RowBox struct {
	Boxes []Box
}

RowBox holds multiple boxes on a single line

func (*RowBox) AdvanceRect added in v0.0.4

func (rb *RowBox) AdvanceRect() fixed.Int26_6

func (*RowBox) DrawBox added in v0.0.4

func (rb *RowBox) DrawBox(i Image, y fixed.Int26_6, dc *DrawConfig)

func (*RowBox) FontDrawer added in v0.0.4

func (rb *RowBox) FontDrawer() *font.Drawer

func (*RowBox) Len added in v0.0.4

func (rb *RowBox) Len() int

func (*RowBox) MaxSize added in v0.0.4

func (rb *RowBox) MaxSize() (fixed.Int26_6, fixed.Int26_6)

func (*RowBox) MetricsRect added in v0.0.4

func (rb *RowBox) MetricsRect() font.Metrics

func (*RowBox) MinSize added in v0.0.4

func (rb *RowBox) MinSize() (fixed.Int26_6, fixed.Int26_6)

func (*RowBox) TextValue added in v0.0.4

func (rb *RowBox) TextValue() string

func (*RowBox) Whitespace added in v0.0.4

func (rb *RowBox) Whitespace() bool

type SimpleBoxer

type SimpleBoxer struct {
	Tokenizer Tokenizer
	// contains filtered or unexported fields
}

SimpleBoxer simple tokenizer basically determines if something unicode.IsSpace or is a new line, or is text and tells the calling Folder that. Putting the elements in the correct Box. SimpleBoxer simple tokenizer basically determines if something unicode.IsSpace or is a new line, or is text and tells the calling Folder that. Putting the elements in the correct Box.

func NewRichBoxer added in v0.0.4

func NewRichBoxer(args ...interface{}) *SimpleBoxer

NewRichBoxer creates a new boxer using a variety of arguments to create the contents and options

func NewSimpleBoxer

func NewSimpleBoxer(contents []*Content, drawer *font.Drawer, options ...BoxerOption) *SimpleBoxer

NewSimpleBoxer simple tokenizer basically determines if something unicode.IsSpace or is a new line, or is text and tells the calling Folder that. Putting the elements in the correct Box.

func (*SimpleBoxer) Back

func (sb *SimpleBoxer) Back(i int)

Back goes back i spaces (ie unreads)

func (*SimpleBoxer) FontDrawer

func (sb *SimpleBoxer) FontDrawer() *font.Drawer

FontDrawer encapsulates default fonts and more

func (*SimpleBoxer) HasNext

func (sb *SimpleBoxer) HasNext() bool

HasNext unprocessed bytes exist

func (*SimpleBoxer) Next

func (sb *SimpleBoxer) Next() (Box, int, error)

Next gets the next word in a Box

func (*SimpleBoxer) Pos

func (sb *SimpleBoxer) Pos() int

Pos current parser position.

func (*SimpleBoxer) Push

func (sb *SimpleBoxer) Push(box ...Box)

Push puts a box back on to the cache stack

func (*SimpleBoxer) Reset added in v0.0.4

func (sb *SimpleBoxer) Reset()

Reset restarts the tokenization

func (*SimpleBoxer) SetFontDrawer

func (sb *SimpleBoxer) SetFontDrawer(face *font.Drawer)

SetFontDrawer Changes the default font

func (*SimpleBoxer) Shift

func (sb *SimpleBoxer) Shift() Box

func (*SimpleBoxer) Unshift

func (sb *SimpleBoxer) Unshift(box ...Box)

Unshift basically is Push but to the start

type SimpleFolder

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

SimpleFolder is a simple Folder

func NewSimpleFolder

func NewSimpleFolder(boxer Boxer, container image.Rectangle, lastFontDrawer *font.Drawer, options ...FolderOption) *SimpleFolder

NewSimpleFolder constructs a SimpleFolder applies options provided.

func (*SimpleFolder) NewLine

func (sf *SimpleFolder) NewLine() *SimpleLine

NewLine constructs a new simple line. (Later to be a factory proxy)

func (*SimpleFolder) Next

func (sf *SimpleFolder) Next(yspace int) (Line, error)

Next generates the next life if space

type SimpleLine

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

SimpleLine is a simple implementation to prevent name space names later. Represents a line

func (*SimpleLine) Boxes

func (l *SimpleLine) Boxes() []Box

Boxes are the lines contents

func (*SimpleLine) DrawLine

func (l *SimpleLine) DrawLine(i Image, options ...DrawOption) error

DrawLine renders image to image, you can control the location by using the SubImage function.

func (*SimpleLine) Pop

func (l *SimpleLine) Pop() Box

Pop a box off of the end of a line. Ignores all height components that will require a recalculation, drops PageBreak

func (*SimpleLine) PopSpaceFor

func (l *SimpleLine) PopSpaceFor(sf *SimpleFolder, r image.Rectangle, box Box) (int, error)

PopSpaceFor will push box at the end, if there isn't enough width, it will make width space.

func (*SimpleLine) Push

func (l *SimpleLine) Push(b Box, a fixed.Int26_6)

Push a box onto the end, and also copy values in appropriately

func (*SimpleLine) Size

func (l *SimpleLine) Size() image.Rectangle

Size is the size consumed of the line

func (*SimpleLine) TextValue

func (l *SimpleLine) TextValue() string

TextValue extracts the text value of the line

func (*SimpleLine) YValue

func (l *SimpleLine) YValue() int

YValue where the baseline is

type SimpleTextBox

type SimpleTextBox struct {
	Contents string
	Bounds   fixed.Rectangle26_6

	Advance fixed.Int26_6
	Metrics font.Metrics
	// contains filtered or unexported fields
}

SimpleTextBox represents an indivisible series of characters.

func (*SimpleTextBox) AdvanceRect

func (sb *SimpleTextBox) AdvanceRect() fixed.Int26_6

AdvanceRect width of text

func (*SimpleTextBox) DrawBox

func (sb *SimpleTextBox) DrawBox(i Image, y fixed.Int26_6, dc *DrawConfig)

DrawBox renders object

func (*SimpleTextBox) FontDrawer

func (sb *SimpleTextBox) FontDrawer() *font.Drawer

FontDrawer font used

func (*SimpleTextBox) Len

func (sb *SimpleTextBox) Len() int

Len is the string length of the contents of the box

func (*SimpleTextBox) MaxSize added in v0.0.4

func (sb *SimpleTextBox) MaxSize() (fixed.Int26_6, fixed.Int26_6)

func (*SimpleTextBox) MetricsRect

func (sb *SimpleTextBox) MetricsRect() font.Metrics

MetricsRect all other font details of text

func (*SimpleTextBox) MinSize added in v0.0.4

func (sb *SimpleTextBox) MinSize() (fixed.Int26_6, fixed.Int26_6)

func (*SimpleTextBox) TextValue

func (sb *SimpleTextBox) TextValue() string

TextValue stored value of the box

func (*SimpleTextBox) Whitespace

func (sb *SimpleTextBox) Whitespace() bool

Whitespace if this is a white space or not

type SimpleWrapper

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

SimpleWrapper provides basic text wrapping functionality.

func NewRichWrapper added in v0.0.4

func NewRichWrapper(args ...interface{}) *SimpleWrapper

NewRichWrapper creates a new wrapper. valid args are font.Face, string, and WrapperOption

func NewSimpleWrapper

func NewSimpleWrapper(contents []*Content, grf font.Face, opts ...WrapperOption) *SimpleWrapper

NewSimpleWrapper creates a new wrapper. This function retains previous text position, useful for creating "pages." assumes black text

func (*SimpleWrapper) ApplyOptions

func (sw *SimpleWrapper) ApplyOptions(opts ...WrapperOption)

ApplyOptions allows the application of options to the SimpleWrapper (Such as new fonts, or turning on / off boxes.

func (*SimpleWrapper) HasNext

func (sw *SimpleWrapper) HasNext() bool

HasNext are there any unprocessed bytes in the boxer

func (*SimpleWrapper) RenderLines

func (sw *SimpleWrapper) RenderLines(i Image, ls []Line, at image.Point, options ...DrawOption) error

RenderLines draws the boxes for the given lines. on the image, starting at the specified point ignoring the original boundaries but maintaining the wrapping. Also applies alignment options.

func (*SimpleWrapper) TextToRect

func (sw *SimpleWrapper) TextToRect(r image.Rectangle, ops ...FitterOption) ([]Line, image.Point, error)

TextToRect calculates and returns the position of each box and the image.Point it would end.

func (*SimpleWrapper) TextToSpecs added in v0.0.4

func (sw *SimpleWrapper) TextToSpecs(opts ...SpecOption) (*LayoutResult, error)

TextToSpecs performs layout based on complex constraints. It returns the layout result containing lines, page size, and offsets.

Example (A4)
package main

import (
	"fmt"
	"image"
	"image/color"
	"image/draw"
	"image/png"
	"log"
	"os"

	wordwrap "github.com/arran4/golang-wordwrap"
	"github.com/arran4/golang-wordwrap/util"
)

// Helper to save image for documentation
func saveDocImage(name string, img image.Image) {
	f, err := os.Create("doc/" + name)
	if err != nil {
		log.Fatal(err)
	}
	defer func() {
		if err := f.Close(); err != nil {
			log.Fatal(err)
		}
	}()
	if err := png.Encode(f, img); err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Generated doc/%s\n", name)
}

func main() {
	gr, err := util.OpenFont("goregular")
	if err != nil {
		log.Fatal(err)
	}
	font := util.GetFontFace(24, 96, gr)

	text := "This is an example of an A4 document layout. It uses a fixed A4 width and standard padding."

	wrapper := wordwrap.NewRichWrapper(
		font,
		text,
	)

	// Layout Specs: A4 Width (96 DPI), 20px Padding, White Background
	result, err := wrapper.TextToSpecs(
		wordwrap.Width(wordwrap.A4Width(96)),
		wordwrap.Padding(20, color.Black),
		wordwrap.PageBackground(color.White),
	)
	if err != nil {
		log.Fatal(err)
	}

	img := image.NewRGBA(image.Rect(0, 0, result.PageSize.X, result.PageSize.Y))

	// Draw Background
	if result.PageBackground != nil {
		draw.Draw(img, img.Bounds(), &image.Uniform{result.PageBackground}, image.Point{}, draw.Src)
	}

	if err := wrapper.RenderLines(img, result.Lines, result.ContentStart); err != nil {
		log.Fatal(err)
	}

	saveDocImage("a4_example.png", img)

}
Output:

Generated doc/a4_example.png
Example (A4_full)
package main

import (
	"fmt"
	"image"
	"image/color"
	"image/draw"
	"image/png"
	"log"
	"os"

	wordwrap "github.com/arran4/golang-wordwrap"
	"github.com/arran4/golang-wordwrap/util"
)

// Helper to save image for documentation
func saveDocImage(name string, img image.Image) {
	f, err := os.Create("doc/" + name)
	if err != nil {
		log.Fatal(err)
	}
	defer func() {
		if err := f.Close(); err != nil {
			log.Fatal(err)
		}
	}()
	if err := png.Encode(f, img); err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Generated doc/%s\n", name)
}

func main() {
	gr, err := util.OpenFont("goregular")
	if err != nil {
		log.Fatal(err)
	}
	font := util.GetFontFace(24, 96, gr)

	text := "This is an example of a full A4 document layout. It uses a fixed A4 width and height."

	wrapper := wordwrap.NewRichWrapper(
		font,
		text,
	)

	// Layout Specs: A4 Width & Height (96 DPI), 20px Padding, White Background
	result, err := wrapper.TextToSpecs(
		wordwrap.Width(wordwrap.A4Width(96)),
		wordwrap.Height(wordwrap.A4Height(96)),
		wordwrap.Padding(20, color.Black),
		wordwrap.PageBackground(color.White),
	)
	if err != nil {
		log.Fatal(err)
	}

	img := image.NewRGBA(image.Rect(0, 0, result.PageSize.X, result.PageSize.Y))

	// Draw Background
	if result.PageBackground != nil {
		draw.Draw(img, img.Bounds(), &image.Uniform{result.PageBackground}, image.Point{}, draw.Src)
	}

	if err := wrapper.RenderLines(img, result.Lines, result.ContentStart); err != nil {
		log.Fatal(err)
	}

	saveDocImage("a4_full_example.png", img)

}
Output:

Generated doc/a4_full_example.png
Example (Flexible)
package main

import (
	"fmt"
	"image"
	"image/color"
	"image/draw"
	"image/png"
	"log"
	"os"

	wordwrap "github.com/arran4/golang-wordwrap"
	"github.com/arran4/golang-wordwrap/util"
)

// Helper to save image for documentation
func saveDocImage(name string, img image.Image) {
	f, err := os.Create("doc/" + name)
	if err != nil {
		log.Fatal(err)
	}
	defer func() {
		if err := f.Close(); err != nil {
			log.Fatal(err)
		}
	}()
	if err := png.Encode(f, img); err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Generated doc/%s\n", name)
}

func main() {
	// Layout using a flexible width constraint: at most A4 width, but shrinking to content (Natural) width if smaller.

	gr, err := util.OpenFont("goregular")
	if err != nil {
		log.Fatal(err)
	}
	font := util.GetFontFace(24, 96, gr)

	// Long text to demonstrate wrapping
	wrapper := wordwrap.NewRichWrapper(
		font,
		"This text will wrap at A4 width because of the constraint logic.",
	)

	result, err := wrapper.TextToSpecs(
		wordwrap.Width(wordwrap.Min(wordwrap.A4Width(96), wordwrap.Unbounded())),
		wordwrap.PageBackground(color.White),
	)
	if err != nil {
		log.Fatal(err)
	}

	img := image.NewRGBA(image.Rect(0, 0, result.PageSize.X, result.PageSize.Y))
	if result.PageBackground != nil {
		draw.Draw(img, img.Bounds(), &image.Uniform{result.PageBackground}, image.Point{}, draw.Src)
	}
	if err := wrapper.RenderLines(img, result.Lines, result.ContentStart); err != nil {
		log.Fatal(err)
	}

	saveDocImage("flexible_example.png", img)

}
Output:

Generated doc/flexible_example.png
Example (Simple)
package main

import (
	"fmt"
	"image"
	"image/png"
	"log"
	"os"

	wordwrap "github.com/arran4/golang-wordwrap"
	"github.com/arran4/golang-wordwrap/util"
)

// Helper to save image for documentation
func saveDocImage(name string, img image.Image) {
	f, err := os.Create("doc/" + name)
	if err != nil {
		log.Fatal(err)
	}
	defer func() {
		if err := f.Close(); err != nil {
			log.Fatal(err)
		}
	}()
	if err := png.Encode(f, img); err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Generated doc/%s\n", name)
}

func main() {
	// Open Font
	gr, err := util.OpenFont("goregular")
	if err != nil {
		log.Fatal(err)
	}
	font := util.GetFontFace(24, 96, gr)

	// Standard Wrapper Args
	args := []interface{}{
		font,
		"Simple Text wrapping example.",
	}

	// Create Wrapper
	wrapper := wordwrap.NewRichWrapper(args...)

	// Layout with Constraint: Fixed Width 200px
	result, err := wrapper.TextToSpecs(wordwrap.Width(wordwrap.Fixed(200)))
	if err != nil {
		log.Fatal(err)
	}

	// Render
	img := image.NewRGBA(image.Rect(0, 0, result.PageSize.X, result.PageSize.Y))
	if err := wrapper.RenderLines(img, result.Lines, result.ContentStart); err != nil {
		log.Fatal(err)
	}

	saveDocImage("simple_example.png", img)

}
Output:

Generated doc/simple_example.png

type SizeFunction added in v0.0.4

type SizeFunction func(contentSize int) int

SizeFunction determines a size based on the measured content size

func A4Height added in v0.0.4

func A4Height(dpi float64) SizeFunction

A4Height helper

func A4Width added in v0.0.4

func A4Width(dpi float64) SizeFunction

A4Width helper

func Auto added in v0.0.4

func Auto() SizeFunction

Auto returns the content size (identity). Same as Unbounded in this context.

func Fixed added in v0.0.4

func Fixed(n int) SizeFunction

Fixed returns a fixed size.

func Max added in v0.0.4

func Max(a, b SizeFunction) SizeFunction

Max returns the maximum of two size functions.

func Min added in v0.0.4

func Min(a, b SizeFunction) SizeFunction

Min returns the minimum of two size functions.

func Unbounded added in v0.0.4

func Unbounded() SizeFunction

Unbounded returns the content size.

type SourceImageMapper

type SourceImageMapper func(image.Image) image.Image

SourceImageMapper allows passing in of an option that will map the original input in some way

func (SourceImageMapper) Apply

func (s SourceImageMapper) Apply(config *DrawConfig)

Apply installs the image source mapper

type SpecConfig added in v0.0.4

type SpecConfig struct {
	WidthFn        SizeFunction
	HeightFn       SizeFunction
	Margin         SpecMargin
	PageBackground color.Color
}

SpecConfig holds configuration for TextToSpecs

type SpecMargin added in v0.0.4

type SpecMargin struct {
	Top, Right, Bottom, Left int
	Color                    color.Color
}

type SpecOption added in v0.0.4

type SpecOption interface {
	ApplySpec(config *SpecConfig)
}

SpecOption configures the TextToSpecs layout

type Style added in v0.0.4

type Style struct {
	FontDrawerSrc   image.Image
	BackgroundColor image.Image // can be used for colour or image
	Padding         fixed.Rectangle26_6
	Margin          fixed.Rectangle26_6

	Alignment       BaselineAlignment
	Effects         []BoxEffect
	FixedBackground bool
	BgPositioning   BackgroundPositioning
	Border          fixed.Rectangle26_6
	BorderImage     image.Image
	Decorators      []func(Box) Box
	MinSize         fixed.Point26_6
	// contains filtered or unexported fields
}

Style defines the visual properties of content.

func NewStyle added in v0.0.4

func NewStyle() *Style

NewStyle creates a new style

type TiledImage added in v0.0.4

type TiledImage struct {
	Src image.Image
}

TiledImage implements infinite tiling of a source image

func (*TiledImage) At added in v0.0.4

func (t *TiledImage) At(x, y int) color.Color

func (*TiledImage) Bounds added in v0.0.4

func (t *TiledImage) Bounds() image.Rectangle

func (*TiledImage) ColorModel added in v0.0.4

func (t *TiledImage) ColorModel() color.Model

type Tokenizer added in v0.0.4

type Tokenizer func(text []rune) (int, []rune, int)

Tokenizer is a function that tokenizes the text

type VerticalBlockPosition

type VerticalBlockPosition int

VerticalBlockPosition information about how to position the entire block of text rather than just the line vertically

const (
	// TopBLock positions the entire block of text top
	TopBLock VerticalBlockPosition = iota
	// VerticalCenterBlock positions the entire block of text center
	VerticalCenterBlock
	// BottomBlock positions the entire block of text bottom
	BottomBlock
)

func (VerticalBlockPosition) ApplyWrapperConfig

func (hp VerticalBlockPosition) ApplyWrapperConfig(wr interface{})

ApplyWrapperConfig Stores the position against the wrapper object

type WidthOption added in v0.0.4

type WidthOption SizeFunction

WidthOption configures the width constraint

func Width added in v0.0.4

func Width(f SizeFunction) WidthOption

Width sets the width constraint

func (WidthOption) ApplySpec added in v0.0.4

func (f WidthOption) ApplySpec(c *SpecConfig)

type WrapperOption

type WrapperOption interface {
	// ApplyWrapperConfig applies the config.
	ApplyWrapperConfig(interface{})
}

WrapperOption for folders

func NewPageBreakBox

func NewPageBreakBox(b Box, opts ...BoxerOption) WrapperOption

NewPageBreakBox is a FolderOption that tells the Liner to add a chevron image to the end of every text block that continues past the given rect.

func YOverflow

func YOverflow(i OverflowMode) WrapperOption

YOverflow is a FolderOption that sets the type over overflow mode we will allow

Directories

Path Synopsis
cmd
dogoal command
generatesample command
pagelimits command
richwraptoimage command
texttoimage command

Jump to

Keyboard shortcuts

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