vg

package
v0.0.0-...-7c6133f Latest Latest
Warning

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

Go to latest
Published: May 30, 2016 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

vg defines an interface for drawing 2D vector graphics. This package is designed with the hope that many different vector graphics back-ends can conform to the interface.

Index

Constants

View Source
const (
	MoveComp = iota
	LineComp
	ArcComp
	CloseComp
)

Constants that tag the type of each path component.

Variables

View Source
var FontDirs = initFontDirs()

FontDirs is a slice of directories searched for font data files. If the first font file found is unreadable or cannot be parsed, then subsequent directories are not tried, and the font will fail to load.

The default slice contains, in the following order, the values of the environment variable VGFONTPATH if it is defined, then the vg source fonts directory if it is found (i.e., if vg was installed by go get). If the resulting FontDirs slice is empty then the current directory is added to it. This slice may be changed to load fonts from different locations.

View Source
var (
	// FontMap maps Postscript/PDF font names to compatible
	// free fonts (TrueType converted ghostscript fonts).
	// Fonts that are not keys of this map are not supported.
	FontMap = map[string]string{

		"Courier":             "NimbusMonL-Regu",
		"Courier-Bold":        "NimbusMonL-Bold",
		"Courier-Oblique":     "NimbusMonL-ReguObli",
		"Courier-BoldOblique": "NimbusMonL-BoldObli",

		"Helvetica":             "NimbusSanL-Regu",
		"Helvetica-Bold":        "NimbusSanL-Bold",
		"Helvetica-Oblique":     "NimbusSanL-ReguItal",
		"Helvetica-BoldOblique": "NimbusSanL-BoldItal",

		"Times-Roman":      "NimbusRomNo9L-Regu",
		"Times-Bold":       "NimbusRomNo9L-Medi",
		"Times-Italic":     "NimbusRomNo9L-ReguItal",
		"Times-BoldItalic": "NimbusRomNo9L-MediItal",
	}
)

Functions

func Initialize

func Initialize(c Canvas)

Initialize sets all of the canvas's values to their initial values.

Types

type Canvas

type Canvas interface {
	// SetLineWidth sets the width of stroked paths.
	// If the width is set to 0 then stroked lines are
	// not drawn.
	//
	// The initial line width is 1 point.
	SetLineWidth(Length)

	// SetLineDash sets the dash pattern for lines.
	// The first argument is the pattern (units on,
	// units off, etc.) and the second argument
	// is the initial offset into the pattern.
	//
	// The inital dash pattern is a solid line.
	SetLineDash([]Length, Length)

	// SetColor sets the current drawing color.
	// Note that fill color and stroke color are
	// the same so if you want different fill
	// and stroke colorls then you must use two
	// separate calls to SetColor.
	//
	// The initial color is black.  If SetColor is
	// called with a nil color then black is used.
	SetColor(color.Color)

	// Rotate applies a rotation transform to the
	// context.  The parameter is specified in
	// radians.
	Rotate(float64)

	// Translate applies a translational transform
	// to the context.
	Translate(Length, Length)

	// Scale applies a scaling transform to the
	// context.
	Scale(float64, float64)

	// Push saves the current line width, the
	// current dash pattern, the current
	// transforms, and the current color
	// onto a stack so that the state can later
	// be restored by calling Pop().
	Push()

	// Pop restores the context saved by the
	// corresponding call to Push().
	Pop()

	// Stroke strokes the given path.
	Stroke(Path)

	// Fill fills the given path.
	Fill(Path)

	// FillString fills in text at the specified
	// location using the given font.
	FillString(Font, Length, Length, string)

	// DPI returns the number of canvas dots in
	// an inch.
	DPI() float64
}

A Canvas is the main drawing interface for 2D vector graphics. The origin is in the bottom left corner.

type Font

type Font struct {
	// Size is the size of the font.  The font size can
	// be used as a reasonable value for the vertical
	// distance between two successive lines of text.
	Size Length
	// contains filtered or unexported fields
}

A Font represents one of the supported font faces.

func MakeFont

func MakeFont(name string, size Length) (font Font, err error)

