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-03-23 23:12:52 +00:00
|
|
|
package annotator ;import (_df "bytes";_ca "errors";_g "github.com/unidoc/unipdf/v3/common";_b "github.com/unidoc/unipdf/v3/contentstream";_eeb "github.com/unidoc/unipdf/v3/contentstream/draw";_gg "github.com/unidoc/unipdf/v3/core";_e "github.com/unidoc/unipdf/v3/internal/textencoding";
|
|
|
|
_ge "github.com/unidoc/unipdf/v3/model";_c "image";_ed "math";_eb "strings";_ee "unicode";);
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// 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 *_ge .PdfPage ,name string ,rect []float64 ,opt CheckboxFieldOptions )(*_ge .PdfFieldButton ,error ){if page ==nil {return nil ,_ca .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
|
|
|
|
};if len (name )<=0{return nil ,_ca .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 ,_ca .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
|
|
|
|
};_ddca ,_dfd :=_ge .NewStandard14Font (_ge .ZapfDingbatsName );if _dfd !=nil {return nil ,_dfd ;};_gcdg :=_ge .NewPdfField ();_ceba :=&_ge .PdfFieldButton {};_gcdg .SetContext (_ceba );_ceba .PdfField =_gcdg ;_ceba .T =_gg .MakeString (name );_ceba .SetType (_ge .ButtonTypeCheckbox );
|
|
|
|
_aca :="\u004f\u0066\u0066";if opt .Checked {_aca ="\u0059\u0065\u0073";};_ceba .V =_gg .MakeName (_aca );_dea :=_ge .NewPdfAnnotationWidget ();_dea .Rect =_gg .MakeArrayFromFloats (rect );_dea .P =page .ToPdfObject ();_dea .F =_gg .MakeInteger (4);_dea .Parent =_ceba .ToPdfObject ();
|
|
|
|
_cgc :=rect [2]-rect [0];_ecbg :=rect [3]-rect [1];var _egd _df .Buffer ;_egd .WriteString ("\u0071\u000a");_egd .WriteString ("\u0030 \u0030\u0020\u0031\u0020\u0072\u0067\n");_egd .WriteString ("\u0042\u0054\u000a");_egd .WriteString ("\u002f\u005a\u0061D\u0062\u0020\u0031\u0032\u0020\u0054\u0066\u000a");
|
|
|
|
_egd .WriteString ("\u0045\u0054\u000a");_egd .WriteString ("\u0051\u000a");_cffd :=_b .NewContentCreator ();_cffd .Add_q ();_cffd .Add_rg (0,0,1);_cffd .Add_BT ();_cffd .Add_Tf (*_gg .MakeName ("\u005a\u0061\u0044\u0062"),12);_cffd .Add_Td (0,0);_cffd .Add_ET ();
|
|
|
|
_cffd .Add_Q ();_cdea :=_ge .NewXObjectForm ();_cdea .SetContentStream (_cffd .Bytes (),_gg .NewRawEncoder ());_cdea .BBox =_gg .MakeArrayFromFloats ([]float64 {0,0,_cgc ,_ecbg });_cdea .Resources =_ge .NewPdfPageResources ();_cdea .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_ddca .ToPdfObject ());
|
|
|
|
_cffd =_b .NewContentCreator ();_cffd .Add_q ();_cffd .Add_re (0,0,_cgc ,_ecbg );_cffd .Add_W ().Add_n ();_cffd .Add_rg (0,0,1);_cffd .Translate (0,3.0);_cffd .Add_BT ();_cffd .Add_Tf (*_gg .MakeName ("\u005a\u0061\u0044\u0062"),12);_cffd .Add_Td (0,0);
|
|
|
|
_cffd .Add_Tj (*_gg .MakeString ("\u0034"));_cffd .Add_ET ();_cffd .Add_Q ();_defg :=_ge .NewXObjectForm ();_defg .SetContentStream (_cffd .Bytes (),_gg .NewRawEncoder ());_defg .BBox =_gg .MakeArrayFromFloats ([]float64 {0,0,_cgc ,_ecbg });_defg .Resources =_ge .NewPdfPageResources ();
|
|
|
|
_defg .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_ddca .ToPdfObject ());_fabf :=_gg .MakeDict ();_fabf .Set ("\u004f\u0066\u0066",_cdea .ToPdfObject ());_fabf .Set ("\u0059\u0065\u0073",_defg .ToPdfObject ());_ecab :=_gg .MakeDict ();_ecab .Set ("\u004e",_fabf );
|
|
|
|
_dea .AP =_ecab ;_dea .AS =_gg .MakeName (_aca );_ceba .Annotations =append (_ceba .Annotations ,_dea );return _ceba ,nil ;};func _fea (_efgd *_ge .PdfAcroForm ,_cab *_ge .PdfAnnotationWidget ,_afe *_ge .PdfFieldChoice ,_ffda AppearanceStyle )(*_gg .PdfObjectDictionary ,error ){_ece ,_aeg :=_gg .GetArray (_cab .Rect );
|
|
|
|
if !_aeg {return nil ,_ca .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_eede ,_ecd :=_ge .NewPdfRectangle (*_ece );if _ecd !=nil {return nil ,_ecd ;};_ebe ,_fbfe :=_eede .Width (),_eede .Height ();_g .Log .Debug ("\u0043\u0068\u006f\u0069\u0063\u0065\u002c\u0020\u0077\u0061\u0020\u0042S\u003a\u0020\u0025\u0076",_cab .BS );
|
|
|
|
_dcc ,_ecd :=_b .NewContentStreamParser (_fbfc (_afe .PdfField )).Parse ();if _ecd !=nil {return nil ,_ecd ;};_bcb ,_daf :=_gg .GetDict (_cab .MK );if _daf {_deege ,_ :=_gg .GetDict (_cab .BS );_ebfa :=_ffda .applyAppearanceCharacteristics (_bcb ,_deege ,nil );
|
|
|
|
if _ebfa !=nil {return nil ,_ebfa ;};};_dbg :=_gg .MakeDict ();for _ ,_cabc :=range _afe .Opt .Elements (){if _gede ,_gbf :=_gg .GetArray (_cabc );_gbf &&_gede .Len ()==2{_cabc =_gede .Get (1);};var _dfe string ;if _gbcf ,_abc :=_gg .GetString (_cabc );
|
|
|
|
_abc {_dfe =_gbcf .Decoded ();}else if _dcff ,_gfba :=_gg .GetName (_cabc );_gfba {_dfe =_dcff .String ();}else {_g .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",_cabc );
|
|
|
|
return nil ,_ca .New ("\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u002f\u0073t\u0072\u0069\u006e\u0067");};if len (_dfe )> 0{_dbgb ,_eebd :=_fbdb (_afe .PdfField ,_ebe ,_fbfe ,_dfe ,_ffda ,_dcc ,_efgd .DR ,_bcb );if _eebd !=nil {return nil ,_eebd ;
|
|
|
|
};_dbg .Set (*_gg .MakeName (_dfe ),_dbgb .ToPdfObject ());};};_fbe :=_gg .MakeDict ();_fbe .Set ("\u004e",_dbg );return _fbe ,nil ;};
|
2021-01-26 01:31:56 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`.
|
|
|
|
// Implements interface model.FieldAppearanceGenerator.
|
|
|
|
func (_ccb FieldAppearance )GenerateAppearanceDict (form *_ge .PdfAcroForm ,field *_ge .PdfField ,wa *_ge .PdfAnnotationWidget )(*_gg .PdfObjectDictionary ,error ){_g .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 );
|
|
|
|
_ ,_fg :=field .GetContext ().(*_ge .PdfFieldText );_gcb ,_bd :=_gg .GetDict (wa .AP );if _bd &&_ccb .OnlyIfMissing &&(!_fg ||!_ccb .RegenerateTextFields ){_g .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 _gcb ,nil ;};if form .DR ==nil {form .DR =_ge .NewPdfPageResources ();};switch _ad :=field .GetContext ().(type ){case *_ge .PdfFieldText :_fc :=_ad ;switch {case _fc .Flags ().Has (_ge .FieldFlagPassword ):return nil ,nil ;case _fc .Flags ().Has (_ge .FieldFlagFileSelect ):return nil ,nil ;
|
|
|
|
case _fc .Flags ().Has (_ge .FieldFlagComb ):if _fc .MaxLen !=nil {_eg ,_fbce :=_ede (wa ,_fc ,form .DR ,_ccb .Style ());if _fbce !=nil {return nil ,_fbce ;};return _eg ,nil ;};};_abg ,_ce :=_ebf (wa ,_fc ,form .DR ,_ccb .Style ());if _ce !=nil {return nil ,_ce ;
|
|
|
|
};return _abg ,nil ;case *_ge .PdfFieldButton :_gea :=_ad ;if _gea .IsCheckbox (){_bg ,_ccba :=_abff (wa ,_gea ,form .DR ,_ccb .Style ());if _ccba !=nil {return nil ,_ccba ;};return _bg ,nil ;};_g .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",_gea .GetType ());
|
|
|
|
case *_ge .PdfFieldChoice :_ffd :=_ad ;switch {case _ffd .Flags ().Has (_ge .FieldFlagCombo ):_dd ,_dde :=_fea (form ,wa ,_ffd ,_ccb .Style ());if _dde !=nil {return nil ,_dde ;};return _dd ,nil ;default:_g .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",_ffd .Flags ().String ());
|
|
|
|
};default:_g .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",_ad );};return nil ,nil ;};
|
|
|
|
|
|
|
|
// TextFieldOptions defines optional parameter for a text field in a form.
|
|
|
|
type TextFieldOptions struct{MaxLen int ;Value string ;};
|
|
|
|
|
|
|
|
// 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 *_ge .PdfSignature ,lines []*SignatureLine ,opts *SignatureFieldOpts )(*_ge .PdfFieldSignature ,error ){if signature ==nil {return nil ,_ca .New ("\u0073\u0069\u0067na\u0074\u0075\u0072\u0065\u0020\u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u006e\u0069\u006c");
|
|
|
|
};_edge ,_cfff :=_baea (lines ,opts );if _cfff !=nil {return nil ,_cfff ;};_ffab :=_ge .NewPdfFieldSignature (signature );_ffab .Rect =_gg .MakeArrayFromFloats (opts .Rect );_ffab .AP =_edge ;return _ffab ,nil ;};
|
|
|
|
|
|
|
|
// NewSignatureLine returns a new signature line displayed as a part of the
|
|
|
|
// signature field appearance.
|
|
|
|
func NewSignatureLine (desc ,text string )*SignatureLine {return &SignatureLine {Desc :desc ,Text :text };};
|
|
|
|
|
|
|
|
// Style returns the appearance style of `fa`. If not specified, returns default style.
|
|
|
|
func (_dg FieldAppearance )Style ()AppearanceStyle {if _dg ._bf !=nil {return *_dg ._bf ;};return AppearanceStyle {AutoFontSizeFraction :0.65,CheckmarkRune :'✔',BorderSize :0.0,BorderColor :_ge .NewPdfColorDeviceGray (0),FillColor :_ge .NewPdfColorDeviceGray (1),MultilineLineHeight :1.2,MultilineVAlignMiddle :false ,DrawAlignmentReticle :false ,AllowMK :true };
|
2021-02-22 02:29:48 +00:00
|
|
|
};
|
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// SetStyle applies appearance `style` to `fa`.
|
|
|
|
func (_bff *FieldAppearance )SetStyle (style AppearanceStyle ){_bff ._bf =&style };
|
2021-03-13 21:28:23 +00:00
|
|
|
|
2021-03-23 23:12:52 +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 ;_bf *AppearanceStyle ;};func _ebf (_bgc *_ge .PdfAnnotationWidget ,_dge *_ge .PdfFieldText ,_daa *_ge .PdfPageResources ,_ea AppearanceStyle )(*_gg .PdfObjectDictionary ,error ){_aa :=_ge .NewPdfPageResources ();
|
|
|
|
_dad ,_ebg :=_gg .GetArray (_bgc .Rect );if !_ebg {return nil ,_ca .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_bffa ,_fbcg :=_ge .NewPdfRectangle (*_dad );if _fbcg !=nil {return nil ,_fbcg ;};_gbb ,_fdc :=_bffa .Width (),_bffa .Height ();
|
|
|
|
_ccg ,_edgfg :=_gbb ,_fdc ;_ba ,_fga :=_gg .GetDict (_bgc .MK );if _fga {_gcbd ,_ :=_gg .GetDict (_bgc .BS );_ef :=_ea .applyAppearanceCharacteristics (_ba ,_gcbd ,nil );if _ef !=nil {return nil ,_ef ;};};_edcg ,_fbcg :=_b .NewContentStreamParser (_fbfc (_dge .PdfField )).Parse ();
|
|
|
|
if _fbcg !=nil {return nil ,_fbcg ;};_dgd :=_b .NewContentCreator ();if _ea .BorderSize > 0{_dfb (_dgd ,_ea ,_gbb ,_fdc );};if _ea .DrawAlignmentReticle {_bfg :=_ea ;_bfg .BorderSize =0.2;_facf (_dgd ,_bfg ,_gbb ,_fdc );};_dgd .Add_BMC ("\u0054\u0078");
|
|
|
|
_dgd .Add_q ();_gbb ,_fdc =_ea .applyRotation (_ba ,_gbb ,_fdc ,_dgd );_dgd .Add_BT ();_be ,_cbe ,_fbcg :=_ea .processDA (_dge .PdfField ,_edcg ,_daa ,_aa ,_dgd );if _fbcg !=nil {return nil ,_fbcg ;};_dca :=_be .Font ;_bdc :=_be .Size ;_ccge :=_gg .MakeName (_be .Name );
|
|
|
|
_cad :=_bdc ==0;if _cad &&_cbe {_bdc =_fdc *_ea .AutoFontSizeFraction ;};_bdf :=_dca .Encoder ();if _bdf ==nil {_g .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");
|
|
|
|
_bdf =_e .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};_fa ,_fbcg :=_dca .GetFontDescriptor ();if _fbcg !=nil {_g .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 _bbg string ;if _fbb ,_dcd :=_gg .GetString (_dge .V );_dcd {_bbg =_fbb .Decoded ();};if len (_bbg )==0{return nil ,nil ;};_ebfd :=[]string {_bbg };_fdb :=false ;if _dge .Flags ().Has (_ge .FieldFlagMultiline ){_fdb =true ;_bbg =_eb .Replace (_bbg ,"\u000d\u000a","\u000a",-1);
|
|
|
|
_bbg =_eb .Replace (_bbg ,"\u000d","\u000a",-1);_ebfd =_eb .Split (_bbg ,"\u000a");};_fe :=0.0;_efa :=0;if _bdf !=nil {_cg :=len (_ebfd );_dgg :=0;for _dgg < _cg {var _eae float64 ;_cdc :=-1;_ag :=0.0;for _dgef ,_dab :=range _ebfd [_dgg ]{if _dab ==' '{_cdc =_dgef ;
|
|
|
|
_eae =_ag ;};_fcg ,_de :=_dca .GetRuneMetrics (_dab );if !_de {_g .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",_dab );
|
|
|
|
continue ;};_ag +=_fcg .Wx ;if _fdb &&!_cad &&_bdc *_ag /1000.0> _gbb &&_cdc > 0{_dga :=_ebfd [_dgg ][_cdc +1:];if _dgg < len (_ebfd )-1{_ebfd =append (_ebfd [:_dgg +1],_ebfd [_dgg :]...);_ebfd [_dgg +1]=_dga ;}else {_ebfd =append (_ebfd ,_dga );};_cg ++;
|
|
|
|
_ebfd [_dgg ]=_ebfd [_dgg ][0:_cdc ];_ag =_eae ;break ;};};if _ag > _fe {_fe =_ag ;};_ebfd [_dgg ]=string (_bdf .Encode (_ebfd [_dgg ]));if len (_ebfd [_dgg ])> 0{_efa ++;};_dgg ++;};};_ege :=2.0;if _bdc ==0||_cad &&_fe > 0&&_ege +_fe *_bdc /1000.0> _gbb {_bdc =0.95*1000.0*(_gbb -_ege )/_fe ;
|
|
|
|
};_fab :=_dc ;{if _ffc ,_fdg :=_gg .GetIntVal (_dge .Q );_fdg {switch _ffc {case 0:_fab =_dc ;case 1:_fab =_eec ;case 2:_fab =_bcd ;default:_g .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",_ffc );
|
|
|
|
};};};_bgb :=_ea .MultilineLineHeight ;_fcga :=_bdc ;if _fdb &&_efa > 1{_fcga =_bgb *_bdc ;};var _bbc float64 ;if _fa !=nil {_bbc ,_fbcg =_fa .GetCapHeight ();if _fbcg !=nil {_g .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",_fbcg );
|
|
|
|
};};if int (_bbc )<=0{_g .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;};_dda :=_bbc /1000.0*_bdc ;_bbb :=0.0;{_fcb :=float64 (_efa )*_fcga ;if _cad &&_bbb +_fcb > _fdc {_bdc =0.95*(_fdc -_bbb )/float64 (_efa );_fcga =_bdc ;if _fdb &&_efa > 1{_fcga =_bgb *_bdc ;};_dda =_bbc /1000.0*_bdc ;_fcb =float64 (_efa )*_fcga ;
|
|
|
|
};if _fdc > _fcb {if _fdb {if _ea .MultilineVAlignMiddle {_abgf :=(_fdc -_fcb )/2.0;_fbf :=_abgf +_fcb -_fcga ;_bbb =_fbf ;}else {_bbb =_fdc -_fcga ;_bbb -=_bdc *0.5;};}else {_bbb =(_fdc -_dda )/2.0;};};};_dgd .Add_Tf (*_ccge ,_bdc );_dgd .Add_Td (_ege ,_bbb );
|
|
|
|
_afd :=_ege ;_bag :=_ege ;for _def ,_aac :=range _ebfd {_fdd :=0.0;for _ ,_fabe :=range _aac {_efc ,_ffa :=_dca .GetRuneMetrics (_fabe );if !_ffa {continue ;};_fdd +=_efc .Wx ;};_bae :=_fdd /1000.0*_bdc ;_ebfb :=_gbb -_bae ;var _fed float64 ;switch _fab {case _dc :_fed =_afd ;
|
|
|
|
case _eec :_fed =_ebfb /2;case _bcd :_fed =_ebfb ;};_ege =_fed -_bag ;if _ege > 0.0{_dgd .Add_Td (_ege ,0);};_bag =_fed ;_dgd .Add_Tj (*_gg .MakeString (_aac ));if _def < len (_ebfd )-1{_dgd .Add_Td (0,-_fcga *_bgb );};};_dgd .Add_ET ();_dgd .Add_Q ();
|
|
|
|
_dgd .Add_EMC ();_afc :=_ge .NewXObjectForm ();_afc .Resources =_aa ;_afc .BBox =_gg .MakeArrayFromFloats ([]float64 {0,0,_ccg ,_edgfg });_afc .SetContentStream (_dgd .Bytes (),_aegb ());_ggd :=_gg .MakeDict ();_ggd .Set ("\u004e",_afc .ToPdfObject ());
|
|
|
|
return _ggd ,nil ;};func _ede (_efg *_ge .PdfAnnotationWidget ,_baa *_ge .PdfFieldText ,_faf *_ge .PdfPageResources ,_cec AppearanceStyle )(*_gg .PdfObjectDictionary ,error ){_dce :=_ge .NewPdfPageResources ();_cef ,_cdd :=_gg .GetArray (_efg .Rect );if !_cdd {return nil ,_ca .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");
|
|
|
|
};_dgea ,_eeg :=_ge .NewPdfRectangle (*_cef );if _eeg !=nil {return nil ,_eeg ;};_feg ,_ec :=_dgea .Width (),_dgea .Height ();_gbd ,_ae :=_feg ,_ec ;_gfg ,_fge :=_gg .GetDict (_efg .MK );if _fge {_ddeb ,_ :=_gg .GetDict (_efg .BS );_dcb :=_cec .applyAppearanceCharacteristics (_gfg ,_ddeb ,nil );
|
|
|
|
if _dcb !=nil {return nil ,_dcb ;};};_fcc ,_fge :=_gg .GetIntVal (_baa .MaxLen );if !_fge {return nil ,_ca .New ("\u006d\u0061\u0078\u006c\u0065\u006e\u0020\u006e\u006ft\u0020\u0073\u0065\u0074");};if _fcc <=0{return nil ,_ca .New ("\u006d\u0061\u0078\u004c\u0065\u006e\u0020\u0069\u006ev\u0061\u006c\u0069\u0064");
|
|
|
|
};_bbd :=_feg /float64 (_fcc );_efd ,_eeg :=_b .NewContentStreamParser (_fbfc (_baa .PdfField )).Parse ();if _eeg !=nil {return nil ,_eeg ;};_dee :=_b .NewContentCreator ();if _cec .BorderSize > 0{_dfb (_dee ,_cec ,_feg ,_ec );};if _cec .DrawAlignmentReticle {_bga :=_cec ;
|
|
|
|
_bga .BorderSize =0.2;_facf (_dee ,_bga ,_feg ,_ec );};_dee .Add_BMC ("\u0054\u0078");_dee .Add_q ();_ ,_ec =_cec .applyRotation (_gfg ,_feg ,_ec ,_dee );_dee .Add_BT ();_abf ,_aec ,_eeg :=_cec .processDA (_baa .PdfField ,_efd ,_faf ,_dce ,_dee );if _eeg !=nil {return nil ,_eeg ;
|
|
|
|
};_bdfa :=_abf .Font ;_fda :=_gg .MakeName (_abf .Name );_ccdd :=_abf .Size ;_dag :=_ccdd ==0;if _dag &&_aec {_ccdd =_ec *_cec .AutoFontSizeFraction ;};_db :=_bdfa .Encoder ();if _db ==nil {_g .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");
|
|
|
|
_db =_e .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};var _dcf string ;if _aed ,_fff :=_gg .GetString (_baa .V );_fff {_dcf =_aed .Decoded ();};_dee .Add_Tf (*_fda ,_ccdd );var _fdge float64 ;for _ ,_feb :=range _dcf {_fbd ,_gce :=_bdfa .GetRuneMetrics (_feb );
|
|
|
|
if !_gce {_g .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",_feb );
|
|
|
|
continue ;};_fdab :=_fbd .Wy ;if int (_fdab )<=0{_fdab =_fbd .Wx ;};if _fdab > _fdge {_fdge =_fdab ;};};if int (_fdge )==0{_g .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");
|
|
|
|
_fdge =1000;};_eaa ,_eeg :=_bdfa .GetFontDescriptor ();if _eeg !=nil {_g .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 _fgf float64 ;if _eaa !=nil {_fgf ,_eeg =_eaa .GetCapHeight ();if _eeg !=nil {_g .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",_eeg );
|
|
|
|
};};if int (_fgf )<=0{_g .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");
|
|
|
|
_fgf =1000.0;};_bcg :=_fgf /1000.0*_ccdd ;_deb :=0.0;_ac :=1.0*_ccdd *(_fdge /1000.0);{_eeca :=_ac ;if _dag &&_deb +_eeca > _ec {_ccdd =0.95*(_ec -_deb );_bcg =_fgf /1000.0*_ccdd ;};if _ec > _bcg {_deb =(_ec -_bcg )/2.0;};};_dee .Add_Td (0,_deb );if _dgefg ,_efge :=_gg .GetIntVal (_baa .Q );
|
|
|
|
_efge {switch _dgefg {case 2:if len (_dcf )< _fcc {_bcf :=float64 (_fcc -len (_dcf ))*_bbd ;_dee .Add_Td (_bcf ,0);};};};for _dac ,_eebe :=range _dcf {_fba :=2.0;_bcc :=string (_eebe );if _db !=nil {_aee ,_ccf :=_bdfa .GetRuneMetrics (_eebe );if !_ccf {_g .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",_eebe );
|
|
|
|
continue ;};_bcc =string (_db .Encode (_bcc ));_bgf :=_ccdd *_aee .Wx /1000.0;_deeg :=(_bbd -_bgf )/2;_fba =_deeg ;};_dee .Add_Td (_fba ,0);_dee .Add_Tj (*_gg .MakeString (_bcc ));if _dac !=len (_dcf )-1{_dee .Add_Td (_bbd -_fba ,0);};};_dee .Add_ET ();
|
|
|
|
_dee .Add_Q ();_dee .Add_EMC ();_aeed :=_ge .NewXObjectForm ();_aeed .Resources =_dce ;_aeed .BBox =_gg .MakeArrayFromFloats ([]float64 {0,0,_gbd ,_ae });_aeed .SetContentStream (_dee .Bytes (),_aegb ());_bbdc :=_gg .MakeDict ();_bbdc .Set ("\u004e",_aeed .ToPdfObject ());
|
|
|
|
return _bbdc ,nil ;};
|
2021-03-13 21:28:23 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// 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 *_ge .PdfPage ,name string ,rect []float64 ,opt ComboboxFieldOptions )(*_ge .PdfFieldChoice ,error ){if page ==nil {return nil ,_ca .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
|
|
|
|
};if len (name )<=0{return nil ,_ca .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 ,_ca .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
|
|
|
|
};_beea :=_ge .NewPdfField ();_deaf :=&_ge .PdfFieldChoice {};_beea .SetContext (_deaf );_deaf .PdfField =_beea ;_deaf .T =_gg .MakeString (name );_deaf .Opt =_gg .MakeArray ();for _ ,_gfeb :=range opt .Choices {_deaf .Opt .Append (_gg .MakeString (_gfeb ));
|
|
|
|
};_deaf .SetFlag (_ge .FieldFlagCombo );_fbcb :=_ge .NewPdfAnnotationWidget ();_fbcb .Rect =_gg .MakeArrayFromFloats (rect );_fbcb .P =page .ToPdfObject ();_fbcb .F =_gg .MakeInteger (4);_fbcb .Parent =_deaf .ToPdfObject ();_deaf .Annotations =append (_deaf .Annotations ,_fbcb );
|
|
|
|
return _deaf ,nil ;};
|
2021-03-13 21:28:23 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// ComboboxFieldOptions defines optional parameters for a combobox form field.
|
|
|
|
type ComboboxFieldOptions struct{
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// Choices is the list of string values that can be selected.
|
|
|
|
Choices []string ;};func _dfa (_caff _c .Image ,_bad string ,_cfcc *SignatureFieldOpts ,_gfc []float64 ,_bagea *_b .ContentCreator )(*_gg .PdfObjectName ,*_ge .XObjectImage ,error ){_effbd ,_gdg :=_ge .DefaultImageHandler {}.NewImageFromGoImage (_caff );
|
|
|
|
if _gdg !=nil {return nil ,nil ,_gdg ;};_eee ,_gdg :=_ge .NewXObjectImageFromImage (_effbd ,nil ,_cfcc .Encoder );if _gdg !=nil {return nil ,nil ,_gdg ;};_dgb ,_egc :=float64 (*_eee .Width ),float64 (*_eee .Height );_gbdf :=_gfc [2]-_gfc [0];_dcdb :=_gfc [3]-_gfc [1];
|
|
|
|
if _cfcc .AutoSize {_gbde :=_ed .Min (_gbdf /_dgb ,_dcdb /_egc );_dgb *=_gbde ;_egc *=_gbde ;_gfc [0]=_gfc [0]+(_gbdf /2)-(_dgb /2);_gfc [1]=_gfc [1]+(_dcdb /2)-(_egc /2);};var _bddg *_gg .PdfObjectName ;if _afdd ,_aae :=_gg .GetName (_eee .Name );_aae {_bddg =_afdd ;
|
|
|
|
}else {_bddg =_gg .MakeName (_bad );};if _bagea !=nil {_bagea .Add_q ().Translate (_gfc [0],_gfc [1]).Scale (_dgb ,_egc ).Add_Do (*_bddg ).Add_Q ();}else {return nil ,nil ,_ca .New ("\u0043\u006f\u006e\u0074en\u0074\u0043\u0072\u0065\u0061\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u0075l\u006c");
|
|
|
|
};return _bddg ,_eee ,nil ;};
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// CreateCircleAnnotation creates a circle/ellipse annotation object with appearance stream that can be added to
|
|
|
|
// page PDF annotations.
|
|
|
|
func CreateCircleAnnotation (circDef CircleAnnotationDef )(*_ge .PdfAnnotation ,error ){_edg :=_ge .NewPdfAnnotationCircle ();if circDef .BorderEnabled {_bc ,_edc ,_gb :=circDef .BorderColor .R (),circDef .BorderColor .G (),circDef .BorderColor .B ();_edg .C =_gg .MakeArrayFromFloats ([]float64 {_bc ,_edc ,_gb });
|
|
|
|
_f :=_ge .NewBorderStyle ();_f .SetBorderWidth (circDef .BorderWidth );_edg .BS =_f .ToPdfObject ();};if circDef .FillEnabled {_eef ,_cb ,_gf :=circDef .FillColor .R (),circDef .FillColor .G (),circDef .FillColor .B ();_edg .IC =_gg .MakeArrayFromFloats ([]float64 {_eef ,_cb ,_gf });
|
|
|
|
}else {_edg .IC =_gg .MakeArrayFromIntegers ([]int {});};if circDef .Opacity < 1.0{_edg .CA =_gg .MakeFloat (circDef .Opacity );};_edgf ,_fb ,_caf :=_gc (circDef );if _caf !=nil {return nil ,_caf ;};_edg .AP =_edgf ;_edg .Rect =_gg .MakeArrayFromFloats ([]float64 {_fb .Llx ,_fb .Lly ,_fb .Urx ,_fb .Ury });
|
|
|
|
return _edg .PdfAnnotation ,nil ;};
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// CreateLineAnnotation creates a line annotation object that can be added to page PDF annotations.
|
|
|
|
func CreateLineAnnotation (lineDef LineAnnotationDef )(*_ge .PdfAnnotation ,error ){_fde :=_ge .NewPdfAnnotationLine ();_fde .L =_gg .MakeArrayFromFloats ([]float64 {lineDef .X1 ,lineDef .Y1 ,lineDef .X2 ,lineDef .Y2 });_dfde :=_gg .MakeName ("\u004e\u006f\u006e\u0065");
|
|
|
|
if lineDef .LineEndingStyle1 ==_eeb .LineEndingStyleArrow {_dfde =_gg .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");};_dcffb :=_gg .MakeName ("\u004e\u006f\u006e\u0065");if lineDef .LineEndingStyle2 ==_eeb .LineEndingStyleArrow {_dcffb =_gg .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");
|
|
|
|
};_fde .LE =_gg .MakeArray (_dfde ,_dcffb );if lineDef .Opacity < 1.0{_fde .CA =_gg .MakeFloat (lineDef .Opacity );};_gged ,_ebd ,_cgb :=lineDef .LineColor .R (),lineDef .LineColor .G (),lineDef .LineColor .B ();_fde .IC =_gg .MakeArrayFromFloats ([]float64 {_gged ,_ebd ,_cgb });
|
|
|
|
_fde .C =_gg .MakeArrayFromFloats ([]float64 {_gged ,_ebd ,_cgb });_ggg :=_ge .NewBorderStyle ();_ggg .SetBorderWidth (lineDef .LineWidth );_fde .BS =_ggg .ToPdfObject ();_abcc ,_gdfc ,_gebb :=_dcad (lineDef );if _gebb !=nil {return nil ,_gebb ;};_fde .AP =_abcc ;
|
|
|
|
_fde .Rect =_gg .MakeArrayFromFloats ([]float64 {_gdfc .Llx ,_gdfc .Lly ,_gdfc .Urx ,_gdfc .Ury });return _fde .PdfAnnotation ,nil ;};
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-03-23 23:12:52 +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 *_ge .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_ge .PdfColorDeviceRGB ;Opacity float64 ;};func _gc (_gbc CircleAnnotationDef )(*_gg .PdfObjectDictionary ,*_ge .PdfRectangle ,error ){_da :=_ge .NewXObjectForm ();
|
|
|
|
_da .Resources =_ge .NewPdfPageResources ();_bb :="";if _gbc .Opacity < 1.0{_a :=_gg .MakeDict ();_a .Set ("\u0063\u0061",_gg .MakeFloat (_gbc .Opacity ));_a .Set ("\u0043\u0041",_gg .MakeFloat (_gbc .Opacity ));_cafe :=_da .Resources .AddExtGState ("\u0067\u0073\u0031",_a );
|
|
|
|
if _cafe !=nil {_g .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 ,_cafe ;};_bb ="\u0067\u0073\u0031";};_cc ,_gfb ,_eed ,_fbc :=_af (_gbc ,_bb );
|
|
|
|
if _fbc !=nil {return nil ,nil ,_fbc ;};_fbc =_da .SetContentStream (_cc ,nil );if _fbc !=nil {return nil ,nil ,_fbc ;};_da .BBox =_gfb .ToPdfObject ();_cba :=_gg .MakeDict ();_cba .Set ("\u004e",_da .ToPdfObject ());return _cba ,_eed ,nil ;};func _bege (_fcd LineAnnotationDef ,_agff string )([]byte ,*_ge .PdfRectangle ,*_ge .PdfRectangle ,error ){_gcff :=_eeb .Line {X1 :0,Y1 :0,X2 :_fcd .X2 -_fcd .X1 ,Y2 :_fcd .Y2 -_fcd .Y1 ,LineColor :_fcd .LineColor ,Opacity :_fcd .Opacity ,LineWidth :_fcd .LineWidth ,LineEndingStyle1 :_fcd .LineEndingStyle1 ,LineEndingStyle2 :_fcd .LineEndingStyle2 };
|
|
|
|
_egba ,_cece ,_dgbe :=_gcff .Draw (_agff );if _dgbe !=nil {return nil ,nil ,nil ,_dgbe ;};_agfc :=&_ge .PdfRectangle {};_agfc .Llx =_fcd .X1 +_cece .Llx ;_agfc .Lly =_fcd .Y1 +_cece .Lly ;_agfc .Urx =_fcd .X1 +_cece .Urx ;_agfc .Ury =_fcd .Y1 +_cece .Ury ;
|
|
|
|
return _egba ,_cece ,_agfc ,nil ;};
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-03-23 23:12:52 +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 *_ge .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 _eeb .LineEndingStyle ;LineEndingStyle2 _eeb .LineEndingStyle ;};func _af (_fd CircleAnnotationDef ,_ff string )([]byte ,*_ge .PdfRectangle ,*_ge .PdfRectangle ,error ){_cf :=_eeb .Circle {X :_fd .X ,Y :_fd .Y ,Width :_fd .Width ,Height :_fd .Height ,FillEnabled :_fd .FillEnabled ,FillColor :_fd .FillColor ,BorderEnabled :_fd .BorderEnabled ,BorderWidth :_fd .BorderWidth ,BorderColor :_fd .BorderColor ,Opacity :_fd .Opacity };
|
|
|
|
_ab ,_edd ,_gfe :=_cf .Draw (_ff );if _gfe !=nil {return nil ,nil ,nil ,_gfe ;};_ga :=&_ge .PdfRectangle {};_ga .Llx =_fd .X +_edd .Llx ;_ga .Lly =_fd .Y +_edd .Lly ;_ga .Urx =_fd .X +_edd .Urx ;_ga .Ury =_fd .Y +_edd .Ury ;return _ab ,_edd ,_ga ,nil ;
|
|
|
|
};func _eaeb (_gaf RectangleAnnotationDef ,_bbgbe string )([]byte ,*_ge .PdfRectangle ,*_ge .PdfRectangle ,error ){_cag :=_eeb .Rectangle {X :0,Y :0,Width :_gaf .Width ,Height :_gaf .Height ,FillEnabled :_gaf .FillEnabled ,FillColor :_gaf .FillColor ,BorderEnabled :_gaf .BorderEnabled ,BorderWidth :2*_gaf .BorderWidth ,BorderColor :_gaf .BorderColor ,Opacity :_gaf .Opacity };
|
|
|
|
_bfgca ,_dbgd ,_caa :=_cag .Draw (_bbgbe );if _caa !=nil {return nil ,nil ,nil ,_caa ;};_dgdg :=&_ge .PdfRectangle {};_dgdg .Llx =_gaf .X +_dbgd .Llx ;_dgdg .Lly =_gaf .Y +_dbgd .Lly ;_dgdg .Urx =_gaf .X +_dbgd .Urx ;_dgdg .Ury =_gaf .Y +_dbgd .Ury ;return _bfgca ,_dbgd ,_dgdg ,nil ;
|
|
|
|
};
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// NewSignatureFieldOpts returns a new initialized instance of options
|
|
|
|
// used to generate a signature appearance.
|
|
|
|
func NewSignatureFieldOpts ()*SignatureFieldOpts {return &SignatureFieldOpts {Font :_ge .DefaultFont (),FontSize :10,LineHeight :1,AutoSize :true ,TextColor :_ge .NewPdfColorDeviceGray (0),BorderColor :_ge .NewPdfColorDeviceGray (0),FillColor :_ge .NewPdfColorDeviceGray (1),Encoder :_gg .NewFlateEncoder (),ImagePosition :SignatureImageLeft };
|
|
|
|
};
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// AppearanceStyle defines style parameters for appearance stream generation.
|
|
|
|
type AppearanceStyle struct{
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// How much of Rect height to fill when autosizing text.
|
|
|
|
AutoFontSizeFraction float64 ;
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// CheckmarkRune is a rune used for check mark in checkboxes (for ZapfDingbats font).
|
|
|
|
CheckmarkRune rune ;BorderSize float64 ;BorderColor _ge .PdfColor ;FillColor _ge .PdfColor ;
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// Multiplier for lineheight for multi line text.
|
|
|
|
MultilineLineHeight float64 ;MultilineVAlignMiddle bool ;
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// Visual guide checking alignment of field contents (debugging).
|
|
|
|
DrawAlignmentReticle bool ;
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// Allow field MK appearance characteristics to override style settings.
|
|
|
|
AllowMK bool ;
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// Fonts holds appearance styles for fonts.
|
|
|
|
Fonts *AppearanceFontStyle ;};func _facf (_dae *_b .ContentCreator ,_ggf AppearanceStyle ,_ecc ,_beg float64 ){_dae .Add_q ().Add_re (0,0,_ecc ,_beg ).Add_re (0,_beg /2,_ecc ,_beg /2).Add_re (0,0,_ecc ,_beg ).Add_re (_ecc /2,0,_ecc /2,_beg ).Add_w (_ggf .BorderSize ).SetStrokingColor (_ggf .BorderColor ).SetNonStrokingColor (_ggf .FillColor ).Add_B ().Add_Q ();
|
|
|
|
};func _dcad (_dgda LineAnnotationDef )(*_gg .PdfObjectDictionary ,*_ge .PdfRectangle ,error ){_fedg :=_ge .NewXObjectForm ();_fedg .Resources =_ge .NewPdfPageResources ();_eaf :="";if _dgda .Opacity < 1.0{_defd :=_gg .MakeDict ();_defd .Set ("\u0063\u0061",_gg .MakeFloat (_dgda .Opacity ));
|
|
|
|
_abfgc :=_fedg .Resources .AddExtGState ("\u0067\u0073\u0031",_defd );if _abfgc !=nil {_g .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 ,_abfgc ;
|
|
|
|
};_eaf ="\u0067\u0073\u0031";};_geg ,_dbcd ,_eaag ,_ggb :=_bege (_dgda ,_eaf );if _ggb !=nil {return nil ,nil ,_ggb ;};_ggb =_fedg .SetContentStream (_geg ,nil );if _ggb !=nil {return nil ,nil ,_ggb ;};_fedg .BBox =_dbcd .ToPdfObject ();_fcgaa :=_gg .MakeDict ();
|
|
|
|
_fcgaa .Set ("\u004e",_fedg .ToPdfObject ());return _fcgaa ,_eaag ,nil ;};func _abff (_fac *_ge .PdfAnnotationWidget ,_bde *_ge .PdfFieldButton ,_eff *_ge .PdfPageResources ,_gd AppearanceStyle )(*_gg .PdfObjectDictionary ,error ){_ggc ,_ccga :=_gg .GetArray (_fac .Rect );
|
|
|
|
if !_ccga {return nil ,_ca .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_dgc ,_agd :=_ge .NewPdfRectangle (*_ggc );if _agd !=nil {return nil ,_agd ;};_ged ,_cgd :=_dgc .Width (),_dgc .Height ();_acg ,_cdg :=_ged ,_cgd ;
|
|
|
|
_g .Log .Debug ("\u0043\u0068\u0065\u0063kb\u006f\u0078\u002c\u0020\u0077\u0061\u0020\u0042\u0053\u003a\u0020\u0025\u0076",_fac .BS );_abd ,_agd :=_ge .NewStandard14Font ("\u005a\u0061\u0070f\u0044\u0069\u006e\u0067\u0062\u0061\u0074\u0073");if _agd !=nil {return nil ,_agd ;
|
|
|
|
};_cgf ,_ccc :=_gg .GetDict (_fac .MK );if _ccc {_bbgg ,_ :=_gg .GetDict (_fac .BS );_dabb :=_gd .applyAppearanceCharacteristics (_cgf ,_bbgg ,_abd );if _dabb !=nil {return nil ,_dabb ;};};_aff :=_ge .NewXObjectForm ();{_gcc :=_b .NewContentCreator ();
|
|
|
|
if _gd .BorderSize > 0{_dfb (_gcc ,_gd ,_ged ,_cgd );};if _gd .DrawAlignmentReticle {_ceb :=_gd ;_ceb .BorderSize =0.2;_facf (_gcc ,_ceb ,_ged ,_cgd );};_ged ,_cgd =_gd .applyRotation (_cgf ,_ged ,_cgd ,_gcc );_agg :=_gd .AutoFontSizeFraction *_cgd ;_edb ,_bce :=_abd .GetRuneMetrics (_gd .CheckmarkRune );
|
|
|
|
if !_bce {return nil ,_ca .New ("\u0067l\u0079p\u0068\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");};_gdc :=_abd .Encoder ();_eea :=_gdc .Encode (string (_gd .CheckmarkRune ));_aea :=_edb .Wx *_agg /1000.0;_fgad :=705.0;_faa :=_fgad /1000.0*_agg ;
|
|
|
|
_gec :=2.0;_dagc :=1.0;if _aea < _ged {_gec =(_ged -_aea )/2.0;};if _faa < _cgd {_dagc =(_cgd -_faa )/2.0;};_gcc .Add_q ().Add_g (0).Add_BT ().Add_Tf ("\u005a\u0061\u0044\u0062",_agg ).Add_Td (_gec ,_dagc ).Add_Tj (*_gg .MakeStringFromBytes (_eea )).Add_ET ().Add_Q ();
|
|
|
|
_aff .Resources =_ge .NewPdfPageResources ();_aff .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_abd .ToPdfObject ());_aff .BBox =_gg .MakeArrayFromFloats ([]float64 {0,0,_acg ,_cdg });_aff .SetContentStream (_gcc .Bytes (),_aegb ());};_bcce :=_ge .NewXObjectForm ();
|
|
|
|
{_bba :=_b .NewContentCreator ();if _gd .BorderSize > 0{_dfb (_bba ,_gd ,_ged ,_cgd );};_bcce .BBox =_gg .MakeArrayFromFloats ([]float64 {0,0,_acg ,_cdg });_bcce .SetContentStream (_bba .Bytes (),_aegb ());};_cdbd :=_gg .MakeDict ();_cdbd .Set ("\u004f\u0066\u0066",_bcce .ToPdfObject ());
|
|
|
|
_cdbd .Set ("\u0059\u0065\u0073",_aff .ToPdfObject ());_aag :=_gg .MakeDict ();_aag .Set ("\u004e",_cdbd );return _aag ,nil ;};func (_ddc *AppearanceStyle )applyAppearanceCharacteristics (_baee *_gg .PdfObjectDictionary ,_fegg *_gg .PdfObjectDictionary ,_fgc *_ge .PdfFont )error {if !_ddc .AllowMK {return nil ;
|
|
|
|
};if CA ,_bbda :=_gg .GetString (_baee .Get ("\u0043\u0041"));_bbda &&_fgc !=nil {_dfed :=CA .Bytes ();if len (_dfed )!=0{_dgcc :=[]rune (_fgc .Encoder ().Decode (_dfed ));if len (_dgcc )==1{_ddc .CheckmarkRune =_dgcc [0];};};};if BC ,_bccb :=_gg .GetArray (_baee .Get ("\u0042\u0043"));
|
|
|
|
_bccb {_fbeb ,_cff :=BC .ToFloat64Array ();if _cff !=nil {return _cff ;};switch len (_fbeb ){case 1:_ddc .BorderColor =_ge .NewPdfColorDeviceGray (_fbeb [0]);case 3:_ddc .BorderColor =_ge .NewPdfColorDeviceRGB (_fbeb [0],_fbeb [1],_fbeb [2]);case 4:_ddc .BorderColor =_ge .NewPdfColorDeviceCMYK (_fbeb [0],_fbeb [1],_fbeb [2],_fbeb [3]);
|
|
|
|
default:_g .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 (_fbeb ));
|
|
|
|
};if _fegg !=nil {if _ggfa ,_ccgf :=_gg .GetNumberAsFloat (_fegg .Get ("\u0057"));_ccgf ==nil {_ddc .BorderSize =_ggfa ;};};};if BG ,_ada :=_gg .GetArray (_baee .Get ("\u0042\u0047"));_ada {_dede ,_cafa :=BG .ToFloat64Array ();if _cafa !=nil {return _cafa ;
|
|
|
|
};switch len (_dede ){case 1:_ddc .FillColor =_ge .NewPdfColorDeviceGray (_dede [0]);case 3:_ddc .FillColor =_ge .NewPdfColorDeviceRGB (_dede [0],_dede [1],_dede [2]);case 4:_ddc .FillColor =_ge .NewPdfColorDeviceCMYK (_dede [0],_dede [1],_dede [2],_dede [3]);
|
|
|
|
default:_g .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 (_dede ));
|
|
|
|
};};return nil ;};
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-03-23 23:12:52 +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 *_ge .PdfPage ,name string ,rect []float64 ,opt TextFieldOptions )(*_ge .PdfFieldText ,error ){if page ==nil {return nil ,_ca .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};if len (name )<=0{return nil ,_ca .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 ,_ca .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");};_ffb :=_ge .NewPdfField ();_eebg :=&_ge .PdfFieldText {};_ffb .SetContext (_eebg );_eebg .PdfField =_ffb ;_eebg .T =_gg .MakeString (name );
|
|
|
|
if opt .MaxLen > 0{_eebg .MaxLen =_gg .MakeInteger (int64 (opt .MaxLen ));};if len (opt .Value )> 0{_eebg .V =_gg .MakeString (opt .Value );};_dfbb :=_ge .NewPdfAnnotationWidget ();_dfbb .Rect =_gg .MakeArrayFromFloats (rect );_dfbb .P =page .ToPdfObject ();
|
|
|
|
_dfbb .F =_gg .MakeInteger (4);_dfbb .Parent =_eebg .ToPdfObject ();_eebg .Annotations =append (_eebg .Annotations ,_dfbb );return _eebg ,nil ;};func _fbfc (_eegc *_ge .PdfField )string {if _eegc ==nil {return "";};_baf ,_afb :=_eegc .GetContext ().(*_ge .PdfFieldText );
|
|
|
|
if !_afb {return _fbfc (_eegc .Parent );};if _baf .DA !=nil {return _baf .DA .Str ();};return _fbfc (_baf .Parent );};func _dfb (_dgag *_b .ContentCreator ,_ccfe AppearanceStyle ,_bdfae ,_adf float64 ){_dgag .Add_q ().Add_re (0,0,_bdfae ,_adf ).Add_w (_ccfe .BorderSize ).SetStrokingColor (_ccfe .BorderColor ).SetNonStrokingColor (_ccfe .FillColor ).Add_B ().Add_Q ();
|
2021-02-22 02:29:48 +00:00
|
|
|
};
|
2021-01-26 01:31:56 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// 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 *_ge .PdfFont ;
|
|
|
|
|
|
|
|
// Size represents the size of the font used for the field appearance.
|
|
|
|
// If size is 0, a default font size will be used.
|
|
|
|
// The default font size is calculated using the available annotation
|
|
|
|
// height and the AutoFontSizeFraction of the AppearanceStyle.
|
|
|
|
Size float64 ;};func _aegb ()_gg .StreamEncoder {return _gg .NewFlateEncoder ()};const (_dc quadding =0;_eec quadding =1;_bcd quadding =2;);func _cae (_baeb RectangleAnnotationDef )(*_gg .PdfObjectDictionary ,*_ge .PdfRectangle ,error ){_cgcd :=_ge .NewXObjectForm ();
|
|
|
|
_cgcd .Resources =_ge .NewPdfPageResources ();_fbcbg :="";if _baeb .Opacity < 1.0{_fcfg :=_gg .MakeDict ();_fcfg .Set ("\u0063\u0061",_gg .MakeFloat (_baeb .Opacity ));_fcfg .Set ("\u0043\u0041",_gg .MakeFloat (_baeb .Opacity ));_aeeg :=_cgcd .Resources .AddExtGState ("\u0067\u0073\u0031",_fcfg );
|
|
|
|
if _aeeg !=nil {_g .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 ,_aeeg ;};_fbcbg ="\u0067\u0073\u0031";};_ebde ,_bdde ,_ebcg ,_baad :=_eaeb (_baeb ,_fbcbg );
|
|
|
|
if _baad !=nil {return nil ,nil ,_baad ;};_baad =_cgcd .SetContentStream (_ebde ,nil );if _baad !=nil {return nil ,nil ,_baad ;};_cgcd .BBox =_bdde .ToPdfObject ();_dgbd :=_gg .MakeDict ();_dgbd .Set ("\u004e",_cgcd .ToPdfObject ());return _dgbd ,_ebcg ,nil ;
|
|
|
|
};
|
2020-11-11 18:48:37 +00:00
|
|
|
|
|
|
|
// AppearanceFontStyle defines font style characteristics for form fields,
|
|
|
|
// used in the filling/flattening process.
|
|
|
|
type AppearanceFontStyle struct{
|
|
|
|
|
|
|
|
// Fallback represents a global font fallback, used for fields which do
|
|
|
|
// not specify a font in their default appearance (DA). The fallback is
|
|
|
|
// also used if there is a font specified in the DA, but it is not
|
|
|
|
// found in the AcroForm resources (DR).
|
|
|
|
Fallback *AppearanceFont ;
|
|
|
|
|
|
|
|
// FieldFallbacks defines font fallbacks for specific fields. The map keys
|
|
|
|
// represent the names of the fields (which can be specified by their
|
|
|
|
// partial or full names). Specific field fallback fonts take precedence
|
|
|
|
// over the global font fallback.
|
|
|
|
FieldFallbacks map[string ]*AppearanceFont ;
|
|
|
|
|
|
|
|
// ForceReplace forces the replacement of fonts in the filling/flattening
|
|
|
|
// process, even if the default appearance (DA) specify a valid font.
|
|
|
|
// If no fallback font is provided, setting this field has no effect.
|
2021-03-23 23:12:52 +00:00
|
|
|
ForceReplace bool ;};type quadding int ;func (_bage *AppearanceStyle )applyRotation (_bdca *_gg .PdfObjectDictionary ,_dfc ,_gdce float64 ,_bge *_b .ContentCreator )(float64 ,float64 ){if !_bage .AllowMK {return _dfc ,_gdce ;};if _bdca ==nil {return _dfc ,_gdce ;
|
|
|
|
};_daag ,_ :=_gg .GetNumberAsFloat (_bdca .Get ("\u0052"));if _daag ==0{return _dfc ,_gdce ;};_gecf :=-_daag ;_agc :=_eeb .Path {Points :[]_eeb .Point {_eeb .NewPoint (0,0).Rotate (_gecf ),_eeb .NewPoint (_dfc ,0).Rotate (_gecf ),_eeb .NewPoint (0,_gdce ).Rotate (_gecf ),_eeb .NewPoint (_dfc ,_gdce ).Rotate (_gecf )}}.GetBoundingBox ();
|
|
|
|
_bge .RotateDeg (_daag );_bge .Translate (_agc .X ,_agc .Y );return _agc .Width ,_agc .Height ;};
|
|
|
|
|
|
|
|
// CheckboxFieldOptions defines optional parameters for a checkbox field a form.
|
|
|
|
type CheckboxFieldOptions struct{Checked bool ;};
|
|
|
|
|
|
|
|
// 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 ;
|
2021-03-13 21:28:23 +00:00
|
|
|
|
|
|
|
// 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).
|
2021-03-23 23:12:52 +00:00
|
|
|
type RectangleAnnotationDef struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_ge .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_ge .PdfColorDeviceRGB ;Opacity float64 ;};
|
2021-02-11 10:35:13 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// SignatureLine represents a line of information in the signature field appearance.
|
|
|
|
type SignatureLine struct{Desc string ;Text string ;};func _fbdb (_ebc *_ge .PdfField ,_bbf ,_gge float64 ,_bbe string ,_ebee AppearanceStyle ,_fcf *_b .ContentStreamOperations ,_cddc *_ge .PdfPageResources ,_cde *_gg .PdfObjectDictionary )(*_ge .XObjectForm ,error ){_efdg :=_ge .NewPdfPageResources ();
|
|
|
|
_ebff ,_daca :=_bbf ,_gge ;_faac :=_b .NewContentCreator ();if _ebee .BorderSize > 0{_dfb (_faac ,_ebee ,_bbf ,_gge );};if _ebee .DrawAlignmentReticle {_bbeg :=_ebee ;_bbeg .BorderSize =0.2;_facf (_faac ,_bbeg ,_bbf ,_gge );};_faac .Add_BMC ("\u0054\u0078");
|
|
|
|
_faac .Add_q ();_faac .Add_BT ();_bbf ,_gge =_ebee .applyRotation (_cde ,_bbf ,_gge ,_faac );_bee ,_dceb ,_bfd :=_ebee .processDA (_ebc ,_fcf ,_cddc ,_efdg ,_faac );if _bfd !=nil {return nil ,_bfd ;};_daab :=_bee .Font ;_geb :=_bee .Size ;_deg :=_gg .MakeName (_bee .Name );
|
|
|
|
_cdf :=_geb ==0;if _cdf &&_dceb {_geb =_gge *_ebee .AutoFontSizeFraction ;};_cefc :=_daab .Encoder ();if _cefc ==nil {_g .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");
|
|
|
|
_cefc =_e .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};if len (_bbe )==0{return nil ,nil ;};_dedd :=2.0;_eca :=0.0;if _cefc !=nil {for _ ,_afg :=range _bbe {_abe ,_ebgc :=_daab .GetRuneMetrics (_afg );if !_ebgc {_g .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",_afg );
|
|
|
|
continue ;};_eca +=_abe .Wx ;};_bbe =string (_cefc .Encode (_bbe ));};if _geb ==0||_cdf &&_eca > 0&&_dedd +_eca *_geb /1000.0> _bbf {_geb =0.95*1000.0*(_bbf -_dedd )/_eca ;};_fef :=1.0*_geb ;_aaa :=2.0;{_eeff :=_fef ;if _cdf &&_aaa +_eeff > _gge {_geb =0.95*(_gge -_aaa );
|
|
|
|
_fef =1.0*_geb ;_eeff =_fef ;};if _gge > _eeff {_aaa =(_gge -_eeff )/2.0;_aaa +=1.50;};};_faac .Add_Tf (*_deg ,_geb );_faac .Add_Td (_dedd ,_aaa );_faac .Add_Tj (*_gg .MakeString (_bbe ));_faac .Add_ET ();_faac .Add_Q ();_faac .Add_EMC ();_baec :=_ge .NewXObjectForm ();
|
|
|
|
_baec .Resources =_efdg ;_baec .BBox =_gg .MakeArrayFromFloats ([]float64 {0,0,_ebff ,_daca });_baec .SetContentStream (_faac .Bytes (),_aegb ());return _baec ,nil ;};func _baea (_gac []*SignatureLine ,_ffg *SignatureFieldOpts )(*_gg .PdfObjectDictionary ,error ){if _ffg ==nil {_ffg =NewSignatureFieldOpts ();
|
|
|
|
};var _agcf error ;var _cffb *_gg .PdfObjectName ;_afec :=_ffg .Font ;if _afec !=nil {_cbb ,_ :=_afec .GetFontDescriptor ();if _cbb !=nil {if _begb ,_ecb :=_cbb .FontName .(*_gg .PdfObjectName );_ecb {_cffb =_begb ;};};if _cffb ==nil {_cffb =_gg .MakeName ("\u0046\u006f\u006et\u0031");
|
|
|
|
};}else {if _afec ,_agcf =_ge .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");_agcf !=nil {return nil ,_agcf ;};_cffb =_gg .MakeName ("\u0048\u0065\u006c\u0076");};_gee :=_ffg .FontSize ;if _gee <=0{_gee =10;};if _ffg .LineHeight <=0{_ffg .LineHeight =1;
|
|
|
|
};_dgee :=_ffg .LineHeight *_gee ;_dcbb ,_faab :=_afec .GetRuneMetrics (' ');if !_faab {return nil ,_ca .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");
|
|
|
|
};_dgeb :=_dcbb .Wx ;var _ega float64 ;var _gfgb []string ;for _ ,_eecag :=range _gac {if _eecag .Text ==""{continue ;};_gecfc :=_eecag .Text ;if _eecag .Desc !=""{_gecfc =_eecag .Desc +"\u003a\u0020"+_gecfc ;};_gfgb =append (_gfgb ,_gecfc );var _dgadb float64 ;
|
|
|
|
for _ ,_bdd :=range _gecfc {_bbcf ,_bbfg :=_afec .GetRuneMetrics (_bdd );if !_bbfg {continue ;};_dgadb +=_bbcf .Wx ;};if _dgadb > _ega {_ega =_dgadb ;};};_ega =_ega *_gee /1000.0;_bccd :=float64 (len (_gfgb ))*_dgee ;_fbcc :=_ffg .Image !=nil ;_bea :=_ffg .Rect ;
|
|
|
|
if _bea ==nil {_bea =[]float64 {0,0,_ega ,_bccd };if _fbcc {_bea [2]=_ega *2;_bea [3]=_bccd *2;};_ffg .Rect =_bea ;};_bfdg :=_bea [2]-_bea [0];_acd :=_bea [3]-_bea [1];_cbd ,_cfcb :=_bea ,_bea ;var _fbaa ,_cbbf float64 ;if _fbcc &&len (_gfgb )> 0{if _ffg .ImagePosition <=SignatureImageRight {_aaag :=[]float64 {_bea [0],_bea [1],_bea [0]+(_bfdg /2),_bea [3]};
|
|
|
|
_fad :=[]float64 {_bea [0]+(_bfdg /2),_bea [1],_bea [2],_bea [3]};if _ffg .ImagePosition ==SignatureImageLeft {_cbd ,_cfcb =_aaag ,_fad ;}else {_cbd ,_cfcb =_fad ,_aaag ;};}else {_bbga :=[]float64 {_bea [0],_bea [1],_bea [2],_bea [1]+(_acd /2)};_fedc :=[]float64 {_bea [0],_bea [1]+(_acd /2),_bea [2],_bea [3]};
|
|
|
|
if _ffg .ImagePosition ==SignatureImageTop {_cbd ,_cfcb =_fedc ,_bbga ;}else {_cbd ,_cfcb =_bbga ,_fedc ;};};};_fbaa =_cfcb [2]-_cfcb [0];_cbbf =_cfcb [3]-_cfcb [1];var _bccf float64 ;if _ffg .AutoSize {if _ega > _fbaa ||_bccd > _cbbf {_fbfg :=_ed .Min (_fbaa /_ega ,_cbbf /_bccd );
|
|
|
|
_gee *=_fbfg ;};_dgee =_ffg .LineHeight *_gee ;_bccf +=(_cbbf -float64 (len (_gfgb ))*_dgee )/2;};_effbf :=_b .NewContentCreator ();_eba :=_ge .NewPdfPageResources ();_eba .SetFontByName (*_cffb ,_afec .ToPdfObject ());if _ffg .BorderSize <=0{_ffg .BorderSize =0;
|
|
|
|
_ffg .BorderColor =_ge .NewPdfColorDeviceGray (1);};if _ffg .BorderColor ==nil {_ffg .BorderColor =_ge .NewPdfColorDeviceGray (1);};if _ffg .FillColor ==nil {_ffg .FillColor =_ge .NewPdfColorDeviceGray (1);};_effbf .Add_q ().SetNonStrokingColor (_ffg .FillColor ).SetStrokingColor (_ffg .BorderColor ).Add_w (_ffg .BorderSize ).Add_re (_bea [0],_bea [1],_bfdg ,_acd ).Add_B ().Add_Q ();
|
|
|
|
if _ffg .WatermarkImage !=nil {_abaa :=[]float64 {_bea [0],_bea [1],_bea [2],_bea [3]};_eefb ,_geag ,_bgeb :=_dfa (_ffg .WatermarkImage ,"\u0049\u006d\u0061\u0067\u0065\u0057\u0061\u0074\u0065r\u006d\u0061\u0072\u006b",_ffg ,_abaa ,_effbf );if _bgeb !=nil {return nil ,_bgeb ;
|
|
|
|
};_eba .SetXObjectImageByName (*_eefb ,_geag );};_effbf .Add_q ();_effbf .Translate (_cfcb [0],_cfcb [3]-_dgee -_bccf );_effbf .Add_BT ();_fbea :=_afec .Encoder ();for _ ,_cgdg :=range _gfgb {var _edee []byte ;for _ ,_gag :=range _cgdg {if _ee .IsSpace (_gag ){if len (_edee )> 0{_effbf .SetNonStrokingColor (_ffg .TextColor ).Add_Tf (*_cffb ,_gee ).Add_TL (_dgee ).Add_TJ ([]_gg .PdfObject {_gg .MakeStringFromBytes (_edee )}...);
|
|
|
|
_edee =nil ;};_effbf .Add_Tf (*_cffb ,_gee ).Add_TL (_dgee ).Add_TJ ([]_gg .PdfObject {_gg .MakeFloat (-_dgeb )}...);}else {_edee =append (_edee ,_fbea .Encode (string (_gag ))...);};};if len (_edee )> 0{_effbf .SetNonStrokingColor (_ffg .TextColor ).Add_Tf (*_cffb ,_gee ).Add_TL (_dgee ).Add_TJ ([]_gg .PdfObject {_gg .MakeStringFromBytes (_edee )}...);
|
|
|
|
};_effbf .Add_Td (0,-_dgee );};_effbf .Add_ET ();_effbf .Add_Q ();if _fbcc {_fdbd ,_acgc ,_bdea :=_dfa (_ffg .Image ,"\u0049\u006d\u0061\u0067\u0065\u0053\u0069\u0067\u006ea\u0074\u0075\u0072\u0065",_ffg ,_cbd ,_effbf );if _bdea !=nil {return nil ,_bdea ;
|
|
|
|
};_eba .SetXObjectImageByName (*_fdbd ,_acgc );};_fbg :=_ge .NewXObjectForm ();_fbg .Resources =_eba ;_fbg .BBox =_gg .MakeArrayFromFloats (_bea );_fbg .SetContentStream (_effbf .Bytes (),_aegb ());_dgcf :=_gg .MakeDict ();_dgcf .Set ("\u004e",_fbg .ToPdfObject ());
|
|
|
|
return _dgcf ,nil ;};
|
2021-03-13 21:28:23 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// CreateRectangleAnnotation creates a rectangle annotation object that can be added to page PDF annotations.
|
|
|
|
func CreateRectangleAnnotation (rectDef RectangleAnnotationDef )(*_ge .PdfAnnotation ,error ){_acae :=_ge .NewPdfAnnotationSquare ();if rectDef .BorderEnabled {_aagg ,_ffgc ,_aage :=rectDef .BorderColor .R (),rectDef .BorderColor .G (),rectDef .BorderColor .B ();
|
|
|
|
_acae .C =_gg .MakeArrayFromFloats ([]float64 {_aagg ,_ffgc ,_aage });_facb :=_ge .NewBorderStyle ();_facb .SetBorderWidth (rectDef .BorderWidth );_acae .BS =_facb .ToPdfObject ();};if rectDef .FillEnabled {_bgbf ,_gcdc ,_ebad :=rectDef .FillColor .R (),rectDef .FillColor .G (),rectDef .FillColor .B ();
|
|
|
|
_acae .IC =_gg .MakeArrayFromFloats ([]float64 {_bgbf ,_gcdc ,_ebad });}else {_acae .IC =_gg .MakeArrayFromIntegers ([]int {});};if rectDef .Opacity < 1.0{_acae .CA =_gg .MakeFloat (rectDef .Opacity );};_gacf ,_efdd ,_ecec :=_cae (rectDef );if _ecec !=nil {return nil ,_ecec ;
|
|
|
|
};_acae .AP =_gacf ;_acae .Rect =_gg .MakeArrayFromFloats ([]float64 {_efdd .Llx ,_efdd .Lly ,_efdd .Urx ,_efdd .Ury });return _acae .PdfAnnotation ,nil ;};const (SignatureImageLeft SignatureImagePosition =iota ;SignatureImageRight ;SignatureImageTop ;
|
|
|
|
SignatureImageBottom ;);
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// SignatureFieldOpts represents a set of options used to configure
|
|
|
|
// an appearance widget dictionary.
|
|
|
|
type SignatureFieldOpts struct{
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// Rect represents the area the signature annotation is displayed on.
|
|
|
|
Rect []float64 ;
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// AutoSize specifies if the content of the appearance should be
|
|
|
|
// scaled to fit in the annotation rectangle.
|
|
|
|
AutoSize bool ;
|
2020-10-12 14:17:59 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// Font specifies the font of the text content.
|
|
|
|
Font *_ge .PdfFont ;
|
2020-10-12 14:17:59 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// FontSize specifies the size of the text content.
|
|
|
|
FontSize float64 ;
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// LineHeight specifies the height of a line of text in the appearance annotation.
|
|
|
|
LineHeight float64 ;
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// TextColor represents the color of the text content displayed.
|
|
|
|
TextColor _ge .PdfColor ;
|
2021-01-07 14:20:10 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// FillColor represents the background color of the appearance annotation area.
|
|
|
|
FillColor _ge .PdfColor ;
|
2020-08-31 21:12:07 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// BorderSize represents border size of the appearance annotation area.
|
|
|
|
BorderSize float64 ;
|
2021-01-07 14:20:10 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// BorderColor represents the border color of the appearance annotation area.
|
|
|
|
BorderColor _ge .PdfColor ;
|
2021-01-07 14:20:10 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// WatermarkImage specifies the image used as a watermark that will be rendered
|
|
|
|
// behind the signature.
|
|
|
|
WatermarkImage _c .Image ;
|
2021-02-11 10:35:13 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// Image represents the image used for the signature appearance.
|
|
|
|
Image _c .Image ;
|
2021-03-13 21:28:23 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// Encoder specifies the image encoder used for image signature. Defaults to flate encoder.
|
|
|
|
Encoder _gg .StreamEncoder ;
|
2021-03-13 21:28:23 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// ImagePosition specifies the image location relative to the text signature.
|
|
|
|
ImagePosition SignatureImagePosition ;};func (_fbfb *AppearanceStyle )processDA (_bec *_ge .PdfField ,_fgfg *_b .ContentStreamOperations ,_cfg ,_gcd *_ge .PdfPageResources ,_eddg *_b .ContentCreator )(*AppearanceFont ,bool ,error ){var _fgd *AppearanceFont ;
|
|
|
|
var _cafd bool ;if _fbfb .Fonts !=nil {if _fbfb .Fonts .Fallback !=nil {_fgd =_fbfb .Fonts .Fallback ;};if _gfa :=_fbfb .Fonts .FieldFallbacks ;_gfa !=nil {if _dacd ,_cfa :=_gfa [_bec .PartialName ()];_cfa {_fgd =_dacd ;}else if _bffb ,_cca :=_bec .FullName ();
|
|
|
|
_cca ==nil {if _effb ,_ead :=_gfa [_bffb ];_ead {_fgd =_effb ;};};};_cafd =_fbfb .Fonts .ForceReplace ;};var _gca string ;var _cabd float64 ;var _gdf bool ;if _fgfg !=nil {for _ ,_gcac :=range *_fgfg {if _gcac .Operand =="\u0054\u0066"&&len (_gcac .Params )==2{if _afcc ,_ggfd :=_gg .GetNameVal (_gcac .Params [0]);
|
|
|
|
_ggfd {_gca =_afcc ;};if _bbaa ,_cfe :=_gg .GetNumberAsFloat (_gcac .Params [1]);_cfe ==nil {_cabd =_bbaa ;};_gdf =true ;continue ;};_eddg .AddOperand (*_gcac );};};var _aaab *AppearanceFont ;var _bcbb _gg .PdfObject ;if _cafd &&_fgd !=nil {_aaab =_fgd ;
|
|
|
|
}else {if _cfg !=nil &&_gca !=""{if _bfgc ,_cabdg :=_cfg .GetFontByName (*_gg .MakeName (_gca ));_cabdg {if _eeaa ,_cfc :=_ge .NewPdfFontFromPdfObject (_bfgc );_cfc ==nil {_bcbb =_bfgc ;_aaab =&AppearanceFont {Name :_gca ,Font :_eeaa ,Size :_cabd };}else {_g .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",_cfc );
|
|
|
|
};};};if _aaab ==nil &&_fgd !=nil {_aaab =_fgd ;};if _aaab ==nil {_dgad ,_egb :=_ge .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");if _egb !=nil {return nil ,false ,_egb ;};_aaab =&AppearanceFont {Name :"\u0048\u0065\u006c\u0076",Font :_dgad ,Size :_cabd };
|
|
|
|
};};_bgd :=*_gg .MakeName (_aaab .Name );if _bcbb ==nil {_bcbb =_aaab .Font .ToPdfObject ();};if _cfg !=nil &&!_cfg .HasFontByName (_bgd ){_cfg .SetFontByName (_bgd ,_bcbb );};if _gcd !=nil &&!_gcd .HasFontByName (_bgd ){_gcd .SetFontByName (_bgd ,_bcbb );
|
|
|
|
};return _aaab ,_gdf ,nil ;};
|
2021-03-13 21:28:23 +00:00
|
|
|
|
2021-03-23 23:12:52 +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 (_gcf FieldAppearance )WrapContentStream (page *_ge .PdfPage )error {_abeg ,_dbc :=page .GetAllContentStreams ();if _dbc !=nil {return _dbc ;};_cdfd :=_b .NewContentStreamParser (_abeg );_dbb ,_dbc :=_cdfd .Parse ();if _dbc !=nil {return _dbc ;};_dbb .WrapIfNeeded ();
|
|
|
|
_fdabg :=[]string {_dbb .String ()};return page .SetContentStreams (_fdabg ,_aegb ());};
|