mirror of
https://github.com/unidoc/unioffice.git
synced 2025-04-29 13:49:10 +08:00

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.
221 lines
6.2 KiB
Go
221 lines
6.2 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 presentationml
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"fmt"
|
|
"log"
|
|
"strconv"
|
|
|
|
"baliance.com/gooxml"
|
|
)
|
|
|
|
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{}
|
|
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
|
|
return ret
|
|
}
|
|
|
|
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"},
|
|
Value: fmt.Sprintf("%d", b2i(*m.ShowAnimationAttr))})
|
|
}
|
|
if m.ResizeGraphicsAttr != nil {
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "resizeGraphics"},
|
|
Value: fmt.Sprintf("%d", b2i(*m.ResizeGraphicsAttr))})
|
|
}
|
|
if m.AllowPngAttr != nil {
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "allowPng"},
|
|
Value: fmt.Sprintf("%d", b2i(*m.AllowPngAttr))})
|
|
}
|
|
if m.RelyOnVmlAttr != nil {
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "relyOnVml"},
|
|
Value: fmt.Sprintf("%d", b2i(*m.RelyOnVmlAttr))})
|
|
}
|
|
if m.OrganizeInFoldersAttr != nil {
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "organizeInFolders"},
|
|
Value: fmt.Sprintf("%d", b2i(*m.OrganizeInFoldersAttr))})
|
|
}
|
|
if m.UseLongFilenamesAttr != nil {
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "useLongFilenames"},
|
|
Value: fmt.Sprintf("%d", b2i(*m.UseLongFilenamesAttr))})
|
|
}
|
|
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
|
|
}
|
|
|
|
func (m *CT_WebProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
|
// initialize to default
|
|
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
|
|
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:
|
|
log.Printf("skipping unsupported element on CT_WebProperties %v", el.Name)
|
|
if err := d.Skip(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
case xml.EndElement:
|
|
break lCT_WebProperties
|
|
case xml.CharData:
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Validate validates the CT_WebProperties and its children
|
|
func (m *CT_WebProperties) Validate() error {
|
|
return m.ValidateWithPath("CT_WebProperties")
|
|
}
|
|
|
|
// ValidateWithPath validates the CT_WebProperties and its children, prefixing error messages with path
|
|
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
|
|
}
|