From 9d0f8a7aa9aa7d2381184c98878c1a0edb393b7b Mon Sep 17 00:00:00 2001 From: gomutex Date: Tue, 18 Jun 2024 15:11:21 +0530 Subject: [PATCH] ctypes structure and additional para props --- doc/background.go | 10 +- doc/background_test.go | 8 +- doc/document_test.go | 4 +- elemtypes/optOnOffElem.go | 21 ++ wml/ctypes/empty.go | 10 + wml/ctypes/empty_test.go | 63 ++++ wml/{docxrun => ctypes}/shd.go | 24 +- wml/{docxrun => ctypes}/shd_test.go | 24 +- wml/ctypes/tab.go | 77 +++++ wml/ctypes/tab_test.go | 218 +++++++++++++ wml/docxpara/paragraph_property.go | 111 ------- wml/docxpara/paragraph_style.go | 39 --- wml/docxpara/paragraph_style_test.go | 31 -- wml/docxpara/props.go | 291 ++++++++++++++++++ ...ragraph_property_test.go => props_test.go} | 20 +- wml/docxrun/border.go | 18 +- wml/docxrun/border_test.go | 26 +- wml/docxrun/eALayout.go | 12 +- wml/docxrun/eALayout_test.go | 38 +-- wml/docxrun/effect.go | 4 +- wml/docxrun/effect_test.go | 8 +- wml/docxrun/em.go | 4 +- wml/docxrun/em_test.go | 22 +- wml/docxrun/expaComp.go | 4 +- wml/docxrun/expaComp_test.go | 6 +- wml/docxrun/rFonts.go | 20 +- wml/docxrun/rFonts_test.go | 22 +- wml/docxrun/run.go | 13 +- wml/docxrun/runprop.go | 3 +- wml/docxrun/vertAlign.go | 4 +- wml/docxrun/vertAlign_test.go | 6 +- wml/hdrftr/footer.go | 6 +- wml/hdrftr/footer_test.go | 10 +- wml/hdrftr/header.go | 6 +- wml/hdrftr/header_test.go | 10 +- wml/hdrftr/titlePg.go | 4 +- wml/hdrftr/titlePg_test.go | 16 +- wml/runcontent/tabs.go | 99 ------ wml/sections/docGrid.go | 8 +- wml/sections/docGrid_test.go | 10 +- wml/sections/formProt.go | 4 +- wml/sections/formProt_test.go | 6 +- wml/sections/pageNum.go | 4 +- wml/sections/pageNum_test.go | 6 +- wml/sections/pageSize.go | 10 +- wml/sections/pageSize_test.go | 6 +- wml/sections/sectionProp_test.go | 6 +- wml/sections/sectionType.go | 4 +- wml/sections/sectionType_test.go | 6 +- wml/sections/testDirecion_test.go | 8 +- wml/sections/textDirection.go | 4 +- wml/{simpletypes => stypes}/borderStyle.go | 2 +- .../borderStyle_test.go | 2 +- wml/{simpletypes => stypes}/combBracket.go | 2 +- .../combBracket_test.go | 2 +- wml/{simpletypes => stypes}/docGridType.go | 2 +- .../docGridType_test.go | 2 +- wml/{simpletypes => stypes}/em.go | 2 +- wml/{simpletypes => stypes}/em_test.go | 2 +- wml/{simpletypes => stypes}/fontTypeHint.go | 2 +- .../fontTypeHint_test.go | 2 +- wml/{simpletypes => stypes}/hdrFtr.go | 2 +- wml/{simpletypes => stypes}/hdrFtr_test.go | 2 +- wml/{simpletypes => stypes}/numFmt.go | 2 +- wml/{simpletypes => stypes}/numFmt_test.go | 2 +- wml/{simpletypes => stypes}/onOff.go | 2 +- wml/{simpletypes => stypes}/onOff_test.go | 2 +- wml/{simpletypes => stypes}/pageOrient.go | 2 +- .../pageOrient_test.go | 2 +- wml/{simpletypes => stypes}/sectionMark.go | 2 +- .../sectionMark_test.go | 2 +- wml/{simpletypes => stypes}/shd.go | 2 +- wml/{simpletypes => stypes}/shd_test.go | 2 +- wml/stypes/tabJc.go | 52 ++++ wml/stypes/tabJc_test.go | 84 +++++ wml/stypes/tabTlc.go | 49 +++ wml/stypes/tabTlc_test.go | 83 +++++ wml/{simpletypes => stypes}/textDirection.go | 2 +- .../textDirection_test.go | 2 +- wml/{simpletypes => stypes}/textEffect.go | 2 +- .../textEffect_test.go | 2 +- wml/{simpletypes => stypes}/textScale.go | 2 +- wml/{simpletypes => stypes}/textScale_test.go | 2 +- wml/{simpletypes => stypes}/themeColor.go | 2 +- .../themeColor_test.go | 2 +- wml/{simpletypes => stypes}/themeFont.go | 2 +- wml/{simpletypes => stypes}/themeFont_test.go | 2 +- wml/{simpletypes => stypes}/vertAlignRun.go | 2 +- .../vertAlignRun_test.go | 2 +- wml/table/table_cell_property.go | 6 +- 90 files changed, 1212 insertions(+), 524 deletions(-) create mode 100644 elemtypes/optOnOffElem.go create mode 100644 wml/ctypes/empty.go create mode 100644 wml/ctypes/empty_test.go rename wml/{docxrun => ctypes}/shd.go (73%) rename wml/{docxrun => ctypes}/shd_test.go (92%) create mode 100644 wml/ctypes/tab.go create mode 100644 wml/ctypes/tab_test.go delete mode 100644 wml/docxpara/paragraph_property.go delete mode 100644 wml/docxpara/paragraph_style.go delete mode 100644 wml/docxpara/paragraph_style_test.go create mode 100644 wml/docxpara/props.go rename wml/docxpara/{paragraph_property_test.go => props_test.go} (68%) delete mode 100644 wml/runcontent/tabs.go rename wml/{simpletypes => stypes}/borderStyle.go (99%) rename wml/{simpletypes => stypes}/borderStyle_test.go (98%) rename wml/{simpletypes => stypes}/combBracket.go (98%) rename wml/{simpletypes => stypes}/combBracket_test.go (99%) rename wml/{simpletypes => stypes}/docGridType.go (97%) rename wml/{simpletypes => stypes}/docGridType_test.go (99%) rename wml/{simpletypes => stypes}/em.go (97%) rename wml/{simpletypes => stypes}/em_test.go (99%) rename wml/{simpletypes => stypes}/fontTypeHint.go (97%) rename wml/{simpletypes => stypes}/fontTypeHint_test.go (99%) rename wml/{simpletypes => stypes}/hdrFtr.go (97%) rename wml/{simpletypes => stypes}/hdrFtr_test.go (99%) rename wml/{simpletypes => stypes}/numFmt.go (99%) rename wml/{simpletypes => stypes}/numFmt_test.go (99%) rename wml/{simpletypes => stypes}/onOff.go (97%) rename wml/{simpletypes => stypes}/onOff_test.go (99%) rename wml/{simpletypes => stypes}/pageOrient.go (96%) rename wml/{simpletypes => stypes}/pageOrient_test.go (99%) rename wml/{simpletypes => stypes}/sectionMark.go (98%) rename wml/{simpletypes => stypes}/sectionMark_test.go (99%) rename wml/{simpletypes => stypes}/shd.go (99%) rename wml/{simpletypes => stypes}/shd_test.go (98%) create mode 100644 wml/stypes/tabJc.go create mode 100644 wml/stypes/tabJc_test.go create mode 100644 wml/stypes/tabTlc.go create mode 100644 wml/stypes/tabTlc_test.go rename wml/{simpletypes => stypes}/textDirection.go (98%) rename wml/{simpletypes => stypes}/textDirection_test.go (99%) rename wml/{simpletypes => stypes}/textEffect.go (98%) rename wml/{simpletypes => stypes}/textEffect_test.go (99%) rename wml/{simpletypes => stypes}/textScale.go (96%) rename wml/{simpletypes => stypes}/textScale_test.go (99%) rename wml/{simpletypes => stypes}/themeColor.go (99%) rename wml/{simpletypes => stypes}/themeColor_test.go (98%) rename wml/{simpletypes => stypes}/themeFont.go (98%) rename wml/{simpletypes => stypes}/themeFont_test.go (99%) rename wml/{simpletypes => stypes}/vertAlignRun.go (97%) rename wml/{simpletypes => stypes}/vertAlignRun_test.go (99%) diff --git a/doc/background.go b/doc/background.go index 1bdfc4c..3eb5cf4 100644 --- a/doc/background.go +++ b/doc/background.go @@ -3,17 +3,17 @@ package doc import ( "encoding/xml" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) // Specifies the background information for this document // // This background shall be displayed on all pages of the document, behind all other document content. type Background struct { - Color *string `xml:"color,attr,omitempty"` - ThemeColor *simpletypes.ThemeColor `xml:"themeColor,attr,omitempty"` - ThemeTint *string `xml:"themeTint,attr,omitempty"` - ThemeShade *string `xml:"themeShade,attr,omitempty"` + Color *string `xml:"color,attr,omitempty"` + ThemeColor *stypes.ThemeColor `xml:"themeColor,attr,omitempty"` + ThemeTint *string `xml:"themeTint,attr,omitempty"` + ThemeShade *string `xml:"themeShade,attr,omitempty"` } func (b *Background) MarshalXML(e *xml.Encoder, start xml.StartElement) error { diff --git a/doc/background_test.go b/doc/background_test.go index 30c59f5..0b48e65 100644 --- a/doc/background_test.go +++ b/doc/background_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestBackground_MarshalXML(t *testing.T) { @@ -18,7 +18,7 @@ func TestBackground_MarshalXML(t *testing.T) { name: "With all attributes", input: Background{ Color: StringPtr("FFFFFF"), - ThemeColor: ThemeColorPtr(simpletypes.ThemeColorAccent1), + ThemeColor: ThemeColorPtr(stypes.ThemeColorAccent1), ThemeTint: StringPtr("500"), ThemeShade: StringPtr("200"), }, @@ -64,7 +64,7 @@ func TestBackground_UnmarshalXML(t *testing.T) { inputXML: ``, expected: Background{ Color: StringPtr("FFFFFF"), - ThemeColor: ThemeColorPtr(simpletypes.ThemeColorAccent1), + ThemeColor: ThemeColorPtr(stypes.ThemeColorAccent1), ThemeTint: StringPtr("500"), ThemeShade: StringPtr("200"), }, @@ -134,6 +134,6 @@ func StringPtr(s string) *string { return &s } -func ThemeColorPtr(t simpletypes.ThemeColor) *simpletypes.ThemeColor { +func ThemeColorPtr(t stypes.ThemeColor) *stypes.ThemeColor { return &t } diff --git a/doc/document_test.go b/doc/document_test.go index b43cbae..2b63c07 100644 --- a/doc/document_test.go +++ b/doc/document_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestDocument_MarshalXML(t *testing.T) { @@ -19,7 +19,7 @@ func TestDocument_MarshalXML(t *testing.T) { input: Document{ Background: &Background{ Color: StringPtr("FF0000"), - ThemeColor: ThemeColorPtr(simpletypes.ThemeColorAccent1), + ThemeColor: ThemeColorPtr(stypes.ThemeColorAccent1), ThemeTint: StringPtr("500"), ThemeShade: StringPtr("200"), }, diff --git a/elemtypes/optOnOffElem.go b/elemtypes/optOnOffElem.go new file mode 100644 index 0000000..887d94a --- /dev/null +++ b/elemtypes/optOnOffElem.go @@ -0,0 +1,21 @@ +package elemtypes + +import ( + "encoding/xml" + + "github.com/gomutex/godocx/wml/stypes" +) + +// OptOnOffElem helper struct that has only one optional field which is OnOff type +type OptOnOffElem struct { + Val stypes.OnOff `xml:"val,attr,omitempty"` +} + +// MarshalXML implements the xml.Marshaler interface for the OnOffElem type. +// It encodes the OnOffElem to its corresponding XML representation. +func (s *OptOnOffElem) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + if s.Val != "" { + start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "w:val"}, Value: string(s.Val)}) + } + return e.EncodeElement("", start) +} diff --git a/wml/ctypes/empty.go b/wml/ctypes/empty.go new file mode 100644 index 0000000..c9a2453 --- /dev/null +++ b/wml/ctypes/empty.go @@ -0,0 +1,10 @@ +package ctypes + +import "encoding/xml" + +type Empty struct { +} + +func (s *Empty) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + return e.EncodeElement("", start) +} diff --git a/wml/ctypes/empty_test.go b/wml/ctypes/empty_test.go new file mode 100644 index 0000000..ede64cd --- /dev/null +++ b/wml/ctypes/empty_test.go @@ -0,0 +1,63 @@ +package ctypes + +import ( + "encoding/xml" + "strings" + "testing" +) + +func TestEmpty_MarshalXML(t *testing.T) { + tests := []struct { + name string + input Empty + expected string + }{ + { + name: "Empty element", + input: Empty{}, + expected: ``, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var result strings.Builder + encoder := xml.NewEncoder(&result) + start := xml.StartElement{Name: xml.Name{Local: "w:tab"}} + + err := tt.input.MarshalXML(encoder, start) + if err != nil { + t.Fatalf("Error marshaling XML: %v", err) + } + + encoder.Flush() + + if result.String() != tt.expected { + t.Errorf("Expected XML:\n%s\nGot:\n%s", tt.expected, result.String()) + } + }) + } +} + +func TestEmpty_UnmarshalXML(t *testing.T) { + tests := []struct { + name string + inputXML string + }{ + { + name: "Empty element", + inputXML: ``, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var result Empty + + err := xml.Unmarshal([]byte(tt.inputXML), &result) + if err != nil { + t.Fatalf("Error unmarshaling XML: %v", err) + } + }) + } +} diff --git a/wml/docxrun/shd.go b/wml/ctypes/shd.go similarity index 73% rename from wml/docxrun/shd.go rename to wml/ctypes/shd.go index 9c4bdee..b568a6d 100644 --- a/wml/docxrun/shd.go +++ b/wml/ctypes/shd.go @@ -1,22 +1,22 @@ -package docxrun +package ctypes import ( "encoding/xml" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) // Shading represents the shading properties for a run in a WordprocessingML document. type Shading struct { - Val simpletypes.Shading `xml:"val,attr"` - Color *string `xml:"color,attr,omitempty"` - ThemeColor *simpletypes.ThemeColor `xml:"themeColor,attr,omitempty"` - ThemeFill *simpletypes.ThemeColor `xml:"themeFill,attr,omitempty"` - ThemeTint *string `xml:"themeTint,attr,omitempty"` - ThemeShade *string `xml:"themeShade,attr,omitempty"` - Fill *string `xml:"fill,attr,omitempty"` - ThemeFillTint *string `xml:"themeFillTint,attr,omitempty"` - ThemeFillShade *string `xml:"themeFillShade,attr,omitempty"` + Val stypes.Shading `xml:"val,attr"` + Color *string `xml:"color,attr,omitempty"` + ThemeColor *stypes.ThemeColor `xml:"themeColor,attr,omitempty"` + ThemeFill *stypes.ThemeColor `xml:"themeFill,attr,omitempty"` + ThemeTint *string `xml:"themeTint,attr,omitempty"` + ThemeShade *string `xml:"themeShade,attr,omitempty"` + Fill *string `xml:"fill,attr,omitempty"` + ThemeFillTint *string `xml:"themeFillTint,attr,omitempty"` + ThemeFillShade *string `xml:"themeFillShade,attr,omitempty"` } func (s *Shading) MarshalXML(e *xml.Encoder, start xml.StartElement) error { @@ -80,7 +80,7 @@ func (s *Shading) SetFill(fill string) *Shading { } // ShadingType sets the shading type for the shading. -func (s *Shading) SetShadingType(shdType simpletypes.Shading) *Shading { +func (s *Shading) SetShadingType(shdType stypes.Shading) *Shading { s.Val = shdType return s } diff --git a/wml/docxrun/shd_test.go b/wml/ctypes/shd_test.go similarity index 92% rename from wml/docxrun/shd_test.go rename to wml/ctypes/shd_test.go index efd38ae..16df555 100644 --- a/wml/docxrun/shd_test.go +++ b/wml/ctypes/shd_test.go @@ -1,16 +1,16 @@ -package docxrun +package ctypes import ( "encoding/xml" "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestShd_MarshalXML(t *testing.T) { - themeColor1 := simpletypes.ThemeColorAccent2 - themeFill1 := simpletypes.ThemeColorAccent1 + themeColor1 := stypes.ThemeColorAccent2 + themeFill1 := stypes.ThemeColorAccent1 tests := []struct { name string shading Shading @@ -19,14 +19,14 @@ func TestShd_MarshalXML(t *testing.T) { { name: "Basic Shd with Val", shading: Shading{ - Val: simpletypes.ShdClear, + Val: stypes.ShdClear, }, expected: ``, }, { name: "Shd with all attributes", shading: Shading{ - Val: simpletypes.ShdSolid, + Val: stypes.ShdSolid, Color: stringPtr("FFFFFF"), ThemeColor: &themeColor1, ThemeFill: &themeFill1, @@ -41,7 +41,7 @@ func TestShd_MarshalXML(t *testing.T) { { name: "Shd with some attributes nil", shading: Shading{ - Val: simpletypes.ShdDiagStripe, + Val: stypes.ShdDiagStripe, ThemeColor: &themeColor1, ThemeFill: &themeFill1, ThemeTint: stringPtr("500"), @@ -73,8 +73,8 @@ func TestShd_MarshalXML(t *testing.T) { } func TestShd_UnmarshalXML(t *testing.T) { - themeColor1 := simpletypes.ThemeColorAccent2 - themeFill1 := simpletypes.ThemeColorAccent1 + themeColor1 := stypes.ThemeColorAccent2 + themeFill1 := stypes.ThemeColorAccent1 tests := []struct { name string inputXML string @@ -84,14 +84,14 @@ func TestShd_UnmarshalXML(t *testing.T) { name: "Basic Shd with Val", inputXML: ``, expectedShd: Shading{ - Val: simpletypes.ShdClear, + Val: stypes.ShdClear, }, }, { name: "Shd with all attributes", inputXML: ``, expectedShd: Shading{ - Val: simpletypes.ShdSolid, + Val: stypes.ShdSolid, Color: stringPtr("FFFFFF"), ThemeColor: &themeColor1, ThemeFill: &themeFill1, @@ -106,7 +106,7 @@ func TestShd_UnmarshalXML(t *testing.T) { name: "Shd with some attributes missing", inputXML: ``, expectedShd: Shading{ - Val: simpletypes.ShdDiagStripe, + Val: stypes.ShdDiagStripe, ThemeColor: &themeColor1, ThemeFill: &themeFill1, ThemeTint: stringPtr("500"), diff --git a/wml/ctypes/tab.go b/wml/ctypes/tab.go new file mode 100644 index 0000000..15b6696 --- /dev/null +++ b/wml/ctypes/tab.go @@ -0,0 +1,77 @@ +package ctypes + +import ( + "encoding/xml" + "fmt" + "strconv" + + "github.com/gomutex/godocx/wml/stypes" +) + +// Custom Tab Stop +type Tab struct { + // Tab Stop Type + Val *stypes.CustTabStop `xml:"val,attr,omitempty"` + + //Tab Stop Position + Position *int `xml:"pos,attr,omitempty"` + + //Custom Tab Stop Leader Character + LeaderChar *stypes.CustLeadChar `xml:"leader,attr,omitempty"` +} + +func (t *Tab) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + start.Name.Local = "w:tab" + start.Attr = []xml.Attr{} + + if t.Val != nil { + start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "val"}, Value: string(*t.Val)}) + } + + if t.Position != nil { + start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "pos"}, Value: strconv.Itoa(*t.Position)}) + } + + if t.LeaderChar != nil { + start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "leader"}, Value: string(*t.LeaderChar)}) + } + + err := e.EncodeToken(start) + if err != nil { + return err + } + + return e.EncodeToken(xml.EndElement{Name: start.Name}) +} + +type Tabs struct { + Tab []Tab `xml:"tab,omitempty"` +} + +func (t Tabs) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + + if len(t.Tab) == 0 { + return nil + } + + // Create the enclosing XML element + start.Name = xml.Name{Local: "w:tabs"} + + err := e.EncodeToken(start) + if err != nil { + return fmt.Errorf("error encoding start element: %v", err) + } + + for _, tab := range t.Tab { + if err := tab.MarshalXML(e, xml.StartElement{}); err != nil { + return fmt.Errorf("error encoding tab: %v", err) + } + } + + err = e.EncodeToken(start.End()) + if err != nil { + return fmt.Errorf("error encoding end element: %v", err) + } + + return nil +} diff --git a/wml/ctypes/tab_test.go b/wml/ctypes/tab_test.go new file mode 100644 index 0000000..217ac35 --- /dev/null +++ b/wml/ctypes/tab_test.go @@ -0,0 +1,218 @@ +package ctypes + +import ( + "encoding/xml" + "reflect" + "strings" + "testing" + + "github.com/gomutex/godocx/wml/stypes" +) + +func TestTab_MarshalXML(t *testing.T) { + tests := []struct { + name string + input Tab + expected string + }{ + { + name: "With all attributes", + input: Tab{ + Val: CTabStopPtr(stypes.CustTabStopCenter), + Position: IntPtr(720), + LeaderChar: LeadCharPtr(stypes.CustLeadCharDot), + }, + expected: ``, + }, + { + name: "Without optional attributes", + input: Tab{ + Val: CTabStopPtr(stypes.CustTabStopRight), + Position: IntPtr(1440), + }, + expected: ``, + }, + { + name: "Empty struct", + input: Tab{}, + expected: ``, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var result strings.Builder + encoder := xml.NewEncoder(&result) + start := xml.StartElement{Name: xml.Name{Local: "w:tab"}} + + err := tt.input.MarshalXML(encoder, start) + if err != nil { + t.Fatalf("Error marshaling XML: %v", err) + } + + encoder.Flush() + + if result.String() != tt.expected { + t.Errorf("Expected XML:\n%s\nGot:\n%s", tt.expected, result.String()) + } + }) + } +} +func TestTab_UnmarshalXML(t *testing.T) { + tests := []struct { + name string + inputXML string + expected Tab + }{ + { + name: "With all attributes", + inputXML: ``, + expected: Tab{ + Val: CTabStopPtr(stypes.CustTabStopCenter), + Position: IntPtr(720), + LeaderChar: LeadCharPtr(stypes.CustLeadCharDot), + }, + }, + { + name: "Without optional attributes", + inputXML: ``, + expected: Tab{ + Val: CTabStopPtr(stypes.CustTabStopRight), + Position: IntPtr(1440), + }, + }, + { + name: "Empty struct", + inputXML: ``, + expected: Tab{}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var result Tab + + err := xml.Unmarshal([]byte(tt.inputXML), &result) + if err != nil { + t.Fatalf("Error unmarshaling XML: %v", err) + } + + // Compare Val + if tt.expected.Val != nil { + if result.Val == nil || *result.Val != *tt.expected.Val { + t.Errorf("Expected Val %s but got %v", *tt.expected.Val, *result.Val) + } + } else if result.Val != nil { + t.Errorf("Expected Val nil but got %v", *result.Val) + } + + // Compare Position + if tt.expected.Position != nil { + if result.Position == nil || *result.Position != *tt.expected.Position { + t.Errorf("Expected Position %d but got %v", *tt.expected.Position, *result.Position) + } + } else if result.Position != nil { + t.Errorf("Expected Position nil but got %v", *result.Position) + } + + // Compare LeaderChar + if tt.expected.LeaderChar != nil { + if result.LeaderChar == nil || *result.LeaderChar != *tt.expected.LeaderChar { + t.Errorf("Expected LeaderChar %s but got %v", *tt.expected.LeaderChar, *result.LeaderChar) + } + } else if result.LeaderChar != nil { + t.Errorf("Expected LeaderChar nil but got %v", *result.LeaderChar) + } + }) + } +} +func TestTabs_MarshalXML(t *testing.T) { + tests := []struct { + name string + tabs Tabs + expected string + }{ + { + name: "Empty Tabs", + tabs: Tabs{}, + expected: ``, + }, + { + name: "Tabs with Multiple Tab elements", + tabs: Tabs{ + Tab: []Tab{ + {Val: CTabStopPtr(stypes.CustTabStopCenter), Position: IntPtr(100), LeaderChar: LeadCharPtr(stypes.CustLeadCharDot)}, + {Val: CTabStopPtr(stypes.CustTabStopLeft), Position: IntPtr(200), LeaderChar: LeadCharPtr(stypes.CustLeadCharHyphen)}, + }, + }, + expected: ``, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + xmlBytes, err := xml.Marshal(tt.tabs) + if err != nil { + t.Fatalf("Unexpected error during Marshal: %v", err) + } + + actual := strings.TrimSpace(string(xmlBytes)) + if actual != tt.expected { + t.Fatalf("Unexpected XML output: expected '%s' but got '%s'", tt.expected, actual) + } + }) + } +} +func TestTabs_UnmarshalXML(t *testing.T) { + tests := []struct { + name string + xmlInput string + expected Tabs + }{ + { + name: "Empty Tabs", + xmlInput: ``, + expected: Tabs{}, + }, + { + name: "Tabs with Multiple Tab elements", + xmlInput: ` + + + `, + expected: Tabs{ + Tab: []Tab{ + {Val: CTabStopPtr(stypes.CustTabStopCenter), Position: IntPtr(100), LeaderChar: LeadCharPtr(stypes.CustLeadCharDot)}, + {Val: CTabStopPtr(stypes.CustTabStopLeft), Position: IntPtr(200), LeaderChar: LeadCharPtr(stypes.CustLeadCharHyphen)}, + }, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var tabs Tabs + err := xml.Unmarshal([]byte(tt.xmlInput), &tabs) + if err != nil { + t.Fatalf("Unexpected error during Unmarshal: %v", err) + } + + // Compare individual fields of Tabs struct + if !reflect.DeepEqual(tabs, tt.expected) { + t.Errorf("Unmarshaled Tabs struct does not match expected:\nExpected: %+v\nActual: %+v", tt.expected, tabs) + } + }) + } +} + +func IntPtr(v int) *int { + return &v +} + +func LeadCharPtr(lc stypes.CustLeadChar) *stypes.CustLeadChar { + return &lc +} + +func CTabStopPtr(v stypes.CustTabStop) *stypes.CustTabStop { + return &v +} diff --git a/wml/docxpara/paragraph_property.go b/wml/docxpara/paragraph_property.go deleted file mode 100644 index 53f081c..0000000 --- a/wml/docxpara/paragraph_property.go +++ /dev/null @@ -1,111 +0,0 @@ -package docxpara - -import ( - "encoding/xml" - - "github.com/gomutex/godocx/wml/docxrun" - "github.com/gomutex/godocx/wml/formatting" - "github.com/gomutex/godocx/wml/liststyle" -) - -// Numbering Level Associated Paragraph Properties -type ParagraphProperty struct { - DivID *string - KeepNext *bool - KeepLines *bool - PageBreakBefore *bool - WidowControl *bool - Style *ParagraphStyle - Justification *formatting.Justification - RunProperty *docxrun.RunProperty - NumberingProperty *liststyle.NumberingProperty -} - -func DefaultParaProperty() *ParagraphProperty { - return &ParagraphProperty{} -} - -func (pp *ParagraphProperty) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error) { - elem := xml.StartElement{Name: xml.Name{Local: "w:pPr"}} - - // Opening element - if err = e.EncodeToken(elem); err != nil { - return err - } - - // Encoding element - if pp.Style != nil { - if err = e.EncodeElement(pp.Style, xml.StartElement{Name: xml.Name{Local: "w:pStyle"}}); err != nil { - return err - } - } - - if pp.RunProperty != nil { - propsElement := xml.StartElement{Name: xml.Name{Local: "w:rPr"}} - if err = e.EncodeElement(pp.RunProperty, propsElement); err != nil { - return err - } - } - - // Encoding element - if pp.Justification != nil { - if err = e.EncodeElement(pp.Justification, xml.StartElement{Name: xml.Name{Local: "w:jc"}}); err != nil { - return err - } - } - - // Encoding element - if pp.NumberingProperty != nil { - if err = e.EncodeElement(pp.NumberingProperty, xml.StartElement{Name: xml.Name{Local: "w:numPr"}}); err != nil { - return err - } - } - - // Closing element - if err = e.EncodeToken(elem.End()); err != nil { - return err - } - - return nil -} - -func (pp *ParagraphProperty) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) { - for { - token, err := d.Token() - if err != nil { - return err - } - - switch t := token.(type) { - case xml.StartElement: - switch t.Name.Local { - case "pStyle": - if err = d.DecodeElement(&pp.Style, &t); err != nil { - return err - } - case "jc": - if err = d.DecodeElement(&pp.Justification, &t); err != nil { - return err - } - case "numPr": - if err = d.DecodeElement(&pp.NumberingProperty, &t); err != nil { - return err - } - case "rPr": - pp.RunProperty = &docxrun.RunProperty{} - if err = d.DecodeElement(pp.RunProperty, &t); err != nil { - return err - } - default: - if err = d.Skip(); err != nil { - return err - } - } - case xml.EndElement: - // Check if it's the end of the w:pPr element - if t == start.End() { - return nil - } - } - } -} diff --git a/wml/docxpara/paragraph_style.go b/wml/docxpara/paragraph_style.go deleted file mode 100644 index e6731b3..0000000 --- a/wml/docxpara/paragraph_style.go +++ /dev/null @@ -1,39 +0,0 @@ -package docxpara - -import "encoding/xml" - -// ParagraphStyle represents the name of a paragraph style associated with a numbering level in a document. -// When a paragraph style includes a numbering definition, any numbering level defined by the numPr element (§17.3.1.19) -// shall be ignored. Instead, this element specifies the numbering level associated with that paragraph style. -type ParagraphStyle struct { - Value string -} - -// NewParagraphStyle creates a new ParagraphStyle. -func NewParagraphStyle(val string) *ParagraphStyle { - return &ParagraphStyle{Value: val} -} - -// DefaultParagraphStyle creates the default ParagraphStyle with the value "Normal". -func DefaultParagraphStyle() *ParagraphStyle { - return &ParagraphStyle{Value: "Normal"} -} - -func (p *ParagraphStyle) MarshalXML(e *xml.Encoder, start xml.StartElement) error { - start.Name.Local = "w:pStyle" - start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "w:val"}, Value: p.Value}) - return e.EncodeElement("", start) -} - -func (p *ParagraphStyle) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { - var attr string - for _, a := range start.Attr { - if a.Name.Local == "val" { - attr = a.Value - break - } - } - - p.Value = attr - return d.Skip() // Skipping the inner content -} diff --git a/wml/docxpara/paragraph_style_test.go b/wml/docxpara/paragraph_style_test.go deleted file mode 100644 index 1c6af73..0000000 --- a/wml/docxpara/paragraph_style_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package docxpara - -import ( - "encoding/xml" - "strings" - "testing" -) - -func TestParagraphStyle(t *testing.T) { - testParagraphStyle := NewParagraphStyle("Heading1") - - xmlData, err := xml.Marshal(testParagraphStyle) - if err != nil { - t.Fatalf("Error marshaling ParagraphStyle to XML: %v", err) - } - - var unmarshaledParagraphStyle ParagraphStyle - err = xml.Unmarshal(xmlData, &unmarshaledParagraphStyle) - if err != nil { - t.Fatalf("Error unmarshaling XML to ParagraphStyle: %v", err) - } - - if testParagraphStyle.Value != unmarshaledParagraphStyle.Value { - t.Errorf("Expected paragraph style value %s, got %s", testParagraphStyle.Value, unmarshaledParagraphStyle.Value) - } - - expectedXMLString := `` - if !strings.Contains(string(xmlData), expectedXMLString) { - t.Errorf("Expected XML string %s, got %s", expectedXMLString, string(xmlData)) - } -} diff --git a/wml/docxpara/props.go b/wml/docxpara/props.go new file mode 100644 index 0000000..11ab2d3 --- /dev/null +++ b/wml/docxpara/props.go @@ -0,0 +1,291 @@ +package docxpara + +import ( + "encoding/xml" + "fmt" + + "github.com/gomutex/godocx/elemtypes" + "github.com/gomutex/godocx/wml/ctypes" + "github.com/gomutex/godocx/wml/docxrun" + "github.com/gomutex/godocx/wml/formatting" + "github.com/gomutex/godocx/wml/liststyle" +) + +// Numbering Level Associated Paragraph Properties +type ParagraphProperty struct { + // This element specifies the style ID of the paragraph style which shall be used to format the contents of this paragraph. + Style *elemtypes.SingleStrVal `xml:"pStyle,omitempty"` + + //Keep Paragraph With Next Paragraph + KeepNext *elemtypes.OptOnOffElem `xml:"keepNext,omitempty"` + + //Keep All Lines On One Page + KeepLines *elemtypes.OptOnOffElem `xml:"keepLines,omitempty"` + + //Start Paragraph on Next Page + PageBreakBefore *elemtypes.OptOnOffElem `xml:"pageBreakBefore,omitempty"` + + //Allow First/Last Line to Display on a Separate Page + WindowControl *elemtypes.OptOnOffElem `xml:"widowControl,omitempty"` + + //Suppress Line Numbers for Paragraph + SuppressLineNmbrs *elemtypes.OptOnOffElem `xml:"suppressLineNumbers,omitempty"` + + //Suppress Hyphenation for Paragraph + SuppressAutoHyphens *elemtypes.OptOnOffElem `xml:"suppressAutoHyphens,omitempty"` + + //Use East Asian Typography Rules for First and Last Character per Line + Kinsoku *elemtypes.OptOnOffElem `xml:"kinsoku,omitempty"` + + //Allow Line Breaking At Character Level + WordWrap *elemtypes.OptOnOffElem `xml:"wordWrap,omitempty"` + + //Allow Punctuation to Extent Past Text Extents + OverflowPunct *elemtypes.OptOnOffElem `xml:"overflowPunct,omitempty"` + + //Compress Punctuation at Start of a Line + TopLinePunct *elemtypes.OptOnOffElem `xml:"topLinePunct,omitempty"` + + //Automatically Adjust Spacing of Latin and East Asian Text + AutoSpaceDE *elemtypes.OptOnOffElem `xml:"autoSpaceDE,omitempty"` + + //Automatically Adjust Spacing of East Asian Text and Numbers + AutoSpaceDN *elemtypes.OptOnOffElem `xml:"autoSpaceDN,omitempty"` + + //Right to Left Paragraph Layout + Bidi *elemtypes.OptOnOffElem `xml:"bidi,omitempty"` + + //Automatically Adjust Right Indent When Using Document Grid + AdjustRightInd *elemtypes.OptOnOffElem `xml:"adjustRightInd,omitempty"` + + //Use Document Grid Settings for Inter-Line Paragraph Spacing + SnapToGrid *elemtypes.OptOnOffElem `xml:"snapToGrid,omitempty"` + + //Ignore Spacing Above and Below When Using Identical Styles + CtxlSpacing *elemtypes.OptOnOffElem `xml:"contextualSpacing,omitempty"` + + // Use Left/Right Indents as Inside/Outside Indents + MirrorIndents *elemtypes.OptOnOffElem `xml:"mirrorIndents,omitempty"` + + //This element specifies the shading applied to the contents of the paragraph. + Shading *ctypes.Shading `xml:"shd,omitempty"` + + //Set of Custom Tab Stops + Tabs ctypes.Tabs `xml:"tabs,omitempty"` + + DivID *string + Justification *formatting.Justification `xml:"jc,omitempty"` + RunProperty *docxrun.RunProperty `xml:"rPr,omitempty"` + NumberingProperty *liststyle.NumberingProperty `xml:"numPr,omitempty"` + + // TODO: Implement this + // Text Frame Properties + // FrameProp *FrameProp `xml:"framePr,omitempty"` + // This element specifies that the current paragraph references a numbering definition instance in the current document. + // NumPr *NumPr `xml:"numpr,omitempty"` + //This element specifies the borders for the parent paragraph. Each child element shall specify a specific type of border (left, right, bottom, top, and between). + // Border *Border `xml:"pBdr,omitempty"` + // Spacing Spacing + //Indent Indent +} + +type OnOffElems struct { + elem *elemtypes.OptOnOffElem + XMLName string +} + +func (pp *ParagraphProperty) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error) { + elem := xml.StartElement{Name: xml.Name{Local: "w:pPr"}} + + // Opening element + if err = e.EncodeToken(elem); err != nil { + return err + } + + // onOffElems := []OnOffElems{ + // {pp.KeepNext, "w:keepNext"}, + // } + + if pp.Style != nil { + if err = pp.Style.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:pStyle"}, + }); err != nil { + return fmt.Errorf("style: %w", err) + } + } + + if pp.KeepLines != nil { + if err = pp.KeepLines.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:keepLines"}, + }); err != nil { + return fmt.Errorf("keepLines: %w", err) + } + } + + if pp.KeepNext != nil { + if err = pp.KeepNext.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:keepNext"}, + }); err != nil { + return fmt.Errorf("keep next: %w", err) + } + } + + if pp.PageBreakBefore != nil { + if err = pp.PageBreakBefore.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:pageBreakBefore"}, + }); err != nil { + return fmt.Errorf("pageBreakBefore: %w", err) + } + } + + if pp.WindowControl != nil { + if err = pp.WindowControl.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:widowControl"}, + }); err != nil { + return fmt.Errorf("widowControl: %w", err) + } + } + + if pp.SuppressLineNmbrs != nil { + if err = pp.SuppressLineNmbrs.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:suppressLineNumbers"}, + }); err != nil { + return fmt.Errorf("suppressLineNumbers: %w", err) + } + } + + if pp.SuppressAutoHyphens != nil { + if err = pp.SuppressAutoHyphens.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:suppressAutoHyphens"}, + }); err != nil { + return fmt.Errorf("suppressAutoHyphens: %w", err) + } + } + + if pp.Kinsoku != nil { + if err = pp.Kinsoku.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:kinsoku"}, + }); err != nil { + return fmt.Errorf("kinsoku: %w", err) + } + } + + if pp.OverflowPunct != nil { + if err = pp.OverflowPunct.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:overflowPunct"}, + }); err != nil { + return fmt.Errorf("overflowPunct: %w", err) + } + } + + if pp.TopLinePunct != nil { + if err = pp.TopLinePunct.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:topLinePunct"}, + }); err != nil { + return fmt.Errorf("topLinePunct: %w", err) + } + } + + if pp.AutoSpaceDE != nil { + if err = pp.AutoSpaceDE.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:autoSpaceDE"}, + }); err != nil { + return fmt.Errorf("autoSpaceDE: %w", err) + } + } + + if pp.AutoSpaceDN != nil { + if err = pp.AutoSpaceDN.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:autoSpaceDN"}, + }); err != nil { + return fmt.Errorf("autoSpaceDN: %w", err) + } + } + + if pp.Bidi != nil { + if err = pp.Bidi.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:bidi"}, + }); err != nil { + return fmt.Errorf("bidi: %w", err) + } + } + + if pp.AdjustRightInd != nil { + if err = pp.AdjustRightInd.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:adjustRightInd"}, + }); err != nil { + return fmt.Errorf("adjustRightInd: %w", err) + } + } + + if pp.SnapToGrid != nil { + if err = pp.SnapToGrid.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:snapToGrid"}, + }); err != nil { + return fmt.Errorf("snapToGrid: %w", err) + } + } + + if pp.CtxlSpacing != nil { + if err = pp.CtxlSpacing.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:contextualSpacing"}, + }); err != nil { + return fmt.Errorf("contextualSpacing: %w", err) + } + } + + if pp.MirrorIndents != nil { + if err = pp.MirrorIndents.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:mirrorIndents"}, + }); err != nil { + return fmt.Errorf("mirrorIndents: %w", err) + } + } + + if pp.WordWrap != nil { + if err = pp.WordWrap.MarshalXML(e, xml.StartElement{ + Name: xml.Name{Local: "w:wordWrap"}, + }); err != nil { + return fmt.Errorf("wordWrap: %w", err) + } + } + + if pp.RunProperty != nil { + propsElement := xml.StartElement{Name: xml.Name{Local: "w:rPr"}} + if err = e.EncodeElement(pp.RunProperty, propsElement); err != nil { + return err + } + } + + if pp.Justification != nil { + if err = pp.Justification.MarshalXML(e, xml.StartElement{}); err != nil { + return fmt.Errorf("Justification: %w", err) + } + } + + if pp.NumberingProperty != nil { + if err = pp.NumberingProperty.MarshalXML(e, xml.StartElement{}); err != nil { + return fmt.Errorf("NumberingProperty: %w", err) + } + } + + if err = e.EncodeToken(elem.End()); err != nil { + return err + } + + return nil +} + +// NewParagraphStyle creates a new ParagraphStyle. +func NewParagraphStyle(val string) *elemtypes.SingleStrVal { + return &elemtypes.SingleStrVal{Val: val} +} + +// DefaultParagraphStyle creates the default ParagraphStyle with the value "Normal". +func DefaultParagraphStyle() *elemtypes.SingleStrVal { + return &elemtypes.SingleStrVal{Val: "Normal"} +} + +func DefaultParaProperty() *ParagraphProperty { + return &ParagraphProperty{} +} diff --git a/wml/docxpara/paragraph_property_test.go b/wml/docxpara/props_test.go similarity index 68% rename from wml/docxpara/paragraph_property_test.go rename to wml/docxpara/props_test.go index b49c44c..bc066e4 100644 --- a/wml/docxpara/paragraph_property_test.go +++ b/wml/docxpara/props_test.go @@ -8,7 +8,7 @@ import ( ) func areParagraphPropertiesEqual(p1, p2 ParagraphProperty) bool { - return p1.Style.Value == p2.Style.Value && + return p1.Style.Val == p2.Style.Val && p1.Justification.Value == p2.Justification.Value } @@ -33,3 +33,21 @@ func TestParagraphProperty(t *testing.T) { t.Errorf("Expected ParagraphProperty %v, got %v", expectedParagraphProperty, parsedParagraphProperty) } } + +func TestNewParagraphStyle(t *testing.T) { + expected := "TestStyle" + style := NewParagraphStyle(expected) + + if style.Val != expected { + t.Errorf("NewParagraphStyle() = %s; want %s", style.Val, expected) + } +} + +func TestDefaultParagraphStyle(t *testing.T) { + expected := "Normal" + style := DefaultParagraphStyle() + + if style.Val != expected { + t.Errorf("DefaultParagraphStyle() = %s; want %s", style.Val, expected) + } +} diff --git a/wml/docxrun/border.go b/wml/docxrun/border.go index 70a8657..20806fd 100644 --- a/wml/docxrun/border.go +++ b/wml/docxrun/border.go @@ -3,18 +3,18 @@ package docxrun import ( "encoding/xml" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) type TextBorder struct { - Val simpletypes.BorderStyle `xml:"val,attr"` - Color *string `xml:"color,attr,omitempty"` - ThemeColor *simpletypes.ThemeColor `xml:"themeColor,attr,omitempty"` - ThemeTint *string `xml:"themeTint,attr,omitempty"` - ThemeShade *string `xml:"themeShade,attr,omitempty"` - Space *string `xml:"space,attr,omitempty"` - Shadow *simpletypes.OnOff `xml:"shadow,attr,omitempty"` - Frame *simpletypes.OnOff `xml:"frame,attr,omitempty"` + Val stypes.BorderStyle `xml:"val,attr"` + Color *string `xml:"color,attr,omitempty"` + ThemeColor *stypes.ThemeColor `xml:"themeColor,attr,omitempty"` + ThemeTint *string `xml:"themeTint,attr,omitempty"` + ThemeShade *string `xml:"themeShade,attr,omitempty"` + Space *string `xml:"space,attr,omitempty"` + Shadow *stypes.OnOff `xml:"shadow,attr,omitempty"` + Frame *stypes.OnOff `xml:"frame,attr,omitempty"` } func (t *TextBorder) MarshalXML(e *xml.Encoder, start xml.StartElement) error { diff --git a/wml/docxrun/border_test.go b/wml/docxrun/border_test.go index 85a3141..56c209b 100644 --- a/wml/docxrun/border_test.go +++ b/wml/docxrun/border_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestTextBorder_MarshalXML(t *testing.T) { @@ -17,21 +17,21 @@ func TestTextBorder_MarshalXML(t *testing.T) { { name: "With all attributes", input: TextBorder{ - Val: simpletypes.BorderStyleSingle, + Val: stypes.BorderStyleSingle, Color: StringPtr("FF0000"), - ThemeColor: themeColorPointer(simpletypes.ThemeColorAccent1), + ThemeColor: themeColorPointer(stypes.ThemeColorAccent1), ThemeTint: StringPtr("500"), ThemeShade: StringPtr("200"), Space: StringPtr("0"), - Shadow: OnOffPtr(simpletypes.OnOffTrue), - Frame: OnOffPtr(simpletypes.OnOffTrue), + Shadow: OnOffPtr(stypes.OnOffTrue), + Frame: OnOffPtr(stypes.OnOffTrue), }, expected: ``, }, { name: "Without optional attributes", input: TextBorder{ - Val: simpletypes.BorderStyleDouble, + Val: stypes.BorderStyleDouble, }, expected: ``, }, @@ -68,21 +68,21 @@ func TestTextBorder_UnmarshalXML(t *testing.T) { inputXML: ``, expected: TextBorder{ - Val: simpletypes.BorderStyleSingle, + Val: stypes.BorderStyleSingle, Color: StringPtr("FF0000"), - ThemeColor: themeColorPointer(simpletypes.ThemeColorAccent1), + ThemeColor: themeColorPointer(stypes.ThemeColorAccent1), ThemeTint: StringPtr("500"), ThemeShade: StringPtr("200"), Space: StringPtr("0"), - Shadow: OnOffPtr(simpletypes.OnOffTrue), - Frame: OnOffPtr(simpletypes.OnOffTrue), + Shadow: OnOffPtr(stypes.OnOffTrue), + Frame: OnOffPtr(stypes.OnOffTrue), }, }, { name: "Without optional attributes", inputXML: ``, expected: TextBorder{ - Val: simpletypes.BorderStyleDouble, + Val: stypes.BorderStyleDouble, }, }, } @@ -171,10 +171,10 @@ func StringPtr(s string) *string { return &s } -func OnOffPtr(o simpletypes.OnOff) *simpletypes.OnOff { +func OnOffPtr(o stypes.OnOff) *stypes.OnOff { return &o } -func themeColorPointer(t simpletypes.ThemeColor) *simpletypes.ThemeColor { +func themeColorPointer(t stypes.ThemeColor) *stypes.ThemeColor { return &t } diff --git a/wml/docxrun/eALayout.go b/wml/docxrun/eALayout.go index 8dd505d..6eb42b7 100644 --- a/wml/docxrun/eALayout.go +++ b/wml/docxrun/eALayout.go @@ -4,16 +4,16 @@ import ( "encoding/xml" "strconv" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) // East Asian Typography Settings type EALayout struct { - ID *int `xml:"id,attr,omitempty"` - Combine *simpletypes.OnOff `xml:"combine,attr,omitempty"` - CombineBrkts *simpletypes.CombineBrackets `xml:"combineBrackets,attr,omitempty"` - Vert *simpletypes.OnOff `xml:"vert,attr,omitempty"` - VertCompress *simpletypes.OnOff `xml:"vertCompress,attr,omitempty"` + ID *int `xml:"id,attr,omitempty"` + Combine *stypes.OnOff `xml:"combine,attr,omitempty"` + CombineBrkts *stypes.CombineBrackets `xml:"combineBrackets,attr,omitempty"` + Vert *stypes.OnOff `xml:"vert,attr,omitempty"` + VertCompress *stypes.OnOff `xml:"vertCompress,attr,omitempty"` } func (ea *EALayout) MarshalXML(e *xml.Encoder, start xml.StartElement) error { diff --git a/wml/docxrun/eALayout_test.go b/wml/docxrun/eALayout_test.go index 4789160..89d32cc 100644 --- a/wml/docxrun/eALayout_test.go +++ b/wml/docxrun/eALayout_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) // Helper functions to create pointers @@ -13,11 +13,11 @@ func intPtr(i int) *int { return &i } -func onOffPtr(value simpletypes.OnOff) *simpletypes.OnOff { +func onOffPtr(value stypes.OnOff) *stypes.OnOff { return &value } -func combineBracketsPtr(value simpletypes.CombineBrackets) *simpletypes.CombineBrackets { +func combineBracketsPtr(value stypes.CombineBrackets) *stypes.CombineBrackets { return &value } @@ -31,10 +31,10 @@ func TestEALayout_MarshalXML(t *testing.T) { name: "All attributes set", layout: EALayout{ ID: intPtr(1), - Combine: onOffPtr(simpletypes.OnOffOn), - CombineBrkts: combineBracketsPtr(simpletypes.CombineBracketsRound), - Vert: onOffPtr(simpletypes.OnOffOff), - VertCompress: onOffPtr(simpletypes.OnOffOn), + Combine: onOffPtr(stypes.OnOffOn), + CombineBrkts: combineBracketsPtr(stypes.CombineBracketsRound), + Vert: onOffPtr(stypes.OnOffOff), + VertCompress: onOffPtr(stypes.OnOffOn), }, expected: ``, }, @@ -48,28 +48,28 @@ func TestEALayout_MarshalXML(t *testing.T) { { name: "Only Combine set", layout: EALayout{ - Combine: onOffPtr(simpletypes.OnOffOn), + Combine: onOffPtr(stypes.OnOffOn), }, expected: ``, }, { name: "Only CombineBrkts set", layout: EALayout{ - CombineBrkts: combineBracketsPtr(simpletypes.CombineBracketsSquare), + CombineBrkts: combineBracketsPtr(stypes.CombineBracketsSquare), }, expected: ``, }, { name: "Only Vert set", layout: EALayout{ - Vert: onOffPtr(simpletypes.OnOffOff), + Vert: onOffPtr(stypes.OnOffOff), }, expected: ``, }, { name: "Only VertCompress set", layout: EALayout{ - VertCompress: onOffPtr(simpletypes.OnOffOn), + VertCompress: onOffPtr(stypes.OnOffOn), }, expected: ``, }, @@ -109,10 +109,10 @@ func TestEALayout_UnmarshalXML(t *testing.T) { inputXML: ``, expected: EALayout{ ID: intPtr(1), - Combine: onOffPtr(simpletypes.OnOffOn), - CombineBrkts: combineBracketsPtr(simpletypes.CombineBracketsRound), - Vert: onOffPtr(simpletypes.OnOffOff), - VertCompress: onOffPtr(simpletypes.OnOffOn), + Combine: onOffPtr(stypes.OnOffOn), + CombineBrkts: combineBracketsPtr(stypes.CombineBracketsRound), + Vert: onOffPtr(stypes.OnOffOff), + VertCompress: onOffPtr(stypes.OnOffOn), }, }, { @@ -126,28 +126,28 @@ func TestEALayout_UnmarshalXML(t *testing.T) { name: "Only Combine set", inputXML: ``, expected: EALayout{ - Combine: onOffPtr(simpletypes.OnOffOn), + Combine: onOffPtr(stypes.OnOffOn), }, }, { name: "Only CombineBrkts set", inputXML: ``, expected: EALayout{ - CombineBrkts: combineBracketsPtr(simpletypes.CombineBracketsSquare), + CombineBrkts: combineBracketsPtr(stypes.CombineBracketsSquare), }, }, { name: "Only Vert set", inputXML: ``, expected: EALayout{ - Vert: onOffPtr(simpletypes.OnOffOff), + Vert: onOffPtr(stypes.OnOffOff), }, }, { name: "Only VertCompress set", inputXML: ``, expected: EALayout{ - VertCompress: onOffPtr(simpletypes.OnOffOn), + VertCompress: onOffPtr(stypes.OnOffOn), }, }, { diff --git a/wml/docxrun/effect.go b/wml/docxrun/effect.go index cd917ba..9389dcd 100644 --- a/wml/docxrun/effect.go +++ b/wml/docxrun/effect.go @@ -3,11 +3,11 @@ package docxrun import ( "encoding/xml" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) type Effect struct { - Val *simpletypes.TextEffect `xml:"val,attr,omitempty"` + Val *stypes.TextEffect `xml:"val,attr,omitempty"` } // MarshalXML implements the xml.Marshaler interface for the Effect type. diff --git a/wml/docxrun/effect_test.go b/wml/docxrun/effect_test.go index aee7f24..74bd1aa 100644 --- a/wml/docxrun/effect_test.go +++ b/wml/docxrun/effect_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestEffect_MarshalXML(t *testing.T) { @@ -16,7 +16,7 @@ func TestEffect_MarshalXML(t *testing.T) { }{ { name: "With value", - input: Effect{Val: TextEffectPtr(simpletypes.TextEffectBlinkBackground)}, + input: Effect{Val: TextEffectPtr(stypes.TextEffectBlinkBackground)}, expected: ``, }, { @@ -55,7 +55,7 @@ func TestEffect_UnmarshalXML(t *testing.T) { { name: "With value", inputXML: ``, - expected: Effect{Val: TextEffectPtr(simpletypes.TextEffectBlinkBackground)}, + expected: Effect{Val: TextEffectPtr(stypes.TextEffectBlinkBackground)}, }, { name: "Without value", @@ -89,6 +89,6 @@ func TestEffect_UnmarshalXML(t *testing.T) { } } -func TextEffectPtr(value simpletypes.TextEffect) *simpletypes.TextEffect { +func TextEffectPtr(value stypes.TextEffect) *stypes.TextEffect { return &value } diff --git a/wml/docxrun/em.go b/wml/docxrun/em.go index 516f637..b6c9ce8 100644 --- a/wml/docxrun/em.go +++ b/wml/docxrun/em.go @@ -3,12 +3,12 @@ package docxrun import ( "encoding/xml" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) // Emphasis Mark type Em struct { - Val simpletypes.Em `xml:"val,attr"` + Val stypes.Em `xml:"val,attr"` } func (f *Em) MarshalXML(e *xml.Encoder, start xml.StartElement) error { diff --git a/wml/docxrun/em_test.go b/wml/docxrun/em_test.go index d515ecd..97c6f6e 100644 --- a/wml/docxrun/em_test.go +++ b/wml/docxrun/em_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestEm_MarshalXML(t *testing.T) { @@ -16,27 +16,27 @@ func TestEm_MarshalXML(t *testing.T) { }{ { name: "Valid Value - none", - em: Em{Val: simpletypes.EmNone}, + em: Em{Val: stypes.EmNone}, expected: ``, }, { name: "Valid Value - dot", - em: Em{Val: simpletypes.EmDot}, + em: Em{Val: stypes.EmDot}, expected: ``, }, { name: "Valid Value - comma", - em: Em{Val: simpletypes.EmComma}, + em: Em{Val: stypes.EmComma}, expected: ``, }, { name: "Valid Value - circle", - em: Em{Val: simpletypes.EmCircle}, + em: Em{Val: stypes.EmCircle}, expected: ``, }, { name: "Valid Value - underDot", - em: Em{Val: simpletypes.EmUnderDot}, + em: Em{Val: stypes.EmUnderDot}, expected: ``, }, } @@ -70,27 +70,27 @@ func TestEm_UnmarshalXML(t *testing.T) { { name: "Valid Value - none", inputXML: ``, - expected: Em{Val: simpletypes.EmNone}, + expected: Em{Val: stypes.EmNone}, }, { name: "Valid Value - dot", inputXML: ``, - expected: Em{Val: simpletypes.EmDot}, + expected: Em{Val: stypes.EmDot}, }, { name: "Valid Value - comma", inputXML: ``, - expected: Em{Val: simpletypes.EmComma}, + expected: Em{Val: stypes.EmComma}, }, { name: "Valid Value - circle", inputXML: ``, - expected: Em{Val: simpletypes.EmCircle}, + expected: Em{Val: stypes.EmCircle}, }, { name: "Valid Value - underDot", inputXML: ``, - expected: Em{Val: simpletypes.EmUnderDot}, + expected: Em{Val: stypes.EmUnderDot}, }, } diff --git a/wml/docxrun/expaComp.go b/wml/docxrun/expaComp.go index e28050b..b66f552 100644 --- a/wml/docxrun/expaComp.go +++ b/wml/docxrun/expaComp.go @@ -3,14 +3,14 @@ package docxrun import ( "encoding/xml" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) // This element specifies the amount by which each character shall be expanded or when the character is rendered in the document // // This property has an of stretching or compressing each character in the run, as opposed to the spacing element (§2.3.2.33) which expands/compresses the text by adding additional character pitch but not changing the width of the actual characters displayed on the line. type ExpaComp struct { - Val *simpletypes.TextScale `xml:"val,attr,omitempty"` + Val *stypes.TextScale `xml:"val,attr,omitempty"` } // MarshalXML implements the xml.Marshaler interface for the ExpaComp type. diff --git a/wml/docxrun/expaComp_test.go b/wml/docxrun/expaComp_test.go index 3d8e388..69299a8 100644 --- a/wml/docxrun/expaComp_test.go +++ b/wml/docxrun/expaComp_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestExpaComp_MarshalXML(t *testing.T) { @@ -89,7 +89,7 @@ func TestExpaComp_UnmarshalXML(t *testing.T) { } } -func TextScalePtr(value uint16) *simpletypes.TextScale { - ts := simpletypes.TextScale(value) +func TextScalePtr(value uint16) *stypes.TextScale { + ts := stypes.TextScale(value) return &ts } diff --git a/wml/docxrun/rFonts.go b/wml/docxrun/rFonts.go index f6878f9..00f5a66 100644 --- a/wml/docxrun/rFonts.go +++ b/wml/docxrun/rFonts.go @@ -3,20 +3,20 @@ package docxrun import ( "encoding/xml" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) // Run Fonts type RunFonts struct { - Hint simpletypes.FontTypeHint `xml:"hint,attr,omitempty"` - Ascii string `xml:"ascii,attr,omitempty"` - HAnsi string `xml:"hAnsi,attr,omitempty"` - EastAsia string `xml:"eastAsia,attr,omitempty"` - CS string `xml:"cs,attr,omitempty"` - AsciiTheme simpletypes.ThemeFont `xml:"asciiTheme,attr,omitempty"` - HAnsiTheme simpletypes.ThemeFont `xml:"hAnsiTheme,attr,omitempty"` - EastAsiaTheme simpletypes.ThemeFont `xml:"eastAsiaTheme,attr,omitempty"` - CSTheme simpletypes.ThemeFont `xml:"cstheme,attr,omitempty"` + Hint stypes.FontTypeHint `xml:"hint,attr,omitempty"` + Ascii string `xml:"ascii,attr,omitempty"` + HAnsi string `xml:"hAnsi,attr,omitempty"` + EastAsia string `xml:"eastAsia,attr,omitempty"` + CS string `xml:"cs,attr,omitempty"` + AsciiTheme stypes.ThemeFont `xml:"asciiTheme,attr,omitempty"` + HAnsiTheme stypes.ThemeFont `xml:"hAnsiTheme,attr,omitempty"` + EastAsiaTheme stypes.ThemeFont `xml:"eastAsiaTheme,attr,omitempty"` + CSTheme stypes.ThemeFont `xml:"cstheme,attr,omitempty"` } func (rf *RunFonts) MarshalXML(e *xml.Encoder, start xml.StartElement) error { diff --git a/wml/docxrun/rFonts_test.go b/wml/docxrun/rFonts_test.go index 646643b..dfbfd40 100644 --- a/wml/docxrun/rFonts_test.go +++ b/wml/docxrun/rFonts_test.go @@ -5,20 +5,20 @@ import ( "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestRunFontsMarshalXML(t *testing.T) { rf := RunFonts{ - Hint: simpletypes.FontTypeHintDefault, + Hint: stypes.FontTypeHintDefault, Ascii: "Arial", HAnsi: "Calibri", EastAsia: "SimSun", CS: "Arial", - AsciiTheme: simpletypes.ThemeFontMajorAscii, - HAnsiTheme: simpletypes.ThemeFontMajorHAnsi, - EastAsiaTheme: simpletypes.ThemeFontMajorEastAsia, - CSTheme: simpletypes.ThemeFontMajorBidi, + AsciiTheme: stypes.ThemeFontMajorAscii, + HAnsiTheme: stypes.ThemeFontMajorHAnsi, + EastAsiaTheme: stypes.ThemeFontMajorEastAsia, + CSTheme: stypes.ThemeFontMajorBidi, } var output strings.Builder @@ -45,15 +45,15 @@ func TestRunFontsUnmarshalXML(t *testing.T) { } expected := RunFonts{ - Hint: simpletypes.FontTypeHintDefault, + Hint: stypes.FontTypeHintDefault, Ascii: "Arial", HAnsi: "Calibri", EastAsia: "SimSun", CS: "Arial", - AsciiTheme: simpletypes.ThemeFontMajorAscii, - HAnsiTheme: simpletypes.ThemeFontMajorHAnsi, - EastAsiaTheme: simpletypes.ThemeFontMajorEastAsia, - CSTheme: simpletypes.ThemeFontMajorBidi, + AsciiTheme: stypes.ThemeFontMajorAscii, + HAnsiTheme: stypes.ThemeFontMajorHAnsi, + EastAsiaTheme: stypes.ThemeFontMajorEastAsia, + CSTheme: stypes.ThemeFontMajorBidi, } if rf != expected { diff --git a/wml/docxrun/run.go b/wml/docxrun/run.go index e34e969..20d509d 100644 --- a/wml/docxrun/run.go +++ b/wml/docxrun/run.go @@ -5,9 +5,10 @@ import ( "github.com/gomutex/godocx/dml" "github.com/gomutex/godocx/elemtypes" + "github.com/gomutex/godocx/wml/ctypes" "github.com/gomutex/godocx/wml/formatting" "github.com/gomutex/godocx/wml/runcontent" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) // A Run is part of a paragraph that has its own style. It could be @@ -20,7 +21,7 @@ type RunChild struct { InstrText *string Text *runcontent.Text Drawing *dml.Drawing - Tab *runcontent.Tab + Tab *ctypes.Empty `xml:"tab,omitempty"` Break *runcontent.Break } @@ -64,8 +65,8 @@ func (r *Run) Size(size uint64) *Run { return r } -func (r *Run) Shading(shdType simpletypes.Shading, color, fill string) *Run { - r.RunProperty.Shading = NewShading().SetShadingType(shdType).SetColor(color).SetFill(fill) +func (r *Run) Shading(shdType stypes.Shading, color, fill string) *Run { + r.RunProperty.Shading = ctypes.NewShading().SetShadingType(shdType).SetColor(color).SetFill(fill) return r } @@ -196,7 +197,7 @@ func (r *Run) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error) { } if data.Tab != nil { - err := data.Tab.MarshalXML(e, xml.StartElement{}) + err := data.Tab.MarshalXML(e, xml.StartElement{Name: xml.Name{Local: "w:tab"}}) if err != nil { return err } @@ -237,7 +238,7 @@ loop: return err } case "tab": - tabElem := &runcontent.Tab{} + tabElem := &ctypes.Empty{} if err = d.DecodeElement(tabElem, &elem); err != nil { return err } diff --git a/wml/docxrun/runprop.go b/wml/docxrun/runprop.go index 7a71f6a..fc547d1 100644 --- a/wml/docxrun/runprop.go +++ b/wml/docxrun/runprop.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/gomutex/godocx/elemtypes" + "github.com/gomutex/godocx/wml/ctypes" "github.com/gomutex/godocx/wml/formatting" ) @@ -14,7 +15,7 @@ type RunProperty struct { Color *formatting.Color `xml:"color,omitempty"` Size *FontSize `xml:"sz,omitempty"` SizeCs *FontSizeCS `xml:"szCs,omitempty"` - Shading *Shading `xml:"shd,omitempty"` + Shading *ctypes.Shading `xml:"shd,omitempty"` Highlight *formatting.Highlight `xml:"highlight,omitempty"` Underline *formatting.Underline `xml:"u,omitempty"` Effect *Effect `xml:"effect,omitempty"` diff --git a/wml/docxrun/vertAlign.go b/wml/docxrun/vertAlign.go index a552308..233d35b 100644 --- a/wml/docxrun/vertAlign.go +++ b/wml/docxrun/vertAlign.go @@ -3,11 +3,11 @@ package docxrun import ( "encoding/xml" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) type VertAlign struct { - Val simpletypes.VerticalAlignRun `xml:"val,attr,omitempty"` + Val stypes.VerticalAlignRun `xml:"val,attr,omitempty"` } func (v *VertAlign) MarshalXML(e *xml.Encoder, start xml.StartElement) error { diff --git a/wml/docxrun/vertAlign_test.go b/wml/docxrun/vertAlign_test.go index ae503c6..51b389d 100644 --- a/wml/docxrun/vertAlign_test.go +++ b/wml/docxrun/vertAlign_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestVertAlign_MarshalXML(t *testing.T) { @@ -16,7 +16,7 @@ func TestVertAlign_MarshalXML(t *testing.T) { }{ { name: "Valid Value", - vertAlign: VertAlign{Val: simpletypes.VerticalAlignRunBaseline}, + vertAlign: VertAlign{Val: stypes.VerticalAlignRunBaseline}, expected: ``, }, } @@ -49,7 +49,7 @@ func TestVertAlign_UnmarshalXML(t *testing.T) { { name: "Valid Value", inputXML: ``, - expected: VertAlign{Val: simpletypes.VerticalAlignRunBaseline}, + expected: VertAlign{Val: stypes.VerticalAlignRunBaseline}, }, } diff --git a/wml/hdrftr/footer.go b/wml/hdrftr/footer.go index ffb178f..ca67bbc 100644 --- a/wml/hdrftr/footer.go +++ b/wml/hdrftr/footer.go @@ -3,13 +3,13 @@ package hdrftr import ( "encoding/xml" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) // Footer Reference type FooterReference struct { - Type simpletypes.HdrFtrType `xml:"type,attr"` //Footer or Footer Type - ID string `xml:"id,attr"` //Relationship to Part + Type stypes.HdrFtrType `xml:"type,attr"` //Footer or Footer Type + ID string `xml:"id,attr"` //Relationship to Part } func (h *FooterReference) MarshalXML(e *xml.Encoder, start xml.StartElement) error { diff --git a/wml/hdrftr/footer_test.go b/wml/hdrftr/footer_test.go index 7ef7a2c..a3acae3 100644 --- a/wml/hdrftr/footer_test.go +++ b/wml/hdrftr/footer_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestFooterReference_MarshalXML(t *testing.T) { @@ -18,14 +18,14 @@ func TestFooterReference_MarshalXML(t *testing.T) { name: "Marshal with ID and Type", input: FooterReference{ ID: "rId1", - Type: simpletypes.HdrFtrFirst, + Type: stypes.HdrFtrFirst, }, expected: ``, }, { name: "Marshal with Type only", input: FooterReference{ - Type: simpletypes.HdrFtrEven, + Type: stypes.HdrFtrEven, }, expected: ``, }, @@ -73,14 +73,14 @@ func TestFooterReference_UnmarshalXML(t *testing.T) { inputXML: ``, expected: FooterReference{ ID: "rId1", - Type: simpletypes.HdrFtrFirst, + Type: stypes.HdrFtrFirst, }, }, { name: "Unmarshal with Type only", inputXML: ``, expected: FooterReference{ - Type: simpletypes.HdrFtrEven, + Type: stypes.HdrFtrEven, }, }, { diff --git a/wml/hdrftr/header.go b/wml/hdrftr/header.go index 29f203f..cd2f750 100644 --- a/wml/hdrftr/header.go +++ b/wml/hdrftr/header.go @@ -3,13 +3,13 @@ package hdrftr import ( "encoding/xml" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) // Header Reference type HeaderReference struct { - Type simpletypes.HdrFtrType `xml:"type,attr"` //Header or Footer Type - ID string `xml:"id,attr"` //Relationship to Part + Type stypes.HdrFtrType `xml:"type,attr"` //Header or Footer Type + ID string `xml:"id,attr"` //Relationship to Part } func (h *HeaderReference) MarshalXML(e *xml.Encoder, start xml.StartElement) error { diff --git a/wml/hdrftr/header_test.go b/wml/hdrftr/header_test.go index d8e33d7..822b58f 100644 --- a/wml/hdrftr/header_test.go +++ b/wml/hdrftr/header_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestHeaderReference_MarshalXML(t *testing.T) { @@ -18,14 +18,14 @@ func TestHeaderReference_MarshalXML(t *testing.T) { name: "Marshal with ID and Type", input: HeaderReference{ ID: "rId1", - Type: simpletypes.HdrFtrFirst, + Type: stypes.HdrFtrFirst, }, expected: ``, }, { name: "Marshal with Type only", input: HeaderReference{ - Type: simpletypes.HdrFtrEven, + Type: stypes.HdrFtrEven, }, expected: ``, }, @@ -72,14 +72,14 @@ func TestHeaderReference_UnmarshalXML(t *testing.T) { inputXML: ``, expected: HeaderReference{ ID: "rId1", - Type: simpletypes.HdrFtrFirst, + Type: stypes.HdrFtrFirst, }, }, { name: "Unmarshal with Type only", inputXML: ``, expected: HeaderReference{ - Type: simpletypes.HdrFtrEven, + Type: stypes.HdrFtrEven, }, }, { diff --git a/wml/hdrftr/titlePg.go b/wml/hdrftr/titlePg.go index c65d468..c28b351 100644 --- a/wml/hdrftr/titlePg.go +++ b/wml/hdrftr/titlePg.go @@ -3,12 +3,12 @@ package hdrftr import ( "encoding/xml" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) // Different First Page Headers and Footers type TitlePg struct { - Val simpletypes.OnOff `xml:"val,attr,omitempty"` + Val stypes.OnOff `xml:"val,attr,omitempty"` } func (t *TitlePg) MarshalXML(e *xml.Encoder, start xml.StartElement) error { diff --git a/wml/hdrftr/titlePg_test.go b/wml/hdrftr/titlePg_test.go index 96b65d0..ad83927 100644 --- a/wml/hdrftr/titlePg_test.go +++ b/wml/hdrftr/titlePg_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestTitlePg_MarshalXML(t *testing.T) { @@ -16,19 +16,19 @@ func TestTitlePg_MarshalXML(t *testing.T) { }{ { titlePg: TitlePg{ - Val: simpletypes.OnOff("on"), + Val: stypes.OnOff("on"), }, expectedXML: ``, }, { titlePg: TitlePg{ - Val: simpletypes.OnOff("1"), + Val: stypes.OnOff("1"), }, expectedXML: ``, }, { titlePg: TitlePg{ - Val: simpletypes.OnOff(""), + Val: stypes.OnOff(""), }, expectedXML: ``, }, @@ -67,26 +67,26 @@ func TestTitlePg_UnmarshalXML(t *testing.T) { { xmlInput: ``, expectedTitlePg: TitlePg{ - Val: simpletypes.OnOff("on"), + Val: stypes.OnOff("on"), }, }, { xmlInput: ``, expectedTitlePg: TitlePg{ - Val: simpletypes.OnOff("off"), + Val: stypes.OnOff("off"), }, }, { xmlInput: ``, expectedTitlePg: TitlePg{ - Val: simpletypes.OnOff(""), + Val: stypes.OnOff(""), }, err: errors.New("invalid OnOff string"), }, { xmlInput: ``, expectedTitlePg: TitlePg{ - Val: simpletypes.OnOff(""), + Val: stypes.OnOff(""), }, }, } diff --git a/wml/runcontent/tabs.go b/wml/runcontent/tabs.go deleted file mode 100644 index 6ac3555..0000000 --- a/wml/runcontent/tabs.go +++ /dev/null @@ -1,99 +0,0 @@ -package runcontent - -import "encoding/xml" - -// Custom Tab Stop -type Tab struct { - Val *string // Tab Stop Type - Pos *string // Tab Stop Position - LeaderChar *LeadChar // Custom Tab Stop Leader Character -} - -type LeadChar string - -const ( - LeadCharNone LeadChar = "none" - LeadCharDot LeadChar = "dot" - LeadCharHypen LeadChar = "hyphen" - LeadCharUnderScore LeadChar = "underscore" - LeadCharHeavy LeadChar = "heavy" - LeadCharMiddleDot LeadChar = "middleDot" - LeadCharInvalid LeadChar = "" -) - -func LeadCharFromStr(val string) (LeadChar, error) { - switch val { - case "none": - return LeadCharNone, nil - case "dot": - return LeadCharDot, nil - case "hyphen": - return LeadCharHypen, nil - case "underscore": - return LeadCharUnderScore, nil - case "heavy": - return LeadCharHeavy, nil - case "middleDot": - return LeadCharMiddleDot, nil - default: - return LeadCharInvalid, nil - } -} - -func (t *Tab) MarshalXML(e *xml.Encoder, start xml.StartElement) error { - start.Name.Local = "w:tab" - start.Attr = []xml.Attr{} - - if t.Val != nil { - start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "val"}, Value: *t.Val}) - } - - if t.Pos != nil { - start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "pos"}, Value: *t.Pos}) - } - - if t.LeaderChar != nil { - start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "leader"}, Value: string(*t.LeaderChar)}) - } - - err := e.EncodeToken(start) - if err != nil { - return err - } - - return e.EncodeToken(xml.EndElement{Name: start.Name}) -} - -func (t *Tab) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { - for _, a := range start.Attr { - switch a.Name.Local { - case "val": - t.Val = &a.Value - case "pos": - t.Pos = &a.Value - case "leader": - lc, err := LeadCharFromStr(a.Value) - if err != nil { - return err - } - t.LeaderChar = &lc - } - } - - for { - currentToken, err := d.Token() - if err != nil { - return err - } - - switch elem := currentToken.(type) { - case xml.StartElement: - switch elem.Name.Local { - } - case xml.EndElement: - if elem == start.End() { - return nil - } - } - } -} diff --git a/wml/sections/docGrid.go b/wml/sections/docGrid.go index dac7fdd..903dc91 100644 --- a/wml/sections/docGrid.go +++ b/wml/sections/docGrid.go @@ -4,14 +4,14 @@ import ( "encoding/xml" "strconv" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) // DocGrid represents the document grid settings. type DocGrid struct { - Type simpletypes.DocGridType `xml:"type,attr,omitempty"` - LinePitch *int `xml:"linePitch,attr,omitempty"` - CharSpace *int `xml:"charSpace,attr,omitempty"` + Type stypes.DocGridType `xml:"type,attr,omitempty"` + LinePitch *int `xml:"linePitch,attr,omitempty"` + CharSpace *int `xml:"charSpace,attr,omitempty"` } // MarshalXML implements the xml.Marshaler interface for the DocGrid type. diff --git a/wml/sections/docGrid_test.go b/wml/sections/docGrid_test.go index 72a58b4..d9736db 100644 --- a/wml/sections/docGrid_test.go +++ b/wml/sections/docGrid_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestDocGrid_MarshalXML_AllAttributes(t *testing.T) { @@ -13,7 +13,7 @@ func TestDocGrid_MarshalXML_AllAttributes(t *testing.T) { charSpace := 120 docGrid := DocGrid{ - Type: simpletypes.DocGridLinesAndChars, + Type: stypes.DocGridLinesAndChars, LinePitch: &linePitch, CharSpace: &charSpace, } @@ -25,7 +25,7 @@ func TestDocGrid_MarshalXML_AllAttributes(t *testing.T) { func TestDocGrid_MarshalXML_OmitEmptyAttributes(t *testing.T) { docGrid := DocGrid{ - Type: simpletypes.DocGridLines, + Type: stypes.DocGridLines, } expectedXML := `` @@ -63,7 +63,7 @@ func TestDocGrid_UnmarshalXML_AllAttributes(t *testing.T) { linePitch := 240 charSpace := 120 expectedDocGrid := DocGrid{ - Type: simpletypes.DocGridLinesAndChars, + Type: stypes.DocGridLinesAndChars, LinePitch: &linePitch, CharSpace: &charSpace, } @@ -75,7 +75,7 @@ func TestDocGrid_UnmarshalXML_MinimalAttributes(t *testing.T) { xmlInput := `` expectedDocGrid := DocGrid{ - Type: simpletypes.DocGridLines, + Type: stypes.DocGridLines, } checkUnmarshalXML(t, xmlInput, expectedDocGrid) diff --git a/wml/sections/formProt.go b/wml/sections/formProt.go index 85bf456..abfdf50 100644 --- a/wml/sections/formProt.go +++ b/wml/sections/formProt.go @@ -3,12 +3,12 @@ package sections import ( "encoding/xml" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) // FormProt represents the text direction settings in a Word document. type FormProt struct { - Val simpletypes.OnOff `xml:"val,attr,omitempty"` + Val stypes.OnOff `xml:"val,attr,omitempty"` } // MarshalXML implements the xml.Marshaler interface for the FormProt type. diff --git a/wml/sections/formProt_test.go b/wml/sections/formProt_test.go index 80ea07a..175cf8b 100644 --- a/wml/sections/formProt_test.go +++ b/wml/sections/formProt_test.go @@ -4,7 +4,7 @@ import ( "encoding/xml" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestFormProt_MarshalXML(t *testing.T) { @@ -15,7 +15,7 @@ func TestFormProt_MarshalXML(t *testing.T) { }{ { name: "WithVal", - formProt: FormProt{Val: simpletypes.OnOff("on")}, + formProt: FormProt{Val: stypes.OnOff("on")}, expected: ``, }, { @@ -47,7 +47,7 @@ func TestFormProt_UnmarshalXML(t *testing.T) { }{ { xmlStr: ``, - expected: FormProt{Val: simpletypes.OnOff("on")}, + expected: FormProt{Val: stypes.OnOff("on")}, }, { xmlStr: ``, diff --git a/wml/sections/pageNum.go b/wml/sections/pageNum.go index 4603de8..40b0804 100644 --- a/wml/sections/pageNum.go +++ b/wml/sections/pageNum.go @@ -3,12 +3,12 @@ package sections import ( "encoding/xml" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) // PageNumbering represents the page numbering format in a Word document. type PageNumbering struct { - Format simpletypes.NumFmt `xml:"fmt,attr,omitempty"` + Format stypes.NumFmt `xml:"fmt,attr,omitempty"` } // MarshalXML implements the xml.Marshaler interface for the PageNumbering type. diff --git a/wml/sections/pageNum_test.go b/wml/sections/pageNum_test.go index 833d135..e7df0a3 100644 --- a/wml/sections/pageNum_test.go +++ b/wml/sections/pageNum_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestPageNumbering_MarshalXML(t *testing.T) { @@ -16,7 +16,7 @@ func TestPageNumbering_MarshalXML(t *testing.T) { }{ { name: "With format", - input: PageNumbering{Format: simpletypes.NumFmtDecimal}, + input: PageNumbering{Format: stypes.NumFmtDecimal}, expected: ``, }, { @@ -55,7 +55,7 @@ func TestPageNumbering_UnmarshalXML(t *testing.T) { { name: "With format", inputXML: ``, - expected: PageNumbering{Format: simpletypes.NumFmtDecimal}, + expected: PageNumbering{Format: stypes.NumFmtDecimal}, }, { name: "Without format", diff --git a/wml/sections/pageSize.go b/wml/sections/pageSize.go index f7f7d11..c9872ee 100644 --- a/wml/sections/pageSize.go +++ b/wml/sections/pageSize.go @@ -4,15 +4,15 @@ import ( "encoding/xml" "strconv" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) // Page Size : w:pgSz type PageSize struct { - Width *uint64 `xml:"w,attr,omitempty"` - Height *uint64 `xml:"h,attr,omitempty"` - Orient simpletypes.PageOrient `xml:"orient,attr,omitempty"` - Code *int `xml:"code,attr,omitempty"` + Width *uint64 `xml:"w,attr,omitempty"` + Height *uint64 `xml:"h,attr,omitempty"` + Orient stypes.PageOrient `xml:"orient,attr,omitempty"` + Code *int `xml:"code,attr,omitempty"` } func (p *PageSize) MarshalXML(e *xml.Encoder, start xml.StartElement) error { diff --git a/wml/sections/pageSize_test.go b/wml/sections/pageSize_test.go index 92286c6..d282cc3 100644 --- a/wml/sections/pageSize_test.go +++ b/wml/sections/pageSize_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestPageSize_MarshalXML(t *testing.T) { @@ -19,7 +19,7 @@ func TestPageSize_MarshalXML(t *testing.T) { input: PageSize{ Width: uint64Ptr(12240), Height: uint64Ptr(15840), - Orient: simpletypes.PageOrientLandscape, + Orient: stypes.PageOrientLandscape, Code: intPtr(1), }, expected: ``, @@ -70,7 +70,7 @@ func TestPageSize_UnmarshalXML(t *testing.T) { expected: PageSize{ Width: uint64Ptr(12240), Height: uint64Ptr(15840), - Orient: simpletypes.PageOrientLandscape, + Orient: stypes.PageOrientLandscape, Code: intPtr(1), }, }, diff --git a/wml/sections/sectionProp_test.go b/wml/sections/sectionProp_test.go index c4a9b31..57a42f7 100644 --- a/wml/sections/sectionProp_test.go +++ b/wml/sections/sectionProp_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/gomutex/godocx/wml/hdrftr" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestSectionProp_MarshalXML(t *testing.T) { @@ -27,7 +27,7 @@ func TestSectionProp_MarshalXML(t *testing.T) { }, Type: &SectionType{Val: "nextPage"}, PageMargin: &PageMargin{Top: intPtr(1440), Bottom: intPtr(1440), Left: intPtr(1440), Right: intPtr(1440)}, - PageNum: &PageNumbering{Format: simpletypes.NumFmtDecimal}, + PageNum: &PageNumbering{Format: stypes.NumFmtDecimal}, FormProt: &FormProt{Val: "true"}, TitlePg: &hdrftr.TitlePg{Val: "true"}, TextDir: &TextDirection{Val: "lrTb"}, @@ -118,7 +118,7 @@ func TestSectionProp_UnmarshalXML(t *testing.T) { }, Type: &SectionType{Val: "nextPage"}, PageMargin: &PageMargin{Top: intPtr(1440), Bottom: intPtr(1440), Left: intPtr(1440), Right: intPtr(1440)}, - PageNum: &PageNumbering{Format: simpletypes.NumFmtDecimal}, + PageNum: &PageNumbering{Format: stypes.NumFmtDecimal}, FormProt: &FormProt{Val: "true"}, TitlePg: &hdrftr.TitlePg{Val: "true"}, TextDir: &TextDirection{Val: "lrTb"}, diff --git a/wml/sections/sectionType.go b/wml/sections/sectionType.go index 7eec909..6225524 100644 --- a/wml/sections/sectionType.go +++ b/wml/sections/sectionType.go @@ -3,11 +3,11 @@ package sections import ( "encoding/xml" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) type SectionType struct { - Val simpletypes.SectionMark `xml:"val,attr,omitempty"` + Val stypes.SectionMark `xml:"val,attr,omitempty"` } // MarshalXML implements the xml.Marshaler interface for the SectionType type. diff --git a/wml/sections/sectionType_test.go b/wml/sections/sectionType_test.go index 12d8767..9d7ed24 100644 --- a/wml/sections/sectionType_test.go +++ b/wml/sections/sectionType_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestSectionType_MarshalXML(t *testing.T) { @@ -16,7 +16,7 @@ func TestSectionType_MarshalXML(t *testing.T) { }{ { name: "Valid SectionType", - input: SectionType{Val: simpletypes.SectionMark("nextPage")}, + input: SectionType{Val: stypes.SectionMark("nextPage")}, expected: ``, }, { @@ -55,7 +55,7 @@ func TestSectionType_UnmarshalXML(t *testing.T) { { name: "Valid SectionType", inputXML: ``, - expected: SectionType{Val: simpletypes.SectionMark("nextPage")}, + expected: SectionType{Val: stypes.SectionMark("nextPage")}, }, { name: "Empty SectionType", diff --git a/wml/sections/testDirecion_test.go b/wml/sections/testDirecion_test.go index 340585e..4cc4ef6 100644 --- a/wml/sections/testDirecion_test.go +++ b/wml/sections/testDirecion_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) func TestTextDirection_MarshalXML(t *testing.T) { @@ -17,7 +17,7 @@ func TestTextDirection_MarshalXML(t *testing.T) { }{ { name: "WithVal", - textDir: TextDirection{Val: simpletypes.TextDirectionLrTb}, + textDir: TextDirection{Val: stypes.TextDirectionLrTb}, expected: ``, shouldMarshal: true, }, @@ -29,7 +29,7 @@ func TestTextDirection_MarshalXML(t *testing.T) { }, { name: "Empty", - textDir: TextDirection{Val: simpletypes.TextDirection("")}, + textDir: TextDirection{Val: stypes.TextDirection("")}, expected: ``, shouldMarshal: false, // Not expected to marshal because Val is empty }, @@ -61,7 +61,7 @@ func TestTextDirection_UnmarshalXML(t *testing.T) { }{ { xmlStr: ``, - expected: TextDirection{Val: simpletypes.TextDirectionLrTb}, + expected: TextDirection{Val: stypes.TextDirectionLrTb}, }, { xmlStr: ``, diff --git a/wml/sections/textDirection.go b/wml/sections/textDirection.go index 102a5de..624c20c 100644 --- a/wml/sections/textDirection.go +++ b/wml/sections/textDirection.go @@ -3,12 +3,12 @@ package sections import ( "encoding/xml" - "github.com/gomutex/godocx/wml/simpletypes" + "github.com/gomutex/godocx/wml/stypes" ) // TextDirection represents the text direction settings in a Word document. type TextDirection struct { - Val simpletypes.TextDirection `xml:"val,attr,omitempty"` + Val stypes.TextDirection `xml:"val,attr,omitempty"` } // MarshalXML implements the xml.Marshaler interface for the TextDirection type. diff --git a/wml/simpletypes/borderStyle.go b/wml/stypes/borderStyle.go similarity index 99% rename from wml/simpletypes/borderStyle.go rename to wml/stypes/borderStyle.go index 68208b2..ddc21de 100644 --- a/wml/simpletypes/borderStyle.go +++ b/wml/stypes/borderStyle.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/borderStyle_test.go b/wml/stypes/borderStyle_test.go similarity index 98% rename from wml/simpletypes/borderStyle_test.go rename to wml/stypes/borderStyle_test.go index 434f0bb..af8427b 100644 --- a/wml/simpletypes/borderStyle_test.go +++ b/wml/stypes/borderStyle_test.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/combBracket.go b/wml/stypes/combBracket.go similarity index 98% rename from wml/simpletypes/combBracket.go rename to wml/stypes/combBracket.go index 3d107e6..a58c14c 100644 --- a/wml/simpletypes/combBracket.go +++ b/wml/stypes/combBracket.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/combBracket_test.go b/wml/stypes/combBracket_test.go similarity index 99% rename from wml/simpletypes/combBracket_test.go rename to wml/stypes/combBracket_test.go index 1f5af47..6eb5756 100644 --- a/wml/simpletypes/combBracket_test.go +++ b/wml/stypes/combBracket_test.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/docGridType.go b/wml/stypes/docGridType.go similarity index 97% rename from wml/simpletypes/docGridType.go rename to wml/stypes/docGridType.go index 5e039ed..dcf1aaf 100644 --- a/wml/simpletypes/docGridType.go +++ b/wml/stypes/docGridType.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/docGridType_test.go b/wml/stypes/docGridType_test.go similarity index 99% rename from wml/simpletypes/docGridType_test.go rename to wml/stypes/docGridType_test.go index 78d4704..739e567 100644 --- a/wml/simpletypes/docGridType_test.go +++ b/wml/stypes/docGridType_test.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/em.go b/wml/stypes/em.go similarity index 97% rename from wml/simpletypes/em.go rename to wml/stypes/em.go index 5309750..9cee8b6 100644 --- a/wml/simpletypes/em.go +++ b/wml/stypes/em.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/em_test.go b/wml/stypes/em_test.go similarity index 99% rename from wml/simpletypes/em_test.go rename to wml/stypes/em_test.go index a6db4ec..6eb06f5 100644 --- a/wml/simpletypes/em_test.go +++ b/wml/stypes/em_test.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/fontTypeHint.go b/wml/stypes/fontTypeHint.go similarity index 97% rename from wml/simpletypes/fontTypeHint.go rename to wml/stypes/fontTypeHint.go index 79d56e0..341e5d5 100644 --- a/wml/simpletypes/fontTypeHint.go +++ b/wml/stypes/fontTypeHint.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/fontTypeHint_test.go b/wml/stypes/fontTypeHint_test.go similarity index 99% rename from wml/simpletypes/fontTypeHint_test.go rename to wml/stypes/fontTypeHint_test.go index c8859c0..cfdc1d5 100644 --- a/wml/simpletypes/fontTypeHint_test.go +++ b/wml/stypes/fontTypeHint_test.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/hdrFtr.go b/wml/stypes/hdrFtr.go similarity index 97% rename from wml/simpletypes/hdrFtr.go rename to wml/stypes/hdrFtr.go index f760763..5444c9a 100644 --- a/wml/simpletypes/hdrFtr.go +++ b/wml/stypes/hdrFtr.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/hdrFtr_test.go b/wml/stypes/hdrFtr_test.go similarity index 99% rename from wml/simpletypes/hdrFtr_test.go rename to wml/stypes/hdrFtr_test.go index 3cd5d72..1f5c0be 100644 --- a/wml/simpletypes/hdrFtr_test.go +++ b/wml/stypes/hdrFtr_test.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/numFmt.go b/wml/stypes/numFmt.go similarity index 99% rename from wml/simpletypes/numFmt.go rename to wml/stypes/numFmt.go index 4513609..86a54a6 100644 --- a/wml/simpletypes/numFmt.go +++ b/wml/stypes/numFmt.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/numFmt_test.go b/wml/stypes/numFmt_test.go similarity index 99% rename from wml/simpletypes/numFmt_test.go rename to wml/stypes/numFmt_test.go index 9848b98..e98cddd 100644 --- a/wml/simpletypes/numFmt_test.go +++ b/wml/stypes/numFmt_test.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/onOff.go b/wml/stypes/onOff.go similarity index 97% rename from wml/simpletypes/onOff.go rename to wml/stypes/onOff.go index 4981e75..0d8557a 100644 --- a/wml/simpletypes/onOff.go +++ b/wml/stypes/onOff.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/onOff_test.go b/wml/stypes/onOff_test.go similarity index 99% rename from wml/simpletypes/onOff_test.go rename to wml/stypes/onOff_test.go index ad0c838..32a3fb7 100644 --- a/wml/simpletypes/onOff_test.go +++ b/wml/stypes/onOff_test.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/pageOrient.go b/wml/stypes/pageOrient.go similarity index 96% rename from wml/simpletypes/pageOrient.go rename to wml/stypes/pageOrient.go index ea16321..19e78bd 100644 --- a/wml/simpletypes/pageOrient.go +++ b/wml/stypes/pageOrient.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/pageOrient_test.go b/wml/stypes/pageOrient_test.go similarity index 99% rename from wml/simpletypes/pageOrient_test.go rename to wml/stypes/pageOrient_test.go index 0315927..b4fcae5 100644 --- a/wml/simpletypes/pageOrient_test.go +++ b/wml/stypes/pageOrient_test.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/sectionMark.go b/wml/stypes/sectionMark.go similarity index 98% rename from wml/simpletypes/sectionMark.go rename to wml/stypes/sectionMark.go index 6a036fd..a6c6de7 100644 --- a/wml/simpletypes/sectionMark.go +++ b/wml/stypes/sectionMark.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/sectionMark_test.go b/wml/stypes/sectionMark_test.go similarity index 99% rename from wml/simpletypes/sectionMark_test.go rename to wml/stypes/sectionMark_test.go index 63a110d..dd0f6ae 100644 --- a/wml/simpletypes/sectionMark_test.go +++ b/wml/stypes/sectionMark_test.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/shd.go b/wml/stypes/shd.go similarity index 99% rename from wml/simpletypes/shd.go rename to wml/stypes/shd.go index 9924cbe..c7020b0 100644 --- a/wml/simpletypes/shd.go +++ b/wml/stypes/shd.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/shd_test.go b/wml/stypes/shd_test.go similarity index 98% rename from wml/simpletypes/shd_test.go rename to wml/stypes/shd_test.go index 677346e..3e7b6ea 100644 --- a/wml/simpletypes/shd_test.go +++ b/wml/stypes/shd_test.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/stypes/tabJc.go b/wml/stypes/tabJc.go new file mode 100644 index 0000000..789db8c --- /dev/null +++ b/wml/stypes/tabJc.go @@ -0,0 +1,52 @@ +package stypes + +import ( + "encoding/xml" + "errors" +) + +// CustTabStop represents the custom tab stop type. +type CustTabStop string + +const ( + CustTabStopClear CustTabStop = "clear" + CustTabStopLeft CustTabStop = "left" + CustTabStopCenter CustTabStop = "center" + CustTabStopRight CustTabStop = "right" + CustTabStopDecimal CustTabStop = "decimal" + CustTabStopBar CustTabStop = "bar" + CustTabStopNum CustTabStop = "num" + CustTabStopInvalid CustTabStop = "" +) + +// Function to convert string to CustTabStop. +func CustTabStopFromStr(val string) (CustTabStop, error) { + switch val { + case "clear": + return CustTabStopClear, nil + case "left": + return CustTabStopLeft, nil + case "center": + return CustTabStopCenter, nil + case "right": + return CustTabStopRight, nil + case "decimal": + return CustTabStopDecimal, nil + case "bar": + return CustTabStopBar, nil + case "num": + return CustTabStopNum, nil + default: + return CustTabStopInvalid, errors.New("Invalid CustTabStop value") + } +} + +// Method to unmarshal XML attribute into CustTabStop. +func (t *CustTabStop) UnmarshalXMLAttr(attr xml.Attr) error { + val, err := CustTabStopFromStr(attr.Value) + if err != nil { + return err + } + *t = val + return nil +} diff --git a/wml/stypes/tabJc_test.go b/wml/stypes/tabJc_test.go new file mode 100644 index 0000000..20a8bd0 --- /dev/null +++ b/wml/stypes/tabJc_test.go @@ -0,0 +1,84 @@ +package stypes + +import ( + "encoding/xml" + "testing" +) + +func TestCustTabStopFromStr(t *testing.T) { + tests := []struct { + input string + expected CustTabStop + }{ + {"clear", CustTabStopClear}, + {"left", CustTabStopLeft}, + {"center", CustTabStopCenter}, + {"right", CustTabStopRight}, + {"decimal", CustTabStopDecimal}, + {"bar", CustTabStopBar}, + {"num", CustTabStopNum}, + {"invalid", CustTabStopInvalid}, + } + + for _, tt := range tests { + t.Run(tt.input, func(t *testing.T) { + result, err := CustTabStopFromStr(tt.input) + if tt.expected == CustTabStopInvalid && err == nil { + t.Fatalf("Expected error for input %s but got none", tt.input) + } + + if result != tt.expected { + t.Errorf("Expected %s but got %s", tt.expected, result) + } + }) + } +} + +func TestCustTabStop_UnmarshalXMLAttr(t *testing.T) { + tests := []struct { + name string + inputXML string + expected CustTabStop + }{ + { + name: "Valid attribute clear", + inputXML: ``, + expected: CustTabStopClear, + }, + { + name: "Valid attribute left", + inputXML: ``, + expected: CustTabStopLeft, + }, + { + name: "Valid attribute center", + inputXML: ``, + expected: CustTabStopCenter, + }, + { + name: "Invalid attribute", + inputXML: ``, + expected: CustTabStopInvalid, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + type Element struct { + XMLName xml.Name `xml:"element"` + Tab CustTabStop `xml:"tab,attr"` + } + + var elem Element + + err := xml.Unmarshal([]byte(tt.inputXML), &elem) + if tt.expected == CustTabStopInvalid && err == nil { + t.Fatalf("Expected error for input XML %s but got none", tt.inputXML) + } + + if elem.Tab != tt.expected { + t.Errorf("Expected %s but got %s", tt.expected, elem.Tab) + } + }) + } +} diff --git a/wml/stypes/tabTlc.go b/wml/stypes/tabTlc.go new file mode 100644 index 0000000..569400c --- /dev/null +++ b/wml/stypes/tabTlc.go @@ -0,0 +1,49 @@ +package stypes + +import ( + "encoding/xml" + "errors" +) + +// Custom Tab Stop Leader Character +type CustLeadChar string + +const ( + CustLeadCharNone CustLeadChar = "none" + CustLeadCharDot CustLeadChar = "dot" + CustLeadCharHyphen CustLeadChar = "hyphen" + CustLeadCharUnderScore CustLeadChar = "underscore" + CustLeadCharHeavy CustLeadChar = "heavy" + CustLeadCharMiddleDot CustLeadChar = "middleDot" + CustLeadCharInvalid CustLeadChar = "" +) + +func CustLeadCharFromStr(val string) (CustLeadChar, error) { + switch val { + case "none": + return CustLeadCharNone, nil + case "dot": + return CustLeadCharDot, nil + case "hyphen": + return CustLeadCharHyphen, nil + case "underscore": + return CustLeadCharUnderScore, nil + case "heavy": + return CustLeadCharHeavy, nil + case "middleDot": + return CustLeadCharMiddleDot, nil + default: + return CustLeadCharInvalid, errors.New("Invalid Lead Char") + } +} + +func (d *CustLeadChar) UnmarshalXMLAttr(attr xml.Attr) error { + val, err := CustLeadCharFromStr(attr.Value) + if err != nil { + return err + } + + *d = val + + return nil +} diff --git a/wml/stypes/tabTlc_test.go b/wml/stypes/tabTlc_test.go new file mode 100644 index 0000000..ca3fd80 --- /dev/null +++ b/wml/stypes/tabTlc_test.go @@ -0,0 +1,83 @@ +package stypes + +import ( + "encoding/xml" + "testing" +) + +func TestCustLeadCharFromStr(t *testing.T) { + tests := []struct { + input string + expected CustLeadChar + }{ + {"none", CustLeadCharNone}, + {"dot", CustLeadCharDot}, + {"hyphen", CustLeadCharHypen}, + {"underscore", CustLeadCharUnderScore}, + {"heavy", CustLeadCharHeavy}, + {"middleDot", CustLeadCharMiddleDot}, + {"invalid", CustLeadCharInvalid}, + } + + for _, tt := range tests { + t.Run(tt.input, func(t *testing.T) { + result, err := CustLeadCharFromStr(tt.input) + if tt.expected == CustLeadCharInvalid && err == nil { + t.Fatalf("Expected error for input %s but got none", tt.input) + } + + if result != tt.expected { + t.Errorf("Expected %s but got %s", tt.expected, result) + } + }) + } +} + +func TestCustLeadChar_UnmarshalXMLAttr(t *testing.T) { + tests := []struct { + name string + inputXML string + expected CustLeadChar + }{ + { + name: "Valid attribute none", + inputXML: ``, + expected: CustLeadCharNone, + }, + { + name: "Valid attribute dot", + inputXML: ``, + expected: CustLeadCharDot, + }, + { + name: "Valid attribute hyphen", + inputXML: ``, + expected: CustLeadCharHypen, + }, + { + name: "Invalid attribute", + inputXML: ``, + expected: CustLeadCharInvalid, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + type Element struct { + XMLName xml.Name `xml:"element"` + Leader CustLeadChar `xml:"leader,attr"` + } + + var elem Element + + err := xml.Unmarshal([]byte(tt.inputXML), &elem) + if tt.expected == CustLeadCharInvalid && err == nil { + t.Fatalf("Expected error for input XML %s but got none", tt.inputXML) + } + + if elem.Leader != tt.expected { + t.Errorf("Expected %s but got %s", tt.expected, elem.Leader) + } + }) + } +} diff --git a/wml/simpletypes/textDirection.go b/wml/stypes/textDirection.go similarity index 98% rename from wml/simpletypes/textDirection.go rename to wml/stypes/textDirection.go index 7f5b763..3bce4fa 100644 --- a/wml/simpletypes/textDirection.go +++ b/wml/stypes/textDirection.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/textDirection_test.go b/wml/stypes/textDirection_test.go similarity index 99% rename from wml/simpletypes/textDirection_test.go rename to wml/stypes/textDirection_test.go index f9375e8..b3a525f 100644 --- a/wml/simpletypes/textDirection_test.go +++ b/wml/stypes/textDirection_test.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/textEffect.go b/wml/stypes/textEffect.go similarity index 98% rename from wml/simpletypes/textEffect.go rename to wml/stypes/textEffect.go index 247776b..9d6d70c 100644 --- a/wml/simpletypes/textEffect.go +++ b/wml/stypes/textEffect.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/textEffect_test.go b/wml/stypes/textEffect_test.go similarity index 99% rename from wml/simpletypes/textEffect_test.go rename to wml/stypes/textEffect_test.go index b67fac6..8c6b261 100644 --- a/wml/simpletypes/textEffect_test.go +++ b/wml/stypes/textEffect_test.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/textScale.go b/wml/stypes/textScale.go similarity index 96% rename from wml/simpletypes/textScale.go rename to wml/stypes/textScale.go index 3d18c17..eb573b3 100644 --- a/wml/simpletypes/textScale.go +++ b/wml/stypes/textScale.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/textScale_test.go b/wml/stypes/textScale_test.go similarity index 99% rename from wml/simpletypes/textScale_test.go rename to wml/stypes/textScale_test.go index 87bece7..ea14714 100644 --- a/wml/simpletypes/textScale_test.go +++ b/wml/stypes/textScale_test.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/themeColor.go b/wml/stypes/themeColor.go similarity index 99% rename from wml/simpletypes/themeColor.go rename to wml/stypes/themeColor.go index ca0e11d..f3c8b38 100644 --- a/wml/simpletypes/themeColor.go +++ b/wml/stypes/themeColor.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/themeColor_test.go b/wml/stypes/themeColor_test.go similarity index 98% rename from wml/simpletypes/themeColor_test.go rename to wml/stypes/themeColor_test.go index 0d43a76..edd4bfd 100644 --- a/wml/simpletypes/themeColor_test.go +++ b/wml/stypes/themeColor_test.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/themeFont.go b/wml/stypes/themeFont.go similarity index 98% rename from wml/simpletypes/themeFont.go rename to wml/stypes/themeFont.go index 6b53b4c..ae3803a 100644 --- a/wml/simpletypes/themeFont.go +++ b/wml/stypes/themeFont.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/themeFont_test.go b/wml/stypes/themeFont_test.go similarity index 99% rename from wml/simpletypes/themeFont_test.go rename to wml/stypes/themeFont_test.go index 07eb8eb..9333c0d 100644 --- a/wml/simpletypes/themeFont_test.go +++ b/wml/stypes/themeFont_test.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/vertAlignRun.go b/wml/stypes/vertAlignRun.go similarity index 97% rename from wml/simpletypes/vertAlignRun.go rename to wml/stypes/vertAlignRun.go index b11e987..323d3ac 100644 --- a/wml/simpletypes/vertAlignRun.go +++ b/wml/stypes/vertAlignRun.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/simpletypes/vertAlignRun_test.go b/wml/stypes/vertAlignRun_test.go similarity index 99% rename from wml/simpletypes/vertAlignRun_test.go rename to wml/stypes/vertAlignRun_test.go index b83af02..bad6c22 100644 --- a/wml/simpletypes/vertAlignRun_test.go +++ b/wml/stypes/vertAlignRun_test.go @@ -1,4 +1,4 @@ -package simpletypes +package stypes import ( "encoding/xml" diff --git a/wml/table/table_cell_property.go b/wml/table/table_cell_property.go index e7a36df..f41e75b 100644 --- a/wml/table/table_cell_property.go +++ b/wml/table/table_cell_property.go @@ -4,11 +4,11 @@ import ( "encoding/xml" "github.com/gomutex/godocx/common/constants" - "github.com/gomutex/godocx/wml/docxrun" + "github.com/gomutex/godocx/wml/ctypes" ) type TableCellProperty struct { - Shading *docxrun.Shading + Shading *ctypes.Shading } func (t *TableCellProperty) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error) { @@ -39,7 +39,7 @@ func (t *TableCellProperty) UnmarshalXML(d *xml.Decoder, start xml.StartElement) case xml.StartElement: switch elem.Name { case xml.Name{Space: constants.WMLNamespace, Local: "shd"}, xml.Name{Space: constants.AltWMLNamespace, Local: "shd"}: - shd := docxrun.Shading{} + shd := ctypes.Shading{} if err = d.DecodeElement(&shd, &elem); err != nil { return err }