mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 16:59:27 +08:00
1 parent
36c0dc3ca0
commit
6c3068b813
2 files changed
+18
-7
No files matched your search
@@ -174,7 +174,7 @@ func (e *Editor) outputSnapshot(ctx context.Context, options WriteOptions) (*Edi
|
|||||||
return &snapshot, nil
|
return &snapshot, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// compressionImageSafety 保护蒙版资源,识别不能可靠降采样的图案及隐藏内容
|
// compressionImageSafety 保护蒙版及其原图和替换图像,识别不能可靠降采样的图案及隐藏内容
|
||||||
// 入参: ctx 取消上下文, images 图片资源
|
// 入参: ctx 取消上下文, images 图片资源
|
||||||
// 返回: map[string]bool 只能无损处理的资源路径, bool 是否可分析尺寸, error 读取或取消错误
|
// 返回: map[string]bool 只能无损处理的资源路径, bool 是否可分析尺寸, error 读取或取消错误
|
||||||
func (r *Reader) compressionImageSafety(ctx context.Context, images []ImageInfo) (map[string]bool, bool, error) {
|
func (r *Reader) compressionImageSafety(ctx context.Context, images []ImageInfo) (map[string]bool, bool, error) {
|
||||||
@@ -251,7 +251,7 @@ func (r *Reader) compressionImageSafety(ctx context.Context, images []ImageInfo)
|
|||||||
if element.Name.Local == "Pattern" {
|
if element.Name.Local == "Pattern" {
|
||||||
geometry = false
|
geometry = false
|
||||||
}
|
}
|
||||||
resource, masked := "", false
|
resource, substitution, masked := "", "", false
|
||||||
for _, attr := range element.Attr {
|
for _, attr := range element.Attr {
|
||||||
if attr.Name.Space != "" {
|
if attr.Name.Space != "" {
|
||||||
continue
|
continue
|
||||||
@@ -262,6 +262,9 @@ func (r *Reader) compressionImageSafety(ctx context.Context, images []ImageInfo)
|
|||||||
if attr.Name.Local == "ResourceID" {
|
if attr.Name.Local == "ResourceID" {
|
||||||
resource = editorResourceID(attr.Value)
|
resource = editorResourceID(attr.Value)
|
||||||
}
|
}
|
||||||
|
if attr.Name.Local == "Substitution" {
|
||||||
|
substitution = editorResourceID(attr.Value)
|
||||||
|
}
|
||||||
if attr.Name.Local == "ImageMask" {
|
if attr.Name.Local == "ImageMask" {
|
||||||
masks[editorResourceID(attr.Value)] = true
|
masks[editorResourceID(attr.Value)] = true
|
||||||
masked = true
|
masked = true
|
||||||
@@ -269,6 +272,9 @@ func (r *Reader) compressionImageSafety(ctx context.Context, images []ImageInfo)
|
|||||||
}
|
}
|
||||||
if masked {
|
if masked {
|
||||||
masks[resource] = true
|
masks[resource] = true
|
||||||
|
if substitution != "" {
|
||||||
|
masks[substitution] = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case xml.EndElement:
|
case xml.EndElement:
|
||||||
stack = stack[:len(stack)-1]
|
stack = stack[:len(stack)-1]
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ func (r *Reader) compressionImageSizes(ctx context.Context, images []ImageInfo,
|
|||||||
return result, ctx.Err()
|
return result, ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
// DrawObject 收集图片的完整显示尺寸,不使用裁剪后的局部面积
|
// DrawObject 汇总原图和替换图像的完整显示尺寸,不使用裁剪后的局部面积
|
||||||
// 入参: object 图形对象, state 继承状态
|
// 入参: object 图形对象, state 继承状态
|
||||||
// 返回: error 取消或几何错误
|
// 返回: error 取消或几何错误
|
||||||
func (v *compressionImages) DrawObject(object *GraphicObject, state RenderState) error {
|
func (v *compressionImages) DrawObject(object *GraphicObject, state RenderState) error {
|
||||||
@@ -168,8 +168,8 @@ func (v *compressionImages) DrawObject(object *GraphicObject, state RenderState)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
img := object.ImageObject
|
img := object.ImageObject
|
||||||
id := editorResourceID(img.ResourceID)
|
ids := [2]string{editorResourceID(img.ResourceID), editorResourceID(img.Substitution)}
|
||||||
if id == "" {
|
if ids[0] == "" || img.Substitution != "" && ids[1] == "" {
|
||||||
return fmt.Errorf("invalid image resource")
|
return fmt.Errorf("invalid image resource")
|
||||||
}
|
}
|
||||||
box, err := ParseBox(img.Boundary)
|
box, err := ParseBox(img.Boundary)
|
||||||
@@ -185,8 +185,13 @@ func (v *compressionImages) DrawObject(object *GraphicObject, state RenderState)
|
|||||||
if size.X == 0 || size.Y == 0 {
|
if size.X == 0 || size.Y == 0 {
|
||||||
return fmt.Errorf("invalid image placement")
|
return fmt.Errorf("invalid image placement")
|
||||||
}
|
}
|
||||||
old := v.sizes[id]
|
for _, id := range ids {
|
||||||
v.sizes[id] = image.Pt(max(old.X, size.X), max(old.Y, size.Y))
|
if id == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
old := v.sizes[id]
|
||||||
|
v.sizes[id] = image.Pt(max(old.X, size.X), max(old.Y, size.Y))
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user