mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-29 13:48:54 +08:00
12 lines
6.4 KiB
Go
12 lines
6.4 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 (_a "errors";_b "github.com/golang/freetype/truetype";_ae "github.com/unidoc/unipdf/v3/core";_cf "github.com/unidoc/unipdf/v3/internal/textencoding";_g "github.com/unidoc/unipdf/v3/internal/transform";_d "github.com/unidoc/unipdf/v3/model";_ef "golang.org/x/image/font";_ab "image";_c "image/color";);type Context interface{Push ();Pop ();Matrix ()_g .Matrix ;SetMatrix (_dd _g .Matrix );Translate (_ag ,_be float64 );Scale (_dc ,_fe float64 );Rotate (_bee float64 );MoveTo (_bc ,_ed float64 );LineTo (_ac ,_cd float64 );CubicTo (_dcd ,_ca ,_gf ,_ff ,_fd ,_ged float64 );QuadraticTo (_df ,_ad ,_eg ,_gg float64 );NewSubPath ();ClosePath ();ClearPath ();Clip ();ClipPreserve ();ResetClip ();LineWidth ()float64 ;SetLineWidth (_bd float64 );SetLineCap (_aga LineCap );SetLineJoin (_age LineJoin );SetDash (_dfa ...float64 );SetDashOffset (_bb float64 );Fill ();FillPreserve ();Stroke ();StrokePreserve ();SetRGBA (_cdd ,_fc ,_bdg ,_af float64 );SetFillRGBA (_bbf ,_ga ,_bbd ,_ffd float64 );SetFillStyle (_cdb Pattern );SetFillRule (_ce FillRule );SetStrokeRGBA (_afa ,_ddf ,_adg ,_abe float64 );SetStrokeStyle (_bg Pattern );TextState ()*TextState ;DrawString (_ace string ,_deb ,_bbdd float64 );MeasureString (_ec string )(_bef ,_cfe float64 );DrawRectangle (_cc ,_fda ,_bf ,_ede float64 );DrawImage (_da _ab .Image ,_cef ,_eb int );DrawImageAnchored (_dcda _ab .Image ,_fb ,_caa int ,_eca ,_bfb float64 );Height ()int ;Width ()int ;};type TextFont struct{Font *_d .PdfFont ;Face _ef .Face ;Size float64 ;_ea *_b .Font ;_cfef *_d .PdfFont ;};func (_aee *TextFont )WithSize (size float64 ,originalFont *_d .PdfFont )*TextFont {if size <=1{size =10;};return &TextFont {Font :_aee .Font ,Face :_b .NewFace (_aee ._ea ,&_b .Options {Size :size }),Size :size ,_ea :_aee ._ea ,_cfef :originalFont };};func (_ade *TextState )ProcDQ (data []byte ,aw ,ac float64 ,ctx Context ){_ade .Tw =aw ;_ade .Tc =ac ;_ade .ProcQ (data ,ctx );};func (_gaa *TextState )Translate (tx ,ty float64 ){_gaa .Tm =_g .TranslationMatrix (tx ,ty ).Mult (_gaa .Tm );};type TextState struct{Tc float64 ;Tw float64 ;Th float64 ;Tl float64 ;Tf *TextFont ;Ts float64 ;Tm _g .Matrix ;Tlm _g .Matrix ;};func NewTextFontFromPath (filePath string ,size float64 )(*TextFont ,error ){_dfe ,_cb :=_d .NewPdfFontFromTTFFile (filePath );if _cb !=nil {return nil ,_cb ;};return NewTextFont (_dfe ,size );};func NewTextState ()*TextState {return &TextState {Th :100,Tm :_g .IdentityMatrix (),Tlm :_g .IdentityMatrix ()};};type LineJoin int ;func (_bca *TextState )ProcTd (tx ,ty float64 ){_bca .Tlm .Concat (_g .TranslationMatrix (tx ,-ty ));_bca .Tm =_bca .Tlm .Clone ();};func (_fbd *TextFont )GetRuneMetrics (r rune )(float64 ,float64 ,bool ){if _cbd ,_cgd :=_fbd .Font .GetRuneMetrics (r );_cgd &&_cbd .Wx !=0{return _cbd .Wx ,_cbd .Wy ,_cgd ;};if _fbd ._cfef ==nil {return 0,0,false ;};_abg ,_aea :=_fbd ._cfef .GetRuneMetrics (r );return _abg .Wx ,_abg .Wy ,_aea &&_abg .Wx !=0;};const (LineCapRound LineCap =iota ;LineCapButt ;LineCapSquare ;);func (_bfg *TextFont )BytesToCharcodes (data []byte )[]_cf .CharCode {if _bfg ._cfef !=nil {return _bfg ._cfef .BytesToCharcodes (data );};return _bfg .Font .BytesToCharcodes (data );};type LineCap int ;func (_dfb *TextState )ProcQ (data []byte ,ctx Context ){_dfb .ProcTStar ();_dfb .ProcTj (data ,ctx )};func (_gd *TextFont )CharcodesToUnicode (charcodes []_cf .CharCode )[]rune {if _gd ._cfef !=nil {return _gd ._cfef .CharcodesToUnicode (charcodes );};return _gd .Font .CharcodesToUnicode (charcodes );};func (_dee *TextState )Reset (){_dee .Tm =_g .IdentityMatrix ();_dee .Tlm =_g .IdentityMatrix ()};func (_caae *TextState )ProcTStar (){_caae .ProcTd (0,-_caae .Tl )};type FillRule int ;func (_bdb *TextState )ProcTm (a ,b ,c ,d ,e ,f float64 ){_bdb .Tm =_g .NewMatrix (a ,b ,c ,d ,e ,-f );_bdb .Tlm =_bdb .Tm .Clone ();};func (_ffb *TextState )ProcTj (data []byte ,ctx Context ){_ceb :=_ffb .Tf .Size ;_cad :=_ffb .Th /100.0;_fdb :=_g .NewMatrix (_ceb *_cad ,0,0,_ceb ,0,_ffb .Ts );_ba :=_ffb .Tf .CharcodesToUnicode (_ffb .Tf .BytesToCharcodes (data ));for _ ,_gec :=range _ba {if _gec =='\x00'{continue ;};_ggg :=_ffb .Tm .Clone ();_ffb .Tm .Concat (_fdb );_fbg ,_fbf :=_ffb .Tm .Transform (0,0);ctx .Scale (1,-1);ctx .DrawString (string (_gec ),_fbg ,_fbf );ctx .Scale (1,-1);_fa :=0.0;if _gec ==' '{_fa =_ffb .Tw ;};var _gedb float64 ;if _daf ,_ ,_cgf :=_ffb .Tf .GetRuneMetrics (_gec );_cgf {_gedb =_daf *0.001*_ceb ;}else {_gedb ,_ =ctx .MeasureString (string (_gec ));};_ebc :=(_gedb +_ffb .Tc +_fa )*_cad ;_ffb .Tm =_g .TranslationMatrix (_ebc ,0).Mult (_ggg );};};func (_db *TextState )ProcTf (font *TextFont ){_db .Tf =font };const (LineJoinRound LineJoin =iota ;LineJoinBevel ;);func NewTextFont (font *_d .PdfFont ,size float64 )(*TextFont ,error ){_fec :=font .FontDescriptor ();if _fec ==nil {return nil ,_a .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");};_cfec ,_dg :=_ae .GetStream (_fec .FontFile2 );if !_dg {return nil ,_a .New ("\u006di\u0073\u0073\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u0020f\u0069\u006c\u0065\u0020\u0073\u0074\u0072\u0065\u0061\u006d");};_bcc ,_bfd :=_ae .DecodeStream (_cfec );if _bfd !=nil {return nil ,_bfd ;};_gfa ,_bfd :=_b .Parse (_bcc );if _bfd !=nil {return nil ,_bfd ;};if size <=1{size =10;};return &TextFont {Font :font ,Face :_b .NewFace (_gfa ,&_b .Options {Size :size }),Size :size ,_ea :_gfa },nil ;};func (_bgf *TextState )ProcTD (tx ,ty float64 ){_bgf .Tl =-ty ;_bgf .ProcTd (tx ,ty )};const (FillRuleWinding FillRule =iota ;FillRuleEvenOdd ;);type Gradient interface{Pattern ;AddColorStop (_f float64 ,_aa _c .Color );};type Pattern interface{ColorAt (_de ,_ge int )_c .Color ;};func (_afc *TextFont )GetCharMetrics (code _cf .CharCode )(float64 ,float64 ,bool ){if _bfa ,_gdc :=_afc .Font .GetCharMetrics (code );_gdc &&_bfa .Wx !=0{return _bfa .Wx ,_bfa .Wy ,_gdc ;};if _afc ._cfef ==nil {return 0,0,false ;};_cg ,_fg :=_afc ._cfef .GetCharMetrics (code );return _cg .Wx ,_cg .Wy ,_fg &&_cg .Wx !=0;}; |