mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-04 22:17:22 +08:00
113 lines
30 KiB
Go
113 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 (_cf "encoding/xml";_df "fmt";_g "github.com/unidoc/unipdf/v3/common";_ag "github.com/unidoc/unipdf/v3/contentstream";_e "github.com/unidoc/unipdf/v3/contentstream/draw";_a "github.com/unidoc/unipdf/v3/internal/graphic2d";_bf "golang.org/x/net/html/charset";
|
|
_cg "io";_c "math";_fe "os";_d "strconv";_fa "strings";_b "unicode";);func _eb (_ageb *GraphicSVG ,_adf *_ag .ContentCreator ){_adf .Add_q ();_ageb .Style .toContentStream (_adf );_gdb ,_geac :=_ebcda (_ageb .Attributes ["\u0078"],64);if _geac !=nil {_g .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",_geac .Error ());
|
|
};_ff ,_geac :=_ebcda (_ageb .Attributes ["\u0079"],64);if _geac !=nil {_g .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",_geac .Error ());
|
|
};_cea ,_geac :=_ebcda (_ageb .Attributes ["\u0077\u0069\u0064t\u0068"],64);if _geac !=nil {_g .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",_geac .Error ());
|
|
};_gce ,_geac :=_ebcda (_ageb .Attributes ["\u0068\u0065\u0069\u0067\u0068\u0074"],64);if _geac !=nil {_g .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",_geac .Error ());
|
|
};_adf .Add_re (_gdb *_ageb ._cce ,_ff *_ageb ._cce ,_cea *_ageb ._cce ,_gce *_ageb ._cce );if _ageb .Style .FillColor !=""&&_ageb .Style .StrokeColor !=""{_adf .Add_B ();}else if _ageb .Style .FillColor !=""{_adf .Add_f ();}else if _ageb .Style .StrokeColor !=""{_adf .Add_S ();
|
|
};_adf .Add_Q ();};func _dfb (_bba string )(_cae ,_fabb ,_gfbg float64 ){if (len (_bba )!=4&&len (_bba )!=7)||_bba [0]!='#'{_g .Log .Debug ("I\u006ev\u0061\u006c\u0069\u0064\u0020\u0068\u0065\u0078 \u0063\u006f\u0064\u0065: \u0025\u0073",_bba );return _cae ,_fabb ,_gfbg ;
|
|
};var _eage ,_egag ,_fgae int ;if len (_bba )==4{var _ecd ,_egcg ,_edef int ;_gafc ,_cfba :=_df .Sscanf (_bba ,"\u0023\u0025\u0031\u0078\u0025\u0031\u0078\u0025\u0031\u0078",&_ecd ,&_egcg ,&_edef );if _cfba !=nil {_g .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",_bba ,_cfba );
|
|
return _cae ,_fabb ,_gfbg ;};if _gafc !=3{_g .Log .Debug ("I\u006ev\u0061\u006c\u0069\u0064\u0020\u0068\u0065\u0078 \u0063\u006f\u0064\u0065: \u0025\u0073",_bba );return _cae ,_fabb ,_gfbg ;};_eage =_ecd *16+_ecd ;_egag =_egcg *16+_egcg ;_fgae =_edef *16+_edef ;
|
|
}else {_ebb ,_acc :=_df .Sscanf (_bba ,"\u0023\u0025\u0032\u0078\u0025\u0032\u0078\u0025\u0032\u0078",&_eage ,&_egag ,&_fgae );if _acc !=nil {_g .Log .Debug ("I\u006ev\u0061\u006c\u0069\u0064\u0020\u0068\u0065\u0078 \u0063\u006f\u0064\u0065: \u0025\u0073",_bba );
|
|
return _cae ,_fabb ,_gfbg ;};if _ebb !=3{_g .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",_bba ,_ebb );
|
|
return _cae ,_fabb ,_gfbg ;};};_cfbe :=float64 (_eage )/255.0;_bgge :=float64 (_egag )/255.0;_fce :=float64 (_fgae )/255.0;return _cfbe ,_bgge ,_fce ;};func (_aca *commands )isCommand (_befc string )bool {for _ ,_fagf :=range _aca ._eef {if _fa .ToLower (_befc )==_fagf {return true ;
|
|
};};return false ;};type Command struct{Symbol string ;Params []float64 ;};type Subpath struct{Commands []*Command ;};func _dbfa (_fff string )[]token {var (_fdgc []token ;_gcfc string ;);for _ ,_bbf :=range _fff {_gad :=string (_bbf );switch {case _dcc .isCommand (_gad ):_fdgc ,_gcfc =_ebe (_fdgc ,_gcfc );
|
|
_fdgc =append (_fdgc ,token {_gad ,true });case _gad =="\u002e":if _gcfc ==""{_gcfc ="\u0030";};if _fa .Contains (_gcfc ,_gad ){_fdgc =append (_fdgc ,token {_gcfc ,false });_gcfc ="\u0030";};fallthrough;case _gad >="\u0030"&&_gad <="\u0039"||_gad =="\u0065":_gcfc +=_gad ;
|
|
case _gad =="\u002d":if _fa .HasSuffix (_gcfc ,"\u0065"){_gcfc +=_gad ;}else {_fdgc ,_ =_ebe (_fdgc ,_gcfc );_gcfc =_gad ;};default:_fdgc ,_gcfc =_ebe (_fdgc ,_gcfc );};};_fdgc ,_ =_ebe (_fdgc ,_gcfc );return _fdgc ;};type GraphicSVGStyle struct{FillColor string ;
|
|
StrokeColor string ;StrokeWidth float64 ;};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 ;_cce float64 ;
|
|
};func _ebe (_cedb []token ,_cga string )([]token ,string ){if _cga !=""{_cedb =append (_cedb ,token {_cga ,false });_cga ="";};return _cedb ,_cga ;};func _ac (_ba *GraphicSVG ,_bae *_ag .ContentCreator ){_bae .Add_q ();_ba .Style .toContentStream (_bae );
|
|
_aeb ,_cfg :=_ebcda (_ba .Attributes ["\u0063\u0078"],64);if _cfg !=nil {_g .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",_cfg .Error ());
|
|
};_bgf ,_cfg :=_ebcda (_ba .Attributes ["\u0063\u0079"],64);if _cfg !=nil {_g .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",_cfg .Error ());
|
|
};_ea ,_cfg :=_ebcda (_ba .Attributes ["\u0072"],64);if _cfg !=nil {_g .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",_cfg .Error ());
|
|
};_add :=_ea *_ba ._cce ;_ace :=_ea *_ba ._cce ;_dge :=_add *_bfc ;_fad :=_ace *_bfc ;_ffd :=_e .NewCubicBezierPath ();_ffd =_ffd .AppendCurve (_e .NewCubicBezierCurve (-_add ,0,-_add ,_fad ,-_dge ,_ace ,0,_ace ));_ffd =_ffd .AppendCurve (_e .NewCubicBezierCurve (0,_ace ,_dge ,_ace ,_add ,_fad ,_add ,0));
|
|
_ffd =_ffd .AppendCurve (_e .NewCubicBezierCurve (_add ,0,_add ,-_fad ,_dge ,-_ace ,0,-_ace ));_ffd =_ffd .AppendCurve (_e .NewCubicBezierCurve (0,-_ace ,-_dge ,-_ace ,-_add ,-_fad ,-_add ,0));_ffd =_ffd .Offset (_aeb *_ba ._cce ,_bgf *_ba ._cce );if _ba .Style .StrokeWidth > 0{_ffd =_ffd .Offset (_ba .Style .StrokeWidth /2,_ba .Style .StrokeWidth /2);
|
|
};_e .DrawBezierPathWithCreator (_ffd ,_bae );if _ba .Style .FillColor !=""&&_ba .Style .StrokeColor !=""{_bae .Add_B ();}else if _ba .Style .FillColor !=""{_bae .Add_f ();}else if _ba .Style .StrokeColor !=""{_bae .Add_S ();};_bae .Add_h ();_bae .Add_Q ();
|
|
};type commands struct{_eef []string ;_bcc map[string ]int ;_aege string ;_ebae string ;};func _fga (_aebf *_cf .Decoder )(*GraphicSVG ,error ){for {_cge ,_cgbf :=_aebf .Token ();if _cge ==nil &&_cgbf ==_cg .EOF {break ;};if _cgbf !=nil {return nil ,_cgbf ;
|
|
};switch _beff :=_cge .(type ){case _cf .StartElement :return _edd (_beff ),nil ;};};return &GraphicSVG {},nil ;};func _gfbe (_aaaa string )(_gfcd []float64 ,_bafg error ){var _fedg float64 ;_cffb :=0;_fge :=true ;for _ggec ,_cgcf :=range _aaaa {if _cgcf =='.'{if _fge {_fge =false ;
|
|
continue ;};_fedg ,_bafg =_ebcda (_aaaa [_cffb :_ggec ],64);if _bafg !=nil {return ;};_gfcd =append (_gfcd ,_fedg );_cffb =_ggec ;};};_fedg ,_bafg =_ebcda (_aaaa [_cffb :],64);if _bafg !=nil {return ;};_gfcd =append (_gfcd ,_fedg );return ;};func _aaef (_bfcc string )(*Path ,error ){_dcc =_aea ();
|
|
_agg ,_fgag :=_bda (_dbfa (_bfcc ));if _fgag !=nil {return nil ,_fgag ;};return _abg (_agg ),nil ;};func (_fedb pathParserError )Error ()string {return _fedb ._acag };func _fdg (_fgb []float64 )[]float64 {for _gee ,_fbdg :=0,len (_fgb )-1;_gee < _fbdg ;
|
|
_gee ,_fbdg =_gee +1,_fbdg -1{_fgb [_gee ],_fgb [_fbdg ]=_fgb [_fbdg ],_fgb [_gee ];};return _fgb ;};func (_bgbd *Path )compare (_agca *Path )bool {if len (_bgbd .Subpaths )!=len (_agca .Subpaths ){return false ;};for _dbb ,_cffg :=range _bgbd .Subpaths {if !_cffg .compare (_agca .Subpaths [_dbb ]){return false ;
|
|
};};return true ;};func _bc (_bge *GraphicSVG ,_afb *_ag .ContentCreator ){_afb .Add_q ();_bge .Style .toContentStream (_afb );_egg ,_gag :=_ebcda (_bge .Attributes ["\u0063\u0078"],64);if _gag !=nil {_g .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",_gag .Error ());
|
|
};_fgg ,_gag :=_ebcda (_bge .Attributes ["\u0063\u0079"],64);if _gag !=nil {_g .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",_gag .Error ());
|
|
};_dc ,_gag :=_ebcda (_bge .Attributes ["\u0072\u0078"],64);if _gag !=nil {_g .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",_gag .Error ());
|
|
};_cdag ,_gag :=_ebcda (_bge .Attributes ["\u0072\u0079"],64);if _gag !=nil {_g .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",_gag .Error ());
|
|
};_eag :=_dc *_bge ._cce ;_bde :=_cdag *_bge ._cce ;_fec :=_egg *_bge ._cce ;_bgb :=_fgg *_bge ._cce ;_fba :=_eag *_bfc ;_cdb :=_bde *_bfc ;_ceg :=_e .NewCubicBezierPath ();_ceg =_ceg .AppendCurve (_e .NewCubicBezierCurve (-_eag ,0,-_eag ,_cdb ,-_fba ,_bde ,0,_bde ));
|
|
_ceg =_ceg .AppendCurve (_e .NewCubicBezierCurve (0,_bde ,_fba ,_bde ,_eag ,_cdb ,_eag ,0));_ceg =_ceg .AppendCurve (_e .NewCubicBezierCurve (_eag ,0,_eag ,-_cdb ,_fba ,-_bde ,0,-_bde ));_ceg =_ceg .AppendCurve (_e .NewCubicBezierCurve (0,-_bde ,-_fba ,-_bde ,-_eag ,-_cdb ,-_eag ,0));
|
|
_ceg =_ceg .Offset (_fec ,_bgb );if _bge .Style .StrokeWidth > 0{_ceg =_ceg .Offset (_bge .Style .StrokeWidth /2,_bge .Style .StrokeWidth /2);};_e .DrawBezierPathWithCreator (_ceg ,_afb );if _bge .Style .FillColor !=""&&_bge .Style .StrokeColor !=""{_afb .Add_B ();
|
|
}else if _bge .Style .FillColor !=""{_afb .Add_f ();}else if _bge .Style .StrokeColor !=""{_afb .Add_S ();};_afb .Add_h ();_afb .Add_Q ();};func _dgb ()*GraphicSVGStyle {return &GraphicSVGStyle {FillColor :"\u00230\u0030\u0030\u0030\u0030\u0030",StrokeColor :"",StrokeWidth :0};
|
|
};func _aea ()commands {var _aaa =map[string ]int {"\u006d":2,"\u007a":0,"\u006c":2,"\u0068":1,"\u0076":1,"\u0063":6,"\u0073":4,"\u0071":4,"\u0074":2,"\u0061":7};var _fbbc []string ;for _faa :=range _aaa {_fbbc =append (_fbbc ,_faa );};return commands {_fbbc ,_aaa ,"\u006d","\u007a"};
|
|
};func (_fab *GraphicSVG )setDefaultScaling (_dgc float64 ){_fab ._cce =_dgc ;if _fab .Style !=nil &&_fab .Style .StrokeWidth > 0{_fab .Style .StrokeWidth =_fab .Style .StrokeWidth *_fab ._cce ;};for _ ,_bab :=range _fab .Children {_bab .setDefaultScaling (_dgc );
|
|
};};type Path struct{Subpaths []*Subpath ;};func _edd (_bgc _cf .StartElement )*GraphicSVG {_ebcd :=&GraphicSVG {};_egc :=make (map[string ]string );for _ ,_fbac :=range _bgc .Attr {_egc [_fbac .Name .Local ]=_fbac .Value ;};_ebcd .Name =_bgc .Name .Local ;
|
|
_ebcd .Attributes =_egc ;_ebcd ._cce =1;if _ebcd .Name =="\u0073\u0076\u0067"{_gfb ,_cgb :=_afec (_egc ["\u0076i\u0065\u0077\u0042\u006f\u0078"]);if _cgb !=nil {_g .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",_cgb );
|
|
return nil ;};_ebcd .ViewBox .X =_gfb [0];_ebcd .ViewBox .Y =_gfb [1];_ebcd .ViewBox .W =_gfb [2];_ebcd .ViewBox .H =_gfb [3];_ebcd .Width =_ebcd .ViewBox .W ;_ebcd .Height =_ebcd .ViewBox .H ;if _fda ,_bcdg :=_egc ["\u0077\u0069\u0064t\u0068"];_bcdg {_ead ,_bac :=_ebcda (_fda ,64);
|
|
if _bac !=nil {_g .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",_bac );return nil ;};_ebcd .Width =_ead ;
|
|
};if _feg ,_agcg :=_egc ["\u0068\u0065\u0069\u0067\u0068\u0074"];_agcg {_ega ,_eee :=_ebcda (_feg ,64);if _eee !=nil {_g .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",_eee );
|
|
return nil ;};_ebcd .Height =_ega ;};if _ebcd .Width > 0&&_ebcd .Height > 0{_ebcd ._cce =_ebcd .Width /_ebcd .ViewBox .W ;};};return _ebcd ;};func (_fbg *Subpath )compare (_effa *Subpath )bool {if len (_fbg .Commands )!=len (_effa .Commands ){return false ;
|
|
};for _aae ,_eged :=range _fbg .Commands {if !_eged .compare (_effa .Commands [_aae ]){return false ;};};return true ;};func _abg (_gaca []*Command )*Path {_dbba :=&Path {};var _ecc []*Command ;for _fgd ,_aed :=range _gaca {switch _fa .ToLower (_aed .Symbol ){case _dcc ._aege :if len (_ecc )> 0{_dbba .Subpaths =append (_dbba .Subpaths ,&Subpath {_ecc });
|
|
};_ecc =[]*Command {_aed };case _dcc ._ebae :_ecc =append (_ecc ,_aed );_dbba .Subpaths =append (_dbba .Subpaths ,&Subpath {_ecc });_ecc =[]*Command {};default:_ecc =append (_ecc ,_aed );if len (_gaca )==_fgd +1{_dbba .Subpaths =append (_dbba .Subpaths ,&Subpath {_ecc });
|
|
};};};return _dbba ;};func _dcbd (_cdba string )(_afd ,_acff string ){if _cdba ==""||(_cdba [len (_cdba )-1]>='0'&&_cdba [len (_cdba )-1]<='9'){return _cdba ,"";};_afd =_cdba ;for _ ,_ddb :=range _ge {if _fa .Contains (_afd ,_ddb ){_acff =_ddb ;};_afd =_fa .TrimSuffix (_afd ,_ddb );
|
|
};return ;};func (_adfc *Command )compare (_fggb *Command )bool {if _adfc .Symbol !=_fggb .Symbol {return false ;};for _acb ,_ab :=range _adfc .Params {if _ab !=_fggb .Params [_acb ]{return false ;};};return true ;};func _bda (_bea []token )([]*Command ,error ){var (_fdf []*Command ;
|
|
_eae []float64 ;);for _ggf :=len (_bea )-1;_ggf >=0;_ggf --{_cfd :=_bea [_ggf ];if _cfd ._cfa {_bec :=_dcc ._bcc [_fa .ToLower (_cfd ._afg )];_bce :=len (_eae );if _bec ==0&&_bce ==0{_gdcd :=&Command {Symbol :_cfd ._afg };_fdf =append ([]*Command {_gdcd },_fdf ...);
|
|
}else if _bec !=0&&_bce %_bec ==0{_bege :=_bce /_bec ;for _aebd :=0;_aebd < _bege ;_aebd ++{_fbc :=_cfd ._afg ;if _fbc =="\u006d"&&_aebd < _bege -1{_fbc ="\u006c";};if _fbc =="\u004d"&&_aebd < _bege -1{_fbc ="\u004c";};_ffgf :=&Command {_fbc ,_fdg (_eae [:_bec ])};
|
|
_fdf =append ([]*Command {_ffgf },_fdf ...);_eae =_eae [_bec :];};}else {_dbbb :=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"+_cfd ._afg };
|
|
return nil ,_dbbb ;};}else {_cgc ,_efe :=_ebcda (_cfd ._afg ,64);if _efe !=nil {return nil ,_efe ;};_eae =append (_eae ,_cgc );};};return _fdf ,nil ;};func _cdc (_bad *GraphicSVG ,_feaa *_ag .ContentCreator ){_feaa .Add_q ();_bad .Style .toContentStream (_feaa );
|
|
_bef ,_bcf :=_ebcda (_bad .Attributes ["\u0078\u0031"],64);if _bcf !=nil {_g .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",_bcf .Error ());
|
|
};_de ,_bcf :=_ebcda (_bad .Attributes ["\u0079\u0031"],64);if _bcf !=nil {_g .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",_bcf .Error ());
|
|
};_da ,_bcf :=_ebcda (_bad .Attributes ["\u0078\u0032"],64);if _bcf !=nil {_g .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",_bcf .Error ());
|
|
};_daa ,_bcf :=_ebcda (_bad .Attributes ["\u0079\u0032"],64);if _bcf !=nil {_g .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",_bcf .Error ());
|
|
};_feaa .Add_m (_bef *_bad ._cce ,_de *_bad ._cce );_feaa .Add_l (_da *_bad ._cce ,_daa *_bad ._cce );if _bad .Style .FillColor !=""&&_bad .Style .StrokeColor !=""{_feaa .Add_B ();}else if _bad .Style .FillColor !=""{_feaa .Add_f ();}else if _bad .Style .StrokeColor !=""{_feaa .Add_S ();
|
|
};_feaa .Add_h ();_feaa .Add_Q ();};func _daad (_deb float64 ,_caf int )float64 {_ede :=_c .Pow (10,float64 (_caf ));return float64 (_eec (_deb *_ede ))/_ede ;};func ParseFromFile (path string )(*GraphicSVG ,error ){_cfe ,_baa :=_fe .Open (path );if _baa !=nil {return nil ,_baa ;
|
|
};defer _cfe .Close ();return ParseFromStream (_cfe );};func _gg (_egd *GraphicSVG ,_cc *_ag .ContentCreator ){_cc .Add_q ();_egd .Style .toContentStream (_cc );_eac ,_gda :=_afec (_egd .Attributes ["\u0070\u006f\u0069\u006e\u0074\u0073"]);if _gda !=nil {_g .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",_gda );
|
|
return ;};if len (_eac )%2> 0{_g .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 _cdd :=0;_cdd < len (_eac );{if _cdd ==0{_cc .Add_m (_eac [_cdd ]*_egd ._cce ,_eac [_cdd +1]*_egd ._cce );}else {_cc .Add_l (_eac [_cdd ]*_egd ._cce ,_eac [_cdd +1]*_egd ._cce );};_cdd +=2;};_cc .Add_l (_eac [0]*_egd ._cce ,_eac [1]*_egd ._cce );
|
|
if _egd .Style .FillColor !=""&&_egd .Style .StrokeColor !=""{_cc .Add_B ();}else if _egd .Style .FillColor !=""{_cc .Add_f ();}else if _egd .Style .StrokeColor !=""{_cc .Add_S ();};_cc .Add_h ();_cc .Add_Q ();};func (_ged *GraphicSVG )Decode (decoder *_cf .Decoder )error {for {_gge ,_adac :=decoder .Token ();
|
|
if _gge ==nil &&_adac ==_cg .EOF {break ;};if _adac !=nil {return _adac ;};switch _beg :=_gge .(type ){case _cf .StartElement :_gac :=_edd (_beg );_bdec :=_gac .Decode (decoder );if _bdec !=nil {return _bdec ;};_ged .Children =append (_ged .Children ,_gac );
|
|
case _cf .CharData :_gbd :=_fa .TrimSpace (string (_beg ));if _gbd !=""{_ged .Content =string (_beg );};case _cf .EndElement :if _beg .Name .Local ==_ged .Name {return nil ;};};};return nil ;};func (_ffg *Command )isAbsolute ()bool {return _ffg .Symbol ==_fa .ToUpper (_ffg .Symbol )};
|
|
type token struct{_afg string ;_cfa bool ;};func _ddf (_feca map[string ]string ,_feab float64 )(*GraphicSVGStyle ,error ){_fabc :=_dgb ();_ecb ,_gede :=_feca ["\u0066\u0069\u006c\u006c"];if _gede {_fabc .FillColor =_ecb ;if _ecb =="\u006e\u006f\u006e\u0065"{_fabc .FillColor ="";
|
|
};};_aag ,_ecf :=_feca ["\u0073\u0074\u0072\u006f\u006b\u0065"];if _ecf {_fabc .StrokeColor =_aag ;if _aag =="\u006e\u006f\u006e\u0065"{_fabc .StrokeColor ="";};};_acdd ,_dbf :=_feca ["\u0073\u0074\u0072o\u006b\u0065\u002d\u0077\u0069\u0064\u0074\u0068"];
|
|
if _dbf {_aeg ,_aac :=_ebcda (_acdd ,64);if _aac !=nil {return nil ,_aac ;};_fabc .StrokeWidth =_aeg *_feab ;};return _fabc ,nil ;};func (_begb *GraphicSVGStyle )toContentStream (_bcg *_ag .ContentCreator ){if _begb ==nil {return ;};if _begb .FillColor !=""{var _acg ,_fbb ,_ced float64 ;
|
|
if _bcfa ,_dgef :=_a .ColorMap [_begb .FillColor ];_dgef {_egdb ,_gcee ,_bcb ,_ :=_bcfa .RGBA ();_acg ,_fbb ,_ced =float64 (_egdb ),float64 (_gcee ),float64 (_bcb );}else {_acg ,_fbb ,_ced =_dfb (_begb .FillColor );};_bcg .Add_rg (_acg ,_fbb ,_ced );};
|
|
if _begb .StrokeColor !=""{var _cfb ,_dce ,_eadd float64 ;if _bb ,_fecg :=_a .ColorMap [_begb .StrokeColor ];_fecg {_bdfd ,_gbb ,_gcb ,_ :=_bb .RGBA ();_cfb ,_dce ,_eadd =float64 (_bdfd )/255.0,float64 (_gbb )/255.0,float64 (_gcb )/255.0;}else {_cfb ,_dce ,_eadd =_dfb (_begb .StrokeColor );
|
|
};_bcg .Add_RG (_cfb ,_dce ,_eadd );};if _begb .StrokeWidth > 0{_bcg .Add_w (_begb .StrokeWidth );};};func ParseFromString (svgStr string )(*GraphicSVG ,error ){return ParseFromStream (_fa .NewReader (svgStr ));};type pathParserError struct{_acag string };
|
|
func (_ddc *GraphicSVG )toContentStream (_fef *_ag .ContentCreator ){_ebc ,_acd :=_ddf (_ddc .Attributes ,_ddc ._cce );if _acd !=nil {_g .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",_acd );
|
|
};_ddc .Style =_ebc ;switch _ddc .Name {case "\u0070\u0061\u0074\u0068":_dd (_ddc ,_fef );for _ ,_baf :=range _ddc .Children {_baf .toContentStream (_fef );};case "\u0072\u0065\u0063\u0074":_eb (_ddc ,_fef );for _ ,_fcb :=range _ddc .Children {_fcb .toContentStream (_fef );
|
|
};case "\u0063\u0069\u0072\u0063\u006c\u0065":_ac (_ddc ,_fef );for _ ,_gef :=range _ddc .Children {_gef .toContentStream (_fef );};case "\u0065l\u006c\u0069\u0070\u0073\u0065":_bc (_ddc ,_fef );for _ ,_dbd :=range _ddc .Children {_dbd .toContentStream (_fef );
|
|
};case "\u0070\u006f\u006c\u0079\u006c\u0069\u006e\u0065":_gcfe (_ddc ,_fef );for _ ,_gfc :=range _ddc .Children {_gfc .toContentStream (_fef );};case "\u0070o\u006c\u0079\u0067\u006f\u006e":_gg (_ddc ,_fef );for _ ,_acf :=range _ddc .Children {_acf .toContentStream (_fef );
|
|
};case "\u006c\u0069\u006e\u0065":_cdc (_ddc ,_fef );for _ ,_dddd :=range _ddc .Children {_dddd .toContentStream (_fef );};case "\u0067":_ggc ,_cfgg :=_ddc .Attributes ["\u0066\u0069\u006c\u006c"];_ebg ,_bff :=_ddc .Attributes ["\u0073\u0074\u0072\u006f\u006b\u0065"];
|
|
_bdga ,_dcg :=_ddc .Attributes ["\u0073\u0074\u0072o\u006b\u0065\u002d\u0077\u0069\u0064\u0074\u0068"];for _ ,_dee :=range _ddc .Children {if _ ,_eba :=_dee .Attributes ["\u0066\u0069\u006c\u006c"];!_eba &&_cfgg {_dee .Attributes ["\u0066\u0069\u006c\u006c"]=_ggc ;
|
|
};if _ ,_efgc :=_dee .Attributes ["\u0073\u0074\u0072\u006f\u006b\u0065"];!_efgc &&_bff {_dee .Attributes ["\u0073\u0074\u0072\u006f\u006b\u0065"]=_ebg ;};if _ ,_acfd :=_dee .Attributes ["\u0073\u0074\u0072o\u006b\u0065\u002d\u0077\u0069\u0064\u0074\u0068"];
|
|
!_acfd &&_dcg {_dee .Attributes ["\u0073\u0074\u0072o\u006b\u0065\u002d\u0077\u0069\u0064\u0074\u0068"]=_bdga ;};_dee .toContentStream (_fef );};};};func (_ebd *GraphicSVG )SetScaling (xFactor ,yFactor float64 ){_efb :=_ebd .Width /_ebd .ViewBox .W ;_ebcg :=_ebd .Height /_ebd .ViewBox .H ;
|
|
_ebd .setDefaultScaling (_c .Max (_efb ,_ebcg ));for _ ,_febg :=range _ebd .Children {_febg .SetScaling (xFactor ,yFactor );};};var (_ge =[]string {"\u0063\u006d","\u006d\u006d","\u0070\u0078","\u0070\u0074"};_ce =map[string ]float64 {"\u0063\u006d":_ad ,"\u006d\u006d":_db ,"\u0070\u0078":_fea ,"\u0070\u0074":1};
|
|
);func _eec (_eade float64 )int {return int (_eade +_c .Copysign (0.5,_eade ))};func _dd (_ee *GraphicSVG ,_af *_ag .ContentCreator ){_af .Add_q ();_ee .Style .toContentStream (_af );_bd ,_fg :=_aaef (_ee .Attributes ["\u0064"]);if _fg !=nil {_g .Log .Error ("\u0045R\u0052\u004f\u0052\u003a\u0020\u0025s",_fg .Error ());
|
|
};var (_eg ,_ef =0.0,0.0;_ec ,_efg =0.0,0.0;_efc *Command ;);for _ ,_fb :=range _bd .Subpaths {for _ ,_ed :=range _fb .Commands {switch _fa .ToLower (_ed .Symbol ){case "\u006d":_ec ,_efg =_ed .Params [0]*_ee ._cce ,_ed .Params [1]*_ee ._cce ;if !_ed .isAbsolute (){_ec ,_efg =_eg +_ec -_ee .ViewBox .X ,_ef +_efg -_ee .ViewBox .Y ;
|
|
};_af .Add_m (_daad (_ec ,3),_daad (_efg ,3));_eg ,_ef =_ec ,_efg ;case "\u0063":_dg ,_fc ,_ae ,_bdg ,_ddg ,_aa :=_ed .Params [0]*_ee ._cce ,_ed .Params [1]*_ee ._cce ,_ed .Params [2]*_ee ._cce ,_ed .Params [3]*_ee ._cce ,_ed .Params [4]*_ee ._cce ,_ed .Params [5]*_ee ._cce ;
|
|
if !_ed .isAbsolute (){_dg ,_fc ,_ae ,_bdg ,_ddg ,_aa =_eg +_dg ,_ef +_fc ,_eg +_ae ,_ef +_bdg ,_eg +_ddg ,_ef +_aa ;};_af .Add_c (_daad (_dg ,3),_daad (_fc ,3),_daad (_ae ,3),_daad (_bdg ,3),_daad (_ddg ,3),_daad (_aa ,3));_eg ,_ef =_ddg ,_aa ;case "\u0073":_cd ,_cda ,_bg ,_cfc :=_ed .Params [0]*_ee ._cce ,_ed .Params [1]*_ee ._cce ,_ed .Params [2]*_ee ._cce ,_ed .Params [3]*_ee ._cce ;
|
|
if !_ed .isAbsolute (){_cd ,_cda ,_bg ,_cfc =_eg +_cd ,_ef +_cda ,_eg +_bg ,_ef +_cfc ;};_af .Add_c (_daad (_eg ,3),_daad (_ef ,3),_daad (_cd ,3),_daad (_cda ,3),_daad (_bg ,3),_daad (_cfc ,3));_eg ,_ef =_bg ,_cfc ;case "\u006c":_ga ,_gc :=_ed .Params [0]*_ee ._cce ,_ed .Params [1]*_ee ._cce ;
|
|
if !_ed .isAbsolute (){_ga ,_gc =_eg +_ga ,_ef +_gc ;};_af .Add_l (_daad (_ga ,3),_daad (_gc ,3));_eg ,_ef =_ga ,_gc ;case "\u0068":_afc :=_ed .Params [0]*_ee ._cce ;if !_ed .isAbsolute (){_afc =_eg +_afc ;};_af .Add_l (_daad (_afc ,3),_daad (_ef ,3));
|
|
_eg =_afc ;case "\u0076":_fd :=_ed .Params [0]*_ee ._cce ;if !_ed .isAbsolute (){_fd =_ef +_fd ;};_af .Add_l (_daad (_eg ,3),_daad (_fd ,3));_ef =_fd ;case "\u0071":_gf ,_agf ,_gd ,_bdf :=_ed .Params [0]*_ee ._cce ,_ed .Params [1]*_ee ._cce ,_ed .Params [2]*_ee ._cce ,_ed .Params [3]*_ee ._cce ;
|
|
if !_ed .isAbsolute (){_gf ,_agf ,_gd ,_bdf =_eg +_gf ,_ef +_agf ,_eg +_gd ,_ef +_bdf ;};_fbd ,_ca :=_a .QuadraticToCubicBezier (_eg ,_ef ,_gf ,_agf ,_gd ,_bdf );_af .Add_c (_daad (_fbd .X ,3),_daad (_fbd .Y ,3),_daad (_ca .X ,3),_daad (_ca .Y ,3),_daad (_gd ,3),_daad (_bdf ,3));
|
|
_eg ,_ef =_gd ,_bdf ;case "\u0074":var _dgd ,_gcf _a .Point ;_fae ,_ade :=_ed .Params [0]*_ee ._cce ,_ed .Params [1]*_ee ._cce ;if !_ed .isAbsolute (){_fae ,_ade =_eg +_fae ,_ef +_ade ;};if _efc !=nil &&_fa .ToLower (_efc .Symbol )=="\u0071"{_fag :=_a .Point {X :_efc .Params [0]*_ee ._cce ,Y :_efc .Params [1]*_ee ._cce };
|
|
_adc :=_a .Point {X :_efc .Params [2]*_ee ._cce ,Y :_efc .Params [3]*_ee ._cce };_afe :=_adc .Mul (2.0).Sub (_fag );_dgd ,_gcf =_a .QuadraticToCubicBezier (_eg ,_ef ,_afe .X ,_afe .Y ,_fae ,_ade );};_af .Add_c (_daad (_dgd .X ,3),_daad (_dgd .Y ,3),_daad (_gcf .X ,3),_daad (_gcf .Y ,3),_daad (_fae ,3),_daad (_ade ,3));
|
|
_eg ,_ef =_fae ,_ade ;case "\u0061":_gea ,_afa :=_ed .Params [0]*_ee ._cce ,_ed .Params [1]*_ee ._cce ;_ddd :=_ed .Params [2];_edf :=_ed .Params [3]> 0;_gdc :=_ed .Params [4]> 0;_gb ,_age :=_ed .Params [5]*_ee ._cce ,_ed .Params [6]*_ee ._cce ;if !_ed .isAbsolute (){_gb ,_age =_eg +_gb ,_ef +_age ;
|
|
};_adcb :=_a .EllipseToCubicBeziers (_eg ,_ef ,_gea ,_afa ,_ddd ,_edf ,_gdc ,_gb ,_age );for _ ,_gaf :=range _adcb {_af .Add_c (_daad (_gaf [1].X ,3),_daad ((_gaf [1].Y ),3),_daad ((_gaf [2].X ),3),_daad ((_gaf [2].Y ),3),_daad ((_gaf [3].X ),3),_daad ((_gaf [3].Y ),3));
|
|
};_eg ,_ef =_gb ,_age ;case "\u007a":_af .Add_h ();};_efc =_ed ;};};if _ee .Style .FillColor !=""&&_ee .Style .StrokeColor !=""{_af .Add_B ();}else if _ee .Style .FillColor !=""{_af .Add_f ();}else if _ee .Style .StrokeColor !=""{_af .Add_S ();};_af .Add_h ();
|
|
_af .Add_Q ();};func ParseFromStream (source _cg .Reader )(*GraphicSVG ,error ){_acea :=_cf .NewDecoder (source );_acea .CharsetReader =_bf .NewReaderLabel ;_cec ,_caa :=_fga (_acea );if _caa !=nil {return nil ,_caa ;};if _cff :=_cec .Decode (_acea );_cff !=nil &&_cff !=_cg .EOF {return nil ,_cff ;
|
|
};return _cec ,nil ;};var _dcc commands ;func _gcfe (_ada *GraphicSVG ,_dfg *_ag .ContentCreator ){_dfg .Add_q ();_ada .Style .toContentStream (_dfg );_ffdf ,_be :=_afec (_ada .Attributes ["\u0070\u006f\u0069\u006e\u0074\u0073"]);if _be !=nil {_g .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",_be );
|
|
return ;};if len (_ffdf )%2> 0{_g .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 _adae :=0;_adae < len (_ffdf );{if _adae ==0{_dfg .Add_m (_ffdf [_adae ]*_ada ._cce ,_ffdf [_adae +1]*_ada ._cce );}else {_dfg .Add_l (_ffdf [_adae ]*_ada ._cce ,_ffdf [_adae +1]*_ada ._cce );};_adae +=2;};if _ada .Style .FillColor !=""&&_ada .Style .StrokeColor !=""{_dfg .Add_B ();
|
|
}else if _ada .Style .FillColor !=""{_dfg .Add_f ();}else if _ada .Style .StrokeColor !=""{_dfg .Add_S ();};_dfg .Add_h ();_dfg .Add_Q ();};func _afec (_agfd string )([]float64 ,error ){_faad :=-1;var _ecbb []float64 ;_fgc :=' ';for _gadb ,_aad :=range _agfd {if !_b .IsNumber (_aad )&&_aad !='.'&&!(_aad =='-'&&_fgc =='e')&&_aad !='e'{if _faad !=-1{_gafb ,_egb :=_gfbe (_agfd [_faad :_gadb ]);
|
|
if _egb !=nil {return _ecbb ,_egb ;};_ecbb =append (_ecbb ,_gafb ...);};if _aad =='-'{_faad =_gadb ;}else {_faad =-1;};}else if _faad ==-1{_faad =_gadb ;};_fgc =_aad ;};if _faad !=-1&&_faad !=len (_agfd ){_dfe ,_ggg :=_gfbe (_agfd [_faad :]);if _ggg !=nil {return _ecbb ,_ggg ;
|
|
};_ecbb =append (_ecbb ,_dfe ...);};return _ecbb ,nil ;};func _ebcda (_bga string ,_dbdf int )(float64 ,error ){_dbbg ,_fcc :=_dcbd (_bga );_adaeg ,_aegg :=_d .ParseFloat (_dbbg ,_dbdf );if _aegg !=nil {return 0,_aegg ;};if _ccb ,_bgg :=_ce [_fcc ];_bgg {_adaeg =_adaeg *_ccb ;
|
|
}else {_adaeg =_adaeg *_fea ;};return _adaeg ,nil ;};const (_fea =0.72;_ad =28.3464;_db =_ad /10;_bfc =0.551784;);func (_agef *GraphicSVG )ToContentCreator (cc *_ag .ContentCreator ,scaleX ,scaleY ,translateX ,translateY float64 )*_ag .ContentCreator {if _agef .Name =="\u0073\u0076\u0067"{_agef .SetScaling (scaleX ,scaleY );
|
|
cc .Add_cm (1,0,0,1,translateX ,translateY );_agef .setDefaultScaling (_agef ._cce );cc .Add_q ();_gbc :=_c .Max (scaleX ,scaleY );cc .Add_re (_agef .ViewBox .X *_gbc ,_agef .ViewBox .Y *_gbc ,_agef .ViewBox .W *_gbc ,_agef .ViewBox .H *_gbc );cc .Add_W ();
|
|
cc .Add_n ();for _ ,_dgg :=range _agef .Children {_dgg .ViewBox =_agef .ViewBox ;_dgg .toContentStream (cc );};cc .Add_Q ();return cc ;};return nil ;}; |