mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-30 09:37:26 +08:00
This commit is contained in:
1 parent
62456ce44d
commit
8d26471b1e
3 files changed
+82
-45
No files matched your search
+50
-16
@@ -16,6 +16,7 @@ package ofdgo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -154,19 +155,19 @@ func parseFillColor(fillColor *FillColor) color.Color {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parseFillPaint 解析填充画刷
|
// parseFillPaint 解析填充画刷
|
||||||
// 入参: fillColor 填充颜色节点, x X坐标, y Y坐标, pageH 页面高度, originX 原点X坐标, originY 原点Y坐标
|
// 入参: fillColor 填充颜色节点, x X坐标, y Y坐标, pageH 页面高度
|
||||||
// 返回: any 填充画刷
|
// 返回: any 填充画刷
|
||||||
func parseFillPaint(fillColor *FillColor, x, y, pageH, originX, originY float64) any {
|
func parseFillPaint(fillColor *FillColor, x, y, pageH float64) any {
|
||||||
if fillColor == nil {
|
if fillColor == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if fillColor.Pattern != nil {
|
if fillColor.Pattern != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if gradient := parseAxialShdGradient(fillColor.AxialShd, fillColor.Alpha, x, y, pageH, originX, originY); gradient != nil {
|
if gradient := parseAxialShdGradient(fillColor.AxialShd, fillColor.Alpha, x, y, pageH); gradient != nil {
|
||||||
return gradient
|
return gradient
|
||||||
}
|
}
|
||||||
if gradient := parseRadialShdGradient(fillColor.RadialShd, fillColor.Alpha, x, y, pageH, originX, originY); gradient != nil {
|
if gradient := parseRadialShdGradient(fillColor.RadialShd, fillColor.Alpha, x, y, pageH); gradient != nil {
|
||||||
return gradient
|
return gradient
|
||||||
}
|
}
|
||||||
if fillColor.AxialShd != nil {
|
if fillColor.AxialShd != nil {
|
||||||
@@ -201,16 +202,16 @@ func parseStrokeColor(strokeColor *StrokeColor) color.Color {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parseStrokePaint 解析勾边画刷
|
// parseStrokePaint 解析勾边画刷
|
||||||
// 入参: strokeColor 勾边颜色节点, x X坐标, y Y坐标, pageH 页面高度, originX 原点X坐标, originY 原点Y坐标
|
// 入参: strokeColor 勾边颜色节点, x X坐标, y Y坐标, pageH 页面高度
|
||||||
// 返回: any 勾边画刷
|
// 返回: any 勾边画刷
|
||||||
func parseStrokePaint(strokeColor *StrokeColor, x, y, pageH, originX, originY float64) any {
|
func parseStrokePaint(strokeColor *StrokeColor, x, y, pageH float64) any {
|
||||||
if strokeColor == nil {
|
if strokeColor == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if gradient := parseAxialShdGradient(strokeColor.AxialShd, strokeColor.Alpha, x, y, pageH, originX, originY); gradient != nil {
|
if gradient := parseAxialShdGradient(strokeColor.AxialShd, strokeColor.Alpha, x, y, pageH); gradient != nil {
|
||||||
return gradient
|
return gradient
|
||||||
}
|
}
|
||||||
if gradient := parseRadialShdGradient(strokeColor.RadialShd, strokeColor.Alpha, x, y, pageH, originX, originY); gradient != nil {
|
if gradient := parseRadialShdGradient(strokeColor.RadialShd, strokeColor.Alpha, x, y, pageH); gradient != nil {
|
||||||
return gradient
|
return gradient
|
||||||
}
|
}
|
||||||
if strokeColor.AxialShd != nil {
|
if strokeColor.AxialShd != nil {
|
||||||
@@ -287,9 +288,9 @@ func parseShdSegments(segments []ShdSegment, alpha *int) canvas.Grad {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parseAxialShdGradient 解析轴向渐变
|
// parseAxialShdGradient 解析轴向渐变
|
||||||
// 入参: axialShd 轴向渐变节点, alpha 透明度, x X坐标, y Y坐标, pageH 页面高度, originX 原点X坐标, originY 原点Y坐标
|
// 入参: axialShd 轴向渐变节点, alpha 透明度, x X坐标, y Y坐标, pageH 页面高度
|
||||||
// 返回: canvas.Gradient 渐变对象
|
// 返回: canvas.Gradient 渐变对象
|
||||||
func parseAxialShdGradient(axialShd *AxialShd, alpha *int, x, y, pageH, originX, originY float64) canvas.Gradient {
|
func parseAxialShdGradient(axialShd *AxialShd, alpha *int, x, y, pageH float64) canvas.Gradient {
|
||||||
if axialShd == nil {
|
if axialShd == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -302,18 +303,51 @@ func parseAxialShdGradient(axialShd *AxialShd, alpha *int, x, y, pageH, originX,
|
|||||||
if gradient == nil {
|
if gradient == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
startPoint := canvas.Point{X: x + start[0] - originX, Y: pageH - (y + start[1]) - originY}
|
startPoint := canvas.Point{X: x + start[0], Y: pageH - (y + start[1])}
|
||||||
endPoint := canvas.Point{X: x + end[0] - originX, Y: pageH - (y + end[1]) - originY}
|
endPoint := canvas.Point{X: x + end[0], Y: pageH - (y + end[1])}
|
||||||
if startPoint.Equals(endPoint) {
|
if startPoint.Equals(endPoint) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return gradient.ToLinear(startPoint, endPoint)
|
return gradient.ToLinear(startPoint, endPoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// axialShdClip 获取轴向渐变的延伸裁剪区域
|
||||||
|
// 入参: ctx 画布上下文, paint 画刷, shading 轴向渐变节点
|
||||||
|
// 返回: *canvas.Path 裁剪区域
|
||||||
|
func axialShdClip(ctx *canvas.Context, paint any, shading *AxialShd) *canvas.Path {
|
||||||
|
gradient, ok := paint.(*canvas.LinearGradient)
|
||||||
|
if !ok || shading == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
extend, _ := strconv.Atoi(shading.Extend)
|
||||||
|
if extend == 3 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
d := gradient.End.Sub(gradient.Start)
|
||||||
|
axis := canvas.Matrix{{d.X, -d.Y, gradient.Start.X}, {d.Y, d.X, gradient.Start.Y}}
|
||||||
|
origin := ctx.CoordView().Dot(canvas.Point{})
|
||||||
|
view := ctx.CoordSystemView().Mul(ctx.View()).Translate(origin.X, origin.Y).Mul(axis)
|
||||||
|
if view.Det() == 0 {
|
||||||
|
return &canvas.Path{}
|
||||||
|
}
|
||||||
|
width, height := ctx.Size()
|
||||||
|
area := (canvas.Rect{X1: width, Y1: height}).Transform(view.Inv())
|
||||||
|
if extend&1 == 0 {
|
||||||
|
area.X0 = math.Max(area.X0, 0)
|
||||||
|
}
|
||||||
|
if extend&2 == 0 {
|
||||||
|
area.X1 = math.Min(area.X1, 1)
|
||||||
|
}
|
||||||
|
if area.X1 <= area.X0 {
|
||||||
|
return &canvas.Path{}
|
||||||
|
}
|
||||||
|
return area.ToPath().Transform(axis)
|
||||||
|
}
|
||||||
|
|
||||||
// parseRadialShdGradient 解析径向渐变
|
// parseRadialShdGradient 解析径向渐变
|
||||||
// 入参: radialShd 径向渐变节点, alpha 透明度, x X坐标, y Y坐标, pageH 页面高度, originX 原点X坐标, originY 原点Y坐标
|
// 入参: radialShd 径向渐变节点, alpha 透明度, x X坐标, y Y坐标, pageH 页面高度
|
||||||
// 返回: canvas.Gradient 渐变对象
|
// 返回: canvas.Gradient 渐变对象
|
||||||
func parseRadialShdGradient(radialShd *RadialShd, alpha *int, x, y, pageH, originX, originY float64) canvas.Gradient {
|
func parseRadialShdGradient(radialShd *RadialShd, alpha *int, x, y, pageH float64) canvas.Gradient {
|
||||||
if radialShd == nil || radialShd.EndRadius <= 0 {
|
if radialShd == nil || radialShd.EndRadius <= 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -326,8 +360,8 @@ func parseRadialShdGradient(radialShd *RadialShd, alpha *int, x, y, pageH, origi
|
|||||||
if gradient == nil {
|
if gradient == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
startPoint := canvas.Point{X: x + start[0] - originX, Y: pageH - (y + start[1]) - originY}
|
startPoint := canvas.Point{X: x + start[0], Y: pageH - (y + start[1])}
|
||||||
endPoint := canvas.Point{X: x + end[0] - originX, Y: pageH - (y + end[1]) - originY}
|
endPoint := canvas.Point{X: x + end[0], Y: pageH - (y + end[1])}
|
||||||
return gradient.ToRadial(startPoint, radialShd.StartRadius, endPoint, radialShd.EndRadius)
|
return gradient.ToRadial(startPoint, radialShd.StartRadius, endPoint, radialShd.EndRadius)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-8
@@ -30,6 +30,8 @@ type pathStyle struct {
|
|||||||
strokeColor color.Color
|
strokeColor color.Color
|
||||||
fillPaint any
|
fillPaint any
|
||||||
strokePaint any
|
strokePaint any
|
||||||
|
fillAxialShd *AxialShd
|
||||||
|
strokeAxialShd *AxialShd
|
||||||
fillPattern *Pattern
|
fillPattern *Pattern
|
||||||
fillPatternColor color.Color
|
fillPatternColor color.Color
|
||||||
lineWidth float64
|
lineWidth float64
|
||||||
@@ -65,7 +67,8 @@ func (s *pathStyle) applyFillColor(fill *FillColor, bx, by, pageH float64, alpha
|
|||||||
s.fillPattern = fillColorNode.Pattern
|
s.fillPattern = fillColorNode.Pattern
|
||||||
s.fillPatternColor = patternColor(fillColorNode)
|
s.fillPatternColor = patternColor(fillColorNode)
|
||||||
s.fillColor = parseFillColor(fillColorNode)
|
s.fillColor = parseFillColor(fillColorNode)
|
||||||
s.fillPaint = parseFillPaint(fillColorNode, bx, by, pageH, 0, 0)
|
s.fillPaint = parseFillPaint(fillColorNode, bx, by, pageH)
|
||||||
|
s.fillAxialShd = fillColorNode.AxialShd
|
||||||
}
|
}
|
||||||
|
|
||||||
// applyStrokeColor 应用描边颜色
|
// applyStrokeColor 应用描边颜色
|
||||||
@@ -73,7 +76,8 @@ func (s *pathStyle) applyFillColor(fill *FillColor, bx, by, pageH float64, alpha
|
|||||||
func (s *pathStyle) applyStrokeColor(stroke *StrokeColor, bx, by, pageH float64, alpha *int) {
|
func (s *pathStyle) applyStrokeColor(stroke *StrokeColor, bx, by, pageH float64, alpha *int) {
|
||||||
strokeColorNode := withStrokeAlpha(stroke, alpha)
|
strokeColorNode := withStrokeAlpha(stroke, alpha)
|
||||||
s.strokeColor = parseStrokeColor(strokeColorNode)
|
s.strokeColor = parseStrokeColor(strokeColorNode)
|
||||||
s.strokePaint = parseStrokePaint(strokeColorNode, bx, by, pageH, 0, 0)
|
s.strokePaint = parseStrokePaint(strokeColorNode, bx, by, pageH)
|
||||||
|
s.strokeAxialShd = strokeColorNode.AxialShd
|
||||||
}
|
}
|
||||||
|
|
||||||
// pathLineCap 转换线帽样式
|
// pathLineCap 转换线帽样式
|
||||||
@@ -211,18 +215,19 @@ func (r *Renderer) renderPath(ctx *canvas.Context, obj PathObject, pageH float64
|
|||||||
style.fillPaint = style.fillColor
|
style.fillPaint = style.fillColor
|
||||||
}
|
}
|
||||||
if shouldFill {
|
if shouldFill {
|
||||||
|
fillClip := intersectClipPath(clipPath, axialShdClip(ctx, style.fillPaint, style.fillAxialShd))
|
||||||
fp := p
|
fp := p
|
||||||
fillRule := canvas.NonZero
|
fillRule := canvas.NonZero
|
||||||
if obj.Rule == "Even-Odd" {
|
if obj.Rule == "Even-Odd" {
|
||||||
fillRule = canvas.EvenOdd
|
fillRule = canvas.EvenOdd
|
||||||
if clipPath != nil || style.fillPattern != nil {
|
if fillClip != nil || style.fillPattern != nil {
|
||||||
fp = fp.Settle(fillRule)
|
fp = fp.Settle(fillRule)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if clipPath != nil {
|
if fillClip != nil {
|
||||||
fp = fp.Copy()
|
fp = fp.Copy()
|
||||||
fp.Close()
|
fp.Close()
|
||||||
fp = applyClipPath(fp, clipPath)
|
fp = applyClipPath(fp, fillClip)
|
||||||
}
|
}
|
||||||
if style.fillPattern != nil {
|
if style.fillPattern != nil {
|
||||||
r.renderPattern(ctx, style.fillPattern, style.fillPatternColor, pageH, fp, ctm, bx, by)
|
r.renderPattern(ctx, style.fillPattern, style.fillPatternColor, pageH, fp, ctm, bx, by)
|
||||||
@@ -253,13 +258,14 @@ func (r *Renderer) renderPath(ctx *canvas.Context, obj PathObject, pageH float64
|
|||||||
if len(style.dashPattern) > 0 {
|
if len(style.dashPattern) > 0 {
|
||||||
ctx.SetDashes(style.dashOffset, style.dashPattern...)
|
ctx.SetDashes(style.dashOffset, style.dashPattern...)
|
||||||
}
|
}
|
||||||
if clipPath != nil {
|
strokeClip := intersectClipPath(clipPath, axialShdClip(ctx, style.strokePaint, style.strokeAxialShd))
|
||||||
|
if strokeClip != nil {
|
||||||
sp := p.Copy()
|
sp := p.Copy()
|
||||||
if len(style.dashPattern) > 0 {
|
if len(style.dashPattern) > 0 {
|
||||||
sp = sp.Dash(style.dashOffset, style.dashPattern...)
|
sp = sp.Dash(style.dashOffset, style.dashPattern...)
|
||||||
}
|
}
|
||||||
sp = sp.Stroke(style.lineWidth, style.lineCap, style.lineJoin, canvas.Tolerance)
|
sp = sp.Stroke(style.lineWidth, style.lineCap, style.lineJoin, canvas.Tolerance)
|
||||||
sp = applyClipPath(sp, clipPath)
|
sp = applyClipPath(sp, strokeClip)
|
||||||
ctx.SetFill(style.strokePaint)
|
ctx.SetFill(style.strokePaint)
|
||||||
ctx.SetStrokeColor(canvas.Transparent)
|
ctx.SetStrokeColor(canvas.Transparent)
|
||||||
ctx.DrawPath(0, 0, sp)
|
ctx.DrawPath(0, 0, sp)
|
||||||
@@ -543,7 +549,6 @@ func applyClipPath(path, clip *canvas.Path) *canvas.Path {
|
|||||||
if pathRect, ok := rectangularPath(path); ok {
|
if pathRect, ok := rectangularPath(path); ok {
|
||||||
return pathRect.And(rect).ToPath()
|
return pathRect.And(rect).ToPath()
|
||||||
}
|
}
|
||||||
return path.Flatten(canvas.Tolerance).Clip(rect.X0, rect.Y0, rect.X1, rect.Y1)
|
|
||||||
}
|
}
|
||||||
return path.And(clip)
|
return path.And(clip)
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-21
@@ -80,17 +80,22 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
|
|||||||
if dp != nil && dp.FillColor != nil {
|
if dp != nil && dp.FillColor != nil {
|
||||||
fillColorNode = withFillAlpha(dp.FillColor, obj.Alpha)
|
fillColorNode = withFillAlpha(dp.FillColor, obj.Alpha)
|
||||||
fillColor = parseFillColor(fillColorNode)
|
fillColor = parseFillColor(fillColorNode)
|
||||||
fillPaint = parseFillPaint(fillColorNode, bx, by, pageH, 0, 0)
|
fillPaint = parseFillPaint(fillColorNode, bx, by, pageH)
|
||||||
}
|
}
|
||||||
if obj.FillColor != nil {
|
if obj.FillColor != nil {
|
||||||
fillColorNode = withFillAlpha(obj.FillColor, obj.Alpha)
|
fillColorNode = withFillAlpha(obj.FillColor, obj.Alpha)
|
||||||
fillColor = parseFillColor(fillColorNode)
|
fillColor = parseFillColor(fillColorNode)
|
||||||
fillPaint = parseFillPaint(fillColorNode, bx, by, pageH, 0, 0)
|
fillPaint = parseFillPaint(fillColorNode, bx, by, pageH)
|
||||||
}
|
}
|
||||||
if fillPaint == nil {
|
if fillPaint == nil {
|
||||||
fillPaint = fillColor
|
fillPaint = fillColor
|
||||||
}
|
}
|
||||||
|
fillClip := clipPath
|
||||||
|
if fillColorNode != nil {
|
||||||
|
fillClip = intersectClipPath(fillClip, axialShdClip(ctx, fillPaint, fillColorNode.AxialShd))
|
||||||
|
}
|
||||||
strokeStyle := newPathStyle(nil, defaultStroke, 0, obj.Alpha)
|
strokeStyle := newPathStyle(nil, defaultStroke, 0, obj.Alpha)
|
||||||
|
strokeClip := clipPath
|
||||||
if shouldStroke {
|
if shouldStroke {
|
||||||
if dp != nil {
|
if dp != nil {
|
||||||
strokeStyle.applyDrawParam(dp, bx, by, pageH, obj.Alpha)
|
strokeStyle.applyDrawParam(dp, bx, by, pageH, obj.Alpha)
|
||||||
@@ -105,6 +110,7 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
|
|||||||
strokeStyle.strokePaint = colorWithAlpha(canvas.Black, obj.Alpha)
|
strokeStyle.strokePaint = colorWithAlpha(canvas.Black, obj.Alpha)
|
||||||
}
|
}
|
||||||
strokeStyle.scale(ctm)
|
strokeStyle.scale(ctm)
|
||||||
|
strokeClip = intersectClipPath(strokeClip, axialShdClip(ctx, strokeStyle.strokePaint, strokeStyle.strokeAxialShd))
|
||||||
}
|
}
|
||||||
fontStyle := canvas.FontRegular
|
fontStyle := canvas.FontRegular
|
||||||
weight := obj.Weight
|
weight := obj.Weight
|
||||||
@@ -144,7 +150,7 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
|
|||||||
face := ff.Face(sizePt, fillPaint, fontStyle, canvas.FontNormal)
|
face := ff.Face(sizePt, fillPaint, fontStyle, canvas.FontNormal)
|
||||||
glyphTransforms := r.textObjectGlyphTransforms(fontID, obj)
|
glyphTransforms := r.textObjectGlyphTransforms(fontID, obj)
|
||||||
hasUnderline := strings.Contains(obj.Decoration, "Underline")
|
hasUnderline := strings.Contains(obj.Decoration, "Underline")
|
||||||
useGlyphFillPaint := fillColorNode != nil && fillColorNode.AxialShd != nil
|
_, axialFill := fillPaint.(*canvas.LinearGradient)
|
||||||
verticalAdvance := (obj.ReadDirection-obj.CharDirection)%180 != 0
|
verticalAdvance := (obj.ReadDirection-obj.CharDirection)%180 != 0
|
||||||
advanceX, advanceY := 1.0, 0.0
|
advanceX, advanceY := 1.0, 0.0
|
||||||
switch obj.ReadDirection {
|
switch obj.ReadDirection {
|
||||||
@@ -168,7 +174,7 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
|
|||||||
}
|
}
|
||||||
dxs, dys := parseFloats(tc.DeltaX), parseFloats(tc.DeltaY)
|
dxs, dys := parseFloats(tc.DeltaX), parseFloats(tc.DeltaY)
|
||||||
xs, ys := parseFloats(tc.X), parseFloats(tc.Y)
|
xs, ys := parseFloats(tc.X), parseFloats(tc.Y)
|
||||||
drawAsPath := embeddedFont || textCodePositioned(tc, xs, ys) || clipPath != nil || shouldStroke
|
drawAsPath := embeddedFont || textCodePositioned(tc, xs, ys) || fillClip != nil || axialFill || shouldStroke
|
||||||
cx, cy := 0.0, 0.0
|
cx, cy := 0.0, 0.0
|
||||||
previousAdvance := 0.0
|
previousAdvance := 0.0
|
||||||
if len(xs) > 0 {
|
if len(xs) > 0 {
|
||||||
@@ -219,10 +225,6 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
|
|||||||
canvasX, canvasY = tx+bx, pageH-(ty+by)
|
canvasX, canvasY = tx+bx, pageH-(ty+by)
|
||||||
}
|
}
|
||||||
textWidth := glyphWidth * hScale
|
textWidth := glyphWidth * hScale
|
||||||
glyphFillPaint := fillPaint
|
|
||||||
if useGlyphFillPaint {
|
|
||||||
glyphFillPaint = parseFillPaint(fillColorNode, bx, by, pageH, canvasX, canvasY)
|
|
||||||
}
|
|
||||||
advanceLimit := 0.0
|
advanceLimit := 0.0
|
||||||
if obj.CharDirection == 0 {
|
if obj.CharDirection == 0 {
|
||||||
advanceLimit = textGlyphAdvanceLimit(dxs, dys, xs, i, len(glyphs), cx)
|
advanceLimit = textGlyphAdvanceLimit(dxs, dys, xs, i, len(glyphs), cx)
|
||||||
@@ -237,10 +239,10 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
|
|||||||
transform = transform.Mul(glyphMatrix)
|
transform = transform.Mul(glyphMatrix)
|
||||||
}
|
}
|
||||||
path := glyphPath.Copy().Transform(transform.Scale(scaleX, 1))
|
path := glyphPath.Copy().Transform(transform.Scale(scaleX, 1))
|
||||||
if shouldFill && glyphFillPaint != nil {
|
if shouldFill && fillPaint != nil {
|
||||||
ctx.SetFill(glyphFillPaint)
|
ctx.SetFill(fillPaint)
|
||||||
ctx.SetStrokeColor(canvas.Transparent)
|
ctx.SetStrokeColor(canvas.Transparent)
|
||||||
ctx.DrawPath(0, 0, applyClipPath(path.Copy(), clipPath))
|
ctx.DrawPath(0, 0, applyClipPath(path.Copy(), fillClip))
|
||||||
}
|
}
|
||||||
if len(strokeStyle.dashPattern) > 0 {
|
if len(strokeStyle.dashPattern) > 0 {
|
||||||
path = path.Dash(strokeStyle.dashOffset, strokeStyle.dashPattern...)
|
path = path.Dash(strokeStyle.dashOffset, strokeStyle.dashPattern...)
|
||||||
@@ -248,7 +250,7 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
|
|||||||
path = path.Stroke(strokeStyle.lineWidth, strokeStyle.lineCap, strokeStyle.lineJoin, canvas.Tolerance)
|
path = path.Stroke(strokeStyle.lineWidth, strokeStyle.lineCap, strokeStyle.lineJoin, canvas.Tolerance)
|
||||||
ctx.SetFill(strokeStyle.strokePaint)
|
ctx.SetFill(strokeStyle.strokePaint)
|
||||||
ctx.SetStrokeColor(canvas.Transparent)
|
ctx.SetStrokeColor(canvas.Transparent)
|
||||||
ctx.DrawPath(0, 0, applyClipPath(path, clipPath))
|
ctx.DrawPath(0, 0, applyClipPath(path, strokeClip))
|
||||||
if hasUnderline {
|
if hasUnderline {
|
||||||
underline := &canvas.Path{}
|
underline := &canvas.Path{}
|
||||||
underline.MoveTo(0, -sizeMM*0.1)
|
underline.MoveTo(0, -sizeMM*0.1)
|
||||||
@@ -261,9 +263,9 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if glyphFillPaint != nil {
|
if fillPaint != nil {
|
||||||
ctx.SetFill(glyphFillPaint)
|
ctx.SetFill(fillPaint)
|
||||||
if clipPath != nil {
|
if fillClip != nil || axialFill {
|
||||||
scaleX := hScale
|
scaleX := hScale
|
||||||
if advanceLimit > 0 && glyphWidth*scaleX > advanceLimit {
|
if advanceLimit > 0 && glyphWidth*scaleX > advanceLimit {
|
||||||
scaleX = advanceLimit / glyphWidth
|
scaleX = advanceLimit / glyphWidth
|
||||||
@@ -273,7 +275,7 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
|
|||||||
if useTextMatrix {
|
if useTextMatrix {
|
||||||
textTransform = textTransform.Mul(glyphMatrix)
|
textTransform = textTransform.Mul(glyphMatrix)
|
||||||
}
|
}
|
||||||
glyphPath = applyClipPath(glyphPath.Copy().Transform(textTransform.Scale(scaleX, 1)), clipPath)
|
glyphPath = applyClipPath(glyphPath.Copy().Transform(textTransform.Scale(scaleX, 1)), fillClip)
|
||||||
ctx.DrawPath(0, 0, glyphPath)
|
ctx.DrawPath(0, 0, glyphPath)
|
||||||
if hasUnderline {
|
if hasUnderline {
|
||||||
uw := sizeMM * 0.05
|
uw := sizeMM * 0.05
|
||||||
@@ -313,11 +315,7 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
|
|||||||
ctx.Scale(hScale, 1)
|
ctx.Scale(hScale, 1)
|
||||||
x, y = 0, 0
|
x, y = 0, 0
|
||||||
}
|
}
|
||||||
textFace := face
|
text := canvas.NewTextLine(face, str, canvas.Left)
|
||||||
if useGlyphFillPaint {
|
|
||||||
textFace = ff.Face(sizePt, glyphFillPaint, fontStyle, canvas.FontNormal)
|
|
||||||
}
|
|
||||||
text := canvas.NewTextLine(textFace, str, canvas.Left)
|
|
||||||
ctx.DrawText(x, y, text)
|
ctx.DrawText(x, y, text)
|
||||||
if scaled {
|
if scaled {
|
||||||
ctx.Pop()
|
ctx.Pop()
|
||||||
|
|||||||
Reference in new issue
Block a user