unioffice/common/common.go

416 lines
48 KiB
Go
Raw Normal View History

2020-08-23 14:15:53 +00:00
//
// Copyright 2020 FoxyUtils ehf. All rights reserved.
//
// This is a commercial product and requires a license to operate.
// A trial license can be obtained at https://unidoc.io
//
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
//
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
// Package common contains wrapper types and utilities common to all of the
// OOXML document formats.
//
// Package common contains common properties used by the subpackages.
2023-03-01 18:42:44 +00:00
package common ;import (_e "archive/zip";_f "bytes";_ce "encoding/xml";_ccg "errors";_bf "fmt";_ac "github.com/unidoc/unioffice";_fce "github.com/unidoc/unioffice/common/logger";_fcb "github.com/unidoc/unioffice/common/tempstorage";_be "github.com/unidoc/unioffice/common/tempstorage/diskstore";_fc "github.com/unidoc/unioffice/measurement";_ca "github.com/unidoc/unioffice/schema/soo/dml";_cd "github.com/unidoc/unioffice/schema/soo/ofc/custom_properties";_ad "github.com/unidoc/unioffice/schema/soo/ofc/docPropsVTypes";_dc "github.com/unidoc/unioffice/schema/soo/ofc/extended_properties";_daa "github.com/unidoc/unioffice/schema/soo/pkg/content_types";_dgd "github.com/unidoc/unioffice/schema/soo/pkg/metadata/core_properties";_eb "github.com/unidoc/unioffice/schema/soo/pkg/relationships";_dge "github.com/unidoc/unioffice/zippkg";_g "image";_ "image/gif";_ "image/jpeg";_ "image/png";_cg "os";_da "reflect";_b "regexp";_fb "strconv";_ed "strings";_dg "time";);func (_gfb CustomProperties )SetPropertyAsVstream (name string ,vstream *_ad .Vstream ){_ecfb :=_gfb .getNewProperty (name );_ecfb .Vstream =vstream ;_gfb .setOrReplaceProperty (_ecfb );};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// EnsureDefault esnures that an extension and default content type exist,
// adding it if necessary.
func (_bb ContentTypes )EnsureDefault (ext ,contentType string ){ext =_ed .ToLower (ext );for _ ,_abc :=range _bb ._dgb .Default {if _abc .ExtensionAttr ==ext {_abc .ContentTypeAttr =contentType ;return ;};};_dgde :=&_daa .Default {};_dgde .ContentTypeAttr =contentType ;_dgde .ExtensionAttr =ext ;_bb ._dgb .Default =append (_bb ._dgb .Default ,_dgde );};
2020-10-12 13:59:12 +00:00
2023-03-01 18:42:44 +00:00
// NewTableWithXfrm makes a new table with a pointer to its parent Xfrm for changing its offset and size.
func NewTableWithXfrm (xfrm *_ca .CT_Transform2D )*Table {_fefb :=_ca .NewTbl ();_fefb .TblPr =_ca .NewCT_TableProperties ();return &Table {_bfce :_fefb ,_cda :xfrm };};func (_ceb CustomProperties )SetPropertyAsOstream (name string ,ostream string ){_daag :=_ceb .getNewProperty (name );_daag .Ostream =&ostream ;_ceb .setOrReplaceProperty (_daag );};
2020-10-12 13:59:12 +00:00
2023-03-01 18:42:44 +00:00
// RelativeHeight returns the relative height of an image given a fixed width.
// This is used when setting image to a fixed width to calculate the height
// required to keep the same image aspect ratio.
func (_gef ImageRef )RelativeHeight (w _fc .Distance )_fc .Distance {_acd :=float64 (_gef .Size ().Y )/float64 (_gef .Size ().X );return w *_fc .Distance (_acd );};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// SetCreated sets the time that the document was created.
func (_dagg CoreProperties )SetCreated (t _dg .Time ){_dagg ._bcb .Created =_fceb (t ,"\u0064c\u0074e\u0072\u006d\u0073\u003a\u0063\u0072\u0065\u0061\u0074\u0065\u0064");};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// NewAppProperties constructs a new AppProperties.
func NewAppProperties ()AppProperties {_fff :=AppProperties {_cb :_dc .NewProperties ()};_fff .SetCompany ("\u0046\u006f\u0078\u0079\u0055\u0074\u0069\u006c\u0073\u0020\u0065\u0068\u0066");_fff .SetApplication ("g\u0069\u0074\u0068\u0075\u0062\u002ec\u006f\u006d\u002f\u0075\u006e\u0069\u0064\u006f\u0063/\u0075\u006e\u0069o\u0066f\u0069\u0063\u0065");_fff .SetDocSecurity (0);_fff .SetLinksUpToDate (false );var _de ,_eeg ,_bdc int64 ;_bf .Sscanf (Version ,"\u0025\u0064\u002e\u0025\u0064\u002e\u0025\u0064",&_de ,&_eeg ,&_bdc );_ffb :=float64 (_de )+float64 (_eeg )/10000.0;_fff .SetApplicationVersion (_bf .Sprintf ("\u0025\u0030\u0037\u002e\u0034\u0066",_ffb ));return _fff ;};
2021-07-30 17:03:26 +00:00
2023-03-01 18:42:44 +00:00
// RelativeWidth returns the relative width of an image given a fixed height.
// This is used when setting image to a fixed height to calculate the width
// required to keep the same image aspect ratio.
func (_ffdd ImageRef )RelativeWidth (h _fc .Distance )_fc .Distance {_ebag :=float64 (_ffdd .Size ().X )/float64 (_ffdd .Size ().Y );return h *_fc .Distance (_ebag );};const _bed ="2\u00300\u0036\u002d\u0030\u0031\u002d\u0030\u0032\u00541\u0035\u003a\u0030\u0034:0\u0035\u005a";
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// NewTableStyles constructs a new TableStyles.
func NewTableStyles ()TableStyles {return TableStyles {_fbgg :_ca .NewTblStyleLst ()}};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// Image is a container for image information. It's used as we need format and
// and size information to use images.
// It contains either the filesystem path to the image, or the image itself.
type Image struct{Size _g .Point ;Format string ;Path string ;Data *[]byte ;};
2021-09-22 16:41:01 +00:00
2023-03-01 18:42:44 +00:00
// SetLastModifiedBy records the last person to modify the document.
func (_ef CoreProperties )SetLastModifiedBy (s string ){_ef ._bcb .LastModifiedBy =&s };
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// ContentTypes is the top level "[Content_Types].xml" in a zip package.
type ContentTypes struct{_dgb *_daa .Types };
2020-10-12 13:59:12 +00:00
2023-03-01 18:42:44 +00:00
// Description returns the description of the document
func (_gcg CoreProperties )Description ()string {if _gcg ._bcb .Description !=nil {return string (_gcg ._bcb .Description .Data );};return "";};
2022-02-05 13:05:36 +00:00
2023-03-01 18:42:44 +00:00
// Data returns the data of an image file, if any.
func (_edg ImageRef )Data ()*[]byte {return _edg ._gge .Data };
2022-02-05 13:05:36 +00:00
2023-03-01 18:42:44 +00:00
// FindRIDForN returns the relationship ID for the i'th relationship of type t.
func (_dec Relationships )FindRIDForN (i int ,t string )string {for _ ,_ageg :=range _dec ._fcdb .CT_Relationships .Relationship {if _ageg .TypeAttr ==t {if i ==0{return _ageg .IdAttr ;};i --;};};return "";};
2020-10-12 13:59:12 +00:00
2023-03-01 18:42:44 +00:00
// X returns the inner wrapped XML type of CustomProperty.
func (_eed CustomProperty )X ()*_cd .CT_Property {return _eed ._dfa };
2020-10-12 13:59:12 +00:00
2023-03-01 18:42:44 +00:00
// AddImageToZip adds an image (either from bytes or from disk) and adds it to the zip file.
func AddImageToZip (z *_e .Writer ,img ImageRef ,imageNum int ,dt _ac .DocType )error {_dbd :=_ac .AbsoluteImageFilename (dt ,imageNum ,_ed .ToLower (img .Format ()));if img .Data ()!=nil &&len (*img .Data ())> 0{if _bcad :=_dge .AddFileFromBytes (z ,_dbd ,*img .Data ());_bcad !=nil {return _bcad ;};}else if img .Path ()!=""{if _cff :=_dge .AddFileFromDisk (z ,_dbd ,img .Path ());_cff !=nil {return _cff ;};}else {return _bf .Errorf ("\u0075\u006es\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0069\u006d\u0061\u0067\u0065\u0020\u0073\u006f\u0075\u0072\u0063\u0065\u003a %\u002b\u0076",img );};return nil ;};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// Pages returns total number of pages which are saved by the text editor which produced the document.
// For unioffice created documents, it is 0.
func (_cgg AppProperties )Pages ()int32 {if _cgg ._cb .Pages !=nil {return *_cgg ._cb .Pages ;};return 0;};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// GetPropertyByName returns a custom property selected by it's name.
func (_abg CustomProperties )GetPropertyByName (name string )CustomProperty {_agb :=_abg ._cad .Property ;for _ ,_edf :=range _agb {if *_edf .NameAttr ==name {return CustomProperty {_dfa :_edf };};};return CustomProperty {};};func (_bcd CustomProperties )SetPropertyAsDate (name string ,date _dg .Time ){date =date .UTC ();_ebed ,_bab ,_fffd :=date .Date ();_daee ,_afde ,_ffg :=date .Clock ();_cce :=_dg .Date (_ebed ,_bab ,_fffd ,_daee ,_afde ,_ffg ,0,_dg .UTC );_gcf :=_bcd .getNewProperty (name );_gcf .Filetime =&_cce ;_bcd .setOrReplaceProperty (_gcf );};const _gaag =6;
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// ExtraFile is an unsupported file type extracted from, or to be written to a
// zip package
type ExtraFile struct{ZipPath string ;DiskPath string ;};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// SetOffsetX sets horizontal offset of a table in distance units (see measurement package).
func (_aede Table )SetOffsetX (offX float64 ){if _aede ._cda .Off ==nil {_aede ._cda .Off =_ca .NewCT_Point2D ();_bfb :=int64 (0);_aede ._cda .Off .YAttr =_ca .ST_Coordinate {ST_CoordinateUnqualified :&_bfb };};_bacb :=_fc .ToEMU (offX );_aede ._cda .Off .XAttr =_ca .ST_Coordinate {ST_CoordinateUnqualified :&_bacb };};func (_bfad CustomProperties )SetPropertyAsI1 (name string ,i1 int8 ){_feg :=_bfad .getNewProperty (name );_feg .I1 =&i1 ;_bfad .setOrReplaceProperty (_feg );};
2021-03-16 20:51:18 +00:00
2023-03-01 18:42:44 +00:00
// SetTarget set the target (path) of a relationship.
func (_bfdd Relationship )SetTarget (s string ){_bfdd ._cbg .TargetAttr =s };func (_fcba CustomProperties )SetPropertyAsLpstr (name string ,lpstr string ){_dad :=_fcba .getNewProperty (name );_dad .Lpstr =&lpstr ;_fcba .setOrReplaceProperty (_dad );};
2021-08-23 20:44:48 +00:00
2023-03-01 18:42:44 +00:00
// ImageFromBytes returns an Image struct for an in-memory image. You can also
2022-12-06 11:56:49 +00:00
// construct an Image directly if the file and size are known.
2023-03-01 18:42:44 +00:00
func ImageFromBytes (data []byte )(Image ,error ){_fba :=Image {};_gbd ,_bceg ,_efbe :=_g .Decode (_f .NewReader (data ));if _efbe !=nil {return _fba ,_bf .Errorf ("\u0075n\u0061\u0062\u006c\u0065 \u0074\u006f\u0020\u0070\u0061r\u0073e\u0020i\u006d\u0061\u0067\u0065\u003a\u0020\u0025s",_efbe );};_fba .Data =&data ;_fba .Format =_bceg ;_fba .Size =_gbd .Bounds ().Size ();return _fba ,nil ;};
2020-11-09 01:00:18 +00:00
2023-03-01 18:42:44 +00:00
// Size returns the size of an image
func (_cebf ImageRef )Size ()_g .Point {return _cebf ._gge .Size };const _gbc =12;func (_gfa CustomProperties )SetPropertyAsR4 (name string ,r4 float32 ){_gee :=_gfa .getNewProperty (name );_gee .R4 =&r4 ;_gfa .setOrReplaceProperty (_gee );};func _fceb (_eec _dg .Time ,_gaa string )*_ac .XSDAny {_baf :=&_ac .XSDAny {XMLName :_ce .Name {Local :_gaa }};_baf .Attrs =append (_baf .Attrs ,_ce .Attr {Name :_ce .Name {Local :"\u0078\u0073\u0069\u003a\u0074\u0079\u0070\u0065"},Value :"\u0064\u0063\u0074\u0065\u0072\u006d\u0073\u003a\u00573\u0043\u0044\u0054\u0046"});_baf .Attrs =append (_baf .Attrs ,_ce .Attr {Name :_ce .Name {Local :"\u0078m\u006c\u006e\u0073\u003a\u0078\u0073i"},Value :"\u0068\u0074\u0074\u0070\u003a/\u002f\u0077\u0077\u0077\u002e\u0077\u0033\u002e\u006f\u0072\u0067\u002f\u00320\u0030\u0031\u002f\u0058\u004d\u004c\u0053\u0063\u0068\u0065\u006d\u0061\u002d\u0069\u006e\u0073\u0074\u0061\u006e\u0063\u0065"});_baf .Attrs =append (_baf .Attrs ,_ce .Attr {Name :_ce .Name {Local :"\u0078\u006d\u006c\u006e\u0073\u003a\u0064\u0063\u0074\u0065\u0072\u006d\u0073"},Value :"\u0068t\u0074\u0070\u003a\u002f/\u0070\u0075\u0072\u006c\u002eo\u0072g\u002fd\u0063\u002f\u0074\u0065\u0072\u006d\u0073/"});_baf .Data =[]byte (_eec .Format (_bed ));return _baf ;};func (_aba CustomProperties )getNewProperty (_bbd string )*_cd .CT_Property {_aaba :=_aba ._cad .Property ;_db :=int32 (1);for _ ,_eae :=range _aaba {if _eae .PidAttr > _db {_db =_eae .PidAttr ;};};_gd :=_cd .NewCT_Property ();_gd .NameAttr =&_bbd ;_gd .PidAttr =_db +1;_gd .FmtidAttr ="\u007b\u0044\u0035\u0043\u0044\u0044\u0035\u0030\u0035\u002d\u0032\u0045\u0039\u0043\u002d\u0031\u0030\u0031\u0042\u002d\u0039\u0033\u0039\u0037-\u0030\u0038\u0030\u0030\u0032B\u0032\u0043F\u0039\u0041\u0045\u007d";return _gd ;};
2020-11-09 01:00:18 +00:00
2023-03-01 18:42:44 +00:00
// NewRelationship constructs a new relationship.
func NewRelationship ()Relationship {return Relationship {_cbg :_eb .NewRelationship ()}};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// NewContentTypes returns a wrapper around a newly constructed content-types.
func NewContentTypes ()ContentTypes {_abf :=ContentTypes {_dgb :_daa .NewTypes ()};_abf .AddDefault ("\u0078\u006d\u006c","\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u0078\u006d\u006c");_abf .AddDefault ("\u0072\u0065\u006c\u0073","\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006fn\u002f\u0076\u006ed\u002e\u006f\u0070\u0065\u006e\u0078\u006d\u006c\u0066\u006fr\u006d\u0061\u0074\u0073\u002dpa\u0063\u006b\u0061\u0067\u0065\u002e\u0072\u0065\u006c\u0061\u0074\u0069\u006f\u006e\u0073\u0068\u0069\u0070\u0073\u002b\u0078\u006d\u006c");_abf .AddDefault ("\u0070\u006e\u0067","\u0069m\u0061\u0067\u0065\u002f\u0070\u006eg");_abf .AddDefault ("\u006a\u0070\u0065\u0067","\u0069\u006d\u0061\u0067\u0065\u002f\u006a\u0070\u0065\u0067");_abf .AddDefault ("\u006a\u0070\u0067","\u0069m\u0061\u0067\u0065\u002f\u006a\u0070g");_abf .AddDefault ("\u0077\u006d\u0066","i\u006d\u0061\u0067\u0065\u002f\u0078\u002d\u0077\u006d\u0066");_abf .AddOverride ("\u002fd\u006fc\u0050\u0072\u006f\u0070\u0073/\u0063\u006fr\u0065\u002e\u0078\u006d\u006c","\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u0076\u006e\u0064\u002e\u006f\u0070\u0065\u006ex\u006d\u006c\u0066\u006f\u0072\u006d\u0061\u0074\u0073-\u0070\u0061\u0063\u006b\u0061\u0067\u0065\u002e\u0063\u006f\u0072\u0065\u002dp\u0072\u006f\u0070\u0065\u0072\u0074i\u0065\u0073\u002bx\u006d\u006c");_abf .AddOverride ("\u002f\u0064\u006f\u0063\u0050\u0072\u006f\u0070\u0073\u002f\u0061\u0070p\u002e\u0078\u006d\u006c","a\u0070\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u0076\u006e\u0064\u002e\u006f\u0070\u0065\u006e\u0078\u006d\u006c\u0066o\u0072\u006d\u0061\u0074\u0073\u002d\u006f\u0066\u0066\u0069\u0063\u0065\u0064\u006f\u0063\u0075m\u0065\u006e\u0074\u002e\u0065\u0078\u0074\u0065\u006e\u0064\u0065\u0064\u002dp\u0072\u006f\u0070\u0065\u0072\u0074\u0069\u0065\u0073\u002b\u0078m\u006c");return _abf ;};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// SetDescription records the description of the document.
func (_efg CoreProperties )SetDescription (s string ){if _efg ._bcb .Description ==nil {_efg ._bcb .Description =&_ac .XSDAny {XMLName :_ce .Name {Local :"\u0064\u0063\u003a\u0064\u0065\u0073\u0063\u0072\u0069p\u0074\u0069\u006f\u006e"}};};_efg ._bcb .Description .Data =[]byte (s );};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// GetImageBytesByTarget returns Image object with Data bytes read from its target.
func (_cadd *DocBase )GetImageBytesByTarget (target string )(Image ,error ){if target !=""{target ="\u0077\u006f\u0072d\u002f"+target ;for _ ,_feb :=range _cadd .Images {if _feb .Target ()==target {return ImageFromStorage (_feb .Path ());};};};return Image {},_ddb ;};
2021-09-22 16:41:01 +00:00
2023-03-01 18:42:44 +00:00
// WriteExtraFiles writes the extra files to the zip package.
func (_cgcg *DocBase )WriteExtraFiles (z *_e .Writer )error {for _ ,_fcde :=range _cgcg .ExtraFiles {if _fge :=_dge .AddFileFromDisk (z ,_fcde .ZipPath ,_fcde .DiskPath );_fge !=nil {return _fge ;};};return nil ;};const _bacd =2022;func (_ebe CustomProperties )setProperty (_aaf *_cd .CT_Property ){_ebe .setPropertyHelper (_aaf ,false )};func (_cfac CustomProperties )SetPropertyAsArray (name string ,array *_ad .Array ){_ccbc :=_cfac .getNewProperty (name );_ccbc .Array =array ;_cfac .setOrReplaceProperty (_ccbc );};
2021-05-31 16:22:30 +00:00
2023-03-01 18:42:44 +00:00
// AddRow adds a row to a table.
func (_gfga Table )AddRow ()*TableRow {_fbff :=_ca .NewCT_TableRow ();for _eac :=0;_eac < len (_gfga ._bfce .TblGrid .GridCol );_eac ++{_fbff .Tc =append (_fbff .Tc ,_ca .NewCT_TableCell ());};_gfga ._bfce .Tr =append (_gfga ._bfce .Tr ,_fbff );return &TableRow {_cba :_fbff };};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// SetDocSecurity sets the document security flag.
func (_cdg AppProperties )SetDocSecurity (v int32 ){_cdg ._cb .DocSecurity =_ac .Int32 (v )};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// PropertiesList returns the list of all custom properties of the document.
func (_ddc CustomProperties )PropertiesList ()[]*_cd .CT_Property {return _ddc ._cad .Property };
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// TableCol represents a column in a table.
type TableCol struct{_cbdg *_ca .CT_TableCol };func (_gfg CustomProperties )SetPropertyAsI2 (name string ,i2 int16 ){_fbe :=_gfg .getNewProperty (name );_fbe .I2 =&i2 ;_gfg .setOrReplaceProperty (_fbe );};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// Relationships returns a slice of all of the relationships.
2023-03-01 18:42:44 +00:00
func (_bac Relationships )Relationships ()[]Relationship {_cadg :=[]Relationship {};for _ ,_cfdg :=range _bac ._fcdb .Relationship {_cadg =append (_cadg ,Relationship {_cbg :_cfdg });};return _cadg ;};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// GetTargetByRelIdAndType returns a target path with the associated relation ID.
func (_daeg Relationships )GetTargetByRelIdAndType (idAttr string ,typeAttr string )string {for _ ,_ead :=range _daeg ._fcdb .Relationship {if _ead .IdAttr ==idAttr &&_ead .TypeAttr ==typeAttr {return _ead .TargetAttr ;};};return "";};const _abca =15;
2020-10-12 13:59:12 +00:00
2023-03-01 18:42:44 +00:00
// RemoveOverrideByIndex removes an override given a path and override index.
func (_df ContentTypes )RemoveOverrideByIndex (path string ,indexToFind int )error {_gf :=path [0:len (path )-5];if !_ed .HasPrefix (_gf ,"\u002f"){_gf ="\u002f"+_gf ;};_gbf ,_cfa :=_b .Compile (_gf +"\u0028\u005b\u0030-\u0039\u005d\u002b\u0029\u002e\u0078\u006d\u006c");if _cfa !=nil {return _cfa ;};_cfd :=0;_fdaf :=-1;for _bad ,_gac :=range _df ._dgb .Override {if _cgd :=_gbf .FindStringSubmatch (_gac .PartNameAttr );len (_cgd )> 1{if _cfd ==indexToFind {_fdaf =_bad ;}else if _cfd > indexToFind {_dca ,_ :=_fb .Atoi (_cgd [1]);_dca --;_gac .PartNameAttr =_bf .Sprintf ("\u0025\u0073\u0025\u0064\u002e\u0078\u006d\u006c",_gf ,_dca );};_cfd ++;};};if _fdaf > -1{copy (_df ._dgb .Override [_fdaf :],_df ._dgb .Override [_fdaf +1:]);_df ._dgb .Override =_df ._dgb .Override [0:len (_df ._dgb .Override )-1];};return nil ;};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// SetApplicationVersion sets the version of the application that created the
// document. Per MS, the verison string mut be in the form 'XX.YYYY'.
func (_ded AppProperties )SetApplicationVersion (s string ){_ded ._cb .AppVersion =&s };func (_cgc CustomProperties )SetPropertyAsClsid (name string ,clsid string ){_ebcc :=_cgc .getNewProperty (name );_ebcc .Clsid =&clsid ;_cgc .setOrReplaceProperty (_ebcc );};func (_abce CustomProperties )setPropertyHelper (_efa *_cd .CT_Property ,_ccb bool ){_cafc :=_abce .GetPropertyByName (*_efa .NameAttr );if (_cafc ==CustomProperty {}){_abce ._cad .Property =append (_abce ._cad .Property ,_efa );}else if _ccb {_efa .FmtidAttr =_cafc ._dfa .FmtidAttr ;if _cafc ._dfa .PidAttr ==0{_efa .PidAttr =_cafc ._dfa .PidAttr ;};_efa .LinkTargetAttr =_cafc ._dfa .LinkTargetAttr ;*_cafc ._dfa =*_efa ;};};
2022-02-05 13:05:36 +00:00
2023-03-01 18:42:44 +00:00
// SetID set the ID of a relationship.
func (_dgg Relationship )SetID (ID string ){_dgg ._cbg .IdAttr =ID ;};func _cdb (_acfa *_ac .XSDAny )_dg .Time {if _acfa ==nil {return _dg .Time {};};_ffc ,_adab :=_dg .Parse (_bed ,string (_acfa .Data ));if _adab !=nil {_fce .Log .Debug ("\u0065\u0072\u0072\u006f\u0072\u0020\u0070\u0061\u0072\u0073i\u006e\u0067\u0020\u0074\u0069\u006d\u0065 \u0066\u0072\u006f\u006d\u0020\u0025\u0073\u003a\u0020\u0025\u0073",string (_acfa .Data ),_adab );};return _ffc ;};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// AddHyperlink adds an external hyperlink relationship.
func (_ege Relationships )AddHyperlink (target string )Hyperlink {_aad :=_ege .AddRelationship (target ,_ac .HyperLinkType );_aad ._cbg .TargetModeAttr =_eb .ST_TargetModeExternal ;return Hyperlink (_aad );};
2021-06-16 07:10:52 +00:00
2023-03-01 18:42:44 +00:00
// ImageFromStorage reads an image using the currently set
// temporary storage mechanism (see tempstorage). You can also
// construct an Image directly if the file and size are known.
func ImageFromStorage (path string )(Image ,error ){_bgca :=Image {};_fga ,_dead :=_fcb .Open (path );if _dead !=nil {return _bgca ,_bf .Errorf ("\u0065\u0072\u0072or\u0020\u0072\u0065\u0061\u0064\u0069\u006e\u0067\u0020\u0069\u006d\u0061\u0067\u0065\u003a\u0020\u0025\u0073",_dead );};defer _fga .Close ();_egfa ,_bcg ,_dead :=_g .Decode (_fga );if _dead !=nil {return _bgca ,_bf .Errorf ("\u0075n\u0061\u0062\u006c\u0065 \u0074\u006f\u0020\u0070\u0061r\u0073e\u0020i\u006d\u0061\u0067\u0065\u003a\u0020\u0025s",_dead );};_bgca .Path =path ;_bgca .Format =_bcg ;_bgca .Size =_egfa .Bounds ().Size ();return _bgca ,nil ;};func (_bgfb Relationship )String ()string {return _bf .Sprintf ("\u007b\u0049\u0044\u003a \u0025\u0073\u0020\u0054\u0061\u0072\u0067\u0065\u0074\u003a \u0025s\u0020\u0054\u0079\u0070\u0065\u003a\u0020%\u0073\u007d",_bgfb .ID (),_bgfb .Target (),_bgfb .Type ());};
2021-06-16 07:10:52 +00:00
2023-03-01 18:42:44 +00:00
// ImageRef is a reference to an image within a document.
type ImageRef struct{_ffd *DocBase ;_dcb Relationships ;_gge Image ;_bgbc string ;_bbda string ;};
2021-06-16 07:10:52 +00:00
2023-03-01 18:42:44 +00:00
// Table represents a table in the document.
type Table struct{_bfce *_ca .Tbl ;_cda *_ca .CT_Transform2D ;};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// X returns the inner wrapped XML type.
func (_cdc Theme )X ()*_ca .Theme {return _cdc ._cfdge };
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// AddExtraFileFromZip is used when reading an unsupported file from an OOXML
// file. This ensures that unsupported file content will at least round-trip
// correctly.
func (_gdc *DocBase )AddExtraFileFromZip (f *_e .File )error {_ffgc ,_fbg :=_dge .ExtractToDiskTmp (f ,_gdc .TmpPath );if _fbg !=nil {return _bf .Errorf ("\u0065\u0072r\u006f\u0072\u0020\u0065x\u0074\u0072a\u0063\u0074\u0069\u006e\u0067\u0020\u0075\u006es\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0066\u0069\u006ce\u003a\u0020\u0025\u0073",_fbg );};_gdc .ExtraFiles =append (_gdc .ExtraFiles ,ExtraFile {ZipPath :f .Name ,DiskPath :_ffgc });return nil ;};func (_ggd CustomProperties )SetPropertyAsI4 (name string ,i4 int32 ){_bca :=_ggd .getNewProperty (name );_bca .I4 =&i4 ;_ggd .setOrReplaceProperty (_bca );};
2022-04-09 14:27:46 +00:00
2023-03-01 18:42:44 +00:00
// X returns the inner wrapped XML type.
func (_abfe CoreProperties )X ()*_dgd .CoreProperties {return _abfe ._bcb };
2022-04-09 14:27:46 +00:00
2023-03-01 18:42:44 +00:00
// X returns the inner raw content types.
func (_befg ContentTypes )X ()*_daa .Types {return _befg ._dgb };
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// NewRelationshipsCopy creates a new relationships wrapper as a copy of passed in instance.
func NewRelationshipsCopy (rels Relationships )Relationships {_deaa :=*rels ._fcdb ;return Relationships {_fcdb :&_deaa };};func (_fcdf CustomProperties )SetPropertyAsDecimal (name string ,decimal float64 ){_abb :=_fcdf .getNewProperty (name );_abb .Decimal =&decimal ;_fcdf .setOrReplaceProperty (_abb );};func (_fbbb CustomProperties )SetPropertyAsUi1 (name string ,ui1 uint8 ){_geb :=_fbbb .getNewProperty (name );_geb .Ui1 =&ui1 ;_fbbb .setOrReplaceProperty (_geb );};
2022-12-06 11:56:49 +00:00
2023-03-01 18:42:44 +00:00
// X returns the inner wrapped XML type.
func (_fcg Table )X ()*_ca .Tbl {return _fcg ._bfce };func (_aff CustomProperties )SetPropertyAsCy (name string ,cy string ){_bea :=_aff .getNewProperty (name );_bea .Cy =&cy ;_aff .setOrReplaceProperty (_bea );};func (_cafd CustomProperties )SetPropertyAsUi2 (name string ,ui2 uint16 ){_gab :=_cafd .getNewProperty (name );_gab .Ui2 =&ui2 ;_cafd .setOrReplaceProperty (_gab );};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// SetTarget changes the target attribute of the image reference (e.g. in the case of the creation of the reference or if the image which the reference is related to was moved from one location to another).
func (_eag *ImageRef )SetTarget (target string ){_eag ._bbda =target };
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// TableRow represents a row in a table.
type TableRow struct{_cba *_ca .CT_TableRow };
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// X returns the inner wrapped XML type.
func (_dcbc Relationship )X ()*_eb .Relationship {return _dcbc ._cbg };
2021-11-10 11:45:21 +00:00
2023-03-01 18:42:44 +00:00
// MakeImageRef constructs an image reference which is a reference to a
// particular image file inside a document. The same image can be used multiple
// times in a document by re-use the ImageRef.
func MakeImageRef (img Image ,d *DocBase ,rels Relationships )ImageRef {return ImageRef {_gge :img ,_ffd :d ,_dcb :rels };};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// Relationship is a relationship within a .rels file.
type Relationship struct{_cbg *_eb .Relationship };
2021-04-23 20:00:00 +00:00
2023-03-01 18:42:44 +00:00
// Relationships represents a .rels file.
type Relationships struct{_fcdb *_eb .Relationships };
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// Hyperlink is just an appropriately configured relationship.
type Hyperlink Relationship ;const _ebdc ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";
2022-04-09 14:27:46 +00:00
2022-12-06 11:56:49 +00:00
// AddCol adds a column to a table.
2023-03-01 18:42:44 +00:00
func (_dbdf Table )AddCol ()*TableCol {_afaa :=_ca .NewCT_TableCol ();_dbdf ._bfce .TblGrid .GridCol =append (_dbdf ._bfce .TblGrid .GridCol ,_afaa );for _ ,_ddcd :=range _dbdf ._bfce .Tr {_fgf :=_ca .NewCT_TableCell ();_ddcd .Tc =append (_ddcd .Tc ,_fgf );};return &TableCol {_cbdg :_afaa };};func (_dbg *ImageRef )SetRelID (id string ){_dbg ._bgbc =id };
2021-05-31 16:22:30 +00:00
2023-03-01 18:42:44 +00:00
// IsEmpty returns true if there are no relationships.
func (_cgcb Relationships )IsEmpty ()bool {return _cgcb ._fcdb ==nil ||len (_cgcb ._fcdb .Relationship )==0;};
2021-05-31 16:22:30 +00:00
2023-03-01 18:42:44 +00:00
// GetOrCreateCustomProperties returns the custom properties of the document (and if they not exist yet, creating them first).
func (_cec *DocBase )GetOrCreateCustomProperties ()CustomProperties {if _cec .CustomProperties .X ()==nil {_cec .CreateCustomProperties ();};return _cec .CustomProperties ;};
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// Path returns the path to an image file, if any.
func (_eedb ImageRef )Path ()string {return _eedb ._gge .Path };
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// Modified returns the time that the document was modified.
func (_eg CoreProperties )Modified ()_dg .Time {return _cdb (_eg ._bcb .Modified )};var ReleasedAt =_dg .Date (_bacd ,_gbc ,_gaag ,_abca ,_fedc ,0,0,_dg .UTC );
2020-08-23 14:15:53 +00:00
2023-03-01 18:42:44 +00:00
// Category returns the category of the document
func (_ecg CoreProperties )Category ()string {if _ecg ._bcb .Category !=nil {return *_ecg ._bcb .Category ;};return "";};
2021-11-10 11:45:21 +00:00
2023-03-01 18:42:44 +00:00
// SetOffsetY sets vertical offset of a table in distance units (see measurement package).
func (_fbffe Table )SetOffsetY (offY float64 ){if _fbffe ._cda .Off ==nil {_fbffe ._cda .Off =_ca .NewCT_Point2D ();_fegg :=int64 (0);_fbffe ._cda .Off .XAttr =_ca .ST_Coordinate {ST_CoordinateUnqualified :&_fegg };};_ecfbf :=_fc .ToEMU (offY );_fbffe ._cda .Off .YAttr =_ca .ST_Coordinate {ST_CoordinateUnqualified :&_ecfbf };};
2021-11-10 11:45:21 +00:00
2023-03-01 18:42:44 +00:00
// NewTable makes a new table.
func NewTable ()*Table {_caaf :=_ca .NewTbl ();_caaf .TblPr =_ca .NewCT_TableProperties ();return &Table {_bfce :_caaf };};func (_cab CustomProperties )SetPropertyAsStream (name string ,stream string ){_gcad :=_cab .getNewProperty (name );_gcad .Stream =&stream ;_cab .setOrReplaceProperty (_gcad );};
2020-10-12 13:59:12 +00:00
2023-03-01 18:42:44 +00:00
// NewRelationships creates a new relationship wrapper.
func NewRelationships ()Relationships {return Relationships {_fcdb :_eb .NewRelationships ()}};
2021-11-10 11:45:21 +00:00
2023-03-01 18:42:44 +00:00
// EnsureOverride ensures that an override for the given path exists, adding it if necessary
func (_cca ContentTypes )EnsureOverride (path ,contentType string ){for _ ,_bfa :=range _cca ._dgb .Override {if _bfa .PartNameAttr ==path {if _ed .HasPrefix (contentType ,"\u0068\u0074\u0074\u0070"){_fce .Log .Debug ("\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u0074\u0079p\u0065\u0020\u0027%\u0073\u0027\u0020\u0069\u0073\u0020\u0069\u006e\u0063\u006fr\u0072\u0065\u0063\u0074\u002c m\u0075\u0073\u0074\u0020\u006e\u006f\u0074\u0020\u0073\u0074\u0061\u0072\u0074\u0020\u0077\u0069\u0074\u0068\u0020\u0068\u0074\u0074\u0070",contentType );};_bfa .ContentTypeAttr =contentType ;return ;};};_cca .AddOverride (path ,contentType );};
2021-11-10 11:45:21 +00:00
2023-03-01 18:42:44 +00:00
// Clear removes any existing relationships.
func (_ega Relationships )Clear (){_ega ._fcdb .Relationship =nil };
2021-11-10 11:45:21 +00:00
2023-03-01 18:42:44 +00:00
// Rows returns all table rows.
func (_bgbe Table )Rows ()[]*TableRow {_baec :=_bgbe ._bfce .Tr ;_gfbd :=[]*TableRow {};for _ ,_afb :=range _baec {_gfbd =append (_gfbd ,&TableRow {_cba :_afb });};return _gfbd ;};
2021-11-10 11:45:21 +00:00
2023-03-01 18:42:44 +00:00
// AddCustomRelationships adds relationships related to custom properties to the document.
func (_ebf *DocBase )AddCustomRelationships (){_ebf .ContentTypes .AddOverride ("/\u0064o\u0063\u0050\u0072\u006f\u0070\u0073\u002f\u0063u\u0073\u0074\u006f\u006d.x\u006d\u006c","\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002fv\u006e\u0064\u002e\u006f\u0070\u0065n\u0078\u006d\u006c\u0066\u006fr\u006d\u0061\u0074\u0073\u002d\u006f\u0066\u0066\u0069\u0063\u0065\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u002e\u0063\u0075\u0073\u0074\u006f\u006d\u002d\u0070r\u006f\u0070\u0065\u0072\u0074\u0069\u0065\u0073+\u0078\u006d\u006c");_ebf .Rels .AddRelationship ("\u0064\u006f\u0063\u0050ro\u0070\u0073\u002f\u0063\u0075\u0073\u0074\u006f\u006d\u002e\u0078\u006d\u006c",_ac .CustomPropertiesType );};
2021-11-10 11:45:21 +00:00
2023-03-01 18:42:44 +00:00
// Company returns the name of the company that created the document.
2022-12-06 11:56:49 +00:00
// For unioffice created documents, it defaults to github.com/unidoc/unioffice
2023-03-01 18:42:44 +00:00
func (_cbc AppProperties )Company ()string {if _cbc ._cb .Company !=nil {return *_cbc ._cb .Company ;};return "";};
2022-04-09 14:27:46 +00:00
2023-03-01 18:42:44 +00:00
// AddAutoRelationship adds a relationship with an automatically generated
// filename based off of the type. It should be preferred over AddRelationship
// to ensure consistent filenames are maintained.
func (_eecg Relationships )AddAutoRelationship (dt _ac .DocType ,src string ,idx int ,ctype string )Relationship {return _eecg .AddRelationship (_ac .RelativeFilename (dt ,src ,ctype ,idx ),ctype );};var _ddb =_ccg .New ("\u0069\u006d\u0061\u0067\u0065\u0020\u006e\u006f\u0074\u0020\u0066o\u0075\u006e\u0064\u0020\u0069\u006e\u0020\u0073\u0074\u006fr\u0061\u0067\u0065");func (_bge CustomProperties )SetPropertyAsBlob (name ,blob string ){_ecdc :=_bge .getNewProperty (name );_ecdc .Blob =&blob ;_bge .setOrReplaceProperty (_ecdc );};
2021-06-16 07:10:52 +00:00
2023-03-01 18:42:44 +00:00
// X returns the inner wrapped XML type.
func (_edb AppProperties )X ()*_dc .Properties {return _edb ._cb };
2022-01-15 21:17:38 +00:00
2023-03-01 18:42:44 +00:00
// CopyRelationship copies the relationship.
func (_bga Relationships )CopyRelationship (idAttr string )(Relationship ,bool ){for _gdcc :=range _bga ._fcdb .Relationship {if _bga ._fcdb .Relationship [_gdcc ].IdAttr ==idAttr {_ebac :=*_bga ._fcdb .Relationship [_gdcc ];_bceb :=len (_bga ._fcdb .Relationship )+1;_deg :=map[string ]struct{}{};for _ ,_bbca :=range _bga ._fcdb .Relationship {_deg [_bbca .IdAttr ]=struct{}{};};for _ ,_bedc :=_deg [_bf .Sprintf ("\u0072\u0049\u0064%\u0064",_bceb )];_bedc ;_ ,_bedc =_deg [_bf .Sprintf ("\u0072\u0049\u0064%\u0064",_bceb )]{_bceb ++;};_ebac .IdAttr =_bf .Sprintf ("\u0072\u0049\u0064%\u0064",_bceb );_bga ._fcdb .Relationship =append (_bga ._fcdb .Relationship ,&_ebac );return Relationship {_cbg :&_ebac },true ;};};return Relationship {},false ;};func (_ggf CustomProperties )SetPropertyAsVector (name string ,vector *_ad .Vector ){_afa :=_ggf .getNewProperty (name );_afa .Vector =vector ;_ggf .setOrReplaceProperty (_afa );};
2020-10-12 13:59:12 +00:00
2023-03-01 18:42:44 +00:00
// SetCompany sets the name of the company that created the document.
func (_fda AppProperties )SetCompany (s string ){_fda ._cb .Company =&s };
2021-05-31 16:22:30 +00:00
2023-03-01 18:42:44 +00:00
// Target returns the target attrubute of the image reference (a path where the image file is located in the document structure).
func (_bede *ImageRef )Target ()string {return _bede ._bbda };
2021-05-31 16:22:30 +00:00
2023-03-01 18:42:44 +00:00
// AppProperties contains properties specific to the document and the
// application that created it.
type AppProperties struct{_cb *_dc .Properties };
2022-01-15 21:17:38 +00:00
2023-03-01 18:42:44 +00:00
// Target returns the target (path) of a relationship.
func (_fbf Relationship )Target ()string {return _fbf ._cbg .TargetAttr };func (_dba CustomProperties )SetPropertyAsOstorage (name string ,ostorage string ){_aee :=_dba .getNewProperty (name );_aee .Ostorage =&ostorage ;_dba .setOrReplaceProperty (_aee );};func (_bcba CustomProperties )SetPropertyAsUi8 (name string ,ui8 uint64 ){_gbe :=_bcba .getNewProperty (name );_gbe .Ui8 =&ui8 ;_bcba .setOrReplaceProperty (_gbe );};
2022-01-15 21:17:38 +00:00
2022-12-06 11:56:49 +00:00
// Properties returns table properties.
2023-03-01 18:42:44 +00:00
func (_eecga Table )Properties ()*_ca .CT_TableProperties {return _eecga ._bfce .TblPr };
2021-06-16 07:10:52 +00:00
2023-03-01 18:42:44 +00:00
// Author returns the author of the document
func (_eef CoreProperties )Author ()string {if _eef ._bcb .Creator !=nil {return string (_eef ._bcb .Creator .Data );};return "";};
2022-01-15 21:17:38 +00:00
2023-03-01 18:42:44 +00:00
// GetByRelId returns a relationship with the associated relation ID.
func (_cag Relationships )GetByRelId (idAttr string )Relationship {for _ ,_aadc :=range _cag ._fcdb .Relationship {if _aadc .IdAttr ==idAttr {return Relationship {_cbg :_aadc };};};return Relationship {};};
2020-11-09 01:00:18 +00:00
2023-03-01 18:42:44 +00:00
// Created returns the time that the document was created.
func (_dcc CoreProperties )Created ()_dg .Time {return _cdb (_dcc ._bcb .Created )};
2020-11-09 01:00:18 +00:00
2022-12-06 11:56:49 +00:00
// SetLinksUpToDate sets the links up to date flag.
2023-03-01 18:42:44 +00:00
func (_caf AppProperties )SetLinksUpToDate (v bool ){_caf ._cb .LinksUpToDate =_ac .Bool (v )};
2020-12-17 22:07:08 +00:00
2023-03-01 18:42:44 +00:00
// SetAuthor records the author of the document.
func (_ffe CoreProperties )SetAuthor (s string ){if _ffe ._bcb .Creator ==nil {_ffe ._bcb .Creator =&_ac .XSDAny {XMLName :_ce .Name {Local :"\u0064\u0063\u003a\u0063\u0072\u0065\u0061\u0074\u006f\u0072"}};};_ffe ._bcb .Creator .Data =[]byte (s );};func (_beb CustomProperties )SetPropertyAsFiletime (name string ,filetime _dg .Time ){_aeec :=_beb .getNewProperty (name );_aeec .Filetime =&filetime ;_beb .setOrReplaceProperty (_aeec );};func (_gca CustomProperties )SetPropertyAsBstr (name string ,bstr string ){_ggdb :=_gca .getNewProperty (name );_ggdb .Bstr =&bstr ;_gca .setOrReplaceProperty (_ggdb );};
2020-12-17 22:07:08 +00:00
2023-03-01 18:42:44 +00:00
// DefAttr returns the DefAttr property.
func (_daagf TableStyles )DefAttr ()string {return _daagf ._fbgg .DefAttr };
2020-12-17 22:07:08 +00:00
2023-03-01 18:42:44 +00:00
// Cells returns an array of row cells.
func (_baaa TableRow )Cells ()[]*_ca .CT_TableCell {return _baaa ._cba .Tc };
2020-12-17 22:07:08 +00:00
2023-03-01 18:42:44 +00:00
// ID returns the ID of a relationship.
func (_bdd Relationship )ID ()string {return _bdd ._cbg .IdAttr };
2020-12-17 22:07:08 +00:00
2023-03-01 18:42:44 +00:00
// SetApplication sets the name of the application that created the document.
func (_cbf AppProperties )SetApplication (s string ){_cbf ._cb .Application =&s };
2021-11-10 11:45:21 +00:00
2023-03-01 18:42:44 +00:00
// ImageFromFile reads an image from a file on disk. It doesn't keep the image
// in memory and only reads it to determine the format and size. You can also
// construct an Image directly if the file and size are known.
// NOTE: See also ImageFromStorage.
func ImageFromFile (path string )(Image ,error ){_egf ,_bcbb :=_cg .Open (path );_bgc :=Image {};if _bcbb !=nil {return _bgc ,_bf .Errorf ("\u0065\u0072\u0072or\u0020\u0072\u0065\u0061\u0064\u0069\u006e\u0067\u0020\u0069\u006d\u0061\u0067\u0065\u003a\u0020\u0025\u0073",_bcbb );};defer _egf .Close ();_edfg ,_dde ,_bcbb :=_g .Decode (_egf );if _bcbb !=nil {return _bgc ,_bf .Errorf ("\u0075n\u0061\u0062\u006c\u0065 \u0074\u006f\u0020\u0070\u0061r\u0073e\u0020i\u006d\u0061\u0067\u0065\u003a\u0020\u0025s",_bcbb );};_bgc .Path =path ;_bgc .Format =_dde ;_bgc .Size =_edfg .Bounds ().Size ();return _bgc ,nil ;};func (_bae CustomProperties )SetPropertyAsEmpty (name string ){_fef :=_bae .getNewProperty (name );_fef .Empty =_ad .NewEmpty ();_bae .setOrReplaceProperty (_fef );};
2021-11-10 11:45:21 +00:00
2023-03-01 18:42:44 +00:00
// SetTitle records the title of the document.
func (_dcdg CoreProperties )SetTitle (s string ){if _dcdg ._bcb .Title ==nil {_dcdg ._bcb .Title =&_ac .XSDAny {XMLName :_ce .Name {Local :"\u0064\u0063\u003a\u0074\u0069\u0074\u006c\u0065"}};};_dcdg ._bcb .Title .Data =[]byte (s );};func (_agg CustomProperties )setOrReplaceProperty (_cbca *_cd .CT_Property ){_agg .setPropertyHelper (_cbca ,true );};
2021-11-10 11:45:21 +00:00
2023-03-01 18:42:44 +00:00
// AddRelationship adds a relationship.
func (_fdf Relationships )AddRelationship (target ,ctype string )Relationship {if !_ed .HasPrefix (ctype ,"\u0068t\u0074\u0070\u003a\u002f\u002f"){_fce .Log .Debug ("\u0072\u0065\u006c\u0061\u0074\u0069\u006f\u006es\u0068\u0069\u0070 t\u0079\u0070\u0065\u0020\u0025\u0073 \u0073\u0068\u006f\u0075\u006c\u0064\u0020\u0073\u0074\u0061\u0072\u0074\u0020\u0077\u0069t\u0068\u0020\u0027\u0068\u0074\u0074\u0070\u003a/\u002f\u0027",ctype );};_bcbe :=_eb .NewRelationship ();_afg :=len (_fdf ._fcdb .Relationship )+1;_bbf :=map[string ]struct{}{};for _ ,_ced :=range _fdf ._fcdb .Relationship {_bbf [_ced .IdAttr ]=struct{}{};};for _ ,_ccbg :=_bbf [_bf .Sprintf ("\u0072\u0049\u0064%\u0064",_afg )];_ccbg ;_ ,_ccbg =_bbf [_bf .Sprintf ("\u0072\u0049\u0064%\u0064",_afg )]{_afg ++;};_bcbe .IdAttr =_bf .Sprintf ("\u0072\u0049\u0064%\u0064",_afg );_bcbe .TargetAttr =target ;_bcbe .TypeAttr =ctype ;_fdf ._fcdb .Relationship =append (_fdf ._fcdb .Relationship ,_bcbe );return Relationship {_cbg :_bcbe };};func (_eca CustomProperties )SetPropertyAsR8 (name string ,r8 float64 ){_ffeg :=_eca .getNewProperty (name );_ffeg .R8 =&r8 ;_eca .setOrReplaceProperty (_ffeg );};
// SetHeight sets row height, see measurement package.
func (_dabd TableRow )SetHeight (m _fc .Distance ){_bedd :=_fc .ToEMU (float64 (m ));_dabd ._cba .HAttr =_ca .ST_Coordinate {ST_CoordinateUnqualified :&_bedd };};func (_bdb TableRow )addCell ()*_ca .CT_TableCell {_ede :=_ca .NewCT_TableCell ();_bdb ._cba .Tc =append (_bdb ._cba .Tc ,_ede );return _ede ;};
2022-04-09 14:27:46 +00:00
2022-12-06 11:56:49 +00:00
// CustomProperty contains document specific property.
// Using of this type is deprecated.
2023-03-01 18:42:44 +00:00
type CustomProperty struct{_dfa *_cd .CT_Property };
2021-04-23 20:00:00 +00:00
2023-03-01 18:42:44 +00:00
// ContentStatus returns the content status of the document (e.g. "Final", "Draft")
func (_dag CoreProperties )ContentStatus ()string {if _dag ._bcb .ContentStatus !=nil {return *_dag ._bcb .ContentStatus ;};return "";};
2021-05-31 16:22:30 +00:00
2023-03-01 18:42:44 +00:00
// CopyOverride copies override content type for a given `path` and puts it with a path `newPath`.
func (_bgb ContentTypes )CopyOverride (path ,newPath string ){if !_ed .HasPrefix (path ,"\u002f"){path ="\u002f"+path ;};if !_ed .HasPrefix (newPath ,"\u002f"){newPath ="\u002f"+newPath ;};for _bce :=range _bgb ._dgb .Override {if _bgb ._dgb .Override [_bce ].PartNameAttr ==path {_afd :=*_bgb ._dgb .Override [_bce ];_afd .PartNameAttr =newPath ;_bgb ._dgb .Override =append (_bgb ._dgb .Override ,&_afd );};};};
2021-06-16 07:10:52 +00:00
2023-03-01 18:42:44 +00:00
// GetTargetByRelId returns a target path with the associated relation ID.
func (_egfg Relationships )GetTargetByRelId (idAttr string )string {for _ ,_ebd :=range _egfg ._fcdb .Relationship {if _ebd .IdAttr ==idAttr {return _ebd .TargetAttr ;};};return "";};
2021-06-16 07:10:52 +00:00
2023-03-01 18:42:44 +00:00
// X returns the inner wrapped XML type.
func (_bbc CustomProperties )X ()*_cd .Properties {return _bbc ._cad };
2021-06-16 07:10:52 +00:00
2023-03-01 18:42:44 +00:00
// SetStyle assigns TableStyle to a table.
func (_aec Table )SetStyle (style *_ca .CT_TableStyle ){if _aec ._bfce .TblPr ==nil {_aec ._bfce .TblPr =_ca .NewCT_TableProperties ();};if _aec ._bfce .TblPr .Choice ==nil {_aec ._bfce .TblPr .Choice =_ca .NewCT_TablePropertiesChoice ();};_aec ._bfce .TblPr .Choice .TableStyle =style ;};
2021-06-16 07:10:52 +00:00
2023-03-01 18:42:44 +00:00
// ApplicationVersion returns the version of the application that created the
// document.
func (_aed AppProperties )ApplicationVersion ()string {if _aed ._cb .AppVersion !=nil {return *_aed ._cb .AppVersion ;};return "";};
2021-06-16 07:10:52 +00:00
2023-03-01 18:42:44 +00:00
// TblStyle returns the TblStyle property.
func (_ffbe TableStyles )TblStyle ()[]*_ca .CT_TableStyle {return _ffbe ._fbgg .TblStyle };
2021-06-16 07:10:52 +00:00
2023-03-01 18:42:44 +00:00
// Application returns the name of the application that created the document.
// For unioffice created documents, it defaults to github.com/unidoc/unioffice
func (_bg AppProperties )Application ()string {if _bg ._cb .Application !=nil {return *_bg ._cb .Application ;};return "";};const Version ="\u0031\u002e\u0032\u0031\u002e\u0031";
2021-06-16 07:10:52 +00:00
2023-03-01 18:42:44 +00:00
// Type returns the type of a relationship.
func (_gde Relationship )Type ()string {return _gde ._cbg .TypeAttr };
2022-02-25 19:20:45 +00:00
2023-03-01 18:42:44 +00:00
// RelID returns the relationship ID.
func (_bde ImageRef )RelID ()string {return _bde ._bgbc };
2022-02-25 19:20:45 +00:00
2023-03-01 18:42:44 +00:00
// DocBase is the type embedded in in the Document/Workbook/Presentation types
// that contains members common to all.
type DocBase struct{ContentTypes ContentTypes ;AppProperties AppProperties ;Rels Relationships ;CoreProperties CoreProperties ;CustomProperties CustomProperties ;Thumbnail _g .Image ;Images []ImageRef ;ExtraFiles []ExtraFile ;TmpPath string ;};func (_cbd CustomProperties )SetPropertyAsBool (name string ,b bool ){_ebad :=_cbd .getNewProperty (name );_ebad .Bool =&b ;_cbd .setOrReplaceProperty (_ebad );};func init (){_be .SetAsStorage ()};func (_dae CustomProperties )SetPropertyAsStorage (name string ,storage string ){_ecf :=_dae .getNewProperty (name );_ecf .Storage =&storage ;_dae .setOrReplaceProperty (_ecf );};
2022-12-06 11:56:49 +00:00
2023-03-01 18:42:44 +00:00
// RemoveOverride removes an override given a path.
func (_ddd ContentTypes )RemoveOverride (path string ){if !_ed .HasPrefix (path ,"\u002f"){path ="\u002f"+path ;};for _bc ,_cbfd :=range _ddd ._dgb .Override {if _cbfd .PartNameAttr ==path {copy (_ddd ._dgb .Override [_bc :],_ddd ._dgb .Override [_bc +1:]);_ddd ._dgb .Override =_ddd ._dgb .Override [0:len (_ddd ._dgb .Override )-1];};};};
2021-08-23 20:44:48 +00:00
2023-03-01 18:42:44 +00:00
// SetWidth sets column width, see measurement package.
func (_bfg TableCol )SetWidth (m _fc .Distance ){_geef :=_fc .ToEMU (float64 (m ));_bfg ._cbdg .WAttr =_ca .ST_Coordinate {ST_CoordinateUnqualified :&_geef };};
2022-02-25 19:20:45 +00:00
2023-03-01 18:42:44 +00:00
// SetContentStatus records the content status of the document.
func (_befe CoreProperties )SetContentStatus (s string ){_befe ._bcb .ContentStatus =&s };func UtcTimeFormat (t _dg .Time )string {return t .Format (_ebdc )+"\u0020\u0055\u0054\u0043"};
2022-02-25 19:20:45 +00:00
2023-03-01 18:42:44 +00:00
// Properties returns table properties.
func (_aeeg Table )Grid ()*_ca .CT_TableGrid {return _aeeg ._bfce .TblGrid };func (_bec CustomProperties )SetPropertyAsUi4 (name string ,ui4 uint32 ){_bgf :=_bec .getNewProperty (name );_bgf .Ui4 =&ui4 ;_bec .setOrReplaceProperty (_bgf );};func (_gga CustomProperties )SetPropertyAsLpwstr (name string ,lpwstr string ){_geca :=_gga .getNewProperty (name );_geca .Lpwstr =&lpwstr ;_gga .setOrReplaceProperty (_geca );};
2022-02-25 19:20:45 +00:00
2023-03-01 18:42:44 +00:00
// NewCustomProperties constructs a new CustomProperties.
func NewCustomProperties ()CustomProperties {return CustomProperties {_cad :_cd .NewProperties ()}};
2022-06-27 19:44:23 +00:00
2022-12-06 11:56:49 +00:00
// X returns the inner wrapped XML type.
2023-03-01 18:42:44 +00:00
func (_abd TableStyles )X ()*_ca .TblStyleLst {return _abd ._fbgg };
2022-06-27 19:44:23 +00:00
2023-03-01 18:42:44 +00:00
// Format returns the format of the underlying image
func (_cgdc ImageRef )Format ()string {return _cgdc ._gge .Format };
2022-06-27 19:44:23 +00:00
2023-03-01 18:42:44 +00:00
// CustomProperties contains document specific properties.
type CustomProperties struct{_cad *_cd .Properties };func (_ffef CustomProperties )SetPropertyAsError (name string ,error string ){_ebc :=_ffef .getNewProperty (name );_ebc .Error =&error ;_ffef .setOrReplaceProperty (_ebc );};
2022-09-02 11:46:53 +00:00
2022-12-06 11:56:49 +00:00
// SetLanguage records the language of the document.
2023-03-01 18:42:44 +00:00
func (_cfdd CoreProperties )SetLanguage (s string ){_cfdd ._bcb .Language =&_ac .XSDAny {XMLName :_ce .Name {Local :"d\u0063\u003a\u006c\u0061\u006e\u0067\u0075\u0061\u0067\u0065"}};_cfdd ._bcb .Language .Data =[]byte (s );};
2022-09-02 11:46:53 +00:00
2023-03-01 18:42:44 +00:00
// X returns the underlying raw XML data.
func (_fee Relationships )X ()*_eb .Relationships {return _fee ._fcdb };
2022-09-02 11:46:53 +00:00
2023-03-01 18:42:44 +00:00
// Theme is a drawingml theme.
type Theme struct{_cfdge *_ca .Theme };
2022-12-06 11:56:49 +00:00
2023-03-01 18:42:44 +00:00
// Append appends DocBase part of an office document to another DocBase.
func (_ge DocBase )Append (docBase1 DocBase )DocBase {_fa :=docBase1 .ContentTypes .X ();for _ ,_ea :=range _fa .Default {_ge .ContentTypes .AddDefault (_ea .ExtensionAttr ,_ea .ContentTypeAttr );};for _ ,_cdf :=range _fa .Override {_ge .ContentTypes .AddOverride (_cdf .PartNameAttr ,_cdf .ContentTypeAttr );};_bef :=_ge .AppProperties .X ();_aa :=docBase1 .AppProperties .X ();if _bef .Pages !=nil {if _aa .Pages !=nil {*_bef .Pages +=*_aa .Pages ;};}else if _aa .Pages !=nil {_bef .Pages =_aa .Pages ;};if _bef .Words !=nil {if _aa .Words !=nil {*_bef .Words +=*_aa .Words ;};}else if _aa .Words !=nil {_bef .Words =_aa .Words ;};if _bef .Characters !=nil {if _aa .Characters !=nil {*_bef .Characters +=*_aa .Characters ;};}else if _aa .Characters !=nil {_bef .Characters =_aa .Characters ;};if _bef .Lines !=nil {if _aa .Lines !=nil {*_bef .Lines +=*_aa .Lines ;};}else if _aa .Lines !=nil {_bef .Lines =_aa .Lines ;};if _bef .Paragraphs !=nil {if _aa .Paragraphs !=nil {*_bef .Paragraphs +=*_aa .Paragraphs ;};}else if _aa .Paragraphs !=nil {_bef .Paragraphs =_aa .Paragraphs ;};if _bef .Notes !=nil {if _aa .Notes !=nil {*_bef .Notes +=*_aa .Notes ;};}else if _aa .Notes !=nil {_bef .Notes =_aa .Notes ;};if _bef .HiddenSlides !=nil {if _aa .HiddenSlides !=nil {*_bef .HiddenSlides +=*_aa .HiddenSlides ;};}else if _aa .HiddenSlides !=nil {_bef .HiddenSlides =_aa .HiddenSlides ;};if _bef .MMClips !=nil {if _aa .MMClips !=nil {*_bef .MMClips +=*_aa .MMClips ;};}else if _aa .MMClips !=nil {_bef .MMClips =_aa .MMClips ;};if _bef .LinksUpToDate !=nil {if _aa .LinksUpToDate !=nil {*_bef .LinksUpToDate =*_bef .LinksUpToDate &&*_aa .LinksUpToDate ;};}else if _aa .LinksUpToDate !=nil {_bef .LinksUpToDate =_aa .LinksUpToDate ;};if _bef .CharactersWithSpaces !=nil {if _aa .CharactersWithSpaces !=nil {*_bef .CharactersWithSpaces +=*_aa .CharactersWithSpaces ;};}else if _aa .CharactersWithSpaces !=nil {_bef .CharactersWithSpaces =_aa .CharactersWithSpaces ;};if _bef .SharedDoc !=nil {if _aa .SharedDoc !=nil {*_bef .SharedDoc =*_bef .SharedDoc ||*_aa .SharedDoc ;};}else if _aa .SharedDoc !=nil {_bef .SharedDoc =_aa .SharedDoc ;};if _bef .HyperlinksChanged !=nil {if _aa .HyperlinksChanged !=nil {*_bef .HyperlinksChanged =*_bef .HyperlinksChanged ||*_aa .HyperlinksChanged ;};}else if _aa .HyperlinksChanged !=nil {_bef .HyperlinksChanged =_aa .HyperlinksChanged ;};_bef .DigSig =nil ;if _bef .TitlesOfParts ==nil &&_aa .TitlesOfParts !=nil {_bef .TitlesOfParts =_aa .TitlesOfParts ;};if _bef .HeadingPairs !=nil {if _aa .HeadingPairs !=nil {_ag :=_bef .HeadingPairs .Vector ;_aab :=_aa .HeadingPairs .Vector ;_gg :=_ag .Variant ;_fcf :=_aab .Variant ;_edd :=[]*_ad .Variant {};for _dga :=0;_dga < len (_fcf );_dga +=2{_dd :=_fcf [_dga ].Lpstr ;_ga :=false ;for _gec :=0;_gec < len (_gg );_gec +=2{_edc :=_gg [_gec ].Lpstr ;if _edc !=nil &&_dd !=nil &&*_edc ==*_dd {*_gg [_gec +1].I4 =*_gg [_gec +1].I4 +*_fcf [_dga +1].I4 ;_ga =true ;break ;};};if !_ga {_edd =append (_edd ,&_ad .Variant {CT_Variant :_ad .CT_Variant {Lpstr :_fcf [_dga ].Lpstr }});_edd =append (_edd ,&_ad .Variant {CT_Variant :_ad .CT_Variant {I4 :_fcf [_dga ].I4 }});};};_gg =append (_gg ,_edd ...);_ag .SizeAttr =uint32 (len (_gg ));};}else if _aa .HeadingPairs !=nil {_bef .HeadingPairs =_aa .HeadingPairs ;};if _bef .HLinks !=nil {if _aa .HLinks !=nil {_eba :=_bef .HLinks .Vector ;_geg :=_aa .HLinks .Vector ;_cae :=_eba .Variant ;_ada :=_geg .Variant ;for _ ,_ec :=range _ada {_ab :=true ;for _ ,_fe :=range _cae {if _da .DeepEqual (_fe ,_ec ){_ab =false ;break ;};};if _ab {_cae =append (_cae ,_ec );_eba .SizeAttr ++;};};};}else if _aa .HLinks !=nil {_bef .HLinks =_aa .HLinks ;};_fd :=_ge .GetOrCreateCustomProperties ();_bfd :=docBase1 .GetOrCreateCustomProperties ();for _ ,_acf :=range _bfd .PropertiesList (){_fd .setProperty (_acf );};_ge .CustomProperties =_fd ;_ba :=_ge .Rels .X ().Relationship ;for _ ,_af :=range docBase1 .Rels .X ().Relationship {_beg :=true ;for _ ,_adc :=range _ba {if _adc .TargetAttr ==_af .TargetAttr &&_adc .TypeAttr ==_af .TypeAttr {_beg =false ;break ;};};if _beg {_ge .Re
2022-12-06 11:56:49 +00:00
2023-03-01 18:42:44 +00:00
// CoreProperties contains document specific properties.
type CoreProperties struct{_bcb *_dgd .CoreProperties };
2022-12-06 11:56:49 +00:00
2023-03-01 18:42:44 +00:00
// AddOverride adds an override content type for a given path name.
func (_eee ContentTypes )AddOverride (path ,contentType string ){if !_ed .HasPrefix (path ,"\u002f"){path ="\u002f"+path ;};if _ed .HasPrefix (contentType ,"\u0068\u0074\u0074\u0070"){_fce .Log .Debug ("\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u0074\u0079p\u0065\u0020\u0027%\u0073\u0027\u0020\u0069\u0073\u0020\u0069\u006e\u0063\u006fr\u0072\u0065\u0063\u0074\u002c m\u0075\u0073\u0074\u0020\u006e\u006f\u0074\u0020\u0073\u0074\u0061\u0072\u0074\u0020\u0077\u0069\u0074\u0068\u0020\u0068\u0074\u0074\u0070",contentType );};for _ ,_ggb :=range _eee ._dgb .Override {if _ggb .PartNameAttr ==path &&_ggb .ContentTypeAttr ==contentType {return ;};};_ccc :=_daa .NewOverride ();_ccc .PartNameAttr =path ;_ccc .ContentTypeAttr =contentType ;_eee ._dgb .Override =append (_eee ._dgb .Override ,_ccc );};
// SetCategory records the category of the document.
func (_fbb CoreProperties )SetCategory (s string ){_fbb ._bcb .Category =&s };func (_abag CustomProperties )SetPropertyAsOblob (name ,oblob string ){_bdg :=_abag .getNewProperty (name );_bdg .Oblob =&oblob ;_abag .setOrReplaceProperty (_bdg );};
// LastModifiedBy returns the name of the last person to modify the document
func (_dcd CoreProperties )LastModifiedBy ()string {if _dcd ._bcb .LastModifiedBy !=nil {return *_dcd ._bcb .LastModifiedBy ;};return "";};
2022-12-06 11:56:49 +00:00
// NewCoreProperties constructs a new CoreProperties.
2023-03-01 18:42:44 +00:00
func NewCoreProperties ()CoreProperties {return CoreProperties {_bcb :_dgd .NewCoreProperties ()}};
// Title returns the Title of the document
func (_egg CoreProperties )Title ()string {if _egg ._bcb .Title !=nil {return string (_egg ._bcb .Title .Data );};return "";};
// TableStyles contains document specific properties.
type TableStyles struct{_fbgg *_ca .TblStyleLst };
// CreateCustomProperties creates the custom properties of the document.
func (_cebb *DocBase )CreateCustomProperties (){_cebb .CustomProperties =NewCustomProperties ();_cebb .AddCustomRelationships ();};const _fedc =30;
// AddDefault registers a default content type for a given file extension.
func (_dgad ContentTypes )AddDefault (fileExtension string ,contentType string ){fileExtension =_ed .ToLower (fileExtension );for _ ,_gb :=range _dgad ._dgb .Default {if _gb .ExtensionAttr ==fileExtension &&_gb .ContentTypeAttr ==contentType {return ;};};_ecd :=_daa .NewDefault ();_ecd .ExtensionAttr =fileExtension ;_ecd .ContentTypeAttr =contentType ;_dgad ._dgb .Default =append (_dgad ._dgb .Default ,_ecd );};
// SetModified sets the time that the document was modified.
func (_fcd CoreProperties )SetModified (t _dg .Time ){_fcd ._bcb .Modified =_fceb (t ,"\u0064\u0063t\u0065\u0072\u006ds\u003a\u006d\u006f\u0064\u0069\u0066\u0069\u0065\u0064");};
// Remove removes an existing relationship.
func (_deb Relationships )Remove (rel Relationship )bool {for _dac ,_def :=range _deb ._fcdb .Relationship {if _def ==rel ._cbg {copy (_deb ._fcdb .Relationship [_dac :],_deb ._fcdb .Relationship [_dac +1:]);_deb ._fcdb .Relationship =_deb ._fcdb .Relationship [0:len (_deb ._fcdb .Relationship )-1];return true ;};};return false ;};
// NewTheme constructs a new theme.
func NewTheme ()Theme {return Theme {_ca .NewTheme ()}};