2020-11-23 22:15:56 +00:00
|
|
|
package context ;import (_a "errors";_b "github.com/golang/freetype/truetype";_ae "github.com/unidoc/unipdf/v3/core";_cf "github.com/unidoc/unipdf/v3/internal/textencoding";_g "github.com/unidoc/unipdf/v3/internal/transform";_d "github.com/unidoc/unipdf/v3/model";_ef "golang.org/x/image/font";_ab "image";_c "image/color";);type Context interface{Push ();Pop ();Matrix ()_g .Matrix ;SetMatrix (_dd _g .Matrix );Translate (_ag ,_be float64 );Scale (_dc ,_fe float64 );Rotate (_bee float64 );MoveTo (_bc ,_ed float64 );LineTo (_ac ,_cd float64 );CubicTo (_dcd ,_ca ,_gf ,_ff ,_fd ,_ged float64 );QuadraticTo (_df ,_ad ,_eg ,_gg float64 );NewSubPath ();ClosePath ();ClearPath ();Clip ();ClipPreserve ();ResetClip ();LineWidth ()float64 ;SetLineWidth (_bd float64 );SetLineCap (_aga LineCap );SetLineJoin (_age LineJoin );SetDash (_dfa ...float64 );SetDashOffset (_bb float64 );Fill ();FillPreserve ();Stroke ();StrokePreserve ();SetRGBA (_cdd ,_fc ,_bdg ,_af float64 );SetFillRGBA (_bbf ,_ga ,_bbd ,_ffd float64 );SetFillStyle (_cdb Pattern );SetFillRule (_ce FillRule );SetStrokeRGBA (_afa ,_ddf ,_adg ,_abe float64 );SetStrokeStyle (_bg Pattern );TextState ()*TextState ;DrawString (_ace string ,_deb ,_bbdd float64 );MeasureString (_ec string )(_bef ,_cfe float64 );DrawRectangle (_cc ,_fda ,_bf ,_ede float64 );DrawImage (_da _ab .Image ,_cef ,_eb int );DrawImageAnchored (_dcda _ab .Image ,_fb ,_caa int ,_eca ,_bfb float64 );Height ()int ;Width ()int ;};type TextFont struct{Font *_d .PdfFont ;Face _ef .Face ;Size float64 ;_ea *_b .Font ;_cfef *_d .PdfFont ;};func (_aee *TextFont )WithSize (size float64 ,originalFont *_d .PdfFont )*TextFont {if size <=1{size =10;};return &TextFont {Font :_aee .Font ,Face :_b .NewFace (_aee ._ea ,&_b .Options {Size :size }),Size :size ,_ea :_aee ._ea ,_cfef :originalFont };};func (_ade *TextState )ProcDQ (data []byte ,aw ,ac float64 ,ctx Context ){_ade .Tw =aw ;_ade .Tc =ac ;_ade .ProcQ (data ,ctx );};func (_gaa *TextState )Translate (tx ,ty float64 ){_gaa .Tm =_g .TranslationMatrix (tx ,ty ).Mult (_gaa .Tm );};type TextState struct{Tc float64 ;Tw float64 ;Th float64 ;Tl float64 ;Tf *TextFont ;Ts float64 ;Tm _g .Matrix ;Tlm _g .Matrix ;};func NewTextFontFromPath (filePath string ,size float64 )(*TextFont ,error ){_dfe ,_cb :=_d .NewPdfFontFromTTFFile (filePath );if _cb !=nil {return nil ,_cb ;};return NewTextFont (_dfe ,size );};func NewTextState ()*TextState {return &TextState {Th :100,Tm :_g .IdentityMatrix (),Tlm :_g .IdentityMatrix ()};};type LineJoin int ;func (_bca *TextState )ProcTd (tx ,ty float64 ){_bca .Tlm .Concat (_g .TranslationMatrix (tx ,-ty ));_bca .Tm =_bca .Tlm .Clone ();};func (_fbd *TextFont )GetRuneMetrics (r rune )(float64 ,float64 ,bool ){if _cbd ,_cgd :=_fbd .Font .GetRuneMetrics (r );_cgd &&_cbd .Wx !=0{return _cbd .Wx ,_cbd .Wy ,_cgd ;};if _fbd ._cfef ==nil {return 0,0,false ;};_abg ,_aea :=_fbd ._cfef .GetRuneMetrics (r );return _abg .Wx ,_abg .Wy ,_aea &&_abg .Wx !=0;};const (LineCapRound LineCap =iota ;LineCapButt ;LineCapSquare ;);func (_bfg *TextFont )BytesToCharcodes (data []byte )[]_cf .CharCode {if _bfg ._cfef !=nil {return _bfg ._cfef .BytesToCharcodes (data );};return _bfg .Font .BytesToCharcodes (data );};type LineCap int ;func (_dfb *TextState )ProcQ (data []byte ,ctx Context ){_dfb .ProcTStar ();_dfb .ProcTj (data ,ctx )};func (_gd *TextFont )CharcodesToUnicode (charcodes []_cf .CharCode )[]rune {if _gd ._cfef !=nil {return _gd ._cfef .CharcodesToUnicode (charcodes );};return _gd .Font .CharcodesToUnicode (charcodes );};func (_dee *TextState )Reset (){_dee .Tm =_g .IdentityMatrix ();_dee .Tlm =_g .IdentityMatrix ()};func (_caae *TextState )ProcTStar (){_caae .ProcTd (0,-_caae .Tl )};type FillRule int ;func (_bdb *TextState )ProcTm (a ,b ,c ,d ,e ,f float64 ){_bdb .Tm =_g .NewMatrix (a ,b ,c ,d ,e ,-f );_bdb .Tlm =_bdb .Tm .Clone ();};func (_ffb *TextState )ProcTj (data []byte ,ctx Context ){_ceb :=_ffb .Tf .Size ;_cad :=_ffb .Th /100.0;_fdb :=_g .NewMatrix (_ceb *_cad ,0,0,_ceb ,0,_ffb .Ts );_ba :=_ffb .Tf .CharcodesToUnicode (_ffb .Tf .BytesToCharcodes (data ));for _ ,
|