// // 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 annotator provides an interface for creating annotations with appearance // streams. It goes beyond the models package which includes definitions of basic annotation models, in that it // can create the appearance streams which specify the exact appearance as needed by many pdf viewers for consistent // appearance of the annotations. // It also contains methods for generating appearance streams for fields via widget annotations. package annotator ;import (_g "bytes";_f "errors";_b "github.com/unidoc/unipdf/v3/common";_ae "github.com/unidoc/unipdf/v3/contentstream";_aa "github.com/unidoc/unipdf/v3/contentstream/draw";_af "github.com/unidoc/unipdf/v3/core";_ac "github.com/unidoc/unipdf/v3/internal/textencoding"; _gf "github.com/unidoc/unipdf/v3/model";_gb "image";_c "math";_ba "strings";_e "unicode";);func (_fdg *AppearanceStyle )applyAppearanceCharacteristics (_dbag *_af .PdfObjectDictionary ,_adfg *_af .PdfObjectDictionary ,_bfe *_gf .PdfFont )error {if !_fdg .AllowMK {return nil ; };if CA ,_ceda :=_af .GetString (_dbag .Get ("\u0043\u0041"));_ceda &&_bfe !=nil {_afb :=CA .Bytes ();if len (_afb )!=0{_dgg :=[]rune (_bfe .Encoder ().Decode (_afb ));if len (_dgg )==1{_fdg .CheckmarkRune =_dgg [0];};};};if BC ,_dfc :=_af .GetArray (_dbag .Get ("\u0042\u0043")); _dfc {_egcf ,_ddee :=BC .ToFloat64Array ();if _ddee !=nil {return _ddee ;};switch len (_egcf ){case 1:_fdg .BorderColor =_gf .NewPdfColorDeviceGray (_egcf [0]);case 3:_fdg .BorderColor =_gf .NewPdfColorDeviceRGB (_egcf [0],_egcf [1],_egcf [2]);case 4:_fdg .BorderColor =_gf .NewPdfColorDeviceCMYK (_egcf [0],_egcf [1],_egcf [2],_egcf [3]); default:_b .Log .Debug ("\u0045\u0052\u0052\u004f\u0052:\u0020\u0042\u0043\u0020\u002d\u0020\u0049\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072\u0020\u006f\u0066\u0020\u0063\u006f\u006c\u006f\u0072\u0020\u0063\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074\u0073\u0020\u0028\u0025\u0064)",len (_egcf )); };if _adfg !=nil {if _aac ,_bcba :=_af .GetNumberAsFloat (_adfg .Get ("\u0057"));_bcba ==nil {_fdg .BorderSize =_aac ;};};};if BG ,_dcf :=_af .GetArray (_dbag .Get ("\u0042\u0047"));_dcf {_afge ,_cca :=BG .ToFloat64Array ();if _cca !=nil {return _cca ; };switch len (_afge ){case 1:_fdg .FillColor =_gf .NewPdfColorDeviceGray (_afge [0]);case 3:_fdg .FillColor =_gf .NewPdfColorDeviceRGB (_afge [0],_afge [1],_afge [2]);case 4:_fdg .FillColor =_gf .NewPdfColorDeviceCMYK (_afge [0],_afge [1],_afge [2],_afge [3]); default:_b .Log .Debug ("\u0045\u0052\u0052\u004f\u0052:\u0020\u0042\u0047\u0020\u002d\u0020\u0049\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072\u0020\u006f\u0066\u0020\u0063\u006f\u006c\u006f\u0072\u0020\u0063\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074\u0073\u0020\u0028\u0025\u0064)",len (_afge )); };};return nil ;}; // LineAnnotationDef defines a line between point 1 (X1,Y1) and point 2 (X2,Y2). The line ending styles can be none // (regular line), or arrows at either end. The line also has a specified width, color and opacity. type LineAnnotationDef struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_gf .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 _aa .LineEndingStyle ;LineEndingStyle2 _aa .LineEndingStyle ;};func (_dca *AppearanceStyle )processDA (_bfge *_gf .PdfField ,_fde *_ae .ContentStreamOperations ,_aaa ,_cdg *_gf .PdfPageResources ,_aeba *_ae .ContentCreator )(*AppearanceFont ,bool ,error ){var _bea *AppearanceFont ; var _cdc bool ;if _dca .Fonts !=nil {if _dca .Fonts .Fallback !=nil {_bea =_dca .Fonts .Fallback ;};if _dda :=_dca .Fonts .FieldFallbacks ;_dda !=nil {if _aed ,_gedc :=_dda [_bfge .PartialName ()];_gedc {_bea =_aed ;}else if _fgcd ,_bcgb :=_bfge .FullName (); _bcgb ==nil {if _edcd ,_cbd :=_dda [_fgcd ];_cbd {_bea =_edcd ;};};};_cdc =_dca .Fonts .ForceReplace ;};var _acd string ;var _cgea float64 ;var _bafbg bool ;if _fde !=nil {for _ ,_adff :=range *_fde {if _adff .Operand =="\u0054\u0066"&&len (_adff .Params )==2{if _eacc ,_cba :=_af .GetNameVal (_adff .Params [0]); _cba {_acd =_eacc ;};if _begf ,_fcfd :=_af .GetNumberAsFloat (_adff .Params [1]);_fcfd ==nil {_cgea =_begf ;};_bafbg =true ;continue ;};_aeba .AddOperand (*_adff );};};var _fgd *AppearanceFont ;var _bga _af .PdfObject ;if _cdc &&_bea !=nil {_fgd =_bea ; }else {if _aaa !=nil &&_acd !=""{if _afed ,_fbf :=_aaa .GetFontByName (*_af .MakeName (_acd ));_fbf {if _aef ,_egae :=_gf .NewPdfFontFromPdfObject (_afed );_egae ==nil {_bga =_afed ;_fgd =&AppearanceFont {Name :_acd ,Font :_aef ,Size :_cgea };}else {_b .Log .Debug ("\u0045\u0052\u0052\u004f\u0052:\u0020\u0063\u006f\u0075\u006c\u0064\u0020\u006e\u006f\u0074\u0020\u006c\u006fa\u0064\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0061\u006e\u0063\u0065\u0020\u0066\u006f\u006e\u0074\u003a\u0020\u0025\u0076",_egae ); };};};if _fgd ==nil &&_bea !=nil {_fgd =_bea ;};if _fgd ==nil {_afbf ,_gga :=_gf .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");if _gga !=nil {return nil ,false ,_gga ;};_fgd =&AppearanceFont {Name :"\u0048\u0065\u006c\u0076",Font :_afbf ,Size :_cgea }; };};_eedg :=*_af .MakeName (_fgd .Name );if _bga ==nil {_bga =_fgd .Font .ToPdfObject ();};if _aaa !=nil &&!_aaa .HasFontByName (_eedg ){_aaa .SetFontByName (_eedg ,_bga );};if _cdg !=nil &&!_cdg .HasFontByName (_eedg ){_cdg .SetFontByName (_eedg ,_bga ); };return _fgd ,_bafbg ,nil ;}; // SignatureFieldOpts represents a set of options used to configure // an appearance widget dictionary. type SignatureFieldOpts struct{ // Rect represents the area the signature annotation is displayed on. Rect []float64 ; // AutoSize specifies if the content of the appearance should be // scaled to fit in the annotation rectangle. AutoSize bool ; // Font specifies the font of the text content. Font *_gf .PdfFont ; // FontSize specifies the size of the text content. FontSize float64 ; // LineHeight specifies the height of a line of text in the appearance annotation. LineHeight float64 ; // TextColor represents the color of the text content displayed. TextColor _gf .PdfColor ; // FillColor represents the background color of the appearance annotation area. FillColor _gf .PdfColor ; // BorderSize represents border size of the appearance annotation area. BorderSize float64 ; // BorderColor represents the border color of the appearance annotation area. BorderColor _gf .PdfColor ; // WatermarkImage specifies the image used as a watermark that will be rendered // behind the signature. WatermarkImage _gb .Image ; // Image represents the image used for the signature appearance. Image _gb .Image ; // Encoder specifies the image encoder used for image signature. Defaults to flate encoder. Encoder _af .StreamEncoder ; // ImagePosition specifies the image location relative to the text signature. ImagePosition SignatureImagePosition ;};func _gdag (_afg *_gf .PdfField ,_efdd ,_bbgc float64 ,_gaa string ,_ebecb AppearanceStyle ,_bfg *_ae .ContentStreamOperations ,_fed *_gf .PdfPageResources ,_gdad *_af .PdfObjectDictionary )(*_gf .XObjectForm ,error ){_ead :=_gf .NewPdfPageResources (); _dddf ,_ecc :=_efdd ,_bbgc ;_bbdb :=_ae .NewContentCreator ();if _ebecb .BorderSize > 0{_gea (_bbdb ,_ebecb ,_efdd ,_bbgc );};if _ebecb .DrawAlignmentReticle {_cecg :=_ebecb ;_cecg .BorderSize =0.2;_afa (_bbdb ,_cecg ,_efdd ,_bbgc );};_bbdb .Add_BMC ("\u0054\u0078"); _bbdb .Add_q ();_bbdb .Add_BT ();_efdd ,_bbgc =_ebecb .applyRotation (_gdad ,_efdd ,_bbgc ,_bbdb );_fcge ,_ebbf ,_bedf :=_ebecb .processDA (_afg ,_bfg ,_fed ,_ead ,_bbdb );if _bedf !=nil {return nil ,_bedf ;};_gfad :=_fcge .Font ;_bacc :=_fcge .Size ;_dga :=_af .MakeName (_fcge .Name ); _bdc :=_bacc ==0;if _bdc &&_ebbf {_bacc =_bbgc *_ebecb .AutoFontSizeFraction ;};_fcgd :=_gfad .Encoder ();if _fcgd ==nil {_b .Log .Debug ("\u0057\u0041RN\u003a\u0020\u0066\u006f\u006e\u0074\u0020\u0065\u006e\u0063\u006f\u0064\u0065\u0072\u0020\u0069\u0073\u0020\u006e\u0069l\u002e\u0020\u0041\u0073s\u0075\u006d\u0069\u006eg \u0069\u0064e\u006et\u0069\u0074\u0079\u0020\u0065\u006ec\u006f\u0064\u0065r\u002e\u0020O\u0075\u0074\u0070\u0075\u0074\u0020\u006d\u0061\u0079\u0020\u0062\u0065\u0020\u0069n\u0063\u006f\u0072\u0072\u0065\u0063\u0074\u002e"); _fcgd =_ac .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};if len (_gaa )==0{return nil ,nil ;};_eace :=2.0;_febe :=0.0;if _fcgd !=nil {for _ ,_degd :=range _gaa {_eceg ,_aeb :=_gfad .GetRuneMetrics (_degd );if !_aeb {_b .Log .Debug ("\u0046\u006f\u006e\u0074\u0020\u0064o\u0065\u0073\u0020\u006e\u006f\u0074\u0020\u0068\u0061\u0076\u0065\u0020\u0072\u0075\u006e\u0065\u0020\u006d\u0065\u0074r\u0069\u0063\u0073\u0020\u0066\u006f\u0072\u0020\u0025\u0076\u0020\u002d\u0020\u0073k\u0069p\u0070\u0069\u006e\u0067",_degd ); continue ;};_febe +=_eceg .Wx ;};_gaa =string (_fcgd .Encode (_gaa ));};if _bacc ==0||_bdc &&_febe > 0&&_eace +_febe *_bacc /1000.0> _efdd {_bacc =0.95*1000.0*(_efdd -_eace )/_febe ;};_aaf :=1.0*_bacc ;_fef :=2.0;{_eeef :=_aaf ;if _bdc &&_fef +_eeef > _bbgc {_bacc =0.95*(_bbgc -_fef ); _aaf =1.0*_bacc ;_eeef =_aaf ;};if _bbgc > _eeef {_fef =(_bbgc -_eeef )/2.0;_fef +=1.50;};};_bbdb .Add_Tf (*_dga ,_bacc );_bbdb .Add_Td (_eace ,_fef );_bbdb .Add_Tj (*_af .MakeString (_gaa ));_bbdb .Add_ET ();_bbdb .Add_Q ();_bbdb .Add_EMC ();_dcd :=_gf .NewXObjectForm (); _dcd .Resources =_ead ;_dcd .BBox =_af .MakeArrayFromFloats ([]float64 {0,0,_dddf ,_ecc });_dcd .SetContentStream (_bbdb .Bytes (),_cbb ());return _dcd ,nil ;}; // NewComboboxField generates a new combobox form field with partial name `name` at location `rect` // on specified `page` and with field specific options `opt`. func NewComboboxField (page *_gf .PdfPage ,name string ,rect []float64 ,opt ComboboxFieldOptions )(*_gf .PdfFieldChoice ,error ){if page ==nil {return nil ,_f .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064"); };if len (name )<=0{return nil ,_f .New ("\u0072\u0065\u0071\u0075\u0069\u0072\u0065\u0064\u0020\u0061\u0074\u0074\u0072\u0069\u0062u\u0074e\u0020\u006e\u006f\u0074\u0020\u0073\u0070\u0065\u0063\u0069\u0066\u0069\u0065\u0064");};if len (rect )!=4{return nil ,_f .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065"); };_cafg :=_gf .NewPdfField ();_bcd :=&_gf .PdfFieldChoice {};_cafg .SetContext (_bcd );_bcd .PdfField =_cafg ;_bcd .T =_af .MakeString (name );_bcd .Opt =_af .MakeArray ();for _ ,_bcc :=range opt .Choices {_bcd .Opt .Append (_af .MakeString (_bcc ));}; _bcd .SetFlag (_gf .FieldFlagCombo );_eefe :=_gf .NewPdfAnnotationWidget ();_eefe .Rect =_af .MakeArrayFromFloats (rect );_eefe .P =page .ToPdfObject ();_eefe .F =_af .MakeInteger (4);_eefe .Parent =_bcd .ToPdfObject ();_bcd .Annotations =append (_bcd .Annotations ,_eefe ); return _bcd ,nil ;}; // NewSignatureField returns a new signature field with a visible appearance // containing the specified signature lines and styled according to the // specified options. func NewSignatureField (signature *_gf .PdfSignature ,lines []*SignatureLine ,opts *SignatureFieldOpts )(*_gf .PdfFieldSignature ,error ){if signature ==nil {return nil ,_f .New ("\u0073\u0069\u0067na\u0074\u0075\u0072\u0065\u0020\u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u006e\u0069\u006c"); };_bfeb ,_agfe :=_fcc (lines ,opts );if _agfe !=nil {return nil ,_agfe ;};_baec :=_gf .NewPdfFieldSignature (signature );_baec .Rect =_af .MakeArrayFromFloats (opts .Rect );_baec .AP =_bfeb ;return _baec ,nil ;};func _afa (_age *_ae .ContentCreator ,_aga AppearanceStyle ,_fgb ,_aaee float64 ){_age .Add_q ().Add_re (0,0,_fgb ,_aaee ).Add_re (0,_aaee /2,_fgb ,_aaee /2).Add_re (0,0,_fgb ,_aaee ).Add_re (_fgb /2,0,_fgb /2,_aaee ).Add_w (_aga .BorderSize ).SetStrokingColor (_aga .BorderColor ).SetNonStrokingColor (_aga .FillColor ).Add_B ().Add_Q (); }; // NewCheckboxField generates a new checkbox field with partial name `name` at location `rect` // on specified `page` and with field specific options `opt`. func NewCheckboxField (page *_gf .PdfPage ,name string ,rect []float64 ,opt CheckboxFieldOptions )(*_gf .PdfFieldButton ,error ){if page ==nil {return nil ,_f .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064"); };if len (name )<=0{return nil ,_f .New ("\u0072\u0065\u0071\u0075\u0069\u0072\u0065\u0064\u0020\u0061\u0074\u0074\u0072\u0069\u0062u\u0074e\u0020\u006e\u006f\u0074\u0020\u0073\u0070\u0065\u0063\u0069\u0066\u0069\u0065\u0064");};if len (rect )!=4{return nil ,_f .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065"); };_dbd ,_eebf :=_gf .NewStandard14Font (_gf .ZapfDingbatsName );if _eebf !=nil {return nil ,_eebf ;};_bcaba :=_gf .NewPdfField ();_fcb :=&_gf .PdfFieldButton {};_bcaba .SetContext (_fcb );_fcb .PdfField =_bcaba ;_fcb .T =_af .MakeString (name );_fcb .SetType (_gf .ButtonTypeCheckbox ); _eefa :="\u004f\u0066\u0066";if opt .Checked {_eefa ="\u0059\u0065\u0073";};_fcb .V =_af .MakeName (_eefa );_baca :=_gf .NewPdfAnnotationWidget ();_baca .Rect =_af .MakeArrayFromFloats (rect );_baca .P =page .ToPdfObject ();_baca .F =_af .MakeInteger (4); _baca .Parent =_fcb .ToPdfObject ();_edbg :=rect [2]-rect [0];_cce :=rect [3]-rect [1];var _befe _g .Buffer ;_befe .WriteString ("\u0071\u000a");_befe .WriteString ("\u0030 \u0030\u0020\u0031\u0020\u0072\u0067\n");_befe .WriteString ("\u0042\u0054\u000a"); _befe .WriteString ("\u002f\u005a\u0061D\u0062\u0020\u0031\u0032\u0020\u0054\u0066\u000a");_befe .WriteString ("\u0045\u0054\u000a");_befe .WriteString ("\u0051\u000a");_dgd :=_ae .NewContentCreator ();_dgd .Add_q ();_dgd .Add_rg (0,0,1);_dgd .Add_BT (); _dgd .Add_Tf (*_af .MakeName ("\u005a\u0061\u0044\u0062"),12);_dgd .Add_Td (0,0);_dgd .Add_ET ();_dgd .Add_Q ();_bfcef :=_gf .NewXObjectForm ();_bfcef .SetContentStream (_dgd .Bytes (),_af .NewRawEncoder ());_bfcef .BBox =_af .MakeArrayFromFloats ([]float64 {0,0,_edbg ,_cce }); _bfcef .Resources =_gf .NewPdfPageResources ();_bfcef .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_dbd .ToPdfObject ());_dgd =_ae .NewContentCreator ();_dgd .Add_q ();_dgd .Add_re (0,0,_edbg ,_cce );_dgd .Add_W ().Add_n ();_dgd .Add_rg (0,0,1); _dgd .Translate (0,3.0);_dgd .Add_BT ();_dgd .Add_Tf (*_af .MakeName ("\u005a\u0061\u0044\u0062"),12);_dgd .Add_Td (0,0);_dgd .Add_Tj (*_af .MakeString ("\u0034"));_dgd .Add_ET ();_dgd .Add_Q ();_bcf :=_gf .NewXObjectForm ();_bcf .SetContentStream (_dgd .Bytes (),_af .NewRawEncoder ()); _bcf .BBox =_af .MakeArrayFromFloats ([]float64 {0,0,_edbg ,_cce });_bcf .Resources =_gf .NewPdfPageResources ();_bcf .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_dbd .ToPdfObject ());_fgcda :=_af .MakeDict ();_fgcda .Set ("\u004f\u0066\u0066",_bfcef .ToPdfObject ()); _fgcda .Set ("\u0059\u0065\u0073",_bcf .ToPdfObject ());_fcba :=_af .MakeDict ();_fcba .Set ("\u004e",_fgcda );_baca .AP =_fcba ;_baca .AS =_af .MakeName (_eefa );_fcb .Annotations =append (_fcb .Annotations ,_baca );return _fcb ,nil ;}; // SetStyle applies appearance `style` to `fa`. func (_dg *FieldAppearance )SetStyle (style AppearanceStyle ){_dg ._eba =&style }; // GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`. // Implements interface model.FieldAppearanceGenerator. func (_fbe FieldAppearance )GenerateAppearanceDict (form *_gf .PdfAcroForm ,field *_gf .PdfField ,wa *_gf .PdfAnnotationWidget )(*_af .PdfObjectDictionary ,error ){_b .Log .Trace ("\u0047\u0065n\u0065\u0072\u0061\u0074e\u0041\u0070p\u0065\u0061\u0072\u0061\u006e\u0063\u0065\u0044i\u0063\u0074\u0020\u0066\u006f\u0072\u0020\u0025\u0076\u0020\u0020\u0056:\u0020\u0025\u002b\u0076",field .PartialName (),field .V ); _ ,_ed :=field .GetContext ().(*_gf .PdfFieldText );_bfff ,_bggf :=_af .GetDict (wa .AP );if _bggf &&_fbe .OnlyIfMissing &&(!_ed ||!_fbe .RegenerateTextFields ){_b .Log .Trace ("\u0041\u006c\u0072\u0065a\u0064\u0079\u0020\u0070\u006f\u0070\u0075\u006c\u0061\u0074e\u0064 \u002d\u0020\u0069\u0067\u006e\u006f\u0072i\u006e\u0067"); return _bfff ,nil ;};if form .DR ==nil {form .DR =_gf .NewPdfPageResources ();};switch _dd :=field .GetContext ().(type ){case *_gf .PdfFieldText :_acf :=_dd ;switch {case _acf .Flags ().Has (_gf .FieldFlagPassword ):return nil ,nil ;case _acf .Flags ().Has (_gf .FieldFlagFileSelect ):return nil ,nil ; case _acf .Flags ().Has (_gf .FieldFlagComb ):if _acf .MaxLen !=nil {_ea ,_cda :=_fbea (wa ,_acf ,form .DR ,_fbe .Style ());if _cda !=nil {return nil ,_cda ;};return _ea ,nil ;};};_caf ,_bed :=_cdf (wa ,_acf ,form .DR ,_fbe .Style ());if _bed !=nil {return nil ,_bed ; };return _caf ,nil ;case *_gf .PdfFieldButton :_fd :=_dd ;if _fd .IsCheckbox (){_edd ,_fbeg :=_adfd (wa ,_fd ,form .DR ,_fbe .Style ());if _fbeg !=nil {return nil ,_fbeg ;};return _edd ,nil ;};_b .Log .Debug ("\u0054\u004f\u0044\u004f\u003a\u0020\u0055\u004e\u0048\u0041\u004e\u0044\u004c\u0045\u0044 \u0062u\u0074\u0074\u006f\u006e\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u002b\u0076",_fd .GetType ()); case *_gf .PdfFieldChoice :_ecb :=_dd ;switch {case _ecb .Flags ().Has (_gf .FieldFlagCombo ):_fbb ,_aab :=_ddda (form ,wa ,_ecb ,_fbe .Style ());if _aab !=nil {return nil ,_aab ;};return _fbb ,nil ;default:_b .Log .Debug ("\u0054\u004f\u0044\u004f\u003a\u0020\u0055N\u0048\u0041\u004eD\u004c\u0045\u0044\u0020c\u0068\u006f\u0069\u0063\u0065\u0020\u0066\u0069\u0065\u006c\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0066\u006c\u0061\u0067\u0073\u003a\u0020\u0025\u0073",_ecb .Flags ().String ()); };default:_b .Log .Debug ("\u0054\u004f\u0044\u004f\u003a\u0020\u0055\u004e\u0048\u0041N\u0044\u004c\u0045\u0044\u0020\u0066\u0069e\u006c\u0064\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_dd );};return nil ,nil ;};func _adfd (_bge *_gf .PdfAnnotationWidget ,_cbef *_gf .PdfFieldButton ,_eed *_gf .PdfPageResources ,_fg AppearanceStyle )(*_af .PdfObjectDictionary ,error ){_dcg ,_dde :=_af .GetArray (_bge .Rect ); if !_dde {return nil ,_f .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_adgg ,_ffe :=_gf .NewPdfRectangle (*_dcg );if _ffe !=nil {return nil ,_ffe ;};_abb ,_aegg :=_adgg .Width (),_adgg .Height ();_aegf ,_bbd :=_abb ,_aegg ; _b .Log .Debug ("\u0043\u0068\u0065\u0063kb\u006f\u0078\u002c\u0020\u0077\u0061\u0020\u0042\u0053\u003a\u0020\u0025\u0076",_bge .BS );_bef ,_ffe :=_gf .NewStandard14Font ("\u005a\u0061\u0070f\u0044\u0069\u006e\u0067\u0062\u0061\u0074\u0073");if _ffe !=nil {return nil ,_ffe ; };_bege ,_bfce :=_af .GetDict (_bge .MK );if _bfce {_eae ,_ :=_af .GetDict (_bge .BS );_egda :=_fg .applyAppearanceCharacteristics (_bege ,_eae ,_bef );if _egda !=nil {return nil ,_egda ;};};_eac :=_gf .NewXObjectForm ();{_gee :=_ae .NewContentCreator (); if _fg .BorderSize > 0{_gea (_gee ,_fg ,_abb ,_aegg );};if _fg .DrawAlignmentReticle {_bafc :=_fg ;_bafc .BorderSize =0.2;_afa (_gee ,_bafc ,_abb ,_aegg );};_abb ,_aegg =_fg .applyRotation (_bege ,_abb ,_aegg ,_gee );_fegc :=_fg .AutoFontSizeFraction *_aegg ; _feb ,_gda :=_bef .GetRuneMetrics (_fg .CheckmarkRune );if !_gda {return nil ,_f .New ("\u0067l\u0079p\u0068\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");};_bae :=_bef .Encoder ();_bdd :=_bae .Encode (string (_fg .CheckmarkRune ));_ebb :=_feb .Wx *_fegc /1000.0; _bac :=705.0;_ccd :=_bac /1000.0*_fegc ;_gc :=2.0;_egf :=1.0;if _ebb < _abb {_gc =(_abb -_ebb )/2.0;};if _ccd < _aegg {_egf =(_aegg -_ccd )/2.0;};_gee .Add_q ().Add_g (0).Add_BT ().Add_Tf ("\u005a\u0061\u0044\u0062",_fegc ).Add_Td (_gc ,_egf ).Add_Tj (*_af .MakeStringFromBytes (_bdd )).Add_ET ().Add_Q (); _eac .Resources =_gf .NewPdfPageResources ();_eac .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_bef .ToPdfObject ());_eac .BBox =_af .MakeArrayFromFloats ([]float64 {0,0,_aegf ,_bbd });_eac .SetContentStream (_gee .Bytes (),_cbb ());};_bcab :=_gf .NewXObjectForm (); {_ddb :=_ae .NewContentCreator ();if _fg .BorderSize > 0{_gea (_ddb ,_fg ,_abb ,_aegg );};_bcab .BBox =_af .MakeArrayFromFloats ([]float64 {0,0,_aegf ,_bbd });_bcab .SetContentStream (_ddb .Bytes (),_cbb ());};_eea :=_af .MakeDict ();_eea .Set ("\u004f\u0066\u0066",_bcab .ToPdfObject ()); _eea .Set ("\u0059\u0065\u0073",_eac .ToPdfObject ());_agg :=_af .MakeDict ();_agg .Set ("\u004e",_eea );return _agg ,nil ;};func _fbea (_edc *_gf .PdfAnnotationWidget ,_bbgd *_gf .PdfFieldText ,_afcd *_gf .PdfPageResources ,_fagg AppearanceStyle )(*_af .PdfObjectDictionary ,error ){_ee :=_gf .NewPdfPageResources (); _egc ,_egd :=_af .GetArray (_edc .Rect );if !_egd {return nil ,_f .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_daf ,_beg :=_gf .NewPdfRectangle (*_egc );if _beg !=nil {return nil ,_beg ;};_dgc ,_gad :=_daf .Width (),_daf .Height (); _dbb ,_bbf :=_dgc ,_gad ;_ddf ,_acfe :=_af .GetDict (_edc .MK );if _acfe {_eee ,_ :=_af .GetDict (_edc .BS );_ceb :=_fagg .applyAppearanceCharacteristics (_ddf ,_eee ,nil );if _ceb !=nil {return nil ,_ceb ;};};_gbg ,_acfe :=_af .GetIntVal (_bbgd .MaxLen ); if !_acfe {return nil ,_f .New ("\u006d\u0061\u0078\u006c\u0065\u006e\u0020\u006e\u006ft\u0020\u0073\u0065\u0074");};if _gbg <=0{return nil ,_f .New ("\u006d\u0061\u0078\u004c\u0065\u006e\u0020\u0069\u006ev\u0061\u006c\u0069\u0064");};_ab :=_dgc /float64 (_gbg ); _dce ,_beg :=_ae .NewContentStreamParser (_eeg (_bbgd .PdfField )).Parse ();if _beg !=nil {return nil ,_beg ;};_fab :=_ae .NewContentCreator ();if _fagg .BorderSize > 0{_gea (_fab ,_fagg ,_dgc ,_gad );};if _fagg .DrawAlignmentReticle {_cbgd :=_fagg ;_cbgd .BorderSize =0.2; _afa (_fab ,_cbgd ,_dgc ,_gad );};_fab .Add_BMC ("\u0054\u0078");_fab .Add_q ();_ ,_gad =_fagg .applyRotation (_ddf ,_dgc ,_gad ,_fab );_fab .Add_BT ();_edf ,_ged ,_beg :=_fagg .processDA (_bbgd .PdfField ,_dce ,_afcd ,_ee ,_fab );if _beg !=nil {return nil ,_beg ; };_begg :=_edf .Font ;_dag :=_af .MakeName (_edf .Name );_bcb :=_edf .Size ;_aeg :=_bcb ==0;if _aeg &&_ged {_bcb =_gad *_fagg .AutoFontSizeFraction ;};_add :=_begg .Encoder ();if _add ==nil {_b .Log .Debug ("\u0057\u0041RN\u003a\u0020\u0066\u006f\u006e\u0074\u0020\u0065\u006e\u0063\u006f\u0064\u0065\u0072\u0020\u0069\u0073\u0020\u006e\u0069l\u002e\u0020\u0041\u0073s\u0075\u006d\u0069\u006eg \u0069\u0064e\u006et\u0069\u0074\u0079\u0020\u0065\u006ec\u006f\u0064\u0065r\u002e\u0020O\u0075\u0074\u0070\u0075\u0074\u0020\u006d\u0061\u0079\u0020\u0062\u0065\u0020\u0069n\u0063\u006f\u0072\u0072\u0065\u0063\u0074\u002e"); _add =_ac .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};var _bcaa string ;if _adb ,_fbad :=_af .GetString (_bbgd .V );_fbad {_bcaa =_adb .Decoded ();};_fab .Add_Tf (*_dag ,_bcb );var _aff float64 ;for _ ,_ade :=range _bcaa {_accg ,_ddff :=_begg .GetRuneMetrics (_ade ); if !_ddff {_b .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a \u0052\u0075\u006e\u0065\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064\u0020\u0069\u006e\u0020\u0066\u006fn\u0074\u003a\u0020\u0025\u0076\u0020\u002d\u0020\u0073\u006b\u0069\u0070\u0070\u0069n\u0067 \u006f\u0076\u0065\u0072",_ade ); continue ;};_gec :=_accg .Wy ;if int (_gec )<=0{_gec =_accg .Wx ;};if _gec > _aff {_aff =_gec ;};};if int (_aff )==0{_b .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0055\u006e\u0061\u0062\u006c\u0065\u0020\u0074o\u0020\u0064\u0065\u0074\u0065\u0072\u006d\u0069\u006e\u0065\u0020\u006d\u0061x\u0020\u0067\u006c\u0079\u0070\u0068\u0020\u0073\u0069\u007a\u0065\u0020- \u0075\u0073\u0069\u006e\u0067\u0020\u0031\u0030\u0030\u0030"); _aff =1000;};_cfe ,_beg :=_begg .GetFontDescriptor ();if _beg !=nil {_b .Log .Debug ("\u0045\u0072ro\u0072\u003a\u0020U\u006e\u0061\u0062\u006ce t\u006f g\u0065\u0074\u0020\u0066\u006f\u006e\u0074 d\u0065\u0073\u0063\u0072\u0069\u0070\u0074o\u0072");}; var _fae float64 ;if _cfe !=nil {_fae ,_beg =_cfe .GetCapHeight ();if _beg !=nil {_b .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0055\u006e\u0061\u0062\u006c\u0065 \u0074\u006f\u0020\u0067\u0065\u0074 \u0066\u006f\u006e\u0074\u0020\u0043\u0061\u0070\u0048\u0065\u0069\u0067\u0068t\u003a\u0020\u0025\u0076",_beg ); };};if int (_fae )<=0{_b .Log .Debug ("W\u0041\u0052\u004e\u003a\u0020\u0043\u0061\u0070\u0048e\u0069\u0067\u0068\u0074\u0020\u006e\u006ft \u0061\u0076\u0061\u0069l\u0061\u0062\u006c\u0065\u0020\u002d\u0020\u0073\u0065tt\u0069\u006eg\u0020\u0074\u006f\u0020\u0031\u0030\u0030\u0030"); _fae =1000.0;};_ded :=_fae /1000.0*_bcb ;_gbga :=0.0;_bafb :=1.0*_bcb *(_aff /1000.0);{_ceg :=_bafb ;if _aeg &&_gbga +_ceg > _gad {_bcb =0.95*(_gad -_gbga );_ded =_fae /1000.0*_bcb ;};if _gad > _ded {_gbga =(_gad -_ded )/2.0;};};_fab .Add_Td (0,_gbga ); if _agcb ,_dec :=_af .GetIntVal (_bbgd .Q );_dec {switch _agcb {case 2:if len (_bcaa )< _gbg {_df :=float64 (_gbg -len (_bcaa ))*_ab ;_fab .Add_Td (_df ,0);};};};for _adef ,_ega :=range _bcaa {_cdb :=2.0;_gbd :=string (_ega );if _add !=nil {_eeb ,_cdbd :=_begg .GetRuneMetrics (_ega ); if !_cdbd {_b .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a \u0052\u0075\u006e\u0065\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064\u0020\u0069\u006e\u0020\u0066\u006fn\u0074\u003a\u0020\u0025\u0076\u0020\u002d\u0020\u0073\u006b\u0069\u0070\u0070\u0069n\u0067 \u006f\u0076\u0065\u0072",_ega ); continue ;};_gbd =string (_add .Encode (_gbd ));_gdd :=_bcb *_eeb .Wx /1000.0;_bee :=(_ab -_gdd )/2;_cdb =_bee ;};_fab .Add_Td (_cdb ,0);_fab .Add_Tj (*_af .MakeString (_gbd ));if _adef !=len (_bcaa )-1{_fab .Add_Td (_ab -_cdb ,0);};};_fab .Add_ET ();_fab .Add_Q (); _fab .Add_EMC ();_ebec :=_gf .NewXObjectForm ();_ebec .Resources =_ee ;_ebec .BBox =_af .MakeArrayFromFloats ([]float64 {0,0,_dbb ,_bbf });_ebec .SetContentStream (_fab .Bytes (),_cbb ());_feac :=_af .MakeDict ();_feac .Set ("\u004e",_ebec .ToPdfObject ()); return _feac ,nil ;}; // CheckboxFieldOptions defines optional parameters for a checkbox field a form. type CheckboxFieldOptions struct{Checked bool ;}; // NewSignatureLine returns a new signature line displayed as a part of the // signature field appearance. func NewSignatureLine (desc ,text string )*SignatureLine {return &SignatureLine {Desc :desc ,Text :text };};func _eeg (_gggb *_gf .PdfField )string {if _gggb ==nil {return "";};_cab ,_dfd :=_gggb .GetContext ().(*_gf .PdfFieldText );if !_dfd {return _eeg (_gggb .Parent ); };if _cab .DA !=nil {return _cab .DA .Str ();};return _eeg (_cab .Parent );}; // CreateRectangleAnnotation creates a rectangle annotation object that can be added to page PDF annotations. func CreateRectangleAnnotation (rectDef RectangleAnnotationDef )(*_gf .PdfAnnotation ,error ){_bafa :=_gf .NewPdfAnnotationSquare ();if rectDef .BorderEnabled {_cfc ,_ggeb ,_ggeg :=rectDef .BorderColor .R (),rectDef .BorderColor .G (),rectDef .BorderColor .B (); _bafa .C =_af .MakeArrayFromFloats ([]float64 {_cfc ,_ggeb ,_ggeg });_cecb :=_gf .NewBorderStyle ();_cecb .SetBorderWidth (rectDef .BorderWidth );_bafa .BS =_cecb .ToPdfObject ();};if rectDef .FillEnabled {_gbaa ,_ebg ,_accb :=rectDef .FillColor .R (),rectDef .FillColor .G (),rectDef .FillColor .B (); _bafa .IC =_af .MakeArrayFromFloats ([]float64 {_gbaa ,_ebg ,_accb });}else {_bafa .IC =_af .MakeArrayFromIntegers ([]int {});};if rectDef .Opacity < 1.0{_bafa .CA =_af .MakeFloat (rectDef .Opacity );};_ebea ,_fcfb ,_bce :=_gag (rectDef );if _bce !=nil {return nil ,_bce ; };_bafa .AP =_ebea ;_bafa .Rect =_af .MakeArrayFromFloats ([]float64 {_fcfb .Llx ,_fcfb .Lly ,_fcfb .Urx ,_fcfb .Ury });return _bafa .PdfAnnotation ,nil ;};func _gefb (_ddbe LineAnnotationDef )(*_af .PdfObjectDictionary ,*_gf .PdfRectangle ,error ){_bdfd :=_gf .NewXObjectForm (); _bdfd .Resources =_gf .NewPdfPageResources ();_bcbaf :="";if _ddbe .Opacity < 1.0{_dgdd :=_af .MakeDict ();_dgdd .Set ("\u0063\u0061",_af .MakeFloat (_ddbe .Opacity ));_abd :=_bdfd .Resources .AddExtGState ("\u0067\u0073\u0031",_dgdd );if _abd !=nil {_b .Log .Debug ("U\u006e\u0061\u0062\u006c\u0065\u0020t\u006f\u0020\u0061\u0064\u0064\u0020\u0065\u0078\u0074g\u0073\u0074\u0061t\u0065 \u0067\u0073\u0031"); return nil ,nil ,_abd ;};_bcbaf ="\u0067\u0073\u0031";};_fedc ,_fdac ,_geb ,_bedb :=_gbf (_ddbe ,_bcbaf );if _bedb !=nil {return nil ,nil ,_bedb ;};_bedb =_bdfd .SetContentStream (_fedc ,nil );if _bedb !=nil {return nil ,nil ,_bedb ;};_bdfd .BBox =_fdac .ToPdfObject (); _abe :=_af .MakeDict ();_abe .Set ("\u004e",_bdfd .ToPdfObject ());return _abe ,_geb ,nil ;}; // NewSignatureFieldOpts returns a new initialized instance of options // used to generate a signature appearance. func NewSignatureFieldOpts ()*SignatureFieldOpts {return &SignatureFieldOpts {Font :_gf .DefaultFont (),FontSize :10,LineHeight :1,AutoSize :true ,TextColor :_gf .NewPdfColorDeviceGray (0),BorderColor :_gf .NewPdfColorDeviceGray (0),FillColor :_gf .NewPdfColorDeviceGray (1),Encoder :_af .NewFlateEncoder (),ImagePosition :SignatureImageLeft }; }; // AppearanceFont represents a font used for generating the appearance of a // field in the filling/flattening process. type AppearanceFont struct{ // Name represents the name of the font which will be added to the // AcroForm resources (DR). Name string ; // Font represents the actual font used for the field appearance. Font *_gf .PdfFont ; // Size represents the size of the font used for the field appearance. // If size is 0, a default font size will be used. // The default font size is calculated using the available annotation // height and the AutoFontSizeFraction of the AppearanceStyle. Size float64 ;}; // SignatureImagePosition specifies the image signature location relative to the text signature. // If text signature is not defined, this position will be ignored. type SignatureImagePosition int ;func _cbb ()_af .StreamEncoder {return _af .NewFlateEncoder ()}; // Style returns the appearance style of `fa`. If not specified, returns default style. func (_fbaf FieldAppearance )Style ()AppearanceStyle {if _fbaf ._eba !=nil {return *_fbaf ._eba ;};return AppearanceStyle {AutoFontSizeFraction :0.65,CheckmarkRune :'✔',BorderSize :0.0,BorderColor :_gf .NewPdfColorDeviceGray (0),FillColor :_gf .NewPdfColorDeviceGray (1),MultilineLineHeight :1.2,MultilineVAlignMiddle :false ,DrawAlignmentReticle :false ,AllowMK :true }; };func _fcgc (_caa _gb .Image ,_efag string ,_cfed *SignatureFieldOpts ,_dee []float64 ,_ddag *_ae .ContentCreator )(*_af .PdfObjectName ,*_gf .XObjectImage ,error ){_fega ,_adeb :=_gf .DefaultImageHandler {}.NewImageFromGoImage (_caa );if _adeb !=nil {return nil ,nil ,_adeb ; };_feaa ,_adeb :=_gf .NewXObjectImageFromImage (_fega ,nil ,_cfed .Encoder );if _adeb !=nil {return nil ,nil ,_adeb ;};_gede ,_bcbbc :=float64 (*_feaa .Width ),float64 (*_feaa .Height );_bfa :=_dee [2]-_dee [0];_cdgf :=_dee [3]-_dee [1];if _cfed .AutoSize {_eab :=_c .Min (_bfa /_gede ,_cdgf /_bcbbc ); _gede *=_eab ;_bcbbc *=_eab ;_dee [0]=_dee [0]+(_bfa /2)-(_gede /2);_dee [1]=_dee [1]+(_cdgf /2)-(_bcbbc /2);};var _fdcc *_af .PdfObjectName ;if _ccac ,_cabd :=_af .GetName (_feaa .Name );_cabd {_fdcc =_ccac ;}else {_fdcc =_af .MakeName (_efag );};if _ddag !=nil {_ddag .Add_q ().Translate (_dee [0],_dee [1]).Scale (_gede ,_bcbbc ).Add_Do (*_fdcc ).Add_Q (); }else {return nil ,nil ,_f .New ("\u0043\u006f\u006e\u0074en\u0074\u0043\u0072\u0065\u0061\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u0075l\u006c");};return _fdcc ,_feaa ,nil ;};func _cdf (_efb *_gf .PdfAnnotationWidget ,_gfa *_gf .PdfFieldText ,_bfc *_gf .PdfPageResources ,_aae AppearanceStyle )(*_af .PdfObjectDictionary ,error ){_eda :=_gf .NewPdfPageResources (); _bdf ,_aee :=_af .GetArray (_efb .Rect );if !_aee {return nil ,_f .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_baf ,_ff :=_gf .NewPdfRectangle (*_bdf );if _ff !=nil {return nil ,_ff ;};_ebe ,_fa :=_baf .Width (),_baf .Height (); _bffa ,_efd :=_ebe ,_fa ;_gab ,_ggg :=_af .GetDict (_efb .MK );if _ggg {_dgf ,_ :=_af .GetDict (_efb .BS );_cg :=_aae .applyAppearanceCharacteristics (_gab ,_dgf ,nil );if _cg !=nil {return nil ,_cg ;};};_afc ,_ff :=_ae .NewContentStreamParser (_eeg (_gfa .PdfField )).Parse (); if _ff !=nil {return nil ,_ff ;};_cbg :=_ae .NewContentCreator ();if _aae .BorderSize > 0{_gea (_cbg ,_aae ,_ebe ,_fa );};if _aae .DrawAlignmentReticle {_bc :=_aae ;_bc .BorderSize =0.2;_afa (_cbg ,_bc ,_ebe ,_fa );};_cbg .Add_BMC ("\u0054\u0078");_cbg .Add_q (); _ebe ,_fa =_aae .applyRotation (_gab ,_ebe ,_fa ,_cbg );_cbg .Add_BT ();_aaeg ,_cec ,_ff :=_aae .processDA (_gfa .PdfField ,_afc ,_bfc ,_eda ,_cbg );if _ff !=nil {return nil ,_ff ;};_fag :=_aaeg .Font ;_gd :=_aaeg .Size ;_faf :=_af .MakeName (_aaeg .Name ); _agc :=_gd ==0;if _agc &&_cec {_gd =_fa *_aae .AutoFontSizeFraction ;};_fcf :=_fag .Encoder ();if _fcf ==nil {_b .Log .Debug ("\u0057\u0041RN\u003a\u0020\u0066\u006f\u006e\u0074\u0020\u0065\u006e\u0063\u006f\u0064\u0065\u0072\u0020\u0069\u0073\u0020\u006e\u0069l\u002e\u0020\u0041\u0073s\u0075\u006d\u0069\u006eg \u0069\u0064e\u006et\u0069\u0074\u0079\u0020\u0065\u006ec\u006f\u0064\u0065r\u002e\u0020O\u0075\u0074\u0070\u0075\u0074\u0020\u006d\u0061\u0079\u0020\u0062\u0065\u0020\u0069n\u0063\u006f\u0072\u0072\u0065\u0063\u0074\u002e"); _fcf =_ac .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};_gfg ,_ff :=_fag .GetFontDescriptor ();if _ff !=nil {_b .Log .Debug ("\u0045\u0072ro\u0072\u003a\u0020U\u006e\u0061\u0062\u006ce t\u006f g\u0065\u0074\u0020\u0066\u006f\u006e\u0074 d\u0065\u0073\u0063\u0072\u0069\u0070\u0074o\u0072"); };var _fea string ;if _bb ,_db :=_af .GetString (_gfa .V );_db {_fea =_bb .Decoded ();};if len (_fea )==0{return nil ,nil ;};_bba :=[]string {_fea };_cga :=false ;if _gfa .Flags ().Has (_gf .FieldFlagMultiline ){_cga =true ;_fea =_ba .Replace (_fea ,"\u000d\u000a","\u000a",-1); _fea =_ba .Replace (_fea ,"\u000d","\u000a",-1);_bba =_ba .Split (_fea ,"\u000a");};_agd :=0.0;_beda :=0;if _fcf !=nil {_gbb :=len (_bba );_cae :=0;for _cae < _gbb {var _fbef float64 ;_eaa :=-1;_aaec :=0.0;for _eff ,_ge :=range _bba [_cae ]{if _ge ==' '{_eaa =_eff ; _fbef =_aaec ;};_bbg ,_ffg :=_fag .GetRuneMetrics (_ge );if !_ffg {_b .Log .Debug ("\u0046\u006f\u006e\u0074\u0020\u0064o\u0065\u0073\u0020\u006e\u006f\u0074\u0020\u0068\u0061\u0076\u0065\u0020\u0072\u0075\u006e\u0065\u0020\u006d\u0065\u0074r\u0069\u0063\u0073\u0020\u0066\u006f\u0072\u0020\u0025\u0076\u0020\u002d\u0020\u0073k\u0069p\u0070\u0069\u006e\u0067",_ge ); continue ;};_aaec +=_bbg .Wx ;if _cga &&!_agc &&_gd *_aaec /1000.0> _ebe &&_eaa > 0{_ddd :=_bba [_cae ][_eaa +1:];if _cae < len (_bba )-1{_bba =append (_bba [:_cae +1],_bba [_cae :]...);_bba [_cae +1]=_ddd ;}else {_bba =append (_bba ,_ddd );};_gbb ++;_bba [_cae ]=_bba [_cae ][0:_eaa ]; _aaec =_fbef ;break ;};};if _aaec > _agd {_agd =_aaec ;};_bba [_cae ]=string (_fcf .Encode (_bba [_cae ]));if len (_bba [_cae ])> 0{_beda ++;};_cae ++;};};_fcg :=2.0;if _gd ==0||_agc &&_agd > 0&&_fcg +_agd *_gd /1000.0> _ebe {_gd =0.95*1000.0*(_ebe -_fcg )/_agd ; };_deg :=_cdd ;{if _ece ,_dba :=_af .GetIntVal (_gfa .Q );_dba {switch _ece {case 0:_deg =_cdd ;case 1:_deg =_ce ;case 2:_deg =_bgg ;default:_b .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0055\u006e\u0073\u0075\u0070\u0070\u006f\u0072t\u0065\u0064\u0020\u0071\u0075\u0061\u0064\u0064\u0069\u006e\u0067\u003a\u0020%\u0064\u0020\u002d\u0020\u0075\u0073\u0069\u006e\u0067\u0020\u006c\u0065ft\u0020\u0061\u006c\u0069\u0067\u006e\u006d\u0065\u006e\u0074",_ece ); };};};_aea :=_aae .MultilineLineHeight ;_cdff :=_gd ;if _cga &&_beda > 1{_cdff =_aea *_gd ;};var _fce float64 ;if _gfg !=nil {_fce ,_ff =_gfg .GetCapHeight ();if _ff !=nil {_b .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0055\u006e\u0061\u0062\u006c\u0065 \u0074\u006f\u0020\u0067\u0065\u0074 \u0066\u006f\u006e\u0074\u0020\u0043\u0061\u0070\u0048\u0065\u0069\u0067\u0068t\u003a\u0020\u0025\u0076",_ff ); };};if int (_fce )<=0{_b .Log .Debug ("W\u0041\u0052\u004e\u003a\u0020\u0043\u0061\u0070\u0048e\u0069\u0067\u0068\u0074\u0020\u006e\u006ft \u0061\u0076\u0061\u0069l\u0061\u0062\u006c\u0065\u0020\u002d\u0020\u0073\u0065tt\u0069\u006eg\u0020\u0074\u006f\u0020\u0031\u0030\u0030\u0030"); _fce =1000;};_bgdd :=_fce /1000.0*_gd ;_dddg :=0.0;{_adc :=float64 (_beda )*_cdff ;if _agc &&_dddg +_adc > _fa {_gd =0.95*(_fa -_dddg )/float64 (_beda );_cdff =_gd ;if _cga &&_beda > 1{_cdff =_aea *_gd ;};_bgdd =_fce /1000.0*_gd ;_adc =float64 (_beda )*_cdff ; };if _fa > _adc {if _cga {if _aae .MultilineVAlignMiddle {_aaef :=(_fa -_adc )/2.0;_fdd :=_aaef +_adc -_cdff ;_dddg =_fdd ;}else {_dddg =_fa -_cdff ;_dddg -=_gd *0.5;};}else {_dddg =(_fa -_bgdd )/2.0;};};};_cbg .Add_Tf (*_faf ,_gd );_cbg .Add_Td (_fcg ,_dddg ); _bfb :=_fcg ;_da :=_fcg ;for _bca ,_bde :=range _bba {_eg :=0.0;for _ ,_fdc :=range _bde {_dc ,_fdde :=_fag .GetRuneMetrics (_fdc );if !_fdde {continue ;};_eg +=_dc .Wx ;};_ffa :=_eg /1000.0*_gd ;_adf :=_ebe -_ffa ;var _dea float64 ;switch _deg {case _cdd :_dea =_bfb ; case _ce :_dea =_adf /2;case _bgg :_dea =_adf ;};_fcg =_dea -_da ;if _fcg > 0.0{_cbg .Add_Td (_fcg ,0);};_da =_dea ;_cbg .Add_Tj (*_af .MakeString (_bde ));if _bca < len (_bba )-1{_cbg .Add_Td (0,-_cdff *_aea );};};_cbg .Add_ET ();_cbg .Add_Q ();_cbg .Add_EMC (); _ggc :=_gf .NewXObjectForm ();_ggc .Resources =_eda ;_ggc .BBox =_af .MakeArrayFromFloats ([]float64 {0,0,_bffa ,_efd });_ggc .SetContentStream (_cbg .Bytes (),_cbb ());_adg :=_af .MakeDict ();_adg .Set ("\u004e",_ggc .ToPdfObject ());return _adg ,nil ; };func _be (_ga CircleAnnotationDef )(*_af .PdfObjectDictionary ,*_gf .PdfRectangle ,error ){_afe :=_gf .NewXObjectForm ();_afe .Resources =_gf .NewPdfPageResources ();_fba :="";if _ga .Opacity < 1.0{_ec :=_af .MakeDict ();_ec .Set ("\u0063\u0061",_af .MakeFloat (_ga .Opacity )); _ec .Set ("\u0043\u0041",_af .MakeFloat (_ga .Opacity ));_de :=_afe .Resources .AddExtGState ("\u0067\u0073\u0031",_ec );if _de !=nil {_b .Log .Debug ("U\u006e\u0061\u0062\u006c\u0065\u0020t\u006f\u0020\u0061\u0064\u0064\u0020\u0065\u0078\u0074g\u0073\u0074\u0061t\u0065 \u0067\u0073\u0031"); return nil ,nil ,_de ;};_fba ="\u0067\u0073\u0031";};_gfb ,_cb ,_cbe ,_fec :=_feg (_ga ,_fba );if _fec !=nil {return nil ,nil ,_fec ;};_fec =_afe .SetContentStream (_gfb ,nil );if _fec !=nil {return nil ,nil ,_fec ;};_afe .BBox =_cb .ToPdfObject ();_gg :=_af .MakeDict (); _gg .Set ("\u004e",_afe .ToPdfObject ());return _gg ,_cbe ,nil ;};func _gea (_ced *_ae .ContentCreator ,_ege AppearanceStyle ,_cebd ,_bbff float64 ){_ced .Add_q ().Add_re (0,0,_cebd ,_bbff ).Add_w (_ege .BorderSize ).SetStrokingColor (_ege .BorderColor ).SetNonStrokingColor (_ege .FillColor ).Add_B ().Add_Q (); };func _gbf (_ecbg LineAnnotationDef ,_bbded string )([]byte ,*_gf .PdfRectangle ,*_gf .PdfRectangle ,error ){_acaa :=_aa .Line {X1 :0,Y1 :0,X2 :_ecbg .X2 -_ecbg .X1 ,Y2 :_ecbg .Y2 -_ecbg .Y1 ,LineColor :_ecbg .LineColor ,Opacity :_ecbg .Opacity ,LineWidth :_ecbg .LineWidth ,LineEndingStyle1 :_ecbg .LineEndingStyle1 ,LineEndingStyle2 :_ecbg .LineEndingStyle2 }; _bfcf ,_cegc ,_acff :=_acaa .Draw (_bbded );if _acff !=nil {return nil ,nil ,nil ,_acff ;};_abda :=&_gf .PdfRectangle {};_abda .Llx =_ecbg .X1 +_cegc .Llx ;_abda .Lly =_ecbg .Y1 +_cegc .Lly ;_abda .Urx =_ecbg .X1 +_cegc .Urx ;_abda .Ury =_ecbg .Y1 +_cegc .Ury ; return _bfcf ,_cegc ,_abda ,nil ;};func _feg (_eb CircleAnnotationDef ,_bf string )([]byte ,*_gf .PdfRectangle ,*_gf .PdfRectangle ,error ){_fc :=_aa .Circle {X :_eb .X ,Y :_eb .Y ,Width :_eb .Width ,Height :_eb .Height ,FillEnabled :_eb .FillEnabled ,FillColor :_eb .FillColor ,BorderEnabled :_eb .BorderEnabled ,BorderWidth :_eb .BorderWidth ,BorderColor :_eb .BorderColor ,Opacity :_eb .Opacity }; _cc ,_baa ,_bff :=_fc .Draw (_bf );if _bff !=nil {return nil ,nil ,nil ,_bff ;};_bd :=&_gf .PdfRectangle {};_bd .Llx =_eb .X +_baa .Llx ;_bd .Lly =_eb .Y +_baa .Lly ;_bd .Urx =_eb .X +_baa .Urx ;_bd .Ury =_eb .Y +_baa .Ury ;return _cc ,_baa ,_bd ,nil ; }; // WrapContentStream ensures that the entire content stream for a `page` is wrapped within q ... Q operands. // Ensures that following operands that are added are not affected by additional operands that are added. // Implements interface model.ContentStreamWrapper. func (_bcbb FieldAppearance )WrapContentStream (page *_gf .PdfPage )error {_fdb ,_cff :=page .GetAllContentStreams ();if _cff !=nil {return _cff ;};_ccab :=_ae .NewContentStreamParser (_fdb );_ada ,_cff :=_ccab .Parse ();if _cff !=nil {return _cff ;};_ada .WrapIfNeeded (); _ebbfc :=[]string {_ada .String ()};return page .SetContentStreams (_ebbfc ,_cbb ());};func _cbaa (_affb RectangleAnnotationDef ,_eccd string )([]byte ,*_gf .PdfRectangle ,*_gf .PdfRectangle ,error ){_gddd :=_aa .Rectangle {X :0,Y :0,Width :_affb .Width ,Height :_affb .Height ,FillEnabled :_affb .FillEnabled ,FillColor :_affb .FillColor ,BorderEnabled :_affb .BorderEnabled ,BorderWidth :2*_affb .BorderWidth ,BorderColor :_affb .BorderColor ,Opacity :_affb .Opacity }; _dafe ,_ffce ,_fdcd :=_gddd .Draw (_eccd );if _fdcd !=nil {return nil ,nil ,nil ,_fdcd ;};_eedcg :=&_gf .PdfRectangle {};_eedcg .Llx =_affb .X +_ffce .Llx ;_eedcg .Lly =_affb .Y +_ffce .Lly ;_eedcg .Urx =_affb .X +_ffce .Urx ;_eedcg .Ury =_affb .Y +_ffce .Ury ; return _dafe ,_ffce ,_eedcg ,nil ;}; // TextFieldOptions defines optional parameter for a text field in a form. type TextFieldOptions struct{MaxLen int ;Value string ;}; // SignatureLine represents a line of information in the signature field appearance. type SignatureLine struct{Desc string ;Text string ;};func _gag (_dcb RectangleAnnotationDef )(*_af .PdfObjectDictionary ,*_gf .PdfRectangle ,error ){_fca :=_gf .NewXObjectForm ();_fca .Resources =_gf .NewPdfPageResources ();_aeee :="";if _dcb .Opacity < 1.0{_ceeg :=_af .MakeDict (); _ceeg .Set ("\u0063\u0061",_af .MakeFloat (_dcb .Opacity ));_ceeg .Set ("\u0043\u0041",_af .MakeFloat (_dcb .Opacity ));_bab :=_fca .Resources .AddExtGState ("\u0067\u0073\u0031",_ceeg );if _bab !=nil {_b .Log .Debug ("U\u006e\u0061\u0062\u006c\u0065\u0020t\u006f\u0020\u0061\u0064\u0064\u0020\u0065\u0078\u0074g\u0073\u0074\u0061t\u0065 \u0067\u0073\u0031"); return nil ,nil ,_bab ;};_aeee ="\u0067\u0073\u0031";};_efc ,_geac ,_fbff ,_bdce :=_cbaa (_dcb ,_aeee );if _bdce !=nil {return nil ,nil ,_bdce ;};_bdce =_fca .SetContentStream (_efc ,nil );if _bdce !=nil {return nil ,nil ,_bdce ;};_fca .BBox =_geac .ToPdfObject (); _eabf :=_af .MakeDict ();_eabf .Set ("\u004e",_fca .ToPdfObject ());return _eabf ,_fbff ,nil ;}; // CircleAnnotationDef defines a circle annotation or ellipse at position (X, Y) and Width and Height. // The annotation has various style parameters including Fill and Border options and Opacity. type CircleAnnotationDef struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_gf .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_gf .PdfColorDeviceRGB ;Opacity float64 ;}; // CreateLineAnnotation creates a line annotation object that can be added to page PDF annotations. func CreateLineAnnotation (lineDef LineAnnotationDef )(*_gf .PdfAnnotation ,error ){_eegg :=_gf .NewPdfAnnotationLine ();_eegg .L =_af .MakeArrayFromFloats ([]float64 {lineDef .X1 ,lineDef .Y1 ,lineDef .X2 ,lineDef .Y2 });_ebeg :=_af .MakeName ("\u004e\u006f\u006e\u0065"); if lineDef .LineEndingStyle1 ==_aa .LineEndingStyleArrow {_ebeg =_af .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");};_dacf :=_af .MakeName ("\u004e\u006f\u006e\u0065");if lineDef .LineEndingStyle2 ==_aa .LineEndingStyleArrow {_dacf =_af .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077"); };_eegg .LE =_af .MakeArray (_ebeg ,_dacf );if lineDef .Opacity < 1.0{_eegg .CA =_af .MakeFloat (lineDef .Opacity );};_ccdf ,_cabf ,_aedd :=lineDef .LineColor .R (),lineDef .LineColor .G (),lineDef .LineColor .B ();_eegg .IC =_af .MakeArrayFromFloats ([]float64 {_ccdf ,_cabf ,_aedd }); _eegg .C =_af .MakeArrayFromFloats ([]float64 {_ccdf ,_cabf ,_aedd });_bffd :=_gf .NewBorderStyle ();_bffd .SetBorderWidth (lineDef .LineWidth );_eegg .BS =_bffd .ToPdfObject ();_gba ,_aaba ,_bacd :=_gefb (lineDef );if _bacd !=nil {return nil ,_bacd ;}; _eegg .AP =_gba ;_eegg .Rect =_af .MakeArrayFromFloats ([]float64 {_aaba .Llx ,_aaba .Lly ,_aaba .Urx ,_aaba .Ury });return _eegg .PdfAnnotation ,nil ;};const (SignatureImageLeft SignatureImagePosition =iota ;SignatureImageRight ;SignatureImageTop ;SignatureImageBottom ; ); // ComboboxFieldOptions defines optional parameters for a combobox form field. type ComboboxFieldOptions struct{ // Choices is the list of string values that can be selected. Choices []string ;};type quadding int ;const (_cdd quadding =0;_ce quadding =1;_bgg quadding =2;); // AppearanceFontStyle defines font style characteristics for form fields, // used in the filling/flattening process. type AppearanceFontStyle struct{ // Fallback represents a global font fallback, used for fields which do // not specify a font in their default appearance (DA). The fallback is // also used if there is a font specified in the DA, but it is not // found in the AcroForm resources (DR). Fallback *AppearanceFont ; // FieldFallbacks defines font fallbacks for specific fields. The map keys // represent the names of the fields (which can be specified by their // partial or full names). Specific field fallback fonts take precedence // over the global font fallback. FieldFallbacks map[string ]*AppearanceFont ; // ForceReplace forces the replacement of fonts in the filling/flattening // process, even if the default appearance (DA) specify a valid font. // If no fallback font is provided, setting this field has no effect. ForceReplace bool ;};func _ddda (_eef *_gf .PdfAcroForm ,_bfcc *_gf .PdfAnnotationWidget ,_ggcg *_gf .PdfFieldChoice ,_eeda AppearanceStyle )(*_af .PdfObjectDictionary ,error ){_ggd ,_eedc :=_af .GetArray (_bfcc .Rect );if !_eedc {return nil ,_f .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074"); };_cac ,_eddb :=_gf .NewPdfRectangle (*_ggd );if _eddb !=nil {return nil ,_eddb ;};_fbadd ,_faeb :=_cac .Width (),_cac .Height ();_b .Log .Debug ("\u0043\u0068\u006f\u0069\u0063\u0065\u002c\u0020\u0077\u0061\u0020\u0042S\u003a\u0020\u0025\u0076",_bfcc .BS ); _efba ,_eddb :=_ae .NewContentStreamParser (_eeg (_ggcg .PdfField )).Parse ();if _eddb !=nil {return nil ,_eddb ;};_cfd ,_bcac :=_af .GetDict (_bfcc .MK );if _bcac {_bcg ,_ :=_af .GetDict (_bfcc .BS );_gef :=_eeda .applyAppearanceCharacteristics (_cfd ,_bcg ,nil ); if _gef !=nil {return nil ,_gef ;};};_eefc :=_af .MakeDict ();for _ ,_aca :=range _ggcg .Opt .Elements (){if _geg ,_cgd :=_af .GetArray (_aca );_cgd &&_geg .Len ()==2{_aca =_geg .Get (1);};var _cge string ;if _bbde ,_fda :=_af .GetString (_aca );_fda {_cge =_bbde .Decoded (); }else if _gfaf ,_gdg :=_af .GetName (_aca );_gdg {_cge =_gfaf .String ();}else {_b .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a \u004f\u0070\u0074\u0020\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006de\u002f\u0073\u0074\u0072\u0069\u006e\u0067 \u002d\u0020\u0025\u0054",_aca ); return nil ,_f .New ("\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u002f\u0073t\u0072\u0069\u006e\u0067");};if len (_cge )> 0{_ecd ,_gff :=_gdag (_ggcg .PdfField ,_fbadd ,_faeb ,_cge ,_eeda ,_efba ,_eef .DR ,_cfd );if _gff !=nil {return nil ,_gff ; };_eefc .Set (*_af .MakeName (_cge ),_ecd .ToPdfObject ());};};_gde :=_af .MakeDict ();_gde .Set ("\u004e",_eefc );return _gde ,nil ;}; // AppearanceStyle defines style parameters for appearance stream generation. type AppearanceStyle struct{ // How much of Rect height to fill when autosizing text. AutoFontSizeFraction float64 ; // CheckmarkRune is a rune used for check mark in checkboxes (for ZapfDingbats font). CheckmarkRune rune ;BorderSize float64 ;BorderColor _gf .PdfColor ;FillColor _gf .PdfColor ; // Multiplier for lineheight for multi line text. MultilineLineHeight float64 ;MultilineVAlignMiddle bool ; // Visual guide checking alignment of field contents (debugging). DrawAlignmentReticle bool ; // Allow field MK appearance characteristics to override style settings. AllowMK bool ; // Fonts holds appearance styles for fonts. Fonts *AppearanceFontStyle ;};func (_gaba *AppearanceStyle )applyRotation (_cegg *_af .PdfObjectDictionary ,_gefc ,_fafa float64 ,_ffc *_ae .ContentCreator )(float64 ,float64 ){if !_gaba .AllowMK {return _gefc ,_fafa ;};if _cegg ==nil {return _gefc ,_fafa ; };_ddec ,_ :=_af .GetNumberAsFloat (_cegg .Get ("\u0052"));if _ddec ==0{return _gefc ,_fafa ;};_bbfc :=-_ddec ;_agaa :=_aa .Path {Points :[]_aa .Point {_aa .NewPoint (0,0).Rotate (_bbfc ),_aa .NewPoint (_gefc ,0).Rotate (_bbfc ),_aa .NewPoint (0,_fafa ).Rotate (_bbfc ),_aa .NewPoint (_gefc ,_fafa ).Rotate (_bbfc )}}.GetBoundingBox (); _ffc .RotateDeg (_ddec );_ffc .Translate (_agaa .X ,_agaa .Y );return _agaa .Width ,_agaa .Height ;};func _fcc (_dgb []*SignatureLine ,_fdae *SignatureFieldOpts )(*_af .PdfObjectDictionary ,error ){if _fdae ==nil {_fdae =NewSignatureFieldOpts ();};var _eacf error ; var _cgb *_af .PdfObjectName ;_fdf :=_fdae .Font ;if _fdf !=nil {_ggdb ,_ :=_fdf .GetFontDescriptor ();if _ggdb !=nil {if _edca ,_egaa :=_ggdb .FontName .(*_af .PdfObjectName );_egaa {_cgb =_edca ;};};if _cgb ==nil {_cgb =_af .MakeName ("\u0046\u006f\u006et\u0031"); };}else {if _fdf ,_eacf =_gf .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");_eacf !=nil {return nil ,_eacf ;};_cgb =_af .MakeName ("\u0048\u0065\u006c\u0076");};_bdca :=_fdae .FontSize ;if _bdca <=0{_bdca =10;};if _fdae .LineHeight <=0{_fdae .LineHeight =1; };_cag :=_fdae .LineHeight *_bdca ;_def ,_cgg :=_fdf .GetRuneMetrics (' ');if !_cgg {return nil ,_f .New ("\u0074\u0068e \u0066\u006f\u006et\u0020\u0064\u006f\u0065s n\u006ft \u0068\u0061\u0076\u0065\u0020\u0061\u0020sp\u0061\u0063\u0065\u0020\u0067\u006c\u0079p\u0068"); };_cacc :=_def .Wx ;var _befg float64 ;var _cbfc []string ;for _ ,_agf :=range _dgb {if _agf .Text ==""{continue ;};_bdcc :=_agf .Text ;if _agf .Desc !=""{_bdcc =_agf .Desc +"\u003a\u0020"+_bdcc ;};_cbfc =append (_cbfc ,_bdcc );var _ddeg float64 ;for _ ,_cee :=range _bdcc {_ecce ,_dac :=_fdf .GetRuneMetrics (_cee ); if !_dac {continue ;};_ddeg +=_ecce .Wx ;};if _ddeg > _befg {_befg =_ddeg ;};};_befg =_befg *_bdca /1000.0;_faed :=float64 (len (_cbfc ))*_cag ;_fefg :=_fdae .Image !=nil ;_egb :=_fdae .Rect ;if _egb ==nil {_egb =[]float64 {0,0,_befg ,_faed };if _fefg {_egb [2]=_befg *2; _egb [3]=_faed *2;};_fdae .Rect =_egb ;};_gcg :=_egb [2]-_egb [0];_ecdd :=_egb [3]-_egb [1];_eacb ,_gge :=_egb ,_egb ;var _bgef ,_ggcc float64 ;if _fefg &&len (_cbfc )> 0{if _fdae .ImagePosition <=SignatureImageRight {_efa :=[]float64 {_egb [0],_egb [1],_egb [0]+(_gcg /2),_egb [3]}; _aefe :=[]float64 {_egb [0]+(_gcg /2),_egb [1],_egb [2],_egb [3]};if _fdae .ImagePosition ==SignatureImageLeft {_eacb ,_gge =_efa ,_aefe ;}else {_eacb ,_gge =_aefe ,_efa ;};}else {_gffc :=[]float64 {_egb [0],_egb [1],_egb [2],_egb [1]+(_ecdd /2)};_fgg :=[]float64 {_egb [0],_egb [1]+(_ecdd /2),_egb [2],_egb [3]}; if _fdae .ImagePosition ==SignatureImageTop {_eacb ,_gge =_fgg ,_gffc ;}else {_eacb ,_gge =_gffc ,_fgg ;};};};_bgef =_gge [2]-_gge [0];_ggcc =_gge [3]-_gge [1];var _dgba float64 ;if _fdae .AutoSize {if _befg > _bgef ||_faed > _ggcc {_dcdb :=_c .Min (_bgef /_befg ,_ggcc /_faed ); _bdca *=_dcdb ;};_cag =_fdae .LineHeight *_bdca ;_dgba +=(_ggcc -float64 (len (_cbfc ))*_cag )/2;};_ccda :=_ae .NewContentCreator ();_ccb :=_gf .NewPdfPageResources ();_ccb .SetFontByName (*_cgb ,_fdf .ToPdfObject ());if _fdae .BorderSize <=0{_fdae .BorderSize =0; _fdae .BorderColor =_gf .NewPdfColorDeviceGray (1);};if _fdae .BorderColor ==nil {_fdae .BorderColor =_gf .NewPdfColorDeviceGray (1);};if _fdae .FillColor ==nil {_fdae .FillColor =_gf .NewPdfColorDeviceGray (1);};_ccda .Add_q ().SetNonStrokingColor (_fdae .FillColor ).SetStrokingColor (_fdae .BorderColor ).Add_w (_fdae .BorderSize ).Add_re (_egb [0],_egb [1],_gcg ,_ecdd ).Add_B ().Add_Q (); if _fdae .WatermarkImage !=nil {_afbb :=[]float64 {_egb [0],_egb [1],_egb [2],_egb [3]};_fbab ,_dfe ,_gac :=_fcgc (_fdae .WatermarkImage ,"\u0049\u006d\u0061\u0067\u0065\u0057\u0061\u0074\u0065r\u006d\u0061\u0072\u006b",_fdae ,_afbb ,_ccda );if _gac !=nil {return nil ,_gac ; };_ccb .SetXObjectImageByName (*_fbab ,_dfe );};_ccda .Add_q ();_ccda .Translate (_gge [0],_gge [3]-_cag -_dgba );_ccda .Add_BT ();_eca :=_fdf .Encoder ();for _ ,_fdda :=range _cbfc {var _dacc []byte ;for _ ,_ccg :=range _fdda {if _e .IsSpace (_ccg ){if len (_dacc )> 0{_ccda .SetNonStrokingColor (_fdae .TextColor ).Add_Tf (*_cgb ,_bdca ).Add_TL (_cag ).Add_TJ ([]_af .PdfObject {_af .MakeStringFromBytes (_dacc )}...); _dacc =nil ;};_ccda .Add_Tf (*_cgb ,_bdca ).Add_TL (_cag ).Add_TJ ([]_af .PdfObject {_af .MakeFloat (-_cacc )}...);}else {_dacc =append (_dacc ,_eca .Encode (string (_ccg ))...);};};if len (_dacc )> 0{_ccda .SetNonStrokingColor (_fdae .TextColor ).Add_Tf (*_cgb ,_bdca ).Add_TL (_cag ).Add_TJ ([]_af .PdfObject {_af .MakeStringFromBytes (_dacc )}...); };_ccda .Add_Td (0,-_cag );};_ccda .Add_ET ();_ccda .Add_Q ();if _fefg {_eefcb ,_egab ,_fbc :=_fcgc (_fdae .Image ,"\u0049\u006d\u0061\u0067\u0065\u0053\u0069\u0067\u006ea\u0074\u0075\u0072\u0065",_fdae ,_eacb ,_ccda );if _fbc !=nil {return nil ,_fbc ; };_ccb .SetXObjectImageByName (*_eefcb ,_egab );};_bgdc :=_gf .NewXObjectForm ();_bgdc .Resources =_ccb ;_bgdc .BBox =_af .MakeArrayFromFloats (_egb );_bgdc .SetContentStream (_ccda .Bytes (),_cbb ());_gcf :=_af .MakeDict ();_gcf .Set ("\u004e",_bgdc .ToPdfObject ()); return _gcf ,nil ;}; // RectangleAnnotationDef is a rectangle defined with a specified Width and Height and a lower left corner at (X,Y). // The rectangle can optionally have a border and a filling color. // The Width/Height includes the border (if any specified). type RectangleAnnotationDef struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_gf .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_gf .PdfColorDeviceRGB ;Opacity float64 ;}; // CreateCircleAnnotation creates a circle/ellipse annotation object with appearance stream that can be added to // page PDF annotations. func CreateCircleAnnotation (circDef CircleAnnotationDef )(*_gf .PdfAnnotation ,error ){_fe :=_gf .NewPdfAnnotationCircle ();if circDef .BorderEnabled {_d ,_ca ,_ef :=circDef .BorderColor .R (),circDef .BorderColor .G (),circDef .BorderColor .B ();_fe .C =_af .MakeArrayFromFloats ([]float64 {_d ,_ca ,_ef }); _aad :=_gf .NewBorderStyle ();_aad .SetBorderWidth (circDef .BorderWidth );_fe .BS =_aad .ToPdfObject ();};if circDef .FillEnabled {_cad ,_bg ,_bgd :=circDef .FillColor .R (),circDef .FillColor .G (),circDef .FillColor .B ();_fe .IC =_af .MakeArrayFromFloats ([]float64 {_cad ,_bg ,_bgd }); }else {_fe .IC =_af .MakeArrayFromIntegers ([]int {});};if circDef .Opacity < 1.0{_fe .CA =_af .MakeFloat (circDef .Opacity );};_ad ,_fb ,_cd :=_be (circDef );if _cd !=nil {return nil ,_cd ;};_fe .AP =_ad ;_fe .Rect =_af .MakeArrayFromFloats ([]float64 {_fb .Llx ,_fb .Lly ,_fb .Urx ,_fb .Ury }); return _fe .PdfAnnotation ,nil ;}; // NewTextField generates a new text field with partial name `name` at location // specified by `rect` on given `page` and with field specific options `opt`. func NewTextField (page *_gf .PdfPage ,name string ,rect []float64 ,opt TextFieldOptions )(*_gf .PdfFieldText ,error ){if page ==nil {return nil ,_f .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};if len (name )<=0{return nil ,_f .New ("\u0072\u0065\u0071\u0075\u0069\u0072\u0065\u0064\u0020\u0061\u0074\u0074\u0072\u0069\u0062u\u0074e\u0020\u006e\u006f\u0074\u0020\u0073\u0070\u0065\u0063\u0069\u0066\u0069\u0065\u0064"); };if len (rect )!=4{return nil ,_f .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");};_ggdd :=_gf .NewPdfField ();_edg :=&_gf .PdfFieldText {};_ggdd .SetContext (_edg );_edg .PdfField =_ggdd ;_edg .T =_af .MakeString (name ); if opt .MaxLen > 0{_edg .MaxLen =_af .MakeInteger (int64 (opt .MaxLen ));};if len (opt .Value )> 0{_edg .V =_af .MakeString (opt .Value );};_edb :=_gf .NewPdfAnnotationWidget ();_edb .Rect =_af .MakeArrayFromFloats (rect );_edb .P =page .ToPdfObject (); _edb .F =_af .MakeInteger (4);_edb .Parent =_edg .ToPdfObject ();_edg .Annotations =append (_edg .Annotations ,_edb );return _edg ,nil ;}; // FieldAppearance implements interface model.FieldAppearanceGenerator and generates appearance streams // for fields taking into account what value is in the field. A common use case is for generating the // appearance stream prior to flattening fields. // // If `OnlyIfMissing` is true, the field appearance is generated only for fields that do not have an // appearance stream specified. // If `RegenerateTextFields` is true, all text fields are regenerated (even if OnlyIfMissing is true). type FieldAppearance struct{OnlyIfMissing bool ;RegenerateTextFields bool ;_eba *AppearanceStyle ;};