Documentation ¶
Overview ¶
Package cairo wraps libcairo, a 2D graphics library with support for multiple output devices. Libcairo is is designed to produce consistent output on all output media while taking advantage of display hardware acceleration when available.
The cairo API provides operations similar to the drawing operators of PostScript and PDF. Operations in cairo including stroking and filling cubic Bézier splines, transforming and compositing translucent images, and antialiased text rendering. All drawing operations can be transformed by any affine transformation (scale, rotation, shear, etc.)
Reference semantics ¶
Many types in this and related packages are references, that behave much like file handles, to underlying libcairo objects. These handles are values that can be copied at will, but the libcairo object referenced must be freed explicitly with Close (or Unmap, in the case of MappedImageSurface).
Naming Conventions ¶
Cairo refers to this package and its related packages. Libcairo refers to the C library that this package is a binding to.
Libcairo version ¶
This package requires libcairo version 1.12 or greater. Libcairo must be compiled with:
CAIRO_HAS_IMAGE_SURFACE
Related packages, such as cairo/ps, may require further options compiled in to libcairo, but they will be documented.
Libcairo can be found at http://cairographics.org .
Xtensions ¶
Many types, functions, and methods are prefixed by Xtension. You may ignore these unless you are writing an extension. An extension is a package that integrates another portion of libcairo or binds with a library that supports libcairo integration.
Example (HelloWorld) ¶
A simple hello world that writes a blue "Hello, world" to hello.png.
Adapted from http://cairographics.org/FAQ/#minimal_C_program .
surface, err := NewImageSurface(FormatARGB32, 240, 80) if err != nil { log.Fatalln(err) } defer surface.Close() cr, err := New(surface) if err != nil { log.Fatalln(err) } defer cr.Close() cr. SelectFont("serif", 0, WeightBold). SetFontSize(32). SetSourceColor(Blue). MoveTo(Pt(10, 50)). ShowText("Hello, world") img, err := surface.ToImage() if err != nil { log.Fatalln(err) } f, err := os.Create("hello.png") if err != nil { log.Fatalln(err) } defer f.Close() err = png.Encode(f, img) if err != nil { log.Fatalln(err) }
Output:
Index ¶
- Constants
- Variables
- func Version() string
- func XtensionGlyphsGotoC(gs []Glyph, useGlyphAllocate bool) (glyphs *C.cairo_glyph_t, N C.int)
- func XtensionRegisterAlienRasterPatternSubtype(name string, fac func(*C.cairo_pattern_t) (Pattern, error))
- func XtensionRegisterAlienUserFontSubtype(name string, fac func(*C.cairo_font_face_t) (Font, error))
- func XtensionRegisterRawToDevice(d deviceType, f func(*C.cairo_device_t) (Device, error))
- func XtensionRegisterRawToFont(t fontType, f func(*C.cairo_font_face_t) (Font, error))
- func XtensionRegisterRawToSurface(t surfaceType, f func(*C.cairo_surface_t) (Surface, error))
- func XtensionTextClustersGotoC(tcs []TextCluster, useTextClusterAllocator bool) (cs *C.cairo_text_cluster_t, N C.int)
- func XtensionWrapWriter(w io.Writer) (closure unsafe.Pointer)
- type AlphaColor
- type Circle
- type Color
- type ColorStop
- type Content
- type Context
- func (c *Context) AntialiasMode() antialias
- func (c *Context) AppendPath(path Path) error
- func (c *Context) Arc(circle Circle, fromAngle, toAngle float64) *Context
- func (c *Context) ArcNegative(circle Circle, fromAngle, toAngle float64) *Context
- func (c *Context) Circle(circle Circle) *Context
- func (c *Context) Clip() *Context
- func (c *Context) ClipExtents() Rectangle
- func (c *Context) ClipPreserve() *Context
- func (c *Context) ClipRectangles() (list []Rectangle, err error)
- func (c *Context) Close() error
- func (c *Context) ClosePath() *Context
- func (c *Context) CopyPage() *Context
- func (c *Context) CopyPath() (Path, error)
- func (c *Context) CopyPathFlat() (Path, error)
- func (c *Context) CurrentPoint() (cp Point, defined bool)
- func (c *Context) CurveTo(p1, p2, p3 Point) *Context
- func (c *Context) DashCount() int
- func (c *Context) Dashes() (offset float64, dashes []float64)
- func (c *Context) DeviceToUser(p Point) (q Point)
- func (c *Context) DeviceToUserDistance(v Point) Point
- func (c *Context) Err() error
- func (c *Context) Fill() *Context
- func (c *Context) FillExtents() Rectangle
- func (c *Context) FillPreserve() *Context
- func (c *Context) FillRule() fillRule
- func (c *Context) Font() (Font, error)
- func (c *Context) FontExtents() FontExtents
- func (c *Context) FontMatrix() Matrix
- func (c *Context) FontOptions() *FontOptions
- func (c *Context) GlyphExtents(glyphs []Glyph) TextExtents
- func (c *Context) GlyphPath(glyphs []Glyph) *Context
- func (c *Context) GroupTarget() (Surface, error)
- func (c *Context) InClip(pt Point) bool
- func (c *Context) InFill(pt Point) bool
- func (c *Context) InStroke(pt Point) bool
- func (c *Context) LineCap() lineCap
- func (c *Context) LineJoin() lineJoin
- func (c *Context) LineTo(p Point) *Context
- func (c *Context) LineWidth() float64
- func (c *Context) Mask(p Pattern) *Context
- func (c *Context) MaskSurface(s Surface, offsetVector Point) *Context
- func (c *Context) Matrix() Matrix
- func (c *Context) MiterLimit() float64
- func (c *Context) MoveTo(p Point) *Context
- func (c *Context) NewPath() *Context
- func (c *Context) NewSubPath() *Context
- func (c *Context) Operator() operator
- func (c *Context) Paint() *Context
- func (c *Context) PaintAlpha(alpha float64) *Context
- func (c *Context) PathExtents() Rectangle
- func (c *Context) PopGroup() (Pattern, error)
- func (c *Context) PopGroupToSource() error
- func (c *Context) PushGroup() *Context
- func (c *Context) PushGroupWithContent(content Content) *Context
- func (c *Context) Rectangle(r Rectangle) *Context
- func (c *Context) RelCurveTo(v1, v2, v3 Point) *Context
- func (c *Context) RelLineTo(v Point) *Context
- func (c *Context) RelMoveTo(v Point) *Context
- func (c *Context) ResetClip() *Context
- func (c *Context) ResetMatrix() *Context
- func (c *Context) Restore() error
- func (c *Context) Rotate(θ float64) *Context
- func (c *Context) Save() *Context
- func (c *Context) SaveRestore(f func(*Context) error) (err error)
- func (c *Context) Scale(v Point) *Context
- func (c *Context) ScaledFont() (*ScaledFont, error)
- func (c *Context) SelectFont(family string, slant slant, weight weight) *Context
- func (c *Context) SetAntialiasMode(a antialias) *Context
- func (c *Context) SetDash(offset float64, dashes ...float64) error
- func (c *Context) SetFillRule(f fillRule) *Context
- func (c *Context) SetFont(f Font) *Context
- func (c *Context) SetFontMatrix(m Matrix) *Context
- func (c *Context) SetFontOptions(opts *FontOptions) *Context
- func (c *Context) SetFontSize(size float64) *Context
- func (c *Context) SetLineCap(lc lineCap) *Context
- func (c *Context) SetLineJoin(l lineJoin) *Context
- func (c *Context) SetLineWidth(width float64) *Context
- func (c *Context) SetMatrix(m Matrix) *Context
- func (c *Context) SetMiterLimit(ml float64) *Context
- func (c *Context) SetOperator(op operator) *Context
- func (c *Context) SetScaledFont(sf *ScaledFont) *Context
- func (c *Context) SetSource(source Pattern) *Context
- func (c *Context) SetSourceColor(col color.Color) *Context
- func (c *Context) SetSourceSurface(s Surface, originDisplacement Point) error
- func (c *Context) SetTolerance(tolerance float64) *Context
- func (c *Context) ShowGlyphs(glyphs []Glyph) *Context
- func (c *Context) ShowPage() *Context
- func (c *Context) ShowText(s string) *Context
- func (c *Context) ShowTextGlyphs(s string, glyphs []Glyph, clusters []TextCluster, flags TextClusterFlags) *Context
- func (c *Context) Source() (Pattern, error)
- func (c *Context) Stroke() *Context
- func (c *Context) StrokeExtents() Rectangle
- func (c *Context) StrokePreserve() *Context
- func (c *Context) Target() Surface
- func (c *Context) TextExtents(s string) TextExtents
- func (c *Context) TextPath(s string) *Context
- func (c *Context) Tolerance() float64
- func (c *Context) Transform(m Matrix) *Context
- func (c *Context) Translate(v Point) *Context
- func (c *Context) UserToDevice(p Point) (q Point)
- func (c *Context) UserToDeviceDistance(v Point) Point
- type Device
- type Font
- type FontExtents
- type FontOptions
- func (f *FontOptions) AntialiasMode() antialias
- func (f *FontOptions) Clone() *FontOptions
- func (f *FontOptions) Close() error
- func (f *FontOptions) Equal(o *FontOptions) bool
- func (f *FontOptions) Err() error
- func (f *FontOptions) HintMetrics() hintMetrics
- func (f *FontOptions) HintStyle() hintStyle
- func (f *FontOptions) Merge(o *FontOptions) *FontOptions
- func (f *FontOptions) SetAntialiasMode(a antialias) *FontOptions
- func (f *FontOptions) SetHintMetrics(h hintMetrics) *FontOptions
- func (f *FontOptions) SetHintStyle(h hintStyle) *FontOptions
- func (f *FontOptions) SetSubpixelOrder(s subpixelOrder) *FontOptions
- func (f *FontOptions) SubpixelOrder() subpixelOrder
- type Format
- type Glyph
- type Gradient
- type ImageSurface
- type LinearGradient
- type MappedImageSurface
- type Matrix
- func (m Matrix) Clone() Matrix
- func (m Matrix) Invert() Matrix
- func (m Matrix) Mul(n Matrix) Matrix
- func (m Matrix) Rotate(radians float64) Matrix
- func (m Matrix) Scale(vector Point) Matrix
- func (m Matrix) Translate(vector Point) Matrix
- func (m Matrix) X0() float64
- func (m Matrix) XX() float64
- func (m Matrix) XY() float64
- func (m Matrix) XtensionRaw() C.cairo_matrix_t
- func (m Matrix) Y0() float64
- func (m Matrix) YX() float64
- func (m Matrix) YY() float64
- type Mesh
- type Paged
- type PagedSurface
- type PagedVectorSurface
- type Patch
- type Path
- type PathElement
- type Pattern
- type Point
- func (p Point) Add(q Point) Point
- func (p Point) Angle() float64
- func (p Point) Conj() Point
- func (p Point) Div(k float64) Point
- func (p Point) Dot(q Point) float64
- func (p Point) Eq(q Point) bool
- func (p Point) In(r Rectangle) bool
- func (p Point) InCirc(c Circle) bool
- func (p Point) Mag() float64
- func (p Point) Mod(r Rectangle) Point
- func (p Point) Mul(k float64) Point
- func (p Point) Near(q Point, ε float64) bool
- func (p Point) Norm() (n Point)
- func (p Point) Rx() Point
- func (p Point) Ry() Point
- func (p Point) String() string
- func (p Point) Sub(q Point) Point
- func (p Point) Sx(x float64) Point
- func (p Point) Sy(y float64) Point
- func (p Point) Transform(m Matrix) Point
- func (p Point) TransformDistance(m Matrix) Point
- type RadialGradient
- type Rectangle
- func (r Rectangle) Add(p Point) Rectangle
- func (r Rectangle) Canon() Rectangle
- func (r Rectangle) Dx() float64
- func (r Rectangle) Dy() float64
- func (r Rectangle) Empty() bool
- func (r Rectangle) In(s Rectangle) bool
- func (r Rectangle) Intersect(s Rectangle) Rectangle
- func (r Rectangle) Overlaps(s Rectangle) bool
- func (r Rectangle) Size() Point
- func (r Rectangle) String() string
- func (r Rectangle) Sub(p Point) Rectangle
- func (r Rectangle) Verts() (x0y0, x0y1, x1y1, x1y0 Point)
- type ScaledFont
- type SolidPattern
- type Subsurface
- type Surface
- type SurfacePattern
- type TextCluster
- type TextClusterFlags
- type TextExtents
- type ToyFont
- type VectorBacked
- type VectorSurface
- type XtensionDevice
- func (c *XtensionDevice) Close() error
- func (c *XtensionDevice) Equal(d Device) bool
- func (c *XtensionDevice) Err() error
- func (c *XtensionDevice) Flush()
- func (c *XtensionDevice) Lock() (err error)
- func (c *XtensionDevice) Type() deviceType
- func (c *XtensionDevice) Unlock()
- func (c *XtensionDevice) XtensionRaw() *C.cairo_device_t
- func (d *XtensionDevice) XtensionRegisterWriter(w unsafe.Pointer)
- type XtensionFont
- type XtensionPagedSurface
- type XtensionPagedVectorSurface
- type XtensionPattern
- func (p *XtensionPattern) Close() error
- func (p *XtensionPattern) Err() error
- func (p *XtensionPattern) Extend() extend
- func (p *XtensionPattern) Filter() filter
- func (p *XtensionPattern) Matrix() Matrix
- func (p *XtensionPattern) SetExtend(e extend)
- func (p *XtensionPattern) SetFilter(f filter)
- func (p *XtensionPattern) SetMatrix(m Matrix)
- func (p *XtensionPattern) Type() patternType
- func (p *XtensionPattern) XtensionRaw() *C.cairo_pattern_t
- type XtensionSurface
- func (e *XtensionSurface) Close() error
- func (e *XtensionSurface) Content() Content
- func (e *XtensionSurface) CreateSimilar(c Content, w, h int) (Surface, error)
- func (e *XtensionSurface) CreateSimilarImage(f Format, w, h int) (ImageSurface, error)
- func (e *XtensionSurface) CreateSubsurface(r Rectangle) (s Subsurface, err error)
- func (e *XtensionSurface) Device() (Device, error)
- func (e *XtensionSurface) DeviceOffset() (vector Point)
- func (e *XtensionSurface) Equal(s Surface) bool
- func (e *XtensionSurface) Err() error
- func (e *XtensionSurface) Flush() error
- func (e *XtensionSurface) FontOptions() *FontOptions
- func (e *XtensionSurface) HasShowTextGlyphs() bool
- func (e *XtensionSurface) MapImage(r image.Rectangle) (MappedImageSurface, error)
- func (e *XtensionSurface) SetDeviceOffset(vector Point)
- func (e *XtensionSurface) Type() surfaceType
- func (e *XtensionSurface) XtensionRaw() *C.cairo_surface_t
- func (s *XtensionSurface) XtensionRegisterWriter(w unsafe.Pointer)
- type XtensionVectorSurface
Examples ¶
Constants ¶
const ( //AntialiasDefault uses the default antialiasing for the subsystem //and target device. AntialiasDefault antialias = C.CAIRO_ANTIALIAS_DEFAULT //AntialiasNone uses a bilevel alpha mask. AntialiasNone antialias = C.CAIRO_ANTIALIAS_NONE //AntialiasGray performs single-color antialiasing (using shades of gray //for black text on white background, for example). AntialiasGray antialias = C.CAIRO_ANTIALIAS_GRAY //AntialiasSubpixel performs antialiasing by taking advantage of the order //of subpixel elements on devices such as LCD panels. AntialiasSubpixel antialias = C.CAIRO_ANTIALIAS_SUBPIXEL //AntialiasFast is a hint that the backend should perform some antialiasing //but prefer speed over quality. AntialiasFast antialias = C.CAIRO_ANTIALIAS_FAST //AntialiasGood is a hint that the backend should balance quality against //performance. AntialiasGood antialias = C.CAIRO_ANTIALIAS_GOOD //AntialiasBest is a hint that the backend should render at the highest //quality, sacrificing speed if necessary. AntialiasBest antialias = C.CAIRO_ANTIALIAS_BEST )
Specifies the type of antialiasing to do when rendering text or shapes.
As it is not necessarily clear from the above what advantages a particular antialias method provides, since libcairo 1.12, there is also a set of hints:
AntialiasFast Allow the backend to degrade raster quality for speed AntialiasGood A balance between speed and quality AntialiasBest A high-fidelity, but potentially slow, raster mode
These make no guarantee on how the backend will perform its rasterisation (if it even rasterises!), nor that they have any differing effect other than to enable some form of antialiasing. In the case of glyph rendering, AntialiasFast and AntialiasGood will be mapped to AntialiasGray, with AntialiasBest being equivalent to AntialiasSubpixel.
The interpretation of AntialiasDefault is left entirely up to the backend, typically this will be similar to AntialiasGood.
Originally cairo_antialias_t.
const ( //DeviceTypeDRM is a Direct Render Manager device. DeviceTypeDRM deviceType = C.CAIRO_DEVICE_TYPE_DRM //DeviceTypeGL is an OpenGL device. DeviceTypeGL deviceType = C.CAIRO_DEVICE_TYPE_GL //DeviceTypeScript is a script recording pseudo-Device. DeviceTypeScript deviceType = C.CAIRO_DEVICE_TYPE_SCRIPT //DeviceTypeXCB is an XCB device. DeviceTypeXCB deviceType = C.CAIRO_DEVICE_TYPE_XCB //DeviceTypeXLib is an X lib device. DeviceTypeXLib deviceType = C.CAIRO_DEVICE_TYPE_XLIB //DeviceTypeXML is an XML device. DeviceTypeXML deviceType = C.CAIRO_DEVICE_TYPE_XML //DeviceTypeCogl is a Cogl device. DeviceTypeCogl deviceType = C.CAIRO_DEVICE_TYPE_COGL //DeviceTypeWin32 is a Win32 device. DeviceTypeWin32 deviceType = C.CAIRO_DEVICE_TYPE_WIN32 )
A deviceType describes the type of a given device, also known as a "backend".
A deviceType value has the following methods, in addition to String, which all return bool:
Native A native device (win32, xcb, etc). GL OpenGL or Cogl. Pseudo A device that doesn't output to a screen of some kind (XML).
Originally cairo_device_type_t.
const ( //ExtendNone makes pixels outside of the source pattern are fully transparent. ExtendNone extend = C.CAIRO_EXTEND_NONE //ExtendRepeat means the pattern is tiled by repeating. ExtendRepeat extend = C.CAIRO_EXTEND_REPEAT //ExtendReflect means the pattern is tiled by reflecting at the edges. ExtendReflect extend = C.CAIRO_EXTEND_REFLECT //ExtendPad means pixels outside of the pattern copy the closest pixel //from the source. ExtendPad extend = C.CAIRO_EXTEND_PAD )
The extend type describes how pattern color/alpha will be determined for areas "outside" the pattern's natural area, (for example, outside the surface bounds or outside the gradient geometry).
Originally cairo_extend_t.
const ( //FillRuleWinding works as follows: //If the path crosses the ray from left-to-right, counts +1. //If the path crosses the ray from right to left, counts -1. //(Left and right are determined from the perspective of looking along //the ray from the starting point.) If the total count is non-zero, //the point will be filled. FillRuleWinding fillRule = C.CAIRO_FILL_RULE_WINDING //FillRuleEvenOdd counts the total number of intersections, //without regard to the orientation of the contour. //If the total number of intersections is odd, the point will be filled. FillRuleEvenOdd fillRule = C.CAIRO_FILL_RULE_EVEN_ODD )
The fillRule type is used to select how paths are filled. For both fill rules, whether or not a point is included in the fill is determined by taking a ray from that point to infinity and looking at intersections with the path. The ray can be in any direction, as long as it doesn't pass through the end point of a segment or have a tricky intersection such as intersecting tangent to the path. (Note that filling is not actually implemented in this way. This is just a description of the rule that is applied.)
Originally cairo_fill_rule_t.
const ( //FilterFast is a high performance filter with quality similar to //FilterNearest. FilterFast filter = C.CAIRO_FILTER_FAST //FilterGood is a reasonable performance filter, with quality similiar to //FilterBilinear. FilterGood filter = C.CAIRO_FILTER_GOOD //FilterBest is the highest quality filter, but may not be suitable //for interactive use. FilterBest filter = C.CAIRO_FILTER_BEST //FilterNearest is nearest-neighbor filtering. FilterNearest filter = C.CAIRO_FILTER_NEAREST //FilterBilinear uses linear interpolation in two dimensions. FilterBilinear filter = C.CAIRO_FILTER_BILINEAR )
The filter type indicates what filtering should be applied when reading pixel values from patterns.
Originally cairo_filter_t.
const ( //SlantNormal is standard upright font style. SlantNormal slant = C.CAIRO_FONT_SLANT_NORMAL //SlantItalic is italic font style. SlantItalic slant = C.CAIRO_FONT_SLANT_ITALIC //SlantOblique is oblique font style. SlantOblique slant = C.CAIRO_FONT_SLANT_OBLIQUE )
Specifies variants of a font face based on their slant.
Originally cairo_font_slant_t.
const ( //FontTypeToy fonts are created using cairo's toy font api. FontTypeToy fontType = C.CAIRO_FONT_TYPE_TOY //FontTypeWin32 is a native Windows font. FontTypeWin32 fontType = C.CAIRO_FONT_TYPE_WIN32 //FontTypeQuartz is a native Macintosh font. FontTypeQuartz fontType = C.CAIRO_FONT_TYPE_QUARTZ //previously knonw as CAIRO_FONT_TYPE_ATSUI //FontTypeUser was created using cairo's user font api. // //A type with FontTypeUser also has a Subtype. FontTypeUser fontType = C.CAIRO_FONT_TYPE_USER )
A fontType describes the type of a given font face or scaled font. The font types are also known as "font backends" within cairo.
Originally cairo_font_type_t.
const ( //WeightNormal is normal font weight. WeightNormal weight = C.CAIRO_FONT_WEIGHT_NORMAL //WeightBold is bold font weight. WeightBold weight = C.CAIRO_FONT_WEIGHT_BOLD )
Specifies variants of a font face based on their weight.
Orginally cairo_font_weight_t.
const ( //HintMetricsDefault use hint metrics in the default manner //for the font backend and target device. HintMetricsDefault hintMetrics = C.CAIRO_HINT_METRICS_DEFAULT //HintMetricsOff does not hint font metrics. HintMetricsOff hintMetrics = C.CAIRO_HINT_METRICS_OFF //HintMetricsOn hints font metrics. HintMetricsOn hintMetrics = C.CAIRO_HINT_METRICS_ON )
Specifies whether to hint font metrics; hinting font metrics means quantizing them so that they are integer values in device space. Doing this improves the consistency of letter and line spacing, however it also means that text will be laid out differently at different zoom factors.
Oringally cairo_hint_metrics_t.
const ( //HintStyleDefault uses the default hint style for the font backend and target //device. HintStyleDefault hintStyle = C.CAIRO_HINT_STYLE_DEFAULT //HintStyleNone does not hint outlines. HintStyleNone hintStyle = C.CAIRO_HINT_STYLE_NONE //HintStyleSlight outlines slightly, to improve contrast while retaining //good fidelity of the original shapes. HintStyleSlight hintStyle = C.CAIRO_HINT_STYLE_SLIGHT //HintStyleMedium outlines with medium strength, giving a compromise //between fidelity to the original shapes and contrast HintStyleMedium hintStyle = C.CAIRO_HINT_STYLE_MEDIUM //HintStyleFull outlines to maximize contrast. HintStyleFull hintStyle = C.CAIRO_HINT_STYLE_FULL )
The hintStyle type specifies the hinting method to use for font outlines. Hinting is the process of fitting outlines to the pixel grid in order to improve the appearance of the result. Since hinting outlines involves distorting them, it also reduces the faithfulness to the original outline shapes. Not all of the outline hinting styles are supported by all font backends.
Originally cairo_hint_style_t.
const ( //LineCapButt starts(stops) the line exactly at the start(end) point. LineCapButt lineCap = C.CAIRO_LINE_CAP_BUTT //LineCapRound uses a round ending, the center of the circle is the end point. LineCapRound lineCap = C.CAIRO_LINE_CAP_ROUND //LineCapSquare uses a squared ending, the center of the square is //the end point. LineCapSquare lineCap = C.CAIRO_LINE_CAP_SQUARE )
Specifies how to render the endpoints of the path when stroking.
Originally cairo_line_cap_t.
const ( //LineJoinMiter uses a sharp (angled) corner. LineJoinMiter lineJoin = C.CAIRO_LINE_JOIN_MITER //LineJoinRound uses a rounded join, the center of the circle //is the join point. LineJoinRound lineJoin = C.CAIRO_LINE_JOIN_ROUND //LineJoinBevel uses a cut-off join, the join is cut off at half //the line width from the joint point. LineJoinBevel lineJoin = C.CAIRO_LINE_JOIN_BEVEL )
Specifies how to render the junction of two lines when stroking.
Originally cairo_line_join_t.
const ( //OpClear clears destination layer (bounded). OpClear operator = C.CAIRO_OPERATOR_CLEAR //OpSource replaces destination layer (bounded). OpSource operator = C.CAIRO_OPERATOR_SOURCE //OpOver draws source layer on top of destination layer (bounded). OpOver operator = C.CAIRO_OPERATOR_OVER //OpIn draws source where there was destination content (unbounded). OpIn operator = C.CAIRO_OPERATOR_IN //OpOut draws source where there was no destination content (unounded). OpOut operator = C.CAIRO_OPERATOR_OUT //OpAtop draws source on top of destination content and only there. OpAtop operator = C.CAIRO_OPERATOR_ATOP //OpDest ignores the source. OpDest operator = C.CAIRO_OPERATOR_DEST //OpDestOver draw destination on top of source. OpDestOver operator = C.CAIRO_OPERATOR_DEST_OVER //OpDestIn leaves destination only where there was source content. OpDestIn operator = C.CAIRO_OPERATOR_DEST_IN //OpDestOut leaves destination only where there was no source content. OpDestOut operator = C.CAIRO_OPERATOR_DEST_OUT //OpDestAtop leaves destination on top of source content and only there. OpDestAtop operator = C.CAIRO_OPERATOR_DEST_ATOP //OpXor shows source and destination where there is only one of them. OpXor operator = C.CAIRO_OPERATOR_XOR //OpAdd accumulates source and destination layers. OpAdd operator = C.CAIRO_OPERATOR_ADD //OpSaturate is like OpOver, but assumes source and dest are disjoint //geometries. OpSaturate operator = C.CAIRO_OPERATOR_SATURATE //OpMultiply multiplies source and destination layers. //This causes the result to be at least as the darker inputs. OpMultiply operator = C.CAIRO_OPERATOR_MULTIPLY //OpScreen complements and multiples source and destination. //This causes the result to be as light as the lighter inputs. OpScreen operator = C.CAIRO_OPERATOR_SCREEN //OpOverlay multiplies or screens, depending on the lightness //of the destination color. OpOverlay operator = C.CAIRO_OPERATOR_OVERLAY //OpDarken replaces the destination with source if is darker, otherwise //keeps the source. OpDarken operator = C.CAIRO_OPERATOR_DARKEN //OpLighten replaces the destiantion with source if it is lighter, otherwise //keeps the source. OpLighten operator = C.CAIRO_OPERATOR_LIGHTEN //OpColorDodge brightens the destination color to reflect the source color. OpColorDodge operator = C.CAIRO_OPERATOR_COLOR_DODGE //OpColorBurn darkens the destination color to reflect the source color. OpColorBurn operator = C.CAIRO_OPERATOR_COLOR_BURN //OpHardLight multiplies or screens, dependent on source color. OpHardLight operator = C.CAIRO_OPERATOR_HARD_LIGHT //OpSoftLight darkens or lightens, dependent on source color. OpSoftLight operator = C.CAIRO_OPERATOR_SOFT_LIGHT //OpDifference takes the difference of the source and destination color. OpDifference operator = C.CAIRO_OPERATOR_DIFFERENCE //OpExclusion produces an effect similar to difference, but with lower contrast. OpExclusion operator = C.CAIRO_OPERATOR_EXCLUSION //OpHueHSL creates a color with the hue of the source and the saturation //and luminosity of the target. OpHueHSL operator = C.CAIRO_OPERATOR_HSL_HUE //OpSaturationHSL creates a color with the saturation of the source //and the hue and luminosity of the target. //Painting with this mode onto a gray area produces no change. OpSaturationHSL operator = C.CAIRO_OPERATOR_HSL_SATURATION //OpColorHSL creates a color with the hue and saturation of the source //and the luminosity of the target. //This preserves the gray levels of the target and useful for coloring //monochrome images or tinting color images. OpColorHSL operator = C.CAIRO_OPERATOR_HSL_COLOR //OpLuminosityHSL creates a color with the luminosity of the source //and the hue and saturation of the target. //This produces an inverse effect to OpColorHSL. OpLuminosityHSL operator = C.CAIRO_OPERATOR_HSL_LUMINOSITY )
An operator sets the compositing operator for all cairo drawing operations.
The operators marked as unbounded modify their destination even outside of the mask layer (that is, their effect is not bound by the mask layer). However, their effect can still be limited by way of clipping.
To keep things simple, the operator descriptions here document the behavior for when both source and destination are either fully transparent or fully opaque. The actual implementation works for translucent layers too. For a more detailed explanation of the effects of each operator, including the mathematical definitions, see http://cairographics.org/operators/ .
Originally cairo_operator_t.
const ( //PatternTypeSolid represents a uniform color, which may be opaque //or translucent. PatternTypeSolid = C.CAIRO_PATTERN_TYPE_SOLID //PatternTypeSurface represents a pattern defined by a Surface. PatternTypeSurface = C.CAIRO_PATTERN_TYPE_SURFACE //PatternTypeLinear represents a pattern that is a linear gradient. PatternTypeLinear = C.CAIRO_PATTERN_TYPE_LINEAR //PatternTypeRadial represents a pattern that is a radial gradient. PatternTypeRadial = C.CAIRO_PATTERN_TYPE_RADIAL //PatternTypeMesh represents a pattern defined by a mesh. PatternTypeMesh = C.CAIRO_PATTERN_TYPE_MESH //PatternTypeRasterSource is a user pattern providing raster data. // //A raster pattern also has a Subtype. PatternTypeRasterSource = C.CAIRO_PATTERN_TYPE_RASTER_SOURCE )
A patternType describes the type of a given pattern.
Originally cairo_pattern_type_t
const ( //PathMoveTo is a move-to operation. PathMoveTo pathDataType = C.CAIRO_PATH_MOVE_TO //PathLineTo is a line-to operation. PathLineTo pathDataType = C.CAIRO_PATH_LINE_TO //PathCurveTo is a curve-to operation. PathCurveTo pathDataType = C.CAIRO_PATH_CURVE_TO //PathClosePath is a close-path operation. PathClosePath pathDataType = C.CAIRO_PATH_CLOSE_PATH )
A pathDataType is used to describe the type of one portion of a path when represented as a Path.
Originally cairo_path_data_type_t.
const ( //SubpixelOrderDefault uses the default subpixel order for the target device. SubpixelOrderDefault subpixelOrder = C.CAIRO_SUBPIXEL_ORDER_DEFAULT //SubpixelOrderRGB organizes subpixels horizontally with red at the left. SubpixelOrderRGB subpixelOrder = C.CAIRO_SUBPIXEL_ORDER_RGB //SubpixelOrderBGR organizes supixels horizontally with blue at the left. SubpixelOrderBGR subpixelOrder = C.CAIRO_SUBPIXEL_ORDER_BGR //SubpixelOrderVRGB organizes supixels vertically with red on top. SubpixelOrderVRGB subpixelOrder = C.CAIRO_SUBPIXEL_ORDER_VRGB //SubpixelOrderVBGR organizes supixels vertically with blue on top. SubpixelOrderVBGR subpixelOrder = C.CAIRO_SUBPIXEL_ORDER_VBGR )
Originally cairo_subpixel_order_t.
const ( //SurfaceTypeImage is an image surface. SurfaceTypeImage surfaceType = C.CAIRO_SURFACE_TYPE_IMAGE //SurfaceTypePDF is a PDF surface. SurfaceTypePDF surfaceType = C.CAIRO_SURFACE_TYPE_PDF //SurfaceTypePS is a PS surface. SurfaceTypePS surfaceType = C.CAIRO_SURFACE_TYPE_PS //SurfaceTypeXLib is an X lib surface. SurfaceTypeXLib surfaceType = C.CAIRO_SURFACE_TYPE_XLIB //SurfaceTypeXCB is an XCB surface. SurfaceTypeXCB surfaceType = C.CAIRO_SURFACE_TYPE_XCB //SurfaceTypeGlitz is a Glitz surface. SurfaceTypeGlitz surfaceType = C.CAIRO_SURFACE_TYPE_GLITZ //SurfaceTypeQuartz is a Quartz surface. SurfaceTypeQuartz surfaceType = C.CAIRO_SURFACE_TYPE_QUARTZ //SurfaceTypeScript is a script surface. SurfaceTypeScript surfaceType = C.CAIRO_SURFACE_TYPE_SCRIPT //SurfaceTypeWin32 is a Win32 surface SurfaceTypeWin32 surfaceType = C.CAIRO_SURFACE_TYPE_WIN32 //SurfaceTypeBeOS is a BeOS surface. SurfaceTypeBeOS surfaceType = C.CAIRO_SURFACE_TYPE_BEOS //SurfaceTypeDirectFB is a DirectFB surface. SurfaceTypeDirectFB surfaceType = C.CAIRO_SURFACE_TYPE_DIRECTFB //SurfaceTypeSVG is an SVG surface. SurfaceTypeSVG surfaceType = C.CAIRO_SURFACE_TYPE_SVG //SurfaceTypeOS2 is an OS/2 surface. SurfaceTypeOS2 surfaceType = C.CAIRO_SURFACE_TYPE_OS2 //SurfaceTypeWin32Printing is a Win32 printing surface. SurfaceTypeWin32Printing surfaceType = C.CAIRO_SURFACE_TYPE_WIN32_PRINTING //SurfaceTypeQuartzImage is a Quartz image surface. SurfaceTypeQuartzImage surfaceType = C.CAIRO_SURFACE_TYPE_QUARTZ_IMAGE //SurfaceTypeQT is a QT surface. SurfaceTypeQT surfaceType = C.CAIRO_SURFACE_TYPE_QT //SurfaceTypeRecording is a recording surface. SurfaceTypeRecording surfaceType = C.CAIRO_SURFACE_TYPE_RECORDING //SurfaceTypeVG is a VG surface. SurfaceTypeVG surfaceType = C.CAIRO_SURFACE_TYPE_VG //SurfaceTypeGL is an OpenGL surface. SurfaceTypeGL surfaceType = C.CAIRO_SURFACE_TYPE_GL //SurfaceTypeDRM is a DRM surface. SurfaceTypeDRM surfaceType = C.CAIRO_SURFACE_TYPE_DRM //SurfaceTypeTee is a tee surface. SurfaceTypeTee surfaceType = C.CAIRO_SURFACE_TYPE_TEE //SurfaceTypeXML is an XML surface. SurfaceTypeXML surfaceType = C.CAIRO_SURFACE_TYPE_XML //SurfaceTypeSkia is a Skia surface. SurfaceTypeSkia surfaceType = C.CAIRO_SURFACE_TYPE_SKIA //SurfaceTypeSubsurface is a subsurface. SurfaceTypeSubsurface surfaceType = C.CAIRO_SURFACE_TYPE_SUBSURFACE //SurfaceTypeCogl is a Cogl surface. SurfaceTypeCogl surfaceType = C.CAIRO_SURFACE_TYPE_COGL )
A surfaceType describes the type of a given surface. The surface types are also known as "backends" or "surface backends" within cairo.
Originally cairo_surface_type_t.
Variables ¶
var ( ColorModel = color.ModelFunc(func(c color.Color) color.Color { if c, ok := c.(Color); ok { return c } if c, ok := c.(AlphaColor); ok { return Color{c.R, c.G, c.B} } r, g, b, _ := c.RGBA() return Color{cto01(r), cto01(g), cto01(b)} }) AlphaColorModel = color.ModelFunc(func(c color.Color) color.Color { if c, ok := c.(AlphaColor); ok { return c } if c, ok := c.(Color); ok { return AlphaColor{c.R, c.G, c.B, 1} } r, g, b, a := c.RGBA() return AlphaColor{cto01(r), cto01(g), cto01(b), cto01(a)} }) )
These models can convert any color.Color to themselves.
The conversion may be lossy.
var ( Black = Color{} White = Color{1, 1, 1} Red = Color{R: 1} Green = Color{G: 1} Blue = Color{B: 1} Transparent = AlphaColor{} )
Basic colors.
var ( //ErrInvalidLibcairoHandle is returned if a Go handle to a libcairo resource //has no pointer to any libcairo resource. ErrInvalidLibcairoHandle = errors.New("invalid handle to libcairo resource") //ErrInvalidPathData is returned if a Path contains undefined data. ErrInvalidPathData = mkerr(errInvalidPathData) //ErrInvalidDash is returned by Context.SetDash if the dash format //is ill-specified. ErrInvalidDash = mkerr(errInvalidDash) )
var XtensionCairoWriteFuncT = C.callback_getter()
XtensionCairoWriteFuncT is a cairo_write_func_t that expects as its closure argument the result of calling XtensionWrapWriter on a Writer. The surface or device created with this pair must be used to register the wrapped Writer with that objects XtensionRegisterWriter method.
Anything less will cause at best memory leaks and at worst random errors.
See XtensionWrapWriter for more information.
Functions ¶
func XtensionGlyphsGotoC ¶
XtensionGlyphsGotoC converts a []Glyph into an array of cairo_glyph_t.
The returned array has been created with malloc unless useGlyphAllocate is true, in which case cairo_glyph_allocate is used instead. Unless the cairo_glyph_t is meant to be used with a user font, useGlyphAllocate must be false.
func XtensionRegisterAlienRasterPatternSubtype ¶
func XtensionRegisterAlienRasterPatternSubtype(name string, fac func(*C.cairo_pattern_t) (Pattern, error))
XtensionRegisterAlienRasterPatternSubtype registers a factory to create a Go wrapper an existing libcairo raster pattern and associates it with a unique name, retrievable via Subtype.
After the subtype is registered, instances MUST be registered with XtensionRegisterAlienRasterPattern.
func XtensionRegisterAlienUserFontSubtype ¶
func XtensionRegisterAlienUserFontSubtype(name string, fac func(*C.cairo_font_face_t) (Font, error))
XtensionRegisterAlienUserFontSubtype registers a factory to create a Go wrapper around an existing libcairo user font and associates it with a unique name, retrievable via Subtype.
After the subtype is registered, instances MUST be registered with XtensionRegisterAlienUserFont.
func XtensionRegisterRawToDevice ¶
func XtensionRegisterRawToDevice(d deviceType, f func(*C.cairo_device_t) (Device, error))
XtensionRegisterRawToDevice registers a factory to convert a libcairo device into a properly formed Device of the proper underlying type.
If no factory is registered a default XtensionDevice will be returned.
func XtensionRegisterRawToFont ¶
func XtensionRegisterRawToFont(t fontType, f func(*C.cairo_font_face_t) (Font, error))
XtensionRegisterRawToFont registers a factory to convert a libcairo font face into a properly formed cairo Font of the appropriate underlying type.
It is mandatory for extensions defining new font types to call this during init, otherwise users will get random not implemented panics for your font.
For user fonts you must use XtensionRegisterUserAlienFontSubtype.
func XtensionRegisterRawToSurface ¶
func XtensionRegisterRawToSurface(t surfaceType, f func(*C.cairo_surface_t) (Surface, error))
XtensionRegisterRawToSurface registers a factory to convert a libcairo surface into a properly formed cairo Surface of the appropriate type.
It is mandatory for extensions defining new surface types to call this function during init, otherwise users will get random not implemented panics for your surface.
func XtensionTextClustersGotoC ¶
func XtensionTextClustersGotoC(tcs []TextCluster, useTextClusterAllocator bool) (cs *C.cairo_text_cluster_t, N C.int)
XtensionTextClustersGotoC converts a []TextCluster into an array of cairo_text_cluster_t.
The returned array has been created with malloc unless useTextClusterAllocator is true, in which case cairo_text_cluster_allocate is used instead. Unless the resultant array is to be used with a user font, useTextClusterAllocator must be false.
func XtensionWrapWriter ¶
XtensionWrapWriter wraps a writer in a special container to communicate with libcairo.
It also stores the returned value so that it is not garbage collected.
You must use this along with XtensionCairoWriteFuncT when wrapping any of libcairo's _create_for_stream factories.
After the surface or device is created the returned pointer must be registered with the surface or device using its XtensionRegisterWriter method.
Example ¶
Say you wanted to wrap an X surface created with cairo_X_surface_create_for_stream.
In the factory for your Go surface, you need code like the following:
wrapped := cairo.XtensionWrapWriter(iowriter) s := C.cairo_X_surface_create_for_stream(cairo.XtensionCairoWriteFuncT, wrapped) S := cairo.NewXtensionSurface(s) S.XtensionRegisterWriter(wrapped)
Types ¶
type AlphaColor ¶
type AlphaColor struct {
R, G, B, A float64
}
AlphaColor represents an RGBA color where each component is in [0,1].
func (AlphaColor) Canon ¶
func (a AlphaColor) Canon() AlphaColor
Canon returns a new color with all values clamped to [0,1].
func (AlphaColor) Color ¶
func (a AlphaColor) Color() Color
Color returns a without the alpha channel.
func (AlphaColor) RGBA ¶
func (a AlphaColor) RGBA() (r, g, b, alpha uint32)
type Circle ¶
A Circle contains the points swept out by Radius from Center.
It is well-formed if the Radius is nonnegative.
type Color ¶
type Color struct {
R, G, B float64
}
Color represents an RGB color where each component is in [0, 1].
func (Color) Alpha ¶
func (c Color) Alpha(alpha float64) AlphaColor
Alpha returns c with an alpha channel set to alpha.
type ColorStop ¶
type ColorStop struct { //Offset specifies the location of this color stop along the gradient's //control vector. Offset float64 Color color.Color }
A ColorStop is the color of a single gradient stop.
Note that when defining gradients it two, or more, stops are specified with identical offset values, they will be sorted according to the order in which the stops are added. Stops added earlier will compare less than stops added later. This can be useful for reliably making sharp color transitions instead of the typical blend.
type Content ¶
type Content int
Content is used to describe the content that a surface will contain, whether color information, alpha (translucence vs. opacity), or both.
Note that this type is only exposed as some extensions require it and that ¶
Originally cairo_content_t.
const ( //ContentColor specifies that the surface will hold color content only. ContentColor Content = C.CAIRO_CONTENT_COLOR //ContentAlpha specifies that the surface will hold alpha content only. ContentAlpha Content = C.CAIRO_CONTENT_ALPHA //ContentColorAlpha specifies that the surface will hold color and alpha //content. ContentColorAlpha Content = C.CAIRO_CONTENT_COLOR_ALPHA )
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
The Context is the main object used when drawing with cairo.
Defaults ¶
The default compositing operator is OpOver.
The default source pattern is equivalent to
cairo.NewSolidPattern(color.Black)
The default fill rule is FillRuleWinding.
The default line cap rule is LineCapButt.
The default line join is LineJoinMiter.
The default line width is 2.
The default miter limit is 10.
The default operator is OpOver.
The default tolerance is 0.1.
The default font size is 10.
The default font slant is SlantNormal.
The default font weight is WeightNormal.
The default font family is platform-specific but typically "sans-serif", using the toy font api.
Originally cairo_t.
func New ¶
New creates a new drawing context that draws on the target surface.
Originally cairo_create.
func (*Context) AntialiasMode ¶
func (c *Context) AntialiasMode() antialias
AntialiasMode reports the current shape antialiasing mode.
Originally cairo_get_antialias.
func (*Context) AppendPath ¶
AppendPath appends path onto the current path of c.
Originally cairo_append_path.
func (*Context) Arc ¶
Arc adds a circular arc along the surface of circle from fromAngle increasing to toAngle.
If fromAngle < toAngle, then toAngle will be increased by 2π until fromAngle > toAngle.
If there is a current point, an initial line segment will be added to the path to connect the current point to the beginning of the arc. If this initial line is undesired, call ClosePath before Arc.
Angles are measured in radians. An angle of 0 is in the direction of the positive X axis in user space. An angle of π/2 radians (90°) is in the direction of the positive Y axis in user space. With the default transformation matrix, angles increase clockwise.
To convert from degrees to radians use
degrees * π/180
Arc gives the arc in the direction of increasing angles. Use ArcNegative to get the arc in the direction of decreasing angles.
The arc is circular in user space.
Originally cairo_arc.
func (*Context) ArcNegative ¶
ArcNegative adds a circular arc along the surface of circle from fromAngle decreasing to toAngle.
If fromAngle > toAngle, then toAngle will be dereased by 2π until fromAngle < toAngle.
ArcNegative gives the arc in the direction of decreasing angles. Use Arc to get the arc in the direction of increasing angles.
Originally cairo_arc_negative.
func (*Context) Circle ¶
Circle is shorthand for calling Arc from 0 to 2π.
Example (DrawEllipse) ¶
is, err := NewImageSurface(FormatARGB32, 500, 500) if err != nil { log.Fatalln(err) } c, err := New(is) if err != nil { log.Fatalln(err) } //To achieve an elliptical arc, you can scale the current transformation //matrix by different amounts in the X and Y directions. //This draws an ellipse in the box given by Rectangle r. r := Rect(0, 0, 50, 60) c.SaveRestore(func(c *Context) error { mid := r.Size().Div(2) c. Translate(r.Min.Add(mid)). Scale(mid). Circle(UC) return nil })
Output:
func (*Context) Clip ¶
Clip establishes a new clip region by intersecting the current clip region with the current path as it would be filled by Fill and according to the current fill rule.
After Clip, the current path will be cleared from the cairo context.
The current clip region affects all drawing operations by effectively masking out any changes to the surface that are outside the current clip region.
Clip can only make the clip region smaller, never larger. But the current clip is part of the graphics state, so a temporary restriction of the clip region can be achieved by calling Clip within a Save/Restore pair. The only other means of increasing the size of the clip region is ResetClip.
Originally cairo_clip.
func (*Context) ClipExtents ¶
ClipExtents computes a bounding box in user coordinates covering the area inside the current clip.
Originally cairo_clip_extents.
func (*Context) ClipPreserve ¶
ClipPreserve is identical Clip but preserves the path in c.
Originally cairo_clip_preserve.
func (*Context) ClipRectangles ¶
ClipRectangles reports the current clip region as a list of rectangles in user coordinates or an error if the clip region cannot be so represented.
Originally cairo_copy_clip_rectangle_list.
func (*Context) ClosePath ¶
ClosePath adds a line segment from the current point to the beginning of the current sub-path and closes the sub-path. After this call the current point will be at the joined endpoint of the sub-path.
The behavior of ClosePath is distinct from simply calling LineTo with the equivalent coordinate in the case of stroking. When a closed sub-path is stroked, there are no caps on the ends of the sub-path. Instead, there is a line join connecting the final and initial segments of the sub-path.
If there is no current point, this method will have no effect.
ClosePath will place an explicit PathMoveTo following the PathClosePath into the current path.
func (*Context) CopyPage ¶
CopyPage emits the current page for backends that support multiple pages, but doesn't clear it, so, the contents of the current page will be retained for the next page too.
Use ShowPage if you want to get an empty page after the emission.
This is a convenience function that simply calls CopyPage on c's target.
Originally cairo_copy_page.
func (*Context) CopyPathFlat ¶
CopyPathFlat returns a linearized copy of the current path.
CopyPathFlat behaves like CopyPath except that any curves in the path will be approximated with piecewise-linear approximations, accurate to within the current tolerance value. That is, the result is guaranteed to not have any elements of type PathCurveTo which will instead be replaced by a series of PathLineTo elements.
Originally cairo_copy_path_flat.
func (*Context) CurrentPoint ¶
CurrentPoint reports the current point of the current path. The current point is, conceptually, the final point reached by the path so far.
The current point is returned in the user-space coordinate system.
If there is no defined current point, or if c is in an error state, (ZP, false) will be returned. Otherwise the (cp, true) will be returned where cp is the current point.
Most path constructions alter the current point.
Some functions use and alter the current point, but do not otherwise change the current path, see ShowText.
Some functions unset the current path, and, as a result, the current point, such as Fill.
Originally cairo_has_current_point and cairo_get_current_point.
func (*Context) CurveTo ¶
CurveTo adds a cubic Bézier spline to the path from the current point to p3 in user space coordinates, using p1 and p2 as the control points. After calling CurveTo, the current point will be p3.
If there is no current point, CurveTo will behave as if preceded by a call to MoveTo(p1)
Originally cairo_curve_to.
func (*Context) DashCount ¶
DashCount reports the length of the dash sequence or 0 if dashing is not currently in effect.
Originally cairo_get_dash_count.
func (*Context) Dashes ¶
Dashes reports the current dash sequence. If dashing is not currently in effect the length of dashes is 0.
Originally cairo_get_dash
func (*Context) DeviceToUser ¶
DeviceToUser takes the point p from device space to the point q in user space by multiplication with the inverse of the current transformation matrix.
Originally cairo_device_to_user.
func (*Context) DeviceToUserDistance ¶
DeviceToUserDistance transforms a distance vector v from device to user space. This method is similar to DeviceToUser, except that the translation components of the current transformation matrix will be ignored.
Originally cairo_device_to_user_distance.
func (*Context) Fill ¶
Fill fills the current path according to the current fill rule, (each sub-path is implicitly closed before being filled). After fill, the current path will be cleared from the cairo context.
Originally cairo_fill.
func (*Context) FillExtents ¶
FillExtents computes a bounding box in user coordinates covering the area that would be affected, (the "inked" area), by a Fill operation given the current path and fill parameters. If the current path is empty, it returns ZR. Surface dimensions and clipping are not taken into account.
Contrast with PathExtents, which is similar, but returns non-zero extents for some paths with no inked area, (such as a simple line segment).
FillExtents must necessarily do more work to compute the precise inked areas in light of the fill rule, so PathExtents may be more desirable for sake of performance if the non-inked path extents are desired.
Originally cairo_fill_extents.
func (*Context) FillPreserve ¶
FillPreserve is identical to Fill except it does not clear the current path.
Originally cairo_fill_preserve.
func (*Context) FillRule ¶
func (c *Context) FillRule() fillRule
FillRule reports the current fill rule.
Originally cairo_get_fill_rule.
func (*Context) FontExtents ¶
func (c *Context) FontExtents() FontExtents
FontExtents returns the extents of the currently selected font.
Originally cairo_font_extents.
func (*Context) FontMatrix ¶
FontMatrix reports the current font matrix.
Originally cairo_get_font_matrix.
func (*Context) FontOptions ¶
func (c *Context) FontOptions() *FontOptions
FontOptions reports the current font options of c.
Originally cairo_get_font_options.
func (*Context) GlyphExtents ¶
func (c *Context) GlyphExtents(glyphs []Glyph) TextExtents
GlyphExtents reports the extents for glyphs.
The extents describe a user-space rectangle that encloses the "inked" portion of the text, as it would be drawn with ShownText. Additionally, the x_advance and y_advance values indicate the amount by which the current point would be advanced by ShowText.
Note that whitespace characters do not directly contribute to the size of the rectangle (extents.Width and extents.Height), but they do contribute indirectly by changing the position of non-whitespace characters. In particular, trailing whitespace characters are likely to not affect the size of the rectangle, though they will affect the AdvanceX and AdvanceY values.
Originally cairo_glyph_extents.
func (*Context) GlyphPath ¶
GlyphPath adds a closed path for the glyphs to the current path. The generated path, if filled, achieves an effect similar to that of ShowGlyphs.
Originally cairo_glyph_path.
func (*Context) GroupTarget ¶
GroupTarget returns the current destination surface for c. If there have been no calls to PushGroup/PushGroupWithContent, this is equivalent to Target. Otherwise, Originally cairo_get_group_target.
func (*Context) InClip ¶
InClip reports whether pt is in the currently visible area defined by the clipping region.
Originally cairo_in_clip.
func (*Context) InFill ¶
InFill reports whether the given point is inside the area that would be affected by a Fill, given the current path and filling parameters. Surface dimensions and clipping are not taken into account.
Originally cairo_in_fill.
func (*Context) InStroke ¶
InStroke reports whether the given point is inside the area that would be affected by a Stroke operation given the current path and stroking parameters. Surface dimensions and clipping are not taken into account.
Originally cairo_in_stroke.
func (*Context) LineCap ¶
func (c *Context) LineCap() lineCap
LineCap reports the current line cap.
Originally cairo_get_line_cap.
func (*Context) LineJoin ¶
func (c *Context) LineJoin() lineJoin
LineJoin reports the current line join style.
Originally cairo_get_line_join.
func (*Context) LineTo ¶
LineTo adds a line to the path from the current point to p in user space coordinates.
If there is no current point, LineTo will behave as if preceded by a call to MoveTo(p)
Originally cairo_line_to.
func (*Context) LineWidth ¶
LineWidth reports the line width as set by SetLineWidth and does not take any intervening changes to the coordinate transform matrix into account.
Originally cairo_get_line_width
func (*Context) Mask ¶
Mask paints the current source using the alpha channel of pattern as a mask. Opaque areas of pattern are painted with the source, transparent areas are not painted.
Originally cairo_mask.
func (*Context) MaskSurface ¶
MaskSurface paints the current source using the alpha channel of surface as a mask. Opaque areas of surface are painted with the source, transparent areas are not painted.
Originally cairo_mask_surface.
func (*Context) Matrix ¶
Matrix returns the current transformation matrix.
Originally cairo_get_matrix.
func (*Context) MiterLimit ¶
MiterLimit returns the current miter limit as set by SetMiterLimit.
Originally cairo_get_miter_limit.
func (*Context) MoveTo ¶
MoveTo begins a new sub-path and sets the current point to p.
Originally cairo_move_to.
func (*Context) NewPath ¶
NewPath clears the current path and, by extension, the current point.
Originally cairo_new_path.
func (*Context) NewSubPath ¶
NewSubPath begins a new sub-path. The existing path is not affected, but the current point is cleared.
In many cases, this is not needed since new sub-paths are frequently started with MoveTo.
NewSubPath is particularly useful when beginning a new sub-path with one of the Arc calls, as, in this case, it is no longer necessary to manually computer the arc's inital coordinates for use with MoveTo.
Originally cairo_new_sub_path.
func (*Context) Operator ¶
func (c *Context) Operator() operator
Operator reports the current compositing operator.
Originally cairo_get_operator.
func (*Context) Paint ¶
Paint paints the current source everywhere within the current clip region.
originally cairo_paint.
func (*Context) PaintAlpha ¶
PaintAlpha paints the current source everywhere within the current clip region, using a mask of constant alpha value alpha.
The effect is similar to Paint, but the drawing is faded out using the alpha value.
originally cairo_paint.
func (*Context) PathExtents ¶
PathExtents computes a bounding box in user-space coordinates covering the points on the current path. If the current path is empty, returns ZR. Stroke parameters, fill rule, surface dimensions and clipping are not taken into account.
PathExtents is in contrast to FillExtents and StrokeExtents which return the extents of only the area that would be "inked" by the corresponding drawing operations.
The result of PathExtents is defined as equivalent to the limit of StrokeExtents with LineCapRound as the line width approaches 0, but never approaching the empty rectangle returned by StrokeExtents for a line width of 0.
Specifically, this means that zero-area sub-paths such as MoveTo contribute to the extents. However, a lone MoveTo will not contribute to the results of PathExtents.
Originally cairo_path_extents.
func (*Context) PopGroup ¶
PopGroup terminates the redirection begun by a call to PushGroup or PushGroupWithContent and returns a new Pattern.
The drawing state of c is reset to what it was before the call to PushGroup/PushGroupWithContent.
See the documentation for PushGroup for more information.
Originally cairo_pop_group.
func (*Context) PopGroupToSource ¶
PopGroupToSource terminates the redirection begun by a call to PushGroup or PushGroupWithContent and installs the resultant pattern as the source pattern in c.
The drawing state of c is reset to what it was before the call to PushGroup/PushGroupWithContent.
It is a convenience method equivalent to
func PopGroupToSource(c *Context) error { p, err := c.PopGroup() if err != nil { return err } c.SetSource(p) return p.Close() }
See the documentation for PushGroup for more information.
Originally cairo_pop_group_to_source.
func (*Context) PushGroup ¶
PushGroup temporarily redirects drawing to an intermediate surface known as a group. The redirection lasts until the group is completed by a call to PopGroup or PopGroupToSource. These calls provide the result of any drawing to the group as a pattern, either as an explicit object or set as the source pattern.
This group functionality can be convenient for performing intermediate compositing. One common use of a group is to render objects as opaque within the group, so that they occlude each other, and then blend the result with translucence onto the destination.
Groups can be nested arbitrarily deep by making balanced calls to PushGroup and PopGroup/PopGroupToSource. Each call pushes/pops the new target group onto/from a stack.
Like Save, any changes to the drawing state following PushGroup will not be visible after a call to PopGroup/PopGroupToSource.
By default, this intermediate group will have a content type of ContentColorAlpha. Other content types may be specified by calling PushGroupWithContent instead.
An example of a translucent filled and stroked path without any portion of the visible under the stroke:
c.PushGroup(). SetSource(fillPattern). FillPreserve(). SetSource(strokePattern). Stroke(). PopGroupToSource() c.PaintWithAlpha(alpha)
Originally cairo_push_group.
func (*Context) PushGroupWithContent ¶
PushGroupWithContent is similar to PushGroup except for additionally setting the content of the group.
See the documentation for PushGroup for more information.
Originally cairo_push_group_with_content.
func (*Context) Rectangle ¶
Rectangle adds a closed sub-path rectangle to the current path at position r.Min in user-space coordinates.
This function is logically equivalent to:
c.MoveTo(r.Min) c.LineTo(Pt(r.Dx(), 0)) c.LineTo(Pt(0, r.Dy())) c.LineTo(Pt(-r.Dx(), 0)) c.ClosePath()
Originally cairo_rectangle.
func (*Context) RelCurveTo ¶
RelCurveTo is a relative-coordinate version of CurveTo. All points are considered as vectors with an origin at the current point.
If there is no current point, c is now in an error state.
It is equivalent to
if p, ok := c.CurrentPoint(); ok { c.CurveTo(p.Add(v1), p.Add(v2), p.Add(v3)) } else { // c is broken now }
Originally cairo_rel_curve_to.
func (*Context) RelLineTo ¶
RelLineTo is a relative-coordinate version of LineTo. The point v is considered a vector with the origin at the current point.
If there is no current point, c is now in an error state.
It is equivalent to
if p, ok := c.CurrentPoint(); ok { c.LineTo(p.Add(v)) } else { // c is broken now }
Originally cairo_rel_line_to.
func (*Context) RelMoveTo ¶
RelMoveTo begins a new sub-path. After this call the current point will be offset by v.
If there is no current point, c is now in an error state.
It is equivalent to
if p, ok := c.CurrentPoint(); ok { c.Move(p.Add(v)) } else { // c is broken now }
Originally cairo_rel_move_to.
func (*Context) ResetClip ¶
ResetClip resets the current clip region to its original, unrestricted state. That is, set the clip region to an infinitely large shape containing the target surface. Equivalently, one can imagine the clip region being reset to the exact bounds of the target surface.
Note that code meant to be reusable should not call ResetClip as it will cause results unexpected by higher-level code which calls ResetClip. Consider using Save and Restore around Clip as a more robust means of temporarily restricting the clip region.
Originally cairo_reset_clip.
func (*Context) ResetMatrix ¶
ResetMatrix resets the current transformation matrix to the identity matrix.
Originally cairo_identity_matrix.
func (*Context) Restore ¶
Restore the last drawing state saved with Save and remove that state from the stack of saved states.
It is malformed to call Restore without a previous call to Save.
Originally cairo_restore.
func (*Context) Rotate ¶
Rotate the current transformation matrix by θ by rotating the user-space axes. The rotation of the axes takes places after any existing transformation of user space. The rotation direction for positive angles is from the positive X axis toward the positive Y axis.
Originally cairo_rotate.
func (*Context) Save ¶
Save makes a copy of the current drawing state on an internal stack of drawing states.
Further calls on c will affect the current state but no saved states. A call to Restore returns c to the state it was in at the last invocation of Save.
Originally cairo_save.
func (*Context) SaveRestore ¶
SaveRestore saves the current drawing state, runs f on c, and then restores the current drawing state.
func (*Context) Scale ¶
Scale scales the current transformation matrix by v by scaling the user-space axes by v.X and v.Y. The scaling of the axes takes place after any existing transformation of user space.
Originally cairo_scale.
func (*Context) ScaledFont ¶
func (c *Context) ScaledFont() (*ScaledFont, error)
ScaledFont reports the scaled font of c.
Originally cairo_get_scaled_font.
func (*Context) SelectFont ¶
SelectFont selects a family and style of font from a simplified description as a family name, slant and weight.
Libcairo provides no operation to list available family names on the system, as this is part of the toy api. The standard CSS2 generic family names, ("serif", "sans-serif", "cursive", "fantasy", "monospace"), are likely to work as expected.
If family starts with the string "cairo:", or if no native font backends are compiled in, libcairo will use an internal font family.
If text is drawn without a call to SelectFont or SetFont or SetScaledFont, the platform-specific default family is used, typically "sans-serif", and the default slant is SlantNormal and the default weight is WeightNormal.
For "real" see the font-backend-specific factor functions for the font backend you are using. The resulting font face could then be used with ScaledFontCreate and SetScaledFont.
Note ¶
SelectFont is part of the "toy" text API.
Originally cairo_select_font_face.
func (*Context) SetAntialiasMode ¶
SetAntialiasMode sets the antialiasing mode of the rasterizer used for drawing shapes. This value is a hint, and a particular backend may or may not support a particular value.
At the current time, no backend supports AntialiasSubpixel when drawing shapes.
SetAntialiasMode does not affect text rendering, instead use FontOptions.SetAntialiasMode.
Originally cairo_set_antialias.
func (*Context) SetDash ¶
SetDash sets the dash pattern to be used by Stroke.
A dash pattern is specified by a sequence of positive float64s.
Each float64 represents the length of alternating "on" and "off" portions of the stroke.
The offset specifies an offset into the pattern at which the stroke begins.
Each "on" segment will have caps applied as if the segment were a separate sub-path. It is valid to use an "on" length of 0 with LineCapRound or LineCapSquare in order to distribute dots or squares along a path.
Note ¶
The length values are in user-space units as evaluated at the time of stroking, which is not necessarily the same as the user space at the time SetDash is called.
Special Cases ¶
If the length of dashes is 0, dashing is disabled.
If the length of dashes is 1, a symmetric pattern is assumed, where the alternating off and on portions are of the single length provided. That is
SetDash(0, .5)
and
SetDash(0, .5, .5)
are equivalent.
Errors ¶
If any of the elements of dashes is negative or all are zero, ErrInvalidDash is returned and the dash is not set. This differs from libcairo, which puts c into an error mode.
Originally cairo_set_dash.
func (*Context) SetFillRule ¶
SetFillRule sets the fill rule on c. The fill rule is used to determine which regions are inside or outside a complex, potentially self-intersecting, path.
The fill rule affects Fill and Clip.
Originally cairo_set_fill_rule.
func (*Context) SetFont ¶
SetFont replaces the current font face of c with f.
Originally cairo_set_font_face.
func (*Context) SetFontMatrix ¶
SetFontMatrix sets the current font matrix to m. The font matrix gives a transformation from the design space of the font (in this space, the em-square is 1 unit by 1 unit) to user space.
Originally cairo_set_font_matrix.
func (*Context) SetFontOptions ¶
func (c *Context) SetFontOptions(opts *FontOptions) *Context
SetFontOptions sets the custom font rendering options for c. Rendering operations are derived by merging opts with the FontOptions of the underlying surface: if any of the options in opts is the default, the value of the surface is used.
Originally cairo_set_font_options.
func (*Context) SetFontSize ¶
SetFontSize sets the current font matrix to a scale by a factor of size, replacing any font matrix previously set with SetFontSize or SetFontMatrix.
Originally cairo_set_font_size.
func (*Context) SetLineWidth ¶
SetLineWidth sets the current line width. The line width specifies the diameter of a pen that is circular in user space, though the device space pen may be an ellipse due to shearing in the coordinate transform matrix. The user space and coordinate transform matrix referred to above are computed at stroke time, not at the time SetLineWidth is called.
Originally cairo_set_line_width.
func (*Context) SetMatrix ¶
SetMatrix sets the current transformation matrix to m.
Originally cairo_set_matrix.
func (*Context) SetMiterLimit ¶
SetMiterLimit sets the miter limit.
When the current line join style is LineJoinMiter, the miter limit is used to determine whether the lines should be joined with a bevel instead of a miter.
Cairo divides the length of the miter by the line width. If the result is greater than the miter limit, the style is converted to a bevel.
A miter limit for a given angle can be computed by:
miter limit = 1/sin(angle/2)
Examples ¶
For the default of 10, joins with interior angles less than 11 degrees are converted from miters to bevels.
For reference, a mite limit of 2 makes the miter cutoff at 60 degrees, and a miter limit of 1.414 makes the cutoff at 90 degrees.
Originally cairo_set_miter_limit.
func (*Context) SetOperator ¶
SetOperator sets the compositing operator used for all drawing operations.
Originally cairo_set_operator.
func (*Context) SetScaledFont ¶
func (c *Context) SetScaledFont(sf *ScaledFont) *Context
SetScaledFont replaces the current font face, font matrix, and font options with those of sf. Except for some translation, the current coordinate transforms matrix of c should be the same as that of sf.
Originally cairo_set_scaled_font.
func (*Context) SetSource ¶
SetSource sets the source pattern of c to source. This pattern will be used for any subsequent drawing operations, until a new source pattern is set.
Note ¶
The pattern's transformation matrix will be locked to the user space in effect at the time of SetSource. This means that further modifications of the current transformation matrix will not affect the source pattern. See Pattern.SetMatrix.
Originally cairo_set_source.
func (*Context) SetSourceColor ¶
SetSourceColor sets the source pattern to col. This color will be used for any subsequent drawing operations, until a new source pattern is set.
Originally cairo_set_source_rgba.
func (*Context) SetSourceSurface ¶
SetSourceSurface is a convenience function for creating a pattern from a surface and setting it as the source pattern in c with SetSource.
The originDisplacement vector gives the user-space coordinates at which the surface origin should appear. The surface origin is its upper-left corner before any transformation has been applied. The x and y components of the vector are negated and then set as the translation values in the pattern matrix.
Other than the initial pattern matrix, described above, all other pattern attributes are set to their default values. The resulting pattern can be retrieved by calling Source.
Originally cairo_set_source_surface.
func (*Context) SetTolerance ¶
SetTolerance sets the tolerance, in device units, when converting paths into trapezoids. Curved segments of the path will be subdivided until the maximum deviation between the original path and the polygonal approximation is less than tolerance.
A larger value than the default of 0.1 will give better performance. While in general a lower value improves appearance, it is unlikely a value lower than .1 will improve appearance significantly.
The accuracy of paths within libcairo is limited by the precision of its internal arithmetic and tolerance is restricted by the smallest representable internal value.
Originally cairo_set_tolerance.
func (*Context) ShowGlyphs ¶
ShowGlyphs draws a shape generated from gylphs rendered according to the current Font, font matrix, and FontOptions.
Originally cairo_show_glyphs.
func (*Context) ShowPage ¶
ShowPage emits and clears the current page for backends that support multiple pages.
Use CopyPage if you don't want to clear the page.
This is a convenience function that simply calls ShowPage on c's target.
Originally cairo_show_page.
func (*Context) ShowText ¶
ShowText draws a shape generated from s, rendered according to the current Font, font matrix, and FontOptions.
This method first computes a set of glyphs for the string of text. The first glyph is placed so that its origin is at the current point. The origin of each subsequent glyph is offset from that of the previous glyph by the advance values of the previous glyph.
After this call the current point is moved to the origin of where the next glyph would be placed in this same progression. That is, the current point will be at the origin of the final glyph offset by its advance values. This allows for easy display of a single logical string with multiple calls to ShowText.
Note ¶
ShowText is part of the toy api. See ShowGlyphs for the "real" text display api.
Originally cairo_show_text.
func (*Context) ShowTextGlyphs ¶
func (c *Context) ShowTextGlyphs(s string, glyphs []Glyph, clusters []TextCluster, flags TextClusterFlags) *Context
ShowTextGlyphs renders similarly to ShowGlyphs but, if the target surface support it, uses the provided text and cluster mapping to embed the text for the glyphs shown in the output. If the target surface does not support the extended attributes, this method behaves exactly as ShowGlyphs(glyphs).
The mapping between s and glyphs is provided by clusters. Each cluster covers a number of text bytes and glyphs, and neighboring clusters cover neighboring areas of s and glyphs. The clusters should collectively cover s and glyphs in entirety.
The first cluster always covers bytes from the beginning of s. If flags do not have TextClusterBackward set, the first cluster also covers the beginning of glyphs, otherwise it covers the end of the glyphs array and following clusters move backward.
Originally cairo_show_text_glyphs.
func (*Context) Source ¶
Source returns the current source pattern for c.
Originally cairo_get_source.
func (*Context) Stroke ¶
Stroke strokes the current path according to the current line width,
After Stroke, the current path will be cleared from the cairo context.
Degenerate segments and sub-paths are treated specially and provide a useful result. These can result in two different situations:
1. Zero-length "on" segments set in SetDash. If the cap style is LineCapRound or LineCapSquare then these segments will be drawn as circular dots or squares respectively. In the case of LineCapSquare, the orientation of the squares is determined by the direction of the underlying path.
2. A sub-path created by MoveTo followed by either a ClosePath or one or more calls to LineTo to the same coordinate as the MoveTo. If the cap style is LineCapRound then these sub-paths will be drawn as circular dots. Note that in the case of LineCapSquare a degenerate sub-path will not be drawn at all, as the correct orientation is indeterminate.
In no case will a cap style of LineCapButt cause anything to be drawn in the case of either degenerate segments or sub-paths.
Originally cairo_stroke.
func (*Context) StrokeExtents ¶
StrokeExtents computes a bounding box in user coordinates covering the area that would be affected, (the "inked" area), by a Stroke operation given the current path and stroke parameters. If the current path is empty, returns the empty rectangle ZR. Surface dimensions and clipping are not taken into account.
Note that StrokeExtents must necessarily do more work to compute the precise inked areas in light of the stroke parameters, so PathExtents may be more desirable for sake of performance if non-inked path extents are desired.
Originally cairo_stroke_extents.
func (*Context) StrokePreserve ¶
StrokePreserve is identical to Stroke except the path is not cleared.
Originally cairo_stroke_preserve.
func (*Context) TextExtents ¶
func (c *Context) TextExtents(s string) TextExtents
TextExtents reports the extents for s. The extents describe a user-space rectangle that encloses the "inked" portion of the text, as it would be drawn with ShownText. Additionally, the x_advance and y_advance values indicate the amount by which the current point would be advanced by ShowText.
Note that whitespace characters do not directly contribute to the size of the rectangle (extents.Width and extents.Height), but they do contribute indirectly by changing the position of non-whitespace characters. In particular, trailing whitespace characters are likely to not affect the size of the rectangle, though they will affect the AdvanceX and AdvanceY values.
Originally cairo_text_extents.
func (*Context) TextPath ¶
TextPath adds closed paths for text to the current path. The generated path if filled, achieves an effect similar to that of ShowText.
Text conversion and positioning is done similar to ShowText.
Like ShowText, After this call the current point is moved to the origin of where the next glyph would be placed in this same progression. hat is, the current point will be at the origin of the final glyph offset by its advance values. This allows for chaining multiple calls to to TextPath without having to set current point in between.
Note: The TextPath method is part of what the libcairo designers call the "toy" text API. It is convenient for short demos and simple programs, but it is not expected to be adequate for serious text-using applications. See GlyphPath for the "real" text path in cairo.
Originally cairo_text_path.
func (*Context) Tolerance ¶
Tolerance reports the tolerance in device units.
Originally cairo_get_tolerance.
func (*Context) Transform ¶
Transform applies m to the current transformation matrix as an additional transformation. The new transformation of user space takes place after any existing transformation.
Originally cairo_transform.
func (*Context) Translate ¶
Translate the current transformation matrix by vector v. This offset is interpreted as a user-space coordinate according to the CTM in place before the new call to Translate. In other words, the translation of the user-space origin takes place after any existing transformation.
Originally cairo_translate.
func (*Context) UserToDevice ¶
UserToDevice takes the point p from user space to the point q in device space by multiplication with the current transformation matrix.
Originally cairo_user_to_device.
func (*Context) UserToDeviceDistance ¶
UserToDeviceDistance transforms a distance vector v from user to device space. This method is similar to UserToDevice, except that the translation components of the current transformation matrix will be ignored.
Originally cairo_user_to_device_distance.
type Device ¶
type Device interface { Type() deviceType Err() error Close() error Lock() error Unlock() Flush() Equal(Device) bool //only for writing extensions. XtensionRaw() *C.cairo_device_t XtensionRegisterWriter(w unsafe.Pointer) // contains filtered or unexported methods }
A Device abstracts the rendering backend of a cairo surface.
Devices are created using custom functions specific to the rendering system you want to use.
An important function that devices fulfill is sharing access to the rendering system between libcairo and your application. If you want to access a device directly that you used to draw to with Cairo, you must first call Flush to ensure that Cairo finishes all operations on the device and resets it to a clean state.
Cairo also provides the Lock and Release methods to synchronize access to the rendering system in a multithreaded environment. This is done internally, but can also be used by applications.
Putting this all together a function that works with devices should often look like:
func WithDevice(d Device, work func(Device) error) (err error) { d.Flush() if err = d.Lock(); err != nil { return } defer d.Unlock() return work(d) }
All methods are documented on XtensionDevice.
func XtensionRegisterAlienDevice ¶
func XtensionRegisterAlienDevice(d *C.cairo_device_t) (Device, error)
XtensionRegisterAlienDevice registers a device created outside of this package and creates a Device of the proper type.
This is only necessary if you are using another library that creates its own libcairo device that will interact with this package.
type Font ¶
type Font interface { Type() fontType Close() error Err() error Subtype() string XtensionRaw() *C.cairo_font_face_t }
Font specifies all aspects of a font other than the size or font matrix.
All methods are documented on XtensionFont ¶
Originally cairo_font_face_t.
func XtensionRegisterAlienUserFont ¶
func XtensionRegisterAlienUserFont(subtype string, f *C.cairo_font_face_t) (Font, error)
XtensionRegisterAlienUserFont registers a libcairo user font with cairo.
The subtype must be registered XtensionRegisterAlienUserFontSubtype.
type FontExtents ¶
type FontExtents struct { //Ascent is the distance the font extends above the baseline. Ascent float64 //Descent is the distance the font extends below the baseline. Descent float64 //Height is the recommended vertical distance between baselines //when setting consecutive lines of text with the font. Height float64 //MaxAdvanceX is the maximum distance in the X direction that //the origin is advanced for any glyph in the font. // //Originally max_y_advance. MaxAdvanceX float64 //MaxAdvanceY is the maximum distance in the Y direction that //the origin is advanced for any glyph in the font. // //This will be zero for most fonts used for horizontal writing. // //Originally max_x_advance. MaxAdvanceY float64 }
FontExtents stores metric information for a font. Values are given in the current user-space coordinate system.
Because font metrics are in user-space coordinates, they are mostly, but not entirely, independent of the current transformation matrix. They will, however, change slightly due to hinting but otherwise remain unchanged.
Originally cairo_font_extents_t.
func XtensionFontExtentsCtoGo ¶
func XtensionFontExtentsCtoGo(fe C.cairo_font_extents_t) FontExtents
XtensionFontExtentsCtoGo converts a cairo_font_extent_t into a FontExtents value.
func (FontExtents) ExternalLeading ¶
func (f FontExtents) ExternalLeading() float64
ExternalLeading reports the difference between the Height and the sum of the Ascent and Descent. Also known as "line spacing".
func (FontExtents) XtensionRaw ¶
func (f FontExtents) XtensionRaw() C.cairo_font_extents_t
XtensionRaw returns f as a cairo_font_extents_t.
type FontOptions ¶
type FontOptions struct {
// contains filtered or unexported fields
}
FontOptions specify how fonts should be rendered. Most of the time the font options implied by a surface are just right and do not need changes, but, for pixel-based targets, tweaking font options may result in superior output on a particular display.
Originally cairo_font_options_t.
func NewFontOptions ¶
func NewFontOptions() *FontOptions
NewFontOptions creates a new FontOptions with the default values.
Originally cairo_font_options_create.
func (*FontOptions) AntialiasMode ¶
func (f *FontOptions) AntialiasMode() antialias
AntialiasMode reports the antialiasing mode of f.
Originally cairo_font_topns_get_antialias.
func (*FontOptions) Clone ¶
func (f *FontOptions) Clone() *FontOptions
Clone creates a new FontOptions with the same values as f.
Originally cairo_font_options_copy.
func (*FontOptions) Close ¶
func (f *FontOptions) Close() error
Close destroys the FontOptions. Close is idempotent.
Originally cairo_font_options_destroy.
func (*FontOptions) Equal ¶
func (f *FontOptions) Equal(o *FontOptions) bool
Equal compares f with o.
Originally cairo_font_options_equal.
func (*FontOptions) Err ¶
func (f *FontOptions) Err() error
Err queries f to see if there is an error.
Originally cairo_font_options_status.
func (*FontOptions) HintMetrics ¶
func (f *FontOptions) HintMetrics() hintMetrics
HintMetrics reports the hint metrics of f.
Originally cairo_font_options_get_hint_metrics.
func (*FontOptions) HintStyle ¶
func (f *FontOptions) HintStyle() hintStyle
HintStyle reports the hint style of f.
Originally cairo_font_options_get_hint_style.
func (*FontOptions) Merge ¶
func (f *FontOptions) Merge(o *FontOptions) *FontOptions
Merge merges non-default options from o into f and return f.
Originally cairo_font_options_merge.
func (*FontOptions) SetAntialiasMode ¶
func (f *FontOptions) SetAntialiasMode(a antialias) *FontOptions
SetAntialiasMode sets the antialiasing mode of f and returns f.
Originally cairo_font_options_set_antialias.
func (*FontOptions) SetHintMetrics ¶
func (f *FontOptions) SetHintMetrics(h hintMetrics) *FontOptions
SetHintMetrics sets the hint metrics of f and returns f.
Originally cairo_font_options_set_hint_metrics.
func (*FontOptions) SetHintStyle ¶
func (f *FontOptions) SetHintStyle(h hintStyle) *FontOptions
SetHintStyle sets the hint style of f and returns f.
Originally cairo_font_options_set_hint_style.
func (*FontOptions) SetSubpixelOrder ¶
func (f *FontOptions) SetSubpixelOrder(s subpixelOrder) *FontOptions
SetSubpixelOrder sets the subpixel ordering of f and returns f.
Originally cairo_font_options_set_subpixel_order.
func (*FontOptions) SubpixelOrder ¶
func (f *FontOptions) SubpixelOrder() subpixelOrder
SubpixelOrder reports the subpixel ordering of f.
Originally cairo_font_options_get_subpixel_order.
type Format ¶
type Format int
Format identifies the memory format of image data.
Originally cairo_format_t.
const ( //FormatInvalid specifies an unsupported or nonexistent format. FormatInvalid Format = C.CAIRO_FORMAT_INVALID //FormatARGB32 specifies that each pixel is a native-endian 32 bit quanity //listed as transparency, red, green, and then blue. FormatARGB32 Format = C.CAIRO_FORMAT_ARGB32 //zero value //FormatRGB24 is the same as FormatARGB32 but the 8-bits of transparency //are unused. FormatRGB24 Format = C.CAIRO_FORMAT_RGB24 //FormatA8 stores each pixel in an 8-bit quantity holding an alpha value. FormatA8 Format = C.CAIRO_FORMAT_A8 //FormatA1 stores each pixel in a 1-bit quantity holding an alpha value. FormatA1 Format = C.CAIRO_FORMAT_A1 //FormatRGB16_565 stores each pixel as a 16-bit quantity with 5 bits for //red, 6 bits for green, and 5 bits for blue. FormatRGB16_565 Format = C.CAIRO_FORMAT_RGB16_565 //FormatRGB30 is like FormatRGB24 but with 10 bits per pixel instead //of 8. FormatRGB30 Format = C.CAIRO_FORMAT_RGB30 )
type Glyph ¶
Glyph holds information about a single glyph when drawing or measuring text. A font is (in simple terms) a collection of shapes used to draw text. A glyph is one of these shapes. There can be multiple glyphs for a single character (alternates to be used in different contexts, for example), or a glyph can be a ligature of multiple characters. Cairo doesn't expose any way of converting input text into glyphs, so in order to use the Cairo interfaces that take arrays of glyphs, you must directly access the appropriate underlying font system.
Note that the offsets given by Point.X and Point.Y are not cumulative. When drawing or measuring text, each glyph is individually positioned with respect to the overall origin
Originally cairo_glyph_t.
func XtensionGlyphsCtoGo ¶
func XtensionGlyphsCtoGo(glyphs *C.cairo_glyph_t, N C.int) []Glyph
XtensionGlyphsCtoGo converts an array of cario_glyph_t to a []Glyph.
type Gradient ¶
type Gradient interface { Pattern ColorStops() []ColorStop // contains filtered or unexported methods }
Gradient is a linear or radial gradient.
type ImageSurface ¶
type ImageSurface struct { *XtensionSurface // contains filtered or unexported fields }
An ImageSurface is an in-memory surface.
func FromImage ¶
func FromImage(img image.Image) (ImageSurface, error)
FromImage copies an image into a surface.
The created image surface will have the same size as img, the optimal stride for img's width, and FormatARGB32.
Originally cairo_image_surface_create_for_data and cairo_format_stride_for_width.
func NewImageSurface ¶
func NewImageSurface(format Format, width, height int) (ImageSurface, error)
NewImageSurface creates an image surface of the given width, height, and format.
Originally cairo_image_surface_create.
func (ImageSurface) Format ¶
func (is ImageSurface) Format() Format
Format reports the format of the surface.
Originally cairo_image_surface_get_format.
func (ImageSurface) Height ¶
func (is ImageSurface) Height() int
Height reports the height of the surface in pixels.
Originally cairo_image_surface_get_height.
func (ImageSurface) Size ¶
func (is ImageSurface) Size() Point
Size returns the width and height of the image surface as a Point.
func (ImageSurface) Stride ¶
func (is ImageSurface) Stride() int
Stride reports the stride of the image surface in number of bytes.
Originally cairo_image_surface_get_stride.
func (ImageSurface) ToImage ¶
func (is ImageSurface) ToImage() (*image.RGBA, error)
ToImage returns a copy of the surface as an image.
Originally cairo_image_surface_get_data.
func (ImageSurface) Width ¶
func (is ImageSurface) Width() int
Width reports the width of the surface in pixels.
Originally cairo_image_surface_get_width.
type LinearGradient ¶
type LinearGradient struct {
// contains filtered or unexported fields
}
LinearGradient is a linear gradient pattern.
func NewLinearGradient ¶
func NewLinearGradient(start, end Point, colorStops ...ColorStop) LinearGradient
NewLinearGradient creates a new linear gradient, from start to end, with specified color stops.
Originally cairo_pattern_create_linear and cairo_pattern_add_color_stop_rgba.
func (LinearGradient) ColorStops ¶
func (p LinearGradient) ColorStops() (cs []ColorStop)
ColorStops reports the color stops defined on this gradient.
Originally cairo_pattern_get_color_stop_count and cairo_pattern_get_color_stop_rgba.
func (LinearGradient) Line ¶
func (l LinearGradient) Line() (start, end Point)
Line returns the start and end points of this linear gradient.
Originally cairo_pattern_get_linear_points.
type MappedImageSurface ¶
type MappedImageSurface struct {
ImageSurface
}
MappedImageSurface is a special ImageSurface created by Surface.Map.
func (MappedImageSurface) Close ¶
func (m MappedImageSurface) Close() error
Close always returns nil on a MappedImageSurface
func (MappedImageSurface) Unmap ¶
func (m MappedImageSurface) Unmap() error
Unmap uploads the content of the image to the target surface. Afterwards, the image is destroyed.
Originally cairo_surface_unmap.
type Matrix ¶
type Matrix struct {
// contains filtered or unexported fields
}
Matrix is used throughout cairo to convert between different coordinate spaces.
A Matrix holds an affine transformation, such as a scale, rotation, shear, or a combination of these.
The transformation of a point (x,y) is given by:
x' = xx*x + xy*y + x0 y' = yx*y + yy*y + y0
Originally cairo_matrix_t.
func NewIdentityMatrix ¶
func NewIdentityMatrix() (I Matrix)
NewIdentityMatrix creates the identity I.
Originally cairo_init_identity.
func NewMatrix ¶
NewMatrix creates the affine transformation matrix given by xx, yx, xy, yy, x0, y0.
Originally cairo_matrix_init
func NewRotateMatrix ¶
NewRotateMatrix creates a matrix that rotates by radians.
Originally cairo_matrix_init_rotate.
func NewScaleMatrix ¶
NewScaleMatrix creates a matrix that scales by vector.
Originally cairo_matrix_init_scale.
func NewTranslateMatrix ¶
NewTranslateMatrix matrix creates a matrix that translates by vector.
Originally cairo_init_translate.
func (Matrix) Mul ¶
Mul multiples m by n and returns the new result r, such that r = m*n.
Originally cairo_matrix_multiply.
func (Matrix) Rotate ¶
Rotate rotates m by radians and returns itself.
Originally cairo_matrix_rotate.
func (Matrix) Translate ¶
Translate translates m by vector and returns itself.
Originally cairo_matrix_translate.
func (Matrix) XtensionRaw ¶
func (m Matrix) XtensionRaw() C.cairo_matrix_t
XtensionRaw returns the raw C value of m.
type Mesh ¶
type Mesh struct {
*XtensionPattern
}
Mesh is a mesh pattern.
Mesh patterns are tensor-product patch meshes (type 7 shadings in PDF). Mesh patterns may also be used to create other types of shadings that are special cases of tensor-product patch meshes such as Coons patch meshes (type 6 shading in PDF) and Gouraud-shaded triangle meshes (type 4 and 5 shadings in PDF).
Mesh patterns consist of one or more tensor-product patches.
func NewMesh ¶
NewMesh creates a new mesh pattern with patches. There must be at least one patch.
Originally cairo_pattern_create_mesh, cairo_mesh_pattern_begin_patch, cairo_mesh_pattern_end_patch, cairo_mesh_pattern_move_to, cairo_mesh_pattern_line_to, cairo_mesh_pattern_curve_to, cairo_mesh_pattern_set_control_point, and cairo_mesh_pattern_set_corner_color_rgba.
type Paged ¶
type Paged interface { ShowPage() CopyPage() }
Paged is the set of methods available to a paged surface.
All methods are documented on XtensionPagedSurface.
type PagedSurface ¶
PagedSurface is a surface that has the concept of pages.
All Paged methods are documented on XtensionPagedSurface.
type PagedVectorSurface ¶
type PagedVectorSurface interface { Surface Paged VectorBacked }
PagedVectorSurface is a surface that has the concept of pages and a native vector backend.
type Patch ¶
type Patch struct { //Controls are the at most 4 control points. Controls []Point //Colors are the at most 4 corner colors. Colors []color.Color //Path is the path defining this patch. // //Note that if you assign an existing path all PathClosePath elements //will be ignored. Path Path }
Patch represents a tensor-product patch.
A tensor-product patch is defined by 4 Bézier curves (side 0, 1, 2, 3) and by 4 additional control points (P₀, P₁, P₂, P₃) that provide further control over the patch and complete the definition of the tensor-product patch. The corner C₀ is the first point of the patch.
All methods that take a control point or corner point index are taken mod 4.
C₁ Side 1 C₂ +---------------+ | | | P₁ P₂ | | | Side 0 | | Side 2 | | | | | P₀ P₃ | | | +---------------+ C₀ Side 3 C₃
Degenerate sides are permitted so straight lines may be used. A zero length line on one side may be used to create 3 sided patches.
Each patch is constructed by calling MoveTo to specify the first point in the patch C₀. The sides are then specified by calls to CurveTo and LineTo.
The four additional control points (P₀, P₁, P₂, P₃) in a patch can be specified with SetControlPoints.
At each corner of the patch (C₀, C₁, C₂, C₃) a color may be specified with SetCornerColors.
Note: The coordinates are always in pattern space. For a new pattern, pattern space is identical to user space, but the relationship between the spaces can be changed with SetMatrix.
Special cases ¶
A Coons patch is a special case of the tensor-product patch where the control points are implicitly defined by the sides of the patch. The default value for any control point not specified is the implicit value for a Coons patch, i.e. if no control points are specified the patch is a Coons patch.
A triangle is a special case of the tensor-product patch where the control points are implicitly defined by the sides of the patch, all the sides are lines and one of them has length 0. That is, if the patch is specified using just 3 lines, it is a triangle.
If the corners connected by the 0-length side have the same color, the patch is a Gouraud-shaded triangle.
Orientation ¶
Patches may be oriented differently to the above diagram. For example, the first point could be at the top left. The diagram only shows the relationship between the sides, corners and control points.
Regardless of where the first point is located, when specifying colors, corner 0 will always be the first point, corner 1 the point between side 0 and side 1, and so on.
Defaults ¶
If less than 4 sides have been defined, the first missing side is defined as a line from the current point to the first point of the patch (C₀) and the other sides are degenerate lines from C₀ to C₀. The corners between the added sides will all be coincident with C₀ of the patch and their color will be set to be the same as the color of C₀.
Any corner color whose color is not explicitly specified defaults to transparent black.
When two patches overlap, the last one that has been added is drawn over the first one.
When a patch folds over itself, points are sorted depending on their parameter coordinates inside the patch. The v coordinate ranges from 0 to 1 when moving from side 3 to side 1; the u coordinate ranges from 0 to 1 when going from side 0 to side 2. Points with higher v coordinate hide points with lower v coordinate. When two points have the same v coordinate, the one with higher u coordinate is above. This means that points nearer to side 1 are above points nearer to side 3; when this is not sufficient to decide which point is above (for example when both points belong to side 1 or side 3) points nearer to side 2 are above points nearer to side 0.
More information ¶
For a complete definition of tensor-product patches, see the PDF specification (ISO32000) †, which describes the parametrization in detail.
† https://wwwimages2.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdf
Example (Coons) ¶
coons := &Patch{} coons.MoveTo(ZP) coons.CurveTo(Pt(30, -30), Pt(60, 30), Pt(100, 0)) coons.CurveTo(Pt(60, 30), Pt(130, 60), Pt(100, 100)) coons.CurveTo(Pt(30, 70), Pt(-30, 30), Pt(0, 100)) coons.SetCornerColors(Red, Green, Blue, Color{R: 1, G: 1})
Output:
Example (GouraudShadedTriangle) ¶
gst := &Patch{} gst.MoveTo(Pt(100, 100)) gst.LineTo(Pt(130, 130)) gst.LineTo(Pt(130, 70)) gst.SetCornerColors(Red, Green, Blue)
Output:
func (*Patch) CurveTo ¶
CurveTo adds a cubic Bézier spline to the current patch, from the current point to p2, using p0 and p1 as the control points.
If the current patch has no current point, this method will behave as if preceded by a call to MoveTo(p0).
After this call the current point will be p2.
Originally cairo_mesh_pattern_curve_to.
func (*Patch) LineTo ¶
LineTo adds a line to the current patch from the current point to p.
If there is no current point, this call is equivalent to MoveTo.
After this call the current point is p.
Originally cairo_mesh_pattern_line_to.
func (*Patch) MoveTo ¶
MoveTo defines the first point of the current patch in the mesh.
After this call the current point is p.
Originally cairo_mesh_pattern_move_to.
func (*Patch) SetControlPoints ¶
SetControlPoints sets the at most 4 internal control points of the current patch.
Originally cairo_mesh_pattern_set_control_point.
func (*Patch) SetCornerColors ¶
SetCornerColors sets the at most 4 corner colors in the current patch.
Originally cairo_mesh_pattern_set_corner_color_rgba.
type Path ¶
type Path []PathElement
A Path is a representation of a path.
type PathElement ¶
type PathElement interface { //Type reports the type of this path element. Type() pathDataType //Points returns a copy of this path element's points. //Its length will always be 0, 1, or 3. Points() []Point //String renders a human readable interpretation of this path element. String() string // contains filtered or unexported methods }
A PathElement is a single item in a Path.
type Pattern ¶
type Pattern interface { Type() patternType Err() error Close() error SetExtend(extend) Extend() extend SetFilter(filter) Filter() filter SetMatrix(Matrix) Matrix() Matrix XtensionRaw() *C.cairo_pattern_t }
Pattern is a pattern used for drawing.
Originally cairo_pattern_t.
func XtensionRegisterAlienRasterPattern ¶
func XtensionRegisterAlienRasterPattern(subtype string, p *C.cairo_pattern_t) (Pattern, error)
XtensionRegisterAlienRasterPattern registers a libcairo user font with cairo.
The subtype must be registered with XtensionRegisterAlienRasterPatternSubtype.
type Point ¶
type Point struct {
X, Y float64
}
Point is an X, Y coordinate pair. The axes increase right and down.
When a Point is used as a vector, it is considered as a line segment from (0, 0) to (X, Y).
var ZP Point
ZP is the zero point.
func (Point) Mod ¶
Mod returns the point q in r such that p.X-q.X is a multiple of r's width and p.Y-q.Y is a multiple of r's height.
func (Point) Transform ¶
Transform transforms p by m, returning a new point.
Originally cairo_matrix_transform.
func (Point) TransformDistance ¶
TransformDistance transforms the distance vector p by m. This is similar to Transform except that the translation component of m are ignored.
Originally cairo_matrix_transform_distance.
type RadialGradient ¶
type RadialGradient struct {
// contains filtered or unexported fields
}
RadialGradient is a radial gradient pattern.
func NewRadialGradient ¶
func NewRadialGradient(start, end Circle, colorStops ...ColorStop) RadialGradient
NewRadialGradient creates a new radial gradient between the circles start and end, with specified color stops.
Originally cairo_pattern_create_radial and cairo_pattern_add_color_stop_rgba.
func (RadialGradient) ColorStops ¶
func (p RadialGradient) ColorStops() (cs []ColorStop)
ColorStops reports the color stops defined on this gradient.
Originally cairo_pattern_get_color_stop_count and cairo_pattern_get_color_stop_rgba.
func (RadialGradient) RadialCircles ¶
func (r RadialGradient) RadialCircles() (start, end Circle)
RadialCircles reports the gradient endpoints.
Originally cairo_pattern_get_radial_circles.
type Rectangle ¶
type Rectangle struct {
Min, Max Point
}
A Rectangle contains the points with Min.X <= X < Max.X, Min.Y <= Y < Max.Y. A Rectangle is always axis-aligned. It is well-formed if Min.X <= Max.X and likewise for Y. Points are always well-formed. A rectangle's methods always return well-formed outputs for well-formed inputs.
var ZR Rectangle
ZR is the zero Rectangle.
func (Rectangle) Canon ¶
Canon returns the canonical version of r. The returned rectangle has minimum and maximum coordinates swapped if necessary so that it is well-formed.
func (Rectangle) Intersect ¶
Intersect returns the largest rectangle contained by both r and s. If the two rectangles do not overlap then the zero rectangle will be returned.
type ScaledFont ¶
type ScaledFont struct {
// contains filtered or unexported fields
}
A ScaledFont is a font scaled to a particular size and device resolution.
ScaledFont is most useful for low-level font usage where a library or application wants to cache a reference to a scaled font to speed up computation of metrics.
Originally cairo_scaled_font_t.
func NewScaledFont ¶
func NewScaledFont(f Font, fontMatrix, CTM Matrix, opts *FontOptions) (*ScaledFont, error)
NewScaledFont creates a scaled font of f.
The fontMatrix is the the font space to user space transformation matrix for the font.
The CTM is the user to device coordinate transformation matrix.
Originally cairo_scaled_font_create.
func (*ScaledFont) Close ¶
func (s *ScaledFont) Close() error
Close frees the resources of s.
Originally cairo_scaled_font_destroy.
func (*ScaledFont) Err ¶
func (s *ScaledFont) Err() error
Err reports any error on s.
Originally cairo_scaled_font_status.
func (*ScaledFont) Font ¶
func (s *ScaledFont) Font() (Font, error)
Font returns the Font s was created with.
func (*ScaledFont) XtensionRaw ¶
func (s *ScaledFont) XtensionRaw() *C.cairo_scaled_font_t
XtensionRaw returns the underlying C value of s.
type SolidPattern ¶
type SolidPattern struct { *XtensionPattern // contains filtered or unexported fields }
SolidPattern is a Pattern corresponding to a single translucent color.
func NewSolidPattern ¶
func NewSolidPattern(c color.Color) SolidPattern
NewSolidPattern creates a solid pattern of color c.
Originally cairo_pattern_create_rgba.
func (SolidPattern) Color ¶
func (s SolidPattern) Color() AlphaColor
Color returns the color this pattern was created with.
Originally cairo_pattern_get_rgba.
type Subsurface ¶
type Subsurface struct {
XtensionPagedVectorSurface
}
Subsurface is a buffer or restrained copy of surface.
It must be created with CreateSubsurface.
type Surface ¶
type Surface interface { CreateSimilar(c Content, w, h int) (Surface, error) CreateSimilarImage(f Format, w, h int) (ImageSurface, error) CreateSubsurface(r Rectangle) (Subsurface, error) Err() error Close() error Flush() error Content() Content Device() (Device, error) FontOptions() *FontOptions SetDeviceOffset(Point) DeviceOffset() Point Type() surfaceType HasShowTextGlyphs() bool MapImage(r image.Rectangle) (MappedImageSurface, error) Equal(Surface) bool //XtensionRaw is ONLY for adding libcairo subsystems outside this package. //Otherwise just ignore. XtensionRaw() *C.cairo_surface_t //XtensionRegisterWriter is ONLY for adding libcairo subsystems outside //this package. //Otherwise just ignore. XtensionRegisterWriter(unsafe.Pointer) // contains filtered or unexported methods }
Surface represents an image, either as the destination of a drawing operation or as the source when drawing onto another surface.
To draw to a Surface, create a Context with the surface as the target.
All methods are documented on XtensionSurface.
Originally cairo_surface_t.
func XtensionRegisterAlienMappedSurface ¶
func XtensionRegisterAlienMappedSurface(s, from *C.cairo_surface_t) (S, From Surface, err error)
XtensionRegisterAlienMappedSurface registers a mapped image surface s. The surface s was mapped from is required.
It is okay if from has been previously registered.
This is only necessary if you are using another library that creates its own libcairo surface that will interact with this package.
func XtensionRegisterAlienSurface ¶
func XtensionRegisterAlienSurface(s *C.cairo_surface_t) (Surface, error)
XtensionRegisterAlienSurface registers a surface created outside of this package and creates a Surface of the proper type.
This is only necessary if you are using another library that creates its own libcairo surface that will interact with this package.
If s is a mapped image surface you must use XtensionRegisterAlienMappedSurface.
func XtensionRevivifySurface ¶
func XtensionRevivifySurface(s *C.cairo_surface_t) (S Surface, err error)
XtensionRevivifySurface recreates a Go Surface of the proper type from a C surface.
This is for extension writers only.
type SurfacePattern ¶
type SurfacePattern struct { *XtensionPattern // contains filtered or unexported fields }
SurfacePattern is a Pattern backed by a Surface.
func NewSurfacePattern ¶
func NewSurfacePattern(s Surface) (sp SurfacePattern, err error)
NewSurfacePattern creates a Pattern from a Surface.
Originally cairo_pattern_create_for_surface.
func (SurfacePattern) Surface ¶
func (s SurfacePattern) Surface() Surface
Surface returns the Surface of this Pattern.
Originally cairo_pattern_get_surface.
type TextCluster ¶
type TextCluster struct {
RuneLength, NumGlyphs int
}
TextCluster holds information about a single text cluster. A text cluster is a minimal mapping of some glyphs to some runes.
For a cluster to be valid, RuneLength and NumGlyphs should be non-negative and at least one non-zero. Note that clusters with zero glyphs are not as well supported as normal clusters. For example, PDF rendering applications typically ignore those clusters when PDF text is being selected.
Originally cairo_text_cluster_t.
func XtensionTextClustersCtoGo ¶
func XtensionTextClustersCtoGo(clusters *C.cairo_text_cluster_t, N C.int) []TextCluster
XtensionTextClustersCtoGo converts an array of cairo_text_cluster_t into a []TextCluster.
type TextClusterFlags ¶
type TextClusterFlags int
TextClusterFlags specify properties of a text cluster mapping.
Originally cairo_text_cluster_flags_t.
const ( //TextClusterDefault specifies that the default properties are to be used. TextClusterDefault TextClusterFlags = 0 //TextClusterBackward specifies that the clusters in the cluster slice map //to glyphs in the glyph slice from end to start. TextClusterBackward TextClusterFlags = C.CAIRO_TEXT_CLUSTER_FLAG_BACKWARD )
func (TextClusterFlags) String ¶
func (t TextClusterFlags) String() (s string)
type TextExtents ¶
type TextExtents struct { //The horizontal distance from the origin to the leftmost part of the glyhps //as drawn. //Positive if the glyphs lie entirely to the right of the origin. // //Originally x_bearing. BearingX float64 //The vertical distance from the origin to the topmost part of the glyhps //as drawn. //Positive if the glyphs lie entirely below the origin. // //Originally y_bearing. BearingY float64 //Width of the glyphs as drawn. Width float64 //Height of the glyphs as drawn. Height float64 //AdvanceX is the distance in the X direction to advance after drawing //these glyphs. // //Originally x_advance. AdvanceX float64 //AdvanceY is the distance in the Y direction to advance after drawing //these glyphs. // //This will be zero for most fonts used for horizontal writing. // //Originally y_advance. AdvanceY float64 }
TextExtents stores the extents of a single glyph or string of glyphs in user-space coordinates. Because text extents are in user-space coordinates, they are mostly, but not entirely, independent of the current transformation matrix. They will, however, change slightly due to hinting.
Originally cairo_text_extents_t.
func XtensionNewTextExtents ¶
func XtensionNewTextExtents(te C.cairo_text_extents_t) TextExtents
XtensionNewTextExtents converts a cairo_text_extents_t into a TextExtents.
func (TextExtents) XtensionRaw ¶
func (t TextExtents) XtensionRaw() C.cairo_text_extents_t
XtensionRaw returns t as a cairo_text_extents_t.
type ToyFont ¶
type ToyFont struct { *XtensionFont // contains filtered or unexported fields }
ToyFont is a Font created by the libcairo "toy" font API.
See Context.SelectFace for more details.
func NewToyFont ¶
NewToyFont creates a toy font of the given family, slant, and weight.
If family is "", the default toy font for the given platform will be used, typically sans-serif.
See Context.SelectFont for more details.
Originally cairo_toy_font_face_create.
type VectorBacked ¶
type VectorBacked interface { SetFallbackResolution(xppi, yppi float64) FallbackResolution() (xppi, yppi float64) }
VectorBacked is the set of methods available to a surface with a native vector backend.
All methods are documented on XtensionVectorSurface.
type VectorSurface ¶
type VectorSurface interface { Surface VectorBacked }
VectorSurface is a surface with a native vector backend.
All VectorBacked methods are documented on XtensionVectorSurface.
type XtensionDevice ¶
type XtensionDevice struct {
// contains filtered or unexported fields
}
XtensionDevice is the "base class" and default implementation for libcairo devices.
Unless a particular type of device exposes special operations on the device, it will be an object of this type regardless of its deviceType.
Originally cairo_device_t.
func NewXtensionDevice ¶
func NewXtensionDevice(d *C.cairo_device_t) *XtensionDevice
NewXtensionDevice creates a plain device for a c surface.
This is only for extension builders.
func (*XtensionDevice) Close ¶
func (c *XtensionDevice) Close() error
Close releases the resources of this device.
Originally cairo_device_destroy.
func (*XtensionDevice) Equal ¶
func (c *XtensionDevice) Equal(d Device) bool
Equal reports whether c and d are handles of the same device.
func (*XtensionDevice) Err ¶
func (c *XtensionDevice) Err() error
Err reports any error on this device.
Originally cairo_device_status.
func (*XtensionDevice) Flush ¶
func (c *XtensionDevice) Flush()
Flush any pending operations and restore any temporary modification to the device state made by libcairo.
This method must be called before switching from using the device with Cairo to operating on it directly with native APIs. If the device doesn't support direct access, then this does nothing.
This may lock devices.
Originally cairo_device_flush.
func (*XtensionDevice) Lock ¶
func (c *XtensionDevice) Lock() (err error)
Lock acquires the device for the current thread. This method will block until no other thread has acquired the device.
If err is nil, you successfully acquired the device. From now on your thread owns the device and no other thread will be able to acquire it until a matching call to Unlock.
It is allowed to recursively acquire the device multiple times from the same thread.
Note ¶
You must never acquire two different devices at the same time unless this is explicitly allowed. Otherwise, the possibility of deadlocks exist.
As various libcairo functions can acquire devices when called, these may also cause deadlocks when you call them with an acquired device. So you must not have a device acquired when calling them.
These functions are marked in the documentation.
Orignally cairo_device_acquire.
func (*XtensionDevice) Type ¶
func (c *XtensionDevice) Type() deviceType
Type reports the type of this device.
Originally cairo_device_get_type.
func (*XtensionDevice) Unlock ¶
func (c *XtensionDevice) Unlock()
Unlock releases the device previously acquired by Lock.
Originally cairo_device_release.
func (*XtensionDevice) XtensionRaw ¶
func (c *XtensionDevice) XtensionRaw() *C.cairo_device_t
XtensionRaw returns the raw cairo_device_t pointer.
XtensionRaw is only meant for creating new device types and should NEVER be used directly.
func (*XtensionDevice) XtensionRegisterWriter ¶
func (d *XtensionDevice) XtensionRegisterWriter(w unsafe.Pointer)
XtensionRegisterWriter registers the writer wrapped by XtensionWrapWriter with the surface so that it does not get garbage collected until libcairo releases the device.
See XtensionWrapWriter for more information.
type XtensionFont ¶
type XtensionFont struct {
// contains filtered or unexported fields
}
XtensionFont is the "base class" of cairo fonts.
It is meant only for embedding in new font types and should NEVER be used directly.
func XtensionNewFont ¶
func XtensionNewFont(f *C.cairo_font_face_t) *XtensionFont
XtensionNewFont creates a base go font from a c font face.
This is only for extension builders.
func (*XtensionFont) Close ¶
func (f *XtensionFont) Close() error
Close frees the resources used by this font.
Originally cairo_font_face_destroy.
func (*XtensionFont) Err ¶
func (f *XtensionFont) Err() error
Err reports any errors on this font.
Originally cairo_font_face_status.
func (*XtensionFont) Subtype ¶
func (f *XtensionFont) Subtype() string
Subtype reports the subtype of the font.
This returns "" unless Type reports FontTypeUser.
func (*XtensionFont) Type ¶
func (f *XtensionFont) Type() fontType
Type reports the type of the font.
Originally cairo_font_face_get_type.
func (*XtensionFont) XtensionRaw ¶
func (f *XtensionFont) XtensionRaw() *C.cairo_font_face_t
XtensionRaw return the raw cairo_font_face_t pointer.
XtensionRaw is only meant for creating new font types and should NEVER be used directly.
type XtensionPagedSurface ¶
type XtensionPagedSurface struct {
*XtensionSurface
}
XtensionPagedSurface is the "base class" for cairo surfaces that are paged.
It is meant only for embedding in new surface types and should NEVER be used directly.
func NewXtensionPagedSurface ¶
func NewXtensionPagedSurface(s *C.cairo_surface_t) XtensionPagedSurface
NewXtensionPagedSurface creates a base go paged surface from a c surface.
This is only for extension builders.
func (XtensionPagedSurface) CopyPage ¶
func (e XtensionPagedSurface) CopyPage()
CopyPage emits the current page, but does not clear it. The contents of the current page will be retained for the next page.
Use ShowPage to emit the current page and clear it.
Originally cairo_surface_copy_page.
func (XtensionPagedSurface) ShowPage ¶
func (e XtensionPagedSurface) ShowPage()
ShowPage emits and clears the current page.
Use CopyPage if you want to emit the current page but not clear it.
Originally cairo_surface_show_page.
type XtensionPagedVectorSurface ¶
type XtensionPagedVectorSurface struct {
*XtensionSurface
}
XtensionPagedVectorSurface is the "base class" for cairo surfaces that are paged and have native support for vector graphics.
It is meant only for embedding in new surface types and should NEVER be used directly.
func NewXtensionPagedVectorSurface ¶
func NewXtensionPagedVectorSurface(s *C.cairo_surface_t) XtensionPagedVectorSurface
NewXtensionPagedVectorSurface creates a base go paged vector surface from a c surface.
This is only for extension builders.
func (XtensionPagedVectorSurface) CopyPage ¶
func (e XtensionPagedVectorSurface) CopyPage()
CopyPage is documented on XtensionPagedSurface.
func (XtensionPagedVectorSurface) FallbackResolution ¶
func (e XtensionPagedVectorSurface) FallbackResolution() (xppi, yppi float64)
FallbackResolution is documented on XtensionVectorSurface.
func (XtensionPagedVectorSurface) SetFallbackResolution ¶
func (e XtensionPagedVectorSurface) SetFallbackResolution(xppi, yppi float64)
SetFallbackResolution is documented on XtensionVectorSurface.
func (XtensionPagedVectorSurface) ShowPage ¶
func (e XtensionPagedVectorSurface) ShowPage()
ShowPage is documented on XtensionPagedSurface.
type XtensionPattern ¶
type XtensionPattern struct {
// contains filtered or unexported fields
}
XtensionPattern is meant to be embedded in user-provided raster patterns.
func XtensionNewPattern ¶
func XtensionNewPattern(p *C.cairo_pattern_t) *XtensionPattern
XtensionNewPattern returns a Pattern from a properly created cairo_pattern_t. This is only useful for a cairo_pattern_t created from cairo_pattern_create_raster_source.
func (*XtensionPattern) Close ¶
func (p *XtensionPattern) Close() error
Close releases the pattern's resources.
Originally cairo_pattern_destroy.
func (*XtensionPattern) Err ¶
func (p *XtensionPattern) Err() error
Err reports any error on this pattern.
Originally cairo_pattern_status.
func (*XtensionPattern) Extend ¶
func (p *XtensionPattern) Extend() extend
Extend reports the mode used for drawing outside the area of this pattern.
Originally cairo_pattern_get_extend.
func (*XtensionPattern) Filter ¶
func (p *XtensionPattern) Filter() filter
Filter returns the filter used when resizing this pattern.
Originally cairo_pattern_get_filter.
func (*XtensionPattern) Matrix ¶
func (p *XtensionPattern) Matrix() Matrix
Matrix returns this patterns transformation matrix.
Originally cairo_pattern_get_matrix.
func (*XtensionPattern) SetExtend ¶
func (p *XtensionPattern) SetExtend(e extend)
SetExtend sets the mode used for drawing outside the area of this pattern.
Originally cairo_pattern_set_extend.
func (*XtensionPattern) SetFilter ¶
func (p *XtensionPattern) SetFilter(f filter)
SetFilter sets the filter used when resizing this pattern.
Originally cairo_pattern_set_filter.
func (*XtensionPattern) SetMatrix ¶
func (p *XtensionPattern) SetMatrix(m Matrix)
SetMatrix sets the pattern's transformation matrix. This matrix is a transformation from user space to pattern space.
When a pattern is first created it always has the identity matrix for its transformation matrix, which means that pattern space is initially identical to user space.
Important ¶
Please note that the direction of this transformation matrix is from user space to pattern space. This means that if you imagine the flow from a pattern to user space (and on to device space), then coordinates in that flow will be transformed by the inverse of the pattern matrix.
Originally cairo_pattern_set_matrix.
func (*XtensionPattern) Type ¶
func (p *XtensionPattern) Type() patternType
Type returns the type of the pattern.
Originally cairo_pattern_get_type.
func (*XtensionPattern) XtensionRaw ¶
func (p *XtensionPattern) XtensionRaw() *C.cairo_pattern_t
XtensionRaw returns p as a *cairo_pattern_t.
type XtensionSurface ¶
type XtensionSurface struct {
// contains filtered or unexported fields
}
XtensionSurface is the "base class" for cairo surfaces.
It is meant only for embedding in new surface types and should NEVER be used directly.
func NewXtensionSurface ¶
func NewXtensionSurface(s *C.cairo_surface_t) (x *XtensionSurface)
NewXtensionSurface creates a base go surface from a c surface.
This is only for extension builders.
func (*XtensionSurface) Close ¶
func (e *XtensionSurface) Close() error
Close frees the resources used by this surface.
Originally cairo_surface_destroy.
func (*XtensionSurface) Content ¶
func (e *XtensionSurface) Content() Content
Content reports the content of the surface.
Originally cairo_surface_get_content.
func (*XtensionSurface) CreateSimilar ¶
func (e *XtensionSurface) CreateSimilar(c Content, w, h int) (Surface, error)
CreateSimilar is documented in the Surface interface. with e. For example, the new surface will have the same fallback resolution and font options as e. Generally, the new surface will also use the same backend as e, unless that is not possible for some reason.
Initially the contents of the returned surface are all 0 (transparent if contents have transparency, black otherwise.)
Originally cairo_surface_create_similar.
func (*XtensionSurface) CreateSimilarImage ¶
func (e *XtensionSurface) CreateSimilarImage(f Format, w, h int) (ImageSurface, error)
CreateSimilarImage creates a new surface that is as compatible as possible for uploading to and using in conjunction with existing surface. However, this surface can still be used like any normal image surface.
Initially the contents of the returned surface are all 0 (transparent if contents have transparency, black otherwise.)
Originally cairo_surface_create_similar_image.
func (*XtensionSurface) CreateSubsurface ¶
func (e *XtensionSurface) CreateSubsurface(r Rectangle) (s Subsurface, err error)
CreateSubsurface creates a window into e defined by r. All operations performed on s are clipped and translated to e. No operation on s performed outside the bounds of r are performed on e.
This is useful for passing constrained child surfaces to routines that draw directly on the parent surface with no further allocations, double buffering, or copies.
Warning ¶
The semantics of subsurfaces have not yet been finalized in libcairo, unless r is: in full device units, is contained within the extents of the target surface, and the target or subsurface's device transforms are not changed.
Originally cairo_surface_create_for_rectangle.
func (*XtensionSurface) Device ¶
func (e *XtensionSurface) Device() (Device, error)
Device reports the device of this surface.
Originally cairo_surface_get_device.
func (*XtensionSurface) DeviceOffset ¶
func (e *XtensionSurface) DeviceOffset() (vector Point)
DeviceOffset reports the device offset set by SetDeviceOffset.
Originally cairo_surface_get_device_offset.
func (*XtensionSurface) Equal ¶
func (e *XtensionSurface) Equal(s Surface) bool
Equal reports whether e and s are handles to the same surface.
func (*XtensionSurface) Err ¶
func (e *XtensionSurface) Err() error
Err reports any errors on the surface.
Originally cairo_surface_status.
func (*XtensionSurface) Flush ¶
func (e *XtensionSurface) Flush() error
Flush performs any pending drawing and restores any temporary modifcations that libcairo has made to the surface's state.
Originally cairo_surface_flush.
func (*XtensionSurface) FontOptions ¶
func (e *XtensionSurface) FontOptions() *FontOptions
FontOptions retrieves the default font rendering options for this surface.
Originally cairo_surface_get_font_options.
func (*XtensionSurface) HasShowTextGlyphs ¶
func (e *XtensionSurface) HasShowTextGlyphs() bool
HasShowTextGlyphs reports whether this surface uses provided text and cluster data when called by a context's ShowTextGlyphs operation.
Even if this method returns false, the ShowTextGlyphs operation will succeed, but the extra information will be ignored and the call will be equivalent to ShowGlyphs.
Originally cairo_surface_has_show_text_glyphs.
func (*XtensionSurface) MapImage ¶
func (e *XtensionSurface) MapImage(r image.Rectangle) (MappedImageSurface, error)
MapImage returns an image surface that is the most efficient mechanism for modifying the backing store of this surface.
If r is Empty, the entire surface is mapped, otherwise, just the region described by r is mapped.
Note that r is an image.Rectangle and not a cairo.Rectangle.
It is the callers responsibility to all Close on the returned surface in order to upload the content of the mapped image to this surface and destroys the image surface.
The returned surface is an ImageSurface with a special Close method.
Warning ¶
Using this surface as a target or source while mapped is undefined.
The result of mapping a surface multiple times is undefined.
Changing the device transform of either surface before the image surface is unmapped is undefined.
Originally cairo_surface_map_to_image.
func (*XtensionSurface) SetDeviceOffset ¶
func (e *XtensionSurface) SetDeviceOffset(vector Point)
SetDeviceOffset sets the device offset of this surface.
The device offset adds to the device coordinates determined by the coordinate transform matrix when drawing to a surface.
One use case for this method is to create a surface that redirects a portion of drawing offscreen invisble to users of the Cairo api. Setting a transform is insufficent as queries such as DeviceToUser expose this offset.
Note that the offset affects drawing to the surface as well as using the surface in a source pattern.
The x and y components are in the unit of the surface's underlying device.
Originally cairo_surface_set_device_offset.
func (*XtensionSurface) Type ¶
func (e *XtensionSurface) Type() surfaceType
Type reports the type of this surface.
Originally cairo_surface_get_type.
func (*XtensionSurface) XtensionRaw ¶
func (e *XtensionSurface) XtensionRaw() *C.cairo_surface_t
XtensionRaw returns the raw cairo_surface_t pointer.
XtensionRaw is only meant for creating new surface types and should NEVER be used directly.
func (*XtensionSurface) XtensionRegisterWriter ¶
func (s *XtensionSurface) XtensionRegisterWriter(w unsafe.Pointer)
XtensionRegisterWriter registers the writer wrapped by XtensionWrapWriter with the surface so that it does not get garbage collected until libcairo releases the surface.
See XtensionWrapWriter for more information.
type XtensionVectorSurface ¶
type XtensionVectorSurface struct {
*XtensionSurface
}
XtensionVectorSurface is the "base class" for cairo surfaces that have native support for vector graphics.
It is meant only for embedding in new surface types and should NEVER be used directly.
func NewXtensionVectorSurface ¶
func NewXtensionVectorSurface(s *C.cairo_surface_t) XtensionVectorSurface
NewXtensionVectorSurface creates a base go vector surface from a c surface.
This is only for extension builders.
func (XtensionVectorSurface) FallbackResolution ¶
func (e XtensionVectorSurface) FallbackResolution() (xppi, yppi float64)
FallbackResolution reports the fallback resolution.
Originally cairo_surface_get_fallback_resolution.
func (XtensionVectorSurface) SetFallbackResolution ¶
func (e XtensionVectorSurface) SetFallbackResolution(xppi, yppi float64)
SetFallbackResolution sets the horizontal and vertical resolution for image fallbacks.
When certain operations aren't supported natively by a backend, cairo will fallback by rendering operations to an image and then overlaying that image onto the output.
If not called the default for x and y is 300 pixels per inch.
Originally cairo_surface_set_fallback_resolution.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Examples come from http://cairographics.org/samples and as such these examples are in the public domain and were originally contributed by Øyvind Kolås.
|
Examples come from http://cairographics.org/samples and as such these examples are in the public domain and were originally contributed by Øyvind Kolås. |
Package mimepattern creates patterns from images that, when possible, directly embed the uncompressed image data into the target surface.
|
Package mimepattern creates patterns from images that, when possible, directly embed the uncompressed image data into the target surface. |
Package pdf implements the PDF backend for libcairo rendering.
|
Package pdf implements the PDF backend for libcairo rendering. |
Package ps implements the PostScript backend for libcairo rendering.
|
Package ps implements the PostScript backend for libcairo rendering. |
Package recording provides a surface that records drawing operations performed on it to later be replayed on another surface.
|
Package recording provides a surface that records drawing operations performed on it to later be replayed on another surface. |
Package script implements a device and surface for writing drawing operations to a file for debugging purposes.
|
Package script implements a device and surface for writing drawing operations to a file for debugging purposes. |
Package svg implements the SVG backend for libcairo rendering.
|
Package svg implements the SVG backend for libcairo rendering. |
Package tee implements a surface that multiplexes all operations performed on it to the one or more underlying surfaces.
|
Package tee implements a surface that multiplexes all operations performed on it to the one or more underlying surfaces. |