MakeFont returns a font object. The name of the font must be a key of the FontMap. The font file is located by searching the FontDirs slice for a directory containing the relevant font file. The font file name is name mapped by FontMap with the .ttf extension. For example, the font file for the font name Courier is NimbusMonL-Regu.ttf.

func (*Font) Extents

func (f *Font) Extents() FontExtents

Extents returns the FontExtents for a font.

func (*Font) Font

func (f *Font) Font() *truetype.Font

Font returns the corresponding truetype.Font.

func (*Font) Name

func (f *Font) Name() string

Name returns the name of the font.

func (*Font) SetName

func (f *Font) SetName(name string) error

SetName sets the name of the font, effectively changing the font. If an error is returned then the font is left unchanged.

func (*Font) Width

func (f *Font) Width(s string) Length

Width returns width of a string when drawn using the font.

type FontExtents

type FontExtents struct {
	// Ascent is the distance that the text
	// extends above the baseline.
	Ascent Length

	// Descent is the distance that the text
	// extends below the baseline.  The descent
	// is given as a negative value.
	Descent Length

	// Height is the distance from the lowest
	// descending point to the highest ascending
	// point.
	Height Length
}

FontExtents contains font metric information.

type Length

type Length float64

A Length is a unit-independent representation of length. Internally, the length is stored in postscript points.

func Centimeters

func Centimeters(cm float64) Length

Centimeters returns a length for the given number of centimeters.

func Inches

func Inches(in float64) Length

Inches returns a length for the given numer of inches.

func Millimeters

func Millimeters(mm float64) Length

Millimeters returns a length for the given number of millimeters.

func Points

func Points(pt float64) Length

Points returns a length for the given number of points.

func (Length) Centimeters

func (l Length) Centimeters() float64

Centimeters returns the length in centimeters.

func (Length) Dots

func (l Length) Dots(c Canvas) float64

Dots returns the length in dots for the given Canvas.

func (Length) Inches

func (l Length) Inches() float64

Inches returns the length in inches.

func (Length) Millimeters

func (l Length) Millimeters() float64

Millimeters returns the length in millimeters.

func (Length) Points

func (l Length) Points() float64

Points returns the length in postscript points.

type Path

type Path []PathComp

func (*Path) Arc

func (p *Path) Arc(x, y, rad Length, s, a float64)

Arc adds an arc to the path defined by the center point of the arc's circle, the radius of the circle and the start and sweep angles.

func (*Path) Close

func (p *Path) Close()

Close closes the path by connecting the current location to the start location with a line.

func (*Path) Line

func (p *Path) Line(x, y Length)

Line draws a line from the current point to the given point.

func (*Path) Move

func (p *Path) Move(x, y Length)

Move moves the current location of the path to the given point.

type PathComp

type PathComp struct {
	// Type is the type of a particluar component.
	// Based on the type, each of the following
	// fields may have a different meaning or may
	// be meaningless.
	Type int

	// The X and Y fields are used as the destination
	// of a MoveComp or LineComp and are the center
	// point of an ArcComp.  They are not used in
	// the CloseComp.
	X, Y Length

	// Radius is only used for ArcComps, it is
	// the radius of the circle defining the arc.
	Radius Length

	// Start and Angle are only used for ArcComps.
	// They define the start angle and sweep angle of
	// the arc around the circle.  The units of the
	// angle are radians.
	Start, Angle float64
}

A PathComp is a component of a path structure.

Directories

Path Synopsis
The vgeps implemens the vg.Canvas interface using encapsulated postscript.
The vgeps implemens the vg.Canvas interface using encapsulated postscript.
vgimg implements the vg.Canvas interface using draw2d (code.google.com/p/draw2d/draw2d) as a backend to output raster images.
vgimg implements the vg.Canvas interface using draw2d (code.google.com/p/draw2d/draw2d) as a backend to output raster images.
The vgpdf implemens the vg.Canvas interface using gopdf (bitbucket.org/zombiezen/gopdf/pdf).
The vgpdf implemens the vg.Canvas interface using gopdf (bitbucket.org/zombiezen/gopdf/pdf).
The vgsvg package uses svgo (github.com/ajstarks/svgo) as a backend for vg.
The vgsvg package uses svgo (github.com/ajstarks/svgo) as a backend for vg.

Jump to

Keyboard shortcuts

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