2022-04-27 00:10:33 +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-06-27 19:58:38 +00:00
|
|
|
package unichart ;import (_a "bytes";_b "fmt";_gb "github.com/unidoc/unichart/render";_bc "github.com/unidoc/unipdf/v3/common";_e "github.com/unidoc/unipdf/v3/contentstream";_c "github.com/unidoc/unipdf/v3/contentstream/draw";_gf "github.com/unidoc/unipdf/v3/core";
|
|
|
|
_df "github.com/unidoc/unipdf/v3/model";_da "image/color";_aa "io";_g "math";);func (_faa *Renderer )SetStrokeColor (color _da .Color ){_faa ._aag =color ;_cb ,_ee ,_gga ,_ :=_adf (color );_faa ._ag .Add_RG (_cb ,_ee ,_gga );};func (_cg *Renderer )GetDPI ()float64 {return _cg ._gc };
|
|
|
|
func (_bf *Renderer )LineTo (x ,y int ){_bf ._ag .Add_l (float64 (x ),float64 (y ))};func (_fcg *Renderer )SetFontColor (color _da .Color ){_fcg ._bd =color };func (_dad *Renderer )ArcTo (cx ,cy int ,rx ,ry ,startAngle ,deltaAngle float64 ){startAngle =_bfd (2.0*_g .Pi -startAngle );
|
|
|
|
deltaAngle =_bfd (-deltaAngle );_caa ,_fca :=deltaAngle ,1;if _g .Abs (deltaAngle )> 90.0{_fca =int (_g .Ceil (_g .Abs (deltaAngle )/90.0));_caa =deltaAngle /float64 (_fca );};var (_gbc =_bcf (_caa /2);_ec =_g .Abs (4.0/3.0*(1.0-_g .Cos (_gbc ))/_g .Sin (_gbc ));
|
|
|
|
_aee =float64 (cx );_ef =float64 (cy ););for _efa :=0;_efa < _fca ;_efa ++{_gfd :=_bcf (startAngle +float64 (_efa )*_caa );_bdb :=_bcf (startAngle +float64 (_efa +1)*_caa );_fe :=_g .Cos (_gfd );_ab :=_g .Cos (_bdb );_ccd :=_g .Sin (_gfd );_fgg :=_g .Sin (_bdb );
|
|
|
|
var _age []float64 ;if _caa > 0{_age =[]float64 {_aee +rx *_fe ,_ef -ry *_ccd ,_aee +rx *(_fe -_ec *_ccd ),_ef -ry *(_ccd +_ec *_fe ),_aee +rx *(_ab +_ec *_fgg ),_ef -ry *(_fgg -_ec *_ab ),_aee +rx *_ab ,_ef -ry *_fgg };}else {_age =[]float64 {_aee +rx *_fe ,_ef -ry *_ccd ,_aee +rx *(_fe +_ec *_ccd ),_ef -ry *(_ccd -_ec *_fe ),_aee +rx *(_ab -_ec *_fgg ),_ef -ry *(_fgg +_ec *_ab ),_aee +rx *_ab ,_ef -ry *_fgg };
|
|
|
|
};if _efa ==0{_dad ._ag .Add_l (_age [0],_age [1]);};_dad ._ag .Add_c (_age [2],_age [3],_age [4],_age [5],_age [6],_age [7]);};};func (_gcg *Renderer )QuadCurveTo (cx ,cy ,x ,y int ){_gcg ._ag .Add_v (float64 (x ),float64 (y ),float64 (cx ),float64 (cy ));
|
|
|
|
};func (_fgeg *Renderer )ClearTextRotation (){_fgeg ._caf =0};func (_aeb *Renderer )SetFont (font _gb .Font ){_bga ,_aad :=font .(*_df .PdfFont );if !_aad {_bc .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 ;};_de ,_aad :=_aeb ._cc [_bga ];if !_aad {_de =_fcae ("\u0046\u006f\u006e\u0074",1,_aeb ._dg .HasFontByName );if _fd :=_aeb ._dg .SetFontByName (_de ,_bga .ToPdfObject ());_fd !=nil {_bc .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",_bga );
|
|
|
|
};_aeb ._cc [_bga ]=_de ;};_aeb ._ag .Add_Tf (_de ,_aeb ._ae );_aeb ._fc =_bga ;};func (_ac *Renderer )Stroke (){_ac ._ag .Add_S ()};func _bfd (_bca float64 )float64 {return _bca *180/_g .Pi };func (_cbf *Renderer )Close (){_cbf ._ag .Add_h ()};func (_cd *Renderer )Fill (){_cd ._ag .Add_f ()};
|
|
|
|
func (_fef *Renderer )FillStroke (){_fef ._ag .Add_B ()};func (_gg *Renderer )SetClassName (name string ){};func (_fda *Renderer )SetTextRotation (radians float64 ){_fda ._caf =_bfd (-radians )};func NewRenderer (cc *_e .ContentCreator ,res *_df .PdfPageResources )func (int ,int )(_gb .Renderer ,error ){return func (_fa ,_bg int )(_gb .Renderer ,error ){_bde :=&Renderer {_ca :_fa ,_gd :_bg ,_gc :72,_ag :cc ,_dg :res ,_cc :map[*_df .PdfFont ]_gf .PdfObjectName {}};
|
|
|
|
_bde .ResetStyle ();return _bde ,nil ;};};func (_bdec *Renderer )SetDPI (dpi float64 ){_bdec ._gc =dpi };func (_abb *Renderer )Save (w _aa .Writer )error {if w ==nil {return nil ;};_ ,_ga :=_aa .Copy (w ,_a .NewBuffer (_abb ._ag .Bytes ()));return _ga ;
|
|
|
|
};type Renderer struct{_ca int ;_gd int ;_gc float64 ;_ag *_e .ContentCreator ;_dg *_df .PdfPageResources ;_f _da .Color ;_aag _da .Color ;_cad float64 ;_fc *_df .PdfFont ;_ae float64 ;_bd _da .Color ;_caf float64 ;_cc map[*_df .PdfFont ]_gf .PdfObjectName ;
|
|
|
|
};func _adf (_eg _da .Color )(float64 ,float64 ,float64 ,float64 ){_dcd ,_gag ,_cdd ,_eee :=_gad (_eg );return float64 (_dcd )/255,float64 (_gag )/255,float64 (_cdd )/255,float64 (_eee )/255;};func (_be *Renderer )Text (text string ,x ,y int ){_be ._ag .Add_q ();
|
|
|
|
_be .SetFont (_be ._fc );_bbf ,_dfe ,_bfg ,_ :=_adf (_be ._bd );_be ._ag .Add_rg (_bbf ,_dfe ,_bfg );_be ._ag .Translate (float64 (x ),float64 (y )).Scale (1,-1);if _dbc :=_be ._caf ;_dbc !=0{_be ._ag .RotateDeg (_dbc );};_be ._ag .Add_BT ().Add_TL (_be ._ae );
|
|
|
|
var (_bgdf =_be ._fc .Encoder ();_aaa =_be .wrapText (text );_dbd =len (_aaa ););for _agbg ,_dd :=range _aaa {_be ._ag .Add_TJ (_gf .MakeStringFromBytes (_bgdf .Encode (_dd )));if _agbg !=_dbd -1{_be ._ag .Add_Tstar ();};};_be ._ag .Add_ET ();_be ._ag .Add_Q ();
|
|
|
|
};func (_fg *Renderer )SetFillColor (color _da .Color ){_fg ._f =color ;_ce ,_db ,_agb ,_ :=_adf (color );_fg ._ag .Add_rg (_ce ,_db ,_agb );};func (_bac *Renderer )MoveTo (x ,y int ){_bac ._ag .Add_m (float64 (x ),float64 (y ))};func (_bb *Renderer )ResetStyle (){_bb .SetFillColor (_da .Black );
|
|
|
|
_bb .SetStrokeColor (_da .Transparent );_bb .SetStrokeWidth (0);_bb .SetFont (_df .DefaultFont ());_bb .SetFontColor (_da .Black );_bb .SetFontSize (12);_bb .SetTextRotation (0);};func (_bgd *Renderer )SetFontSize (size float64 ){_bgd ._ae =size };func (_af *Renderer )SetStrokeWidth (width float64 ){_af ._cad =width ;
|
|
|
|
_af ._ag .Add_w (width )};func (_aea *Renderer )Circle (radius float64 ,x ,y int ){_fge :=radius ;if _eda :=_aea ._cad ;_eda !=0{_fge -=_eda /2;};_fcaf :=_fge *0.551784;_fcd :=_c .CubicBezierPath {Curves :[]_c .CubicBezierCurve {_c .NewCubicBezierCurve (-_fge ,0,-_fge ,_fcaf ,-_fcaf ,_fge ,0,_fge ),_c .NewCubicBezierCurve (0,_fge ,_fcaf ,_fge ,_fge ,_fcaf ,_fge ,0),_c .NewCubicBezierCurve (_fge ,0,_fge ,-_fcaf ,_fcaf ,-_fge ,0,-_fge ),_c .NewCubicBezierCurve (0,-_fge ,-_fcaf ,-_fge ,-_fge ,-_fcaf ,-_fge ,0)}};
|
|
|
|
if _ecc :=_aea ._cad ;_ecc !=0{_fcd =_fcd .Offset (_ecc /2,_ecc /2);};_fcd =_fcd .Offset (float64 (x ),float64 (y ));_c .DrawBezierPathWithCreator (_fcd ,_aea ._ag );};func _fcae (_gfc string ,_adaf int ,_gfg func (_gf .PdfObjectName )bool )_gf .PdfObjectName {_afe :=_gf .PdfObjectName (_b .Sprintf ("\u0025\u0073\u0025\u0064",_gfc ,_adaf ));
|
|
|
|
for _gbd :=_adaf ;_gfg (_afe );{_gbd ++;_afe =_gf .PdfObjectName (_b .Sprintf ("\u0025\u0073\u0025\u0064",_gfc ,_gbd ));};return _afe ;};func _gad (_efab _da .Color )(uint8 ,uint8 ,uint8 ,uint8 ){_eca ,_fab ,_gbg ,_ecd :=_efab .RGBA ();return uint8 (_eca >>8),uint8 (_fab >>8),uint8 (_gbg >>8),uint8 (_ecd >>8);
|
|
|
|
};func (_bbfe *Renderer )MeasureText (text string )_gb .Box {_dae :=_bbfe ._ae ;_ded ,_gcd :=_bbfe ._fc .GetFontDescriptor ();if _gcd !=nil {_bc .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 {_bacb ,_deb :=_ded .GetCapHeight ();if _deb !=nil {_bc .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",_deb );
|
|
|
|
}else {_dae =_bacb /1000.0*_bbfe ._ae ;};};var (_dbe =0.0;_dc =_bbfe .wrapText (text ););for _ ,_bbg :=range _dc {if _add :=_bbfe .getTextWidth (_bbg );_add > _dbe {_dbe =_add ;};};_bae :=_gb .NewBox (0,0,int (_dbe ),int (_dae ));if _aab :=_bbfe ._caf ;
|
|
|
|
_aab !=0{_bae =_bae .Corners ().Rotate (_aab ).Box ();};return _bae ;};func _bcf (_fad float64 )float64 {return _fad *_g .Pi /180.0};func (_ge *Renderer )wrapText (_bbc string )[]string {var (_eaf []string ;_ggc []rune ;);for _ ,_fb :=range _bbc {if _fb =='\n'{_eaf =append (_eaf ,string (_ggc ));
|
|
|
|
_ggc =[]rune {};continue ;};_ggc =append (_ggc ,_fb );};if len (_ggc )> 0{_eaf =append (_eaf ,string (_ggc ));};return _eaf ;};func (_afb *Renderer )SetStrokeDashArray (dashArray []float64 ){_dfg :=make ([]int64 ,len (dashArray ));for _ea ,_ed :=range dashArray {_dfg [_ea ]=int64 (_ed );
|
|
|
|
};_afb ._ag .Add_d (_dfg ,0);};func (_edb *Renderer )getTextWidth (_dcc string )float64 {var _cab float64 ;for _ ,_dbg :=range _dcc {_gcde ,_ada :=_edb ._fc .GetRuneMetrics (_dbg );if !_ada {_bc .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",_dbg );
|
|
|
|
};_cab +=_gcde .Wx ;};return _edb ._ae *_cab /1000.0;};
|