aboutsummaryrefslogtreecommitdiff
path: root/unipdf/render/internal/context/context.go
blob: 5d5a57ab0c63b90358d2c6d2d9509a66c49523d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// 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/unidoc/freetype/truetype";_gf "github.com/unidoc/unipdf/v4/core";_fe "github.com/unidoc/unipdf/v4/internal/cmap";_eg "github.com/unidoc/unipdf/v4/internal/textencoding";_aa "github.com/unidoc/unipdf/v4/internal/transform";
_cd "github.com/unidoc/unipdf/v4/model";_ad "golang.org/x/image/font";_g "image";_c "image/color";_cf "strconv";_f "strings";);func (_bgg *TextFont )NewFace (size float64 )_ad .Face {return _b .NewFace (_bgg ._eab ,&_b .Options {Size :size });};type TextFont struct{Font *_cd .PdfFont ;
Size float64 ;_eab *_b .Font ;_dca *_cd .PdfFont ;};const (FillRuleWinding FillRule =iota ;FillRuleEvenOdd ;);type Context interface{Push ();Pop ();Matrix ()_aa .Matrix ;SetMatrix (_ac _aa .Matrix );Translate (_aaa ,_ae float64 );Scale (_d ,_df float64 );
Rotate (_ag float64 );MoveTo (_agd ,_ec float64 );LineTo (_bfa ,_ee float64 );CubicTo (_ea ,_fd ,_gd ,_dc ,_gfb ,_ge float64 );QuadraticTo (_bd ,_ef ,_fg ,_aab float64 );NewSubPath ();ClosePath ();ClearPath ();Clip ();ClipPreserve ();ResetClip ();LineWidth ()float64 ;
SetLineWidth (_da float64 );SetLineCap (_dg LineCap );SetLineJoin (_ed LineJoin );SetDash (_cc ...float64 );SetDashOffset (_gff float64 );Fill ();FillPreserve ();Stroke ();StrokePreserve ();SetRGBA (_fdc ,_gg ,_gef ,_bb float64 );SetFillRGBA (_ccf ,_fa ,_cg ,_ga float64 );
SetFillStyle (_fcf Pattern );SetFillRule (_geg FillRule );SetStrokeRGBA (_gc ,_gcf ,_bdc ,_fea float64 );SetStrokeStyle (_ede Pattern );FillPattern ()Pattern ;StrokePattern ()Pattern ;TextState ()*TextState ;DrawString (_ab string ,_bcf _ad .Face ,_add ,_egg float64 );
MeasureString (_bde string ,_eb _ad .Face )(_bcd ,_gde float64 );DrawRectangle (_eca ,_cgd ,_ged ,_cfc float64 );DrawImage (_ff _g .Image ,_gge ,_egf int );DrawImageAnchored (_aee _g .Image ,_agg ,_fb int ,_ebe ,_bfac float64 );Height ()int ;Width ()int ;
};const (LineJoinRound LineJoin =iota ;LineJoinBevel ;);type TextRenderingMode int ;func (_fdf *TextState )ProcTm (a ,b ,c ,d ,e ,f float64 ){_fdf .Tm =_aa .NewMatrix (a ,b ,c ,d ,e ,f );_fdf .Tlm =_fdf .Tm .Clone ();};type TextState struct{Tc float64 ;
Tw float64 ;Th float64 ;Tl float64 ;Tf *TextFont ;Ts float64 ;Tm _aa .Matrix ;Tlm _aa .Matrix ;Tr TextRenderingMode ;GlobalScale float64 ;};func (_bga *TextFont )GetCharMetrics (code _eg .CharCode )(float64 ,float64 ,bool ){if _efb ,_afg :=_bga .Font .GetCharMetrics (code );
_afg &&_efb .Wx !=0{return _efb .Wx ,_efb .Wy ,_afg ;};if _bga ._dca ==nil {return 0,0,false ;};_ggc ,_fbc :=_bga ._dca .GetCharMetrics (code );return _ggc .Wx ,_ggc .Wy ,_fbc &&_ggc .Wx !=0;};func (_cdab *TextState )ProcTf (font *TextFont ){_cdab .Tf =font };
const (TextRenderingModeFill TextRenderingMode =iota ;TextRenderingModeStroke ;TextRenderingModeFillStroke ;TextRenderingModeInvisible ;TextRenderingModeFillClip ;TextRenderingModeStrokeClip ;TextRenderingModeFillStrokeClip ;TextRenderingModeClip ;);func NewTextFont (font *_cd .PdfFont ,size float64 )(*TextFont ,error ){_bg :=font .FontDescriptor ();
if _bg ==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");};_bcc ,_bge :=_gf .GetStream (_bg .FontFile2 );if !_bge {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");
};_aeec ,_bce :=_gf .DecodeStream (_bcc );if _bce !=nil {return nil ,_bce ;};_daa ,_bce :=_b .Parse (_aeec );if _bce !=nil {return nil ,_bce ;};_bdd :=font .FontDescriptor ().FontName .String ();_adc :=len (_bdd )> 7&&_bdd [6]=='+';if _bg .Flags !=nil {_gdd ,_efa :=_cf .Atoi (_bg .Flags .String ());
if _efa ==nil &&_gdd ==32{_adc =false ;};};if !_daa .HasCmap ()&&(!_f .Contains (font .Encoder ().String (),"\u0049d\u0065\u006e\u0074\u0069\u0074\u0079-")||!_adc ){return nil ,_a .New ("\u006e\u006f c\u006d\u0061\u0070 \u0061\u006e\u0064\u0020enc\u006fdi\u006e\u0067\u0020\u0069\u0073\u0020\u006eot\u0020\u0069\u0064\u0065\u006e\u0074\u0069t\u0079");
};return &TextFont {Font :font ,Size :size ,_eab :_daa },nil ;};func (_dde *TextState )ProcTj (data []byte ,ctx Context ){_db :=_dde .Tf .Size ;_gb :=_dde .Th /100.0;_gac :=_dde .GlobalScale ;_daab :=_aa .NewMatrix (_db *_gb ,0,0,_db ,0,_dde .Ts );_aef :=ctx .Matrix ();
_bgga :=_aef .Clone ().Mult (_dde .Tm .Clone ().Mult (_daab )).ScalingFactorY ();_fgd :=_dde .Tf .NewFace (_bgga );_age :=_dde .Tf .BytesToCharcodes (data );for _ ,_fae :=range _age {_adg ,_deb :=_dde .Tf .CharcodeToRunes (_fae );_daae :=string (_deb );
if _daae =="\u0000"{continue ;};_abab :=_aef .Clone ().Mult (_dde .Tm .Clone ().Mult (_daab ));_eff :=_abab .ScalingFactorY ();_abab =_abab .Scale (1/_eff ,-1/_eff );if _dde .Tr !=TextRenderingModeInvisible {ctx .SetMatrix (_abab );ctx .DrawString (_daae ,_fgd ,0,0);
ctx .SetMatrix (_aef );};_cdf :=0.0;if _daae =="\u0020"{_cdf =_dde .Tw ;};_cff ,_ ,_dcc :=_dde .Tf .GetCharMetrics (_adg );if _dcc {_cff =_cff *0.001*_db ;}else {_cff ,_ =ctx .MeasureString (_daae ,_fgd );_cff =_cff /_gac ;};_fge :=(_cff +_dde .Tc +_cdf )*_gb ;
_dde .Tm =_dde .Tm .Mult (_aa .TranslationMatrix (_fge ,0));};};func (_abe *TextFont )WithSize (size float64 ,originalFont *_cd .PdfFont )*TextFont {return &TextFont {Font :_abe .Font ,Size :size ,_eab :_abe ._eab ,_dca :originalFont };};func (_dd *TextState )ProcTD (tx ,ty float64 ){_dd .Tl =-ty ;
_dd .ProcTd (tx ,ty )};func (_cca *TextFont )BytesToCharcodes (data []byte )[]_eg .CharCode {if _cca ._dca !=nil {return _cca ._dca .BytesToCharcodes (data );};return _cca .Font .BytesToCharcodes (data );};func (_de *TextState )ProcTStar (){_de .ProcTd (0,-_de .Tl )};
func NewTextState ()TextState {return TextState {Th :100,Tm :_aa .IdentityMatrix (),Tlm :_aa .IdentityMatrix ()};};func (_fdcc *TextFont )charcodeToRunesSimple (_eeb _eg .CharCode )(_eg .CharCode ,[]rune ){_agb :=[]_eg .CharCode {_eeb };if _fdcc .Font .IsSimple ()&&_fdcc ._eab !=nil {if _fec :=_fdcc ._eab .Index (rune (_eeb ));
_fec > 0{return _eeb ,[]rune {rune (_eeb )};};};if _fdcc ._eab !=nil &&!_fdcc ._eab .HasCmap ()&&_f .Contains (_fdcc .Font .Encoder ().String (),"\u0049d\u0065\u006e\u0074\u0069\u0074\u0079-"){if _bcea :=_fdcc ._eab .Index (rune (_eeb ));_bcea > 0{return _eeb ,[]rune {rune (_eeb )};
};};return _eeb ,_fdcc .Font .CharcodesToUnicode (_agb );};type FillRule int ;func (_fed *TextState )ProcQ (data []byte ,ctx Context ){_fed .ProcTStar ();_fed .ProcTj (data ,ctx )};func (_aaf *TextState )Translate (tx ,ty float64 ){_aaf .Tm =_aaf .Tm .Mult (_aa .TranslationMatrix (tx ,ty ));
};func NewTextFontFromPath (filePath string ,size float64 )(*TextFont ,error ){_efd ,_fce :=_cd .NewPdfFontFromTTFFile (filePath );if _fce !=nil {return nil ,_fce ;};return NewTextFont (_efd ,size );};func (_gace *TextState )Reset (){_gace .Tm =_aa .IdentityMatrix ();
_gace .Tlm =_aa .IdentityMatrix ()};type LineJoin int ;const (LineCapRound LineCap =iota ;LineCapButt ;LineCapSquare ;);type Gradient interface{Pattern ;AddColorStop (_fcc float64 ,_bf _c .Color );};type LineCap int ;type Pattern interface{ColorAt (_fc ,_bc int )_c .Color ;
};func (_ecb *TextState )ProcTd (tx ,ty float64 ){_ecb .Tlm .Concat (_aa .TranslationMatrix (tx ,ty ));_ecb .Tm =_ecb .Tlm .Clone ();};func (_eec *TextFont )CharcodeToRunes (charcode _eg .CharCode )(_eg .CharCode ,[]rune ){_feac :=[]_eg .CharCode {charcode };
if _eec ._dca ==nil ||_eec ._dca ==_eec .Font {return _eec .charcodeToRunesSimple (charcode );};_ffa :=_eec ._dca .CharcodesToUnicode (_feac );_bbb ,_ :=_eec .Font .RunesToCharcodeBytes (_ffa );_feag :=_eec .Font .BytesToCharcodes (_bbb );_ebg :=charcode ;
if len (_feag )> 0&&_feag [0]!=0{_ebg =_feag [0];};if string (_ffa )==string (_fe .MissingCodeRune )&&_eec ._dca .BaseFont ()==_eec .Font .BaseFont (){return _eec .charcodeToRunesSimple (charcode );};return _ebg ,_ffa ;};func (_cda *TextState )ProcDQ (data []byte ,aw ,ac float64 ,ctx Context ){_cda .Tw =aw ;
_cda .Tc =ac ;_cda .ProcQ (data ,ctx );};