2022-12-15 21:59:56 +00:00
|
|
|
//
|
|
|
|
// 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/
|
|
|
|
|
2023-02-07 17:17:49 +00:00
|
|
|
package svg ;import (_fd "encoding/xml";_gb "fmt";_gg "github.com/unidoc/unipdf/v3/common";_fc "github.com/unidoc/unipdf/v3/contentstream";_b "github.com/unidoc/unipdf/v3/contentstream/draw";_ee "github.com/unidoc/unipdf/v3/internal/graphic2d";_eb "golang.org/x/net/html/charset";
|
|
|
|
_fa "io";_ff "math";_cb "os";_f "strconv";_c "strings";_e "unicode";);func _ecc (_eec []token ,_eeff string )([]token ,string ){if _eeff !=""{_eec =append (_eec ,token {_eeff ,false });_eeff ="";};return _eec ,_eeff ;};func _bgag (_dcdc float64 ,_dde int )float64 {_egcf :=_ff .Pow (10,float64 (_dde ));
|
|
|
|
return float64 (_bbdb (_dcdc *_egcf ))/_egcf ;};func (_ffgg *Command )compare (_ggfd *Command )bool {if _ffgg .Symbol !=_ggfd .Symbol {return false ;};for _bgbc ,_fegg :=range _ffgg .Params {if _fegg !=_ggfd .Params [_bgbc ]{return false ;};};return true ;
|
|
|
|
};func (_eba *GraphicSVG )SetScaling (xFactor ,yFactor float64 ){_dag :=_eba .Width /_eba .ViewBox .W ;_efe :=_eba .Height /_eba .ViewBox .H ;_eba .setDefaultScaling (_ff .Max (_dag ,_efe ));for _ ,_fbf :=range _eba .Children {_fbf .SetScaling (xFactor ,yFactor );
|
|
|
|
};};func (_dbbb *Path )compare (_fgde *Path )bool {if len (_dbbb .Subpaths )!=len (_fgde .Subpaths ){return false ;};for _gfagf ,_bga :=range _dbbb .Subpaths {if !_bga .compare (_fgde .Subpaths [_gfagf ]){return false ;};};return true ;};func _agd ()commands {var _gfca =map[string ]int {"\u006d":2,"\u007a":0,"\u006c":2,"\u0068":1,"\u0076":1,"\u0063":6,"\u0073":4,"\u0071":4,"\u0074":2,"\u0061":7};
|
|
|
|
var _agaf []string ;for _agde :=range _gfca {_agaf =append (_agaf ,_agde );};return commands {_agaf ,_gfca ,"\u006d","\u007a"};};const (_gbc =0.72;_gd =28.3464;_fdc =_gd /10;_cc =0.551784;);func _bfdc (_bddca string )[]token {var (_eab []token ;_ced string ;
|
|
|
|
);for _ ,_bbbd :=range _bddca {_fff :=string (_bbbd );switch {case _bgc .isCommand (_fff ):_eab ,_ced =_ecc (_eab ,_ced );_eab =append (_eab ,token {_fff ,true });case _fff =="\u002e":if _ced ==""{_ced ="\u0030";};if _c .Contains (_ced ,_fff ){_eab =append (_eab ,token {_ced ,false });
|
|
|
|
_ced ="\u0030";};fallthrough;case _fff >="\u0030"&&_fff <="\u0039"||_fff =="\u0065":_ced +=_fff ;case _fff =="\u002d":if _c .HasSuffix (_ced ,"\u0065"){_ced +=_fff ;}else {_eab ,_ =_ecc (_eab ,_ced );_ced =_fff ;};default:_eab ,_ced =_ecc (_eab ,_ced );
|
|
|
|
};};_eab ,_ =_ecc (_eab ,_ced );return _eab ;};func (_bdde *commands )isCommand (_bbd string )bool {for _ ,_ffgb :=range _bdde ._deff {if _c .ToLower (_bbd )==_ffgb {return true ;};};return false ;};type Path struct{Subpaths []*Subpath ;};func _ge (_aef *GraphicSVG ,_ea *_fc .ContentCreator ){_ea .Add_q ();
|
|
|
|
_aef .Style .toContentStream (_ea );_bf ,_aaa :=_dgf (_aef .Attributes ["\u0063\u0078"],64);if _aaa !=nil {_gg .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",_aaa .Error ());
|
|
|
|
};_dfbdb ,_aaa :=_dgf (_aef .Attributes ["\u0063\u0079"],64);if _aaa !=nil {_gg .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",_aaa .Error ());
|
|
|
|
};_dga ,_aaa :=_dgf (_aef .Attributes ["\u0072\u0078"],64);if _aaa !=nil {_gg .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",_aaa .Error ());
|
|
|
|
};_ed ,_aaa :=_dgf (_aef .Attributes ["\u0072\u0079"],64);if _aaa !=nil {_gg .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",_aaa .Error ());
|
|
|
|
};_fcda :=_dga *_aef ._da ;_bde :=_ed *_aef ._da ;_ded :=_bf *_aef ._da ;_dd :=_dfbdb *_aef ._da ;_bbb :=_fcda *_cc ;_dfc :=_bde *_cc ;_efd :=_b .NewCubicBezierPath ();_efd =_efd .AppendCurve (_b .NewCubicBezierCurve (-_fcda ,0,-_fcda ,_dfc ,-_bbb ,_bde ,0,_bde ));
|
|
|
|
_efd =_efd .AppendCurve (_b .NewCubicBezierCurve (0,_bde ,_bbb ,_bde ,_fcda ,_dfc ,_fcda ,0));_efd =_efd .AppendCurve (_b .NewCubicBezierCurve (_fcda ,0,_fcda ,-_dfc ,_bbb ,-_bde ,0,-_bde ));_efd =_efd .AppendCurve (_b .NewCubicBezierCurve (0,-_bde ,-_bbb ,-_bde ,-_fcda ,-_dfc ,-_fcda ,0));
|
|
|
|
_efd =_efd .Offset (_ded ,_dd );if _aef .Style .StrokeWidth > 0{_efd =_efd .Offset (_aef .Style .StrokeWidth /2,_aef .Style .StrokeWidth /2);};_b .DrawBezierPathWithCreator (_efd ,_ea );if _aef .Style .FillColor !=""&&_aef .Style .StrokeColor !=""{_ea .Add_B ();
|
|
|
|
}else if _aef .Style .FillColor !=""{_ea .Add_f ();}else if _aef .Style .StrokeColor !=""{_ea .Add_S ();};_ea .Add_h ();_ea .Add_Q ();};type Command struct{Symbol string ;Params []float64 ;};func (_acb *GraphicSVG )Decode (decoder *_fd .Decoder )error {for {_gaf ,_dge :=decoder .Token ();
|
|
|
|
if _gaf ==nil &&_dge ==_fa .EOF {break ;};if _dge !=nil {return _dge ;};switch _fcdaa :=_gaf .(type ){case _fd .StartElement :_dcf :=_eeb (_fcdaa );_edc :=_dcf .Decode (decoder );if _edc !=nil {return _edc ;};_acb .Children =append (_acb .Children ,_dcf );
|
|
|
|
case _fd .CharData :_ged :=_c .TrimSpace (string (_fcdaa ));if _ged !=""{_acb .Content =string (_fcdaa );};case _fd .EndElement :if _fcdaa .Name .Local ==_acb .Name {return nil ;};};};return nil ;};func _aage (_bda *GraphicSVG ,_ad *_fc .ContentCreator ){_ad .Add_q ();
|
|
|
|
_bda .Style .toContentStream (_ad );_gfac ,_ffaf :=_dgf (_bda .Attributes ["\u0063\u0078"],64);if _ffaf !=nil {_gg .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",_ffaf .Error ());
|
|
|
|
};_deg ,_ffaf :=_dgf (_bda .Attributes ["\u0063\u0079"],64);if _ffaf !=nil {_gg .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",_ffaf .Error ());
|
|
|
|
};_ggc ,_ffaf :=_dgf (_bda .Attributes ["\u0072"],64);if _ffaf !=nil {_gg .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",_ffaf .Error ());
|
|
|
|
};_bdb :=_ggc *_bda ._da ;_dfbd :=_ggc *_bda ._da ;_fb :=_bdb *_cc ;_eff :=_dfbd *_cc ;_cfd :=_b .NewCubicBezierPath ();_cfd =_cfd .AppendCurve (_b .NewCubicBezierCurve (-_bdb ,0,-_bdb ,_eff ,-_fb ,_dfbd ,0,_dfbd ));_cfd =_cfd .AppendCurve (_b .NewCubicBezierCurve (0,_dfbd ,_fb ,_dfbd ,_bdb ,_eff ,_bdb ,0));
|
|
|
|
_cfd =_cfd .AppendCurve (_b .NewCubicBezierCurve (_bdb ,0,_bdb ,-_eff ,_fb ,-_dfbd ,0,-_dfbd ));_cfd =_cfd .AppendCurve (_b .NewCubicBezierCurve (0,-_dfbd ,-_fb ,-_dfbd ,-_bdb ,-_eff ,-_bdb ,0));_cfd =_cfd .Offset (_gfac *_bda ._da ,_deg *_bda ._da );if _bda .Style .StrokeWidth > 0{_cfd =_cfd .Offset (_bda .Style .StrokeWidth /2,_bda .Style .StrokeWidth /2);
|
|
|
|
};_b .DrawBezierPathWithCreator (_cfd ,_ad );if _bda .Style .FillColor !=""&&_bda .Style .StrokeColor !=""{_ad .Add_B ();}else if _bda .Style .FillColor !=""{_ad .Add_f ();}else if _bda .Style .StrokeColor !=""{_ad .Add_S ();};_ad .Add_h ();_ad .Add_Q ();
|
|
|
|
};func _bbdb (_adfg float64 )int {return int (_adfg +_ff .Copysign (0.5,_adfg ))};func ParseFromFile (path string )(*GraphicSVG ,error ){_ddgc ,_bgeb :=_cb .Open (path );if _bgeb !=nil {return nil ,_bgeb ;};defer _ddgc .Close ();return ParseFromStream (_ddgc );
|
|
|
|
};func _def (_aaf map[string ]string ,_abe float64 )(*GraphicSVGStyle ,error ){_cbgc :=_add ();_gcc ,_ebe :=_aaf ["\u0066\u0069\u006c\u006c"];if _ebe {_cbgc .FillColor =_gcc ;if _gcc =="\u006e\u006f\u006e\u0065"{_cbgc .FillColor ="";};};_bfd ,_ebd :=_aaf ["\u0073\u0074\u0072\u006f\u006b\u0065"];
|
|
|
|
if _ebd {_cbgc .StrokeColor =_bfd ;if _bfd =="\u006e\u006f\u006e\u0065"{_cbgc .StrokeColor ="";};};_adg ,_edba :=_aaf ["\u0073\u0074\u0072o\u006b\u0065\u002d\u0077\u0069\u0064\u0074\u0068"];if _edba {_bfcf ,_bgb :=_dgf (_adg ,64);if _bgb !=nil {return nil ,_bgb ;
|
|
|
|
};_cbgc .StrokeWidth =_bfcf *_abe ;};return _cbgc ,nil ;};func _cfg (_dgd *GraphicSVG ,_ga *_fc .ContentCreator ){_ga .Add_q ();_dgd .Style .toContentStream (_ga );_dcd ,_ccb :=_dgf (_dgd .Attributes ["\u0078"],64);if _ccb !=nil {_gg .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",_ccb .Error ());
|
|
|
|
};_aegc ,_ccb :=_dgf (_dgd .Attributes ["\u0079"],64);if _ccb !=nil {_gg .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",_ccb .Error ());
|
|
|
|
};_gfa ,_ccb :=_dgf (_dgd .Attributes ["\u0077\u0069\u0064t\u0068"],64);if _ccb !=nil {_gg .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",_ccb .Error ());
|
|
|
|
};_efc ,_ccb :=_dgf (_dgd .Attributes ["\u0068\u0065\u0069\u0067\u0068\u0074"],64);if _ccb !=nil {_gg .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",_ccb .Error ());
|
|
|
|
};_ga .Add_re (_dcd *_dgd ._da ,_aegc *_dgd ._da ,_gfa *_dgd ._da ,_efc *_dgd ._da );if _dgd .Style .FillColor !=""&&_dgd .Style .StrokeColor !=""{_ga .Add_B ();}else if _dgd .Style .FillColor !=""{_ga .Add_f ();}else if _dgd .Style .StrokeColor !=""{_ga .Add_S ();
|
|
|
|
};_ga .Add_Q ();};func _aab (_caf string )(*Path ,error ){_bgc =_agd ();_cdb ,_gae :=_bdc (_bfdc (_caf ));if _gae !=nil {return nil ,_gae ;};return _egd (_cdb ),nil ;};var (_gc =[]string {"\u0063\u006d","\u006d\u006d","\u0070\u0078","\u0070\u0074"};_d =map[string ]float64 {"\u0063\u006d":_gd ,"\u006d\u006d":_fdc ,"\u0070\u0078":_gbc ,"\u0070\u0074":1};
|
|
|
|
);func (_bcf *GraphicSVG )ToContentCreator (cc *_fc .ContentCreator )*_fc .ContentCreator {if _bcf .Name =="\u0073\u0076\u0067"{cc .Add_cm (1,0,0,1,0,0);_bcf .setDefaultScaling (_bcf ._da );for _ ,_faf :=range _bcf .Children {_faf .ViewBox =_bcf .ViewBox ;
|
|
|
|
_faf .toContentStream (cc );};return cc ;};return nil ;};func _ega (_eef *GraphicSVG ,_dgb *_fc .ContentCreator ){_dgb .Add_q ();_eef .Style .toContentStream (_dgb );_fg ,_bbe :=_efb (_eef .Attributes ["\u0070\u006f\u0069\u006e\u0074\u0073"]);if _bbe !=nil {_gg .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",_bbe );
|
|
|
|
return ;};if len (_fg )%2> 0{_gg .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 _edb :=0;_edb < len (_fg );{if _edb ==0{_dgb .Add_m (_fg [_edb ]*_eef ._da ,_fg [_edb +1]*_eef ._da );}else {_dgb .Add_l (_fg [_edb ]*_eef ._da ,_fg [_edb +1]*_eef ._da );};_edb +=2;};_dgb .Add_l (_fg [0]*_eef ._da ,_fg [1]*_eef ._da );if _eef .Style .FillColor !=""&&_eef .Style .StrokeColor !=""{_dgb .Add_B ();
|
|
|
|
}else if _eef .Style .FillColor !=""{_dgb .Add_f ();}else if _eef .Style .StrokeColor !=""{_dgb .Add_S ();};_dgb .Add_h ();_dgb .Add_Q ();};func (_bbeb pathParserError )Error ()string {return _bbeb ._bddcb };func _eeb (_gfe _fd .StartElement )*GraphicSVG {_bdfc :=&GraphicSVG {};
|
|
|
|
_egg :=make (map[string ]string );for _ ,_dcb :=range _gfe .Attr {_egg [_dcb .Name .Local ]=_dcb .Value ;};_bdfc .Name =_gfe .Name .Local ;_bdfc .Attributes =_egg ;_bdfc ._da =1;if _bdfc .Name =="\u0073\u0076\u0067"{_cbg ,_ddc :=_efb (_egg ["\u0076i\u0065\u0077\u0042\u006f\u0078"]);
|
|
|
|
if _ddc !=nil {_gg .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",_ddc );return nil ;};
|
|
|
|
_bdfc .ViewBox .X =_cbg [0];_bdfc .ViewBox .Y =_cbg [1];_bdfc .ViewBox .W =_cbg [2];_bdfc .ViewBox .H =_cbg [3];_bdfc .Width =_bdfc .ViewBox .W ;_bdfc .Height =_bdfc .ViewBox .H ;if _dgae ,_edd :=_egg ["\u0077\u0069\u0064t\u0068"];_edd {_cbb ,_gbg :=_dgf (_dgae ,64);
|
|
|
|
if _gbg !=nil {_gg .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",_gbg );return nil ;};_bdfc .Width =_cbb ;
|
|
|
|
};if _bfcc ,_gfec :=_egg ["\u0068\u0065\u0069\u0067\u0068\u0074"];_gfec {_feg ,_geg :=_dgf (_bfcc ,64);if _geg !=nil {_gg .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",_geg );
|
|
|
|
return nil ;};_bdfc .Height =_feg ;};if _bdfc .Width > 0&&_bdfc .Height > 0{_bdfc ._da =_bdfc .Width /_bdfc .ViewBox .W ;};};return _bdfc ;};func _add ()*GraphicSVGStyle {return &GraphicSVGStyle {FillColor :"\u00230\u0030\u0030\u0030\u0030\u0030",StrokeColor :"",StrokeWidth :0};
|
|
|
|
};func (_gge *GraphicSVG )setDefaultScaling (_ba float64 ){_gge ._da =_ba ;if _gge .Style !=nil &&_gge .Style .StrokeWidth > 0{_gge .Style .StrokeWidth =_gge .Style .StrokeWidth *_gge ._da ;};for _ ,_ffdb :=range _gge .Children {_ffdb .setDefaultScaling (_ba );
|
|
|
|
};};func (_egaa *GraphicSVG )toContentStream (_ceee *_fc .ContentCreator ){_gca ,_gfc :=_def (_egaa .Attributes ,_egaa ._da );if _gfc !=nil {_gg .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",_gfc );
|
|
|
|
};_egaa .Style =_gca ;switch _egaa .Name {case "\u0070\u0061\u0074\u0068":_de (_egaa ,_ceee );for _ ,_dba :=range _egaa .Children {_dba .toContentStream (_ceee );};case "\u0072\u0065\u0063\u0074":_cfg (_egaa ,_ceee );for _ ,_eefa :=range _egaa .Children {_eefa .toContentStream (_ceee );
|
|
|
|
};case "\u0063\u0069\u0072\u0063\u006c\u0065":_aage (_egaa ,_ceee );for _ ,_bg :=range _egaa .Children {_bg .toContentStream (_ceee );};case "\u0065l\u006c\u0069\u0070\u0073\u0065":_ge (_egaa ,_ceee );for _ ,_bfc :=range _egaa .Children {_bfc .toContentStream (_ceee );
|
|
|
|
};case "\u0070\u006f\u006c\u0079\u006c\u0069\u006e\u0065":_dfcc (_egaa ,_ceee );for _ ,_ggcc :=range _egaa .Children {_ggcc .toContentStream (_ceee );};case "\u0070o\u006c\u0079\u0067\u006f\u006e":_ega (_egaa ,_ceee );for _ ,_egf :=range _egaa .Children {_egf .toContentStream (_ceee );
|
|
|
|
};case "\u006c\u0069\u006e\u0065":_ggf (_egaa ,_ceee );for _ ,_adf :=range _egaa .Children {_adf .toContentStream (_ceee );};case "\u0067":_eaf ,_cce :=_egaa .Attributes ["\u0066\u0069\u006c\u006c"];_dda ,_cdg :=_egaa .Attributes ["\u0073\u0074\u0072\u006f\u006b\u0065"];
|
|
|
|
_aga ,_dbc :=_egaa .Attributes ["\u0073\u0074\u0072o\u006b\u0065\u002d\u0077\u0069\u0064\u0074\u0068"];for _ ,_fcc :=range _egaa .Children {if _ ,_gec :=_fcc .Attributes ["\u0066\u0069\u006c\u006c"];!_gec &&_cce {_fcc .Attributes ["\u0066\u0069\u006c\u006c"]=_eaf ;
|
|
|
|
};if _ ,_feca :=_fcc .Attributes ["\u0073\u0074\u0072\u006f\u006b\u0065"];!_feca &&_cdg {_fcc .Attributes ["\u0073\u0074\u0072\u006f\u006b\u0065"]=_dda ;};if _ ,_bfa :=_fcc .Attributes ["\u0073\u0074\u0072o\u006b\u0065\u002d\u0077\u0069\u0064\u0074\u0068"];
|
|
|
|
!_bfa &&_dbc {_fcc .Attributes ["\u0073\u0074\u0072o\u006b\u0065\u002d\u0077\u0069\u0064\u0074\u0068"]=_aga ;};_fcc .toContentStream (_ceee );};};};func _dgf (_acae string ,_cbgf int )(float64 ,error ){_cgd ,_ede :=_dcdd (_acae );_dgcde ,_ggec :=_f .ParseFloat (_cgd ,_cbgf );
|
|
|
|
if _ggec !=nil {return 0,_ggec ;};if _dgab ,_dadb :=_d [_ede ];_dadb {_dgcde =_dgcde *_dgab ;}else {_dgcde =_dgcde *_gbc ;};return _dgcde ,nil ;};func _egd (_eafg []*Command )*Path {_gcff :=&Path {};var _cfcg []*Command ;for _gffg ,_abf :=range _eafg {switch _c .ToLower (_abf .Symbol ){case _bgc ._bdg :if len (_cfcg )> 0{_gcff .Subpaths =append (_gcff .Subpaths ,&Subpath {_cfcg });
|
|
|
|
};_cfcg =[]*Command {_abf };case _bgc ._ecg :_cfcg =append (_cfcg ,_abf );_gcff .Subpaths =append (_gcff .Subpaths ,&Subpath {_cfcg });_cfcg =[]*Command {};default:_cfcg =append (_cfcg ,_abf );if len (_eafg )==_gffg +1{_gcff .Subpaths =append (_gcff .Subpaths ,&Subpath {_cfcg });
|
|
|
|
};};};return _gcff ;};func (_edbb *Subpath )compare (_ebf *Subpath )bool {if len (_edbb .Commands )!=len (_ebf .Commands ){return false ;};for _fgc ,_fdd :=range _edbb .Commands {if !_fdd .compare (_ebf .Commands [_fgc ]){return false ;};};return true ;
|
|
|
|
};func (_ggb *Command )isAbsolute ()bool {return _ggb .Symbol ==_c .ToUpper (_ggb .Symbol )};func _de (_ffg *GraphicSVG ,_a *_fc .ContentCreator ){_a .Add_q ();_ffg .Style .toContentStream (_a );_gga ,_bd :=_aab (_ffg .Attributes ["\u0064"]);if _bd !=nil {_gg .Log .Error ("\u0045R\u0052\u004f\u0052\u003a\u0020\u0025s",_bd .Error ());
|
|
|
|
};var (_ec ,_eg =0.0,0.0;_fcd ,_gcd =0.0,0.0;_dc *Command ;);for _ ,_dee :=range _gga .Subpaths {for _ ,_ecb :=range _dee .Commands {switch _c .ToLower (_ecb .Symbol ){case "\u006d":_fcd ,_gcd =_ecb .Params [0]*_ffg ._da ,_ecb .Params [1]*_ffg ._da ;if !_ecb .isAbsolute (){_fcd ,_gcd =_ec +_fcd -_ffg .ViewBox .X ,_eg +_gcd -_ffg .ViewBox .Y ;
|
|
|
|
};_a .Add_m (_bgag (_fcd ,3),_bgag (_gcd ,3));_ec ,_eg =_fcd ,_gcd ;case "\u0063":_gf ,_db ,_cd ,_aa ,_bb ,_fcb :=_ecb .Params [0]*_ffg ._da ,_ecb .Params [1]*_ffg ._da ,_ecb .Params [2]*_ffg ._da ,_ecb .Params [3]*_ffg ._da ,_ecb .Params [4]*_ffg ._da ,_ecb .Params [5]*_ffg ._da ;
|
|
|
|
if !_ecb .isAbsolute (){_gf ,_db ,_cd ,_aa ,_bb ,_fcb =_ec +_gf ,_eg +_db ,_ec +_cd ,_eg +_aa ,_ec +_bb ,_eg +_fcb ;};_a .Add_c (_bgag (_gf ,3),_bgag (_db ,3),_bgag (_cd ,3),_bgag (_aa ,3),_bgag (_bb ,3),_bgag (_fcb ,3));_ec ,_eg =_bb ,_fcb ;case "\u0073":_ffa ,_cf ,_ggg ,_df :=_ecb .Params [0]*_ffg ._da ,_ecb .Params [1]*_ffg ._da ,_ecb .Params [2]*_ffg ._da ,_ecb .Params [3]*_ffg ._da ;
|
|
|
|
if !_ecb .isAbsolute (){_ffa ,_cf ,_ggg ,_df =_ec +_ffa ,_eg +_cf ,_ec +_ggg ,_eg +_df ;};_a .Add_c (_bgag (_ec ,3),_bgag (_eg ,3),_bgag (_ffa ,3),_bgag (_cf ,3),_bgag (_ggg ,3),_bgag (_df ,3));_ec ,_eg =_ggg ,_df ;case "\u006c":_af ,_gfd :=_ecb .Params [0]*_ffg ._da ,_ecb .Params [1]*_ffg ._da ;
|
|
|
|
if !_ecb .isAbsolute (){_af ,_gfd =_ec +_af ,_eg +_gfd ;};_a .Add_l (_bgag (_af ,3),_bgag (_gfd ,3));_ec ,_eg =_af ,_gfd ;case "\u0068":_ac :=_ecb .Params [0]*_ffg ._da ;if !_ecb .isAbsolute (){_ac =_ec +_ac ;};_a .Add_l (_bgag (_ac ,3),_bgag (_eg ,3));
|
|
|
|
_ec =_ac ;case "\u0076":_aag :=_ecb .Params [0]*_ffg ._da ;if !_ecb .isAbsolute (){_aag =_eg +_aag ;};_a .Add_l (_bgag (_ec ,3),_bgag (_aag ,3));_eg =_aag ;case "\u0071":_cg ,_ef ,_dce ,_ccg :=_ecb .Params [0]*_ffg ._da ,_ecb .Params [1]*_ffg ._da ,_ecb .Params [2]*_ffg ._da ,_ecb .Params [3]*_ffg ._da ;
|
|
|
|
if !_ecb .isAbsolute (){_cg ,_ef ,_dce ,_ccg =_ec +_cg ,_eg +_ef ,_ec +_dce ,_eg +_ccg ;};_fe ,_fca :=_ee .QuadraticToCubicBezier (_ec ,_eg ,_cg ,_ef ,_dce ,_ccg );_a .Add_c (_bgag (_fe .X ,3),_bgag (_fe .Y ,3),_bgag (_fca .X ,3),_bgag (_fca .Y ,3),_bgag (_dce ,3),_bgag (_ccg ,3));
|
|
|
|
_ec ,_eg =_dce ,_ccg ;case "\u0074":var _deef ,_ege _ee .Point ;_bdf ,_dbe :=_ecb .Params [0]*_ffg ._da ,_ecb .Params [1]*_ffg ._da ;if !_ecb .isAbsolute (){_bdf ,_dbe =_ec +_bdf ,_eg +_dbe ;};if _dc !=nil &&_c .ToLower (_dc .Symbol )=="\u0071"{_dfb :=_ee .Point {X :_dc .Params [0]*_ffg ._da ,Y :_dc .Params [1]*_ffg ._da };
|
|
|
|
_ca :=_ee .Point {X :_dc .Params [2]*_ffg ._da ,Y :_dc .Params [3]*_ffg ._da };_dg :=_ca .Mul (2.0).Sub (_dfb );_deef ,_ege =_ee .QuadraticToCubicBezier (_ec ,_eg ,_dg .X ,_dg .Y ,_bdf ,_dbe );};_a .Add_c (_bgag (_deef .X ,3),_bgag (_deef .Y ,3),_bgag (_ege .X ,3),_bgag (_ege .Y ,3),_bgag (_bdf ,3),_bgag (_dbe ,3));
|
|
|
|
_ec ,_eg =_bdf ,_dbe ;case "\u0061":_fec ,_bdd :=_ecb .Params [0]*_ffg ._da ,_ecb .Params [1]*_ffg ._da ;_ae :=_ecb .Params [2];_dbb :=_ecb .Params [3]> 0;_aeg :=_ecb .Params [4]> 0;_ab ,_ce :=_ecb .Params [5]*_ffg ._da ,_ecb .Params [6]*_ffg ._da ;if !_ecb .isAbsolute (){_ab ,_ce =_ec +_ab ,_eg +_ce ;
|
|
|
|
};_ffd :=_ee .EllipseToCubicBeziers (_ec ,_eg ,_fec ,_bdd ,_ae ,_dbb ,_aeg ,_ab ,_ce );for _ ,_bddc :=range _ffd {_a .Add_c (_bgag (_bddc [1].X ,3),_bgag ((_bddc [1].Y ),3),_bgag ((_bddc [2].X ),3),_bgag ((_bddc [2].Y ),3),_bgag ((_bddc [3].X ),3),_bgag ((_bddc [3].Y ),3));
|
|
|
|
};_ec ,_eg =_ab ,_ce ;case "\u007a":_a .Add_h ();};_dc =_ecb ;};};if _ffg .Style .FillColor !=""&&_ffg .Style .StrokeColor !=""{_a .Add_B ();}else if _ffg .Style .FillColor !=""{_a .Add_f ();}else if _ffg .Style .StrokeColor !=""{_a .Add_S ();};_a .Add_h ();
|
|
|
|
_a .Add_Q ();};type commands struct{_deff []string ;_geb map[string ]int ;_bdg string ;_ecg string ;};func _efcf (_fgef string )(_ccd ,_acc ,_ddcc float64 ){if (len (_fgef )!=4&&len (_fgef )!=7)||_fgef [0]!='#'{_gg .Log .Debug ("I\u006ev\u0061\u006c\u0069\u0064\u0020\u0068\u0065\u0078 \u0063\u006f\u0064\u0065: \u0025\u0073",_fgef );
|
|
|
|
return _ccd ,_acc ,_ddcc ;};var _gaff ,_ffb ,_gcg int ;if len (_fgef )==4{var _efg ,_dfbda ,_cagg int ;_bef ,_afg :=_gb .Sscanf (_fgef ,"\u0023\u0025\u0031\u0078\u0025\u0031\u0078\u0025\u0031\u0078",&_efg ,&_dfbda ,&_cagg );if _afg !=nil {_gg .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",_fgef ,_afg );
|
|
|
|
return _ccd ,_acc ,_ddcc ;};if _bef !=3{_gg .Log .Debug ("I\u006ev\u0061\u006c\u0069\u0064\u0020\u0068\u0065\u0078 \u0063\u006f\u0064\u0065: \u0025\u0073",_fgef );return _ccd ,_acc ,_ddcc ;};_gaff =_efg *16+_efg ;_ffb =_dfbda *16+_dfbda ;_gcg =_cagg *16+_cagg ;
|
|
|
|
}else {_bgaa ,_addf :=_gb .Sscanf (_fgef ,"\u0023\u0025\u0032\u0078\u0025\u0032\u0078\u0025\u0032\u0078",&_gaff ,&_ffb ,&_gcg );if _addf !=nil {_gg .Log .Debug ("I\u006ev\u0061\u006c\u0069\u0064\u0020\u0068\u0065\u0078 \u0063\u006f\u0064\u0065: \u0025\u0073",_fgef );
|
|
|
|
return _ccd ,_acc ,_ddcc ;};if _bgaa !=3{_gg .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",_fgef ,_bgaa );
|
|
|
|
return _ccd ,_acc ,_ddcc ;};};_faea :=float64 (_gaff )/255.0;_dgea :=float64 (_ffb )/255.0;_bcac :=float64 (_gcg )/255.0;return _faea ,_dgea ,_bcac ;};func _dcdd (_bdec string )(_acg ,_fdgg string ){if _bdec ==""||(_bdec [len (_bdec )-1]>='0'&&_bdec [len (_bdec )-1]<='9'){return _bdec ,"";
|
|
|
|
};_acg =_bdec ;for _ ,_cbd :=range _gc {if _c .Contains (_acg ,_cbd ){_fdgg =_cbd ;};_acg =_c .TrimSuffix (_acg ,_cbd );};return ;};func (_degg *GraphicSVGStyle )toContentStream (_bcfe *_fc .ContentCreator ){if _degg ==nil {return ;};if _degg .FillColor !=""{var _eag ,_dec ,_fcaf float64 ;
|
|
|
|
if _eca ,_bae :=_ee .ColorMap [_degg .FillColor ];_bae {_cea ,_bfe ,_bge ,_ :=_eca .RGBA ();_eag ,_dec ,_fcaf =float64 (_cea ),float64 (_bfe ),float64 (_bge );}else {_eag ,_dec ,_fcaf =_efcf (_degg .FillColor );};_bcfe .Add_rg (_eag ,_dec ,_fcaf );};if _degg .StrokeColor !=""{var _afa ,_fae ,_fag float64 ;
|
|
|
|
if _fded ,_cdc :=_ee .ColorMap [_degg .StrokeColor ];_cdc {_gaa ,_ggfe ,_bcb ,_ :=_fded .RGBA ();_afa ,_fae ,_fag =float64 (_gaa )/255.0,float64 (_ggfe )/255.0,float64 (_bcb )/255.0;}else {_afa ,_fae ,_fag =_efcf (_degg .StrokeColor );};_bcfe .Add_RG (_afa ,_fae ,_fag );
|
|
|
|
};if _degg .StrokeWidth > 0{_bcfe .Add_w (_degg .StrokeWidth );};};func _ecba (_ddb []float64 )[]float64 {for _dff ,_gdd :=0,len (_ddb )-1;_dff < _gdd ;_dff ,_gdd =_dff +1,_gdd -1{_ddb [_dff ],_ddb [_gdd ]=_ddb [_gdd ],_ddb [_dff ];};return _ddb ;};func _ggf (_ag *GraphicSVG ,_cee *_fc .ContentCreator ){_cee .Add_q ();
|
|
|
|
_ag .Style .toContentStream (_cee );_bcc ,_fgd :=_dgf (_ag .Attributes ["\u0078\u0031"],64);if _fgd !=nil {_gg .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",_fgd .Error ());
|
|
|
|
};_ccgg ,_fgd :=_dgf (_ag .Attributes ["\u0079\u0031"],64);if _fgd !=nil {_gg .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",_fgd .Error ());
|
|
|
|
};_ecd ,_fgd :=_dgf (_ag .Attributes ["\u0078\u0032"],64);if _fgd !=nil {_gg .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",_fgd .Error ());
|
|
|
|
};_dgc ,_fgd :=_dgf (_ag .Attributes ["\u0079\u0032"],64);if _fgd !=nil {_gg .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",_fgd .Error ());
|
|
|
|
};_cee .Add_m (_bcc *_ag ._da ,_ccgg *_ag ._da );_cee .Add_l (_ecd *_ag ._da ,_dgc *_ag ._da );if _ag .Style .FillColor !=""&&_ag .Style .StrokeColor !=""{_cee .Add_B ();}else if _ag .Style .FillColor !=""{_cee .Add_f ();}else if _ag .Style .StrokeColor !=""{_cee .Add_S ();
|
|
|
|
};_cee .Add_h ();_cee .Add_Q ();};func _dgca (_bgbd string )(_abfb []float64 ,_aaff error ){var _ccbg float64 ;_dgcd :=0;_gcfa :=true ;for _adde ,_abd :=range _bgbd {if _abd =='.'{if _gcfa {_gcfa =false ;continue ;};_ccbg ,_aaff =_dgf (_bgbd [_dgcd :_adde ],64);
|
|
|
|
if _aaff !=nil {return ;};_abfb =append (_abfb ,_ccbg );_dgcd =_adde ;};};_ccbg ,_aaff =_dgf (_bgbd [_dgcd :],64);if _aaff !=nil {return ;};_abfb =append (_abfb ,_ccbg );return ;};var _bgc commands ;type Subpath struct{Commands []*Command ;};func ParseFromString (svgStr string )(*GraphicSVG ,error ){return ParseFromStream (_c .NewReader (svgStr ));
|
|
|
|
};func _cgg (_gfag *_fd .Decoder )(*GraphicSVG ,error ){for {_ggaf ,_cfde :=_gfag .Token ();if _ggaf ==nil &&_cfde ==_fa .EOF {break ;};if _cfde !=nil {return nil ,_cfde ;};switch _ace :=_ggaf .(type ){case _fd .StartElement :return _eeb (_ace ),nil ;};
|
|
|
|
};return &GraphicSVG {},nil ;};func ParseFromStream (source _fa .Reader )(*GraphicSVG ,error ){_dbca :=_fd .NewDecoder (source );_dbca .CharsetReader =_eb .NewReaderLabel ;_dece ,_gfg :=_cgg (_dbca );if _gfg !=nil {return nil ,_gfg ;};if _bfb :=_dece .Decode (_dbca );
|
|
|
|
_bfb !=nil &&_bfb !=_fa .EOF {return nil ,_bfb ;};return _dece ,nil ;};type token struct{_agg string ;_dfg bool ;};func _bdc (_cgae []token )([]*Command ,error ){var (_gcab []*Command ;_gffc []float64 ;);for _fea :=len (_cgae )-1;_fea >=0;_fea --{_dad :=_cgae [_fea ];
|
|
|
|
if _dad ._dfg {_fafg :=_bgc ._geb [_c .ToLower (_dad ._agg )];_eefg :=len (_gffc );if _fafg ==0&&_eefg ==0{_cdd :=&Command {Symbol :_dad ._agg };_gcab =append ([]*Command {_cdd },_gcab ...);}else if _fafg !=0&&_eefg %_fafg ==0{_fee :=_eefg /_fafg ;for _cca :=0;
|
|
|
|
_cca < _fee ;_cca ++{_bca :=_dad ._agg ;if _bca =="\u006d"&&_cca < _fee -1{_bca ="\u006c";};if _bca =="\u004d"&&_cca < _fee -1{_bca ="\u004c";};_gebb :=&Command {_bca ,_ecba (_gffc [:_fafg ])};_gcab =append ([]*Command {_gebb },_gcab ...);_gffc =_gffc [_fafg :];
|
|
|
|
};}else {_gcde :=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"+_dad ._agg };return nil ,_gcde ;
|
|
|
|
};}else {_agdc ,_edcc :=_dgf (_dad ._agg ,64);if _edcc !=nil {return nil ,_edcc ;};_gffc =append (_gffc ,_agdc );};};return _gcab ,nil ;};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 ;_da float64 ;};type GraphicSVGStyle struct{FillColor string ;StrokeColor string ;StrokeWidth float64 ;};func _dfcc (_bc *GraphicSVG ,_aeb *_fc .ContentCreator ){_aeb .Add_q ();_bc .Style .toContentStream (_aeb );
|
|
|
|
_dfd ,_cde :=_efb (_bc .Attributes ["\u0070\u006f\u0069\u006e\u0074\u0073"]);if _cde !=nil {_gg .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",_cde );
|
|
|
|
return ;};if len (_dfd )%2> 0{_gg .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 _cga :=0;_cga < len (_dfd );{if _cga ==0{_aeb .Add_m (_dfd [_cga ]*_bc ._da ,_dfd [_cga +1]*_bc ._da );}else {_aeb .Add_l (_dfd [_cga ]*_bc ._da ,_dfd [_cga +1]*_bc ._da );};_cga +=2;};if _bc .Style .FillColor !=""&&_bc .Style .StrokeColor !=""{_aeb .Add_B ();
|
|
|
|
}else if _bc .Style .FillColor !=""{_aeb .Add_f ();}else if _bc .Style .StrokeColor !=""{_aeb .Add_S ();};_aeb .Add_h ();_aeb .Add_Q ();};func _efb (_cgb string )([]float64 ,error ){_eaec :=-1;var _dbee []float64 ;_acbg :=' ';for _afb ,_eafc :=range _cgb {if !_e .IsNumber (_eafc )&&_eafc !='.'&&!(_eafc =='-'&&_acbg =='e')&&_eafc !='e'{if _eaec !=-1{_ddd ,_gdg :=_dgca (_cgb [_eaec :_afb ]);
|
|
|
|
if _gdg !=nil {return _dbee ,_gdg ;};_dbee =append (_dbee ,_ddd ...);};if _eafc =='-'{_eaec =_afb ;}else {_eaec =-1;};}else if _eaec ==-1{_eaec =_afb ;};_acbg =_eafc ;};if _eaec !=-1&&_eaec !=len (_cgb ){_bgab ,_feggf :=_dgca (_cgb [_eaec :]);if _feggf !=nil {return _dbee ,_feggf ;
|
|
|
|
};_dbee =append (_dbee ,_bgab ...);};return _dbee ,nil ;};type pathParserError struct{_bddcb string };
|