Documentation
¶
Overview ¶
Package rastercore 提供可切换栅格后端共用的渲染上下文状态机。
gg、ftgg、tinyskia 三个后端只有「画笔/路径提交/图像合成」随光栅库不同, 其余语义完全一致:Push/Pop 样式镜像、逻辑矩阵累计、毫米→设备像素换算、 描边造型缩放、路径扫描、DrawImage 矩阵拼装、CopyStrokeToFill 等。 这些共享逻辑集中在本包,各后端只需实现 Hooks。
Core 直接满足 render.DrawContext(并带 Raster),且全部使用与绘制库无关 的 geom 类型,因此本包与各后端都不依赖 tdewolff/canvas。
Index ¶
- func MatrixScale(m geom.Matrix) float64
- type Core
- func (c *Core) ClearFill()
- func (c *Core) ClearStroke()
- func (c *Core) CopyStrokeToFill()
- func (c *Core) CurrentMatrix() geom.Matrix
- func (c *Core) DrawImage(img image.Image, x, y float64, dpmm float64)
- func (c *Core) DrawPath(x, y float64, p *geom.Path)
- func (c *Core) Pop()
- func (c *Core) Push()
- func (c *Core) Raster() *image.RGBA
- func (c *Core) RenderImage(img image.Image, m geom.Matrix)
- func (c *Core) Rotate(deg float64)
- func (c *Core) Scale(sx, sy float64)
- func (c *Core) SetDashes(offset float64, dashes ...float64)
- func (c *Core) SetFillColor(col color.Color)
- func (c *Core) SetFillGradient(g geom.Gradient)
- func (c *Core) SetFillPaint(paint geom.Paint)
- func (c *Core) SetFillRule(rule geom.FillRule)
- func (c *Core) SetStrokeCapper(cap geom.Capper)
- func (c *Core) SetStrokeColor(col color.Color)
- func (c *Core) SetStrokeGradient(g geom.Gradient)
- func (c *Core) SetStrokeJoiner(join geom.Joiner)
- func (c *Core) SetStrokePaint(paint geom.Paint)
- func (c *Core) SetStrokeWidth(w float64)
- func (c *Core) StrokeCapper() geom.Capper
- func (c *Core) StrokeJoiner() geom.Joiner
- func (c *Core) StrokeWidth() float64
- func (c *Core) TextPath(p *geom.Path, x, y float64)
- func (c *Core) Translate(x, y float64)
- type DeviceOp
- type DevicePath
- type DeviceSeg
- type Hooks
- type StrokeStyle
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MatrixScale ¶
MatrixScale 返回矩阵的不变缩放因子(行列式开方),用于线宽/虚线换算。
Types ¶
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core 是 DrawContext 的共享实现。像素尺寸与 canvas 的 Rasterize 取整 规则一致(int(w*dpmm+0.5))。
func New ¶
func New(width, height float64, resolution geom.Resolution, factory func(wpx, hpx int, dpmm, hpix float64) Hooks) (*Core, error)
New 计算像素尺寸并调用 factory 构造光栅库的 Hooks。factory 收到已经过 取整校验的 wpx/hpx(像素)与 dpmm/hpix,返回库相关的 Hooks 实现。
func (*Core) CopyStrokeToFill ¶
func (c *Core) CopyStrokeToFill()
CopyStrokeToFill 把当前描边画笔真正复制为填充画笔(含纯色、渐变)。
func (*Core) CurrentMatrix ¶
CurrentMatrix 返回当前逻辑矩阵(CoordSystem·View)。
func (*Core) RenderImage ¶
RenderImage 按绝对设备矩阵绘制预渲染图片。
func (*Core) SetFillGradient ¶
SetFillGradient 设置渐变填充(延迟到 DrawPath 时按矩阵采样)。
func (*Core) SetFillPaint ¶
SetFillPaint 设置填充画笔(颜色、渐变或清除)。
func (*Core) SetStrokeCapper ¶
SetStrokeCapper 设置线帽。
func (*Core) SetStrokeGradient ¶
SetStrokeGradient 设置描边渐变(延迟到 DrawPath 时按矩阵采样)。
func (*Core) SetStrokeJoiner ¶
SetStrokeJoiner 设置连接器,并记录斜接限制。
func (*Core) SetStrokePaint ¶
SetStrokePaint 设置描边画笔(颜色、渐变或清除)。
type DevicePath ¶
type DevicePath struct {
Segs []DeviceSeg
}
DevicePath 是复用缓冲的设备路径,避免每次绘制都分配新切片。
func (*DevicePath) CubeTo ¶
func (p *DevicePath) CubeTo(c1x, c1y, c2x, c2y, x, y float64)
CubeTo 追加一个三次贝塞尔段。
type Hooks ¶
type Hooks interface {
// Push 保存光栅库自身的画笔与变换。
Push()
// Pop 恢复最近一次 Push 保存的光栅库画笔与变换。
Pop()
// SetFillSolid 设置纯色填充画笔。
SetFillSolid(c color.Color)
// SetStrokeSolid 设置纯色描边画笔。
SetStrokeSolid(c color.Color)
// ClearFill 清除填充画笔。
ClearFill()
// ClearStroke 清除描边画笔。
ClearStroke()
// SetFillRule 设置光栅库的填充规则。
SetFillRule(rule geom.FillRule)
// DrawDevicePath 提交已换算到设备像素坐标的路径,并按需填充/描边。
// m 是当次绘制的完整逻辑矩阵(渐变采样/几何换算用);fillGrad 与
// strokeGrad 为 nil 表示使用当前已设置的纯色画笔。Core 已保证 fill 与
// stroke 至少一个为真,且 stroke 为真时 style.Width>0。
DrawDevicePath(path *DevicePath, m geom.Matrix, fill, stroke bool, fillGrad, strokeGrad geom.Gradient, style StrokeStyle)
// RenderImage 按绝对设备矩阵合成预渲染图像(离屏合成/mesh/文字图层)。
RenderImage(img image.Image, m geom.Matrix)
// Raster 返回当前绘制的全部内容对应的 RGBA 图像。
Raster() *image.RGBA
}
Hooks 是共享状态机与具体光栅库之间的桥。
Core 负责渲染上下文语义,Hooks 只做与库相关的画笔设置、路径提交与图像 合成,全部使用 geom 类型。