mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-08-30 12:12:40 +08:00
feat(电子发票): 修复一个非标准发票解析问题
This commit is contained in:
+17
-4
@@ -805,8 +805,8 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
|
||||
if i < len(xs) {
|
||||
cx = xs[i]
|
||||
} else if i > 0 {
|
||||
if i-1 < len(dxs) {
|
||||
cx += dxs[i-1]
|
||||
if dx, ok := textDelta(dxs, i-1); ok {
|
||||
cx += dx
|
||||
} else if len(dys) == 0 {
|
||||
cx += face.TextWidth(str)
|
||||
}
|
||||
@@ -814,8 +814,8 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
|
||||
if i < len(ys) {
|
||||
cy = ys[i]
|
||||
} else if i > 0 {
|
||||
if i-1 < len(dys) {
|
||||
cy += dys[i-1]
|
||||
if dy, ok := textDelta(dys, i-1); ok {
|
||||
cy += dy
|
||||
}
|
||||
}
|
||||
tx, ty := ctm.Transform(cx, cy)
|
||||
@@ -875,6 +875,19 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
|
||||
ctx.Pop()
|
||||
}
|
||||
|
||||
// textDelta 获取文本偏移量
|
||||
// 入参: deltas 偏移量数组, index 偏移量索引
|
||||
// 返回: float64 偏移量, bool 是否存在
|
||||
func textDelta(deltas []float64, index int) (float64, bool) {
|
||||
if len(deltas) == 0 {
|
||||
return 0, false
|
||||
}
|
||||
if index < len(deltas) {
|
||||
return deltas[index], true
|
||||
}
|
||||
return deltas[len(deltas)-1], true
|
||||
}
|
||||
|
||||
// hasTextMatrix 判断文本是否需要应用字形变换
|
||||
// 入参: ctm 变换矩阵
|
||||
// 返回: bool 是否需要变换
|
||||
|
||||
Reference in New Issue
Block a user