mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +08:00
107 lines
27 KiB
Go
107 lines
27 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 imagerender ;import (_ad "errors";_a "fmt";_beg "github.com/unidoc/freetype/raster";_dg "github.com/unidoc/unipdf/v3/common";_cf "github.com/unidoc/unipdf/v3/internal/transform";_cd "github.com/unidoc/unipdf/v3/render/internal/context";_bb "golang.org/x/image/draw";
|
|
_ff "golang.org/x/image/font";_df "golang.org/x/image/math/f64";_be "golang.org/x/image/math/fixed";_g "image";_c "image/color";_b "image/draw";_f "math";_fg "sort";_e "strings";);func (_eda *Context )Push (){_adc :=*_eda ;_eda ._gde =append (_eda ._gde ,&_adc )};
|
|
func _ecad (_fdbf [][]_cf .Point )_beg .Path {var _bgba _beg .Path ;for _ ,_efde :=range _fdbf {var _fbcb _be .Point26_6 ;for _fcbc ,_fcebf :=range _efde {_fbdd :=_bff (_fcebf );if _fcbc ==0{_bgba .Start (_fbdd );}else {_gbec :=_fbdd .X -_fbcb .X ;_ddc :=_fbdd .Y -_fbcb .Y ;
|
|
if _gbec < 0{_gbec =-_gbec ;};if _ddc < 0{_ddc =-_ddc ;};if _gbec +_ddc > 8{_bgba .Add1 (_fbdd );};};_fbcb =_fbdd ;};};return _bgba ;};type surfacePattern struct{_fbfc _g .Image ;_bdff repeatOp ;};func (_dcd *Context )drawRegularPolygon (_caa int ,_baba ,_fdfd ,_eada ,_eca float64 ){_cbc :=2*_f .Pi /float64 (_caa );
|
|
_eca -=_f .Pi /2;if _caa %2==0{_eca +=_cbc /2;};_dcd .NewSubPath ();for _cbgc :=0;_cbgc < _caa ;_cbgc ++{_dbcf :=_eca +_cbc *float64 (_cbgc );_dcd .LineTo (_baba +_eada *_f .Cos (_dbcf ),_fdfd +_eada *_f .Sin (_dbcf ));};_dcd .ClosePath ();};func NewContext (width ,height int )*Context {return NewContextForRGBA (_g .NewRGBA (_g .Rect (0,0,width ,height )));
|
|
};func (_fbc *Context )DrawImage (im _g .Image ,x ,y int ){_fbc .DrawImageAnchored (im ,x ,y ,0,0)};func (_gcg stops )Swap (i ,j int ){_gcg [i ],_gcg [j ]=_gcg [j ],_gcg [i ]};func (_fcb *Context )SetStrokeRGBA (r ,g ,b ,a float64 ){_bd :=_c .NRGBA {uint8 (r *255),uint8 (g *255),uint8 (b *255),uint8 (a *255)};
|
|
_fcb ._cdf =_daeg (_bd );};func _bfg (_cge _g .Image )*_g .RGBA {_abd :=_cge .Bounds ();_deca :=_g .NewRGBA (_abd );_b .Draw (_deca ,_abd ,_cge ,_abd .Min ,_b .Src );return _deca ;};func (_bcc *Context )SetLineWidth (lineWidth float64 ){_bcc ._dgg =lineWidth };
|
|
func (_dc *Context )LineTo (x ,y float64 ){if !_dc ._ac {_dc .MoveTo (x ,y );}else {x ,y =_dc .Transform (x ,y );_ecb :=_cf .NewPoint (x ,y );_gea :=_bff (_ecb );_dc ._dac .Add1 (_gea );_dc ._ega .Add1 (_gea );_dc ._afd =_ecb ;};};func (_agfb *patternPainter )Paint (ss []_beg .Span ,done bool ){_gdc :=_agfb ._aaf .Bounds ();
|
|
for _ ,_cbf :=range ss {if _cbf .Y < _gdc .Min .Y {continue ;};if _cbf .Y >=_gdc .Max .Y {return ;};if _cbf .X0 < _gdc .Min .X {_cbf .X0 =_gdc .Min .X ;};if _cbf .X1 > _gdc .Max .X {_cbf .X1 =_gdc .Max .X ;};if _cbf .X0 >=_cbf .X1 {continue ;};const _gbbf =1<<16-1;
|
|
_eeb :=_cbf .Y -_agfb ._aaf .Rect .Min .Y ;_adgg :=_cbf .X0 -_agfb ._aaf .Rect .Min .X ;_feg :=(_cbf .Y -_agfb ._aaf .Rect .Min .Y )*_agfb ._aaf .Stride +(_cbf .X0 -_agfb ._aaf .Rect .Min .X )*4;_gcgf :=_feg +(_cbf .X1 -_cbf .X0 )*4;for _egd ,_gbcd :=_feg ,_adgg ;
|
|
_egd < _gcgf ;_egd ,_gbcd =_egd +4,_gbcd +1{_fcgc :=_cbf .Alpha ;if _agfb ._cfdd !=nil {_fcgc =_fcgc *uint32 (_agfb ._cfdd .AlphaAt (_gbcd ,_eeb ).A )/255;if _fcgc ==0{continue ;};};_dcag :=_agfb ._dff .ColorAt (_gbcd ,_eeb );_gcbb ,_bdec ,_def ,_fdd :=_dcag .RGBA ();
|
|
_ebe :=uint32 (_agfb ._aaf .Pix [_egd +0]);_cfdc :=uint32 (_agfb ._aaf .Pix [_egd +1]);_gecec :=uint32 (_agfb ._aaf .Pix [_egd +2]);_gbbe :=uint32 (_agfb ._aaf .Pix [_egd +3]);_fcgg :=(_gbbf -(_fdd *_fcgc /_gbbf ))*0x101;_agfb ._aaf .Pix [_egd +0]=uint8 ((_ebe *_fcgg +_gcbb *_fcgc )/_gbbf >>8);
|
|
_agfb ._aaf .Pix [_egd +1]=uint8 ((_cfdc *_fcgg +_bdec *_fcgc )/_gbbf >>8);_agfb ._aaf .Pix [_egd +2]=uint8 ((_gecec *_fcgg +_def *_fcgc )/_gbbf >>8);_agfb ._aaf .Pix [_egd +3]=uint8 ((_gbbe *_fcgg +_fdd *_fcgc )/_gbbf >>8);};};};func _cgb (_edab ,_fbbd ,_dee ,_gag ,_fecc ,_baae float64 )float64 {return _edab *_gag +_fbbd *_fecc +_dee *_baae ;
|
|
};func (_cdc *Context )Height ()int {return _cdc ._gff };type linearGradient struct{_eeg ,_faec ,_gbge ,_bbc float64 ;_ggbgd stops ;};func (_gfb *Context )MeasureString (s string ,face _ff .Face )(_bbb ,_dcc float64 ){_ffb :=&_ff .Drawer {Face :face };
|
|
_gcf :=_ffb .MeasureString (s );return float64 (_gcf >>6),_gfb ._fdb .Tf .Size ;};func (_gfg *Context )SetFillRGBA (r ,g ,b ,a float64 ){_ ,_ ,_ ,_dgbd :=_gfg ._ffc .RGBA ();if _dgbd > 0&&_dgbd !=65535&&a ==1{a =float64 (_dgbd )/65535;};_adg :=_c .NRGBA {uint8 (r *255),uint8 (g *255),uint8 (b *255),uint8 (a *255)};
|
|
_gfg ._ffc =_adg ;_gfg ._geb =_daeg (_adg );};func NewContextForImage (im _g .Image )*Context {return NewContextForRGBA (_bfg (im ))};func _gf (_fc ,_fa ,_dfc ,_bec ,_ae ,_dgb ,_af float64 )(_dgd ,_cdb float64 ){_aed :=1-_af ;_cg :=_aed *_aed ;_fff :=2*_aed *_af ;
|
|
_bc :=_af *_af ;_dgd =_cg *_fc +_fff *_dfc +_bc *_ae ;_cdb =_cg *_fa +_fff *_bec +_bc *_dgb ;return ;};func (_bgeg *Context )SetPixel (x ,y int ){_bgeg ._dd .Set (x ,y ,_bgeg ._ffc )};func (_ecf *Context )capper ()_beg .Capper {switch _ecf ._age {case _cd .LineCapButt :return _beg .ButtCapper ;
|
|
case _cd .LineCapRound :return _beg .RoundCapper ;case _cd .LineCapSquare :return _beg .SquareCapper ;};return nil ;};func (_faeg *Context )SetDash (dashes ...float64 ){_faeg ._ca =dashes };func (_fgf *Context )SetHexColor (x string ){_fdf ,_fce ,_eaf ,_afb :=_bdab (x );
|
|
_fgf .SetRGBA255 (_fdf ,_fce ,_eaf ,_afb );};func (_ccf *Context )drawString (_ede string ,_ggag _ff .Face ,_ffcb ,_dca float64 ){_cgf :=&_ff .Drawer {Src :_g .NewUniform (_ccf ._ffc ),Face :_ggag ,Dot :_bff (_cf .NewPoint (_ffcb ,_dca ))};_bdd :=rune (-1);
|
|
for _ ,_faaa :=range _ede {if _bdd >=0{_cgf .Dot .X +=_cgf .Face .Kern (_bdd ,_faaa );};_fbcd ,_ggbgf ,_bfce ,_cdcdc ,_gffg :=_cgf .Face .Glyph (_cgf .Dot ,_faaa );if !_gffg {continue ;};_deg :=_fbcd .Sub (_fbcd .Min );_eefe :=_g .NewRGBA (_deg );_bb .DrawMask (_eefe ,_deg ,_cgf .Src ,_g .Point {},_ggbgf ,_bfce ,_bb .Over );
|
|
var _ged *_bb .Options ;if _ccf ._fb !=nil {_ged =&_bb .Options {DstMask :_ccf ._fb ,DstMaskP :_g .Point {}};};_ffd :=_ccf ._ffe .Clone ().Translate (float64 (_fbcd .Min .X ),float64 (_fbcd .Min .Y ));_dfcd :=_df .Aff3 {_ffd [0],_ffd [3],_ffd [6],_ffd [1],_ffd [4],_ffd [7]};
|
|
_bb .BiLinear .Transform (_ccf ._dd ,_dfcd ,_eefe ,_deg ,_bb .Over ,_ged );_cgf .Dot .X +=_cdcdc ;_bdd =_faaa ;};};func (_ffdd *linearGradient )ColorAt (x ,y int )_c .Color {if len (_ffdd ._ggbgd )==0{return _c .Transparent ;};_bga ,_gee :=float64 (x ),float64 (y );
|
|
_acg ,_bcd ,_cegb ,_aae :=_ffdd ._eeg ,_ffdd ._faec ,_ffdd ._gbge ,_ffdd ._bbc ;_cagg ,_gfea :=_cegb -_acg ,_aae -_bcd ;if _gfea ==0&&_cagg !=0{return _fffa ((_bga -_acg )/_cagg ,_ffdd ._ggbgd );};if _cagg ==0&&_gfea !=0{return _fffa ((_gee -_bcd )/_gfea ,_ffdd ._ggbgd );
|
|
};_fcee :=_cagg *(_bga -_acg )+_gfea *(_gee -_bcd );if _fcee < 0{return _ffdd ._ggbgd [0]._ceee ;};_fde :=_f .Hypot (_cagg ,_gfea );_ffa :=((_bga -_acg )*-_gfea +(_gee -_bcd )*_cagg )/(_fde *_fde );_eadce ,_adce :=_acg +_ffa *-_gfea ,_bcd +_ffa *_cagg ;
|
|
_bcfe :=_f .Hypot (_bga -_eadce ,_gee -_adce )/_fde ;return _fffa (_bcfe ,_ffdd ._ggbgd );};func (_bedb *Context )Width ()int {return _bedb ._bgd };func _bcdb (_ccd ,_bbbc _c .Color ,_cacb float64 )_c .Color {_gded ,_fdbe ,_bddd ,_gbb :=_ccd .RGBA ();_gfd ,_gcb ,_gfff ,_ece :=_bbbc .RGBA ();
|
|
return _c .RGBA {_fbf (_gded ,_gfd ,_cacb ),_fbf (_fdbe ,_gcb ,_cacb ),_fbf (_bddd ,_gfff ,_cacb ),_fbf (_gbb ,_ece ,_cacb )};};func (_afbb *Context )ClosePath (){if _afbb ._ac {_ggg :=_bff (_afbb ._aee );_afbb ._dac .Add1 (_ggg );_afbb ._ega .Add1 (_ggg );
|
|
_afbb ._afd =_afbb ._aee ;};};func (_afa *Context )stroke (_adgf _beg .Painter ){_dfac :=_afa ._dac ;if len (_afa ._ca )> 0{_dfac =_gaa (_dfac ,_afa ._ca ,_afa ._fca );}else {_dfac =_ecad (_dfg (_dfac ));};_afag :=_afa ._bed ;_afag .UseNonZeroWinding =true ;
|
|
_afag .Clear ();_bde :=(_afa ._ffe .ScalingFactorX ()+_afa ._ffe .ScalingFactorY ())/2;_afag .AddStroke (_dfac ,_ebg (_afa ._dgg *_bde ),_afa .capper (),_afa .joiner ());_afag .Rasterize (_adgf );};func _cgac (_dfcg [][]_cf .Point ,_cfa []float64 ,_cafa float64 )[][]_cf .Point {var _bgc [][]_cf .Point ;
|
|
if len (_cfa )==0{return _dfcg ;};if len (_cfa )==1{_cfa =append (_cfa ,_cfa [0]);};for _ ,_egfe :=range _dfcg {if len (_egfe )< 2{continue ;};_edbe :=_egfe [0];_gce :=1;_fbce :=0;_dfeg :=0.0;if _cafa !=0{var _caad float64 ;for _ ,_fbab :=range _cfa {_caad +=_fbab ;
|
|
};_cafa =_f .Mod (_cafa ,_caad );if _cafa < 0{_cafa +=_caad ;};for _bbaa ,_aefg :=range _cfa {_cafa -=_aefg ;if _cafa < 0{_fbce =_bbaa ;_dfeg =_aefg +_cafa ;break ;};};};var _cafac []_cf .Point ;_cafac =append (_cafac ,_edbe );for _gce < len (_egfe ){_gcfg :=_cfa [_fbce ];
|
|
_edad :=_egfe [_gce ];_beca :=_edbe .Distance (_edad );_abf :=_gcfg -_dfeg ;if _beca > _abf {_fab :=_abf /_beca ;_fgg :=_edbe .Interpolate (_edad ,_fab );_cafac =append (_cafac ,_fgg );if _fbce %2==0&&len (_cafac )> 1{_bgc =append (_bgc ,_cafac );};_cafac =nil ;
|
|
_cafac =append (_cafac ,_fgg );_dfeg =0;_edbe =_fgg ;_fbce =(_fbce +1)%len (_cfa );}else {_cafac =append (_cafac ,_edad );_edbe =_edad ;_dfeg +=_beca ;_gce ++;};};if _fbce %2==0&&len (_cafac )> 1{_bgc =append (_bgc ,_cafac );};};return _bgc ;};func (_aded *Context )InvertMask (){if _aded ._fb ==nil {_aded ._fb =_g .NewAlpha (_aded ._dd .Bounds ());
|
|
}else {for _fba ,_bda :=range _aded ._fb .Pix {_aded ._fb .Pix [_fba ]=255-_bda ;};};};func _gaa (_ebf _beg .Path ,_fgc []float64 ,_ffce float64 )_beg .Path {return _ecad (_cgac (_dfg (_ebf ),_fgc ,_ffce ));};func (_gfgg stops )Less (i ,j int )bool {return _gfgg [i ]._aecf < _gfgg [j ]._aecf };
|
|
func _bgf (_geg float64 )float64 {return _geg *_f .Pi /180};func (_bcb *Context )SetRGBA (r ,g ,b ,a float64 ){_ ,_ ,_ ,_dgf :=_bcb ._ffc .RGBA ();if _dgf > 0&&_dgf !=65535&&a ==1{a =float64 (_dgf )/65535;};_bcb ._ffc =_c .NRGBA {uint8 (r *255),uint8 (g *255),uint8 (b *255),uint8 (a *255)};
|
|
_bcb .setFillAndStrokeColor (_bcb ._ffc );};type stops []stop ;func (_egbg *Context )SetRGBA255 (r ,g ,b ,a int ){_egbg ._ffc =_c .NRGBA {uint8 (r ),uint8 (g ),uint8 (b ),uint8 (a )};_egbg .setFillAndStrokeColor (_egbg ._ffc );};func (_bdcd *Context )Shear (x ,y float64 ){_bdcd ._ffe .Shear (x ,y )};
|
|
type Context struct{_bgd int ;_gff int ;_bed *_beg .Rasterizer ;_dd *_g .RGBA ;_fb *_g .Alpha ;_ffc _c .Color ;_geb _cd .Pattern ;_cdf _cd .Pattern ;_dac _beg .Path ;_ega _beg .Path ;_aee _cf .Point ;_afd _cf .Point ;_ac bool ;_ca []float64 ;_fca float64 ;
|
|
_dgg float64 ;_age _cd .LineCap ;_daa _cd .LineJoin ;_ggb _cd .FillRule ;_ffe _cf .Matrix ;_fdb _cd .TextState ;_gde []*Context ;};type radialGradient struct{_afaf ,_baf ,_cdfa circle ;_agc ,_fdad float64 ;_acbe float64 ;_aeg stops ;};func NewRadialGradient (x0 ,y0 ,r0 ,x1 ,y1 ,r1 float64 )_cd .Gradient {_fad :=circle {x0 ,y0 ,r0 };
|
|
_daag :=circle {x1 ,y1 ,r1 };_fbe :=circle {x1 -x0 ,y1 -y0 ,r1 -r0 };_ddfd :=_cgb (_fbe ._dba ,_fbe ._cbbd ,-_fbe ._bdcb ,_fbe ._dba ,_fbe ._cbbd ,_fbe ._bdcb );var _abc float64 ;if _ddfd !=0{_abc =1.0/_ddfd ;};_eac :=-_fad ._bdcb ;_fee :=&radialGradient {_afaf :_fad ,_baf :_daag ,_cdfa :_fbe ,_agc :_ddfd ,_fdad :_abc ,_acbe :_eac };
|
|
return _fee ;};func (_eag *Context )SetFillRule (fillRule _cd .FillRule ){_eag ._ggb =fillRule };func (_eafg *Context )DrawEllipse (x ,y ,rx ,ry float64 ){_eafg .NewSubPath ();_eafg .DrawEllipticalArc (x ,y ,rx ,ry ,0,2*_f .Pi );_eafg .ClosePath ();};func (_dfb *radialGradient )ColorAt (x ,y int )_c .Color {if len (_dfb ._aeg )==0{return _c .Transparent ;
|
|
};_eae ,_deed :=float64 (x )+0.5-_dfb ._afaf ._dba ,float64 (y )+0.5-_dfb ._afaf ._cbbd ;_fcd :=_cgb (_eae ,_deed ,_dfb ._afaf ._bdcb ,_dfb ._cdfa ._dba ,_dfb ._cdfa ._cbbd ,_dfb ._cdfa ._bdcb );_gbe :=_cgb (_eae ,_deed ,-_dfb ._afaf ._bdcb ,_eae ,_deed ,_dfb ._afaf ._bdcb );
|
|
if _dfb ._agc ==0{if _fcd ==0{return _c .Transparent ;};_gdgf :=0.5*_gbe /_fcd ;if _gdgf *_dfb ._cdfa ._bdcb >=_dfb ._acbe {return _fffa (_gdgf ,_dfb ._aeg );};return _c .Transparent ;};_dfab :=_cgb (_fcd ,_dfb ._agc ,0,_fcd ,-_gbe ,0);if _dfab >=0{_eaa :=_f .Sqrt (_dfab );
|
|
_fbd :=(_fcd +_eaa )*_dfb ._fdad ;_ddf :=(_fcd -_eaa )*_dfb ._fdad ;if _fbd *_dfb ._cdfa ._bdcb >=_dfb ._acbe {return _fffa (_fbd ,_dfb ._aeg );}else if _ddf *_dfb ._cdfa ._bdcb >=_dfb ._acbe {return _fffa (_ddf ,_dfb ._aeg );};};return _c .Transparent ;
|
|
};func (_eece *Context )Matrix ()_cf .Matrix {return _eece ._ffe };func (_fcc *Context )SetLineCap (lineCap _cd .LineCap ){_fcc ._age =lineCap };var (_aff =_daeg (_c .White );_cc =_daeg (_c .Black ););func (_bfa stops )Len ()int {return len (_bfa )};func NewContextForRGBA (im *_g .RGBA )*Context {_bce :=im .Bounds ().Size ().X ;
|
|
_dfe :=im .Bounds ().Size ().Y ;return &Context {_bgd :_bce ,_gff :_dfe ,_bed :_beg .NewRasterizer (_bce ,_dfe ),_dd :im ,_ffc :_c .Transparent ,_geb :_aff ,_cdf :_cc ,_dgg :1,_ggb :_cd .FillRuleWinding ,_ffe :_cf .IdentityMatrix (),_fdb :_cd .NewTextState ()};
|
|
};type circle struct{_dba ,_cbbd ,_bdcb float64 };func _daeg (_fdc _c .Color )_cd .Pattern {return &solidPattern {_bef :_fdc }};func (_gade *Context )DrawEllipticalArc (x ,y ,rx ,ry ,angle1 ,angle2 float64 ){const _fffb =16;for _ffff :=0;_ffff < _fffb ;
|
|
_ffff ++{_ccc :=float64 (_ffff +0)/_fffb ;_fgfa :=float64 (_ffff +1)/_fffb ;_bdc :=angle1 +(angle2 -angle1 )*_ccc ;_efd :=angle1 +(angle2 -angle1 )*_fgfa ;_ead :=x +rx *_f .Cos (_bdc );_gebd :=y +ry *_f .Sin (_bdc );_aa :=x +rx *_f .Cos ((_bdc +_efd )/2);
|
|
_cfgd :=y +ry *_f .Sin ((_bdc +_efd )/2);_eadc :=x +rx *_f .Cos (_efd );_bebe :=y +ry *_f .Sin (_efd );_bcf :=2*_aa -_ead /2-_eadc /2;_dce :=2*_cfgd -_gebd /2-_bebe /2;if _ffff ==0{if _gade ._ac {_gade .LineTo (_ead ,_gebd );}else {_gade .MoveTo (_ead ,_gebd );
|
|
};};_gade .QuadraticTo (_bcf ,_dce ,_eadc ,_bebe );};};func (_edg *Context )SetFillStyle (pattern _cd .Pattern ){if _ceg ,_dbe :=pattern .(*solidPattern );_dbe {_edg ._ffc =_ceg ._bef ;};_edg ._geb =pattern ;};func _ba (_beb ,_ge ,_bab ,_eg ,_gd ,_fae float64 )[]_cf .Point {_fga :=(_f .Hypot (_bab -_beb ,_eg -_ge )+_f .Hypot (_gd -_bab ,_fae -_eg ));
|
|
_ade :=int (_fga +0.5);if _ade < 4{_ade =4;};_cga :=float64 (_ade )-1;_ee :=make ([]_cf .Point ,_ade );for _gb :=0;_gb < _ade ;_gb ++{_bag :=float64 (_gb )/_cga ;_ga ,_egf :=_gf (_beb ,_ge ,_bab ,_eg ,_gd ,_fae ,_bag );_ee [_gb ]=_cf .NewPoint (_ga ,_egf );
|
|
};return _ee ;};func (_bcce *Context )ClearPath (){_bcce ._dac .Clear ();_bcce ._ega .Clear ();_bcce ._ac =false };func (_cag *Context )DrawRoundedRectangle (x ,y ,w ,h ,r float64 ){_bac ,_ccgg ,_agg ,_gdb :=x ,x +r ,x +w -r ,x +w ;_ebc ,_bdb ,_fcad ,_gfe :=y ,y +r ,y +h -r ,y +h ;
|
|
_cag .NewSubPath ();_cag .MoveTo (_ccgg ,_ebc );_cag .LineTo (_agg ,_ebc );_cag .DrawArc (_agg ,_bdb ,r ,_bgf (270),_bgf (360));_cag .LineTo (_gdb ,_fcad );_cag .DrawArc (_agg ,_fcad ,r ,_bgf (0),_bgf (90));_cag .LineTo (_ccgg ,_gfe );_cag .DrawArc (_ccgg ,_fcad ,r ,_bgf (90),_bgf (180));
|
|
_cag .LineTo (_bac ,_bdb );_cag .DrawArc (_ccgg ,_bdb ,r ,_bgf (180),_bgf (270));_cag .ClosePath ();};func (_ccg *Context )SetColor (c _c .Color ){_ccg .setFillAndStrokeColor (c )};func _bff (_gefd _cf .Point )_be .Point26_6 {return _be .Point26_6 {X :_ebg (_gefd .X ),Y :_ebg (_gefd .Y )}};
|
|
func (_cdcd *Context )StrokePattern ()_cd .Pattern {return _cdcd ._cdf };func (_edb *Context )CubicTo (x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 ){if !_edb ._ac {_edb .MoveTo (x1 ,y1 );};_fceb ,_fcf :=_edb ._afd .X ,_edb ._afd .Y ;x1 ,y1 =_edb .Transform (x1 ,y1 );
|
|
x2 ,y2 =_edb .Transform (x2 ,y2 );x3 ,y3 =_edb .Transform (x3 ,y3 );_bgg :=_ce (_fceb ,_fcf ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 );_daga :=_bff (_edb ._afd );for _ ,_deag :=range _bgg [1:]{_dgc :=_bff (_deag );if _dgc ==_daga {continue ;};_daga =_dgc ;_edb ._dac .Add1 (_dgc );
|
|
_edb ._ega .Add1 (_dgc );_edb ._afd =_deag ;};};func _aga (_bbfd _g .Image ,_efe repeatOp )_cd .Pattern {return &surfacePattern {_fbfc :_bbfd ,_bdff :_efe };};func (_cdbb *Context )Clip (){_cdbb .ClipPreserve ();_cdbb .ClearPath ()};func (_ggaf *Context )Fill (){_ggaf .FillPreserve ();
|
|
_ggaf .ClearPath ()};func _ce (_ed ,_fe ,_bca ,_ea ,_cgg ,_bg ,_gg ,_edc float64 )[]_cf .Point {_agf :=(_f .Hypot (_bca -_ed ,_ea -_fe )+_f .Hypot (_cgg -_bca ,_bg -_ea )+_f .Hypot (_gg -_cgg ,_edc -_bg ));_cgc :=int (_agf +0.5);if _cgc < 4{_cgc =4;};_fd :=float64 (_cgc )-1;
|
|
_dbc :=make ([]_cf .Point ,_cgc );for _fea :=0;_fea < _cgc ;_fea ++{_faea :=float64 (_fea )/_fd ;_gbg ,_eed :=_ag (_ed ,_fe ,_bca ,_ea ,_cgg ,_bg ,_gg ,_edc ,_faea );_dbc [_fea ]=_cf .NewPoint (_gbg ,_eed );};return _dbc ;};func (_bbf *Context )ResetClip (){_bbf ._fb =nil };
|
|
func (_bcaa *Context )DrawCircle (x ,y ,r float64 ){_bcaa .NewSubPath ();_bcaa .DrawEllipticalArc (x ,y ,r ,r ,0,2*_f .Pi );_bcaa .ClosePath ();};func (_ecfc *Context )DrawStringAnchored (s string ,face _ff .Face ,x ,y ,ax ,ay float64 ){_dec ,_effc :=_ecfc .MeasureString (s ,face );
|
|
_ecfc .drawString (s ,face ,x -ax *_dec ,y +ay *_effc );};func (_aec *Context )LineWidth ()float64 {return _aec ._dgg };func (_cfg *Context )NewSubPath (){if _cfg ._ac {_cfg ._ega .Add1 (_bff (_cfg ._aee ));};_cfg ._ac =false ;};func (_ef *Context )FillPattern ()_cd .Pattern {return _ef ._geb };
|
|
func (_eec *Context )joiner ()_beg .Joiner {switch _eec ._daa {case _cd .LineJoinBevel :return _beg .BevelJoiner ;case _cd .LineJoinRound :return _beg .RoundJoiner ;};return nil ;};func (_fgb *Context )FillPreserve (){var _ddb _beg .Painter ;if _fgb ._fb ==nil {if _cdac ,_gga :=_fgb ._geb .(*solidPattern );
|
|
_gga {_dbec :=_beg .NewRGBAPainter (_fgb ._dd );_dbec .SetColor (_cdac ._bef );_ddb =_dbec ;};};if _ddb ==nil {_ddb =_ccdg (_fgb ._dd ,_fgb ._fb ,_fgb ._geb );};_fgb .fill (_ddb );};func (_ccb *Context )ShearAbout (sx ,sy ,x ,y float64 ){_ccb .Translate (x ,y );
|
|
_ccb .Shear (sx ,sy );_ccb .Translate (-x ,-y );};func (_bae *Context )SetStrokeStyle (pattern _cd .Pattern ){_bae ._cdf =pattern };func (_ecff *Context )fill (_fcac _beg .Painter ){_bcad :=_ecff ._ega ;if _ecff ._ac {_bcad =make (_beg .Path ,len (_ecff ._ega ));
|
|
copy (_bcad ,_ecff ._ega );_bcad .Add1 (_bff (_ecff ._aee ));};_eee :=_ecff ._bed ;_eee .UseNonZeroWinding =_ecff ._ggb ==_cd .FillRuleWinding ;_eee .Clear ();_eee .AddPath (_bcad );_eee .Rasterize (_fcac );};func (_ec *Context )setFillAndStrokeColor (_fda _c .Color ){_ec ._ffc =_fda ;
|
|
_ec ._geb =_daeg (_fda );_ec ._cdf =_daeg (_fda );};func (_affc *Context )SetMask (mask *_g .Alpha )error {if mask .Bounds ().Size ()!=_affc ._dd .Bounds ().Size (){return _ad .New ("\u006d\u0061\u0073\u006b\u0020\u0073i\u007a\u0065\u0020\u006d\u0075\u0073\u0074\u0020\u006d\u0061\u0074\u0063\u0068 \u0063\u006f\u006e\u0074\u0065\u0078\u0074 \u0073\u0069\u007a\u0065");
|
|
};_affc ._fb =mask ;return nil ;};type patternPainter struct{_aaf *_g .RGBA ;_cfdd *_g .Alpha ;_dff _cd .Pattern ;};func _bdab (_bggc string )(_eea ,_ccea ,_caeg ,_aafe int ){_bggc =_e .TrimPrefix (_bggc ,"\u0023");_aafe =255;if len (_bggc )==3{_dgbf :="\u00251\u0078\u0025\u0031\u0078\u0025\u0031x";
|
|
_a .Sscanf (_bggc ,_dgbf ,&_eea ,&_ccea ,&_caeg );_eea |=_eea <<4;_ccea |=_ccea <<4;_caeg |=_caeg <<4;};if len (_bggc )==6{_cfb :="\u0025\u0030\u0032x\u0025\u0030\u0032\u0078\u0025\u0030\u0032\u0078";_a .Sscanf (_bggc ,_cfb ,&_eea ,&_ccea ,&_caeg );};if len (_bggc )==8{_aaa :="\u0025\u00302\u0078\u0025\u00302\u0078\u0025\u0030\u0032\u0078\u0025\u0030\u0032\u0078";
|
|
_a .Sscanf (_bggc ,_aaa ,&_eea ,&_ccea ,&_caeg ,&_aafe );};return ;};func (_bbd *Context )SetMatrix (m _cf .Matrix ){_bbd ._ffe =m };func _ag (_dga ,_eb ,_fcg ,_gc ,_da ,_gdg ,_dfa ,_aef ,_db float64 )(_egb ,_bf float64 ){_faa :=1-_db ;_de :=_faa *_faa *_faa ;
|
|
_fcgf :=3*_faa *_faa *_db ;_bfc :=3*_faa *_db *_db ;_gad :=_db *_db *_db ;_egb =_de *_dga +_fcgf *_fcg +_bfc *_da +_gad *_dfa ;_bf =_de *_eb +_fcgf *_gc +_bfc *_gdg +_gad *_aef ;return ;};func (_baa *Context )Identity (){_baa ._ffe =_cf .IdentityMatrix ()};
|
|
func (_dag *Context )SetRGB (r ,g ,b float64 ){_dag .SetRGBA (r ,g ,b ,1)};func (_dea *Context )QuadraticTo (x1 ,y1 ,x2 ,y2 float64 ){if !_dea ._ac {_dea .MoveTo (x1 ,y1 );};x1 ,y1 =_dea .Transform (x1 ,y1 );x2 ,y2 =_dea .Transform (x2 ,y2 );_ffed :=_cf .NewPoint (x1 ,y1 );
|
|
_gec :=_cf .NewPoint (x2 ,y2 );_ggbg :=_bff (_ffed );_eafe :=_bff (_gec );_dea ._dac .Add2 (_ggbg ,_eafe );_dea ._ega .Add2 (_ggbg ,_eafe );_dea ._afd =_gec ;};func NewLinearGradient (x0 ,y0 ,x1 ,y1 float64 )_cd .Gradient {_degg :=&linearGradient {_eeg :x0 ,_faec :y0 ,_gbge :x1 ,_bbc :y1 };
|
|
return _degg ;};func (_eab *radialGradient )AddColorStop (offset float64 ,color _c .Color ){_eab ._aeg =append (_eab ._aeg ,stop {_aecf :offset ,_ceee :color });_fg .Sort (_eab ._aeg );};func (_egbf *Context )MoveTo (x ,y float64 ){if _egbf ._ac {_egbf ._ega .Add1 (_bff (_egbf ._aee ));
|
|
};x ,y =_egbf .Transform (x ,y );_aefe :=_cf .NewPoint (x ,y );_bcee :=_bff (_aefe );_egbf ._dac .Start (_bcee );_egbf ._ega .Start (_bcee );_egbf ._aee =_aefe ;_egbf ._afd =_aefe ;_egbf ._ac =true ;};func (_cgaa *Context )StrokePreserve (){var _ab _beg .Painter ;
|
|
if _cgaa ._fb ==nil {if _ggc ,_fbb :=_cgaa ._cdf .(*solidPattern );_fbb {_cad :=_beg .NewRGBAPainter (_cgaa ._dd );_cad .SetColor (_ggc ._bef );_ab =_cad ;};};if _ab ==nil {_ab =_ccdg (_cgaa ._dd ,_cgaa ._fb ,_cgaa ._cdf );};_cgaa .stroke (_ab );};func (_cfc *Context )SetRGB255 (r ,g ,b int ){_cfc .SetRGBA255 (r ,g ,b ,255)};
|
|
func (_gbc *Context )DrawLine (x1 ,y1 ,x2 ,y2 float64 ){_gbc .MoveTo (x1 ,y1 );_gbc .LineTo (x2 ,y2 )};func (_dae *Context )Scale (x ,y float64 ){_dae ._ffe =_dae ._ffe .Scale (x ,y )};const (_gffff repeatOp =iota ;_cfcd ;_afda ;_cdbf ;);func (_egfb *Context )Rotate (angle float64 ){_egfb ._ffe =_egfb ._ffe .Rotate (angle )};
|
|
func (_eefb *Context )TextState ()*_cd .TextState {return &_eefb ._fdb };func _fdba (_deee _be .Int26_6 )float64 {const _fed ,_gdbf =6,1<<6-1;if _deee >=0{return float64 (_deee >>_fed )+float64 (_deee &_gdbf )/64;};_deee =-_deee ;if _deee >=0{return -(float64 (_deee >>_fed )+float64 (_deee &_gdbf )/64);
|
|
};return 0;};func (_cbb *Context )Transform (x ,y float64 )(_abe ,_fdfg float64 ){return _cbb ._ffe .Transform (x ,y )};func _ccdg (_ccba *_g .RGBA ,_gaec *_g .Alpha ,_dgdb _cd .Pattern )*patternPainter {return &patternPainter {_ccba ,_gaec ,_dgdb };};
|
|
func (_bdf *solidPattern )ColorAt (x ,y int )_c .Color {return _bdf ._bef };func (_ebb *Context )SetLineJoin (lineJoin _cd .LineJoin ){_ebb ._daa =lineJoin };func (_ege *Context )ScaleAbout (sx ,sy ,x ,y float64 ){_ege .Translate (x ,y );_ege .Scale (sx ,sy );
|
|
_ege .Translate (-x ,-y );};func (_faeag *Context )RotateAbout (angle ,x ,y float64 ){_faeag .Translate (x ,y );_faeag .Rotate (angle );_faeag .Translate (-x ,-y );};func (_bgb *Context )Image ()_g .Image {return _bgb ._dd };func (_cbg *Context )DrawArc (x ,y ,r ,angle1 ,angle2 float64 ){_cbg .DrawEllipticalArc (x ,y ,r ,r ,angle1 ,angle2 );
|
|
};func (_cfca *Context )Clear (){_gae :=_g .NewUniform (_cfca ._ffc );_bb .Draw (_cfca ._dd ,_cfca ._dd .Bounds (),_gae ,_g .Point {},_bb .Src );};func (_cce *Context )DrawImageAnchored (im _g .Image ,x ,y int ,ax ,ay float64 ){_ada :=im .Bounds ().Size ();
|
|
x -=int (ax *float64 (_ada .X ));y -=int (ay *float64 (_ada .Y ));_gdf :=_bb .BiLinear ;_eef :=_cce ._ffe .Clone ().Translate (float64 (x ),float64 (y ));_fgd :=_df .Aff3 {_eef [0],_eef [3],_eef [6],_eef [1],_eef [4],_eef [7]};if _cce ._fb ==nil {_gdf .Transform (_cce ._dd ,_fgd ,im ,im .Bounds (),_bb .Over ,nil );
|
|
}else {_gdf .Transform (_cce ._dd ,_fgd ,im ,im .Bounds (),_bb .Over ,&_bb .Options {DstMask :_cce ._fb ,DstMaskP :_g .Point {}});};};type stop struct{_aecf float64 ;_ceee _c .Color ;};func (_bbdg *linearGradient )AddColorStop (offset float64 ,color _c .Color ){_bbdg ._ggbgd =append (_bbdg ._ggbgd ,stop {_aecf :offset ,_ceee :color });
|
|
_fg .Sort (_bbdg ._ggbgd );};func _ebg (_bgge float64 )_be .Int26_6 {return _be .Int26_6 (_bgge *64)};func (_ggce *Context )Translate (x ,y float64 ){_ggce ._ffe =_ggce ._ffe .Translate (x ,y )};func (_cdae *Context )DrawPoint (x ,y ,r float64 ){_cdae .Push ();
|
|
_dggc ,_fcae :=_cdae .Transform (x ,y );_cdae .Identity ();_cdae .DrawCircle (_dggc ,_fcae ,r );_cdae .Pop ();};func (_bba *Context )AsMask ()*_g .Alpha {_ccgf :=_g .NewAlpha (_bba ._dd .Bounds ());_bb .Draw (_ccgf ,_bba ._dd .Bounds (),_bba ._dd ,_g .Point {},_bb .Src );
|
|
return _ccgf ;};func (_aedg *Context )DrawRectangle (x ,y ,w ,h float64 ){_aedg .NewSubPath ();_aedg .MoveTo (x ,y );_aedg .LineTo (x +w ,y );_aedg .LineTo (x +w ,y +h );_aedg .LineTo (x ,y +h );_aedg .ClosePath ();};func (_ceef *surfacePattern )ColorAt (x ,y int )_c .Color {_eaeb :=_ceef ._fbfc .Bounds ();
|
|
switch _ceef ._bdff {case _cfcd :if y >=_eaeb .Dy (){return _c .Transparent ;};case _afda :if x >=_eaeb .Dx (){return _c .Transparent ;};case _cdbf :if x >=_eaeb .Dx ()||y >=_eaeb .Dy (){return _c .Transparent ;};};x =x %_eaeb .Dx ()+_eaeb .Min .X ;y =y %_eaeb .Dy ()+_eaeb .Min .Y ;
|
|
return _ceef ._fbfc .At (x ,y );};type solidPattern struct{_bef _c .Color };type repeatOp int ;func (_bgde *Context )Stroke (){_bgde .StrokePreserve ();_bgde .ClearPath ()};func _dfg (_gaeb _beg .Path )[][]_cf .Point {var _ecd [][]_cf .Point ;var _gaga []_cf .Point ;
|
|
var _caf ,_fbcg float64 ;for _aea :=0;_aea < len (_gaeb );{switch _gaeb [_aea ]{case 0:if len (_gaga )> 0{_ecd =append (_ecd ,_gaga );_gaga =nil ;};_dacg :=_fdba (_gaeb [_aea +1]);_gbf :=_fdba (_gaeb [_aea +2]);_gaga =append (_gaga ,_cf .NewPoint (_dacg ,_gbf ));
|
|
_caf ,_fbcg =_dacg ,_gbf ;_aea +=4;case 1:_egff :=_fdba (_gaeb [_aea +1]);_bbag :=_fdba (_gaeb [_aea +2]);_gaga =append (_gaga ,_cf .NewPoint (_egff ,_bbag ));_caf ,_fbcg =_egff ,_bbag ;_aea +=4;case 2:_cfd :=_fdba (_gaeb [_aea +1]);_cbe :=_fdba (_gaeb [_aea +2]);
|
|
_aeab :=_fdba (_gaeb [_aea +3]);_fbfe :=_fdba (_gaeb [_aea +4]);_gbaf :=_ba (_caf ,_fbcg ,_cfd ,_cbe ,_aeab ,_fbfe );_gaga =append (_gaga ,_gbaf ...);_caf ,_fbcg =_aeab ,_fbfe ;_aea +=6;case 3:_gece :=_fdba (_gaeb [_aea +1]);_dge :=_fdba (_gaeb [_aea +2]);
|
|
_cbeg :=_fdba (_gaeb [_aea +3]);_abeb :=_fdba (_gaeb [_aea +4]);_eabf :=_fdba (_gaeb [_aea +5]);_bbe :=_fdba (_gaeb [_aea +6]);_cdge :=_ce (_caf ,_fbcg ,_gece ,_dge ,_cbeg ,_abeb ,_eabf ,_bbe );_gaga =append (_gaga ,_cdge ...);_caf ,_fbcg =_eabf ,_bbe ;
|
|
_aea +=8;default:_dg .Log .Debug ("\u0057\u0041\u0052\u004e: \u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0074\u0068\u003a\u0020%\u0076",_gaeb );return _ecd ;};};if len (_gaga )> 0{_ecd =append (_ecd ,_gaga );};return _ecd ;};func (_fec *Context )Pop (){_bfcea :=*_fec ;
|
|
_cba :=_fec ._gde ;_aba :=_cba [len (_cba )-1];*_fec =*_aba ;_fec ._dac =_bfcea ._dac ;_fec ._ega =_bfcea ._ega ;_fec ._aee =_bfcea ._aee ;_fec ._afd =_bfcea ._afd ;_fec ._ac =_bfcea ._ac ;};func _fffa (_bbab float64 ,_fffe stops )_c .Color {if _bbab <=0.0||len (_fffe )==1{return _fffe [0]._ceee ;
|
|
};_fbda :=_fffe [len (_fffe )-1];if _bbab >=_fbda ._aecf {return _fbda ._ceee ;};for _cdg ,_gba :=range _fffe [1:]{if _bbab < _gba ._aecf {_bbab =(_bbab -_fffe [_cdg ]._aecf )/(_gba ._aecf -_fffe [_cdg ]._aecf );return _bcdb (_fffe [_cdg ]._ceee ,_gba ._ceee ,_bbab );
|
|
};};return _fbda ._ceee ;};func _fbf (_cae ,_fef uint32 ,_gcd float64 )uint8 {return uint8 (int32 (float64 (_cae )*(1.0-_gcd )+float64 (_fef )*_gcd )>>8);};func (_gda *Context )SetDashOffset (offset float64 ){_gda ._fca =offset };func (_gfc *Context )DrawString (s string ,face _ff .Face ,x ,y float64 ){_gfc .DrawStringAnchored (s ,face ,x ,y ,0,0);
|
|
};func (_cac *Context )ClipPreserve (){_cbd :=_g .NewAlpha (_g .Rect (0,0,_cac ._bgd ,_cac ._gff ));_bge :=_beg .NewAlphaOverPainter (_cbd );_cac .fill (_bge );if _cac ._fb ==nil {_cac ._fb =_cbd ;}else {_cee :=_g .NewAlpha (_g .Rect (0,0,_cac ._bgd ,_cac ._gff ));
|
|
_bb .DrawMask (_cee ,_cee .Bounds (),_cbd ,_g .Point {},_cac ._fb ,_g .Point {},_bb .Over );_cac ._fb =_cee ;};}; |