unipdf/annotator/annotator.go
2023-09-07 17:40:17 +00:00

459 lines
72 KiB
Go

//
// Copyright 2020 FoxyUtils ehf. All rights reserved.
//
// This is a commercial product and requires a license to operate.
// A trial license can be obtained at https://unidoc.io
//
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
//
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
// Package 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 (_ca "bytes";_e "errors";_c "github.com/unidoc/unipdf/v3/common";_cg "github.com/unidoc/unipdf/v3/contentstream";_ga "github.com/unidoc/unipdf/v3/contentstream/draw";_bf "github.com/unidoc/unipdf/v3/core";_b "github.com/unidoc/unipdf/v3/internal/textencoding";
_f "github.com/unidoc/unipdf/v3/model";_bd "image";_g "math";_ce "strings";_be "unicode";);
// 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 *_f .PdfPage ,name string ,rect []float64 ,opt TextFieldOptions )(*_f .PdfFieldText ,error ){if page ==nil {return nil ,_e .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};if len (name )<=0{return nil ,_e .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 ,_e .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");};_bfc :=_f .NewPdfField ();_ddbe :=&_f .PdfFieldText {};_bfc .SetContext (_ddbe );_ddbe .PdfField =_bfc ;_ddbe .T =_bf .MakeString (name );
if opt .MaxLen > 0{_ddbe .MaxLen =_bf .MakeInteger (int64 (opt .MaxLen ));};if len (opt .Value )> 0{_ddbe .V =_bf .MakeString (opt .Value );};_egde :=_f .NewPdfAnnotationWidget ();_egde .Rect =_bf .MakeArrayFromFloats (rect );_egde .P =page .ToPdfObject ();
_egde .F =_bf .MakeInteger (4);_egde .Parent =_ddbe .ToPdfObject ();_ddbe .Annotations =append (_ddbe .Annotations ,_egde );return _ddbe ,nil ;};func _ddd (_fg CircleAnnotationDef ,_ge string )([]byte ,*_f .PdfRectangle ,*_f .PdfRectangle ,error ){_bdg :=_ga .Circle {X :_fg .X ,Y :_fg .Y ,Width :_fg .Width ,Height :_fg .Height ,FillEnabled :_fg .FillEnabled ,FillColor :_fg .FillColor ,BorderEnabled :_fg .BorderEnabled ,BorderWidth :_fg .BorderWidth ,BorderColor :_fg .BorderColor ,Opacity :_fg .Opacity };
_beg ,_bad ,_aa :=_bdg .Draw (_ge );if _aa !=nil {return nil ,nil ,nil ,_aa ;};_eg :=&_f .PdfRectangle {};_eg .Llx =_fg .X +_bad .Llx ;_eg .Lly =_fg .Y +_bad .Lly ;_eg .Urx =_fg .X +_bad .Urx ;_eg .Ury =_fg .Y +_bad .Ury ;return _beg ,_bad ,_eg ,nil ;};
func _gedd (_bgba []_ga .Point )(_cedg []_ga .Point ,_dgfc []_ga .Point ,_ebe error ){_eabd :=len (_bgba )-1;if len (_bgba )< 1{return nil ,nil ,_e .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 _eabd ==1{_dbg :=_ga .Point {X :(2*_bgba [0].X +_bgba [1].X )/3,Y :(2*_bgba [0].Y +_bgba [1].Y )/3};_cedg =append (_cedg ,_dbg );_dgfc =append (_dgfc ,_ga .Point {X :2*_dbg .X -_bgba [0].X ,Y :2*_dbg .Y -_bgba [0].Y });return _cedg ,_dgfc ,nil ;};
_efcg :=make ([]float64 ,_eabd );for _dgag :=1;_dgag < _eabd -1;_dgag ++{_efcg [_dgag ]=4*_bgba [_dgag ].X +2*_bgba [_dgag +1].X ;};_efcg [0]=_bgba [0].X +2*_bgba [1].X ;_efcg [_eabd -1]=(8*_bgba [_eabd -1].X +_bgba [_eabd ].X )/2.0;_bfaa :=_ecddd (_efcg );
for _gfee :=1;_gfee < _eabd -1;_gfee ++{_efcg [_gfee ]=4*_bgba [_gfee ].Y +2*_bgba [_gfee +1].Y ;};_efcg [0]=_bgba [0].Y +2*_bgba [1].Y ;_efcg [_eabd -1]=(8*_bgba [_eabd -1].Y +_bgba [_eabd ].Y )/2.0;_edfb :=_ecddd (_efcg );_cedg =make ([]_ga .Point ,_eabd );
_dgfc =make ([]_ga .Point ,_eabd );for _cgffb :=0;_cgffb < _eabd ;_cgffb ++{_cedg [_cgffb ]=_ga .Point {X :_bfaa [_cgffb ],Y :_edfb [_cgffb ]};if _cgffb < _eabd -1{_dgfc [_cgffb ]=_ga .Point {X :2*_bgba [_cgffb +1].X -_bfaa [_cgffb +1],Y :2*_bgba [_cgffb +1].Y -_edfb [_cgffb +1]};
}else {_dgfc [_cgffb ]=_ga .Point {X :(_bgba [_eabd ].X +_bfaa [_eabd -1])/2,Y :(_bgba [_eabd ].Y +_edfb [_eabd -1])/2};};};return _cedg ,_dgfc ,nil ;};
// 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 *_f .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 _ef (_bffd *_f .PdfAnnotationWidget ,_dddb *_f .PdfFieldText ,_fad *_f .PdfPageResources ,_caf AppearanceStyle )(*_bf .PdfObjectDictionary ,error ){_cd :=_f .NewPdfPageResources ();_ebdg ,_dbc :=_bf .GetArray (_bffd .Rect );if !_dbc {return nil ,_e .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");
};_agfg ,_fae :=_f .NewPdfRectangle (*_ebdg );if _fae !=nil {return nil ,_fae ;};_gbd ,_efa :=_agfg .Width (),_agfg .Height ();_caa ,_abb :=_gbd ,_efa ;_gbb ,_dege :=_bf .GetDict (_bffd .MK );if _dege {_beec ,_ :=_bf .GetDict (_bffd .BS );_eba :=_caf .applyAppearanceCharacteristics (_gbb ,_beec ,nil );
if _eba !=nil {return nil ,_eba ;};};_cbda ,_dege :=_bf .GetIntVal (_dddb .MaxLen );if !_dege {return nil ,_e .New ("\u006d\u0061\u0078\u006c\u0065\u006e\u0020\u006e\u006ft\u0020\u0073\u0065\u0074");};if _cbda <=0{return nil ,_e .New ("\u006d\u0061\u0078\u004c\u0065\u006e\u0020\u0069\u006ev\u0061\u006c\u0069\u0064");
};_gac :=_gbd /float64 (_cbda );_bdd ,_fae :=_cg .NewContentStreamParser (_cde (_dddb .PdfField )).Parse ();if _fae !=nil {return nil ,_fae ;};_fdef :=_cg .NewContentCreator ();if _caf .BorderSize > 0{_gab (_fdef ,_caf ,_gbd ,_efa );};if _caf .DrawAlignmentReticle {_dbd :=_caf ;
_dbd .BorderSize =0.2;_adfa (_fdef ,_dbd ,_gbd ,_efa );};_fdef .Add_BMC ("\u0054\u0078");_fdef .Add_q ();_ ,_efa =_caf .applyRotation (_gbb ,_gbd ,_efa ,_fdef );_fdef .Add_BT ();_ede ,_bgfc ,_fae :=_caf .processDA (_dddb .PdfField ,_bdd ,_fad ,_cd ,_fdef );
if _fae !=nil {return nil ,_fae ;};_efg :=_ede .Font ;_cfbb :=_bf .MakeName (_ede .Name );_fac :=_ede .Size ;_def :=_fac ==0;if _def &&_bgfc {_fac =_efa *_caf .AutoFontSizeFraction ;};_caff :=_efg .Encoder ();if _caff ==nil {_c .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");
_caff =_b .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};var _fdb string ;if _geab ,_ggd :=_bf .GetString (_dddb .V );_ggd {_fdb =_geab .Decoded ();};_fdef .Add_Tf (*_cfbb ,_fac );var _dfd float64 ;for _ ,_gag :=range _fdb {_gdf ,_eae :=_efg .GetRuneMetrics (_gag );
if !_eae {_c .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",_gag );
continue ;};_eeb :=_gdf .Wy ;if int (_eeb )<=0{_eeb =_gdf .Wx ;};if _eeb > _dfd {_dfd =_eeb ;};};if int (_dfd )==0{_c .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");
_dfd =1000;};_bfae ,_fae :=_efg .GetFontDescriptor ();if _fae !=nil {_c .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 _bbc float64 ;if _bfae !=nil {_bbc ,_fae =_bfae .GetCapHeight ();if _fae !=nil {_c .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",_fae );
};};if int (_bbc )<=0{_c .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");
_bbc =1000.0;};_dfc :=_bbc /1000.0*_fac ;_dbcc :=0.0;_acd :=1.0*_fac *(_dfd /1000.0);{_eeac :=_acd ;if _def &&_dbcc +_eeac > _efa {_fac =0.95*(_efa -_dbcc );_dfc =_bbc /1000.0*_fac ;};if _efa > _dfc {_dbcc =(_efa -_dfc )/2.0;};};_fdef .Add_Td (0,_dbcc );
if _cadd ,_aeg :=_bf .GetIntVal (_dddb .Q );_aeg {switch _cadd {case 2:if len (_fdb )< _cbda {_dgc :=float64 (_cbda -len (_fdb ))*_gac ;_fdef .Add_Td (_dgc ,0);};};};for _dgg ,_aff :=range _fdb {_fbg :=_cb ;if _caf .MarginLeft !=nil {_fbg =*_caf .MarginLeft ;
};_bdce :=string (_aff );if _caff !=nil {_ccf ,_gcbe :=_efg .GetRuneMetrics (_aff );if !_gcbe {_c .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",_aff );
continue ;};_bdce =string (_caff .Encode (_bdce ));_cbg :=_fac *_ccf .Wx /1000.0;_gba :=(_gac -_cbg )/2;_fbg =_gba ;};_fdef .Add_Td (_fbg ,0);_fdef .Add_Tj (*_bf .MakeString (_bdce ));if _dgg !=len (_fdb )-1{_fdef .Add_Td (_gac -_fbg ,0);};};_fdef .Add_ET ();
_fdef .Add_Q ();_fdef .Add_EMC ();_ece :=_f .NewXObjectForm ();_ece .Resources =_cd ;_ece .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_caa ,_abb });_ece .SetContentStream (_fdef .Bytes (),_bffe ());_dfa :=_bf .MakeDict ();_dfa .Set ("\u004e",_ece .ToPdfObject ());
return _dfa ,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 []_ga .Path ;
// Color is the color of the line. Default to black.
Color *_f .PdfColorDeviceRGB ;
// LineWidth is the width of the line.
LineWidth float64 ;};
// 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 ;_bb *AppearanceStyle ;};func (_fdcf *AppearanceStyle )applyAppearanceCharacteristics (_afe *_bf .PdfObjectDictionary ,_dgba *_bf .PdfObjectDictionary ,_eaa *_f .PdfFont )error {if !_fdcf .AllowMK {return nil ;
};if CA ,_ceaf :=_bf .GetString (_afe .Get ("\u0043\u0041"));_ceaf &&_eaa !=nil {_gef :=CA .Bytes ();if len (_gef )!=0{_eeg :=[]rune (_eaa .Encoder ().Decode (_gef ));if len (_eeg )==1{_fdcf .CheckmarkRune =_eeg [0];};};};if BC ,_egdb :=_bf .GetArray (_afe .Get ("\u0042\u0043"));
_egdb {_gbbd ,_bda :=BC .ToFloat64Array ();if _bda !=nil {return _bda ;};switch len (_gbbd ){case 1:_fdcf .BorderColor =_f .NewPdfColorDeviceGray (_gbbd [0]);case 3:_fdcf .BorderColor =_f .NewPdfColorDeviceRGB (_gbbd [0],_gbbd [1],_gbbd [2]);case 4:_fdcf .BorderColor =_f .NewPdfColorDeviceCMYK (_gbbd [0],_gbbd [1],_gbbd [2],_gbbd [3]);
default:_c .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 (_gbbd ));
};if _dgba !=nil {if _fggc ,_bddd :=_bf .GetNumberAsFloat (_dgba .Get ("\u0057"));_bddd ==nil {_fdcf .BorderSize =_fggc ;};};};if BG ,_dca :=_bf .GetArray (_afe .Get ("\u0042\u0047"));_dca {_gae ,_bebc :=BG .ToFloat64Array ();if _bebc !=nil {return _bebc ;
};switch len (_gae ){case 1:_fdcf .FillColor =_f .NewPdfColorDeviceGray (_gae [0]);case 3:_fdcf .FillColor =_f .NewPdfColorDeviceRGB (_gae [0],_gae [1],_gae [2]);case 4:_fdcf .FillColor =_f .NewPdfColorDeviceCMYK (_gae [0],_gae [1],_gae [2],_gae [3]);default:_c .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 (_gae ));
};};return nil ;};
// GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`.
// Implements interface model.FieldAppearanceGenerator.
func (_bff FieldAppearance )GenerateAppearanceDict (form *_f .PdfAcroForm ,field *_f .PdfField ,wa *_f .PdfAnnotationWidget )(*_bf .PdfObjectDictionary ,error ){_c .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 );
_ ,_bg :=field .GetContext ().(*_f .PdfFieldText );_agg ,_ab :=_bf .GetDict (wa .AP );if _ab &&_bff .OnlyIfMissing &&(!_bg ||!_bff .RegenerateTextFields ){_c .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 _agg ,nil ;};if form .DR ==nil {form .DR =_f .NewPdfPageResources ();};switch _bag :=field .GetContext ().(type ){case *_f .PdfFieldText :_af :=_bag ;if _gg :=_cde (_af .PdfField );_gg ==""{_af .DA =form .DA ;};switch {case _af .Flags ().Has (_f .FieldFlagPassword ):return nil ,nil ;
case _af .Flags ().Has (_f .FieldFlagFileSelect ):return nil ,nil ;case _af .Flags ().Has (_f .FieldFlagComb ):if _af .MaxLen !=nil {_ecd ,_bed :=_ef (wa ,_af ,form .DR ,_bff .Style ());if _bed !=nil {return nil ,_bed ;};return _ecd ,nil ;};};_bgc ,_gfg :=_fd (wa ,_af ,form .DR ,_bff .Style ());
if _gfg !=nil {return nil ,_gfg ;};return _bgc ,nil ;case *_f .PdfFieldButton :_aeb :=_bag ;if _aeb .IsCheckbox (){_ged ,_geg :=_dgb (wa ,_aeb ,form .DR ,_bff .Style ());if _geg !=nil {return nil ,_geg ;};return _ged ,nil ;};_c .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",_aeb .GetType ());
case *_f .PdfFieldChoice :_agc :=_bag ;switch {case _agc .Flags ().Has (_f .FieldFlagCombo ):_egb ,_fgg :=_cedd (form ,wa ,_agc ,_bff .Style ());if _fgg !=nil {return nil ,_fgg ;};return _egb ,nil ;default:_c .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",_agc .Flags ().String ());
};default:_c .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",_bag );};return nil ,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 *_f .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_f .PdfColorDeviceRGB ;Opacity float64 ;};
// Style returns the appearance style of `fa`. If not specified, returns default style.
func (_cbd FieldAppearance )Style ()AppearanceStyle {if _cbd ._bb !=nil {return *_cbd ._bb ;};_age :=_cb ;return AppearanceStyle {AutoFontSizeFraction :0.65,CheckmarkRune :'✔',BorderSize :0.0,BorderColor :_f .NewPdfColorDeviceGray (0),FillColor :_f .NewPdfColorDeviceGray (1),MultilineLineHeight :1.2,MultilineVAlignMiddle :false ,DrawAlignmentReticle :false ,AllowMK :true ,MarginLeft :&_age };
};func _cedd (_cdf *_f .PdfAcroForm ,_cgff *_f .PdfAnnotationWidget ,_agce *_f .PdfFieldChoice ,_bfab AppearanceStyle )(*_bf .PdfObjectDictionary ,error ){_edc ,_gbcd :=_bf .GetArray (_cgff .Rect );if !_gbcd {return nil ,_e .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");
};_ebc ,_afb :=_f .NewPdfRectangle (*_edc );if _afb !=nil {return nil ,_afb ;};_dga ,_egdd :=_ebc .Width (),_ebc .Height ();_c .Log .Debug ("\u0043\u0068\u006f\u0069\u0063\u0065\u002c\u0020\u0077\u0061\u0020\u0042S\u003a\u0020\u0025\u0076",_cgff .BS );
_fcb ,_afb :=_cg .NewContentStreamParser (_cde (_agce .PdfField )).Parse ();if _afb !=nil {return nil ,_afb ;};_cbef ,_gcg :=_bf .GetDict (_cgff .MK );if _gcg {_egbc ,_ :=_bf .GetDict (_cgff .BS );_aga :=_bfab .applyAppearanceCharacteristics (_cbef ,_egbc ,nil );
if _aga !=nil {return nil ,_aga ;};};_gfe :=_bf .MakeDict ();for _ ,_dgga :=range _agce .Opt .Elements (){if _adff ,_cfbc :=_bf .GetArray (_dgga );_cfbc &&_adff .Len ()==2{_dgga =_adff .Get (1);};var _faf string ;if _ebda ,_dbeb :=_bf .GetString (_dgga );
_dbeb {_faf =_ebda .Decoded ();}else if _cgb ,_efb :=_bf .GetName (_dgga );_efb {_faf =_cgb .String ();}else {_c .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",_dgga );
return nil ,_e .New ("\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u002f\u0073t\u0072\u0069\u006e\u0067");};if len (_faf )> 0{_beeg ,_gee :=_adfb (_agce .PdfField ,_dga ,_egdd ,_faf ,_bfab ,_fcb ,_cdf .DR ,_cbef );if _gee !=nil {return nil ,_gee ;
};_gfe .Set (*_bf .MakeName (_faf ),_beeg .ToPdfObject ());};};_bfb :=_bf .MakeDict ();_bfb .Set ("\u004e",_gfe );return _bfb ,nil ;};
// CreateRectangleAnnotation creates a rectangle annotation object that can be added to page PDF annotations.
func CreateRectangleAnnotation (rectDef RectangleAnnotationDef )(*_f .PdfAnnotation ,error ){_bbec :=_f .NewPdfAnnotationSquare ();if rectDef .BorderEnabled {_fdead ,_fag ,_afdb :=rectDef .BorderColor .R (),rectDef .BorderColor .G (),rectDef .BorderColor .B ();
_bbec .C =_bf .MakeArrayFromFloats ([]float64 {_fdead ,_fag ,_afdb });_ecbc :=_f .NewBorderStyle ();_ecbc .SetBorderWidth (rectDef .BorderWidth );_bbec .BS =_ecbc .ToPdfObject ();};if rectDef .FillEnabled {_afbd ,_cgfe ,_fee :=rectDef .FillColor .R (),rectDef .FillColor .G (),rectDef .FillColor .B ();
_bbec .IC =_bf .MakeArrayFromFloats ([]float64 {_afbd ,_cgfe ,_fee });}else {_bbec .IC =_bf .MakeArrayFromIntegers ([]int {});};if rectDef .Opacity < 1.0{_bbec .CA =_bf .MakeFloat (rectDef .Opacity );};_cgaf ,_gcd ,_gdcg :=_dbgd (rectDef );if _gdcg !=nil {return nil ,_gdcg ;
};_bbec .AP =_cgaf ;_bbec .Rect =_bf .MakeArrayFromFloats ([]float64 {_gcd .Llx ,_gcd .Lly ,_gcd .Urx ,_gcd .Ury });return _bbec .PdfAnnotation ,nil ;};func _adfb (_adga *_f .PdfField ,_ebfd ,_dabf float64 ,_bfg string ,_aeae AppearanceStyle ,_afd *_cg .ContentStreamOperations ,_adfbd *_f .PdfPageResources ,_ebfg *_bf .PdfObjectDictionary )(*_f .XObjectForm ,error ){_bcbg :=_f .NewPdfPageResources ();
_bbf ,_aae :=_ebfd ,_dabf ;_cea :=_cg .NewContentCreator ();if _aeae .BorderSize > 0{_gab (_cea ,_aeae ,_ebfd ,_dabf );};if _aeae .DrawAlignmentReticle {_edgb :=_aeae ;_edgb .BorderSize =0.2;_adfa (_cea ,_edgb ,_ebfd ,_dabf );};_cea .Add_BMC ("\u0054\u0078");
_cea .Add_q ();_cea .Add_BT ();_ebfd ,_dabf =_aeae .applyRotation (_ebfg ,_ebfd ,_dabf ,_cea );_dcd ,_dggd ,_fcg :=_aeae .processDA (_adga ,_afd ,_adfbd ,_bcbg ,_cea );if _fcg !=nil {return nil ,_fcg ;};_cgc :=_dcd .Font ;_fce :=_dcd .Size ;_bdge :=_bf .MakeName (_dcd .Name );
_aabf :=_fce ==0;if _aabf &&_dggd {_fce =_dabf *_aeae .AutoFontSizeFraction ;};_gbda :=_cgc .Encoder ();if _gbda ==nil {_c .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");
_gbda =_b .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};if len (_bfg )==0{return nil ,nil ;};_acge :=_cb ;if _aeae .MarginLeft !=nil {_acge =*_aeae .MarginLeft ;};_aba :=0.0;if _gbda !=nil {for _ ,_ccae :=range _bfg {_agcg ,_edga :=_cgc .GetRuneMetrics (_ccae );
if !_edga {_c .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",_ccae );
continue ;};_aba +=_agcg .Wx ;};_bfg =string (_gbda .Encode (_bfg ));};if _fce ==0||_aabf &&_aba > 0&&_acge +_aba *_fce /1000.0> _ebfd {_fce =0.95*1000.0*(_ebfd -_acge )/_aba ;};_beb :=1.0*_fce ;_dae :=2.0;{_bbd :=_beb ;if _aabf &&_dae +_bbd > _dabf {_fce =0.95*(_dabf -_dae );
_beb =1.0*_fce ;_bbd =_beb ;};if _dabf > _bbd {_dae =(_dabf -_bbd )/2.0;_dae +=1.50;};};_cea .Add_Tf (*_bdge ,_fce );_cea .Add_Td (_acge ,_dae );_cea .Add_Tj (*_bf .MakeString (_bfg ));_cea .Add_ET ();_cea .Add_Q ();_cea .Add_EMC ();_decb :=_f .NewXObjectForm ();
_decb .Resources =_bcbg ;_decb .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_bbf ,_aae });_decb .SetContentStream (_cea .Bytes (),_bffe ());return _decb ,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 ;};
// SetStyle applies appearance `style` to `fa`.
func (_gc *FieldAppearance )SetStyle (style AppearanceStyle ){_gc ._bb =&style };func _cbc (_aaeegc LineAnnotationDef )(*_bf .PdfObjectDictionary ,*_f .PdfRectangle ,error ){_abgc :=_f .NewXObjectForm ();_abgc .Resources =_f .NewPdfPageResources ();_gbfg :="";
if _aaeegc .Opacity < 1.0{_eged :=_bf .MakeDict ();_eged .Set ("\u0063\u0061",_bf .MakeFloat (_aaeegc .Opacity ));_gbac :=_abgc .Resources .AddExtGState ("\u0067\u0073\u0031",_eged );if _gbac !=nil {_c .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 ,_gbac ;};_gbfg ="\u0067\u0073\u0031";};_adbcc ,_cfec ,_fcef ,_bfef :=_bfcb (_aaeegc ,_gbfg );if _bfef !=nil {return nil ,nil ,_bfef ;};_bfef =_abgc .SetContentStream (_adbcc ,nil );if _bfef !=nil {return nil ,nil ,_bfef ;};_abgc .BBox =_cfec .ToPdfObject ();
_aaf :=_bf .MakeDict ();_aaf .Set ("\u004e",_abgc .ToPdfObject ());return _aaf ,_fcef ,nil ;};
// CreateLineAnnotation creates a line annotation object that can be added to page PDF annotations.
func CreateLineAnnotation (lineDef LineAnnotationDef )(*_f .PdfAnnotation ,error ){_ccab :=_f .NewPdfAnnotationLine ();_ccab .L =_bf .MakeArrayFromFloats ([]float64 {lineDef .X1 ,lineDef .Y1 ,lineDef .X2 ,lineDef .Y2 });_gceb :=_bf .MakeName ("\u004e\u006f\u006e\u0065");
if lineDef .LineEndingStyle1 ==_ga .LineEndingStyleArrow {_gceb =_bf .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");};_fdbf :=_bf .MakeName ("\u004e\u006f\u006e\u0065");if lineDef .LineEndingStyle2 ==_ga .LineEndingStyleArrow {_fdbf =_bf .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");
};_ccab .LE =_bf .MakeArray (_gceb ,_fdbf );if lineDef .Opacity < 1.0{_ccab .CA =_bf .MakeFloat (lineDef .Opacity );};_bbbc ,_eafe ,_dfed :=lineDef .LineColor .R (),lineDef .LineColor .G (),lineDef .LineColor .B ();_ccab .IC =_bf .MakeArrayFromFloats ([]float64 {_bbbc ,_eafe ,_dfed });
_ccab .C =_bf .MakeArrayFromFloats ([]float64 {_bbbc ,_eafe ,_dfed });_egef :=_f .NewBorderStyle ();_egef .SetBorderWidth (lineDef .LineWidth );_ccab .BS =_egef .ToPdfObject ();_eacc ,_gdce ,_ecfe :=_cbc (lineDef );if _ecfe !=nil {return nil ,_ecfe ;};
_ccab .AP =_eacc ;_ccab .Rect =_bf .MakeArrayFromFloats ([]float64 {_gdce .Llx ,_gdce .Lly ,_gdce .Urx ,_gdce .Ury });return _ccab .PdfAnnotation ,nil ;};func _ace (_agca _bd .Image ,_gddg string ,_eab *SignatureFieldOpts ,_cfga []float64 ,_dgfb *_cg .ContentCreator )(*_bf .PdfObjectName ,*_f .XObjectImage ,error ){_gfgf ,_babd :=_f .DefaultImageHandler {}.NewImageFromGoImage (_agca );
if _babd !=nil {return nil ,nil ,_babd ;};_aegd ,_babd :=_f .NewXObjectImageFromImage (_gfgf ,nil ,_eab .Encoder );if _babd !=nil {return nil ,nil ,_babd ;};_ddbf ,_gfdd :=float64 (*_aegd .Width ),float64 (*_aegd .Height );_add :=_cfga [2]-_cfga [0];_dddf :=_cfga [3]-_cfga [1];
if _eab .AutoSize {_eaaa :=_g .Min (_add /_ddbf ,_dddf /_gfdd );_ddbf *=_eaaa ;_gfdd *=_eaaa ;_cfga [0]=_cfga [0]+(_add /2)-(_ddbf /2);_cfga [1]=_cfga [1]+(_dddf /2)-(_gfdd /2);};var _dbb *_bf .PdfObjectName ;if _gaef ,_cge :=_bf .GetName (_aegd .Name );
_cge {_dbb =_gaef ;}else {_dbb =_bf .MakeName (_gddg );};if _dgfb !=nil {_dgfb .Add_q ().Translate (_cfga [0],_cfga [1]).Scale (_ddbf ,_gfdd ).Add_Do (*_dbb ).Add_Q ();}else {return nil ,nil ,_e .New ("\u0043\u006f\u006e\u0074en\u0074\u0043\u0072\u0065\u0061\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u0075l\u006c");
};return _dbb ,_aegd ,nil ;};
// SetStyle applies appearance `style` to `fa`.
func (_gaae *ImageFieldAppearance )SetStyle (style AppearanceStyle ){_gaae ._deb =&style };func _dede (_bcbc *InkAnnotationDef )(*_bf .PdfObjectDictionary ,*_f .PdfRectangle ,error ){_abae :=_f .NewXObjectForm ();_ega ,_bcbgf ,_efe :=_acbf (_bcbc );if _efe !=nil {return nil ,nil ,_efe ;
};_efe =_abae .SetContentStream (_ega ,nil );if _efe !=nil {return nil ,nil ,_efe ;};_abae .BBox =_bcbgf .ToPdfObject ();_abae .Resources =_f .NewPdfPageResources ();_abae .Resources .ProcSet =_bf .MakeArray (_bf .MakeName ("\u0050\u0044\u0046"));_fdf :=_bf .MakeDict ();
_fdf .Set ("\u004e",_abae .ToPdfObject ());return _fdf ,_bcbgf ,nil ;};const (SignatureImageLeft SignatureImagePosition =iota ;SignatureImageRight ;SignatureImageTop ;SignatureImageBottom ;);
// 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 *_f .PdfPage ,name string ,rect []float64 ,opt CheckboxFieldOptions )(*_f .PdfFieldButton ,error ){if page ==nil {return nil ,_e .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
};if len (name )<=0{return nil ,_e .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 ,_e .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
};_bcdf ,_fafc :=_f .NewStandard14Font (_f .ZapfDingbatsName );if _fafc !=nil {return nil ,_fafc ;};_dee :=_f .NewPdfField ();_defb :=&_f .PdfFieldButton {};_dee .SetContext (_defb );_defb .PdfField =_dee ;_defb .T =_bf .MakeString (name );_defb .SetType (_f .ButtonTypeCheckbox );
_cgd :="\u004f\u0066\u0066";if opt .Checked {_cgd ="\u0059\u0065\u0073";};_defb .V =_bf .MakeName (_cgd );_fgfdd :=_f .NewPdfAnnotationWidget ();_fgfdd .Rect =_bf .MakeArrayFromFloats (rect );_fgfdd .P =page .ToPdfObject ();_fgfdd .F =_bf .MakeInteger (4);
_fgfdd .Parent =_defb .ToPdfObject ();_gcgd :=rect [2]-rect [0];_eddf :=rect [3]-rect [1];var _fbgf _ca .Buffer ;_fbgf .WriteString ("\u0071\u000a");_fbgf .WriteString ("\u0030 \u0030\u0020\u0031\u0020\u0072\u0067\n");_fbgf .WriteString ("\u0042\u0054\u000a");
_fbgf .WriteString ("\u002f\u005a\u0061D\u0062\u0020\u0031\u0032\u0020\u0054\u0066\u000a");_fbgf .WriteString ("\u0045\u0054\u000a");_fbgf .WriteString ("\u0051\u000a");_agbf :=_cg .NewContentCreator ();_agbf .Add_q ();_agbf .Add_rg (0,0,1);_agbf .Add_BT ();
_agbf .Add_Tf (*_bf .MakeName ("\u005a\u0061\u0044\u0062"),12);_agbf .Add_Td (0,0);_agbf .Add_ET ();_agbf .Add_Q ();_bfga :=_f .NewXObjectForm ();_bfga .SetContentStream (_agbf .Bytes (),_bf .NewRawEncoder ());_bfga .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_gcgd ,_eddf });
_bfga .Resources =_f .NewPdfPageResources ();_bfga .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_bcdf .ToPdfObject ());_agbf =_cg .NewContentCreator ();_agbf .Add_q ();_agbf .Add_re (0,0,_gcgd ,_eddf );_agbf .Add_W ().Add_n ();_agbf .Add_rg (0,0,1);
_agbf .Translate (0,3.0);_agbf .Add_BT ();_agbf .Add_Tf (*_bf .MakeName ("\u005a\u0061\u0044\u0062"),12);_agbf .Add_Td (0,0);_agbf .Add_Tj (*_bf .MakeString ("\u0034"));_agbf .Add_ET ();_agbf .Add_Q ();_bfdg :=_f .NewXObjectForm ();_bfdg .SetContentStream (_agbf .Bytes (),_bf .NewRawEncoder ());
_bfdg .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_gcgd ,_eddf });_bfdg .Resources =_f .NewPdfPageResources ();_bfdg .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_bcdf .ToPdfObject ());_dcg :=_bf .MakeDict ();_dcg .Set ("\u004f\u0066\u0066",_bfga .ToPdfObject ());
_dcg .Set ("\u0059\u0065\u0073",_bfdg .ToPdfObject ());_dgdb :=_bf .MakeDict ();_dgdb .Set ("\u004e",_dcg );_fgfdd .AP =_dgdb ;_fgfdd .AS =_bf .MakeName (_cgd );_defb .Annotations =append (_defb .Annotations ,_fgfdd );return _defb ,nil ;};func _gab (_ead *_cg .ContentCreator ,_ade AppearanceStyle ,_fcbg ,_ada float64 ){_ead .Add_q ().Add_re (0,0,_fcbg ,_ada ).Add_w (_ade .BorderSize ).SetStrokingColor (_ade .BorderColor ).SetNonStrokingColor (_ade .FillColor ).Add_B ().Add_Q ();
};
// 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 *_f .PdfPage ,name string ,rect []float64 ,opt ComboboxFieldOptions )(*_f .PdfFieldChoice ,error ){if page ==nil {return nil ,_e .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
};if len (name )<=0{return nil ,_e .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 ,_e .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
};_fbbg :=_f .NewPdfField ();_bbgf :=&_f .PdfFieldChoice {};_fbbg .SetContext (_bbgf );_bbgf .PdfField =_fbbg ;_bbgf .T =_bf .MakeString (name );_bbgf .Opt =_bf .MakeArray ();for _ ,_ecee :=range opt .Choices {_bbgf .Opt .Append (_bf .MakeString (_ecee ));
};_bbgf .SetFlag (_f .FieldFlagCombo );_gff :=_f .NewPdfAnnotationWidget ();_gff .Rect =_bf .MakeArrayFromFloats (rect );_gff .P =page .ToPdfObject ();_gff .F =_bf .MakeInteger (4);_gff .Parent =_bbgf .ToPdfObject ();_bbgf .Annotations =append (_bbgf .Annotations ,_gff );
return _bbgf ,nil ;};func _cde (_daed *_f .PdfField )string {if _daed ==nil {return "";};_ecg ,_aaca :=_daed .GetContext ().(*_f .PdfFieldText );if !_aaca {return _cde (_daed .Parent );};if _ecg .DA !=nil {return _ecg .DA .Str ();};return _cde (_ecg .Parent );
};func _gcee (_ceaa []*SignatureLine ,_ddcb *SignatureFieldOpts )(*_bf .PdfObjectDictionary ,error ){if _ddcb ==nil {_ddcb =NewSignatureFieldOpts ();};var _affa error ;var _ege *_bf .PdfObjectName ;_gdd :=_ddcb .Font ;if _gdd !=nil {_acf ,_ :=_gdd .GetFontDescriptor ();
if _acf !=nil {if _cfa ,_ffb :=_acf .FontName .(*_bf .PdfObjectName );_ffb {_ege =_cfa ;};};if _ege ==nil {_ege =_bf .MakeName ("\u0046\u006f\u006et\u0031");};}else {if _gdd ,_affa =_f .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");
_affa !=nil {return nil ,_affa ;};_ege =_bf .MakeName ("\u0048\u0065\u006c\u0076");};_edcf :=_ddcb .FontSize ;if _edcf <=0{_edcf =10;};if _ddcb .LineHeight <=0{_ddcb .LineHeight =1;};_edd :=_ddcb .LineHeight *_edcf ;_acdf ,_gdef :=_gdd .GetRuneMetrics (' ');
if !_gdef {return nil ,_e .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");};_aggf :=_acdf .Wx ;var _fgcb float64 ;var _aca []string ;
for _ ,_adac :=range _ceaa {if _adac .Text ==""{continue ;};_adfba :=_adac .Text ;if _adac .Desc !=""{_adfba =_adac .Desc +"\u003a\u0020"+_adfba ;};_aca =append (_aca ,_adfba );var _eeec float64 ;for _ ,_afg :=range _adfba {_aaba ,_agfgd :=_gdd .GetRuneMetrics (_afg );
if !_agfgd {continue ;};_eeec +=_aaba .Wx ;};if _eeec > _fgcb {_fgcb =_eeec ;};};_fgcb =_fgcb *_edcf /1000.0;_dgdf :=float64 (len (_aca ))*_edd ;_acfc :=_ddcb .Image !=nil ;_abge :=_ddcb .Rect ;if _abge ==nil {_abge =[]float64 {0,0,_fgcb ,_dgdf };if _acfc {_abge [2]=_fgcb *2;
_abge [3]=_dgdf *2;};_ddcb .Rect =_abge ;};_bafa :=_abge [2]-_abge [0];_egddd :=_abge [3]-_abge [1];_fef ,_dge :=_abge ,_abge ;var _bfbb ,_eddc float64 ;if _acfc &&len (_aca )> 0{if _ddcb .ImagePosition <=SignatureImageRight {_acbd :=[]float64 {_abge [0],_abge [1],_abge [0]+(_bafa /2),_abge [3]};
_afac :=[]float64 {_abge [0]+(_bafa /2),_abge [1],_abge [2],_abge [3]};if _ddcb .ImagePosition ==SignatureImageLeft {_fef ,_dge =_acbd ,_afac ;}else {_fef ,_dge =_afac ,_acbd ;};}else {_fdbb :=[]float64 {_abge [0],_abge [1],_abge [2],_abge [1]+(_egddd /2)};
_acdc :=[]float64 {_abge [0],_abge [1]+(_egddd /2),_abge [2],_abge [3]};if _ddcb .ImagePosition ==SignatureImageTop {_fef ,_dge =_acdc ,_fdbb ;}else {_fef ,_dge =_fdbb ,_acdc ;};};};_bfbb =_dge [2]-_dge [0];_eddc =_dge [3]-_dge [1];var _gfbf float64 ;if _ddcb .AutoSize {if _fgcb > _bfbb ||_dgdf > _eddc {_gagg :=_g .Min (_bfbb /_fgcb ,_eddc /_dgdf );
_edcf *=_gagg ;};_edd =_ddcb .LineHeight *_edcf ;_gfbf +=(_eddc -float64 (len (_aca ))*_edd )/2;};_gebd :=_cg .NewContentCreator ();_fcba :=_f .NewPdfPageResources ();_fcba .SetFontByName (*_ege ,_gdd .ToPdfObject ());if _ddcb .BorderSize <=0{_ddcb .BorderSize =0;
_ddcb .BorderColor =_f .NewPdfColorDeviceGray (1);};_gebd .Add_q ();if _ddcb .FillColor !=nil {_gebd .SetNonStrokingColor (_ddcb .FillColor );};if _ddcb .BorderColor !=nil {_gebd .SetStrokingColor (_ddcb .BorderColor );};_gebd .Add_w (_ddcb .BorderSize ).Add_re (_abge [0],_abge [1],_bafa ,_egddd );
if _ddcb .FillColor !=nil &&_ddcb .BorderColor !=nil {_gebd .Add_B ();}else if _ddcb .FillColor !=nil {_gebd .Add_f ();}else if _ddcb .BorderColor !=nil {_gebd .Add_S ();};_gebd .Add_Q ();if _ddcb .WatermarkImage !=nil {_edb :=[]float64 {_abge [0],_abge [1],_abge [2],_abge [3]};
_fba ,_aggc ,_ddg :=_ace (_ddcb .WatermarkImage ,"\u0049\u006d\u0061\u0067\u0065\u0057\u0061\u0074\u0065r\u006d\u0061\u0072\u006b",_ddcb ,_edb ,_gebd );if _ddg !=nil {return nil ,_ddg ;};_fcba .SetXObjectImageByName (*_fba ,_aggc );};_gebd .Add_q ();_gebd .Translate (_dge [0],_dge [3]-_edd -_gfbf );
_gebd .Add_BT ();_bge :=_gdd .Encoder ();for _ ,_bbeg :=range _aca {var _fdd []byte ;for _ ,_efbe :=range _bbeg {if _be .IsSpace (_efbe ){if len (_fdd )> 0{_gebd .SetNonStrokingColor (_ddcb .TextColor ).Add_Tf (*_ege ,_edcf ).Add_TL (_edd ).Add_TJ ([]_bf .PdfObject {_bf .MakeStringFromBytes (_fdd )}...);
_fdd =nil ;};_gebd .Add_Tf (*_ege ,_edcf ).Add_TL (_edd ).Add_TJ ([]_bf .PdfObject {_bf .MakeFloat (-_aggf )}...);}else {_fdd =append (_fdd ,_bge .Encode (string (_efbe ))...);};};if len (_fdd )> 0{_gebd .SetNonStrokingColor (_ddcb .TextColor ).Add_Tf (*_ege ,_edcf ).Add_TL (_edd ).Add_TJ ([]_bf .PdfObject {_bf .MakeStringFromBytes (_fdd )}...);
};_gebd .Add_Td (0,-_edd );};_gebd .Add_ET ();_gebd .Add_Q ();if _acfc {_fdg ,_ecc ,_cfeg :=_ace (_ddcb .Image ,"\u0049\u006d\u0061\u0067\u0065\u0053\u0069\u0067\u006ea\u0074\u0075\u0072\u0065",_ddcb ,_fef ,_gebd );if _cfeg !=nil {return nil ,_cfeg ;};
_fcba .SetXObjectImageByName (*_fdg ,_ecc );};_fge :=_f .NewXObjectForm ();_fge .Resources =_fcba ;_fge .BBox =_bf .MakeArrayFromFloats (_abge );_fge .SetContentStream (_gebd .Bytes (),_bffe ());_aaa :=_bf .MakeDict ();_aaa .Set ("\u004e",_fge .ToPdfObject ());
return _aaa ,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 _f .PdfColor ;FillColor _f .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 ;};
// 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 (_abga FieldAppearance )WrapContentStream (page *_f .PdfPage )error {_ebac ,_feb :=page .GetAllContentStreams ();if _feb !=nil {return _feb ;};_afec :=_cg .NewContentStreamParser (_ebac );_adfe ,_feb :=_afec .Parse ();if _feb !=nil {return _feb ;};
_adfe .WrapIfNeeded ();_gbf :=[]string {_adfe .String ()};return page .SetContentStreams (_gbf ,_bffe ());};func _cfff (_gfgb [][]_ga .CubicBezierCurve ,_daa *_f .PdfColorDeviceRGB ,_gaab float64 )([]byte ,*_f .PdfRectangle ,error ){_babc :=_cg .NewContentCreator ();
_babc .Add_q ().SetStrokingColor (_daa ).Add_w (_gaab );_fea :=_ga .NewCubicBezierPath ();for _ ,_ffe :=range _gfgb {_fea .Curves =append (_fea .Curves ,_ffe ...);for _gbcdf ,_dcbc :=range _ffe {if _gbcdf ==0{_babc .Add_m (_dcbc .P0 .X ,_dcbc .P0 .Y );
}else {_babc .Add_l (_dcbc .P0 .X ,_dcbc .P0 .Y );};_babc .Add_c (_dcbc .P1 .X ,_dcbc .P1 .Y ,_dcbc .P2 .X ,_dcbc .P2 .Y ,_dcbc .P3 .X ,_dcbc .P3 .Y );};};_babc .Add_S ().Add_Q ();return _babc .Bytes (),_fea .GetBoundingBox ().ToPdfRectangle (),nil ;};
func (_bba *AppearanceFont )fillName (){if _bba .Font ==nil ||_bba .Name !=""{return ;};_ag :=_bba .Font .FontDescriptor ();if _ag ==nil ||_ag .FontName ==nil {return ;};_bba .Name =_ag .FontName .String ();};func _cgbd (_aced *_f .PdfFieldButton ,_abea *_f .PdfAnnotationWidget ,_feca AppearanceStyle )(*_bf .PdfObjectDictionary ,error ){_aaab ,_efac :=_bf .GetArray (_abea .Rect );
if !_efac {return nil ,_e .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_adeg ,_gdgd :=_f .NewPdfRectangle (*_aaab );if _gdgd !=nil {return nil ,_gdgd ;};_edf ,_bfdf :=_adeg .Width (),_adeg .Height ();_aged :=_cg .NewContentCreator ();
if _feca .BorderSize > 0{_gab (_aged ,_feca ,_edf ,_bfdf );};if _feca .DrawAlignmentReticle {_dbf :=_feca ;_dbf .BorderSize =0.2;_adfa (_aged ,_dbf ,_edf ,_bfdf );};_fca :=_aced .GetFillImage ();_bafag ,_gdgd :=_edfg (_edf ,_bfdf ,_fca ,_feca );if _gdgd !=nil {return nil ,_gdgd ;
};_bbca ,_dedd :=_bf .GetDict (_abea .MK );if _dedd {_bbca .Set ("\u006c",_bafag .ToPdfObject ());};_bebcc :=_bf .MakeDict ();_bebcc .Set ("\u0046\u0052\u004d",_bafag .ToPdfObject ());_fadb :=_f .NewPdfPageResources ();_fadb .ProcSet =_bf .MakeArray (_bf .MakeName ("\u0050\u0044\u0046"));
_fadb .XObject =_bebcc ;_ddede :=_edf -2;_ccg :=_bfdf -2;_aged .Add_q ();_aged .Add_re (1,1,_ddede ,_ccg );_aged .Add_W ();_aged .Add_n ();_ddede -=2;_ccg -=2;_aged .Add_q ();_aged .Add_re (2,2,_ddede ,_ccg );_aged .Add_W ();_aged .Add_n ();_eeaa :=_g .Min (_ddede /float64 (_fca .Width ),_ccg /float64 (_fca .Height ));
_aged .Add_cm (_eeaa ,0,0,_eeaa ,(_edf /2)-(float64 (_fca .Width )*_eeaa /2)+2,2);_aged .Add_Do ("\u0046\u0052\u004d");_aged .Add_Q ();_aged .Add_Q ();_ffag :=_f .NewXObjectForm ();_ffag .FormType =_bf .MakeInteger (1);_ffag .Resources =_fadb ;_ffag .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_edf ,_bfdf });
_ffag .Matrix =_bf .MakeArrayFromFloats ([]float64 {1.0,0.0,0.0,1.0,0.0,0.0});_ffag .SetContentStream (_aged .Bytes (),_bffe ());_eggc :=_bf .MakeDict ();_eggc .Set ("\u004e",_ffag .ToPdfObject ());return _eggc ,nil ;};
// GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`.
// Implements interface model.FieldAppearanceGenerator.
func (_ddgg ImageFieldAppearance )GenerateAppearanceDict (form *_f .PdfAcroForm ,field *_f .PdfField ,wa *_f .PdfAnnotationWidget )(*_bf .PdfObjectDictionary ,error ){_ ,_faff :=field .GetContext ().(*_f .PdfFieldButton );if !_faff {_c .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 ;};_eeag ,_adgaf :=_bf .GetDict (wa .AP );if _adgaf &&_ddgg .OnlyIfMissing {_c .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 _eeag ,nil ;};if form .DR ==nil {form .DR =_f .NewPdfPageResources ();};switch _efdb :=field .GetContext ().(type ){case *_f .PdfFieldButton :if _efdb .IsPush (){_bebe ,_fgfb :=_cgbd (_efdb ,wa ,_ddgg .Style ());if _fgfb !=nil {return nil ,_fgfb ;
};return _bebe ,nil ;};};return nil ,nil ;};func _bfcb (_gec LineAnnotationDef ,_agfb string )([]byte ,*_f .PdfRectangle ,*_f .PdfRectangle ,error ){_eafa :=_ga .Line {X1 :0,Y1 :0,X2 :_gec .X2 -_gec .X1 ,Y2 :_gec .Y2 -_gec .Y1 ,LineColor :_gec .LineColor ,Opacity :_gec .Opacity ,LineWidth :_gec .LineWidth ,LineEndingStyle1 :_gec .LineEndingStyle1 ,LineEndingStyle2 :_gec .LineEndingStyle2 };
_aeef ,_caaea ,_gcegc :=_eafa .Draw (_agfb );if _gcegc !=nil {return nil ,nil ,nil ,_gcegc ;};_gaabg :=&_f .PdfRectangle {};_gaabg .Llx =_gec .X1 +_caaea .Llx ;_gaabg .Lly =_gec .Y1 +_caaea .Lly ;_gaabg .Urx =_gec .X1 +_caaea .Urx ;_gaabg .Ury =_gec .Y1 +_caaea .Ury ;
return _aeef ,_caaea ,_gaabg ,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 (_bfe ImageFieldAppearance )WrapContentStream (page *_f .PdfPage )error {_fbac ,_ccgb :=page .GetAllContentStreams ();if _ccgb !=nil {return _ccgb ;};_ebg :=_cg .NewContentStreamParser (_fbac );_fcab ,_ccgb :=_ebg .Parse ();if _ccgb !=nil {return _ccgb ;
};_fcab .WrapIfNeeded ();_feg :=[]string {_fcab .String ()};return page .SetContentStreams (_feg ,_bffe ());};func _acaga (_fbfe RectangleAnnotationDef ,_ffc string )([]byte ,*_f .PdfRectangle ,*_f .PdfRectangle ,error ){_deba :=_ga .Rectangle {X :0,Y :0,Width :_fbfe .Width ,Height :_fbfe .Height ,FillEnabled :_fbfe .FillEnabled ,FillColor :_fbfe .FillColor ,BorderEnabled :_fbfe .BorderEnabled ,BorderWidth :2*_fbfe .BorderWidth ,BorderColor :_fbfe .BorderColor ,Opacity :_fbfe .Opacity };
_daaa ,_dcag ,_dbcf :=_deba .Draw (_ffc );if _dbcf !=nil {return nil ,nil ,nil ,_dbcf ;};_ebdd :=&_f .PdfRectangle {};_ebdd .Llx =_fbfe .X +_dcag .Llx ;_ebdd .Lly =_fbfe .Y +_dcag .Lly ;_ebdd .Urx =_fbfe .X +_dcag .Urx ;_ebdd .Ury =_fbfe .Y +_dcag .Ury ;
return _daaa ,_dcag ,_ebdd ,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 _edfg (_aacf ,_gdgb float64 ,_aed *_f .Image ,_dbbf AppearanceStyle )(*_f .XObjectForm ,error ){_efc ,_fbf :=_f .NewXObjectImageFromImage (_aed ,nil ,_bf .NewFlateEncoder ());if _fbf !=nil {return nil ,_fbf ;};_efc .Decode =_bf .MakeArrayFromFloats ([]float64 {0.0,1.0,0.0,1.0,0.0,1.0});
_fded :=_f .NewPdfPageResources ();_fded .ProcSet =_bf .MakeArray (_bf .MakeName ("\u0050\u0044\u0046"),_bf .MakeName ("\u0049\u006d\u0061\u0067\u0065\u0043"));_fded .SetXObjectImageByName (_bf .PdfObjectName ("\u0049\u006d\u0030"),_efc );_cbba :=_cg .NewContentCreator ();
_cbba .Add_q ();_cbba .Add_cm (float64 (_aed .Width ),0,0,float64 (_aed .Height ),0,0);_cbba .Add_Do ("\u0049\u006d\u0030");_cbba .Add_Q ();_bddc :=_f .NewXObjectForm ();_bddc .FormType =_bf .MakeInteger (1);_bddc .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,float64 (_aed .Width ),float64 (_aed .Height )});
_bddc .Resources =_fded ;_bddc .SetContentStream (_cbba .Bytes (),_bffe ());return _bddc ,nil ;};
// CircleAnnotationDef defines a circle annotation or ellipse at position (X, Y) and Width and Height.
// The annotation has various style parameters including Fill and Border options and Opacity.
type CircleAnnotationDef struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_f .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_f .PdfColorDeviceRGB ;Opacity float64 ;};
// NewSignatureFieldOpts returns a new initialized instance of options
// used to generate a signature appearance.
func NewSignatureFieldOpts ()*SignatureFieldOpts {return &SignatureFieldOpts {Font :_f .DefaultFont (),FontSize :10,LineHeight :1,AutoSize :true ,TextColor :_f .NewPdfColorDeviceGray (0),BorderColor :_f .NewPdfColorDeviceGray (0),FillColor :_f .NewPdfColorDeviceGray (1),Encoder :_bf .NewFlateEncoder (),ImagePosition :SignatureImageLeft };
};
// CreateInkAnnotation creates an ink annotation object that can be added to the annotation list of a PDF page.
func CreateInkAnnotation (inkDef InkAnnotationDef )(*_f .PdfAnnotation ,error ){_bbcg :=_f .NewPdfAnnotationInk ();_gdeb :=_bf .MakeArray ();for _ ,_aec :=range inkDef .Paths {if _aec .Length ()==0{continue ;};_gceg :=[]float64 {};for _ ,_acag :=range _aec .Points {_gceg =append (_gceg ,_acag .X ,_acag .Y );
};_gdeb .Append (_bf .MakeArrayFromFloats (_gceg ));};_bbcg .InkList =_gdeb ;if inkDef .Color ==nil {inkDef .Color =_f .NewPdfColorDeviceRGB (0.0,0.0,0.0);};_bbcg .C =_bf .MakeArrayFromFloats ([]float64 {inkDef .Color .R (),inkDef .Color .G (),inkDef .Color .B ()});
_eebb ,_dbcd ,_dfe :=_dede (&inkDef );if _dfe !=nil {return nil ,_dfe ;};_bbcg .AP =_eebb ;_bbcg .Rect =_bf .MakeArrayFromFloats ([]float64 {_dbcd .Llx ,_dbcd .Lly ,_dbcd .Urx ,_dbcd .Ury });return _bbcg .PdfAnnotation ,nil ;};
// TextFieldOptions defines optional parameter for a text field in a form.
type TextFieldOptions struct{MaxLen int ;Value string ;};func _fd (_gcb *_f .PdfAnnotationWidget ,_bgf *_f .PdfFieldText ,_bbg *_f .PdfPageResources ,_bae AppearanceStyle )(*_bf .PdfObjectDictionary ,error ){_ddc :=_f .NewPdfPageResources ();_deg ,_ea :=_bf .GetArray (_gcb .Rect );
if !_ea {return nil ,_e .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_dac ,_fgc :=_f .NewPdfRectangle (*_deg );if _fgc !=nil {return nil ,_fgc ;};_ceg ,_dc :=_dac .Width (),_dac .Height ();_gd ,_adf :=_ceg ,_dc ;_bde ,_cgf :=_bf .GetDict (_gcb .MK );
if _cgf {_bc ,_ :=_bf .GetDict (_gcb .BS );_cegd :=_bae .applyAppearanceCharacteristics (_bde ,_bc ,nil );if _cegd !=nil {return nil ,_cegd ;};};_bfa ,_fgc :=_cg .NewContentStreamParser (_cde (_bgf .PdfField )).Parse ();if _fgc !=nil {return nil ,_fgc ;
};_dde :=_cg .NewContentCreator ();if _bae .BorderSize > 0{_gab (_dde ,_bae ,_ceg ,_dc );};if _bae .DrawAlignmentReticle {_bbaea :=_bae ;_bbaea .BorderSize =0.2;_adfa (_dde ,_bbaea ,_ceg ,_dc );};_dde .Add_BMC ("\u0054\u0078");_dde .Add_q ();_ceg ,_dc =_bae .applyRotation (_bde ,_ceg ,_dc ,_dde );
_dde .Add_BT ();_dab ,_agf ,_fgc :=_bae .processDA (_bgf .PdfField ,_bfa ,_bbg ,_ddc ,_dde );if _fgc !=nil {return nil ,_fgc ;};_dcc :=_dab .Font ;_ccc :=_dab .Size ;_beda :=_bf .MakeName (_dab .Name );_gcc :=_ccc ==0;if _gcc &&_agf {_ccc =_dc *_bae .AutoFontSizeFraction ;
};_ebf :=_dcc .Encoder ();if _ebf ==nil {_c .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");
_ebf =_b .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};_fc ,_fgc :=_dcc .GetFontDescriptor ();if _fgc !=nil {_c .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 _eed string ;if _eeda ,_bdc :=_bf .GetString (_bgf .V );_bdc {_eed =_eeda .Decoded ();};if len (_eed )==0{return nil ,nil ;};_fb :=[]string {_eed };_adg :=false ;if _bgf .Flags ().Has (_f .FieldFlagMultiline ){_adg =true ;_eed =_ce .Replace (_eed ,"\u000d\u000a","\u000a",-1);
_eed =_ce .Replace (_eed ,"\u000d","\u000a",-1);_fb =_ce .Split (_eed ,"\u000a");};_ed :=make ([]string ,len (_fb ));copy (_ed ,_fb );_agb :=_bae .MultilineLineHeight ;_dad :=0.0;_fcc :=0;if _ebf !=nil {for _ccc >=0{_fbb :=make ([]string ,len (_fb ));copy (_fbb ,_fb );
_egf :=make ([]string ,len (_ed ));copy (_egf ,_ed );_dad =0.0;_fcc =0;_bee :=len (_fbb );_fgf :=0;for _fgf < _bee {var _eea float64 ;_acc :=-1;_dag :=_cb ;if _bae .MarginLeft !=nil {_dag =*_bae .MarginLeft ;};for _dce ,_gfb :=range _fbb [_fgf ]{if _gfb ==' '{_acc =_dce ;
};_cee ,_gb :=_dcc .GetRuneMetrics (_gfb );if !_gb {_c .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",_gfb );
continue ;};_eea =_dag ;_dag +=_cee .Wx ;if _adg &&!_gcc &&_ccc *_dag /1000.0> _ceg {_gfgc :=_dce ;_cbb :=_dce ;if _acc > 0{_gfgc =_acc +1;_cbb =_acc ;};_gfd :=_fbb [_fgf ][_gfgc :];_ebd :=_egf [_fgf ][_gfgc :];if _fgf < len (_fbb )-1{_fbb =append (_fbb [:_fgf +1],_fbb [_fgf :]...);
_fbb [_fgf +1]=_gfd ;_egf =append (_egf [:_fgf +1],_egf [_fgf :]...);_egf [_fgf +1]=_ebd ;}else {_fbb =append (_fbb ,_gfd );_egf =append (_egf ,_ebd );};_fbb [_fgf ]=_fbb [_fgf ][0:_cbb ];_egf [_fgf ]=_egf [_fgf ][0:_cbb ];_bee ++;_dag =_eea ;break ;};
};if _dag > _dad {_dad =_dag ;};_fbb [_fgf ]=string (_ebf .Encode (_fbb [_fgf ]));if len (_fbb [_fgf ])> 0{_fcc ++;};_fgf ++;};_bec :=_ccc ;if _fcc > 1{_bec *=_agb ;};_dgf :=float64 (_fcc )*_bec ;if _gcc ||_dgf <=_dc {_fb =_fbb ;_ed =_egf ;break ;};_ccc --;
};};_ccd :=_cb ;if _bae .MarginLeft !=nil {_ccd =*_bae .MarginLeft ;};if _ccc ==0||_gcc &&_dad > 0&&_ccd +_dad *_ccc /1000.0> _ceg {_ccc =0.95*1000.0*(_ceg -_ccd )/_dad ;};_db :=_bbae ;{if _fgcf ,_cff :=_bf .GetIntVal (_bgf .Q );_cff {switch _fgcf {case 0:_db =_bbae ;
case 1:_db =_aea ;case 2:_db =_acb ;default:_c .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",_fgcf );
};};};_fe :=_ccc ;if _adg &&_fcc > 1{_fe =_agb *_ccc ;};var _bab float64 ;if _fc !=nil {_bab ,_fgc =_fc .GetCapHeight ();if _fgc !=nil {_c .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",_fgc );
};};if int (_bab )<=0{_c .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");
_bab =1000;};_afa :=_bab /1000.0*_ccc ;_cbe :=0.0;{_gce :=float64 (_fcc )*_fe ;if _gcc &&_cbe +_gce > _dc {_ccc =0.95*(_dc -_cbe )/float64 (_fcc );_fe =_ccc ;if _adg &&_fcc > 1{_fe =_agb *_ccc ;};_afa =_bab /1000.0*_ccc ;_gce =float64 (_fcc )*_fe ;};if _dc > _gce {if _adg {if _bae .MultilineVAlignMiddle {_dba :=(_dc -(_gce +_afa ))/2.0;
_ecf :=_dba +_gce +_afa -_fe ;_cbe =_ecf ;if _fcc > 1{_cbe =_cbe +(_gce /_ccc *float64 (_fcc ))-_fe -_afa ;};if _cbe < _gce {_cbe =(_dc -_afa )/2.0;};}else {_cbe =_dc -_fe ;if _cbe > _ccc {_dagg :=0.0;if _adg &&_bae .MultilineLineHeight > 1&&_fcc > 1{_dagg =_bae .MultilineLineHeight -1;
};_cbe -=_ccc *(0.5-_dagg );};};}else {_cbe =(_dc -_afa )/2.0;};};};_dde .Add_Tf (*_beda ,_ccc );_dde .Add_Td (_ccd ,_cbe );_fde :=_ccd ;_gea :=_ccd ;for _cfb ,_cca :=range _fb {_gbc :=0.0;for _ ,_abg :=range _ed [_cfb ]{_gedc ,_edg :=_dcc .GetRuneMetrics (_abg );
if !_edg {continue ;};_gbc +=_gedc .Wx ;};_fgfd :=_gbc /1000.0*_ccc ;_abd :=_ceg -_fgfd ;var _fed float64 ;switch _db {case _bbae :_fed =_fde ;case _aea :_fed =_abd /2;case _acb :_fed =_abd ;};_ccd =_fed -_gea ;if _ccd > 0.0{_dde .Add_Td (_ccd ,0);};_gea =_fed ;
_dde .Add_Tj (*_bf .MakeString (_cca ));if _cfb < len (_fb )-1{_dde .Add_Td (0,-_ccc *_agb );};};_dde .Add_ET ();_dde .Add_Q ();_dde .Add_EMC ();_dbe :=_f .NewXObjectForm ();_dbe .Resources =_ddc ;_dbe .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_gd ,_adf });
_dbe .SetContentStream (_dde .Bytes (),_bffe ());_eac :=_bf .MakeDict ();_eac .Set ("\u004e",_dbe .ToPdfObject ());return _eac ,nil ;};func _ecddd (_bdb []float64 )[]float64 {var (_cbac =len (_bdb );_adag =make ([]float64 ,_cbac );_afgc =make ([]float64 ,_cbac );
);_aaeeg :=2.0;_adag [0]=_bdb [0]/_aaeeg ;for _acfe :=1;_acfe < _cbac ;_acfe ++{_afgc [_acfe ]=1/_aaeeg ;if _acfe < _cbac -1{_aaeeg =4.0;}else {_aaeeg =3.5;};_aaeeg -=_afgc [_acfe ];_adag [_acfe ]=(_bdb [_acfe ]-_adag [_acfe -1])/_aaeeg ;};for _gdcd :=1;
_gdcd < _cbac ;_gdcd ++{_adag [_cbac -_gdcd -1]-=_afgc [_cbac -_gdcd ]*_adag [_cbac -_gdcd ];};return _adag ;};
// CreateCircleAnnotation creates a circle/ellipse annotation object with appearance stream that can be added to
// page PDF annotations.
func CreateCircleAnnotation (circDef CircleAnnotationDef )(*_f .PdfAnnotation ,error ){_fa :=_f .NewPdfAnnotationCircle ();if circDef .BorderEnabled {_da ,_cad ,_gaf :=circDef .BorderColor .R (),circDef .BorderColor .G (),circDef .BorderColor .B ();_fa .C =_bf .MakeArrayFromFloats ([]float64 {_da ,_cad ,_gaf });
_df :=_f .NewBorderStyle ();_df .SetBorderWidth (circDef .BorderWidth );_fa .BS =_df .ToPdfObject ();};if circDef .FillEnabled {_a ,_eb ,_dg :=circDef .FillColor .R (),circDef .FillColor .G (),circDef .FillColor .B ();_fa .IC =_bf .MakeArrayFromFloats ([]float64 {_a ,_eb ,_dg });
}else {_fa .IC =_bf .MakeArrayFromIntegers ([]int {});};if circDef .Opacity < 1.0{_fa .CA =_bf .MakeFloat (circDef .Opacity );};_ac ,_cf ,_ee :=_dd (circDef );if _ee !=nil {return nil ,_ee ;};_fa .AP =_ac ;_fa .Rect =_bf .MakeArrayFromFloats ([]float64 {_cf .Llx ,_cf .Lly ,_cf .Urx ,_cf .Ury });
return _fa .PdfAnnotation ,nil ;};
// ImageFieldAppearance implements interface model.FieldAppearanceGenerator and generates appearance streams
// for attaching an image to a button field.
type ImageFieldAppearance struct{OnlyIfMissing bool ;_deb *AppearanceStyle ;};
// 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 *_f .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 _ga .LineEndingStyle ;LineEndingStyle2 _ga .LineEndingStyle ;};func (_bfaee *AppearanceStyle )applyRotation (_efd *_bf .PdfObjectDictionary ,_gdc ,_bcc float64 ,_cga *_cg .ContentCreator )(float64 ,float64 ){if !_bfaee .AllowMK {return _gdc ,_bcc ;
};if _efd ==nil {return _gdc ,_bcc ;};_ebff ,_ :=_bf .GetNumberAsFloat (_efd .Get ("\u0052"));if _ebff ==0{return _gdc ,_bcc ;};_fec :=-_ebff ;_gedf :=_ga .Path {Points :[]_ga .Point {_ga .NewPoint (0,0).Rotate (_fec ),_ga .NewPoint (_gdc ,0).Rotate (_fec ),_ga .NewPoint (0,_bcc ).Rotate (_fec ),_ga .NewPoint (_gdc ,_bcc ).Rotate (_fec )}}.GetBoundingBox ();
_cga .RotateDeg (_ebff );_cga .Translate (_gedf .X ,_gedf .Y );return _gedf .Width ,_gedf .Height ;};
// 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 (_baf *AppearanceStyle )processDA (_ffge *_f .PdfField ,_dcdd *_cg .ContentStreamOperations ,_bgfb ,_dfg *_f .PdfPageResources ,_ddeg *_cg .ContentCreator )(*AppearanceFont ,bool ,error ){var _ggc *AppearanceFont ;
var _efdf bool ;if _baf .Fonts !=nil {if _baf .Fonts .Fallback !=nil {_ggc =_baf .Fonts .Fallback ;};if _eadd :=_baf .Fonts .FieldFallbacks ;_eadd !=nil {if _fcd ,_faa :=_eadd [_ffge .PartialName ()];_faa {_ggc =_fcd ;}else if _gde ,_fdea :=_ffge .FullName ();
_fdea ==nil {if _egg ,_eca :=_eadd [_gde ];_eca {_ggc =_egg ;};};};if _ggc !=nil {_ggc .fillName ();};_efdf =_baf .Fonts .ForceReplace ;};var _ddb string ;var _gbe float64 ;var _gcf bool ;if _dcdd !=nil {for _ ,_dded :=range *_dcdd {if _dded .Operand =="\u0054\u0066"&&len (_dded .Params )==2{if _accg ,_cbga :=_bf .GetNameVal (_dded .Params [0]);
_cbga {_ddb =_accg ;};if _ded ,_dbaa :=_bf .GetNumberAsFloat (_dded .Params [1]);_dbaa ==nil {_gbe =_ded ;};_gcf =true ;continue ;};_ddeg .AddOperand (*_dded );};};var _adb *AppearanceFont ;var _gdg _bf .PdfObject ;if _efdf &&_ggc !=nil {_adb =_ggc ;}else {if _bgfb !=nil &&_ddb !=""{if _egc ,_caae :=_bgfb .GetFontByName (*_bf .MakeName (_ddb ));
_caae {if _aegf ,_dfab :=_f .NewPdfFontFromPdfObject (_egc );_dfab ==nil {_gdg =_egc ;_adb =&AppearanceFont {Name :_ddb ,Font :_aegf ,Size :_gbe };}else {_c .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",_dfab );
};};};if _adb ==nil &&_ggc !=nil {_adb =_ggc ;};if _adb ==nil {_cada ,_fceb :=_f .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");if _fceb !=nil {return nil ,false ,_fceb ;};_adb =&AppearanceFont {Name :"\u0048\u0065\u006c\u0076",Font :_cada ,Size :_gbe };
};};if _adb .Size <=0&&_baf .Fonts !=nil &&_baf .Fonts .FallbackSize > 0{_adb .Size =_baf .Fonts .FallbackSize ;};_fbgd :=*_bf .MakeName (_adb .Name );if _gdg ==nil {_gdg =_adb .Font .ToPdfObject ();};if _bgfb !=nil &&!_bgfb .HasFontByName (_fbgd ){_bgfb .SetFontByName (_fbgd ,_gdg );
};if _dfg !=nil &&!_dfg .HasFontByName (_fbgd ){_dfg .SetFontByName (_fbgd ,_gdg );};return _adb ,_gcf ,nil ;};
// Style returns the appearance style of `fa`. If not specified, returns default style.
func (_fcgd ImageFieldAppearance )Style ()AppearanceStyle {if _fcgd ._deb !=nil {return *_fcgd ._deb ;};return AppearanceStyle {BorderSize :0.0,BorderColor :_f .NewPdfColorDeviceGray (0),FillColor :_f .NewPdfColorDeviceGray (1),DrawAlignmentReticle :false };
};func _bffe ()_bf .StreamEncoder {return _bf .NewFlateEncoder ()};func _acbf (_gddb *InkAnnotationDef )([]byte ,*_f .PdfRectangle ,error ){_bddcd :=[][]_ga .CubicBezierCurve {};for _ ,_adbb :=range _gddb .Paths {if _adbb .Length ()==0{continue ;};_ebgb :=_adbb .Points ;
_adfd ,_bbb ,_cag :=_gedd (_ebgb );if _cag !=nil {return nil ,nil ,_cag ;};if len (_adfd )!=len (_bbb ){return nil ,nil ,_e .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");
};_afge :=[]_ga .CubicBezierCurve {};for _dedg :=0;_dedg < len (_adfd );_dedg ++{_afge =append (_afge ,_ga .CubicBezierCurve {P0 :_ebgb [_dedg ],P1 :_adfd [_dedg ],P2 :_bbb [_dedg ],P3 :_ebgb [_dedg +1]});};if len (_afge )> 0{_bddcd =append (_bddcd ,_afge );
};};_acca ,_bfgf ,_bca :=_cfff (_bddcd ,_gddb .Color ,_gddb .LineWidth );if _bca !=nil {return nil ,nil ,_bca ;};return _acca ,_bfgf ,nil ;};func _dbgd (_cac RectangleAnnotationDef )(*_bf .PdfObjectDictionary ,*_f .PdfRectangle ,error ){_cgae :=_f .NewXObjectForm ();
_cgae .Resources =_f .NewPdfPageResources ();_fbc :="";if _cac .Opacity < 1.0{_gfbb :=_bf .MakeDict ();_gfbb .Set ("\u0063\u0061",_bf .MakeFloat (_cac .Opacity ));_gfbb .Set ("\u0043\u0041",_bf .MakeFloat (_cac .Opacity ));_eeca :=_cgae .Resources .AddExtGState ("\u0067\u0073\u0031",_gfbb );
if _eeca !=nil {_c .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 ,_eeca ;};_fbc ="\u0067\u0073\u0031";};_feec ,_fgb ,_bccc ,_cbdd :=_acaga (_cac ,_fbc );
if _cbdd !=nil {return nil ,nil ,_cbdd ;};_cbdd =_cgae .SetContentStream (_feec ,nil );if _cbdd !=nil {return nil ,nil ,_cbdd ;};_cgae .BBox =_fgb .ToPdfObject ();_dgda :=_bf .MakeDict ();_dgda .Set ("\u004e",_cgae .ToPdfObject ());return _dgda ,_bccc ,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 *_f .PdfPage ,name string ,rect []float64 ,opt ImageFieldOptions )(*_f .PdfFieldButton ,error ){if page ==nil {return nil ,_e .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};if len (name )<=0{return nil ,_e .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 ,_e .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");};_baeg :=_f .NewPdfField ();_fbbc :=&_f .PdfFieldButton {};_fbbc .PdfField =_baeg ;_baeg .SetContext (_fbbc );_fbbc .SetType (_f .ButtonTypePush );
_fbbc .T =_bf .MakeString (name );_cbgb :=_f .NewPdfAnnotationWidget ();_cbgb .Rect =_bf .MakeArrayFromFloats (rect );_cbgb .P =page .ToPdfObject ();_cbgb .F =_bf .MakeInteger (4);_cbgb .Parent =_fbbc .ToPdfObject ();_efbec :=rect [2]-rect [0];_abf :=rect [3]-rect [1];
_fdeg :=opt ._gbfb ;_gaff :=_cg .NewContentCreator ();if _fdeg .BorderSize > 0{_gab (_gaff ,_fdeg ,_efbec ,_abf );};if _fdeg .DrawAlignmentReticle {_deea :=_fdeg ;_deea .BorderSize =0.2;_adfa (_gaff ,_deea ,_efbec ,_abf );};_eggb ,_caaf :=_edfg (_efbec ,_abf ,opt .Image ,_fdeg );
if _caaf !=nil {return nil ,_caaf ;};_ggf ,_eaf :=_bf .GetDict (_cbgb .MK );if _eaf {_ggf .Set ("\u006c",_eggb .ToPdfObject ());};_acae :=_bf .MakeDict ();_acae .Set ("\u0046\u0052\u004d",_eggb .ToPdfObject ());_eaea :=_f .NewPdfPageResources ();_eaea .ProcSet =_bf .MakeArray (_bf .MakeName ("\u0050\u0044\u0046"));
_eaea .XObject =_acae ;_ccb :=_efbec -2;_gebb :=_abf -2;_gaff .Add_q ();_gaff .Add_re (1,1,_ccb ,_gebb );_gaff .Add_W ();_gaff .Add_n ();_ccb -=2;_gebb -=2;_gaff .Add_q ();_gaff .Add_re (2,2,_ccb ,_gebb );_gaff .Add_W ();_gaff .Add_n ();_aege :=_g .Min (_ccb /float64 (opt .Image .Width ),_gebb /float64 (opt .Image .Height ));
_gaff .Add_cm (_aege ,0,0,_aege ,(_efbec /2)-(float64 (opt .Image .Width )*_aege /2)+2,2);_gaff .Add_Do ("\u0046\u0052\u004d");_gaff .Add_Q ();_gaff .Add_Q ();_gaa :=_f .NewXObjectForm ();_gaa .FormType =_bf .MakeInteger (1);_gaa .Resources =_eaea ;_gaa .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_efbec ,_abf });
_gaa .Matrix =_bf .MakeArrayFromFloats ([]float64 {1.0,0.0,0.0,1.0,0.0,0.0});_gaa .SetContentStream (_gaff .Bytes (),_bffe ());_ffa :=_bf .MakeDict ();_ffa .Set ("\u004e",_gaa .ToPdfObject ());_cbgb .AP =_ffa ;_fbbc .Annotations =append (_fbbc .Annotations ,_cbgb );
return _fbbc ,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 ;type quadding int ;
// ImageFieldOptions defines optional parameters for a push button with image attach capability form field.
type ImageFieldOptions struct{Image *_f .Image ;_gbfb AppearanceStyle ;};func _dgb (_aee *_f .PdfAnnotationWidget ,_efaa *_f .PdfFieldButton ,_ff *_f .PdfPageResources ,_bcb AppearanceStyle )(*_bf .PdfObjectDictionary ,error ){_ebfc ,_abe :=_bf .GetArray (_aee .Rect );
if !_abe {return nil ,_e .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_egd ,_dgd :=_f .NewPdfRectangle (*_ebfc );if _dgd !=nil {return nil ,_dgd ;};_eec ,_ffg :=_egd .Width (),_egd .Height ();_gadg ,_cba :=_eec ,_ffg ;
_c .Log .Debug ("\u0043\u0068\u0065\u0063kb\u006f\u0078\u002c\u0020\u0077\u0061\u0020\u0042\u0053\u003a\u0020\u0025\u0076",_aee .BS );_aab ,_dgd :=_f .NewStandard14Font ("\u005a\u0061\u0070f\u0044\u0069\u006e\u0067\u0062\u0061\u0074\u0073");if _dgd !=nil {return nil ,_dgd ;
};_cdb ,_gfgd :=_bf .GetDict (_aee .MK );if _gfgd {_bcbf ,_ :=_bf .GetDict (_aee .BS );_ecb :=_bcb .applyAppearanceCharacteristics (_cdb ,_bcbf ,_aab );if _ecb !=nil {return nil ,_ecb ;};};_gbdc :=_f .NewXObjectForm ();{_afff :=_cg .NewContentCreator ();
if _bcb .BorderSize > 0{_gab (_afff ,_bcb ,_eec ,_ffg );};if _bcb .DrawAlignmentReticle {_aac :=_bcb ;_aac .BorderSize =0.2;_adfa (_afff ,_aac ,_eec ,_ffg );};_eec ,_ffg =_bcb .applyRotation (_cdb ,_eec ,_ffg ,_afff );_cfe :=_bcb .AutoFontSizeFraction *_ffg ;
_bcd ,_bcf :=_aab .GetRuneMetrics (_bcb .CheckmarkRune );if !_bcf {return nil ,_e .New ("\u0067l\u0079p\u0068\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");};_dfda :=_aab .Encoder ();_bfd :=_dfda .Encode (string (_bcb .CheckmarkRune ));
_bbgc :=_bcd .Wx *_cfe /1000.0;_ecdd :=705.0;_efgf :=_ecdd /1000.0*_cfe ;_gfa :=_cb ;if _bcb .MarginLeft !=nil {_gfa =*_bcb .MarginLeft ;};_aabe :=1.0;if _bbgc < _eec {_gfa =(_eec -_bbgc )/2.0;};if _efgf < _ffg {_aabe =(_ffg -_efgf )/2.0;};_afff .Add_q ().Add_g (0).Add_BT ().Add_Tf ("\u005a\u0061\u0044\u0062",_cfe ).Add_Td (_gfa ,_aabe ).Add_Tj (*_bf .MakeStringFromBytes (_bfd )).Add_ET ().Add_Q ();
_gbdc .Resources =_f .NewPdfPageResources ();_gbdc .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_aab .ToPdfObject ());_gbdc .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_gadg ,_cba });_gbdc .SetContentStream (_afff .Bytes (),_bffe ());};_bdeb :=_f .NewXObjectForm ();
{_efgc :=_cg .NewContentCreator ();if _bcb .BorderSize > 0{_gab (_efgc ,_bcb ,_eec ,_ffg );};_bdeb .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_gadg ,_cba });_bdeb .SetContentStream (_efgc .Bytes (),_bffe ());};_fdc :=_bf .MakeDict ();_fdc .Set ("\u004f\u0066\u0066",_bdeb .ToPdfObject ());
_fdc .Set ("\u0059\u0065\u0073",_gbdc .ToPdfObject ());_bddb :=_bf .MakeDict ();_bddb .Set ("\u004e",_fdc );return _bddb ,nil ;};func _adfa (_bgb *_cg .ContentCreator ,_geb AppearanceStyle ,_fcea ,_aef float64 ){_bgb .Add_q ().Add_re (0,0,_fcea ,_aef ).Add_re (0,_aef /2,_fcea ,_aef /2).Add_re (0,0,_fcea ,_aef ).Add_re (_fcea /2,0,_fcea /2,_aef ).Add_w (_geb .BorderSize ).SetStrokingColor (_geb .BorderColor ).SetNonStrokingColor (_geb .FillColor ).Add_B ().Add_Q ();
};
// CheckboxFieldOptions defines optional parameters for a checkbox field a form.
type CheckboxFieldOptions struct{Checked bool ;};func _dd (_cfg CircleAnnotationDef )(*_bf .PdfObjectDictionary ,*_f .PdfRectangle ,error ){_ced :=_f .NewXObjectForm ();_ced .Resources =_f .NewPdfPageResources ();_gf :="";if _cfg .Opacity < 1.0{_ba :=_bf .MakeDict ();
_ba .Set ("\u0063\u0061",_bf .MakeFloat (_cfg .Opacity ));_ba .Set ("\u0043\u0041",_bf .MakeFloat (_cfg .Opacity ));_de :=_ced .Resources .AddExtGState ("\u0067\u0073\u0031",_ba );if _de !=nil {_c .Log .Debug ("U\u006e\u0061\u0062\u006c\u0065\u0020t\u006f\u0020\u0061\u0064\u0064\u0020\u0065\u0078\u0074g\u0073\u0074\u0061t\u0065 \u0067\u0073\u0031");
return nil ,nil ,_de ;};_gf ="\u0067\u0073\u0031";};_cc ,_ae ,_ec ,_ad :=_ddd (_cfg ,_gf );if _ad !=nil {return nil ,nil ,_ad ;};_ad =_ced .SetContentStream (_cc ,nil );if _ad !=nil {return nil ,nil ,_ad ;};_ced .BBox =_ae .ToPdfObject ();_dec :=_bf .MakeDict ();
_dec .Set ("\u004e",_ced .ToPdfObject ());return _dec ,_ec ,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 *_f .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 _f .PdfColor ;
// FillColor represents the background color of the appearance annotation area.
FillColor _f .PdfColor ;
// BorderSize represents border size of the appearance annotation area.
BorderSize float64 ;
// BorderColor represents the border color of the appearance annotation area.
BorderColor _f .PdfColor ;
// WatermarkImage specifies the image used as a watermark that will be rendered
// behind the signature.
WatermarkImage _bd .Image ;
// Image represents the image used for the signature appearance.
Image _bd .Image ;
// Encoder specifies the image encoder used for image signature. Defaults to flate encoder.
Encoder _bf .StreamEncoder ;
// ImagePosition specifies the image location relative to the text signature.
ImagePosition SignatureImagePosition ;};
// 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 *_f .PdfSignature ,lines []*SignatureLine ,opts *SignatureFieldOpts )(*_f .PdfFieldSignature ,error ){if signature ==nil {return nil ,_e .New ("\u0073\u0069\u0067na\u0074\u0075\u0072\u0065\u0020\u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u006e\u0069\u006c");
};_fdee ,_fcge :=_gcee (lines ,opts );if _fcge !=nil {return nil ,_fcge ;};_acgg :=_f .NewPdfFieldSignature (signature );_acgg .Rect =_bf .MakeArrayFromFloats (opts .Rect );_acgg .AP =_fdee ;return _acgg ,nil ;};const (_bbae quadding =0;_aea quadding =1;
_acb quadding =2;_cb float64 =2.0;);
// SignatureLine represents a line of information in the signature field appearance.
type SignatureLine struct{Desc string ;Text string ;};