mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 08:46:55 +08:00
1 parent
ee873443e0
commit
28175723e6
5 files changed
+28
-19
No files matched your search
@@ -10,7 +10,7 @@ require (
|
||||
github.com/tdewolff/canvas v0.0.0-20260923214215-09804640d00c
|
||||
github.com/tdewolff/font v0.0.0-20260913163313-54f98bb59ee6
|
||||
github.com/xiaoqidun/jbig2 v1.1.1
|
||||
github.com/xiaoqidun/pdfgo v0.0.0-20261008072006-d519e7a38749
|
||||
github.com/xiaoqidun/pdfgo v0.0.0-20261008074859-a724a7b51281
|
||||
golang.org/x/crypto v0.57.0
|
||||
golang.org/x/image v0.46.0
|
||||
golang.org/x/text v0.42.0
|
||||
|
||||
@@ -62,8 +62,8 @@ github.com/tdewolff/test v1.0.12 h1:7F21DqIajswxuche0geHdrUZRCWE4oko4b7bcmkkrxk=
|
||||
github.com/tdewolff/test v1.0.12/go.mod h1:XPuWBzvdUzhCuxWO1ojpXsyzsA5bFoS3tO/Q3kFuTG8=
|
||||
github.com/xiaoqidun/jbig2 v1.1.1 h1:SjliS9ZO0e9HX5oYUfBuXrfFsXhWricrSz+XY4zORDI=
|
||||
github.com/xiaoqidun/jbig2 v1.1.1/go.mod h1:8QonVWtENmh2kc6l+leqeGl7psb79DWlHDkCpdChjfQ=
|
||||
github.com/xiaoqidun/pdfgo v0.0.0-20261008072006-d519e7a38749 h1:jWImuld2SXZp826sudLJJUUOEEMPj/Jy77ItAE778Sg=
|
||||
github.com/xiaoqidun/pdfgo v0.0.0-20261008072006-d519e7a38749/go.mod h1:4Pf0JO0BEf1uzRY+uZjlMjN/OPn3PYa0YMi6cqPPTLQ=
|
||||
github.com/xiaoqidun/pdfgo v0.0.0-20261008074859-a724a7b51281 h1:xtRrxDRoPCN+IzqaAC8BR334Uif9VScpwTa4fk2gfBg=
|
||||
github.com/xiaoqidun/pdfgo v0.0.0-20261008074859-a724a7b51281/go.mod h1:4Pf0JO0BEf1uzRY+uZjlMjN/OPn3PYa0YMi6cqPPTLQ=
|
||||
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
||||
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
||||
github.com/yuin/goldmark v1.8.5 h1:r6N5afV5qj/5S4UTch8agZHJ8UxNCMwX7WjkkJam2NA=
|
||||
|
||||
+14
-13
@@ -613,37 +613,38 @@ func (p *pdfImporter) compositeObjects(nodes []pdfCompositeNode) error {
|
||||
|
||||
// opaque 检查图元是否无需与页面背景混合
|
||||
// 入参: space 当前混合空间
|
||||
// 返回: bool 是否可直接保留
|
||||
func (n pdfCompositeNode) opaque(space *pdfgo.ColorSpace) bool {
|
||||
// 返回: bool 是否可直接保留, error 遮罩解析错误
|
||||
func (n pdfCompositeNode) opaque(space *pdfgo.ColorSpace) (bool, error) {
|
||||
if n.group != nil {
|
||||
g := n.group
|
||||
if g.Knockout && n.textObject == nil || g.Alpha != 1 || g.SoftMask != nil || !pdfNormalBlend(g.BlendMode) || g.ColorSpace != nil && !g.ColorSpace.Equal(space) {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
for _, child := range n.children {
|
||||
if !child.opaque(space) {
|
||||
return false
|
||||
if opaque, err := child.opaque(space); err != nil || !opaque {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
return true
|
||||
return true, nil
|
||||
}
|
||||
style, fill, stroke := n.style()
|
||||
if n.image != nil && style.FillOverprint {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
if style.SoftMask != nil || !pdfNormalBlend(style.BlendMode) || fill && style.Fill.Alpha != 1 || stroke && style.Stroke.Alpha != 1 {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
if fill && style.FillOverprint && pdfOverprintNeedsSeparation(style.Fill) || stroke && style.StrokeOverprint && pdfOverprintNeedsSeparation(style.Stroke) {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
if fill && pdfGradientError(style.Fill) != nil || stroke && pdfGradientError(style.Stroke) != nil {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
if n.image != nil && (n.image.Image.Mask != nil || n.image.Image.SoftMask != nil) {
|
||||
return false
|
||||
if n.image != nil {
|
||||
masked, err := n.image.Image.HasMask()
|
||||
return !masked, err
|
||||
}
|
||||
return true
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// direct 检查sRGB图元能否使用标准OFD透明度而无需背景合成
|
||||
|
||||
@@ -228,7 +228,7 @@ func (p *pdfImporter) compositePattern(paint pdfgo.Paint) (*pdfCompositePattern,
|
||||
|
||||
// directCompositeNode 检查图元、透明组和图案单元能否独立保留,逐层核对背景混合
|
||||
// 入参: node 图元, space 混合空间
|
||||
// 返回: bool 是否可直接转换, error 图案解析错误
|
||||
// 返回: bool 是否可直接转换, error 图案或遮罩解析错误
|
||||
func (p *pdfImporter) directCompositeNode(node pdfCompositeNode, space *pdfgo.ColorSpace) (bool, error) {
|
||||
if node.group == nil && space.Device() {
|
||||
style, fill, stroke := node.style()
|
||||
@@ -290,7 +290,11 @@ func (p *pdfImporter) directCompositeNode(node pdfCompositeNode, space *pdfgo.Co
|
||||
if group := node.group; group != nil && !group.Knockout && group.Alpha == 1 && group.SoftMask == nil && pdfNormalBlend(group.BlendMode) && (group.ColorSpace == nil || group.ColorSpace.SRGBEquivalent()) {
|
||||
directGroup = true
|
||||
}
|
||||
if !node.opaque(space) && !(space.SRGBEquivalent() && (directGroup || node.direct())) {
|
||||
opaque, err := node.opaque(space)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if !opaque && !(space.SRGBEquivalent() && (directGroup || node.direct())) {
|
||||
if node.textObject != nil && space.SRGBEquivalent() {
|
||||
for _, child := range node.children {
|
||||
if direct, err := p.directCompositeNode(child, space); err != nil || !direct {
|
||||
|
||||
+5
-1
@@ -101,7 +101,11 @@ func pdfOpaqueVisitor(visitor pdfgo.Visitor) pdfgo.Visitor {
|
||||
return check(m.Style, m.Mode%4 == 0 || m.Mode%4 == 2, m.Mode%4 == 1 || m.Mode%4 == 2)
|
||||
},
|
||||
Image: func(m pdfgo.ImageMark) error {
|
||||
if m.Image.ImageMask || m.Image.Mask != nil || m.Image.SoftMask != nil || m.Image.Stream.Dictionary["SMaskInData"] != nil {
|
||||
masked, err := m.Image.HasMask()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if masked {
|
||||
return &pdfgo.UnsupportedError{Feature: "non-sRGB masked group image"}
|
||||
}
|
||||
return check(m.Style, true, false)
|
||||
|
||||
Reference in new issue
Block a user