mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +08:00
466 lines
74 KiB
Go
466 lines
74 KiB
Go
//
|
|
// Copyright 2020 FoxyUtils ehf. All rights reserved.
|
|
//
|
|
// This is a commercial product and requires a license to operate.
|
|
// A trial license can be obtained at https://unidoc.io
|
|
//
|
|
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
|
|
//
|
|
// Use of this source code is governed by the UniDoc End User License Agreement
|
|
// terms that can be accessed at https://unidoc.io/eula/
|
|
|
|
// Package annotator provides an interface for creating annotations with appearance
|
|
// streams. It goes beyond the models package which includes definitions of basic annotation models, in that it
|
|
// can create the appearance streams which specify the exact appearance as needed by many pdf viewers for consistent
|
|
// appearance of the annotations.
|
|
// It also contains methods for generating appearance streams for fields via widget annotations.
|
|
package annotator ;import (_g "bytes";_bda "errors";_bd "github.com/unidoc/unipdf/v3/common";_d "github.com/unidoc/unipdf/v3/contentstream";_ed "github.com/unidoc/unipdf/v3/contentstream/draw";_ba "github.com/unidoc/unipdf/v3/core";_f "github.com/unidoc/unipdf/v3/internal/textencoding";
|
|
_cgd "github.com/unidoc/unipdf/v3/model";_a "image";_e "math";_cg "strings";_c "unicode";);func (_dda *AppearanceStyle )applyAppearanceCharacteristics (_cdg *_ba .PdfObjectDictionary ,_geaag *_ba .PdfObjectDictionary ,_bdea *_cgd .PdfFont )error {if !_dda .AllowMK {return nil ;
|
|
};if CA ,_gdd :=_ba .GetString (_cdg .Get ("\u0043\u0041"));_gdd &&_bdea !=nil {_fddc :=CA .Bytes ();if len (_fddc )!=0{_fcd :=[]rune (_bdea .Encoder ().Decode (_fddc ));if len (_fcd )==1{_dda .CheckmarkRune =_fcd [0];};};};if BC ,_bdd :=_ba .GetArray (_cdg .Get ("\u0042\u0043"));
|
|
_bdd {_gga ,_dede :=BC .ToFloat64Array ();if _dede !=nil {return _dede ;};switch len (_gga ){case 1:_dda .BorderColor =_cgd .NewPdfColorDeviceGray (_gga [0]);case 3:_dda .BorderColor =_cgd .NewPdfColorDeviceRGB (_gga [0],_gga [1],_gga [2]);case 4:_dda .BorderColor =_cgd .NewPdfColorDeviceCMYK (_gga [0],_gga [1],_gga [2],_gga [3]);
|
|
default:_bd .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 (_gga ));
|
|
};if _geaag !=nil {if _fce ,_fgad :=_ba .GetNumberAsFloat (_geaag .Get ("\u0057"));_fgad ==nil {_dda .BorderSize =_fce ;};};};if BG ,_cab :=_ba .GetArray (_cdg .Get ("\u0042\u0047"));_cab {_dae ,_dabff :=BG .ToFloat64Array ();if _dabff !=nil {return _dabff ;
|
|
};switch len (_dae ){case 1:_dda .FillColor =_cgd .NewPdfColorDeviceGray (_dae [0]);case 3:_dda .FillColor =_cgd .NewPdfColorDeviceRGB (_dae [0],_dae [1],_dae [2]);case 4:_dda .FillColor =_cgd .NewPdfColorDeviceCMYK (_dae [0],_dae [1],_dae [2],_dae [3]);
|
|
default:_bd .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 (_dae ));
|
|
};};return nil ;};
|
|
|
|
// 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 *_cgd .PdfSignature ,lines []*SignatureLine ,opts *SignatureFieldOpts )(*_cgd .PdfFieldSignature ,error ){if signature ==nil {return nil ,_bda .New ("\u0073\u0069\u0067na\u0074\u0075\u0072\u0065\u0020\u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u006e\u0069\u006c");
|
|
};_fcdgg ,_dgc :=_gbe (lines ,opts );if _dgc !=nil {return nil ,_dgc ;};_dbde :=_cgd .NewPdfFieldSignature (signature );_dbde .Rect =_ba .MakeArrayFromFloats (opts .Rect );_dbde .AP =_fcdgg ;return _dbde ,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 };};
|
|
|
|
// 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 *_cgd .PdfPage ,name string ,rect []float64 ,opt CheckboxFieldOptions )(*_cgd .PdfFieldButton ,error ){if page ==nil {return nil ,_bda .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
|
|
};if len (name )<=0{return nil ,_bda .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 ,_bda .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
|
|
};_ccda ,_bcce :=_cgd .NewStandard14Font (_cgd .ZapfDingbatsName );if _bcce !=nil {return nil ,_bcce ;};_daf :=_cgd .NewPdfField ();_gcbf :=&_cgd .PdfFieldButton {};_daf .SetContext (_gcbf );_gcbf .PdfField =_daf ;_gcbf .T =_ba .MakeString (name );_gcbf .SetType (_cgd .ButtonTypeCheckbox );
|
|
_aac :="\u004f\u0066\u0066";if opt .Checked {_aac ="\u0059\u0065\u0073";};_gcbf .V =_ba .MakeName (_aac );_ccag :=_cgd .NewPdfAnnotationWidget ();_ccag .Rect =_ba .MakeArrayFromFloats (rect );_ccag .P =page .ToPdfObject ();_ccag .F =_ba .MakeInteger (4);
|
|
_ccag .Parent =_gcbf .ToPdfObject ();_aegc :=rect [2]-rect [0];_bcbc :=rect [3]-rect [1];var _dbega _g .Buffer ;_dbega .WriteString ("\u0071\u000a");_dbega .WriteString ("\u0030 \u0030\u0020\u0031\u0020\u0072\u0067\n");_dbega .WriteString ("\u0042\u0054\u000a");
|
|
_dbega .WriteString ("\u002f\u005a\u0061D\u0062\u0020\u0031\u0032\u0020\u0054\u0066\u000a");_dbega .WriteString ("\u0045\u0054\u000a");_dbega .WriteString ("\u0051\u000a");_dgbd :=_d .NewContentCreator ();_dgbd .Add_q ();_dgbd .Add_rg (0,0,1);_dgbd .Add_BT ();
|
|
_dgbd .Add_Tf (*_ba .MakeName ("\u005a\u0061\u0044\u0062"),12);_dgbd .Add_Td (0,0);_dgbd .Add_ET ();_dgbd .Add_Q ();_dbd :=_cgd .NewXObjectForm ();_dbd .SetContentStream (_dgbd .Bytes (),_ba .NewRawEncoder ());_dbd .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_aegc ,_bcbc });
|
|
_dbd .Resources =_cgd .NewPdfPageResources ();_dbd .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_ccda .ToPdfObject ());_dgbd =_d .NewContentCreator ();_dgbd .Add_q ();_dgbd .Add_re (0,0,_aegc ,_bcbc );_dgbd .Add_W ().Add_n ();_dgbd .Add_rg (0,0,1);
|
|
_dgbd .Translate (0,3.0);_dgbd .Add_BT ();_dgbd .Add_Tf (*_ba .MakeName ("\u005a\u0061\u0044\u0062"),12);_dgbd .Add_Td (0,0);_dgbd .Add_Tj (*_ba .MakeString ("\u0034"));_dgbd .Add_ET ();_dgbd .Add_Q ();_gdf :=_cgd .NewXObjectForm ();_gdf .SetContentStream (_dgbd .Bytes (),_ba .NewRawEncoder ());
|
|
_gdf .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_aegc ,_bcbc });_gdf .Resources =_cgd .NewPdfPageResources ();_gdf .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_ccda .ToPdfObject ());_cadd :=_ba .MakeDict ();_cadd .Set ("\u004f\u0066\u0066",_dbd .ToPdfObject ());
|
|
_cadd .Set ("\u0059\u0065\u0073",_gdf .ToPdfObject ());_aecd :=_ba .MakeDict ();_aecd .Set ("\u004e",_cadd );_ccag .AP =_aecd ;_ccag .AS =_ba .MakeName (_aac );_gcbf .Annotations =append (_gcbf .Annotations ,_ccag );return _gcbf ,nil ;};
|
|
|
|
// WrapContentStream ensures that the entire content stream for a `page` is wrapped within q ... Q operands.
|
|
// Ensures that following operands that are added are not affected by additional operands that are added.
|
|
// Implements interface model.ContentStreamWrapper.
|
|
func (_bcdgf ImageFieldAppearance )WrapContentStream (page *_cgd .PdfPage )error {_aed ,_cffe :=page .GetAllContentStreams ();if _cffe !=nil {return _cffe ;};_baage :=_d .NewContentStreamParser (_aed );_gged ,_cffe :=_baage .Parse ();if _cffe !=nil {return _cffe ;
|
|
};_gged .WrapIfNeeded ();_fbeb :=[]string {_gged .String ()};return page .SetContentStreams (_fbeb ,_feaa ());};func _gbf (_fecd []_ed .Point )(_gfef []_ed .Point ,_efge []_ed .Point ,_ada error ){_egggg :=len (_fecd )-1;if len (_fecd )< 1{return nil ,nil ,_bda .New ("\u0041\u0074\u0020\u006c\u0065\u0061\u0073\u0074\u0020\u0074\u0077\u006f\u0020\u0070\u006f\u0069\u006e\u0074s \u0072e\u0071\u0075\u0069\u0072\u0065\u0064\u0020\u0074\u006f\u0020\u0063\u0061l\u0063\u0075\u006c\u0061\u0074\u0065\u0020\u0063\u0075\u0072\u0076\u0065\u0020\u0063\u006f\u006e\u0074r\u006f\u006c\u0020\u0070\u006f\u0069\u006e\u0074\u0073");
|
|
};if _egggg ==1{_dadb :=_ed .Point {X :(2*_fecd [0].X +_fecd [1].X )/3,Y :(2*_fecd [0].Y +_fecd [1].Y )/3};_gfef =append (_gfef ,_dadb );_efge =append (_efge ,_ed .Point {X :2*_dadb .X -_fecd [0].X ,Y :2*_dadb .Y -_fecd [0].Y });return _gfef ,_efge ,nil ;
|
|
};_eba :=make ([]float64 ,_egggg );for _debg :=1;_debg < _egggg -1;_debg ++{_eba [_debg ]=4*_fecd [_debg ].X +2*_fecd [_debg +1].X ;};_eba [0]=_fecd [0].X +2*_fecd [1].X ;_eba [_egggg -1]=(8*_fecd [_egggg -1].X +_fecd [_egggg ].X )/2.0;_eefg :=_eebcg (_eba );
|
|
for _egb :=1;_egb < _egggg -1;_egb ++{_eba [_egb ]=4*_fecd [_egb ].Y +2*_fecd [_egb +1].Y ;};_eba [0]=_fecd [0].Y +2*_fecd [1].Y ;_eba [_egggg -1]=(8*_fecd [_egggg -1].Y +_fecd [_egggg ].Y )/2.0;_fcc :=_eebcg (_eba );_gfef =make ([]_ed .Point ,_egggg );
|
|
_efge =make ([]_ed .Point ,_egggg );for _ddec :=0;_ddec < _egggg ;_ddec ++{_gfef [_ddec ]=_ed .Point {X :_eefg [_ddec ],Y :_fcc [_ddec ]};if _ddec < _egggg -1{_efge [_ddec ]=_ed .Point {X :2*_fecd [_ddec +1].X -_eefg [_ddec +1],Y :2*_fecd [_ddec +1].Y -_fcc [_ddec +1]};
|
|
}else {_efge [_ddec ]=_ed .Point {X :(_fecd [_egggg ].X +_eefg [_egggg -1])/2,Y :(_fecd [_egggg ].Y +_fcc [_egggg -1])/2};};};return _gfef ,_efge ,nil ;};func _aagc (_ccfa *_cgd .PdfField ,_dbef ,_bfaa float64 ,_fdfd string ,_fgc AppearanceStyle ,_fddg *_d .ContentStreamOperations ,_dfcg *_cgd .PdfPageResources ,_ccca *_ba .PdfObjectDictionary )(*_cgd .XObjectForm ,error ){_cgfb :=_cgd .NewPdfPageResources ();
|
|
_efe ,_bedd :=_dbef ,_bfaa ;_eedd :=_d .NewContentCreator ();if _fgc .BorderSize > 0{_afg (_eedd ,_fgc ,_dbef ,_bfaa );};if _fgc .DrawAlignmentReticle {_cce :=_fgc ;_cce .BorderSize =0.2;_dcgg (_eedd ,_cce ,_dbef ,_bfaa );};_eedd .Add_BMC ("\u0054\u0078");
|
|
_eedd .Add_q ();_eedd .Add_BT ();_dbef ,_bfaa =_fgc .applyRotation (_ccca ,_dbef ,_bfaa ,_eedd );_fgba ,_cgebg ,_cag :=_fgc .processDA (_ccfa ,_fddg ,_dfcg ,_cgfb ,_eedd );if _cag !=nil {return nil ,_cag ;};_bbda :=_fgba .Font ;_dabf :=_fgba .Size ;_gcfg :=_ba .MakeName (_fgba .Name );
|
|
_bcdg :=_dabf ==0;if _bcdg &&_cgebg {_dabf =_bfaa *_fgc .AutoFontSizeFraction ;};_eaaf :=_bbda .Encoder ();if _eaaf ==nil {_bd .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");
|
|
_eaaf =_f .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};if len (_fdfd )==0{return nil ,nil ;};_fcfa :=_baa ;if _fgc .MarginLeft !=nil {_fcfa =*_fgc .MarginLeft ;};_ggca :=0.0;if _eaaf !=nil {for _ ,_gfcc :=range _fdfd {_fbc ,_eggc :=_bbda .GetRuneMetrics (_gfcc );
|
|
if !_eggc {_bd .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",_gfcc );
|
|
continue ;};_ggca +=_fbc .Wx ;};_fdfd =string (_eaaf .Encode (_fdfd ));};if _dabf ==0||_bcdg &&_ggca > 0&&_fcfa +_ggca *_dabf /1000.0> _dbef {_dabf =0.95*1000.0*(_dbef -_fcfa )/_ggca ;};_afdb :=1.0*_dabf ;_bae :=2.0;{_fge :=_afdb ;if _bcdg &&_bae +_fge > _bfaa {_dabf =0.95*(_bfaa -_bae );
|
|
_afdb =1.0*_dabf ;_fge =_afdb ;};if _bfaa > _fge {_bae =(_bfaa -_fge )/2.0;_bae +=1.50;};};_eedd .Add_Tf (*_gcfg ,_dabf );_eedd .Add_Td (_fcfa ,_bae );_eedd .Add_Tj (*_ba .MakeString (_fdfd ));_eedd .Add_ET ();_eedd .Add_Q ();_eedd .Add_EMC ();_gde :=_cgd .NewXObjectForm ();
|
|
_gde .Resources =_cgfb ;_gde .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_efe ,_bedd });_gde .SetContentStream (_eedd .Bytes (),_feaa ());return _gde ,nil ;};
|
|
|
|
// CheckboxFieldOptions defines optional parameters for a checkbox field a form.
|
|
type CheckboxFieldOptions struct{Checked bool ;};func _ebc (_gb CircleAnnotationDef )(*_ba .PdfObjectDictionary ,*_cgd .PdfRectangle ,error ){_cc :=_cgd .NewXObjectForm ();_cc .Resources =_cgd .NewPdfPageResources ();_cd :="";if _gb .Opacity < 1.0{_bc :=_ba .MakeDict ();
|
|
_bc .Set ("\u0063\u0061",_ba .MakeFloat (_gb .Opacity ));_bc .Set ("\u0043\u0041",_ba .MakeFloat (_gb .Opacity ));_eg :=_cc .Resources .AddExtGState ("\u0067\u0073\u0031",_bc );if _eg !=nil {_bd .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 ,_eg ;};_cd ="\u0067\u0073\u0031";};_ga ,_fa ,_bf ,_fga :=_ee (_gb ,_cd );if _fga !=nil {return nil ,nil ,_fga ;};_fga =_cc .SetContentStream (_ga ,nil );if _fga !=nil {return nil ,nil ,_fga ;};_cc .BBox =_fa .ToPdfObject ();_cb :=_ba .MakeDict ();
|
|
_cb .Set ("\u004e",_cc .ToPdfObject ());return _cb ,_bf ,nil ;};
|
|
|
|
// CreateLineAnnotation creates a line annotation object that can be added to page PDF annotations.
|
|
func CreateLineAnnotation (lineDef LineAnnotationDef )(*_cgd .PdfAnnotation ,error ){_edae :=_cgd .NewPdfAnnotationLine ();_edae .L =_ba .MakeArrayFromFloats ([]float64 {lineDef .X1 ,lineDef .Y1 ,lineDef .X2 ,lineDef .Y2 });_cdda :=_ba .MakeName ("\u004e\u006f\u006e\u0065");
|
|
if lineDef .LineEndingStyle1 ==_ed .LineEndingStyleArrow {_cdda =_ba .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");};_dagb :=_ba .MakeName ("\u004e\u006f\u006e\u0065");if lineDef .LineEndingStyle2 ==_ed .LineEndingStyleArrow {_dagb =_ba .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");
|
|
};_edae .LE =_ba .MakeArray (_cdda ,_dagb );if lineDef .Opacity < 1.0{_edae .CA =_ba .MakeFloat (lineDef .Opacity );};_bcbe ,_faad ,_defe :=lineDef .LineColor .R (),lineDef .LineColor .G (),lineDef .LineColor .B ();_edae .IC =_ba .MakeArrayFromFloats ([]float64 {_bcbe ,_faad ,_defe });
|
|
_edae .C =_ba .MakeArrayFromFloats ([]float64 {_bcbe ,_faad ,_defe });_faab :=_cgd .NewBorderStyle ();_faab .SetBorderWidth (lineDef .LineWidth );_edae .BS =_faab .ToPdfObject ();_fgee ,_cfdf ,_cfdbd :=_gfgc (lineDef );if _cfdbd !=nil {return nil ,_cfdbd ;
|
|
};_edae .AP =_fgee ;_edae .Rect =_ba .MakeArrayFromFloats ([]float64 {_cfdf .Llx ,_cfdf .Lly ,_cfdf .Urx ,_cfdf .Ury });return _edae .PdfAnnotation ,nil ;};
|
|
|
|
// NewImageField generates a new image field with partial name `name` at location `rect`
|
|
// on specified `page` and with field specific options `opt`.
|
|
func NewImageField (page *_cgd .PdfPage ,name string ,rect []float64 ,opt ImageFieldOptions )(*_cgd .PdfFieldButton ,error ){if page ==nil {return nil ,_bda .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
|
|
};if len (name )<=0{return nil ,_bda .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 ,_bda .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
|
|
};_eca :=_cgd .NewPdfField ();_abfc :=&_cgd .PdfFieldButton {};_abfc .PdfField =_eca ;_eca .SetContext (_abfc );_abfc .SetType (_cgd .ButtonTypePush );_abfc .T =_ba .MakeString (name );_edeea :=_cgd .NewPdfAnnotationWidget ();_edeea .Rect =_ba .MakeArrayFromFloats (rect );
|
|
_edeea .P =page .ToPdfObject ();_edeea .F =_ba .MakeInteger (4);_edeea .Parent =_abfc .ToPdfObject ();_dade :=rect [2]-rect [0];_dec :=rect [3]-rect [1];_ggad :=opt ._edee ;_daef :=_d .NewContentCreator ();if _ggad .BorderSize > 0{_afg (_daef ,_ggad ,_dade ,_dec );
|
|
};if _ggad .DrawAlignmentReticle {_ebffc :=_ggad ;_ebffc .BorderSize =0.2;_dcgg (_daef ,_ebffc ,_dade ,_dec );};_fced ,_cafa :=_cafe (_dade ,_dec ,opt .Image ,_ggad );if _cafa !=nil {return nil ,_cafa ;};_fbfg ,_ega :=_ba .GetDict (_edeea .MK );if _ega {_fbfg .Set ("\u006c",_fced .ToPdfObject ());
|
|
};_cee :=_ba .MakeDict ();_cee .Set ("\u0046\u0052\u004d",_fced .ToPdfObject ());_agef :=_cgd .NewPdfPageResources ();_agef .ProcSet =_ba .MakeArray (_ba .MakeName ("\u0050\u0044\u0046"));_agef .XObject =_cee ;_gbdb :=_dade -2;_gcfc :=_dec -2;_daef .Add_q ();
|
|
_daef .Add_re (1,1,_gbdb ,_gcfc );_daef .Add_W ();_daef .Add_n ();_gbdb -=2;_gcfc -=2;_daef .Add_q ();_daef .Add_re (2,2,_gbdb ,_gcfc );_daef .Add_W ();_daef .Add_n ();_agac :=_e .Min (_gbdb /float64 (opt .Image .Width ),_gcfc /float64 (opt .Image .Height ));
|
|
_daef .Add_cm (_agac ,0,0,_agac ,(_dade /2)-(float64 (opt .Image .Width )*_agac /2)+2,2);_daef .Add_Do ("\u0046\u0052\u004d");_daef .Add_Q ();_daef .Add_Q ();_ddef :=_cgd .NewXObjectForm ();_ddef .FormType =_ba .MakeInteger (1);_ddef .Resources =_agef ;
|
|
_ddef .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_dade ,_dec });_ddef .Matrix =_ba .MakeArrayFromFloats ([]float64 {1.0,0.0,0.0,1.0,0.0,0.0});_ddef .SetContentStream (_daef .Bytes (),_feaa ());_decf :=_ba .MakeDict ();_decf .Set ("\u004e",_ddef .ToPdfObject ());
|
|
_edeea .AP =_decf ;_abfc .Annotations =append (_abfc .Annotations ,_edeea );return _abfc ,nil ;};func _egedg (_bgbef RectangleAnnotationDef ,_acea string )([]byte ,*_cgd .PdfRectangle ,*_cgd .PdfRectangle ,error ){_dce :=_ed .Rectangle {X :0,Y :0,Width :_bgbef .Width ,Height :_bgbef .Height ,FillEnabled :_bgbef .FillEnabled ,FillColor :_bgbef .FillColor ,BorderEnabled :_bgbef .BorderEnabled ,BorderWidth :2*_bgbef .BorderWidth ,BorderColor :_bgbef .BorderColor ,Opacity :_bgbef .Opacity };
|
|
_bfb ,_afed ,_dgef :=_dce .Draw (_acea );if _dgef !=nil {return nil ,nil ,nil ,_dgef ;};_dagf :=&_cgd .PdfRectangle {};_dagf .Llx =_bgbef .X +_afed .Llx ;_dagf .Lly =_bgbef .Y +_afed .Lly ;_dagf .Urx =_bgbef .X +_afed .Urx ;_dagf .Ury =_bgbef .Y +_afed .Ury ;
|
|
return _bfb ,_afed ,_dagf ,nil ;};func _ee (_ggc CircleAnnotationDef ,_bbd string )([]byte ,*_cgd .PdfRectangle ,*_cgd .PdfRectangle ,error ){_gc :=_ed .Circle {X :_ggc .X ,Y :_ggc .Y ,Width :_ggc .Width ,Height :_ggc .Height ,FillEnabled :_ggc .FillEnabled ,FillColor :_ggc .FillColor ,BorderEnabled :_ggc .BorderEnabled ,BorderWidth :_ggc .BorderWidth ,BorderColor :_ggc .BorderColor ,Opacity :_ggc .Opacity };
|
|
_ag ,_dg ,_ae :=_gc .Draw (_bbd );if _ae !=nil {return nil ,nil ,nil ,_ae ;};_edc :=&_cgd .PdfRectangle {};_edc .Llx =_ggc .X +_dg .Llx ;_edc .Lly =_ggc .Y +_dg .Lly ;_edc .Urx =_ggc .X +_dg .Urx ;_edc .Ury =_ggc .Y +_dg .Ury ;return _ag ,_dg ,_edc ,nil ;
|
|
};
|
|
|
|
// GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`.
|
|
// Implements interface model.FieldAppearanceGenerator.
|
|
func (_gad FieldAppearance )GenerateAppearanceDict (form *_cgd .PdfAcroForm ,field *_cgd .PdfField ,wa *_cgd .PdfAnnotationWidget )(*_ba .PdfObjectDictionary ,error ){_bd .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 );
|
|
_ ,_aea :=field .GetContext ().(*_cgd .PdfFieldText );_bga ,_fb :=_ba .GetDict (wa .AP );if _fb &&_gad .OnlyIfMissing &&(!_aea ||!_gad .RegenerateTextFields ){_bd .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 _bga ,nil ;};if form .DR ==nil {form .DR =_cgd .NewPdfPageResources ();};switch _cbe :=field .GetContext ().(type ){case *_cgd .PdfFieldText :_ge :=_cbe ;if _ggg :=_ccb (_ge .PdfField );_ggg ==""{_ge .DA =form .DA ;};switch {case _ge .Flags ().Has (_cgd .FieldFlagPassword ):return nil ,nil ;
|
|
case _ge .Flags ().Has (_cgd .FieldFlagFileSelect ):return nil ,nil ;case _ge .Flags ().Has (_cgd .FieldFlagComb ):if _ge .MaxLen !=nil {_cbb ,_eef :=_cea (wa ,_ge ,form .DR ,_gad .Style ());if _eef !=nil {return nil ,_eef ;};return _cbb ,nil ;};};_ad ,_eeg :=_agb (wa ,_ge ,form .DR ,_gad .Style ());
|
|
if _eeg !=nil {return nil ,_eeg ;};return _ad ,nil ;case *_cgd .PdfFieldButton :_fcf :=_cbe ;if _fcf .IsCheckbox (){_gcb ,_bfd :=_ggfb (wa ,_fcf ,form .DR ,_gad .Style ());if _bfd !=nil {return nil ,_bfd ;};return _gcb ,nil ;};_bd .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",_fcf .GetType ());
|
|
case *_cgd .PdfFieldChoice :_gd :=_cbe ;switch {case _gd .Flags ().Has (_cgd .FieldFlagCombo ):_cde ,_bgb :=_acf (form ,wa ,_gd ,_gad .Style ());if _bgb !=nil {return nil ,_bgb ;};return _cde ,nil ;default:_bd .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",_gd .Flags ().String ());
|
|
};default:_bd .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",_cbe );};return nil ,nil ;};
|
|
|
|
// SetStyle applies appearance `style` to `fa`.
|
|
func (_ffffd *ImageFieldAppearance )SetStyle (style AppearanceStyle ){_ffffd ._abgb =&style };
|
|
|
|
// Style returns the appearance style of `fa`. If not specified, returns default style.
|
|
func (_dd FieldAppearance )Style ()AppearanceStyle {if _dd ._ccf !=nil {return *_dd ._ccf ;};_db :=_baa ;return AppearanceStyle {AutoFontSizeFraction :0.65,CheckmarkRune :'✔',BorderSize :0.0,BorderColor :_cgd .NewPdfColorDeviceGray (0),FillColor :_cgd .NewPdfColorDeviceGray (1),MultilineLineHeight :1.2,MultilineVAlignMiddle :false ,DrawAlignmentReticle :false ,AllowMK :true ,MarginLeft :&_db };
|
|
};func _baed (_dfcd [][]_ed .CubicBezierCurve ,_ccgf *_cgd .PdfColorDeviceRGB ,_fbfd float64 )([]byte ,*_cgd .PdfRectangle ,error ){_dgae :=_d .NewContentCreator ();_dgae .Add_q ().SetStrokingColor (_ccgf ).Add_w (_fbfd );_debb :=_ed .NewCubicBezierPath ();
|
|
for _ ,_adee :=range _dfcd {_debb .Curves =append (_debb .Curves ,_adee ...);for _gfea ,_bcff :=range _adee {if _gfea ==0{_dgae .Add_m (_bcff .P0 .X ,_bcff .P0 .Y );}else {_dgae .Add_l (_bcff .P0 .X ,_bcff .P0 .Y );};_dgae .Add_c (_bcff .P1 .X ,_bcff .P1 .Y ,_bcff .P2 .X ,_bcff .P2 .Y ,_bcff .P3 .X ,_bcff .P3 .Y );
|
|
};};_dgae .Add_S ().Add_Q ();return _dgae .Bytes (),_debb .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
|
|
|
// CreateInkAnnotation creates an ink annotation object that can be added to the annotation list of a PDF page.
|
|
func CreateInkAnnotation (inkDef InkAnnotationDef )(*_cgd .PdfAnnotation ,error ){_eebe :=_cgd .NewPdfAnnotationInk ();_cfed :=_ba .MakeArray ();for _ ,_fcg :=range inkDef .Paths {if _fcg .Length ()==0{continue ;};_bebd :=[]float64 {};for _ ,_gag :=range _fcg .Points {_bebd =append (_bebd ,_gag .X ,_gag .Y );
|
|
};_cfed .Append (_ba .MakeArrayFromFloats (_bebd ));};_eebe .InkList =_cfed ;if inkDef .Color ==nil {inkDef .Color =_cgd .NewPdfColorDeviceRGB (0.0,0.0,0.0);};_eebe .C =_ba .MakeArrayFromFloats ([]float64 {inkDef .Color .R (),inkDef .Color .G (),inkDef .Color .B ()});
|
|
_ffaa ,_aegf ,_cba :=_bbdgg (&inkDef );if _cba !=nil {return nil ,_cba ;};_eebe .AP =_ffaa ;_eebe .Rect =_ba .MakeArrayFromFloats ([]float64 {_aegf .Llx ,_aegf .Lly ,_aegf .Urx ,_aegf .Ury });return _eebe .PdfAnnotation ,nil ;};
|
|
|
|
// SignatureLine represents a line of information in the signature field appearance.
|
|
type SignatureLine struct{Desc string ;Text string ;};
|
|
|
|
// 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 ;
|
|
|
|
// ImageFieldAppearance implements interface model.FieldAppearanceGenerator and generates appearance streams
|
|
// for attaching an image to a button field.
|
|
type ImageFieldAppearance struct{OnlyIfMissing bool ;_abgb *AppearanceStyle ;};
|
|
|
|
// 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 *_cgd .PdfPage ,name string ,rect []float64 ,opt TextFieldOptions )(*_cgd .PdfFieldText ,error ){if page ==nil {return nil ,_bda .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};
|
|
if len (name )<=0{return nil ,_bda .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 ,_bda .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
|
|
};_cbfe :=_cgd .NewPdfField ();_daa :=&_cgd .PdfFieldText {};_cbfe .SetContext (_daa );_daa .PdfField =_cbfe ;_daa .T =_ba .MakeString (name );if opt .MaxLen > 0{_daa .MaxLen =_ba .MakeInteger (int64 (opt .MaxLen ));};if len (opt .Value )> 0{_daa .V =_ba .MakeString (opt .Value );
|
|
};_fdfa :=_cgd .NewPdfAnnotationWidget ();_fdfa .Rect =_ba .MakeArrayFromFloats (rect );_fdfa .P =page .ToPdfObject ();_fdfa .F =_ba .MakeInteger (4);_fdfa .Parent =_daa .ToPdfObject ();_daa .Annotations =append (_daa .Annotations ,_fdfa );return _daa ,nil ;
|
|
};const (SignatureImageLeft SignatureImagePosition =iota ;SignatureImageRight ;SignatureImageTop ;SignatureImageBottom ;);func _acca (_acgg *_cgd .PdfFieldButton ,_fgag *_cgd .PdfAnnotationWidget ,_gbad AppearanceStyle )(*_ba .PdfObjectDictionary ,error ){_ead ,_cegb :=_ba .GetArray (_fgag .Rect );
|
|
if !_cegb {return nil ,_bda .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_cefd ,_ddb :=_cgd .NewPdfRectangle (*_ead );if _ddb !=nil {return nil ,_ddb ;};_ggee ,_bbag :=_cefd .Width (),_cefd .Height ();_bbed :=_d .NewContentCreator ();
|
|
if _gbad .BorderSize > 0{_afg (_bbed ,_gbad ,_ggee ,_bbag );};if _gbad .DrawAlignmentReticle {_edgg :=_gbad ;_edgg .BorderSize =0.2;_dcgg (_bbed ,_edgg ,_ggee ,_bbag );};_cgfgf :=_acgg .GetFillImage ();_eag ,_ddb :=_cafe (_ggee ,_bbag ,_cgfgf ,_gbad );
|
|
if _ddb !=nil {return nil ,_ddb ;};_cfdb ,_afdd :=_ba .GetDict (_fgag .MK );if _afdd {_cfdb .Set ("\u006c",_eag .ToPdfObject ());};_eebc :=_ba .MakeDict ();_eebc .Set ("\u0046\u0052\u004d",_eag .ToPdfObject ());_edbga :=_cgd .NewPdfPageResources ();_edbga .ProcSet =_ba .MakeArray (_ba .MakeName ("\u0050\u0044\u0046"));
|
|
_edbga .XObject =_eebc ;_cgba :=_ggee -2;_cggg :=_bbag -2;_bbed .Add_q ();_bbed .Add_re (1,1,_cgba ,_cggg );_bbed .Add_W ();_bbed .Add_n ();_cgba -=2;_cggg -=2;_bbed .Add_q ();_bbed .Add_re (2,2,_cgba ,_cggg );_bbed .Add_W ();_bbed .Add_n ();_cgee :=_e .Min (_cgba /float64 (_cgfgf .Width ),_cggg /float64 (_cgfgf .Height ));
|
|
_bbed .Add_cm (_cgee ,0,0,_cgee ,(_ggee /2)-(float64 (_cgfgf .Width )*_cgee /2)+2,2);_bbed .Add_Do ("\u0046\u0052\u004d");_bbed .Add_Q ();_bbed .Add_Q ();_dcdd :=_cgd .NewXObjectForm ();_dcdd .FormType =_ba .MakeInteger (1);_dcdd .Resources =_edbga ;_dcdd .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_ggee ,_bbag });
|
|
_dcdd .Matrix =_ba .MakeArrayFromFloats ([]float64 {1.0,0.0,0.0,1.0,0.0,0.0});_dcdd .SetContentStream (_bbed .Bytes (),_feaa ());_feg :=_ba .MakeDict ();_feg .Set ("\u004e",_dcdd .ToPdfObject ());return _feg ,nil ;};func (_gab *AppearanceFont )fillName (){if _gab .Font ==nil ||_gab .Name !=""{return ;
|
|
};_ca :=_gab .Font .FontDescriptor ();if _ca ==nil ||_ca .FontName ==nil {return ;};_gab .Name =_ca .FontName .String ();};
|
|
|
|
// ComboboxFieldOptions defines optional parameters for a combobox form field.
|
|
type ComboboxFieldOptions struct{
|
|
|
|
// Choices is the list of string values that can be selected.
|
|
Choices []string ;};func _bece (_caef _a .Image ,_bbgc string ,_dedc *SignatureFieldOpts ,_bedg []float64 ,_befd *_d .ContentCreator )(*_ba .PdfObjectName ,*_cgd .XObjectImage ,error ){_ecdd ,_bfc :=_cgd .DefaultImageHandler {}.NewImageFromGoImage (_caef );
|
|
if _bfc !=nil {return nil ,nil ,_bfc ;};_cagb ,_bfc :=_cgd .NewXObjectImageFromImage (_ecdd ,nil ,_dedc .Encoder );if _bfc !=nil {return nil ,nil ,_bfc ;};_deba ,_afcc :=float64 (*_cagb .Width ),float64 (*_cagb .Height );_ebec :=_bedg [2]-_bedg [0];_cda :=_bedg [3]-_bedg [1];
|
|
if _dedc .AutoSize {_gfce :=_e .Min (_ebec /_deba ,_cda /_afcc );_deba *=_gfce ;_afcc *=_gfce ;_bedg [0]=_bedg [0]+(_ebec /2)-(_deba /2);_bedg [1]=_bedg [1]+(_cda /2)-(_afcc /2);};var _ebea *_ba .PdfObjectName ;if _eeb ,_ddc :=_ba .GetName (_cagb .Name );
|
|
_ddc {_ebea =_eeb ;}else {_ebea =_ba .MakeName (_bbgc );};if _befd !=nil {_befd .Add_q ().Translate (_bedg [0],_bedg [1]).Scale (_deba ,_afcc ).Add_Do (*_ebea ).Add_Q ();}else {return nil ,nil ,_bda .New ("\u0043\u006f\u006e\u0074en\u0074\u0043\u0072\u0065\u0061\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u0075l\u006c");
|
|
};return _ebea ,_cagb ,nil ;};
|
|
|
|
// WrapContentStream ensures that the entire content stream for a `page` is wrapped within q ... Q operands.
|
|
// Ensures that following operands that are added are not affected by additional operands that are added.
|
|
// Implements interface model.ContentStreamWrapper.
|
|
func (_gcaf FieldAppearance )WrapContentStream (page *_cgd .PdfPage )error {_bgac ,_ecca :=page .GetAllContentStreams ();if _ecca !=nil {return _ecca ;};_cbbg :=_d .NewContentStreamParser (_bgac );_dcbg ,_ecca :=_cbbg .Parse ();if _ecca !=nil {return _ecca ;
|
|
};_dcbg .WrapIfNeeded ();_fgf :=[]string {_dcbg .String ()};return page .SetContentStreams (_fgf ,_feaa ());};
|
|
|
|
// InkAnnotationDef holds base information for constructing an ink annotation.
|
|
type InkAnnotationDef struct{
|
|
|
|
// Paths is the array of stroked paths which compose the annotation.
|
|
Paths []_ed .Path ;
|
|
|
|
// Color is the color of the line. Default to black.
|
|
Color *_cgd .PdfColorDeviceRGB ;
|
|
|
|
// LineWidth is the width of the line.
|
|
LineWidth float64 ;};func _dcgg (_ggcaa *_d .ContentCreator ,_aagcd AppearanceStyle ,_cdf ,_ccfae float64 ){_ggcaa .Add_q ().Add_re (0,0,_cdf ,_ccfae ).Add_re (0,_ccfae /2,_cdf ,_ccfae /2).Add_re (0,0,_cdf ,_ccfae ).Add_re (_cdf /2,0,_cdf /2,_ccfae ).Add_w (_aagcd .BorderSize ).SetStrokingColor (_aagcd .BorderColor ).SetNonStrokingColor (_aagcd .FillColor ).Add_B ().Add_Q ();
|
|
};func _bbdgg (_ffe *InkAnnotationDef )(*_ba .PdfObjectDictionary ,*_cgd .PdfRectangle ,error ){_bbdb :=_cgd .NewXObjectForm ();_ffgf ,_bbfe ,_geac :=_gfgg (_ffe );if _geac !=nil {return nil ,nil ,_geac ;};_geac =_bbdb .SetContentStream (_ffgf ,nil );if _geac !=nil {return nil ,nil ,_geac ;
|
|
};_bbdb .BBox =_bbfe .ToPdfObject ();_bbdb .Resources =_cgd .NewPdfPageResources ();_bbdb .Resources .ProcSet =_ba .MakeArray (_ba .MakeName ("\u0050\u0044\u0046"));_gced :=_ba .MakeDict ();_gced .Set ("\u004e",_bbdb .ToPdfObject ());return _gced ,_bbfe ,nil ;
|
|
};func _afg (_bfe *_d .ContentCreator ,_dgb AppearanceStyle ,_eaac ,_bgbf float64 ){_bfe .Add_q ().Add_re (0,0,_eaac ,_bgbf ).Add_w (_dgb .BorderSize ).SetStrokingColor (_dgb .BorderColor ).SetNonStrokingColor (_dgb .FillColor ).Add_B ().Add_Q ();};
|
|
|
|
// GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`.
|
|
// Implements interface model.FieldAppearanceGenerator.
|
|
func (_fcee ImageFieldAppearance )GenerateAppearanceDict (form *_cgd .PdfAcroForm ,field *_cgd .PdfField ,wa *_cgd .PdfAnnotationWidget )(*_ba .PdfObjectDictionary ,error ){_ ,_add :=field .GetContext ().(*_cgd .PdfFieldButton );if !_add {_bd .Log .Trace ("C\u006f\u0075\u006c\u0064\u0020\u006fn\u006c\u0079\u0020\u0068\u0061\u006ed\u006c\u0065\u0020\u0062\u0075\u0074\u0074o\u006e\u0020\u002d\u0020\u0069\u0067\u006e\u006f\u0072\u0069n\u0067");
|
|
return nil ,nil ;};_bgf ,_gfac :=_ba .GetDict (wa .AP );if _gfac &&_fcee .OnlyIfMissing {_bd .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 _bgf ,nil ;};if form .DR ==nil {form .DR =_cgd .NewPdfPageResources ();};switch _ceaa :=field .GetContext ().(type ){case *_cgd .PdfFieldButton :if _ceaa .IsPush (){_egga ,_fac :=_acca (_ceaa ,wa ,_fcee .Style ());if _fac !=nil {return nil ,_fac ;
|
|
};return _egga ,nil ;};};return nil ,nil ;};func _eebcg (_ggac []float64 )[]float64 {var (_ffec =len (_ggac );_baeb =make ([]float64 ,_ffec );_baaf =make ([]float64 ,_ffec ););_fbd :=2.0;_baeb [0]=_ggac [0]/_fbd ;for _cecd :=1;_cecd < _ffec ;_cecd ++{_baaf [_cecd ]=1/_fbd ;
|
|
if _cecd < _ffec -1{_fbd =4.0;}else {_fbd =3.5;};_fbd -=_baaf [_cecd ];_baeb [_cecd ]=(_ggac [_cecd ]-_baeb [_cecd -1])/_fbd ;};for _eged :=1;_eged < _ffec ;_eged ++{_baeb [_ffec -_eged -1]-=_baaf [_ffec -_eged ]*_baeb [_ffec -_eged ];};return _baeb ;};
|
|
func _egd (_dcd _ba .PdfObject ,_fcb *_cgd .PdfPageResources )(*_ba .PdfObjectName ,float64 ,bool ){var (_edbg *_ba .PdfObjectName ;_bffc float64 ;_gfe bool ;);if _ccee ,_ffad :=_ba .GetDict (_dcd );_ffad &&_ccee !=nil {_acb :=_ba .TraceToDirectObject (_ccee .Get ("\u004e"));
|
|
switch _edga :=_acb .(type ){case *_ba .PdfObjectStream :_ddaa ,_feeb :=_ba .DecodeStream (_edga );if _feeb !=nil {_bd .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u0020\u0075\u006e\u0061\u0062\u006c\u0065\u0020\u0064\u0065\u0063\u006f\u0064\u0065\u0020\u0063\u006f\u006e\u0074e\u006e\u0074\u0020\u0073\u0074r\u0065\u0061m\u003a\u0020\u0025\u0076",_feeb .Error ());
|
|
return nil ,0,false ;};_ade ,_feeb :=_d .NewContentStreamParser (string (_ddaa )).Parse ();if _feeb !=nil {_bd .Log .Debug ("\u0045\u0052R\u004f\u0052\u0020\u0075n\u0061\u0062l\u0065\u0020\u0070\u0061\u0072\u0073\u0065\u0020c\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0073\u0074\u0072\u0065\u0061m\u003a\u0020\u0025\u0076",_feeb .Error ());
|
|
return nil ,0,false ;};_fece :=_d .NewContentStreamProcessor (*_ade );_fece .AddHandler (_d .HandlerConditionEnumOperand ,"\u0054\u0066",func (_dca *_d .ContentStreamOperation ,_aafc _d .GraphicsState ,_adg *_cgd .PdfPageResources )error {if len (_dca .Params )==2{if _cfea ,_edbe :=_ba .GetName (_dca .Params [0]);
|
|
_edbe {_edbg =_cfea ;};if _ddeg ,_cbf :=_ba .GetNumberAsFloat (_dca .Params [1]);_cbf ==nil {_bffc =_ddeg ;};_gfe =true ;return _d .ErrEarlyExit ;};return nil ;});_fece .Process (_fcb );return _edbg ,_bffc ,_gfe ;};};return nil ,0,false ;};
|
|
|
|
// CreateCircleAnnotation creates a circle/ellipse annotation object with appearance stream that can be added to
|
|
// page PDF annotations.
|
|
func CreateCircleAnnotation (circDef CircleAnnotationDef )(*_cgd .PdfAnnotation ,error ){_bb :=_cgd .NewPdfAnnotationCircle ();if circDef .BorderEnabled {_eb ,_bdf ,_fg :=circDef .BorderColor .R (),circDef .BorderColor .G (),circDef .BorderColor .B ();
|
|
_bb .C =_ba .MakeArrayFromFloats ([]float64 {_eb ,_bdf ,_fg });_ab :=_cgd .NewBorderStyle ();_ab .SetBorderWidth (circDef .BorderWidth );_bb .BS =_ab .ToPdfObject ();};if circDef .FillEnabled {_gg ,_be ,_bea :=circDef .FillColor .R (),circDef .FillColor .G (),circDef .FillColor .B ();
|
|
_bb .IC =_ba .MakeArrayFromFloats ([]float64 {_gg ,_be ,_bea });}else {_bb .IC =_ba .MakeArrayFromIntegers ([]int {});};if circDef .Opacity < 1.0{_bb .CA =_ba .MakeFloat (circDef .Opacity );};_ec ,_bbf ,_ef :=_ebc (circDef );if _ef !=nil {return nil ,_ef ;
|
|
};_bb .AP =_ec ;_bb .Rect =_ba .MakeArrayFromFloats ([]float64 {_bbf .Llx ,_bbf .Lly ,_bbf .Urx ,_bbf .Ury });return _bb .PdfAnnotation ,nil ;};
|
|
|
|
// AppearanceStyle defines style parameters for appearance stream generation.
|
|
type AppearanceStyle struct{
|
|
|
|
// How much of Rect height to fill when autosizing text.
|
|
AutoFontSizeFraction float64 ;
|
|
|
|
// CheckmarkRune is a rune used for check mark in checkboxes (for ZapfDingbats font).
|
|
CheckmarkRune rune ;BorderSize float64 ;BorderColor _cgd .PdfColor ;FillColor _cgd .PdfColor ;
|
|
|
|
// Multiplier for lineheight for multi line text.
|
|
MultilineLineHeight float64 ;MultilineVAlignMiddle bool ;
|
|
|
|
// Visual guide checking alignment of field contents (debugging).
|
|
DrawAlignmentReticle bool ;
|
|
|
|
// Allow field MK appearance characteristics to override style settings.
|
|
AllowMK bool ;
|
|
|
|
// Fonts holds appearance styles for fonts.
|
|
Fonts *AppearanceFontStyle ;
|
|
|
|
// MarginLeft represents the amount of space to leave on the left side of
|
|
// the form field bounding box when generating appearances (default: 2.0).
|
|
MarginLeft *float64 ;};
|
|
|
|
// Style returns the appearance style of `fa`. If not specified, returns default style.
|
|
func (_ebge ImageFieldAppearance )Style ()AppearanceStyle {if _ebge ._abgb !=nil {return *_ebge ._abgb ;};return AppearanceStyle {BorderSize :0.0,BorderColor :_cgd .NewPdfColorDeviceGray (0),FillColor :_cgd .NewPdfColorDeviceGray (1),DrawAlignmentReticle :false };
|
|
};
|
|
|
|
// 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 *_cgd .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 _ed .LineEndingStyle ;LineEndingStyle2 _ed .LineEndingStyle ;};
|
|
|
|
// 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 *_cgd .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_cgd .PdfColorDeviceRGB ;Opacity float64 ;};const (_ece quadding =0;
|
|
_aa quadding =1;_bg quadding =2;_baa float64 =2.0;);
|
|
|
|
// 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 *_cgd .PdfFont ;
|
|
|
|
// Size represents the size of the font used for the field appearance.
|
|
// If the font size is 0, the value of the FallbackSize field of the
|
|
// AppearanceFontStyle is used, if set. Otherwise, the font size is
|
|
// calculated based on the available annotation height and on the
|
|
// AutoFontSizeFraction field of the AppearanceStyle.
|
|
Size float64 ;};func (_adfa *AppearanceStyle )processDA (_dcbe *_cgd .PdfField ,_cbc *_d .ContentStreamOperations ,_cfg ,_dgeea *_cgd .PdfPageResources ,_fcdga *_d .ContentCreator )(*AppearanceFont ,bool ,error ){var _baef *AppearanceFont ;var _gaeb bool ;
|
|
if _adfa .Fonts !=nil {if _adfa .Fonts .Fallback !=nil {_baef =_adfa .Fonts .Fallback ;};if _ede :=_adfa .Fonts .FieldFallbacks ;_ede !=nil {if _eab ,_gee :=_ede [_dcbe .PartialName ()];_gee {_baef =_eab ;}else if _eea ,_abec :=_dcbe .FullName ();_abec ==nil {if _cfb ,_fcfae :=_ede [_eea ];
|
|
_fcfae {_baef =_cfb ;};};};if _baef !=nil {_baef .fillName ();};_gaeb =_adfa .Fonts .ForceReplace ;};var _fcdgad string ;var _degf float64 ;var _efbe bool ;if _cbc !=nil {for _ ,_gbdc :=range *_cbc {if _gbdc .Operand =="\u0054\u0066"&&len (_gbdc .Params )==2{if _cfd ,_aaf :=_ba .GetNameVal (_gbdc .Params [0]);
|
|
_aaf {_fcdgad =_cfd ;};if _ccd ,_gded :=_ba .GetNumberAsFloat (_gbdc .Params [1]);_gded ==nil {_degf =_ccd ;};_efbe =true ;continue ;};_fcdga .AddOperand (*_gbdc );};};var _cgfbg *AppearanceFont ;var _gffa _ba .PdfObject ;if _gaeb &&_baef !=nil {_cgfbg =_baef ;
|
|
}else {if _cfg !=nil &&_fcdgad !=""{if _edeb ,_edb :=_cfg .GetFontByName (*_ba .MakeName (_fcdgad ));_edb {if _gdb ,_fee :=_cgd .NewPdfFontFromPdfObject (_edeb );_fee ==nil {_gffa =_edeb ;_cgfbg =&AppearanceFont {Name :_fcdgad ,Font :_gdb ,Size :_degf };
|
|
}else {_bd .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",_fee );
|
|
};};};if _cgfbg ==nil &&_baef !=nil {_cgfbg =_baef ;};if _cgfbg ==nil {_fabc ,_cff :=_cgd .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");if _cff !=nil {return nil ,false ,_cff ;};_cgfbg =&AppearanceFont {Name :"\u0048\u0065\u006c\u0076",Font :_fabc ,Size :_degf };
|
|
};};if _cgfbg .Size <=0&&_adfa .Fonts !=nil &&_adfa .Fonts .FallbackSize > 0{_cgfbg .Size =_adfa .Fonts .FallbackSize ;};_fbf :=*_ba .MakeName (_cgfbg .Name );if _gffa ==nil {_gffa =_cgfbg .Font .ToPdfObject ();};if _cfg !=nil &&!_cfg .HasFontByName (_fbf ){_cfg .SetFontByName (_fbf ,_gffa );
|
|
};if _dgeea !=nil &&!_dgeea .HasFontByName (_fbf ){_dgeea .SetFontByName (_fbf ,_gffa );};return _cgfbg ,_efbe ,nil ;};
|
|
|
|
// AppearanceFontStyle defines font style characteristics for form fields,
|
|
// used in the filling/flattening process.
|
|
type AppearanceFontStyle struct{
|
|
|
|
// Fallback represents a global font fallback, used for fields which do
|
|
// not specify a font in their default appearance (DA). The fallback is
|
|
// also used if there is a font specified in the DA, but it is not
|
|
// found in the AcroForm resources (DR).
|
|
Fallback *AppearanceFont ;
|
|
|
|
// FallbackSize represents a global font size fallback used for fields
|
|
// which do not specify a font size in their default appearance (DA).
|
|
// The fallback size is applied only if its value is larger than zero.
|
|
FallbackSize float64 ;
|
|
|
|
// FieldFallbacks defines font fallbacks for specific fields. The map keys
|
|
// represent the names of the fields (which can be specified by their
|
|
// partial or full names). Specific field fallback fonts take precedence
|
|
// over the global font fallback.
|
|
FieldFallbacks map[string ]*AppearanceFont ;
|
|
|
|
// ForceReplace forces the replacement of fonts in the filling/flattening
|
|
// process, even if the default appearance (DA) specifies a valid font.
|
|
// If no fallback font is provided, setting this field has no effect.
|
|
ForceReplace bool ;};func _cea (_eed *_cgd .PdfAnnotationWidget ,_baag *_cgd .PdfFieldText ,_cge *_cgd .PdfPageResources ,_ceb AppearanceStyle )(*_ba .PdfObjectDictionary ,error ){_afa :=_cgd .NewPdfPageResources ();_fec ,_fea :=_ba .GetArray (_eed .Rect );
|
|
if !_fea {return nil ,_bda .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_fbe ,_abef :=_cgd .NewPdfRectangle (*_fec );if _abef !=nil {return nil ,_abef ;};_eae ,_acg :=_fbe .Width (),_fbe .Height ();_gca ,_agdb :=_eae ,_acg ;
|
|
_dcg ,_adf :=_ba .GetDict (_eed .MK );if _adf {_gcc ,_ :=_ba .GetDict (_eed .BS );_eaf :=_ceb .applyAppearanceCharacteristics (_dcg ,_gcc ,nil );if _eaf !=nil {return nil ,_eaf ;};};_bcbf ,_adf :=_ba .GetIntVal (_baag .MaxLen );if !_adf {return nil ,_bda .New ("\u006d\u0061\u0078\u006c\u0065\u006e\u0020\u006e\u006ft\u0020\u0073\u0065\u0074");
|
|
};if _bcbf <=0{return nil ,_bda .New ("\u006d\u0061\u0078\u004c\u0065\u006e\u0020\u0069\u006ev\u0061\u006c\u0069\u0064");};_abf :=_eae /float64 (_bcbf );_agf ,_abef :=_d .NewContentStreamParser (_ccb (_baag .PdfField )).Parse ();if _abef !=nil {return nil ,_abef ;
|
|
};_gfc :=_d .NewContentCreator ();if _ceb .BorderSize > 0{_afg (_gfc ,_ceb ,_eae ,_acg );};if _ceb .DrawAlignmentReticle {_abg :=_ceb ;_abg .BorderSize =0.2;_dcgg (_gfc ,_abg ,_eae ,_acg );};_gfc .Add_BMC ("\u0054\u0078");_gfc .Add_q ();_ ,_acg =_ceb .applyRotation (_dcg ,_eae ,_acg ,_gfc );
|
|
_gfc .Add_BT ();_agdc ,_dab ,_abef :=_ceb .processDA (_baag .PdfField ,_agf ,_cge ,_afa ,_gfc );if _abef !=nil {return nil ,_abef ;};_cdc :=_agdc .Font ;_bbg :=_ba .MakeName (_agdc .Name );_age :=_agdc .Size ;_egg :=_age ==0;if _egg &&_dab {_age =_acg *_ceb .AutoFontSizeFraction ;
|
|
};_eafg :=_cdc .Encoder ();if _eafg ==nil {_bd .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");
|
|
_eafg =_f .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};var _geaa string ;if _dgee ,_cbg :=_ba .GetString (_baag .V );_cbg {_geaa =_dgee .Decoded ();};_gfc .Add_Tf (*_bbg ,_age );var _bbdf float64 ;for _ ,_beb :=range _geaa {_cbgc ,_ffff :=_cdc .GetRuneMetrics (_beb );
|
|
if !_ffff {_bd .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",_beb );
|
|
continue ;};_gbaf :=_cbgc .Wy ;if int (_gbaf )<=0{_gbaf =_cbgc .Wx ;};if _gbaf > _bbdf {_bbdf =_gbaf ;};};if int (_bbdf )==0{_bd .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");
|
|
_bbdf =1000;};_cafc ,_abef :=_cdc .GetFontDescriptor ();if _abef !=nil {_bd .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 _cgf float64 ;if _cafc !=nil {_cgf ,_abef =_cafc .GetCapHeight ();if _abef !=nil {_bd .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",_abef );
|
|
};};if int (_cgf )<=0{_bd .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");
|
|
_cgf =1000.0;};_edgd :=_cgf /1000.0*_age ;_bgab :=0.0;_ebb :=1.0*_age *(_bbdf /1000.0);{_eff :=_ebb ;if _egg &&_bgab +_eff > _acg {_age =0.95*(_acg -_bgab );_edgd =_cgf /1000.0*_age ;};if _acg > _edgd {_bgab =(_acg -_edgd )/2.0;};};_gfc .Add_Td (0,_bgab );
|
|
if _bcec ,_agbd :=_ba .GetIntVal (_baag .Q );_agbd {switch _bcec {case 2:if len (_geaa )< _bcbf {_agde :=float64 (_bcbf -len (_geaa ))*_abf ;_gfc .Add_Td (_agde ,0);};};};for _cgb ,_cebd :=range _geaa {_ebgg :=_baa ;if _ceb .MarginLeft !=nil {_ebgg =*_ceb .MarginLeft ;
|
|
};_eda :=string (_cebd );if _eafg !=nil {_dag ,_gaa :=_cdc .GetRuneMetrics (_cebd );if !_gaa {_bd .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",_cebd );
|
|
continue ;};_eda =string (_eafg .Encode (_eda ));_fdd :=_age *_dag .Wx /1000.0;_ege :=(_abf -_fdd )/2;_ebgg =_ege ;};_gfc .Add_Td (_ebgg ,0);_gfc .Add_Tj (*_ba .MakeString (_eda ));if _cgb !=len (_geaa )-1{_gfc .Add_Td (_abf -_ebgg ,0);};};_gfc .Add_ET ();
|
|
_gfc .Add_Q ();_gfc .Add_EMC ();_gfg :=_cgd .NewXObjectForm ();_gfg .Resources =_afa ;_gfg .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_gca ,_agdb });_gfg .SetContentStream (_gfc .Bytes (),_feaa ());_dgf :=_ba .MakeDict ();_dgf .Set ("\u004e",_gfg .ToPdfObject ());
|
|
return _dgf ,nil ;};
|
|
|
|
// SignatureFieldOpts represents a set of options used to configure
|
|
// an appearance widget dictionary.
|
|
type SignatureFieldOpts struct{
|
|
|
|
// Rect represents the area the signature annotation is displayed on.
|
|
Rect []float64 ;
|
|
|
|
// AutoSize specifies if the content of the appearance should be
|
|
// scaled to fit in the annotation rectangle.
|
|
AutoSize bool ;
|
|
|
|
// Font specifies the font of the text content.
|
|
Font *_cgd .PdfFont ;
|
|
|
|
// FontSize specifies the size of the text content.
|
|
FontSize float64 ;
|
|
|
|
// LineHeight specifies the height of a line of text in the appearance annotation.
|
|
LineHeight float64 ;
|
|
|
|
// TextColor represents the color of the text content displayed.
|
|
TextColor _cgd .PdfColor ;
|
|
|
|
// FillColor represents the background color of the appearance annotation area.
|
|
FillColor _cgd .PdfColor ;
|
|
|
|
// BorderSize represents border size of the appearance annotation area.
|
|
BorderSize float64 ;
|
|
|
|
// BorderColor represents the border color of the appearance annotation area.
|
|
BorderColor _cgd .PdfColor ;
|
|
|
|
// WatermarkImage specifies the image used as a watermark that will be rendered
|
|
// behind the signature.
|
|
WatermarkImage _a .Image ;
|
|
|
|
// Image represents the image used for the signature appearance.
|
|
Image _a .Image ;
|
|
|
|
// Encoder specifies the image encoder used for image signature. Defaults to flate encoder.
|
|
Encoder _ba .StreamEncoder ;
|
|
|
|
// ImagePosition specifies the image location relative to the text signature.
|
|
ImagePosition SignatureImagePosition ;};func _gfgg (_bgaf *InkAnnotationDef )([]byte ,*_cgd .PdfRectangle ,error ){_geec :=[][]_ed .CubicBezierCurve {};for _ ,_bgbe :=range _bgaf .Paths {if _bgbe .Length ()==0{continue ;};_bbfb :=_bgbe .Points ;_faef ,_beg ,_gaad :=_gbf (_bbfb );
|
|
if _gaad !=nil {return nil ,nil ,_gaad ;};if len (_faef )!=len (_beg ){return nil ,nil ,_bda .New ("\u0049\u006e\u0065\u0071\u0075\u0061\u006c\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020\u006f\u0066\u0020\u0063\u0061l\u0063\u0075\u006c\u0061\u0074\u0065\u0064\u0020\u0066\u0069\u0072\u0073\u0074\u0020\u0061\u006e\u0064\u0020\u0073\u0065\u0063\u006f\u006e\u0064\u0020\u0063\u006f\u006e\u0074\u0072o\u006c\u0020\u0070\u006f\u0069n\u0074");
|
|
};_gec :=[]_ed .CubicBezierCurve {};for _fgfe :=0;_fgfe < len (_faef );_fgfe ++{_gec =append (_gec ,_ed .CubicBezierCurve {P0 :_bbfb [_fgfe ],P1 :_faef [_fgfe ],P2 :_beg [_fgfe ],P3 :_bbfb [_fgfe +1]});};if len (_gec )> 0{_geec =append (_geec ,_gec );};
|
|
};_agc ,_ddd ,_dbcb :=_baed (_geec ,_bgaf .Color ,_bgaf .LineWidth );if _dbcb !=nil {return nil ,nil ,_dbcb ;};return _agc ,_ddd ,nil ;};func _adgb (_gbae LineAnnotationDef ,_ddg string )([]byte ,*_cgd .PdfRectangle ,*_cgd .PdfRectangle ,error ){_abga :=_ed .Line {X1 :0,Y1 :0,X2 :_gbae .X2 -_gbae .X1 ,Y2 :_gbae .Y2 -_gbae .Y1 ,LineColor :_gbae .LineColor ,Opacity :_gbae .Opacity ,LineWidth :_gbae .LineWidth ,LineEndingStyle1 :_gbae .LineEndingStyle1 ,LineEndingStyle2 :_gbae .LineEndingStyle2 };
|
|
_acggg ,_fcfad ,_gffb :=_abga .Draw (_ddg );if _gffb !=nil {return nil ,nil ,nil ,_gffb ;};_cddf :=&_cgd .PdfRectangle {};_cddf .Llx =_gbae .X1 +_fcfad .Llx ;_cddf .Lly =_gbae .Y1 +_fcfad .Lly ;_cddf .Urx =_gbae .X1 +_fcfad .Urx ;_cddf .Ury =_gbae .Y1 +_fcfad .Ury ;
|
|
return _acggg ,_fcfad ,_cddf ,nil ;};func _cafe (_eegb ,_abad float64 ,_gfde *_cgd .Image ,_bead AppearanceStyle )(*_cgd .XObjectForm ,error ){_dedd ,_gef :=_cgd .NewXObjectImageFromImage (_gfde ,nil ,_ba .NewFlateEncoder ());if _gef !=nil {return nil ,_gef ;
|
|
};_dedd .Decode =_ba .MakeArrayFromFloats ([]float64 {0.0,1.0,0.0,1.0,0.0,1.0});_bbagb :=_cgd .NewPdfPageResources ();_bbagb .ProcSet =_ba .MakeArray (_ba .MakeName ("\u0050\u0044\u0046"),_ba .MakeName ("\u0049\u006d\u0061\u0067\u0065\u0043"));_bbagb .SetXObjectImageByName (_ba .PdfObjectName ("\u0049\u006d\u0030"),_dedd );
|
|
_aeb :=_d .NewContentCreator ();_aeb .Add_q ();_aeb .Add_cm (float64 (_gfde .Width ),0,0,float64 (_gfde .Height ),0,0);_aeb .Add_Do ("\u0049\u006d\u0030");_aeb .Add_Q ();_faca :=_cgd .NewXObjectForm ();_faca .FormType =_ba .MakeInteger (1);_faca .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,float64 (_gfde .Width ),float64 (_gfde .Height )});
|
|
_faca .Resources =_bbagb ;_faca .SetContentStream (_aeb .Bytes (),_feaa ());return _faca ,nil ;};type quadding int ;func _ggfb (_eec *_cgd .PdfAnnotationWidget ,_efd *_cgd .PdfFieldButton ,_agec *_cgd .PdfPageResources ,_dcb AppearanceStyle )(*_ba .PdfObjectDictionary ,error ){_fffc ,_bef :=_ba .GetArray (_eec .Rect );
|
|
if !_bef {return nil ,_bda .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_def ,_caa :=_cgd .NewPdfRectangle (*_fffc );if _caa !=nil {return nil ,_caa ;};_ebff ,_aga :=_def .Width (),_def .Height ();_abed ,_eddb :=_ebff ,_aga ;
|
|
_bd .Log .Debug ("\u0043\u0068\u0065\u0063kb\u006f\u0078\u002c\u0020\u0077\u0061\u0020\u0042\u0053\u003a\u0020\u0025\u0076",_eec .BS );_ddf ,_caa :=_cgd .NewStandard14Font ("\u005a\u0061\u0070f\u0044\u0069\u006e\u0067\u0062\u0061\u0074\u0073");if _caa !=nil {return nil ,_caa ;
|
|
};_bcf ,_cae :=_ba .GetDict (_eec .MK );if _cae {_fgb ,_ :=_ba .GetDict (_eec .BS );_ebeb :=_dcb .applyAppearanceCharacteristics (_bcf ,_fgb ,_ddf );if _ebeb !=nil {return nil ,_ebeb ;};};_edf :=_cgd .NewXObjectForm ();{_faaa :=_d .NewContentCreator ();
|
|
if _dcb .BorderSize > 0{_afg (_faaa ,_dcb ,_ebff ,_aga );};if _dcb .DrawAlignmentReticle {_gff :=_dcb ;_gff .BorderSize =0.2;_dcgg (_faaa ,_gff ,_ebff ,_aga );};_ebff ,_aga =_dcb .applyRotation (_bcf ,_ebff ,_aga ,_faaa );_abb :=_dcb .AutoFontSizeFraction *_aga ;
|
|
_cefc ,_gega :=_ddf .GetRuneMetrics (_dcb .CheckmarkRune );if !_gega {return nil ,_bda .New ("\u0067l\u0079p\u0068\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");};_ced :=_ddf .Encoder ();_dee :=_ced .Encode (string (_dcb .CheckmarkRune ));
|
|
_fab :=_cefc .Wx *_abb /1000.0;_dde :=705.0;_agfg :=_dde /1000.0*_abb ;_efb :=_baa ;if _dcb .MarginLeft !=nil {_efb =*_dcb .MarginLeft ;};_faeb :=1.0;if _fab < _ebff {_efb =(_ebff -_fab )/2.0;};if _agfg < _aga {_faeb =(_aga -_agfg )/2.0;};_faaa .Add_q ().Add_g (0).Add_BT ().Add_Tf ("\u005a\u0061\u0044\u0062",_abb ).Add_Td (_efb ,_faeb ).Add_Tj (*_ba .MakeStringFromBytes (_dee )).Add_ET ().Add_Q ();
|
|
_edf .Resources =_cgd .NewPdfPageResources ();_edf .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_ddf .ToPdfObject ());_edf .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_abed ,_eddb });_edf .SetContentStream (_faaa .Bytes (),_feaa ());};_ffg :=_cgd .NewXObjectForm ();
|
|
{_gbd :=_d .NewContentCreator ();if _dcb .BorderSize > 0{_afg (_gbd ,_dcb ,_ebff ,_aga );};_ffg .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_abed ,_eddb });_ffg .SetContentStream (_gbd .Bytes (),_feaa ());};_fdgb :=_ba .PdfObjectName ("\u0059\u0065\u0073");
|
|
_fgd ,_cae :=_ba .GetDict (_eec .PdfAnnotation .AP );if _cae &&_fgd !=nil {_eafe :=_ba .TraceToDirectObject (_fgd .Get ("\u004e"));switch _gcg :=_eafe .(type ){case *_ba .PdfObjectDictionary :_aec :=_gcg .Keys ();for _ ,_cdd :=range _aec {if _cdd !="\u004f\u0066\u0066"{_fdgb =_cdd ;
|
|
};};};};_gbc :=_ba .MakeDict ();_gbc .Set ("\u004f\u0066\u0066",_ffg .ToPdfObject ());_gbc .Set (_fdgb ,_edf .ToPdfObject ());_dbbg :=_ba .MakeDict ();_dbbg .Set ("\u004e",_gbc );return _dbbg ,nil ;};
|
|
|
|
// RectangleAnnotationDef is a rectangle defined with a specified Width and Height and a lower left corner at (X,Y).
|
|
// The rectangle can optionally have a border and a filling color.
|
|
// The Width/Height includes the border (if any specified).
|
|
type RectangleAnnotationDef struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_cgd .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_cgd .PdfColorDeviceRGB ;Opacity float64 ;};
|
|
|
|
// TextFieldOptions defines optional parameter for a text field in a form.
|
|
type TextFieldOptions struct{MaxLen int ;Value string ;};
|
|
|
|
// 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 *_cgd .PdfPage ,name string ,rect []float64 ,opt ComboboxFieldOptions )(*_cgd .PdfFieldChoice ,error ){if page ==nil {return nil ,_bda .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
|
|
};if len (name )<=0{return nil ,_bda .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 ,_bda .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
|
|
};_gdc :=_cgd .NewPdfField ();_fagd :=&_cgd .PdfFieldChoice {};_gdc .SetContext (_fagd );_fagd .PdfField =_gdc ;_fagd .T =_ba .MakeString (name );_fagd .Opt =_ba .MakeArray ();for _ ,_cebc :=range opt .Choices {_fagd .Opt .Append (_ba .MakeString (_cebc ));
|
|
};_fagd .SetFlag (_cgd .FieldFlagCombo );_bgba :=_cgd .NewPdfAnnotationWidget ();_bgba .Rect =_ba .MakeArrayFromFloats (rect );_bgba .P =page .ToPdfObject ();_bgba .F =_ba .MakeInteger (4);_bgba .Parent =_fagd .ToPdfObject ();_fagd .Annotations =append (_fagd .Annotations ,_bgba );
|
|
return _fagd ,nil ;};
|
|
|
|
// ImageFieldOptions defines optional parameters for a push button with image attach capability form field.
|
|
type ImageFieldOptions struct{Image *_cgd .Image ;_edee AppearanceStyle ;};func _agb (_ff *_cgd .PdfAnnotationWidget ,_adc *_cgd .PdfFieldText ,_ggf *_cgd .PdfPageResources ,_caf AppearanceStyle )(*_ba .PdfObjectDictionary ,error ){_gae :=_cgd .NewPdfPageResources ();
|
|
_eee ,_ebf :=_ba .GetArray (_ff .Rect );if !_ebf {return nil ,_bda .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_ce ,_cf :=_cgd .NewPdfRectangle (*_eee );if _cf !=nil {return nil ,_cf ;};_ebe ,_faf :=_ce .Width (),_ce .Height ();
|
|
_de ,_edg :=_ebe ,_faf ;_deb ,_aag :=_ba .GetDict (_ff .MK );if _aag {_ea ,_ :=_ba .GetDict (_ff .BS );_ecg :=_caf .applyAppearanceCharacteristics (_deb ,_ea ,nil );if _ecg !=nil {return nil ,_ecg ;};};_dbc ,_cf :=_d .NewContentStreamParser (_ccb (_adc .PdfField )).Parse ();
|
|
if _cf !=nil {return nil ,_cf ;};_ebd :=_d .NewContentCreator ();if _caf .BorderSize > 0{_afg (_ebd ,_caf ,_ebe ,_faf );};if _caf .DrawAlignmentReticle {_cgg :=_caf ;_cgg .BorderSize =0.2;_dcgg (_ebd ,_cgg ,_ebe ,_faf );};_ebd .Add_BMC ("\u0054\u0078");
|
|
_ebd .Add_q ();_ebe ,_faf =_caf .applyRotation (_deb ,_ebe ,_faf ,_ebd );_ebd .Add_BT ();_agbg ,_gac ,_cf :=_caf .processDA (_adc .PdfField ,_dbc ,_ggf ,_gae ,_ebd );if _cf !=nil {return nil ,_cf ;};_geg :=_agbg .Font ;_bee :=_agbg .Size ;_df :=_ba .MakeName (_agbg .Name );
|
|
if _adc .Flags ().Has (_cgd .FieldFlagMultiline )&&_adc .MaxLen !=nil {_bd .Log .Debug ("\u004c\u006f\u006f\u006b\u0020\u0066\u006f\u0072\u0020\u0041\u0050\u0020\u0064\u0069\u0063\u0074\u0069\u006fn\u0061\u0072\u0079\u0020\u0066\u006f\u0072 \u004e\u0020\u006f\u0062\u006a\u0065\u0063\u0074\u0020\u0063\u006fn\u0074\u0065\u006e\u0074\u0020\u0073\u0074\u0072\u0065\u0061\u006d");
|
|
if _cgc ,_gege ,_dfg :=_egd (_ff .PdfAnnotation .AP ,_ggf );_dfg {_df =_cgc ;_bee =_gege ;_gac =true ;};};_fad :=_bee ==0;if _fad &&_gac {_bee =_faf *_caf .AutoFontSizeFraction ;};_dbg :=_geg .Encoder ();if _dbg ==nil {_bd .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");
|
|
_dbg =_f .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};_egc ,_cf :=_geg .GetFontDescriptor ();if _cf !=nil {_bd .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 _bde string ;if _gcf ,_fag :=_ba .GetString (_adc .V );_fag {_bde =_gcf .Decoded ();};if len (_bde )==0{return nil ,nil ;};_dfgg :=[]string {_bde };_ecc :=false ;if _adc .Flags ().Has (_cgd .FieldFlagMultiline ){_ecc =true ;_bde =_cg .Replace (_bde ,"\u000d\u000a","\u000a",-1);
|
|
_bde =_cg .Replace (_bde ,"\u000d","\u000a",-1);_dfgg =_cg .Split (_bde ,"\u000a");};_ceg :=make ([]string ,len (_dfgg ));copy (_ceg ,_dfgg );_ebg :=_caf .MultilineLineHeight ;_dfd :=0.0;_fff :=0;if _dbg !=nil {for _bee >=0{_acd :=make ([]string ,len (_dfgg ));
|
|
copy (_acd ,_dfgg );_dbe :=make ([]string ,len (_ceg ));copy (_dbe ,_ceg );_dfd =0.0;_fff =0;_af :=len (_acd );_fe :=0;for _fe < _af {var _gea float64 ;_fd :=-1;_bcb :=_baa ;if _caf .MarginLeft !=nil {_bcb =*_caf .MarginLeft ;};for _faff ,_bce :=range _acd [_fe ]{if _bce ==' '{_fd =_faff ;
|
|
};_cgdd ,_bgd :=_geg .GetRuneMetrics (_bce );if !_bgd {_bd .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",_bce );
|
|
continue ;};_gea =_bcb ;_bcb +=_cgdd .Wx ;if _ecc &&!_fad &&_bee *_bcb /1000.0> _ebe {_dfa :=_faff ;_gda :=_faff ;if _fd > 0{_dfa =_fd +1;_gda =_fd ;};_fdg :=_acd [_fe ][_dfa :];_bbb :=_dbe [_fe ][_dfa :];if _fe < len (_acd )-1{_acd =append (_acd [:_fe +1],_acd [_fe :]...);
|
|
_acd [_fe +1]=_fdg ;_dbe =append (_dbe [:_fe +1],_dbe [_fe :]...);_dbe [_fe +1]=_bbb ;}else {_acd =append (_acd ,_fdg );_dbe =append (_dbe ,_bbb );};_acd [_fe ]=_acd [_fe ][0:_gda ];_dbe [_fe ]=_dbe [_fe ][0:_gda ];_af ++;_bcb =_gea ;break ;};};if _bcb > _dfd {_dfd =_bcb ;
|
|
};_acd [_fe ]=string (_dbg .Encode (_acd [_fe ]));if len (_acd [_fe ])> 0{_fff ++;};_fe ++;};_fdc :=_bee ;if _fff > 1{_fdc *=_ebg ;};_ecef :=float64 (_fff )*_fdc ;if _fad ||_ecef <=_faf {_dfgg =_acd ;_ceg =_dbe ;break ;};_bee --;};};_bba :=_baa ;if _caf .MarginLeft !=nil {_bba =*_caf .MarginLeft ;
|
|
};if _bee ==0||_fad &&_dfd > 0&&_bba +_dfd *_bee /1000.0> _ebe {_bee =0.95*1000.0*(_ebe -_bba )/_dfd ;};_cef :=_ece ;{if _adce ,_dc :=_ba .GetIntVal (_adc .Q );_dc {switch _adce {case 0:_cef =_ece ;case 1:_cef =_aa ;case 2:_cef =_bg ;default:_bd .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",_adce );
|
|
};};};_bgg :=_bee ;if _ecc &&_fff > 1{_bgg =_ebg *_bee ;};var _bac float64 ;if _egc !=nil {_bac ,_cf =_egc .GetCapHeight ();if _cf !=nil {_bd .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",_cf );
|
|
};};if int (_bac )<=0{_bd .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");
|
|
_bac =1000;};_gba :=_bac /1000.0*_bee ;_deg :=0.0;{_dge :=float64 (_fff )*_bgg ;if _fad &&_deg +_dge > _faf {_bee =0.95*(_faf -_deg )/float64 (_fff );_bgg =_bee ;if _ecc &&_fff > 1{_bgg =_ebg *_bee ;};_gba =_bac /1000.0*_bee ;_dge =float64 (_fff )*_bgg ;
|
|
};if _faf > _dge {if _ecc {if _caf .MultilineVAlignMiddle {_fae :=(_faf -(_dge +_gba ))/2.0;_faa :=_fae +_dge +_gba -_bgg ;_deg =_faa ;if _fff > 1{_deg =_deg +(_dge /_bee *float64 (_fff ))-_bgg -_gba ;};if _deg < _dge {_deg =(_faf -_gba )/2.0;};}else {_deg =_faf -_bgg ;
|
|
if _deg > _bee {_da :=0.0;if _ecc &&_caf .MultilineLineHeight > 1&&_fff > 1{_da =_caf .MultilineLineHeight -1;};_deg -=_bee *(0.5-_da );};};}else {_deg =(_faf -_gba )/2.0;};};};_ebd .Add_Tf (*_df ,_bee );_ebd .Add_Td (_bba ,_deg );_abc :=_bba ;_dga :=_bba ;
|
|
for _dcf ,_gce :=range _dfgg {_dbb :=0.0;for _ ,_agd :=range _ceg [_dcf ]{_edd ,_bab :=_geg .GetRuneMetrics (_agd );if !_bab {continue ;};_dbb +=_edd .Wx ;};_cca :=_dbb /1000.0*_bee ;_ebfd :=_ebe -_cca ;var _gf float64 ;switch _cef {case _ece :_gf =_abc ;
|
|
case _aa :_gf =_ebfd /2;case _bg :_gf =_ebfd ;};_bba =_gf -_dga ;if _bba > 0.0{_ebd .Add_Td (_bba ,0);};_dga =_gf ;_ebd .Add_Tj (*_ba .MakeString (_gce ));if _dcf < len (_dfgg )-1{_ebd .Add_Td (0,-_bee *_ebg );};};_ebd .Add_ET ();_ebd .Add_Q ();_ebd .Add_EMC ();
|
|
_fdf :=_cgd .NewXObjectForm ();_fdf .Resources =_gae ;_fdf .BBox =_ba .MakeArrayFromFloats ([]float64 {0,0,_de ,_edg });_fdf .SetContentStream (_ebd .Bytes (),_feaa ());_gfb :=_ba .MakeDict ();_gfb .Set ("\u004e",_fdf .ToPdfObject ());return _gfb ,nil ;
|
|
};func _gbe (_eefb []*SignatureLine ,_ccg *SignatureFieldOpts )(*_ba .PdfObjectDictionary ,error ){if _ccg ==nil {_ccg =NewSignatureFieldOpts ();};var _bbe error ;var _baba *_ba .PdfObjectName ;_afc :=_ccg .Font ;if _afc !=nil {_gbb ,_ :=_afc .GetFontDescriptor ();
|
|
if _gbb !=nil {if _fdcf ,_ecd :=_gbb .FontName .(*_ba .PdfObjectName );_ecd {_baba =_fdcf ;};};if _baba ==nil {_baba =_ba .MakeName ("\u0046\u006f\u006et\u0031");};}else {if _afc ,_bbe =_cgd .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");
|
|
_bbe !=nil {return nil ,_bbe ;};_baba =_ba .MakeName ("\u0048\u0065\u006c\u0076");};_dbf :=_ccg .FontSize ;if _dbf <=0{_dbf =10;};if _ccg .LineHeight <=0{_ccg .LineHeight =1;};_ageb :=_ccg .LineHeight *_dbf ;_fbb ,_gfa :=_afc .GetRuneMetrics (' ');if !_gfa {return nil ,_bda .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");
|
|
};_caac :=_fbb .Wx ;var _cedg float64 ;var _abbb []string ;for _ ,_gbbd :=range _eefb {if _gbbd .Text ==""{continue ;};_fgae :=_gbbd .Text ;if _gbbd .Desc !=""{_fgae =_gbbd .Desc +"\u003a\u0020"+_fgae ;};_abbb =append (_abbb ,_fgae );var _bbaa float64 ;
|
|
for _ ,_dgfc :=range _fgae {_gaae ,_fabg :=_afc .GetRuneMetrics (_dgfc );if !_fabg {continue ;};_bbaa +=_gaae .Wx ;};if _bbaa > _cedg {_cedg =_bbaa ;};};_cedg =_cedg *_dbf /1000.0;_ccgb :=float64 (len (_abbb ))*_ageb ;_efbd :=_ccg .Image !=nil ;_ebcg :=_ccg .Rect ;
|
|
if _ebcg ==nil {_ebcg =[]float64 {0,0,_cedg ,_ccgb };if _efbd {_ebcg [2]=_cedg *2;_ebcg [3]=_ccgb *2;};_ccg .Rect =_ebcg ;};_acfe :=_ebcg [2]-_ebcg [0];_dcgd :=_ebcg [3]-_ebcg [1];_fdgg ,_fgaa :=_ebcg ,_ebcg ;var _bcc ,_fbcf float64 ;if _efbd &&len (_abbb )> 0{if _ccg .ImagePosition <=SignatureImageRight {_cfe :=[]float64 {_ebcg [0],_ebcg [1],_ebcg [0]+(_acfe /2),_ebcg [3]};
|
|
_efc :=[]float64 {_ebcg [0]+(_acfe /2),_ebcg [1],_ebcg [2],_ebcg [3]};if _ccg .ImagePosition ==SignatureImageLeft {_fdgg ,_fgaa =_cfe ,_efc ;}else {_fdgg ,_fgaa =_efc ,_cfe ;};}else {_acc :=[]float64 {_ebcg [0],_ebcg [1],_ebcg [2],_ebcg [1]+(_dcgd /2)};
|
|
_cgfg :=[]float64 {_ebcg [0],_ebcg [1]+(_dcgd /2),_ebcg [2],_ebcg [3]};if _ccg .ImagePosition ==SignatureImageTop {_fdgg ,_fgaa =_cgfg ,_acc ;}else {_fdgg ,_fgaa =_acc ,_cgfg ;};};};_bcc =_fgaa [2]-_fgaa [0];_fbcf =_fgaa [3]-_fgaa [1];var _cbda float64 ;
|
|
if _ccg .AutoSize {if _cedg > _bcc ||_ccgb > _fbcf {_cec :=_e .Min (_bcc /_cedg ,_fbcf /_ccgb );_dbf *=_cec ;};_ageb =_ccg .LineHeight *_dbf ;_cbda +=(_fbcf -float64 (len (_abbb ))*_ageb )/2;};_dad :=_d .NewContentCreator ();_eedb :=_cgd .NewPdfPageResources ();
|
|
_eedb .SetFontByName (*_baba ,_afc .ToPdfObject ());if _ccg .BorderSize <=0{_ccg .BorderSize =0;_ccg .BorderColor =_cgd .NewPdfColorDeviceGray (1);};_dad .Add_q ();if _ccg .FillColor !=nil {_dad .SetNonStrokingColor (_ccg .FillColor );};if _ccg .BorderColor !=nil {_dad .SetStrokingColor (_ccg .BorderColor );
|
|
};_dad .Add_w (_ccg .BorderSize ).Add_re (_ebcg [0],_ebcg [1],_acfe ,_dcgd );if _ccg .FillColor !=nil &&_ccg .BorderColor !=nil {_dad .Add_B ();}else if _ccg .FillColor !=nil {_dad .Add_f ();}else if _ccg .BorderColor !=nil {_dad .Add_S ();};_dad .Add_Q ();
|
|
if _ccg .WatermarkImage !=nil {_bbbg :=[]float64 {_ebcg [0],_ebcg [1],_ebcg [2],_ebcg [3]};_gfdd ,_acfa ,_bgge :=_bece (_ccg .WatermarkImage ,"\u0049\u006d\u0061\u0067\u0065\u0057\u0061\u0074\u0065r\u006d\u0061\u0072\u006b",_ccg ,_bbbg ,_dad );if _bgge !=nil {return nil ,_bgge ;
|
|
};_eedb .SetXObjectImageByName (*_gfdd ,_acfa );};_dad .Add_q ();_dad .Translate (_fgaa [0],_fgaa [3]-_ageb -_cbda );_dad .Add_BT ();_fed :=_afc .Encoder ();for _ ,_eggg :=range _abbb {var _bfec []byte ;for _ ,_ebcc :=range _eggg {if _c .IsSpace (_ebcc ){if len (_bfec )> 0{_dad .SetNonStrokingColor (_ccg .TextColor ).Add_Tf (*_baba ,_dbf ).Add_TL (_ageb ).Add_TJ ([]_ba .PdfObject {_ba .MakeStringFromBytes (_bfec )}...);
|
|
_bfec =nil ;};_dad .Add_Tf (*_baba ,_dbf ).Add_TL (_ageb ).Add_TJ ([]_ba .PdfObject {_ba .MakeFloat (-_caac )}...);}else {_bfec =append (_bfec ,_fed .Encode (string (_ebcc ))...);};};if len (_bfec )> 0{_dad .SetNonStrokingColor (_ccg .TextColor ).Add_Tf (*_baba ,_dbf ).Add_TL (_ageb ).Add_TJ ([]_ba .PdfObject {_ba .MakeStringFromBytes (_bfec )}...);
|
|
};_dad .Add_Td (0,-_ageb );};_dad .Add_ET ();_dad .Add_Q ();if _efbd {_cdfe ,_afea ,_bced :=_bece (_ccg .Image ,"\u0049\u006d\u0061\u0067\u0065\u0053\u0069\u0067\u006ea\u0074\u0075\u0072\u0065",_ccg ,_fdgg ,_dad );if _bced !=nil {return nil ,_bced ;};_eedb .SetXObjectImageByName (*_cdfe ,_afea );
|
|
};_gaaea :=_cgd .NewXObjectForm ();_gaaea .Resources =_eedb ;_gaaea .BBox =_ba .MakeArrayFromFloats (_ebcg );_gaaea .SetContentStream (_dad .Bytes (),_feaa ());_efce :=_ba .MakeDict ();_efce .Set ("\u004e",_gaaea .ToPdfObject ());return _efce ,nil ;};
|
|
|
|
// CreateRectangleAnnotation creates a rectangle annotation object that can be added to page PDF annotations.
|
|
func CreateRectangleAnnotation (rectDef RectangleAnnotationDef )(*_cgd .PdfAnnotation ,error ){_bgc :=_cgd .NewPdfAnnotationSquare ();if rectDef .BorderEnabled {_cegbc ,_daag ,_acdb :=rectDef .BorderColor .R (),rectDef .BorderColor .G (),rectDef .BorderColor .B ();
|
|
_bgc .C =_ba .MakeArrayFromFloats ([]float64 {_cegbc ,_daag ,_acdb });_cege :=_cgd .NewBorderStyle ();_cege .SetBorderWidth (rectDef .BorderWidth );_bgc .BS =_cege .ToPdfObject ();};if rectDef .FillEnabled {_bdc ,_ecf ,_cgeg :=rectDef .FillColor .R (),rectDef .FillColor .G (),rectDef .FillColor .B ();
|
|
_bgc .IC =_ba .MakeArrayFromFloats ([]float64 {_bdc ,_ecf ,_cgeg });}else {_bgc .IC =_ba .MakeArrayFromIntegers ([]int {});};if rectDef .Opacity < 1.0{_bgc .CA =_ba .MakeFloat (rectDef .Opacity );};_bfcc ,_dggd ,_fffca :=_ebdg (rectDef );if _fffca !=nil {return nil ,_fffca ;
|
|
};_bgc .AP =_bfcc ;_bgc .Rect =_ba .MakeArrayFromFloats ([]float64 {_dggd .Llx ,_dggd .Lly ,_dggd .Urx ,_dggd .Ury });return _bgc .PdfAnnotation ,nil ;};func _gfgc (_ffadb LineAnnotationDef )(*_ba .PdfObjectDictionary ,*_cgd .PdfRectangle ,error ){_adad :=_cgd .NewXObjectForm ();
|
|
_adad .Resources =_cgd .NewPdfPageResources ();_fgg :="";if _ffadb .Opacity < 1.0{_bdac :=_ba .MakeDict ();_bdac .Set ("\u0063\u0061",_ba .MakeFloat (_ffadb .Opacity ));_gacd :=_adad .Resources .AddExtGState ("\u0067\u0073\u0031",_bdac );if _gacd !=nil {_bd .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 ,_gacd ;};_fgg ="\u0067\u0073\u0031";};_gbbc ,_edbd ,_fggc ,_dfb :=_adgb (_ffadb ,_fgg );if _dfb !=nil {return nil ,nil ,_dfb ;};_dfb =_adad .SetContentStream (_gbbc ,nil );if _dfb !=nil {return nil ,nil ,_dfb ;};_adad .BBox =_edbd .ToPdfObject ();
|
|
_aegce :=_ba .MakeDict ();_aegce .Set ("\u004e",_adad .ToPdfObject ());return _aegce ,_fggc ,nil ;};func _ccb (_fgdc *_cgd .PdfField )string {if _fgdc ==nil {return "";};_ggd ,_caff :=_fgdc .GetContext ().(*_cgd .PdfFieldText );if !_caff {return _ccb (_fgdc .Parent );
|
|
};if _ggd .DA !=nil {return _ggd .DA .Str ();};return _ccb (_ggd .Parent );};func (_eacg *AppearanceStyle )applyRotation (_bbbf *_ba .PdfObjectDictionary ,_gcfb ,_ffa float64 ,_ccec *_d .ContentCreator )(float64 ,float64 ){if !_eacg .AllowMK {return _gcfb ,_ffa ;
|
|
};if _bbbf ==nil {return _gcfb ,_ffa ;};_fcdg ,_ :=_ba .GetNumberAsFloat (_bbbf .Get ("\u0052"));if _fcdg ==0{return _gcfb ,_ffa ;};_afee :=-_fcdg ;_bcda :=_ed .Path {Points :[]_ed .Point {_ed .NewPoint (0,0).Rotate (_afee ),_ed .NewPoint (_gcfb ,0).Rotate (_afee ),_ed .NewPoint (0,_ffa ).Rotate (_afee ),_ed .NewPoint (_gcfb ,_ffa ).Rotate (_afee )}}.GetBoundingBox ();
|
|
_ccec .RotateDeg (_fcdg );_ccec .Translate (_bcda .X ,_bcda .Y );return _bcda .Width ,_bcda .Height ;};func _acf (_fgde *_cgd .PdfAcroForm ,_aab *_cgd .PdfAnnotationWidget ,_cebg *_cgd .PdfFieldChoice ,_cbd AppearanceStyle )(*_ba .PdfObjectDictionary ,error ){_beec ,_afd :=_ba .GetArray (_aab .Rect );
|
|
if !_afd {return nil ,_bda .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_dfc ,_bcd :=_cgd .NewPdfRectangle (*_beec );if _bcd !=nil {return nil ,_bcd ;};_bbdg ,_bed :=_dfc .Width (),_dfc .Height ();_bd .Log .Debug ("\u0043\u0068\u006f\u0069\u0063\u0065\u002c\u0020\u0077\u0061\u0020\u0042S\u003a\u0020\u0025\u0076",_aab .BS );
|
|
_eac ,_bcd :=_d .NewContentStreamParser (_ccb (_cebg .PdfField )).Parse ();if _bcd !=nil {return nil ,_bcd ;};_aba ,_gfd :=_ba .GetDict (_aab .MK );if _gfd {_gabd ,_ :=_ba .GetDict (_aab .BS );_cggf :=_cbd .applyAppearanceCharacteristics (_aba ,_gabd ,nil );
|
|
if _cggf !=nil {return nil ,_cggf ;};};_dcgb :=_ba .MakeDict ();for _ ,_bfa :=range _cebg .Opt .Elements (){if _cdde ,_cbdf :=_ba .GetArray (_bfa );_cbdf &&_cdde .Len ()==2{_bfa =_cdde .Get (1);};var _cbeg string ;if _ebdc ,_bec :=_ba .GetString (_bfa );
|
|
_bec {_cbeg =_ebdc .Decoded ();}else if _bff ,_afda :=_ba .GetName (_bfa );_afda {_cbeg =_bff .String ();}else {_bd .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",_bfa );
|
|
return nil ,_bda .New ("\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u002f\u0073t\u0072\u0069\u006e\u0067");};if len (_cbeg )> 0{_dgg ,_ded :=_aagc (_cebg .PdfField ,_bbdg ,_bed ,_cbeg ,_cbd ,_eac ,_fgde .DR ,_aba );if _ded !=nil {return nil ,_ded ;
|
|
};_dcgb .Set (*_ba .MakeName (_cbeg ),_dgg .ToPdfObject ());};};_babd :=_ba .MakeDict ();_babd .Set ("\u004e",_dcgb );return _babd ,nil ;};
|
|
|
|
// FieldAppearance implements interface model.FieldAppearanceGenerator and generates appearance streams
|
|
// for fields taking into account what value is in the field. A common use case is for generating the
|
|
// appearance stream prior to flattening fields.
|
|
//
|
|
// If `OnlyIfMissing` is true, the field appearance is generated only for fields that do not have an
|
|
// appearance stream specified.
|
|
// If `RegenerateTextFields` is true, all text fields are regenerated (even if OnlyIfMissing is true).
|
|
type FieldAppearance struct{OnlyIfMissing bool ;RegenerateTextFields bool ;_ccf *AppearanceStyle ;};func _feaa ()_ba .StreamEncoder {return _ba .NewFlateEncoder ()};
|
|
|
|
// SetStyle applies appearance `style` to `fa`.
|
|
func (_fc *FieldAppearance )SetStyle (style AppearanceStyle ){_fc ._ccf =&style };
|
|
|
|
// NewSignatureFieldOpts returns a new initialized instance of options
|
|
// used to generate a signature appearance.
|
|
func NewSignatureFieldOpts ()*SignatureFieldOpts {return &SignatureFieldOpts {Font :_cgd .DefaultFont (),FontSize :10,LineHeight :1,AutoSize :true ,TextColor :_cgd .NewPdfColorDeviceGray (0),BorderColor :_cgd .NewPdfColorDeviceGray (0),FillColor :_cgd .NewPdfColorDeviceGray (1),Encoder :_ba .NewFlateEncoder (),ImagePosition :SignatureImageLeft };
|
|
};func _ebdg (_aeaf RectangleAnnotationDef )(*_ba .PdfObjectDictionary ,*_cgd .PdfRectangle ,error ){_gbdf :=_cgd .NewXObjectForm ();_gbdf .Resources =_cgd .NewPdfPageResources ();_gfda :="";if _aeaf .Opacity < 1.0{_gaf :=_ba .MakeDict ();_gaf .Set ("\u0063\u0061",_ba .MakeFloat (_aeaf .Opacity ));
|
|
_gaf .Set ("\u0043\u0041",_ba .MakeFloat (_aeaf .Opacity ));_dff :=_gbdf .Resources .AddExtGState ("\u0067\u0073\u0031",_gaf );if _dff !=nil {_bd .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 ,_dff ;};_gfda ="\u0067\u0073\u0031";};_gdfd ,_addf ,_dege ,_dgge :=_egedg (_aeaf ,_gfda );if _dgge !=nil {return nil ,nil ,_dgge ;};_dgge =_gbdf .SetContentStream (_gdfd ,nil );if _dgge !=nil {return nil ,nil ,_dgge ;};_gbdf .BBox =_addf .ToPdfObject ();
|
|
_cfeaf :=_ba .MakeDict ();_cfeaf .Set ("\u004e",_gbdf .ToPdfObject ());return _cfeaf ,_dege ,nil ;}; |