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 ¶
const ( MoveComp = iota LineComp ArcComp CloseComp )
Constants that tag the type of each path component.
Variables ¶
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.
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 ¶
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.
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 ¶
Centimeters returns a length for the given number of centimeters.
func Millimeters ¶
Millimeters returns a length for the given number of millimeters.
func (Length) Centimeters ¶
Centimeters returns the length in centimeters.
func (Length) Millimeters ¶
Millimeters returns the length in millimeters.
type Path ¶
type Path []PathComp
func (*Path) Arc ¶
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.
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. |