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