2020-11-11 18:48:37 +00:00
|
|
|
package imagerender ;import (_da "errors";_d "fmt";_dae "github.com/golang/freetype/raster";_bd "github.com/unidoc/unipdf/v3/common";_b "github.com/unidoc/unipdf/v3/internal/transform";_bb "github.com/unidoc/unipdf/v3/render/internal/context";_a "golang.org/x/image/draw";_df "golang.org/x/image/font";_ge "golang.org/x/image/math/f64";_bg "golang.org/x/image/math/fixed";_f "image";_ga "image/color";_ec "image/draw";_g "math";_eg "sort";_ea "strings";);func (_ced *Context )Identity (){_ced ._ead =_b .IdentityMatrix ()};func (_fce *Context )SetLineJoin (lineJoin _bb .LineJoin ){_fce ._fc =lineJoin };func (_bbff *Context )Stroke (){_bbff .StrokePreserve ();_bbff .ClearPath ()};func _ee (_ace ,_geb ,_gg ,_bbde ,_bbc ,_ecc ,_af ,_fbcb ,_gd float64 )(_cb ,_fd float64 ){_eccc :=1-_gd ;_db :=_eccc *_eccc *_eccc ;_cbe :=3*_eccc *_eccc *_gd ;_dfc :=3*_eccc *_gd *_gd ;_fa :=_gd *_gd *_gd ;_cb =_db *_ace +_cbe *_gg +_dfc *_bbc +_fa *_af ;_fd =_db *_geb +_cbe *_bbde +_dfc *_ecc +_fa *_fbcb ;return ;};type repeatOp int ;var (_cf =_cfge (_ga .White );_ba =_cfge (_ga .Black ););func (_gca *Context )SetLineCap (lineCap _bb .LineCap ){_gca ._ece =lineCap };func (_gbb *Context )DrawEllipticalArc (x ,y ,rx ,ry ,angle1 ,angle2 float64 ){const _fga =16;for _beg :=0;_beg < _fga ;_beg ++{_face :=float64 (_beg +0)/_fga ;_bgeb :=float64 (_beg +1)/_fga ;_eebg :=angle1 +(angle2 -angle1 )*_face ;_adaa :=angle1 +(angle2 -angle1 )*_bgeb ;_cbc :=x +rx *_g .Cos (_eebg );_bfb :=y +ry *_g .Sin (_eebg );_cccc :=x +rx *_g .Cos ((_eebg +_adaa )/2);_fgbf :=y +ry *_g .Sin ((_eebg +_adaa )/2);_ddd :=x +rx *_g .Cos (_adaa );_ecf :=y +ry *_g .Sin (_adaa );_agg :=2*_cccc -_cbc /2-_ddd /2;_bbe :=2*_fgbf -_bfb /2-_ecf /2;if _beg ==0{if _gbb ._gffc {_gbb .LineTo (_cbc ,_bfb );}else {_gbb .MoveTo (_cbc ,_bfb );};};_gbb .QuadraticTo (_agg ,_bbe ,_ddd ,_ecf );};};func (_ag *Context )SetFillRule (fillRule _bb .FillRule ){_ag ._ceb =fillRule };func _fca (_fdg _bg .Int26_6 )float64 {const _cgdg ,_gcg =6,1<<6-1;if _fdg >=0{return float64 (_fdg >>_cgdg )+float64 (_fdg &_gcg )/64;};_fdg =-_fdg ;if _fdg >=0{return -(float64 (_fdg >>_cgdg )+float64 (_fdg &_gcg )/64);};return 0;};func (_deag *Context )DrawLine (x1 ,y1 ,x2 ,y2 float64 ){_deag .MoveTo (x1 ,y1 );_deag .LineTo (x2 ,y2 )};func (_dfda *Context )joiner ()_dae .Joiner {switch _dfda ._fc {case _bb .LineJoinBevel :return _dae .BevelJoiner ;case _bb .LineJoinRound :return _dae .RoundJoiner ;};return nil ;};func _cfcd (_gaeg string )(_ggf ,_ecea ,_ecae ,_bgge int ){_gaeg =_ea .TrimPrefix (_gaeg ,"\u0023");_bgge =255;if len (_gaeg )==3{_baf :="\u00251\u0078\u0025\u0031\u0078\u0025\u0031x";_d .Sscanf (_gaeg ,_baf ,&_ggf ,&_ecea ,&_ecae );_ggf |=_ggf <<4;_ecea |=_ecea <<4;_ecae |=_ecae <<4;};if len (_gaeg )==6{_dacg :="\u0025\u0030\u0032x\u0025\u0030\u0032\u0078\u0025\u0030\u0032\u0078";_d .Sscanf (_gaeg ,_dacg ,&_ggf ,&_ecea ,&_ecae );};if len (_gaeg )==8{_dedb :="\u0025\u00302\u0078\u0025\u00302\u0078\u0025\u0030\u0032\u0078\u0025\u0030\u0032\u0078";_d .Sscanf (_gaeg ,_dedb ,&_ggf ,&_ecea ,&_ecae ,&_bgge );};return ;};func (_cfg *Context )DrawPoint (x ,y ,r float64 ){_cfg .Push ();_cagg ,_adc :=_cfg .Transform (x ,y );_cfg .Identity ();_cfg .DrawCircle (_cagg ,_adc ,r );_cfg .Pop ();};func NewContextForImage (im _f .Image )*Context {return NewContextForRGBA (_eacb (im ))};func _adeg (_caeb ,_gebd ,_afd ,_dcc ,_age ,_fgg float64 )float64 {return _caeb *_dcc +_gebd *_age +_afd *_fgg ;};func (_eeg *Context )ShearAbout (sx ,sy ,x ,y float64 ){_eeg .Translate (x ,y );_eeg .Shear (sx ,sy );_eeg .Translate (-x ,-y );};func (_eea *Context )SetStrokeRGBA (r ,g ,b ,a float64 ){_be :=_ga .NRGBA {uint8 (r *255),uint8 (g *255),uint8 (b *255),uint8 (a *255)};_eea ._de =_cfge (_be );};func (_aafa *radialGradient )AddColorStop (offset float64 ,color _ga .Color ){_aafa ._adbf =append (_aafa ._adbf ,stop {_bdf :offset ,_fba :color });_eg .Sort (_aafa ._adbf );};func (_fcd *Context )DrawArc (x ,y ,r ,angle1 ,angle2 float64 ){_fcd .DrawEllipticalArc (x ,y ,r ,r ,angle1 ,angle2 );};func (_gbd *Context )StrokePreserve (){var _eab _dae .Painter ;i
|