Documentation
¶
Overview ¶
Package purecairo is a pure-Go implementation of the Cairo 2D graphics API silk uses, with zero CGO dependencies. The package builds on every platform Go supports — macOS, Linux, Windows, BSD — without libcairo, libpng, libfreetype, or fontconfig.
API surface mirrors `cairo_*` and silk's `_hack` extensions, so silk can swap libcairo for purecairo by re-exporting the types and functions through a thin alias layer.
Algorithm references: where the C source uses a non-trivial algorithm (path stroking, arc → cubic flatten, two-circle radial gradients), the Go side either ports the same approach or substitutes a published equivalent. The cairo C source under `cairo/src/` is the reference; specific functions are cited in per-section comments.
Cross-platform parity:
- Image surface backed by image.RGBA (every platform).
- Text via golang.org/x/image/font/opentype with a per-OS system font discovery walk (font.go). Bundled Go-Regular TrueType is the universal fallback so the binary always has a face.
- Window upload: silk's window code reads DataPtr() as cairo ARGB32 (BGRA byte order on little-endian) and passes it to gl.TexImage2D — Surface.Flush() rebuilds that mirror buffer.
Implemented:
- Path: MoveTo, LineTo, CurveTo, Arc / ArcNegative, Rectangle, Line, RoundRect, NewPath, ClosePath.
- Fill / FillPreserve: anti-aliased via golang.org/x/image/vector. Solid + surface + linear/radial gradient sources.
- Stroke / StrokePreserve: per-segment thin-quad rasterisation (caps default to butt, joins to miter).
- Save / Restore + transform stack with cairo column-vector semantics.
- Clip / ClipPreserve / ResetClip / ClipBounds: AABB approximation. ClipBounds returns user-space rect via CTM inverse.
- Paint / PaintWithAlpha: OPERATOR_CLEAR, SOURCE, OVER respected.
- ShowGlyphs / ShowGlyphs_hack via opentype faces with CJK fallback chain.
Not implemented:
- PDF / SVG / PostScript export surfaces.
- Platform-native surfaces (xlib, quartz, win32).
- Path-shaped clipping (AABB only for now).
Index ¶
- Constants
- func Multiplygeom_Mat3x2(result, a, b *geom.Mat3x2)
- type Antialias
- type Content
- type Context
- func (this *Context) Antialias() Antialias
- func (this *Context) AppendPath(p *Path)
- func (this *Context) Arc(xc, yc, radius, a0, a1 float64)
- func (this *Context) ArcNegative(xc, yc, radius, a0, a1 float64)
- func (this *Context) Clip()
- func (this *Context) ClipBounds() (x, y, w, h float64)
- func (this *Context) ClipPreserve()
- func (this *Context) ClosePath()
- func (this *Context) CopyPage()
- func (this *Context) CopyPath() *Path
- func (this *Context) CopyPathFlat() *Path
- func (this *Context) CurrentPoint() (x, y float64)
- func (this *Context) CurveTo(x1, y1, x2, y2, x3, y3 float64)
- func (this *Context) Dash() Dash
- func (this *Context) Destroy()
- func (this *Context) DeviceToUser(x, y *float64)
- func (this *Context) DeviceToUserDistance(x, y *float64)
- func (this *Context) Fill()
- func (this *Context) FillExtens() (x1, y1, x2, y2 float64)
- func (this *Context) FillPreserve()
- func (this *Context) FillRule() FillRule
- func (this *Context) FontExtents() *FontExtents
- func (this *Context) FontFace() *FontFace
- func (this *Context) FontMatrix(m *geom.Mat3x2)
- func (this *Context) FontOptions(o *FontOptions)
- func (this *Context) GetMatrix(m *geom.Mat3x2)
- func (this *Context) GlyphExtents(glyphs []Glyph) *TextExtents
- func (this *Context) GroupTarget() *Surface
- func (this *Context) HasCurrentPoint() bool
- func (this *Context) InClip(x, y float64) bool
- func (this *Context) InFill(x, y float64) bool
- func (this *Context) InStroke(x, y float64) bool
- func (this *Context) Line(x0, y0, x1, y1 float64)
- func (this *Context) LineCap() LineCap
- func (this *Context) LineJoin() LineJoin
- func (this *Context) LineTo(x, y float64)
- func (this *Context) LineWidth() float64
- func (this *Context) Mask(p *Pattern)
- func (this *Context) MaskSurface(s *Surface, x, y float64)
- func (this *Context) MiterLimit() float64
- func (this *Context) MoveTo(x, y float64)
- func (this *Context) NewPath()
- func (this *Context) NewSubPath()
- func (this *Context) Operator() Operator
- func (this *Context) Paint()
- func (this *Context) PaintWithAlpha(alpha float64)
- func (this *Context) PathExtens() (x1, y1, x2, y2 float64)
- func (this *Context) PopGroup() *Pattern
- func (this *Context) PopGroupToSource()
- func (this *Context) PushGroup()
- func (this *Context) PushGroupWidthContent(c Content)
- func (this *Context) Rectangle(x, y, w, h float64)
- func (this *Context) RelCurveTo(x1, y1, x2, y2, x3, y3 float64)
- func (this *Context) RelLineTo(dx, dy float64)
- func (this *Context) RelMoveTo(dx, dy float64)
- func (this *Context) ResetClip()
- func (this *Context) ResetMatrix()
- func (this *Context) Restore()
- func (this *Context) Rotate(r float64)
- func (this *Context) RoundRect(x, y, w, h, r float64)
- func (this *Context) Save()
- func (this *Context) Scale(sx, sy float64)
- func (this *Context) ScaledFont() *ScaledFont
- func (this *Context) SelectFontFace(family string, slant FontSlant, weight FontWeight)
- func (this *Context) SetAntialias(a Antialias)
- func (this *Context) SetDash(d Dash)
- func (this *Context) SetFillRule(r FillRule)
- func (this *Context) SetFontFace(f *FontFace)
- func (this *Context) SetFontMatrix(m *geom.Mat3x2)
- func (this *Context) SetFontOptions(o *FontOptions)
- func (this *Context) SetFontSize(s float64)
- func (this *Context) SetLineCap(c LineCap)
- func (this *Context) SetLineJoin(j LineJoin)
- func (this *Context) SetLineWidth(w float64)
- func (this *Context) SetMatrix(m *geom.Mat3x2)
- func (this *Context) SetMiterLimit(m float64)
- func (this *Context) SetOperator(o Operator)
- func (this *Context) SetScaledFont(sf *ScaledFont)
- func (this *Context) SetSource(p *Pattern)
- func (this *Context) SetSourceRGB(r, g, b float64)
- func (this *Context) SetSourceRGBA(r, g, b, a float64)
- func (this *Context) SetSourceSurface(s *Surface, x, y float64)
- func (this *Context) SetTolerance(v float64)
- func (this *Context) ShowGlyphs(glyphs []Glyph)
- func (this *Context) ShowGlyphs_hack(p unsafe.Pointer, n int)
- func (this *Context) ShowPage()
- func (this *Context) ShowText(text string)
- func (this *Context) Source() *Pattern
- func (this *Context) Status() Status
- func (this *Context) Stroke()
- func (this *Context) StrokeExtens() (x1, y1, x2, y2 float64)
- func (this *Context) StrokePreserve()
- func (this *Context) Target() *Surface
- func (this *Context) TextExtents(text string) *TextExtents
- func (this *Context) TextPath(s string)
- func (this *Context) Tolerance() float64
- func (this *Context) Transform(m *geom.Mat3x2)
- func (this *Context) Translate(tx, ty float64)
- func (this *Context) UserToDevice(x, y *float64)
- func (this *Context) UserToDeviceDistance(x, y *float64)
- type Dash
- type Device
- type Extend
- type FillRule
- type Filter
- type FontExtents
- type FontFace
- type FontOptions
- func (this *FontOptions) Antialias() Antialias
- func (this *FontOptions) Copy() *FontOptions
- func (this *FontOptions) Destroy()
- func (this *FontOptions) Equal(other *FontOptions) bool
- func (this *FontOptions) Hash() uint32
- func (this *FontOptions) HintMetrics() int
- func (this *FontOptions) HintStyle() int
- func (this *FontOptions) Merge(other *FontOptions)
- func (this *FontOptions) SetAntialias(a Antialias)
- func (this *FontOptions) SetHintMetrics(int)
- func (this *FontOptions) SetHintStyle(int)
- func (this *FontOptions) SetSubpixelOrder(int)
- func (this *FontOptions) Status() Status
- func (this *FontOptions) SubpixelOrder() int
- type FontSlant
- type FontWeight
- type Format
- type Glyph
- type Image
- type LineCap
- type LineJoin
- type MappedImage
- type Operator
- type Path
- type PathDataType
- type Pattern
- func (this *Pattern) AddColorStopRGB(off, r, g, b float64)
- func (this *Pattern) AddColorStopRGBA(off, r, g, b, a float64)
- func (this *Pattern) ColorStopCount() int
- func (this *Pattern) ColorStopRGBA(idx int) (off, r, g, b, a float64)
- func (this *Pattern) Destroy()
- func (this *Pattern) Extend() Extend
- func (this *Pattern) Filter() Filter
- func (this *Pattern) GetMatrix(m *geom.Mat3x2)
- func (this *Pattern) RGBA() (r, g, b, a float64)
- func (this *Pattern) SetExtend(e Extend)
- func (this *Pattern) SetFilter(f Filter)
- func (this *Pattern) SetMatrix(m *geom.Mat3x2)
- func (this *Pattern) Status() Status
- func (this *Pattern) Surface() *Surface
- func (this *Pattern) Type() int
- type Rectangle
- type RectangleInt
- type RectangleList
- type ScaledFont
- func (this *ScaledFont) Ctm(m *geom.Mat3x2)
- func (this *ScaledFont) Destroy()
- func (this *ScaledFont) FontExtents() *FontExtents
- func (this *ScaledFont) FontFace() *FontFace
- func (this *ScaledFont) FontMatrix(m *geom.Mat3x2)
- func (this *ScaledFont) FontOptions() *FontOptions
- func (this *ScaledFont) GlyphExtents(glyphs []Glyph) *TextExtents
- func (this *ScaledFont) GlyphExtents_hack(p unsafe.Pointer, n int) *TextExtents
- func (this *ScaledFont) GlyphPath(glyphs []Glyph)
- func (this *ScaledFont) ScaleMatrix(m *geom.Mat3x2)
- func (this *ScaledFont) Status() Status
- func (this *ScaledFont) TextExtents(text string) *TextExtents
- func (this *ScaledFont) TextToGlyphs_hack(x, y float64, text string, out func(buf unsafe.Pointer, num int)) error
- func (this *ScaledFont) Type() int
- type Status
- type Surface
- func (this *Surface) Content() Content
- func (this *Surface) CopyPage()
- func (this *Surface) CreateForRectangle(r Rectangle) *Surface
- func (this *Surface) CreateSimilar(c Content, w, h int) *Surface
- func (this *Surface) CreateSimilarImage(f Format, w, h int) *Surface
- func (this *Surface) DataPtr() unsafe.Pointer
- func (this *Surface) Destroy()
- func (this *Surface) Device() *Device
- func (this *Surface) DeviceOffset() (x, y float64)
- func (this *Surface) FallbackResolution() (xppi, yppi float64)
- func (this *Surface) Finish()
- func (this *Surface) Flush()
- func (this *Surface) FontOptions() *FontOptions
- func (this *Surface) Format() Format
- func (this *Surface) GetMimeData(mimeType string) ([]byte, bool)
- func (this *Surface) HasShowTextGlyphs() bool
- func (this *Surface) Height() int
- func (this *Surface) Image() (image.Image, error)
- func (this *Surface) MapToImage(extents *RectangleInt) *MappedImage
- func (this *Surface) MarkDirty()
- func (this *Surface) NewContext() *Context
- func (this *Surface) RGBA() *image.RGBA
- func (this *Surface) SetData(src []uint8) error
- func (this *Surface) SetDeviceOffset(x, y float64)
- func (this *Surface) SetFallbackResolution(xppi, yppi float64)
- func (this *Surface) SetImage(img image.Image) error
- func (this *Surface) SetMimeData(mimeType string, data []byte)
- func (this *Surface) ShowPage()
- func (this *Surface) Status() Status
- func (this *Surface) Stride() int
- func (this *Surface) Type() SurfaceType
- func (this *Surface) UnmapImage(im *MappedImage)
- func (this *Surface) Width() int
- func (this *Surface) WritePNG(filename string) error
- func (this *Surface) WritePNGToStream(w io.Writer) error
- type SurfaceType
- type TextExtents
Constants ¶
const FORMAT_ARGB = FORMAT_ARGB32
FORMAT_ARGB is the ARGB32 alias used throughout silk/paint.
Variables ¶
This section is empty.
Functions ¶
func Multiplygeom_Mat3x2 ¶
Multiplygeom.Mat3x2 mirrors the original cairo.go helper used by silk (the misnamed "Multiplygeom.Mat3x2" function).
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func (*Context) AppendPath ¶
func (*Context) ArcNegative ¶
func (*Context) ClipBounds ¶
ClipBounds returns the clip extents in USER (post-CTM-inverse) space — matching libcairo's cairo_clip_extents semantics. silk's drawWidgetChildren intersects these with child Bounds(), which are also in user space, so returning device coords here would inflate the per-widget viewport by the HiDPI scale and overflow children.
We compute the user-space AABB by transforming the four device-clip corners through the inverse CTM. For pure scale+translate (the common case) this collapses to the obvious axis-aligned answer; the matrix path also handles rotated CTMs correctly.
func (*Context) ClipPreserve ¶
func (this *Context) ClipPreserve()
func (*Context) CopyPathFlat ¶
func (*Context) CurrentPoint ¶
func (*Context) DeviceToUser ¶
DeviceToUser inverts the CTM at (*x, *y). Mirrors cairo's cairo_device_to_user.
func (*Context) DeviceToUserDistance ¶
DeviceToUserDistance inverts the linear part of the CTM (no translation). Used for distance / size conversions where the origin shouldn't matter.
func (*Context) FillExtens ¶
func (*Context) FillPreserve ¶
func (this *Context) FillPreserve()
func (*Context) FontExtents ¶
func (this *Context) FontExtents() *FontExtents
func (*Context) FontMatrix ¶
func (*Context) FontOptions ¶
func (this *Context) FontOptions(o *FontOptions)
func (*Context) GlyphExtents ¶
func (this *Context) GlyphExtents(glyphs []Glyph) *TextExtents
func (*Context) GroupTarget ¶
func (*Context) HasCurrentPoint ¶
func (*Context) MaskSurface ¶
func (*Context) MiterLimit ¶
func (*Context) NewSubPath ¶
func (this *Context) NewSubPath()
func (*Context) PaintWithAlpha ¶
PaintWithAlpha fills the active clip region with the current source. Honours the active Porter-Duff operator — most importantly OpClear (zeroes the destination) and OpOver (alpha-blends source over dest).
The clear case is critical: silk's Window.paint() begins each frame with `SetOperator(OpClear); Paint(); SetOperator(OpOver)` to wipe the back buffer. If we ignored the operator and painted with the source colour instead, every frame would inherit the previous frame's last source — visible as huge coloured panels under the rest of the UI.
func (*Context) PathExtens ¶
func (*Context) PopGroupToSource ¶
func (this *Context) PopGroupToSource()
func (*Context) PushGroupWidthContent ¶
func (*Context) RelCurveTo ¶
func (*Context) ResetMatrix ¶
func (this *Context) ResetMatrix()
func (*Context) Rotate ¶
Rotate concatenates a rotation onto the CTM. cairo_rotate semantics: rotates user space, so CTM_new = CTM * Rotate(theta).
func (*Context) Scale ¶
Scale concatenates a user-space scale. Scaling user space by (sx, sy) means a unit user vector now maps to (sx, sy) user → applied to existing CTM that already maps user→device. So Xx, Xy multiply by sx; Yx, Yy multiply by sy.
func (*Context) ScaledFont ¶
func (this *Context) ScaledFont() *ScaledFont
func (*Context) SelectFontFace ¶
func (this *Context) SelectFontFace(family string, slant FontSlant, weight FontWeight)
func (*Context) SetAntialias ¶
func (*Context) SetFillRule ¶
func (*Context) SetFontFace ¶
func (*Context) SetFontMatrix ¶
func (*Context) SetFontOptions ¶
func (this *Context) SetFontOptions(o *FontOptions)
func (*Context) SetFontSize ¶
func (*Context) SetLineCap ¶
func (*Context) SetLineJoin ¶
func (*Context) SetLineWidth ¶
func (*Context) SetMiterLimit ¶
func (*Context) SetOperator ¶
func (*Context) SetScaledFont ¶
func (this *Context) SetScaledFont(sf *ScaledFont)
func (*Context) SetSource ¶
SetSource binds a pattern as the active fill / paint source. Solid colours stay on state.source; surfaces feed state.sourceSurf; gradients build a per-pixel image.Image on state.sourceImage.
func (*Context) SetSourceRGB ¶
func (*Context) SetSourceRGBA ¶
func (*Context) SetSourceSurface ¶
SetSourceSurface mirrors cairo_set_source_surface: subsequent fill / paint draws sample pixels from `s`, with the surface's pixel (0, 0) anchored at user (x, y).
func (*Context) SetTolerance ¶
func (*Context) ShowGlyphs ¶
ShowGlyphs renders an explicit glyph slice. Same code path as ShowGlyphs_hack but takes a typed slice — used by silk's higher-level helpers that don't go through the unsafe-pointer dance.
func (*Context) ShowGlyphs_hack ¶
ShowGlyphs_hack rasterises the glyph array at p (length n) using the active scaled font. CTM applies to each glyph's (X, Y) — that's the cairo convention, glyph positions live in user space and the rasteriser pushes them through the matrix.
Glyphs whose rune isn't in the primary face flow through the CJK fallback face, matching libcairo's substitution behaviour.
func (*Context) ShowText ¶
ShowText renders `text` starting at the current point. Each rune's advance moves the current point so consecutive ShowText calls concatenate. CTM applies to glyph positions identically to ShowGlyphs.
func (*Context) StrokeExtens ¶
func (*Context) StrokePreserve ¶
func (this *Context) StrokePreserve()
func (*Context) TextExtents ¶
func (this *Context) TextExtents(text string) *TextExtents
func (*Context) Transform ¶
Transform applies a user-space matrix m onto the CTM. The composition is CTM_new = CTM * m, mirroring cairo_transform.
func (*Context) Translate ¶
Translate concatenates a user-space translation onto the CTM. The device shift equals (Xx*tx + Xy*ty, Yx*tx + Yy*ty) — under a 2x HiDPI scale, Translate(10, 0) shifts device by 20 pixels. silk's geom.Mat3x2.Translate would shift by 10, breaking the coord match between Rectangle (which scales) and Translate (which doesn't).
func (*Context) UserToDevice ¶
func (*Context) UserToDeviceDistance ¶
type FontExtents ¶
type FontFace ¶
type FontFace struct {
// contains filtered or unexported fields
}
func NewToyFontFace ¶
func NewToyFontFace(family string, slant FontSlant, weight FontWeight) *FontFace
func (*FontFace) ToyWeight ¶
func (this *FontFace) ToyWeight() FontWeight
type FontOptions ¶
type FontOptions struct{}
func NewFontOptions ¶
func NewFontOptions() *FontOptions
func (*FontOptions) Antialias ¶
func (this *FontOptions) Antialias() Antialias
func (*FontOptions) Copy ¶
func (this *FontOptions) Copy() *FontOptions
func (*FontOptions) Destroy ¶
func (this *FontOptions) Destroy()
func (*FontOptions) Equal ¶
func (this *FontOptions) Equal(other *FontOptions) bool
func (*FontOptions) Hash ¶
func (this *FontOptions) Hash() uint32
func (*FontOptions) HintMetrics ¶
func (this *FontOptions) HintMetrics() int
func (*FontOptions) HintStyle ¶
func (this *FontOptions) HintStyle() int
func (*FontOptions) Merge ¶
func (this *FontOptions) Merge(other *FontOptions)
func (*FontOptions) SetAntialias ¶
func (this *FontOptions) SetAntialias(a Antialias)
func (*FontOptions) SetHintMetrics ¶
func (this *FontOptions) SetHintMetrics(int)
func (*FontOptions) SetHintStyle ¶
func (this *FontOptions) SetHintStyle(int)
func (*FontOptions) SetSubpixelOrder ¶
func (this *FontOptions) SetSubpixelOrder(int)
func (*FontOptions) Status ¶
func (this *FontOptions) Status() Status
func (*FontOptions) SubpixelOrder ¶
func (this *FontOptions) SubpixelOrder() int
type FontWeight ¶
type FontWeight int
const ( FONT_WEIGHT_NORMAL FontWeight = iota FONT_WEIGHT_BOLD )
type Glyph ¶
type Image ¶
Image is the high-level interface silk uses for surfaces; ImageSurface is just a *Surface alias.
type MappedImage ¶
type MappedImage struct {
Surface *Surface
}
MappedImage is a lightweight handle returned by MapToImage — purecairo only ever maps to the current surface, so the type is a pass-through.
type Operator ¶
type Operator int
const ( OPERATOR_CLEAR Operator = iota OPERATOR_SOURCE OPERATOR_OVER OPERATOR_IN OPERATOR_OUT OPERATOR_ATOP OPERATOR_DEST OPERATOR_DEST_OVER OPERATOR_DEST_IN OPERATOR_DEST_OUT OPERATOR_DEST_ATOP OPERATOR_XOR OPERATOR_ADD OPERATOR_SATURATE OPERATOR_MULTIPLY OPERATOR_SCREEN OPERATOR_OVERLAY OPERATOR_DARKEN OPERATOR_LIGHTEN OPERATOR_COLOR_DODGE OPERATOR_COLOR_BURN OPERATOR_HARD_LIGHT OPERATOR_SOFT_LIGHT OPERATOR_DIFFERENCE OPERATOR_EXCLUSION OPERATOR_HSL_HUE OPERATOR_HSL_SATURATION OPERATOR_HSL_COLOR OPERATOR_HSL_LUMINOSITY )
type PathDataType ¶
type PathDataType int
type Pattern ¶
type Pattern struct {
// contains filtered or unexported fields
}
Pattern is the source for fill/stroke. silk uses solid colour patterns most of the time, surface patterns for image brushes, and gradients for theme buttons / cards / radial avatars.
func NewLinearPattern ¶
NewLinearPattern creates a linear gradient between (x0, y0) and (x1, y1) in user space. Add stops with AddColorStopRGBA.
func NewPatternForSurface ¶
func NewRGBAPattern ¶
func NewRGBPattern ¶
func NewRadialPattern ¶
NewRadialPattern creates a radial gradient between two circles. Stops interpolate from the inner (r0) to the outer (r1) circle — silk's avatar / card highlights typically pass r0 = 0.
func (*Pattern) AddColorStopRGB ¶
AddColorStopRGB / AddColorStopRGBA push a stop onto the gradient stop list. Stops stay sorted by offset because silk's callers add them in order; if a future caller breaks that, sampling still yields a sensible (clamped) colour for any t.
func (*Pattern) AddColorStopRGBA ¶
func (*Pattern) ColorStopCount ¶
func (*Pattern) ColorStopRGBA ¶
type RectangleInt ¶
type RectangleInt struct {
X, Y, Width, Height int32
}
type RectangleList ¶
type ScaledFont ¶
type ScaledFont struct {
// contains filtered or unexported fields
}
func NewScaledFont ¶
func NewScaledFont(face *FontFace, matrix, ctm *geom.Mat3x2, options *FontOptions) *ScaledFont
func (*ScaledFont) Ctm ¶
func (this *ScaledFont) Ctm(m *geom.Mat3x2)
func (*ScaledFont) Destroy ¶
func (this *ScaledFont) Destroy()
func (*ScaledFont) FontExtents ¶
func (this *ScaledFont) FontExtents() *FontExtents
FontExtents reports ascent / descent / line-height in pixels. Drives silk's text alignment math; needs to be a real number (not the placeholder constants the bitmap stub returned) so labels position vertically the same as on the libcairo build.
func (*ScaledFont) FontFace ¶
func (this *ScaledFont) FontFace() *FontFace
func (*ScaledFont) FontMatrix ¶
func (this *ScaledFont) FontMatrix(m *geom.Mat3x2)
func (*ScaledFont) FontOptions ¶
func (this *ScaledFont) FontOptions() *FontOptions
func (*ScaledFont) GlyphExtents ¶
func (this *ScaledFont) GlyphExtents(glyphs []Glyph) *TextExtents
GlyphExtents totals the advance width of glyphs[] using the real face. Heights come from font metrics. Cairo uses this for hit tests and selection rectangles.
func (*ScaledFont) GlyphExtents_hack ¶
func (this *ScaledFont) GlyphExtents_hack(p unsafe.Pointer, n int) *TextExtents
GlyphExtents_hack reads `n` Glyphs from raw memory and delegates to GlyphExtents. silk's CGO bypass passes an unsafe pointer; same 24-byte stride as the libcairo build.
func (*ScaledFont) GlyphPath ¶
func (this *ScaledFont) GlyphPath(glyphs []Glyph)
func (*ScaledFont) ScaleMatrix ¶
func (this *ScaledFont) ScaleMatrix(m *geom.Mat3x2)
func (*ScaledFont) Status ¶
func (this *ScaledFont) Status() Status
func (*ScaledFont) TextExtents ¶
func (this *ScaledFont) TextExtents(text string) *TextExtents
TextExtents measures width/height of a text string at this font's scale. Used by silk's alignment + ellipsis logic.
func (*ScaledFont) TextToGlyphs_hack ¶
func (*ScaledFont) Type ¶
func (this *ScaledFont) Type() int
type Surface ¶
type Surface struct {
// contains filtered or unexported fields
}
Surface mirrors cairo_surface_t. silk uses image surfaces almost exclusively (window back-buffer, off-screen pixmaps); we back it with image.RGBA for the rasteriser to write into.
Byte-order bridge: silk's window upload path reads DataPtr() as Cairo ARGB32 — which on little-endian machines lands as BGRA in memory. Go's image.RGBA stores RGBA. To keep Window.paint() unchanged we maintain a parallel `dataBGRA` slice that mirrors img.Pix with R↔B swapped; Flush() rebuilds it. DataPtr() returns dataBGRA, which Window.paint() then ships to gl.TexImage2D as gl.BGRA without converting per-channel.
Reference: cairo/src/cairo-image-surface.c (CAIRO_FORMAT_ARGB32 pixel layout). cairo's native format on little-endian platforms is already BGRA byte order, so the byte-swap loop here matches what libcairo would have produced internally.
func NewImageSurface ¶
NewImageSurface creates an image-backed surface of the given format. FORMAT_ARGB32 is the dominant case in silk.
func NewImageSurfaceFromPNG ¶
NewImageSurfaceFromPNG decodes a PNG from disk into a fresh surface.
func NewImageSurfaceFromPNGStream ¶
NewImageSurfaceFromPNGStream decodes a PNG from any reader.
func NewWin ¶
NewWin is a no-op stub for windows-specific window surfaces — silk's glfw path doesn't use it under silk_pure_go.
func (*Surface) CreateForRectangle ¶
func (*Surface) CreateSimilarImage ¶
func (*Surface) DataPtr ¶
DataPtr returns the Cairo-compatible BGRA byte buffer for GL upload. Lazy-rebuilt by Flush — call Flush before DataPtr if Drawing has happened since the last frame.
func (*Surface) DeviceOffset ¶
func (*Surface) FallbackResolution ¶
func (*Surface) Finish ¶
func (this *Surface) Finish()
Finish matches cairo_surface_finish: after it the surface accepts no further drawing. A pure-Go surface owns only Go memory that the collector reclaims, so there is nothing to release — but the method must exist, because callers selected by filename on Windows (gui/window_windows.go) call it on every build, cgo or not.
func (*Surface) Flush ¶
func (this *Surface) Flush()
Flush rebuilds dataBGRA from img.Pix (R↔B swapped). Called every frame by Window.paint() right before DataPtr() / TexImage2D, so the GL upload sees Cairo-compatible BGRA byte order. Rebuilding is O(W*H) but a 1400×900 frame is ~5MB — well below the GPU's per-frame texture upload bandwidth.
func (*Surface) FontOptions ¶
func (this *Surface) FontOptions() *FontOptions
func (*Surface) HasShowTextGlyphs ¶
func (*Surface) Image ¶
Image returns the surface as a Go image.Image. Match Pixmap interface signature expected by silk/paint: (image.Image, error).
func (*Surface) MapToImage ¶
func (this *Surface) MapToImage(extents *RectangleInt) *MappedImage
func (*Surface) NewContext ¶
NewContext allocates a drawing context for this surface. The Context holds rasteriser state + transform stack.
func (*Surface) RGBA ¶
RGBA returns the underlying *image.RGBA directly. Used by purego rasteriser internals.
func (*Surface) SetData ¶
SetData copies the raw pixel byte stream into the surface backing store. silk uses this to wrap caller-allocated framebuffers.
func (*Surface) SetDeviceOffset ¶
func (*Surface) SetFallbackResolution ¶
func (*Surface) SetImage ¶
SetImage copies an image.Image into the surface. Used by silk's TextToPixmap / IconTextToPixmap helpers.
func (*Surface) SetMimeData ¶
func (*Surface) Type ¶
func (this *Surface) Type() SurfaceType
func (*Surface) UnmapImage ¶
func (this *Surface) UnmapImage(im *MappedImage)
type SurfaceType ¶
type SurfaceType int
const ( SURFACE_TYPE_IMAGE SurfaceType = iota SURFACE_TYPE_PDF SURFACE_TYPE_PS SURFACE_TYPE_XLIB SURFACE_TYPE_XCB SURFACE_TYPE_GLITZ SURFACE_TYPE_QUARTZ SURFACE_TYPE_WIN32 )