mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-08-30 12:12:40 +08:00
feat(字体渲染): 优化字体渲染
This commit is contained in:
+24
-2
@@ -97,8 +97,9 @@ type TextObject struct {
|
||||
|
||||
// FillColor 填充颜色
|
||||
type FillColor struct {
|
||||
Value string `xml:"Value,attr"`
|
||||
Alpha *int `xml:"Alpha,attr"`
|
||||
Value string `xml:"Value,attr"`
|
||||
Alpha *int `xml:"Alpha,attr"`
|
||||
AxialShd *AxialShd `xml:"AxialShd"`
|
||||
}
|
||||
|
||||
// TextCode 文本内容节点
|
||||
@@ -141,6 +142,27 @@ type PathObject struct {
|
||||
|
||||
// StrokeColor 勾边颜色
|
||||
type StrokeColor struct {
|
||||
Value string `xml:"Value,attr"`
|
||||
Alpha *int `xml:"Alpha,attr"`
|
||||
AxialShd *AxialShd `xml:"AxialShd"`
|
||||
}
|
||||
|
||||
// AxialShd 轴向渐变
|
||||
type AxialShd struct {
|
||||
Extend string `xml:"Extend,attr"`
|
||||
StartPoint string `xml:"StartPoint,attr"`
|
||||
EndPoint string `xml:"EndPoint,attr"`
|
||||
Segment []ShdSegment `xml:"Segment"`
|
||||
}
|
||||
|
||||
// ShdSegment 渐变分段
|
||||
type ShdSegment struct {
|
||||
Position float64 `xml:"Position,attr"`
|
||||
Color ShdColor `xml:"Color"`
|
||||
}
|
||||
|
||||
// ShdColor 渐变颜色
|
||||
type ShdColor struct {
|
||||
Value string `xml:"Value,attr"`
|
||||
Alpha *int `xml:"Alpha,attr"`
|
||||
}
|
||||
|
||||
+10
-10
@@ -256,10 +256,10 @@ func (r *Renderer) renderLayer(ctx *canvas.Context, layer Layer, pageH float64,
|
||||
defaultLW = dp.LineWidth
|
||||
}
|
||||
if dp.FillColor != nil {
|
||||
defaultFill = parseColorWithAlpha(dp.FillColor.Value, dp.FillColor.Alpha)
|
||||
defaultFill = parseFillColor(dp.FillColor)
|
||||
}
|
||||
if dp.StrokeColor != nil {
|
||||
defaultStroke = parseColorWithAlpha(dp.StrokeColor.Value, dp.StrokeColor.Alpha)
|
||||
defaultStroke = parseStrokeColor(dp.StrokeColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -303,10 +303,10 @@ func (r *Renderer) renderCompositeGraphicUnit(ctx *canvas.Context, cgu Composite
|
||||
defaultLW = dp.LineWidth
|
||||
}
|
||||
if dp.FillColor != nil {
|
||||
defaultFill = parseColorWithAlpha(dp.FillColor.Value, dp.FillColor.Alpha)
|
||||
defaultFill = parseFillColor(dp.FillColor)
|
||||
}
|
||||
if dp.StrokeColor != nil {
|
||||
defaultStroke = parseColorWithAlpha(dp.StrokeColor.Value, dp.StrokeColor.Alpha)
|
||||
defaultStroke = parseStrokeColor(dp.StrokeColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -482,10 +482,10 @@ func (r *Renderer) renderPath(ctx *canvas.Context, obj PathObject, pageH float64
|
||||
lineWidth = dp.LineWidth
|
||||
}
|
||||
if dp.FillColor != nil {
|
||||
fillColor = parseColorWithAlpha(dp.FillColor.Value, dp.FillColor.Alpha)
|
||||
fillColor = parseFillColor(dp.FillColor)
|
||||
}
|
||||
if dp.StrokeColor != nil {
|
||||
strokeColor = parseColorWithAlpha(dp.StrokeColor.Value, dp.StrokeColor.Alpha)
|
||||
strokeColor = parseStrokeColor(dp.StrokeColor)
|
||||
}
|
||||
if dp.Cap == "Round" {
|
||||
lineCap = canvas.RoundCap
|
||||
@@ -507,10 +507,10 @@ func (r *Renderer) renderPath(ctx *canvas.Context, obj PathObject, pageH float64
|
||||
lineWidth = obj.LineWidth
|
||||
}
|
||||
if obj.FillColor != nil {
|
||||
fillColor = parseColorWithAlpha(obj.FillColor.Value, obj.FillColor.Alpha)
|
||||
fillColor = parseFillColor(obj.FillColor)
|
||||
}
|
||||
if obj.StrokeColor != nil {
|
||||
strokeColor = parseColorWithAlpha(obj.StrokeColor.Value, obj.StrokeColor.Alpha)
|
||||
strokeColor = parseStrokeColor(obj.StrokeColor)
|
||||
}
|
||||
if obj.Cap != "" {
|
||||
if obj.Cap == "Round" {
|
||||
@@ -603,10 +603,10 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
|
||||
fillColor = canvas.Black
|
||||
}
|
||||
if dp != nil && dp.FillColor != nil {
|
||||
fillColor = parseColorWithAlpha(dp.FillColor.Value, dp.FillColor.Alpha)
|
||||
fillColor = parseFillColor(dp.FillColor)
|
||||
}
|
||||
if obj.FillColor != nil {
|
||||
fillColor = parseColorWithAlpha(obj.FillColor.Value, obj.FillColor.Alpha)
|
||||
fillColor = parseFillColor(obj.FillColor)
|
||||
}
|
||||
fontStyle := canvas.FontRegular
|
||||
weight := obj.Weight
|
||||
|
||||
@@ -45,6 +45,50 @@ func parseColorWithAlpha(val string, alpha *int) color.Color {
|
||||
return color.Black
|
||||
}
|
||||
|
||||
// parseFillColor 解析填充颜色
|
||||
// 入参: fillColor 填充颜色节点
|
||||
// 返回: color.Color 颜色对象
|
||||
func parseFillColor(fillColor *FillColor) color.Color {
|
||||
if fillColor == nil {
|
||||
return nil
|
||||
}
|
||||
if strings.TrimSpace(fillColor.Value) != "" {
|
||||
return parseColorWithAlpha(fillColor.Value, fillColor.Alpha)
|
||||
}
|
||||
return parseAxialShdColor(fillColor.AxialShd, fillColor.Alpha)
|
||||
}
|
||||
|
||||
// parseStrokeColor 解析勾边颜色
|
||||
// 入参: strokeColor 勾边颜色节点
|
||||
// 返回: color.Color 颜色对象
|
||||
func parseStrokeColor(strokeColor *StrokeColor) color.Color {
|
||||
if strokeColor == nil {
|
||||
return nil
|
||||
}
|
||||
if strings.TrimSpace(strokeColor.Value) != "" {
|
||||
return parseColorWithAlpha(strokeColor.Value, strokeColor.Alpha)
|
||||
}
|
||||
return parseAxialShdColor(strokeColor.AxialShd, strokeColor.Alpha)
|
||||
}
|
||||
|
||||
// parseAxialShdColor 解析轴向渐变颜色
|
||||
// 入参: axialShd 轴向渐变节点, alpha 透明度
|
||||
// 返回: color.Color 颜色对象
|
||||
func parseAxialShdColor(axialShd *AxialShd, alpha *int) color.Color {
|
||||
if axialShd != nil {
|
||||
for _, segment := range axialShd.Segment {
|
||||
if strings.TrimSpace(segment.Color.Value) == "" {
|
||||
continue
|
||||
}
|
||||
if alpha == nil {
|
||||
alpha = segment.Color.Alpha
|
||||
}
|
||||
return parseColorWithAlpha(segment.Color.Value, alpha)
|
||||
}
|
||||
}
|
||||
return color.Black
|
||||
}
|
||||
|
||||
// GetDeltaX 获取X轴偏移量数组
|
||||
// 返回: []float64 偏移量数组
|
||||
func (tc *TextCode) GetDeltaX() []float64 {
|
||||
|
||||
Reference in New Issue
Block a user