unioffice/common/common.go

506 lines
49 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.
2024-10-17 17:05:28 +00:00
package common ;import (_e "archive/zip";_b "bytes";_dfd "encoding/xml";_df "errors";_f "fmt";_eb "github.com/unidoc/unioffice";_ee "github.com/unidoc/unioffice/common/logger";_dfe "github.com/unidoc/unioffice/common/tempstorage";_fe "github.com/unidoc/unioffice/common/tempstorage/diskstore";
_cf "github.com/unidoc/unioffice/measurement";_gc "github.com/unidoc/unioffice/schema/soo/dml";_fc "github.com/unidoc/unioffice/schema/soo/ofc/custom_properties";_c "github.com/unidoc/unioffice/schema/soo/ofc/docPropsVTypes";_bed "github.com/unidoc/unioffice/schema/soo/ofc/extended_properties";
_fa "github.com/unidoc/unioffice/schema/soo/pkg/content_types";_bag "github.com/unidoc/unioffice/schema/soo/pkg/metadata/core_properties";_fb "github.com/unidoc/unioffice/schema/soo/pkg/relationships";_cg "github.com/unidoc/unioffice/zippkg";_dc "image";
_ "image/gif";_ "image/jpeg";_ "image/png";_ge "os";_g "reflect";_ba "regexp";_bba "strconv";_be "strings";_bb "time";);
2023-07-04 11:04:03 +00:00
2024-10-17 17:05:28 +00:00
// SetCompany sets the name of the company that created the document.
func (_ede AppProperties )SetCompany (s string ){_ede ._agbd .Company =&s };const _dfdd ="2\u00300\u0036\u002d\u0030\u0031\u002d\u0030\u0032\u00541\u0035\u003a\u0030\u0034:0\u0035\u005a";func (_bbb CustomProperties )SetPropertyAsLpstr (name string ,lpstr string ){_gda :=_bbb .getNewProperty (name );
_gda .Lpstr =&lpstr ;_bbb .setOrReplaceProperty (_gda );};
2022-04-09 14:27:46 +00:00
2024-10-17 17:05:28 +00:00
// PropertiesList returns the list of all custom properties of the document.
func (_cba CustomProperties )PropertiesList ()[]*_fc .CT_Property {return _cba ._da .Property };
2021-05-31 16:22:30 +00:00
2024-10-17 17:05:28 +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 _dc .Point ;Format string ;Path string ;Data *[]byte ;};
2020-08-23 14:15:53 +00:00
2024-10-17 17:05:28 +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 (_gac *DocBase )AddExtraFileFromZip (f *_e .File )error {_ded ,_adg :=_cg .ExtractToDiskTmp (f ,_gac .TmpPath );if _adg !=nil {return _f .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",_adg );
};_gac .ExtraFiles =append (_gac .ExtraFiles ,ExtraFile {ZipPath :f .Name ,DiskPath :_ded });return nil ;};func (_eaff CustomProperties )SetPropertyAsVstream (name string ,vstream *_c .Vstream ){_ffdc :=_eaff .getNewProperty (name );_ffdc .Vstream =vstream ;
_eaff .setOrReplaceProperty (_ffdc );};
2023-09-16 17:56:36 +00:00
2024-10-17 17:05:28 +00:00
// CoreProperties contains document specific properties.
type CoreProperties struct{_affb *_bag .CoreProperties };func (_dee CustomProperties )SetPropertyAsUi4 (name string ,ui4 uint32 ){_acf :=_dee .getNewProperty (name );_acf .Ui4 =&ui4 ;_dee .setOrReplaceProperty (_acf );};func _bbac (_ccba *_eb .XSDAny )_bb .Time {if _ccba ==nil {return _bb .Time {};
};_cee ,_bcf :=_bb .Parse (_dfdd ,string (_ccba .Data ));if _bcf !=nil {_ee .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 (_ccba .Data ),_bcf );
};return _cee ;};func (_egb *ImageRef )SetRelID (id string ){_egb ._adb =id };
2021-11-10 11:45:21 +00:00
2024-10-17 17:05:28 +00:00
// SetAuthor records the author of the document.
func (_bda CoreProperties )SetAuthor (s string ){if _bda ._affb .Creator ==nil {_bda ._affb .Creator =&_eb .XSDAny {XMLName :_dfd .Name {Local :"\u0064\u0063\u003a\u0063\u0072\u0065\u0061\u0074\u006f\u0072"}};};_bda ._affb .Creator .Data =[]byte (s );};
func (_fdba CustomProperties )SetPropertyAsArray (name string ,array *_c .Array ){_acd :=_fdba .getNewProperty (name );_acd .Array =array ;_fdba .setOrReplaceProperty (_acd );};
2024-10-17 17:05:28 +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 ;};const _gaa =2024;const Version ="\u0031\u002e\u0033\u0037\u002e\u0030";func (_dda CustomProperties )SetPropertyAsR4 (name string ,r4 float32 ){_beeg :=_dda .getNewProperty (name );_beeg .R4 =&r4 ;
_dda .setOrReplaceProperty (_beeg );};
2021-11-10 11:45:21 +00:00
2024-10-17 17:05:28 +00:00
// NewRelationship constructs a new relationship.
func NewRelationship ()Relationship {return Relationship {_gabd :_fb .NewRelationship ()}};
2021-11-10 11:45:21 +00:00
2024-10-17 17:05:28 +00:00
// LastModifiedBy returns the name of the last person to modify the document
func (_bbd CoreProperties )LastModifiedBy ()string {if _bbd ._affb .LastModifiedBy !=nil {return *_bbd ._affb .LastModifiedBy ;};return "";};
2020-10-12 13:59:12 +00:00
2024-10-17 17:05:28 +00:00
// X returns the inner wrapped XML type.
func (_gebc TableStyles )X ()*_gc .TblStyleLst {return _gebc ._facf };
2021-05-31 16:22:30 +00:00
2024-10-17 17:05:28 +00:00
// TableRow represents a row in a table.
type TableRow struct{_agec *_gc .CT_TableRow };func (_dbgb CustomProperties )SetPropertyAsUi1 (name string ,ui1 uint8 ){_eda :=_dbgb .getNewProperty (name );_eda .Ui1 =&ui1 ;_dbgb .setOrReplaceProperty (_eda );};const _aee ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";
func (_fad CustomProperties )SetPropertyAsNull (name string ){_efb :=_fad .getNewProperty (name );_efb .Null =_c .NewNull ();_fad .setOrReplaceProperty (_efb );};
2022-01-15 21:17:38 +00:00
2024-09-16 09:59:58 +00:00
// NewRelationshipsCopy creates a new relationships wrapper as a copy of passed in instance.
2024-10-17 17:05:28 +00:00
func NewRelationshipsCopy (rels Relationships )Relationships {_cgaf :=*rels ._aabd ;return Relationships {_aabd :&_cgaf };};
2024-05-04 18:48:06 +00:00
2024-10-17 17:05:28 +00:00
// Clear removes any existing relationships.
func (_fee Relationships )Clear (){_fee ._aabd .Relationship =nil };func (_fdcf CustomProperties )SetPropertyAsUi2 (name string ,ui2 uint16 ){_fed :=_fdcf .getNewProperty (name );_fed .Ui2 =&ui2 ;_fdcf .setOrReplaceProperty (_fed );};
2024-05-04 18:48:06 +00:00
2024-10-17 17:05:28 +00:00
// SetModified sets the time that the document was modified.
func (_fefg CoreProperties )SetModified (t _bb .Time ){_fefg ._affb .Modified =_bbg (t ,"\u0064\u0063t\u0065\u0072\u006ds\u003a\u006d\u006f\u0064\u0069\u0066\u0069\u0065\u0064");};func _bbg (_gee _bb .Time ,_cdd string )*_eb .XSDAny {_cae :=&_eb .XSDAny {XMLName :_dfd .Name {Local :_cdd }};
_cae .Attrs =append (_cae .Attrs ,_dfd .Attr {Name :_dfd .Name {Local :"\u0078\u0073\u0069\u003a\u0074\u0079\u0070\u0065"},Value :"\u0064\u0063\u0074\u0065\u0072\u006d\u0073\u003a\u00573\u0043\u0044\u0054\u0046"});_cae .Attrs =append (_cae .Attrs ,_dfd .Attr {Name :_dfd .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"});
_cae .Attrs =append (_cae .Attrs ,_dfd .Attr {Name :_dfd .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/"});
_cae .Data =[]byte (_gee .Format (_dfdd ));return _cae ;};func (_cacd CustomProperties )SetPropertyAsI2 (name string ,i2 int16 ){_fcfc :=_cacd .getNewProperty (name );_fcfc .I2 =&i2 ;_cacd .setOrReplaceProperty (_fcfc );};func (_dgfe CustomProperties )SetPropertyAsOstream (name string ,ostream string ){_age :=_dgfe .getNewProperty (name );
_age .Ostream =&ostream ;_dgfe .setOrReplaceProperty (_age );};
2024-05-04 18:48:06 +00:00
2024-10-17 17:05:28 +00:00
// NewTable makes a new table.
func NewTable ()*Table {_cfbf :=_gc .NewTbl ();_cfbf .TblPr =_gc .NewCT_TableProperties ();return &Table {_cgcc :_cfbf };};
2022-01-15 21:17:38 +00:00
2024-10-17 17:05:28 +00:00
// RemoveOverride removes an override given a path.
func (_cga ContentTypes )RemoveOverride (path string ){if !_be .HasPrefix (path ,"\u002f"){path ="\u002f"+path ;};for _ddg ,_gbf :=range _cga ._bfa .Override {if _gbf .PartNameAttr ==path {copy (_cga ._bfa .Override [_ddg :],_cga ._bfa .Override [_ddg +1:]);
_cga ._bfa .Override =_cga ._bfa .Override [0:len (_cga ._bfa .Override )-1];};};};func (_dbd CustomProperties )getNewProperty (_fefe string )*_fc .CT_Property {_acg :=_dbd ._da .Property ;_ddc :=int32 (1);for _ ,_fge :=range _acg {if _fge .PidAttr > _ddc {_ddc =_fge .PidAttr ;
};};_fcc :=_fc .NewCT_Property ();_fcc .NameAttr =&_fefe ;_fcc .PidAttr =_ddc +1;_fcc .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 _fcc ;};
2022-01-15 21:17:38 +00:00
2024-10-17 17:05:28 +00:00
// Cells returns an array of row cells.
func (_beae TableRow )Cells ()[]*_gc .CT_TableCell {return _beae ._agec .Tc };
2020-11-09 01:00:18 +00:00
2024-10-17 17:05:28 +00:00
// CopyRelationship copies the relationship.
func (_gbb Relationships )CopyRelationship (idAttr string )(Relationship ,bool ){for _cgfb :=range _gbb ._aabd .Relationship {if _gbb ._aabd .Relationship [_cgfb ].IdAttr ==idAttr {_dea :=*_gbb ._aabd .Relationship [_cgfb ];_cab :=len (_gbb ._aabd .Relationship )+1;
_bgb :=map[string ]struct{}{};for _ ,_ccd :=range _gbb ._aabd .Relationship {_bgb [_ccd .IdAttr ]=struct{}{};};for _ ,_bfac :=_bgb [_f .Sprintf ("\u0072\u0049\u0064%\u0064",_cab )];_bfac ;_ ,_bfac =_bgb [_f .Sprintf ("\u0072\u0049\u0064%\u0064",_cab )]{_cab ++;
};_dea .IdAttr =_f .Sprintf ("\u0072\u0049\u0064%\u0064",_cab );_gbb ._aabd .Relationship =append (_gbb ._aabd .Relationship ,&_dea );return Relationship {_gabd :&_dea },true ;};};return Relationship {},false ;};
2020-12-17 22:07:08 +00:00
2024-10-17 17:05:28 +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 (_cef ImageRef )RelativeWidth (h _cf .Distance )_cf .Distance {_ecggf :=float64 (_cef .Size ().X )/float64 (_cef .Size ().Y );return h *_cf .Distance (_ecggf );};
2024-09-16 09:59:58 +00:00
2024-10-17 17:05:28 +00:00
// DefAttr returns the DefAttr property.
func (_ade TableStyles )DefAttr ()string {return _ade ._facf .DefAttr };
2023-05-26 09:49:04 +00:00
2024-10-17 17:05:28 +00:00
// NewCoreProperties constructs a new CoreProperties.
func NewCoreProperties ()CoreProperties {return CoreProperties {_affb :_bag .NewCoreProperties ()}};
2024-05-04 18:48:06 +00:00
2024-10-17 17:05:28 +00:00
// GetTargetByRelIdAndType returns a target path with the associated relation ID.
func (_dgaf Relationships )GetTargetByRelIdAndType (idAttr string ,typeAttr string )string {for _ ,_degg :=range _dgaf ._aabd .Relationship {if _degg .IdAttr ==idAttr &&_degg .TypeAttr ==typeAttr {return _degg .TargetAttr ;};};return "";};
2024-05-04 18:48:06 +00:00
2024-10-17 17:05:28 +00:00
// SetID set the ID of a relationship.
func (_gae Relationship )SetID (ID string ){_gae ._gabd .IdAttr =ID ;};
2024-05-04 18:48:06 +00:00
2024-10-17 17:05:28 +00:00
// ApplicationVersion returns the version of the application that created the
// document.
func (_fef AppProperties )ApplicationVersion ()string {if _fef ._agbd .AppVersion !=nil {return *_fef ._agbd .AppVersion ;};return "";};
2020-12-17 22:07:08 +00:00
2024-10-17 17:05:28 +00:00
// SetHeight sets row height, see measurement package.
func (_fabd TableRow )SetHeight (m _cf .Distance ){_eabc :=_cf .ToEMU (float64 (m ));_fabd ._agec .HAttr =_gc .ST_Coordinate {ST_CoordinateUnqualified :&_eabc };};
2020-12-17 22:07:08 +00:00
2024-10-17 17:05:28 +00:00
// SetLastModifiedBy records the last person to modify the document.
func (_baf CoreProperties )SetLastModifiedBy (s string ){_baf ._affb .LastModifiedBy =&s };func (_geee CustomProperties )SetPropertyAsStorage (name string ,storage string ){_dga :=_geee .getNewProperty (name );_dga .Storage =&storage ;_geee .setOrReplaceProperty (_dga );
};
2021-11-10 11:45:21 +00:00
2024-10-17 17:05:28 +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 _eb .DocType )error {_eaeb :=_eb .AbsoluteImageFilename (dt ,imageNum ,_be .ToLower (img .Format ()));if img .Data ()!=nil &&len (*img .Data ())> 0{if _bfe :=_cg .AddFileFromBytes (z ,_eaeb ,*img .Data ());
_bfe !=nil {return _bfe ;};}else if img .Path ()!=""{if _gebd :=_cg .AddFileFromDisk (z ,_eaeb ,img .Path ());_gebd !=nil {return _gebd ;};}else {return _f .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 ;};
2024-05-04 18:48:06 +00:00
2024-10-17 17:05:28 +00:00
// Append appends DocBase part of an office document to another DocBase.
func (_fg DocBase )Append (docBase1 DocBase )DocBase {_gb :=docBase1 .ContentTypes .X ();for _ ,_af :=range _gb .Default {_fg .ContentTypes .AddDefault (_af .ExtensionAttr ,_af .ContentTypeAttr );};for _ ,_ab :=range _gb .Override {_fg .ContentTypes .AddOverride (_ab .PartNameAttr ,_ab .ContentTypeAttr );
};_aa :=_fg .AppProperties .X ();_ag :=docBase1 .AppProperties .X ();if _aa .Pages !=nil {if _ag .Pages !=nil {*_aa .Pages +=*_ag .Pages ;};}else if _ag .Pages !=nil {_aa .Pages =_ag .Pages ;};if _aa .Words !=nil {if _ag .Words !=nil {*_aa .Words +=*_ag .Words ;
};}else if _ag .Words !=nil {_aa .Words =_ag .Words ;};if _aa .Characters !=nil {if _ag .Characters !=nil {*_aa .Characters +=*_ag .Characters ;};}else if _ag .Characters !=nil {_aa .Characters =_ag .Characters ;};if _aa .Lines !=nil {if _ag .Lines !=nil {*_aa .Lines +=*_ag .Lines ;
};}else if _ag .Lines !=nil {_aa .Lines =_ag .Lines ;};if _aa .Paragraphs !=nil {if _ag .Paragraphs !=nil {*_aa .Paragraphs +=*_ag .Paragraphs ;};}else if _ag .Paragraphs !=nil {_aa .Paragraphs =_ag .Paragraphs ;};if _aa .Notes !=nil {if _ag .Notes !=nil {*_aa .Notes +=*_ag .Notes ;
};}else if _ag .Notes !=nil {_aa .Notes =_ag .Notes ;};if _aa .HiddenSlides !=nil {if _ag .HiddenSlides !=nil {*_aa .HiddenSlides +=*_ag .HiddenSlides ;};}else if _ag .HiddenSlides !=nil {_aa .HiddenSlides =_ag .HiddenSlides ;};if _aa .MMClips !=nil {if _ag .MMClips !=nil {*_aa .MMClips +=*_ag .MMClips ;
};}else if _ag .MMClips !=nil {_aa .MMClips =_ag .MMClips ;};if _aa .LinksUpToDate !=nil {if _ag .LinksUpToDate !=nil {*_aa .LinksUpToDate =*_aa .LinksUpToDate &&*_ag .LinksUpToDate ;};}else if _ag .LinksUpToDate !=nil {_aa .LinksUpToDate =_ag .LinksUpToDate ;
};if _aa .CharactersWithSpaces !=nil {if _ag .CharactersWithSpaces !=nil {*_aa .CharactersWithSpaces +=*_ag .CharactersWithSpaces ;};}else if _ag .CharactersWithSpaces !=nil {_aa .CharactersWithSpaces =_ag .CharactersWithSpaces ;};if _aa .SharedDoc !=nil {if _ag .SharedDoc !=nil {*_aa .SharedDoc =*_aa .SharedDoc ||*_ag .SharedDoc ;
};}else if _ag .SharedDoc !=nil {_aa .SharedDoc =_ag .SharedDoc ;};if _aa .HyperlinksChanged !=nil {if _ag .HyperlinksChanged !=nil {*_aa .HyperlinksChanged =*_aa .HyperlinksChanged ||*_ag .HyperlinksChanged ;};}else if _ag .HyperlinksChanged !=nil {_aa .HyperlinksChanged =_ag .HyperlinksChanged ;
};_aa .DigSig =nil ;if _aa .TitlesOfParts ==nil &&_ag .TitlesOfParts !=nil {_aa .TitlesOfParts =_ag .TitlesOfParts ;};if _aa .HeadingPairs !=nil {if _ag .HeadingPairs !=nil {_db :=_aa .HeadingPairs .Vector ;_eg :=_ag .HeadingPairs .Vector ;_gbd :=_db .Variant ;
_cc :=_eg .Variant ;_ef :=[]*_c .Variant {};for _cd :=0;_cd < len (_cc );_cd +=2{_fd :=_cc [_cd ].Lpstr ;_bg :=false ;for _aff :=0;_aff < len (_gbd );_aff +=2{_bea :=_gbd [_aff ].Lpstr ;if _bea !=nil &&_fd !=nil &&*_bea ==*_fd {*_gbd [_aff +1].I4 =*_gbd [_aff +1].I4 +*_cc [_cd +1].I4 ;
_bg =true ;break ;};};if !_bg {_ef =append (_ef ,&_c .Variant {CT_Variant :_c .CT_Variant {Lpstr :_cc [_cd ].Lpstr }});_ef =append (_ef ,&_c .Variant {CT_Variant :_c .CT_Variant {I4 :_cc [_cd ].I4 }});};};_gbd =append (_gbd ,_ef ...);_db .SizeAttr =uint32 (len (_gbd ));
};}else if _ag .HeadingPairs !=nil {_aa .HeadingPairs =_ag .HeadingPairs ;};if _aa .HLinks !=nil {if _ag .HLinks !=nil {_ae :=_aa .HLinks .Vector ;_cdb :=_ag .HLinks .Vector ;_aeb :=_ae .Variant ;_abc :=_cdb .Variant ;for _ ,_bf :=range _abc {_cdc :=true ;
for _ ,_bgc :=range _aeb {if _g .DeepEqual (_bgc ,_bf ){_cdc =false ;break ;};};if _cdc {_aeb =append (_aeb ,_bf );_ae .SizeAttr ++;};};};}else if _ag .HLinks !=nil {_aa .HLinks =_ag .HLinks ;};_ed :=_fg .GetOrCreateCustomProperties ();_eaf :=docBase1 .GetOrCreateCustomProperties ();
for _ ,_dg :=range _eaf .PropertiesList (){_ed .setProperty (_dg );};_fg .CustomProperties =_ed ;_bd :=_fg .Rels .X ().Relationship ;for _ ,_cdg :=range docBase1 .Rels .X ().Relationship {_dd :=true ;for _ ,_beb :=range _bd {if _beb .TargetAttr ==_cdg .TargetAttr &&_beb .TypeAttr ==_cdg .TypeAttr {_dd =false ;
break ;};};if _dd {_fg .Rels .AddRelationship (_cdg .TargetAttr ,_cdg .TypeAttr );};};for _ ,_ec :=range docBase1 .ExtraFiles {_cdbg :=_ec .ZipPath ;_eab :=true ;for _ ,_ce :=range _fg .ExtraFiles {if _ce .ZipPath ==_cdbg {_eab =false ;break ;};};if _eab {_fg .ExtraFiles =append (_fg .ExtraFiles ,_ec );
};};return _fg ;};
2021-11-10 11:45:21 +00:00
2024-10-17 17:05:28 +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 _dc .Image ;Images []ImageRef ;ExtraFiles []ExtraFile ;TmpPath string ;};func (_gfe CustomProperties )SetPropertyAsBlob (name ,blob string ){_fag :=_gfe .getNewProperty (name );
_fag .Blob =&blob ;_gfe .setOrReplaceProperty (_fag );};
2024-05-04 18:48:06 +00:00
2024-10-17 17:05:28 +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 ){_fdg ,_ffad :=_ge .Open (path );_cded :=Image {};if _ffad !=nil {return _cded ,_f .Errorf ("\u0065\u0072\u0072or\u0020\u0072\u0065\u0061\u0064\u0069\u006e\u0067\u0020\u0069\u006d\u0061\u0067\u0065\u003a\u0020\u0025\u0073",_ffad );
};defer _fdg .Close ();_gfea ,_dbb ,_ffad :=_dc .Decode (_fdg );if _ffad !=nil {return _cded ,_f .Errorf ("\u0075n\u0061\u0062\u006c\u0065 \u0074\u006f\u0020\u0070\u0061r\u0073e\u0020i\u006d\u0061\u0067\u0065\u003a\u0020\u0025s",_ffad );};_cded .Path =path ;
_cded .Format =_dbb ;_cded .Size =_gfea .Bounds ().Size ();return _cded ,nil ;};
2024-10-17 17:05:28 +00:00
// CustomProperty contains document specific property.
// Using of this type is deprecated.
type CustomProperty struct{_ceg *_fc .CT_Property };func (_eae CustomProperties )SetPropertyAsFiletime (name string ,filetime _bb .Time ){_gg :=_eae .getNewProperty (name );_gg .Filetime =&filetime ;_eae .setOrReplaceProperty (_gg );};
2024-09-16 09:59:58 +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.
2024-10-17 17:05:28 +00:00
func (_bae Relationships )AddAutoRelationship (dt _eb .DocType ,src string ,idx int ,ctype string )Relationship {return _bae .AddRelationship (_eb .RelativeFilename (dt ,src ,ctype ,idx ),ctype );};
2021-06-16 07:10:52 +00:00
2024-10-17 17:05:28 +00:00
// GetByRelId returns a relationship with the associated relation ID.
func (_cccd Relationships )GetByRelId (idAttr string )Relationship {for _ ,_cfbg :=range _cccd ._aabd .Relationship {if _cfbg .IdAttr ==idAttr {return Relationship {_gabd :_cfbg };};};return Relationship {};};
2021-06-16 07:10:52 +00:00
2024-10-17 17:05:28 +00:00
// CustomProperties contains document specific properties.
type CustomProperties struct{_da *_fc .Properties };func (_ffa CustomProperties )setProperty (_caf *_fc .CT_Property ){_ffa .setPropertyHelper (_caf ,false )};const _gaac =30;
2024-05-04 18:48:06 +00:00
2024-10-17 17:05:28 +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 (_gcb AppProperties )Pages ()int32 {if _gcb ._agbd .Pages !=nil {return *_gcb ._agbd .Pages ;};return 0;};func (_fdbe CustomProperties )SetPropertyAsR8 (name string ,r8 float64 ){_dac :=_fdbe .getNewProperty (name );_dac .R8 =&r8 ;_fdbe .setOrReplaceProperty (_dac );
};
2024-06-20 13:33:45 +00:00
2024-10-17 17:05:28 +00:00
// Relationships represents a .rels file.
type Relationships struct{_aabd *_fb .Relationships };func (_bcc CustomProperties )SetPropertyAsBool (name string ,b bool ){_gbc :=_bcc .getNewProperty (name );_gbc .Bool =&b ;_bcc .setOrReplaceProperty (_gbc );};
2022-02-25 19:20:45 +00:00
2024-10-17 17:05:28 +00:00
// SetDescription records the description of the document.
func (_afe CoreProperties )SetDescription (s string ){if _afe ._affb .Description ==nil {_afe ._affb .Description =&_eb .XSDAny {XMLName :_dfd .Name {Local :"\u0064\u0063\u003a\u0064\u0065\u0073\u0063\u0072\u0069p\u0074\u0069\u006f\u006e"}};};_afe ._affb .Description .Data =[]byte (s );
2024-09-16 09:59:58 +00:00
};
2022-02-25 19:20:45 +00:00
2024-10-17 17:05:28 +00:00
// RemoveOverrideByIndex removes an override given a path and override index.
func (_bga ContentTypes )RemoveOverrideByIndex (path string ,indexToFind int )error {_feff :=path [0:len (path )-5];if !_be .HasPrefix (_feff ,"\u002f"){_feff ="\u002f"+_feff ;};_fbb ,_fbc :=_ba .Compile (_feff +"\u0028\u005b\u0030-\u0039\u005d\u002b\u0029\u002e\u0078\u006d\u006c");
if _fbc !=nil {return _fbc ;};_eeg :=0;_bc :=-1;for _bdb ,_cad :=range _bga ._bfa .Override {if _cced :=_fbb .FindStringSubmatch (_cad .PartNameAttr );len (_cced )> 1{if _eeg ==indexToFind {_bc =_bdb ;}else if _eeg > indexToFind {_ccb ,_ :=_bba .Atoi (_cced [1]);
_ccb --;_cad .PartNameAttr =_f .Sprintf ("\u0025\u0073\u0025\u0064\u002e\u0078\u006d\u006c",_feff ,_ccb );};_eeg ++;};};if _bc > -1{copy (_bga ._bfa .Override [_bc :],_bga ._bfa .Override [_bc +1:]);_bga ._bfa .Override =_bga ._bfa .Override [0:len (_bga ._bfa .Override )-1];
};return nil ;};
2021-08-23 20:44:48 +00:00
2024-10-17 17:05:28 +00:00
// TableStyles contains document specific properties.
type TableStyles struct{_facf *_gc .TblStyleLst };
2023-09-16 17:56:36 +00:00
2024-10-17 17:05:28 +00:00
// SetStyle assigns TableStyle to a table.
func (_efeb Table )SetStyle (style *_gc .CT_TableStyle ){if _efeb ._cgcc .TblPr ==nil {_efeb ._cgcc .TblPr =_gc .NewCT_TableProperties ();};if _efeb ._cgcc .TblPr .Choice ==nil {_efeb ._cgcc .TblPr .Choice =_gc .NewCT_TablePropertiesChoice ();};_efeb ._cgcc .TblPr .Choice .TableStyle =style ;
};func (_dgga CustomProperties )SetPropertyAsI8 (name string ,i8 int64 ){_gde :=_dgga .getNewProperty (name );_gde .I8 =&i8 ;_dgga .setOrReplaceProperty (_gde );};func (_bfgb CustomProperties )SetPropertyAsInt (name string ,i int ){_ccbae :=_bfgb .getNewProperty (name );
_fbce :=int32 (i );_ccbae .Int =&_fbce ;_bfgb .setOrReplaceProperty (_ccbae );};
2024-09-16 09:59:58 +00:00
2024-10-17 17:05:28 +00:00
// CreateCustomProperties creates the custom properties of the document.
func (_fda *DocBase )CreateCustomProperties (){_fda .CustomProperties =NewCustomProperties ();_fda .AddCustomRelationships ();};
2023-09-16 17:56:36 +00:00
2024-10-17 17:05:28 +00:00
// Hyperlink is just an appropriately configured relationship.
type Hyperlink Relationship ;
2022-06-27 19:44:23 +00:00
2024-10-17 17:05:28 +00:00
// AddOverride adds an override content type for a given path name.
func (_abgb ContentTypes )AddOverride (path ,contentType string ){if !_be .HasPrefix (path ,"\u002f"){path ="\u002f"+path ;};if _be .HasPrefix (contentType ,"\u0068\u0074\u0074\u0070"){_ee .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 _ ,_fba :=range _abgb ._bfa .Override {if _fba .PartNameAttr ==path {return ;};};_fce :=_fa .NewOverride ();_fce .PartNameAttr =path ;_fce .ContentTypeAttr =contentType ;_abgb ._bfa .Override =append (_abgb ._bfa .Override ,_fce );};func (_agca CustomProperties )SetPropertyAsStream (name string ,stream string ){_eegc :=_agca .getNewProperty (name );
_eegc .Stream =&stream ;_agca .setOrReplaceProperty (_eegc );};
2023-06-10 07:12:37 +00:00
2024-10-17 17:05:28 +00:00
// ContentStatus returns the content status of the document (e.g. "Final", "Draft")
func (_abe CoreProperties )ContentStatus ()string {if _abe ._affb .ContentStatus !=nil {return *_abe ._affb .ContentStatus ;};return "";};
2023-06-10 07:12:37 +00:00
2024-10-17 17:05:28 +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 (_aef AppProperties )Application ()string {if _aef ._agbd .Application !=nil {return *_aef ._agbd .Application ;};return "";};
2023-06-10 07:12:37 +00:00
2024-10-17 17:05:28 +00:00
// CopyOverride copies override content type for a given `path` and puts it with a path `newPath`.
func (_ac ContentTypes )CopyOverride (path ,newPath string ){if !_be .HasPrefix (path ,"\u002f"){path ="\u002f"+path ;};if !_be .HasPrefix (newPath ,"\u002f"){newPath ="\u002f"+newPath ;};for _egd :=range _ac ._bfa .Override {if _ac ._bfa .Override [_egd ].PartNameAttr ==path {_deg :=*_ac ._bfa .Override [_egd ];
_deg .PartNameAttr =newPath ;_ac ._bfa .Override =append (_ac ._bfa .Override ,&_deg );};};};
2023-06-10 07:12:37 +00:00
2024-10-17 17:05:28 +00:00
// X returns the underlying raw XML data.
func (_dged Relationships )X ()*_fb .Relationships {return _dged ._aabd };func (_edd CustomProperties )SetPropertyAsBstr (name string ,bstr string ){_gdaf :=_edd .getNewProperty (name );_gdaf .Bstr =&bstr ;_edd .setOrReplaceProperty (_gdaf );};
2023-06-10 07:12:37 +00:00
2024-10-17 17:05:28 +00:00
// X returns the inner raw content types.
func (_ddb ContentTypes )X ()*_fa .Types {return _ddb ._bfa };
2024-06-20 13:33:45 +00:00
2024-10-17 17:05:28 +00:00
// AppProperties contains properties specific to the document and the
// application that created it.
type AppProperties struct{_agbd *_bed .Properties };
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// ContentTypes is the top level "[Content_Types].xml" in a zip package.
type ContentTypes struct{_bfa *_fa .Types };
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// AddRow adds a row to a table.
func (_eeb Table )AddRow ()*TableRow {_gaf :=_gc .NewCT_TableRow ();for _bcb :=0;_bcb < len (_eeb ._cgcc .TblGrid .GridCol );_bcb ++{_gaf .Tc =append (_gaf .Tc ,_gc .NewCT_TableCell ());};_eeb ._cgcc .Tr =append (_eeb ._cgcc .Tr ,_gaf );return &TableRow {_agec :_gaf };
};
2023-07-04 11:04:03 +00:00
2024-10-17 17:05:28 +00:00
// Title returns the Title of the document
func (_fcg CoreProperties )Title ()string {if _fcg ._affb .Title !=nil {return string (_fcg ._affb .Title .Data );};return "";};
2023-06-10 07:12:37 +00:00
2024-10-17 17:05:28 +00:00
// NewCustomProperties constructs a new CustomProperties.
func NewCustomProperties ()CustomProperties {return CustomProperties {_da :_fc .NewProperties ()}};func (_efe CustomProperties )SetPropertyAsI1 (name string ,i1 int8 ){_ffea :=_efe .getNewProperty (name );_ffea .I1 =&i1 ;_efe .setOrReplaceProperty (_ffea );
};
2022-09-02 11:46:53 +00:00
2024-10-17 17:05:28 +00:00
// NewAppProperties constructs a new AppProperties.
func NewAppProperties ()AppProperties {_de :=AppProperties {_agbd :_bed .NewProperties ()};_de .SetCompany ("\u0046\u006f\u0078\u0079\u0055\u0074\u0069\u006c\u0073\u0020\u0065\u0068\u0066");_de .SetApplication ("g\u0069\u0074\u0068\u0075\u0062\u002ec\u006f\u006d\u002f\u0075\u006e\u0069\u0064\u006f\u0063/\u0075\u006e\u0069o\u0066f\u0069\u0063\u0065");
_de .SetDocSecurity (0);_de .SetLinksUpToDate (false );var _ebb ,_cce ,_ece int64 ;_f .Sscanf (Version ,"\u0025\u0064\u002e\u0025\u0064\u002e\u0025\u0064",&_ebb ,&_cce ,&_ece );_cbec :=float64 (_ebb )+float64 (_cce )/10000.0;_de .SetApplicationVersion (_f .Sprintf ("\u0025\u0030\u0037\u002e\u0034\u0066",_cbec ));
return _de ;};
2022-09-02 11:46:53 +00:00
2024-10-17 17:05:28 +00:00
// Target returns the target (path) of a relationship.
func (_aaa Relationship )Target ()string {return _aaa ._gabd .TargetAttr };
2022-09-02 11:46:53 +00:00
2024-10-17 17:05:28 +00:00
// Company returns the name of the company that created the document.
// For unioffice created documents, it defaults to github.com/unidoc/unioffice
func (_fdc AppProperties )Company ()string {if _fdc ._agbd .Company !=nil {return *_fdc ._agbd .Company ;};return "";};func (_bdag CustomProperties )SetPropertyAsOblob (name ,oblob string ){_ddce :=_bdag .getNewProperty (name );_ddce .Oblob =&oblob ;_bdag .setOrReplaceProperty (_ddce );
};
2022-12-06 11:56:49 +00:00
2024-10-17 17:05:28 +00:00
// WriteExtraFiles writes the extra files to the zip package.
func (_gca *DocBase )WriteExtraFiles (z *_e .Writer )error {for _ ,_gedc :=range _gca .ExtraFiles {if _cagb :=_cg .AddFileFromDisk (z ,_gedc .ZipPath ,_gedc .DiskPath );_cagb !=nil {return _cagb ;};};return nil ;};
2023-08-06 17:57:53 +00:00
2024-10-17 17:05:28 +00:00
// Description returns the description of the document
func (_cdbe CoreProperties )Description ()string {if _cdbe ._affb .Description !=nil {return string (_cdbe ._affb .Description .Data );};return "";};const _ffg =15;
2022-12-06 11:56:49 +00:00
2024-10-17 17:05:28 +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 ){_cddf :=Image {};_ebc ,_acc :=_dfe .Open (path );if _acc !=nil {return _cddf ,_f .Errorf ("\u0065\u0072\u0072or\u0020\u0072\u0065\u0061\u0064\u0069\u006e\u0067\u0020\u0069\u006d\u0061\u0067\u0065\u003a\u0020\u0025\u0073",_acc );
};defer _ebc .Close ();_dfb ,_ececg ,_acc :=_dc .Decode (_ebc );if _acc !=nil {return _cddf ,_f .Errorf ("\u0075n\u0061\u0062\u006c\u0065 \u0074\u006f\u0020\u0070\u0061r\u0073e\u0020i\u006d\u0061\u0067\u0065\u003a\u0020\u0025s",_acc );};_cddf .Path =path ;
_cddf .Format =_ececg ;_cddf .Size =_dfb .Bounds ().Size ();return _cddf ,nil ;};
2024-10-17 17:05:28 +00:00
// X returns the inner wrapped XML type.
func (_cde AppProperties )X ()*_bed .Properties {return _cde ._agbd };
2022-12-06 11:56:49 +00:00
2024-10-17 17:05:28 +00:00
// NewContentTypes returns a wrapper around a newly constructed content-types.
func NewContentTypes ()ContentTypes {_dgf :=ContentTypes {_bfa :_fa .NewTypes ()};_dgf .AddDefault ("\u0078\u006d\u006c","\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u0078\u006d\u006c");_dgf .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");
_dgf .AddDefault ("\u0070\u006e\u0067","\u0069m\u0061\u0067\u0065\u002f\u0070\u006eg");_dgf .AddDefault ("\u006a\u0070\u0065\u0067","\u0069\u006d\u0061\u0067\u0065\u002f\u006a\u0070\u0065\u0067");_dgf .AddDefault ("\u006a\u0070\u0067","\u0069m\u0061\u0067\u0065\u002f\u006a\u0070g");
_dgf .AddDefault ("\u0077\u006d\u0066","i\u006d\u0061\u0067\u0065\u002f\u0078\u002d\u0077\u006d\u0066");_dgf .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");
_dgf .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 _dgf ;};
2024-06-20 13:33:45 +00:00
2024-10-17 17:05:28 +00:00
// ImageFromBytes returns an Image struct for an in-memory image. You can also
// construct an Image directly if the file and size are known.
func ImageFromBytes (data []byte )(Image ,error ){_bccd :=Image {};_fcb ,_edg ,_egbe :=_dc .Decode (_b .NewReader (data ));if _egbe !=nil {return _bccd ,_f .Errorf ("\u0075n\u0061\u0062\u006c\u0065 \u0074\u006f\u0020\u0070\u0061r\u0073e\u0020i\u006d\u0061\u0067\u0065\u003a\u0020\u0025s",_egbe );
};_bccd .Data =&data ;_bccd .Format =_edg ;_bccd .Size =_fcb .Bounds ().Size ();return _bccd ,nil ;};
2023-03-01 18:42:44 +00:00
2024-10-17 17:05:28 +00:00
// EnsureOverride ensures that an override for the given path exists, adding it if necessary
func (_gec ContentTypes )EnsureOverride (path ,contentType string ){for _ ,_ced :=range _gec ._bfa .Override {if _ced .PartNameAttr ==path {if _be .HasPrefix (contentType ,"\u0068\u0074\u0074\u0070"){_ee .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 );
};_ced .ContentTypeAttr =contentType ;return ;};};_gec .AddOverride (path ,contentType );};
2023-03-01 18:42:44 +00:00
2024-10-17 17:05:28 +00:00
// X returns the inner wrapped XML type.
func (_dcb CoreProperties )X ()*_bag .CoreProperties {return _dcb ._affb };
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// SetWidth sets column width, see measurement package.
func (_geba TableCol )SetWidth (m _cf .Distance ){_faa :=_cf .ToEMU (float64 (m ));_geba ._caae .WAttr =_gc .ST_Coordinate {ST_CoordinateUnqualified :&_faa };};
2024-05-22 00:21:11 +00:00
2024-09-16 09:59:58 +00:00
// SetOffsetX sets horizontal offset of a table in distance units (see measurement package).
2024-10-17 17:05:28 +00:00
func (_fgg Table )SetOffsetX (offX float64 ){if _fgg ._bcfa .Off ==nil {_fgg ._bcfa .Off =_gc .NewCT_Point2D ();_cfc :=int64 (0);_fgg ._bcfa .Off .YAttr =_gc .ST_Coordinate {ST_CoordinateUnqualified :&_cfc };};_bcec :=_cf .ToEMU (offX );_fgg ._bcfa .Off .XAttr =_gc .ST_Coordinate {ST_CoordinateUnqualified :&_bcec };
2024-09-16 09:59:58 +00:00
};
2022-12-06 11:56:49 +00:00
2024-10-17 17:05:28 +00:00
// SetApplication sets the name of the application that created the document.
func (_bab AppProperties )SetApplication (s string ){_bab ._agbd .Application =&s };
2024-06-20 13:33:45 +00:00
2024-10-17 17:05:28 +00:00
// Created returns the time that the document was created.
func (_agce CoreProperties )Created ()_bb .Time {return _bbac (_agce ._affb .Created )};
2023-03-01 18:42:44 +00:00
2024-10-17 17:05:28 +00:00
// X returns the inner wrapped XML type of CustomProperty.
func (_bcg CustomProperty )X ()*_fc .CT_Property {return _bcg ._ceg };
2023-05-26 09:49:04 +00:00
2024-10-17 17:05:28 +00:00
// Format returns the format of the underlying image
func (_dgb ImageRef )Format ()string {return _dgb ._cgc .Format };
2023-05-26 09:49:04 +00:00
2024-10-17 17:05:28 +00:00
// SetLanguage records the language of the document.
func (_dcfc CoreProperties )SetLanguage (s string ){_dcfc ._affb .Language =&_eb .XSDAny {XMLName :_dfd .Name {Local :"d\u0063\u003a\u006c\u0061\u006e\u0067\u0075\u0061\u0067\u0065"}};_dcfc ._affb .Language .Data =[]byte (s );};
2023-08-06 17:57:53 +00:00
2024-10-17 17:05:28 +00:00
// Table represents a table in the document.
type Table struct{_cgcc *_gc .Tbl ;_bcfa *_gc .CT_Transform2D ;};func (_eag CustomProperties )setOrReplaceProperty (_agf *_fc .CT_Property ){_eag .setPropertyHelper (_agf ,true );};
2023-08-06 17:57:53 +00:00
2024-10-17 17:05:28 +00:00
// Size returns the size of an image
func (_ecgc ImageRef )Size ()_dc .Point {return _ecgc ._cgc .Size };
2024-02-17 03:37:07 +00:00
2024-10-17 17:05:28 +00:00
// NewRelationships creates a new relationship wrapper.
func NewRelationships ()Relationships {return Relationships {_aabd :_fb .NewRelationships ()}};func (_bde CustomProperties )SetPropertyAsUint (name string ,ui uint ){_geb :=_bde .getNewProperty (name );_ga :=uint32 (ui );_geb .Uint =&_ga ;_bde .setOrReplaceProperty (_geb );
};
2024-02-17 03:37:07 +00:00
2024-10-17 17:05:28 +00:00
// Relationship is a relationship within a .rels file.
type Relationship struct{_gabd *_fb .Relationship };
2024-02-17 03:37:07 +00:00
2024-10-17 17:05:28 +00:00
// Properties returns table properties.
func (_dfec Table )Grid ()*_gc .CT_TableGrid {return _dfec ._cgcc .TblGrid };var _gab =_df .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");
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// Rows returns all table rows.
func (_ccbaa Table )Rows ()[]*TableRow {_cdbec :=_ccbaa ._cgcc .Tr ;_cge :=[]*TableRow {};for _ ,_eceb :=range _cdbec {_cge =append (_cge ,&TableRow {_agec :_eceb });};return _cge ;};
2024-07-28 07:48:26 +00:00
2024-10-17 17:05:28 +00:00
// AddDefault registers a default content type for a given file extension.
func (_ceb ContentTypes )AddDefault (fileExtension string ,contentType string ){fileExtension =_be .ToLower (fileExtension );for _ ,_afc :=range _ceb ._bfa .Default {if _afc .ExtensionAttr ==fileExtension {return ;};};_cac :=_fa .NewDefault ();_cac .ExtensionAttr =fileExtension ;
_cac .ContentTypeAttr =contentType ;_ceb ._bfa .Default =append (_ceb ._bfa .Default ,_cac );};func (_abgbf CustomProperties )SetPropertyAsCy (name string ,cy string ){_aab :=_abgbf .getNewProperty (name );_aab .Cy =&cy ;_abgbf .setOrReplaceProperty (_aab );
};func (_ecec CustomProperties )SetPropertyAsLpwstr (name string ,lpwstr string ){_cfb :=_ecec .getNewProperty (name );_cfb .Lpwstr =&lpwstr ;_ecec .setOrReplaceProperty (_cfb );};
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// TblStyle returns the TblStyle property.
func (_gfb TableStyles )TblStyle ()[]*_gc .CT_TableStyle {return _gfb ._facf .TblStyle };
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// X returns the inner wrapped XML type.
func (_gcfa Relationship )X ()*_fb .Relationship {return _gcfa ._gabd };
2024-02-17 03:37:07 +00:00
2024-10-17 17:05:28 +00:00
// Properties returns table properties.
func (_bac Table )Properties ()*_gc .CT_TableProperties {return _bac ._cgcc .TblPr };
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// ID returns the ID of a relationship.
func (_bgd Relationship )ID ()string {return _bgd ._gabd .IdAttr };
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// Type returns the type of a relationship.
func (_aba Relationship )Type ()string {return _aba ._gabd .TypeAttr };
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// IsEmpty returns true if there are no relationships.
func (_fab Relationships )IsEmpty ()bool {return _fab ._aabd ==nil ||len (_fab ._aabd .Relationship )==0;};func (_dcfd CustomProperties )SetPropertyAsDecimal (name string ,decimal float64 ){_aec :=_dcfd .getNewProperty (name );_aec .Decimal =&decimal ;
_dcfd .setOrReplaceProperty (_aec );};
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// SetCreated sets the time that the document was created.
func (_ege CoreProperties )SetCreated (t _bb .Time ){_ege ._affb .Created =_bbg (t ,"\u0064c\u0074e\u0072\u006d\u0073\u003a\u0063\u0072\u0065\u0061\u0074\u0065\u0064");};
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// Category returns the category of the document
func (_dbg CoreProperties )Category ()string {if _dbg ._affb .Category !=nil {return *_dbg ._affb .Category ;};return "";};
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// RelID returns the relationship ID.
func (_ebf ImageRef )RelID ()string {return _ebf ._adb };
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// SetLinksUpToDate sets the links up to date flag.
func (_affe AppProperties )SetLinksUpToDate (v bool ){_affe ._agbd .LinksUpToDate =_eb .Bool (v )};
2024-02-17 03:37:07 +00:00
2024-10-17 17:05:28 +00:00
// Data returns the data of an image file, if any.
func (_afcg ImageRef )Data ()*[]byte {return _afcg ._cgc .Data };func (_bad CustomProperties )SetPropertyAsEmpty (name string ){_agbe :=_bad .getNewProperty (name );_agbe .Empty =_c .NewEmpty ();_bad .setOrReplaceProperty (_agbe );};
2024-02-17 03:37:07 +00:00
2024-10-17 17:05:28 +00:00
// GetOrCreateCustomProperties returns the custom properties of the document (and if they not exist yet, creating them first).
func (_gdf *DocBase )GetOrCreateCustomProperties ()CustomProperties {if _gdf .CustomProperties .X ()==nil {_gdf .CreateCustomProperties ();};return _gdf .CustomProperties ;};
2023-03-01 18:42:44 +00:00
2024-10-17 17:05:28 +00:00
// Target returns the target attrubute of the image reference (a path where the image file is located in the document structure).
func (_fdd *ImageRef )Target ()string {return _fdd ._fcd };func (_eaef TableRow )addCell ()*_gc .CT_TableCell {_dfbe :=_gc .NewCT_TableCell ();_eaef ._agec .Tc =append (_eaef ._agec .Tc ,_dfbe );return _dfbe ;};
2023-03-01 18:42:44 +00:00
2024-10-17 17:05:28 +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 {_cgc :img ,_dge :d ,_dbdf :rels };};
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// AddCol adds a column to a table.
func (_cdce Table )AddCol ()*TableCol {_eaee :=_gc .NewCT_TableCol ();_cdce ._cgcc .TblGrid .GridCol =append (_cdce ._cgcc .TblGrid .GridCol ,_eaee );for _ ,_fbe :=range _cdce ._cgcc .Tr {_fdce :=_gc .NewCT_TableCell ();_fbe .Tc =append (_fbe .Tc ,_fdce );
};return &TableCol {_caae :_eaee };};func (_agbb CustomProperties )SetPropertyAsDate (name string ,date _bb .Time ){date =date .UTC ();_fff ,_dcba ,_baa :=date .Date ();_eea ,_fffg ,_ecgg :=date .Clock ();_ead :=_bb .Date (_fff ,_dcba ,_baa ,_eea ,_fffg ,_ecgg ,0,_bb .UTC );
_eeab :=_agbb .getNewProperty (name );_eeab .Filetime =&_ead ;_agbb .setOrReplaceProperty (_eeab );};
2024-09-16 09:59:58 +00:00
2024-10-17 17:05:28 +00:00
// AddRelationship adds a relationship.
func (_dadd Relationships )AddRelationship (target ,ctype string )Relationship {if !_be .HasPrefix (ctype ,"\u0068t\u0074\u0070\u003a\u002f\u002f"){_ee .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 );
};_edge :=_fb .NewRelationship ();_dcbb :=len (_dadd ._aabd .Relationship )+1;_dcd :=map[string ]struct{}{};for _ ,_acdb :=range _dadd ._aabd .Relationship {_dcd [_acdb .IdAttr ]=struct{}{};};for _ ,_dfa :=_dcd [_f .Sprintf ("\u0072\u0049\u0064%\u0064",_dcbb )];
_dfa ;_ ,_dfa =_dcd [_f .Sprintf ("\u0072\u0049\u0064%\u0064",_dcbb )]{_dcbb ++;};_edge .IdAttr =_f .Sprintf ("\u0072\u0049\u0064%\u0064",_dcbb );_edge .TargetAttr =target ;_edge .TypeAttr =ctype ;_dadd ._aabd .Relationship =append (_dadd ._aabd .Relationship ,_edge );
return Relationship {_gabd :_edge };};
2023-03-01 18:42:44 +00:00
2024-10-17 17:05:28 +00:00
// GetImageBytesByTarget returns Image object with Data bytes read from its target.
func (_feg *DocBase )GetImageBytesByTarget (target string )(Image ,error ){if target !=""{target ="\u0077\u006f\u0072d\u002f"+target ;for _ ,_aebf :=range _feg .Images {if _aebf .Target ()==target {if _be .ToLower (_aebf .Format ())!="\u0065\u006d\u0066"{return ImageFromStorage (_aebf .Path ());
};return Image {Path :_aebf .Path (),Format :_aebf .Format ()},nil ;};};};return Image {},_gab ;};
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// GetPropertyByName returns a custom property selected by it's name.
func (_dad CustomProperties )GetPropertyByName (name string )CustomProperty {_ffd :=_dad ._da .Property ;for _ ,_gf :=range _ffd {if *_gf .NameAttr ==name {return CustomProperty {_ceg :_gf };};};return CustomProperty {};};const _gedf =10;const _bcgb =17;
func (_cgb CustomProperties )SetPropertyAsOstorage (name string ,ostorage string ){_fbbg :=_cgb .getNewProperty (name );_fbbg .Ostorage =&ostorage ;_cgb .setOrReplaceProperty (_fbbg );};
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// Relationships returns a slice of all of the relationships.
func (_fgbc Relationships )Relationships ()[]Relationship {_bgaf :=[]Relationship {};for _ ,_aebe :=range _fgbc ._aabd .Relationship {_bgaf =append (_bgaf ,Relationship {_gabd :_aebe });};return _bgaf ;};
2023-04-15 17:27:31 +00:00
2024-10-17 17:05:28 +00:00
// EnsureDefault esnures that an extension and default content type exist,
// adding it if necessary.
func (_ddda ContentTypes )EnsureDefault (ext ,contentType string ){ext =_be .ToLower (ext );for _ ,_cag :=range _ddda ._bfa .Default {if _cag .ExtensionAttr ==ext {_cag .ContentTypeAttr =contentType ;return ;};};_caa :=&_fa .Default {};_caa .ContentTypeAttr =contentType ;
_caa .ExtensionAttr =ext ;_ddda ._bfa .Default =append (_ddda ._bfa .Default ,_caa );};
2023-05-26 09:49:04 +00:00
2024-10-17 17:05:28 +00:00
// SetTitle records the title of the document.
func (_ace CoreProperties )SetTitle (s string ){if _ace ._affb .Title ==nil {_ace ._affb .Title =&_eb .XSDAny {XMLName :_dfd .Name {Local :"\u0064\u0063\u003a\u0074\u0069\u0074\u006c\u0065"}};};_ace ._affb .Title .Data =[]byte (s );};func init (){_fe .SetAsStorage ()};
func (_fgc CustomProperties )SetPropertyAsVector (name string ,vector *_c .Vector ){_cff :=_fgc .getNewProperty (name );_cff .Vector =vector ;_fgc .setOrReplaceProperty (_cff );};func (_ged CustomProperties )SetPropertyAsI4 (name string ,i4 int32 ){_fbd :=_ged .getNewProperty (name );
_fbd .I4 =&i4 ;_ged .setOrReplaceProperty (_fbd );};
2023-08-06 17:57:53 +00:00
2024-10-17 17:05:28 +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 (_agc AppProperties )SetApplicationVersion (s string ){_agc ._agbd .AppVersion =&s };
2023-12-12 23:20:29 +00:00
2024-10-17 17:05:28 +00:00
// AddCustomRelationships adds relationships related to custom properties to the document.
func (_ddbf *DocBase )AddCustomRelationships (){_ddbf .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");
_ddbf .Rels .AddRelationship ("\u0064\u006f\u0063\u0050ro\u0070\u0073\u002f\u0063\u0075\u0073\u0074\u006f\u006d\u002e\u0078\u006d\u006c",_eb .CustomPropertiesType );};
2023-12-12 23:20:29 +00:00
2024-10-17 17:05:28 +00:00
// SetDocSecurity sets the document security flag.
func (_fdb AppProperties )SetDocSecurity (v int32 ){_fdb ._agbd .DocSecurity =_eb .Int32 (v )};
2024-05-08 13:54:39 +00:00
2024-10-17 17:05:28 +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 (_efd ImageRef )RelativeHeight (w _cf .Distance )_cf .Distance {_edea :=float64 (_efd .Size ().Y )/float64 (_efd .Size ().X );return w *_cf .Distance (_edea );};
2024-05-08 13:54:39 +00:00
2024-10-17 17:05:28 +00:00
// Author returns the author of the document
func (_bfd CoreProperties )Author ()string {if _bfd ._affb .Creator !=nil {return string (_bfd ._affb .Creator .Data );};return "";};
2023-12-12 23:20:29 +00:00
2024-10-17 17:05:28 +00:00
// Path returns the path to an image file, if any.
func (_ccc ImageRef )Path ()string {return _ccc ._cgc .Path };
2024-05-04 18:48:06 +00:00
2024-07-28 07:48:26 +00:00
// X returns the inner wrapped XML type.
2024-10-17 17:05:28 +00:00
func (_fbg Table )X ()*_gc .Tbl {return _fbg ._cgcc };var ReleasedAt =_bb .Date (_gaa ,_gedf ,_bcgb ,_ffg ,_gaac ,0,0,_bb .UTC );
2024-05-04 18:48:06 +00:00
2024-10-17 17:05:28 +00:00
// SetPages sets the pages count of the document.
func (_abg AppProperties )SetPages (n int32 ){_abg ._agbd .Pages =&n };
2024-05-04 18:48:06 +00:00
2024-10-17 17:05:28 +00:00
// NewTableWithXfrm makes a new table with a pointer to its parent Xfrm for changing its offset and size.
func NewTableWithXfrm (xfrm *_gc .CT_Transform2D )*Table {_fcef :=_gc .NewTbl ();_fcef .TblPr =_gc .NewCT_TableProperties ();return &Table {_cgcc :_fcef ,_bcfa :xfrm };};
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// NewTableStyles constructs a new TableStyles.
func NewTableStyles ()TableStyles {return TableStyles {_facf :_gc .NewTblStyleLst ()}};
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// NewTheme constructs a new theme.
func NewTheme ()Theme {return Theme {_gc .NewTheme ()}};
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// SetContentStatus records the content status of the document.
func (_bcd CoreProperties )SetContentStatus (s string ){_bcd ._affb .ContentStatus =&s };
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// GetTargetByRelId returns a target path with the associated relation ID.
func (_cgd Relationships )GetTargetByRelId (idAttr string )string {for _ ,_add :=range _cgd ._aabd .Relationship {if _add .IdAttr ==idAttr {return _add .TargetAttr ;};};return "";};
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// AddHyperlink adds an external hyperlink relationship.
func (_acfb Relationships )AddHyperlink (target string )Hyperlink {_abgd :=_acfb .AddRelationship (target ,_eb .HyperLinkType );_abgd ._gabd .TargetModeAttr =_fb .ST_TargetModeExternal ;return Hyperlink (_abgd );};
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// SetTarget set the target (path) of a relationship.
func (_fae Relationship )SetTarget (s string ){_fae ._gabd .TargetAttr =s };
// X returns the inner wrapped XML type.
func (_edac Theme )X ()*_gc .Theme {return _edac ._ddge };
// 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 (_adf *ImageRef )SetTarget (target string ){_adf ._fcd =target };
2024-05-22 00:21:11 +00:00
2024-07-28 07:48:26 +00:00
// Modified returns the time that the document was modified.
2024-10-17 17:05:28 +00:00
func (_cgf CoreProperties )Modified ()_bb .Time {return _bbac (_cgf ._affb .Modified )};
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// Theme is a drawingml theme.
type Theme struct{_ddge *_gc .Theme };
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// TableCol represents a column in a table.
type TableCol struct{_caae *_gc .CT_TableCol };
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// ImageRef is a reference to an image within a document.
type ImageRef struct{_dge *DocBase ;_dbdf Relationships ;_cgc Image ;_adb string ;_fcd string ;};func (_ad CustomProperties )SetPropertyAsError (name string ,error string ){_ecb :=_ad .getNewProperty (name );_ecb .Error =&error ;_ad .setOrReplaceProperty (_ecb );
};
2024-05-22 00:21:11 +00:00
2024-10-17 17:05:28 +00:00
// FindRIDForN returns the relationship ID for the i'th relationship of type t.
func (_bcca Relationships )FindRIDForN (i int ,t string )string {for _ ,_daf :=range _bcca ._aabd .CT_Relationships .Relationship {if _daf .TypeAttr ==t {if i ==0{return _daf .IdAttr ;};i --;};};return "";};func UtcTimeFormat (t _bb .Time )string {return t .Format (_aee )+"\u0020\u0055\u0054\u0043"};
func (_dag Relationship )String ()string {return _f .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",_dag .ID (),_dag .Target (),_dag .Type ());
};func (_bce CustomProperties )setPropertyHelper (_ecg *_fc .CT_Property ,_bdf bool ){_cagg :=_bce .GetPropertyByName (*_ecg .NameAttr );if (_cagg ==CustomProperty {}){_bce ._da .Property =append (_bce ._da .Property ,_ecg );}else if _bdf {_ecg .FmtidAttr =_cagg ._ceg .FmtidAttr ;
if _cagg ._ceg .PidAttr ==0{_ecg .PidAttr =_cagg ._ceg .PidAttr ;};_ecg .LinkTargetAttr =_cagg ._ceg .LinkTargetAttr ;*_cagg ._ceg =*_ecg ;};};
2024-09-16 09:59:58 +00:00
2024-10-17 17:05:28 +00:00
// SetOffsetY sets vertical offset of a table in distance units (see measurement package).
func (_bfacc Table )SetOffsetY (offY float64 ){if _bfacc ._bcfa .Off ==nil {_bfacc ._bcfa .Off =_gc .NewCT_Point2D ();_gabf :=int64 (0);_bfacc ._bcfa .Off .XAttr =_gc .ST_Coordinate {ST_CoordinateUnqualified :&_gabf };};_fdbc :=_cf .ToEMU (offY );_bfacc ._bcfa .Off .YAttr =_gc .ST_Coordinate {ST_CoordinateUnqualified :&_fdbc };
};func (_agff CustomProperties )SetPropertyAsUi8 (name string ,ui8 uint64 ){_aed :=_agff .getNewProperty (name );_aed .Ui8 =&ui8 ;_agff .setOrReplaceProperty (_aed );};
2024-09-16 09:59:58 +00:00
2024-10-17 17:05:28 +00:00
// SetCategory records the category of the document.
func (_dcf CoreProperties )SetCategory (s string ){_dcf ._affb .Category =&s };func (_badf CustomProperties )SetPropertyAsClsid (name string ,clsid string ){_fgb :=_badf .getNewProperty (name );_fgb .Clsid =&clsid ;_badf .setOrReplaceProperty (_fgb );};
2024-09-16 09:59:58 +00:00
2024-07-28 07:48:26 +00:00
2024-10-17 17:05:28 +00:00
// X returns the inner wrapped XML type.
func (_eaa CustomProperties )X ()*_fc .Properties {return _eaa ._da };
2024-09-16 09:59:58 +00:00
2024-10-17 17:05:28 +00:00
// Remove removes an existing relationship.
func (_cec Relationships )Remove (rel Relationship )bool {for _cbb ,_fdf :=range _cec ._aabd .Relationship {if _fdf ==rel ._gabd {copy (_cec ._aabd .Relationship [_cbb :],_cec ._aabd .Relationship [_cbb +1:]);_cec ._aabd .Relationship =_cec ._aabd .Relationship [0:len (_cec ._aabd .Relationship )-1];
return true ;};};return false ;};