36 lines
7.1 KiB
Go
Raw Normal View History

2020-08-27 21:45:09 +00:00
//
// 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/
2021-04-17 13:46:54 +00:00
package context ;import (_b "errors";_bf "github.com/golang/freetype/truetype";_ddd "github.com/unidoc/unipdf/v3/core";_fc "github.com/unidoc/unipdf/v3/internal/textencoding";_f "github.com/unidoc/unipdf/v3/internal/transform";_de "github.com/unidoc/unipdf/v3/model";
_g "golang.org/x/image/font";_dd "image";_c "image/color";);func (_eeea *TextState )ProcTf (font *TextFont ){_eeea .Tf =font };type Gradient interface{Pattern ;AddColorStop (_fce float64 ,_gf _c .Color );};func NewTextFont (font *_de .PdfFont ,size float64 )(*TextFont ,error ){_daa :=font .FontDescriptor ();
if _daa ==nil {return nil ,_b .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");};_ge ,_ca :=_ddd .GetStream (_daa .FontFile2 );if !_ca {return nil ,_b .New ("\u006di\u0073\u0073\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u0020f\u0069\u006c\u0065\u0020\u0073\u0074\u0072\u0065\u0061\u006d");
};_ec ,_cef :=_ddd .DecodeStream (_ge );if _cef !=nil {return nil ,_cef ;};_dgda ,_cef :=_bf .Parse (_ec );if _cef !=nil {return nil ,_cef ;};return &TextFont {Font :font ,Size :size ,_cc :_dgda },nil ;};func (_ege *TextState )ProcTj (data []byte ,ctx Context ){_cad :=_ege .Tf .Size ;
_fdfc :=_ege .Th /100.0;_ecb :=_ege .GlobalScale ;_df :=_f .NewMatrix (_cad *_fdfc ,0,0,_cad ,0,_ege .Ts );_cda :=ctx .Matrix ();_def :=_cda .Clone ().Mult (_ege .Tm .Clone ().Mult (_df )).ScalingFactorY ();_gde :=_ege .Tf .NewFace (_def );_bgda :=_ege .Tf .BytesToCharcodes (data );
_fgf :=_ege .Tf .CharcodesToUnicode (_bgda );for _dfa ,_bfb :=range _fgf {if _bfb =='\x00'{continue ;};_ggf :=_cda .Clone ().Mult (_ege .Tm .Clone ().Mult (_df ));_gb :=_ggf .ScalingFactorY ();_ggf =_ggf .Scale (1/_gb ,-1/_gb );if _ege .Tr !=TextRenderingModeInvisible {ctx .SetMatrix (_ggf );
ctx .DrawString (string (_bfb ),_gde ,0,0);ctx .SetMatrix (_cda );};_dbf :=0.0;if _bfb ==' '{_dbf =_ege .Tw ;};_bcc ,_ ,_cff :=_ege .Tf .GetRuneMetrics (_bfb );if !_cff &&_dfa < len (_bgda ){_bcc ,_ ,_cff =_ege .Tf .GetCharMetrics (_bgda [_dfa ]);};if _cff {_bcc =_bcc *0.001*_cad ;
}else {_bcc ,_ =ctx .MeasureString (string (_bfb ),_gde );_bcc =_bcc /_ecb ;};_be :=(_bcc +_ege .Tc +_dbf )*_fdfc ;_ege .Tm =_ege .Tm .Mult (_f .TranslationMatrix (_be ,0));};};func (_dea *TextState )Reset (){_dea .Tm =_f .IdentityMatrix ();_dea .Tlm =_f .IdentityMatrix ()};
type LineJoin int ;func (_aacf *TextFont )CharcodesToUnicode (charcodes []_fc .CharCode )[]rune {if _aacf ._fdf !=nil {return _aacf ._fdf .CharcodesToUnicode (charcodes );};return _aacf .Font .CharcodesToUnicode (charcodes );};const (FillRuleWinding FillRule =iota ;
FillRuleEvenOdd ;);func (_cga *TextFont )BytesToCharcodes (data []byte )[]_fc .CharCode {if _cga ._fdf !=nil {return _cga ._fdf .BytesToCharcodes (data );};return _cga .Font .BytesToCharcodes (data );};type TextFont struct{Font *_de .PdfFont ;Size float64 ;
_cc *_bf .Font ;_fdf *_de .PdfFont ;};func (_ead *TextFont )NewFace (size float64 )_g .Face {return _bf .NewFace (_ead ._cc ,&_bf .Options {Size :size });};func NewTextFontFromPath (filePath string ,size float64 )(*TextFont ,error ){_fbb ,_fbc :=_de .NewPdfFontFromTTFFile (filePath );
if _fbc !=nil {return nil ,_fbc ;};return NewTextFont (_fbb ,size );};func (_fgff *TextState )ProcQ (data []byte ,ctx Context ){_fgff .ProcTStar ();_fgff .ProcTj (data ,ctx )};func (_fcag *TextFont )GetRuneMetrics (r rune )(float64 ,float64 ,bool ){if _efg ,_adg :=_fcag .Font .GetRuneMetrics (r );
_adg &&_efg .Wx !=0{return _efg .Wx ,_efg .Wy ,_adg ;};if _fcag ._fdf ==nil {return 0,0,false ;};_gee ,_ceg :=_fcag ._fdf .GetRuneMetrics (r );return _gee .Wx ,_gee .Wy ,_ceg &&_gee .Wx !=0;};const (TextRenderingModeFill TextRenderingMode =iota ;TextRenderingModeStroke ;
TextRenderingModeFillStroke ;TextRenderingModeInvisible ;TextRenderingModeFillClip ;TextRenderingModeStrokeClip ;TextRenderingModeFillStrokeClip ;TextRenderingModeClip ;);func (_efeg *TextFont )WithSize (size float64 ,originalFont *_de .PdfFont )*TextFont {return &TextFont {Font :_efeg .Font ,Size :size ,_cc :_efeg ._cc ,_fdf :originalFont };
};func NewTextState ()TextState {return TextState {Th :100,Tm :_f .IdentityMatrix (),Tlm :_f .IdentityMatrix ()};};type TextState struct{Tc float64 ;Tw float64 ;Th float64 ;Tl float64 ;Tf *TextFont ;Ts float64 ;Tm _f .Matrix ;Tlm _f .Matrix ;Tr TextRenderingMode ;
GlobalScale float64 ;};type Pattern interface{ColorAt (_fd ,_e int )_c .Color ;};type Context interface{Push ();Pop ();Matrix ()_f .Matrix ;SetMatrix (_a _f .Matrix );Translate (_bc ,_fca float64 );Scale (_ee ,_ff float64 );Rotate (_gd float64 );MoveTo (_dg ,_bg float64 );
LineTo (_ac ,_cg float64 );CubicTo (_cd ,_ba ,_ga ,_ce ,_gc ,_ea float64 );QuadraticTo (_fcab ,_bd ,_bcf ,_aa float64 );NewSubPath ();ClosePath ();ClearPath ();Clip ();ClipPreserve ();ResetClip ();LineWidth ()float64 ;SetLineWidth (_dgc float64 );SetLineCap (_db LineCap );
SetLineJoin (_eb LineJoin );SetDash (_gg ...float64 );SetDashOffset (_fe float64 );Fill ();FillPreserve ();Stroke ();StrokePreserve ();SetRGBA (_eed ,_gce ,_cf ,_gfe float64 );SetFillRGBA (_eg ,_dgd ,_gfea ,_fa float64 );SetFillStyle (_fg Pattern );SetFillRule (_bfd FillRule );
SetStrokeRGBA (_ced ,_bb ,_aac ,_aaf float64 );SetStrokeStyle (_ed Pattern );FillPattern ()Pattern ;StrokePattern ()Pattern ;TextState ()*TextState ;DrawString (_dda string ,_faa _g .Face ,_da ,_ef float64 );MeasureString (_bbg string ,_acc _g .Face )(_bgb ,_ab float64 );
DrawRectangle (_fcd ,_af ,_fb ,_cgg float64 );DrawImage (_cfb _dd .Image ,_bgd ,_efe int );DrawImageAnchored (_aafa _dd .Image ,_ad ,_faad int ,_bbf ,_eee float64 );Height ()int ;Width ()int ;};type LineCap int ;const (LineCapRound LineCap =iota ;LineCapButt ;
LineCapSquare ;);type FillRule int ;func (_eeg *TextState )Translate (tx ,ty float64 ){_eeg .Tm =_eeg .Tm .Mult (_f .TranslationMatrix (tx ,ty ));};func (_dcf *TextState )ProcTm (a ,b ,c ,d ,e ,f float64 ){_dcf .Tm =_f .NewMatrix (a ,b ,c ,d ,e ,f );_dcf .Tlm =_dcf .Tm .Clone ();
};func (_fcagf *TextState )ProcTStar (){_fcagf .ProcTd (0,-_fcagf .Tl )};func (_geg *TextState )ProcTd (tx ,ty float64 ){_geg .Tlm .Concat (_f .TranslationMatrix (tx ,ty ));_geg .Tm =_geg .Tlm .Clone ();};const (LineJoinRound LineJoin =iota ;LineJoinBevel ;
);func (_dee *TextState )ProcTD (tx ,ty float64 ){_dee .Tl =-ty ;_dee .ProcTd (tx ,ty )};func (_dc *TextFont )GetCharMetrics (code _fc .CharCode )(float64 ,float64 ,bool ){if _deb ,_fab :=_dc .Font .GetCharMetrics (code );_fab &&_deb .Wx !=0{return _deb .Wx ,_deb .Wy ,_fab ;
};if _dc ._fdf ==nil {return 0,0,false ;};_bae ,_fac :=_dc ._fdf .GetCharMetrics (code );return _bae .Wx ,_bae .Wy ,_fac &&_bae .Wx !=0;};type TextRenderingMode int ;func (_gcc *TextState )ProcDQ (data []byte ,aw ,ac float64 ,ctx Context ){_gcc .Tw =aw ;
_gcc .Tc =ac ;_gcc .ProcQ (data ,ctx );};