mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 13:56:32 +08:00
1 parent
5e0da3da28
commit
ee6c9f6a16
82 files changed
+4316
-4310
No files matched your search
@@ -22,14 +22,6 @@ import (
|
||||
"github.com/tdewolff/canvas"
|
||||
)
|
||||
|
||||
// canvasNativeStroke 判断描边是否由Canvas提供
|
||||
// 入参: geometry 几何后端
|
||||
// 返回: bool 是否采用原生描边
|
||||
func canvasNativeStroke(geometry GeometryBackend) bool {
|
||||
_, ok := geometry.(CanvasBackend)
|
||||
return ok
|
||||
}
|
||||
|
||||
// Curves 在输出边界转换椭圆弧,其他曲线保持原样
|
||||
// 入参: path 页面路径
|
||||
// 返回: GeometryPath 贝塞尔路径, error 路径错误
|
||||
@@ -41,65 +33,6 @@ func (CanvasBackend) Curves(path GeometryPath) (GeometryPath, error) {
|
||||
return *geometryFromCanvasPath(p.ReplaceArcs()), nil
|
||||
}
|
||||
|
||||
// canvasStrokeOptions 转换Canvas描边样式,虚线由调用方传入
|
||||
// 入参: width 描边宽度, cap 线帽, join 连接, tolerance 展开误差
|
||||
// 返回: StrokeOptions 公共描边样式
|
||||
func canvasStrokeOptions(width float64, cap canvas.Capper, join canvas.Joiner, tolerance float64) StrokeOptions {
|
||||
options := StrokeOptions{Width: width, Cap: "Butt", Join: "Miter", MiterLimit: defaultMiterLimit, Tolerance: tolerance}
|
||||
switch cap.(type) {
|
||||
case canvas.RoundCapper:
|
||||
options.Cap = "Round"
|
||||
case canvas.SquareCapper:
|
||||
options.Cap = "Square"
|
||||
}
|
||||
switch value := join.(type) {
|
||||
case canvas.RoundJoiner:
|
||||
options.Join = "Round"
|
||||
case canvas.BevelJoiner:
|
||||
options.Join = "Bevel"
|
||||
case canvas.MiterJoiner:
|
||||
options.MiterLimit = value.Limit
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
// canvasStrokePath 通过配置的几何后端生成描边,不修改源路径
|
||||
// 入参: geometry 几何后端, path Canvas路径, options 描边样式
|
||||
// 返回: *canvas.Path 描边轮廓, error 几何错误
|
||||
func canvasStrokePath(geometry GeometryBackend, path *canvas.Path, options StrokeOptions) (*canvas.Path, error) {
|
||||
outline, err := geometry.Stroke(*geometryFromCanvasPath(path), options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return geometryToCanvasPath(&outline)
|
||||
}
|
||||
|
||||
// strokeCanvasPath 将文字和复杂画刷的描边交给配置的几何后端
|
||||
// 入参: path Canvas路径, width 描边宽度, cap 线帽, join 连接
|
||||
// 返回: *canvas.Path 描边轮廓
|
||||
func (r *Renderer) strokeCanvasPath(path *canvas.Path, width float64, cap canvas.Capper, join canvas.Joiner) *canvas.Path {
|
||||
return r.strokeDashedCanvasPath(path, width, cap, join, 0, nil)
|
||||
}
|
||||
|
||||
// strokeDashedCanvasPath 通过公共几何后端展开虚线和线帽,保留零长度绘制段
|
||||
// 入参: path 路径, width 线宽, cap 线帽, join 连接, offset 虚线偏移, dashes 虚线数组
|
||||
// 返回: *canvas.Path 描边填充轮廓
|
||||
func (r *Renderer) strokeDashedCanvasPath(path *canvas.Path, width float64, cap canvas.Capper, join canvas.Joiner, offset float64, dashes []float64) *canvas.Path {
|
||||
geometry, err := r.Geometry()
|
||||
if err != nil {
|
||||
r.renderError = err
|
||||
return &canvas.Path{}
|
||||
}
|
||||
options := canvasStrokeOptions(width, cap, join, canvas.Tolerance)
|
||||
options.DashOffset, options.Dashes = offset, dashes
|
||||
result, err := canvasStrokePath(geometry, path, options)
|
||||
if err != nil {
|
||||
r.renderError = err
|
||||
return &canvas.Path{}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Path 解析对象的标准紧缩路径并转换到页面坐标
|
||||
// 入参: object 路径对象
|
||||
// 返回: GeometryPath 页面路径, error 无效路径错误
|
||||
@@ -245,6 +178,73 @@ func (CanvasBackend) Clip(r *Renderer, clips *Clips, matrix Matrix, parent *Geom
|
||||
return geometryFromCanvasPath(intersectClipPath(p, clip)), nil
|
||||
}
|
||||
|
||||
// canvasNativeStroke 判断描边是否由Canvas提供
|
||||
// 入参: geometry 几何后端
|
||||
// 返回: bool 是否采用原生描边
|
||||
func canvasNativeStroke(geometry GeometryBackend) bool {
|
||||
_, ok := geometry.(CanvasBackend)
|
||||
return ok
|
||||
}
|
||||
|
||||
// canvasStrokeOptions 转换Canvas描边样式,虚线由调用方传入
|
||||
// 入参: width 描边宽度, cap 线帽, join 连接, tolerance 展开误差
|
||||
// 返回: StrokeOptions 公共描边样式
|
||||
func canvasStrokeOptions(width float64, cap canvas.Capper, join canvas.Joiner, tolerance float64) StrokeOptions {
|
||||
options := StrokeOptions{Width: width, Cap: "Butt", Join: "Miter", MiterLimit: defaultMiterLimit, Tolerance: tolerance}
|
||||
switch cap.(type) {
|
||||
case canvas.RoundCapper:
|
||||
options.Cap = "Round"
|
||||
case canvas.SquareCapper:
|
||||
options.Cap = "Square"
|
||||
}
|
||||
switch value := join.(type) {
|
||||
case canvas.RoundJoiner:
|
||||
options.Join = "Round"
|
||||
case canvas.BevelJoiner:
|
||||
options.Join = "Bevel"
|
||||
case canvas.MiterJoiner:
|
||||
options.MiterLimit = value.Limit
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
// canvasStrokePath 通过配置的几何后端生成描边,不修改源路径
|
||||
// 入参: geometry 几何后端, path Canvas路径, options 描边样式
|
||||
// 返回: *canvas.Path 描边轮廓, error 几何错误
|
||||
func canvasStrokePath(geometry GeometryBackend, path *canvas.Path, options StrokeOptions) (*canvas.Path, error) {
|
||||
outline, err := geometry.Stroke(*geometryFromCanvasPath(path), options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return geometryToCanvasPath(&outline)
|
||||
}
|
||||
|
||||
// strokeCanvasPath 将文字和复杂画刷的描边交给配置的几何后端
|
||||
// 入参: path Canvas路径, width 描边宽度, cap 线帽, join 连接
|
||||
// 返回: *canvas.Path 描边轮廓
|
||||
func (r *Renderer) strokeCanvasPath(path *canvas.Path, width float64, cap canvas.Capper, join canvas.Joiner) *canvas.Path {
|
||||
return r.strokeDashedCanvasPath(path, width, cap, join, 0, nil)
|
||||
}
|
||||
|
||||
// strokeDashedCanvasPath 通过公共几何后端展开虚线和线帽,保留零长度绘制段
|
||||
// 入参: path 路径, width 线宽, cap 线帽, join 连接, offset 虚线偏移, dashes 虚线数组
|
||||
// 返回: *canvas.Path 描边填充轮廓
|
||||
func (r *Renderer) strokeDashedCanvasPath(path *canvas.Path, width float64, cap canvas.Capper, join canvas.Joiner, offset float64, dashes []float64) *canvas.Path {
|
||||
geometry, err := r.Geometry()
|
||||
if err != nil {
|
||||
r.renderError = err
|
||||
return &canvas.Path{}
|
||||
}
|
||||
options := canvasStrokeOptions(width, cap, join, canvas.Tolerance)
|
||||
options.DashOffset, options.Dashes = offset, dashes
|
||||
result, err := canvasStrokePath(geometry, path, options)
|
||||
if err != nil {
|
||||
r.renderError = err
|
||||
return &canvas.Path{}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// geometryToCanvasPath 将页面坐标路径转换为默认几何引擎的向上纵轴
|
||||
// 入参: path 独立几何路径,nil表示不裁剪
|
||||
// 返回: *canvas.Path 默认引擎路径, error 不支持的路径指令
|
||||
|
||||
Reference in new issue
Block a user