2021-09-22 16:41:01 +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/
|
|
|
|
|
2022-01-15 21:17:38 +00:00
|
|
|
package convert ;import (_e "bytes";_g "errors";_bfc "github.com/unidoc/unioffice/common/logger";_caa "github.com/unidoc/unioffice/common/tempstorage";_ef "github.com/unidoc/unioffice/internal/convertutils";_d "github.com/unidoc/unioffice/measurement";_cb "github.com/unidoc/unioffice/presentation";_gd "github.com/unidoc/unioffice/schema/soo/dml";_ag "github.com/unidoc/unioffice/schema/soo/dml/chart";_fd "github.com/unidoc/unioffice/schema/soo/pml";_ae "github.com/unidoc/unipdf/v3/contentstream/draw";_efg "github.com/unidoc/unipdf/v3/creator";_ab "github.com/unidoc/unipdf/v3/model";_f "github.com/unidoc/unipdf/v3/render";_ca "image";_c "image/color";_a "image/draw";_ba "strconv";_bf "strings";);func (_dbfa *convertContext )getColorFromFontReference (_bcbf *_gd .CT_FontReference )_efg .Color {var _gfeb _efg .Color ;var _eacda string ;if _eaab :=_bcbf .SrgbClr ;_eaab !=nil {_eacda =_eaab .ValAttr ;}else if _gccb :=_bcbf .SchemeClr ;_gccb !=nil {_eacda =_ef .GetColorStringFromDmlColor (_dbfa ._abed .GetColorBySchemeColor (_gccb .ValAttr ));_eacda =_ef .AdjustColor (_eacda ,_gccb .EG_ColorTransform );};if _eacda !=""{_gfeb =_efg .ColorRGBFromHex ("\u0023"+_eacda );};return _gfeb ;};type line struct{_eae float64 ;_bbcd float64 ;_bcca float64 ;_gbfa float64 ;_defe float64 ;_daf []*word ;};func (_ea *convertContext )stretchImage (_edf *_efg .Image ,_dbe *_gd .CT_StretchInfoProperties ,_cde ,_fda ,_ffe ,_cbcc float64 )(*_efg .Image ,float64 ,float64 ){_feg :=_dbe .FillRect ;if _feg ==nil {_gba :=_edf .Width ()/_edf .Height ();_cg :=_ffe /_cbcc ;var _agf ,_feec float64 ;if _gba > _cg {_feec =_cbcc ;_agf =_cbcc *_gba ;}else {_agf =_ffe ;_feec =_ffe /_gba ;};_edf .Scale (_agf /_edf .Width (),_feec /_edf .Height ());return _edf ,_cde ,_fda ;};var _cf ,_bbac ,_bad ,_gaa float64 ;if _abeb :=_feg .LAttr ;_abeb !=nil {_bad =_ef .FromSTPercentage (_abeb );};if _deg :=_feg .TAttr ;_deg !=nil {_cf =_ef .FromSTPercentage (_deg );};if _bda :=_feg .RAttr ;_bda !=nil {_gaa =_ef .FromSTPercentage (_bda );};if _cac :=_feg .BAttr ;_cac !=nil {_bbac =_ef .FromSTPercentage (_cac );};_bgf :=_ffe *(1-_bad -_gaa );_dbeb :=_cbcc *(1-_cf -_bbac );_edf .Scale (_bgf /_edf .Width (),_dbeb /_edf .Height ());return _edf ,_cde +_bad *_ffe ,_fda +_cf *_cbcc ;};func (_gdf *convertContext )makeSlide (){_dfe :=_gdf ._acfa .X ().CSld ;if _dfe ==nil {return ;};_efb :=&background {};if _ge :=_dfe .Bg ;_ge !=nil {if _af :=_ge .BgPr ;_af !=nil {if _af .NoFill ==nil {if _eeef :=_af .SolidFill ;_eeef !=nil {_gdb ,_gcf :=_gdf .getColorFromSolidFill (_eeef );if _gdb !=nil {_efb ._fea =_gdb ;_efb ._bdeb =_gcf ;};}else if _bcg :=_af .BlipFill ;_bcg !=nil {_efb ._bbaeb =_bcg ;};};};};_gdf ._gggf =_efb ;if _fca :=_dfe .SpTree ;_fca !=nil {for _ ,_ce :=range _fca .Choice {if _ce !=nil {for _ ,_dg :=range _ce .Sp {if _dg !=nil {_adg :=_gdf .getShapes (_dg );_gdf ._egcc =append (_gdf ._egcc ,_adg ...);};};for _ ,_bdb :=range _ce .GraphicFrame {if _bdb !=nil {var _gde ,_baa ,_add ,_eeeb float64 ;if _afd :=_bdb .Xfrm ;_afd !=nil {_gde ,_baa ,_add ,_eeeb =_ef .GetDataFromXfrm (_afd );};if _cae :=_bdb .Graphic ;_cae !=nil {if _ddg :=_cae .GraphicData ;_ddg !=nil {for _ ,_gcd :=range _ddg .Any {if _de ,_eb :=_gcd .(*_ag .Chart );_eb {_dff ,_bb :=_gdf .makePdfBlockFromChart (_de ,_add ,_eeeb );if _bb !=nil {_bfc .Log .Debug ("C\u0061\u006e\u006e\u006ft \u0072e\u0061\u0064\u0020\u0062\u006co\u0063\u006b\u003a\u0020\u0025\u0073",_bb );};if _dff !=nil {_dff .SetPos (_gde ,_baa );_gdf ._egcc =append (_gdf ._egcc ,_dff );};}else if _cc ,_eff :=_gcd .(*_gd .Tbl );_eff {_edc :=_gdf .makePdfBlockFromTable (_cc ,_add );if _edc !=nil {_bcf :=_efg .NewBlock (_add ,_eeeb );_bcf .SetPos (_gde ,_baa );_bcf .Draw (_edc );_gdf ._egcc =append (_gdf ._egcc ,_bcf );};};};};};};};for _ ,_gdc :=range _ce .CxnSp {if _gdc !=nil {_efgg :=_gdf .getConnectors (_gdc );_gdf ._egcc =append (_gdf ._egcc ,_efgg ...);};};for _ ,_bcge :=range _ce .Pic {if _bcge !=nil {var _adc ,_aea ,_bcfb ,_fg float64 ;if _fef :=_bcge .SpPr ;_fef !=nil {if _afg :=_fef .Xfrm ;_afg !=nil {_adc ,_aea ,_bcfb ,_fg =_ef .GetDataFromXfrm (
|
2021-09-22 16:41:01 +00:00
|
|
|
|
|
|
|
// FontStyle represents a kind of font styling. It can be FontStyle_Regular, FontStyle_Bold, FontStyle_Italic and FontStyle_BoldItalic.
|
2022-01-15 21:17:38 +00:00
|
|
|
type FontStyle =_ef .FontStyle ;func (_fgd *convertContext )tileImage (_gfe *_efg .Image ,_gce *_gd .CT_TileInfoProperties ,_gae ,_cbg float64 )*_efg .Image {_fcaa ,_ffc :=1.0,1.0;if _ede :=_gce .SxAttr ;_ede !=nil {_fcaa =_ef .FromSTPercentage (_ede );};if _bgb :=_gce .SyAttr ;_bgb !=nil {_ffc =_ef .FromSTPercentage (_bgb );};_gfc :=_ef .MakeTempCreator (_gae ,_cbg );_gfe .Scale (_fcaa ,_ffc );_edg ,_bbc :=_gfe .Width (),_gfe .Height ();var _db ,_fbcf float64 ;if _bcc :=_gce .TxAttr ;_bcc !=nil {_db =_d .FromEMU (_ef .FromSTCoordinate (*_bcc ));};if _gcee :=_gce .TyAttr ;_gcee !=nil {_fbcf =_d .FromEMU (_ef .FromSTCoordinate (*_gcee ));};if _db > 0{_db -=_edg ;};if _fbcf > 0{_fbcf -=_bbc ;};_fga :=_fgd ._bcfe /_edg +1;_ebg :=_fgd ._fabbd /_bbc +1;for _bac :=0.0;_bac <=_fga ;_bac ++{_cab :=_bac *_edg ;for _cdd :=0.0;_cdd <=_ebg ;_cdd ++{_fag :=_cdd *_bbc ;_gfe .SetPos (_cab +_db ,_fag +_fbcf );_gfc .Draw (_gfe );};};_bgg ,_abe :=_ef .GetPageFromCreator (_gfc );if _abe !=nil {_bfc .Log .Debug ("\u0043\u0061\u006e\u006e\u006f\u0074 \u0067\u0065\u0074\u0020\u0069\u006d\u0061\u0067\u0065\u0020\u0066\u0072\u006fm\u0020\u0063\u0072\u0065\u0061\u0074\u006fr\u003a\u0020\u0025\u0073",_abe );return nil ;};_adge ,_abe :=_f .NewImageDevice ().Render (_bgg );if _abe !=nil {_bfc .Log .Debug ("\u0043\u0061\u006eno\u0074\u0020\u0072\u0065\u006e\u0064\u0065\u0072\u0020\u0069\u006d\u0061\u0067\u0065\u003a\u0020\u0025\u0073",_abe );return nil ;};_abg ,_abe :=_fgd ._ebe .NewImageFromGoImage (_adge );if _abe !=nil {_bfc .Log .Debug ("\u0043\u0061nn\u006f\u0074\u0020c\u0072\u0065\u0061\u0074e i\u006dag\u0065\u0020\u0066\u0072\u006f\u006d\u0020Go\u0049\u006d\u0061\u0067\u0065\u003a\u0020%\u0073",_abe );return nil ;};return _abg ;};func _fbbb (_egcd float64 )float64 {return _egcd *_d .Millimeter };func (_fbe *convertContext )drawSlide (){_fbe ._ebe .NewPage ();for _ ,_ff :=range _fbe ._egcc {if _ff !=nil {_fbe ._ebe .MoveTo (0,0);_fbe ._ebe .Draw (_ff );};};};
|
|
|
|
|
|
|
|
// ConvertToPdf converts a presentation to a PDF file. This package is beta, breaking changes can take place.
|
|
|
|
func ConvertToPdf (pr *_cb .Presentation )*_efg .Creator {_bag :=pr .X ().SldSz ;_fee :=_d .FromEMU (int64 (_bag .CxAttr ));_ed :=_d .FromEMU (int64 (_bag .CyAttr ));_bc :=_efg .PageSize {_fee ,_ed };_fb :=_efg .New ();_fb .SetPageSize (_bc );var _fc *_gd .Theme ;if len (pr .Themes ())> 0{_fc =pr .Themes ()[0];};for _ ,_bg :=range pr .Slides (){if _bg .X ()==nil {continue ;};_fcg :=&convertContext {_ebe :_fb ,_acfa :&_bg ,_aged :_bg .GetSlideLayout (),_fgc :pr .SlideMasters ()[0].X (),_abed :pr ,_ccfe :_fc ,_beg :_bg .X ().ClrMapOvr ,_fabbd :_bc [1],_bcfe :_bc [0]};_fcg ._aged =_bg .GetSlideLayout ();_fcg .extractDefaultProperties ();_fcg .makeSlide ();_fcg .drawSlide ();};return _fb ;};func _cdgc (_bgbef *bool )bool {return _bgbef !=nil &&*_bgbef };func _efafc (_cgbc *_gd .CT_TableCellProperties ,_gcgd *_gd .CT_TableStyleCellStyle ,_aeda ,_bdag ,_cacb ,_ggcd bool )*_gd .CT_TableCellProperties {_egccf :=_gd .NewCT_TableCellProperties ();if _cgbc !=nil {*_egccf =*_cgbc ;};if _gcgd ==nil {return _egccf ;};if _beebb :=_gcgd .FillRef ;_beebb !=nil {_defg :=_gd .NewCT_SolidColorFillProperties ();_defg .ScrgbClr =_beebb .ScrgbClr ;_defg .SrgbClr =_beebb .SrgbClr ;_defg .HslClr =_beebb .HslClr ;_defg .SysClr =_beebb .SysClr ;_defg .SchemeClr =_beebb .SchemeClr ;_defg .PrstClr =_beebb .PrstClr ;_egccf .SolidFill =_defg ;};if _egccf .NoFill ==nil &&_egccf .SolidFill ==nil {if _gagc :=_gcgd .Fill ;_gagc !=nil {if _egccf .NoFill ==nil {_egccf .NoFill =_gagc .NoFill ;};if _egccf .SolidFill ==nil {_egccf .SolidFill =_gagc .SolidFill ;};};};if _eaea :=_gcgd .TcBdr ;_eaea !=nil {if _egccf .LnL ==nil {var _cbf *_gd .CT_ThemeableLineStyle ;if _cacb {_cbf =_eaea .Left ;}else {_cbf =_eaea .InsideV ;};if _cbf !=nil {_egccf .LnL =_cbf .Ln ;};};if _egccf .LnR ==nil {var _fgca *_gd .CT_ThemeableLineStyle ;if _ggcd {_fgca =_eaea .Right ;}else {_fgca =_eaea .InsideV ;};if _fgca !=nil {_egccf .LnR =_fgca .Ln ;};};if _egccf .LnT ==nil {var _ded *_gd .CT_ThemeableLineStyle ;if _aeda {_ded =_eaea .Top ;}else {_ded =_eaea .InsideH ;};if _ded !=nil {_egccf .LnT =_ded .Ln ;};};if _egccf .LnB ==nil {var _gge *_gd .CT_ThemeableLineStyle ;if _bdag {_gge =_eaea .Bottom ;}else {_gge =_eaea .InsideH ;};if _gge !=nil {_egccf .LnB =_gge .Ln ;};};};return _egccf ;};func _eca (_bcfbd ,_dged *_gd .CT_TextCharacterProperties )*_gd .CT_TextCharacterProperties {_ggace :=_gd .NewCT_TextCharacterProperties ();if _bcfbd !=nil {*_ggace =*_bcfbd ;};if _dged ==nil {return _ggace ;};if _ggace .KumimojiAttr ==nil {_ggace .KumimojiAttr =_dged .KumimojiAttr ;};if _ggace .LangAttr ==nil {_ggace .LangAttr =_dged .LangAttr ;};if _ggace .AltLangAttr ==nil {_ggace .AltLangAttr =_dged .AltLangAttr ;};if _ggace .SzAttr ==nil {_ggace .SzAttr =_dged .SzAttr ;};if _ggace .BAttr ==nil {_ggace .BAttr =_dged .BAttr ;};if _ggace .IAttr ==nil {_ggace .IAttr =_dged .IAttr ;};if _ggace .UAttr ==_gd .ST_TextUnderlineTypeUnset {_ggace .UAttr =_dged .UAttr ;};if _ggace .StrikeAttr ==_gd .ST_TextStrikeTypeUnset {_ggace .StrikeAttr =_dged .StrikeAttr ;};if _ggace .KernAttr ==nil {_ggace .KernAttr =_dged .KernAttr ;};if _ggace .CapAttr ==_gd .ST_TextCapsTypeUnset {_ggace .CapAttr =_dged .CapAttr ;};if _ggace .SpcAttr ==nil {_ggace .SpcAttr =_dged .SpcAttr ;};if _ggace .NormalizeHAttr ==nil {_ggace .NormalizeHAttr =_dged .NormalizeHAttr ;};if _ggace .BaselineAttr ==nil {_ggace .BaselineAttr =_dged .BaselineAttr ;};if _ggace .NoProofAttr ==nil {_ggace .NoProofAttr =_dged .NoProofAttr ;};if _ggace .DirtyAttr ==nil {_ggace .DirtyAttr =_dged .DirtyAttr ;};if _ggace .ErrAttr ==nil {_ggace .ErrAttr =_dged .ErrAttr ;};if _ggace .SmtCleanAttr ==nil {_ggace .SmtCleanAttr =_dged .SmtCleanAttr ;};if _ggace .SmtIdAttr ==nil {_ggace .SmtIdAttr =_dged .SmtIdAttr ;};if _ggace .BmkAttr ==nil {_ggace .BmkAttr =_dged .BmkAttr ;};if _ggace .Ln ==nil {_ggace .Ln =_dged .Ln ;};if _ggace .NoFill ==nil {_ggace .NoFill =_dged .NoFill ;};if _ggace .SolidFill ==nil {_ggace .SolidFill =_dged .SolidFill ;};if _ggace .BlipFill ==nil {_ggace .BlipFill =_dged .BlipFill ;};if _ggace .EffectLst ==nil {_ggace .EffectLst =_dged .Eff
|
2021-11-10 11:45:21 +00:00
|
|
|
|
|
|
|
// RegisterFontsFromDirectory registers all fonts from the given directory automatically detecting font families and styles.
|
2022-01-15 21:17:38 +00:00
|
|
|
func RegisterFontsFromDirectory (dirName string )error {return _ef .RegisterFontsFromDirectory (dirName )};
|
2021-11-10 11:45:21 +00:00
|
|
|
|
2022-01-15 21:17:38 +00:00
|
|
|
// RegisterFont makes a PdfFont accessible for using in converting to PDF.
|
|
|
|
func RegisterFont (name string ,style FontStyle ,font *_ab .PdfFont ){_ef .RegisterFont (name ,style ,font );};func (_dfc *textboxContext )addCurrentWordToParagraph (){if _dfc ._aeaa &&_dfc ._bfcd ._gbfa +_dfc ._dbd ._bfa > _dfc ._bfcd ._bcca {_dfc .newLine ();};if !_dfc ._dbd ._gdff ||len (_dfc ._bfcd ._daf )> 0{_dfc ._dbd ._edcb =_dfc ._bfcd ._gbfa ;_dfc ._bfcd ._daf =append (_dfc ._bfcd ._daf ,_dfc ._dbd );_dfc ._bfcd ._gbfa +=_dfc ._dbd ._bfa ;for _ ,_deee :=range _dfc ._dbd ._cdba {_dfc .adjustHeights (_deee ._dfecc );};};};func (_fbd *textboxContext )newParagraph (){_eaff :=¶graph {};_eaff ._efaa =_fbd ._bde ;_fbd ._cgef =_eaff ;};func _gdba (_gcff int ,_acec bool )string {_dce :=(_gcff -1)/26+1;_ebf :=byte ((_gcff -1)%26);if _acec {_ebf +=byte (65);}else {_ebf +=byte (97);};_eded :=_e .NewBuffer ([]byte {});for _fbba :=0;_fbba < _dce ;_fbba ++{_eded .Write ([]byte {_ebf });};return _eded .String ();};func (_gdfb *convertContext )makeStyleFromRPr (_gaac *_gd .CT_TextCharacterProperties )(*_efg .TextStyle ,bool ,bool ,bool ){var _bcd ,_eacg ,_fdbf bool ;_afc :=_gdfb ._ebe .NewTextStyle ();if _gaac !=nil {_bdd :=_ef .FontStyle_Regular ;_dfba :=_cdgc (_gaac .BAttr );_gbfg :=_cdgc (_gaac .IAttr );if _dfba &&_gbfg {_bdd =_ef .FontStyle_BoldItalic ;}else if _dfba {_bdd =_ef .FontStyle_Bold ;}else if _gbfg {_bdd =_ef .FontStyle_Italic ;};_fdbf =_gaac .UAttr !=_gd .ST_TextUnderlineTypeUnset &&_gaac .UAttr !=_gd .ST_TextUnderlineTypeNone ;_fbed :="\u0064e\u0066\u0061\u0075\u006c\u0074";if _cacc :=_gaac .Latin ;_cacc !=nil {_fbed =_cacc .TypefaceAttr ;}else if _cfb :=_gaac .Ea ;_cfb !=nil {_fbed =_cfb .TypefaceAttr ;}else if _eedg :=_gaac .Cs ;_eedg !=nil {_fbed =_eedg .TypefaceAttr ;}else if _eba :=_gaac .Sym ;_eba !=nil {_fbed =_eba .TypefaceAttr ;};if _fedd ,_ccg :=_ef .StdFontsMap [_fbed ];_ccg {_afc .Font =_ef .AssignStdFontByName (_afc ,_fedd [_bdd ]);}else if _cdcd :=_ef .GetRegisteredFont (_fbed ,_bdd );_cdcd !=nil {_afc .Font =_cdcd ;}else {_bfc .Log .Debug ("\u0046\u006f\u006e\u0074\u0020\u0025\u0073\u0020\u0077\u0069\u0074h\u0020\u0073\u0074\u0079\u006c\u0065\u0020\u0025s\u0020i\u0073\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064\u002c\u0020\u0072\u0065\u0073\u0065\u0074 \u0074\u006f\u0020\u0064\u0065\u0066\u0061\u0075\u006c\u0074\u002e",_fbed ,_bdd );_afc .Font =_ef .AssignStdFontByName (_afc ,_ef .StdFontsMap ["\u0064e\u0066\u0061\u0075\u006c\u0074"][_bdd ]);};var _aga float64 ;if _eecd :=_gaac .SzAttr ;_eecd !=nil {_aga =float64 (*_eecd )/100;}else {_aga =_ef .DefaultFontSize ;};if _cga :=_gaac .BaselineAttr ;_cga !=nil {if _gggb :=_cga .ST_PercentageDecimal ;_gggb !=nil {if *_gggb > 0{_bcd =true ;}else if *_gggb < 0{_eacg =true ;};};};if _bcd ||_eacg {_aga *=0.64;};_afc .FontSize =_aga ;_dad :=0.0;if _dfa :=_gaac .SpcAttr ;_dfa !=nil {if _bbca :=_dfa .ST_TextPointUnqualified ;_bbca !=nil {_dad =float64 (*_bbca )/100;};};_afc .CharSpacing =_dad ;};return &_afc ,_bcd ,_eacg ,_fdbf ;};func (_cbdf *textboxContext )alignParagraphsVertically (_feecg _gd .ST_TextAnchoringType ){if _feecg ==_gd .ST_TextAnchoringTypeT {return ;};_defa :=0.0;for _ ,_bcb :=range _cbdf ._gcg {_defa +=_bcb ._bded +_bcb ._fgfb +_bcb ._aeef ;};var _fgeg float64 ;switch _feecg {case _gd .ST_TextAnchoringTypeCtr :_fgeg =(_cbdf ._acfg -_defa )/2;case _gd .ST_TextAnchoringTypeB :_fgeg =_cbdf ._acfg -_defa ;};for _ ,_bfgd :=range _cbdf ._gcg {_bfgd ._efaa +=_fgeg ;};};func (_fabb *convertContext )getBorderStyle (_bab *_gd .CT_LineProperties )(_efg .CellBorderStyle ,*_efg .Color ,float64 ){if _bab ==nil ||_bab .NoFill !=nil {return _efg .CellBorderStyleNone ,nil ,0;};var _bbed _efg .Color ;if _cecg :=_bab .SolidFill ;_cecg !=nil {_bbed ,_ =_fabb .getColorFromSolidFill (_cecg );};_dga :=0.0;if _ggbe :=_bab .WAttr ;_ggbe !=nil {_dga =_d .FromEMU (int64 (*_ggbe ));};return _efg .CellBorderStyleSingle ,&_bbed ,_dga ;};func (_ga *convertContext )extractDefaultProperties (){_cd :=_ga ._abed .X ();_gag :=_cd .DefaultTextStyle ;var _fcf ,_faa ,_be ,_ac ,_fbc ,_gb ,_gc ,_gbf ,_eeec ,_ad *_gd .CT_TextParagraphProperties ;if _gag !=nil {_f
|