// // 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 (_bb "bytes";_ac "errors";_a "github.com/unidoc/unipdf/v3/common";_d "github.com/unidoc/unipdf/v3/contentstream";_bc "github.com/unidoc/unipdf/v3/contentstream/draw";_c "github.com/unidoc/unipdf/v3/core";_ad "github.com/unidoc/unipdf/v3/internal/textencoding"; _ef "github.com/unidoc/unipdf/v3/model";_bbb "image";_f "math";_e "strings";_ab "unicode";);func _ffae (_ffcb *_ef .PdfPage ,_gafa _bc .Rectangle ,_dfae string ,_fegeb string ,_acef _ef .PdfColor ,_bbea *_ef .PdfFont ,_dbeb *float64 ,_aegc _c .PdfObject )(*_ef .PdfFieldButton ,error ){_bfccf ,_egae :=_gafa .X ,_gafa .Y ; _eccca :=_gafa .Width ;_gedf :=_gafa .Height ;if _gafa .FillColor ==nil {_gafa .FillColor =_ef .NewPdfColorDeviceGray (0.7);};if _acef ==nil {_acef =_ef .NewPdfColorDeviceGray (0);};if _bbea ==nil {_eba ,_ebca :=_ef .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a"); if _ebca !=nil {return nil ,_ebca ;};_bbea =_eba ;};_caee :=_ef .NewPdfField ();_ceed :=&_ef .PdfFieldButton {};_caee .SetContext (_ceed );_ceed .PdfField =_caee ;_ceed .T =_c .MakeString (_dfae );_ceed .SetType (_ef .ButtonTypePush );_ceed .V =_c .MakeName ("\u004f\u0066\u0066"); _ceed .Ff =_c .MakeInteger (4);_bge :=_c .MakeDict ();_bge .Set (*_c .MakeName ("\u0043\u0041"),_c .MakeString (_fegeb ));_bgdc ,_dcb :=_bbea .GetFontDescriptor ();if _dcb !=nil {return nil ,_dcb ;};_gdfg :=_c .MakeName ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a"); _egbb :=12.0;if _bgdc !=nil &&_bgdc .FontName !=nil {_gdfg ,_ =_c .GetName (_bgdc .FontName );};if _dbeb !=nil {_egbb =*_dbeb ;};_bcgc :=_d .NewContentCreator ();_bcgc .Add_q ();_bcgc .SetNonStrokingColor (_gafa .FillColor );_bcgc .Add_re (0,0,_eccca ,_gedf ); _bcgc .Add_f ();_bcgc .Add_Q ();_bcgc .Add_q ();_bcgc .Add_BT ();_ddcf :=0.0;for _ ,_bcdg :=range _fegeb {_fbbc ,_bgfe :=_bbea .GetRuneMetrics (_bcdg );if !_bgfe {_a .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",_bcdg ); continue ;};_ddcf +=_fbbc .Wx ;};_ddcf =_ddcf /1000.0*_egbb ;var _badc float64 ;if _bgdc !=nil {_badc ,_dcb =_bgdc .GetCapHeight ();if _dcb !=nil {_a .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",_dcb ); };};if int (_badc )<=0{_a .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"); _badc =1000;};_acaa :=_badc /1000.0*_egbb ;_afdc :=(_gedf -_acaa )/2.0;_aae :=(_eccca -_ddcf )/2.0;_bcgc .Add_Tf (*_gdfg ,_egbb );_bcgc .SetNonStrokingColor (_acef );_bcgc .Add_Td (_aae ,_afdc );_bcgc .Add_Tj (*_c .MakeString (_fegeb ));_bcgc .Add_ET (); _bcgc .Add_Q ();_ecfge :=_ef .NewXObjectForm ();_ecfge .SetContentStream (_bcgc .Bytes (),_c .NewRawEncoder ());_ecfge .BBox =_c .MakeArrayFromFloats ([]float64 {0,0,_eccca ,_gedf });_ecfge .Resources =_ef .NewPdfPageResources ();_ecfge .Resources .SetFontByName (*_gdfg ,_bbea .ToPdfObject ()); _ccad :=_c .MakeDict ();_ccad .Set ("\u004e",_ecfge .ToPdfObject ());_eada :=_ef .NewPdfAnnotationWidget ();_eada .Rect =_c .MakeArrayFromFloats ([]float64 {_bfccf ,_egae ,_bfccf +_eccca ,_egae +_gedf });_eada .P =_ffcb .ToPdfObject ();_eada .F =_c .MakeInteger (4); _eada .Parent =_ceed .ToPdfObject ();_eada .A =_aegc ;_eada .MK =_bge ;_eada .AP =_ccad ;_ceed .Annotations =append (_ceed .Annotations ,_eada );return _ceed ,nil ;};func _ccbf (_bfed LineAnnotationDef )(*_c .PdfObjectDictionary ,*_ef .PdfRectangle ,error ){_cgee :=_ef .NewXObjectForm (); _cgee .Resources =_ef .NewPdfPageResources ();_egge :="";if _bfed .Opacity < 1.0{_cgga :=_c .MakeDict ();_cgga .Set ("\u0063\u0061",_c .MakeFloat (_bfed .Opacity ));_dbggb :=_cgee .Resources .AddExtGState ("\u0067\u0073\u0031",_cgga );if _dbggb !=nil {_a .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 ,_dbggb ;};_egge ="\u0067\u0073\u0031";};_gdcg ,_acfc ,_becb ,_cfde :=_afcf (_bfed ,_egge );if _cfde !=nil {return nil ,nil ,_cfde ;};_cfde =_cgee .SetContentStream (_gdcg ,nil );if _cfde !=nil {return nil ,nil ,_cfde ;};_cgee .BBox =_acfc .ToPdfObject (); _fbd :=_c .MakeDict ();_fbd .Set ("\u004e",_cgee .ToPdfObject ());return _fbd ,_becb ,nil ;}; // CreateRectangleAnnotation creates a rectangle annotation object that can be added to page PDF annotations. func CreateRectangleAnnotation (rectDef RectangleAnnotationDef )(*_ef .PdfAnnotation ,error ){_bccg :=_ef .NewPdfAnnotationSquare ();if rectDef .BorderEnabled {_eee ,_aga ,_beaa :=rectDef .BorderColor .R (),rectDef .BorderColor .G (),rectDef .BorderColor .B (); _bccg .C =_c .MakeArrayFromFloats ([]float64 {_eee ,_aga ,_beaa });_gaeg :=_ef .NewBorderStyle ();_gaeg .SetBorderWidth (rectDef .BorderWidth );_bccg .BS =_gaeg .ToPdfObject ();};if rectDef .FillEnabled {_bgb ,_agdf ,_bga :=rectDef .FillColor .R (),rectDef .FillColor .G (),rectDef .FillColor .B (); _bccg .IC =_c .MakeArrayFromFloats ([]float64 {_bgb ,_agdf ,_bga });}else {_bccg .IC =_c .MakeArrayFromIntegers ([]int {});};if rectDef .Opacity < 1.0{_bccg .CA =_c .MakeFloat (rectDef .Opacity );};_eec ,_bgda ,_cgeae :=_fcce (rectDef );if _cgeae !=nil {return nil ,_cgeae ; };_bccg .AP =_eec ;_bccg .Rect =_c .MakeArrayFromFloats ([]float64 {_bgda .Llx ,_bgda .Lly ,_bgda .Urx ,_bgda .Ury });return _bccg .PdfAnnotation ,nil ;}; // NewSignatureFieldOpts returns a new initialized instance of options // used to generate a signature appearance. func NewSignatureFieldOpts ()*SignatureFieldOpts {return &SignatureFieldOpts {Font :_ef .DefaultFont (),FontSize :10,LineHeight :1,AutoSize :true ,TextColor :_ef .NewPdfColorDeviceGray (0),BorderColor :_ef .NewPdfColorDeviceGray (0),FillColor :_ef .NewPdfColorDeviceGray (1),Encoder :_c .NewFlateEncoder (),ImagePosition :SignatureImageLeft }; };func _deg (_fag CircleAnnotationDef )(*_c .PdfObjectDictionary ,*_ef .PdfRectangle ,error ){_bbe :=_ef .NewXObjectForm ();_bbe .Resources =_ef .NewPdfPageResources ();_ce :="";if _fag .Opacity < 1.0{_aaa :=_c .MakeDict ();_aaa .Set ("\u0063\u0061",_c .MakeFloat (_fag .Opacity )); _aaa .Set ("\u0043\u0041",_c .MakeFloat (_fag .Opacity ));_dee :=_bbe .Resources .AddExtGState ("\u0067\u0073\u0031",_aaa );if _dee !=nil {_a .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 ,_dee ;};_ce ="\u0067\u0073\u0031";};_cf ,_dd ,_df ,_dg :=_bf (_fag ,_ce );if _dg !=nil {return nil ,nil ,_dg ;};_dg =_bbe .SetContentStream (_cf ,nil );if _dg !=nil {return nil ,nil ,_dg ;};_bbe .BBox =_dd .ToPdfObject ();_ca :=_c .MakeDict (); _ca .Set ("\u004e",_bbe .ToPdfObject ());return _ca ,_df ,nil ;};func _aca (_abd *_ef .PdfField ,_aded ,_cag float64 ,_deec string ,_ecg AppearanceStyle ,_ffda *_d .ContentStreamOperations ,_eefb *_ef .PdfPageResources ,_ccga *_c .PdfObjectDictionary )(*_ef .XObjectForm ,error ){_dgda :=_ef .NewPdfPageResources (); _ffab ,_cgd :=_aded ,_cag ;_dcca :=_d .NewContentCreator ();if _ecg .BorderSize > 0{_cfcb (_dcca ,_ecg ,_aded ,_cag );};if _ecg .DrawAlignmentReticle {_dbdb :=_ecg ;_dbdb .BorderSize =0.2;_bae (_dcca ,_dbdb ,_aded ,_cag );};_dcca .Add_BMC ("\u0054\u0078"); _dcca .Add_q ();_dcca .Add_BT ();_aded ,_cag =_ecg .applyRotation (_ccga ,_aded ,_cag ,_dcca );_fgb ,_affe ,_gfbf :=_ecg .processDA (_abd ,_ffda ,_eefb ,_dgda ,_dcca );if _gfbf !=nil {return nil ,_gfbf ;};_cafc :=_fgb .Font ;_defc :=_fgb .Size ;_fbg :=_c .MakeName (_fgb .Name ); _dbcc :=_defc ==0;if _dbcc &&_affe {_defc =_cag *_ecg .AutoFontSizeFraction ;};_fgd :=_cafc .Encoder ();if _fgd ==nil {_a .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"); _fgd =_ad .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};if len (_deec )==0{return nil ,nil ;};_fege :=_bfa ;if _ecg .MarginLeft !=nil {_fege =*_ecg .MarginLeft ;};_gff :=0.0;if _fgd !=nil {for _ ,_cbfc :=range _deec {_ccb ,_ecf :=_cafc .GetRuneMetrics (_cbfc ); if !_ecf {_a .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",_cbfc ); continue ;};_gff +=_ccb .Wx ;};_deec =string (_fgd .Encode (_deec ));};if _defc ==0||_dbcc &&_gff > 0&&_fege +_gff *_defc /1000.0> _aded {_defc =0.95*1000.0*(_aded -_fege )/_gff ;};_ccdc :=1.0*_defc ;_deef :=2.0;{_ace :=_ccdc ;if _dbcc &&_deef +_ace > _cag {_defc =0.95*(_cag -_deef ); _ccdc =1.0*_defc ;_ace =_ccdc ;};if _cag > _ace {_deef =(_cag -_ace )/2.0;_deef +=1.50;};};_dcca .Add_Tf (*_fbg ,_defc );_dcca .Add_Td (_fege ,_deef );_dcca .Add_Tj (*_c .MakeString (_deec ));_dcca .Add_ET ();_dcca .Add_Q ();_dcca .Add_EMC ();_dgc :=_ef .NewXObjectForm (); _dgc .Resources =_dgda ;_dgc .BBox =_c .MakeArrayFromFloats ([]float64 {0,0,_ffab ,_cgd });_dgc .SetContentStream (_dcca .Bytes (),_dced ());return _dgc ,nil ;}; // 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 ; // FallbackSize represents a global font size fallback used for fields // which do not specify a font size in their default appearance (DA). // The fallback size is applied only if its value is larger than zero. FallbackSize float64 ; // 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) specifies a valid font. // If no fallback font is provided, setting this field has no effect. ForceReplace bool ;};func (_fcb *AppearanceStyle )applyAppearanceCharacteristics (_agd *_c .PdfObjectDictionary ,_gaa *_c .PdfObjectDictionary ,_gabg *_ef .PdfFont )error {if !_fcb .AllowMK {return nil ;};if CA ,_aaag :=_c .GetString (_agd .Get ("\u0043\u0041")); _aaag &&_gabg !=nil {_bbbd :=CA .Bytes ();if len (_bbbd )!=0{_ggcac :=[]rune (_gabg .Encoder ().Decode (_bbbd ));if len (_ggcac )==1{_fcb .CheckmarkRune =_ggcac [0];};};};if BC ,_cae :=_c .GetArray (_agd .Get ("\u0042\u0043"));_cae {_ddb ,_acfa :=BC .ToFloat64Array (); if _acfa !=nil {return _acfa ;};switch len (_ddb ){case 1:_fcb .BorderColor =_ef .NewPdfColorDeviceGray (_ddb [0]);case 3:_fcb .BorderColor =_ef .NewPdfColorDeviceRGB (_ddb [0],_ddb [1],_ddb [2]);case 4:_fcb .BorderColor =_ef .NewPdfColorDeviceCMYK (_ddb [0],_ddb [1],_ddb [2],_ddb [3]); default:_a .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 (_ddb )); };if _gaa !=nil {if _dbec ,_dccaa :=_c .GetNumberAsFloat (_gaa .Get ("\u0057"));_dccaa ==nil {_fcb .BorderSize =_dbec ;};};};if BG ,_faeb :=_c .GetArray (_agd .Get ("\u0042\u0047"));_faeb {_bbdf ,_dbga :=BG .ToFloat64Array ();if _dbga !=nil {return _dbga ; };switch len (_bbdf ){case 1:_fcb .FillColor =_ef .NewPdfColorDeviceGray (_bbdf [0]);case 3:_fcb .FillColor =_ef .NewPdfColorDeviceRGB (_bbdf [0],_bbdf [1],_bbdf [2]);case 4:_fcb .FillColor =_ef .NewPdfColorDeviceCMYK (_bbdf [0],_bbdf [1],_bbdf [2],_bbdf [3]); default:_a .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 (_bbdf )); };};return nil ;}; // CreateCircleAnnotation creates a circle/ellipse annotation object with appearance stream that can be added to // page PDF annotations. func CreateCircleAnnotation (circDef CircleAnnotationDef )(*_ef .PdfAnnotation ,error ){_aa :=_ef .NewPdfAnnotationCircle ();if circDef .BorderEnabled {_aab ,_db ,_g :=circDef .BorderColor .R (),circDef .BorderColor .G (),circDef .BorderColor .B ();_aa .C =_c .MakeArrayFromFloats ([]float64 {_aab ,_db ,_g }); _fa :=_ef .NewBorderStyle ();_fa .SetBorderWidth (circDef .BorderWidth );_aa .BS =_fa .ToPdfObject ();};if circDef .FillEnabled {_cg ,_fb ,_gg :=circDef .FillColor .R (),circDef .FillColor .G (),circDef .FillColor .B ();_aa .IC =_c .MakeArrayFromFloats ([]float64 {_cg ,_fb ,_gg }); }else {_aa .IC =_c .MakeArrayFromIntegers ([]int {});};if circDef .Opacity < 1.0{_aa .CA =_c .MakeFloat (circDef .Opacity );};_cb ,_de ,_af :=_deg (circDef );if _af !=nil {return nil ,_af ;};_aa .AP =_cb ;_aa .Rect =_c .MakeArrayFromFloats ([]float64 {_de .Llx ,_de .Lly ,_de .Urx ,_de .Ury }); return _aa .PdfAnnotation ,nil ;}; // SetStyle applies appearance `style` to `fa`. func (_ee *FieldAppearance )SetStyle (style AppearanceStyle ){_ee ._degg =&style };func _dced ()_c .StreamEncoder {return _c .NewFlateEncoder ()};func _bcd (_defg *_ef .PdfAnnotationWidget ,_ecd *_ef .PdfFieldText ,_efc *_ef .PdfPageResources ,_fbab AppearanceStyle )(*_c .PdfObjectDictionary ,error ){_eag :=_ef .NewPdfPageResources (); _abf ,_fgcd :=_c .GetArray (_defg .Rect );if !_fgcd {return nil ,_ac .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_bgd ,_ead :=_ef .NewPdfRectangle (*_abf );if _ead !=nil {return nil ,_ead ;};_dec ,_dfe :=_bgd .Width (),_bgd .Height (); _aag ,_cde :=_dec ,_dfe ;_eagb ,_faa :=_c .GetDict (_defg .MK );if _faa {_cec ,_ :=_c .GetDict (_defg .BS );_acc :=_fbab .applyAppearanceCharacteristics (_eagb ,_cec ,nil );if _acc !=nil {return nil ,_acc ;};};_ggc ,_faa :=_c .GetIntVal (_ecd .MaxLen ); if !_faa {return nil ,_ac .New ("\u006d\u0061\u0078\u006c\u0065\u006e\u0020\u006e\u006ft\u0020\u0073\u0065\u0074");};if _ggc <=0{return nil ,_ac .New ("\u006d\u0061\u0078\u004c\u0065\u006e\u0020\u0069\u006ev\u0061\u006c\u0069\u0064");};_abff :=_dec /float64 (_ggc ); _ebd ,_ead :=_d .NewContentStreamParser (_efec (_ecd .PdfField )).Parse ();if _ead !=nil {return nil ,_ead ;};_ffd :=_d .NewContentCreator ();if _fbab .BorderSize > 0{_cfcb (_ffd ,_fbab ,_dec ,_dfe );};if _fbab .DrawAlignmentReticle {_aeb :=_fbab ;_aeb .BorderSize =0.2; _bae (_ffd ,_aeb ,_dec ,_dfe );};_ffd .Add_BMC ("\u0054\u0078");_ffd .Add_q ();_ ,_dfe =_fbab .applyRotation (_eagb ,_dec ,_dfe ,_ffd );_ffd .Add_BT ();_caaa ,_cdf ,_ead :=_fbab .processDA (_ecd .PdfField ,_ebd ,_efc ,_eag ,_ffd );if _ead !=nil {return nil ,_ead ; };_fdf :=_caaa .Font ;_gfgd :=_c .MakeName (_caaa .Name );_aba :=_caaa .Size ;_beac :=_aba ==0;if _beac &&_cdf {_aba =_dfe *_fbab .AutoFontSizeFraction ;};_effb :=_fdf .Encoder ();if _effb ==nil {_a .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"); _effb =_ad .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};var _dcd string ;if _cfe ,_fae :=_c .GetString (_ecd .V );_fae {_dcd =_cfe .Decoded ();};_ffd .Add_Tf (*_gfgd ,_aba );var _eage float64 ;for _ ,_bffd :=range _dcd {_fcc ,_aff :=_fdf .GetRuneMetrics (_bffd ); if !_aff {_a .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",_bffd ); continue ;};_edbc :=_fcc .Wy ;if int (_edbc )<=0{_edbc =_fcc .Wx ;};if _edbc > _eage {_eage =_edbc ;};};if int (_eage )==0{_a .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"); _eage =1000;};_bgf ,_ead :=_fdf .GetFontDescriptor ();if _ead !=nil {_a .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 _ded float64 ;if _bgf !=nil {_ded ,_ead =_bgf .GetCapHeight ();if _ead !=nil {_a .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",_ead ); };};if int (_ded )<=0{_a .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"); _ded =1000.0;};_edaa :=_ded /1000.0*_aba ;_bbbc :=0.0;_ggbd :=1.0*_aba *(_eage /1000.0);{_dbe :=_ggbd ;if _beac &&_bbbc +_dbe > _dfe {_aba =0.95*(_dfe -_bbbc );_edaa =_ded /1000.0*_aba ;};if _dfe > _edaa {_bbbc =(_dfe -_edaa )/2.0;};};_ffd .Add_Td (0,_bbbc ); if _ebf ,_dgdd :=_c .GetIntVal (_ecd .Q );_dgdd {switch _ebf {case 2:if len (_dcd )< _ggc {_ffb :=float64 (_ggc -len (_dcd ))*_abff ;_ffd .Add_Td (_ffb ,0);};};};for _caf ,_fdfa :=range _dcd {_cda :=_bfa ;if _fbab .MarginLeft !=nil {_cda =*_fbab .MarginLeft ; };_feb :=string (_fdfa );if _effb !=nil {_afc ,_bdgf :=_fdf .GetRuneMetrics (_fdfa );if !_bdgf {_a .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",_fdfa ); continue ;};_feb =string (_effb .Encode (_feb ));_fddg :=_aba *_afc .Wx /1000.0;_dfee :=(_abff -_fddg )/2;_cda =_dfee ;};_ffd .Add_Td (_cda ,0);_ffd .Add_Tj (*_c .MakeString (_feb ));if _caf !=len (_dcd )-1{_ffd .Add_Td (_abff -_cda ,0);};};_ffd .Add_ET (); _ffd .Add_Q ();_ffd .Add_EMC ();_egdg :=_ef .NewXObjectForm ();_egdg .Resources =_eag ;_egdg .BBox =_c .MakeArrayFromFloats ([]float64 {0,0,_aag ,_cde });_egdg .SetContentStream (_ffd .Bytes (),_dced ());_ccc :=_c .MakeDict ();_ccc .Set ("\u004e",_egdg .ToPdfObject ()); return _ccc ,nil ;}; // InkAnnotationDef holds base information for constructing an ink annotation. type InkAnnotationDef struct{ // Paths is the array of stroked paths which compose the annotation. Paths []_bc .Path ; // Color is the color of the line. Default to black. Color *_ef .PdfColorDeviceRGB ; // LineWidth is the width of the line. LineWidth float64 ;}; // 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 _ef .PdfColor ;FillColor _ef .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 ; // MarginLeft represents the amount of space to leave on the left side of // the form field bounding box when generating appearances (default: 2.0). MarginLeft *float64 ;};func _febe (_fad *_ef .PdfAnnotationWidget ,_efa *_ef .PdfFieldButton ,_bfcg *_ef .PdfPageResources ,_fca AppearanceStyle )(*_c .PdfObjectDictionary ,error ){_geeg ,_efcf :=_c .GetArray (_fad .Rect );if !_efcf {return nil ,_ac .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074"); };_ega ,_dce :=_ef .NewPdfRectangle (*_geeg );if _dce !=nil {return nil ,_dce ;};_dde ,_gfb :=_ega .Width (),_ega .Height ();_dcc ,_gab :=_dde ,_gfb ;_a .Log .Debug ("\u0043\u0068\u0065\u0063kb\u006f\u0078\u002c\u0020\u0077\u0061\u0020\u0042\u0053\u003a\u0020\u0025\u0076",_fad .BS ); _caaf ,_dce :=_ef .NewStandard14Font ("\u005a\u0061\u0070f\u0044\u0069\u006e\u0067\u0062\u0061\u0074\u0073");if _dce !=nil {return nil ,_dce ;};_cdd ,_dbcg :=_c .GetDict (_fad .MK );if _dbcg {_dae ,_ :=_c .GetDict (_fad .BS );_bbdg :=_fca .applyAppearanceCharacteristics (_cdd ,_dae ,_caaf ); if _bbdg !=nil {return nil ,_bbdg ;};};_ddg :=_ef .NewXObjectForm ();{_afg :=_d .NewContentCreator ();if _fca .BorderSize > 0{_cfcb (_afg ,_fca ,_dde ,_gfb );};if _fca .DrawAlignmentReticle {_debe :=_fca ;_debe .BorderSize =0.2;_bae (_afg ,_debe ,_dde ,_gfb ); };_dde ,_gfb =_fca .applyRotation (_cdd ,_dde ,_gfb ,_afg );_bfe :=_fca .AutoFontSizeFraction *_gfb ;_fbb ,_dfab :=_caaf .GetRuneMetrics (_fca .CheckmarkRune );if !_dfab {return nil ,_ac .New ("\u0067l\u0079p\u0068\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); };_dba :=_caaf .Encoder ();_bef :=_dba .Encode (string (_fca .CheckmarkRune ));_eeff :=_fbb .Wx *_bfe /1000.0;_ccf :=705.0;_baa :=_ccf /1000.0*_bfe ;_ggfc :=_bfa ;if _fca .MarginLeft !=nil {_ggfc =*_fca .MarginLeft ;};_cddg :=1.0;if _eeff < _dde {_ggfc =(_dde -_eeff )/2.0; };if _baa < _gfb {_cddg =(_gfb -_baa )/2.0;};_afg .Add_q ().Add_g (0).Add_BT ().Add_Tf ("\u005a\u0061\u0044\u0062",_bfe ).Add_Td (_ggfc ,_cddg ).Add_Tj (*_c .MakeStringFromBytes (_bef )).Add_ET ().Add_Q ();_ddg .Resources =_ef .NewPdfPageResources ();_ddg .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_caaf .ToPdfObject ()); _ddg .BBox =_c .MakeArrayFromFloats ([]float64 {0,0,_dcc ,_gab });_ddg .SetContentStream (_afg .Bytes (),_dced ());};_baab :=_ef .NewXObjectForm ();{_abbd :=_d .NewContentCreator ();if _fca .BorderSize > 0{_cfcb (_abbd ,_fca ,_dde ,_gfb );};_baab .BBox =_c .MakeArrayFromFloats ([]float64 {0,0,_dcc ,_gab }); _baab .SetContentStream (_abbd .Bytes (),_dced ());};_egb :=_c .PdfObjectName ("\u0059\u0065\u0073");_eed ,_dbcg :=_c .GetDict (_fad .PdfAnnotation .AP );if _dbcg &&_eed !=nil {_cecf :=_c .TraceToDirectObject (_eed .Get ("\u004e"));switch _eae :=_cecf .(type ){case *_c .PdfObjectDictionary :_agc :=_eae .Keys (); for _ ,_bdb :=range _agc {if _bdb !="\u004f\u0066\u0066"{_egb =_bdb ;};};};};_beab :=_c .MakeDict ();_beab .Set ("\u004f\u0066\u0066",_baab .ToPdfObject ());_beab .Set (_egb ,_ddg .ToPdfObject ());_acf :=_c .MakeDict ();_acf .Set ("\u004e",_beab );return _acf ,nil ; };const (_cc quadding =0;_dfb quadding =1;_def quadding =2;_bfa float64 =2.0;);func _gbcc (_fcba *InkAnnotationDef )([]byte ,*_ef .PdfRectangle ,error ){_aee :=[][]_bc .CubicBezierCurve {};for _ ,_dbcf :=range _fcba .Paths {if _dbcf .Length ()==0{continue ; };_dcgg :=_dbcf .Points ;_dga ,_ffeg ,_bffe :=_deaa (_dcgg );if _bffe !=nil {return nil ,nil ,_bffe ;};if len (_dga )!=len (_ffeg ){return nil ,nil ,_ac .New ("\u0049\u006e\u0065\u0071\u0075\u0061\u006c\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020\u006f\u0066\u0020\u0063\u0061l\u0063\u0075\u006c\u0061\u0074\u0065\u0064\u0020\u0066\u0069\u0072\u0073\u0074\u0020\u0061\u006e\u0064\u0020\u0073\u0065\u0063\u006f\u006e\u0064\u0020\u0063\u006f\u006e\u0074\u0072o\u006c\u0020\u0070\u006f\u0069n\u0074"); };_cffg :=[]_bc .CubicBezierCurve {};for _beca :=0;_beca < len (_dga );_beca ++{_cffg =append (_cffg ,_bc .CubicBezierCurve {P0 :_dcgg [_beca ],P1 :_dga [_beca ],P2 :_ffeg [_beca ],P3 :_dcgg [_beca +1]});};if len (_cffg )> 0{_aee =append (_aee ,_cffg ); };};_effbb ,_bbbdb ,_afcg :=_egcc (_aee ,_fcba .Color ,_fcba .LineWidth );if _afcg !=nil {return nil ,nil ,_afcg ;};return _effbb ,_bbbdb ,nil ;};func (_ea *AppearanceFont )fillName (){if _ea .Font ==nil ||_ea .Name !=""{return ;};_fd :=_ea .Font .FontDescriptor (); if _fd ==nil ||_fd .FontName ==nil {return ;};_ea .Name =_fd .FontName .String ();}; // 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 *_ef .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_ef .PdfColorDeviceRGB ;Opacity float64 ;};func _egcc (_bcfg [][]_bc .CubicBezierCurve ,_bgc *_ef .PdfColorDeviceRGB ,_dda float64 )([]byte ,*_ef .PdfRectangle ,error ){_ebda :=_d .NewContentCreator (); _ebda .Add_q ().SetStrokingColor (_bgc ).Add_w (_dda );_cdba :=_bc .NewCubicBezierPath ();for _ ,_ddcc :=range _bcfg {_cdba .Curves =append (_cdba .Curves ,_ddcc ...);for _ddac ,_bbc :=range _ddcc {if _ddac ==0{_ebda .Add_m (_bbc .P0 .X ,_bbc .P0 .Y ); }else {_ebda .Add_l (_bbc .P0 .X ,_bbc .P0 .Y );};_ebda .Add_c (_bbc .P1 .X ,_bbc .P1 .Y ,_bbc .P2 .X ,_bbc .P2 .Y ,_bbc .P3 .X ,_bbc .P3 .Y );};};_ebda .Add_S ().Add_Q ();return _ebda .Bytes (),_cdba .GetBoundingBox ().ToPdfRectangle (),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 *_ef .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_ef .PdfColorDeviceRGB ;Opacity float64 ;}; // TextFieldOptions defines optional parameter for a text field in a form. type TextFieldOptions struct{MaxLen int ;Value string ;}; // CreateLineAnnotation creates a line annotation object that can be added to page PDF annotations. func CreateLineAnnotation (lineDef LineAnnotationDef )(*_ef .PdfAnnotation ,error ){_aegcg :=_ef .NewPdfAnnotationLine ();_aegcg .L =_c .MakeArrayFromFloats ([]float64 {lineDef .X1 ,lineDef .Y1 ,lineDef .X2 ,lineDef .Y2 });_abde :=_c .MakeName ("\u004e\u006f\u006e\u0065"); if lineDef .LineEndingStyle1 ==_bc .LineEndingStyleArrow {_abde =_c .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");};_cddf :=_c .MakeName ("\u004e\u006f\u006e\u0065");if lineDef .LineEndingStyle2 ==_bc .LineEndingStyleArrow {_cddf =_c .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077"); };_aegcg .LE =_c .MakeArray (_abde ,_cddf );if lineDef .Opacity < 1.0{_aegcg .CA =_c .MakeFloat (lineDef .Opacity );};_ceae ,_dgg ,_cfdb :=lineDef .LineColor .R (),lineDef .LineColor .G (),lineDef .LineColor .B ();_aegcg .IC =_c .MakeArrayFromFloats ([]float64 {_ceae ,_dgg ,_cfdb }); _aegcg .C =_c .MakeArrayFromFloats ([]float64 {_ceae ,_dgg ,_cfdb });_dgf :=_ef .NewBorderStyle ();_dgf .SetBorderWidth (lineDef .LineWidth );_aegcg .BS =_dgf .ToPdfObject ();_bbcd ,_egg ,_ddee :=_ccbf (lineDef );if _ddee !=nil {return nil ,_ddee ;};_aegcg .AP =_bbcd ; _aegcg .Rect =_c .MakeArrayFromFloats ([]float64 {_egg .Llx ,_egg .Lly ,_egg .Urx ,_egg .Ury });return _aegcg .PdfAnnotation ,nil ;}; // SetStyle applies appearance `style` to `fa`. func (_ecdd *ImageFieldAppearance )SetStyle (style AppearanceStyle ){_ecdd ._dcf =&style };func _dff (_gdc []*SignatureLine ,_afb *SignatureFieldOpts )(*_c .PdfObjectDictionary ,error ){if _afb ==nil {_afb =NewSignatureFieldOpts ();};var _bggd error ;var _cca *_c .PdfObjectName ; _ebcc :=_afb .Font ;if _ebcc !=nil {_eefc ,_ :=_ebcc .GetFontDescriptor ();if _eefc !=nil {if _fcg ,_efb :=_eefc .FontName .(*_c .PdfObjectName );_efb {_cca =_fcg ;};};if _cca ==nil {_cca =_c .MakeName ("\u0046\u006f\u006et\u0031");};}else {if _ebcc ,_bggd =_ef .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a"); _bggd !=nil {return nil ,_bggd ;};_cca =_c .MakeName ("\u0048\u0065\u006c\u0076");};_ffc :=_afb .FontSize ;if _ffc <=0{_ffc =10;};if _afb .LineHeight <=0{_afb .LineHeight =1;};_efcd :=_afb .LineHeight *_ffc ;_fgde ,_cea :=_ebcc .GetRuneMetrics (' ');if !_cea {return nil ,_ac .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"); };_gbbc :=_fgde .Wx ;var _afcc float64 ;var _ebcf []string ;for _ ,_dede :=range _gdc {if _dede .Text ==""{continue ;};_cdfg :=_dede .Text ;if _dede .Desc !=""{_cdfg =_dede .Desc +"\u003a\u0020"+_cdfg ;};_ebcf =append (_ebcf ,_cdfg );var _fdfe float64 ; for _ ,_eefea :=range _cdfg {_cac ,_afec :=_ebcc .GetRuneMetrics (_eefea );if !_afec {continue ;};_fdfe +=_cac .Wx ;};if _fdfe > _afcc {_afcc =_fdfe ;};};_afcc =_afcc *_ffc /1000.0;_egfe :=float64 (len (_ebcf ))*_efcd ;_bcgf :=_afb .Image !=nil ;_afca :=_afb .Rect ; if _afca ==nil {_afca =[]float64 {0,0,_afcc ,_egfe };if _bcgf {_afca [2]=_afcc *2;_afca [3]=_egfe *2;};_afb .Rect =_afca ;};_ffbaa :=_afca [2]-_afca [0];_bcgb :=_afca [3]-_afca [1];_deff ,_fegg :=_afca ,_afca ;var _gcb ,_geb float64 ;if _bcgf &&len (_ebcf )> 0{if _afb .ImagePosition <=SignatureImageRight {_fggac :=[]float64 {_afca [0],_afca [1],_afca [0]+(_ffbaa /2),_afca [3]}; _cgce :=[]float64 {_afca [0]+(_ffbaa /2),_afca [1],_afca [2],_afca [3]};if _afb .ImagePosition ==SignatureImageLeft {_deff ,_fegg =_fggac ,_cgce ;}else {_deff ,_fegg =_cgce ,_fggac ;};}else {_dbgg :=[]float64 {_afca [0],_afca [1],_afca [2],_afca [1]+(_bcgb /2)}; _dfad :=[]float64 {_afca [0],_afca [1]+(_bcgb /2),_afca [2],_afca [3]};if _afb .ImagePosition ==SignatureImageTop {_deff ,_fegg =_dfad ,_dbgg ;}else {_deff ,_fegg =_dbgg ,_dfad ;};};};_gcb =_fegg [2]-_fegg [0];_geb =_fegg [3]-_fegg [1];var _cba float64 ; if _afb .AutoSize {if _afcc > _gcb ||_egfe > _geb {_bad :=_f .Min (_gcb /_afcc ,_geb /_egfe );_ffc *=_bad ;};_efcd =_afb .LineHeight *_ffc ;_cba +=(_geb -float64 (len (_ebcf ))*_efcd )/2;};_gfe :=_d .NewContentCreator ();_aagf :=_ef .NewPdfPageResources (); _aagf .SetFontByName (*_cca ,_ebcc .ToPdfObject ());if _afb .BorderSize <=0{_afb .BorderSize =0;_afb .BorderColor =_ef .NewPdfColorDeviceGray (1);};_gfe .Add_q ();if _afb .FillColor !=nil {_gfe .SetNonStrokingColor (_afb .FillColor );};if _afb .BorderColor !=nil {_gfe .SetStrokingColor (_afb .BorderColor ); };_gfe .Add_w (_afb .BorderSize ).Add_re (_afca [0],_afca [1],_ffbaa ,_bcgb );if _afb .FillColor !=nil &&_afb .BorderColor !=nil {_gfe .Add_B ();}else if _afb .FillColor !=nil {_gfe .Add_f ();}else if _afb .BorderColor !=nil {_gfe .Add_S ();};_gfe .Add_Q (); if _afb .WatermarkImage !=nil {_baec :=[]float64 {_afca [0],_afca [1],_afca [2],_afca [3]};_abgg ,_acea ,_ddcb :=_afce (_afb .WatermarkImage ,"\u0049\u006d\u0061\u0067\u0065\u0057\u0061\u0074\u0065r\u006d\u0061\u0072\u006b",_afb ,_baec ,_gfe );if _ddcb !=nil {return nil ,_ddcb ; };_aagf .SetXObjectImageByName (*_abgg ,_acea );};_gfe .Add_q ();_gfe .Translate (_fegg [0],_fegg [3]-_efcd -_cba );_gfe .Add_BT ();_ecc :=_ebcc .Encoder ();for _ ,_gbf :=range _ebcf {var _ffcc []byte ;for _ ,_aaba :=range _gbf {if _ab .IsSpace (_aaba ){if len (_ffcc )> 0{_gfe .SetNonStrokingColor (_afb .TextColor ).Add_Tf (*_cca ,_ffc ).Add_TL (_efcd ).Add_TJ ([]_c .PdfObject {_c .MakeStringFromBytes (_ffcc )}...); _ffcc =nil ;};_gfe .Add_Tf (*_cca ,_ffc ).Add_TL (_efcd ).Add_TJ ([]_c .PdfObject {_c .MakeFloat (-_gbbc )}...);}else {_ffcc =append (_ffcc ,_ecc .Encode (string (_aaba ))...);};};if len (_ffcc )> 0{_gfe .SetNonStrokingColor (_afb .TextColor ).Add_Tf (*_cca ,_ffc ).Add_TL (_efcd ).Add_TJ ([]_c .PdfObject {_c .MakeStringFromBytes (_ffcc )}...); };_gfe .Add_Td (0,-_efcd );};_gfe .Add_ET ();_gfe .Add_Q ();if _bcgf {_adgf ,_cadb ,_bfdd :=_afce (_afb .Image ,"\u0049\u006d\u0061\u0067\u0065\u0053\u0069\u0067\u006ea\u0074\u0075\u0072\u0065",_afb ,_deff ,_gfe );if _bfdd !=nil {return nil ,_bfdd ;};_aagf .SetXObjectImageByName (*_adgf ,_cadb ); };_eac :=_ef .NewXObjectForm ();_eac .Resources =_aagf ;_eac .BBox =_c .MakeArrayFromFloats (_afca );_eac .SetContentStream (_gfe .Bytes (),_dced ());_gbc :=_c .MakeDict ();_gbc .Set ("\u004e",_eac .ToPdfObject ());return _gbc ,nil ;}; // GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`. // Implements interface model.FieldAppearanceGenerator. func (_egdd ImageFieldAppearance )GenerateAppearanceDict (form *_ef .PdfAcroForm ,field *_ef .PdfField ,wa *_ef .PdfAnnotationWidget )(*_c .PdfObjectDictionary ,error ){_ ,_ecga :=field .GetContext ().(*_ef .PdfFieldButton );if !_ecga {_a .Log .Trace ("C\u006f\u0075\u006c\u0064\u0020\u006fn\u006c\u0079\u0020\u0068\u0061\u006ed\u006c\u0065\u0020\u0062\u0075\u0074\u0074o\u006e\u0020\u002d\u0020\u0069\u0067\u006e\u006f\u0072\u0069n\u0067"); return nil ,nil ;};_gaaa ,_efaa :=_c .GetDict (wa .AP );if _efaa &&_egdd .OnlyIfMissing {_a .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 _gaaa ,nil ;};if form .DR ==nil {form .DR =_ef .NewPdfPageResources ();};switch _adad :=field .GetContext ().(type ){case *_ef .PdfFieldButton :if _adad .IsPush (){_edda ,_befg :=_egda (_adad ,wa ,_egdd .Style ());if _befg !=nil {return nil ,_befg ; };return _edda ,nil ;};};return nil ,nil ;};func _ceda (_egaf _c .PdfObject ,_dfgb *_ef .PdfPageResources )(*_c .PdfObjectName ,float64 ,bool ){var (_ffe *_c .PdfObjectName ;_fbbd float64 ;_ggdf bool ;);if _fge ,_fefb :=_c .GetDict (_egaf );_fefb &&_fge !=nil {_bbbca :=_c .TraceToDirectObject (_fge .Get ("\u004e")); switch _gaff :=_bbbca .(type ){case *_c .PdfObjectStream :_gegf ,_cadc :=_c .DecodeStream (_gaff );if _cadc !=nil {_a .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u0020\u0075\u006e\u0061\u0062\u006c\u0065\u0020\u0064\u0065\u0063\u006f\u0064\u0065\u0020\u0063\u006f\u006e\u0074e\u006e\u0074\u0020\u0073\u0074r\u0065\u0061m\u003a\u0020\u0025\u0076",_cadc .Error ()); return nil ,0,false ;};_dcdac ,_cadc :=_d .NewContentStreamParser (string (_gegf )).Parse ();if _cadc !=nil {_a .Log .Debug ("\u0045\u0052R\u004f\u0052\u0020\u0075n\u0061\u0062l\u0065\u0020\u0070\u0061\u0072\u0073\u0065\u0020c\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0073\u0074\u0072\u0065\u0061m\u003a\u0020\u0025\u0076",_cadc .Error ()); return nil ,0,false ;};_dbdd :=_d .NewContentStreamProcessor (*_dcdac );_dbdd .AddHandler (_d .HandlerConditionEnumOperand ,"\u0054\u0066",func (_cbb *_d .ContentStreamOperation ,_ebb _d .GraphicsState ,_ege *_ef .PdfPageResources )error {if len (_cbb .Params )==2{if _eab ,_adba :=_c .GetName (_cbb .Params [0]); _adba {_ffe =_eab ;};if _cdfab ,_fdg :=_c .GetNumberAsFloat (_cbb .Params [1]);_fdg ==nil {_fbbd =_cdfab ;};_ggdf =true ;return _d .ErrEarlyExit ;};return nil ;});_dbdd .Process (_dfgb );return _ffe ,_fbbd ,_ggdf ;};};return nil ,0,false ;}; // FormResetActionOptions holds options for creating a form reset button. type FormResetActionOptions struct{ // Rectangle holds the button position, size, and color. Rectangle _bc .Rectangle ; // Label specifies the text that would be displayed on the button. Label string ; // LabelColor specifies the button label color. LabelColor _ef .PdfColor ; // Font specifies a font used for rendering the button label. // When omitted it will fallback to use a Helvetica font. Font *_ef .PdfFont ; // FontSize specifies the font size used in rendering the button label. // The default font size is 12pt. FontSize *float64 ; // Fields specifies list of fields that could be resetted. // This list may contain indirect object to fields or field names. Fields *_c .PdfObjectArray ; // IsExclusionList specifies that the fields in the `Fields` array would be excluded form reset process. IsExclusionList bool ;}; // 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 *_ef .PdfFont ; // Size represents the size of the font used for the field appearance. // If the font size is 0, the value of the FallbackSize field of the // AppearanceFontStyle is used, if set. Otherwise, the font size is // calculated based on the available annotation height and on the // AutoFontSizeFraction field of the AppearanceStyle. Size float64 ;};func _cfcb (_dcda *_d .ContentCreator ,_effa AppearanceStyle ,_dbg ,_gcc float64 ){_dcda .Add_q ().Add_re (0,0,_dbg ,_gcc ).Add_w (_effa .BorderSize ).SetStrokingColor (_effa .BorderColor ).SetNonStrokingColor (_effa .FillColor ).Add_B ().Add_Q (); };func _dca (_cfg ,_dbgb float64 ,_aagc *_ef .Image ,_gdde AppearanceStyle )(*_ef .XObjectForm ,error ){_aed ,_cff :=_ef .NewXObjectImageFromImage (_aagc ,nil ,_c .NewFlateEncoder ());if _cff !=nil {return nil ,_cff ;};_aed .Decode =_c .MakeArrayFromFloats ([]float64 {0.0,1.0,0.0,1.0,0.0,1.0}); _adcd :=_ef .NewPdfPageResources ();_adcd .ProcSet =_c .MakeArray (_c .MakeName ("\u0050\u0044\u0046"),_c .MakeName ("\u0049\u006d\u0061\u0067\u0065\u0043"));_adcd .SetXObjectImageByName (_c .PdfObjectName ("\u0049\u006d\u0030"),_aed );_aedb :=_d .NewContentCreator (); _aedb .Add_q ();_aedb .Add_cm (float64 (_aagc .Width ),0,0,float64 (_aagc .Height ),0,0);_aedb .Add_Do ("\u0049\u006d\u0030");_aedb .Add_Q ();_bed :=_ef .NewXObjectForm ();_bed .FormType =_c .MakeInteger (1);_bed .BBox =_c .MakeArrayFromFloats ([]float64 {0,0,float64 (_aagc .Width ),float64 (_aagc .Height )}); _bed .Resources =_adcd ;_bed .SetContentStream (_aedb .Bytes (),_dced ());return _bed ,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 *_ef .PdfSignature ,lines []*SignatureLine ,opts *SignatureFieldOpts )(*_ef .PdfFieldSignature ,error ){if signature ==nil {return nil ,_ac .New ("\u0073\u0069\u0067na\u0074\u0075\u0072\u0065\u0020\u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u006e\u0069\u006c"); };_efdc ,_daea :=_dff (lines ,opts );if _daea !=nil {return nil ,_daea ;};_eea :=_ef .NewPdfFieldSignature (signature );_eea .Rect =_c .MakeArrayFromFloats (opts .Rect );_eea .AP =_efdc ;return _eea ,nil ;}; // ImageFieldOptions defines optional parameters for a push button with image attach capability form field. type ImageFieldOptions struct{Image *_ef .Image ;_cce AppearanceStyle ;};func (_cdfa *AppearanceStyle )processDA (_cbc *_ef .PdfField ,_dbfb *_d .ContentStreamOperations ,_fgab ,_gdb *_ef .PdfPageResources ,_bceg *_d .ContentCreator )(*AppearanceFont ,bool ,error ){var _afge *AppearanceFont ; var _bag bool ;if _cdfa .Fonts !=nil {if _cdfa .Fonts .Fallback !=nil {_afge =_cdfa .Fonts .Fallback ;};if _bgdf :=_cdfa .Fonts .FieldFallbacks ;_bgdf !=nil {if _bgfg ,_ada :=_bgdf [_cbc .PartialName ()];_ada {_afge =_bgfg ;}else if _dgeb ,_edac :=_cbc .FullName (); _edac ==nil {if _cgeb ,_afef :=_bgdf [_dgeb ];_afef {_afge =_cgeb ;};};};if _afge !=nil {_afge .fillName ();};_bag =_cdfa .Fonts .ForceReplace ;};var _debf string ;var _bcg float64 ;var _efed bool ;if _dbfb !=nil {for _ ,_dag :=range *_dbfb {if _dag .Operand =="\u0054\u0066"&&len (_dag .Params )==2{if _bbec ,_dbfa :=_c .GetNameVal (_dag .Params [0]); _dbfa {_debf =_bbec ;};if _cad ,_cdeg :=_c .GetNumberAsFloat (_dag .Params [1]);_cdeg ==nil {_bcg =_cad ;};_efed =true ;continue ;};_bceg .AddOperand (*_dag );};};var _cbdcd *AppearanceFont ;var _egfd _c .PdfObject ;if _bag &&_afge !=nil {_cbdcd =_afge ; }else {if _fgab !=nil &&_debf !=""{if _cbfg ,_defa :=_fgab .GetFontByName (*_c .MakeName (_debf ));_defa {if _fccg ,_ffba :=_ef .NewPdfFontFromPdfObject (_cbfg );_ffba ==nil {_egfd =_cbfg ;_cbdcd =&AppearanceFont {Name :_debf ,Font :_fccg ,Size :_bcg }; }else {_a .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",_ffba ); };};};if _cbdcd ==nil &&_afge !=nil {_cbdcd =_afge ;};if _cbdcd ==nil {_caad ,_fgga :=_ef .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");if _fgga !=nil {return nil ,false ,_fgga ;};_cbdcd =&AppearanceFont {Name :"\u0048\u0065\u006c\u0076",Font :_caad ,Size :_bcg }; };};if _cbdcd .Size <=0&&_cdfa .Fonts !=nil &&_cdfa .Fonts .FallbackSize > 0{_cbdcd .Size =_cdfa .Fonts .FallbackSize ;};_bfdg :=*_c .MakeName (_cbdcd .Name );if _egfd ==nil {_egfd =_cbdcd .Font .ToPdfObject ();};if _fgab !=nil &&!_fgab .HasFontByName (_bfdg ){_fgab .SetFontByName (_bfdg ,_egfd ); };if _gdb !=nil &&!_gdb .HasFontByName (_bfdg ){_gdb .SetFontByName (_bfdg ,_egfd );};return _cbdcd ,_efed ,nil ;}; // 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 ; // 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 *_ef .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 _ef .PdfColor ; // FillColor represents the background color of the appearance annotation area. FillColor _ef .PdfColor ; // BorderSize represents border size of the appearance annotation area. BorderSize float64 ; // BorderColor represents the border color of the appearance annotation area. BorderColor _ef .PdfColor ; // WatermarkImage specifies the image used as a watermark that will be rendered // behind the signature. WatermarkImage _bbb .Image ; // Image represents the image used for the signature appearance. Image _bbb .Image ; // Encoder specifies the image encoder used for image signature. Defaults to flate encoder. Encoder _c .StreamEncoder ; // ImagePosition specifies the image location relative to the text signature. ImagePosition SignatureImagePosition ;}; // CheckboxFieldOptions defines optional parameters for a checkbox field a form. type CheckboxFieldOptions struct{Checked bool ;};func _egda (_eca *_ef .PdfFieldButton ,_cace *_ef .PdfAnnotationWidget ,_dfag AppearanceStyle )(*_c .PdfObjectDictionary ,error ){_becf ,_ebdb :=_c .GetArray (_cace .Rect );if !_ebdb {return nil ,_ac .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074"); };_gbba ,_egbe :=_ef .NewPdfRectangle (*_becf );if _egbe !=nil {return nil ,_egbe ;};_ecbd ,_dcce :=_gbba .Width (),_gbba .Height ();_bgfc :=_d .NewContentCreator ();if _dfag .BorderSize > 0{_cfcb (_bgfc ,_dfag ,_ecbd ,_dcce );};if _dfag .DrawAlignmentReticle {_bfdc :=_dfag ; _bfdc .BorderSize =0.2;_bae (_bgfc ,_bfdc ,_ecbd ,_dcce );};_dbba :=_eca .GetFillImage ();_cacee ,_egbe :=_dca (_ecbd ,_dcce ,_dbba ,_dfag );if _egbe !=nil {return nil ,_egbe ;};_ecfga ,_ddd :=_c .GetDict (_cace .MK );if _ddd {_ecfga .Set ("\u006c",_cacee .ToPdfObject ()); };_cbdfd :=_c .MakeDict ();_cbdfd .Set ("\u0046\u0052\u004d",_cacee .ToPdfObject ());_aefc :=_ef .NewPdfPageResources ();_aefc .ProcSet =_c .MakeArray (_c .MakeName ("\u0050\u0044\u0046"));_aefc .XObject =_cbdfd ;_eace :=_ecbd -2;_bfadd :=_dcce -2;_bgfc .Add_q (); _bgfc .Add_re (1,1,_eace ,_bfadd );_bgfc .Add_W ();_bgfc .Add_n ();_eace -=2;_bfadd -=2;_bgfc .Add_q ();_bgfc .Add_re (2,2,_eace ,_bfadd );_bgfc .Add_W ();_bgfc .Add_n ();_dffd :=_f .Min (_eace /float64 (_dbba .Width ),_bfadd /float64 (_dbba .Height )); _bgfc .Add_cm (_dffd ,0,0,_dffd ,(_ecbd /2)-(float64 (_dbba .Width )*_dffd /2)+2,2);_bgfc .Add_Do ("\u0046\u0052\u004d");_bgfc .Add_Q ();_bgfc .Add_Q ();_cbbab :=_ef .NewXObjectForm ();_cbbab .FormType =_c .MakeInteger (1);_cbbab .Resources =_aefc ;_cbbab .BBox =_c .MakeArrayFromFloats ([]float64 {0,0,_ecbd ,_dcce }); _cbbab .Matrix =_c .MakeArrayFromFloats ([]float64 {1.0,0.0,0.0,1.0,0.0,0.0});_cbbab .SetContentStream (_bgfc .Bytes (),_dced ());_ffcbe :=_c .MakeDict ();_ffcbe .Set ("\u004e",_cbbab .ToPdfObject ());return _ffcbe ,nil ;};func _eagg (_ggfac *InkAnnotationDef )(*_c .PdfObjectDictionary ,*_ef .PdfRectangle ,error ){_fgba :=_ef .NewXObjectForm (); _fggb ,_dbbe ,_egc :=_gbcc (_ggfac );if _egc !=nil {return nil ,nil ,_egc ;};_egc =_fgba .SetContentStream (_fggb ,nil );if _egc !=nil {return nil ,nil ,_egc ;};_fgba .BBox =_dbbe .ToPdfObject ();_fgba .Resources =_ef .NewPdfPageResources ();_fgba .Resources .ProcSet =_c .MakeArray (_c .MakeName ("\u0050\u0044\u0046")); _gbag :=_c .MakeDict ();_gbag .Set ("\u004e",_fgba .ToPdfObject ());return _gbag ,_dbbe ,nil ;};const (_fgf =1;_eedbg =2;_fagg =4;_ddcd =8;_feff =16;_cdaag =32;_adaf =64;_dfbg =128;_cfbe =256;_ffgd =512;_cgea =1024;_edbe =2048;_ceef =4096;); // 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 *_ef .PdfPage ,name string ,rect []float64 ,opt ComboboxFieldOptions )(*_ef .PdfFieldChoice ,error ){if page ==nil {return nil ,_ac .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064"); };if len (name )<=0{return nil ,_ac .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 ,_ac .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065"); };_cebf :=_ef .NewPdfField ();_afbc :=&_ef .PdfFieldChoice {};_cebf .SetContext (_afbc );_afbc .PdfField =_cebf ;_afbc .T =_c .MakeString (name );_afbc .Opt =_c .MakeArray ();for _ ,_eccc :=range opt .Choices {_afbc .Opt .Append (_c .MakeString (_eccc )); };_afbc .SetFlag (_ef .FieldFlagCombo );_fdfaa :=_ef .NewPdfAnnotationWidget ();_fdfaa .Rect =_c .MakeArrayFromFloats (rect );_fdfaa .P =page .ToPdfObject ();_fdfaa .F =_c .MakeInteger (4);_fdfaa .Parent =_afbc .ToPdfObject ();_afbc .Annotations =append (_afbc .Annotations ,_fdfaa ); return _afbc ,nil ;};func _bf (_ggg CircleAnnotationDef ,_dgd string )([]byte ,*_ef .PdfRectangle ,*_ef .PdfRectangle ,error ){_bfc :=_bc .Circle {X :_ggg .X ,Y :_ggg .Y ,Width :_ggg .Width ,Height :_ggg .Height ,FillEnabled :_ggg .FillEnabled ,FillColor :_ggg .FillColor ,BorderEnabled :_ggg .BorderEnabled ,BorderWidth :_ggg .BorderWidth ,BorderColor :_ggg .BorderColor ,Opacity :_ggg .Opacity }; _da ,_cbe ,_dfd :=_bfc .Draw (_dgd );if _dfd !=nil {return nil ,nil ,nil ,_dfd ;};_fg :=&_ef .PdfRectangle {};_fg .Llx =_ggg .X +_cbe .Llx ;_fg .Lly =_ggg .Y +_cbe .Lly ;_fg .Urx =_ggg .X +_cbe .Urx ;_fg .Ury =_ggg .Y +_cbe .Ury ;return _da ,_cbe ,_fg ,nil ; }; // FormSubmitActionOptions holds options for creating a form submit button. type FormSubmitActionOptions struct{ // Rectangle holds the button position, size, and color. Rectangle _bc .Rectangle ; // Url specifies the URL where the fieds will be submitted. Url string ; // Label specifies the text that would be displayed on the button. Label string ; // LabelColor specifies the button label color. LabelColor _ef .PdfColor ; // Font specifies a font used for rendering the button label. // When omitted it will fallback to use a Helvetica font. Font *_ef .PdfFont ; // FontSize specifies the font size used in rendering the button label. // The default font size is 12pt. FontSize *float64 ; // Fields specifies list of fields that could be submitted. // This list may contain indirect object to fields or field names. Fields *_c .PdfObjectArray ; // IsExclusionList specifies that the fields contain in `Fields` array would not be submitted. IsExclusionList bool ; // IncludeEmptyFields specifies if all fields would be submitted even though it's value is empty. IncludeEmptyFields bool ; // SubmitAsPDF specifies that the document shall be submitted as PDF. // If set then all the other flags shall be ignored. SubmitAsPDF bool ;}; // SignatureLine represents a line of information in the signature field appearance. type SignatureLine struct{Desc string ;Text string ;};func _afa (_ddc *_ef .PdfAnnotationWidget ,_efd *_ef .PdfFieldText ,_ff *_ef .PdfPageResources ,_bfd AppearanceStyle )(*_c .PdfObjectDictionary ,error ){_gbb :=_ef .NewPdfPageResources ();_bbd ,_ffa :=_c .GetArray (_ddc .Rect ); if !_ffa {return nil ,_ac .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_daa ,_eb :=_ef .NewPdfRectangle (*_bbd );if _eb !=nil {return nil ,_eb ;};_cfcc ,_be :=_daa .Width (),_daa .Height ();_bbae ,_ge :=_cfcc ,_be ;_dbf :=true ; _ga :=_ef .NewXObjectForm ();_ga .BBox =_c .MakeArrayFromFloats ([]float64 {0,0,_bbae ,_ge });if _ddc .AP !=nil {if _eff ,_bfcd :=_c .GetDict (_ddc .AP );_bfcd &&_eff !=nil {_cfd :=_c .TraceToDirectObject (_eff .Get ("\u004e"));switch _bg :=_cfd .(type ){case *_c .PdfObjectStream :_ed ,_fea :=_c .DecodeStream (_bg ); if _fea !=nil {_a .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u0020\u0075\u006e\u0061\u0062\u006c\u0065\u0020\u0064\u0065\u0063\u006f\u0064\u0065\u0020\u0063\u006f\u006e\u0074e\u006e\u0074\u0020\u0073\u0074r\u0065\u0061m\u003a\u0020\u0025\u0076",_fea .Error ()); break ;};_edf ,_fea :=_d .NewContentStreamParser (string (_ed )).Parse ();if _fea !=nil {_a .Log .Debug ("\u0045\u0052R\u004f\u0052\u0020\u0075n\u0061\u0062l\u0065\u0020\u0070\u0061\u0072\u0073\u0065\u0020c\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0073\u0074\u0072\u0065\u0061m\u003a\u0020\u0025\u0076",_fea .Error ()); break ;};_ae :=_d .NewContentStreamProcessor (*_edf );_ae .AddHandler (_d .HandlerConditionEnumAllOperands ,"",func (_abb *_d .ContentStreamOperation ,_aaab _d .GraphicsState ,_gggb *_ef .PdfPageResources )error {if _abb .Operand =="\u0054\u006a"||_abb .Operand =="\u0054\u004a"{if len (_abb .Params )==1{if _eeg ,_egfc :=_c .GetString (_abb .Params [0]); _egfc {_dbf =_e .TrimSpace (_eeg .Str ())=="";};return _d .ErrEarlyExit ;};return nil ;};return nil ;});_ae .Process (nil );if !_dbf {if _fec ,_eegd :=_c .GetDict (_bg .Get ("\u0052e\u0073\u006f\u0075\u0072\u0063\u0065s"));_eegd {_gbb ,_fea =_ef .NewPdfPageResourcesFromDict (_fec ); if _fea !=nil {return nil ,_fea ;};};if _fc ,_ggac :=_c .GetArray (_bg .Get ("\u004d\u0061\u0074\u0072\u0069\u0078"));_ggac {_ga .Matrix =_fc ;};_ga .SetContentStream (_ed ,_dced ());};};};};if _dbf {_ebc ,_cbd :=_c .GetDict (_ddc .MK );if _cbd {_bca ,_ :=_c .GetDict (_ddc .BS ); _bfad :=_bfd .applyAppearanceCharacteristics (_ebc ,_bca ,nil );if _bfad !=nil {return nil ,_bfad ;};};_fgc ,_eaa :=_d .NewContentStreamParser (_efec (_efd .PdfField )).Parse ();if _eaa !=nil {return nil ,_eaa ;};_gd :=_d .NewContentCreator ();if _bfd .BorderSize > 0{_cfcb (_gd ,_bfd ,_cfcc ,_be ); };if _bfd .DrawAlignmentReticle {_ec :=_bfd ;_ec .BorderSize =0.2;_bae (_gd ,_ec ,_cfcc ,_be );};_gd .Add_BMC ("\u0054\u0078");_gd .Add_q ();_cfcc ,_be =_bfd .applyRotation (_ebc ,_cfcc ,_be ,_gd );_gd .Add_BT ();_dfbd ,_dfc ,_eaa :=_bfd .processDA (_efd .PdfField ,_fgc ,_ff ,_gbb ,_gd ); if _eaa !=nil {return nil ,_eaa ;};_edb :=_dfbd .Font ;_dbd :=_dfbd .Size ;_ggf :=_c .MakeName (_dfbd .Name );if _efd .Flags ().Has (_ef .FieldFlagMultiline )&&_efd .MaxLen !=nil {_a .Log .Debug ("\u004c\u006f\u006f\u006b\u0020\u0066\u006f\u0072\u0020\u0041\u0050\u0020\u0064\u0069\u0063\u0074\u0069\u006fn\u0061\u0072\u0079\u0020\u0066\u006f\u0072 \u004e\u0020\u006f\u0062\u006a\u0065\u0063\u0074\u0020\u0063\u006fn\u0074\u0065\u006e\u0074\u0020\u0073\u0074\u0072\u0065\u0061\u006d"); if _cdg ,_efe ,_eaab :=_ceda (_ddc .PdfAnnotation .AP ,_ff );_eaab {_ggf =_cdg ;_dbd =_efe ;_dfc =true ;};};_gf :=_dbd ==0;if _gf &&_dfc {_dbd =_be *_bfd .AutoFontSizeFraction ;};_dea :=_edb .Encoder ();if _dea ==nil {_a .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"); _dea =_ad .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};_cee ,_eaa :=_edb .GetFontDescriptor ();if _eaa !=nil {_a .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 _fcd string ;if _gee ,_aef :=_c .GetString (_efd .V );_aef {_fcd =_gee .Decoded ();};if len (_fcd )==0{return nil ,nil ;};_afd :=[]string {_fcd };_ceb :=false ;if _efd .Flags ().Has (_ef .FieldFlagMultiline ){_ceb =true ;_fcd =_e .Replace (_fcd ,"\u000d\u000a","\u000a",-1); _fcd =_e .Replace (_fcd ,"\u000d","\u000a",-1);_afd =_e .Split (_fcd ,"\u000a");};_gc :=make ([]string ,len (_afd ));copy (_gc ,_afd );_gaf :=_bfd .MultilineLineHeight ;_cbdd :=0.0;_ddf :=0;if _dea !=nil {for _dbd >=0{_ced :=make ([]string ,len (_afd )); copy (_ced ,_afd );_ebg :=make ([]string ,len (_gc ));copy (_ebg ,_gc );_cbdd =0.0;_ddf =0;_ag :=len (_ced );_fagd :=0;for _fagd < _ag {var _cbdc float64 ;_cgc :=-1;_fbe :=_bfa ;if _bfd .MarginLeft !=nil {_fbe =*_bfd .MarginLeft ;};for _bdg ,_cge :=range _ced [_fagd ]{if _cge ==' '{_cgc =_bdg ; };_eef ,_egd :=_edb .GetRuneMetrics (_cge );if !_egd {_a .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",_cge ); continue ;};_cbdc =_fbe ;_fbe +=_eef .Wx ;if _ceb &&!_gf &&_dbd *_fbe /1000.0> _cfcc {_caa :=_bdg ;_eefe :=_bdg ;if _cgc > 0{_caa =_cgc +1;_eefe =_cgc ;};_cbf :=_ced [_fagd ][_caa :];_gce :=_ebg [_fagd ][_caa :];if _fagd < len (_ced )-1{_ced =append (_ced [:_fagd +1],_ced [_fagd :]...); _ced [_fagd +1]=_cbf ;_ebg =append (_ebg [:_fagd +1],_ebg [_fagd :]...);_ebg [_fagd +1]=_gce ;}else {_ced =append (_ced ,_cbf );_ebg =append (_ebg ,_gce );};_ced [_fagd ]=_ced [_fagd ][0:_eefe ];_ebg [_fagd ]=_ebg [_fagd ][0:_eefe ];_ag ++;_fbe =_cbdc ; break ;};};if _fbe > _cbdd {_cbdd =_fbe ;};_ced [_fagd ]=string (_dea .Encode (_ced [_fagd ]));if len (_ced [_fagd ])> 0{_ddf ++;};_fagd ++;};_bce :=_dbd ;if _ddf > 1{_bce *=_gaf ;};_gde :=float64 (_ddf )*_bce ;if _gf ||_gde <=_be {_afd =_ced ;_gc =_ebg ; break ;};_dbd --;};};_bea :=_bfa ;if _bfd .MarginLeft !=nil {_bea =*_bfd .MarginLeft ;};if _dbd ==0||_gf &&_cbdd > 0&&_bea +_cbdd *_dbd /1000.0> _cfcc {_dbd =0.95*1000.0*(_cfcc -_bea )/_cbdd ;};_acb :=_cc ;{if _ba ,_edd :=_c .GetIntVal (_efd .Q );_edd {switch _ba {case 0:_acb =_cc ; case 1:_acb =_dfb ;case 2:_acb =_def ;default:_a .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",_ba ); };};};_bbed :=_dbd ;if _ceb &&_ddf > 1{_bbed =_gaf *_dbd ;};var _afe float64 ;if _cee !=nil {_afe ,_eaa =_cee .GetCapHeight ();if _eaa !=nil {_a .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",_eaa ); };};if int (_afe )<=0{_a .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"); _afe =1000;};_bec :=_afe /1000.0*_dbd ;_gcf :=0.0;{_fbac :=float64 (_ddf )*_bbed ;if _gf &&_gcf +_fbac > _be {_dbd =0.95*(_be -_gcf )/float64 (_ddf );_bbed =_dbd ;if _ceb &&_ddf > 1{_bbed =_gaf *_dbd ;};_bec =_afe /1000.0*_dbd ;_fbac =float64 (_ddf )*_bbed ; };if _be > _fbac {if _ceb {if _bfd .MultilineVAlignMiddle {_bfcc :=(_be -(_fbac +_bec ))/2.0;_cebb :=_bfcc +_fbac +_bec -_bbed ;_gcf =_cebb ;if _ddf > 1{_gcf =_gcf +(_fbac /_dbd *float64 (_ddf ))-_bbed -_bec ;};if _gcf < _fbac {_gcf =(_be -_bec )/2.0;}; }else {_gcf =_be -_bbed ;if _gcf > _dbd {_bab :=0.0;if _ceb &&_bfd .MultilineLineHeight > 1&&_ddf > 1{_bab =_bfd .MultilineLineHeight -1;};_gcf -=_dbd *(0.5-_bab );};};}else {_gcf =(_be -_bec )/2.0;};};};_gd .Add_Tf (*_ggf ,_dbd );_gd .Add_Td (_bea ,_gcf ); _agb :=_bea ;_cab :=_bea ;for _deb ,_dc :=range _afd {_ggb :=0.0;for _ ,_dbcb :=range _gc [_deb ]{_dcg ,_abba :=_edb .GetRuneMetrics (_dbcb );if !_abba {continue ;};_ggb +=_dcg .Wx ;};_bff :=_ggb /1000.0*_dbd ;_gfg :=_cfcc -_bff ;var _fdd float64 ;switch _acb {case _cc :_fdd =_agb ; case _dfb :_fdd =_gfg /2;case _def :_fdd =_gfg ;};_bea =_fdd -_cab ;if _bea > 0.0{_gd .Add_Td (_bea ,0);};_cab =_fdd ;_gd .Add_Tj (*_c .MakeString (_dc ));if _deb < len (_afd )-1{_gd .Add_Td (0,-_dbd *_gaf );};};_gd .Add_ET ();_gd .Add_Q ();_gd .Add_EMC (); _ga .SetContentStream (_gd .Bytes (),_dced ());};_ga .Resources =_gbb ;_gaed :=_c .MakeDict ();_gaed .Set ("\u004e",_ga .ToPdfObject ());return _gaed ,nil ;}; // NewImageField generates a new image field with partial name `name` at location `rect` // on specified `page` and with field specific options `opt`. func NewImageField (page *_ef .PdfPage ,name string ,rect []float64 ,opt ImageFieldOptions )(*_ef .PdfFieldButton ,error ){if page ==nil {return nil ,_ac .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064"); };if len (name )<=0{return nil ,_ac .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 ,_ac .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065"); };_eabd :=_ef .NewPdfField ();_fed :=&_ef .PdfFieldButton {};_fed .PdfField =_eabd ;_eabd .SetContext (_fed );_fed .SetType (_ef .ButtonTypePush );_fed .T =_c .MakeString (name );_dcec :=_ef .NewPdfAnnotationWidget ();_dcec .Rect =_c .MakeArrayFromFloats (rect ); _dcec .P =page .ToPdfObject ();_dcec .F =_c .MakeInteger (4);_dcec .Parent =_fed .ToPdfObject ();_dfadg :=rect [2]-rect [0];_addd :=rect [3]-rect [1];_cbba :=opt ._cce ;_egag :=_d .NewContentCreator ();if _cbba .BorderSize > 0{_cfcb (_egag ,_cbba ,_dfadg ,_addd ); };if _cbba .DrawAlignmentReticle {_geegc :=_cbba ;_geegc .BorderSize =0.2;_bae (_egag ,_geegc ,_dfadg ,_addd );};_gdef ,_gad :=_dca (_dfadg ,_addd ,opt .Image ,_cbba );if _gad !=nil {return nil ,_gad ;};_gbaf ,_acdd :=_c .GetDict (_dcec .MK );if _acdd {_gbaf .Set ("\u006c",_gdef .ToPdfObject ()); };_bccf :=_c .MakeDict ();_bccf .Set ("\u0046\u0052\u004d",_gdef .ToPdfObject ());_dccg :=_ef .NewPdfPageResources ();_dccg .ProcSet =_c .MakeArray (_c .MakeName ("\u0050\u0044\u0046"));_dccg .XObject =_bccf ;_eaefd :=_dfadg -2;_bdd :=_addd -2;_egag .Add_q (); _egag .Add_re (1,1,_eaefd ,_bdd );_egag .Add_W ();_egag .Add_n ();_eaefd -=2;_bdd -=2;_egag .Add_q ();_egag .Add_re (2,2,_eaefd ,_bdd );_egag .Add_W ();_egag .Add_n ();_cbdf :=_f .Min (_eaefd /float64 (opt .Image .Width ),_bdd /float64 (opt .Image .Height )); _egag .Add_cm (_cbdf ,0,0,_cbdf ,(_dfadg /2)-(float64 (opt .Image .Width )*_cbdf /2)+2,2);_egag .Add_Do ("\u0046\u0052\u004d");_egag .Add_Q ();_egag .Add_Q ();_cdec :=_ef .NewXObjectForm ();_cdec .FormType =_c .MakeInteger (1);_cdec .Resources =_dccg ; _cdec .BBox =_c .MakeArrayFromFloats ([]float64 {0,0,_dfadg ,_addd });_cdec .Matrix =_c .MakeArrayFromFloats ([]float64 {1.0,0.0,0.0,1.0,0.0,0.0});_cdec .SetContentStream (_egag .Bytes (),_dced ());_bbeb :=_c .MakeDict ();_bbeb .Set ("\u004e",_cdec .ToPdfObject ()); _dcec .AP =_bbeb ;_fed .Annotations =append (_fed .Annotations ,_dcec );return _fed ,nil ;}; // GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`. // Implements interface model.FieldAppearanceGenerator. func (_fba FieldAppearance )GenerateAppearanceDict (form *_ef .PdfAcroForm ,field *_ef .PdfField ,wa *_ef .PdfAnnotationWidget )(*_c .PdfObjectDictionary ,error ){_a .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 ); _ ,_bcb :=field .GetContext ().(*_ef .PdfFieldText );_cfc ,_bd :=_c .GetDict (wa .AP );if _bd &&_fba .OnlyIfMissing &&(!_bcb ||!_fba .RegenerateTextFields ){_a .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 _cfc ,nil ;};if form .DR ==nil {form .DR =_ef .NewPdfPageResources ();};switch _fga :=field .GetContext ().(type ){case *_ef .PdfFieldText :_fbf :=_fga ;if _fe :=_efec (_fbf .PdfField );_fe ==""{_fbf .DA =form .DA ;};switch {case _fbf .Flags ().Has (_ef .FieldFlagPassword ):return nil ,nil ; case _fbf .Flags ().Has (_ef .FieldFlagFileSelect ):return nil ,nil ;case _fbf .Flags ().Has (_ef .FieldFlagComb ):if _fbf .MaxLen !=nil {_acd ,_fgg :=_bcd (wa ,_fbf ,form .DR ,_fba .Style ());if _fgg !=nil {return nil ,_fgg ;};return _acd ,nil ;};};_ccd ,_gb :=_afa (wa ,_fbf ,form .DR ,_fba .Style ()); if _gb !=nil {return nil ,_gb ;};return _ccd ,nil ;case *_ef .PdfFieldButton :_bfb :=_fga ;if _bfb .IsCheckbox (){_dfa ,_gge :=_febe (wa ,_bfb ,form .DR ,_fba .Style ());if _gge !=nil {return nil ,_gge ;};return _dfa ,nil ;};_a .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",_bfb .GetType ()); case *_ef .PdfFieldChoice :_gga :=_fga ;switch {case _gga .Flags ().Has (_ef .FieldFlagCombo ):_egf ,_bba :=_aac (form ,wa ,_gga ,_fba .Style ());if _bba !=nil {return nil ,_bba ;};return _egf ,nil ;default:_a .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",_gga .Flags ().String ()); };default:_a .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",_fga );};return nil ,nil ;};const (SignatureImageLeft SignatureImagePosition =iota ; SignatureImageRight ;SignatureImageTop ;SignatureImageBottom ;);func _aac (_bcag *_ef .PdfAcroForm ,_ffbd *_ef .PdfAnnotationWidget ,_feg *_ef .PdfFieldChoice ,_bgg AppearanceStyle )(*_c .PdfObjectDictionary ,error ){_effe ,_fadd :=_c .GetArray (_ffbd .Rect ); if !_fadd {return nil ,_ac .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_deda ,_gfbb :=_ef .NewPdfRectangle (*_effe );if _gfbb !=nil {return nil ,_gfbb ;};_eaae ,_fgaa :=_deda .Width (),_deda .Height ();_a .Log .Debug ("\u0043\u0068\u006f\u0069\u0063\u0065\u002c\u0020\u0077\u0061\u0020\u0042S\u003a\u0020\u0025\u0076",_ffbd .BS ); _ccfg ,_gfbb :=_d .NewContentStreamParser (_efec (_feg .PdfField )).Parse ();if _gfbb !=nil {return nil ,_gfbb ;};_aace ,_ffg :=_c .GetDict (_ffbd .MK );if _ffg {_adcb ,_ :=_c .GetDict (_ffbd .BS );_cdb :=_bgg .applyAppearanceCharacteristics (_aace ,_adcb ,nil ); if _cdb !=nil {return nil ,_cdb ;};};_ade :=_c .MakeDict ();for _ ,_fef :=range _feg .Opt .Elements (){if _bde ,_dbb :=_c .GetArray (_fef );_dbb &&_bde .Len ()==2{_fef =_bde .Get (1);};var _caag string ;if _aaga ,_adb :=_c .GetString (_fef );_adb {_caag =_aaga .Decoded (); }else if _cef ,_ggca :=_c .GetName (_fef );_ggca {_caag =_cef .String ();}else {_a .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",_fef ); return nil ,_ac .New ("\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u002f\u0073t\u0072\u0069\u006e\u0067");};if len (_caag )> 0{_ffdd ,_bdc :=_aca (_feg .PdfField ,_eaae ,_fgaa ,_caag ,_bgg ,_ccfg ,_bcag .DR ,_aace );if _bdc !=nil {return nil ,_bdc ; };_ade .Set (*_c .MakeName (_caag ),_ffdd .ToPdfObject ());};};_cbg :=_c .MakeDict ();_cbg .Set ("\u004e",_ade );return _cbg ,nil ;}; // NewFormResetButtonField would create a reset button in specified page according to the parameter in `FormResetActionOptions`. func NewFormResetButtonField (page *_ef .PdfPage ,opt FormResetActionOptions )(*_ef .PdfFieldButton ,error ){_fda :=_ef .NewPdfActionResetForm ();_fda .Fields =opt .Fields ;_fda .Flags =_c .MakeInteger (0);if opt .IsExclusionList {_fda .Flags =_c .MakeInteger (1); };_eddb ,_eaf :=_ffae (page ,opt .Rectangle ,"\u0062\u0074\u006e\u0052\u0065\u0073\u0065\u0074",opt .Label ,opt .LabelColor ,opt .Font ,opt .FontSize ,_fda .ToPdfObject ());if _eaf !=nil {return nil ,_eaf ;};return _eddb ,nil ;}; // ImageFieldAppearance implements interface model.FieldAppearanceGenerator and generates appearance streams // for attaching an image to a button field. type ImageFieldAppearance struct{OnlyIfMissing bool ;_dcf *AppearanceStyle ;};func _ebfab (_fdac RectangleAnnotationDef ,_gfd string )([]byte ,*_ef .PdfRectangle ,*_ef .PdfRectangle ,error ){_dbebd :=_bc .Rectangle {X :0,Y :0,Width :_fdac .Width ,Height :_fdac .Height ,FillEnabled :_fdac .FillEnabled ,FillColor :_fdac .FillColor ,BorderEnabled :_fdac .BorderEnabled ,BorderWidth :2*_fdac .BorderWidth ,BorderColor :_fdac .BorderColor ,Opacity :_fdac .Opacity }; _cfdd ,_bffg ,_dfea :=_dbebd .Draw (_gfd );if _dfea !=nil {return nil ,nil ,nil ,_dfea ;};_fce :=&_ef .PdfRectangle {};_fce .Llx =_fdac .X +_bffg .Llx ;_fce .Lly =_fdac .Y +_bffg .Lly ;_fce .Urx =_fdac .X +_bffg .Urx ;_fce .Ury =_fdac .Y +_bffg .Ury ;return _cfdd ,_bffg ,_fce ,nil ; }; // 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 };}; // Style returns the appearance style of `fa`. If not specified, returns default style. func (_gda ImageFieldAppearance )Style ()AppearanceStyle {if _gda ._dcf !=nil {return *_gda ._dcf ;};return AppearanceStyle {BorderSize :0.0,BorderColor :_ef .NewPdfColorDeviceGray (0),FillColor :_ef .NewPdfColorDeviceGray (1),DrawAlignmentReticle :false }; };func _afce (_fbfg _bbb .Image ,_dfg string ,_cdc *SignatureFieldOpts ,_bcc []float64 ,_add *_d .ContentCreator )(*_c .PdfObjectName ,*_ef .XObjectImage ,error ){_efeb ,_gafg :=_ef .DefaultImageHandler {}.NewImageFromGoImage (_fbfg );if _gafg !=nil {return nil ,nil ,_gafg ; };_gac ,_gafg :=_ef .NewXObjectImageFromImage (_efeb ,nil ,_cdc .Encoder );if _gafg !=nil {return nil ,nil ,_gafg ;};_bdgc ,_ggd :=float64 (*_gac .Width ),float64 (*_gac .Height );_afea :=_bcc [2]-_bcc [0];_ged :=_bcc [3]-_bcc [1];if _cdc .AutoSize {_gdd :=_f .Min (_afea /_bdgc ,_ged /_ggd ); _bdgc *=_gdd ;_ggd *=_gdd ;_bcc [0]=_bcc [0]+(_afea /2)-(_bdgc /2);_bcc [1]=_bcc [1]+(_ged /2)-(_ggd /2);};var _ecb *_c .PdfObjectName ;if _daf ,_gegc :=_c .GetName (_gac .Name );_gegc {_ecb =_daf ;}else {_ecb =_c .MakeName (_dfg );};if _add !=nil {_add .Add_q ().Translate (_bcc [0],_bcc [1]).Scale (_bdgc ,_ggd ).Add_Do (*_ecb ).Add_Q (); }else {return nil ,nil ,_ac .New ("\u0043\u006f\u006e\u0074en\u0074\u0043\u0072\u0065\u0061\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u0075l\u006c");};return _ecb ,_gac ,nil ;};func _bae (_bbeg *_d .ContentCreator ,_geg AppearanceStyle ,_gfc ,_gfgde float64 ){_bbeg .Add_q ().Add_re (0,0,_gfc ,_gfgde ).Add_re (0,_gfgde /2,_gfc ,_gfgde /2).Add_re (0,0,_gfc ,_gfgde ).Add_re (_gfc /2,0,_gfc /2,_gfgde ).Add_w (_geg .BorderSize ).SetStrokingColor (_geg .BorderColor ).SetNonStrokingColor (_geg .FillColor ).Add_B ().Add_Q (); };func _gdg (_aefe []float64 )[]float64 {var (_fcdf =len (_aefe );_cdgd =make ([]float64 ,_fcdf );_acdb =make ([]float64 ,_fcdf ););_bfg :=2.0;_cdgd [0]=_aefe [0]/_bfg ;for _acag :=1;_acag < _fcdf ;_acag ++{_acdb [_acag ]=1/_bfg ;if _acag < _fcdf -1{_bfg =4.0; }else {_bfg =3.5;};_bfg -=_acdb [_acag ];_cdgd [_acag ]=(_aefe [_acag ]-_cdgd [_acag -1])/_bfg ;};for _cga :=1;_cga < _fcdf ;_cga ++{_cdgd [_fcdf -_cga -1]-=_acdb [_fcdf -_cga ]*_cdgd [_fcdf -_cga ];};return _cdgd ;};func _deaa (_fddgd []_bc .Point )(_bcff []_bc .Point ,_fffg []_bc .Point ,_aea error ){_egeb :=len (_fddgd )-1; if len (_fddgd )< 1{return nil ,nil ,_ac .New ("\u0041\u0074\u0020\u006c\u0065\u0061\u0073\u0074\u0020\u0074\u0077\u006f\u0020\u0070\u006f\u0069\u006e\u0074s \u0072e\u0071\u0075\u0069\u0072\u0065\u0064\u0020\u0074\u006f\u0020\u0063\u0061l\u0063\u0075\u006c\u0061\u0074\u0065\u0020\u0063\u0075\u0072\u0076\u0065\u0020\u0063\u006f\u006e\u0074r\u006f\u006c\u0020\u0070\u006f\u0069\u006e\u0074\u0073"); };if _egeb ==1{_cfga :=_bc .Point {X :(2*_fddgd [0].X +_fddgd [1].X )/3,Y :(2*_fddgd [0].Y +_fddgd [1].Y )/3};_bcff =append (_bcff ,_cfga );_fffg =append (_fffg ,_bc .Point {X :2*_cfga .X -_fddgd [0].X ,Y :2*_cfga .Y -_fddgd [0].Y });return _bcff ,_fffg ,nil ; };_debg :=make ([]float64 ,_egeb );for _fdea :=1;_fdea < _egeb -1;_fdea ++{_debg [_fdea ]=4*_fddgd [_fdea ].X +2*_fddgd [_fdea +1].X ;};_debg [0]=_fddgd [0].X +2*_fddgd [1].X ;_debg [_egeb -1]=(8*_fddgd [_egeb -1].X +_fddgd [_egeb ].X )/2.0;_cacc :=_gdg (_debg ); for _fbbf :=1;_fbbf < _egeb -1;_fbbf ++{_debg [_fbbf ]=4*_fddgd [_fbbf ].Y +2*_fddgd [_fbbf +1].Y ;};_debg [0]=_fddgd [0].Y +2*_fddgd [1].Y ;_debg [_egeb -1]=(8*_fddgd [_egeb -1].Y +_fddgd [_egeb ].Y )/2.0;_ffad :=_gdg (_debg );_bcff =make ([]_bc .Point ,_egeb ); _fffg =make ([]_bc .Point ,_egeb );for _cbed :=0;_cbed < _egeb ;_cbed ++{_bcff [_cbed ]=_bc .Point {X :_cacc [_cbed ],Y :_ffad [_cbed ]};if _cbed < _egeb -1{_fffg [_cbed ]=_bc .Point {X :2*_fddgd [_cbed +1].X -_cacc [_cbed +1],Y :2*_fddgd [_cbed +1].Y -_ffad [_cbed +1]}; }else {_fffg [_cbed ]=_bc .Point {X :(_fddgd [_egeb ].X +_cacc [_egeb -1])/2,Y :(_fddgd [_egeb ].Y +_ffad [_egeb -1])/2};};};return _bcff ,_fffg ,nil ;}; // CreateInkAnnotation creates an ink annotation object that can be added to the annotation list of a PDF page. func CreateInkAnnotation (inkDef InkAnnotationDef )(*_ef .PdfAnnotation ,error ){_eegc :=_ef .NewPdfAnnotationInk ();_bgfd :=_c .MakeArray ();for _ ,_cebc :=range inkDef .Paths {if _cebc .Length ()==0{continue ;};_abag :=[]float64 {};for _ ,_cdef :=range _cebc .Points {_abag =append (_abag ,_cdef .X ,_cdef .Y ); };_bgfd .Append (_c .MakeArrayFromFloats (_abag ));};_eegc .InkList =_bgfd ;if inkDef .Color ==nil {inkDef .Color =_ef .NewPdfColorDeviceRGB (0.0,0.0,0.0);};_eegc .C =_c .MakeArrayFromFloats ([]float64 {inkDef .Color .R (),inkDef .Color .G (),inkDef .Color .B ()}); _dcba ,_gggbg ,_eaad :=_eagg (&inkDef );if _eaad !=nil {return nil ,_eaad ;};_eegc .AP =_dcba ;_eegc .Rect =_c .MakeArrayFromFloats ([]float64 {_gggbg .Llx ,_gggbg .Lly ,_gggbg .Urx ,_gggbg .Ury });return _eegc .PdfAnnotation ,nil ;}; // 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 *_ef .PdfPage ,name string ,rect []float64 ,opt CheckboxFieldOptions )(*_ef .PdfFieldButton ,error ){if page ==nil {return nil ,_ac .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064"); };if len (name )<=0{return nil ,_ac .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 ,_ac .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065"); };_dfgg ,_acad :=_ef .NewStandard14Font (_ef .ZapfDingbatsName );if _acad !=nil {return nil ,_acad ;};_ggfe :=_ef .NewPdfField ();_adca :=&_ef .PdfFieldButton {};_ggfe .SetContext (_adca );_adca .PdfField =_ggfe ;_adca .T =_c .MakeString (name );_adca .SetType (_ef .ButtonTypeCheckbox ); _cgcf :="\u004f\u0066\u0066";if opt .Checked {_cgcf ="\u0059\u0065\u0073";};_adca .V =_c .MakeName (_cgcf );_eccb :=_ef .NewPdfAnnotationWidget ();_eccb .Rect =_c .MakeArrayFromFloats (rect );_eccb .P =page .ToPdfObject ();_eccb .F =_c .MakeInteger (4); _eccb .Parent =_adca .ToPdfObject ();_fbea :=rect [2]-rect [0];_ebgg :=rect [3]-rect [1];var _bcda _bb .Buffer ;_bcda .WriteString ("\u0071\u000a");_bcda .WriteString ("\u0030 \u0030\u0020\u0031\u0020\u0072\u0067\n");_bcda .WriteString ("\u0042\u0054\u000a"); _bcda .WriteString ("\u002f\u005a\u0061D\u0062\u0020\u0031\u0032\u0020\u0054\u0066\u000a");_bcda .WriteString ("\u0045\u0054\u000a");_bcda .WriteString ("\u0051\u000a");_afad :=_d .NewContentCreator ();_afad .Add_q ();_afad .Add_rg (0,0,1);_afad .Add_BT (); _afad .Add_Tf (*_c .MakeName ("\u005a\u0061\u0044\u0062"),12);_afad .Add_Td (0,0);_afad .Add_ET ();_afad .Add_Q ();_cgf :=_ef .NewXObjectForm ();_cgf .SetContentStream (_afad .Bytes (),_c .NewRawEncoder ());_cgf .BBox =_c .MakeArrayFromFloats ([]float64 {0,0,_fbea ,_ebgg }); _cgf .Resources =_ef .NewPdfPageResources ();_cgf .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_dfgg .ToPdfObject ());_afad =_d .NewContentCreator ();_afad .Add_q ();_afad .Add_re (0,0,_fbea ,_ebgg );_afad .Add_W ().Add_n ();_afad .Add_rg (0,0,1); _afad .Translate (0,3.0);_afad .Add_BT ();_afad .Add_Tf (*_c .MakeName ("\u005a\u0061\u0044\u0062"),12);_afad .Add_Td (0,0);_afad .Add_Tj (*_c .MakeString ("\u0034"));_afad .Add_ET ();_afad .Add_Q ();_dgb :=_ef .NewXObjectForm ();_dgb .SetContentStream (_afad .Bytes (),_c .NewRawEncoder ()); _dgb .BBox =_c .MakeArrayFromFloats ([]float64 {0,0,_fbea ,_ebgg });_dgb .Resources =_ef .NewPdfPageResources ();_dgb .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_dfgg .ToPdfObject ());_cfcf :=_c .MakeDict ();_cfcf .Set ("\u004f\u0066\u0066",_cgf .ToPdfObject ()); _cfcf .Set ("\u0059\u0065\u0073",_dgb .ToPdfObject ());_feca :=_c .MakeDict ();_feca .Set ("\u004e",_cfcf );_eccb .AP =_feca ;_eccb .AS =_c .MakeName (_cgcf );_adca .Annotations =append (_adca .Annotations ,_eccb );return _adca ,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 (_deac FieldAppearance )WrapContentStream (page *_ef .PdfPage )error {_faeg ,_baac :=page .GetAllContentStreams ();if _baac !=nil {return _baac ;};_egfdb :=_d .NewContentStreamParser (_faeg );_cefc ,_baac :=_egfdb .Parse ();if _baac !=nil {return _baac ; };_cefc .WrapIfNeeded ();_abg :=[]string {_cefc .String ()};return page .SetContentStreams (_abg ,_dced ());};type quadding int ; // 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 *_ef .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 _bc .LineEndingStyle ;LineEndingStyle2 _bc .LineEndingStyle ;}; // 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 ;}; // 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 *_ef .PdfPage ,name string ,rect []float64 ,opt TextFieldOptions )(*_ef .PdfFieldText ,error ){if page ==nil {return nil ,_ac .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};if len (name )<=0{return nil ,_ac .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 ,_ac .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");};_eedb :=_ef .NewPdfField ();_eaef :=&_ef .PdfFieldText {};_eedb .SetContext (_eaef );_eaef .PdfField =_eedb ;_eaef .T =_c .MakeString (name ); if opt .MaxLen > 0{_eaef .MaxLen =_c .MakeInteger (int64 (opt .MaxLen ));};if len (opt .Value )> 0{_eaef .V =_c .MakeString (opt .Value );};_gag :=_ef .NewPdfAnnotationWidget ();_gag .Rect =_c .MakeArrayFromFloats (rect );_gag .P =page .ToPdfObject (); _gag .F =_c .MakeInteger (4);_gag .Parent =_eaef .ToPdfObject ();_eaef .Annotations =append (_eaef .Annotations ,_gag );return _eaef ,nil ;}; // NewFormSubmitButtonField would create a submit button in specified page according to the parameter in `FormSubmitActionOptions`. func NewFormSubmitButtonField (page *_ef .PdfPage ,opt FormSubmitActionOptions )(*_ef .PdfFieldButton ,error ){_gdca :=int64 (_fagg );if opt .IsExclusionList {_gdca |=_fgf ;};if opt .IncludeEmptyFields {_gdca |=_eedbg ;};if opt .SubmitAsPDF {_gdca |=_cfbe ; };_ggfa :=_ef .NewPdfActionSubmitForm ();_ggfa .Flags =_c .MakeInteger (_gdca );_ggfa .F =_ef .NewPdfFilespec ();if opt .Fields !=nil {_ggfa .Fields =opt .Fields ;};_ggfa .F .F =_c .MakeString (opt .Url );_ggfa .F .FS =_c .MakeName ("\u0055\u0052\u004c"); _bfag ,_gdee :=_ffae (page ,opt .Rectangle ,"\u0062t\u006e\u0053\u0075\u0062\u006d\u0069t",opt .Label ,opt .LabelColor ,opt .Font ,opt .FontSize ,_ggfa .ToPdfObject ());if _gdee !=nil {return nil ,_gdee ;};return _bfag ,nil ;};func _efec (_fde *_ef .PdfField )string {if _fde ==nil {return ""; };_cdbe ,_cccb :=_fde .GetContext ().(*_ef .PdfFieldText );if !_cccb {return _efec (_fde .Parent );};if _cdbe .DA !=nil {return _cdbe .DA .Str ();};return _efec (_cdbe .Parent );};func _afcf (_aaf LineAnnotationDef ,_gdga string )([]byte ,*_ef .PdfRectangle ,*_ef .PdfRectangle ,error ){_egad :=_bc .Line {X1 :0,Y1 :0,X2 :_aaf .X2 -_aaf .X1 ,Y2 :_aaf .Y2 -_aaf .Y1 ,LineColor :_aaf .LineColor ,Opacity :_aaf .Opacity ,LineWidth :_aaf .LineWidth ,LineEndingStyle1 :_aaf .LineEndingStyle1 ,LineEndingStyle2 :_aaf .LineEndingStyle2 }; _ebfa ,_ecccd ,_fcae :=_egad .Draw (_gdga );if _fcae !=nil {return nil ,nil ,nil ,_fcae ;};_eega :=&_ef .PdfRectangle {};_eega .Llx =_aaf .X1 +_ecccd .Llx ;_eega .Lly =_aaf .Y1 +_ecccd .Lly ;_eega .Urx =_aaf .X1 +_ecccd .Urx ;_eega .Ury =_aaf .Y1 +_ecccd .Ury ; return _ebfa ,_ecccd ,_eega ,nil ;};func _fcce (_cgad RectangleAnnotationDef )(*_c .PdfObjectDictionary ,*_ef .PdfRectangle ,error ){_gea :=_ef .NewXObjectForm ();_gea .Resources =_ef .NewPdfPageResources ();_ebbe :="";if _cgad .Opacity < 1.0{_ccdg :=_c .MakeDict (); _ccdg .Set ("\u0063\u0061",_c .MakeFloat (_cgad .Opacity ));_ccdg .Set ("\u0043\u0041",_c .MakeFloat (_cgad .Opacity ));_gfce :=_gea .Resources .AddExtGState ("\u0067\u0073\u0031",_ccdg );if _gfce !=nil {_a .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 ,_gfce ;};_ebbe ="\u0067\u0073\u0031";};_bee ,_fbeg ,_ebdd ,_fagge :=_ebfab (_cgad ,_ebbe );if _fagge !=nil {return nil ,nil ,_fagge ;};_fagge =_gea .SetContentStream (_bee ,nil );if _fagge !=nil {return nil ,nil ,_fagge ;};_gea .BBox =_fbeg .ToPdfObject (); _ebcb :=_c .MakeDict ();_ebcb .Set ("\u004e",_gea .ToPdfObject ());return _ebcb ,_ebdd ,nil ;};func (_adg *AppearanceStyle )applyRotation (_cgg *_c .PdfObjectDictionary ,_cdaa ,_aeg float64 ,_bdce *_d .ContentCreator )(float64 ,float64 ){if !_adg .AllowMK {return _cdaa ,_aeg ; };if _cgg ==nil {return _cdaa ,_aeg ;};_dfdc ,_ :=_c .GetNumberAsFloat (_cgg .Get ("\u0052"));if _dfdc ==0{return _cdaa ,_aeg ;};_gba :=-_dfdc ;_caae :=_bc .Path {Points :[]_bc .Point {_bc .NewPoint (0,0).Rotate (_gba ),_bc .NewPoint (_cdaa ,0).Rotate (_gba ),_bc .NewPoint (0,_aeg ).Rotate (_gba ),_bc .NewPoint (_cdaa ,_aeg ).Rotate (_gba )}}.GetBoundingBox (); _bdce .RotateDeg (_dfdc );_bdce .Translate (_caae .X ,_caae .Y );return _caae .Width ,_caae .Height ;}; // 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 ;_degg *AppearanceStyle ;}; // Style returns the appearance style of `fa`. If not specified, returns default style. func (_ccg FieldAppearance )Style ()AppearanceStyle {if _ccg ._degg !=nil {return *_ccg ._degg ;};_eg :=_bfa ;return AppearanceStyle {AutoFontSizeFraction :0.65,CheckmarkRune :'✔',BorderSize :0.0,BorderColor :_ef .NewPdfColorDeviceGray (0),FillColor :_ef .NewPdfColorDeviceGray (1),MultilineLineHeight :1.2,MultilineVAlignMiddle :false ,DrawAlignmentReticle :false ,AllowMK :true ,MarginLeft :&_eg }; }; // 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 (_cfcfa ImageFieldAppearance )WrapContentStream (page *_ef .PdfPage )error {_bacg ,_agda :=page .GetAllContentStreams ();if _agda !=nil {return _agda ;};_ebgc :=_d .NewContentStreamParser (_bacg );_bbdb ,_agda :=_ebgc .Parse ();if _agda !=nil {return _agda ; };_bbdb .WrapIfNeeded ();_fff :=[]string {_bbdb .String ()};return page .SetContentStreams (_fff ,_dced ());};