Documentation
¶
Index ¶
- Constants
- Variables
- func DrawBox(i draw.Image, s image.Rectangle, dc *DrawConfig)
- func IsCR(r rune) bool
- func IsLF(r rune) bool
- func IsSpaceButNotCRLF(r rune) bool
- func Once(f func(r rune) bool) func(rune) bool
- func SimpleBoxerGrab(text []rune) (int, []rune, int)
- func SimpleWrapTextToImage(text string, i Image, grf font.Face, opts ...WrapperOption) error
- func SimpleWrapTextToRect(text string, r image.Rectangle, grf font.Face, opts ...WrapperOption) (*SimpleWrapper, []Line, image.Point, error)
- type Box
- type BoxDrawMap
- type BoxPositionStats
- type Boxer
- type BoxerOption
- type DrawConfig
- type DrawOption
- type FitterConfig
- type FitterIgnoreY
- type FitterOption
- type Folder
- type FolderOption
- type FontDrawer
- type HorizontalBlockPosition
- type HorizontalLinePosition
- type HorizontalLinePositioner
- type Image
- type ImageBox
- func (ib *ImageBox) AdvanceRect() fixed.Int26_6
- func (ib *ImageBox) CalculateMetrics()
- func (ib *ImageBox) DrawBox(i Image, y fixed.Int26_6, dc *DrawConfig)
- func (ib *ImageBox) FontDrawer() *font.Drawer
- func (ib *ImageBox) Len() int
- func (ib *ImageBox) MetricsRect() font.Metrics
- func (ib *ImageBox) TextValue() string
- func (ib *ImageBox) Whitespace() bool
- type ImageBoxOption
- type Line
- type LineBreakBox
- type LinePositionStats
- type OverflowMode
- type PageBreakBox
- func (p *PageBreakBox) AdvanceRect() fixed.Int26_6
- func (p *PageBreakBox) DrawBox(i Image, y fixed.Int26_6, dc *DrawConfig)
- func (p *PageBreakBox) FontDrawer() *font.Drawer
- func (p *PageBreakBox) Len() int
- func (p *PageBreakBox) MetricsRect() font.Metrics
- func (p *PageBreakBox) TextValue() string
- func (p *PageBreakBox) Whitespace() bool
- type SimpleBoxer
- func (sb *SimpleBoxer) Back(i int)
- func (sb *SimpleBoxer) FontDrawer() *font.Drawer
- func (sb *SimpleBoxer) HasNext() bool
- func (sb *SimpleBoxer) Next() (Box, int, error)
- func (sb *SimpleBoxer) Pos() int
- func (sb *SimpleBoxer) Push(box ...Box)
- func (sb *SimpleBoxer) SetFontDrawer(face *font.Drawer)
- func (sb *SimpleBoxer) Shift() Box
- func (sb *SimpleBoxer) Unshift(box ...Box)
- type SimpleFolder
- type SimpleLine
- func (l *SimpleLine) Boxes() []Box
- func (l *SimpleLine) DrawLine(i Image, options ...DrawOption) error
- func (l *SimpleLine) Pop() Box
- func (l *SimpleLine) PopSpaceFor(sf *SimpleFolder, r image.Rectangle, box Box) (int, error)
- func (l *SimpleLine) Push(b Box, a fixed.Int26_6)
- func (l *SimpleLine) Size() image.Rectangle
- func (l *SimpleLine) TextValue() string
- func (l *SimpleLine) YValue() int
- type SimpleTextBox
- func (sb *SimpleTextBox) AdvanceRect() fixed.Int26_6
- func (sb *SimpleTextBox) DrawBox(i Image, y fixed.Int26_6, dc *DrawConfig)
- func (sb *SimpleTextBox) FontDrawer() *font.Drawer
- func (sb *SimpleTextBox) Len() int
- func (sb *SimpleTextBox) MetricsRect() font.Metrics
- func (sb *SimpleTextBox) TextValue() string
- func (sb *SimpleTextBox) Whitespace() bool
- type SimpleWrapper
- func (sw *SimpleWrapper) ApplyOptions(opts ...WrapperOption)
- func (sw *SimpleWrapper) HasNext() bool
- func (sw *SimpleWrapper) RenderLines(i Image, ls []Line, at image.Point, options ...DrawOption) error
- func (sw *SimpleWrapper) TextToRect(r image.Rectangle, ops ...FitterOption) ([]Line, image.Point, error)
- type SourceImageMapper
- type VerticalBlockPosition
- type WrapperOption
Constants ¶
const ( RSimpleBox = iota RCRLF RNIL )
Matches objects
Variables ¶
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
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
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
var ImageBoxMetricBelowTheLine imageBoxOptionMetricCalcFunc = func(ib *ImageBox) font.Metrics { return font.Metrics{ Height: fixed.I(ib.I.Bounds().Dy()), Descent: fixed.I(ib.I.Bounds().Dy()), } }
ImageBoxMetricBelowTheLine Puts the image above the baseline. Rarely done
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
Functions ¶
func DrawBox ¶
func DrawBox(i draw.Image, s image.Rectangle, dc *DrawConfig)
DrawBox literally draws a simple box
func IsSpaceButNotCRLF ¶
IsSpaceButNotCRLF Because spaces are different to CR and LF for word wrapping
func SimpleBoxerGrab ¶
SimpleBoxerGrab Consumer of characters until change. Could be made to conform to strings.Scanner
func SimpleWrapTextToImage ¶
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.
Types ¶
type Box ¶
type Box interface { // AdvanceRect width of text AdvanceRect() fixed.Int26_6 // MetricsRect all other font details of text MetricsRect() font.Metrics // Whitespace if this is a white space or not Whitespace() bool // DrawBox renders object DrawBox(i Image, y fixed.Int26_6, dc *DrawConfig) // FontDrawer font used FontDrawer() *font.Drawer // Len the length of the buffer represented by the box Len() int // TextValue extracts the text value TextValue() string }
Box is a representation of a non-divisible unit (can be nested)
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 BoxPositionStats ¶
type BoxPositionStats struct { *LinePositionStats NumberInLine int PageBoxOffset int WordOffset int }
BoxPositionStats Box position stats
type Boxer ¶
type Boxer interface { // Next gets the next word in a Box Next() (Box, int, error) // SetFontDrawer Changes the default font SetFontDrawer(face *font.Drawer) // FontDrawer encapsulates default fonts and more FontDrawer() *font.Drawer // Back goes back i spaces (ie unreads) Back(i int) // HasNext if there are any unprocessed runes HasNext() bool // Push puts a box back on to the cache stack Push(box ...Box) // Pos text pos Pos() int // Unshift basically is Push but to the start Unshift(b ...Box) // Shift removes the first element but unlike Next doesn't attempt to generate a new one if there is nothing Shift() Box }
Boxer is the tokenizer that splits the line into it's literal 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 DrawConfig ¶
type DrawConfig struct { SourceImageMapper SourceImageMapper BoxDrawMap BoxDrawMap }
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 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 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 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 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 ImageBox ¶
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 ¶
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) MetricsRect ¶
MetricsRect all other font details of text
func (*ImageBox) TextValue ¶
TextValue returns the text suppressed by the line break (probably a white space including a \r\n)
func (*ImageBox) Whitespace ¶
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 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
AdvanceRect width of text
func (*LineBreakBox) DrawBox ¶
func (sb *LineBreakBox) DrawBox(i Image, y fixed.Int26_6, dc *DrawConfig)
DrawBox renders object
type LinePositionStats ¶
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 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 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) MetricsRect ¶
func (p *PageBreakBox) MetricsRect() font.Metrics
MetricsRect all other font details of text
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 SimpleBoxer ¶
type SimpleBoxer struct { Grabber func(text []rune) (int, []rune, int) // 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.
func NewSimpleBoxer ¶
func NewSimpleBoxer(text []rune, 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) FontDrawer ¶
func (sb *SimpleBoxer) FontDrawer() *font.Drawer
FontDrawer encapsulates default fonts and more
func (*SimpleBoxer) Next ¶
func (sb *SimpleBoxer) Next() (Box, int, error)
Next gets the next word in a Box
func (*SimpleBoxer) Push ¶
func (sb *SimpleBoxer) Push(box ...Box)
Push puts a box back on to the cache stack
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)
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) 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
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) MetricsRect ¶
func (sb *SimpleTextBox) MetricsRect() font.Metrics
MetricsRect all other font details of text
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 quick and dirty wrapper.
func NewSimpleWrapper ¶
func NewSimpleWrapper(text string, 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.
type SourceImageMapper ¶
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 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 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