unipdf/annotator/annotator.go

427 lines
66 KiB
Go
Raw Normal View History

2020-08-27 21:45:09 +00:00
//
// 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.
2021-12-14 01:08:28 +00:00
package annotator ;import (_a "bytes";_e "errors";_d "github.com/unidoc/unipdf/v3/common";_ag "github.com/unidoc/unipdf/v3/contentstream";_ffd "github.com/unidoc/unipdf/v3/contentstream/draw";_ba "github.com/unidoc/unipdf/v3/core";_b "github.com/unidoc/unipdf/v3/internal/textencoding";
_ff "github.com/unidoc/unipdf/v3/model";_cc "image";_c "math";_ab "strings";_f "unicode";);const (_ebe quadding =0;_fdf quadding =1;_ed quadding =2;_ca float64 =2.0;);
2021-03-23 23:12:52 +00:00
2021-12-14 01:08:28 +00:00
// 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 ;_ae *AppearanceStyle ;};type quadding int ;func (_fgg *AppearanceStyle )applyAppearanceCharacteristics (_aedd *_ba .PdfObjectDictionary ,_fgge *_ba .PdfObjectDictionary ,_gddg *_ff .PdfFont )error {if !_fgg .AllowMK {return nil ;
};if CA ,_cdga :=_ba .GetString (_aedd .Get ("\u0043\u0041"));_cdga &&_gddg !=nil {_bgag :=CA .Bytes ();if len (_bgag )!=0{_cabb :=[]rune (_gddg .Encoder ().Decode (_bgag ));if len (_cabb )==1{_fgg .CheckmarkRune =_cabb [0];};};};if BC ,_ffdf :=_ba .GetArray (_aedd .Get ("\u0042\u0043"));
_ffdf {_ddg ,_fceg :=BC .ToFloat64Array ();if _fceg !=nil {return _fceg ;};switch len (_ddg ){case 1:_fgg .BorderColor =_ff .NewPdfColorDeviceGray (_ddg [0]);case 3:_fgg .BorderColor =_ff .NewPdfColorDeviceRGB (_ddg [0],_ddg [1],_ddg [2]);case 4:_fgg .BorderColor =_ff .NewPdfColorDeviceCMYK (_ddg [0],_ddg [1],_ddg [2],_ddg [3]);
default:_d .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 (_ddg ));
};if _fgge !=nil {if _ecg ,_dgg :=_ba .GetNumberAsFloat (_fgge .Get ("\u0057"));_dgg ==nil {_fgg .BorderSize =_ecg ;};};};if BG ,_fbe :=_ba .GetArray (_aedd .Get ("\u0042\u0047"));_fbe {_cead ,_cabe :=BG .ToFloat64Array ();if _cabe !=nil {return _cabe ;
};switch len (_cead ){case 1:_fgg .FillColor =_ff .NewPdfColorDeviceGray (_cead [0]);case 3:_fgg .FillColor =_ff .NewPdfColorDeviceRGB (_cead [0],_cead [1],_cead [2]);case 4:_fgg .FillColor =_ff .NewPdfColorDeviceCMYK (_cead [0],_cead [1],_cead [2],_cead [3]);
default:_d .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 (_cead ));
};};return nil ;};
2021-04-06 22:35:37 +00:00
2021-12-14 01:08:28 +00:00
// 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 _acee (_egd []*SignatureLine ,_gddgb *SignatureFieldOpts )(*_ba .PdfObjectDictionary ,error ){if _gddgb ==nil {_gddgb =NewSignatureFieldOpts ();
};var _dede error ;var _ecf *_ba .PdfObjectName ;_bdef :=_gddgb .Font ;if _bdef !=nil {_acg ,_ :=_bdef .GetFontDescriptor ();if _acg !=nil {if _bgaa ,_fdcd :=_acg .FontName .(*_ba .PdfObjectName );_fdcd {_ecf =_bgaa ;};};if _ecf ==nil {_ecf =_ba .MakeName ("\u0046\u006f\u006et\u0031");
};}else {if _bdef ,_dede =_ff .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");_dede !=nil {return nil ,_dede ;};_ecf =_ba .MakeName ("\u0048\u0065\u006c\u0076");};_egbc :=_gddgb .FontSize ;if _egbc <=0{_egbc =10;};if _gddgb .LineHeight <=0{_gddgb .LineHeight =1;
};_acfd :=_gddgb .LineHeight *_egbc ;_ggc ,_dfe :=_bdef .GetRuneMetrics (' ');if !_dfe {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");
};_dcaeb :=_ggc .Wx ;var _bgbb float64 ;var _fgb []string ;for _ ,_agf :=range _egd {if _agf .Text ==""{continue ;};_fbad :=_agf .Text ;if _agf .Desc !=""{_fbad =_agf .Desc +"\u003a\u0020"+_fbad ;};_fgb =append (_fgb ,_fbad );var _bbd float64 ;for _ ,_ggbb :=range _fbad {_fdg ,_cfcb :=_bdef .GetRuneMetrics (_ggbb );
if !_cfcb {continue ;};_bbd +=_fdg .Wx ;};if _bbd > _bgbb {_bgbb =_bbd ;};};_bgbb =_bgbb *_egbc /1000.0;_gca :=float64 (len (_fgb ))*_acfd ;_dga :=_gddgb .Image !=nil ;_gdff :=_gddgb .Rect ;if _gdff ==nil {_gdff =[]float64 {0,0,_bgbb ,_gca };if _dga {_gdff [2]=_bgbb *2;
_gdff [3]=_gca *2;};_gddgb .Rect =_gdff ;};_dgcd :=_gdff [2]-_gdff [0];_dge :=_gdff [3]-_gdff [1];_ggbbe ,_cbe :=_gdff ,_gdff ;var _beg ,_dcfa float64 ;if _dga &&len (_fgb )> 0{if _gddgb .ImagePosition <=SignatureImageRight {_agd :=[]float64 {_gdff [0],_gdff [1],_gdff [0]+(_dgcd /2),_gdff [3]};
_cee :=[]float64 {_gdff [0]+(_dgcd /2),_gdff [1],_gdff [2],_gdff [3]};if _gddgb .ImagePosition ==SignatureImageLeft {_ggbbe ,_cbe =_agd ,_cee ;}else {_ggbbe ,_cbe =_cee ,_agd ;};}else {_faf :=[]float64 {_gdff [0],_gdff [1],_gdff [2],_gdff [1]+(_dge /2)};
_ggbf :=[]float64 {_gdff [0],_gdff [1]+(_dge /2),_gdff [2],_gdff [3]};if _gddgb .ImagePosition ==SignatureImageTop {_ggbbe ,_cbe =_ggbf ,_faf ;}else {_ggbbe ,_cbe =_faf ,_ggbf ;};};};_beg =_cbe [2]-_cbe [0];_dcfa =_cbe [3]-_cbe [1];var _dce float64 ;if _gddgb .AutoSize {if _bgbb > _beg ||_gca > _dcfa {_ebag :=_c .Min (_beg /_bgbb ,_dcfa /_gca );
_egbc *=_ebag ;};_acfd =_gddgb .LineHeight *_egbc ;_dce +=(_dcfa -float64 (len (_fgb ))*_acfd )/2;};_fdb :=_ag .NewContentCreator ();_affc :=_ff .NewPdfPageResources ();_affc .SetFontByName (*_ecf ,_bdef .ToPdfObject ());if _gddgb .BorderSize <=0{_gddgb .BorderSize =0;
_gddgb .BorderColor =_ff .NewPdfColorDeviceGray (1);};if _gddgb .BorderColor ==nil {_gddgb .BorderColor =_ff .NewPdfColorDeviceGray (1);};if _gddgb .FillColor ==nil {_gddgb .FillColor =_ff .NewPdfColorDeviceGray (1);};_fdb .Add_q ().SetNonStrokingColor (_gddgb .FillColor ).SetStrokingColor (_gddgb .BorderColor ).Add_w (_gddgb .BorderSize ).Add_re (_gdff [0],_gdff [1],_dgcd ,_dge ).Add_B ().Add_Q ();
if _gddgb .WatermarkImage !=nil {_ebaa :=[]float64 {_gdff [0],_gdff [1],_gdff [2],_gdff [3]};_dbaf ,_aabc ,_gfc :=_debc (_gddgb .WatermarkImage ,"\u0049\u006d\u0061\u0067\u0065\u0057\u0061\u0074\u0065r\u006d\u0061\u0072\u006b",_gddgb ,_ebaa ,_fdb );if _gfc !=nil {return nil ,_gfc ;
};_affc .SetXObjectImageByName (*_dbaf ,_aabc );};_fdb .Add_q ();_fdb .Translate (_cbe [0],_cbe [3]-_acfd -_dce );_fdb .Add_BT ();_abe :=_bdef .Encoder ();for _ ,_bbe :=range _fgb {var _acc []byte ;for _ ,_egbb :=range _bbe {if _f .IsSpace (_egbb ){if len (_acc )> 0{_fdb .SetNonStrokingColor (_gddgb .TextColor ).Add_Tf (*_ecf ,_egbc ).Add_TL (_acfd ).Add_TJ ([]_ba .PdfObject {_ba .MakeStringFromBytes (_acc )}...);
_acc =nil ;};_fdb .Add_Tf (*_ecf ,_egbc ).Add_TL (_acfd ).Add_TJ ([]_ba .PdfObject {_ba .MakeFloat (-_dcaeb )}...);}else {_acc =append (_acc ,_abe .Encode (string (_egbb ))...);};};if len (_acc )> 0{_fdb .SetNonStrokingColor (_gddgb .TextColor ).Add_Tf (*_ecf ,_egbc ).Add_TL (_acfd ).Add_TJ ([]_ba .PdfObject {_ba .MakeStringFromBytes (_acc )}...);
};_fdb .Add_Td (0,-_acfd );};_fdb .Add_ET ();_fdb .Add_Q ();if _dga {_cdbd ,_gdca ,_ffeg :=_debc (_gddgb .Image ,"\u0049\u006d\u0061\u0067\u0065\u0053\u0069\u0067\u006ea\u0074\u0075\u0072\u0065",_gddgb ,_ggbbe ,_fdb );if _ffeg !=nil {return nil ,_ffeg ;
};_affc .SetXObjectImageByName (*_cdbd ,_gdca );};_dfdg :=_ff .NewXObjectForm ();_dfdg .Resources =_affc ;_dfdg .BBox =_ba .MakeArrayFromFloats (_gdff );_dfdg .SetContentStream (_fdb .Bytes (),_ebg ());_cggd :=_ba .MakeDict ();_cggd .Set ("\u004e",_dfdg .ToPdfObject ());
return _cggd ,nil ;};
2021-04-06 22:35:37 +00:00
2021-12-14 01:08:28 +00:00
// Style returns the appearance style of `fa`. If not specified, returns default style.
func (_ddc FieldAppearance )Style ()AppearanceStyle {if _ddc ._ae !=nil {return *_ddc ._ae ;};_ccb :=_ca ;return AppearanceStyle {AutoFontSizeFraction :0.65,CheckmarkRune :'✔',BorderSize :0.0,BorderColor :_ff .NewPdfColorDeviceGray (0),FillColor :_ff .NewPdfColorDeviceGray (1),MultilineLineHeight :1.2,MultilineVAlignMiddle :false ,DrawAlignmentReticle :false ,AllowMK :true ,MarginLeft :&_ccb };
};func _ebda (_gfag *_ff .PdfAcroForm ,_bgdb *_ff .PdfAnnotationWidget ,_abb *_ff .PdfFieldChoice ,_babd AppearanceStyle )(*_ba .PdfObjectDictionary ,error ){_cggf ,_fge :=_ba .GetArray (_bgdb .Rect );if !_fge {return nil ,_e .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");
};_cab ,_ggb :=_ff .NewPdfRectangle (*_cggf );if _ggb !=nil {return nil ,_ggb ;};_cddf ,_gbcb :=_cab .Width (),_cab .Height ();_d .Log .Debug ("\u0043\u0068\u006f\u0069\u0063\u0065\u002c\u0020\u0077\u0061\u0020\u0042S\u003a\u0020\u0025\u0076",_bgdb .BS );
_efdf ,_ggb :=_ag .NewContentStreamParser (_aegf (_abb .PdfField )).Parse ();if _ggb !=nil {return nil ,_ggb ;};_feg ,_bde :=_ba .GetDict (_bgdb .MK );if _bde {_eeec ,_ :=_ba .GetDict (_bgdb .BS );_ddef :=_babd .applyAppearanceCharacteristics (_feg ,_eeec ,nil );
if _ddef !=nil {return nil ,_ddef ;};};_degc :=_ba .MakeDict ();for _ ,_fcea :=range _abb .Opt .Elements (){if _aada ,_dfd :=_ba .GetArray (_fcea );_dfd &&_aada .Len ()==2{_fcea =_aada .Get (1);};var _cef string ;if _dffc ,_effb :=_ba .GetString (_fcea );
_effb {_cef =_dffc .Decoded ();}else if _babf ,_daaa :=_ba .GetName (_fcea );_daaa {_cef =_babf .String ();}else {_d .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",_fcea );
return nil ,_e .New ("\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u002f\u0073t\u0072\u0069\u006e\u0067");};if len (_cef )> 0{_cafg ,_cefe :=_eda (_abb .PdfField ,_cddf ,_gbcb ,_cef ,_babd ,_efdf ,_gfag .DR ,_feg );if _cefe !=nil {return nil ,_cefe ;
};_degc .Set (*_ba .MakeName (_cef ),_cafg .ToPdfObject ());};};_dadc :=_ba .MakeDict ();_dadc .Set ("\u004e",_degc );return _dadc ,nil ;};func _ebg ()_ba .StreamEncoder {return _ba .NewFlateEncoder ()};func _cge (_gdb *_ff .PdfAnnotationWidget ,_afa *_ff .PdfFieldButton ,_aefa *_ff .PdfPageResources ,_adef AppearanceStyle )(*_ba .PdfObjectDictionary ,error ){_eecd ,_bfcb :=_ba .GetArray (_gdb .Rect );
if !_bfcb {return nil ,_e .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_gdc ,_dbe :=_ff .NewPdfRectangle (*_eecd );if _dbe !=nil {return nil ,_dbe ;};_afff ,_bb :=_gdc .Width (),_gdc .Height ();_dcdg ,_gga :=_afff ,_bb ;
_d .Log .Debug ("\u0043\u0068\u0065\u0063kb\u006f\u0078\u002c\u0020\u0077\u0061\u0020\u0042\u0053\u003a\u0020\u0025\u0076",_gdb .BS );_egb ,_dbe :=_ff .NewStandard14Font ("\u005a\u0061\u0070f\u0044\u0069\u006e\u0067\u0062\u0061\u0074\u0073");if _dbe !=nil {return nil ,_dbe ;
};_agbc ,_egfb :=_ba .GetDict (_gdb .MK );if _egfb {_bab ,_ :=_ba .GetDict (_gdb .BS );_ded :=_adef .applyAppearanceCharacteristics (_agbc ,_bab ,_egb );if _ded !=nil {return nil ,_ded ;};};_bag :=_ff .NewXObjectForm ();{_cde :=_ag .NewContentCreator ();
if _adef .BorderSize > 0{_fde (_cde ,_adef ,_afff ,_bb );};if _adef .DrawAlignmentReticle {_gea :=_adef ;_gea .BorderSize =0.2;_gegf (_cde ,_gea ,_afff ,_bb );};_afff ,_bb =_adef .applyRotation (_agbc ,_afff ,_bb ,_cde );_cfc :=_adef .AutoFontSizeFraction *_bb ;
_fad ,_gcbg :=_egb .GetRuneMetrics (_adef .CheckmarkRune );if !_gcbg {return nil ,_e .New ("\u0067l\u0079p\u0068\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");};_fgc :=_egb .Encoder ();_dbg :=_fgc .Encode (string (_adef .CheckmarkRune ));
_gfab :=_fad .Wx *_cfc /1000.0;_acf :=705.0;_ggdc :=_acf /1000.0*_cfc ;_gedf :=_ca ;if _adef .MarginLeft !=nil {_gedf =*_adef .MarginLeft ;};_ebc :=1.0;if _gfab < _afff {_gedf =(_afff -_gfab )/2.0;};if _ggdc < _bb {_ebc =(_bb -_ggdc )/2.0;};_cde .Add_q ().Add_g (0).Add_BT ().Add_Tf ("\u005a\u0061\u0044\u0062",_cfc ).Add_Td (_gedf ,_ebc ).Add_Tj (*_ba .MakeStringFromBytes (_dbg )).Add_ET ().Add_Q ();
_bag .Resources =_ff .NewPdfPageResources ();_bag .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_egb .ToPdfObject ());_bag .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_dcdg ,_gga });_bag .SetContentStream (_cde .Bytes (),_ebg ());};_edge :=_ff .NewXObjectForm ();
{_affg :=_ag .NewContentCreator ();if _adef .BorderSize > 0{_fde (_affg ,_adef ,_afff ,_bb );};_edge .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_dcdg ,_gga });_edge .SetContentStream (_affg .Bytes (),_ebg ());};_efd :=_ba .MakeDict ();_efd .Set ("\u004f\u0066\u0066",_edge .ToPdfObject ());
_efd .Set ("\u0059\u0065\u0073",_bag .ToPdfObject ());_edd :=_ba .MakeDict ();_edd .Set ("\u004e",_efd );return _edd ,nil ;};
2021-04-06 22:35:37 +00:00
2021-12-14 01:08:28 +00:00
// SetStyle applies appearance `style` to `fa`.
func (_ebb *ImageFieldAppearance )SetStyle (style AppearanceStyle ){_ebb ._cgdf =&style };func _gegf (_faeb *_ag .ContentCreator ,_bcc AppearanceStyle ,_bbb ,_afec float64 ){_faeb .Add_q ().Add_re (0,0,_bbb ,_afec ).Add_re (0,_afec /2,_bbb ,_afec /2).Add_re (0,0,_bbb ,_afec ).Add_re (_bbb /2,0,_bbb /2,_afec ).Add_w (_bcc .BorderSize ).SetStrokingColor (_bcc .BorderColor ).SetNonStrokingColor (_bcc .FillColor ).Add_B ().Add_Q ();
};func _eda (_gfe *_ff .PdfField ,_cebc ,_gaf float64 ,_dcae string ,_fae AppearanceStyle ,_ecb *_ag .ContentStreamOperations ,_age *_ff .PdfPageResources ,_ddbe *_ba .PdfObjectDictionary )(*_ff .XObjectForm ,error ){_bgga :=_ff .NewPdfPageResources ();
_cfa ,_faa :=_cebc ,_gaf ;_cda :=_ag .NewContentCreator ();if _fae .BorderSize > 0{_fde (_cda ,_fae ,_cebc ,_gaf );};if _fae .DrawAlignmentReticle {_bcda :=_fae ;_bcda .BorderSize =0.2;_gegf (_cda ,_bcda ,_cebc ,_gaf );};_cda .Add_BMC ("\u0054\u0078");
_cda .Add_q ();_cda .Add_BT ();_cebc ,_gaf =_fae .applyRotation (_ddbe ,_cebc ,_gaf ,_cda );_dace ,_gafc ,_gdba :=_fae .processDA (_gfe ,_ecb ,_age ,_bgga ,_cda );if _gdba !=nil {return nil ,_gdba ;};_adb :=_dace .Font ;_dfg :=_dace .Size ;_aac :=_ba .MakeName (_dace .Name );
_cbcc :=_dfg ==0;if _cbcc &&_gafc {_dfg =_gaf *_fae .AutoFontSizeFraction ;};_dagg :=_adb .Encoder ();if _dagg ==nil {_d .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");
_dagg =_b .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};if len (_dcae )==0{return nil ,nil ;};_adbc :=_ca ;if _fae .MarginLeft !=nil {_adbc =*_fae .MarginLeft ;};_agg :=0.0;if _dagg !=nil {for _ ,_dfcf :=range _dcae {_eaad ,_bceb :=_adb .GetRuneMetrics (_dfcf );
if !_bceb {_d .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",_dfcf );
continue ;};_agg +=_eaad .Wx ;};_dcae =string (_dagg .Encode (_dcae ));};if _dfg ==0||_cbcc &&_agg > 0&&_adbc +_agg *_dfg /1000.0> _cebc {_dfg =0.95*1000.0*(_cebc -_adbc )/_agg ;};_fga :=1.0*_dfg ;_debf :=2.0;{_eaac :=_fga ;if _cbcc &&_debf +_eaac > _gaf {_dfg =0.95*(_gaf -_debf );
_fga =1.0*_dfg ;_eaac =_fga ;};if _gaf > _eaac {_debf =(_gaf -_eaac )/2.0;_debf +=1.50;};};_cda .Add_Tf (*_aac ,_dfg );_cda .Add_Td (_adbc ,_debf );_cda .Add_Tj (*_ba .MakeString (_dcae ));_cda .Add_ET ();_cda .Add_Q ();_cda .Add_EMC ();_bdg :=_ff .NewXObjectForm ();
_bdg .Resources =_bgga ;_bdg .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_cfa ,_faa });_bdg .SetContentStream (_cda .Bytes (),_ebg ());return _bdg ,nil ;};func _cce (_dff *_ff .PdfAnnotationWidget ,_dgd *_ff .PdfFieldText ,_bfc *_ff .PdfPageResources ,_dee AppearanceStyle )(*_ba .PdfObjectDictionary ,error ){_ddcf :=_ff .NewPdfPageResources ();
_geg ,_baf :=_ba .GetArray (_dff .Rect );if !_baf {return nil ,_e .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_fa ,_fba :=_ff .NewPdfRectangle (*_geg );if _fba !=nil {return nil ,_fba ;};_dab ,_bce :=_fa .Width (),_fa .Height ();
_ead ,_cea :=_dab ,_bce ;_gg ,_gcb :=_ba .GetDict (_dff .MK );if _gcb {_cdg ,_ :=_ba .GetDict (_dff .BS );_gfd :=_dee .applyAppearanceCharacteristics (_gg ,_cdg ,nil );if _gfd !=nil {return nil ,_gfd ;};};_eaaa ,_gcb :=_ba .GetIntVal (_dgd .MaxLen );if !_gcb {return nil ,_e .New ("\u006d\u0061\u0078\u006c\u0065\u006e\u0020\u006e\u006ft\u0020\u0073\u0065\u0074");
};if _eaaa <=0{return nil ,_e .New ("\u006d\u0061\u0078\u004c\u0065\u006e\u0020\u0069\u006ev\u0061\u006c\u0069\u0064");};_aef :=_dab /float64 (_eaaa );_edgf ,_fba :=_ag .NewContentStreamParser (_aegf (_dgd .PdfField )).Parse ();if _fba !=nil {return nil ,_fba ;
};_bdb :=_ag .NewContentCreator ();if _dee .BorderSize > 0{_fde (_bdb ,_dee ,_dab ,_bce );};if _dee .DrawAlignmentReticle {_ebd :=_dee ;_ebd .BorderSize =0.2;_gegf (_bdb ,_ebd ,_dab ,_bce );};_bdb .Add_BMC ("\u0054\u0078");_bdb .Add_q ();_ ,_bce =_dee .applyRotation (_gg ,_dab ,_bce ,_bdb );
_bdb .Add_BT ();_aff ,_ddab ,_fba :=_dee .processDA (_dgd .PdfField ,_edgf ,_bfc ,_ddcf ,_bdb );if _fba !=nil {return nil ,_fba ;};_egf :=_aff .Font ;_efc :=_ba .MakeName (_aff .Name );_ade :=_aff .Size ;_dad :=_ade ==0;if _dad &&_ddab {_ade =_bce *_dee .AutoFontSizeFraction ;
};_fed :=_egf .Encoder ();if _fed ==nil {_d .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");
_fed =_b .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};var _bfb string ;if _gcc ,_afd :=_ba .GetString (_dgd .V );_afd {_bfb =_gcc .Decoded ();};_bdb .Add_Tf (*_efc ,_ade );var _acd float64 ;for _ ,_bgb :=range _bfb {_ceb ,_bdbb :=_egf .GetRuneMetrics (_bgb );
if !_bdbb {_d .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",_bgb );
continue ;};_ffdc :=_ceb .Wy ;if int (_ffdc )<=0{_ffdc =_ceb .Wx ;};if _ffdc > _acd {_acd =_ffdc ;};};if int (_acd )==0{_d .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");
_acd =1000;};_baa ,_fba :=_egf .GetFontDescriptor ();if _fba !=nil {_d .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 _bec float64 ;
if _baa !=nil {_bec ,_fba =_baa .GetCapHeight ();if _fba !=nil {_d .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",_fba );
};};if int (_bec )<=0{_d .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");
_bec =1000.0;};_gef :=_bec /1000.0*_ade ;_dea :=0.0;_dba :=1.0*_ade *(_acd /1000.0);{_gefa :=_dba ;if _dad &&_dea +_gefa > _bce {_ade =0.95*(_bce -_dea );_gef =_bec /1000.0*_ade ;};if _bce > _gef {_dea =(_bce -_gef )/2.0;};};_bdb .Add_Td (0,_dea );if _cf ,_ecd :=_ba .GetIntVal (_dgd .Q );
_ecd {switch _cf {case 2:if len (_bfb )< _eaaa {_bgd :=float64 (_eaaa -len (_bfb ))*_aef ;_bdb .Add_Td (_bgd ,0);};};};for _dcf ,_deg :=range _bfb {_aad :=_ca ;if _dee .MarginLeft !=nil {_aad =*_dee .MarginLeft ;};_cba :=string (_deg );if _fed !=nil {_dgc ,_bcd :=_egf .GetRuneMetrics (_deg );
if !_bcd {_d .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",_deg );
continue ;};_cba =string (_fed .Encode (_cba ));_fac :=_ade *_dgc .Wx /1000.0;_bcdc :=(_aef -_fac )/2;_aad =_bcdc ;};_bdb .Add_Td (_aad ,0);_bdb .Add_Tj (*_ba .MakeString (_cba ));if _dcf !=len (_bfb )-1{_bdb .Add_Td (_aef -_aad ,0);};};_bdb .Add_ET ();
_bdb .Add_Q ();_bdb .Add_EMC ();_deb :=_ff .NewXObjectForm ();_deb .Resources =_ddcf ;_deb .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_ead ,_cea });_deb .SetContentStream (_bdb .Bytes (),_ebg ());_agc :=_ba .MakeDict ();_agc .Set ("\u004e",_deb .ToPdfObject ());
return _agc ,nil ;};func _fde (_caa *_ag .ContentCreator ,_eeg AppearanceStyle ,_cdb ,_gdd float64 ){_caa .Add_q ().Add_re (0,0,_cdb ,_gdd ).Add_w (_eeg .BorderSize ).SetStrokingColor (_eeg .BorderColor ).SetNonStrokingColor (_eeg .FillColor ).Add_B ().Add_Q ();
2021-09-23 22:37:42 +00:00
};
2021-08-13 01:33:42 +00:00
2021-12-14 01:08:28 +00:00
// GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`.
// Implements interface model.FieldAppearanceGenerator.
func (_bgg FieldAppearance )GenerateAppearanceDict (form *_ff .PdfAcroForm ,field *_ff .PdfField ,wa *_ff .PdfAnnotationWidget )(*_ba .PdfObjectDictionary ,error ){_d .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 );
_ ,_aae :=field .GetContext ().(*_ff .PdfFieldText );_df ,_bgeg :=_ba .GetDict (wa .AP );if _bgeg &&_bgg .OnlyIfMissing &&(!_aae ||!_bgg .RegenerateTextFields ){_d .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 _df ,nil ;};if form .DR ==nil {form .DR =_ff .NewPdfPageResources ();};switch _ea :=field .GetContext ().(type ){case *_ff .PdfFieldText :_ede :=_ea ;switch {case _ede .Flags ().Has (_ff .FieldFlagPassword ):return nil ,nil ;case _ede .Flags ().Has (_ff .FieldFlagFileSelect ):return nil ,nil ;
case _ede .Flags ().Has (_ff .FieldFlagComb ):if _ede .MaxLen !=nil {_aea ,_bed :=_cce (wa ,_ede ,form .DR ,_bgg .Style ());if _bed !=nil {return nil ,_bed ;};return _aea ,nil ;};};_gad ,_eaa :=_ccga (wa ,_ede ,form .DR ,_bgg .Style ());if _eaa !=nil {return nil ,_eaa ;
};return _gad ,nil ;case *_ff .PdfFieldButton :_gc :=_ea ;if _gc .IsCheckbox (){_daa ,_gf :=_cge (wa ,_gc ,form .DR ,_bgg .Style ());if _gf !=nil {return nil ,_gf ;};return _daa ,nil ;};_d .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",_gc .GetType ());
case *_ff .PdfFieldChoice :_eag :=_ea ;switch {case _eag .Flags ().Has (_ff .FieldFlagCombo ):_fb ,_edg :=_ebda (form ,wa ,_eag ,_bgg .Style ());if _edg !=nil {return nil ,_edg ;};return _fb ,nil ;default:_d .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",_eag .Flags ().String ());
};default:_d .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",_ea );};return nil ,nil ;};
// TextFieldOptions defines optional parameter for a text field in a form.
type TextFieldOptions struct{MaxLen int ;Value string ;};func _gedg (_dgf LineAnnotationDef ,_dbag string )([]byte ,*_ff .PdfRectangle ,*_ff .PdfRectangle ,error ){_ccff :=_ffd .Line {X1 :0,Y1 :0,X2 :_dgf .X2 -_dgf .X1 ,Y2 :_dgf .Y2 -_dgf .Y1 ,LineColor :_dgf .LineColor ,Opacity :_dgf .Opacity ,LineWidth :_dgf .LineWidth ,LineEndingStyle1 :_dgf .LineEndingStyle1 ,LineEndingStyle2 :_dgf .LineEndingStyle2 };
_adga ,_bdd ,_ffg :=_ccff .Draw (_dbag );if _ffg !=nil {return nil ,nil ,nil ,_ffg ;};_eddd :=&_ff .PdfRectangle {};_eddd .Llx =_dgf .X1 +_bdd .Llx ;_eddd .Lly =_dgf .Y1 +_bdd .Lly ;_eddd .Urx =_dgf .X1 +_bdd .Urx ;_eddd .Ury =_dgf .Y1 +_bdd .Ury ;return _adga ,_bdd ,_eddd ,nil ;
};func _bge (_bf CircleAnnotationDef ,_af string )([]byte ,*_ff .PdfRectangle ,*_ff .PdfRectangle ,error ){_ec :=_ffd .Circle {X :_bf .X ,Y :_bf .Y ,Width :_bf .Width ,Height :_bf .Height ,FillEnabled :_bf .FillEnabled ,FillColor :_bf .FillColor ,BorderEnabled :_bf .BorderEnabled ,BorderWidth :_bf .BorderWidth ,BorderColor :_bf .BorderColor ,Opacity :_bf .Opacity };
_be ,_fd ,_ef :=_ec .Draw (_af );if _ef !=nil {return nil ,nil ,nil ,_ef ;};_db :=&_ff .PdfRectangle {};_db .Llx =_bf .X +_fd .Llx ;_db .Lly =_bf .Y +_fd .Lly ;_db .Urx =_bf .X +_fd .Urx ;_db .Ury =_bf .Y +_fd .Ury ;return _be ,_fd ,_db ,nil ;};
2021-08-13 01:33:42 +00:00
2021-10-22 10:53:20 +00:00
// AppearanceFont represents a font used for generating the appearance of a
// field in the filling/flattening process.
type AppearanceFont struct{
2021-08-13 01:33:42 +00:00
2021-10-22 10:53:20 +00:00
// Name represents the name of the font which will be added to the
// AcroForm resources (DR).
Name string ;
2021-08-13 01:33:42 +00:00
2021-10-22 10:53:20 +00:00
// Font represents the actual font used for the field appearance.
2021-12-14 01:08:28 +00:00
Font *_ff .PdfFont ;
2021-08-13 01:33:42 +00:00
2021-10-22 10:53:20 +00:00
// 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 ;};
2021-08-13 01:33:42 +00:00
2021-12-14 01:08:28 +00:00
// CreateCircleAnnotation creates a circle/ellipse annotation object with appearance stream that can be added to
// page PDF annotations.
func CreateCircleAnnotation (circDef CircleAnnotationDef )(*_ff .PdfAnnotation ,error ){_gd :=_ff .NewPdfAnnotationCircle ();if circDef .BorderEnabled {_dd ,_bg ,_ce :=circDef .BorderColor .R (),circDef .BorderColor .G (),circDef .BorderColor .B ();_gd .C =_ba .MakeArrayFromFloats ([]float64 {_dd ,_bg ,_ce });
_dde :=_ff .NewBorderStyle ();_dde .SetBorderWidth (circDef .BorderWidth );_gd .BS =_dde .ToPdfObject ();};if circDef .FillEnabled {_ga ,_aa ,_dg :=circDef .FillColor .R (),circDef .FillColor .G (),circDef .FillColor .B ();_gd .IC =_ba .MakeArrayFromFloats ([]float64 {_ga ,_aa ,_dg });
}else {_gd .IC =_ba .MakeArrayFromIntegers ([]int {});};if circDef .Opacity < 1.0{_gd .CA =_ba .MakeFloat (circDef .Opacity );};_da ,_ee ,_ccg :=_gab (circDef );if _ccg !=nil {return nil ,_ccg ;};_gd .AP =_da ;_gd .Rect =_ba .MakeArrayFromFloats ([]float64 {_ee .Llx ,_ee .Lly ,_ee .Urx ,_ee .Ury });
return _gd .PdfAnnotation ,nil ;};func (_bfd *AppearanceStyle )applyRotation (_fcc *_ba .PdfObjectDictionary ,_dgcf ,_cbf float64 ,_fdaf *_ag .ContentCreator )(float64 ,float64 ){if !_bfd .AllowMK {return _dgcf ,_cbf ;};if _fcc ==nil {return _dgcf ,_cbf ;
};_aeb ,_ :=_ba .GetNumberAsFloat (_fcc .Get ("\u0052"));if _aeb ==0{return _dgcf ,_cbf ;};_daagf :=-_aeb ;_dcdd :=_ffd .Path {Points :[]_ffd .Point {_ffd .NewPoint (0,0).Rotate (_daagf ),_ffd .NewPoint (_dgcf ,0).Rotate (_daagf ),_ffd .NewPoint (0,_cbf ).Rotate (_daagf ),_ffd .NewPoint (_dgcf ,_cbf ).Rotate (_daagf )}}.GetBoundingBox ();
_fdaf .RotateDeg (_aeb );_fdaf .Translate (_dcdd .X ,_dcdd .Y );return _dcdd .Width ,_dcdd .Height ;};func _dbec (_eebb LineAnnotationDef )(*_ba .PdfObjectDictionary ,*_ff .PdfRectangle ,error ){_bbg :=_ff .NewXObjectForm ();_bbg .Resources =_ff .NewPdfPageResources ();
_ggad :="";if _eebb .Opacity < 1.0{_abc :=_ba .MakeDict ();_abc .Set ("\u0063\u0061",_ba .MakeFloat (_eebb .Opacity ));_cec :=_bbg .Resources .AddExtGState ("\u0067\u0073\u0031",_abc );if _cec !=nil {_d .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 ,_cec ;};_ggad ="\u0067\u0073\u0031";};_cfb ,_fdfc ,_fbadc ,_gff :=_gedg (_eebb ,_ggad );if _gff !=nil {return nil ,nil ,_gff ;};_gff =_bbg .SetContentStream (_cfb ,nil );if _gff !=nil {return nil ,nil ,_gff ;};_bbg .BBox =_fdfc .ToPdfObject ();
_ggab :=_ba .MakeDict ();_ggab .Set ("\u004e",_bbg .ToPdfObject ());return _ggab ,_fbadc ,nil ;};
2021-08-13 01:33:42 +00:00
2021-12-14 01:08:28 +00:00
// GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`.
// Implements interface model.FieldAppearanceGenerator.
func (_cabf ImageFieldAppearance )GenerateAppearanceDict (form *_ff .PdfAcroForm ,field *_ff .PdfField ,wa *_ff .PdfAnnotationWidget )(*_ba .PdfObjectDictionary ,error ){_ ,_cfd :=field .GetContext ().(*_ff .PdfFieldButton );if !_cfd {_d .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 ;};_bfdbg ,_def :=_ba .GetDict (wa .AP );if _def &&_cabf .OnlyIfMissing {_d .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 _bfdbg ,nil ;};if form .DR ==nil {form .DR =_ff .NewPdfPageResources ();};switch _cdeg :=field .GetContext ().(type ){case *_ff .PdfFieldButton :if _cdeg .IsPush (){_fafd ,_bgdbd :=_ddcg (_cdeg ,wa ,_cabf .Style ());if _bgdbd !=nil {return nil ,_bgdbd ;
};return _fafd ,nil ;};};return nil ,nil ;};
2021-08-13 01:33:42 +00:00
2021-12-14 01:08:28 +00:00
// ComboboxFieldOptions defines optional parameters for a combobox form field.
type ComboboxFieldOptions struct{
2021-08-13 01:33:42 +00:00
2021-12-14 01:08:28 +00:00
// Choices is the list of string values that can be selected.
Choices []string ;};
2021-10-22 10:53:20 +00:00
2021-12-14 01:08:28 +00:00
// Style returns the appearance style of `fa`. If not specified, returns default style.
func (_efee ImageFieldAppearance )Style ()AppearanceStyle {if _efee ._cgdf !=nil {return *_efee ._cgdf ;};return AppearanceStyle {BorderSize :0.0,BorderColor :_ff .NewPdfColorDeviceGray (0),FillColor :_ff .NewPdfColorDeviceGray (1),DrawAlignmentReticle :false };
};const (SignatureImageLeft SignatureImagePosition =iota ;SignatureImageRight ;SignatureImageTop ;SignatureImageBottom ;);func _cdeda (_gegc RectangleAnnotationDef ,_bcea string )([]byte ,*_ff .PdfRectangle ,*_ff .PdfRectangle ,error ){_effd :=_ffd .Rectangle {X :0,Y :0,Width :_gegc .Width ,Height :_gegc .Height ,FillEnabled :_gegc .FillEnabled ,FillColor :_gegc .FillColor ,BorderEnabled :_gegc .BorderEnabled ,BorderWidth :2*_gegc .BorderWidth ,BorderColor :_gegc .BorderColor ,Opacity :_gegc .Opacity };
_aecf ,_dfab ,_fec :=_effd .Draw (_bcea );if _fec !=nil {return nil ,nil ,nil ,_fec ;};_cgaa :=&_ff .PdfRectangle {};_cgaa .Llx =_gegc .X +_dfab .Llx ;_cgaa .Lly =_gegc .Y +_dfab .Lly ;_cgaa .Urx =_gegc .X +_dfab .Urx ;_cgaa .Ury =_gegc .Y +_dfab .Ury ;
return _aecf ,_dfab ,_cgaa ,nil ;};
2021-10-22 10:53:20 +00:00
2021-12-14 01:08:28 +00:00
// SignatureFieldOpts represents a set of options used to configure
// an appearance widget dictionary.
type SignatureFieldOpts struct{
2021-10-22 10:53:20 +00:00
2021-12-14 01:08:28 +00:00
// Rect represents the area the signature annotation is displayed on.
Rect []float64 ;
2021-08-13 01:33:42 +00:00
2021-12-14 01:08:28 +00:00
// AutoSize specifies if the content of the appearance should be
// scaled to fit in the annotation rectangle.
AutoSize bool ;
2021-08-13 01:33:42 +00:00
2021-12-14 01:08:28 +00:00
// Font specifies the font of the text content.
Font *_ff .PdfFont ;
2021-08-13 01:33:42 +00:00
2021-12-14 01:08:28 +00:00
// FontSize specifies the size of the text content.
FontSize float64 ;
2021-09-23 22:37:42 +00:00
2021-12-14 01:08:28 +00:00
// LineHeight specifies the height of a line of text in the appearance annotation.
LineHeight float64 ;
2021-09-23 22:37:42 +00:00
2021-12-14 01:08:28 +00:00
// TextColor represents the color of the text content displayed.
TextColor _ff .PdfColor ;
2021-10-22 10:53:20 +00:00
2021-12-14 01:08:28 +00:00
// FillColor represents the background color of the appearance annotation area.
FillColor _ff .PdfColor ;
2021-10-22 10:53:20 +00:00
2021-12-14 01:08:28 +00:00
// BorderSize represents border size of the appearance annotation area.
BorderSize float64 ;
2021-10-22 10:53:20 +00:00
2021-12-14 01:08:28 +00:00
// BorderColor represents the border color of the appearance annotation area.
BorderColor _ff .PdfColor ;
2021-05-11 00:01:27 +00:00
2021-12-14 01:08:28 +00:00
// WatermarkImage specifies the image used as a watermark that will be rendered
// behind the signature.
WatermarkImage _cc .Image ;
2021-04-17 13:46:54 +00:00
2021-12-14 01:08:28 +00:00
// Image represents the image used for the signature appearance.
Image _cc .Image ;
2021-03-13 21:28:23 +00:00
2021-12-14 01:08:28 +00:00
// Encoder specifies the image encoder used for image signature. Defaults to flate encoder.
Encoder _ba .StreamEncoder ;
2021-08-13 01:33:42 +00:00
2021-12-14 01:08:28 +00:00
// ImagePosition specifies the image location relative to the text signature.
ImagePosition SignatureImagePosition ;};
2021-08-13 01:33:42 +00:00
2021-09-23 22:37:42 +00:00
// AppearanceStyle defines style parameters for appearance stream generation.
type AppearanceStyle struct{
2021-08-13 01:33:42 +00:00
2021-09-23 22:37:42 +00:00
// How much of Rect height to fill when autosizing text.
AutoFontSizeFraction float64 ;
2021-08-13 01:33:42 +00:00
2021-09-23 22:37:42 +00:00
// CheckmarkRune is a rune used for check mark in checkboxes (for ZapfDingbats font).
2021-12-14 01:08:28 +00:00
CheckmarkRune rune ;BorderSize float64 ;BorderColor _ff .PdfColor ;FillColor _ff .PdfColor ;
2021-08-13 01:33:42 +00:00
2021-09-23 22:37:42 +00:00
// Multiplier for lineheight for multi line text.
MultilineLineHeight float64 ;MultilineVAlignMiddle bool ;
2021-08-13 01:33:42 +00:00
2021-09-23 22:37:42 +00:00
// 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).
2021-12-14 01:08:28 +00:00
MarginLeft *float64 ;};func _aegf (_dgdb *_ff .PdfField )string {if _dgdb ==nil {return "";};_bcf ,_gbeg :=_dgdb .GetContext ().(*_ff .PdfFieldText );if !_gbeg {return _aegf (_dgdb .Parent );};if _bcf .DA !=nil {return _bcf .DA .Str ();};return _aegf (_bcf .Parent );
};
2021-09-23 22:37:42 +00:00
2021-12-14 01:08:28 +00:00
// AppearanceFontStyle defines font style characteristics for form fields,
// used in the filling/flattening process.
type AppearanceFontStyle struct{
2021-08-13 01:33:42 +00:00
2021-12-14 01:08:28 +00:00
// 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 ;
2021-08-13 01:33:42 +00:00
2021-12-14 01:08:28 +00:00
// 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 ;
2021-09-23 22:37:42 +00:00
2021-12-14 01:08:28 +00:00
// 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 ;
2021-09-23 22:37:42 +00:00
2021-12-14 01:08:28 +00:00
// 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 ;};
2021-09-23 22:37:42 +00:00
2021-12-14 01:08:28 +00:00
// SetStyle applies appearance `style` to `fa`.
func (_eff *FieldAppearance )SetStyle (style AppearanceStyle ){_eff ._ae =&style };func _ccga (_cbc *_ff .PdfAnnotationWidget ,_ddd *_ff .PdfFieldText ,_daag *_ff .PdfPageResources ,_bgee AppearanceStyle )(*_ba .PdfObjectDictionary ,error ){_aba :=_ff .NewPdfPageResources ();
_dc ,_ccf :=_ba .GetArray (_cbc .Rect );if !_ccf {return nil ,_e .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_ad ,_eac :=_ff .NewPdfRectangle (*_dc );if _eac !=nil {return nil ,_eac ;};_fc ,_ceg :=_ad .Width (),_ad .Height ();
_cg ,_effg :=_fc ,_ceg ;_dda ,_de :=_ba .GetDict (_cbc .MK );if _de {_edec ,_ :=_ba .GetDict (_cbc .BS );_fbc :=_bgee .applyAppearanceCharacteristics (_dda ,_edec ,nil );if _fbc !=nil {return nil ,_fbc ;};};_ced ,_eac :=_ag .NewContentStreamParser (_aegf (_ddd .PdfField )).Parse ();
if _eac !=nil {return nil ,_eac ;};_bea :=_ag .NewContentCreator ();if _bgee .BorderSize > 0{_fde (_bea ,_bgee ,_fc ,_ceg );};if _bgee .DrawAlignmentReticle {_gecb :=_bgee ;_gecb .BorderSize =0.2;_gegf (_bea ,_gecb ,_fc ,_ceg );};_bea .Add_BMC ("\u0054\u0078");
_bea .Add_q ();_fc ,_ceg =_bgee .applyRotation (_dda ,_fc ,_ceg ,_bea );_bea .Add_BT ();_gcg ,_fdfd ,_eac :=_bgee .processDA (_ddd .PdfField ,_ced ,_daag ,_aba ,_bea );if _eac !=nil {return nil ,_eac ;};_ffe :=_gcg .Font ;_eg :=_gcg .Size ;_cag :=_ba .MakeName (_gcg .Name );
_cegg :=_eg ==0;if _cegg &&_fdfd {_eg =_ceg *_bgee .AutoFontSizeFraction ;};_fff :=_ffe .Encoder ();if _fff ==nil {_d .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");
_fff =_b .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};_bff ,_eac :=_ffe .GetFontDescriptor ();if _eac !=nil {_d .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 _bgc string ;if _fdc ,_aeg :=_ba .GetString (_ddd .V );_aeg {_bgc =_fdc .Decoded ();};if len (_bgc )==0{return nil ,nil ;};_fbcb :=[]string {_bgc };_ac :=false ;if _ddd .Flags ().Has (_ff .FieldFlagMultiline ){_ac =true ;_bgc =_ab .Replace (_bgc ,"\u000d\u000a","\u000a",-1);
_bgc =_ab .Replace (_bgc ,"\u000d","\u000a",-1);_fbcb =_ab .Split (_bgc ,"\u000a");};_agb :=make ([]string ,len (_fbcb ));copy (_agb ,_fbcb );_aec :=_bgee .MultilineLineHeight ;_gag :=0.0;_fda :=0;if _fff !=nil {for _eg >=0{_cd :=make ([]string ,len (_fbcb ));
copy (_cd ,_fbcb );_gfa :=make ([]string ,len (_agb ));copy (_gfa ,_agb );_gag =0.0;_fda =0;_gba :=len (_cd );_dae :=0;for _dae < _gba {var _gaga float64 ;_cbg :=-1;_aed :=_ca ;if _bgee .MarginLeft !=nil {_aed =*_bgee .MarginLeft ;};for _bgf ,_ddeb :=range _cd [_dae ]{if _ddeb ==' '{_cbg =_bgf ;
_gaga =_aed ;};_eaae ,_cgg :=_ffe .GetRuneMetrics (_ddeb );if !_cgg {_d .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",_ddeb );
continue ;};_aed +=_eaae .Wx ;if _ac &&!_cegg &&_eg *_aed /1000.0> _fc &&_cbg > 0{_cbd :=_cd [_dae ][_cbg +1:];_fbf :=_gfa [_dae ][_cbg +1:];if _dae < len (_cd )-1{_cd =append (_cd [:_dae +1],_cd [_dae :]...);_cd [_dae +1]=_cbd ;_gfa =append (_gfa [:_dae +1],_gfa [_dae :]...);
_gfa [_dae +1]=_fbf ;}else {_cd =append (_cd ,_cbd );_gfa =append (_gfa ,_fbf );};_gba ++;_cd [_dae ]=_cd [_dae ][0:_cbg ];_gfa [_dae ]=_gfa [_dae ][0:_cbg ];_aed =_gaga ;break ;};};if _aed > _gag {_gag =_aed ;};_cd [_dae ]=string (_fff .Encode (_cd [_dae ]));
if len (_cd [_dae ])> 0{_fda ++;};_dae ++;};_adc :=_eg ;if _fda > 1{_adc *=_aec ;};_afb :=float64 (_fda )*_adc ;if _cegg ||_afb <=_ceg {_fbcb =_cd ;_agb =_gfa ;break ;};_eg --;};};_egg :=_ca ;if _bgee .MarginLeft !=nil {_egg =*_bgee .MarginLeft ;};if _eg ==0||_cegg &&_gag > 0&&_egg +_gag *_eg /1000.0> _fc {_eg =0.95*1000.0*(_fc -_egg )/_gag ;
};_bc :=_ebe ;{if _afe ,_caf :=_ba .GetIntVal (_ddd .Q );_caf {switch _afe {case 0:_bc =_ebe ;case 1:_bc =_fdf ;case 2:_bc =_ed ;default:_d .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",_afe );
};};};_bfe :=_eg ;if _ac &&_fda > 1{_bfe =_aec *_eg ;};var _gbc float64 ;if _bff !=nil {_gbc ,_eac =_bff .GetCapHeight ();if _eac !=nil {_d .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",_eac );
};};if int (_gbc )<=0{_d .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");
_gbc =1000;};_eee :=_gbc /1000.0*_eg ;_bdf :=0.0;{_fffe :=float64 (_fda )*_bfe ;if _cegg &&_bdf +_fffe > _ceg {_eg =0.95*(_ceg -_bdf )/float64 (_fda );_bfe =_eg ;if _ac &&_fda > 1{_bfe =_aec *_eg ;};_eee =_gbc /1000.0*_eg ;_fffe =float64 (_fda )*_bfe ;
};if _ceg > _fffe {if _ac {if _bgee .MultilineVAlignMiddle {_cdd :=(_ceg -(_fffe +_eee ))/2.0;_ccbb :=_cdd +_fffe +_eee -_bfe ;_bdf =_ccbb ;if _fda > 1{_bdf =_bdf +(_fffe /_eg *float64 (_fda ))-_bfe -_eee ;};if _bdf < _fffe {_bdf =(_ceg -_eee )/2.0;};}else {_bdf =_ceg -_bfe ;
if _bdf > _eg {_bdf -=_eg *0.5;};};}else {_bdf =(_ceg -_eee )/2.0;};};};_bea .Add_Tf (*_cag ,_eg );_bea .Add_Td (_egg ,_bdf );_eeb :=_egg ;_abab :=_egg ;for _ddb ,_dca :=range _fbcb {_fcd :=0.0;for _ ,_dfc :=range _agb [_ddb ]{_gbe ,_ace :=_ffe .GetRuneMetrics (_dfc );
if !_ace {continue ;};_fcd +=_gbe .Wx ;};_fce :=_fcd /1000.0*_eg ;_fg :=_fc -_fce ;var _gdg float64 ;switch _bc {case _ebe :_gdg =_eeb ;case _fdf :_gdg =_fg /2;case _ed :_gdg =_fg ;};_egg =_gdg -_abab ;if _egg > 0.0{_bea .Add_Td (_egg ,0);};_abab =_gdg ;
_bea .Add_Tj (*_ba .MakeString (_dca ));if _ddb < len (_fbcb )-1{_bea .Add_Td (0,-_eg *_aec );};};_bea .Add_ET ();_bea .Add_Q ();_bea .Add_EMC ();_ged :=_ff .NewXObjectForm ();_ged .Resources =_aba ;_ged .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_cg ,_effg });
_ged .SetContentStream (_bea .Bytes (),_ebg ());_eec :=_ba .MakeDict ();_eec .Set ("\u004e",_ged .ToPdfObject ());return _eec ,nil ;};
2021-09-23 22:37:42 +00:00
2021-12-14 01:08:28 +00:00
// 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 *_ff .PdfSignature ,lines []*SignatureLine ,opts *SignatureFieldOpts )(*_ff .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");
};_cecd ,_bccd :=_acee (lines ,opts );if _bccd !=nil {return nil ,_bccd ;};_cegf :=_ff .NewPdfFieldSignature (signature );_cegf .Rect =_ba .MakeArrayFromFloats (opts .Rect );_cegf .AP =_cecd ;return _cegf ,nil ;};
2021-09-23 22:37:42 +00:00
2021-12-14 01:08:28 +00:00
// SignatureLine represents a line of information in the signature field appearance.
type SignatureLine struct{Desc string ;Text string ;};
2021-09-23 22:37:42 +00:00
2021-12-14 01:08:28 +00:00
// CreateRectangleAnnotation creates a rectangle annotation object that can be added to page PDF annotations.
func CreateRectangleAnnotation (rectDef RectangleAnnotationDef )(*_ff .PdfAnnotation ,error ){_cff :=_ff .NewPdfAnnotationSquare ();if rectDef .BorderEnabled {_gecbb ,_aaa ,_ccd :=rectDef .BorderColor .R (),rectDef .BorderColor .G (),rectDef .BorderColor .B ();
_cff .C =_ba .MakeArrayFromFloats ([]float64 {_gecbb ,_aaa ,_ccd });_ffea :=_ff .NewBorderStyle ();_ffea .SetBorderWidth (rectDef .BorderWidth );_cff .BS =_ffea .ToPdfObject ();};if rectDef .FillEnabled {_cdec ,_cdbg ,_fgab :=rectDef .FillColor .R (),rectDef .FillColor .G (),rectDef .FillColor .B ();
_cff .IC =_ba .MakeArrayFromFloats ([]float64 {_cdec ,_cdbg ,_fgab });}else {_cff .IC =_ba .MakeArrayFromIntegers ([]int {});};if rectDef .Opacity < 1.0{_cff .CA =_ba .MakeFloat (rectDef .Opacity );};_cagd ,_gbaa ,_abcb :=_eebg (rectDef );if _abcb !=nil {return nil ,_abcb ;
};_cff .AP =_cagd ;_cff .Rect =_ba .MakeArrayFromFloats ([]float64 {_gbaa .Llx ,_gbaa .Lly ,_gbaa .Urx ,_gbaa .Ury });return _cff .PdfAnnotation ,nil ;};func _eebg (_bgea RectangleAnnotationDef )(*_ba .PdfObjectDictionary ,*_ff .PdfRectangle ,error ){_eeed :=_ff .NewXObjectForm ();
_eeed .Resources =_ff .NewPdfPageResources ();_cefc :="";if _bgea .Opacity < 1.0{_gafcf :=_ba .MakeDict ();_gafcf .Set ("\u0063\u0061",_ba .MakeFloat (_bgea .Opacity ));_gafcf .Set ("\u0043\u0041",_ba .MakeFloat (_bgea .Opacity ));_gde :=_eeed .Resources .AddExtGState ("\u0067\u0073\u0031",_gafcf );
if _gde !=nil {_d .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 ,_gde ;};_cefc ="\u0067\u0073\u0031";};_cbgcf ,_eea ,_ecbd ,_bbf :=_cdeda (_bgea ,_cefc );
if _bbf !=nil {return nil ,nil ,_bbf ;};_bbf =_eeed .SetContentStream (_cbgcf ,nil );if _bbf !=nil {return nil ,nil ,_bbf ;};_eeed .BBox =_eea .ToPdfObject ();_ddbg :=_ba .MakeDict ();_ddbg .Set ("\u004e",_eeed .ToPdfObject ());return _ddbg ,_ecbd ,nil ;
};func _gab (_ge CircleAnnotationDef )(*_ba .PdfObjectDictionary ,*_ff .PdfRectangle ,error ){_cb :=_ff .NewXObjectForm ();_cb .Resources =_ff .NewPdfPageResources ();_bd :="";if _ge .Opacity < 1.0{_eb :=_ba .MakeDict ();_eb .Set ("\u0063\u0061",_ba .MakeFloat (_ge .Opacity ));
_eb .Set ("\u0043\u0041",_ba .MakeFloat (_ge .Opacity ));_aab :=_cb .Resources .AddExtGState ("\u0067\u0073\u0031",_eb );if _aab !=nil {_d .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 ,_aab ;};_bd ="\u0067\u0073\u0031";};_fe ,_dac ,_gb ,_gec :=_bge (_ge ,_bd );if _gec !=nil {return nil ,nil ,_gec ;};_gec =_cb .SetContentStream (_fe ,nil );if _gec !=nil {return nil ,nil ,_gec ;};_cb .BBox =_dac .ToPdfObject ();_gbg :=_ba .MakeDict ();
_gbg .Set ("\u004e",_cb .ToPdfObject ());return _gbg ,_gb ,nil ;};
2021-09-23 22:37:42 +00:00
2021-12-14 01:08:28 +00:00
// 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 (_adee ImageFieldAppearance )WrapContentStream (page *_ff .PdfPage )error {_abf ,_fdbc :=page .GetAllContentStreams ();if _fdbc !=nil {return _fdbc ;};_abag :=_ag .NewContentStreamParser (_abf );_defg ,_fdbc :=_abag .Parse ();if _fdbc !=nil {return _fdbc ;
};_defg .WrapIfNeeded ();_gaaf :=[]string {_defg .String ()};return page .SetContentStreams (_gaaf ,_ebg ());};
2021-09-23 22:37:42 +00:00
2021-12-14 01:08:28 +00:00
// NewSignatureFieldOpts returns a new initialized instance of options
// used to generate a signature appearance.
func NewSignatureFieldOpts ()*SignatureFieldOpts {return &SignatureFieldOpts {Font :_ff .DefaultFont (),FontSize :10,LineHeight :1,AutoSize :true ,TextColor :_ff .NewPdfColorDeviceGray (0),BorderColor :_ff .NewPdfColorDeviceGray (0),FillColor :_ff .NewPdfColorDeviceGray (1),Encoder :_ba .NewFlateEncoder (),ImagePosition :SignatureImageLeft };
};
2021-09-23 22:37:42 +00:00
2021-12-14 01:08:28 +00:00
// 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 *_ff .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 _ffd .LineEndingStyle ;LineEndingStyle2 _ffd .LineEndingStyle ;};
2021-09-23 22:37:42 +00:00
2021-12-14 01:08:28 +00:00
// CheckboxFieldOptions defines optional parameters for a checkbox field a form.
type CheckboxFieldOptions struct{Checked bool ;};func _cad (_cae ,_ffb float64 ,_cada *_ff .Image ,_agfc AppearanceStyle )(*_ff .XObjectForm ,error ){_daad ,_ebga :=_ff .NewXObjectImageFromImage (_cada ,nil ,_ba .NewFlateEncoder ());if _ebga !=nil {return nil ,_ebga ;
};_daad .Decode =_ba .MakeArrayFromFloats ([]float64 {0.0,1.0,0.0,1.0,0.0,1.0});_add :=_ff .NewPdfPageResources ();_add .ProcSet =_ba .MakeArray (_ba .MakeName ("\u0050\u0044\u0046"),_ba .MakeName ("\u0049\u006d\u0061\u0067\u0065\u0043"));_add .SetXObjectImageByName (_ba .PdfObjectName ("\u0049\u006d\u0030"),_daad );
_cbgc :=_ag .NewContentCreator ();_cbgc .Add_q ();_cbgc .Add_cm (float64 (_cada .Width ),0,0,float64 (_cada .Height ),0,0);_cbgc .Add_Do ("\u0049\u006d\u0030");_cbgc .Add_Q ();_cdbb :=_ff .NewXObjectForm ();_cdbb .FormType =_ba .MakeInteger (1);_cdbb .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,float64 (_cada .Width ),float64 (_cada .Height )});
_cdbb .Resources =_add ;_cdbb .SetContentStream (_cbgc .Bytes (),_ebg ());return _cdbb ,nil ;};
2021-09-23 22:37:42 +00:00
2021-12-14 01:08:28 +00:00
// ImageFieldAppearance implements interface model.FieldAppearanceGenerator and generates appearance streams
// for attaching an image to a button field.
type ImageFieldAppearance struct{OnlyIfMissing bool ;_cgdf *AppearanceStyle ;};func (_dabd *AppearanceStyle )processDA (_fbg *_ff .PdfField ,_dcc *_ag .ContentStreamOperations ,_cgb ,_becf *_ff .PdfPageResources ,_gaa *_ag .ContentCreator )(*AppearanceFont ,bool ,error ){var _bcb *AppearanceFont ;
var _bba bool ;if _dabd .Fonts !=nil {if _dabd .Fonts .Fallback !=nil {_bcb =_dabd .Fonts .Fallback ;};if _beae :=_dabd .Fonts .FieldFallbacks ;_beae !=nil {if _bef ,_cgd :=_beae [_fbg .PartialName ()];_cgd {_bcb =_bef ;}else if _dgdf ,_gdf :=_fbg .FullName ();
_gdf ==nil {if _bdc ,_fbca :=_beae [_dgdf ];_fbca {_bcb =_bdc ;};};};_bba =_dabd .Fonts .ForceReplace ;};var _aabe string ;var _gabb float64 ;var _ddf bool ;if _dcc !=nil {for _ ,_bgda :=range *_dcc {if _bgda .Operand =="\u0054\u0066"&&len (_bgda .Params )==2{if _beaf ,_bage :=_ba .GetNameVal (_bgda .Params [0]);
_bage {_aabe =_beaf ;};if _bbbb ,_fbee :=_ba .GetNumberAsFloat (_bgda .Params [1]);_fbee ==nil {_gabb =_bbbb ;};_ddf =true ;continue ;};_gaa .AddOperand (*_bgda );};};var _gagb *AppearanceFont ;var _dabda _ba .PdfObject ;if _bba &&_bcb !=nil {_gagb =_bcb ;
}else {if _cgb !=nil &&_aabe !=""{if _cfcc ,_ecgb :=_cgb .GetFontByName (*_ba .MakeName (_aabe ));_ecgb {if _eddc ,_fbfc :=_ff .NewPdfFontFromPdfObject (_cfcc );_fbfc ==nil {_dabda =_cfcc ;_gagb =&AppearanceFont {Name :_aabe ,Font :_eddc ,Size :_gabb };
}else {_d .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",_fbfc );
};};};if _gagb ==nil &&_bcb !=nil {_gagb =_bcb ;};if _gagb ==nil {_cdc ,_gee :=_ff .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");if _gee !=nil {return nil ,false ,_gee ;};_gagb =&AppearanceFont {Name :"\u0048\u0065\u006c\u0076",Font :_cdc ,Size :_gabb };
};};if _gagb .Size <=0&&_dabd .Fonts !=nil &&_dabd .Fonts .FallbackSize > 0{_gagb .Size =_dabd .Fonts .FallbackSize ;};_gcge :=*_ba .MakeName (_gagb .Name );if _dabda ==nil {_dabda =_gagb .Font .ToPdfObject ();};if _cgb !=nil &&!_cgb .HasFontByName (_gcge ){_cgb .SetFontByName (_gcge ,_dabda );
};if _becf !=nil &&!_becf .HasFontByName (_gcge ){_becf .SetFontByName (_gcge ,_dabda );};return _gagb ,_ddf ,nil ;};
2021-09-23 22:37:42 +00:00
2021-12-14 01:08:28 +00:00
// 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 *_ff .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_ff .PdfColorDeviceRGB ;Opacity float64 ;};func _debc (_ebab _cc .Image ,_dgdc string ,_ebcb *SignatureFieldOpts ,_adg []float64 ,_aggb *_ag .ContentCreator )(*_ba .PdfObjectName ,*_ff .XObjectImage ,error ){_fcdg ,_caaf :=_ff .DefaultImageHandler {}.NewImageFromGoImage (_ebab );
if _caaf !=nil {return nil ,nil ,_caaf ;};_cfcf ,_caaf :=_ff .NewXObjectImageFromImage (_fcdg ,nil ,_ebcb .Encoder );if _caaf !=nil {return nil ,nil ,_caaf ;};_cefeg ,_aee :=float64 (*_cfcf .Width ),float64 (*_cfcf .Height );_agff :=_adg [2]-_adg [0];_dadg :=_adg [3]-_adg [1];
if _ebcb .AutoSize {_dbc :=_c .Min (_agff /_cefeg ,_dadg /_aee );_cefeg *=_dbc ;_aee *=_dbc ;_adg [0]=_adg [0]+(_agff /2)-(_cefeg /2);_adg [1]=_adg [1]+(_dadg /2)-(_aee /2);};var _geb *_ba .PdfObjectName ;if _gcf ,_fccc :=_ba .GetName (_cfcf .Name );_fccc {_geb =_gcf ;
}else {_geb =_ba .MakeName (_dgdc );};if _aggb !=nil {_aggb .Add_q ().Translate (_adg [0],_adg [1]).Scale (_cefeg ,_aee ).Add_Do (*_geb ).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 _geb ,_cfcf ,nil ;};func _ddcg (_eacd *_ff .PdfFieldButton ,_eae *_ff .PdfAnnotationWidget ,_dbeg AppearanceStyle )(*_ba .PdfObjectDictionary ,error ){_bfba ,_agdf :=_ba .GetArray (_eae .Rect );if !_agdf {return nil ,_e .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");
};_aaeg ,_dfcb :=_ff .NewPdfRectangle (*_bfba );if _dfcb !=nil {return nil ,_dfcb ;};_dagd ,_bgfb :=_aaeg .Width (),_aaeg .Height ();_bbeb :=_ag .NewContentCreator ();if _dbeg .BorderSize > 0{_fde (_bbeb ,_dbeg ,_dagd ,_bgfb );};if _dbeg .DrawAlignmentReticle {_dbae :=_dbeg ;
_dbae .BorderSize =0.2;_gegf (_bbeb ,_dbae ,_dagd ,_bgfb );};_acdc :=_eacd .GetFillImage ();_beaec ,_dfcb :=_cad (_dagd ,_bgfb ,_acdc ,_dbeg );if _dfcb !=nil {return nil ,_dfcb ;};_gfac ,_bead :=_ba .GetDict (_eae .MK );if _bead {_gfac .Set ("\u006c",_beaec .ToPdfObject ());
};_fef :=_ba .MakeDict ();_fef .Set ("\u0046\u0052\u004d",_beaec .ToPdfObject ());_ccgf :=_ff .NewPdfPageResources ();_ccgf .ProcSet =_ba .MakeArray (_ba .MakeName ("\u0050\u0044\u0046"));_ccgf .XObject =_fef ;_afcc :=_dagd -2;_fcaf :=_bgfb -2;_bbeb .Add_q ();
_bbeb .Add_re (1,1,_afcc ,_fcaf );_bbeb .Add_W ();_bbeb .Add_n ();_afcc -=2;_fcaf -=2;_bbeb .Add_q ();_bbeb .Add_re (2,2,_afcc ,_fcaf );_bbeb .Add_W ();_bbeb .Add_n ();_agce :=_c .Min (_afcc /float64 (_acdc .Width ),_fcaf /float64 (_acdc .Height ));_bbeb .Add_cm (_agce ,0,0,_agce ,(_dagd /2)-(float64 (_acdc .Width )*_agce /2)+2,2);
_bbeb .Add_Do ("\u0046\u0052\u004d");_bbeb .Add_Q ();_bbeb .Add_Q ();_ggdg :=_ff .NewXObjectForm ();_ggdg .FormType =_ba .MakeInteger (1);_ggdg .Resources =_ccgf ;_ggdg .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_dagd ,_bgfb });_ggdg .Matrix =_ba .MakeArrayFromFloats ([]float64 {1.0,0.0,0.0,1.0,0.0,0.0});
_ggdg .SetContentStream (_bbeb .Bytes (),_ebg ());_dbea :=_ba .MakeDict ();_dbea .Set ("\u004e",_ggdg .ToPdfObject ());return _dbea ,nil ;};
// CreateLineAnnotation creates a line annotation object that can be added to page PDF annotations.
func CreateLineAnnotation (lineDef LineAnnotationDef )(*_ff .PdfAnnotation ,error ){_aeaf :=_ff .NewPdfAnnotationLine ();_aeaf .L =_ba .MakeArrayFromFloats ([]float64 {lineDef .X1 ,lineDef .Y1 ,lineDef .X2 ,lineDef .Y2 });_cceb :=_ba .MakeName ("\u004e\u006f\u006e\u0065");
if lineDef .LineEndingStyle1 ==_ffd .LineEndingStyleArrow {_cceb =_ba .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");};_cded :=_ba .MakeName ("\u004e\u006f\u006e\u0065");if lineDef .LineEndingStyle2 ==_ffd .LineEndingStyleArrow {_cded =_ba .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");
};_aeaf .LE =_ba .MakeArray (_cceb ,_cded );if lineDef .Opacity < 1.0{_aeaf .CA =_ba .MakeFloat (lineDef .Opacity );};_dgcfc ,_bfdd ,_gddf :=lineDef .LineColor .R (),lineDef .LineColor .G (),lineDef .LineColor .B ();_aeaf .IC =_ba .MakeArrayFromFloats ([]float64 {_dgcfc ,_bfdd ,_gddf });
_aeaf .C =_ba .MakeArrayFromFloats ([]float64 {_dgcfc ,_bfdd ,_gddf });_ccgb :=_ff .NewBorderStyle ();_ccgb .SetBorderWidth (lineDef .LineWidth );_aeaf .BS =_ccgb .ToPdfObject ();_adgf ,_eaea ,_cga :=_dbec (lineDef );if _cga !=nil {return nil ,_cga ;};
_aeaf .AP =_adgf ;_aeaf .Rect =_ba .MakeArrayFromFloats ([]float64 {_eaea .Llx ,_eaea .Lly ,_eaea .Urx ,_eaea .Ury });return _aeaf .PdfAnnotation ,nil ;};
// ImageFieldOptions defines optional parameters for a push button with image attach capability form field.
type ImageFieldOptions struct{Image *_ff .Image ;_bee AppearanceStyle ;};
// 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 *_ff .PdfPage ,name string ,rect []float64 ,opt ComboboxFieldOptions )(*_ff .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");
};_fbef :=_ff .NewPdfField ();_aebc :=&_ff .PdfFieldChoice {};_fbef .SetContext (_aebc );_aebc .PdfField =_fbef ;_aebc .T =_ba .MakeString (name );_aebc .Opt =_ba .MakeArray ();for _ ,_efe :=range opt .Choices {_aebc .Opt .Append (_ba .MakeString (_efe ));
};_aebc .SetFlag (_ff .FieldFlagCombo );_daab :=_ff .NewPdfAnnotationWidget ();_daab .Rect =_ba .MakeArrayFromFloats (rect );_daab .P =page .ToPdfObject ();_daab .F =_ba .MakeInteger (4);_daab .Parent =_aebc .ToPdfObject ();_aebc .Annotations =append (_aebc .Annotations ,_daab );
return _aebc ,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 *_ff .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_ff .PdfColorDeviceRGB ;Opacity float64 ;};
// 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 *_ff .PdfPage ,name string ,rect []float64 ,opt CheckboxFieldOptions )(*_ff .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");
};_bfdb ,_bdgb :=_ff .NewStandard14Font (_ff .ZapfDingbatsName );if _bdgb !=nil {return nil ,_bdgb ;};_gccc :=_ff .NewPdfField ();_eadc :=&_ff .PdfFieldButton {};_gccc .SetContext (_eadc );_eadc .PdfField =_gccc ;_eadc .T =_ba .MakeString (name );_eadc .SetType (_ff .ButtonTypeCheckbox );
_dbgc :="\u004f\u0066\u0066";if opt .Checked {_dbgc ="\u0059\u0065\u0073";};_eadc .V =_ba .MakeName (_dbgc );_dgcc :=_ff .NewPdfAnnotationWidget ();_dgcc .Rect =_ba .MakeArrayFromFloats (rect );_dgcc .P =page .ToPdfObject ();_dgcc .F =_ba .MakeInteger (4);
_dgcc .Parent =_eadc .ToPdfObject ();_dbcb :=rect [2]-rect [0];_dcag :=rect [3]-rect [1];var _beaee _a .Buffer ;_beaee .WriteString ("\u0071\u000a");_beaee .WriteString ("\u0030 \u0030\u0020\u0031\u0020\u0072\u0067\n");_beaee .WriteString ("\u0042\u0054\u000a");
_beaee .WriteString ("\u002f\u005a\u0061D\u0062\u0020\u0031\u0032\u0020\u0054\u0066\u000a");_beaee .WriteString ("\u0045\u0054\u000a");_beaee .WriteString ("\u0051\u000a");_bae :=_ag .NewContentCreator ();_bae .Add_q ();_bae .Add_rg (0,0,1);_bae .Add_BT ();
_bae .Add_Tf (*_ba .MakeName ("\u005a\u0061\u0044\u0062"),12);_bae .Add_Td (0,0);_bae .Add_ET ();_bae .Add_Q ();_afc :=_ff .NewXObjectForm ();_afc .SetContentStream (_bae .Bytes (),_ba .NewRawEncoder ());_afc .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_dbcb ,_dcag });
_afc .Resources =_ff .NewPdfPageResources ();_afc .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_bfdb .ToPdfObject ());_bae =_ag .NewContentCreator ();_bae .Add_q ();_bae .Add_re (0,0,_dbcb ,_dcag );_bae .Add_W ().Add_n ();_bae .Add_rg (0,0,1);
_bae .Translate (0,3.0);_bae .Add_BT ();_bae .Add_Tf (*_ba .MakeName ("\u005a\u0061\u0044\u0062"),12);_bae .Add_Td (0,0);_bae .Add_Tj (*_ba .MakeString ("\u0034"));_bae .Add_ET ();_bae .Add_Q ();_cbb :=_ff .NewXObjectForm ();_cbb .SetContentStream (_bae .Bytes (),_ba .NewRawEncoder ());
_cbb .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_dbcb ,_dcag });_cbb .Resources =_ff .NewPdfPageResources ();_cbb .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_bfdb .ToPdfObject ());_dfa :=_ba .MakeDict ();_dfa .Set ("\u004f\u0066\u0066",_afc .ToPdfObject ());
_dfa .Set ("\u0059\u0065\u0073",_cbb .ToPdfObject ());_fca :=_ba .MakeDict ();_fca .Set ("\u004e",_dfa );_dgcc .AP =_fca ;_dgcc .AS =_ba .MakeName (_dbgc );_eadc .Annotations =append (_eadc .Annotations ,_dgcc );return _eadc ,nil ;};
2021-09-23 22:37:42 +00:00
2021-10-22 10:53:20 +00:00
// SignatureImagePosition specifies the image signature location relative to the text signature.
// If text signature is not defined, this position will be ignored.
2021-12-14 01:08:28 +00:00
type SignatureImagePosition int ;
2021-09-23 22:37:42 +00:00
2021-12-14 01:08:28 +00:00
// 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 *_ff .PdfPage ,name string ,rect []float64 ,opt TextFieldOptions )(*_ff .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");};_agea :=_ff .NewPdfField ();_dead :=&_ff .PdfFieldText {};_agea .SetContext (_dead );_dead .PdfField =_agea ;_dead .T =_ba .MakeString (name );
if opt .MaxLen > 0{_dead .MaxLen =_ba .MakeInteger (int64 (opt .MaxLen ));};if len (opt .Value )> 0{_dead .V =_ba .MakeString (opt .Value );};_adf :=_ff .NewPdfAnnotationWidget ();_adf .Rect =_ba .MakeArrayFromFloats (rect );_adf .P =page .ToPdfObject ();
_adf .F =_ba .MakeInteger (4);_adf .Parent =_dead .ToPdfObject ();_dead .Annotations =append (_dead .Annotations ,_adf );return _dead ,nil ;};
2021-10-22 10:53:20 +00:00
2021-12-14 01:08:28 +00:00
// 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 *_ff .PdfPage ,name string ,rect []float64 ,opt ImageFieldOptions )(*_ff .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");
};_fafa :=_ff .NewPdfField ();_fcac :=&_ff .PdfFieldButton {};_fcac .PdfField =_fafa ;_fafa .SetContext (_fcac );_fcac .SetType (_ff .ButtonTypePush );_fcac .T =_ba .MakeString (name );_dabb :=_ff .NewPdfAnnotationWidget ();_dabb .Rect =_ba .MakeArrayFromFloats (rect );
_dabb .P =page .ToPdfObject ();_dabb .F =_ba .MakeInteger (4);_dabb .Parent =_fcac .ToPdfObject ();_bbbd :=rect [2]-rect [0];_aegb :=rect [3]-rect [1];_ddcd :=opt ._bee ;_gae :=_ag .NewContentCreator ();if _ddcd .BorderSize > 0{_fde (_gae ,_ddcd ,_bbbd ,_aegb );
};if _ddcd .DrawAlignmentReticle {_dcaeg :=_ddcd ;_dcaeg .BorderSize =0.2;_gegf (_gae ,_dcaeg ,_bbbd ,_aegb );};_gcd ,_bacd :=_cad (_bbbd ,_aegb ,opt .Image ,_ddcd );if _bacd !=nil {return nil ,_bacd ;};_gbcc ,_bdcg :=_ba .GetDict (_dabb .MK );if _bdcg {_gbcc .Set ("\u006c",_gcd .ToPdfObject ());
};_afca :=_ba .MakeDict ();_afca .Set ("\u0046\u0052\u004d",_gcd .ToPdfObject ());_egc :=_ff .NewPdfPageResources ();_egc .ProcSet =_ba .MakeArray (_ba .MakeName ("\u0050\u0044\u0046"));_egc .XObject =_afca ;_dgac :=_bbbd -2;_bdfb :=_aegb -2;_gae .Add_q ();
_gae .Add_re (1,1,_dgac ,_bdfb );_gae .Add_W ();_gae .Add_n ();_dgac -=2;_bdfb -=2;_gae .Add_q ();_gae .Add_re (2,2,_dgac ,_bdfb );_gae .Add_W ();_gae .Add_n ();_ddgg :=_c .Min (_dgac /float64 (opt .Image .Width ),_bdfb /float64 (opt .Image .Height ));
_gae .Add_cm (_ddgg ,0,0,_ddgg ,(_bbbd /2)-(float64 (opt .Image .Width )*_ddgg /2)+2,2);_gae .Add_Do ("\u0046\u0052\u004d");_gae .Add_Q ();_gae .Add_Q ();_bdfe :=_ff .NewXObjectForm ();_bdfe .FormType =_ba .MakeInteger (1);_bdfe .Resources =_egc ;_bdfe .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_bbbd ,_aegb });
_bdfe .Matrix =_ba .MakeArrayFromFloats ([]float64 {1.0,0.0,0.0,1.0,0.0,0.0});_bdfe .SetContentStream (_gae .Bytes (),_ebg ());_ceag :=_ba .MakeDict ();_ceag .Set ("\u004e",_bdfe .ToPdfObject ());_dabb .AP =_ceag ;_fcac .Annotations =append (_fcac .Annotations ,_dabb );
return _fcac ,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 (_eaag FieldAppearance )WrapContentStream (page *_ff .PdfPage )error {_gadb ,_fegg :=page .GetAllContentStreams ();if _fegg !=nil {return _fegg ;};_bacb :=_ag .NewContentStreamParser (_gadb );_bfda ,_fegg :=_bacb .Parse ();if _fegg !=nil {return _fegg ;
};_bfda .WrapIfNeeded ();_bgcb :=[]string {_bfda .String ()};return page .SetContentStreams (_bgcb ,_ebg ());};