Todd 59b2711e1b schema: apply more default values
These are implied values as they are the defaults in the XSD
for optional attributes/elements. However I've noticed that
I keep running into issues where Mac Excel/Word fail to open
a file unless an optional default is provided.

I'll just add them all to hopefully increase compatibility and
save painful file format debugging sessions later.
2017-09-04 17:14:06 -05:00

233 lines
6.8 KiB
Go

// Copyright 2017 Baliance. All rights reserved.
//
// Use of this source code is governed by the terms of the Affero GNU General
// Public License version 3.0 as published by the Free Software Foundation and
// appearing in the file LICENSE included in the packaging of this file. A
// commercial license can be purchased by contacting sales@baliance.com.
package wordprocessingml
import (
"encoding/xml"
"fmt"
"baliance.com/gooxml/schema/schemas.openxmlformats.org/officeDocument/2006/sharedTypes"
)
type CT_TblPPr struct {
// Distance From Left of Table to Text
LeftFromTextAttr *sharedTypes.ST_TwipsMeasure
// (Distance From Right of Table to Text
RightFromTextAttr *sharedTypes.ST_TwipsMeasure
// Distance From Top of Table to Text
TopFromTextAttr *sharedTypes.ST_TwipsMeasure
// Distance From Bottom of Table to Text
BottomFromTextAttr *sharedTypes.ST_TwipsMeasure
// Table Vertical Anchor
VertAnchorAttr ST_VAnchor
// Table Horizontal Anchor
HorzAnchorAttr ST_HAnchor
// Relative Horizontal Alignment From Anchor
TblpXSpecAttr sharedTypes.ST_XAlign
// Absolute Horizontal Distance From Anchor
TblpXAttr *ST_SignedTwipsMeasure
// Relative Vertical Alignment from Anchor
TblpYSpecAttr sharedTypes.ST_YAlign
// Absolute Vertical Distance From Anchor
TblpYAttr *ST_SignedTwipsMeasure
}
func NewCT_TblPPr() *CT_TblPPr {
ret := &CT_TblPPr{}
ret.VertAnchorAttr = ST_VAnchor(1)
ret.HorzAnchorAttr = ST_HAnchor(1)
ret.TblpXSpecAttr = sharedTypes.ST_XAlign(1)
ret.TblpYSpecAttr = sharedTypes.ST_YAlign(1)
return ret
}
func (m *CT_TblPPr) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if m.LeftFromTextAttr != nil {
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "w:leftFromText"},
Value: fmt.Sprintf("%v", *m.LeftFromTextAttr)})
}
if m.RightFromTextAttr != nil {
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "w:rightFromText"},
Value: fmt.Sprintf("%v", *m.RightFromTextAttr)})
}
if m.TopFromTextAttr != nil {
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "w:topFromText"},
Value: fmt.Sprintf("%v", *m.TopFromTextAttr)})
}
if m.BottomFromTextAttr != nil {
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "w:bottomFromText"},
Value: fmt.Sprintf("%v", *m.BottomFromTextAttr)})
}
if m.VertAnchorAttr != ST_VAnchorUnset {
attr, err := m.VertAnchorAttr.MarshalXMLAttr(xml.Name{Local: "w:vertAnchor"})
if err != nil {
return err
}
start.Attr = append(start.Attr, attr)
}
if m.HorzAnchorAttr != ST_HAnchorUnset {
attr, err := m.HorzAnchorAttr.MarshalXMLAttr(xml.Name{Local: "w:horzAnchor"})
if err != nil {
return err
}
start.Attr = append(start.Attr, attr)
}
if m.TblpXSpecAttr != sharedTypes.ST_XAlignUnset {
attr, err := m.TblpXSpecAttr.MarshalXMLAttr(xml.Name{Local: "w:tblpXSpec"})
if err != nil {
return err
}
start.Attr = append(start.Attr, attr)
}
if m.TblpXAttr != nil {
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "w:tblpX"},
Value: fmt.Sprintf("%v", *m.TblpXAttr)})
}
if m.TblpYSpecAttr != sharedTypes.ST_YAlignUnset {
attr, err := m.TblpYSpecAttr.MarshalXMLAttr(xml.Name{Local: "w:tblpYSpec"})
if err != nil {
return err
}
start.Attr = append(start.Attr, attr)
}
if m.TblpYAttr != nil {
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "w:tblpY"},
Value: fmt.Sprintf("%v", *m.TblpYAttr)})
}
e.EncodeToken(start)
e.EncodeToken(xml.EndElement{Name: start.Name})
return nil
}
func (m *CT_TblPPr) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
// initialize to default
m.VertAnchorAttr = ST_VAnchor(1)
m.HorzAnchorAttr = ST_HAnchor(1)
m.TblpXSpecAttr = sharedTypes.ST_XAlign(1)
m.TblpYSpecAttr = sharedTypes.ST_YAlign(1)
for _, attr := range start.Attr {
if attr.Name.Local == "leftFromText" {
parsed, err := ParseUnionST_TwipsMeasure(attr.Value)
if err != nil {
return err
}
m.LeftFromTextAttr = &parsed
}
if attr.Name.Local == "rightFromText" {
parsed, err := ParseUnionST_TwipsMeasure(attr.Value)
if err != nil {
return err
}
m.RightFromTextAttr = &parsed
}
if attr.Name.Local == "topFromText" {
parsed, err := ParseUnionST_TwipsMeasure(attr.Value)
if err != nil {
return err
}
m.TopFromTextAttr = &parsed
}
if attr.Name.Local == "bottomFromText" {
parsed, err := ParseUnionST_TwipsMeasure(attr.Value)
if err != nil {
return err
}
m.BottomFromTextAttr = &parsed
}
if attr.Name.Local == "vertAnchor" {
m.VertAnchorAttr.UnmarshalXMLAttr(attr)
}
if attr.Name.Local == "horzAnchor" {
m.HorzAnchorAttr.UnmarshalXMLAttr(attr)
}
if attr.Name.Local == "tblpXSpec" {
m.TblpXSpecAttr.UnmarshalXMLAttr(attr)
}
if attr.Name.Local == "tblpX" {
parsed, err := ParseUnionST_SignedTwipsMeasure(attr.Value)
if err != nil {
return err
}
m.TblpXAttr = &parsed
}
if attr.Name.Local == "tblpYSpec" {
m.TblpYSpecAttr.UnmarshalXMLAttr(attr)
}
if attr.Name.Local == "tblpY" {
parsed, err := ParseUnionST_SignedTwipsMeasure(attr.Value)
if err != nil {
return err
}
m.TblpYAttr = &parsed
}
}
// skip any extensions we may find, but don't support
for {
tok, err := d.Token()
if err != nil {
return fmt.Errorf("parsing CT_TblPPr: %s", err)
}
if el, ok := tok.(xml.EndElement); ok && el.Name == start.Name {
break
}
}
return nil
}
// Validate validates the CT_TblPPr and its children
func (m *CT_TblPPr) Validate() error {
return m.ValidateWithPath("CT_TblPPr")
}
// ValidateWithPath validates the CT_TblPPr and its children, prefixing error messages with path
func (m *CT_TblPPr) ValidateWithPath(path string) error {
if m.LeftFromTextAttr != nil {
if err := m.LeftFromTextAttr.ValidateWithPath(path + "/LeftFromTextAttr"); err != nil {
return err
}
}
if m.RightFromTextAttr != nil {
if err := m.RightFromTextAttr.ValidateWithPath(path + "/RightFromTextAttr"); err != nil {
return err
}
}
if m.TopFromTextAttr != nil {
if err := m.TopFromTextAttr.ValidateWithPath(path + "/TopFromTextAttr"); err != nil {
return err
}
}
if m.BottomFromTextAttr != nil {
if err := m.BottomFromTextAttr.ValidateWithPath(path + "/BottomFromTextAttr"); err != nil {
return err
}
}
if err := m.VertAnchorAttr.ValidateWithPath(path + "/VertAnchorAttr"); err != nil {
return err
}
if err := m.HorzAnchorAttr.ValidateWithPath(path + "/HorzAnchorAttr"); err != nil {
return err
}
if err := m.TblpXSpecAttr.ValidateWithPath(path + "/TblpXSpecAttr"); err != nil {
return err
}
if m.TblpXAttr != nil {
if err := m.TblpXAttr.ValidateWithPath(path + "/TblpXAttr"); err != nil {
return err
}
}
if err := m.TblpYSpecAttr.ValidateWithPath(path + "/TblpYSpecAttr"); err != nil {
return err
}
if m.TblpYAttr != nil {
if err := m.TblpYAttr.ValidateWithPath(path + "/TblpYAttr"); err != nil {
return err
}
}
return nil
}