mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 14:53:44 +08:00
feat(归并文件): 归并根包文件
This commit is contained in:
1 parent
1a8de5a3f1
commit
bfecdeb0d6
12 files changed
+702
-817
No files matched your search
+109
@@ -21,6 +21,18 @@ import (
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
basegeom "github.com/xiaoqidun/ofdgo/internal/base/geom"
|
||||
)
|
||||
|
||||
// 画刷类型,区分纯色、渐变和图案填充
|
||||
const (
|
||||
PaintNone PaintKind = iota
|
||||
PaintSolid
|
||||
PaintLinear
|
||||
PaintRadial
|
||||
PaintPattern
|
||||
PaintMesh
|
||||
)
|
||||
|
||||
// PatternPaint 底纹画刷
|
||||
@@ -36,6 +48,36 @@ type profileGradient struct {
|
||||
colors []MeshVertex
|
||||
}
|
||||
|
||||
// ColorStop 保存渐变区间位置及预乘RGBA颜色节点
|
||||
type ColorStop struct {
|
||||
Offset float64
|
||||
Color color.RGBA
|
||||
}
|
||||
|
||||
// PaintKind 区分无画刷、纯色、轴向渐变、径向渐变、图案和网格渐变
|
||||
type PaintKind uint8
|
||||
|
||||
// Paint 保存后端无关的颜色、渐变和图案,不修改源节点
|
||||
type Paint struct {
|
||||
Kind PaintKind
|
||||
Color color.RGBA
|
||||
Gradient *Shading
|
||||
Pattern *PatternPaint
|
||||
Mesh *MeshShading
|
||||
}
|
||||
|
||||
// Shading 保存OFD对象局部坐标中的渐变,单位为毫米,纵轴向下
|
||||
// Extend、MapType和MapUnit保留标准的延伸及重复语义
|
||||
// Sample存在时按单位区间采样源颜色变换,Stops仍保存各段的显示颜色
|
||||
type Shading struct {
|
||||
Start, End Point
|
||||
StartRadius, EndRadius float64
|
||||
Stops []ColorStop
|
||||
Extend, MapType string
|
||||
MapUnit, Eccentricity, Angle float64
|
||||
Sample func(float64) color.RGBA
|
||||
}
|
||||
|
||||
// ResolveColor 按文档颜色空间和调色板解析颜色,返回预乘透明度的RGBA
|
||||
// 入参: value 颜色分量, index 调色板索引, space 颜色空间标识, alpha 透明度
|
||||
// 返回: color.RGBA 标准颜色, error 颜色定义或配置错误
|
||||
@@ -467,3 +509,70 @@ func (g *profileGradient) At(t float64) color.RGBA {
|
||||
r, green, b := last.rgb(last.Values)
|
||||
return profileColor([3]float64{r, green, b}, last.Alpha)
|
||||
}
|
||||
|
||||
// ResolvePaint 解析颜色、透明度、渐变分段和图案,不依赖绘图库
|
||||
// 入参: fill 填充或转换后的描边节点
|
||||
// 返回: Paint 只读画刷, error 无效渐变
|
||||
func (r *Renderer) ResolvePaint(fill *FillColor) (Paint, error) {
|
||||
previous := r.renderError
|
||||
r.renderError = nil
|
||||
defer func() { r.renderError = previous }()
|
||||
if fill == nil {
|
||||
return Paint{}, nil
|
||||
}
|
||||
if fill.Pattern != nil {
|
||||
return Paint{Kind: PaintPattern, Pattern: parsePatternPaint(fill)}, nil
|
||||
}
|
||||
if fill.GouraudShd != nil || fill.LaGouraudShd != nil {
|
||||
mesh, err := r.resolveMesh(fill)
|
||||
if err != nil {
|
||||
return Paint{}, err
|
||||
}
|
||||
if r.renderError != nil {
|
||||
return Paint{}, r.renderError
|
||||
}
|
||||
return Paint{Kind: PaintMesh, Mesh: mesh}, nil
|
||||
}
|
||||
base := r.parseFillColor(fill)
|
||||
if r.renderError != nil {
|
||||
return Paint{}, r.renderError
|
||||
}
|
||||
if base == nil {
|
||||
return Paint{}, nil
|
||||
}
|
||||
paint := Paint{Kind: PaintSolid, Color: colorToRGBA(base)}
|
||||
if node := fill.AxialShd; node != nil {
|
||||
start, end := parseFloats(node.StartPoint), parseFloats(node.EndPoint)
|
||||
stops := r.renderGradientStops(node.Segment, fill.Alpha)
|
||||
if r.renderError != nil {
|
||||
return Paint{}, r.renderError
|
||||
}
|
||||
sample, err := r.profileGradient(node.Segment, fill.Alpha)
|
||||
if err != nil {
|
||||
return Paint{}, err
|
||||
}
|
||||
if len(start) >= 2 && len(end) >= 2 && len(stops) != 0 && (!basegeom.Equal(start[0], end[0]) || !basegeom.Equal(start[1], end[1])) {
|
||||
paint.Kind = PaintLinear
|
||||
paint.Gradient = &Shading{Start: Point{X: start[0], Y: start[1]}, End: Point{X: end[0], Y: end[1]}, Stops: stops, Extend: node.Extend, MapType: node.MapType, MapUnit: node.MapUnit}
|
||||
paint.Gradient.Sample = sample
|
||||
return paint, nil
|
||||
}
|
||||
}
|
||||
if node := fill.RadialShd; node != nil && node.EndRadius > 0 {
|
||||
start, end := parseFloats(node.StartPoint), parseFloats(node.EndPoint)
|
||||
stops := r.renderGradientStops(node.Segment, fill.Alpha)
|
||||
if r.renderError != nil {
|
||||
return Paint{}, r.renderError
|
||||
}
|
||||
sample, err := r.profileGradient(node.Segment, fill.Alpha)
|
||||
if err != nil {
|
||||
return Paint{}, err
|
||||
}
|
||||
if len(start) >= 2 && len(end) >= 2 && len(stops) != 0 {
|
||||
paint.Kind = PaintRadial
|
||||
paint.Gradient = &Shading{Start: Point{X: start[0], Y: start[1]}, End: Point{X: end[0], Y: end[1]}, StartRadius: node.StartRadius, EndRadius: node.EndRadius, Stops: stops, Extend: node.Extend, MapType: node.MapType, MapUnit: node.MapUnit, Eccentricity: node.Eccentricity, Angle: node.Angle}
|
||||
paint.Gradient.Sample = sample
|
||||
}
|
||||
}
|
||||
return paint, nil
|
||||
}
|
||||
Reference in new issue
Block a user