pack

package
Version: v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2018 License: MIT Imports: 18 Imported by: 1

Documentation

Overview

pack implements packing using maxrects algorithm

Index

Constants

This section is empty.

Variables

View Source
var SupportedFonts = []string{
	".ttf",
}
View Source
var SupportedImages = []string{
	".gif",
	".jpg", ".jpeg",
	".png",
	".bmp",
	".tif",
	".tiff",
	".webp",
}

Functions

func BoxesToSizes

func BoxesToSizes(boxes []Box) []image.Point

func PlaceBoxes

func PlaceBoxes(maxContextSize image.Point, rule maxrect.Rule, boxes []Box) (contextSize image.Point, ok bool)

func SortBoxes

func SortBoxes(boxes []Box)

Types

type Box

type Box struct {
	Name    string
	Padding int
	Size    image.Point
	Place   *image.Rectangle
}

type Font

type Font struct {
	Name      string
	Font      *truetype.Font
	Face      font.Face
	Padding   int
	MaxBounds fixed.Rectangle26_6
	Glyphs    map[rune]*Glyph
	Kern      map[[2]rune]fixed.Int26_6
}

func LoadFont

func LoadFont(name, filename string, fontSize int) (*Font, error)

func (*Font) Boxes

func (font *Font) Boxes() []Box

func (*Font) Draw

func (font *Font) Draw(m draw.Image)

func (*Font) Include

func (font *Font) Include(r rune) bool

func (*Font) IncludeAscii

func (font *Font) IncludeAscii()

func (*Font) IncludeExtendedAscii

func (font *Font) IncludeExtendedAscii()

func (*Font) IncludeString

func (font *Font) IncludeString(s string)

type Glyph

type Glyph struct {
	Rune    rune
	Size    image.Point         // destination size in pixels
	Bounds  fixed.Rectangle26_6 // such that point + bounds, gives image bounds
	Advance fixed.Int26_6
	Place   image.Rectangle // without padding
}

Glyph represents a drawable symbol from a font.

 advance          ----  maxAscent
|-------|          |
         ■■■      ----  bounds.Max.Y
        ■   ■      |
        ■          |
 ■■■■    ■■■■      |
■    ■       ■     |
■    ■       ■     |
•■■■■■  •■■■■   • ----  point.Y
     ■             |
■    ■             |
 ■■■■             ----  bounds.Min.Y
                   |
                  ----  maxDescent

type Image

type Image struct {
	Name string
	Data image.Image
	Size image.Point

	// extra info for GIF-s
	Animated bool
	Index    int // animation-only
	Delay    int // animation-only, ms

	// parameters
	Padding int
	Rotated bool
	SDF     bool

	// final location inside texture
	Place image.Rectangle
}

func LoadImage

func LoadImage(name, filename string) (*Image, error)

func (*Image) Box

func (m *Image) Box() Box

func (*Image) Draw

func (m *Image) Draw(dst draw.Image)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL