1
0
mirror of https://github.com/fumiama/go-docx.git synced 2026-06-08 17:20:26 +08:00

完善group

This commit is contained in:
源文雨
2023-03-05 23:02:07 +08:00
parent ff131af5fa
commit 50aa6e005e
6 changed files with 257 additions and 141 deletions

View File

@@ -30,8 +30,10 @@ import (
type WordprocessingGroup struct {
XMLName xml.Name `xml:"wpg:wgp,omitempty"`
CNvGrpSpPr *WPGcNvGrpSpPr
GroupShapeProperties *WPGGroupShapeProperties
GroupShapeProperties *ShapeProperties `xml:"wpg:grpSpPr,omitempty"`
Elems []interface{}
file *Docx
}
// UnmarshalXML ...
@@ -55,7 +57,7 @@ func (w *WordprocessingGroup) UnmarshalXML(d *xml.Decoder, start xml.StartElemen
}
w.CNvGrpSpPr = &value
case "grpSpPr":
var value WPGGroupShapeProperties
var value ShapeProperties
err = d.DecodeElement(&value, &tt)
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
return err
@@ -70,6 +72,23 @@ func (w *WordprocessingGroup) UnmarshalXML(d *xml.Decoder, start xml.StartElemen
w.Elems = append(w.Elems, &value)
case "wsp":
var value WordprocessingShape
value.file = w.file
err = d.DecodeElement(&value, &tt)
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
return err
}
w.Elems = append(w.Elems, &value)
case "wpc":
var value WordprocessingCanvas
value.file = w.file
err = d.DecodeElement(&value, &tt)
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
return err
}
w.Elems = append(w.Elems, &value)
case "grpSp":
var value WPGGroupShape
value.file = w.file
err = d.DecodeElement(&value, &tt)
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
return err
@@ -129,8 +148,82 @@ type AGroupShapeLocks struct {
XMLName xml.Name `xml:"a:grpSpLocks,omitempty"`
}
// WPGGroupShapeProperties represents the properties applied to a group shape.
type WPGGroupShapeProperties struct {
XMLName xml.Name `xml:"wpg:grpSpPr,omitempty"`
Xfrm *AXfrm
// WPGGroupShape ...
type WPGGroupShape struct {
XMLName xml.Name `xml:"wpg:grpSp,omitempty"`
CNvPr *NonVisualProperties `xml:"wpg:cNvPr,omitempty"`
CNvGrpSpPr *WPGcNvGrpSpPr
GroupShapeProperties *ShapeProperties `xml:"wpg:grpSpPr,omitempty"`
Elems []interface{}
file *Docx
}
// UnmarshalXML ...
func (w *WPGGroupShape) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for {
t, err := d.Token()
if err == io.EOF {
break
}
if err != nil {
return err
}
if tt, ok := t.(xml.StartElement); ok {
switch tt.Name.Local {
case "cNvPr":
var value NonVisualProperties
err = d.DecodeElement(&value, &tt)
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
return err
}
w.CNvPr = &value
case "cNvGrpSpPr":
var value WPGcNvGrpSpPr
err = d.DecodeElement(&value, &tt)
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
return err
}
w.CNvGrpSpPr = &value
case "grpSpPr":
var value ShapeProperties
err = d.DecodeElement(&value, &tt)
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
return err
}
w.GroupShapeProperties = &value
case "pic":
var value Picture
err = d.DecodeElement(&value, &tt)
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
return err
}
w.Elems = append(w.Elems, &value)
case "wsp":
var value WordprocessingShape
value.file = w.file
err = d.DecodeElement(&value, &tt)
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
return err
}
w.Elems = append(w.Elems, &value)
case "wpc":
var value WordprocessingCanvas
value.file = w.file
err = d.DecodeElement(&value, &tt)
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
return err
}
w.Elems = append(w.Elems, &value)
default:
err = d.Skip() // skip unsupported tags
if err != nil {
return err
}
continue
}
}
}
return nil
}