feat(后端架构): 完善GG后端,修复渐变与选区异常
build.yaml / build (push) Successful in 37s

This commit is contained in:
xiaoqidun committed 2026-09-23 18:43:53 +08:00
1 parent c15547f0d2
commit f44d0d8a60
30 files changed
+2075 -463

No files matched your search

+26 -1
View File
@@ -58,7 +58,9 @@ func (b CanvasBackend) Render(page *RasterPage) (image.Image, error) {
}
source = converted
}
drawRasterImage(img, source, page.PixelTransform(cmd.Transform, h))
if err := drawRasterImageCommand(b, page, img, source, cmd); err != nil {
return nil, err
}
continue
}
p := &canvas.Path{}
@@ -93,6 +95,9 @@ func (b CanvasBackend) Render(page *RasterPage) (image.Image, error) {
default:
return nil, fmt.Errorf("canvas command %d: unsupported gradient %d", i, g.Kind)
}
if g.Spread != nil {
paint = canvas.Paint{Gradient: rasterGradientCanvas{g}}
}
}
style := canvas.Style{Fill: paint, FillRule: canvas.NonZero}
if cmd.EvenOdd {
@@ -104,3 +109,23 @@ func (b CanvasBackend) Render(page *RasterPage) (image.Image, error) {
r.Close()
return img, nil
}
// rasterGradientCanvas 将公共渐变交给Canvas采样,不改变OFD周期语义
type rasterGradientCanvas struct{ gradient *RasterGradient }
// At 返回局部坐标的预乘颜色
// 入参: x 横坐标, y 纵坐标
// 返回: color.RGBA 渐变颜色
func (g rasterGradientCanvas) At(x, y float64) color.RGBA { return g.gradient.At(x, y) }
// SetColorSpace 返回转换颜色空间后的独立渐变
// 入参: space 目标颜色空间
// 返回: canvas.Gradient 采样器
func (g rasterGradientCanvas) SetColorSpace(space canvas.ColorSpace) canvas.Gradient {
copy := *g.gradient
copy.Stops = append([]ColorStop(nil), copy.Stops...)
for i := range copy.Stops {
copy.Stops[i].Color = space.ToLinear(copy.Stops[i].Color)
}
return rasterGradientCanvas{&copy}
}