2017-08-28 20:56:18 -05:00
|
|
|
// 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 presentationml
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"strconv"
|
2017-09-04 16:55:00 -05:00
|
|
|
|
|
|
|
"baliance.com/gooxml"
|
2017-08-28 20:56:18 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type CT_WebProperties struct {
|
|
|
|
// Show animation in HTML output
|
|
|
|
ShowAnimationAttr *bool
|
|
|
|
// Resize graphics in HTML output
|
|
|
|
ResizeGraphicsAttr *bool
|
|
|
|
// Allow PNG in HTML output
|
|
|
|
AllowPngAttr *bool
|
|
|
|
// Rely on VML for HTML output
|
|
|
|
RelyOnVmlAttr *bool
|
|
|
|
// Organize HTML output in folders
|
|
|
|
OrganizeInFoldersAttr *bool
|
|
|
|
// Use long file names in HTML output
|
|
|
|
UseLongFilenamesAttr *bool
|
|
|
|
// Image size for HTML output
|
|
|
|
ImgSzAttr ST_WebScreenSize
|
|
|
|
// Encoding for HTML output
|
|
|
|
EncodingAttr *string
|
|
|
|
// Slide Navigation Colors for HTML output
|
|
|
|
ClrAttr ST_WebColorType
|
|
|
|
ExtLst *CT_ExtensionList
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCT_WebProperties() *CT_WebProperties {
|
|
|
|
ret := &CT_WebProperties{}
|
2017-09-04 16:55:00 -05:00
|
|
|
ret.ShowAnimationAttr = gooxml.Bool(false)
|
|
|
|
ret.ResizeGraphicsAttr = gooxml.Bool(true)
|
|
|
|
ret.AllowPngAttr = gooxml.Bool(false)
|
|
|
|
ret.RelyOnVmlAttr = gooxml.Bool(false)
|
|
|
|
ret.OrganizeInFoldersAttr = gooxml.Bool(true)
|
|
|
|
ret.UseLongFilenamesAttr = gooxml.Bool(true)
|
|
|
|
ret.ImgSzAttr = ST_WebScreenSize800x600
|
|
|
|
ret.ClrAttr = ST_WebColorTypeWhiteTextOnBlack
|
2017-08-28 20:56:18 -05:00
|
|
|
return ret
|
|
|
|
}
|
2017-09-01 15:19:23 -05:00
|
|
|
|
2017-08-28 20:56:18 -05:00
|
|
|
func (m *CT_WebProperties) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
|
|
|
if m.ShowAnimationAttr != nil {
|
|
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "showAnimation"},
|
2017-09-03 21:00:35 -05:00
|
|
|
Value: fmt.Sprintf("%d", b2i(*m.ShowAnimationAttr))})
|
2017-08-28 20:56:18 -05:00
|
|
|
}
|
|
|
|
if m.ResizeGraphicsAttr != nil {
|
|
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "resizeGraphics"},
|
2017-09-03 21:00:35 -05:00
|
|
|
Value: fmt.Sprintf("%d", b2i(*m.ResizeGraphicsAttr))})
|
2017-08-28 20:56:18 -05:00
|
|
|
}
|
|
|
|
if m.AllowPngAttr != nil {
|
|
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "allowPng"},
|
2017-09-03 21:00:35 -05:00
|
|
|
Value: fmt.Sprintf("%d", b2i(*m.AllowPngAttr))})
|
2017-08-28 20:56:18 -05:00
|
|
|
}
|
|
|
|
if m.RelyOnVmlAttr != nil {
|
|
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "relyOnVml"},
|
2017-09-03 21:00:35 -05:00
|
|
|
Value: fmt.Sprintf("%d", b2i(*m.RelyOnVmlAttr))})
|
2017-08-28 20:56:18 -05:00
|
|
|
}
|
|
|
|
if m.OrganizeInFoldersAttr != nil {
|
|
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "organizeInFolders"},
|
2017-09-03 21:00:35 -05:00
|
|
|
Value: fmt.Sprintf("%d", b2i(*m.OrganizeInFoldersAttr))})
|
2017-08-28 20:56:18 -05:00
|
|
|
}
|
|
|
|
if m.UseLongFilenamesAttr != nil {
|
|
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "useLongFilenames"},
|
2017-09-03 21:00:35 -05:00
|
|
|
Value: fmt.Sprintf("%d", b2i(*m.UseLongFilenamesAttr))})
|
2017-08-28 20:56:18 -05:00
|
|
|
}
|
|
|
|
if m.ImgSzAttr != ST_WebScreenSizeUnset {
|
|
|
|
attr, err := m.ImgSzAttr.MarshalXMLAttr(xml.Name{Local: "imgSz"})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
start.Attr = append(start.Attr, attr)
|
|
|
|
}
|
|
|
|
if m.EncodingAttr != nil {
|
|
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "encoding"},
|
|
|
|
Value: fmt.Sprintf("%v", *m.EncodingAttr)})
|
|
|
|
}
|
|
|
|
if m.ClrAttr != ST_WebColorTypeUnset {
|
|
|
|
attr, err := m.ClrAttr.MarshalXMLAttr(xml.Name{Local: "clr"})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
start.Attr = append(start.Attr, attr)
|
|
|
|
}
|
|
|
|
e.EncodeToken(start)
|
|
|
|
if m.ExtLst != nil {
|
|
|
|
seextLst := xml.StartElement{Name: xml.Name{Local: "p:extLst"}}
|
|
|
|
e.EncodeElement(m.ExtLst, seextLst)
|
|
|
|
}
|
|
|
|
e.EncodeToken(xml.EndElement{Name: start.Name})
|
|
|
|
return nil
|
|
|
|
}
|
2017-09-01 15:19:23 -05:00
|
|
|
|
2017-08-28 20:56:18 -05:00
|
|
|
func (m *CT_WebProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
|
|
|
// initialize to default
|
2017-09-04 16:55:00 -05:00
|
|
|
m.ShowAnimationAttr = gooxml.Bool(false)
|
|
|
|
m.ResizeGraphicsAttr = gooxml.Bool(true)
|
|
|
|
m.AllowPngAttr = gooxml.Bool(false)
|
|
|
|
m.RelyOnVmlAttr = gooxml.Bool(false)
|
|
|
|
m.OrganizeInFoldersAttr = gooxml.Bool(true)
|
|
|
|
m.UseLongFilenamesAttr = gooxml.Bool(true)
|
|
|
|
m.ImgSzAttr = ST_WebScreenSize800x600
|
|
|
|
m.ClrAttr = ST_WebColorTypeWhiteTextOnBlack
|
2017-08-28 20:56:18 -05:00
|
|
|
for _, attr := range start.Attr {
|
|
|
|
if attr.Name.Local == "showAnimation" {
|
|
|
|
parsed, err := strconv.ParseBool(attr.Value)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
m.ShowAnimationAttr = &parsed
|
|
|
|
}
|
|
|
|
if attr.Name.Local == "resizeGraphics" {
|
|
|
|
parsed, err := strconv.ParseBool(attr.Value)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
m.ResizeGraphicsAttr = &parsed
|
|
|
|
}
|
|
|
|
if attr.Name.Local == "allowPng" {
|
|
|
|
parsed, err := strconv.ParseBool(attr.Value)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
m.AllowPngAttr = &parsed
|
|
|
|
}
|
|
|
|
if attr.Name.Local == "relyOnVml" {
|
|
|
|
parsed, err := strconv.ParseBool(attr.Value)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
m.RelyOnVmlAttr = &parsed
|
|
|
|
}
|
|
|
|
if attr.Name.Local == "organizeInFolders" {
|
|
|
|
parsed, err := strconv.ParseBool(attr.Value)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
m.OrganizeInFoldersAttr = &parsed
|
|
|
|
}
|
|
|
|
if attr.Name.Local == "useLongFilenames" {
|
|
|
|
parsed, err := strconv.ParseBool(attr.Value)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
m.UseLongFilenamesAttr = &parsed
|
|
|
|
}
|
|
|
|
if attr.Name.Local == "imgSz" {
|
|
|
|
m.ImgSzAttr.UnmarshalXMLAttr(attr)
|
|
|
|
}
|
|
|
|
if attr.Name.Local == "encoding" {
|
|
|
|
parsed, err := attr.Value, error(nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
m.EncodingAttr = &parsed
|
|
|
|
}
|
|
|
|
if attr.Name.Local == "clr" {
|
|
|
|
m.ClrAttr.UnmarshalXMLAttr(attr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lCT_WebProperties:
|
|
|
|
for {
|
|
|
|
tok, err := d.Token()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
switch el := tok.(type) {
|
|
|
|
case xml.StartElement:
|
|
|
|
switch el.Name.Local {
|
|
|
|
case "extLst":
|
|
|
|
m.ExtLst = NewCT_ExtensionList()
|
|
|
|
if err := d.DecodeElement(m.ExtLst, &el); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
default:
|
2017-09-01 16:52:12 -05:00
|
|
|
log.Printf("skipping unsupported element on CT_WebProperties %v", el.Name)
|
2017-08-28 20:56:18 -05:00
|
|
|
if err := d.Skip(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case xml.EndElement:
|
|
|
|
break lCT_WebProperties
|
|
|
|
case xml.CharData:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2017-09-01 15:19:23 -05:00
|
|
|
|
|
|
|
// Validate validates the CT_WebProperties and its children
|
2017-08-28 20:56:18 -05:00
|
|
|
func (m *CT_WebProperties) Validate() error {
|
|
|
|
return m.ValidateWithPath("CT_WebProperties")
|
|
|
|
}
|
2017-09-01 15:19:23 -05:00
|
|
|
|
|
|
|
// ValidateWithPath validates the CT_WebProperties and its children, prefixing error messages with path
|
2017-08-28 20:56:18 -05:00
|
|
|
func (m *CT_WebProperties) ValidateWithPath(path string) error {
|
|
|
|
if err := m.ImgSzAttr.ValidateWithPath(path + "/ImgSzAttr"); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := m.ClrAttr.ValidateWithPath(path + "/ClrAttr"); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if m.ExtLst != nil {
|
|
|
|
if err := m.ExtLst.ValidateWithPath(path + "/ExtLst"); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|