Repository navigation
Expand file tree
/
Copy pathdoc.go
More file actions
83 lines (83 loc) · 2.66 KB
/
Copy pathdoc.go
File metadata and controls
83 lines (83 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Package gg provides an enterprise-grade 2D graphics library for Go.
//
// # Overview
//
// gg is a Pure Go 2D graphics library with GPU acceleration, designed for
// IDEs, browsers, and graphics-intensive applications. Built with patterns
// from Skia (Chrome/Android), Cairo (GTK), and Vello (linebender), it
// delivers production-grade rendering with zero CGO dependencies.
//
// Part of the [GoGPU] ecosystem.
//
// # Quick Start
//
// import (
// "github.com/gogpu/gg"
// "github.com/gogpu/gg/text"
// )
//
// dc := gg.NewContext(512, 512)
// defer dc.Close()
//
// dc.ClearWithColor(gg.White)
//
// // Draw shapes
// dc.SetHexColor("#3498db")
// dc.DrawCircle(256, 256, 100)
// dc.Fill()
//
// // Text
// source, _ := text.NewFontSourceFromFile("font.ttf")
// defer source.Close()
// dc.SetFont(source.Face(24))
// dc.SetRGB(0, 0, 0)
// dc.DrawString("Hello", 200, 260)
//
// dc.SavePNG("output.png")
//
// # API Style
//
// The API follows the stateful context pattern (HTML5 Canvas, Cairo):
// - Set state: SetRGB, SetFont, SetLineWidth, SetBlendMode, SetFillBrush
// - Build path: MoveTo, LineTo, CubicTo, DrawCircle, DrawRectangle
// - Render: Fill, Stroke, FillPreserve, StrokePreserve
// - State stack: Push, Pop
//
// Compatible with [fogleman/gg] for easy migration.
//
// # Rendering
//
// Seven-tier GPU acceleration with automatic CPU fallback:
// - Tier 1: SDF shapes (circles, rounded rects, ellipses)
// - Tier 2a: Convex polygon fan tessellation
// - Tier 2b: Stencil-then-cover (arbitrary paths)
// - Tier 4: MSDF text (multi-channel signed distance field)
// - Tier 5: Vello 9-stage compute pipeline (full scenes)
// - Tier 6: Glyph mask cache (hinted bitmap text)
// - CPU: Skia AAA pixel-perfect rasterizer (analytic anti-aliasing)
//
// # Compositing
//
// 29 W3C blend modes for direct Fill/Stroke operations:
// - 14 Porter-Duff compositing operators
// - 11 advanced separable modes (Multiply, Screen, Overlay, ...)
// - 4 non-separable HSL modes (Hue, Saturation, Color, Luminosity)
// - Layer isolation via PushLayer/PopLayer with opacity
//
// # Text
//
// Pure Go font stack with variable font support:
// - Own cmap/hmtx/GSUB/GPOS/gvar/HVAR parsers
// - TrueType bytecode interpreter (skrifa golden parity)
// - MSDF + glyph mask dual-strategy GPU rendering
// - ClearType LCD auto-detection, CJK script-aware hinting
// - OpenType features, bidirectional text, color emoji
//
// # Coordinate System
//
// Standard screen coordinates: origin (0,0) at top-left, X right, Y down.
// Angles in radians, 0 is right, counter-clockwise positive.
//
// [GoGPU]: https://github.com/gogpu
// [fogleman/gg]: https://github.com/fogleman/gg
package gg