2020-09-28 23:18:17 +00:00

12 lines
6.4 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 (_e "errors";_bd "github.com/golang/freetype/truetype";_d "github.com/unidoc/unipdf/v3/core";_a "github.com/unidoc/unipdf/v3/internal/textencoding";_f "github.com/unidoc/unipdf/v3/internal/transform";_fd "github.com/unidoc/unipdf/v3/model";_ac "golang.org/x/image/font";_ed "image";_c "image/color";);type LineCap int ;const (FillRuleWinding FillRule =iota ;FillRuleEvenOdd ;);type Gradient interface{Pattern ;AddColorStop (_ad float64 ,_ef _c .Color );};func (_bgc *TextState )ProcDQ (data []byte ,aw ,ac float64 ,ctx Context ){_bgc .Tw =aw ;_bgc .Tc =ac ;_bgc .ProcQ (data ,ctx );};type TextState struct{Tc float64 ;Tw float64 ;Th float64 ;Tl float64 ;Tf *TextFont ;Ts float64 ;Tm _f .Matrix ;Tlm _f .Matrix ;};func (_eea *TextState )ProcQ (data []byte ,ctx Context ){_eea .ProcTStar ();_eea .ProcTj (data ,ctx )};func (_aeea *TextState )ProcTd (tx ,ty float64 ){_aeea .Tlm .Concat (_f .TranslationMatrix (tx ,-ty ));_aeea .Tm =_aeea .Tlm .Clone ();};func (_bgb *TextFont )BytesToCharcodes (data []byte )[]_a .CharCode {if _bgb ._ec !=nil {return _bgb ._ec .BytesToCharcodes (data );};return _bgb .Font .BytesToCharcodes (data );};func (_fce *TextState )ProcTD (tx ,ty float64 ){_fce .Tl =-ty ;_fce .ProcTd (tx ,ty )};func NewTextFont (font *_fd .PdfFont ,size float64 )(*TextFont ,error ){_cf :=font .FontDescriptor ();if _cf ==nil {return nil ,_e .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");};_agd ,_cd :=_d .GetStream (_cf .FontFile2 );if !_cd {return nil ,_e .New ("\u006di\u0073\u0073\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u0020f\u0069\u006c\u0065\u0020\u0073\u0074\u0072\u0065\u0061\u006d");};_gg ,_fe :=_d .DecodeStream (_agd );if _fe !=nil {return nil ,_fe ;};_eec ,_fe :=_bd .Parse (_gg );if _fe !=nil {return nil ,_fe ;};if size <=1{size =10;};return &TextFont {Font :font ,Face :_bd .NewFace (_eec ,&_bd .Options {Size :size }),Size :size ,_eee :_eec },nil ;};func (_eeg *TextState )Reset (){_eeg .Tm =_f .IdentityMatrix ();_eeg .Tlm =_f .IdentityMatrix ()};func (_dbad *TextFont )GetCharMetrics (code _a .CharCode )(float64 ,float64 ,bool ){if _gd ,_fed :=_dbad .Font .GetCharMetrics (code );_fed &&_gd .Wx !=0{return _gd .Wx ,_gd .Wy ,_fed ;};if _dbad ._ec ==nil {return 0,0,false ;};_aff ,_ea :=_dbad ._ec .GetCharMetrics (code );return _aff .Wx ,_aff .Wy ,_ea &&_aff .Wx !=0;};func (_cga *TextState )ProcTStar (){_cga .ProcTd (0,-_cga .Tl )};func (_ggd *TextFont )GetRuneMetrics (r rune )(float64 ,float64 ,bool ){if _cgd ,_age :=_ggd .Font .GetRuneMetrics (r );_age &&_cgd .Wx !=0{return _cgd .Wx ,_cgd .Wy ,_age ;};if _ggd ._ec ==nil {return 0,0,false ;};_bge ,_gbfa :=_ggd ._ec .GetRuneMetrics (r );return _bge .Wx ,_bge .Wy ,_gbfa &&_bge .Wx !=0;};type FillRule int ;func (_aa *TextFont )CharcodesToUnicode (charcodes []_a .CharCode )[]rune {if _aa ._ec !=nil {return _aa ._ec .CharcodesToUnicode (charcodes );};return _aa .Font .CharcodesToUnicode (charcodes );};func (_ffc *TextState )ProcTm (a ,b ,c ,d ,e ,f float64 ){_ffc .Tm =_f .NewMatrix (a ,b ,c ,d ,e ,-f );_ffc .Tlm =_ffc .Tm .Clone ();};func NewTextFontFromPath (filePath string ,size float64 )(*TextFont ,error ){_bba ,_ccd :=_fd .NewPdfFontFromTTFFile (filePath );if _ccd !=nil {return nil ,_ccd ;};return NewTextFont (_bba ,size );};type Context interface{Push ();Pop ();Matrix ()_f .Matrix ;SetMatrix (_g _f .Matrix );Translate (_acf ,_ae float64 );Scale (_ga ,_bc float64 );Rotate (_gb float64 );MoveTo (_cb ,_gbe float64 );LineTo (_ada ,_de float64 );CubicTo (_ba ,_eb ,_bg ,_ff ,_eg ,_db float64 );QuadraticTo (_ca ,_ce ,_aee ,_cee float64 );NewSubPath ();ClosePath ();ClearPath ();Clip ();ClipPreserve ();ResetClip ();LineWidth ()float64 ;SetLineWidth (_dc float64 );SetLineCap (_dbf LineCap );SetLineJoin (_fde LineJoin );SetDash (_gbc ...float64 );SetDashOffset (_cc float64 );Fill ();FillPreserve ();Stroke ();StrokePreserve ();SetRGBA (_gf ,_egc ,_gad ,_bca float64 );SetFillRGBA (_egg ,_gfe ,_be ,_bdd float64 );SetFillStyle (_aeb Pattern );SetFillRule (_fc FillRule );SetStrokeRGBA (_ee ,_dcb ,_cab ,_edd float64 );SetStrokeStyle (_ege Pattern );TextState ()*TextState ;DrawString (_af string ,_baa ,_gbcc float64 );MeasureString (_gbf string )(_dba ,_gc float64 );DrawRectangle (_dg ,_agc ,_cg ,_ge float64 );DrawImage (_cea _ed .Image ,_fg ,_adg int );DrawImageAnchored (_da _ed .Image ,_gag ,_bb int ,_cgb ,_ace float64 );Height ()int ;Width ()int ;};type LineJoin int ;type TextFont struct{Font *_fd .PdfFont ;Face _ac .Face ;Size float64 ;_eee *_bd .Font ;_ec *_fd .PdfFont ;};type Pattern interface{ColorAt (_fa ,_ag int )_c .Color ;};const (LineCapRound LineCap =iota ;LineCapButt ;LineCapSquare ;);func NewTextState ()*TextState {return &TextState {Th :100,Tm :_f .IdentityMatrix (),Tlm :_f .IdentityMatrix ()};};func (_cad *TextFont )WithSize (size float64 ,originalFont *_fd .PdfFont )*TextFont {if size <=1{size =10;};return &TextFont {Font :_cad .Font ,Face :_bd .NewFace (_cad ._eee ,&_bd .Options {Size :size }),Size :size ,_eee :_cad ._eee ,_ec :originalFont };};func (_dbe *TextState )ProcTf (font *TextFont ){_dbe .Tf =font };const (LineJoinRound LineJoin =iota ;LineJoinBevel ;);func (_gagb *TextState )ProcTj (data []byte ,ctx Context ){_cbe :=_gagb .Tf .Size ;_gbd :=_gagb .Th /100.0;_ceb :=_f .NewMatrix (_cbe *_gbd ,0,0,_cbe ,0,_gagb .Ts );_dbc :=_gagb .Tf .CharcodesToUnicode (_gagb .Tf .BytesToCharcodes (data ));for _ ,_dbd :=range _dbc {if _dbd =='\x00'{continue ;};_dca :=_gagb .Tm .Clone ();_gagb .Tm .Concat (_ceb );_gadb ,_gbdb :=_gagb .Tm .Transform (0,0);ctx .Scale (1,-1);ctx .DrawString (string (_dbd ),_gadb ,_gbdb );ctx .Scale (1,-1);_eecc :=0.0;if _dbd ==' '{_eecc =_gagb .Tw ;};var _bec float64 ;if _aebg ,_ ,_eag :=_gagb .Tf .GetRuneMetrics (_dbd );_eag {_bec =_aebg *0.001*_cbe ;}else {_bec ,_ =ctx .MeasureString (string (_dbd ));};_dgg :=(_bec +_gagb .Tc +_eecc )*_gbd ;_gagb .Tm =_f .TranslationMatrix (_dgg ,0).Mult (_dca );};};func (_agdd *TextState )Translate (tx ,ty float64 ){_agdd .Tm =_f .TranslationMatrix (tx ,ty ).Mult (_agdd .Tm );};