mirror of
https://github.com/fumiama/go-docx.git
synced 2026-06-05 07:40:24 +08:00
finish drawing unmarshalling
This commit is contained in:
@@ -568,7 +568,11 @@ func TestUnmarshalDrawingStructure(t *testing.T) {
|
||||
}
|
||||
if child.Run.Drawing.Inline.Graphic != nil && child.Run.Drawing.Inline.Graphic.GraphicData != nil {
|
||||
t.Log(child.Run.Drawing.Inline.Graphic.GraphicData.URI)
|
||||
if child.Run.Drawing.Inline.Graphic.GraphicData.Pic != nil {
|
||||
t.Log(child.Run.Drawing.Inline.Graphic.GraphicData.Pic.NonVisualPicProperties.NonVisualDrawingProperties.ID, child.Run.Drawing.Inline.Graphic.GraphicData.Pic.BlipFill.Blip.Embed)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,14 +155,65 @@ func (a *AGraphic) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
type AGraphicData struct {
|
||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/main graphicData,omitempty"`
|
||||
URI string `xml:"uri,attr"`
|
||||
Pic PICPic
|
||||
Pic *PICPic
|
||||
}
|
||||
|
||||
func (a *AGraphicData) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
for {
|
||||
t, err := d.Token()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
|
||||
switch tt := t.(type) {
|
||||
case xml.StartElement:
|
||||
switch tt.Name.Local {
|
||||
case "pic":
|
||||
var value PICPic
|
||||
d.DecodeElement(&value, &start)
|
||||
a.Pic = &value
|
||||
default:
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PICPic represents a picture in a Word document.
|
||||
type PICPic struct {
|
||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/picture pic,omitempty"`
|
||||
NonVisualPicProperties PICNonVisualPicProperties
|
||||
BlipFill PICBlipFill
|
||||
NonVisualPicProperties *PICNonVisualPicProperties
|
||||
BlipFill *PICBlipFill
|
||||
// <pic:spPr> is unecessary
|
||||
}
|
||||
|
||||
func (p *PICPic) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
for {
|
||||
t, err := d.Token()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
|
||||
switch tt := t.(type) {
|
||||
case xml.StartElement:
|
||||
switch tt.Name.Local {
|
||||
case "nvPicPr":
|
||||
var value PICNonVisualPicProperties
|
||||
d.DecodeElement(&value, &start)
|
||||
p.NonVisualPicProperties = &value
|
||||
case "blipFill":
|
||||
var value PICBlipFill
|
||||
d.DecodeElement(&value, &start)
|
||||
p.BlipFill = &value
|
||||
default:
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PICNonVisualPicProperties represents the non-visual properties of a picture in a Word document.
|
||||
@@ -171,6 +222,27 @@ type PICNonVisualPicProperties struct {
|
||||
NonVisualDrawingProperties PICNonVisualDrawingProperties
|
||||
}
|
||||
|
||||
func (p *PICNonVisualPicProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
for {
|
||||
t, err := d.Token()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
|
||||
switch tt := t.(type) {
|
||||
case xml.StartElement:
|
||||
switch tt.Name.Local {
|
||||
case "cNvPr":
|
||||
p.NonVisualDrawingProperties.ID = getAtt(tt.Attr, "id")
|
||||
default:
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PICNonVisualDrawingProperties represents the non-visual drawing properties of a picture in a Word document.
|
||||
type PICNonVisualDrawingProperties struct {
|
||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/picture cNvPr,omitempty"`
|
||||
@@ -183,6 +255,27 @@ type PICBlipFill struct {
|
||||
Blip ABlip
|
||||
}
|
||||
|
||||
func (p *PICBlipFill) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
for {
|
||||
t, err := d.Token()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
|
||||
switch tt := t.(type) {
|
||||
case xml.StartElement:
|
||||
switch tt.Name.Local {
|
||||
case "blip":
|
||||
p.Blip.Embed = getAtt(tt.Attr, "embed")
|
||||
default:
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ABlip represents the blip of a picture in a Word document.
|
||||
type ABlip struct {
|
||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/main blip,omitempty"`
|
||||
|
||||
Reference in New Issue
Block a user