2021-03-23 23:12:52 +00:00

35 lines
7.0 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 (_f "errors";_cg "github.com/golang/freetype/truetype";_be "github.com/unidoc/unipdf/v3/core";_ff "github.com/unidoc/unipdf/v3/internal/textencoding";_a "github.com/unidoc/unipdf/v3/internal/transform";_cf "github.com/unidoc/unipdf/v3/model";
_b "golang.org/x/image/font";_c "image";_g "image/color";);const (TextRenderingModeFill TextRenderingMode =iota ;TextRenderingModeStroke ;TextRenderingModeFillStroke ;TextRenderingModeInvisible ;TextRenderingModeFillClip ;TextRenderingModeStrokeClip ;TextRenderingModeFillStrokeClip ;
TextRenderingModeClip ;);func (_deg *TextState )ProcTf (font *TextFont ){_deg .Tf =font };func (_aec *TextState )ProcQ (data []byte ,ctx Context ){_aec .ProcTStar ();_aec .ProcTj (data ,ctx )};type TextState struct{Tc float64 ;Tw float64 ;Th float64 ;Tl float64 ;
Tf *TextFont ;Ts float64 ;Tm _a .Matrix ;Tlm _a .Matrix ;Tr TextRenderingMode ;GlobalScale float64 ;};func (_bgb *TextFont )GetCharMetrics (code _ff .CharCode )(float64 ,float64 ,bool ){if _ga ,_de :=_bgb .Font .GetCharMetrics (code );_de &&_ga .Wx !=0{return _ga .Wx ,_ga .Wy ,_de ;
};if _bgb ._bdc ==nil {return 0,0,false ;};_fbd ,_dd :=_bgb ._bdc .GetCharMetrics (code );return _fbd .Wx ,_fbd .Wy ,_dd &&_fbd .Wx !=0;};type TextRenderingMode int ;func (_cdf *TextState )ProcTd (tx ,ty float64 ){_cdf .Tlm .Concat (_a .TranslationMatrix (tx ,-ty ));
_cdf .Tm =_cdf .Tlm .Clone ();};const (LineJoinRound LineJoin =iota ;LineJoinBevel ;);type LineCap int ;const (LineCapRound LineCap =iota ;LineCapButt ;LineCapSquare ;);func NewTextFont (font *_cf .PdfFont ,size float64 )(*TextFont ,error ){_dbe :=font .FontDescriptor ();
if _dbe ==nil {return nil ,_f .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");};_dac ,_ed :=_be .GetStream (_dbe .FontFile2 );if !_ed {return nil ,_f .New ("\u006di\u0073\u0073\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u0020f\u0069\u006c\u0065\u0020\u0073\u0074\u0072\u0065\u0061\u006d");
};_eff ,_af :=_be .DecodeStream (_dac );if _af !=nil {return nil ,_af ;};_fadb ,_af :=_cg .Parse (_eff );if _af !=nil {return nil ,_af ;};return &TextFont {Font :font ,Size :size ,_bga :_fadb },nil ;};type Context interface{Push ();Pop ();Matrix ()_a .Matrix ;
SetMatrix (_ae _a .Matrix );Translate (_cff ,_db float64 );Scale (_cb ,_ee float64 );Rotate (_aeg float64 );MoveTo (_ecg ,_cbd float64 );LineTo (_aa ,_cbf float64 );CubicTo (_da ,_fa ,_bd ,_bg ,_dbb ,_dc float64 );QuadraticTo (_eg ,_fd ,_gf ,_gd float64 );
NewSubPath ();ClosePath ();ClearPath ();Clip ();ClipPreserve ();ResetClip ();LineWidth ()float64 ;SetLineWidth (_bf float64 );SetLineCap (_fb LineCap );SetLineJoin (_ad LineJoin );SetDash (_ecd ...float64 );SetDashOffset (_dae float64 );Fill ();FillPreserve ();
Stroke ();StrokePreserve ();SetRGBA (_eb ,_gb ,_fc ,_bc float64 );SetFillRGBA (_fad ,_ce ,_gbg ,_dbc float64 );SetFillStyle (_dg Pattern );SetFillRule (_fbg FillRule );SetStrokeRGBA (_fae ,_gc ,_fde ,_fca float64 );SetStrokeStyle (_fbf Pattern );FillPattern ()Pattern ;
StrokePattern ()Pattern ;TextState ()*TextState ;DrawString (_ea string ,_bfg _b .Face ,_ab ,_ceb float64 );MeasureString (_cbe string ,_ffb _b .Face )(_dgc ,_gg float64 );DrawRectangle (_aed ,_fcg ,_ba ,_cee float64 );DrawImage (_efe _c .Image ,_bfd ,_bcg int );
DrawImageAnchored (_fg _c .Image ,_caa ,_ebb int ,_cc ,_eeb float64 );Height ()int ;Width ()int ;};func (_gcc *TextState )ProcTj (data []byte ,ctx Context ){_deb :=_gcc .Tf .Size ;_bda :=_gcc .Th /100.0;_dab :=_gcc .GlobalScale ;_fbe :=_a .NewMatrix (_deb *_bda ,0,0,_deb ,0,_gcc .Ts );
_eaa :=ctx .Matrix ();_fba :=_eaa .Clone ().Mult (_gcc .Tm .Clone ().Mult (_fbe )).ScalingFactorY ();_dcc :=_gcc .Tf .NewFace (_fba );_bfgg :=_gcc .Tf .CharcodesToUnicode (_gcc .Tf .BytesToCharcodes (data ));for _ ,_dbbb :=range _bfgg {if _dbbb =='\x00'{continue ;
};_aaf :=_gcc .Tm .Clone ();_gcc .Tm .Concat (_fbe );if _gcc .Tr !=TextRenderingModeInvisible {_cda ,_dca :=_gcc .Tm .Transform (0,0);ctx .Scale (1/_dab ,-1/_dab );ctx .DrawString (string (_dbbb ),_dcc ,_cda *_dab ,_dca *_dab );ctx .Scale (_dab ,-_dab );
};_aedg :=0.0;if _dbbb ==' '{_aedg =_gcc .Tw ;};var _eebd float64 ;if _ced ,_ ,_ecc :=_gcc .Tf .GetRuneMetrics (_dbbb );_ecc {_eebd =_ced *0.001*_fba /_dab ;}else {_eebd ,_ =ctx .MeasureString (string (_dbbb ),_dcc );};_cfe :=(_eebd +_gcc .Tc +_aedg )*_bda ;
_gcc .Tm =_a .TranslationMatrix (_cfe ,0).Mult (_aaf );};};type FillRule int ;func (_fbb *TextState )ProcTm (a ,b ,c ,d ,e ,f float64 ){_fbb .Tm =_a .NewMatrix (a ,b ,c ,d ,e ,-f );_fbb .Tlm =_fbb .Tm .Clone ();};func (_abb *TextState )ProcTD (tx ,ty float64 ){_abb .Tl =-ty ;
_abb .ProcTd (tx ,ty )};func (_egc *TextState )Translate (tx ,ty float64 ){_egc .Tm =_a .TranslationMatrix (tx ,ty ).Mult (_egc .Tm );};func (_dgcf *TextFont )CharcodesToUnicode (charcodes []_ff .CharCode )[]rune {if _dgcf ._bdc !=nil {return _dgcf ._bdc .CharcodesToUnicode (charcodes );
};return _dgcf .Font .CharcodesToUnicode (charcodes );};func (_gcd *TextFont )BytesToCharcodes (data []byte )[]_ff .CharCode {if _gcd ._bdc !=nil {return _gcd ._bdc .BytesToCharcodes (data );};return _gcd .Font .BytesToCharcodes (data );};func (_efc *TextState )ProcDQ (data []byte ,aw ,ac float64 ,ctx Context ){_efc .Tw =aw ;
_efc .Tc =ac ;_efc .ProcQ (data ,ctx );};const (FillRuleWinding FillRule =iota ;FillRuleEvenOdd ;);type Pattern interface{ColorAt (_d ,_ec int )_g .Color ;};func (_dce *TextState )ProcTStar (){_dce .ProcTd (0,-_dce .Tl )};func NewTextFontFromPath (filePath string ,size float64 )(*TextFont ,error ){_bca ,_cec :=_cf .NewPdfFontFromTTFFile (filePath );
if _cec !=nil {return nil ,_cec ;};return NewTextFont (_bca ,size );};type LineJoin int ;type Gradient interface{Pattern ;AddColorStop (_ef float64 ,_ca _g .Color );};func NewTextState ()TextState {return TextState {Th :100,Tm :_a .IdentityMatrix (),Tlm :_a .IdentityMatrix ()};
};func (_cd *TextFont )NewFace (size float64 )_b .Face {return _cg .NewFace (_cd ._bga ,&_cg .Options {Size :size });};func (_dge *TextFont )GetRuneMetrics (r rune )(float64 ,float64 ,bool ){if _bea ,_adb :=_dge .Font .GetRuneMetrics (r );_adb &&_bea .Wx !=0{return _bea .Wx ,_bea .Wy ,_adb ;
};if _dge ._bdc ==nil {return 0,0,false ;};_bcf ,_gbgg :=_dge ._bdc .GetRuneMetrics (r );return _bcf .Wx ,_bcf .Wy ,_gbgg &&_bcf .Wx !=0;};func (_cge *TextFont )WithSize (size float64 ,originalFont *_cf .PdfFont )*TextFont {return &TextFont {Font :_cge .Font ,Size :size ,_bga :_cge ._bga ,_bdc :originalFont };
};type TextFont struct{Font *_cf .PdfFont ;Size float64 ;_bga *_cg .Font ;_bdc *_cf .PdfFont ;};func (_fe *TextState )Reset (){_fe .Tm =_a .IdentityMatrix ();_fe .Tlm =_a .IdentityMatrix ()};