mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 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 (_f "errors";_ed "github.com/golang/freetype/truetype";_a "github.com/unidoc/unipdf/v3/core";_e "github.com/unidoc/unipdf/v3/internal/textencoding";_d "github.com/unidoc/unipdf/v3/internal/transform";_ec "github.com/unidoc/unipdf/v3/model";
|
|
_g "golang.org/x/image/font";_bc "image";_b "image/color";);const (LineCapRound LineCap =iota ;LineCapButt ;LineCapSquare ;);func (_cda *TextState )Reset (){_cda .Tm =_d .IdentityMatrix ();_cda .Tlm =_d .IdentityMatrix ()};func (_efgc *TextFont )WithSize (size float64 ,originalFont *_ec .PdfFont )*TextFont {return &TextFont {Font :_efgc .Font ,Size :size ,_efg :_efgc ._efg ,_fc :originalFont };
|
|
};func (_ddd *TextFont )GetCharMetrics (code _e .CharCode )(float64 ,float64 ,bool ){if _deac ,_aeb :=_ddd .Font .GetCharMetrics (code );_aeb &&_deac .Wx !=0{return _deac .Wx ,_deac .Wy ,_aeb ;};if _ddd ._fc ==nil {return 0,0,false ;};_eaf ,_baea :=_ddd ._fc .GetCharMetrics (code );
|
|
return _eaf .Wx ,_eaf .Wy ,_baea &&_eaf .Wx !=0;};func (_faf *TextState )ProcTStar (){_faf .ProcTd (0,-_faf .Tl )};type TextRenderingMode int ;const (TextRenderingModeFill TextRenderingMode =iota ;TextRenderingModeStroke ;TextRenderingModeFillStroke ;TextRenderingModeInvisible ;
|
|
TextRenderingModeFillClip ;TextRenderingModeStrokeClip ;TextRenderingModeFillStrokeClip ;TextRenderingModeClip ;);func (_bee *TextFont )CharcodesToUnicode (charcodes []_e .CharCode )[]rune {if _bee ._fc !=nil {return _bee ._fc .CharcodesToUnicode (charcodes );
|
|
};return _bee .Font .CharcodesToUnicode (charcodes );};func (_cc *TextFont )BytesToCharcodes (data []byte )[]_e .CharCode {if _cc ._fc !=nil {return _cc ._fc .BytesToCharcodes (data );};return _cc .Font .BytesToCharcodes (data );};type LineCap int ;func NewTextState ()TextState {return TextState {Th :100,Tm :_d .IdentityMatrix (),Tlm :_d .IdentityMatrix ()};
|
|
};func (_da *TextState )ProcDQ (data []byte ,aw ,ac float64 ,ctx Context ){_da .Tw =aw ;_da .Tc =ac ;_da .ProcQ (data ,ctx );};func NewTextFontFromPath (filePath string ,size float64 )(*TextFont ,error ){_cg ,_gad :=_ec .NewPdfFontFromTTFFile (filePath );
|
|
if _gad !=nil {return nil ,_gad ;};return NewTextFont (_cg ,size );};type TextState struct{Tc float64 ;Tw float64 ;Th float64 ;Tl float64 ;Tf *TextFont ;Ts float64 ;Tm _d .Matrix ;Tlm _d .Matrix ;Tr TextRenderingMode ;GlobalScale float64 ;};type Gradient interface{Pattern ;
|
|
AddColorStop (_ae float64 ,_fe _b .Color );};func (_gdd *TextFont )NewFace (size float64 )_g .Face {return _ed .NewFace (_gdd ._efg ,&_ed .Options {Size :size });};type Context interface{Push ();Pop ();Matrix ()_d .Matrix ;SetMatrix (_gc _d .Matrix );Translate (_ga ,_ag float64 );
|
|
Scale (_ee ,_af float64 );Rotate (_bf float64 );MoveTo (_fd ,_ba float64 );LineTo (_edf ,_fef float64 );CubicTo (_cdg ,_gab ,_df ,_dd ,_cf ,_ce float64 );QuadraticTo (_ecc ,_ad ,_cea ,_db float64 );NewSubPath ();ClosePath ();ClearPath ();Clip ();ClipPreserve ();
|
|
ResetClip ();LineWidth ()float64 ;SetLineWidth (_ea float64 );SetLineCap (_cec LineCap );SetLineJoin (_ge LineJoin );SetDash (_dde ...float64 );SetDashOffset (_geg float64 );Fill ();FillPreserve ();Stroke ();StrokePreserve ();SetRGBA (_dc ,_aa ,_bab ,_dcd float64 );
|
|
SetFillRGBA (_de ,_ab ,_dbf ,_gea float64 );SetFillStyle (_eef Pattern );SetFillRule (_fed FillRule );SetStrokeRGBA (_ff ,_gec ,_bb ,_bae float64 );SetStrokeStyle (_eca Pattern );FillPattern ()Pattern ;StrokePattern ()Pattern ;TextState ()*TextState ;DrawString (_bdc string ,_gd _g .Face ,_bg ,_cdc float64 );
|
|
MeasureString (_fb string ,_gf _g .Face )(_afb ,_ecb float64 );DrawRectangle (_eg ,_egg ,_fbg ,_cff float64 );DrawImage (_aee _bc .Image ,_be ,_agc int );DrawImageAnchored (_dg _bc .Image ,_ef ,_agd int ,_bbd ,_gdf float64 );Height ()int ;Width ()int ;
|
|
};type TextFont struct{Font *_ec .PdfFont ;Size float64 ;_efg *_ed .Font ;_fc *_ec .PdfFont ;};const (LineJoinRound LineJoin =iota ;LineJoinBevel ;);func (_gbc *TextState )ProcTj (data []byte ,ctx Context ){_fdb :=_gbc .Tf .Size ;_gcg :=_gbc .Th /100.0;
|
|
_ccg :=_gbc .GlobalScale ;_bde :=_d .NewMatrix (_fdb *_gcg ,0,0,_fdb ,0,_gbc .Ts );_ecd :=ctx .Matrix ();_dgc :=_ecd .Clone ().Mult (_gbc .Tm .Clone ().Mult (_bde )).ScalingFactorY ();_bff :=_gbc .Tf .NewFace (_dgc );_aec :=_gbc .Tf .BytesToCharcodes (data );
|
|
_fbc :=_gbc .Tf .CharcodesToUnicode (_aec );for _fde ,_ccb :=range _fbc {if _ccb =='\x00'{continue ;};_ged :=_ecd .Clone ().Mult (_gbc .Tm .Clone ().Mult (_bde ));_ceb :=_ged .ScalingFactorY ();_ged =_ged .Scale (1/_ceb ,-1/_ceb );if _gbc .Tr !=TextRenderingModeInvisible {ctx .SetMatrix (_ged );
|
|
ctx .DrawString (string (_ccb ),_bff ,0,0);ctx .SetMatrix (_ecd );};_fab :=0.0;if _ccb ==' '{_fab =_gbc .Tw ;};_eee ,_ ,_fg :=_gbc .Tf .GetRuneMetrics (_ccb );if !_fg &&_fde < len (_aec ){_eee ,_ ,_fg =_gbc .Tf .GetCharMetrics (_aec [_fde ]);};if _fg {_eee =_eee *0.001*_fdb ;
|
|
}else {_eee ,_ =ctx .MeasureString (string (_ccb ),_bff );_eee =_eee /_ccg ;};_cca :=(_eee +_gbc .Tc +_fab )*_gcg ;_gbc .Tm =_gbc .Tm .Mult (_d .TranslationMatrix (_cca ,0));};};func (_cde *TextState )ProcTD (tx ,ty float64 ){_cde .Tl =-ty ;_cde .ProcTd (tx ,ty )};
|
|
type Pattern interface{ColorAt (_cd ,_bd int )_b .Color ;};func (_dbg *TextState )ProcQ (data []byte ,ctx Context ){_dbg .ProcTStar ();_dbg .ProcTj (data ,ctx )};const (FillRuleWinding FillRule =iota ;FillRuleEvenOdd ;);type FillRule int ;func (_ffa *TextState )ProcTm (a ,b ,c ,d ,e ,f float64 ){_ffa .Tm =_d .NewMatrix (a ,b ,c ,d ,e ,f );
|
|
_ffa .Tlm =_ffa .Tm .Clone ();};func (_aag *TextState )ProcTf (font *TextFont ){_aag .Tf =font };func (_gb *TextState )ProcTd (tx ,ty float64 ){_gb .Tlm .Concat (_d .TranslationMatrix (tx ,ty ));_gb .Tm =_gb .Tlm .Clone ();};func NewTextFont (font *_ec .PdfFont ,size float64 )(*TextFont ,error ){_ac :=font .FontDescriptor ();
|
|
if _ac ==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");};_eccd ,_baf :=_a .GetStream (_ac .FontFile2 );if !_baf {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");
|
|
};_fa ,_bea :=_a .DecodeStream (_eccd );if _bea !=nil {return nil ,_bea ;};_dea ,_bea :=_ed .Parse (_fa );if _bea !=nil {return nil ,_bea ;};return &TextFont {Font :font ,Size :size ,_efg :_dea },nil ;};func (_fcb *TextState )Translate (tx ,ty float64 ){_fcb .Tm =_fcb .Tm .Mult (_d .TranslationMatrix (tx ,ty ));
|
|
};type LineJoin int ;func (_gdg *TextFont )GetRuneMetrics (r rune )(float64 ,float64 ,bool ){if _def ,_eb :=_gdg .Font .GetRuneMetrics (r );_eb &&_def .Wx !=0{return _def .Wx ,_def .Wy ,_eb ;};if _gdg ._fc ==nil {return 0,0,false ;};_gcc ,_deg :=_gdg ._fc .GetRuneMetrics (r );
|
|
return _gcc .Wx ,_gcc .Wy ,_deg &&_gcc .Wx !=0;}; |