mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-30 13:48:51 +08:00
35 lines
7.1 KiB
Go
35 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 (_b "errors";_gg "github.com/unidoc/freetype/truetype";_ec "github.com/unidoc/unipdf/v3/core";_e "github.com/unidoc/unipdf/v3/internal/textencoding";_ba "github.com/unidoc/unipdf/v3/internal/transform";_gd "github.com/unidoc/unipdf/v3/model";
|
|
_c "golang.org/x/image/font";_d "image";_g "image/color";);type TextFont struct{Font *_gd .PdfFont ;Size float64 ;_gbga *_gg .Font ;_bbc *_gd .PdfFont ;};func (_ecg *TextFont )CharcodeToRunes (charcode _e .CharCode )(_e .CharCode ,[]rune ){_gdb :=[]_e .CharCode {charcode };
|
|
if _ecg ._bbc ==nil ||_ecg ._bbc ==_ecg .Font {if _ecg .Font .IsSimple ()&&_ecg ._gbga !=nil {if _acd :=_ecg ._gbga .Index (rune (charcode ));_acd > 0{return charcode ,[]rune {rune (charcode )};};};return charcode ,_ecg .Font .CharcodesToUnicode (_gdb );
|
|
};_feab :=_ecg ._bbc .CharcodesToUnicode (_gdb );_ed ,_ :=_ecg .Font .RunesToCharcodeBytes (_feab );_def :=_ecg .Font .BytesToCharcodes (_ed );_ab :=charcode ;if len (_def )> 0&&_def [0]!=0{_ab =_def [0];};return _ab ,_feab ;};func (_fecg *TextState )ProcDQ (data []byte ,aw ,ac float64 ,ctx Context ){_fecg .Tw =aw ;
|
|
_fecg .Tc =ac ;_fecg .ProcQ (data ,ctx );};type Context interface{Push ();Pop ();Matrix ()_ba .Matrix ;SetMatrix (_gb _ba .Matrix );Translate (_df ,_af float64 );Scale (_f ,_bgb float64 );Rotate (_de float64 );MoveTo (_ggd ,_eee float64 );LineTo (_gf ,_db float64 );
|
|
CubicTo (_fa ,_gbg ,_ad ,_cb ,_gfa ,_deg float64 );QuadraticTo (_fe ,_dgg ,_gbgf ,_be float64 );NewSubPath ();ClosePath ();ClearPath ();Clip ();ClipPreserve ();ResetClip ();LineWidth ()float64 ;SetLineWidth (_aa float64 );SetLineCap (_dfe LineCap );SetLineJoin (_bd LineJoin );
|
|
SetDash (_ecc ...float64 );SetDashOffset (_fec float64 );Fill ();FillPreserve ();Stroke ();StrokePreserve ();SetRGBA (_fad ,_adb ,_dee ,_ce float64 );SetFillRGBA (_ced ,_gfc ,_bea ,_ga float64 );SetFillStyle (_aaa Pattern );SetFillRule (_bf FillRule );
|
|
SetStrokeRGBA (_gdf ,_ef ,_gc ,_fc float64 );SetStrokeStyle (_fcb Pattern );FillPattern ()Pattern ;StrokePattern ()Pattern ;TextState ()*TextState ;DrawString (_bba string ,_bgd _c .Face ,_gfaa ,_dd float64 );MeasureString (_fg string ,_gbc _c .Face )(_cc ,_bdd float64 );
|
|
DrawRectangle (_fb ,_ae ,_eg ,_gba float64 );DrawImage (_aeg _d .Image ,_egf ,_ceb int );DrawImageAnchored (_fgf _d .Image ,_gaa ,_ac int ,_cf ,_aeb float64 );Height ()int ;Width ()int ;};func (_gdc *TextFont )GetCharMetrics (code _e .CharCode )(float64 ,float64 ,bool ){if _ade ,_fbf :=_gdc .Font .GetCharMetrics (code );
|
|
_fbf &&_ade .Wx !=0{return _ade .Wx ,_ade .Wy ,_fbf ;};if _gdc ._bbc ==nil {return 0,0,false ;};_bae ,_gdba :=_gdc ._bbc .GetCharMetrics (code );return _bae .Wx ,_bae .Wy ,_gdba &&_bae .Wx !=0;};func (_beg *TextFont )BytesToCharcodes (data []byte )[]_e .CharCode {if _beg ._bbc !=nil {return _beg ._bbc .BytesToCharcodes (data );
|
|
};return _beg .Font .BytesToCharcodes (data );};func (_defg *TextState )Translate (tx ,ty float64 ){_defg .Tm =_defg .Tm .Mult (_ba .TranslationMatrix (tx ,ty ));};type LineCap int ;type Gradient interface{Pattern ;AddColorStop (_bb float64 ,_ee _g .Color );
|
|
};func (_bgbc *TextState )ProcQ (data []byte ,ctx Context ){_bgbc .ProcTStar ();_bgbc .ProcTj (data ,ctx )};const (TextRenderingModeFill TextRenderingMode =iota ;TextRenderingModeStroke ;TextRenderingModeFillStroke ;TextRenderingModeInvisible ;TextRenderingModeFillClip ;
|
|
TextRenderingModeStrokeClip ;TextRenderingModeFillStrokeClip ;TextRenderingModeClip ;);func NewTextFontFromPath (filePath string ,size float64 )(*TextFont ,error ){_cce ,_aff :=_gd .NewPdfFontFromTTFFile (filePath );if _aff !=nil {return nil ,_aff ;};return NewTextFont (_cce ,size );
|
|
};func (_fea *TextFont )WithSize (size float64 ,originalFont *_gd .PdfFont )*TextFont {return &TextFont {Font :_fea .Font ,Size :size ,_gbga :_fea ._gbga ,_bbc :originalFont };};func (_bc *TextState )ProcTf (font *TextFont ){_bc .Tf =font };func (_fbe *TextState )ProcTStar (){_fbe .ProcTd (0,-_fbe .Tl )};
|
|
func (_gcc *TextState )ProcTD (tx ,ty float64 ){_gcc .Tl =-ty ;_gcc .ProcTd (tx ,ty )};type TextRenderingMode int ;type TextState struct{Tc float64 ;Tw float64 ;Th float64 ;Tl float64 ;Tf *TextFont ;Ts float64 ;Tm _ba .Matrix ;Tlm _ba .Matrix ;Tr TextRenderingMode ;
|
|
GlobalScale float64 ;};func (_eeg *TextState )ProcTm (a ,b ,c ,d ,e ,f float64 ){_eeg .Tm =_ba .NewMatrix (a ,b ,c ,d ,e ,f );_eeg .Tlm =_eeg .Tm .Clone ();};type FillRule int ;func NewTextState ()TextState {return TextState {Th :100,Tm :_ba .IdentityMatrix (),Tlm :_ba .IdentityMatrix ()};
|
|
};func (_fd *TextFont )NewFace (size float64 )_c .Face {return _gg .NewFace (_fd ._gbga ,&_gg .Options {Size :size });};func (_ca *TextState )Reset (){_ca .Tm =_ba .IdentityMatrix ();_ca .Tlm =_ba .IdentityMatrix ()};func (_fba *TextState )ProcTd (tx ,ty float64 ){_fba .Tlm .Concat (_ba .TranslationMatrix (tx ,ty ));
|
|
_fba .Tm =_fba .Tlm .Clone ();};type Pattern interface{ColorAt (_bg ,_dg int )_g .Color ;};const (FillRuleWinding FillRule =iota ;FillRuleEvenOdd ;);func (_ff *TextState )ProcTj (data []byte ,ctx Context ){_fce :=_ff .Tf .Size ;_gbd :=_ff .Th /100.0;_dfc :=_ff .GlobalScale ;
|
|
_cd :=_ba .NewMatrix (_fce *_gbd ,0,0,_fce ,0,_ff .Ts );_fcbf :=ctx .Matrix ();_ddf :=_fcbf .Clone ().Mult (_ff .Tm .Clone ().Mult (_cd )).ScalingFactorY ();_ddb :=_ff .Tf .NewFace (_ddf );_fbag :=_ff .Tf .BytesToCharcodes (data );for _ ,_dff :=range _fbag {_eccc ,_ada :=_ff .Tf .CharcodeToRunes (_dff );
|
|
_aec :=string (_ada );if _aec =="\u0000"{continue ;};_ea :=_fcbf .Clone ().Mult (_ff .Tm .Clone ().Mult (_cd ));_dfb :=_ea .ScalingFactorY ();_ea =_ea .Scale (1/_dfb ,-1/_dfb );if _ff .Tr !=TextRenderingModeInvisible {ctx .SetMatrix (_ea );ctx .DrawString (_aec ,_ddb ,0,0);
|
|
ctx .SetMatrix (_fcbf );};_gbcg :=0.0;if _aec =="\u0020"{_gbcg =_ff .Tw ;};_gfb ,_ ,_fac :=_ff .Tf .GetCharMetrics (_eccc );if _fac {_gfb =_gfb *0.001*_fce ;}else {_gfb ,_ =ctx .MeasureString (_aec ,_ddb );_gfb =_gfb /_dfc ;};_fdba :=(_gfb +_ff .Tc +_gbcg )*_gbd ;
|
|
_ff .Tm =_ff .Tm .Mult (_ba .TranslationMatrix (_fdba ,0));};};type LineJoin int ;const (LineJoinRound LineJoin =iota ;LineJoinBevel ;);func NewTextFont (font *_gd .PdfFont ,size float64 )(*TextFont ,error ){_gca :=font .FontDescriptor ();if _gca ==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");
|
|
};_afe ,_aag :=_ec .GetStream (_gca .FontFile2 );if !_aag {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");};_cec ,_fcg :=_ec .DecodeStream (_afe );
|
|
if _fcg !=nil {return nil ,_fcg ;};_gge ,_fcg :=_gg .Parse (_cec );if _fcg !=nil {return nil ,_fcg ;};return &TextFont {Font :font ,Size :size ,_gbga :_gge },nil ;};const (LineCapRound LineCap =iota ;LineCapButt ;LineCapSquare ;); |