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-05-31 17:17:31 +00:00
|
|
|
package annotator ;import (_bbg "bytes";_ea "errors";_bb "github.com/unidoc/unipdf/v3/common";_c "github.com/unidoc/unipdf/v3/contentstream";_gb "github.com/unidoc/unipdf/v3/contentstream/draw";_bc "github.com/unidoc/unipdf/v3/core";_a "github.com/unidoc/unipdf/v3/internal/textencoding";
|
|
|
|
_de "github.com/unidoc/unipdf/v3/model";_d "image";_g "math";_e "strings";_ae "unicode";);
|
2021-04-17 13:46:54 +00:00
|
|
|
|
2021-05-31 17:17:31 +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 (_ccg FieldAppearance )WrapContentStream (page *_de .PdfPage )error {_agbe ,_fbbe :=page .GetAllContentStreams ();if _fbbe !=nil {return _fbbe ;};_bdbf :=_c .NewContentStreamParser (_agbe );_cgb ,_fbbe :=_bdbf .Parse ();if _fbbe !=nil {return _fbbe ;
|
|
|
|
};_cgb .WrapIfNeeded ();_cfb :=[]string {_cgb .String ()};return page .SetContentStreams (_cfb ,_dac ());};
|
|
|
|
|
|
|
|
// TextFieldOptions defines optional parameter for a text field in a form.
|
|
|
|
type TextFieldOptions struct{MaxLen int ;Value string ;};func _fea (_dfa RectangleAnnotationDef ,_befa string )([]byte ,*_de .PdfRectangle ,*_de .PdfRectangle ,error ){_dccd :=_gb .Rectangle {X :0,Y :0,Width :_dfa .Width ,Height :_dfa .Height ,FillEnabled :_dfa .FillEnabled ,FillColor :_dfa .FillColor ,BorderEnabled :_dfa .BorderEnabled ,BorderWidth :2*_dfa .BorderWidth ,BorderColor :_dfa .BorderColor ,Opacity :_dfa .Opacity };
|
|
|
|
_dddd ,_bdgeb ,_gae :=_dccd .Draw (_befa );if _gae !=nil {return nil ,nil ,nil ,_gae ;};_bfd :=&_de .PdfRectangle {};_bfd .Llx =_dfa .X +_bdgeb .Llx ;_bfd .Lly =_dfa .Y +_bdgeb .Lly ;_bfd .Urx =_dfa .X +_bdgeb .Urx ;_bfd .Ury =_dfa .Y +_bdgeb .Ury ;return _dddd ,_bdgeb ,_bfd ,nil ;
|
|
|
|
};func _gfbc (_fadg LineAnnotationDef ,_dcff string )([]byte ,*_de .PdfRectangle ,*_de .PdfRectangle ,error ){_cedc :=_gb .Line {X1 :0,Y1 :0,X2 :_fadg .X2 -_fadg .X1 ,Y2 :_fadg .Y2 -_fadg .Y1 ,LineColor :_fadg .LineColor ,Opacity :_fadg .Opacity ,LineWidth :_fadg .LineWidth ,LineEndingStyle1 :_fadg .LineEndingStyle1 ,LineEndingStyle2 :_fadg .LineEndingStyle2 };
|
|
|
|
_gcgf ,_ggee ,_afaae :=_cedc .Draw (_dcff );if _afaae !=nil {return nil ,nil ,nil ,_afaae ;};_cfg :=&_de .PdfRectangle {};_cfg .Llx =_fadg .X1 +_ggee .Llx ;_cfg .Lly =_fadg .Y1 +_ggee .Lly ;_cfg .Urx =_fadg .X1 +_ggee .Urx ;_cfg .Ury =_fadg .Y1 +_ggee .Ury ;
|
|
|
|
return _gcgf ,_ggee ,_cfg ,nil ;};
|
|
|
|
|
|
|
|
// 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 *_de .PdfPage ,name string ,rect []float64 ,opt ComboboxFieldOptions )(*_de .PdfFieldChoice ,error ){if page ==nil {return nil ,_ea .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
|
|
|
|
};if len (name )<=0{return nil ,_ea .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 ,_ea .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
|
|
|
|
};_febd :=_de .NewPdfField ();_gdc :=&_de .PdfFieldChoice {};_febd .SetContext (_gdc );_gdc .PdfField =_febd ;_gdc .T =_bc .MakeString (name );_gdc .Opt =_bc .MakeArray ();for _ ,_dcca :=range opt .Choices {_gdc .Opt .Append (_bc .MakeString (_dcca ));
|
|
|
|
};_gdc .SetFlag (_de .FieldFlagCombo );_acfd :=_de .NewPdfAnnotationWidget ();_acfd .Rect =_bc .MakeArrayFromFloats (rect );_acfd .P =page .ToPdfObject ();_acfd .F =_bc .MakeInteger (4);_acfd .Parent =_gdc .ToPdfObject ();_gdc .Annotations =append (_gdc .Annotations ,_acfd );
|
|
|
|
return _gdc ,nil ;};func _ccgd (_agfc []*SignatureLine ,_ddaf *SignatureFieldOpts )(*_bc .PdfObjectDictionary ,error ){if _ddaf ==nil {_ddaf =NewSignatureFieldOpts ();};var _bcdf error ;var _dfcg *_bc .PdfObjectName ;_dfcf :=_ddaf .Font ;if _dfcf !=nil {_gffa ,_ :=_dfcf .GetFontDescriptor ();
|
|
|
|
if _gffa !=nil {if _cgdc ,_dgg :=_gffa .FontName .(*_bc .PdfObjectName );_dgg {_dfcg =_cgdc ;};};if _dfcg ==nil {_dfcg =_bc .MakeName ("\u0046\u006f\u006et\u0031");};}else {if _dfcf ,_bcdf =_de .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");
|
|
|
|
_bcdf !=nil {return nil ,_bcdf ;};_dfcg =_bc .MakeName ("\u0048\u0065\u006c\u0076");};_cgbe :=_ddaf .FontSize ;if _cgbe <=0{_cgbe =10;};if _ddaf .LineHeight <=0{_ddaf .LineHeight =1;};_efc :=_ddaf .LineHeight *_cgbe ;_afe ,_bbe :=_dfcf .GetRuneMetrics (' ');
|
|
|
|
if !_bbe {return nil ,_ea .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");};_cbag :=_afe .Wx ;var _aaga float64 ;var _aeb []string ;
|
|
|
|
for _ ,_bgb :=range _agfc {if _bgb .Text ==""{continue ;};_gfac :=_bgb .Text ;if _bgb .Desc !=""{_gfac =_bgb .Desc +"\u003a\u0020"+_gfac ;};_aeb =append (_aeb ,_gfac );var _fefc float64 ;for _ ,_agg :=range _gfac {_fefcc ,_afa :=_dfcf .GetRuneMetrics (_agg );
|
|
|
|
if !_afa {continue ;};_fefc +=_fefcc .Wx ;};if _fefc > _aaga {_aaga =_fefc ;};};_aaga =_aaga *_cgbe /1000.0;_bga :=float64 (len (_aeb ))*_efc ;_gcg :=_ddaf .Image !=nil ;_afc :=_ddaf .Rect ;if _afc ==nil {_afc =[]float64 {0,0,_aaga ,_bga };if _gcg {_afc [2]=_aaga *2;
|
|
|
|
_afc [3]=_bga *2;};_ddaf .Rect =_afc ;};_ddedg :=_afc [2]-_afc [0];_fcag :=_afc [3]-_afc [1];_ggae ,_dbba :=_afc ,_afc ;var _fddg ,_fbac float64 ;if _gcg &&len (_aeb )> 0{if _ddaf .ImagePosition <=SignatureImageRight {_gabd :=[]float64 {_afc [0],_afc [1],_afc [0]+(_ddedg /2),_afc [3]};
|
|
|
|
_ggaa :=[]float64 {_afc [0]+(_ddedg /2),_afc [1],_afc [2],_afc [3]};if _ddaf .ImagePosition ==SignatureImageLeft {_ggae ,_dbba =_gabd ,_ggaa ;}else {_ggae ,_dbba =_ggaa ,_gabd ;};}else {_ebb :=[]float64 {_afc [0],_afc [1],_afc [2],_afc [1]+(_fcag /2)};
|
|
|
|
_cae :=[]float64 {_afc [0],_afc [1]+(_fcag /2),_afc [2],_afc [3]};if _ddaf .ImagePosition ==SignatureImageTop {_ggae ,_dbba =_cae ,_ebb ;}else {_ggae ,_dbba =_ebb ,_cae ;};};};_fddg =_dbba [2]-_dbba [0];_fbac =_dbba [3]-_dbba [1];var _afaa float64 ;if _ddaf .AutoSize {if _aaga > _fddg ||_bga > _fbac {_cbge :=_g .Min (_fddg /_aaga ,_fbac /_bga );
|
|
|
|
_cgbe *=_cbge ;};_efc =_ddaf .LineHeight *_cgbe ;_afaa +=(_fbac -float64 (len (_aeb ))*_efc )/2;};_efff :=_c .NewContentCreator ();_geff :=_de .NewPdfPageResources ();_geff .SetFontByName (*_dfcg ,_dfcf .ToPdfObject ());if _ddaf .BorderSize <=0{_ddaf .BorderSize =0;
|
|
|
|
_ddaf .BorderColor =_de .NewPdfColorDeviceGray (1);};if _ddaf .BorderColor ==nil {_ddaf .BorderColor =_de .NewPdfColorDeviceGray (1);};if _ddaf .FillColor ==nil {_ddaf .FillColor =_de .NewPdfColorDeviceGray (1);};_efff .Add_q ().SetNonStrokingColor (_ddaf .FillColor ).SetStrokingColor (_ddaf .BorderColor ).Add_w (_ddaf .BorderSize ).Add_re (_afc [0],_afc [1],_ddedg ,_fcag ).Add_B ().Add_Q ();
|
|
|
|
if _ddaf .WatermarkImage !=nil {_bad :=[]float64 {_afc [0],_afc [1],_afc [2],_afc [3]};_aece ,_aefb ,_cdbe :=_dfgd (_ddaf .WatermarkImage ,"\u0049\u006d\u0061\u0067\u0065\u0057\u0061\u0074\u0065r\u006d\u0061\u0072\u006b",_ddaf ,_bad ,_efff );if _cdbe !=nil {return nil ,_cdbe ;
|
|
|
|
};_geff .SetXObjectImageByName (*_aece ,_aefb );};_efff .Add_q ();_efff .Translate (_dbba [0],_dbba [3]-_efc -_afaa );_efff .Add_BT ();_afbc :=_dfcf .Encoder ();for _ ,_acbf :=range _aeb {var _fgfb []byte ;for _ ,_ebgg :=range _acbf {if _ae .IsSpace (_ebgg ){if len (_fgfb )> 0{_efff .SetNonStrokingColor (_ddaf .TextColor ).Add_Tf (*_dfcg ,_cgbe ).Add_TL (_efc ).Add_TJ ([]_bc .PdfObject {_bc .MakeStringFromBytes (_fgfb )}...);
|
|
|
|
_fgfb =nil ;};_efff .Add_Tf (*_dfcg ,_cgbe ).Add_TL (_efc ).Add_TJ ([]_bc .PdfObject {_bc .MakeFloat (-_cbag )}...);}else {_fgfb =append (_fgfb ,_afbc .Encode (string (_ebgg ))...);};};if len (_fgfb )> 0{_efff .SetNonStrokingColor (_ddaf .TextColor ).Add_Tf (*_dfcg ,_cgbe ).Add_TL (_efc ).Add_TJ ([]_bc .PdfObject {_bc .MakeStringFromBytes (_fgfb )}...);
|
|
|
|
};_efff .Add_Td (0,-_efc );};_efff .Add_ET ();_efff .Add_Q ();if _gcg {_fgec ,_dcfd ,_ggedc :=_dfgd (_ddaf .Image ,"\u0049\u006d\u0061\u0067\u0065\u0053\u0069\u0067\u006ea\u0074\u0075\u0072\u0065",_ddaf ,_ggae ,_efff );if _ggedc !=nil {return nil ,_ggedc ;
|
|
|
|
};_geff .SetXObjectImageByName (*_fgec ,_dcfd );};_ffb :=_de .NewXObjectForm ();_ffb .Resources =_geff ;_ffb .BBox =_bc .MakeArrayFromFloats (_afc );_ffb .SetContentStream (_efff .Bytes (),_dac ());_eafc :=_bc .MakeDict ();_eafc .Set ("\u004e",_ffb .ToPdfObject ());
|
|
|
|
return _eafc ,nil ;};func _daf (_cga *_de .PdfField )string {if _cga ==nil {return "";};_agd ,_adaa :=_cga .GetContext ().(*_de .PdfFieldText );if !_adaa {return _daf (_cga .Parent );};if _agd .DA !=nil {return _agd .DA .Str ();};return _daf (_agd .Parent );
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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 *_de .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 ;};
|
2021-03-23 23:12:52 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// SignatureFieldOpts represents a set of options used to configure
|
|
|
|
// an appearance widget dictionary.
|
|
|
|
type SignatureFieldOpts struct{
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// Rect represents the area the signature annotation is displayed on.
|
|
|
|
Rect []float64 ;
|
2021-04-06 22:35:37 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// AutoSize specifies if the content of the appearance should be
|
|
|
|
// scaled to fit in the annotation rectangle.
|
|
|
|
AutoSize bool ;
|
2021-04-06 22:35:37 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// Font specifies the font of the text content.
|
2021-05-31 17:17:31 +00:00
|
|
|
Font *_de .PdfFont ;
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// FontSize specifies the size of the text content.
|
|
|
|
FontSize float64 ;
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// LineHeight specifies the height of a line of text in the appearance annotation.
|
|
|
|
LineHeight float64 ;
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// TextColor represents the color of the text content displayed.
|
2021-05-31 17:17:31 +00:00
|
|
|
TextColor _de .PdfColor ;
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// FillColor represents the background color of the appearance annotation area.
|
2021-05-31 17:17:31 +00:00
|
|
|
FillColor _de .PdfColor ;
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// BorderSize represents border size of the appearance annotation area.
|
|
|
|
BorderSize float64 ;
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// BorderColor represents the border color of the appearance annotation area.
|
2021-05-31 17:17:31 +00:00
|
|
|
BorderColor _de .PdfColor ;
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// WatermarkImage specifies the image used as a watermark that will be rendered
|
|
|
|
// behind the signature.
|
2021-05-31 17:17:31 +00:00
|
|
|
WatermarkImage _d .Image ;
|
2021-04-06 22:35:37 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// Image represents the image used for the signature appearance.
|
2021-05-31 17:17:31 +00:00
|
|
|
Image _d .Image ;
|
2021-04-06 22:35:37 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// Encoder specifies the image encoder used for image signature. Defaults to flate encoder.
|
2021-05-31 17:17:31 +00:00
|
|
|
Encoder _bc .StreamEncoder ;
|
2021-04-06 22:35:37 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// ImagePosition specifies the image location relative to the text signature.
|
2021-05-31 17:17:31 +00:00
|
|
|
ImagePosition SignatureImagePosition ;};
|
2020-11-11 18:48:37 +00:00
|
|
|
|
2021-05-11 00:01:27 +00:00
|
|
|
// NewCheckboxField generates a new checkbox field with partial name `name` at location `rect`
|
|
|
|
// on specified `page` and with field specific options `opt`.
|
2021-05-31 17:17:31 +00:00
|
|
|
func NewCheckboxField (page *_de .PdfPage ,name string ,rect []float64 ,opt CheckboxFieldOptions )(*_de .PdfFieldButton ,error ){if page ==nil {return nil ,_ea .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
|
|
|
|
};if len (name )<=0{return nil ,_ea .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 ,_ea .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
|
|
|
|
};_ccbg ,_bfee :=_de .NewStandard14Font (_de .ZapfDingbatsName );if _bfee !=nil {return nil ,_bfee ;};_aeaa :=_de .NewPdfField ();_aad :=&_de .PdfFieldButton {};_aeaa .SetContext (_aad );_aad .PdfField =_aeaa ;_aad .T =_bc .MakeString (name );_aad .SetType (_de .ButtonTypeCheckbox );
|
|
|
|
_bacf :="\u004f\u0066\u0066";if opt .Checked {_bacf ="\u0059\u0065\u0073";};_aad .V =_bc .MakeName (_bacf );_adf :=_de .NewPdfAnnotationWidget ();_adf .Rect =_bc .MakeArrayFromFloats (rect );_adf .P =page .ToPdfObject ();_adf .F =_bc .MakeInteger (4);_adf .Parent =_aad .ToPdfObject ();
|
|
|
|
_bdcd :=rect [2]-rect [0];_dedb :=rect [3]-rect [1];var _dgcb _bbg .Buffer ;_dgcb .WriteString ("\u0071\u000a");_dgcb .WriteString ("\u0030 \u0030\u0020\u0031\u0020\u0072\u0067\n");_dgcb .WriteString ("\u0042\u0054\u000a");_dgcb .WriteString ("\u002f\u005a\u0061D\u0062\u0020\u0031\u0032\u0020\u0054\u0066\u000a");
|
|
|
|
_dgcb .WriteString ("\u0045\u0054\u000a");_dgcb .WriteString ("\u0051\u000a");_ffbf :=_c .NewContentCreator ();_ffbf .Add_q ();_ffbf .Add_rg (0,0,1);_ffbf .Add_BT ();_ffbf .Add_Tf (*_bc .MakeName ("\u005a\u0061\u0044\u0062"),12);_ffbf .Add_Td (0,0);_ffbf .Add_ET ();
|
|
|
|
_ffbf .Add_Q ();_faf :=_de .NewXObjectForm ();_faf .SetContentStream (_ffbf .Bytes (),_bc .NewRawEncoder ());_faf .BBox =_bc .MakeArrayFromFloats ([]float64 {0,0,_bdcd ,_dedb });_faf .Resources =_de .NewPdfPageResources ();_faf .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_ccbg .ToPdfObject ());
|
|
|
|
_ffbf =_c .NewContentCreator ();_ffbf .Add_q ();_ffbf .Add_re (0,0,_bdcd ,_dedb );_ffbf .Add_W ().Add_n ();_ffbf .Add_rg (0,0,1);_ffbf .Translate (0,3.0);_ffbf .Add_BT ();_ffbf .Add_Tf (*_bc .MakeName ("\u005a\u0061\u0044\u0062"),12);_ffbf .Add_Td (0,0);
|
|
|
|
_ffbf .Add_Tj (*_bc .MakeString ("\u0034"));_ffbf .Add_ET ();_ffbf .Add_Q ();_agfe :=_de .NewXObjectForm ();_agfe .SetContentStream (_ffbf .Bytes (),_bc .NewRawEncoder ());_agfe .BBox =_bc .MakeArrayFromFloats ([]float64 {0,0,_bdcd ,_dedb });_agfe .Resources =_de .NewPdfPageResources ();
|
|
|
|
_agfe .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_ccbg .ToPdfObject ());_fcd :=_bc .MakeDict ();_fcd .Set ("\u004f\u0066\u0066",_faf .ToPdfObject ());_fcd .Set ("\u0059\u0065\u0073",_agfe .ToPdfObject ());_fbea :=_bc .MakeDict ();_fbea .Set ("\u004e",_fcd );
|
|
|
|
_adf .AP =_fbea ;_adf .AS =_bc .MakeName (_bacf );_aad .Annotations =append (_aad .Annotations ,_adf );return _aad ,nil ;};
|
2020-11-11 18:48:37 +00:00
|
|
|
|
2021-05-11 00:01:27 +00:00
|
|
|
// SetStyle applies appearance `style` to `fa`.
|
2021-05-31 17:17:31 +00:00
|
|
|
func (_ab *FieldAppearance )SetStyle (style AppearanceStyle ){_ab ._dcf =&style };func _aecd (_gbdb *_de .PdfAnnotationWidget ,_gcf *_de .PdfFieldButton ,_dgef *_de .PdfPageResources ,_bfa AppearanceStyle )(*_bc .PdfObjectDictionary ,error ){_cbcg ,_dea :=_bc .GetArray (_gbdb .Rect );
|
|
|
|
if !_dea {return nil ,_ea .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_edg ,_acbe :=_de .NewPdfRectangle (*_cbcg );if _acbe !=nil {return nil ,_acbe ;};_ced ,_cgec :=_edg .Width (),_edg .Height ();_fbcb ,_bfb :=_ced ,_cgec ;
|
|
|
|
_bb .Log .Debug ("\u0043\u0068\u0065\u0063kb\u006f\u0078\u002c\u0020\u0077\u0061\u0020\u0042\u0053\u003a\u0020\u0025\u0076",_gbdb .BS );_fga ,_acbe :=_de .NewStandard14Font ("\u005a\u0061\u0070f\u0044\u0069\u006e\u0067\u0062\u0061\u0074\u0073");if _acbe !=nil {return nil ,_acbe ;
|
|
|
|
};_ffg ,_ecd :=_bc .GetDict (_gbdb .MK );if _ecd {_dfc ,_ :=_bc .GetDict (_gbdb .BS );_ca :=_bfa .applyAppearanceCharacteristics (_ffg ,_dfc ,_fga );if _ca !=nil {return nil ,_ca ;};};_dega :=_de .NewXObjectForm ();{_edff :=_c .NewContentCreator ();if _bfa .BorderSize > 0{_cfeg (_edff ,_bfa ,_ced ,_cgec );
|
|
|
|
};if _bfa .DrawAlignmentReticle {_afbe :=_bfa ;_afbe .BorderSize =0.2;_gcd (_edff ,_afbe ,_ced ,_cgec );};_ced ,_cgec =_bfa .applyRotation (_ffg ,_ced ,_cgec ,_edff );_cbcf :=_bfa .AutoFontSizeFraction *_cgec ;_eff ,_fge :=_fga .GetRuneMetrics (_bfa .CheckmarkRune );
|
|
|
|
if !_fge {return nil ,_ea .New ("\u0067l\u0079p\u0068\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");};_eeg :=_fga .Encoder ();_geg :=_eeg .Encode (string (_bfa .CheckmarkRune ));_gggd :=_eff .Wx *_cbcf /1000.0;_cfcb :=705.0;_ggce :=_cfcb /1000.0*_cbcf ;
|
|
|
|
_bac :=2.0;_aecg :=1.0;if _gggd < _ced {_bac =(_ced -_gggd )/2.0;};if _ggce < _cgec {_aecg =(_cgec -_ggce )/2.0;};_edff .Add_q ().Add_g (0).Add_BT ().Add_Tf ("\u005a\u0061\u0044\u0062",_cbcf ).Add_Td (_bac ,_aecg ).Add_Tj (*_bc .MakeStringFromBytes (_geg )).Add_ET ().Add_Q ();
|
|
|
|
_dega .Resources =_de .NewPdfPageResources ();_dega .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_fga .ToPdfObject ());_dega .BBox =_bc .MakeArrayFromFloats ([]float64 {0,0,_fbcb ,_bfb });_dega .SetContentStream (_edff .Bytes (),_dac ());};_cbga :=_de .NewXObjectForm ();
|
|
|
|
{_fadd :=_c .NewContentCreator ();if _bfa .BorderSize > 0{_cfeg (_fadd ,_bfa ,_ced ,_cgec );};_cbga .BBox =_bc .MakeArrayFromFloats ([]float64 {0,0,_fbcb ,_bfb });_cbga .SetContentStream (_fadd .Bytes (),_dac ());};_ggab :=_bc .MakeDict ();_ggab .Set ("\u004f\u0066\u0066",_cbga .ToPdfObject ());
|
|
|
|
_ggab .Set ("\u0059\u0065\u0073",_dega .ToPdfObject ());_gab :=_bc .MakeDict ();_gab .Set ("\u004e",_ggab );return _gab ,nil ;};func _cgcd (_ega LineAnnotationDef )(*_bc .PdfObjectDictionary ,*_de .PdfRectangle ,error ){_geffe :=_de .NewXObjectForm ();
|
|
|
|
_geffe .Resources =_de .NewPdfPageResources ();_aae :="";if _ega .Opacity < 1.0{_dede :=_bc .MakeDict ();_dede .Set ("\u0063\u0061",_bc .MakeFloat (_ega .Opacity ));_fcdc :=_geffe .Resources .AddExtGState ("\u0067\u0073\u0031",_dede );if _fcdc !=nil {_bb .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 ,_fcdc ;};_aae ="\u0067\u0073\u0031";};_ecf ,_bcg ,_edbe ,_eab :=_gfbc (_ega ,_aae );if _eab !=nil {return nil ,nil ,_eab ;};_eab =_geffe .SetContentStream (_ecf ,nil );if _eab !=nil {return nil ,nil ,_eab ;};_geffe .BBox =_bcg .ToPdfObject ();
|
|
|
|
_bgcd :=_bc .MakeDict ();_bgcd .Set ("\u004e",_geffe .ToPdfObject ());return _bgcd ,_edbe ,nil ;};
|
|
|
|
|
|
|
|
// Style returns the appearance style of `fa`. If not specified, returns default style.
|
|
|
|
func (_fcg FieldAppearance )Style ()AppearanceStyle {if _fcg ._dcf !=nil {return *_fcg ._dcf ;};return AppearanceStyle {AutoFontSizeFraction :0.65,CheckmarkRune :'✔',BorderSize :0.0,BorderColor :_de .NewPdfColorDeviceGray (0),FillColor :_de .NewPdfColorDeviceGray (1),MultilineLineHeight :1.2,MultilineVAlignMiddle :false ,DrawAlignmentReticle :false ,AllowMK :true };
|
|
|
|
};
|
2020-11-11 18:48:37 +00:00
|
|
|
|
2021-05-11 00:01:27 +00:00
|
|
|
// GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`.
|
|
|
|
// Implements interface model.FieldAppearanceGenerator.
|
2021-05-31 17:17:31 +00:00
|
|
|
func (_cd FieldAppearance )GenerateAppearanceDict (form *_de .PdfAcroForm ,field *_de .PdfField ,wa *_de .PdfAnnotationWidget )(*_bc .PdfObjectDictionary ,error ){_bb .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 );
|
|
|
|
_ ,_acb :=field .GetContext ().(*_de .PdfFieldText );_ge ,_bg :=_bc .GetDict (wa .AP );if _bg &&_cd .OnlyIfMissing &&(!_acb ||!_cd .RegenerateTextFields ){_bb .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 _ge ,nil ;};if form .DR ==nil {form .DR =_de .NewPdfPageResources ();};switch _gbd :=field .GetContext ().(type ){case *_de .PdfFieldText :_fa :=_gbd ;switch {case _fa .Flags ().Has (_de .FieldFlagPassword ):return nil ,nil ;case _fa .Flags ().Has (_de .FieldFlagFileSelect ):return nil ,nil ;
|
|
|
|
case _fa .Flags ().Has (_de .FieldFlagComb ):if _fa .MaxLen !=nil {_dgb ,_fgfd :=_bed (wa ,_fa ,form .DR ,_cd .Style ());if _fgfd !=nil {return nil ,_fgfd ;};return _dgb ,nil ;};};_cg ,_da :=_bd (wa ,_fa ,form .DR ,_cd .Style ());if _da !=nil {return nil ,_da ;
|
|
|
|
};return _cg ,nil ;case *_de .PdfFieldButton :_ebf :=_gbd ;if _ebf .IsCheckbox (){_eg ,_ad :=_aecd (wa ,_ebf ,form .DR ,_cd .Style ());if _ad !=nil {return nil ,_ad ;};return _eg ,nil ;};_bb .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",_ebf .GetType ());
|
|
|
|
case *_de .PdfFieldChoice :_fad :=_gbd ;switch {case _fad .Flags ().Has (_de .FieldFlagCombo ):_befg ,_fd :=_gge (form ,wa ,_fad ,_cd .Style ());if _fd !=nil {return nil ,_fd ;};return _befg ,nil ;default:_bb .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",_fad .Flags ().String ());
|
|
|
|
};default:_bb .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",_gbd );};return nil ,nil ;};const (_dgf quadding =0;
|
|
|
|
_fgf quadding =1;_fc quadding =2;);
|
2021-03-13 21:28:23 +00:00
|
|
|
|
2021-05-31 17:17:31 +00:00
|
|
|
// CreateCircleAnnotation creates a circle/ellipse annotation object with appearance stream that can be added to
|
|
|
|
// page PDF annotations.
|
|
|
|
func CreateCircleAnnotation (circDef CircleAnnotationDef )(*_de .PdfAnnotation ,error ){_f :=_de .NewPdfAnnotationCircle ();if circDef .BorderEnabled {_dc ,_dd ,_db :=circDef .BorderColor .R (),circDef .BorderColor .G (),circDef .BorderColor .B ();_f .C =_bc .MakeArrayFromFloats ([]float64 {_dc ,_dd ,_db });
|
|
|
|
_be :=_de .NewBorderStyle ();_be .SetBorderWidth (circDef .BorderWidth );_f .BS =_be .ToPdfObject ();};if circDef .FillEnabled {_ac ,_bcc ,_dce :=circDef .FillColor .R (),circDef .FillColor .G (),circDef .FillColor .B ();_f .IC =_bc .MakeArrayFromFloats ([]float64 {_ac ,_bcc ,_dce });
|
|
|
|
}else {_f .IC =_bc .MakeArrayFromIntegers ([]int {});};if circDef .Opacity < 1.0{_f .CA =_bc .MakeFloat (circDef .Opacity );};_ed ,_bf ,_gf :=_bef (circDef );if _gf !=nil {return nil ,_gf ;};_f .AP =_ed ;_f .Rect =_bc .MakeArrayFromFloats ([]float64 {_bf .Llx ,_bf .Lly ,_bf .Urx ,_bf .Ury });
|
|
|
|
return _f .PdfAnnotation ,nil ;};const (SignatureImageLeft SignatureImagePosition =iota ;SignatureImageRight ;SignatureImageTop ;SignatureImageBottom ;);func _gcd (_cbgg *_c .ContentCreator ,_ffab AppearanceStyle ,_fcac ,_afdg float64 ){_cbgg .Add_q ().Add_re (0,0,_fcac ,_afdg ).Add_re (0,_afdg /2,_fcac ,_afdg /2).Add_re (0,0,_fcac ,_afdg ).Add_re (_fcac /2,0,_fcac /2,_afdg ).Add_w (_ffab .BorderSize ).SetStrokingColor (_ffab .BorderColor ).SetNonStrokingColor (_ffab .FillColor ).Add_B ().Add_Q ();
|
|
|
|
};
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2021-05-31 17:17:31 +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 *_de .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_de .PdfColorDeviceRGB ;Opacity float64 ;};func _bed (_bbgb *_de .PdfAnnotationWidget ,_ggg *_de .PdfFieldText ,_cf *_de .PdfPageResources ,_dag AppearanceStyle )(*_bc .PdfObjectDictionary ,error ){_afd :=_de .NewPdfPageResources ();
|
|
|
|
_eee ,_deea :=_bc .GetArray (_bbgb .Rect );if !_deea {return nil ,_ea .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_edfd ,_eaf :=_de .NewPdfRectangle (*_eee );if _eaf !=nil {return nil ,_eaf ;};_gbb ,_cfc :=_edfd .Width (),_edfd .Height ();
|
|
|
|
_aec ,_ddb :=_gbb ,_cfc ;_efa ,_bff :=_bc .GetDict (_bbgb .MK );if _bff {_gad ,_ :=_bc .GetDict (_bbgb .BS );_dca :=_dag .applyAppearanceCharacteristics (_efa ,_gad ,nil );if _dca !=nil {return nil ,_dca ;};};_bbb ,_bff :=_bc .GetIntVal (_ggg .MaxLen );
|
|
|
|
if !_bff {return nil ,_ea .New ("\u006d\u0061\u0078\u006c\u0065\u006e\u0020\u006e\u006ft\u0020\u0073\u0065\u0074");};if _bbb <=0{return nil ,_ea .New ("\u006d\u0061\u0078\u004c\u0065\u006e\u0020\u0069\u006ev\u0061\u006c\u0069\u0064");};_dbc :=_gbb /float64 (_bbb );
|
|
|
|
_gadf ,_eaf :=_c .NewContentStreamParser (_daf (_ggg .PdfField )).Parse ();if _eaf !=nil {return nil ,_eaf ;};_ead :=_c .NewContentCreator ();if _dag .BorderSize > 0{_cfeg (_ead ,_dag ,_gbb ,_cfc );};if _dag .DrawAlignmentReticle {_ffda :=_dag ;_ffda .BorderSize =0.2;
|
|
|
|
_gcd (_ead ,_ffda ,_gbb ,_cfc );};_ead .Add_BMC ("\u0054\u0078");_ead .Add_q ();_ ,_cfc =_dag .applyRotation (_efa ,_gbb ,_cfc ,_ead );_ead .Add_BT ();_bfc ,_fbe ,_eaf :=_dag .processDA (_ggg .PdfField ,_gadf ,_cf ,_afd ,_ead );if _eaf !=nil {return nil ,_eaf ;
|
|
|
|
};_gfc :=_bfc .Font ;_dff :=_bc .MakeName (_bfc .Name );_ffe :=_bfc .Size ;_acf :=_ffe ==0;if _acf &&_fbe {_ffe =_cfc *_dag .AutoFontSizeFraction ;};_cbc :=_gfc .Encoder ();if _cbc ==nil {_bb .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");
|
|
|
|
_cbc =_a .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};var _aacd string ;if _dgec ,_gfg :=_bc .GetString (_ggg .V );_gfg {_aacd =_dgec .Decoded ();};_ead .Add_Tf (*_dff ,_ffe );var _eac float64 ;for _ ,_dcd :=range _aacd {_gc ,_gfge :=_gfc .GetRuneMetrics (_dcd );
|
|
|
|
if !_gfge {_bb .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",_dcd );
|
|
|
|
continue ;};_dded :=_gc .Wy ;if int (_dded )<=0{_dded =_gc .Wx ;};if _dded > _eac {_eac =_dded ;};};if int (_eac )==0{_bb .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");
|
|
|
|
_eac =1000;};_ccb ,_eaf :=_gfc .GetFontDescriptor ();if _eaf !=nil {_bb .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 _edfdd float64 ;if _ccb !=nil {_edfdd ,_eaf =_ccb .GetCapHeight ();if _eaf !=nil {_bb .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",_eaf );
|
|
|
|
};};if int (_edfdd )<=0{_bb .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");
|
|
|
|
_edfdd =1000.0;};_dba :=_edfdd /1000.0*_ffe ;_gdd :=0.0;_edd :=1.0*_ffe *(_eac /1000.0);{_bfe :=_edd ;if _acf &&_gdd +_bfe > _cfc {_ffe =0.95*(_cfc -_gdd );_dba =_edfdd /1000.0*_ffe ;};if _cfc > _dba {_gdd =(_cfc -_dba )/2.0;};};_ead .Add_Td (0,_gdd );
|
|
|
|
if _ded ,_fbc :=_bc .GetIntVal (_ggg .Q );_fbc {switch _ded {case 2:if len (_aacd )< _bbb {_efd :=float64 (_bbb -len (_aacd ))*_dbc ;_ead .Add_Td (_efd ,0);};};};for _eca ,_dfg :=range _aacd {_gfb :=2.0;_cdb :=string (_dfg );if _cbc !=nil {_cccf ,_fff :=_gfc .GetRuneMetrics (_dfg );
|
|
|
|
if !_fff {_bb .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",_dfg );
|
|
|
|
continue ;};_cdb =string (_cbc .Encode (_cdb ));_dfd :=_ffe *_cccf .Wx /1000.0;_geed :=(_dbc -_dfd )/2;_gfb =_geed ;};_ead .Add_Td (_gfb ,0);_ead .Add_Tj (*_bc .MakeString (_cdb ));if _eca !=len (_aacd )-1{_ead .Add_Td (_dbc -_gfb ,0);};};_ead .Add_ET ();
|
|
|
|
_ead .Add_Q ();_ead .Add_EMC ();_daa :=_de .NewXObjectForm ();_daa .Resources =_afd ;_daa .BBox =_bc .MakeArrayFromFloats ([]float64 {0,0,_aec ,_ddb });_daa .SetContentStream (_ead .Bytes (),_dac ());_aegg :=_bc .MakeDict ();_aegg .Set ("\u004e",_daa .ToPdfObject ());
|
|
|
|
return _aegg ,nil ;};
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2021-05-31 17:17:31 +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 ;_dcf *AppearanceStyle ;};
|
2021-04-23 20:28:14 +00:00
|
|
|
|
|
|
|
// NewSignatureFieldOpts returns a new initialized instance of options
|
|
|
|
// used to generate a signature appearance.
|
2021-05-31 17:17:31 +00:00
|
|
|
func NewSignatureFieldOpts ()*SignatureFieldOpts {return &SignatureFieldOpts {Font :_de .DefaultFont (),FontSize :10,LineHeight :1,AutoSize :true ,TextColor :_de .NewPdfColorDeviceGray (0),BorderColor :_de .NewPdfColorDeviceGray (0),FillColor :_de .NewPdfColorDeviceGray (1),Encoder :_bc .NewFlateEncoder (),ImagePosition :SignatureImageLeft };
|
|
|
|
};func _gggc (_dgge RectangleAnnotationDef )(*_bc .PdfObjectDictionary ,*_de .PdfRectangle ,error ){_dffe :=_de .NewXObjectForm ();_dffe .Resources =_de .NewPdfPageResources ();_bdbg :="";if _dgge .Opacity < 1.0{_eeb :=_bc .MakeDict ();_eeb .Set ("\u0063\u0061",_bc .MakeFloat (_dgge .Opacity ));
|
|
|
|
_eeb .Set ("\u0043\u0041",_bc .MakeFloat (_dgge .Opacity ));_cfca :=_dffe .Resources .AddExtGState ("\u0067\u0073\u0031",_eeb );if _cfca !=nil {_bb .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 ,_cfca ;};_bdbg ="\u0067\u0073\u0031";};_bgf ,_dga ,_ddd ,_gcec :=_fea (_dgge ,_bdbg );if _gcec !=nil {return nil ,nil ,_gcec ;};_gcec =_dffe .SetContentStream (_bgf ,nil );if _gcec !=nil {return nil ,nil ,_gcec ;};_dffe .BBox =_dga .ToPdfObject ();
|
|
|
|
_afdf :=_bc .MakeDict ();_afdf .Set ("\u004e",_dffe .ToPdfObject ());return _afdf ,_ddd ,nil ;};func _dgeb (_fbb *_de .PdfField ,_cgee ,_ebce float64 ,_egge string ,_gdgc AppearanceStyle ,_eddd *_c .ContentStreamOperations ,_bde *_de .PdfPageResources ,_cad *_bc .PdfObjectDictionary )(*_de .XObjectForm ,error ){_gbda :=_de .NewPdfPageResources ();
|
|
|
|
_bace ,_fca :=_cgee ,_ebce ;_cfe :=_c .NewContentCreator ();if _gdgc .BorderSize > 0{_cfeg (_cfe ,_gdgc ,_cgee ,_ebce );};if _gdgc .DrawAlignmentReticle {_bdb :=_gdgc ;_bdb .BorderSize =0.2;_gcd (_cfe ,_bdb ,_cgee ,_ebce );};_cfe .Add_BMC ("\u0054\u0078");
|
|
|
|
_cfe .Add_q ();_cfe .Add_BT ();_cgee ,_ebce =_gdgc .applyRotation (_cad ,_cgee ,_ebce ,_cfe );_fcc ,_debe ,_bbf :=_gdgc .processDA (_fbb ,_eddd ,_bde ,_gbda ,_cfe );if _bbf !=nil {return nil ,_bbf ;};_dfgf :=_fcc .Font ;_bca :=_fcc .Size ;_acfg :=_bc .MakeName (_fcc .Name );
|
|
|
|
_ebfe :=_bca ==0;if _ebfe &&_debe {_bca =_ebce *_gdgc .AutoFontSizeFraction ;};_fcga :=_dfgf .Encoder ();if _fcga ==nil {_bb .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");
|
|
|
|
_fcga =_a .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};if len (_egge )==0{return nil ,nil ;};_abg :=2.0;_acbb :=0.0;if _fcga !=nil {for _ ,_caf :=range _egge {_agf ,_gde :=_dfgf .GetRuneMetrics (_caf );if !_gde {_bb .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",_caf );
|
|
|
|
continue ;};_acbb +=_agf .Wx ;};_egge =string (_fcga .Encode (_egge ));};if _bca ==0||_ebfe &&_acbb > 0&&_abg +_acbb *_bca /1000.0> _cgee {_bca =0.95*1000.0*(_cgee -_abg )/_acbb ;};_cff :=1.0*_bca ;_age :=2.0;{_dbfc :=_cff ;if _ebfe &&_age +_dbfc > _ebce {_bca =0.95*(_ebce -_age );
|
|
|
|
_cff =1.0*_bca ;_dbfc =_cff ;};if _ebce > _dbfc {_age =(_ebce -_dbfc )/2.0;_age +=1.50;};};_cfe .Add_Tf (*_acfg ,_bca );_cfe .Add_Td (_abg ,_age );_cfe .Add_Tj (*_bc .MakeString (_egge ));_cfe .Add_ET ();_cfe .Add_Q ();_cfe .Add_EMC ();_fac :=_de .NewXObjectForm ();
|
|
|
|
_fac .Resources =_gbda ;_fac .BBox =_bc .MakeArrayFromFloats ([]float64 {0,0,_bace ,_fca });_fac .SetContentStream (_cfe .Bytes (),_dac ());return _fac ,nil ;};
|
2020-10-12 14:17:59 +00:00
|
|
|
|
2021-05-31 17:17:31 +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 };};
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2021-05-31 17:17:31 +00:00
|
|
|
// ComboboxFieldOptions defines optional parameters for a combobox form field.
|
|
|
|
type ComboboxFieldOptions struct{
|
2021-01-07 14:20:10 +00:00
|
|
|
|
2021-05-31 17:17:31 +00:00
|
|
|
// Choices is the list of string values that can be selected.
|
|
|
|
Choices []string ;};func (_efde *AppearanceStyle )applyRotation (_bgd *_bc .PdfObjectDictionary ,_adb ,_bag float64 ,_baa *_c .ContentCreator )(float64 ,float64 ){if !_efde .AllowMK {return _adb ,_bag ;};if _bgd ==nil {return _adb ,_bag ;};_geae ,_ :=_bc .GetNumberAsFloat (_bgd .Get ("\u0052"));
|
|
|
|
if _geae ==0{return _adb ,_bag ;};_cggg :=-_geae ;_cgd :=_gb .Path {Points :[]_gb .Point {_gb .NewPoint (0,0).Rotate (_cggg ),_gb .NewPoint (_adb ,0).Rotate (_cggg ),_gb .NewPoint (0,_bag ).Rotate (_cggg ),_gb .NewPoint (_adb ,_bag ).Rotate (_cggg )}}.GetBoundingBox ();
|
|
|
|
_baa .RotateDeg (_geae );_baa .Translate (_cgd .X ,_cgd .Y );return _cgd .Width ,_cgd .Height ;};func (_ggeb *AppearanceStyle )processDA (_dcg *_de .PdfField ,_aegc *_c .ContentStreamOperations ,_fbca ,_daff *_de .PdfPageResources ,_cgaa *_c .ContentCreator )(*AppearanceFont ,bool ,error ){var _edb *AppearanceFont ;
|
|
|
|
var _cgad bool ;if _ggeb .Fonts !=nil {if _ggeb .Fonts .Fallback !=nil {_edb =_ggeb .Fonts .Fallback ;};if _cec :=_ggeb .Fonts .FieldFallbacks ;_cec !=nil {if _efab ,_bcad :=_cec [_dcg .PartialName ()];_bcad {_edb =_efab ;}else if _ddede ,_ggd :=_dcg .FullName ();
|
|
|
|
_ggd ==nil {if _bcdc ,_aab :=_cec [_ddede ];_aab {_edb =_bcdc ;};};};_cgad =_ggeb .Fonts .ForceReplace ;};var _bdge string ;var _aea float64 ;var _ebcb bool ;if _aegc !=nil {for _ ,_gged :=range *_aegc {if _gged .Operand =="\u0054\u0066"&&len (_gged .Params )==2{if _afbg ,_ebge :=_bc .GetNameVal (_gged .Params [0]);
|
|
|
|
_ebge {_bdge =_afbg ;};if _gfbe ,_dcb :=_bc .GetNumberAsFloat (_gged .Params [1]);_dcb ==nil {_aea =_gfbe ;};_ebcb =true ;continue ;};_cgaa .AddOperand (*_gged );};};var _fgge *AppearanceFont ;var _ede _bc .PdfObject ;if _cgad &&_edb !=nil {_fgge =_edb ;
|
|
|
|
}else {if _fbca !=nil &&_bdge !=""{if _ebfg ,_gabb :=_fbca .GetFontByName (*_bc .MakeName (_bdge ));_gabb {if _fbde ,_afdgf :=_de .NewPdfFontFromPdfObject (_ebfg );_afdgf ==nil {_ede =_ebfg ;_fgge =&AppearanceFont {Name :_bdge ,Font :_fbde ,Size :_aea };
|
|
|
|
}else {_bb .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",_afdgf );
|
|
|
|
};};};if _fgge ==nil &&_edb !=nil {_fgge =_edb ;};if _fgge ==nil {_edddf ,_beb :=_de .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");if _beb !=nil {return nil ,false ,_beb ;};_fgge =&AppearanceFont {Name :"\u0048\u0065\u006c\u0076",Font :_edddf ,Size :_aea };
|
|
|
|
};};_gabc :=*_bc .MakeName (_fgge .Name );if _ede ==nil {_ede =_fgge .Font .ToPdfObject ();};if _fbca !=nil &&!_fbca .HasFontByName (_gabc ){_fbca .SetFontByName (_gabc ,_ede );};if _daff !=nil &&!_daff .HasFontByName (_gabc ){_daff .SetFontByName (_gabc ,_ede );
|
|
|
|
};return _fgge ,_ebcb ,nil ;};
|
2020-08-31 21:12:07 +00:00
|
|
|
|
2021-05-31 17:17:31 +00:00
|
|
|
// CreateRectangleAnnotation creates a rectangle annotation object that can be added to page PDF annotations.
|
|
|
|
func CreateRectangleAnnotation (rectDef RectangleAnnotationDef )(*_de .PdfAnnotation ,error ){_add :=_de .NewPdfAnnotationSquare ();if rectDef .BorderEnabled {_cbb ,_dfgad ,_dcdec :=rectDef .BorderColor .R (),rectDef .BorderColor .G (),rectDef .BorderColor .B ();
|
|
|
|
_add .C =_bc .MakeArrayFromFloats ([]float64 {_cbb ,_dfgad ,_dcdec });_dcga :=_de .NewBorderStyle ();_dcga .SetBorderWidth (rectDef .BorderWidth );_add .BS =_dcga .ToPdfObject ();};if rectDef .FillEnabled {_cgdce ,_degc ,_dcfa :=rectDef .FillColor .R (),rectDef .FillColor .G (),rectDef .FillColor .B ();
|
|
|
|
_add .IC =_bc .MakeArrayFromFloats ([]float64 {_cgdce ,_degc ,_dcfa });}else {_add .IC =_bc .MakeArrayFromIntegers ([]int {});};if rectDef .Opacity < 1.0{_add .CA =_bc .MakeFloat (rectDef .Opacity );};_gfdc ,_agbb ,_fffb :=_gggc (rectDef );if _fffb !=nil {return nil ,_fffb ;
|
|
|
|
};_add .AP =_gfdc ;_add .Rect =_bc .MakeArrayFromFloats ([]float64 {_agbb .Llx ,_agbb .Lly ,_agbb .Urx ,_agbb .Ury });return _add .PdfAnnotation ,nil ;};
|
|
|
|
|
|
|
|
// 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 *_de .PdfPage ,name string ,rect []float64 ,opt TextFieldOptions )(*_de .PdfFieldText ,error ){if page ==nil {return nil ,_ea .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};if len (name )<=0{return nil ,_ea .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 ,_ea .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");};_dbg :=_de .NewPdfField ();_ccf :=&_de .PdfFieldText {};_dbg .SetContext (_ccf );_ccf .PdfField =_dbg ;_ccf .T =_bc .MakeString (name );
|
|
|
|
if opt .MaxLen > 0{_ccf .MaxLen =_bc .MakeInteger (int64 (opt .MaxLen ));};if len (opt .Value )> 0{_ccf .V =_bc .MakeString (opt .Value );};_edfc :=_de .NewPdfAnnotationWidget ();_edfc .Rect =_bc .MakeArrayFromFloats (rect );_edfc .P =page .ToPdfObject ();
|
|
|
|
_edfc .F =_bc .MakeInteger (4);_edfc .Parent =_ccf .ToPdfObject ();_ccf .Annotations =append (_ccf .Annotations ,_edfc );return _ccf ,nil ;};
|
2021-04-23 20:28:14 +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-05-31 17:17:31 +00:00
|
|
|
type SignatureImagePosition int ;
|
2021-04-17 13:46:54 +00:00
|
|
|
|
2021-05-31 17:17:31 +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).
|
|
|
|
type RectangleAnnotationDef struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_de .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_de .PdfColorDeviceRGB ;Opacity float64 ;};func _bd (_feb *_de .PdfAnnotationWidget ,_cgg *_de .PdfFieldText ,_aac *_de .PdfPageResources ,_ace AppearanceStyle )(*_bc .PdfObjectDictionary ,error ){_ebc :=_de .NewPdfPageResources ();
|
|
|
|
_fgb ,_deg :=_bc .GetArray (_feb .Rect );if !_deg {return nil ,_ea .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_cge ,_gef :=_de .NewPdfRectangle (*_fgb );if _gef !=nil {return nil ,_gef ;};_ccc ,_egd :=_cge .Width (),_cge .Height ();
|
|
|
|
_ee ,_gd :=_ccc ,_egd ;_gbc ,_ba :=_bc .GetDict (_feb .MK );if _ba {_gefe ,_ :=_bc .GetDict (_feb .BS );_af :=_ace .applyAppearanceCharacteristics (_gbc ,_gefe ,nil );if _af !=nil {return nil ,_af ;};};_ag ,_gef :=_c .NewContentStreamParser (_daf (_cgg .PdfField )).Parse ();
|
|
|
|
if _gef !=nil {return nil ,_gef ;};_deb :=_c .NewContentCreator ();if _ace .BorderSize > 0{_cfeg (_deb ,_ace ,_ccc ,_egd );};if _ace .DrawAlignmentReticle {_df :=_ace ;_df .BorderSize =0.2;_gcd (_deb ,_df ,_ccc ,_egd );};_deb .Add_BMC ("\u0054\u0078");
|
|
|
|
_deb .Add_q ();_ccc ,_egd =_ace .applyRotation (_gbc ,_ccc ,_egd ,_deb );_deb .Add_BT ();_ff ,_fba ,_gef :=_ace .processDA (_cgg .PdfField ,_ag ,_aac ,_ebc ,_deb );if _gef !=nil {return nil ,_gef ;};_dee :=_ff .Font ;_cef :=_ff .Size ;_gg :=_bc .MakeName (_ff .Name );
|
|
|
|
_gefeg :=_cef ==0;if _gefeg &&_fba {_cef =_egd *_ace .AutoFontSizeFraction ;};_gga :=_dee .Encoder ();if _gga ==nil {_bb .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");
|
|
|
|
_gga =_a .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};_ebd ,_gef :=_dee .GetFontDescriptor ();if _gef !=nil {_bb .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 _gee string ;if _faa ,_cba :=_bc .GetString (_cgg .V );_cba {_gee =_faa .Decoded ();};if len (_gee )==0{return nil ,nil ;};_ga :=[]string {_gee };_afb :=false ;if _cgg .Flags ().Has (_de .FieldFlagMultiline ){_afb =true ;_gee =_e .Replace (_gee ,"\u000d\u000a","\u000a",-1);
|
|
|
|
_gee =_e .Replace (_gee ,"\u000d","\u000a",-1);_ga =_e .Split (_gee ,"\u000a");};_fdb :=0.0;_cgga :=0;if _gga !=nil {_agc :=len (_ga );_cee :=0;for _cee < _agc {var _ffd float64 ;_afbf :=-1;_bcdd :=0.0;for _cdc ,_gfd :=range _ga [_cee ]{if _gfd ==' '{_afbf =_cdc ;
|
|
|
|
_ffd =_bcdd ;};_gfa ,_cbg :=_dee .GetRuneMetrics (_gfd );if !_cbg {_bb .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",_gfd );
|
|
|
|
continue ;};_bcdd +=_gfa .Wx ;if _afb &&!_gefeg &&_cef *_bcdd /1000.0> _ccc &&_afbf > 0{_ceed :=_ga [_cee ][_afbf +1:];if _cee < len (_ga )-1{_ga =append (_ga [:_cee +1],_ga [_cee :]...);_ga [_cee +1]=_ceed ;}else {_ga =append (_ga ,_ceed );};_agc ++;_ga [_cee ]=_ga [_cee ][0:_afbf ];
|
|
|
|
_bcdd =_ffd ;break ;};};if _bcdd > _fdb {_fdb =_bcdd ;};_ga [_cee ]=string (_gga .Encode (_ga [_cee ]));if len (_ga [_cee ])> 0{_cgga ++;};_cee ++;};};_eaa :=2.0;if _cef ==0||_gefeg &&_fdb > 0&&_eaa +_fdb *_cef /1000.0> _ccc {_cef =0.95*1000.0*(_ccc -_eaa )/_fdb ;
|
|
|
|
};_dfe :=_dgf ;{if _adg ,_aeg :=_bc .GetIntVal (_cgg .Q );_aeg {switch _adg {case 0:_dfe =_dgf ;case 1:_dfe =_fgf ;case 2:_dfe =_fc ;default:_bb .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",_adg );
|
|
|
|
};};};_acd :=_ace .MultilineLineHeight ;_dge :=_cef ;if _afb &&_cgga > 1{_dge =_acd *_cef ;};var _gdg float64 ;if _ebd !=nil {_gdg ,_gef =_ebd .GetCapHeight ();if _gef !=nil {_bb .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",_gef );
|
|
|
|
};};if int (_gdg )<=0{_bb .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");
|
|
|
|
_gdg =1000;};_dcc :=_gdg /1000.0*_cef ;_adc :=0.0;{_bge :=float64 (_cgga )*_dge ;if _gefeg &&_adc +_bge > _egd {_cef =0.95*(_egd -_adc )/float64 (_cgga );_dge =_cef ;if _afb &&_cgga > 1{_dge =_acd *_cef ;};_dcc =_gdg /1000.0*_cef ;_bge =float64 (_cgga )*_dge ;
|
|
|
|
};if _egd > _bge {if _afb {if _ace .MultilineVAlignMiddle {_cea :=(_egd -_bge )/2.0;_ggc :=_cea +_bge -_dge ;_adc =_ggc ;}else {_adc =_egd -_dge ;_adc -=_cef *0.5;};}else {_adc =(_egd -_dcc )/2.0;};};};_deb .Add_Tf (*_gg ,_cef );_deb .Add_Td (_eaa ,_adc );
|
|
|
|
_cda :=_eaa ;_fda :=_eaa ;for _ef ,_gea :=range _ga {_fec :=0.0;for _ ,_aag :=range _gea {_gdb ,_ec :=_dee .GetRuneMetrics (_aag );if !_ec {continue ;};_fec +=_gdb .Wx ;};_ccce :=_fec /1000.0*_cef ;_aef :=_ccc -_ccce ;var _ccdd float64 ;switch _dfe {case _dgf :_ccdd =_cda ;
|
|
|
|
case _fgf :_ccdd =_aef /2;case _fc :_ccdd =_aef ;};_eaa =_ccdd -_fda ;if _eaa > 0.0{_deb .Add_Td (_eaa ,0);};_fda =_ccdd ;_deb .Add_Tj (*_bc .MakeString (_gea ));if _ef < len (_ga )-1{_deb .Add_Td (0,-_dge *_acd );};};_deb .Add_ET ();_deb .Add_Q ();_deb .Add_EMC ();
|
|
|
|
_adcd :=_de .NewXObjectForm ();_adcd .Resources =_ebc ;_adcd .BBox =_bc .MakeArrayFromFloats ([]float64 {0,0,_ee ,_gd });_adcd .SetContentStream (_deb .Bytes (),_dac ());_bgc :=_bc .MakeDict ();_bgc .Set ("\u004e",_adcd .ToPdfObject ());return _bgc ,nil ;
|
2021-05-11 00:01:27 +00:00
|
|
|
};
|
2021-04-17 13:46:54 +00:00
|
|
|
|
2021-05-11 00:01:27 +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-05-31 17:17:31 +00:00
|
|
|
ForceReplace bool ;};type quadding int ;func _gge (_cce *_de .PdfAcroForm ,_gff *_de .PdfAnnotationWidget ,_dbf *_de .PdfFieldChoice ,_cdca AppearanceStyle )(*_bc .PdfObjectDictionary ,error ){_gbbg ,_eadf :=_bc .GetArray (_gff .Rect );if !_eadf {return nil ,_ea .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");
|
|
|
|
};_aaca ,_ggcf :=_de .NewPdfRectangle (*_gbbg );if _ggcf !=nil {return nil ,_ggcf ;};_fab ,_ade :=_aaca .Width (),_aaca .Height ();_bb .Log .Debug ("\u0043\u0068\u006f\u0069\u0063\u0065\u002c\u0020\u0077\u0061\u0020\u0042S\u003a\u0020\u0025\u0076",_gff .BS );
|
|
|
|
_cbf ,_ggcf :=_c .NewContentStreamParser (_daf (_dbf .PdfField )).Parse ();if _ggcf !=nil {return nil ,_ggcf ;};_dda ,_ffa :=_bc .GetDict (_gff .MK );if _ffa {_bfcc ,_ :=_bc .GetDict (_gff .BS );_gegg :=_cdca .applyAppearanceCharacteristics (_dda ,_bfcc ,nil );
|
|
|
|
if _gegg !=nil {return nil ,_gegg ;};};_ebda :=_bc .MakeDict ();for _ ,_abd :=range _dbf .Opt .Elements (){if _gbgd ,_ggf :=_bc .GetArray (_abd );_ggf &&_gbgd .Len ()==2{_abd =_gbgd .Get (1);};var _fgbf string ;if _egg ,_bgg :=_bc .GetString (_abd );_bgg {_fgbf =_egg .Decoded ();
|
|
|
|
}else if _fdd ,_edc :=_bc .GetName (_abd );_edc {_fgbf =_fdd .String ();}else {_bb .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",_abd );
|
|
|
|
return nil ,_ea .New ("\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u002f\u0073t\u0072\u0069\u006e\u0067");};if len (_fgbf )> 0{_gabf ,_bfg :=_dgeb (_dbf .PdfField ,_fab ,_ade ,_fgbf ,_cdca ,_cbf ,_cce .DR ,_dda );if _bfg !=nil {return nil ,_bfg ;
|
|
|
|
};_ebda .Set (*_bc .MakeName (_fgbf ),_gabf .ToPdfObject ());};};_bged :=_bc .MakeDict ();_bged .Set ("\u004e",_ebda );return _bged ,nil ;};func _aa (_dg CircleAnnotationDef ,_fef string )([]byte ,*_de .PdfRectangle ,*_de .PdfRectangle ,error ){_aed :=_gb .Circle {X :_dg .X ,Y :_dg .Y ,Width :_dg .Width ,Height :_dg .Height ,FillEnabled :_dg .FillEnabled ,FillColor :_dg .FillColor ,BorderEnabled :_dg .BorderEnabled ,BorderWidth :_dg .BorderWidth ,BorderColor :_dg .BorderColor ,Opacity :_dg .Opacity };
|
|
|
|
_dgc ,_bcd ,_ddf :=_aed .Draw (_fef );if _ddf !=nil {return nil ,nil ,nil ,_ddf ;};_ccd :=&_de .PdfRectangle {};_ccd .Llx =_dg .X +_bcd .Llx ;_ccd .Lly =_dg .Y +_bcd .Lly ;_ccd .Urx =_dg .X +_bcd .Urx ;_ccd .Ury =_dg .Y +_bcd .Ury ;return _dgc ,_bcd ,_ccd ,nil ;
|
|
|
|
};func (_bffb *AppearanceStyle )applyAppearanceCharacteristics (_cdcb *_bc .PdfObjectDictionary ,_gac *_bc .PdfObjectDictionary ,_ddc *_de .PdfFont )error {if !_bffb .AllowMK {return nil ;};if CA ,_bdg :=_bc .GetString (_cdcb .Get ("\u0043\u0041"));_bdg &&_ddc !=nil {_cgc :=CA .Bytes ();
|
|
|
|
if len (_cgc )!=0{_gbde :=[]rune (_ddc .Encoder ().Decode (_cgc ));if len (_gbde )==1{_bffb .CheckmarkRune =_gbde [0];};};};if BC ,_dccb :=_bc .GetArray (_cdcb .Get ("\u0042\u0043"));_dccb {_gefc ,_fag :=BC .ToFloat64Array ();if _fag !=nil {return _fag ;
|
|
|
|
};switch len (_gefc ){case 1:_bffb .BorderColor =_de .NewPdfColorDeviceGray (_gefc [0]);case 3:_bffb .BorderColor =_de .NewPdfColorDeviceRGB (_gefc [0],_gefc [1],_gefc [2]);case 4:_bffb .BorderColor =_de .NewPdfColorDeviceCMYK (_gefc [0],_gefc [1],_gefc [2],_gefc [3]);
|
|
|
|
default:_bb .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 (_gefc ));
|
|
|
|
};if _gac !=nil {if _ebg ,_fgg :=_bc .GetNumberAsFloat (_gac .Get ("\u0057"));_fgg ==nil {_bffb .BorderSize =_ebg ;};};};if BG ,_ccdb :=_bc .GetArray (_cdcb .Get ("\u0042\u0047"));_ccdb {_fbdd ,_cag :=BG .ToFloat64Array ();if _cag !=nil {return _cag ;};
|
|
|
|
switch len (_fbdd ){case 1:_bffb .FillColor =_de .NewPdfColorDeviceGray (_fbdd [0]);case 3:_bffb .FillColor =_de .NewPdfColorDeviceRGB (_fbdd [0],_fbdd [1],_fbdd [2]);case 4:_bffb .FillColor =_de .NewPdfColorDeviceCMYK (_fbdd [0],_fbdd [1],_fbdd [2],_fbdd [3]);
|
|
|
|
default:_bb .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 (_fbdd ));
|
|
|
|
};};return nil ;};
|
|
|
|
|
|
|
|
// SignatureLine represents a line of information in the signature field appearance.
|
|
|
|
type SignatureLine struct{Desc string ;Text string ;};
|
|
|
|
|
|
|
|
// CreateLineAnnotation creates a line annotation object that can be added to page PDF annotations.
|
|
|
|
func CreateLineAnnotation (lineDef LineAnnotationDef )(*_de .PdfAnnotation ,error ){_acfb :=_de .NewPdfAnnotationLine ();_acfb .L =_bc .MakeArrayFromFloats ([]float64 {lineDef .X1 ,lineDef .Y1 ,lineDef .X2 ,lineDef .Y2 });_geggf :=_bc .MakeName ("\u004e\u006f\u006e\u0065");
|
|
|
|
if lineDef .LineEndingStyle1 ==_gb .LineEndingStyleArrow {_geggf =_bc .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");};_ccced :=_bc .MakeName ("\u004e\u006f\u006e\u0065");if lineDef .LineEndingStyle2 ==_gb .LineEndingStyleArrow {_ccced =_bc .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");
|
|
|
|
};_acfb .LE =_bc .MakeArray (_geggf ,_ccced );if lineDef .Opacity < 1.0{_acfb .CA =_bc .MakeFloat (lineDef .Opacity );};_dafa ,_fcda ,_dbaa :=lineDef .LineColor .R (),lineDef .LineColor .G (),lineDef .LineColor .B ();_acfb .IC =_bc .MakeArrayFromFloats ([]float64 {_dafa ,_fcda ,_dbaa });
|
|
|
|
_acfb .C =_bc .MakeArrayFromFloats ([]float64 {_dafa ,_fcda ,_dbaa });_dfga :=_de .NewBorderStyle ();_dfga .SetBorderWidth (lineDef .LineWidth );_acfb .BS =_dfga .ToPdfObject ();_ecb ,_aaf ,_eba :=_cgcd (lineDef );if _eba !=nil {return nil ,_eba ;};_acfb .AP =_ecb ;
|
|
|
|
_acfb .Rect =_bc .MakeArrayFromFloats ([]float64 {_aaf .Llx ,_aaf .Lly ,_aaf .Urx ,_aaf .Ury });return _acfb .PdfAnnotation ,nil ;};
|
2021-04-17 13:46:54 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// AppearanceStyle defines style parameters for appearance stream generation.
|
|
|
|
type AppearanceStyle struct{
|
2021-04-17 13:46:54 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// How much of Rect height to fill when autosizing text.
|
|
|
|
AutoFontSizeFraction float64 ;
|
2021-04-17 13:46:54 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// CheckmarkRune is a rune used for check mark in checkboxes (for ZapfDingbats font).
|
2021-05-31 17:17:31 +00:00
|
|
|
CheckmarkRune rune ;BorderSize float64 ;BorderColor _de .PdfColor ;FillColor _de .PdfColor ;
|
2021-04-17 13:46:54 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// Multiplier for lineheight for multi line text.
|
|
|
|
MultilineLineHeight float64 ;MultilineVAlignMiddle bool ;
|
2021-04-17 13:46:54 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// Visual guide checking alignment of field contents (debugging).
|
|
|
|
DrawAlignmentReticle bool ;
|
2021-02-11 10:35:13 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// Allow field MK appearance characteristics to override style settings.
|
|
|
|
AllowMK bool ;
|
2021-04-17 13:46:54 +00:00
|
|
|
|
2021-04-23 20:28:14 +00:00
|
|
|
// Fonts holds appearance styles for fonts.
|
2021-05-31 17:17:31 +00:00
|
|
|
Fonts *AppearanceFontStyle ;};func _dac ()_bc .StreamEncoder {return _bc .NewFlateEncoder ()};func _dfgd (_aee _d .Image ,_dcde string ,_cadc *SignatureFieldOpts ,_dad []float64 ,_ddeg *_c .ContentCreator )(*_bc .PdfObjectName ,*_de .XObjectImage ,error ){_fce ,_eae :=_de .DefaultImageHandler {}.NewImageFromGoImage (_aee );
|
|
|
|
if _eae !=nil {return nil ,nil ,_eae ;};_cgeeb ,_eae :=_de .NewXObjectImageFromImage (_fce ,nil ,_cadc .Encoder );if _eae !=nil {return nil ,nil ,_eae ;};_gce ,_cgac :=float64 (*_cgeeb .Width ),float64 (*_cgeeb .Height );_dcbb :=_dad [2]-_dad [0];_bae :=_dad [3]-_dad [1];
|
|
|
|
if _cadc .AutoSize {_dcfg :=_g .Min (_dcbb /_gce ,_bae /_cgac );_gce *=_dcfg ;_cgac *=_dcfg ;_dad [0]=_dad [0]+(_dcbb /2)-(_gce /2);_dad [1]=_dad [1]+(_bae /2)-(_cgac /2);};var _acfc *_bc .PdfObjectName ;if _abgc ,_aeed :=_bc .GetName (_cgeeb .Name );_aeed {_acfc =_abgc ;
|
|
|
|
}else {_acfc =_bc .MakeName (_dcde );};if _ddeg !=nil {_ddeg .Add_q ().Translate (_dad [0],_dad [1]).Scale (_gce ,_cgac ).Add_Do (*_acfc ).Add_Q ();}else {return nil ,nil ,_ea .New ("\u0043\u006f\u006e\u0074en\u0074\u0043\u0072\u0065\u0061\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u0075l\u006c");
|
|
|
|
};return _acfc ,_cgeeb ,nil ;};
|
2021-05-11 00:01:27 +00:00
|
|
|
|
2021-05-31 17:17:31 +00:00
|
|
|
// CheckboxFieldOptions defines optional parameters for a checkbox field a form.
|
|
|
|
type CheckboxFieldOptions struct{Checked bool ;};
|
2021-05-11 00:01:27 +00:00
|
|
|
|
2021-05-31 17:17:31 +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 *_de .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 _gb .LineEndingStyle ;LineEndingStyle2 _gb .LineEndingStyle ;};func _cfeg (_gcfa *_c .ContentCreator ,_fbdg AppearanceStyle ,_cdg ,_eacg float64 ){_gcfa .Add_q ().Add_re (0,0,_cdg ,_eacg ).Add_w (_fbdg .BorderSize ).SetStrokingColor (_fbdg .BorderColor ).SetNonStrokingColor (_fbdg .FillColor ).Add_B ().Add_Q ();
|
|
|
|
};
|
2021-03-13 21:28:23 +00:00
|
|
|
|
2021-05-31 17:17:31 +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 *_de .PdfSignature ,lines []*SignatureLine ,opts *SignatureFieldOpts )(*_de .PdfFieldSignature ,error ){if signature ==nil {return nil ,_ea .New ("\u0073\u0069\u0067na\u0074\u0075\u0072\u0065\u0020\u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u006e\u0069\u006c");
|
|
|
|
};_ged ,_ddcg :=_ccgd (lines ,opts );if _ddcg !=nil {return nil ,_ddcg ;};_gfbeg :=_de .NewPdfFieldSignature (signature );_gfbeg .Rect =_bc .MakeArrayFromFloats (opts .Rect );_gfbeg .AP =_ged ;return _gfbeg ,nil ;};func _bef (_cb CircleAnnotationDef )(*_bc .PdfObjectDictionary ,*_de .PdfRectangle ,error ){_gbg :=_de .NewXObjectForm ();
|
|
|
|
_gbg .Resources =_de .NewPdfPageResources ();_fb :="";if _cb .Opacity < 1.0{_fg :=_bc .MakeDict ();_fg .Set ("\u0063\u0061",_bc .MakeFloat (_cb .Opacity ));_fg .Set ("\u0043\u0041",_bc .MakeFloat (_cb .Opacity ));_cc :=_gbg .Resources .AddExtGState ("\u0067\u0073\u0031",_fg );
|
|
|
|
if _cc !=nil {_bb .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 ,_cc ;};_fb ="\u0067\u0073\u0031";};_edf ,_dde ,_aca ,_eb :=_aa (_cb ,_fb );
|
|
|
|
if _eb !=nil {return nil ,nil ,_eb ;};_eb =_gbg .SetContentStream (_edf ,nil );if _eb !=nil {return nil ,nil ,_eb ;};_gbg .BBox =_dde .ToPdfObject ();_fe :=_bc .MakeDict ();_fe .Set ("\u004e",_gbg .ToPdfObject ());return _fe ,_aca ,nil ;};
|