2024-12-20 06:39:10 +00:00

38 lines
8.2 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";_gc "github.com/unidoc/freetype/truetype";_dg "github.com/unidoc/unipdf/v3/core";_fc "github.com/unidoc/unipdf/v3/internal/cmap";_f "github.com/unidoc/unipdf/v3/internal/textencoding";_de "github.com/unidoc/unipdf/v3/internal/transform";
_bc "github.com/unidoc/unipdf/v3/model";_b "golang.org/x/image/font";_ea "image";_d "image/color";_a "strconv";_gb "strings";);const (FillRuleWinding FillRule =iota ;FillRuleEvenOdd ;);type Pattern interface{ColorAt (_ba ,_bb int )_d .Color ;};func (_gff *TextFont )CharcodeToRunes (charcode _f .CharCode )(_f .CharCode ,[]rune ){_gdc :=[]_f .CharCode {charcode };
if _gff ._gee ==nil ||_gff ._gee ==_gff .Font {return _gff .charcodeToRunesSimple (charcode );};_eg :=_gff ._gee .CharcodesToUnicode (_gdc );_dfe ,_ :=_gff .Font .RunesToCharcodeBytes (_eg );_edf :=_gff .Font .BytesToCharcodes (_dfe );_ecc :=charcode ;
if len (_edf )> 0&&_edf [0]!=0{_ecc =_edf [0];};if string (_eg )==string (_fc .MissingCodeRune )&&_gff ._gee .BaseFont ()==_gff .Font .BaseFont (){return _gff .charcodeToRunesSimple (charcode );};return _ecc ,_eg ;};func (_ggb *TextState )ProcTj (data []byte ,ctx Context ){_gbb :=_ggb .Tf .Size ;
_affg :=_ggb .Th /100.0;_bbec :=_ggb .GlobalScale ;_dgb :=_de .NewMatrix (_gbb *_affg ,0,0,_gbb ,0,_ggb .Ts );_gcb :=ctx .Matrix ();_cdf :=_gcb .Clone ().Mult (_ggb .Tm .Clone ().Mult (_dgb )).ScalingFactorY ();_ebe :=_ggb .Tf .NewFace (_cdf );_gga :=_ggb .Tf .BytesToCharcodes (data );
for _ ,_feg :=range _gga {_dge ,_bgda :=_ggb .Tf .CharcodeToRunes (_feg );_ddc :=string (_bgda );if _ddc =="\u0000"{continue ;};_fgc :=_gcb .Clone ().Mult (_ggb .Tm .Clone ().Mult (_dgb ));_fbf :=_fgc .ScalingFactorY ();_fgc =_fgc .Scale (1/_fbf ,-1/_fbf );
if _ggb .Tr !=TextRenderingModeInvisible {ctx .SetMatrix (_fgc );ctx .DrawString (_ddc ,_ebe ,0,0);ctx .SetMatrix (_gcb );};_dcg :=0.0;if _ddc =="\u0020"{_dcg =_ggb .Tw ;};_agg ,_ ,_feb :=_ggb .Tf .GetCharMetrics (_dge );if _feb {_agg =_agg *0.001*_gbb ;
}else {_agg ,_ =ctx .MeasureString (_ddc ,_ebe );_agg =_agg /_bbec ;};_gad :=(_agg +_ggb .Tc +_dcg )*_affg ;_ggb .Tm =_ggb .Tm .Mult (_de .TranslationMatrix (_gad ,0));};};const (TextRenderingModeFill TextRenderingMode =iota ;TextRenderingModeStroke ;TextRenderingModeFillStroke ;
TextRenderingModeInvisible ;TextRenderingModeFillClip ;TextRenderingModeStrokeClip ;TextRenderingModeFillStrokeClip ;TextRenderingModeClip ;);type FillRule int ;type LineJoin int ;type LineCap int ;func (_eeb *TextFont )WithSize (size float64 ,originalFont *_bc .PdfFont )*TextFont {return &TextFont {Font :_eeb .Font ,Size :size ,_fff :_eeb ._fff ,_gee :originalFont };
};type TextFont struct{Font *_bc .PdfFont ;Size float64 ;_fff *_gc .Font ;_gee *_bc .PdfFont ;};type TextState struct{Tc float64 ;Tw float64 ;Th float64 ;Tl float64 ;Tf *TextFont ;Ts float64 ;Tm _de .Matrix ;Tlm _de .Matrix ;Tr TextRenderingMode ;GlobalScale float64 ;
};func (_aec *TextState )ProcTd (tx ,ty float64 ){_aec .Tlm .Concat (_de .TranslationMatrix (tx ,ty ));_aec .Tm =_aec .Tlm .Clone ();};func NewTextFont (font *_bc .PdfFont ,size float64 )(*TextFont ,error ){_ggf :=font .FontDescriptor ();if _ggf ==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");
};_ed ,_aff :=_dg .GetStream (_ggf .FontFile2 );if !_aff {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");};_dfc ,_efe :=_dg .DecodeStream (_ed );
if _efe !=nil {return nil ,_efe ;};_fac ,_efe :=_gc .Parse (_dfc );if _efe !=nil {return nil ,_efe ;};_fd :=font .FontDescriptor ().FontName .String ();_bcb :=len (_fd )> 7&&_fd [6]=='+';if _ggf .Flags !=nil {_ddg ,_cf :=_a .Atoi (_ggf .Flags .String ());
if _cf ==nil &&_ddg ==32{_bcb =false ;};};if !_fac .HasCmap ()&&(!_gb .Contains (font .Encoder ().String (),"\u0049d\u0065\u006e\u0074\u0069\u0074\u0079-")||!_bcb ){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 ,_fff :_fac },nil ;};func NewTextFontFromPath (filePath string ,size float64 )(*TextFont ,error ){_eeg ,_fbc :=_bc .NewPdfFontFromTTFFile (filePath );if _fbc !=nil {return nil ,_fbc ;};return NewTextFont (_eeg ,size );
};const (LineJoinRound LineJoin =iota ;LineJoinBevel ;);func (_fga *TextFont )NewFace (size float64 )_b .Face {return _gc .NewFace (_fga ._fff ,&_gc .Options {Size :size });};func (_gbbg *TextState )Reset (){_gbbg .Tm =_de .IdentityMatrix ();_gbbg .Tlm =_de .IdentityMatrix ()};
func (_gcd *TextState )ProcTD (tx ,ty float64 ){_gcd .Tl =-ty ;_gcd .ProcTd (tx ,ty )};func (_cbe *TextState )ProcDQ (data []byte ,aw ,ac float64 ,ctx Context ){_cbe .Tw =aw ;_cbe .Tc =ac ;_cbe .ProcQ (data ,ctx );};type Context interface{Push ();Pop ();
Matrix ()_de .Matrix ;SetMatrix (_bbb _de .Matrix );Translate (_ae ,_bd float64 );Scale (_fg ,_eaf float64 );Rotate (_gfe float64 );MoveTo (_c ,_af float64 );LineTo (_da ,_dgd float64 );CubicTo (_ef ,_fe ,_dga ,_fcf ,_bdf ,_fb float64 );QuadraticTo (_cd ,_ab ,_aeb ,_abf float64 );
NewSubPath ();ClosePath ();ClearPath ();Clip ();ClipPreserve ();ResetClip ();LineWidth ()float64 ;SetLineWidth (_aba float64 );SetLineCap (_ga LineCap );SetLineJoin (_bbe LineJoin );SetDash (_bg ...float64 );SetDashOffset (_bgd float64 );Fill ();FillPreserve ();
Stroke ();StrokePreserve ();SetRGBA (_cb ,_ff ,_cc ,_ee float64 );SetFillRGBA (_ge ,_gg ,_eag ,_aea float64 );SetFillStyle (_dc Pattern );SetFillRule (_aa FillRule );SetStrokeRGBA (_efb ,_eb ,_aac ,_cca float64 );SetStrokeStyle (_ag Pattern );FillPattern ()Pattern ;
StrokePattern ()Pattern ;TextState ()*TextState ;DrawString (_dd string ,_fcd _b .Face ,_afd ,_bag float64 );MeasureString (_ec string ,_aeae _b .Face )(_ca ,_bf float64 );DrawRectangle (_dea ,_gd ,_bab ,_cbd float64 );DrawImage (_bac _ea .Image ,_bgde ,_ce int );
DrawImageAnchored (_ceg _ea .Image ,_fce ,_fa int ,_baa ,_df float64 );Height ()int ;Width ()int ;};type TextRenderingMode int ;func NewTextState ()TextState {return TextState {Th :100,Tm :_de .IdentityMatrix (),Tlm :_de .IdentityMatrix ()};};func (_bgf *TextFont )BytesToCharcodes (data []byte )[]_f .CharCode {if _bgf ._gee !=nil {return _bgf ._gee .BytesToCharcodes (data );
};return _bgf .Font .BytesToCharcodes (data );};func (_afa *TextState )ProcTm (a ,b ,c ,d ,e ,f float64 ){_afa .Tm =_de .NewMatrix (a ,b ,c ,d ,e ,f );_afa .Tlm =_afa .Tm .Clone ();};func (_gbe *TextState )ProcTStar (){_gbe .ProcTd (0,-_gbe .Tl )};func (_dcb *TextFont )charcodeToRunesSimple (_aag _f .CharCode )(_f .CharCode ,[]rune ){_ffg :=[]_f .CharCode {_aag };
if _dcb .Font .IsSimple ()&&_dcb ._fff !=nil {if _gec :=_dcb ._fff .Index (rune (_aag ));_gec > 0{return _aag ,[]rune {rune (_aag )};};};if _dcb ._fff !=nil &&!_dcb ._fff .HasCmap ()&&_gb .Contains (_dcb .Font .Encoder ().String (),"\u0049d\u0065\u006e\u0074\u0069\u0074\u0079-"){if _bdd :=_dcb ._fff .Index (rune (_aag ));
_bdd > 0{return _aag ,[]rune {rune (_aag )};};};return _aag ,_dcb .Font .CharcodesToUnicode (_ffg );};func (_dcc *TextFont )GetCharMetrics (code _f .CharCode )(float64 ,float64 ,bool ){if _eac ,_fcg :=_dcc .Font .GetCharMetrics (code );_fcg &&_eac .Wx !=0{return _eac .Wx ,_eac .Wy ,_fcg ;
};if _dcc ._gee ==nil {return 0,0,false ;};_ad ,_ac :=_dcc ._gee .GetCharMetrics (code );return _ad .Wx ,_ad .Wy ,_ac &&_ad .Wx !=0;};func (_ega *TextState )ProcTf (font *TextFont ){_ega .Tf =font };func (_ecg *TextState )Translate (tx ,ty float64 ){_ecg .Tm =_ecg .Tm .Mult (_de .TranslationMatrix (tx ,ty ));
};type Gradient interface{Pattern ;AddColorStop (_gf float64 ,_db _d .Color );};const (LineCapRound LineCap =iota ;LineCapButt ;LineCapSquare ;);func (_dbc *TextState )ProcQ (data []byte ,ctx Context ){_dbc .ProcTStar ();_dbc .ProcTj (data ,ctx )};