mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +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 (_f "bytes";_a "fmt";_d "github.com/unidoc/unichart/render";_cc "github.com/unidoc/unipdf/v3/common";_bf "github.com/unidoc/unipdf/v3/contentstream";_ag "github.com/unidoc/unipdf/v3/contentstream/draw";_fd "github.com/unidoc/unipdf/v3/core";
|
|
_cce "github.com/unidoc/unipdf/v3/model";_fe "image/color";_g "io";_b "math";);func (_dga *Renderer )Text (text string ,x ,y int ){_dga ._af .Add_q ();_dga .SetFont (_dga ._gf );_bded ,_fce ,_bgc ,_ :=_fed (_dga ._be );_dga ._af .Add_rg (_bded ,_fce ,_bgc );
|
|
_dga ._af .Translate (float64 (x ),float64 (y )).Scale (1,-1);if _feb :=_dga ._ec ;_feb !=0{_dga ._af .RotateDeg (_feb );};_dga ._af .Add_BT ().Add_TL (_dga ._e );var (_ac =_dga ._gf .Encoder ();_ccd =_dga .wrapText (text );_cfa =len (_ccd ););for _adg ,_bac :=range _ccd {_dga ._af .Add_TJ (_fd .MakeStringFromBytes (_ac .Encode (_bac )));
|
|
if _adg !=_cfa -1{_dga ._af .Add_Tstar ();};};_dga ._af .Add_ET ();_dga ._af .Add_Q ();};func _gff (_fceb float64 )float64 {return _fceb *_b .Pi /180.0};func (_dg *Renderer )SetClassName (name string ){};func (_gbc *Renderer )SetStrokeDashArray (dashArray []float64 ){_dgg :=make ([]int64 ,len (dashArray ));
|
|
for _dfaf ,_gcf :=range dashArray {_dgg [_dfaf ]=int64 (_gcf );};_gbc ._af .Add_d (_dgg ,0);};func (_bda *Renderer )SetStrokeColor (color _fe .Color ){_bda ._db =color ;_ga ,_de ,_bc ,_ :=_fed (color );_bda ._af .Add_RG (_ga ,_de ,_bc );};func (_gae *Renderer )Save (w _g .Writer )error {if w ==nil {return nil ;
|
|
};_ ,_adf :=_g .Copy (w ,_f .NewBuffer (_gae ._af .Bytes ()));return _adf ;};func (_gbcc *Renderer )ClearTextRotation (){_gbcc ._ec =0};func (_eag *Renderer )ArcTo (cx ,cy int ,rx ,ry ,startAngle ,deltaAngle float64 ){startAngle =_cdf (2.0*_b .Pi -startAngle );
|
|
deltaAngle =_cdf (-deltaAngle );_afg ,_gcb :=deltaAngle ,1;if _b .Abs (deltaAngle )> 90.0{_gcb =int (_b .Ceil (_b .Abs (deltaAngle )/90.0));_afg =deltaAngle /float64 (_gcb );};var (_ge =_gff (_afg /2);_edb =_b .Abs (4.0/3.0*(1.0-_b .Cos (_ge ))/_b .Sin (_ge ));
|
|
_agd =float64 (cx );_ad =float64 (cy ););for _bg :=0;_bg < _gcb ;_bg ++{_ecc :=_gff (startAngle +float64 (_bg )*_afg );_ff :=_gff (startAngle +float64 (_bg +1)*_afg );_gfd :=_b .Cos (_ecc );_ce :=_b .Cos (_ff );_cab :=_b .Sin (_ecc );_ba :=_b .Sin (_ff );
|
|
var _cg []float64 ;if _afg > 0{_cg =[]float64 {_agd +rx *_gfd ,_ad -ry *_cab ,_agd +rx *(_gfd -_edb *_cab ),_ad -ry *(_cab +_edb *_gfd ),_agd +rx *(_ce +_edb *_ba ),_ad -ry *(_ba -_edb *_ce ),_agd +rx *_ce ,_ad -ry *_ba };}else {_cg =[]float64 {_agd +rx *_gfd ,_ad -ry *_cab ,_agd +rx *(_gfd +_edb *_cab ),_ad -ry *(_cab -_edb *_gfd ),_agd +rx *(_ce -_edb *_ba ),_ad -ry *(_ba +_edb *_ce ),_agd +rx *_ce ,_ad -ry *_ba };
|
|
};if _bg ==0{_eag ._af .Add_l (_cg [0],_cg [1]);};_eag ._af .Add_c (_cg [2],_cg [3],_cg [4],_cg [5],_cg [6],_cg [7]);};};func (_ed *Renderer )QuadCurveTo (cx ,cy ,x ,y int ){_ed ._af .Add_v (float64 (x ),float64 (y ),float64 (cx ),float64 (cy ));};func (_fcf *Renderer )wrapText (_baa string )[]string {var (_gcfc []string ;
|
|
_acb []rune ;);for _ ,_afb :=range _baa {if _afb =='\n'{_gcfc =append (_gcfc ,string (_acb ));_acb =[]rune {};continue ;};_acb =append (_acb ,_afb );};if len (_acb )> 0{_gcfc =append (_gcfc ,string (_acb ));};return _gcfc ;};func _bec (_bgg _fe .Color )(uint8 ,uint8 ,uint8 ,uint8 ){_eagc ,_gcbg ,_gfe ,_gbe :=_bgg .RGBA ();
|
|
return uint8 (_eagc >>8),uint8 (_gcbg >>8),uint8 (_gfe >>8),uint8 (_gbe >>8);};func (_gfb *Renderer )Fill (){_gfb ._af .Add_f ()};func (_dfa *Renderer )GetDPI ()float64 {return _dfa ._gc };func _cdf (_gea float64 )float64 {return _gea *180/_b .Pi };func (_fb *Renderer )SetFontColor (color _fe .Color ){_fb ._be =color };
|
|
func (_dea *Renderer )MeasureText (text string )_d .Box {_fg :=_dea ._e ;_afd ,_fde :=_dea ._gf .GetFontDescriptor ();if _fde !=nil {_cc .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 {_cd ,_ead :=_afd .GetCapHeight ();if _ead !=nil {_cc .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",_ead );
|
|
}else {_fg =_cd /1000.0*_dea ._e ;};};var (_bad =0.0;_gcbe =_dea .wrapText (text ););for _ ,_ab :=range _gcbe {if _fbb :=_dea .getTextWidth (_ab );_fbb > _bad {_bad =_fbb ;};};_aef :=_d .NewBox (0,0,int (_bad ),int (_fg ));if _gce :=_dea ._ec ;_gce !=0{_aef =_aef .Corners ().Rotate (_gce ).Box ();
|
|
};return _aef ;};func (_ee *Renderer )LineTo (x ,y int ){_ee ._af .Add_l (float64 (x ),float64 (y ))};func _adgd (_da string ,_ebeb int ,_gge func (_fd .PdfObjectName )bool )_fd .PdfObjectName {_acdf :=_fd .PdfObjectName (_a .Sprintf ("\u0025\u0073\u0025\u0064",_da ,_ebeb ));
|
|
for _aad :=_ebeb ;_gge (_acdf );{_aad ++;_acdf =_fd .PdfObjectName (_a .Sprintf ("\u0025\u0073\u0025\u0064",_da ,_aad ));};return _acdf ;};func (_cde *Renderer )getTextWidth (_acd string )float64 {var _afgc float64 ;for _ ,_bbb :=range _acd {_aed ,_cda :=_cde ._gf .GetRuneMetrics (_bbb );
|
|
if !_cda {_cc .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",_bbb );};_afgc +=_aed .Wx ;};return _cde ._e *_afgc /1000.0;
|
|
};func (_ebe *Renderer )SetFont (font _d .Font ){_dce ,_gec :=font .(*_cce .PdfFont );if !_gec {_cc .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 ;
|
|
};_ced ,_gec :=_ebe ._dc [_dce ];if !_gec {_ced =_adgd ("\u0046\u006f\u006e\u0074",1,_ebe ._fc .HasFontByName );if _gaa :=_ebe ._fc .SetFontByName (_ced ,_dce .ToPdfObject ());_gaa !=nil {_cc .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",_dce );
|
|
};_ebe ._dc [_dce ]=_ced ;};_ebe ._af .Add_Tf (_ced ,_ebe ._e );_ebe ._gf =_dce ;};func (_fef *Renderer )Circle (radius float64 ,x ,y int ){_aaf :=radius ;if _eac :=_fef ._gg ;_eac !=0{_aaf -=_eac /2;};_gee :=_aaf *0.551784;_aaa :=_ag .CubicBezierPath {Curves :[]_ag .CubicBezierCurve {_ag .NewCubicBezierCurve (-_aaf ,0,-_aaf ,_gee ,-_gee ,_aaf ,0,_aaf ),_ag .NewCubicBezierCurve (0,_aaf ,_gee ,_aaf ,_aaf ,_gee ,_aaf ,0),_ag .NewCubicBezierCurve (_aaf ,0,_aaf ,-_gee ,_gee ,-_aaf ,0,-_aaf ),_ag .NewCubicBezierCurve (0,-_aaf ,-_gee ,-_aaf ,-_aaf ,-_gee ,-_aaf ,0)}};
|
|
if _agf :=_fef ._gg ;_agf !=0{_aaa =_aaa .Offset (_agf /2,_agf /2);};_aaa =_aaa .Offset (float64 (x ),float64 (y ));_ag .DrawBezierPathWithCreator (_aaa ,_fef ._af );};func (_bca *Renderer )SetFontSize (size float64 ){_bca ._e =size };func (_bade *Renderer )SetTextRotation (radians float64 ){_bade ._ec =_cdf (-radians )};
|
|
type Renderer struct{_df int ;_gb int ;_gc float64 ;_af *_bf .ContentCreator ;_fc *_cce .PdfPageResources ;_ca _fe .Color ;_db _fe .Color ;_gg float64 ;_gf *_cce .PdfFont ;_e float64 ;_be _fe .Color ;_ec float64 ;_dc map[*_cce .PdfFont ]_fd .PdfObjectName ;
|
|
};func (_aa *Renderer )SetStrokeWidth (width float64 ){_aa ._gg =width ;_aa ._af .Add_w (width )};func (_fdb *Renderer )SetDPI (dpi float64 ){_fdb ._gc =dpi };func (_gba *Renderer )FillStroke (){_gba ._af .Add_B ()};func (_bb *Renderer )SetFillColor (color _fe .Color ){_bb ._ca =color ;
|
|
_fdf ,_fee ,_bde ,_ :=_fed (color );_bb ._af .Add_rg (_fdf ,_fee ,_bde );};func _fed (_ebf _fe .Color )(float64 ,float64 ,float64 ,float64 ){_eae ,_beb ,_bbcg ,_bee :=_bec (_ebf );return float64 (_eae )/255,float64 (_beb )/255,float64 (_bbcg )/255,float64 (_bee )/255;
|
|
};func (_cf *Renderer )Close (){_cf ._af .Add_h ()};func (_dcc *Renderer )ResetStyle (){_dcc .SetFillColor (_fe .Black );_dcc .SetStrokeColor (_fe .Transparent );_dcc .SetStrokeWidth (0);_dcc .SetFont (_cce .DefaultFont ());_dcc .SetFontColor (_fe .Black );
|
|
_dcc .SetFontSize (12);_dcc .SetTextRotation (0);};func (_eb *Renderer )MoveTo (x ,y int ){_eb ._af .Add_m (float64 (x ),float64 (y ))};func NewRenderer (cc *_bf .ContentCreator ,res *_cce .PdfPageResources )func (int ,int )(_d .Renderer ,error ){return func (_cb ,_bd int )(_d .Renderer ,error ){_fca :=&Renderer {_df :_cb ,_gb :_bd ,_gc :72,_af :cc ,_fc :res ,_dc :map[*_cce .PdfFont ]_fd .PdfObjectName {}};
|
|
_fca .ResetStyle ();return _fca ,nil ;};};func (_deg *Renderer )Stroke (){_deg ._af .Add_S ()}; |