2021-01-26 01:31:56 +00:00

12 lines
6.6 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 context ;import (_cc "errors";_gf "github.com/golang/freetype/truetype";_f "github.com/unidoc/unipdf/v3/core";_ccg "github.com/unidoc/unipdf/v3/internal/textencoding";_ca "github.com/unidoc/unipdf/v3/internal/transform";_ge "github.com/unidoc/unipdf/v3/model";_g "golang.org/x/image/font";_cb "image";_c "image/color";);func (_bdc *TextState )ProcTStar (){_bdc .ProcTd (0,-_bdc .Tl )};func (_ff *TextFont )GetRuneMetrics (r rune )(float64 ,float64 ,bool ){if _dfg ,_gff :=_ff .Font .GetRuneMetrics (r );_gff &&_dfg .Wx !=0{return _dfg .Wx ,_dfg .Wy ,_gff ;};if _ff ._gdg ==nil {return 0,0,false ;};_gbe ,_fc :=_ff ._gdg .GetRuneMetrics (r );return _gbe .Wx ,_gbe .Wy ,_fc &&_gbe .Wx !=0;};func (_ebe *TextFont )NewFace (size float64 )_g .Face {return _gf .NewFace (_ebe ._fef ,&_gf .Options {Size :size });};type Gradient interface{Pattern ;AddColorStop (_d float64 ,_dc _c .Color );};func NewTextFontFromPath (filePath string ,size float64 )(*TextFont ,error ){_egc ,_abe :=_ge .NewPdfFontFromTTFFile (filePath );if _abe !=nil {return nil ,_abe ;};return NewTextFont (_egc ,size );};func (_cca *TextFont )CharcodesToUnicode (charcodes []_ccg .CharCode )[]rune {if _cca ._gdg !=nil {return _cca ._gdg .CharcodesToUnicode (charcodes );};return _cca .Font .CharcodesToUnicode (charcodes );};func (_bacd *TextState )ProcQ (data []byte ,ctx Context ){_bacd .ProcTStar ();_bacd .ProcTj (data ,ctx )};const (LineJoinRound LineJoin =iota ;LineJoinBevel ;);func (_efbf *TextState )ProcDQ (data []byte ,aw ,ac float64 ,ctx Context ){_efbf .Tw =aw ;_efbf .Tc =ac ;_efbf .ProcQ (data ,ctx );};const (FillRuleWinding FillRule =iota ;FillRuleEvenOdd ;);type LineCap int ;func (_fcf *TextState )ProcTD (tx ,ty float64 ){_fcf .Tl =-ty ;_fcf .ProcTd (tx ,ty )};func (_egf *TextState )ProcTm (a ,b ,c ,d ,e ,f float64 ){_egf .Tm =_ca .NewMatrix (a ,b ,c ,d ,e ,-f );_egf .Tlm =_egf .Tm .Clone ();};const (LineCapRound LineCap =iota ;LineCapButt ;LineCapSquare ;);type TextState struct{Tc float64 ;Tw float64 ;Th float64 ;Tl float64 ;Tf *TextFont ;Ts float64 ;Tm _ca .Matrix ;Tlm _ca .Matrix ;};func (_dec *TextState )ProcTf (font *TextFont ){_dec .Tf =font };func (_egef *TextState )Translate (tx ,ty float64 ){_egef .Tm =_ca .TranslationMatrix (tx ,ty ).Mult (_egef .Tm );};func (_edd *TextState )ProcTd (tx ,ty float64 ){_edd .Tlm .Concat (_ca .TranslationMatrix (tx ,-ty ));_edd .Tm =_edd .Tlm .Clone ();};func NewTextFont (font *_ge .PdfFont ,size float64 )(*TextFont ,error ){_bba :=font .FontDescriptor ();if _bba ==nil {return nil ,_cc .New ("\u0063\u006fu\u006c\u0064\u0020\u006e\u006f\u0074\u0020\u0067\u0065\u0074\u0020\u0066\u006f\u006e\u0074\u0020\u0064\u0065\u0073\u0063\u0072\u0069pt\u006f\u0072");};_gc ,_ef :=_f .GetStream (_bba .FontFile2 );if !_ef {return nil ,_cc .New ("\u006di\u0073\u0073\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u0020f\u0069\u006c\u0065\u0020\u0073\u0074\u0072\u0065\u0061\u006d");};_gcg ,_bcf :=_f .DecodeStream (_gc );if _bcf !=nil {return nil ,_bcf ;};_deg ,_bcf :=_gf .Parse (_gcg );if _bcf !=nil {return nil ,_bcf ;};return &TextFont {Font :font ,Size :size ,_fef :_deg },nil ;};type LineJoin int ;func (_dfd *TextState )ProcTj (data []byte ,ctx Context ){_ccc :=_dfd .Tf .Size ;_af :=_dfd .Th /100.0;_gfg :=_ca .NewMatrix (_ccc *_af ,0,0,_ccc ,0,_dfd .Ts );_ccgg :=ctx .Matrix ();_fga :=_ccgg .Clone ().Mult (_dfd .Tm .Clone ().Mult (_gfg )).ScalingFactorY ();_aa :=_dfd .Tf .NewFace (_fga );_cag :=_dfd .Tf .CharcodesToUnicode (_dfd .Tf .BytesToCharcodes (data ));for _ ,_aca :=range _cag {if _aca =='\x00'{continue ;};_ede :=_dfd .Tm .Clone ();_dfd .Tm .Concat (_gfg );_fed ,_ebb :=_dfd .Tm .Transform (0,0);ctx .Scale (1,-1);ctx .DrawString (string (_aca ),_aa ,_fed ,_ebb );ctx .Scale (1,-1);_cde :=0.0;if _aca ==' '{_cde =_dfd .Tw ;};var _gab float64 ;if _fcb ,_ ,_efb :=_dfd .Tf .GetRuneMetrics (_aca );_efb {_gab =_fcb *0.001*_fga ;}else {_gab ,_ =ctx .MeasureString (string (_aca ),_aa );};_bdf :=(_gab +_dfd .Tc +_cde )*_af ;_dfd .Tm =_ca .TranslationMatrix (_bdf ,0).Mult (_ede );};};func (_ccd *TextFont )GetCharMetrics (code _ccg .CharCode )(float64 ,float64 ,bool ){if _geb ,_faf :=_ccd .Font .GetCharMetrics (code );_faf &&_geb .Wx !=0{return _geb .Wx ,_geb .Wy ,_faf ;};if _ccd ._gdg ==nil {return 0,0,false ;};_bff ,_gbb :=_ccd ._gdg .GetCharMetrics (code );return _bff .Wx ,_bff .Wy ,_gbb &&_bff .Wx !=0;};func NewTextState ()*TextState {return &TextState {Th :100,Tm :_ca .IdentityMatrix (),Tlm :_ca .IdentityMatrix ()};};type Context interface{Push ();Pop ();Matrix ()_ca .Matrix ;SetMatrix (_dd _ca .Matrix );Translate (_gd ,_fe float64 );Scale (_ba ,_e float64 );Rotate (_bd float64 );MoveTo (_be ,_ec float64 );LineTo (_gg ,_bac float64 );CubicTo (_a ,_cd ,_df ,_fa ,_cf ,_ad float64 );QuadraticTo (_ggg ,_eb ,_cbf ,_db float64 );NewSubPath ();ClosePath ();ClearPath ();Clip ();ClipPreserve ();ResetClip ();LineWidth ()float64 ;SetLineWidth (_dca float64 );SetLineCap (_faa LineCap );SetLineJoin (_ee LineJoin );SetDash (_dg ...float64 );SetDashOffset (_ea float64 );Fill ();FillPreserve ();Stroke ();StrokePreserve ();SetRGBA (_caf ,_bg ,_eg ,_ce float64 );SetFillRGBA (_eac ,_fd ,_ag ,_de float64 );SetFillStyle (_cg Pattern );SetFillRule (_dgb FillRule );SetStrokeRGBA (_cee ,_cfa ,_ab ,_ddc float64 );SetStrokeStyle (_ggd Pattern );FillPattern ()Pattern ;StrokePattern ()Pattern ;TextState ()*TextState ;DrawString (_bacb string ,_ac _g .Face ,_ccgf ,_aga float64 );MeasureString (_ead string ,_ece _g .Face )(_agaa ,_bb float64 );DrawRectangle (_cdg ,_ggga ,_ege ,_cdd float64 );DrawImage (_gdc _cb .Image ,_aba ,_bf int );DrawImageAnchored (_eea _cb .Image ,_ddf ,_gb int ,_egd ,_bc float64 );Height ()int ;Width ()int ;};func (_bcb *TextFont )WithSize (size float64 ,originalFont *_ge .PdfFont )*TextFont {return &TextFont {Font :_bcb .Font ,Size :size ,_fef :_bcb ._fef ,_gdg :originalFont };};type TextFont struct{Font *_ge .PdfFont ;Size float64 ;_fef *_gf .Font ;_gdg *_ge .PdfFont ;};type FillRule int ;func (_ed *TextFont )BytesToCharcodes (data []byte )[]_ccg .CharCode {if _ed ._gdg !=nil {return _ed ._gdg .BytesToCharcodes (data );};return _ed .Font .BytesToCharcodes (data );};func (_cab *TextState )Reset (){_cab .Tm =_ca .IdentityMatrix ();_cab .Tlm =_ca .IdentityMatrix ()};type Pattern interface{ColorAt (_ga ,_fg int )_c .Color ;};