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.
2022-12-06 11:56:49 +00:00
package common ;import (_ff "archive/zip";_af "bytes";_ee "encoding/xml";_da "errors";_aa "fmt";_gc "github.com/unidoc/unioffice";_ab "github.com/unidoc/unioffice/common/logger";_ffba "github.com/unidoc/unioffice/common/tempstorage";_gd "github.com/unidoc/unioffice/common/tempstorage/diskstore";_ffb "github.com/unidoc/unioffice/measurement";_fe "github.com/unidoc/unioffice/schema/soo/dml";_fa "github.com/unidoc/unioffice/schema/soo/ofc/custom_properties";_fg "github.com/unidoc/unioffice/schema/soo/ofc/docPropsVTypes";_dad "github.com/unidoc/unioffice/schema/soo/ofc/extended_properties";_c "github.com/unidoc/unioffice/schema/soo/pkg/content_types";_bc "github.com/unidoc/unioffice/schema/soo/pkg/metadata/core_properties";_aae "github.com/unidoc/unioffice/schema/soo/pkg/relationships";_g "github.com/unidoc/unioffice/zippkg";_e "image";_ "image/gif";_ "image/jpeg";_ "image/png";_ag "os";_d "reflect";_ac "regexp";_ec "strconv";_eb "strings";_ef "time";);
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// GetTargetByRelIdAndType returns a target path with the associated relation ID.
func (_geff Relationships )GetTargetByRelIdAndType (idAttr string ,typeAttr string )string {for _ ,_fgg :=range _geff ._feec .Relationship {if _fgg .IdAttr ==idAttr &&_fgg .TypeAttr ==typeAttr {return _fgg .TargetAttr ;};};return "";};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// TableStyles contains document specific properties.
type TableStyles struct{_cff *_fe .TblStyleLst };
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// Type returns the type of a relationship.
func (_dcdc Relationship )Type ()string {return _dcdc ._dge .TypeAttr };func (_fbe CustomProperties )setPropertyHelper (_cgb *_fa .CT_Property ,_cab bool ){_ecd :=_fbe .GetPropertyByName (*_cgb .NameAttr );if (_ecd ==CustomProperty {}){_fbe ._ebc .Property =append (_fbe ._ebc .Property ,_cgb );}else if _cab {_cgb .FmtidAttr =_ecd ._dcf .FmtidAttr ;if _ecd ._dcf .PidAttr ==0{_cgb .PidAttr =_ecd ._dcf .PidAttr ;};_cgb .LinkTargetAttr =_ecd ._dcf .LinkTargetAttr ;*_ecd ._dcf =*_cgb ;};};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// Data returns the data of an image file, if any.
func (_acg ImageRef )Data ()*[]byte {return _acg ._ebee .Data };
2020-10-12 13:59:12 +00:00
2022-12-06 11:56:49 +00:00
// AddDefault registers a default content type for a given file extension.
func (_gde ContentTypes )AddDefault (fileExtension string ,contentType string ){fileExtension =_eb .ToLower (fileExtension );for _ ,_de :=range _gde ._efd .Default {if _de .ExtensionAttr ==fileExtension &&_de .ContentTypeAttr ==contentType {return ;};};_cce :=_c .NewDefault ();_cce .ExtensionAttr =fileExtension ;_cce .ContentTypeAttr =contentType ;_gde ._efd .Default =append (_gde ._efd .Default ,_cce );};
2020-10-12 13:59:12 +00:00
2022-12-06 11:56:49 +00:00
// Cells returns an array of row cells.
func (_ggfg TableRow )Cells ()[]*_fe .CT_TableCell {return _ggfg ._bgag .Tc };
2020-10-12 13:59:12 +00:00
2022-12-06 11:56:49 +00:00
// Target returns the target (path) of a relationship.
func (_caca Relationship )Target ()string {return _caca ._dge .TargetAttr };
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// SetCompany sets the name of the company that created the document.
func (_gbc AppProperties )SetCompany (s string ){_gbc ._dgg .Company =&s };func (_daf CustomProperties )SetPropertyAsUi2 (name string ,ui2 uint16 ){_afe :=_daf .getNewProperty (name );_afe .Ui2 =&ui2 ;_daf .setOrReplaceProperty (_afe );};func (_bca CustomProperties )SetPropertyAsDate (name string ,date _ef .Time ){date =date .UTC ();_dcd ,_ggab ,_cdd :=date .Date ();_cfa ,_fdd ,_gfe :=date .Clock ();_adba :=_ef .Date (_dcd ,_ggab ,_cdd ,_cfa ,_fdd ,_gfe ,0,_ef .UTC );_gdee :=_bca .getNewProperty (name );_gdee .Filetime =&_adba ;_bca .setOrReplaceProperty (_gdee );};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +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 (_ad AppProperties )Company ()string {if _ad ._dgg .Company !=nil {return *_ad ._dgg .Company ;};return "";};func (_dggf CustomProperties )SetPropertyAsI4 (name string ,i4 int32 ){_abca :=_dggf .getNewProperty (name );_abca .I4 =&i4 ;_dggf .setOrReplaceProperty (_abca );};
2021-07-30 17:03:26 +00:00
2022-12-06 11:56:49 +00:00
// SetAuthor records the author of the document.
func (_gcd CoreProperties )SetAuthor (s string ){if _gcd ._gdb .Creator ==nil {_gcd ._gdb .Creator =&_gc .XSDAny {XMLName :_ee .Name {Local :"\u0064\u0063\u003a\u0063\u0072\u0065\u0061\u0074\u006f\u0072"}};};_gcd ._gdb .Creator .Data =[]byte (s );};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// CreateCustomProperties creates the custom properties of the document.
func (_gdd *DocBase )CreateCustomProperties (){_gdd .CustomProperties =NewCustomProperties ();_gdd .AddCustomRelationships ();};func (_fgf CustomProperties )SetPropertyAsEmpty (name string ){_adg :=_fgf .getNewProperty (name );_adg .Empty =_fg .NewEmpty ();_fgf .setOrReplaceProperty (_adg );};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// ImageRef is a reference to an image within a document.
type ImageRef struct{_ccefa *DocBase ;_ebg Relationships ;_ebee Image ;_fgfe string ;_afg string ;};func (_bea CustomProperties )SetPropertyAsR8 (name string ,r8 float64 ){_egcfb :=_bea .getNewProperty (name );_egcfb .R8 =&r8 ;_bea .setOrReplaceProperty (_egcfb );};func (_ade CustomProperties )SetPropertyAsInt (name string ,i int ){_bdg :=_ade .getNewProperty (name );_bdgc :=int32 (i );_bdg .Int =&_bdgc ;_ade .setOrReplaceProperty (_bdg );};
2021-09-22 16:41:01 +00:00
2022-12-06 11:56:49 +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 (_bgc *DocBase )AddExtraFileFromZip (f *_ff .File )error {_fcb ,_dfe :=_g .ExtractToDiskTmp (f ,_bgc .TmpPath );if _dfe !=nil {return _aa .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",_dfe );};_bgc .ExtraFiles =append (_bgc .ExtraFiles ,ExtraFile {ZipPath :f .Name ,DiskPath :_fcb });return nil ;};func (_edbd CustomProperties )SetPropertyAsNull (name string ){_dbb :=_edbd .getNewProperty (name );_dbb .Null =_fg .NewNull ();_edbd .setOrReplaceProperty (_dbb );};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// Relationship is a relationship within a .rels file.
type Relationship struct{_dge *_aae .Relationship };
2020-10-12 13:59:12 +00:00
2022-12-06 11:56:49 +00:00
// SetOffsetY sets vertical offset of a table in distance units (see measurement package).
func (_eede Table )SetOffsetY (offY float64 ){if _eede ._dfg .Off ==nil {_eede ._dfg .Off =_fe .NewCT_Point2D ();_dca :=int64 (0);_eede ._dfg .Off .XAttr =_fe .ST_Coordinate {ST_CoordinateUnqualified :&_dca };};_debb :=_ffb .ToEMU (offY );_eede ._dfg .Off .YAttr =_fe .ST_Coordinate {ST_CoordinateUnqualified :&_debb };};
2022-02-05 13:05:36 +00:00
2022-12-06 11:56:49 +00:00
// Append appends DocBase part of an office document to another DocBase.
func (_eg DocBase )Append (docBase1 DocBase )DocBase {_ece :=docBase1 .ContentTypes .X ();for _ ,_fec :=range _ece .Default {_eg .ContentTypes .AddDefault (_fec .ExtensionAttr ,_fec .ContentTypeAttr );};for _ ,_efe :=range _ece .Override {_eg .ContentTypes .AddOverride (_efe .PartNameAttr ,_efe .ContentTypeAttr );};_dd :=_eg .AppProperties .X ();_df :=docBase1 .AppProperties .X ();if _dd .Pages !=nil {if _df .Pages !=nil {*_dd .Pages +=*_df .Pages ;};}else if _df .Pages !=nil {_dd .Pages =_df .Pages ;};if _dd .Words !=nil {if _df .Words !=nil {*_dd .Words +=*_df .Words ;};}else if _df .Words !=nil {_dd .Words =_df .Words ;};if _dd .Characters !=nil {if _df .Characters !=nil {*_dd .Characters +=*_df .Characters ;};}else if _df .Characters !=nil {_dd .Characters =_df .Characters ;};if _dd .Lines !=nil {if _df .Lines !=nil {*_dd .Lines +=*_df .Lines ;};}else if _df .Lines !=nil {_dd .Lines =_df .Lines ;};if _dd .Paragraphs !=nil {if _df .Paragraphs !=nil {*_dd .Paragraphs +=*_df .Paragraphs ;};}else if _df .Paragraphs !=nil {_dd .Paragraphs =_df .Paragraphs ;};if _dd .Notes !=nil {if _df .Notes !=nil {*_dd .Notes +=*_df .Notes ;};}else if _df .Notes !=nil {_dd .Notes =_df .Notes ;};if _dd .HiddenSlides !=nil {if _df .HiddenSlides !=nil {*_dd .HiddenSlides +=*_df .HiddenSlides ;};}else if _df .HiddenSlides !=nil {_dd .HiddenSlides =_df .HiddenSlides ;};if _dd .MMClips !=nil {if _df .MMClips !=nil {*_dd .MMClips +=*_df .MMClips ;};}else if _df .MMClips !=nil {_dd .MMClips =_df .MMClips ;};if _dd .LinksUpToDate !=nil {if _df .LinksUpToDate !=nil {*_dd .LinksUpToDate =*_dd .LinksUpToDate &&*_df .LinksUpToDate ;};}else if _df .LinksUpToDate !=nil {_dd .LinksUpToDate =_df .LinksUpToDate ;};if _dd .CharactersWithSpaces !=nil {if _df .CharactersWithSpaces !=nil {*_dd .CharactersWithSpaces +=*_df .CharactersWithSpaces ;};}else if _df .CharactersWithSpaces !=nil {_dd .CharactersWithSpaces =_df .CharactersWithSpaces ;};if _dd .SharedDoc !=nil {if _df .SharedDoc !=nil {*_dd .SharedDoc =*_dd .SharedDoc ||*_df .SharedDoc ;};}else if _df .SharedDoc !=nil {_dd .SharedDoc =_df .SharedDoc ;};if _dd .HyperlinksChanged !=nil {if _df .HyperlinksChanged !=nil {*_dd .HyperlinksChanged =*_dd .HyperlinksChanged ||*_df .HyperlinksChanged ;};}else if _df .HyperlinksChanged !=nil {_dd .HyperlinksChanged =_df .HyperlinksChanged ;};_dd .DigSig =nil ;if _dd .TitlesOfParts ==nil &&_df .TitlesOfParts !=nil {_dd .TitlesOfParts =_df .TitlesOfParts ;};if _dd .HeadingPairs !=nil {if _df .HeadingPairs !=nil {_fb :=_dd .HeadingPairs .Vector ;_cb :=_df .HeadingPairs .Vector ;_fd :=_fb .Variant ;_dag :=_cb .Variant ;_fda :=[]*_fg .Variant {};for _ae :=0;_ae < len (_dag );_ae +=2{_cg :=_dag [_ae ].Lpstr ;_be :=false ;for _fgd :=0;_fgd < len (_fd );_fgd +=2{_fgdf :=_fd [_fgd ].Lpstr ;if _fgdf !=nil &&_cg !=nil &&*_fgdf ==*_cg {*_fd [_fgd +1].I4 =*_fd [_fgd +1].I4 +*_dag [_ae +1].I4 ;_be =true ;break ;};};if !_be {_fda =append (_fda ,&_fg .Variant {CT_Variant :_fg .CT_Variant {Lpstr :_dag [_ae ].Lpstr }});_fda =append (_fda ,&_fg .Variant {CT_Variant :_fg .CT_Variant {I4 :_dag [_ae ].I4 }});};};_fd =append (_fd ,_fda ...);_fb .SizeAttr =uint32 (len (_fd ));};}else if _df .HeadingPairs !=nil {_dd .HeadingPairs =_df .HeadingPairs ;};if _dd .HLinks !=nil {if _df .HLinks !=nil {_ddd :=_dd .HLinks .Vector ;_bb :=_df .HLinks .Vector ;_ga :=_ddd .Variant ;_db :=_bb .Variant ;for _ ,_gb :=range _db {_fgc :=true ;for _ ,_bba :=range _ga {if _d .DeepEqual (_bba ,_gb ){_fgc =false ;break ;};};if _fgc {_ga =append (_ga ,_gb );_ddd .SizeAttr ++;};};};}else if _df .HLinks !=nil {_dd .HLinks =_df .HLinks ;};_dgb :=_eg .GetOrCreateCustomProperties ();_ace :=docBase1 .GetOrCreateCustomProperties ();for _ ,_cec :=range _ace .PropertiesList (){_dgb .setProperty (_cec );};_eg .CustomProperties =_dgb ;_ceb :=_eg .Rels .X ().Relationship ;for _ ,_egf :=range docBase1 .Rels .X ().Relationship {_cf :=true ;for _ ,_cd :=range _ceb {if _cd .TargetAttr ==_egf .TargetAttr &&_cd .TypeAttr ==_egf .TypeAttr {_cf =false ;break ;};};if _cf {_eg .Rels .AddRelationship (_egf .TargetAttr ,_egf .TypeAt
2022-02-05 13:05:36 +00:00
2022-12-06 11:56:49 +00:00
// SetDescription records the description of the document.
func (_ecf CoreProperties )SetDescription (s string ){if _ecf ._gdb .Description ==nil {_ecf ._gdb .Description =&_gc .XSDAny {XMLName :_ee .Name {Local :"\u0064\u0063\u003a\u0064\u0065\u0073\u0063\u0072\u0069p\u0074\u0069\u006f\u006e"}};};_ecf ._gdb .Description .Data =[]byte (s );};
2020-10-12 13:59:12 +00:00
2022-12-06 11:56:49 +00:00
// Clear removes any existing relationships.
func (_ecedg Relationships )Clear (){_ecedg ._feec .Relationship =nil };func UtcTimeFormat (t _ef .Time )string {return t .Format (_efbc )+"\u0020\u0055\u0054\u0043"};
2020-10-12 13:59:12 +00:00
2022-12-06 11:56:49 +00:00
// X returns the inner wrapped XML type.
func (_caf CoreProperties )X ()*_bc .CoreProperties {return _caf ._gdb };
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// NewRelationships creates a new relationship wrapper.
func NewRelationships ()Relationships {return Relationships {_feec :_aae .NewRelationships ()}};func (_gga CustomProperties )getNewProperty (_afbc string )*_fa .CT_Property {_cdc :=_gga ._ebc .Property ;_bcb :=int32 (1);for _ ,_bcbf :=range _cdc {if _bcbf .PidAttr > _bcb {_bcb =_bcbf .PidAttr ;};};_gef :=_fa .NewCT_Property ();_gef .NameAttr =&_afbc ;_gef .PidAttr =_bcb +1;_gef .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 _gef ;};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// Remove removes an existing relationship.
func (_fgb Relationships )Remove (rel Relationship )bool {for _dcfd ,_eda :=range _fgb ._feec .Relationship {if _eda ==rel ._dge {copy (_fgb ._feec .Relationship [_dcfd :],_fgb ._feec .Relationship [_dcfd +1:]);_fgb ._feec .Relationship =_fgb ._feec .Relationship [0:len (_fgb ._feec .Relationship )-1];return true ;};};return false ;};func (_gad TableRow )addCell ()*_fe .CT_TableCell {_fcgc :=_fe .NewCT_TableCell ();_gad ._bgag .Tc =append (_gad ._bgag .Tc ,_fcgc );return _fcgc ;};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// TableRow represents a row in a table.
type TableRow struct{_bgag *_fe .CT_TableRow };const _caa =6;func (_eca CustomProperties )SetPropertyAsCy (name string ,cy string ){_ebag :=_eca .getNewProperty (name );_ebag .Cy =&cy ;_eca .setOrReplaceProperty (_ebag );};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// AddImageToZip adds an image (either from bytes or from disk) and adds it to the zip file.
func AddImageToZip (z *_ff .Writer ,img ImageRef ,imageNum int ,dt _gc .DocType )error {_ebd :=_gc .AbsoluteImageFilename (dt ,imageNum ,_eb .ToLower (img .Format ()));if img .Data ()!=nil &&len (*img .Data ())> 0{if _beaf :=_g .AddFileFromBytes (z ,_ebd ,*img .Data ());_beaf !=nil {return _beaf ;};}else if img .Path ()!=""{if _ccc :=_g .AddFileFromDisk (z ,_ebd ,img .Path ());_ccc !=nil {return _ccc ;};}else {return _aa .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 ;};
2021-03-16 20:51:18 +00:00
2022-12-06 11:56:49 +00:00
// SetID set the ID of a relationship.
func (_dbge Relationship )SetID (ID string ){_dbge ._dge .IdAttr =ID ;};const _bfae =15;
2021-08-23 20:44:48 +00:00
2022-12-06 11:56:49 +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 ){_fcbb ,_fea :=_ag .Open (path );_faec :=Image {};if _fea !=nil {return _faec ,_aa .Errorf ("\u0065\u0072\u0072or\u0020\u0072\u0065\u0061\u0064\u0069\u006e\u0067\u0020\u0069\u006d\u0061\u0067\u0065\u003a\u0020\u0025\u0073",_fea );};defer _fcbb .Close ();_ecdg ,_efdc ,_fea :=_e .Decode (_fcbb );if _fea !=nil {return _faec ,_aa .Errorf ("\u0075n\u0061\u0062\u006c\u0065 \u0074\u006f\u0020\u0070\u0061r\u0073e\u0020i\u006d\u0061\u0067\u0065\u003a\u0020\u0025s",_fea );};_faec .Path =path ;_faec .Format =_efdc ;_faec .Size =_ecdg .Bounds ().Size ();return _faec ,nil ;};
2020-11-09 01:00:18 +00:00
2022-12-06 11:56:49 +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 _e .Image ;Images []ImageRef ;ExtraFiles []ExtraFile ;TmpPath string ;};func (_dcfa CustomProperties )SetPropertyAsLpwstr (name string ,lpwstr string ){_aaa :=_dcfa .getNewProperty (name );_aaa .Lpwstr =&lpwstr ;_dcfa .setOrReplaceProperty (_aaa );};
2020-11-09 01:00:18 +00:00
2022-12-06 11:56:49 +00:00
// SetTitle records the title of the document.
func (_fee CoreProperties )SetTitle (s string ){if _fee ._gdb .Title ==nil {_fee ._gdb .Title =&_gc .XSDAny {XMLName :_ee .Name {Local :"\u0064\u0063\u003a\u0074\u0069\u0074\u006c\u0065"}};};_fee ._gdb .Title .Data =[]byte (s );};func (_aggd CustomProperties )SetPropertyAsBlob (name ,blob string ){_aced :=_aggd .getNewProperty (name );_aced .Blob =&blob ;_aggd .setOrReplaceProperty (_aced );};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// Title returns the Title of the document
func (_egcf CoreProperties )Title ()string {if _egcf ._gdb .Title !=nil {return string (_egcf ._gdb .Title .Data );};return "";};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// DefAttr returns the DefAttr property.
func (_gada TableStyles )DefAttr ()string {return _gada ._cff .DefAttr };
2020-08-23 14:15:53 +00:00
2022-09-02 11:46:53 +00:00
// Target returns the target attrubute of the image reference (a path where the image file is located in the document structure).
2022-12-06 11:56:49 +00:00
func (_cgdc *ImageRef )Target ()string {return _cgdc ._afg };
2021-09-22 16:41:01 +00:00
2022-09-02 11:46:53 +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.
2022-12-06 11:56:49 +00:00
type Image struct{Size _e .Point ;Format string ;Path string ;Data *[]byte ;};
2021-05-31 16:22:30 +00:00
2022-12-06 11:56:49 +00:00
// Size returns the size of an image
func (_fba ImageRef )Size ()_e .Point {return _fba ._ebee .Size };func (_bbe CustomProperties )SetPropertyAsDecimal (name string ,decimal float64 ){_feb :=_bbe .getNewProperty (name );_feb .Decimal =&decimal ;_bbe .setOrReplaceProperty (_feb );};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// IsEmpty returns true if there are no relationships.
func (_bdb Relationships )IsEmpty ()bool {return _bdb ._feec ==nil ||len (_bdb ._feec .Relationship )==0;};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// GetOrCreateCustomProperties returns the custom properties of the document (and if they not exist yet, creating them first).
func (_ddg *DocBase )GetOrCreateCustomProperties ()CustomProperties {if _ddg .CustomProperties .X ()==nil {_ddg .CreateCustomProperties ();};return _ddg .CustomProperties ;};
2020-08-23 14:15:53 +00:00
2022-09-02 11:46:53 +00:00
// ApplicationVersion returns the version of the application that created the
// document.
2022-12-06 11:56:49 +00:00
func (_bcd AppProperties )ApplicationVersion ()string {if _bcd ._dgg .AppVersion !=nil {return *_bcd ._dgg .AppVersion ;};return "";};
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.
func (_gdc Relationships )Relationships ()[]Relationship {_acec :=[]Relationship {};for _ ,_ada :=range _gdc ._feec .Relationship {_acec =append (_acec ,Relationship {_dge :_ada });};return _acec ;};func (_cca CustomProperties )setOrReplaceProperty (_aeb *_fa .CT_Property ){_cca .setPropertyHelper (_aeb ,true );};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// SetOffsetX sets horizontal offset of a table in distance units (see measurement package).
func (_ddcc Table )SetOffsetX (offX float64 ){if _ddcc ._dfg .Off ==nil {_ddcc ._dfg .Off =_fe .NewCT_Point2D ();_bedf :=int64 (0);_ddcc ._dfg .Off .YAttr =_fe .ST_Coordinate {ST_CoordinateUnqualified :&_bedf };};_acf :=_ffb .ToEMU (offX );_ddcc ._dfg .Off .XAttr =_fe .ST_Coordinate {ST_CoordinateUnqualified :&_acf };};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// Hyperlink is just an appropriately configured relationship.
type Hyperlink Relationship ;func (_bfge CustomProperties )SetPropertyAsLpstr (name string ,lpstr string ){_cefa :=_bfge .getNewProperty (name );_cefa .Lpstr =&lpstr ;_bfge .setOrReplaceProperty (_cefa );};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// NewTableStyles constructs a new TableStyles.
func NewTableStyles ()TableStyles {return TableStyles {_cff :_fe .NewTblStyleLst ()}};
2020-10-12 13:59:12 +00:00
2022-12-06 11:56:49 +00:00
// SetLastModifiedBy records the last person to modify the document.
func (_deba CoreProperties )SetLastModifiedBy (s string ){_deba ._gdb .LastModifiedBy =&s };
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// FindRIDForN returns the relationship ID for the i'th relationship of type t.
func (_egca Relationships )FindRIDForN (i int ,t string )string {for _ ,_cccb :=range _egca ._feec .CT_Relationships .Relationship {if _cccb .TypeAttr ==t {if i ==0{return _cccb .IdAttr ;};i --;};};return "";};
2022-02-05 13:05:36 +00:00
2022-12-06 11:56:49 +00:00
// SetTarget set the target (path) of a relationship.
func (_cafb Relationship )SetTarget (s string ){_cafb ._dge .TargetAttr =s };func (_ggf CustomProperties )SetPropertyAsI2 (name string ,i2 int16 ){_bcg :=_ggf .getNewProperty (name );_bcg .I2 =&i2 ;_ggf .setOrReplaceProperty (_bcg );};func (_bfad CustomProperties )SetPropertyAsStream (name string ,stream string ){_adb :=_bfad .getNewProperty (name );_adb .Stream =&stream ;_bfad .setOrReplaceProperty (_adb );};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// Created returns the time that the document was created.
func (_dfc CoreProperties )Created ()_ef .Time {return _acad (_dfc ._gdb .Created )};func _acad (_abg *_gc .XSDAny )_ef .Time {if _abg ==nil {return _ef .Time {};};_debe ,_fgcc :=_ef .Parse (_dgged ,string (_abg .Data ));if _fgcc !=nil {_ab .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 (_abg .Data ),_fgcc );};return _debe ;};
2021-06-16 07:10:52 +00:00
2022-12-06 11:56:49 +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 {_ebee :img ,_ccefa :d ,_ebg :rels };};
2021-06-16 07:10:52 +00:00
2022-12-06 11:56:49 +00:00
// AddOverride adds an override content type for a given path name.
func (_cbg ContentTypes )AddOverride (path ,contentType string ){if !_eb .HasPrefix (path ,"\u002f"){path ="\u002f"+path ;};if _eb .HasPrefix (contentType ,"\u0068\u0074\u0074\u0070"){_ab .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 _ ,_agc :=range _cbg ._efd .Override {if _agc .PartNameAttr ==path &&_agc .ContentTypeAttr ==contentType {return ;};};_eag :=_c .NewOverride ();_eag .PartNameAttr =path ;_eag .ContentTypeAttr =contentType ;_cbg ._efd .Override =append (_cbg ._efd .Override ,_eag );};
2021-06-16 07:10:52 +00:00
2022-12-06 11:56:49 +00:00
// CustomProperties contains document specific properties.
type CustomProperties struct{_ebc *_fa .Properties };const Version ="\u0031\u002e\u0032\u0031\u002e\u0031";
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// NewCustomProperties constructs a new CustomProperties.
func NewCustomProperties ()CustomProperties {return CustomProperties {_ebc :_fa .NewProperties ()}};func (_fde CustomProperties )setProperty (_cafd *_fa .CT_Property ){_fde .setPropertyHelper (_cafd ,false );};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// ID returns the ID of a relationship.
func (_cfea Relationship )ID ()string {return _cfea ._dge .IdAttr };
2022-04-09 14:27:46 +00:00
2022-12-06 11:56:49 +00:00
// RelID returns the relationship ID.
func (_dce ImageRef )RelID ()string {return _dce ._fgfe };
2022-04-09 14:27:46 +00:00
2022-12-06 11:56:49 +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 (_dff *ImageRef )SetTarget (target string ){_dff ._afg =target };
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// CopyOverride copies override content type for a given `path` and puts it with a path `newPath`.
func (_eeba ContentTypes )CopyOverride (path ,newPath string ){if !_eb .HasPrefix (path ,"\u002f"){path ="\u002f"+path ;};if !_eb .HasPrefix (newPath ,"\u002f"){newPath ="\u002f"+newPath ;};for _acb :=range _eeba ._efd .Override {if _eeba ._efd .Override [_acb ].PartNameAttr ==path {_fce :=*_eeba ._efd .Override [_acb ];_fce .PartNameAttr =newPath ;_eeba ._efd .Override =append (_eeba ._efd .Override ,&_fce );};};};func (_gcf CustomProperties )SetPropertyAsUint (name string ,ui uint ){_bfc :=_gcf .getNewProperty (name );_cdb :=uint32 (ui );_bfc .Uint =&_cdb ;_gcf .setOrReplaceProperty (_bfc );};func (_agca CustomProperties )SetPropertyAsOstorage (name string ,ostorage string ){_gdba :=_agca .getNewProperty (name );_gdba .Ostorage =&ostorage ;_agca .setOrReplaceProperty (_gdba );};
// ContentTypes is the top level "[Content_Types].xml" in a zip package.
type ContentTypes struct{_efd *_c .Types };const _aec =30;
2020-08-23 14:15:53 +00:00
2022-09-02 11:46:53 +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.
2022-12-06 11:56:49 +00:00
func (_dfca Relationships )AddAutoRelationship (dt _gc .DocType ,src string ,idx int ,ctype string )Relationship {return _dfca .AddRelationship (_gc .RelativeFilename (dt ,src ,ctype ,idx ),ctype );};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// SetDocSecurity sets the document security flag.
func (_gac AppProperties )SetDocSecurity (v int32 ){_gac ._dgg .DocSecurity =_gc .Int32 (v )};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// Theme is a drawingml theme.
type Theme struct{_efa *_fe .Theme };
2021-11-10 11:45:21 +00:00
2022-12-06 11:56:49 +00:00
// AddCustomRelationships adds relationships related to custom properties to the document.
func (_bfga *DocBase )AddCustomRelationships (){_bfga .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");_bfga .Rels .AddRelationship ("\u0064\u006f\u0063\u0050ro\u0070\u0073\u002f\u0063\u0075\u0073\u0074\u006f\u006d\u002e\u0078\u006d\u006c",_gc .CustomPropertiesType );};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// X returns the inner raw content types.
func (_ffc ContentTypes )X ()*_c .Types {return _ffc ._efd };
2021-04-23 20:00:00 +00:00
2022-12-06 11:56:49 +00:00
// SetHeight sets row height, see measurement package.
func (_ebda TableRow )SetHeight (m _ffb .Distance ){_ddca :=_ffb .ToEMU (float64 (m ));_ebda ._bgag .HAttr =_fe .ST_Coordinate {ST_CoordinateUnqualified :&_ddca };};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// Author returns the author of the document
func (_bfe CoreProperties )Author ()string {if _bfe ._gdb .Creator !=nil {return string (_bfe ._gdb .Creator .Data );};return "";};func (_eabf CustomProperties )SetPropertyAsOstream (name string ,ostream string ){_bec :=_eabf .getNewProperty (name );_bec .Ostream =&ostream ;_eabf .setOrReplaceProperty (_bec );};func (_aab CustomProperties )SetPropertyAsArray (name string ,array *_fg .Array ){_ecde :=_aab .getNewProperty (name );_ecde .Array =array ;_aab .setOrReplaceProperty (_ecde );};func (_ded CustomProperties )SetPropertyAsStorage (name string ,storage string ){_gbdf :=_ded .getNewProperty (name );_gbdf .Storage =&storage ;_ded .setOrReplaceProperty (_gbdf );};
2022-04-09 14:27:46 +00:00
2022-12-06 11:56:49 +00:00
// AddCol adds a column to a table.
func (_cbc Table )AddCol ()*TableCol {_eedg :=_fe .NewCT_TableCol ();_cbc ._fcg .TblGrid .GridCol =append (_cbc ._fcg .TblGrid .GridCol ,_eedg );for _ ,_dffg :=range _cbc ._fcg .Tr {_feaa :=_fe .NewCT_TableCell ();_dffg .Tc =append (_dffg .Tc ,_feaa );};return &TableCol {_age :_eedg };};
2021-05-31 16:22:30 +00:00
2022-12-06 11:56:49 +00:00
// Path returns the path to an image file, if any.
func (_ggabb ImageRef )Path ()string {return _ggabb ._ebee .Path };const _dffd =2022;func (_fdc CustomProperties )SetPropertyAsClsid (name string ,clsid string ){_ccf :=_fdc .getNewProperty (name );_ccf .Clsid =&clsid ;_fdc .setOrReplaceProperty (_ccf );};
2021-05-31 16:22:30 +00:00
2022-12-06 11:56:49 +00:00
// X returns the inner wrapped XML type.
func (_acd AppProperties )X ()*_dad .Properties {return _acd ._dgg };
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// WriteExtraFiles writes the extra files to the zip package.
func (_gefb *DocBase )WriteExtraFiles (z *_ff .Writer )error {for _ ,_fagbb :=range _gefb .ExtraFiles {if _cgf :=_g .AddFileFromDisk (z ,_fagbb .ZipPath ,_fagbb .DiskPath );_cgf !=nil {return _cgf ;};};return nil ;};func (_egfd *ImageRef )SetRelID (id string ){_egfd ._fgfe =id };
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// AddHyperlink adds an external hyperlink relationship.
func (_cag Relationships )AddHyperlink (target string )Hyperlink {_eaeg :=_cag .AddRelationship (target ,_gc .HyperLinkType );_eaeg ._dge .TargetModeAttr =_aae .ST_TargetModeExternal ;return Hyperlink (_eaeg );};
2020-08-23 14:15:53 +00:00
2022-12-06 11:56:49 +00:00
// Properties returns table properties.
func (_adgc Table )Properties ()*_fe .CT_TableProperties {return _adgc ._fcg .TblPr };
2021-11-10 11:45:21 +00:00
2022-12-06 11:56:49 +00:00
// Table represents a table in the document.
type Table struct{_fcg *_fe .Tbl ;_dfg *_fe .CT_Transform2D ;};func (_bgf CustomProperties )SetPropertyAsI1 (name string ,i1 int8 ){_dee :=_bgf .getNewProperty (name );_dee .I1 =&i1 ;_bgf .setOrReplaceProperty (_dee );};
2021-11-10 11:45:21 +00:00
2022-12-06 11:56:49 +00:00
// CopyRelationship copies the relationship.
func (_ddc Relationships )CopyRelationship (idAttr string )(Relationship ,bool ){for _eea :=range _ddc ._feec .Relationship {if _ddc ._feec .Relationship [_eea ].IdAttr ==idAttr {_faaa :=*_ddc ._feec .Relationship [_eea ];_eedf :=len (_ddc ._feec .Relationship )+1;_dcea :=map[string ]struct{}{};for _ ,_bdeb :=range _ddc ._feec .Relationship {_dcea [_bdeb .IdAttr ]=struct{}{};};for _ ,_beca :=_dcea [_aa .Sprintf ("\u0072\u0049\u0064%\u0064",_eedf )];_beca ;_ ,_beca =_dcea [_aa .Sprintf ("\u0072\u0049\u0064%\u0064",_eedf )]{_eedf ++;};_faaa .IdAttr =_aa .Sprintf ("\u0072\u0049\u0064%\u0064",_eedf );_ddc ._feec .Relationship =append (_ddc ._feec .Relationship ,&_faaa );return Relationship {_dge :&_faaa },true ;};};return Relationship {},false ;};
2020-10-12 13:59:12 +00:00
2022-12-06 11:56:49 +00:00
// X returns the inner wrapped XML type of CustomProperty.
func (_edf CustomProperty )X ()*_fa .CT_Property {return _edf ._dcf };
2021-11-10 11:45:21 +00:00
2022-12-06 11:56:49 +00:00
// X returns the underlying raw XML data.
func (_daa Relationships )X ()*_aae .Relationships {return _daa ._feec };
2021-11-10 11:45:21 +00:00
2022-12-06 11:56:49 +00:00
// RemoveOverrideByIndex removes an override given a path and override index.
func (_dec ContentTypes )RemoveOverrideByIndex (path string ,indexToFind int )error {_dddd :=path [0:len (path )-5];if !_eb .HasPrefix (_dddd ,"\u002f"){_dddd ="\u002f"+_dddd ;};_fbc ,_ffbg :=_ac .Compile (_dddd +"\u0028\u005b\u0030-\u0039\u005d\u002b\u0029\u002e\u0078\u006d\u006c");if _ffbg !=nil {return _ffbg ;};_eceb :=0;_ccd :=-1;for _dfb ,_cdf :=range _dec ._efd .Override {if _cac :=_fbc .FindStringSubmatch (_cdf .PartNameAttr );len (_cac )> 1{if _eceb ==indexToFind {_ccd =_dfb ;}else if _eceb > indexToFind {_gcg ,_ :=_ec .Atoi (_cac [1]);_gcg --;_cdf .PartNameAttr =_aa .Sprintf ("\u0025\u0073\u0025\u0064\u002e\u0078\u006d\u006c",_dddd ,_gcg );};_eceb ++;};};if _ccd > -1{copy (_dec ._efd .Override [_ccd :],_dec ._efd .Override [_ccd +1:]);_dec ._efd .Override =_dec ._efd .Override [0:len (_dec ._efd .Override )-1];};return nil ;};const _efbc ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";
2021-11-10 11:45:21 +00:00
2022-12-06 11:56:49 +00:00
// X returns the inner wrapped XML type.
func (_gfg CustomProperties )X ()*_fa .Properties {return _gfg ._ebc };
2021-11-10 11:45:21 +00:00
2022-12-06 11:56:49 +00:00
// CoreProperties contains document specific properties.
type CoreProperties struct{_gdb *_bc .CoreProperties };
2021-11-10 11:45:21 +00:00
2022-12-06 11:56:49 +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 (_cc AppProperties )Application ()string {if _cc ._dgg .Application !=nil {return *_cc ._dgg .Application ;};return "";};
2022-04-09 14:27:46 +00:00
2022-12-06 11:56:49 +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 ;};func (_eff CustomProperties )SetPropertyAsBstr (name string ,bstr string ){_ggg :=_eff .getNewProperty (name );_ggg .Bstr =&bstr ;_eff .setOrReplaceProperty (_ggg );};func (_fgcd CustomProperties )SetPropertyAsFiletime (name string ,filetime _ef .Time ){_afcc :=_fgcd .getNewProperty (name );_afcc .Filetime =&filetime ;_fgcd .setOrReplaceProperty (_afcc );};
2021-06-16 07:10:52 +00:00
2022-12-06 11:56:49 +00:00
// GetImageBytesByTarget returns Image object with Data bytes read from its target.
func (_afd *DocBase )GetImageBytesByTarget (target string )(Image ,error ){if target !=""{target ="\u0077\u006f\u0072d\u002f"+target ;for _ ,_eebd :=range _afd .Images {if _eebd .Target ()==target {return ImageFromStorage (_eebd .Path ());};};};return Image {},_cdcf ;};var _cdcf =_da .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");
2022-01-15 21:17:38 +00:00
2022-12-06 11:56:49 +00:00
// SetStyle assigns TableStyle to a table.
func (_bffc Table )SetStyle (style *_fe .CT_TableStyle ){if _bffc ._fcg .TblPr ==nil {_bffc ._fcg .TblPr =_fe .NewCT_TableProperties ();};if _bffc ._fcg .TblPr .Choice ==nil {_bffc ._fcg .TblPr .Choice =_fe .NewCT_TablePropertiesChoice ();};_bffc ._fcg .TblPr .Choice .TableStyle =style ;};
2020-10-12 13:59:12 +00:00
2022-12-06 11:56:49 +00:00
// RemoveOverride removes an override given a path.
func (_bgd ContentTypes )RemoveOverride (path string ){if !_eb .HasPrefix (path ,"\u002f"){path ="\u002f"+path ;};for _aca ,_efb :=range _bgd ._efd .Override {if _efb .PartNameAttr ==path {copy (_bgd ._efd .Override [_aca :],_bgd ._efd .Override [_aca +1:]);_bgd ._efd .Override =_bgd ._efd .Override [0:len (_bgd ._efd .Override )-1];};};};
2021-05-31 16:22:30 +00:00
2022-12-06 11:56:49 +00:00
// NewTableWithXfrm makes a new table with a pointer to its parent Xfrm for changing its offset and size.
func NewTableWithXfrm (xfrm *_fe .CT_Transform2D )*Table {_cde :=_fe .NewTbl ();_cde .TblPr =_fe .NewCT_TableProperties ();return &Table {_fcg :_cde ,_dfg :xfrm };};
2021-05-31 16:22:30 +00:00
2022-12-06 11:56:49 +00:00
// EnsureDefault esnures that an extension and default content type exist,
// adding it if necessary.
func (_dbc ContentTypes )EnsureDefault (ext ,contentType string ){ext =_eb .ToLower (ext );for _ ,_efcf :=range _dbc ._efd .Default {if _efcf .ExtensionAttr ==ext {_efcf .ContentTypeAttr =contentType ;return ;};};_bff :=&_c .Default {};_bff .ContentTypeAttr =contentType ;_bff .ExtensionAttr =ext ;_dbc ._efd .Default =append (_dbc ._efd .Default ,_bff );};
2022-01-15 21:17:38 +00:00
2022-12-06 11:56:49 +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 ){_bga :=Image {};_eced ,_abga :=_ffba .Open (path );if _abga !=nil {return _bga ,_aa .Errorf ("\u0065\u0072\u0072or\u0020\u0072\u0065\u0061\u0064\u0069\u006e\u0067\u0020\u0069\u006d\u0061\u0067\u0065\u003a\u0020\u0025\u0073",_abga );};defer _eced .Close ();_dbf ,_gdg ,_abga :=_e .Decode (_eced );if _abga !=nil {return _bga ,_aa .Errorf ("\u0075n\u0061\u0062\u006c\u0065 \u0074\u006f\u0020\u0070\u0061r\u0073e\u0020i\u006d\u0061\u0067\u0065\u003a\u0020\u0025s",_abga );};_bga .Path =path ;_bga .Format =_gdg ;_bga .Size =_dbf .Bounds ().Size ();return _bga ,nil ;};
2022-01-15 21:17:38 +00:00
2022-12-06 11:56:49 +00:00
// Properties returns table properties.
func (_acbe Table )Grid ()*_fe .CT_TableGrid {return _acbe ._fcg .TblGrid };
2022-01-15 21:17:38 +00:00
2022-12-06 11:56:49 +00:00
// Relationships represents a .rels file.
type Relationships struct{_feec *_aae .Relationships };
2021-06-16 07:10:52 +00:00
2022-12-06 11:56:49 +00:00
// SetCategory records the category of the document.
func (_edb CoreProperties )SetCategory (s string ){_edb ._gdb .Category =&s };
// NewRelationshipsCopy creates a new relationships wrapper as a copy of passed in instance.
func NewRelationshipsCopy (rels Relationships )Relationships {_dgef :=*rels ._feec ;return Relationships {_feec :&_dgef };};
// Rows returns all table rows.
func (_feag Table )Rows ()[]*TableRow {_aaac :=_feag ._fcg .Tr ;_bgcd :=[]*TableRow {};for _ ,_eceg :=range _aaac {_bgcd =append (_bgcd ,&TableRow {_bgag :_eceg });};return _bgcd ;};
2022-01-15 21:17:38 +00:00
2022-06-27 19:44:23 +00:00
// X returns the inner wrapped XML type.
2022-12-06 11:56:49 +00:00
func (_gda Theme )X ()*_fe .Theme {return _gda ._efa };
2022-01-15 21:17:38 +00:00
2022-12-06 11:56:49 +00:00
// Format returns the format of the underlying image
func (_bbg ImageRef )Format ()string {return _bbg ._ebee .Format };
2020-11-09 01:00:18 +00:00
2022-12-06 11:56:49 +00:00
// SetModified sets the time that the document was modified.
func (_afb CoreProperties )SetModified (t _ef .Time ){_afb ._gdb .Modified =_eaf (t ,"\u0064\u0063t\u0065\u0072\u006ds\u003a\u006d\u006f\u0064\u0069\u0066\u0069\u0065\u0064");};
2020-11-09 01:00:18 +00:00
2022-12-06 11:56:49 +00:00
// SetLinksUpToDate sets the links up to date flag.
func (_ba AppProperties )SetLinksUpToDate (v bool ){_ba ._dgg .LinksUpToDate =_gc .Bool (v )};
2020-12-17 22:07:08 +00:00
2022-12-06 11:56:49 +00:00
// Category returns the category of the document
func (_bee CoreProperties )Category ()string {if _bee ._gdb .Category !=nil {return *_bee ._gdb .Category ;};return "";};
2020-12-17 22:07:08 +00:00
2022-12-06 11:56:49 +00:00
// AddRow adds a row to a table.
func (_gcga Table )AddRow ()*TableRow {_cdbc :=_fe .NewCT_TableRow ();for _acedf :=0;_acedf < len (_gcga ._fcg .TblGrid .GridCol );_acedf ++{_cdbc .Tc =append (_cdbc .Tc ,_fe .NewCT_TableCell ());};_gcga ._fcg .Tr =append (_gcga ._fcg .Tr ,_cdbc );return &TableRow {_bgag :_cdbc };};
2020-12-17 22:07:08 +00:00
2022-12-06 11:56:49 +00:00
// X returns the inner wrapped XML type.
func (_ffa TableStyles )X ()*_fe .TblStyleLst {return _ffa ._cff };const _dgged ="2\u00300\u0036\u002d\u0030\u0031\u002d\u0030\u0032\u00541\u0035\u003a\u0030\u0034:0\u0035\u005a";func (_eab CustomProperties )SetPropertyAsUi4 (name string ,ui4 uint32 ){_aaef :=_eab .getNewProperty (name );_aaef .Ui4 =&ui4 ;_eab .setOrReplaceProperty (_aaef );};
2020-12-17 22:07:08 +00:00
2022-12-06 11:56:49 +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 (_aee ImageRef )RelativeHeight (w _ffb .Distance )_ffb .Distance {_eae :=float64 (_aee .Size ().Y )/float64 (_aee .Size ().X );return w *_ffb .Distance (_eae );};func _eaf (_gbb _ef .Time ,_ccef string )*_gc .XSDAny {_deg :=&_gc .XSDAny {XMLName :_ee .Name {Local :_ccef }};_deg .Attrs =append (_deg .Attrs ,_ee .Attr {Name :_ee .Name {Local :"\u0078\u0073\u0069\u003a\u0074\u0079\u0070\u0065"},Value :"\u0064\u0063\u0074\u0065\u0072\u006d\u0073\u003a\u00573\u0043\u0044\u0054\u0046"});_deg .Attrs =append (_deg .Attrs ,_ee .Attr {Name :_ee .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"});_deg .Attrs =append (_deg .Attrs ,_ee .Attr {Name :_ee .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/"});_deg .Data =[]byte (_gbb .Format (_dgged ));return _deg ;};
2020-12-17 22:07:08 +00:00
2022-12-06 11:56:49 +00:00
// PropertiesList returns the list of all custom properties of the document.
func (_cfc CustomProperties )PropertiesList ()[]*_fa .CT_Property {return _cfc ._ebc .Property };
2021-11-10 11:45:21 +00:00
2022-12-06 11:56:49 +00:00
// Description returns the description of the document
func (_bfa CoreProperties )Description ()string {if _bfa ._gdb .Description !=nil {return string (_bfa ._gdb .Description .Data );};return "";};
2021-11-10 11:45:21 +00:00
2022-12-06 11:56:49 +00:00
// EnsureOverride ensures that an override for the given path exists, adding it if necessary
func (_gg ContentTypes )EnsureOverride (path ,contentType string ){for _ ,_cgg :=range _gg ._efd .Override {if _cgg .PartNameAttr ==path {if _eb .HasPrefix (contentType ,"\u0068\u0074\u0074\u0070"){_ab .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 );};_cgg .ContentTypeAttr =contentType ;return ;};};_gg .AddOverride (path ,contentType );};
2021-11-10 11:45:21 +00:00
2022-12-06 11:56:49 +00:00
// AppProperties contains properties specific to the document and the
// application that created it.
type AppProperties struct{_dgg *_dad .Properties };
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.
type CustomProperty struct{_dcf *_fa .CT_Property };func (_fegg CustomProperties )SetPropertyAsI8 (name string ,i8 int64 ){_debd :=_fegg .getNewProperty (name );_debd .I8 =&i8 ;_fegg .setOrReplaceProperty (_debd );};func (_bde CustomProperties )SetPropertyAsR4 (name string ,r4 float32 ){_faa :=_bde .getNewProperty (name );_faa .R4 =&r4 ;_bde .setOrReplaceProperty (_faa );};func (_dba CustomProperties )SetPropertyAsOblob (name ,oblob string ){_cgd :=_dba .getNewProperty (name );_cgd .Oblob =&oblob ;_dba .setOrReplaceProperty (_cgd );};func init (){_gd .SetAsStorage ()};
2021-04-23 20:00:00 +00:00
2022-12-06 11:56:49 +00:00
// NewTable makes a new table.
func NewTable ()*Table {_afef :=_fe .NewTbl ();_afef .TblPr =_fe .NewCT_TableProperties ();return &Table {_fcg :_afef };};
2021-05-31 16:22:30 +00:00
2022-12-06 11:56:49 +00:00
// TblStyle returns the TblStyle property.
func (_gdbe TableStyles )TblStyle ()[]*_fe .CT_TableStyle {return _gdbe ._cff .TblStyle };
2021-06-16 07:10:52 +00:00
2022-12-06 11:56:49 +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 (_acef AppProperties )Pages ()int32 {if _acef ._dgg .Pages !=nil {return *_acef ._dgg .Pages ;};return 0;};
2021-06-16 07:10:52 +00:00
2022-12-06 11:56:49 +00:00
// NewTheme constructs a new theme.
func NewTheme ()Theme {return Theme {_fe .NewTheme ()}};
2021-06-16 07:10:52 +00:00
2022-12-06 11:56:49 +00:00
// SetContentStatus records the content status of the document.
func (_bd CoreProperties )SetContentStatus (s string ){_bd ._gdb .ContentStatus =&s };
2021-06-16 07:10:52 +00:00
2022-12-06 11:56:49 +00:00
// TableCol represents a column in a table.
type TableCol struct{_age *_fe .CT_TableCol };
2021-06-16 07:10:52 +00:00
2022-12-06 11:56:49 +00:00
// GetByRelId returns a relationship with the associated relation ID.
func (_fca Relationships )GetByRelId (idAttr string )Relationship {for _ ,_dcg :=range _fca ._feec .Relationship {if _dcg .IdAttr ==idAttr {return Relationship {_dge :_dcg };};};return Relationship {};};
2021-06-16 07:10:52 +00:00
2022-12-06 11:56:49 +00:00
// AddRelationship adds a relationship.
func (_ffcf Relationships )AddRelationship (target ,ctype string )Relationship {if !_eb .HasPrefix (ctype ,"\u0068t\u0074\u0070\u003a\u002f\u002f"){_ab .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 );};_bfbf :=_aae .NewRelationship ();_gcfg :=len (_ffcf ._feec .Relationship )+1;_fbb :=map[string ]struct{}{};for _ ,_gge :=range _ffcf ._feec .Relationship {_fbb [_gge .IdAttr ]=struct{}{};};for _ ,_ecfg :=_fbb [_aa .Sprintf ("\u0072\u0049\u0064%\u0064",_gcfg )];_ecfg ;_ ,_ecfg =_fbb [_aa .Sprintf ("\u0072\u0049\u0064%\u0064",_gcfg )]{_gcfg ++;};_bfbf .IdAttr =_aa .Sprintf ("\u0072\u0049\u0064%\u0064",_gcfg );_bfbf .TargetAttr =target ;_bfbf .TypeAttr =ctype ;_ffcf ._feec .Relationship =append (_ffcf ._feec .Relationship ,_bfbf );return Relationship {_dge :_bfbf };};func (_dcc CustomProperties )SetPropertyAsBool (name string ,b bool ){_cge :=_dcc .getNewProperty (name );_cge .Bool =&b ;_dcc .setOrReplaceProperty (_cge );};const _befa =12;
2021-06-16 07:10:52 +00:00
2022-12-06 11:56:49 +00:00
// GetTargetByRelId returns a target path with the associated relation ID.
func (_efec Relationships )GetTargetByRelId (idAttr string )string {for _ ,_dgc :=range _efec ._feec .Relationship {if _dgc .IdAttr ==idAttr {return _dgc .TargetAttr ;};};return "";};
2022-02-25 19:20:45 +00:00
2022-12-06 11:56:49 +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 (_bag ImageRef )RelativeWidth (h _ffb .Distance )_ffb .Distance {_cfe :=float64 (_bag .Size ().X )/float64 (_bag .Size ().Y );return h *_ffb .Distance (_cfe );};
2022-02-25 19:20:45 +00:00
2022-09-02 11:46:53 +00:00
// SetWidth sets column width, see measurement package.
2022-12-06 11:56:49 +00:00
func (_eac TableCol )SetWidth (m _ffb .Distance ){_dcac :=_ffb .ToEMU (float64 (m ));_eac ._age .WAttr =_fe .ST_Coordinate {ST_CoordinateUnqualified :&_dcac };};
// NewAppProperties constructs a new AppProperties.
func NewAppProperties ()AppProperties {_ecc :=AppProperties {_dgg :_dad .NewProperties ()};_ecc .SetCompany ("\u0046\u006f\u0078\u0079\u0055\u0074\u0069\u006c\u0073\u0020\u0065\u0068\u0066");_ecc .SetApplication ("g\u0069\u0074\u0068\u0075\u0062\u002ec\u006f\u006d\u002f\u0075\u006e\u0069\u0064\u006f\u0063/\u0075\u006e\u0069o\u0066f\u0069\u0063\u0065");_ecc .SetDocSecurity (0);_ecc .SetLinksUpToDate (false );var _egg ,_dgge ,_eed int64 ;_aa .Sscanf (Version ,"\u0025\u0064\u002e\u0025\u0064\u002e\u0025\u0064",&_egg ,&_dgge ,&_eed );_gf :=float64 (_egg )+float64 (_dgge )/10000.0;_ecc .SetApplicationVersion (_aa .Sprintf ("\u0025\u0030\u0037\u002e\u0034\u0066",_gf ));return _ecc ;};
2021-08-23 20:44:48 +00:00
2022-09-02 11:46:53 +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.
2022-12-06 11:56:49 +00:00
func ImageFromBytes (data []byte )(Image ,error ){_abd :=Image {};_fff ,_fbcg ,_gcc :=_e .Decode (_af .NewReader (data ));if _gcc !=nil {return _abd ,_aa .Errorf ("\u0075n\u0061\u0062\u006c\u0065 \u0074\u006f\u0020\u0070\u0061r\u0073e\u0020i\u006d\u0061\u0067\u0065\u003a\u0020\u0025s",_gcc );};_abd .Data =&data ;_abd .Format =_fbcg ;_abd .Size =_fff .Bounds ().Size ();return _abd ,nil ;};
2022-02-25 19:20:45 +00:00
2022-12-06 11:56:49 +00:00
// NewContentTypes returns a wrapper around a newly constructed content-types.
func NewContentTypes ()ContentTypes {_ge :=ContentTypes {_efd :_c .NewTypes ()};_ge .AddDefault ("\u0078\u006d\u006c","\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u0078\u006d\u006c");_ge .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");_ge .AddDefault ("\u0070\u006e\u0067","\u0069m\u0061\u0067\u0065\u002f\u0070\u006eg");_ge .AddDefault ("\u006a\u0070\u0065\u0067","\u0069\u006d\u0061\u0067\u0065\u002f\u006a\u0070\u0065\u0067");_ge .AddDefault ("\u006a\u0070\u0067","\u0069m\u0061\u0067\u0065\u002f\u006a\u0070g");_ge .AddDefault ("\u0077\u006d\u0066","i\u006d\u0061\u0067\u0065\u002f\u0078\u002d\u0077\u006d\u0066");_ge .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");_ge .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 _ge ;};
2022-02-25 19:20:45 +00:00
2022-12-06 11:56:49 +00:00
// LastModifiedBy returns the name of the last person to modify the document
func (_efee CoreProperties )LastModifiedBy ()string {if _efee ._gdb .LastModifiedBy !=nil {return *_efee ._gdb .LastModifiedBy ;};return "";};
2022-02-25 19:20:45 +00:00
2022-12-06 11:56:49 +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 (_efc AppProperties )SetApplicationVersion (s string ){_efc ._dgg .AppVersion =&s };
2022-06-27 19:44:23 +00:00
2022-12-06 11:56:49 +00:00
// X returns the inner wrapped XML type.
func (_gdbc Table )X ()*_fe .Tbl {return _gdbc ._fcg };
2022-06-27 19:44:23 +00:00
2022-12-06 11:56:49 +00:00
// SetApplication sets the name of the application that created the document.
func (_ca AppProperties )SetApplication (s string ){_ca ._dgg .Application =&s };func (_ega CustomProperties )SetPropertyAsVstream (name string ,vstream *_fg .Vstream ){_agga :=_ega .getNewProperty (name );_agga .Vstream =vstream ;_ega .setOrReplaceProperty (_agga );};func (_bfb CustomProperties )SetPropertyAsUi8 (name string ,ui8 uint64 ){_dbg :=_bfb .getNewProperty (name );_dbg .Ui8 =&ui8 ;_bfb .setOrReplaceProperty (_dbg );};
2022-06-27 19:44:23 +00:00
// X returns the inner wrapped XML type.
2022-12-06 11:56:49 +00:00
func (_becg Relationship )X ()*_aae .Relationship {return _becg ._dge };
2022-09-02 11:46:53 +00:00
2022-12-06 11:56:49 +00:00
// SetLanguage records the language of the document.
func (_fbg CoreProperties )SetLanguage (s string ){_fbg ._gdb .Language =&_gc .XSDAny {XMLName :_ee .Name {Local :"d\u0063\u003a\u006c\u0061\u006e\u0067\u0075\u0061\u0067\u0065"}};_fbg ._gdb .Language .Data =[]byte (s );};
2022-09-02 11:46:53 +00:00
2022-12-06 11:56:49 +00:00
// Modified returns the time that the document was modified.
func (_dggd CoreProperties )Modified ()_ef .Time {return _acad (_dggd ._gdb .Modified )};func (_fagb CustomProperties )SetPropertyAsError (name string ,error string ){_fad :=_fagb .getNewProperty (name );_fad .Error =&error ;_fagb .setOrReplaceProperty (_fad );};
2022-09-02 11:46:53 +00:00
2022-12-06 11:56:49 +00:00
// NewRelationship constructs a new relationship.
func NewRelationship ()Relationship {return Relationship {_dge :_aae .NewRelationship ()}};
// SetCreated sets the time that the document was created.
func (_edd CoreProperties )SetCreated (t _ef .Time ){_edd ._gdb .Created =_eaf (t ,"\u0064c\u0074e\u0072\u006d\u0073\u003a\u0063\u0072\u0065\u0061\u0074\u0065\u0064");};
// GetPropertyByName returns a custom property selected by it's name.
func (_fdf CustomProperties )GetPropertyByName (name string )CustomProperty {_abc :=_fdf ._ebc .Property ;for _ ,_gbd :=range _abc {if *_gbd .NameAttr ==name {return CustomProperty {_dcf :_gbd };};};return CustomProperty {};};
// ContentStatus returns the content status of the document (e.g. "Final", "Draft")
func (_egc CoreProperties )ContentStatus ()string {if _egc ._gdb .ContentStatus !=nil {return *_egc ._gdb .ContentStatus ;};return "";};func (_eeg CustomProperties )SetPropertyAsUi1 (name string ,ui1 uint8 ){_bfg :=_eeg .getNewProperty (name );_bfg .Ui1 =&ui1 ;_eeg .setOrReplaceProperty (_bfg );};func (_dafe Relationship )String ()string {return _aa .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",_dafe .ID (),_dafe .Target (),_dafe .Type ());};func (_bed CustomProperties )SetPropertyAsVector (name string ,vector *_fg .Vector ){_eba :=_bed .getNewProperty (name );_eba .Vector =vector ;_bed .setOrReplaceProperty (_eba );};var ReleasedAt =_ef .Date (_dffd ,_befa ,_caa ,_bfae ,_aec ,0,0,_ef .UTC );
// NewCoreProperties constructs a new CoreProperties.
func NewCoreProperties ()CoreProperties {return CoreProperties {_gdb :_bc .NewCoreProperties ()}};