mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-30 12:35:22 +08:00
1 parent
bec13d523f
commit
b3c4bbc844
45 files changed
+1885
-1453
No files matched your search
+2
-47
@@ -15,11 +15,9 @@
|
||||
package ofdgo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"math"
|
||||
|
||||
codecpdf "github.com/xiaoqidun/ofdgo/internal/codec/pdf"
|
||||
"github.com/xiaoqidun/pdfgo"
|
||||
)
|
||||
|
||||
@@ -79,54 +77,11 @@ func pdfClipContainsBoundary(path pdfgo.Path, matrix pdfgo.Matrix, boundary Box)
|
||||
return left < right && top < bottom && boundary.X >= left && boundary.Y >= top && boundary.X+boundary.W <= right && boundary.Y+boundary.H <= bottom
|
||||
}
|
||||
|
||||
// pdfClipPathKey 按路径完整内容与变换生成键,不依赖可变切片的地址
|
||||
// 入参: ctx 取消上下文, path 裁剪路径, matrix 页面变换
|
||||
// 返回: [32]byte 内容摘要, error 取消错误
|
||||
func pdfClipPathKey(ctx context.Context, path pdfgo.Path, matrix pdfgo.Matrix) ([32]byte, error) {
|
||||
hash := sha256.New()
|
||||
var value [16]byte
|
||||
for _, number := range matrix {
|
||||
binary.LittleEndian.PutUint64(value[:8], math.Float64bits(number))
|
||||
hash.Write(value[:8])
|
||||
}
|
||||
binary.LittleEndian.PutUint64(value[:8], uint64(len(path.Segments)))
|
||||
value[8] = 0
|
||||
if path.EvenOdd {
|
||||
value[8] = 1
|
||||
}
|
||||
hash.Write(value[:9])
|
||||
for _, segment := range path.Segments {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return [32]byte{}, err
|
||||
}
|
||||
binary.LittleEndian.PutUint64(value[:8], uint64(len(segment.Operator)))
|
||||
binary.LittleEndian.PutUint64(value[8:], uint64(len(segment.Points)))
|
||||
hash.Write(value[:])
|
||||
hash.Write([]byte(segment.Operator))
|
||||
for index, point := range segment.Points {
|
||||
if index&255 == 0 {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return [32]byte{}, err
|
||||
}
|
||||
}
|
||||
binary.LittleEndian.PutUint64(value[:8], math.Float64bits(point.X))
|
||||
binary.LittleEndian.PutUint64(value[8:], math.Float64bits(point.Y))
|
||||
hash.Write(value[:])
|
||||
}
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return [32]byte{}, err
|
||||
}
|
||||
var key [32]byte
|
||||
hash.Sum(key[:0])
|
||||
return key, nil
|
||||
}
|
||||
|
||||
// clipPath 复用页面内重复路径编码,按估算字节预算淘汰且不缓存错误
|
||||
// 入参: path 裁剪路径
|
||||
// 返回: pdfClipPath 变换后的边界及编码, error 取消错误
|
||||
func (p *pdfImporter) clipPath(path pdfgo.Path) (pdfClipPath, error) {
|
||||
key, err := pdfClipPathKey(p.ctx, path, p.matrix)
|
||||
key, err := codecpdf.ClipPathKey(p.ctx, path, p.matrix)
|
||||
if err != nil {
|
||||
return pdfClipPath{}, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user