2022-12-15 21:59:56 +00:00

39 lines
8.8 KiB
Go

//
// 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 unichart ;import (_f "bytes";_c "fmt";_ba "github.com/unidoc/unichart/render";_e "github.com/unidoc/unipdf/v3/common";_cf "github.com/unidoc/unipdf/v3/contentstream";_bb "github.com/unidoc/unipdf/v3/contentstream/draw";_gc "github.com/unidoc/unipdf/v3/core";
_ge "github.com/unidoc/unipdf/v3/model";_ga "image/color";_g "io";_fd "math";);func (_cbg *Renderer )ResetStyle (){_cbg .SetFillColor (_ga .Black );_cbg .SetStrokeColor (_ga .Transparent );_cbg .SetStrokeWidth (0);_cbg .SetFont (_ge .DefaultFont ());_cbg .SetFontColor (_ga .Black );
_cbg .SetFontSize (12);_cbg .SetTextRotation (0);};func (_edb *Renderer )SetFont (font _ba .Font ){_bdd ,_be :=font .(*_ge .PdfFont );if !_be {_e .Log .Debug ("\u0045R\u0052\u004f\u0052\u003a\u0020\u0069\u006e\u0076\u0061\u006c\u0069d\u0020\u0066\u006f\u006e\u0074\u0020\u0074\u0079\u0070\u0065");
return ;};_egf ,_be :=_edb ._aa [_bdd ];if !_be {_egf =_cag ("\u0046\u006f\u006e\u0074",1,_edb ._d .HasFontByName );if _gga :=_edb ._d .SetFontByName (_egf ,_bdd .ToPdfObject ());_gga !=nil {_e .Log .Debug ("\u0045\u0052\u0052\u004f\u0052:\u0020\u0063\u006f\u0075\u006c\u0064\u0020\u006e\u006f\u0074\u0020\u0061\u0064d\u0020\u0066\u006f\u006e\u0074\u0020\u0025\u0076\u0020\u0074\u006f\u0020\u0072\u0065\u0073\u006f\u0075\u0072\u0063\u0065\u0073",_bdd );
};_edb ._aa [_bdd ]=_egf ;};_edb ._bc .Add_Tf (_egf ,_edb ._bd );_edb ._fc =_bdd ;};func (_egff *Renderer )SetFontSize (size float64 ){_egff ._bd =size };func (_ad *Renderer )MoveTo (x ,y int ){_ad ._bc .Add_m (float64 (x ),float64 (y ))};func (_gg *Renderer )Fill (){_gg ._bc .Add_f ()};
func _aac (_bbda _ga .Color )(uint8 ,uint8 ,uint8 ,uint8 ){_cef ,_ebg ,_cebc ,_ecb :=_bbda .RGBA ();return uint8 (_cef >>8),uint8 (_ebg >>8),uint8 (_cebc >>8),uint8 (_ecb >>8);};func (_db *Renderer )Stroke (){_db ._bc .Add_S ()};func (_add *Renderer )FillStroke (){_add ._bc .Add_B ()};
type Renderer struct{_cfg int ;_cc int ;_ce float64 ;_bc *_cf .ContentCreator ;_d *_ge .PdfPageResources ;_ec _ga .Color ;_fg _ga .Color ;_eg float64 ;_fc *_ge .PdfFont ;_bd float64 ;_a _ga .Color ;_bg float64 ;_aa map[*_ge .PdfFont ]_gc .PdfObjectName ;
};func _ddd (_cdd float64 )float64 {return _cdd *180/_fd .Pi };func (_cccg *Renderer )Save (w _g .Writer )error {if w ==nil {return nil ;};_ ,_faf :=_g .Copy (w ,_f .NewBuffer (_cccg ._bc .Bytes ()));return _faf ;};func NewRenderer (cc *_cf .ContentCreator ,res *_ge .PdfPageResources )func (int ,int )(_ba .Renderer ,error ){return func (_cb ,_fb int )(_ba .Renderer ,error ){_ced :=&Renderer {_cfg :_cb ,_cc :_fb ,_ce :72,_bc :cc ,_d :res ,_aa :map[*_ge .PdfFont ]_gc .PdfObjectName {}};
_ced .ResetStyle ();return _ced ,nil ;};};func (_df *Renderer )SetClassName (name string ){};func (_ggg *Renderer )Circle (radius float64 ,x ,y int ){_gd :=radius ;if _eec :=_ggg ._eg ;_eec !=0{_gd -=_eec /2;};_ff :=_gd *0.551784;_eee :=_bb .CubicBezierPath {Curves :[]_bb .CubicBezierCurve {_bb .NewCubicBezierCurve (-_gd ,0,-_gd ,_ff ,-_ff ,_gd ,0,_gd ),_bb .NewCubicBezierCurve (0,_gd ,_ff ,_gd ,_gd ,_ff ,_gd ,0),_bb .NewCubicBezierCurve (_gd ,0,_gd ,-_ff ,_ff ,-_gd ,0,-_gd ),_bb .NewCubicBezierCurve (0,-_gd ,-_ff ,-_gd ,-_gd ,-_ff ,-_gd ,0)}};
if _ged :=_ggg ._eg ;_ged !=0{_eee =_eee .Offset (_ged /2,_ged /2);};_eee =_eee .Offset (float64 (x ),float64 (y ));_bb .DrawBezierPathWithCreator (_eee ,_ggg ._bc );};func (_geb *Renderer )SetStrokeColor (color _ga .Color ){_geb ._fg =color ;_ed ,_cg ,_ee ,_ :=_gef (color );
_geb ._bc .Add_RG (_ed ,_cg ,_ee );};func _ffb (_adf float64 )float64 {return _adf *_fd .Pi /180.0};func (_dc *Renderer )ClearTextRotation (){_dc ._bg =0};func (_beb *Renderer )MeasureText (text string )_ba .Box {_fbg :=_beb ._bd ;_cgd ,_dgd :=_beb ._fc .GetFontDescriptor ();
if _dgd !=nil {_e .Log .Debug ("W\u0041\u0052\u004e\u003a\u0020\u0055n\u0061\u0062\u006c\u0065\u0020\u0074o\u0020\u0067\u0065\u0074\u0020\u0066\u006fn\u0074\u0020\u0064\u0065\u0073\u0063\u0072\u0069\u0070\u0074o\u0072");}else {_bgg ,_dda :=_cgd .GetCapHeight ();
if _dda !=nil {_e .Log .Debug ("\u0057\u0041\u0052\u004e\u003a\u0020\u0055\u006e\u0061\u0062\u006c\u0065\u0020t\u006f\u0020\u0067\u0065\u0074\u0020f\u006f\u006e\u0074\u0020\u0063\u0061\u0070\u0020\u0068\u0065\u0069\u0067\u0068t\u003a\u0020\u0025\u0076",_dda );
}else {_fbg =_bgg /1000.0*_beb ._bd ;};};var (_ceb =0.0;_dfe =_beb .wrapText (text ););for _ ,_da :=range _dfe {if _acd :=_beb .getTextWidth (_da );_acd > _ceb {_ceb =_acd ;};};_cce :=_ba .NewBox (0,0,int (_ceb ),int (_fbg ));if _ebd :=_beb ._bg ;_ebd !=0{_cce =_cce .Corners ().Rotate (_ebd ).Box ();
};return _cce ;};func (_ef *Renderer )GetDPI ()float64 {return _ef ._ce };func (_beg *Renderer )wrapText (_bcb string )[]string {var (_cfa []string ;_eeb []rune ;);for _ ,_agc :=range _bcb {if _agc =='\n'{_cfa =append (_cfa ,string (_eeb ));_eeb =[]rune {};
continue ;};_eeb =append (_eeb ,_agc );};if len (_eeb )> 0{_cfa =append (_cfa ,string (_eeb ));};return _cfa ;};func (_bcg *Renderer )LineTo (x ,y int ){_bcg ._bc .Add_l (float64 (x ),float64 (y ))};func (_gea *Renderer )SetDPI (dpi float64 ){_gea ._ce =dpi };
func (_dg *Renderer )SetFillColor (color _ga .Color ){_dg ._ec =color ;_bbe ,_bf ,_cbf ,_ :=_gef (color );_dg ._bc .Add_rg (_bbe ,_bf ,_cbf );};func (_cd *Renderer )Close (){_cd ._bc .Add_h ()};func (_fa *Renderer )SetStrokeDashArray (dashArray []float64 ){_bge :=make ([]int64 ,len (dashArray ));
for _bad ,_cgf :=range dashArray {_bge [_bad ]=int64 (_cgf );};_fa ._bc .Add_d (_bge ,0);};func (_egc *Renderer )QuadCurveTo (cx ,cy ,x ,y int ){_egc ._bc .Add_v (float64 (x ),float64 (y ),float64 (cx ),float64 (cy ));};func (_ca *Renderer )SetTextRotation (radians float64 ){_ca ._bg =_ddd (-radians )};
func (_bfe *Renderer )Text (text string ,x ,y int ){_bfe ._bc .Add_q ();_bfe .SetFont (_bfe ._fc );_ffa ,_geba ,_gb ,_ :=_gef (_bfe ._a );_bfe ._bc .Add_rg (_ffa ,_geba ,_gb );_bfe ._bc .Translate (float64 (x ),float64 (y )).Scale (1,-1);if _agb :=_bfe ._bg ;
_agb !=0{_bfe ._bc .RotateDeg (_agb );};_bfe ._bc .Add_BT ().Add_TL (_bfe ._bd );var (_gge =_bfe ._fc .Encoder ();_dd =_bfe .wrapText (text );_edbb =len (_dd ););for _dbd ,_dgb :=range _dd {_bfe ._bc .Add_TJ (_gc .MakeStringFromBytes (_gge .Encode (_dgb )));
if _dbd !=_edbb -1{_bfe ._bc .Add_Tstar ();};};_bfe ._bc .Add_ET ();_bfe ._bc .Add_Q ();};func (_gf *Renderer )SetStrokeWidth (width float64 ){_gf ._eg =width ;_gf ._bc .Add_w (width )};func _cag (_dbc string ,_bef int ,_gbd func (_gc .PdfObjectName )bool )_gc .PdfObjectName {_fda :=_gc .PdfObjectName (_c .Sprintf ("\u0025\u0073\u0025\u0064",_dbc ,_bef ));
for _cgde :=_bef ;_gbd (_fda );{_cgde ++;_fda =_gc .PdfObjectName (_c .Sprintf ("\u0025\u0073\u0025\u0064",_dbc ,_cgde ));};return _fda ;};func (_gac *Renderer )ArcTo (cx ,cy int ,rx ,ry ,startAngle ,deltaAngle float64 ){startAngle =_ddd (2.0*_fd .Pi -startAngle );
deltaAngle =_ddd (-deltaAngle );_dfd ,_af :=deltaAngle ,1;if _fd .Abs (deltaAngle )> 90.0{_af =int (_fd .Ceil (_fd .Abs (deltaAngle )/90.0));_dfd =deltaAngle /float64 (_af );};var (_cgb =_ffb (_dfd /2);_efd =_fd .Abs (4.0/3.0*(1.0-_fd .Cos (_cgb ))/_fd .Sin (_cgb ));
_ccc =float64 (cx );_cgg =float64 (cy ););for _ac :=0;_ac < _af ;_ac ++{_cedd :=_ffb (startAngle +float64 (_ac )*_dfd );_bga :=_ffb (startAngle +float64 (_ac +1)*_dfd );_fba :=_fd .Cos (_cedd );_acc :=_fd .Cos (_bga );_dfdc :=_fd .Sin (_cedd );_ag :=_fd .Sin (_bga );
var _eb []float64 ;if _dfd > 0{_eb =[]float64 {_ccc +rx *_fba ,_cgg -ry *_dfdc ,_ccc +rx *(_fba -_efd *_dfdc ),_cgg -ry *(_dfdc +_efd *_fba ),_ccc +rx *(_acc +_efd *_ag ),_cgg -ry *(_ag -_efd *_acc ),_ccc +rx *_acc ,_cgg -ry *_ag };}else {_eb =[]float64 {_ccc +rx *_fba ,_cgg -ry *_dfdc ,_ccc +rx *(_fba +_efd *_dfdc ),_cgg -ry *(_dfdc -_efd *_fba ),_ccc +rx *(_acc -_efd *_ag ),_cgg -ry *(_ag +_efd *_acc ),_ccc +rx *_acc ,_cgg -ry *_ag };
};if _ac ==0{_gac ._bc .Add_l (_eb [0],_eb [1]);};_gac ._bc .Add_c (_eb [2],_eb [3],_eb [4],_eb [5],_eb [6],_eb [7]);};};func _gef (_adb _ga .Color )(float64 ,float64 ,float64 ,float64 ){_fae ,_egg ,_fbb ,_ea :=_aac (_adb );return float64 (_fae )/255,float64 (_egg )/255,float64 (_fbb )/255,float64 (_ea )/255;
};func (_fad *Renderer )SetFontColor (color _ga .Color ){_fad ._a =color };func (_bbd *Renderer )getTextWidth (_ebf string )float64 {var _adc float64 ;for _ ,_efg :=range _ebf {_ebfa ,_dbf :=_bbd ._fc .GetRuneMetrics (_efg );if !_dbf {_e .Log .Debug ("\u0045\u0052\u0052OR\u003a\u0020\u0075\u006e\u0073\u0075\u0070\u0070\u006fr\u0074e\u0064 \u0072u\u006e\u0065\u0020\u0025\u0076\u0020\u0069\u006e\u0020\u0066\u006f\u006e\u0074",_efg );
};_adc +=_ebfa .Wx ;};return _bbd ._bd *_adc /1000.0;};