mirror of
https://github.com/fumiama/go-docx.git
synced 2026-06-10 10:23:19 +08:00
simplify drawing namespace
This commit is contained in:
@@ -47,9 +47,11 @@ func (p *Paragraph) AddInlineDrawing(pic []byte) (*Run, error) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Graphic: &AGraphic{
|
Graphic: &AGraphic{
|
||||||
|
XMLA: XMLNS_DRAWINGML_MAIN,
|
||||||
GraphicData: &AGraphicData{
|
GraphicData: &AGraphicData{
|
||||||
URI: XMLNS_PICTURE,
|
URI: XMLNS_PICTURE,
|
||||||
Pic: &PICPic{
|
Pic: &PICPic{
|
||||||
|
XMLPIC: XMLNS_DRAWINGML_PICTURE,
|
||||||
NonVisualPicProperties: &PICNonVisualPicProperties{
|
NonVisualPicProperties: &PICNonVisualPicProperties{
|
||||||
NonVisualDrawingProperties: PICNonVisualDrawingProperties{
|
NonVisualDrawingProperties: PICNonVisualDrawingProperties{
|
||||||
ID: id,
|
ID: id,
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ func main() {
|
|||||||
fmt.Printf("\tWe've found a new run with the text ->%s\n", child.Run.Text.Text)
|
fmt.Printf("\tWe've found a new run with the text ->%s\n", child.Run.Text.Text)
|
||||||
}
|
}
|
||||||
if child.Run.Drawing != nil {
|
if child.Run.Drawing != nil {
|
||||||
fmt.Printf("\tWe've found a new run with the drawing ->%d\n", child.Run.Drawing.Inline.DistT) // TODO: replace to refid
|
fmt.Printf("\tWe've found a new run with the drawing ->%s\n", child.Run.Drawing.Inline.DocPr.Name) // TODO: replace to refid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if child.Link != nil {
|
if child.Link != nil {
|
||||||
|
|||||||
@@ -11,6 +11,11 @@ const (
|
|||||||
A4_EMU_MAX_WIDTH = 5274310
|
A4_EMU_MAX_WIDTH = 5274310
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
XMLNS_DRAWINGML_MAIN = `http://schemas.openxmlformats.org/drawingml/2006/main`
|
||||||
|
XMLNS_DRAWINGML_PICTURE = `http://schemas.openxmlformats.org/drawingml/2006/picture`
|
||||||
|
)
|
||||||
|
|
||||||
// Drawing element contains photos
|
// Drawing element contains photos
|
||||||
type Drawing struct {
|
type Drawing struct {
|
||||||
XMLName xml.Name `xml:"w:drawing,omitempty"`
|
XMLName xml.Name `xml:"w:drawing,omitempty"`
|
||||||
@@ -132,6 +137,7 @@ func (r *WPInline) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
|||||||
case "graphic":
|
case "graphic":
|
||||||
var value AGraphic
|
var value AGraphic
|
||||||
d.DecodeElement(&value, &start)
|
d.DecodeElement(&value, &start)
|
||||||
|
value.XMLA = getAtt(tt.Attr, "a")
|
||||||
r.Graphic = &value
|
r.Graphic = &value
|
||||||
default:
|
default:
|
||||||
continue
|
continue
|
||||||
@@ -214,7 +220,8 @@ type AGraphicFrameLocks struct {
|
|||||||
|
|
||||||
// AGraphic represents a graphic in a Word document.
|
// AGraphic represents a graphic in a Word document.
|
||||||
type AGraphic struct {
|
type AGraphic struct {
|
||||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/main graphic,omitempty"`
|
XMLName xml.Name `xml:"a:graphic,omitempty"`
|
||||||
|
XMLA string `xml:"xmlns:a,attr,omitempty"`
|
||||||
GraphicData *AGraphicData
|
GraphicData *AGraphicData
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,7 +254,7 @@ func (a *AGraphic) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
|||||||
|
|
||||||
// AGraphicData represents the data of a graphic in a Word document.
|
// AGraphicData represents the data of a graphic in a Word document.
|
||||||
type AGraphicData struct {
|
type AGraphicData struct {
|
||||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/main graphicData,omitempty"`
|
XMLName xml.Name `xml:"a:graphicData,omitempty"`
|
||||||
URI string `xml:"uri,attr"`
|
URI string `xml:"uri,attr"`
|
||||||
Pic *PICPic
|
Pic *PICPic
|
||||||
}
|
}
|
||||||
@@ -268,6 +275,7 @@ func (a *AGraphicData) UnmarshalXML(d *xml.Decoder, start xml.StartElement) erro
|
|||||||
case "pic":
|
case "pic":
|
||||||
var value PICPic
|
var value PICPic
|
||||||
d.DecodeElement(&value, &start)
|
d.DecodeElement(&value, &start)
|
||||||
|
value.XMLPIC = getAtt(tt.Attr, "pic")
|
||||||
a.Pic = &value
|
a.Pic = &value
|
||||||
default:
|
default:
|
||||||
continue
|
continue
|
||||||
@@ -280,7 +288,8 @@ func (a *AGraphicData) UnmarshalXML(d *xml.Decoder, start xml.StartElement) erro
|
|||||||
|
|
||||||
// PICPic represents a picture in a Word document.
|
// PICPic represents a picture in a Word document.
|
||||||
type PICPic struct {
|
type PICPic struct {
|
||||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/picture pic,omitempty"`
|
XMLName xml.Name `xml:"pic:pic,omitempty"`
|
||||||
|
XMLPIC string `xml:"xmlns:pic,attr,omitempty"`
|
||||||
NonVisualPicProperties *PICNonVisualPicProperties
|
NonVisualPicProperties *PICNonVisualPicProperties
|
||||||
BlipFill *PICBlipFill
|
BlipFill *PICBlipFill
|
||||||
SpPr *PICSpPr
|
SpPr *PICSpPr
|
||||||
@@ -322,7 +331,7 @@ func (p *PICPic) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
|||||||
|
|
||||||
// PICNonVisualPicProperties represents the non-visual properties of a picture in a Word document.
|
// PICNonVisualPicProperties represents the non-visual properties of a picture in a Word document.
|
||||||
type PICNonVisualPicProperties struct {
|
type PICNonVisualPicProperties struct {
|
||||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/picture nvPicPr,omitempty"`
|
XMLName xml.Name `xml:"pic:nvPicPr,omitempty"`
|
||||||
NonVisualDrawingProperties PICNonVisualDrawingProperties
|
NonVisualDrawingProperties PICNonVisualDrawingProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,13 +361,13 @@ func (p *PICNonVisualPicProperties) UnmarshalXML(d *xml.Decoder, start xml.Start
|
|||||||
|
|
||||||
// PICNonVisualDrawingProperties represents the non-visual drawing properties of a picture in a Word document.
|
// PICNonVisualDrawingProperties represents the non-visual drawing properties of a picture in a Word document.
|
||||||
type PICNonVisualDrawingProperties struct {
|
type PICNonVisualDrawingProperties struct {
|
||||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/picture cNvPr,omitempty"`
|
XMLName xml.Name `xml:"pic:cNvPr,omitempty"`
|
||||||
ID string `xml:"id,attr"`
|
ID string `xml:"id,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PICBlipFill represents the blip fill of a picture in a Word document.
|
// PICBlipFill represents the blip fill of a picture in a Word document.
|
||||||
type PICBlipFill struct {
|
type PICBlipFill struct {
|
||||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/picture blipFill,omitempty"`
|
XMLName xml.Name `xml:"pic:blipFill,omitempty"`
|
||||||
Blip ABlip
|
Blip ABlip
|
||||||
Stretch AStretch
|
Stretch AStretch
|
||||||
}
|
}
|
||||||
@@ -392,26 +401,26 @@ func (p *PICBlipFill) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
|
|||||||
|
|
||||||
// ABlip represents the blip of a picture in a Word document.
|
// ABlip represents the blip of a picture in a Word document.
|
||||||
type ABlip struct {
|
type ABlip struct {
|
||||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/main blip,omitempty"`
|
XMLName xml.Name `xml:"a:blip,omitempty"`
|
||||||
Embed string `xml:"r:embed,attr"`
|
Embed string `xml:"r:embed,attr"`
|
||||||
Cstate string `xml:"cstate,attr"`
|
Cstate string `xml:"cstate,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AStretch ...
|
// AStretch ...
|
||||||
type AStretch struct {
|
type AStretch struct {
|
||||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/main stretch,omitempty"`
|
XMLName xml.Name `xml:"a:stretch,omitempty"`
|
||||||
FillRect AFillRect
|
FillRect AFillRect
|
||||||
}
|
}
|
||||||
|
|
||||||
// AFillRect ...
|
// AFillRect ...
|
||||||
type AFillRect struct {
|
type AFillRect struct {
|
||||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/main fillRect,omitempty"`
|
XMLName xml.Name `xml:"a:fillRect,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PICSpPr is a struct representing the <pic:spPr> element in OpenXML,
|
// PICSpPr is a struct representing the <pic:spPr> element in OpenXML,
|
||||||
// which describes the shape properties for a picture.
|
// which describes the shape properties for a picture.
|
||||||
type PICSpPr struct {
|
type PICSpPr struct {
|
||||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/picture spPr,omitempty"`
|
XMLName xml.Name `xml:"pic:spPr,omitempty"`
|
||||||
Xfrm AXfrm
|
Xfrm AXfrm
|
||||||
PrstGeom APrstGeom
|
PrstGeom APrstGeom
|
||||||
}
|
}
|
||||||
@@ -446,7 +455,7 @@ func (p *PICSpPr) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
|||||||
// AXfrm is a struct representing the <a:xfrm> element in OpenXML,
|
// AXfrm is a struct representing the <a:xfrm> element in OpenXML,
|
||||||
// which describes the position and size of a shape.
|
// which describes the position and size of a shape.
|
||||||
type AXfrm struct {
|
type AXfrm struct {
|
||||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/main xfrm,omitempty"`
|
XMLName xml.Name `xml:"a:xfrm,omitempty"`
|
||||||
Off AOff
|
Off AOff
|
||||||
Ext AExt
|
Ext AExt
|
||||||
}
|
}
|
||||||
@@ -494,7 +503,7 @@ func (a *AXfrm) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
|||||||
// AOff is a struct representing the <a:off> element in OpenXML,
|
// AOff is a struct representing the <a:off> element in OpenXML,
|
||||||
// which describes the offset of a shape from its original position.
|
// which describes the offset of a shape from its original position.
|
||||||
type AOff struct {
|
type AOff struct {
|
||||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/main off,omitempty"`
|
XMLName xml.Name `xml:"a:off,omitempty"`
|
||||||
X int `xml:"x,attr"`
|
X int `xml:"x,attr"`
|
||||||
Y int `xml:"y,attr"`
|
Y int `xml:"y,attr"`
|
||||||
}
|
}
|
||||||
@@ -502,7 +511,7 @@ type AOff struct {
|
|||||||
// AExt is a struct representing the <a:ext> element in OpenXML,
|
// AExt is a struct representing the <a:ext> element in OpenXML,
|
||||||
// which describes the size of a shape.
|
// which describes the size of a shape.
|
||||||
type AExt struct {
|
type AExt struct {
|
||||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/main ext,omitempty"`
|
XMLName xml.Name `xml:"a:ext,omitempty"`
|
||||||
CX int `xml:"cx,attr"`
|
CX int `xml:"cx,attr"`
|
||||||
CY int `xml:"cy,attr"`
|
CY int `xml:"cy,attr"`
|
||||||
}
|
}
|
||||||
@@ -510,7 +519,7 @@ type AExt struct {
|
|||||||
// APrstGeom is a struct representing the <a:prstGeom> element in OpenXML,
|
// APrstGeom is a struct representing the <a:prstGeom> element in OpenXML,
|
||||||
// which describes the preset shape geometry for a shape.
|
// which describes the preset shape geometry for a shape.
|
||||||
type APrstGeom struct {
|
type APrstGeom struct {
|
||||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/main prstGeom,omitempty"`
|
XMLName xml.Name `xml:"a:prstGeom,omitempty"`
|
||||||
Prst string `xml:"prst,attr"`
|
Prst string `xml:"prst,attr"`
|
||||||
AvLst AAvLst
|
AvLst AAvLst
|
||||||
}
|
}
|
||||||
@@ -518,7 +527,7 @@ type APrstGeom struct {
|
|||||||
// AAvLst is a struct representing the <a:avLst> element in OpenXML,
|
// AAvLst is a struct representing the <a:avLst> element in OpenXML,
|
||||||
// which describes the adjustments to the shape's preset geometry.
|
// which describes the adjustments to the shape's preset geometry.
|
||||||
type AAvLst struct {
|
type AAvLst struct {
|
||||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/main avLst,omitempty"`
|
XMLName xml.Name `xml:"a:avLst,omitempty"`
|
||||||
RawXML string `xml:",innerxml"`
|
RawXML string `xml:",innerxml"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user