mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-04 22:17:22 +08:00
39 lines
8.8 KiB
Go
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 (_c "bytes";_e "fmt";_g "github.com/unidoc/unichart/render";_fa "github.com/unidoc/unipdf/v3/common";_fc "github.com/unidoc/unipdf/v3/contentstream";_ef "github.com/unidoc/unipdf/v3/contentstream/draw";_eb "github.com/unidoc/unipdf/v3/core";
|
|
_d "github.com/unidoc/unipdf/v3/model";_f "image/color";_bc "io";_ea "math";);func (_cd *Renderer )wrapText (_gef string )[]string {var (_ee []string ;_agc []rune ;);for _ ,_dge :=range _gef {if _dge =='\n'{_ee =append (_ee ,string (_agc ));_agc =[]rune {};
|
|
continue ;};_agc =append (_agc ,_dge );};if len (_agc )> 0{_ee =append (_ee ,string (_agc ));};return _ee ;};func (_ce *Renderer )SetDPI (dpi float64 ){_ce ._ge =dpi };func (_eab *Renderer )ClearTextRotation (){_eab ._geg =0};func _bdf (_gcg string ,_agd int ,_gcd func (_eb .PdfObjectName )bool )_eb .PdfObjectName {_cec :=_eb .PdfObjectName (_e .Sprintf ("\u0025\u0073\u0025\u0064",_gcg ,_agd ));
|
|
for _bggc :=_agd ;_gcd (_cec );{_bggc ++;_cec =_eb .PdfObjectName (_e .Sprintf ("\u0025\u0073\u0025\u0064",_gcg ,_bggc ));};return _cec ;};func (_ac *Renderer )SetStrokeWidth (width float64 ){_ac ._gg =width ;_ac ._cb .Add_w (width )};func (_dee *Renderer )SetTextRotation (radians float64 ){_dee ._geg =_gbbb (-radians )};
|
|
func (_fba *Renderer )FillStroke (){_fba ._cb .Add_B ()};func NewRenderer (cc *_fc .ContentCreator ,res *_d .PdfPageResources )func (int ,int )(_g .Renderer ,error ){return func (_fcf ,_a int )(_g .Renderer ,error ){_ga :=&Renderer {_bd :_fcf ,_gb :_a ,_ge :72,_cb :cc ,_fd :res ,_fg :map[*_d .PdfFont ]_eb .PdfObjectName {}};
|
|
_ga .ResetStyle ();return _ga ,nil ;};};func (_de *Renderer )SetClassName (name string ){};func _aea (_dfb _f .Color )(float64 ,float64 ,float64 ,float64 ){_ceab ,_efg ,_edgg ,_ffb :=_feb (_dfb );return float64 (_ceab )/255,float64 (_efg )/255,float64 (_edgg )/255,float64 (_ffb )/255;
|
|
};func (_ag *Renderer )SetStrokeColor (color _f .Color ){_ag ._gd =color ;_efc ,_df ,_gac ,_ :=_aea (color );_ag ._cb .Add_RG (_efc ,_df ,_gac );};func _agfd (_adb float64 )float64 {return _adb *_ea .Pi /180.0};func (_fee *Renderer )SetFontColor (color _f .Color ){_fee ._ggc =color };
|
|
func (_ff *Renderer )GetDPI ()float64 {return _ff ._ge };func (_aca *Renderer )Stroke (){_aca ._cb .Add_S ()};func (_cfgg *Renderer )Close (){_cfgg ._cb .Add_h ()};func (_ec *Renderer )QuadCurveTo (cx ,cy ,x ,y int ){_ec ._cb .Add_v (float64 (x ),float64 (y ),float64 (cx ),float64 (cy ));
|
|
};func _feb (_feg _f .Color )(uint8 ,uint8 ,uint8 ,uint8 ){_ega ,_gc ,_cfb ,_cdg :=_feg .RGBA ();return uint8 (_ega >>8),uint8 (_gc >>8),uint8 (_cfb >>8),uint8 (_cdg >>8);};func (_ccf *Renderer )Circle (radius float64 ,x ,y int ){_fbb :=radius ;if _ceb :=_ccf ._gg ;
|
|
_ceb !=0{_fbb -=_ceb /2;};_ggcc :=_fbb *0.551784;_fbg :=_ef .CubicBezierPath {Curves :[]_ef .CubicBezierCurve {_ef .NewCubicBezierCurve (-_fbb ,0,-_fbb ,_ggcc ,-_ggcc ,_fbb ,0,_fbb ),_ef .NewCubicBezierCurve (0,_fbb ,_ggcc ,_fbb ,_fbb ,_ggcc ,_fbb ,0),_ef .NewCubicBezierCurve (_fbb ,0,_fbb ,-_ggcc ,_ggcc ,-_fbb ,0,-_fbb ),_ef .NewCubicBezierCurve (0,-_fbb ,-_ggcc ,-_fbb ,-_fbb ,-_ggcc ,-_fbb ,0)}};
|
|
if _gaf :=_ccf ._gg ;_gaf !=0{_fbg =_fbg .Offset (_gaf /2,_gaf /2);};_fbg =_fbg .Offset (float64 (x ),float64 (y ));_ef .DrawBezierPathWithCreator (_fbg ,_ccf ._cb );};func _gbbb (_bbe float64 )float64 {return _bbe *180/_ea .Pi };func (_edg *Renderer )MeasureText (text string )_g .Box {_gfg :=_edg ._be ;
|
|
_dbc ,_cga :=_edg ._gbb .GetFontDescriptor ();if _cga !=nil {_fa .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 {_acc ,_cba :=_dbc .GetCapHeight ();if _cba !=nil {_fa .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",_cba );
|
|
}else {_gfg =_acc /1000.0*_edg ._be ;};};var (_baf =0.0;_ffe =_edg .wrapText (text ););for _ ,_cge :=range _ffe {if _cea :=_edg .getTextWidth (_cge );_cea > _baf {_baf =_cea ;};};_eg :=_g .NewBox (0,0,int (_baf ),int (_gfg ));if _fdb :=_edg ._geg ;_fdb !=0{_eg =_eg .Corners ().Rotate (_fdb ).Box ();
|
|
};return _eg ;};type Renderer struct{_bd int ;_gb int ;_ge float64 ;_cb *_fc .ContentCreator ;_fd *_d .PdfPageResources ;_cc _f .Color ;_gd _f .Color ;_gg float64 ;_gbb *_d .PdfFont ;_be float64 ;_ggc _f .Color ;_geg float64 ;_fg map[*_d .PdfFont ]_eb .PdfObjectName ;
|
|
};func (_fcc *Renderer )MoveTo (x ,y int ){_fcc ._cb .Add_m (float64 (x ),float64 (y ))};func (_ggcf *Renderer )LineTo (x ,y int ){_ggcf ._cb .Add_l (float64 (x ),float64 (y ))};func (_ceg *Renderer )ArcTo (cx ,cy int ,rx ,ry ,startAngle ,deltaAngle float64 ){startAngle =_gbbb (2.0*_ea .Pi -startAngle );
|
|
deltaAngle =_gbbb (-deltaAngle );_cg ,_fb :=deltaAngle ,1;if _ea .Abs (deltaAngle )> 90.0{_fb =int (_ea .Ceil (_ea .Abs (deltaAngle )/90.0));_cg =deltaAngle /float64 (_fb );};var (_fca =_agfd (_cg /2);_gdg =_ea .Abs (4.0/3.0*(1.0-_ea .Cos (_fca ))/_ea .Sin (_fca ));
|
|
_cfg =float64 (cx );_agf =float64 (cy ););for _dag :=0;_dag < _fb ;_dag ++{_gfe :=_agfd (startAngle +float64 (_dag )*_cg );_af :=_agfd (startAngle +float64 (_dag +1)*_cg );_ca :=_ea .Cos (_gfe );_ba :=_ea .Cos (_af );_daf :=_ea .Sin (_gfe );_cgg :=_ea .Sin (_af );
|
|
var _gbe []float64 ;if _cg > 0{_gbe =[]float64 {_cfg +rx *_ca ,_agf -ry *_daf ,_cfg +rx *(_ca -_gdg *_daf ),_agf -ry *(_daf +_gdg *_ca ),_cfg +rx *(_ba +_gdg *_cgg ),_agf -ry *(_cgg -_gdg *_ba ),_cfg +rx *_ba ,_agf -ry *_cgg };}else {_gbe =[]float64 {_cfg +rx *_ca ,_agf -ry *_daf ,_cfg +rx *(_ca +_gdg *_daf ),_agf -ry *(_daf -_gdg *_ca ),_cfg +rx *(_ba -_gdg *_cgg ),_agf -ry *(_cgg +_gdg *_ba ),_cfg +rx *_ba ,_agf -ry *_cgg };
|
|
};if _dag ==0{_ceg ._cb .Add_l (_gbe [0],_gbe [1]);};_ceg ._cb .Add_c (_gbe [2],_gbe [3],_gbe [4],_gbe [5],_gbe [6],_gbe [7]);};};func (_da *Renderer )SetStrokeDashArray (dashArray []float64 ){_fe :=make ([]int64 ,len (dashArray ));for _fde ,_ace :=range dashArray {_fe [_fde ]=int64 (_ace );
|
|
};_da ._cb .Add_d (_fe ,0);};func (_cf *Renderer )ResetStyle (){_cf .SetFillColor (_f .Black );_cf .SetStrokeColor (_f .Transparent );_cf .SetStrokeWidth (0);_cf .SetFont (_d .DefaultFont ());_cf .SetFontColor (_f .Black );_cf .SetFontSize (12);_cf .SetTextRotation (0);
|
|
};func (_geb *Renderer )Text (text string ,x ,y int ){_geb ._cb .Add_q ();_geb .SetFont (_geb ._gbb );_bf ,_cac ,_bg ,_ :=_aea (_geb ._ggc );_geb ._cb .Add_rg (_bf ,_cac ,_bg );_geb ._cb .Translate (float64 (x ),float64 (y )).Scale (1,-1);if _dbg :=_geb ._geg ;
|
|
_dbg !=0{_geb ._cb .RotateDeg (_dbg );};_geb ._cb .Add_BT ().Add_TL (_geb ._be );var (_bfg =_geb ._gbb .Encoder ();_fbbc =_geb .wrapText (text );_fdeg =len (_fbbc ););for _gaaa ,_acaf :=range _fbbc {_geb ._cb .Add_TJ (_eb .MakeStringFromBytes (_bfg .Encode (_acaf )));
|
|
if _gaaa !=_fdeg -1{_geb ._cb .Add_Tstar ();};};_geb ._cb .Add_ET ();_geb ._cb .Add_Q ();};func (_gfc *Renderer )getTextWidth (_dgg string )float64 {var _fce float64 ;for _ ,_dgge :=range _dgg {_afg ,_bgd :=_gfc ._gbb .GetRuneMetrics (_dgge );if !_bgd {_fa .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",_dgge );
|
|
};_fce +=_afg .Wx ;};return _gfc ._be *_fce /1000.0;};func (_gaa *Renderer )Fill (){_gaa ._cb .Add_f ()};func (_bga *Renderer )Save (w _bc .Writer )error {if w ==nil {return nil ;};_ ,_dec :=_bc .Copy (w ,_c .NewBuffer (_bga ._cb .Bytes ()));return _dec ;
|
|
};func (_db *Renderer )SetFontSize (size float64 ){_db ._be =size };func (_efb *Renderer )SetFont (font _g .Font ){_ae ,_dg :=font .(*_d .PdfFont );if !_dg {_fa .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 ;};_bb ,_dg :=_efb ._fg [_ae ];if !_dg {_bb =_bdf ("\u0046\u006f\u006e\u0074",1,_efb ._fd .HasFontByName );if _cef :=_efb ._fd .SetFontByName (_bb ,_ae .ToPdfObject ());_cef !=nil {_fa .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",_ae );
|
|
};_efb ._fg [_ae ]=_bb ;};_efb ._cb .Add_Tf (_bb ,_efb ._be );_efb ._gbb =_ae ;};func (_ad *Renderer )SetFillColor (color _f .Color ){_ad ._cc =color ;_deb ,_ebg ,_gea ,_ :=_aea (color );_ad ._cb .Add_rg (_deb ,_ebg ,_gea );}; |