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 (_e "errors";_ec "github.com/unidoc/freetype/truetype";_f "github.com/unidoc/unipdf/v3/core";_b "github.com/unidoc/unipdf/v3/internal/textencoding";_ca "github.com/unidoc/unipdf/v3/internal/transform";_cg "github.com/unidoc/unipdf/v3/model";
|
|
_ef "golang.org/x/image/font";_a "image";_c "image/color";);type TextRenderingMode int ;func NewTextFont (font *_cg .PdfFont ,size float64 )(*TextFont ,error ){_gab :=font .FontDescriptor ();if _gab ==nil {return nil ,_e .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");
|
|
};_aag ,_gbc :=_f .GetStream (_gab .FontFile2 );if !_gbc {return nil ,_e .New ("\u006di\u0073\u0073\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u0020f\u0069\u006c\u0065\u0020\u0073\u0074\u0072\u0065\u0061\u006d");};_fbg ,_ggg :=_f .DecodeStream (_aag );
|
|
if _ggg !=nil {return nil ,_ggg ;};_bgd ,_ggg :=_ec .Parse (_fbg );if _ggg !=nil {return nil ,_ggg ;};return &TextFont {Font :font ,Size :size ,_ga :_bgd },nil ;};type Context interface{Push ();Pop ();Matrix ()_ca .Matrix ;SetMatrix (_bb _ca .Matrix );
|
|
Translate (_d ,_df float64 );Scale (_dc ,_gb float64 );Rotate (_ed float64 );MoveTo (_cf ,_ad float64 );LineTo (_ade ,_bd float64 );CubicTo (_bg ,_cfd ,_ea ,_dg ,_ee ,_fa float64 );QuadraticTo (_ceg ,_aa ,_dfd ,_bf float64 );NewSubPath ();ClosePath ();
|
|
ClearPath ();Clip ();ClipPreserve ();ResetClip ();LineWidth ()float64 ;SetLineWidth (_bfd float64 );SetLineCap (_de LineCap );SetLineJoin (_ff LineJoin );SetDash (_ag ...float64 );SetDashOffset (_fg float64 );Fill ();FillPreserve ();Stroke ();StrokePreserve ();
|
|
SetRGBA (_ge ,_dd ,_gc ,_ba float64 );SetFillRGBA (_bae ,_eed ,_gf ,_ceb float64 );SetFillStyle (_eg Pattern );SetFillRule (_fc FillRule );SetStrokeRGBA (_cea ,_cce ,_da ,_eae float64 );SetStrokeStyle (_cgb Pattern );FillPattern ()Pattern ;StrokePattern ()Pattern ;
|
|
TextState ()*TextState ;DrawString (_cca string ,_adec _ef .Face ,_gcc ,_fb float64 );MeasureString (_gfe string ,_ged _ef .Face )(_ece ,_bgf float64 );DrawRectangle (_dgg ,_cb ,_ac ,_dga float64 );DrawImage (_fe _a .Image ,_bcd ,_cd int );DrawImageAnchored (_cfb _a .Image ,_efb ,_cde int ,_bce ,_gg float64 );
|
|
Height ()int ;Width ()int ;};func (_feg *TextFont )WithSize (size float64 ,originalFont *_cg .PdfFont )*TextFont {return &TextFont {Font :_feg .Font ,Size :size ,_ga :_feg ._ga ,_af :originalFont };};func NewTextState ()TextState {return TextState {Th :100,Tm :_ca .IdentityMatrix (),Tlm :_ca .IdentityMatrix ()};
|
|
};const (FillRuleWinding FillRule =iota ;FillRuleEvenOdd ;);func (_dbaf *TextState )ProcTd (tx ,ty float64 ){_dbaf .Tlm .Concat (_ca .TranslationMatrix (tx ,ty ));_dbaf .Tm =_dbaf .Tlm .Clone ();};func NewTextFontFromPath (filePath string ,size float64 )(*TextFont ,error ){_dcf ,_bad :=_cg .NewPdfFontFromTTFFile (filePath );
|
|
if _bad !=nil {return nil ,_bad ;};return NewTextFont (_dcf ,size );};type Gradient interface{Pattern ;AddColorStop (_cae float64 ,_bc _c .Color );};type TextFont struct{Font *_cg .PdfFont ;Size float64 ;_ga *_ec .Font ;_af *_cg .PdfFont ;};func (_gea *TextFont )NewFace (size float64 )_ef .Face {return _ec .NewFace (_gea ._ga ,&_ec .Options {Size :size });
|
|
};func (_bcb *TextState )ProcTStar (){_bcb .ProcTd (0,-_bcb .Tl )};func (_aba *TextState )ProcTf (font *TextFont ){_aba .Tf =font };func (_fed *TextState )ProcQ (data []byte ,ctx Context ){_fed .ProcTStar ();_fed .ProcTj (data ,ctx )};func (_dba *TextState )ProcTm (a ,b ,c ,d ,e ,f float64 ){_dba .Tm =_ca .NewMatrix (a ,b ,c ,d ,e ,f );
|
|
_dba .Tlm =_dba .Tm .Clone ();};type TextState struct{Tc float64 ;Tw float64 ;Th float64 ;Tl float64 ;Tf *TextFont ;Ts float64 ;Tm _ca .Matrix ;Tlm _ca .Matrix ;Tr TextRenderingMode ;GlobalScale float64 ;};func (_def *TextState )ProcTD (tx ,ty float64 ){_def .Tl =-ty ;
|
|
_def .ProcTd (tx ,ty )};func (_eac *TextState )Reset (){_eac .Tm =_ca .IdentityMatrix ();_eac .Tlm =_ca .IdentityMatrix ()};func (_fca *TextState )Translate (tx ,ty float64 ){_fca .Tm =_fca .Tm .Mult (_ca .TranslationMatrix (tx ,ty ));};type Pattern interface{ColorAt (_ce ,_cc int )_c .Color ;
|
|
};func (_add *TextFont )GetCharMetrics (code _b .CharCode )(float64 ,float64 ,bool ){if _ddb ,_adg :=_add .Font .GetCharMetrics (code );_adg &&_ddb .Wx !=0{return _ddb .Wx ,_ddb .Wy ,_adg ;};if _add ._af ==nil {return 0,0,false ;};_fgb ,_bbe :=_add ._af .GetCharMetrics (code );
|
|
return _fgb .Wx ,_fgb .Wy ,_bbe &&_fgb .Wx !=0;};const (LineJoinRound LineJoin =iota ;LineJoinBevel ;);type LineCap int ;func (_bca *TextFont )BytesToCharcodes (data []byte )[]_b .CharCode {if _bca ._af !=nil {return _bca ._af .BytesToCharcodes (data );
|
|
};return _bca .Font .BytesToCharcodes (data );};func (_gag *TextState )ProcDQ (data []byte ,aw ,ac float64 ,ctx Context ){_gag .Tw =aw ;_gag .Tc =ac ;_gag .ProcQ (data ,ctx );};const (TextRenderingModeFill TextRenderingMode =iota ;TextRenderingModeStroke ;
|
|
TextRenderingModeFillStroke ;TextRenderingModeInvisible ;TextRenderingModeFillClip ;TextRenderingModeStrokeClip ;TextRenderingModeFillStrokeClip ;TextRenderingModeClip ;);const (LineCapRound LineCap =iota ;LineCapButt ;LineCapSquare ;);type FillRule int ;
|
|
func (_cda *TextState )ProcTj (data []byte ,ctx Context ){_fee :=_cda .Tf .Size ;_ega :=_cda .Th /100.0;_gggd :=_cda .GlobalScale ;_aafb :=_ca .NewMatrix (_fee *_ega ,0,0,_fee ,0,_cda .Ts );_fd :=ctx .Matrix ();_cac :=_fd .Clone ().Mult (_cda .Tm .Clone ().Mult (_aafb )).ScalingFactorY ();
|
|
_egab :=_cda .Tf .NewFace (_cac );_dec :=_cda .Tf .BytesToCharcodes (data );for _ ,_agg :=range _dec {_gd ,_aca :=_cda .Tf .CharcodeToRunes (_agg );_bdga :=string (_aca );if _bdga =="\u0000"{continue ;};_be :=_fd .Clone ().Mult (_cda .Tm .Clone ().Mult (_aafb ));
|
|
_dbf :=_be .ScalingFactorY ();_be =_be .Scale (1/_dbf ,-1/_dbf );if _cda .Tr !=TextRenderingModeInvisible {ctx .SetMatrix (_be );ctx .DrawString (_bdga ,_egab ,0,0);ctx .SetMatrix (_fd );};_bcaf :=0.0;if _bdga =="\u0020"{_bcaf =_cda .Tw ;};_deg ,_ ,_dgb :=_cda .Tf .GetCharMetrics (_gd );
|
|
if _dgb {_deg =_deg *0.001*_fee ;}else {_deg ,_ =ctx .MeasureString (_bdga ,_egab );_deg =_deg /_gggd ;};_ab :=(_deg +_cda .Tc +_bcaf )*_ega ;_cda .Tm =_cda .Tm .Mult (_ca .TranslationMatrix (_ab ,0));};};type LineJoin int ;func (_cbd *TextFont )CharcodeToRunes (charcode _b .CharCode )(_b .CharCode ,[]rune ){_cag :=[]_b .CharCode {charcode };
|
|
if _cbd ._af ==nil ||_cbd ._af ==_cbd .Font {if _cbd .Font .IsSimple ()&&_cbd ._ga !=nil {if _dfg :=_cbd ._ga .Index (rune (charcode ));_dfg > 0{return charcode ,[]rune {rune (charcode )};};};return charcode ,_cbd .Font .CharcodesToUnicode (_cag );};_fec :=_cbd ._af .CharcodesToUnicode (_cag );
|
|
_aaf ,_ :=_cbd .Font .RunesToCharcodeBytes (_fec );_db :=_cbd .Font .BytesToCharcodes (_aaf );_fgc :=charcode ;if len (_db )> 0&&_db [0]!=0{_fgc =_db [0];};return _fgc ,_fec ;}; |