// // 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 (_e "bytes";_ac "errors";_a "github.com/unidoc/unipdf/v3/common";_bd "github.com/unidoc/unipdf/v3/contentstream";_cc "github.com/unidoc/unipdf/v3/contentstream/draw";_cb "github.com/unidoc/unipdf/v3/core";_be "github.com/unidoc/unipdf/v3/internal/textencoding"; _ae "github.com/unidoc/unipdf/v3/model";_g "image";_ec "math";_c "strings";_d "unicode";);func _egb (_cddb *_ae .PdfField )string {if _cddb ==nil {return "";};_fbe ,_bec :=_cddb .GetContext ().(*_ae .PdfFieldText );if !_bec {return _egb (_cddb .Parent ); };if _fbe .DA !=nil {return _fbe .DA .Str ();};return _egb (_fbe .Parent );}; // CreateCircleAnnotation creates a circle/ellipse annotation object with appearance stream that can be added to // page PDF annotations. func CreateCircleAnnotation (circDef CircleAnnotationDef )(*_ae .PdfAnnotation ,error ){_dc :=_ae .NewPdfAnnotationCircle ();if circDef .BorderEnabled {_aeb ,_aef ,_f :=circDef .BorderColor .R (),circDef .BorderColor .G (),circDef .BorderColor .B ();_dc .C =_cb .MakeArrayFromFloats ([]float64 {_aeb ,_aef ,_f }); _cf :=_ae .NewBorderStyle ();_cf .SetBorderWidth (circDef .BorderWidth );_dc .BS =_cf .ToPdfObject ();};if circDef .FillEnabled {_ca ,_ed ,_cd :=circDef .FillColor .R (),circDef .FillColor .G (),circDef .FillColor .B ();_dc .IC =_cb .MakeArrayFromFloats ([]float64 {_ca ,_ed ,_cd }); }else {_dc .IC =_cb .MakeArrayFromIntegers ([]int {});};if circDef .Opacity < 1.0{_dc .CA =_cb .MakeFloat (circDef .Opacity );};_gg ,_ggc ,_bc :=_cdc (circDef );if _bc !=nil {return nil ,_bc ;};_dc .AP =_gg ;_dc .Rect =_cb .MakeArrayFromFloats ([]float64 {_ggc .Llx ,_ggc .Lly ,_ggc .Urx ,_ggc .Ury }); return _dc .PdfAnnotation ,nil ;};func (_fgfd *AppearanceStyle )processDA (_gfag *_ae .PdfField ,_dfac *_bd .ContentStreamOperations ,_adfb ,_aff *_ae .PdfPageResources ,_bfegb *_bd .ContentCreator )(*AppearanceFont ,bool ,error ){var _cde *AppearanceFont ; var _aab bool ;if _fgfd .Fonts !=nil {if _fgfd .Fonts .Fallback !=nil {_cde =_fgfd .Fonts .Fallback ;};if _deeg :=_fgfd .Fonts .FieldFallbacks ;_deeg !=nil {if _bbe ,_bbcg :=_deeg [_gfag .PartialName ()];_bbcg {_cde =_bbe ;}else if _gbaa ,_gdce :=_gfag .FullName (); _gdce ==nil {if _bfda ,_aecf :=_deeg [_gbaa ];_aecf {_cde =_bfda ;};};};_aab =_fgfd .Fonts .ForceReplace ;};var _fgd string ;var _fcce float64 ;var _ddga bool ;if _dfac !=nil {for _ ,_bbca :=range *_dfac {if _bbca .Operand =="\u0054\u0066"&&len (_bbca .Params )==2{if _bgbde ,_egbg :=_cb .GetNameVal (_bbca .Params [0]); _egbg {_fgd =_bgbde ;};if _agc ,_bdd :=_cb .GetNumberAsFloat (_bbca .Params [1]);_bdd ==nil {_fcce =_agc ;};_ddga =true ;continue ;};_bfegb .AddOperand (*_bbca );};};var _ecec *AppearanceFont ;var _afe _cb .PdfObject ;if _aab &&_cde !=nil {_ecec =_cde ; }else {if _adfb !=nil &&_fgd !=""{if _eaeb ,_cdfd :=_adfb .GetFontByName (*_cb .MakeName (_fgd ));_cdfd {if _gbaf ,_ffg :=_ae .NewPdfFontFromPdfObject (_eaeb );_ffg ==nil {_afe =_eaeb ;_ecec =&AppearanceFont {Name :_fgd ,Font :_gbaf ,Size :_fcce };}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",_ffg ); };};};if _ecec ==nil &&_cde !=nil {_ecec =_cde ;};if _ecec ==nil {_fffe ,_def :=_ae .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");if _def !=nil {return nil ,false ,_def ;};_ecec =&AppearanceFont {Name :"\u0048\u0065\u006c\u0076",Font :_fffe ,Size :_fcce }; };};if _ecec .Size <=0&&_fgfd .Fonts !=nil &&_fgfd .Fonts .FallbackSize > 0{_ecec .Size =_fgfd .Fonts .FallbackSize ;};_eaad :=*_cb .MakeName (_ecec .Name );if _afe ==nil {_afe =_ecec .Font .ToPdfObject ();};if _adfb !=nil &&!_adfb .HasFontByName (_eaad ){_adfb .SetFontByName (_eaad ,_afe ); };if _aff !=nil &&!_aff .HasFontByName (_eaad ){_aff .SetFontByName (_eaad ,_afe );};return _ecec ,_ddga ,nil ;};const (SignatureImageLeft SignatureImagePosition =iota ;SignatureImageRight ;SignatureImageTop ;SignatureImageBottom ;);func _aadc (_ecc LineAnnotationDef )(*_cb .PdfObjectDictionary ,*_ae .PdfRectangle ,error ){_aeagf :=_ae .NewXObjectForm (); _aeagf .Resources =_ae .NewPdfPageResources ();_debb :="";if _ecc .Opacity < 1.0{_ageb :=_cb .MakeDict ();_ageb .Set ("\u0063\u0061",_cb .MakeFloat (_ecc .Opacity ));_dfaaa :=_aeagf .Resources .AddExtGState ("\u0067\u0073\u0031",_ageb );if _dfaaa !=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 ,_dfaaa ;};_debb ="\u0067\u0073\u0031";};_gbc ,_debaa ,_acf ,_dgd :=_dga (_ecc ,_debb );if _dgd !=nil {return nil ,nil ,_dgd ;};_dgd =_aeagf .SetContentStream (_gbc ,nil );if _dgd !=nil {return nil ,nil ,_dgd ;};_aeagf .BBox =_debaa .ToPdfObject (); _afff :=_cb .MakeDict ();_afff .Set ("\u004e",_aeagf .ToPdfObject ());return _afff ,_acf ,nil ;}; // CheckboxFieldOptions defines optional parameters for a checkbox field a form. type CheckboxFieldOptions struct{Checked bool ;};func _acdc (_dbd RectangleAnnotationDef ,_bcd string )([]byte ,*_ae .PdfRectangle ,*_ae .PdfRectangle ,error ){_edb :=_cc .Rectangle {X :0,Y :0,Width :_dbd .Width ,Height :_dbd .Height ,FillEnabled :_dbd .FillEnabled ,FillColor :_dbd .FillColor ,BorderEnabled :_dbd .BorderEnabled ,BorderWidth :2*_dbd .BorderWidth ,BorderColor :_dbd .BorderColor ,Opacity :_dbd .Opacity }; _gadc ,_eedb ,_beb :=_edb .Draw (_bcd );if _beb !=nil {return nil ,nil ,nil ,_beb ;};_dcgg :=&_ae .PdfRectangle {};_dcgg .Llx =_dbd .X +_eedb .Llx ;_dcgg .Lly =_dbd .Y +_eedb .Lly ;_dcgg .Urx =_dbd .X +_eedb .Urx ;_dcgg .Ury =_dbd .Y +_eedb .Ury ;return _gadc ,_eedb ,_dcgg ,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 ;}; // Style returns the appearance style of `fa`. If not specified, returns default style. func (_cef ImageFieldAppearance )Style ()AppearanceStyle {if _cef ._ggca !=nil {return *_cef ._ggca ;};return AppearanceStyle {BorderSize :0.0,BorderColor :_ae .NewPdfColorDeviceGray (0),FillColor :_ae .NewPdfColorDeviceGray (1),DrawAlignmentReticle :false }; }; // 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 *_ae .PdfPage ,name string ,rect []float64 ,opt TextFieldOptions )(*_ae .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");};_dcfe :=_ae .NewPdfField ();_afg :=&_ae .PdfFieldText {};_dcfe .SetContext (_afg );_afg .PdfField =_dcfe ;_afg .T =_cb .MakeString (name ); if opt .MaxLen > 0{_afg .MaxLen =_cb .MakeInteger (int64 (opt .MaxLen ));};if len (opt .Value )> 0{_afg .V =_cb .MakeString (opt .Value );};_ffaf :=_ae .NewPdfAnnotationWidget ();_ffaf .Rect =_cb .MakeArrayFromFloats (rect );_ffaf .P =page .ToPdfObject (); _ffaf .F =_cb .MakeInteger (4);_ffaf .Parent =_afg .ToPdfObject ();_afg .Annotations =append (_afg .Annotations ,_ffaf );return _afg ,nil ;}; // CreateLineAnnotation creates a line annotation object that can be added to page PDF annotations. func CreateLineAnnotation (lineDef LineAnnotationDef )(*_ae .PdfAnnotation ,error ){_cgag :=_ae .NewPdfAnnotationLine ();_cgag .L =_cb .MakeArrayFromFloats ([]float64 {lineDef .X1 ,lineDef .Y1 ,lineDef .X2 ,lineDef .Y2 });_gfbg :=_cb .MakeName ("\u004e\u006f\u006e\u0065"); if lineDef .LineEndingStyle1 ==_cc .LineEndingStyleArrow {_gfbg =_cb .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");};_ccbfd :=_cb .MakeName ("\u004e\u006f\u006e\u0065");if lineDef .LineEndingStyle2 ==_cc .LineEndingStyleArrow {_ccbfd =_cb .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077"); };_cgag .LE =_cb .MakeArray (_gfbg ,_ccbfd );if lineDef .Opacity < 1.0{_cgag .CA =_cb .MakeFloat (lineDef .Opacity );};_bcca ,_ffcf ,_dbeb :=lineDef .LineColor .R (),lineDef .LineColor .G (),lineDef .LineColor .B ();_cgag .IC =_cb .MakeArrayFromFloats ([]float64 {_bcca ,_ffcf ,_dbeb }); _cgag .C =_cb .MakeArrayFromFloats ([]float64 {_bcca ,_ffcf ,_dbeb });_acd :=_ae .NewBorderStyle ();_acd .SetBorderWidth (lineDef .LineWidth );_cgag .BS =_acd .ToPdfObject ();_ebca ,_ggef ,_cdaa :=_aadc (lineDef );if _cdaa !=nil {return nil ,_cdaa ;};_cgag .AP =_ebca ; _cgag .Rect =_cb .MakeArrayFromFloats ([]float64 {_ggef .Llx ,_ggef .Lly ,_ggef .Urx ,_ggef .Ury });return _cgag .PdfAnnotation ,nil ;}; // SetStyle applies appearance `style` to `fa`. func (_ecb *ImageFieldAppearance )SetStyle (style AppearanceStyle ){_ecb ._ggca =&style };func (_bfd *AppearanceStyle )applyAppearanceCharacteristics (_dae *_cb .PdfObjectDictionary ,_aae *_cb .PdfObjectDictionary ,_ecaf *_ae .PdfFont )error {if !_bfd .AllowMK {return nil ; };if CA ,_aceg :=_cb .GetString (_dae .Get ("\u0043\u0041"));_aceg &&_ecaf !=nil {_cbe :=CA .Bytes ();if len (_cbe )!=0{_ggcc :=[]rune (_ecaf .Encoder ().Decode (_cbe ));if len (_ggcc )==1{_bfd .CheckmarkRune =_ggcc [0];};};};if BC ,_bagc :=_cb .GetArray (_dae .Get ("\u0042\u0043")); _bagc {_eegf ,_eag :=BC .ToFloat64Array ();if _eag !=nil {return _eag ;};switch len (_eegf ){case 1:_bfd .BorderColor =_ae .NewPdfColorDeviceGray (_eegf [0]);case 3:_bfd .BorderColor =_ae .NewPdfColorDeviceRGB (_eegf [0],_eegf [1],_eegf [2]);case 4:_bfd .BorderColor =_ae .NewPdfColorDeviceCMYK (_eegf [0],_eegf [1],_eegf [2],_eegf [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 (_eegf )); };if _aae !=nil {if _bbad ,_cbafa :=_cb .GetNumberAsFloat (_aae .Get ("\u0057"));_cbafa ==nil {_bfd .BorderSize =_bbad ;};};};if BG ,_ceag :=_cb .GetArray (_dae .Get ("\u0042\u0047"));_ceag {_dfce ,_fac :=BG .ToFloat64Array ();if _fac !=nil {return _fac ; };switch len (_dfce ){case 1:_bfd .FillColor =_ae .NewPdfColorDeviceGray (_dfce [0]);case 3:_bfd .FillColor =_ae .NewPdfColorDeviceRGB (_dfce [0],_dfce [1],_dfce [2]);case 4:_bfd .FillColor =_ae .NewPdfColorDeviceCMYK (_dfce [0],_dfce [1],_dfce [2],_dfce [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 (_dfce )); };};return 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 ;_ede *AppearanceStyle ;};func _fcd (_agfa *_ae .PdfAnnotationWidget ,_fad *_ae .PdfFieldText ,_ddg *_ae .PdfPageResources ,_aec AppearanceStyle )(*_cb .PdfObjectDictionary ,error ){_dcb :=_ae .NewPdfPageResources (); _edab ,_eaca :=_cb .GetArray (_agfa .Rect );if !_eaca {return nil ,_ac .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_fda ,_aea :=_ae .NewPdfRectangle (*_edab );if _aea !=nil {return nil ,_aea ;};_fef ,_ccb :=_fda .Width (),_fda .Height (); _adf ,_cfaf :=_fef ,_ccb ;_fdde ,_bfb :=_cb .GetDict (_agfa .MK );if _bfb {_efg ,_ :=_cb .GetDict (_agfa .BS );_beggf :=_aec .applyAppearanceCharacteristics (_fdde ,_efg ,nil );if _beggf !=nil {return nil ,_beggf ;};};_eaa ,_bfb :=_cb .GetIntVal (_fad .MaxLen ); if !_bfb {return nil ,_ac .New ("\u006d\u0061\u0078\u006c\u0065\u006e\u0020\u006e\u006ft\u0020\u0073\u0065\u0074");};if _eaa <=0{return nil ,_ac .New ("\u006d\u0061\u0078\u004c\u0065\u006e\u0020\u0069\u006ev\u0061\u006c\u0069\u0064");};_ffae :=_fef /float64 (_eaa ); _cbaf ,_aea :=_bd .NewContentStreamParser (_egb (_fad .PdfField )).Parse ();if _aea !=nil {return nil ,_aea ;};_ce :=_bd .NewContentCreator ();if _aec .BorderSize > 0{_dfc (_ce ,_aec ,_fef ,_ccb );};if _aec .DrawAlignmentReticle {_efde :=_aec ;_efde .BorderSize =0.2; _gag (_ce ,_efde ,_fef ,_ccb );};_ce .Add_BMC ("\u0054\u0078");_ce .Add_q ();_ ,_ccb =_aec .applyRotation (_fdde ,_fef ,_ccb ,_ce );_ce .Add_BT ();_bbg ,_dff ,_aea :=_aec .processDA (_fad .PdfField ,_cbaf ,_ddg ,_dcb ,_ce );if _aea !=nil {return nil ,_aea ; };_fadg :=_bbg .Font ;_gcf :=_cb .MakeName (_bbg .Name );_ace :=_bbg .Size ;_bgad :=_ace ==0;if _bgad &&_dff {_ace =_ccb *_aec .AutoFontSizeFraction ;};_gdg :=_fadg .Encoder ();if _gdg ==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"); _gdg =_be .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};var _fdg string ;if _cce ,_bbcf :=_cb .GetString (_fad .V );_bbcf {_fdg =_cce .Decoded ();};_ce .Add_Tf (*_gcf ,_ace );var _dfe float64 ;for _ ,_cfgc :=range _fdg {_dffd ,_gbag :=_fadg .GetRuneMetrics (_cfgc ); if !_gbag {_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",_cfgc ); continue ;};_bgbd :=_dffd .Wy ;if int (_bgbd )<=0{_bgbd =_dffd .Wx ;};if _bgbd > _dfe {_dfe =_bgbd ;};};if int (_dfe )==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"); _dfe =1000;};_ddc ,_aea :=_fadg .GetFontDescriptor ();if _aea !=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 _bcge float64 ;if _ddc !=nil {_bcge ,_aea =_ddc .GetCapHeight ();if _aea !=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",_aea ); };};if int (_bcge )<=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"); _bcge =1000.0;};_eaf :=_bcge /1000.0*_ace ;_ffbc :=0.0;_aced :=1.0*_ace *(_dfe /1000.0);{_gec :=_aced ;if _bgad &&_ffbc +_gec > _ccb {_ace =0.95*(_ccb -_ffbc );_eaf =_bcge /1000.0*_ace ;};if _ccb > _eaf {_ffbc =(_ccb -_eaf )/2.0;};};_ce .Add_Td (0,_ffbc ); if _bda ,_fcc :=_cb .GetIntVal (_fad .Q );_fcc {switch _bda {case 2:if len (_fdg )< _eaa {_ced :=float64 (_eaa -len (_fdg ))*_ffae ;_ce .Add_Td (_ced ,0);};};};for _acc ,_fff :=range _fdg {_cea :=_df ;if _aec .MarginLeft !=nil {_cea =*_aec .MarginLeft ; };_cdg :=string (_fff );if _gdg !=nil {_bafe ,_gf :=_fadg .GetRuneMetrics (_fff );if !_gf {_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",_fff ); continue ;};_cdg =string (_gdg .Encode (_cdg ));_agff :=_ace *_bafe .Wx /1000.0;_bafa :=(_ffae -_agff )/2;_cea =_bafa ;};_ce .Add_Td (_cea ,0);_ce .Add_Tj (*_cb .MakeString (_cdg ));if _acc !=len (_fdg )-1{_ce .Add_Td (_ffae -_cea ,0);};};_ce .Add_ET (); _ce .Add_Q ();_ce .Add_EMC ();_bfa :=_ae .NewXObjectForm ();_bfa .Resources =_dcb ;_bfa .BBox =_cb .MakeArrayFromFloats ([]float64 {0,0,_adf ,_cfaf });_bfa .SetContentStream (_ce .Bytes (),_adgd ());_ceg :=_cb .MakeDict ();_ceg .Set ("\u004e",_bfa .ToPdfObject ()); return _ceg ,nil ;}; // 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 ;};func _cfge (_eacb _g .Image ,_dgbc string ,_cdb *SignatureFieldOpts ,_ecf []float64 ,_bdcb *_bd .ContentCreator )(*_cb .PdfObjectName ,*_ae .XObjectImage ,error ){_cee ,_ggaa :=_ae .DefaultImageHandler {}.NewImageFromGoImage (_eacb ); if _ggaa !=nil {return nil ,nil ,_ggaa ;};_bae ,_ggaa :=_ae .NewXObjectImageFromImage (_cee ,nil ,_cdb .Encoder );if _ggaa !=nil {return nil ,nil ,_ggaa ;};_ffad ,_dbf :=float64 (*_bae .Width ),float64 (*_bae .Height );_fdac :=_ecf [2]-_ecf [0];_gbfb :=_ecf [3]-_ecf [1]; if _cdb .AutoSize {_eggc :=_ec .Min (_fdac /_ffad ,_gbfb /_dbf );_ffad *=_eggc ;_dbf *=_eggc ;_ecf [0]=_ecf [0]+(_fdac /2)-(_ffad /2);_ecf [1]=_ecf [1]+(_gbfb /2)-(_dbf /2);};var _efdd *_cb .PdfObjectName ;if _age ,_agcg :=_cb .GetName (_bae .Name );_agcg {_efdd =_age ; }else {_efdd =_cb .MakeName (_dgbc );};if _bdcb !=nil {_bdcb .Add_q ().Translate (_ecf [0],_ecf [1]).Scale (_ffad ,_dbf ).Add_Do (*_efdd ).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 _efdd ,_bae ,nil ;};func _ebd (_dec []*SignatureLine ,_agca *SignatureFieldOpts )(*_cb .PdfObjectDictionary ,error ){if _agca ==nil {_agca =NewSignatureFieldOpts ();};var _gaf error ;var _abe *_cb .PdfObjectName ;_fbef :=_agca .Font ;if _fbef !=nil {_bdc ,_ :=_fbef .GetFontDescriptor (); if _bdc !=nil {if _deac ,_ebcg :=_bdc .FontName .(*_cb .PdfObjectName );_ebcg {_abe =_deac ;};};if _abe ==nil {_abe =_cb .MakeName ("\u0046\u006f\u006et\u0031");};}else {if _fbef ,_gaf =_ae .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a"); _gaf !=nil {return nil ,_gaf ;};_abe =_cb .MakeName ("\u0048\u0065\u006c\u0076");};_bce :=_agca .FontSize ;if _bce <=0{_bce =10;};if _agca .LineHeight <=0{_agca .LineHeight =1;};_fae :=_agca .LineHeight *_bce ;_aeg ,_gcc :=_fbef .GetRuneMetrics (' ');if !_gcc {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"); };_edag :=_aeg .Wx ;var _afc float64 ;var _bad []string ;for _ ,_gbafg :=range _dec {if _gbafg .Text ==""{continue ;};_fcbg :=_gbafg .Text ;if _gbafg .Desc !=""{_fcbg =_gbafg .Desc +"\u003a\u0020"+_fcbg ;};_bad =append (_bad ,_fcbg );var _gbafd float64 ; for _ ,_bffa :=range _fcbg {_dfff ,_fbda :=_fbef .GetRuneMetrics (_bffa );if !_fbda {continue ;};_gbafd +=_dfff .Wx ;};if _gbafd > _afc {_afc =_gbafd ;};};_afc =_afc *_bce /1000.0;_acedb :=float64 (len (_bad ))*_fae ;_cbc :=_agca .Image !=nil ;_eaec :=_agca .Rect ; if _eaec ==nil {_eaec =[]float64 {0,0,_afc ,_acedb };if _cbc {_eaec [2]=_afc *2;_eaec [3]=_acedb *2;};_agca .Rect =_eaec ;};_edc :=_eaec [2]-_eaec [0];_dgc :=_eaec [3]-_eaec [1];_gbe ,_ccee :=_eaec ,_eaec ;var _dfaf ,_daef float64 ;if _cbc &&len (_bad )> 0{if _agca .ImagePosition <=SignatureImageRight {_baaf :=[]float64 {_eaec [0],_eaec [1],_eaec [0]+(_edc /2),_eaec [3]}; _dcbd :=[]float64 {_eaec [0]+(_edc /2),_eaec [1],_eaec [2],_eaec [3]};if _agca .ImagePosition ==SignatureImageLeft {_gbe ,_ccee =_baaf ,_dcbd ;}else {_gbe ,_ccee =_dcbd ,_baaf ;};}else {_eegc :=[]float64 {_eaec [0],_eaec [1],_eaec [2],_eaec [1]+(_dgc /2)}; _fefb :=[]float64 {_eaec [0],_eaec [1]+(_dgc /2),_eaec [2],_eaec [3]};if _agca .ImagePosition ==SignatureImageTop {_gbe ,_ccee =_fefb ,_eegc ;}else {_gbe ,_ccee =_eegc ,_fefb ;};};};_dfaf =_ccee [2]-_ccee [0];_daef =_ccee [3]-_ccee [1];var _dce float64 ; if _agca .AutoSize {if _afc > _dfaf ||_acedb > _daef {_gbfg :=_ec .Min (_dfaf /_afc ,_daef /_acedb );_bce *=_gbfg ;};_fae =_agca .LineHeight *_bce ;_dce +=(_daef -float64 (len (_bad ))*_fae )/2;};_fbb :=_bd .NewContentCreator ();_fdgg :=_ae .NewPdfPageResources (); _fdgg .SetFontByName (*_abe ,_fbef .ToPdfObject ());if _agca .BorderSize <=0{_agca .BorderSize =0;_agca .BorderColor =_ae .NewPdfColorDeviceGray (1);};if _agca .BorderColor ==nil {_agca .BorderColor =_ae .NewPdfColorDeviceGray (1);};if _agca .FillColor ==nil {_agca .FillColor =_ae .NewPdfColorDeviceGray (1); };_fbb .Add_q ().SetNonStrokingColor (_agca .FillColor ).SetStrokingColor (_agca .BorderColor ).Add_w (_agca .BorderSize ).Add_re (_eaec [0],_eaec [1],_edc ,_dgc ).Add_B ().Add_Q ();if _agca .WatermarkImage !=nil {_aegb :=[]float64 {_eaec [0],_eaec [1],_eaec [2],_eaec [3]}; _adeae ,_gad ,_gaa :=_cfge (_agca .WatermarkImage ,"\u0049\u006d\u0061\u0067\u0065\u0057\u0061\u0074\u0065r\u006d\u0061\u0072\u006b",_agca ,_aegb ,_fbb );if _gaa !=nil {return nil ,_gaa ;};_fdgg .SetXObjectImageByName (*_adeae ,_gad );};_fbb .Add_q (); _fbb .Translate (_ccee [0],_ccee [3]-_fae -_dce );_fbb .Add_BT ();_dgcb :=_fbef .Encoder ();for _ ,_gaae :=range _bad {var _gcefe []byte ;for _ ,_deba :=range _gaae {if _d .IsSpace (_deba ){if len (_gcefe )> 0{_fbb .SetNonStrokingColor (_agca .TextColor ).Add_Tf (*_abe ,_bce ).Add_TL (_fae ).Add_TJ ([]_cb .PdfObject {_cb .MakeStringFromBytes (_gcefe )}...); _gcefe =nil ;};_fbb .Add_Tf (*_abe ,_bce ).Add_TL (_fae ).Add_TJ ([]_cb .PdfObject {_cb .MakeFloat (-_edag )}...);}else {_gcefe =append (_gcefe ,_dgcb .Encode (string (_deba ))...);};};if len (_gcefe )> 0{_fbb .SetNonStrokingColor (_agca .TextColor ).Add_Tf (*_abe ,_bce ).Add_TL (_fae ).Add_TJ ([]_cb .PdfObject {_cb .MakeStringFromBytes (_gcefe )}...); };_fbb .Add_Td (0,-_fae );};_fbb .Add_ET ();_fbb .Add_Q ();if _cbc {_affa ,_edad ,_aed :=_cfge (_agca .Image ,"\u0049\u006d\u0061\u0067\u0065\u0053\u0069\u0067\u006ea\u0074\u0075\u0072\u0065",_agca ,_gbe ,_fbb );if _aed !=nil {return nil ,_aed ;};_fdgg .SetXObjectImageByName (*_affa ,_edad ); };_befb :=_ae .NewXObjectForm ();_befb .Resources =_fdgg ;_befb .BBox =_cb .MakeArrayFromFloats (_eaec );_befb .SetContentStream (_fbb .Bytes (),_adgd ());_ggac :=_cb .MakeDict ();_ggac .Set ("\u004e",_befb .ToPdfObject ());return _ggac ,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 _ae .PdfColor ;FillColor _ae .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 ;}; // 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 *_ae .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_ae .PdfColorDeviceRGB ;Opacity float64 ;}; // 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 _bfdd (_abef ,_agac float64 ,_gfaee *_ae .Image ,_bca AppearanceStyle )(*_ae .XObjectForm ,error ){_fagd ,_dbaf :=_ae .NewXObjectImageFromImage (_gfaee ,nil ,_cb .NewFlateEncoder ()); if _dbaf !=nil {return nil ,_dbaf ;};_fagd .Decode =_cb .MakeArrayFromFloats ([]float64 {0.0,1.0,0.0,1.0,0.0,1.0});_edga :=_ae .NewPdfPageResources ();_edga .ProcSet =_cb .MakeArray (_cb .MakeName ("\u0050\u0044\u0046"),_cb .MakeName ("\u0049\u006d\u0061\u0067\u0065\u0043")); _edga .SetXObjectImageByName (_cb .PdfObjectName ("\u0049\u006d\u0030"),_fagd );_dfaad :=_bd .NewContentCreator ();_dfaad .Add_q ();_dfaad .Add_cm (float64 (_gfaee .Width ),0,0,float64 (_gfaee .Height ),0,0);_dfaad .Add_Do ("\u0049\u006d\u0030");_dfaad .Add_Q (); _agdg :=_ae .NewXObjectForm ();_agdg .FormType =_cb .MakeInteger (1);_agdg .BBox =_cb .MakeArrayFromFloats ([]float64 {0,0,float64 (_gfaee .Width ),float64 (_gfaee .Height )});_agdg .Resources =_edga ;_agdg .SetContentStream (_dfaad .Bytes (),_adgd ()); return _agdg ,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 *_ae .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 _ae .PdfColor ; // FillColor represents the background color of the appearance annotation area. FillColor _ae .PdfColor ; // BorderSize represents border size of the appearance annotation area. BorderSize float64 ; // BorderColor represents the border color of the appearance annotation area. BorderColor _ae .PdfColor ; // WatermarkImage specifies the image used as a watermark that will be rendered // behind the signature. WatermarkImage _g .Image ; // Image represents the image used for the signature appearance. Image _g .Image ; // Encoder specifies the image encoder used for image signature. Defaults to flate encoder. Encoder _cb .StreamEncoder ; // ImagePosition specifies the image location relative to the text signature. ImagePosition SignatureImagePosition ;}; // GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`. // Implements interface model.FieldAppearanceGenerator. func (_fgg ImageFieldAppearance )GenerateAppearanceDict (form *_ae .PdfAcroForm ,field *_ae .PdfField ,wa *_ae .PdfAnnotationWidget )(*_cb .PdfObjectDictionary ,error ){_ ,_bagd :=field .GetContext ().(*_ae .PdfFieldButton );if !_bagd {_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 ;};_ded ,_cccd :=_cb .GetDict (wa .AP );if _cccd &&_fgg .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 _ded ,nil ;};if form .DR ==nil {form .DR =_ae .NewPdfPageResources ();};switch _eab :=field .GetContext ().(type ){case *_ae .PdfFieldButton :if _eab .IsPush (){_ggd ,_aeag :=_fgga (_eab ,wa ,_fgg .Style ());if _aeag !=nil {return nil ,_aeag ;}; return _ggd ,nil ;};};return nil ,nil ;};func _gfc (_dea *_ae .PdfField ,_beag ,_fddad float64 ,_gcef string ,_aad AppearanceStyle ,_caf *_bd .ContentStreamOperations ,_aagd *_ae .PdfPageResources ,_eeg *_cb .PdfObjectDictionary )(*_ae .XObjectForm ,error ){_gcba :=_ae .NewPdfPageResources (); _bfbd ,_adef :=_beag ,_fddad ;_efe :=_bd .NewContentCreator ();if _aad .BorderSize > 0{_dfc (_efe ,_aad ,_beag ,_fddad );};if _aad .DrawAlignmentReticle {_fabe :=_aad ;_fabe .BorderSize =0.2;_gag (_efe ,_fabe ,_beag ,_fddad );};_efe .Add_BMC ("\u0054\u0078"); _efe .Add_q ();_efe .Add_BT ();_beag ,_fddad =_aad .applyRotation (_eeg ,_beag ,_fddad ,_efe );_fegc ,_fade ,_cge :=_aad .processDA (_dea ,_caf ,_aagd ,_gcba ,_efe );if _cge !=nil {return nil ,_cge ;};_ccg :=_fegc .Font ;_dcae :=_fegc .Size ;_fbg :=_cb .MakeName (_fegc .Name ); _eca :=_dcae ==0;if _eca &&_fade {_dcae =_fddad *_aad .AutoFontSizeFraction ;};_cda :=_ccg .Encoder ();if _cda ==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"); _cda =_be .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};if len (_gcef )==0{return nil ,nil ;};_egg :=_df ;if _aad .MarginLeft !=nil {_egg =*_aad .MarginLeft ;};_aeba :=0.0;if _cda !=nil {for _ ,_aaag :=range _gcef {_cfab ,_gga :=_ccg .GetRuneMetrics (_aaag ); if !_gga {_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",_aaag ); continue ;};_aeba +=_cfab .Wx ;};_gcef =string (_cda .Encode (_gcef ));};if _dcae ==0||_eca &&_aeba > 0&&_egg +_aeba *_dcae /1000.0> _beag {_dcae =0.95*1000.0*(_beag -_egg )/_aeba ;};_gae :=1.0*_dcae ;_acccf :=2.0;{_bgag :=_gae ;if _eca &&_acccf +_bgag > _fddad {_dcae =0.95*(_fddad -_acccf ); _gae =1.0*_dcae ;_bgag =_gae ;};if _fddad > _bgag {_acccf =(_fddad -_bgag )/2.0;_acccf +=1.50;};};_efe .Add_Tf (*_fbg ,_dcae );_efe .Add_Td (_egg ,_acccf );_efe .Add_Tj (*_cb .MakeString (_gcef ));_efe .Add_ET ();_efe .Add_Q ();_efe .Add_EMC ();_cgd :=_ae .NewXObjectForm (); _cgd .Resources =_gcba ;_cgd .BBox =_cb .MakeArrayFromFloats ([]float64 {0,0,_bfbd ,_adef });_cgd .SetContentStream (_efe .Bytes (),_adgd ());return _cgd ,nil ;};func _ebc (_gab *_ae .PdfAcroForm ,_ged *_ae .PdfAnnotationWidget ,_eee *_ae .PdfFieldChoice ,_cg AppearanceStyle )(*_cb .PdfObjectDictionary ,error ){_abdg ,_aecd :=_cb .GetArray (_ged .Rect ); if !_aecd {return nil ,_ac .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_accc ,_ffca :=_ae .NewPdfRectangle (*_abdg );if _ffca !=nil {return nil ,_ffca ;};_ccd ,_bcc :=_accc .Width (),_accc .Height ();_a .Log .Debug ("\u0043\u0068\u006f\u0069\u0063\u0065\u002c\u0020\u0077\u0061\u0020\u0042S\u003a\u0020\u0025\u0076",_ged .BS ); _cbdb ,_ffca :=_bd .NewContentStreamParser (_egb (_eee .PdfField )).Parse ();if _ffca !=nil {return nil ,_ffca ;};_gcbg ,_bdg :=_cb .GetDict (_ged .MK );if _bdg {_gbgd ,_ :=_cb .GetDict (_ged .BS );_bef :=_cg .applyAppearanceCharacteristics (_gcbg ,_gbgd ,nil ); if _bef !=nil {return nil ,_bef ;};};_eaef :=_cb .MakeDict ();for _ ,_aga :=range _eee .Opt .Elements (){if _fde ,_dcaa :=_cb .GetArray (_aga );_dcaa &&_fde .Len ()==2{_aga =_fde .Get (1);};var _gea string ;if _add ,_faba :=_cb .GetString (_aga );_faba {_gea =_add .Decoded (); }else if _eacf ,_gcfb :=_cb .GetName (_aga );_gcfb {_gea =_eacf .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",_aga ); return nil ,_ac .New ("\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u002f\u0073t\u0072\u0069\u006e\u0067");};if len (_gea )> 0{_aefe ,_dgb :=_gfc (_eee .PdfField ,_ccd ,_bcc ,_gea ,_cg ,_cbdb ,_gab .DR ,_gcbg );if _dgb !=nil {return nil ,_dgb ; };_eaef .Set (*_cb .MakeName (_gea ),_aefe .ToPdfObject ());};};_adea :=_cb .MakeDict ();_adea .Set ("\u004e",_eaef );return _adea ,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 (_fgbf ImageFieldAppearance )WrapContentStream (page *_ae .PdfPage )error {_adga ,_dcfeb :=page .GetAllContentStreams ();if _dcfeb !=nil {return _dcfeb ;};_affg :=_bd .NewContentStreamParser (_adga );_eafe ,_dcfeb :=_affg .Parse ();if _dcfeb !=nil {return _dcfeb ; };_eafe .WrapIfNeeded ();_eacg :=[]string {_eafe .String ()};return page .SetContentStreams (_eacg ,_adgd ());}; // ImageFieldAppearance implements interface model.FieldAppearanceGenerator and generates appearance streams // for attaching an image to a button field. type ImageFieldAppearance struct{OnlyIfMissing bool ;_ggca *AppearanceStyle ;}; // TextFieldOptions defines optional parameter for a text field in a form. type TextFieldOptions struct{MaxLen int ;Value string ;};func _aa (_deea *_ae .PdfAnnotationWidget ,_ada *_ae .PdfFieldButton ,_ade *_ae .PdfPageResources ,_acg AppearanceStyle )(*_cb .PdfObjectDictionary ,error ){_fege ,_dccg :=_cb .GetArray (_deea .Rect ); if !_dccg {return nil ,_ac .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_abg ,_edfb :=_ae .NewPdfRectangle (*_fege );if _edfb !=nil {return nil ,_edfb ;};_gbad ,_fbdge :=_abg .Width (),_abg .Height ();_fca ,_aefb :=_gbad ,_fbdge ; _a .Log .Debug ("\u0043\u0068\u0065\u0063kb\u006f\u0078\u002c\u0020\u0077\u0061\u0020\u0042\u0053\u003a\u0020\u0025\u0076",_deea .BS );_fag ,_edfb :=_ae .NewStandard14Font ("\u005a\u0061\u0070f\u0044\u0069\u006e\u0067\u0062\u0061\u0074\u0073");if _edfb !=nil {return nil ,_edfb ; };_dddd ,_ecg :=_cb .GetDict (_deea .MK );if _ecg {_gcbd ,_ :=_cb .GetDict (_deea .BS );_baad :=_acg .applyAppearanceCharacteristics (_dddd ,_gcbd ,_fag );if _baad !=nil {return nil ,_baad ;};};_aaa :=_ae .NewXObjectForm ();{_fgce :=_bd .NewContentCreator (); if _acg .BorderSize > 0{_dfc (_fgce ,_acg ,_gbad ,_fbdge );};if _acg .DrawAlignmentReticle {_eec :=_acg ;_eec .BorderSize =0.2;_gag (_fgce ,_eec ,_gbad ,_fbdge );};_gbad ,_fbdge =_acg .applyRotation (_dddd ,_gbad ,_fbdge ,_fgce );_ddfb :=_acg .AutoFontSizeFraction *_fbdge ; _ege ,_gdc :=_fag .GetRuneMetrics (_acg .CheckmarkRune );if !_gdc {return nil ,_ac .New ("\u0067l\u0079p\u0068\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");};_ddgg :=_fag .Encoder ();_ccc :=_ddgg .Encode (string (_acg .CheckmarkRune )); _faa :=_ege .Wx *_ddfb /1000.0;_ccef :=705.0;_aag :=_ccef /1000.0*_ddfb ;_dag :=_df ;if _acg .MarginLeft !=nil {_dag =*_acg .MarginLeft ;};_adc :=1.0;if _faa < _gbad {_dag =(_gbad -_faa )/2.0;};if _aag < _fbdge {_adc =(_fbdge -_aag )/2.0;};_fgce .Add_q ().Add_g (0).Add_BT ().Add_Tf ("\u005a\u0061\u0044\u0062",_ddfb ).Add_Td (_dag ,_adc ).Add_Tj (*_cb .MakeStringFromBytes (_ccc )).Add_ET ().Add_Q (); _aaa .Resources =_ae .NewPdfPageResources ();_aaa .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_fag .ToPdfObject ());_aaa .BBox =_cb .MakeArrayFromFloats ([]float64 {0,0,_fca ,_aefb });_aaa .SetContentStream (_fgce .Bytes (),_adgd ());};_gbg :=_ae .NewXObjectForm (); {_deb :=_bd .NewContentCreator ();if _acg .BorderSize > 0{_dfc (_deb ,_acg ,_gbad ,_fbdge );};_gbg .BBox =_cb .MakeArrayFromFloats ([]float64 {0,0,_fca ,_aefb });_gbg .SetContentStream (_deb .Bytes (),_adgd ());};_ffbe :=_cb .MakeDict ();_ffbe .Set ("\u004f\u0066\u0066",_gbg .ToPdfObject ()); _ffbe .Set ("\u0059\u0065\u0073",_aaa .ToPdfObject ());_cdf :=_cb .MakeDict ();_cdf .Set ("\u004e",_ffbe );return _cdf ,nil ;}; // ImageFieldOptions defines optional parameters for a push button with image attach capability form field. type ImageFieldOptions struct{Image *_ae .Image ;_gdf AppearanceStyle ;}; // 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 (_gabg FieldAppearance )WrapContentStream (page *_ae .PdfPage )error {_cga ,_ead :=page .GetAllContentStreams ();if _ead !=nil {return _ead ;};_dddf :=_bd .NewContentStreamParser (_cga );_eeaf ,_ead :=_dddf .Parse ();if _ead !=nil {return _ead ;}; _eeaf .WrapIfNeeded ();_gde :=[]string {_eeaf .String ()};return page .SetContentStreams (_gde ,_adgd ());}; // CreateRectangleAnnotation creates a rectangle annotation object that can be added to page PDF annotations. func CreateRectangleAnnotation (rectDef RectangleAnnotationDef )(*_ae .PdfAnnotation ,error ){_bfdc :=_ae .NewPdfAnnotationSquare ();if rectDef .BorderEnabled {_ecafd ,_gcbf ,_face :=rectDef .BorderColor .R (),rectDef .BorderColor .G (),rectDef .BorderColor .B (); _bfdc .C =_cb .MakeArrayFromFloats ([]float64 {_ecafd ,_gcbf ,_face });_gdd :=_ae .NewBorderStyle ();_gdd .SetBorderWidth (rectDef .BorderWidth );_bfdc .BS =_gdd .ToPdfObject ();};if rectDef .FillEnabled {_gbagb ,_egc ,_cgdf :=rectDef .FillColor .R (),rectDef .FillColor .G (),rectDef .FillColor .B (); _bfdc .IC =_cb .MakeArrayFromFloats ([]float64 {_gbagb ,_egc ,_cgdf });}else {_bfdc .IC =_cb .MakeArrayFromIntegers ([]int {});};if rectDef .Opacity < 1.0{_bfdc .CA =_cb .MakeFloat (rectDef .Opacity );};_dcdf ,_gcfg ,_gbcf :=_efea (rectDef );if _gbcf !=nil {return nil ,_gbcf ; };_bfdc .AP =_dcdf ;_bfdc .Rect =_cb .MakeArrayFromFloats ([]float64 {_gcfg .Llx ,_gcfg .Lly ,_gcfg .Urx ,_gcfg .Ury });return _bfdc .PdfAnnotation ,nil ;};func _dga (_gcega LineAnnotationDef ,_cege string )([]byte ,*_ae .PdfRectangle ,*_ae .PdfRectangle ,error ){_afbf :=_cc .Line {X1 :0,Y1 :0,X2 :_gcega .X2 -_gcega .X1 ,Y2 :_gcega .Y2 -_gcega .Y1 ,LineColor :_gcega .LineColor ,Opacity :_gcega .Opacity ,LineWidth :_gcega .LineWidth ,LineEndingStyle1 :_gcega .LineEndingStyle1 ,LineEndingStyle2 :_gcega .LineEndingStyle2 }; _ddbe ,_fddc ,_cbfb :=_afbf .Draw (_cege );if _cbfb !=nil {return nil ,nil ,nil ,_cbfb ;};_gged :=&_ae .PdfRectangle {};_gged .Llx =_gcega .X1 +_fddc .Llx ;_gged .Lly =_gcega .Y1 +_fddc .Lly ;_gged .Urx =_gcega .X1 +_fddc .Urx ;_gged .Ury =_gcega .Y1 +_fddc .Ury ; return _ddbe ,_fddc ,_gged ,nil ;};func _efea (_bbd RectangleAnnotationDef )(*_cb .PdfObjectDictionary ,*_ae .PdfRectangle ,error ){_ggbc :=_ae .NewXObjectForm ();_ggbc .Resources =_ae .NewPdfPageResources ();_dbad :="";if _bbd .Opacity < 1.0{_gdfc :=_cb .MakeDict (); _gdfc .Set ("\u0063\u0061",_cb .MakeFloat (_bbd .Opacity ));_gdfc .Set ("\u0043\u0041",_cb .MakeFloat (_bbd .Opacity ));_eed :=_ggbc .Resources .AddExtGState ("\u0067\u0073\u0031",_gdfc );if _eed !=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 ,_eed ;};_dbad ="\u0067\u0073\u0031";};_beaf ,_gcg ,_cceg ,_adbe :=_acdc (_bbd ,_dbad );if _adbe !=nil {return nil ,nil ,_adbe ;};_adbe =_ggbc .SetContentStream (_beaf ,nil );if _adbe !=nil {return nil ,nil ,_adbe ;};_ggbc .BBox =_gcg .ToPdfObject (); _edea :=_cb .MakeDict ();_edea .Set ("\u004e",_ggbc .ToPdfObject ());return _edea ,_cceg ,nil ;}; // Style returns the appearance style of `fa`. If not specified, returns default style. func (_cbd FieldAppearance )Style ()AppearanceStyle {if _cbd ._ede !=nil {return *_cbd ._ede ;};_fge :=_df ;return AppearanceStyle {AutoFontSizeFraction :0.65,CheckmarkRune :'✔',BorderSize :0.0,BorderColor :_ae .NewPdfColorDeviceGray (0),FillColor :_ae .NewPdfColorDeviceGray (1),MultilineLineHeight :1.2,MultilineVAlignMiddle :false ,DrawAlignmentReticle :false ,AllowMK :true ,MarginLeft :&_fge }; }; // 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 *_ae .PdfPage ,name string ,rect []float64 ,opt ComboboxFieldOptions )(*_ae .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"); };_ffaee :=_ae .NewPdfField ();_gfae :=&_ae .PdfFieldChoice {};_ffaee .SetContext (_gfae );_gfae .PdfField =_ffaee ;_gfae .T =_cb .MakeString (name );_gfae .Opt =_cb .MakeArray ();for _ ,_ebb :=range opt .Choices {_gfae .Opt .Append (_cb .MakeString (_ebb )); };_gfae .SetFlag (_ae .FieldFlagCombo );_bbec :=_ae .NewPdfAnnotationWidget ();_bbec .Rect =_cb .MakeArrayFromFloats (rect );_bbec .P =page .ToPdfObject ();_bbec .F =_cb .MakeInteger (4);_bbec .Parent =_gfae .ToPdfObject ();_gfae .Annotations =append (_gfae .Annotations ,_bbec ); return _gfae ,nil ;};const (_cbf quadding =0;_ffb quadding =1;_dg quadding =2;_df float64 =2.0;); // SetStyle applies appearance `style` to `fa`. func (_ea *FieldAppearance )SetStyle (style AppearanceStyle ){_ea ._ede =&style }; // 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 *_ae .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 _cc .LineEndingStyle ;LineEndingStyle2 _cc .LineEndingStyle ;}; // 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 *_ae .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_ae .PdfColorDeviceRGB ;Opacity float64 ;}; // NewSignatureFieldOpts returns a new initialized instance of options // used to generate a signature appearance. func NewSignatureFieldOpts ()*SignatureFieldOpts {return &SignatureFieldOpts {Font :_ae .DefaultFont (),FontSize :10,LineHeight :1,AutoSize :true ,TextColor :_ae .NewPdfColorDeviceGray (0),BorderColor :_ae .NewPdfColorDeviceGray (0),FillColor :_ae .NewPdfColorDeviceGray (1),Encoder :_cb .NewFlateEncoder (),ImagePosition :SignatureImageLeft }; };type quadding int ;func _ffc (_abd *_ae .PdfAnnotationWidget ,_cbg *_ae .PdfFieldText ,_ddd *_ae .PdfPageResources ,_dgg AppearanceStyle )(*_cb .PdfObjectDictionary ,error ){_cfg :=_ae .NewPdfPageResources ();_bb ,_gb :=_cb .GetArray (_abd .Rect );if !_gb {return nil ,_ac .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074"); };_fgc ,_bag :=_ae .NewPdfRectangle (*_bb );if _bag !=nil {return nil ,_bag ;};_ga ,_fbd :=_fgc .Width (),_fgc .Height ();_baf ,_dge :=_ga ,_fbd ;_cdd ,_db :=_cb .GetDict (_abd .MK );if _db {_bfeg ,_ :=_cb .GetDict (_abd .BS );_agb :=_dgg .applyAppearanceCharacteristics (_cdd ,_bfeg ,nil ); if _agb !=nil {return nil ,_agb ;};};_eae ,_bag :=_bd .NewContentStreamParser (_egb (_cbg .PdfField )).Parse ();if _bag !=nil {return nil ,_bag ;};_bba :=_bd .NewContentCreator ();if _dgg .BorderSize > 0{_dfc (_bba ,_dgg ,_ga ,_fbd );};if _dgg .DrawAlignmentReticle {_dgf :=_dgg ; _dgf .BorderSize =0.2;_gag (_bba ,_dgf ,_ga ,_fbd );};_bba .Add_BMC ("\u0054\u0078");_bba .Add_q ();_ga ,_fbd =_dgg .applyRotation (_cdd ,_ga ,_fbd ,_bba );_bba .Add_BT ();_bcg ,_bea ,_bag :=_dgg .processDA (_cbg .PdfField ,_eae ,_ddd ,_cfg ,_bba );if _bag !=nil {return nil ,_bag ; };_dcd :=_bcg .Font ;_bege :=_bcg .Size ;_edfe :=_cb .MakeName (_bcg .Name );_bffd :=_bege ==0;if _bffd &&_bea {_bege =_fbd *_dgg .AutoFontSizeFraction ;};_da :=_dcd .Encoder ();if _da ==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"); _da =_be .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};_gbd ,_bag :=_dcd .GetFontDescriptor ();if _bag !=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 _eaee string ;if _cba ,_fgb :=_cb .GetString (_cbg .V );_fgb {_eaee =_cba .Decoded ();};if len (_eaee )==0{return nil ,nil ;};_eda :=[]string {_eaee };_efd :=false ;if _cbg .Flags ().Has (_ae .FieldFlagMultiline ){_efd =true ;_eaee =_c .Replace (_eaee ,"\u000d\u000a","\u000a",-1); _eaee =_c .Replace (_eaee ,"\u000d","\u000a",-1);_eda =_c .Split (_eaee ,"\u000a");};_ggf :=make ([]string ,len (_eda ));copy (_ggf ,_eda );_dfg :=_dgg .MultilineLineHeight ;_fea :=0.0;_agf :=0;if _da !=nil {for _bege >=0{_ffa :=make ([]string ,len (_eda )); copy (_ffa ,_eda );_egd :=make ([]string ,len (_ggf ));copy (_egd ,_ggf );_fea =0.0;_agf =0;_ee :=len (_ffa );_dbe :=0;for _dbe < _ee {var _agg float64 ;_fdd :=-1;_gbf :=_df ;if _dgg .MarginLeft !=nil {_gbf =*_dgg .MarginLeft ;};for _fa ,_bga :=range _ffa [_dbe ]{if _bga ==' '{_fdd =_fa ; };_feaf ,_fgf :=_dcd .GetRuneMetrics (_bga );if !_fgf {_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",_bga ); continue ;};_agg =_gbf ;_gbf +=_feaf .Wx ;if _efd &&!_bffd &&_bege *_gbf /1000.0> _ga {_af :=_fa ;_cdcg :=_fa ;if _fdd > 0{_af =_fdd +1;_cdcg =_fdd ;};_dfa :=_ffa [_dbe ][_af :];_edg :=_egd [_dbe ][_af :];if _dbe < len (_ffa )-1{_ffa =append (_ffa [:_dbe +1],_ffa [_dbe :]...); _ffa [_dbe +1]=_dfa ;_egd =append (_egd [:_dbe +1],_egd [_dbe :]...);_egd [_dbe +1]=_edg ;}else {_ffa =append (_ffa ,_dfa );_egd =append (_egd ,_edg );};_ffa [_dbe ]=_ffa [_dbe ][0:_cdcg ];_egd [_dbe ]=_egd [_dbe ][0:_cdcg ];_ee ++;_gbf =_agg ;break ;}; };if _gbf > _fea {_fea =_gbf ;};_ffa [_dbe ]=string (_da .Encode (_ffa [_dbe ]));if len (_ffa [_dbe ])> 0{_agf ++;};_dbe ++;};_dba :=_bege ;if _agf > 1{_dba *=_dfg ;};_ggce :=float64 (_agf )*_dba ;if _bffd ||_ggce <=_fbd {_eda =_ffa ;_ggf =_egd ;break ; };_bege --;};};_dfaa :=_df ;if _dgg .MarginLeft !=nil {_dfaa =*_dgg .MarginLeft ;};if _bege ==0||_bffd &&_fea > 0&&_dfaa +_fea *_bege /1000.0> _ga {_bege =0.95*1000.0*(_ga -_dfaa )/_fea ;};_fab :=_cbf ;{if _fdda ,_aba :=_cb .GetIntVal (_cbg .Q );_aba {switch _fdda {case 0:_fab =_cbf ; case 1:_fab =_ffb ;case 2:_fab =_dg ;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",_fdda ); };};};_gc :=_bege ;if _efd &&_agf > 1{_gc =_dfg *_bege ;};var _gd float64 ;if _gbd !=nil {_gd ,_bag =_gbd .GetCapHeight ();if _bag !=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",_bag ); };};if int (_gd )<=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"); _gd =1000;};_bcgg :=_gd /1000.0*_bege ;_feg :=0.0;{_dfd :=float64 (_agf )*_gc ;if _bffd &&_feg +_dfd > _fbd {_bege =0.95*(_fbd -_feg )/float64 (_agf );_gc =_bege ;if _efd &&_agf > 1{_gc =_dfg *_bege ;};_bcgg =_gd /1000.0*_bege ;_dfd =float64 (_agf )*_gc ; };if _fbd > _dfd {if _efd {if _dgg .MultilineVAlignMiddle {_fec :=(_fbd -(_dfd +_bcgg ))/2.0;_edgd :=_fec +_dfd +_bcgg -_gc ;_feg =_edgd ;if _agf > 1{_feg =_feg +(_dfd /_bege *float64 (_agf ))-_gc -_bcgg ;};if _feg < _dfd {_feg =(_fbd -_bcgg )/2.0;};}else {_feg =_fbd -_gc ; if _feg > _bege {_gba :=0.0;if _efd &&_dgg .MultilineLineHeight > 1&&_agf > 1{_gba =_dgg .MultilineLineHeight -1;};_feg -=_bege *(0.5-_gba );};};}else {_feg =(_fbd -_bcgg )/2.0;};};};_bba .Add_Tf (*_edfe ,_bege );_bba .Add_Td (_dfaa ,_feg );_dca :=_dfaa ; _eb :=_dfaa ;for _gce ,_bbb :=range _eda {_abf :=0.0;for _ ,_fc :=range _ggf [_gce ]{_baab ,_bgb :=_dcd .GetRuneMetrics (_fc );if !_bgb {continue ;};_abf +=_baab .Wx ;};_de :=_abf /1000.0*_bege ;_fdf :=_ga -_de ;var _gcb float64 ;switch _fab {case _cbf :_gcb =_dca ; case _ffb :_gcb =_fdf /2;case _dg :_gcb =_fdf ;};_dfaa =_gcb -_eb ;if _dfaa > 0.0{_bba .Add_Td (_dfaa ,0);};_eb =_gcb ;_bba .Add_Tj (*_cb .MakeString (_bbb ));if _gce < len (_eda )-1{_bba .Add_Td (0,-_bege *_dfg );};};_bba .Add_ET ();_bba .Add_Q ();_bba .Add_EMC (); _dee :=_ae .NewXObjectForm ();_dee .Resources =_cfg ;_dee .BBox =_cb .MakeArrayFromFloats ([]float64 {0,0,_baf ,_dge });_dee .SetContentStream (_bba .Bytes (),_adgd ());_bbc :=_cb .MakeDict ();_bbc .Set ("\u004e",_dee .ToPdfObject ());return _bbc ,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 *_ae .PdfPage ,name string ,rect []float64 ,opt CheckboxFieldOptions )(*_ae .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"); };_aaf ,_gceg :=_ae .NewStandard14Font (_ae .ZapfDingbatsName );if _gceg !=nil {return nil ,_gceg ;};_ggg :=_ae .NewPdfField ();_fbefd :=&_ae .PdfFieldButton {};_ggg .SetContext (_fbefd );_fbefd .PdfField =_ggg ;_fbefd .T =_cb .MakeString (name );_fbefd .SetType (_ae .ButtonTypeCheckbox ); _ccdc :="\u004f\u0066\u0066";if opt .Checked {_ccdc ="\u0059\u0065\u0073";};_fbefd .V =_cb .MakeName (_ccdc );_bed :=_ae .NewPdfAnnotationWidget ();_bed .Rect =_cb .MakeArrayFromFloats (rect );_bed .P =page .ToPdfObject ();_bed .F =_cb .MakeInteger (4); _bed .Parent =_fbefd .ToPdfObject ();_gecg :=rect [2]-rect [0];_cdfe :=rect [3]-rect [1];var _afd _e .Buffer ;_afd .WriteString ("\u0071\u000a");_afd .WriteString ("\u0030 \u0030\u0020\u0031\u0020\u0072\u0067\n");_afd .WriteString ("\u0042\u0054\u000a"); _afd .WriteString ("\u002f\u005a\u0061D\u0062\u0020\u0031\u0032\u0020\u0054\u0066\u000a");_afd .WriteString ("\u0045\u0054\u000a");_afd .WriteString ("\u0051\u000a");_gcd :=_bd .NewContentCreator ();_gcd .Add_q ();_gcd .Add_rg (0,0,1);_gcd .Add_BT ();_gcd .Add_Tf (*_cb .MakeName ("\u005a\u0061\u0044\u0062"),12); _gcd .Add_Td (0,0);_gcd .Add_ET ();_gcd .Add_Q ();_eff :=_ae .NewXObjectForm ();_eff .SetContentStream (_gcd .Bytes (),_cb .NewRawEncoder ());_eff .BBox =_cb .MakeArrayFromFloats ([]float64 {0,0,_gecg ,_cdfe });_eff .Resources =_ae .NewPdfPageResources (); _eff .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_aaf .ToPdfObject ());_gcd =_bd .NewContentCreator ();_gcd .Add_q ();_gcd .Add_re (0,0,_gecg ,_cdfe );_gcd .Add_W ().Add_n ();_gcd .Add_rg (0,0,1);_gcd .Translate (0,3.0);_gcd .Add_BT ();_gcd .Add_Tf (*_cb .MakeName ("\u005a\u0061\u0044\u0062"),12); _gcd .Add_Td (0,0);_gcd .Add_Tj (*_cb .MakeString ("\u0034"));_gcd .Add_ET ();_gcd .Add_Q ();_bfed :=_ae .NewXObjectForm ();_bfed .SetContentStream (_gcd .Bytes (),_cb .NewRawEncoder ());_bfed .BBox =_cb .MakeArrayFromFloats ([]float64 {0,0,_gecg ,_cdfe }); _bfed .Resources =_ae .NewPdfPageResources ();_bfed .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_aaf .ToPdfObject ());_bbf :=_cb .MakeDict ();_bbf .Set ("\u004f\u0066\u0066",_eff .ToPdfObject ());_bbf .Set ("\u0059\u0065\u0073",_bfed .ToPdfObject ()); _gdcea :=_cb .MakeDict ();_gdcea .Set ("\u004e",_bbf );_bed .AP =_gdcea ;_bed .AS =_cb .MakeName (_ccdc );_fbefd .Annotations =append (_fbefd .Annotations ,_bed );return _fbefd ,nil ;};func _adgd ()_cb .StreamEncoder {return _cb .NewFlateEncoder ()}; // 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 *_ae .PdfSignature ,lines []*SignatureLine ,opts *SignatureFieldOpts )(*_ae .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"); };_badb ,_aeff :=_ebd (lines ,opts );if _aeff !=nil {return nil ,_aeff ;};_aadcg :=_ae .NewPdfFieldSignature (signature );_aadcg .Rect =_cb .MakeArrayFromFloats (opts .Rect );_aadcg .AP =_badb ;return _aadcg ,nil ;};func (_eeae *AppearanceStyle )applyRotation (_gfg *_cb .PdfObjectDictionary ,_gac ,_bfee float64 ,_fcb *_bd .ContentCreator )(float64 ,float64 ){if !_eeae .AllowMK {return _gac ,_bfee ; };if _gfg ==nil {return _gac ,_bfee ;};_aggf ,_ :=_cb .GetNumberAsFloat (_gfg .Get ("\u0052"));if _aggf ==0{return _gac ,_bfee ;};_bfc :=-_aggf ;_fgaf :=_cc .Path {Points :[]_cc .Point {_cc .NewPoint (0,0).Rotate (_bfc ),_cc .NewPoint (_gac ,0).Rotate (_bfc ),_cc .NewPoint (0,_bfee ).Rotate (_bfc ),_cc .NewPoint (_gac ,_bfee ).Rotate (_bfc )}}.GetBoundingBox (); _fcb .RotateDeg (_aggf );_fcb .Translate (_fgaf .X ,_fgaf .Y );return _fgaf .Width ,_fgaf .Height ;};func _fgga (_gfb *_ae .PdfFieldButton ,_gcea *_ae .PdfAnnotationWidget ,_ceae AppearanceStyle )(*_cb .PdfObjectDictionary ,error ){_ddgd ,_dcg :=_cb .GetArray (_gcea .Rect ); if !_dcg {return nil ,_ac .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_ddb ,_aadd :=_ae .NewPdfRectangle (*_ddgd );if _aadd !=nil {return nil ,_aadd ;};_ecaa ,_cdge :=_ddb .Width (),_ddb .Height ();_dgfc :=_bd .NewContentCreator (); if _ceae .BorderSize > 0{_dfc (_dgfc ,_ceae ,_ecaa ,_cdge );};if _ceae .DrawAlignmentReticle {_dfb :=_ceae ;_dfb .BorderSize =0.2;_gag (_dgfc ,_dfb ,_ecaa ,_cdge );};_fcde :=_gfb .GetFillImage ();_ebg ,_aadd :=_bfdd (_ecaa ,_cdge ,_fcde ,_ceae );if _aadd !=nil {return nil ,_aadd ; };_gda ,_cff :=_cb .GetDict (_gcea .MK );if _cff {_gda .Set ("\u006c",_ebg .ToPdfObject ());};_abb :=_cb .MakeDict ();_abb .Set ("\u0046\u0052\u004d",_ebg .ToPdfObject ());_fbgg :=_ae .NewPdfPageResources ();_fbgg .ProcSet =_cb .MakeArray (_cb .MakeName ("\u0050\u0044\u0046")); _fbgg .XObject =_abb ;_fdc :=_ecaa -2;_ffgf :=_cdge -2;_dgfc .Add_q ();_dgfc .Add_re (1,1,_fdc ,_ffgf );_dgfc .Add_W ();_dgfc .Add_n ();_fdc -=2;_ffgf -=2;_dgfc .Add_q ();_dgfc .Add_re (2,2,_fdc ,_ffgf );_dgfc .Add_W ();_dgfc .Add_n ();_dgef :=_ec .Min (_fdc /float64 (_fcde .Width ),_ffgf /float64 (_fcde .Height )); _dgfc .Add_cm (_dgef ,0,0,_dgef ,(_ecaa /2)-(float64 (_fcde .Width )*_dgef /2)+2,2);_dgfc .Add_Do ("\u0046\u0052\u004d");_dgfc .Add_Q ();_dgfc .Add_Q ();_ggfe :=_ae .NewXObjectForm ();_ggfe .FormType =_cb .MakeInteger (1);_ggfe .Resources =_fbgg ;_ggfe .BBox =_cb .MakeArrayFromFloats ([]float64 {0,0,_ecaa ,_cdge }); _ggfe .Matrix =_cb .MakeArrayFromFloats ([]float64 {1.0,0.0,0.0,1.0,0.0,0.0});_ggfe .SetContentStream (_dgfc .Bytes (),_adgd ());_gacd :=_cb .MakeDict ();_gacd .Set ("\u004e",_ggfe .ToPdfObject ());return _gacd ,nil ;}; // SignatureLine represents a line of information in the signature field appearance. type SignatureLine struct{Desc string ;Text string ;}; // 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 *_ae .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 _cdc (_cfa CircleAnnotationDef )(*_cb .PdfObjectDictionary ,*_ae .PdfRectangle ,error ){_bf :=_ae .NewXObjectForm ();_bf .Resources =_ae .NewPdfPageResources ();_fe :="";if _cfa .Opacity < 1.0{_dcf :=_cb .MakeDict ();_dcf .Set ("\u0063\u0061",_cb .MakeFloat (_cfa .Opacity )); _dcf .Set ("\u0043\u0041",_cb .MakeFloat (_cfa .Opacity ));_ece :=_bf .Resources .AddExtGState ("\u0067\u0073\u0031",_dcf );if _ece !=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 ,_ece ;};_fe ="\u0067\u0073\u0031";};_ff ,_cfc ,_ba ,_beg :=_fb (_cfa ,_fe );if _beg !=nil {return nil ,nil ,_beg ;};_beg =_bf .SetContentStream (_ff ,nil );if _beg !=nil {return nil ,nil ,_beg ;};_bf .BBox =_cfc .ToPdfObject ();_fd :=_cb .MakeDict (); _fd .Set ("\u004e",_bf .ToPdfObject ());return _fd ,_ba ,nil ;}; // GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`. // Implements interface model.FieldAppearanceGenerator. func (_dd FieldAppearance )GenerateAppearanceDict (form *_ae .PdfAcroForm ,field *_ae .PdfField ,wa *_ae .PdfAnnotationWidget )(*_cb .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 ); _ ,_ef :=field .GetContext ().(*_ae .PdfFieldText );_adg ,_caa :=_cb .GetDict (wa .AP );if _caa &&_dd .OnlyIfMissing &&(!_ef ||!_dd .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 _adg ,nil ;};if form .DR ==nil {form .DR =_ae .NewPdfPageResources ();};switch _dcc :=field .GetContext ().(type ){case *_ae .PdfFieldText :_ddf :=_dcc ;if _gge :=_egb (_ddf .PdfField );_gge ==""{_ddf .DA =form .DA ;};switch {case _ddf .Flags ().Has (_ae .FieldFlagPassword ):return nil ,nil ; case _ddf .Flags ().Has (_ae .FieldFlagFileSelect ):return nil ,nil ;case _ddf .Flags ().Has (_ae .FieldFlagComb ):if _ddf .MaxLen !=nil {_bff ,_fga :=_fcd (wa ,_ddf ,form .DR ,_dd .Style ());if _fga !=nil {return nil ,_fga ;};return _bff ,nil ;};};_ge ,_fbc :=_ffc (wa ,_ddf ,form .DR ,_dd .Style ()); if _fbc !=nil {return nil ,_fbc ;};return _ge ,nil ;case *_ae .PdfFieldButton :_ccf :=_dcc ;if _ccf .IsCheckbox (){_bg ,_ag :=_aa (wa ,_ccf ,form .DR ,_dd .Style ());if _ag !=nil {return nil ,_ag ;};return _bg ,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",_ccf .GetType ()); case *_ae .PdfFieldChoice :_ab :=_dcc ;switch {case _ab .Flags ().Has (_ae .FieldFlagCombo ):_ecee ,_eac :=_ebc (form ,wa ,_ab ,_dd .Style ());if _eac !=nil {return nil ,_eac ;};return _ecee ,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",_ab .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",_dcc );};return nil ,nil ;};func _fb (_begg CircleAnnotationDef ,_fg string )([]byte ,*_ae .PdfRectangle ,*_ae .PdfRectangle ,error ){_eg :=_cc .Circle {X :_begg .X ,Y :_begg .Y ,Width :_begg .Width ,Height :_begg .Height ,FillEnabled :_begg .FillEnabled ,FillColor :_begg .FillColor ,BorderEnabled :_begg .BorderEnabled ,BorderWidth :_begg .BorderWidth ,BorderColor :_begg .BorderColor ,Opacity :_begg .Opacity }; _bfe ,_cab ,_cdcd :=_eg .Draw (_fg );if _cdcd !=nil {return nil ,nil ,nil ,_cdcd ;};_ad :=&_ae .PdfRectangle {};_ad .Llx =_begg .X +_cab .Llx ;_ad .Lly =_begg .Y +_cab .Lly ;_ad .Urx =_begg .X +_cab .Urx ;_ad .Ury =_begg .Y +_cab .Ury ;return _bfe ,_cab ,_ad ,nil ; };func _dfc (_abad *_bd .ContentCreator ,_bagf AppearanceStyle ,_dda ,_gca float64 ){_abad .Add_q ().Add_re (0,0,_dda ,_gca ).Add_w (_bagf .BorderSize ).SetStrokingColor (_bagf .BorderColor ).SetNonStrokingColor (_bagf .FillColor ).Add_B ().Add_Q ();}; // 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 _gag (_gfa *_bd .ContentCreator ,_ecgg AppearanceStyle ,_fagf ,_egge float64 ){_gfa .Add_q ().Add_re (0,0,_fagf ,_egge ).Add_re (0,_egge /2,_fagf ,_egge /2).Add_re (0,0,_fagf ,_egge ).Add_re (_fagf /2,0,_fagf /2,_egge ).Add_w (_ecgg .BorderSize ).SetStrokingColor (_ecgg .BorderColor ).SetNonStrokingColor (_ecgg .FillColor ).Add_B ().Add_Q (); }; // 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 *_ae .PdfPage ,name string ,rect []float64 ,opt ImageFieldOptions )(*_ae .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"); };_ega :=_ae .NewPdfField ();_ecag :=&_ae .PdfFieldButton {};_ecag .PdfField =_ega ;_ega .SetContext (_ecag );_ecag .SetType (_ae .ButtonTypePush );_ecag .T =_cb .MakeString (name );_dbg :=_ae .NewPdfAnnotationWidget ();_dbg .Rect =_cb .MakeArrayFromFloats (rect ); _dbg .P =page .ToPdfObject ();_dbg .F =_cb .MakeInteger (4);_dbg .Parent =_ecag .ToPdfObject ();_ggag :=rect [2]-rect [0];_eggef :=rect [3]-rect [1];_gcec :=opt ._gdf ;_gcbc :=_bd .NewContentCreator ();if _gcec .BorderSize > 0{_dfc (_gcbc ,_gcec ,_ggag ,_eggef ); };if _gcec .DrawAlignmentReticle {_cead :=_gcec ;_cead .BorderSize =0.2;_gag (_gcbc ,_cead ,_ggag ,_eggef );};_gadd ,_dbge :=_bfdd (_ggag ,_eggef ,opt .Image ,_gcec );if _dbge !=nil {return nil ,_dbge ;};_gfd ,_bbag :=_cb .GetDict (_dbg .MK );if _bbag {_gfd .Set ("\u006c",_gadd .ToPdfObject ()); };_adb :=_cb .MakeDict ();_adb .Set ("\u0046\u0052\u004d",_gadd .ToPdfObject ());_fce :=_ae .NewPdfPageResources ();_fce .ProcSet =_cb .MakeArray (_cb .MakeName ("\u0050\u0044\u0046"));_fce .XObject =_adb ;_gacc :=_ggag -2;_ffbd :=_eggef -2;_gcbc .Add_q (); _gcbc .Add_re (1,1,_gacc ,_ffbd );_gcbc .Add_W ();_gcbc .Add_n ();_gacc -=2;_ffbd -=2;_gcbc .Add_q ();_gcbc .Add_re (2,2,_gacc ,_ffbd );_gcbc .Add_W ();_gcbc .Add_n ();_dfafe :=_ec .Min (_gacc /float64 (opt .Image .Width ),_ffbd /float64 (opt .Image .Height )); _gcbc .Add_cm (_dfafe ,0,0,_dfafe ,(_ggag /2)-(float64 (opt .Image .Width )*_dfafe /2)+2,2);_gcbc .Add_Do ("\u0046\u0052\u004d");_gcbc .Add_Q ();_gcbc .Add_Q ();_aaec :=_ae .NewXObjectForm ();_aaec .FormType =_cb .MakeInteger (1);_aaec .Resources =_fce ; _aaec .BBox =_cb .MakeArrayFromFloats ([]float64 {0,0,_ggag ,_eggef });_aaec .Matrix =_cb .MakeArrayFromFloats ([]float64 {1.0,0.0,0.0,1.0,0.0,0.0});_aaec .SetContentStream (_gcbc .Bytes (),_adgd ());_dbee :=_cb .MakeDict ();_dbee .Set ("\u004e",_aaec .ToPdfObject ()); _dbg .AP =_dbee ;_ecag .Annotations =append (_ecag .Annotations ,_dbg );return _ecag ,nil ;};