36 lines
7.1 KiB
Go
Raw Normal View History

2020-08-27 21:45:09 +00:00
//
// 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/
2022-07-13 21:28:43 +00:00
package context ;import (_g "errors";_fd "github.com/unidoc/freetype/truetype";_gf "github.com/unidoc/unipdf/v3/core";_cb "github.com/unidoc/unipdf/v3/internal/textencoding";_gb "github.com/unidoc/unipdf/v3/internal/transform";_gbe "github.com/unidoc/unipdf/v3/model";
_a "golang.org/x/image/font";_f "image";_c "image/color";);const (FillRuleWinding FillRule =iota ;FillRuleEvenOdd ;);type FillRule int ;func (_fec *TextState )ProcTd (tx ,ty float64 ){_fec .Tlm .Concat (_gb .TranslationMatrix (tx ,ty ));_fec .Tm =_fec .Tlm .Clone ();
};func (_aaea *TextFont )NewFace (size float64 )_a .Face {return _fd .NewFace (_aaea ._faf ,&_fd .Options {Size :size });};type LineJoin int ;func (_bfg *TextState )ProcTD (tx ,ty float64 ){_bfg .Tl =-ty ;_bfg .ProcTd (tx ,ty )};func (_dff *TextFont )WithSize (size float64 ,originalFont *_gbe .PdfFont )*TextFont {return &TextFont {Font :_dff .Font ,Size :size ,_faf :_dff ._faf ,_dge :originalFont };
};const (TextRenderingModeFill TextRenderingMode =iota ;TextRenderingModeStroke ;TextRenderingModeFillStroke ;TextRenderingModeInvisible ;TextRenderingModeFillClip ;TextRenderingModeStrokeClip ;TextRenderingModeFillStrokeClip ;TextRenderingModeClip ;);
type Pattern interface{ColorAt (_fc ,_ab int )_c .Color ;};type Context interface{Push ();Pop ();Matrix ()_gb .Matrix ;SetMatrix (_ced _gb .Matrix );Translate (_d ,_fdf float64 );Scale (_cf ,_e float64 );Rotate (_db float64 );MoveTo (_fa ,_ceg float64 );
LineTo (_dbf ,_gba float64 );CubicTo (_cdb ,_dbb ,_aa ,_df ,_gbc ,_abg float64 );QuadraticTo (_ef ,_ea ,_ad ,_cg float64 );NewSubPath ();ClosePath ();ClearPath ();Clip ();ClipPreserve ();ResetClip ();LineWidth ()float64 ;SetLineWidth (_ee float64 );SetLineCap (_efb LineCap );
SetLineJoin (_bb LineJoin );SetDash (_ge ...float64 );SetDashOffset (_eea float64 );Fill ();FillPreserve ();Stroke ();StrokePreserve ();SetRGBA (_eg ,_de ,_ec ,_aae float64 );SetFillRGBA (_dg ,_geb ,_bf ,_geg float64 );SetFillStyle (_dgd Pattern );SetFillRule (_eca FillRule );
SetStrokeRGBA (_eb ,_cbf ,_gc ,_gcf float64 );SetStrokeStyle (_cdg Pattern );FillPattern ()Pattern ;StrokePattern ()Pattern ;TextState ()*TextState ;DrawString (_dbc string ,_dc _a .Face ,_gee ,_gcfc float64 );MeasureString (_dfc string ,_dcg _a .Face )(_gca ,_gcc float64 );
DrawRectangle (_egc ,_deg ,_ebf ,_dcge float64 );DrawImage (_cc _f .Image ,_fdd ,_ag int );DrawImageAnchored (_dege _f .Image ,_ege ,_dbg int ,_eae ,_gce float64 );Height ()int ;Width ()int ;};type TextFont struct{Font *_gbe .PdfFont ;Size float64 ;_faf *_fd .Font ;
_dge *_gbe .PdfFont ;};func (_eef *TextState )ProcTStar (){_eef .ProcTd (0,-_eef .Tl )};type TextState struct{Tc float64 ;Tw float64 ;Th float64 ;Tl float64 ;Tf *TextFont ;Ts float64 ;Tm _gb .Matrix ;Tlm _gb .Matrix ;Tr TextRenderingMode ;GlobalScale float64 ;
};func (_bbg *TextState )ProcTj (data []byte ,ctx Context ){_fg :=_bbg .Tf .Size ;_efbb :=_bbg .Th /100.0;_ccc :=_bbg .GlobalScale ;_gbg :=_gb .NewMatrix (_fg *_efbb ,0,0,_fg ,0,_bbg .Ts );_fecc :=ctx .Matrix ();_ceb :=_fecc .Clone ().Mult (_bbg .Tm .Clone ().Mult (_gbg )).ScalingFactorY ();
_efg :=_bbg .Tf .NewFace (_ceb );_eeaf :=_bbg .Tf .BytesToCharcodes (data );for _ ,_cdc :=range _eeaf {_cdd ,_fbb :=_bbg .Tf .CharcodeToRunes (_cdc );_be :=string (_fbb );if _be =="\u0000"{continue ;};_cdcf :=_fecc .Clone ().Mult (_bbg .Tm .Clone ().Mult (_gbg ));
_cgd :=_cdcf .ScalingFactorY ();_cdcf =_cdcf .Scale (1/_cgd ,-1/_cgd );if _bbg .Tr !=TextRenderingModeInvisible {ctx .SetMatrix (_cdcf );ctx .DrawString (_be ,_efg ,0,0);ctx .SetMatrix (_fecc );};_cfg :=0.0;if _be =="\u0020"{_cfg =_bbg .Tw ;};_ded ,_ ,_aec :=_bbg .Tf .GetCharMetrics (_cdd );
if _aec {_ded =_ded *0.001*_fg ;}else {_ded ,_ =ctx .MeasureString (_be ,_efg );_ded =_ded /_ccc ;};_ga :=(_ded +_bbg .Tc +_cfg )*_efbb ;_bbg .Tm =_bbg .Tm .Mult (_gb .TranslationMatrix (_ga ,0));};};func NewTextState ()TextState {return TextState {Th :100,Tm :_gb .IdentityMatrix (),Tlm :_gb .IdentityMatrix ()};
};func NewTextFontFromPath (filePath string ,size float64 )(*TextFont ,error ){_fb ,_ba :=_gbe .NewPdfFontFromTTFFile (filePath );if _ba !=nil {return nil ,_ba ;};return NewTextFont (_fb ,size );};func (_addc *TextState )Translate (tx ,ty float64 ){_addc .Tm =_addc .Tm .Mult (_gb .TranslationMatrix (tx ,ty ));
};func (_gbf *TextState )ProcQ (data []byte ,ctx Context ){_gbf .ProcTStar ();_gbf .ProcTj (data ,ctx )};func NewTextFont (font *_gbe .PdfFont ,size float64 )(*TextFont ,error ){_cfc :=font .FontDescriptor ();if _cfc ==nil {return nil ,_g .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");
};_gg ,_fcf :=_gf .GetStream (_cfc .FontFile2 );if !_fcf {return nil ,_g .New ("\u006di\u0073\u0073\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u0020f\u0069\u006c\u0065\u0020\u0073\u0074\u0072\u0065\u0061\u006d");};_gfb ,_dfb :=_gf .DecodeStream (_gg );
if _dfb !=nil {return nil ,_dfb ;};_eab ,_dfb :=_fd .Parse (_gfb );if _dfb !=nil {return nil ,_dfb ;};return &TextFont {Font :font ,Size :size ,_faf :_eab },nil ;};func (_af *TextFont )CharcodeToRunes (charcode _cb .CharCode )(_cb .CharCode ,[]rune ){_add :=[]_cb .CharCode {charcode };
if _af ._dge ==nil ||_af ._dge ==_af .Font {if _af .Font .IsSimple ()&&_af ._faf !=nil {if _ae :=_af ._faf .Index (rune (charcode ));_ae > 0{return charcode ,[]rune {rune (charcode )};};};return charcode ,_af .Font .CharcodesToUnicode (_add );};_dcc :=_af ._dge .CharcodesToUnicode (_add );
_agd ,_ :=_af .Font .RunesToCharcodeBytes (_dcc );_ggc :=_af .Font .BytesToCharcodes (_agd );_gff :=charcode ;if len (_ggc )> 0&&_ggc [0]!=0{_gff =_ggc [0];};return _gff ,_dcc ;};const (LineJoinRound LineJoin =iota ;LineJoinBevel ;);type Gradient interface{Pattern ;
AddColorStop (_cd float64 ,_ce _c .Color );};type TextRenderingMode int ;const (LineCapRound LineCap =iota ;LineCapButt ;LineCapSquare ;);func (_dfbd *TextState )ProcTm (a ,b ,c ,d ,e ,f float64 ){_dfbd .Tm =_gb .NewMatrix (a ,b ,c ,d ,e ,f );_dfbd .Tlm =_dfbd .Tm .Clone ();
};func (_cedb *TextFont )GetCharMetrics (code _cb .CharCode )(float64 ,float64 ,bool ){if _afe ,_bbe :=_cedb .Font .GetCharMetrics (code );_bbe &&_afe .Wx !=0{return _afe .Wx ,_afe .Wy ,_bbe ;};if _cedb ._dge ==nil {return 0,0,false ;};_gfbe ,_bbee :=_cedb ._dge .GetCharMetrics (code );
return _gfbe .Wx ,_gfbe .Wy ,_bbee &&_gfbe .Wx !=0;};func (_afd *TextState )Reset (){_afd .Tm =_gb .IdentityMatrix ();_afd .Tlm =_gb .IdentityMatrix ()};func (_fe *TextFont )BytesToCharcodes (data []byte )[]_cb .CharCode {if _fe ._dge !=nil {return _fe ._dge .BytesToCharcodes (data );
};return _fe .Font .BytesToCharcodes (data );};func (_cdcc *TextState )ProcDQ (data []byte ,aw ,ac float64 ,ctx Context ){_cdcc .Tw =aw ;_cdcc .Tc =ac ;_cdcc .ProcQ (data ,ctx );};func (_aeb *TextState )ProcTf (font *TextFont ){_aeb .Tf =font };type LineCap int ;