mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-02 22:17:06 +08:00
36 lines
7.1 KiB
Go
36 lines
7.1 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";_de "github.com/golang/freetype/truetype";_gb "github.com/unidoc/unipdf/v3/core";_g "github.com/unidoc/unipdf/v3/internal/textencoding";_ec "github.com/unidoc/unipdf/v3/internal/transform";_b "github.com/unidoc/unipdf/v3/model";
|
|
_ea "golang.org/x/image/font";_d "image";_ad "image/color";);func (_bef *TextState )ProcTj (data []byte ,ctx Context ){_ag :=_bef .Tf .Size ;_eee :=_bef .Th /100.0;_bcb :=_bef .GlobalScale ;_ebf :=_ec .NewMatrix (_ag *_eee ,0,0,_ag ,0,_bef .Ts );_edbd :=ctx .Matrix ();
|
|
_fdb :=_edbd .Clone ().Mult (_bef .Tm .Clone ().Mult (_ebf )).ScalingFactorY ();_ggd :=_bef .Tf .NewFace (_fdb );_aed :=_bef .Tf .BytesToCharcodes (data );_dcb :=_bef .Tf .CharcodesToUnicode (_aed );for _gcdb ,_eac :=range _dcb {if _eac =='\x00'{continue ;
|
|
};_ggaa :=_edbd .Clone ().Mult (_bef .Tm .Clone ().Mult (_ebf ));_caa :=_ggaa .ScalingFactorY ();_ggaa =_ggaa .Scale (1/_caa ,-1/_caa );if _bef .Tr !=TextRenderingModeInvisible {ctx .SetMatrix (_ggaa );ctx .DrawString (string (_eac ),_ggd ,0,0);ctx .SetMatrix (_edbd );
|
|
};_fdc :=0.0;if _eac ==' '{_fdc =_bef .Tw ;};_geb ,_ ,_aca :=_bef .Tf .GetRuneMetrics (_eac );if !_aca &&_gcdb < len (_aed ){_geb ,_ ,_aca =_bef .Tf .GetCharMetrics (_aed [_gcdb ]);};if _aca {_geb =_geb *0.001*_ag ;}else {_geb ,_ =ctx .MeasureString (string (_eac ),_ggd );
|
|
_geb =_geb /_bcb ;};_gfg :=(_geb +_bef .Tc +_fdc )*_eee ;_bef .Tm =_bef .Tm .Mult (_ec .TranslationMatrix (_gfg ,0));};};func (_aab *TextState )ProcDQ (data []byte ,aw ,ac float64 ,ctx Context ){_aab .Tw =aw ;_aab .Tc =ac ;_aab .ProcQ (data ,ctx );};type TextFont struct{Font *_b .PdfFont ;
|
|
Size float64 ;_gad *_de .Font ;_afg *_b .PdfFont ;};func (_eed *TextFont )NewFace (size float64 )_ea .Face {return _de .NewFace (_eed ._gad ,&_de .Options {Size :size });};func (_eg *TextState )ProcTm (a ,b ,c ,d ,e ,f float64 ){_eg .Tm =_ec .NewMatrix (a ,b ,c ,d ,e ,f );
|
|
_eg .Tlm =_eg .Tm .Clone ();};const (TextRenderingModeFill TextRenderingMode =iota ;TextRenderingModeStroke ;TextRenderingModeFillStroke ;TextRenderingModeInvisible ;TextRenderingModeFillClip ;TextRenderingModeStrokeClip ;TextRenderingModeFillStrokeClip ;
|
|
TextRenderingModeClip ;);type TextRenderingMode int ;func NewTextFontFromPath (filePath string ,size float64 )(*TextFont ,error ){_dge ,_acf :=_b .NewPdfFontFromTTFFile (filePath );if _acf !=nil {return nil ,_acf ;};return NewTextFont (_dge ,size );};func (_aa *TextState )ProcTD (tx ,ty float64 ){_aa .Tl =-ty ;
|
|
_aa .ProcTd (tx ,ty )};func (_afd *TextState )Reset (){_afd .Tm =_ec .IdentityMatrix ();_afd .Tlm =_ec .IdentityMatrix ()};func (_bbf *TextFont )GetCharMetrics (code _g .CharCode )(float64 ,float64 ,bool ){if _fca ,_ca :=_bbf .Font .GetCharMetrics (code );
|
|
_ca &&_fca .Wx !=0{return _fca .Wx ,_fca .Wy ,_ca ;};if _bbf ._afg ==nil {return 0,0,false ;};_cgc ,_bbc :=_bbf ._afg .GetCharMetrics (code );return _cgc .Wx ,_cgc .Wy ,_bbc &&_cgc .Wx !=0;};type TextState struct{Tc float64 ;Tw float64 ;Th float64 ;Tl float64 ;
|
|
Tf *TextFont ;Ts float64 ;Tm _ec .Matrix ;Tlm _ec .Matrix ;Tr TextRenderingMode ;GlobalScale float64 ;};type Gradient interface{Pattern ;AddColorStop (_dg float64 ,_c _ad .Color );};func (_dc *TextFont )WithSize (size float64 ,originalFont *_b .PdfFont )*TextFont {return &TextFont {Font :_dc .Font ,Size :size ,_gad :_dc ._gad ,_afg :originalFont };
|
|
};type FillRule int ;func (_egb *TextState )ProcTStar (){_egb .ProcTd (0,-_egb .Tl )};func (_cbc *TextState )ProcTf (font *TextFont ){_cbc .Tf =font };const (LineCapRound LineCap =iota ;LineCapButt ;LineCapSquare ;);type Context interface{Push ();Pop ();
|
|
Matrix ()_ec .Matrix ;SetMatrix (_da _ec .Matrix );Translate (_efc ,_f float64 );Scale (_gg ,_af float64 );Rotate (_gf float64 );MoveTo (_ba ,_ff float64 );LineTo (_ab ,_cc float64 );CubicTo (_ae ,_dag ,_ee ,_efe ,_bg ,_fc float64 );QuadraticTo (_daf ,_gc ,_gga ,_bf float64 );
|
|
NewSubPath ();ClosePath ();ClearPath ();Clip ();ClipPreserve ();ResetClip ();LineWidth ()float64 ;SetLineWidth (_ccg float64 );SetLineCap (_cb LineCap );SetLineJoin (_cba LineJoin );SetDash (_fd ...float64 );SetDashOffset (_be float64 );Fill ();FillPreserve ();
|
|
Stroke ();StrokePreserve ();SetRGBA (_bc ,_fe ,_dec ,_gcf float64 );SetFillRGBA (_daa ,_cg ,_cd ,_eec float64 );SetFillStyle (_fg Pattern );SetFillRule (_fa FillRule );SetStrokeRGBA (_bec ,_ge ,_bb ,_ga float64 );SetStrokeStyle (_eb Pattern );FillPattern ()Pattern ;
|
|
StrokePattern ()Pattern ;TextState ()*TextState ;DrawString (_ecc string ,_bce _ea .Face ,_ffa ,_ed float64 );MeasureString (_ecb string ,_dee _ea .Face )(_ebe ,_eaa float64 );DrawRectangle (_cbd ,_bceb ,_efcc ,_cf float64 );DrawImage (_fgc _d .Image ,_edb ,_bfa int );
|
|
DrawImageAnchored (_abe _d .Image ,_ac ,_ebed int ,_bfab ,_fcd float64 );Height ()int ;Width ()int ;};func (_fgcb *TextState )Translate (tx ,ty float64 ){_fgcb .Tm =_fgcb .Tm .Mult (_ec .TranslationMatrix (tx ,ty ));};func (_acd *TextFont )CharcodesToUnicode (charcodes []_g .CharCode )[]rune {if _acd ._afg !=nil {return _acd ._afg .CharcodesToUnicode (charcodes );
|
|
};return _acd .Font .CharcodesToUnicode (charcodes );};const (FillRuleWinding FillRule =iota ;FillRuleEvenOdd ;);func NewTextState ()TextState {return TextState {Th :100,Tm :_ec .IdentityMatrix (),Tlm :_ec .IdentityMatrix ()};};func (_fbf *TextState )ProcTd (tx ,ty float64 ){_fbf .Tlm .Concat (_ec .TranslationMatrix (tx ,ty ));
|
|
_fbf .Tm =_fbf .Tlm .Clone ();};const (LineJoinRound LineJoin =iota ;LineJoinBevel ;);func (_ede *TextFont )BytesToCharcodes (data []byte )[]_g .CharCode {if _ede ._afg !=nil {return _ede ._afg .BytesToCharcodes (data );};return _ede .Font .BytesToCharcodes (data );
|
|
};func NewTextFont (font *_b .PdfFont ,size float64 )(*TextFont ,error ){_ace :=font .FontDescriptor ();if _ace ==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");
|
|
};_efb ,_dd :=_gb .GetStream (_ace .FontFile2 );if !_dd {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");};_dac ,_cdb :=_gb .DecodeStream (_efb );
|
|
if _cdb !=nil {return nil ,_cdb ;};_fb ,_cdb :=_de .Parse (_dac );if _cdb !=nil {return nil ,_cdb ;};return &TextFont {Font :font ,Size :size ,_gad :_fb },nil ;};func (_fea *TextState )ProcQ (data []byte ,ctx Context ){_fea .ProcTStar ();_fea .ProcTj (data ,ctx )};
|
|
type Pattern interface{ColorAt (_db ,_ef int )_ad .Color ;};type LineJoin int ;func (_ecg *TextFont )GetRuneMetrics (r rune )(float64 ,float64 ,bool ){if _gcd ,_eab :=_ecg .Font .GetRuneMetrics (r );_eab &&_gcd .Wx !=0{return _gcd .Wx ,_gcd .Wy ,_eab ;
|
|
};if _ecg ._afg ==nil {return 0,0,false ;};_aee ,_bd :=_ecg ._afg .GetRuneMetrics (r );return _aee .Wx ,_aee .Wy ,_bd &&_aee .Wx !=0;};type LineCap int ; |