2020-08-27 21:45:09 +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 (_g "errors";_c "github.com/golang/freetype/truetype";_gb "github.com/unidoc/unipdf/v3/core";_df "github.com/unidoc/unipdf/v3/internal/textencoding";_b "github.com/unidoc/unipdf/v3/internal/transform";_f "github.com/unidoc/unipdf/v3/model";_db "golang.org/x/image/font";_d "image";_af "image/color";);const (LineCapRound LineCap =iota ;LineCapButt ;LineCapSquare ;);func NewTextState ()*TextState {return &TextState {Th :100,Tm :_b .IdentityMatrix (),Tlm :_b .IdentityMatrix ()};};type LineCap int ;type TextState struct{Tc float64 ;Tw float64 ;Th float64 ;Tl float64 ;Tf *TextFont ;Ts float64 ;Tm _b .Matrix ;Tlm _b .Matrix ;};type FillRule int ;const (FillRuleWinding FillRule =iota ;FillRuleEvenOdd ;);type Gradient interface{Pattern ;AddColorStop (_cg float64 ,_bf _af .Color );};func (_bdg *TextFont )BytesToCharcodes (data []byte )[]_df .CharCode {if _bdg ._bba !=nil {return _bdg ._bba .BytesToCharcodes (data );};return _bdg .Font .BytesToCharcodes (data );};func (_bbd *TextState )ProcTD (tx ,ty float64 ){_bbd .Tl =-ty ;_bbd .ProcTd (tx ,ty )};func (_dca *TextState )ProcTStar (){_dca .ProcTd (0,-_dca .Tl )};func NewTextFont (font *_f .PdfFont ,size float64 )(*TextFont ,error ){_abd :=font .FontDescriptor ();if _abd ==nil {return nil ,_g .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");};_abe ,_dfg :=_gb .GetStream (_abd .FontFile2 );if !_dfg {return nil ,_g .New ("\u006di\u0073\u0073\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u0020f\u0069\u006c\u0065\u0020\u0073\u0074\u0072\u0065\u0061\u006d");};_eea ,_bda :=_gb .DecodeStream (_abe );if _bda !=nil {return nil ,_bda ;};_fg ,_bda :=_c .Parse (_eea );if _bda !=nil {return nil ,_bda ;};if size <=1{size =10;};return &TextFont {Font :font ,Face :_c .NewFace (_fg ,&_c .Options {Size :size }),Size :size ,_aa :_fg },nil ;};func (_fac *TextFont )GetRuneMetrics (r rune )(float64 ,float64 ,bool ){if _cd ,_fdg :=_fac .Font .GetRuneMetrics (r );_fdg &&_cd .Wx !=0{return _cd .Wx ,_cd .Wy ,_fdg ;};if _fac ._bba ==nil {return 0,0,false ;};_gg ,_gbe :=_fac ._bba .GetRuneMetrics (r );return _gg .Wx ,_gg .Wy ,_gbe &&_gg .Wx !=0;};func (_efd *TextFont )WithSize (size float64 ,originalFont *_f .PdfFont )*TextFont {if size <=1{size =10;};return &TextFont {Font :_efd .Font ,Face :_c .NewFace (_efd ._aa ,&_c .Options {Size :size }),Size :size ,_aa :_efd ._aa ,_bba :originalFont };};func (_cga *TextState )ProcTd (tx ,ty float64 ){_cga .Tlm .Concat (_b .TranslationMatrix (tx ,-ty ));_cga .Tm =_cga .Tlm .Clone ();};func (_ag *TextState )Reset (){_ag .Tm =_b .IdentityMatrix ();_ag .Tlm =_b .IdentityMatrix ()};func (_ebg *TextState )ProcTj (data []byte ,ctx Context ){_aad :=_ebg .Tf .Size ;_abb :=_ebg .Th /100.0;_gba :=_b .NewMatrix (_aad *_abb ,0,0,_aad ,0,_ebg .Ts );_eab :=_ebg .Tf .CharcodesToUnicode (_ebg .Tf .BytesToCharcodes (data ));for _ ,_cbe :=range _eab {if _cbe =='\x00'{continue ;};_cgba :=_ebg .Tm .Clone ();_ebg .Tm .Concat (_gba );_da ,_cac :=_ebg .Tm .Transform (0,0);ctx .Scale (1,-1);ctx .DrawString (string (_cbe ),_da ,_cac );ctx .Scale (1,-1);_bae :=0.0;if _cbe ==' '{_bae =_ebg .Tw ;};var _ae float64 ;if _bcf ,_ ,_efe :=_ebg .Tf .GetRuneMetrics (_cbe );_efe {_ae =_bcf *0.001*_aad ;}else {_ae ,_ =ctx .MeasureString (string (_cbe ));};_bgd :=(_ae +_ebg .Tc +_bae )*_abb ;_ebg .Tm =_b .TranslationMatrix (_bgd ,0).Mult (_cgba );};};type Pattern interface{ColorAt (_ca ,_fa int )_af .Color ;};type Context interface{Push ();Pop ();Matrix ()_b .Matrix ;SetMatrix (_fe _b .Matrix );Translate (_e ,_ba float64 );Scale (_cgb ,_eg float64 );Rotate (_ea float64 );MoveTo (_cb ,_ab float64 );LineTo (_fc ,_ed float64 );CubicTo (_de ,_ff ,_gd ,_dbd ,_bd ,_bfb float64 );QuadraticTo (_bc ,_bca ,_fed ,_gc float64 );NewSubPath ();ClosePath ();ClearPath ();Clip ();ClipPreserve ();ResetClip ();LineWidth ()float64 ;SetLineWidth (_bdd float64 );SetLineCap (_ad LineCap );SetLineJoin (_cbb LineJoin );SetDash (_gdg ...float64 );SetDashOffset (_ffc float64 );Fill ();FillPreserve ();Stroke ();StrokePreserve ();SetRGBA (_ee ,_baf ,_afg ,_bac float64 );SetFillRGBA (_bg ,_ef ,_bdb ,_bgg float64 );SetFillStyle (_efg Pattern );SetFillRule (_eb FillRule );SetStrokeRGBA (_dc ,_cgd ,_cc ,_dg float64 );SetStrokeStyle (_cbc Pattern );TextState ()*TextState ;DrawString (_fcd string ,_bga ,_cba float64 );MeasureString (_cgdd string )(_ead ,_aff float64 );DrawRectangle (_dea ,_gdd ,_fb ,_edc float64 );DrawImage (_ce _d .Image ,_ega ,_egb int );DrawImageAnchored (_gdc _d .Image ,_gda ,_ceg int ,_ge ,_bb float64 );Height ()int ;Width ()int ;};func (_ga *TextFont )CharcodesToUnicode (charcodes []_df .CharCode )[]rune {if _ga ._bba !=nil {return _ga ._bba .CharcodesToUnicode (charcodes );};return _ga .Font .CharcodesToUnicode (charcodes );};func (_gcg *TextState )ProcTf (font *TextFont ){_gcg .Tf =font };func (_gdae *TextFont )GetCharMetrics (code _df .CharCode )(float64 ,float64 ,bool ){if _dbe ,_gcd :=_gdae .Font .GetCharMetrics (code );_gcd &&_dbe .Wx !=0{return _dbe .Wx ,_dbe .Wy ,_gcd ;};if _gdae ._bba ==nil {return 0,0,false ;};_gf ,_gbd :=_gdae ._bba .GetCharMetrics (code );return _gf .Wx ,_gf .Wy ,_gbd &&_gf .Wx !=0;};func NewTextFontFromPath (filePath string ,size float64 )(*TextFont ,error ){_fd ,_fgc :=_f .NewPdfFontFromTTFFile (filePath );if _fgc !=nil {return nil ,_fgc ;};return NewTextFont (_fd ,size );};type TextFont struct{Font *_f .PdfFont ;Face _db .Face ;Size float64 ;_aa *_c .Font ;_bba *_f .PdfFont ;};func (_cbeg *TextState )ProcDQ (data []byte ,aw ,ac float64 ,ctx Context ){_cbeg .Tw =aw ;_cbeg .Tc =ac ;_cbeg .ProcQ (data ,ctx );};func (_dbec *TextState )Translate (tx ,ty float64 ){_dbec .Tm =_b .TranslationMatrix (tx ,ty ).Mult (_dbec .Tm );};func (_fbg *TextState )ProcQ (data []byte ,ctx Context ){_fbg .ProcTStar ();_fbg .ProcTj (data ,ctx )};type LineJoin int ;const (LineJoinRound LineJoin =iota ;LineJoinBevel ;);func (_abg *TextState )ProcTm (a ,b ,c ,d ,e ,f float64 ){_abg .Tm =_b .NewMatrix (a ,b ,c ,d ,e ,-f );_abg .Tlm =_abg .Tm .Clone ();};