2023-11-11 11:29:03 +00:00

36 lines
7.7 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";_bg "github.com/unidoc/freetype/truetype";_ge "github.com/unidoc/unipdf/v3/core";_fe "github.com/unidoc/unipdf/v3/internal/textencoding";_f "github.com/unidoc/unipdf/v3/internal/transform";_eb "github.com/unidoc/unipdf/v3/model";
_d "golang.org/x/image/font";_c "image";_g "image/color";_gg "strings";);func (_gbc *TextState )ProcTf (font *TextFont ){_gbc .Tf =font };type LineCap int ;type Context interface{Push ();Pop ();Matrix ()_f .Matrix ;SetMatrix (_gd _f .Matrix );Translate (_ef ,_dg float64 );
Scale (_fc ,_a float64 );Rotate (_be float64 );MoveTo (_gf ,_df float64 );LineTo (_ed ,_gfg float64 );CubicTo (_fa ,_eda ,_bgc ,_ga ,_bec ,_fec float64 );QuadraticTo (_bgb ,_ag ,_gfgb ,_bc float64 );NewSubPath ();ClosePath ();ClearPath ();Clip ();ClipPreserve ();
ResetClip ();LineWidth ()float64 ;SetLineWidth (_cf float64 );SetLineCap (_fd LineCap );SetLineJoin (_dd LineJoin );SetDash (_fae ...float64 );SetDashOffset (_dgd float64 );Fill ();FillPreserve ();Stroke ();StrokePreserve ();SetRGBA (_ba ,_efa ,_ff ,_ae float64 );
SetFillRGBA (_bd ,_aa ,_bae ,_ea float64 );SetFillStyle (_ebc Pattern );SetFillRule (_af FillRule );SetStrokeRGBA (_cac ,_ce ,_ebf ,_gc float64 );SetStrokeStyle (_bcc Pattern );FillPattern ()Pattern ;StrokePattern ()Pattern ;TextState ()*TextState ;DrawString (_bee string ,_edag _d .Face ,_gda ,_da float64 );
MeasureString (_ceb string ,_bf _d .Face )(_cg ,_cc float64 );DrawRectangle (_dfa ,_ab ,_eg ,_cec float64 );DrawImage (_bccd _c .Image ,_fb ,_ac int );DrawImageAnchored (_eff _c .Image ,_fga ,_dga int ,_baa ,_dgc float64 );Height ()int ;Width ()int ;};
func (_bad *TextState )ProcDQ (data []byte ,aw ,ac float64 ,ctx Context ){_bad .Tw =aw ;_bad .Tc =ac ;_bad .ProcQ (data ,ctx );};func (_bcd *TextFont )NewFace (size float64 )_d .Face {return _bg .NewFace (_bcd ._daf ,&_bg .Options {Size :size });};func (_cge *TextState )Translate (tx ,ty float64 ){_cge .Tm =_cge .Tm .Mult (_f .TranslationMatrix (tx ,ty ));
};type LineJoin int ;type TextFont struct{Font *_eb .PdfFont ;Size float64 ;_daf *_bg .Font ;_dc *_eb .PdfFont ;};func (_gab *TextFont )WithSize (size float64 ,originalFont *_eb .PdfFont )*TextFont {return &TextFont {Font :_gab .Font ,Size :size ,_daf :_gab ._daf ,_dc :originalFont };
};func (_afa *TextState )ProcTD (tx ,ty float64 ){_afa .Tl =-ty ;_afa .ProcTd (tx ,ty )};type Gradient interface{Pattern ;AddColorStop (_fg float64 ,_ca _g .Color );};func NewTextFont (font *_eb .PdfFont ,size float64 )(*TextFont ,error ){_aac :=font .FontDescriptor ();
if _aac ==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");};_dcc ,_ad :=_ge .GetStream (_aac .FontFile2 );if !_ad {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");
};_aeb ,_bef :=_ge .DecodeStream (_dcc );if _bef !=nil {return nil ,_bef ;};_de ,_bef :=_bg .Parse (_aeb );if _bef !=nil {return nil ,_bef ;};_ged :=font .FontDescriptor ().FontName .String ();_dfb :=len (_ged )> 7&&_ged [6]=='+';if !_de .HasCmap ()&&(!_gg .Contains (font .Encoder ().String (),"\u0049d\u0065\u006e\u0074\u0069\u0074\u0079-")||!_dfb ){return nil ,_e .New ("\u006e\u006f c\u006d\u0061\u0070 \u0061\u006e\u0064\u0020enc\u006fdi\u006e\u0067\u0020\u0069\u0073\u0020\u006eot\u0020\u0069\u0064\u0065\u006e\u0074\u0069t\u0079");
};return &TextFont {Font :font ,Size :size ,_daf :_de },nil ;};func (_bge *TextState )ProcQ (data []byte ,ctx Context ){_bge .ProcTStar ();_bge .ProcTj (data ,ctx )};const (LineJoinRound LineJoin =iota ;LineJoinBevel ;);func (_fag *TextFont )CharcodeToRunes (charcode _fe .CharCode )(_fe .CharCode ,[]rune ){_bdd :=[]_fe .CharCode {charcode };
if _fag ._dc ==nil ||_fag ._dc ==_fag .Font {if _fag .Font .IsSimple ()&&_fag ._daf !=nil {if _fcg :=_fag ._daf .Index (rune (charcode ));_fcg > 0{return charcode ,[]rune {rune (charcode )};};};if _fag ._daf !=nil &&!_fag ._daf .HasCmap ()&&_gg .Contains (_fag .Font .Encoder ().String (),"\u0049d\u0065\u006e\u0074\u0069\u0074\u0079-"){if _feg :=_fag ._daf .Index (rune (charcode ));
_feg > 0{return charcode ,[]rune {rune (charcode )};};};return charcode ,_fag .Font .CharcodesToUnicode (_bdd );};_afe :=_fag ._dc .CharcodesToUnicode (_bdd );_geg ,_ :=_fag .Font .RunesToCharcodeBytes (_afe );_eaa :=_fag .Font .BytesToCharcodes (_geg );
_bdf :=charcode ;if len (_eaa )> 0&&_eaa [0]!=0{_bdf =_eaa [0];};return _bdf ,_afe ;};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 ;
};func (_gb *TextFont )GetCharMetrics (code _fe .CharCode )(float64 ,float64 ,bool ){if _db ,_fde :=_gb .Font .GetCharMetrics (code );_fde &&_db .Wx !=0{return _db .Wx ,_db .Wy ,_fde ;};if _gb ._dc ==nil {return 0,0,false ;};_cb ,_acc :=_gb ._dc .GetCharMetrics (code );
return _cb .Wx ,_cb .Wy ,_acc &&_cb .Wx !=0;};const (LineCapRound LineCap =iota ;LineCapButt ;LineCapSquare ;);const (TextRenderingModeFill TextRenderingMode =iota ;TextRenderingModeStroke ;TextRenderingModeFillStroke ;TextRenderingModeInvisible ;TextRenderingModeFillClip ;
TextRenderingModeStrokeClip ;TextRenderingModeFillStrokeClip ;TextRenderingModeClip ;);func (_cd *TextState )ProcTm (a ,b ,c ,d ,e ,f float64 ){_cd .Tm =_f .NewMatrix (a ,b ,c ,d ,e ,f );_cd .Tlm =_cd .Tm .Clone ();};type Pattern interface{ColorAt (_ee ,_ec int )_g .Color ;
};func (_ffd *TextState )ProcTStar (){_ffd .ProcTd (0,-_ffd .Tl )};func NewTextFontFromPath (filePath string ,size float64 )(*TextFont ,error ){_edf ,_cea :=_eb .NewPdfFontFromTTFFile (filePath );if _cea !=nil {return nil ,_cea ;};return NewTextFont (_edf ,size );
};func (_ecg *TextState )ProcTd (tx ,ty float64 ){_ecg .Tlm .Concat (_f .TranslationMatrix (tx ,ty ));_ecg .Tm =_ecg .Tlm .Clone ();};func (_aaa *TextState )Reset (){_aaa .Tm =_f .IdentityMatrix ();_aaa .Tlm =_f .IdentityMatrix ()};const (FillRuleWinding FillRule =iota ;
FillRuleEvenOdd ;);func (_gaa *TextState )ProcTj (data []byte ,ctx Context ){_fgb :=_gaa .Tf .Size ;_abc :=_gaa .Th /100.0;_cda :=_gaa .GlobalScale ;_adf :=_f .NewMatrix (_fgb *_abc ,0,0,_fgb ,0,_gaa .Ts );_ace :=ctx .Matrix ();_ggd :=_ace .Clone ().Mult (_gaa .Tm .Clone ().Mult (_adf )).ScalingFactorY ();
_cce :=_gaa .Tf .NewFace (_ggd );_edc :=_gaa .Tf .BytesToCharcodes (data );for _ ,_dcf :=range _edc {_dbg ,_edfc :=_gaa .Tf .CharcodeToRunes (_dcf );_ade :=string (_edfc );if _ade =="\u0000"{continue ;};_gdc :=_ace .Clone ().Mult (_gaa .Tm .Clone ().Mult (_adf ));
_fdb :=_gdc .ScalingFactorY ();_gdc =_gdc .Scale (1/_fdb ,-1/_fdb );if _gaa .Tr !=TextRenderingModeInvisible {ctx .SetMatrix (_gdc );ctx .DrawString (_ade ,_cce ,0,0);ctx .SetMatrix (_ace );};_dgb :=0.0;if _ade =="\u0020"{_dgb =_gaa .Tw ;};_ccc ,_ ,_efe :=_gaa .Tf .GetCharMetrics (_dbg );
if _efe {_ccc =_ccc *0.001*_fgb ;}else {_ccc ,_ =ctx .MeasureString (_ade ,_cce );_ccc =_ccc /_cda ;};_fgab :=(_ccc +_gaa .Tc +_dgb )*_abc ;_gaa .Tm =_gaa .Tm .Mult (_f .TranslationMatrix (_fgab ,0));};};func (_fab *TextFont )BytesToCharcodes (data []byte )[]_fe .CharCode {if _fab ._dc !=nil {return _fab ._dc .BytesToCharcodes (data );
};return _fab .Font .BytesToCharcodes (data );};func NewTextState ()TextState {return TextState {Th :100,Tm :_f .IdentityMatrix (),Tlm :_f .IdentityMatrix ()};};type FillRule int ;type TextRenderingMode int ;