mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-02 22:17:06 +08:00
111 lines
30 KiB
Go
111 lines
30 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 svg ;import (_e "encoding/xml";_g "fmt";_dg "github.com/unidoc/unipdf/v3/common";_cbf "github.com/unidoc/unipdf/v3/contentstream";_cb "github.com/unidoc/unipdf/v3/contentstream/draw";_cg "github.com/unidoc/unipdf/v3/internal/graphic2d";_ce "golang.org/x/net/html/charset";
|
|
_ge "io";_gg "math";_fb "os";_f "strconv";_d "strings";_cc "unicode";);func (_gcd *GraphicSVG )toContentStream (_dda *_cbf .ContentCreator ){_bee ,_eeda :=_gbga (_gcd .Attributes ,_gcd ._gggf );if _eeda !=nil {_dg .Log .Debug ("U\u006e\u0061\u0062\u006c\u0065\u0020t\u006f\u0020\u0070\u0061\u0072\u0073e\u0020\u0073\u0074\u0079\u006c\u0065\u0020a\u0074\u0074\u0072\u0069\u0062\u0075\u0074\u0065\u003a\u0020%\u0076",_eeda );
|
|
};_gcd .Style =_bee ;switch _gcd .Name {case "\u0070\u0061\u0074\u0068":_b (_gcd ,_dda );for _ ,_agb :=range _gcd .Children {_agb .toContentStream (_dda );};case "\u0072\u0065\u0063\u0074":_gea (_gcd ,_dda );for _ ,_gda :=range _gcd .Children {_gda .toContentStream (_dda );
|
|
};case "\u0063\u0069\u0072\u0063\u006c\u0065":_aed (_gcd ,_dda );for _ ,_ded :=range _gcd .Children {_ded .toContentStream (_dda );};case "\u0065l\u006c\u0069\u0070\u0073\u0065":_edgg (_gcd ,_dda );for _ ,_ggag :=range _gcd .Children {_ggag .toContentStream (_dda );
|
|
};case "\u0070\u006f\u006c\u0079\u006c\u0069\u006e\u0065":_bf (_gcd ,_dda );for _ ,_dac :=range _gcd .Children {_dac .toContentStream (_dda );};case "\u0070o\u006c\u0079\u0067\u006f\u006e":_gba (_gcd ,_dda );for _ ,_fga :=range _gcd .Children {_fga .toContentStream (_dda );
|
|
};case "\u006c\u0069\u006e\u0065":_ggge (_gcd ,_dda );for _ ,_bgc :=range _gcd .Children {_bgc .toContentStream (_dda );};case "\u0067":_ggd ,_fbd :=_gcd .Attributes ["\u0066\u0069\u006c\u006c"];_gggb ,_cgcg :=_gcd .Attributes ["\u0073\u0074\u0072\u006f\u006b\u0065"];
|
|
_ecb ,_aeb :=_gcd .Attributes ["\u0073\u0074\u0072o\u006b\u0065\u002d\u0077\u0069\u0064\u0074\u0068"];for _ ,_cbd :=range _gcd .Children {if _ ,_geaf :=_cbd .Attributes ["\u0066\u0069\u006c\u006c"];!_geaf &&_fbd {_cbd .Attributes ["\u0066\u0069\u006c\u006c"]=_ggd ;
|
|
};if _ ,_ecd :=_cbd .Attributes ["\u0073\u0074\u0072\u006f\u006b\u0065"];!_ecd &&_cgcg {_cbd .Attributes ["\u0073\u0074\u0072\u006f\u006b\u0065"]=_gggb ;};if _ ,_dab :=_cbd .Attributes ["\u0073\u0074\u0072o\u006b\u0065\u002d\u0077\u0069\u0064\u0074\u0068"];
|
|
!_dab &&_aeb {_cbd .Attributes ["\u0073\u0074\u0072o\u006b\u0065\u002d\u0077\u0069\u0064\u0074\u0068"]=_ecb ;};_cbd .toContentStream (_dda );};};};func (_fae *Command )isAbsolute ()bool {return _fae .Symbol ==_d .ToUpper (_fae .Symbol )};func (_fcdc pathParserError )Error ()string {return _fcdc ._aff };
|
|
func _efa ()*GraphicSVGStyle {return &GraphicSVGStyle {FillColor :"\u00230\u0030\u0030\u0030\u0030\u0030",StrokeColor :"",StrokeWidth :0};};func _eea (_bcg string )([]float64 ,error ){_gede :=-1;var _fffg []float64 ;_begb :=' ';for _ccb ,_ggae :=range _bcg {if !_cc .IsNumber (_ggae )&&_ggae !='.'&&!(_ggae =='-'&&_begb =='e')&&_ggae !='e'{if _gede !=-1{_eedaa ,_dbed :=_fbb (_bcg [_gede :_ccb ]);
|
|
if _dbed !=nil {return _fffg ,_dbed ;};_fffg =append (_fffg ,_eedaa ...);};if _ggae =='-'{_gede =_ccb ;}else {_gede =-1;};}else if _gede ==-1{_gede =_ccb ;};_begb =_ggae ;};if _gede !=-1&&_gede !=len (_bcg ){_deg ,_gcc :=_fbb (_bcg [_gede :]);if _gcc !=nil {return _fffg ,_gcc ;
|
|
};_fffg =append (_fffg ,_deg ...);};return _fffg ,nil ;};type Command struct{Symbol string ;Params []float64 ;};func _adc (_gfc []token )([]*Command ,error ){var (_cbag []*Command ;_ggff []float64 ;);for _efe :=len (_gfc )-1;_efe >=0;_efe --{_ffc :=_gfc [_efe ];
|
|
if _ffc ._dgbc {_dafb :=_edgf ._ecae [_d .ToLower (_ffc ._baeb )];_bdff :=len (_ggff );if _dafb ==0&&_bdff ==0{_ecbb :=&Command {Symbol :_ffc ._baeb };_cbag =append ([]*Command {_ecbb },_cbag ...);}else if _dafb !=0&&_bdff %_dafb ==0{_dcf :=_bdff /_dafb ;
|
|
for _gdc :=0;_gdc < _dcf ;_gdc ++{_fcad :=_ffc ._baeb ;if _fcad =="\u006d"&&_gdc < _dcf -1{_fcad ="\u006c";};if _fcad =="\u004d"&&_gdc < _dcf -1{_fcad ="\u004c";};_gca :=&Command {_fcad ,_ddff (_ggff [:_dafb ])};_cbag =append ([]*Command {_gca },_cbag ...);
|
|
_ggff =_ggff [_dafb :];};}else {_gfaa :=pathParserError {"I\u006e\u0063\u006f\u0072\u0072\u0065c\u0074\u0020\u006e\u0075\u006d\u0062e\u0072\u0020\u006f\u0066\u0020\u0070\u0061r\u0061\u006d\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006fr\u0020"+_ffc ._baeb };
|
|
return nil ,_gfaa ;};}else {_cgbg ,_eged :=_edf (_ffc ._baeb ,64);if _eged !=nil {return nil ,_eged ;};_ggff =append (_ggff ,_cgbg );};};return _cbag ,nil ;};func (_cgg *GraphicSVG )Decode (decoder *_e .Decoder )error {for {_bbad ,_dbc :=decoder .Token ();
|
|
if _bbad ==nil &&_dbc ==_ge .EOF {break ;};if _dbc !=nil {return _dbc ;};switch _gfa :=_bbad .(type ){case _e .StartElement :_bbadc :=_dea (_gfa );_gbg :=_bbadc .Decode (decoder );if _gbg !=nil {return _gbg ;};_cgg .Children =append (_cgg .Children ,_bbadc );
|
|
case _e .CharData :_ggf :=_d .TrimSpace (string (_gfa ));if _ggf !=""{_cgg .Content =string (_gfa );};case _e .EndElement :if _gfa .Name .Local ==_cgg .Name {return nil ;};};};return nil ;};func (_dggb *GraphicSVG )SetScaling (xFactor ,yFactor float64 ){_gafc :=_dggb .Width /_dggb .ViewBox .W ;
|
|
_bc :=_dggb .Height /_dggb .ViewBox .H ;_dggb .setDefaultScaling (_gg .Max (_gafc ,_bc ));for _ ,_ecbe :=range _dggb .Children {_ecbe .SetScaling (xFactor ,yFactor );};};type pathParserError struct{_aff string };func _bef (_dgcc float64 )int {return int (_dgcc +_gg .Copysign (0.5,_dgcc ))};
|
|
func ParseFromString (svgStr string )(*GraphicSVG ,error ){return ParseFromStream (_d .NewReader (svgStr ));};func (_afbg *Path )compare (_aaf *Path )bool {if len (_afbg .Subpaths )!=len (_aaf .Subpaths ){return false ;};for _ega ,_babe :=range _afbg .Subpaths {if !_babe .compare (_aaf .Subpaths [_ega ]){return false ;
|
|
};};return true ;};func _bf (_cda *GraphicSVG ,_bgf *_cbf .ContentCreator ){_bgf .Add_q ();_cda .Style .toContentStream (_bgf );_gfb ,_ad :=_eea (_cda .Attributes ["\u0070\u006f\u0069\u006e\u0074\u0073"]);if _ad !=nil {_dg .Log .Debug ("\u0045\u0052\u0052O\u0052\u0020\u0075\u006e\u0061\u0062\u006c\u0065\u0020\u0074\u006f\u0020\u0070\u0061\u0072\u0073\u0065\u0020\u0070\u006f\u0069\u006e\u0074\u0073\u0020\u0061\u0074\u0074\u0072i\u0062\u0075\u0074\u0065\u003a\u0020\u0025\u0076",_ad );
|
|
return ;};if len (_gfb )%2> 0{_dg .Log .Debug ("\u0045\u0052R\u004f\u0052\u0020\u0069n\u0076\u0061l\u0069\u0064\u0020\u0070\u006f\u0069\u006e\u0074s\u0020\u0061\u0074\u0074\u0072\u0069\u0062\u0075\u0074\u0065\u0020\u006ce\u006e\u0067\u0074\u0068");return ;
|
|
};for _ggb :=0;_ggb < len (_gfb );{if _ggb ==0{_bgf .Add_m (_gfb [_ggb ]*_cda ._gggf ,_gfb [_ggb +1]*_cda ._gggf );}else {_bgf .Add_l (_gfb [_ggb ]*_cda ._gggf ,_gfb [_ggb +1]*_cda ._gggf );};_ggb +=2;};if _cda .Style .FillColor !=""&&_cda .Style .StrokeColor !=""{_bgf .Add_B ();
|
|
}else if _cda .Style .FillColor !=""{_bgf .Add_f ();}else if _cda .Style .StrokeColor !=""{_bgf .Add_S ();};_bgf .Add_h ();_bgf .Add_Q ();};func _b (_gc *GraphicSVG ,_ea *_cbf .ContentCreator ){_ea .Add_q ();_gc .Style .toContentStream (_ea );_ac ,_be :=_bda (_gc .Attributes ["\u0064"]);
|
|
if _be !=nil {_dg .Log .Error ("\u0045R\u0052\u004f\u0052\u003a\u0020\u0025s",_be .Error ());};var (_dag ,_bb =0.0,0.0;_eg ,_gb =0.0,0.0;_ab *Command ;);for _ ,_abe :=range _ac .Subpaths {for _ ,_eb :=range _abe .Commands {switch _d .ToLower (_eb .Symbol ){case "\u006d":_eg ,_gb =_eb .Params [0]*_gc ._gggf ,_eb .Params [1]*_gc ._gggf ;
|
|
if !_eb .isAbsolute (){_eg ,_gb =_dag +_eg -_gc .ViewBox .X ,_bb +_gb -_gc .ViewBox .Y ;};_ea .Add_m (_fac (_eg ,3),_fac (_gb ,3));_dag ,_bb =_eg ,_gb ;case "\u0063":_acg ,_fg ,_dgd ,_dd ,_daf ,_cd :=_eb .Params [0]*_gc ._gggf ,_eb .Params [1]*_gc ._gggf ,_eb .Params [2]*_gc ._gggf ,_eb .Params [3]*_gc ._gggf ,_eb .Params [4]*_gc ._gggf ,_eb .Params [5]*_gc ._gggf ;
|
|
if !_eb .isAbsolute (){_acg ,_fg ,_dgd ,_dd ,_daf ,_cd =_dag +_acg ,_bb +_fg ,_dag +_dgd ,_bb +_dd ,_dag +_daf ,_bb +_cd ;};_ea .Add_c (_fac (_acg ,3),_fac (_fg ,3),_fac (_dgd ,3),_fac (_dd ,3),_fac (_daf ,3),_fac (_cd ,3));_dag ,_bb =_daf ,_cd ;case "\u0073":_egc ,_gbe ,_ff ,_df :=_eb .Params [0]*_gc ._gggf ,_eb .Params [1]*_gc ._gggf ,_eb .Params [2]*_gc ._gggf ,_eb .Params [3]*_gc ._gggf ;
|
|
if !_eb .isAbsolute (){_egc ,_gbe ,_ff ,_df =_dag +_egc ,_bb +_gbe ,_dag +_ff ,_bb +_df ;};_ea .Add_c (_fac (_dag ,3),_fac (_bb ,3),_fac (_egc ,3),_fac (_gbe ,3),_fac (_ff ,3),_fac (_df ,3));_dag ,_bb =_ff ,_df ;case "\u006c":_dbg ,_ec :=_eb .Params [0]*_gc ._gggf ,_eb .Params [1]*_gc ._gggf ;
|
|
if !_eb .isAbsolute (){_dbg ,_ec =_dag +_dbg ,_bb +_ec ;};_ea .Add_l (_fac (_dbg ,3),_fac (_ec ,3));_dag ,_bb =_dbg ,_ec ;case "\u0068":_acd :=_eb .Params [0]*_gc ._gggf ;if !_eb .isAbsolute (){_acd =_dag +_acd ;};_ea .Add_l (_fac (_acd ,3),_fac (_bb ,3));
|
|
_dag =_acd ;case "\u0076":_dc :=_eb .Params [0]*_gc ._gggf ;if !_eb .isAbsolute (){_dc =_bb +_dc ;};_ea .Add_l (_fac (_dag ,3),_fac (_dc ,3));_bb =_dc ;case "\u0071":_ca ,_ebd ,_ebc ,_ag :=_eb .Params [0]*_gc ._gggf ,_eb .Params [1]*_gc ._gggf ,_eb .Params [2]*_gc ._gggf ,_eb .Params [3]*_gc ._gggf ;
|
|
if !_eb .isAbsolute (){_ca ,_ebd ,_ebc ,_ag =_dag +_ca ,_bb +_ebd ,_dag +_ebc ,_bb +_ag ;};_fe ,_fd :=_cg .QuadraticToCubicBezier (_dag ,_bb ,_ca ,_ebd ,_ebc ,_ag );_ea .Add_c (_fac (_fe .X ,3),_fac (_fe .Y ,3),_fac (_fd .X ,3),_fac (_fd .Y ,3),_fac (_ebc ,3),_fac (_ag ,3));
|
|
_dag ,_bb =_ebc ,_ag ;case "\u0074":var _eed ,_fa _cg .Point ;_dgg ,_ga :=_eb .Params [0]*_gc ._gggf ,_eb .Params [1]*_gc ._gggf ;if !_eb .isAbsolute (){_dgg ,_ga =_dag +_dgg ,_bb +_ga ;};if _ab !=nil &&_d .ToLower (_ab .Symbol )=="\u0071"{_ed :=_cg .Point {X :_ab .Params [0]*_gc ._gggf ,Y :_ab .Params [1]*_gc ._gggf };
|
|
_geb :=_cg .Point {X :_ab .Params [2]*_gc ._gggf ,Y :_ab .Params [3]*_gc ._gggf };_bd :=_geb .Mul (2.0).Sub (_ed );_eed ,_fa =_cg .QuadraticToCubicBezier (_dag ,_bb ,_bd .X ,_bd .Y ,_dgg ,_ga );};_ea .Add_c (_fac (_eed .X ,3),_fac (_eed .Y ,3),_fac (_fa .X ,3),_fac (_fa .Y ,3),_fac (_dgg ,3),_fac (_ga ,3));
|
|
_dag ,_bb =_dgg ,_ga ;case "\u0061":_bg ,_dgdf :=_eb .Params [0]*_gc ._gggf ,_eb .Params [1]*_gc ._gggf ;_ba :=_eb .Params [2];_bgb :=_eb .Params [3]> 0;_ae :=_eb .Params [4]> 0;_gga ,_ged :=_eb .Params [5]*_gc ._gggf ,_eb .Params [6]*_gc ._gggf ;if !_eb .isAbsolute (){_gga ,_ged =_dag +_gga ,_bb +_ged ;
|
|
};_eda :=_cg .EllipseToCubicBeziers (_dag ,_bb ,_bg ,_dgdf ,_ba ,_bgb ,_ae ,_gga ,_ged );for _ ,_abd :=range _eda {_ea .Add_c (_fac (_abd [1].X ,3),_fac ((_abd [1].Y ),3),_fac ((_abd [2].X ),3),_fac ((_abd [2].Y ),3),_fac ((_abd [3].X ),3),_fac ((_abd [3].Y ),3));
|
|
};_dag ,_bb =_gga ,_ged ;case "\u007a":_ea .Add_h ();};_ab =_eb ;};};if _gc .Style .FillColor !=""&&_gc .Style .StrokeColor !=""{_ea .Add_B ();}else if _gc .Style .FillColor !=""{_ea .Add_f ();}else if _gc .Style .StrokeColor !=""{_ea .Add_S ();};_ea .Add_h ();
|
|
_ea .Add_Q ();};type GraphicSVGStyle struct{FillColor string ;StrokeColor string ;StrokeWidth float64 ;};func _beg (_fdcf string )[]token {var (_aafb []token ;_afd string ;);for _ ,_ccc :=range _fdcf {_edb :=string (_ccc );switch {case _edgf .isCommand (_edb ):_aafb ,_afd =_abed (_aafb ,_afd );
|
|
_aafb =append (_aafb ,token {_edb ,true });case _edb =="\u002e":if _afd ==""{_afd ="\u0030";};if _d .Contains (_afd ,_edb ){_aafb =append (_aafb ,token {_afd ,false });_afd ="\u0030";};fallthrough;case _edb >="\u0030"&&_edb <="\u0039"||_edb =="\u0065":_afd +=_edb ;
|
|
case _edb =="\u002d":if _d .HasSuffix (_afd ,"\u0065"){_afd +=_edb ;}else {_aafb ,_ =_abed (_aafb ,_afd );_afd =_edb ;};default:_aafb ,_afd =_abed (_aafb ,_afd );};};_aafb ,_ =_abed (_aafb ,_afd );return _aafb ;};func (_dff *Subpath )compare (_bcf *Subpath )bool {if len (_dff .Commands )!=len (_bcf .Commands ){return false ;
|
|
};for _fcb ,_fef :=range _dff .Commands {if !_fef .compare (_bcf .Commands [_fcb ]){return false ;};};return true ;};func _egd (_efc []*Command )*Path {_bgcf :=&Path {};var _fdbg []*Command ;for _fee ,_gefe :=range _efc {switch _d .ToLower (_gefe .Symbol ){case _edgf ._ddf :if len (_fdbg )> 0{_bgcf .Subpaths =append (_bgcf .Subpaths ,&Subpath {_fdbg });
|
|
};_fdbg =[]*Command {_gefe };case _edgf ._aec :_fdbg =append (_fdbg ,_gefe );_bgcf .Subpaths =append (_bgcf .Subpaths ,&Subpath {_fdbg });_fdbg =[]*Command {};default:_fdbg =append (_fdbg ,_gefe );if len (_efc )==_fee +1{_bgcf .Subpaths =append (_bgcf .Subpaths ,&Subpath {_fdbg });
|
|
};};};return _bgcf ;};func _aed (_fed *GraphicSVG ,_gaa *_cbf .ContentCreator ){_gaa .Add_q ();_fed .Style .toContentStream (_gaa );_fdg ,_gad :=_edf (_fed .Attributes ["\u0063\u0078"],64);if _gad !=nil {_dg .Log .Debug ("\u0045\u0072\u0072or\u0020\u0077\u0068\u0069\u006c\u0065\u0020\u0070\u0061r\u0073i\u006eg\u0020`\u0063\u0078\u0060\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020\u0025\u0076",_gad .Error ());
|
|
};_gaf ,_gad :=_edf (_fed .Attributes ["\u0063\u0079"],64);if _gad !=nil {_dg .Log .Debug ("\u0045\u0072\u0072or\u0020\u0077\u0068\u0069\u006c\u0065\u0020\u0070\u0061r\u0073i\u006eg\u0020`\u0063\u0079\u0060\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020\u0025\u0076",_gad .Error ());
|
|
};_fc ,_gad :=_edf (_fed .Attributes ["\u0072"],64);if _gad !=nil {_dg .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020w\u0068\u0069\u006c\u0065\u0020\u0070\u0061\u0072\u0073\u0069\u006e\u0067\u0020`\u0072\u0060\u0020\u0076\u0061\u006c\u0075e\u003a\u0020\u0025\u0076",_gad .Error ());
|
|
};_baa :=_fc *_fed ._gggf ;_acf :=_fc *_fed ._gggf ;_ceg :=_baa *_db ;_dga :=_acf *_db ;_aa :=_cb .NewCubicBezierPath ();_aa =_aa .AppendCurve (_cb .NewCubicBezierCurve (-_baa ,0,-_baa ,_dga ,-_ceg ,_acf ,0,_acf ));_aa =_aa .AppendCurve (_cb .NewCubicBezierCurve (0,_acf ,_ceg ,_acf ,_baa ,_dga ,_baa ,0));
|
|
_aa =_aa .AppendCurve (_cb .NewCubicBezierCurve (_baa ,0,_baa ,-_dga ,_ceg ,-_acf ,0,-_acf ));_aa =_aa .AppendCurve (_cb .NewCubicBezierCurve (0,-_acf ,-_ceg ,-_acf ,-_baa ,-_dga ,-_baa ,0));_aa =_aa .Offset (_fdg *_fed ._gggf ,_gaf *_fed ._gggf );if _fed .Style .StrokeWidth > 0{_aa =_aa .Offset (_fed .Style .StrokeWidth /2,_fed .Style .StrokeWidth /2);
|
|
};_cb .DrawBezierPathWithCreator (_aa ,_gaa );if _fed .Style .FillColor !=""&&_fed .Style .StrokeColor !=""{_gaa .Add_B ();}else if _fed .Style .FillColor !=""{_gaa .Add_f ();}else if _fed .Style .StrokeColor !=""{_gaa .Add_S ();};_gaa .Add_h ();_gaa .Add_Q ();
|
|
};func _gea (_fdb *GraphicSVG ,_gef *_cbf .ContentCreator ){_gef .Add_q ();_fdb .Style .toContentStream (_gef );_edg ,_dagd :=_edf (_fdb .Attributes ["\u0078"],64);if _dagd !=nil {_dg .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020w\u0068\u0069\u006c\u0065\u0020\u0070\u0061\u0072\u0073\u0069\u006e\u0067\u0020`\u0078\u0060\u0020\u0076\u0061\u006c\u0075e\u003a\u0020\u0025\u0076",_dagd .Error ());
|
|
};_bba ,_dagd :=_edf (_fdb .Attributes ["\u0079"],64);if _dagd !=nil {_dg .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020w\u0068\u0069\u006c\u0065\u0020\u0070\u0061\u0072\u0073\u0069\u006e\u0067\u0020`\u0079\u0060\u0020\u0076\u0061\u006c\u0075e\u003a\u0020\u0025\u0076",_dagd .Error ());
|
|
};_cba ,_dagd :=_edf (_fdb .Attributes ["\u0077\u0069\u0064t\u0068"],64);if _dagd !=nil {_dg .Log .Debug ("\u0045\u0072\u0072o\u0072\u0020\u0077\u0068\u0069\u006c\u0065\u0020\u0070\u0061\u0072\u0073\u0069\u006e\u0067\u0020\u0073\u0074\u0072\u006f\u006b\u0065\u0020\u0077\u0069\u0064\u0074\u0068\u0020v\u0061\u006c\u0075\u0065\u003a\u0020\u0025\u0076",_dagd .Error ());
|
|
};_bbd ,_dagd :=_edf (_fdb .Attributes ["\u0068\u0065\u0069\u0067\u0068\u0074"],64);if _dagd !=nil {_dg .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0077h\u0069\u006c\u0065 \u0070\u0061\u0072\u0073i\u006e\u0067\u0020\u0073\u0074\u0072\u006f\u006b\u0065\u0020\u0068\u0065\u0069\u0067\u0068\u0074\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020\u0025\u0076",_dagd .Error ());
|
|
};_gef .Add_re (_edg *_fdb ._gggf ,_bba *_fdb ._gggf ,_cba *_fdb ._gggf ,_bbd *_fdb ._gggf );if _fdb .Style .FillColor !=""&&_fdb .Style .StrokeColor !=""{_gef .Add_B ();}else if _fdb .Style .FillColor !=""{_gef .Add_f ();}else if _fdb .Style .StrokeColor !=""{_gef .Add_S ();
|
|
};_gef .Add_Q ();};var _edgf commands ;func (_bae *GraphicSVG )ToContentCreator (cc *_cbf .ContentCreator ,scaleX ,scaleY ,translateX ,translateY float64 )*_cbf .ContentCreator {if _bae .Name =="\u0073\u0076\u0067"{_bae .SetScaling (scaleX ,scaleY );cc .Add_cm (1,0,0,1,translateX ,translateY );
|
|
_bae .setDefaultScaling (_bae ._gggf );cc .Add_q ();_faa :=_gg .Max (scaleX ,scaleY );cc .Add_re (_bae .ViewBox .X *_faa ,_bae .ViewBox .Y *_faa ,_bae .ViewBox .W *_faa ,_bae .ViewBox .H *_faa );cc .Add_W ();cc .Add_n ();for _ ,_bdf :=range _bae .Children {_bdf .ViewBox =_bae .ViewBox ;
|
|
_bdf .toContentStream (cc );};cc .Add_Q ();return cc ;};return nil ;};func _edgg (_abg *GraphicSVG ,_fbc *_cbf .ContentCreator ){_fbc .Add_q ();_abg .Style .toContentStream (_fbc );_fdc ,_bab :=_edf (_abg .Attributes ["\u0063\u0078"],64);if _bab !=nil {_dg .Log .Debug ("\u0045\u0072\u0072or\u0020\u0077\u0068\u0069\u006c\u0065\u0020\u0070\u0061r\u0073i\u006eg\u0020`\u0063\u0078\u0060\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020\u0025\u0076",_bab .Error ());
|
|
};_fgc ,_bab :=_edf (_abg .Attributes ["\u0063\u0079"],64);if _bab !=nil {_dg .Log .Debug ("\u0045\u0072\u0072or\u0020\u0077\u0068\u0069\u006c\u0065\u0020\u0070\u0061r\u0073i\u006eg\u0020`\u0063\u0079\u0060\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020\u0025\u0076",_bab .Error ());
|
|
};_cgc ,_bab :=_edf (_abg .Attributes ["\u0072\u0078"],64);if _bab !=nil {_dg .Log .Debug ("\u0045\u0072\u0072or\u0020\u0077\u0068\u0069\u006c\u0065\u0020\u0070\u0061r\u0073i\u006eg\u0020`\u0072\u0078\u0060\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020\u0025\u0076",_bab .Error ());
|
|
};_ggg ,_bab :=_edf (_abg .Attributes ["\u0072\u0079"],64);if _bab !=nil {_dg .Log .Debug ("\u0045\u0072\u0072or\u0020\u0077\u0068\u0069\u006c\u0065\u0020\u0070\u0061r\u0073i\u006eg\u0020`\u0072\u0079\u0060\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020\u0025\u0076",_bab .Error ());
|
|
};_fdbf :=_cgc *_abg ._gggf ;_cf :=_ggg *_abg ._gggf ;_acb :=_fdc *_abg ._gggf ;_cag :=_fgc *_abg ._gggf ;_gce :=_fdbf *_db ;_cea :=_cf *_db ;_ede :=_cb .NewCubicBezierPath ();_ede =_ede .AppendCurve (_cb .NewCubicBezierCurve (-_fdbf ,0,-_fdbf ,_cea ,-_gce ,_cf ,0,_cf ));
|
|
_ede =_ede .AppendCurve (_cb .NewCubicBezierCurve (0,_cf ,_gce ,_cf ,_fdbf ,_cea ,_fdbf ,0));_ede =_ede .AppendCurve (_cb .NewCubicBezierCurve (_fdbf ,0,_fdbf ,-_cea ,_gce ,-_cf ,0,-_cf ));_ede =_ede .AppendCurve (_cb .NewCubicBezierCurve (0,-_cf ,-_gce ,-_cf ,-_fdbf ,-_cea ,-_fdbf ,0));
|
|
_ede =_ede .Offset (_acb ,_cag );if _abg .Style .StrokeWidth > 0{_ede =_ede .Offset (_abg .Style .StrokeWidth /2,_abg .Style .StrokeWidth /2);};_cb .DrawBezierPathWithCreator (_ede ,_fbc );if _abg .Style .FillColor !=""&&_abg .Style .StrokeColor !=""{_fbc .Add_B ();
|
|
}else if _abg .Style .FillColor !=""{_fbc .Add_f ();}else if _abg .Style .StrokeColor !=""{_fbc .Add_S ();};_fbc .Add_h ();_fbc .Add_Q ();};type GraphicSVG struct{ViewBox struct{X ,Y ,W ,H float64 ;};Name string ;Attributes map[string ]string ;Children []*GraphicSVG ;
|
|
Content string ;Style *GraphicSVGStyle ;Width float64 ;Height float64 ;_gggf float64 ;};func _bda (_cfc string )(*Path ,error ){_edgf =_gfab ();_dee ,_deba :=_adc (_beg (_cfc ));if _deba !=nil {return nil ,_deba ;};return _egd (_dee ),nil ;};func _gbga (_afb map[string ]string ,_dfb float64 )(*GraphicSVGStyle ,error ){_ggfa :=_efa ();
|
|
_gdd ,_adb :=_afb ["\u0066\u0069\u006c\u006c"];if _adb {_ggfa .FillColor =_gdd ;if _gdd =="\u006e\u006f\u006e\u0065"{_ggfa .FillColor ="";};};_gfe ,_ecdf :=_afb ["\u0073\u0074\u0072\u006f\u006b\u0065"];if _ecdf {_ggfa .StrokeColor =_gfe ;if _gfe =="\u006e\u006f\u006e\u0065"{_ggfa .StrokeColor ="";
|
|
};};_fgb ,_efg :=_afb ["\u0073\u0074\u0072o\u006b\u0065\u002d\u0077\u0069\u0064\u0074\u0068"];if _efg {_fcef ,_feb :=_edf (_fgb ,64);if _feb !=nil {return nil ,_feb ;};_ggfa .StrokeWidth =_fcef *_dfb ;};return _ggfa ,nil ;};type Path struct{Subpaths []*Subpath ;
|
|
};func _bfc (_fcfg string )(_abb ,_dcd string ){if _fcfg ==""||(_fcfg [len (_fcfg )-1]>='0'&&_fcfg [len (_fcfg )-1]<='9'){return _fcfg ,"";};_abb =_fcfg ;for _ ,_dfda :=range _da {if _d .Contains (_abb ,_dfda ){_dcd =_dfda ;};_abb =_d .TrimSuffix (_abb ,_dfda );
|
|
};return ;};func (_fgf *Command )compare (_cgb *Command )bool {if _fgf .Symbol !=_cgb .Symbol {return false ;};for _eege ,_fcf :=range _fgf .Params {if _fcf !=_cgb .Params [_eege ]{return false ;};};return true ;};func _ddff (_cddgd []float64 )[]float64 {for _acc ,_dedd :=0,len (_cddgd )-1;
|
|
_acc < _dedd ;_acc ,_dedd =_acc +1,_dedd -1{_cddgd [_acc ],_cddgd [_dedd ]=_cddgd [_dedd ],_cddgd [_acc ];};return _cddgd ;};func (_cdd *GraphicSVGStyle )toContentStream (_gag *_cbf .ContentCreator ){if _cdd ==nil {return ;};if _cdd .FillColor !=""{var _cddg ,_fca ,_dad float64 ;
|
|
if _gcbb ,_cee :=_cg .ColorMap [_cdd .FillColor ];_cee {_gebe ,_agbd ,_ead ,_ :=_gcbb .RGBA ();_cddg ,_fca ,_dad =float64 (_gebe ),float64 (_agbd ),float64 (_ead );}else {_cddg ,_fca ,_dad =_eag (_cdd .FillColor );};_gag .Add_rg (_cddg ,_fca ,_dad );};
|
|
if _cdd .StrokeColor !=""{var _eae ,_add ,_deb float64 ;if _bce ,_gadg :=_cg .ColorMap [_cdd .StrokeColor ];_gadg {_bea ,_ffag ,_ada ,_ :=_bce .RGBA ();_eae ,_add ,_deb =float64 (_bea )/255.0,float64 (_ffag )/255.0,float64 (_ada )/255.0;}else {_eae ,_add ,_deb =_eag (_cdd .StrokeColor );
|
|
};_gag .Add_RG (_eae ,_add ,_deb );};if _cdd .StrokeWidth > 0{_gag .Add_w (_cdd .StrokeWidth );};};func _gfab ()commands {var _cgd =map[string ]int {"\u006d":2,"\u007a":0,"\u006c":2,"\u0068":1,"\u0076":1,"\u0063":6,"\u0073":4,"\u0071":4,"\u0074":2,"\u0061":7};
|
|
var _ebeb []string ;for _fceg :=range _cgd {_ebeb =append (_ebeb ,_fceg );};return commands {_ebeb ,_cgd ,"\u006d","\u007a"};};func _eag (_facg string )(_ebg ,_ebge ,_dbb float64 ){if (len (_facg )!=4&&len (_facg )!=7)||_facg [0]!='#'{_dg .Log .Debug ("I\u006ev\u0061\u006c\u0069\u0064\u0020\u0068\u0065\u0078 \u0063\u006f\u0064\u0065: \u0025\u0073",_facg );
|
|
return _ebg ,_ebge ,_dbb ;};var _gebg ,_adea ,_cdf int ;if len (_facg )==4{var _daa ,_acbe ,_gdf int ;_dabg ,_bbda :=_g .Sscanf (_facg ,"\u0023\u0025\u0031\u0078\u0025\u0031\u0078\u0025\u0031\u0078",&_daa ,&_acbe ,&_gdf );if _bbda !=nil {_dg .Log .Debug ("\u0049\u006e\u0076a\u006c\u0069\u0064\u0020h\u0065\u0078\u0020\u0063\u006f\u0064\u0065:\u0020\u0025\u0073\u002c\u0020\u0065\u0072\u0072\u006f\u0072\u003a\u0020\u0025\u0076",_facg ,_bbda );
|
|
return _ebg ,_ebge ,_dbb ;};if _dabg !=3{_dg .Log .Debug ("I\u006ev\u0061\u006c\u0069\u0064\u0020\u0068\u0065\u0078 \u0063\u006f\u0064\u0065: \u0025\u0073",_facg );return _ebg ,_ebge ,_dbb ;};_gebg =_daa *16+_daa ;_adea =_acbe *16+_acbe ;_cdf =_gdf *16+_gdf ;
|
|
}else {_afgf ,_edc :=_g .Sscanf (_facg ,"\u0023\u0025\u0032\u0078\u0025\u0032\u0078\u0025\u0032\u0078",&_gebg ,&_adea ,&_cdf );if _edc !=nil {_dg .Log .Debug ("I\u006ev\u0061\u006c\u0069\u0064\u0020\u0068\u0065\u0078 \u0063\u006f\u0064\u0065: \u0025\u0073",_facg );
|
|
return _ebg ,_ebge ,_dbb ;};if _afgf !=3{_dg .Log .Debug ("\u0049\u006e\u0076\u0061\u006c\u0069d\u0020\u0068\u0065\u0078\u0020\u0063\u006f\u0064\u0065\u003a\u0020\u0025\u0073,\u0020\u006e\u0020\u0021\u003d\u0020\u0033 \u0028\u0025\u0064\u0029",_facg ,_afgf );
|
|
return _ebg ,_ebge ,_dbb ;};};_geff :=float64 (_gebg )/255.0;_abbd :=float64 (_adea )/255.0;_egcf :=float64 (_cdf )/255.0;return _geff ,_abbd ,_egcf ;};func ParseFromStream (source _ge .Reader )(*GraphicSVG ,error ){_gcdb :=_e .NewDecoder (source );_gcdb .CharsetReader =_ce .NewReaderLabel ;
|
|
_bgfc ,_cae :=_bag (_gcdb );if _cae !=nil {return nil ,_cae ;};if _cfd :=_bgfc .Decode (_gcdb );_cfd !=nil &&_cfd !=_ge .EOF {return nil ,_cfd ;};return _bgfc ,nil ;};func (_dgb *commands )isCommand (_bafa string )bool {for _ ,_gdg :=range _dgb ._fgbe {if _d .ToLower (_bafa )==_gdg {return true ;
|
|
};};return false ;};type commands struct{_fgbe []string ;_ecae map[string ]int ;_ddf string ;_aec string ;};func _fbb (_dgcd string )(_cbe []float64 ,_aada error ){var _gfg float64 ;_aea :=0;_eec :=true ;for _fbg ,_dca :=range _dgcd {if _dca =='.'{if _eec {_eec =false ;
|
|
continue ;};_gfg ,_aada =_edf (_dgcd [_aea :_fbg ],64);if _aada !=nil {return ;};_cbe =append (_cbe ,_gfg );_aea =_fbg ;};};_gfg ,_aada =_edf (_dgcd [_aea :],64);if _aada !=nil {return ;};_cbe =append (_cbe ,_gfg );return ;};func ParseFromFile (path string )(*GraphicSVG ,error ){_cdg ,_fcd :=_fb .Open (path );
|
|
if _fcd !=nil {return nil ,_fcd ;};defer _cdg .Close ();return ParseFromStream (_cdg );};func (_beb *GraphicSVG )setDefaultScaling (_baae float64 ){_beb ._gggf =_baae ;if _beb .Style !=nil &&_beb .Style .StrokeWidth > 0{_beb .Style .StrokeWidth =_beb .Style .StrokeWidth *_beb ._gggf ;
|
|
};for _ ,_gaff :=range _beb .Children {_gaff .setDefaultScaling (_baae );};};type token struct{_baeb string ;_dgbc bool ;};func _edf (_dgaf string ,_afg int )(float64 ,error ){_fdf ,_dba :=_bfc (_dgaf );_acgc ,_cab :=_f .ParseFloat (_fdf ,_afg );if _cab !=nil {return 0,_cab ;
|
|
};if _fcc ,_egb :=_cbc [_dba ];_egb {_acgc =_acgc *_fcc ;}else {_acgc =_acgc *_ee ;};return _acgc ,nil ;};func _abed (_caf []token ,_ddb string )([]token ,string ){if _ddb !=""{_caf =append (_caf ,token {_ddb ,false });_ddb ="";};return _caf ,_ddb ;};type Subpath struct{Commands []*Command ;
|
|
};func _ggge (_ef *GraphicSVG ,_cca *_cbf .ContentCreator ){_cca .Add_q ();_ef .Style .toContentStream (_cca );_gd ,_afa :=_edf (_ef .Attributes ["\u0078\u0031"],64);if _afa !=nil {_dg .Log .Debug ("\u0045\u0072\u0072or\u0020\u0077\u0068\u0069\u006c\u0065\u0020\u0070\u0061r\u0073i\u006eg\u0020`\u0063\u0078\u0060\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020\u0025\u0076",_afa .Error ());
|
|
};_gedg ,_afa :=_edf (_ef .Attributes ["\u0079\u0031"],64);if _afa !=nil {_dg .Log .Debug ("\u0045\u0072\u0072or\u0020\u0077\u0068\u0069\u006c\u0065\u0020\u0070\u0061r\u0073i\u006eg\u0020`\u0063\u0079\u0060\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020\u0025\u0076",_afa .Error ());
|
|
};_ege ,_afa :=_edf (_ef .Attributes ["\u0078\u0032"],64);if _afa !=nil {_dg .Log .Debug ("\u0045\u0072\u0072or\u0020\u0077\u0068\u0069\u006c\u0065\u0020\u0070\u0061r\u0073i\u006eg\u0020`\u0072\u0078\u0060\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020\u0025\u0076",_afa .Error ());
|
|
};_dfd ,_afa :=_edf (_ef .Attributes ["\u0079\u0032"],64);if _afa !=nil {_dg .Log .Debug ("\u0045\u0072\u0072or\u0020\u0077\u0068\u0069\u006c\u0065\u0020\u0070\u0061r\u0073i\u006eg\u0020`\u0072\u0079\u0060\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020\u0025\u0076",_afa .Error ());
|
|
};_cca .Add_m (_gd *_ef ._gggf ,_gedg *_ef ._gggf );_cca .Add_l (_ege *_ef ._gggf ,_dfd *_ef ._gggf );if _ef .Style .FillColor !=""&&_ef .Style .StrokeColor !=""{_cca .Add_B ();}else if _ef .Style .FillColor !=""{_cca .Add_f ();}else if _ef .Style .StrokeColor !=""{_cca .Add_S ();
|
|
};_cca .Add_h ();_cca .Add_Q ();};func _fac (_fdbb float64 ,_efcf int )float64 {_fcca :=_gg .Pow (10,float64 (_efcf ));return float64 (_bef (_fdbb *_fcca ))/_fcca ;};func _gba (_dgc *GraphicSVG ,_eeg *_cbf .ContentCreator ){_eeg .Add_q ();_dgc .Style .toContentStream (_eeg );
|
|
_eef ,_cac :=_eea (_dgc .Attributes ["\u0070\u006f\u0069\u006e\u0074\u0073"]);if _cac !=nil {_dg .Log .Debug ("\u0045\u0052\u0052O\u0052\u0020\u0075\u006e\u0061\u0062\u006c\u0065\u0020\u0074\u006f\u0020\u0070\u0061\u0072\u0073\u0065\u0020\u0070\u006f\u0069\u006e\u0074\u0073\u0020\u0061\u0074\u0074\u0072i\u0062\u0075\u0074\u0065\u003a\u0020\u0025\u0076",_cac );
|
|
return ;};if len (_eef )%2> 0{_dg .Log .Debug ("\u0045\u0052R\u004f\u0052\u0020\u0069n\u0076\u0061l\u0069\u0064\u0020\u0070\u006f\u0069\u006e\u0074s\u0020\u0061\u0074\u0074\u0072\u0069\u0062\u0075\u0074\u0065\u0020\u006ce\u006e\u0067\u0074\u0068");return ;
|
|
};for _bga :=0;_bga < len (_eef );{if _bga ==0{_eeg .Add_m (_eef [_bga ]*_dgc ._gggf ,_eef [_bga +1]*_dgc ._gggf );}else {_eeg .Add_l (_eef [_bga ]*_dgc ._gggf ,_eef [_bga +1]*_dgc ._gggf );};_bga +=2;};_eeg .Add_l (_eef [0]*_dgc ._gggf ,_eef [1]*_dgc ._gggf );
|
|
if _dgc .Style .FillColor !=""&&_dgc .Style .StrokeColor !=""{_eeg .Add_B ();}else if _dgc .Style .FillColor !=""{_eeg .Add_f ();}else if _dgc .Style .StrokeColor !=""{_eeg .Add_S ();};_eeg .Add_h ();_eeg .Add_Q ();};func _bag (_ebe *_e .Decoder )(*GraphicSVG ,error ){for {_abf ,_ebec :=_ebe .Token ();
|
|
if _abf ==nil &&_ebec ==_ge .EOF {break ;};if _ebec !=nil {return nil ,_ebec ;};switch _bgfcg :=_abf .(type ){case _e .StartElement :return _dea (_bgfcg ),nil ;};};return &GraphicSVG {},nil ;};var (_da =[]string {"\u0063\u006d","\u006d\u006d","\u0070\u0078","\u0070\u0074"};
|
|
_cbc =map[string ]float64 {"\u0063\u006d":_gf ,"\u006d\u006d":_a ,"\u0070\u0078":_ee ,"\u0070\u0074":1};);func _dea (_aae _e .StartElement )*GraphicSVG {_bde :=&GraphicSVG {};_dcc :=make (map[string ]string );for _ ,_fff :=range _aae .Attr {_dcc [_fff .Name .Local ]=_fff .Value ;
|
|
};_bde .Name =_aae .Name .Local ;_bde .Attributes =_dcc ;_bde ._gggf =1;if _bde .Name =="\u0073\u0076\u0067"{_fce ,_bbdd :=_eea (_dcc ["\u0076i\u0065\u0077\u0042\u006f\u0078"]);if _bbdd !=nil {_dg .Log .Debug ("\u0055\u006ea\u0062\u006c\u0065\u0020t\u006f\u0020p\u0061\u0072\u0073\u0065\u0020\u0076\u0069\u0065w\u0042\u006f\u0078\u0020\u0061\u0074\u0074\u0072\u0069\u0062\u0075\u0074e\u003a\u0020\u0025\u0076",_bbdd );
|
|
return nil ;};_bde .ViewBox .X =_fce [0];_bde .ViewBox .Y =_fce [1];_bde .ViewBox .W =_fce [2];_bde .ViewBox .H =_fce [3];_bde .Width =_bde .ViewBox .W ;_bde .Height =_bde .ViewBox .H ;if _aad ,_ade :=_dcc ["\u0077\u0069\u0064t\u0068"];_ade {_gee ,_deaa :=_edf (_aad ,64);
|
|
if _deaa !=nil {_dg .Log .Debug ("U\u006e\u0061\u0062\u006c\u0065\u0020t\u006f\u0020\u0070\u0061\u0072\u0073e\u0020\u0077\u0069\u0064\u0074\u0068\u0020a\u0074\u0074\u0072\u0069\u0062\u0075\u0074\u0065\u003a\u0020%\u0076",_deaa );return nil ;};_bde .Width =_gee ;
|
|
};if _bdd ,_eca :=_dcc ["\u0068\u0065\u0069\u0067\u0068\u0074"];_eca {_dfe ,_adeg :=_edf (_bdd ,64);if _adeg !=nil {_dg .Log .Debug ("\u0055\u006eab\u006c\u0065\u0020t\u006f\u0020\u0070\u0061rse\u0020he\u0069\u0067\u0068\u0074\u0020\u0061\u0074tr\u0069\u0062\u0075\u0074\u0065\u003a\u0020%\u0076",_adeg );
|
|
return nil ;};_bde .Height =_dfe ;};if _bde .Width > 0&&_bde .Height > 0{_bde ._gggf =_bde .Width /_bde .ViewBox .W ;};};return _bde ;};const (_ee =0.72;_gf =28.3464;_a =_gf /10;_db =0.551784;); |