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.
|
2022-09-10 15:35:04 +00:00
|
|
|
package annotator ;import (_b "bytes";_bf "errors";_g "github.com/unidoc/unipdf/v3/common";_c "github.com/unidoc/unipdf/v3/contentstream";_gab "github.com/unidoc/unipdf/v3/contentstream/draw";_de "github.com/unidoc/unipdf/v3/core";_a "github.com/unidoc/unipdf/v3/internal/textencoding";
|
|
|
|
_eb "github.com/unidoc/unipdf/v3/model";_gad "image";_d "math";_ga "strings";_bg "unicode";);func _fea (_efcg *_eb .PdfAcroForm ,_fcf *_eb .PdfAnnotationWidget ,_bgab *_eb .PdfFieldChoice ,_adca AppearanceStyle )(*_de .PdfObjectDictionary ,error ){_bgg ,_fdg :=_de .GetArray (_fcf .Rect );
|
|
|
|
if !_fdg {return nil ,_bf .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_gaa ,_ffa :=_eb .NewPdfRectangle (*_bgg );if _ffa !=nil {return nil ,_ffa ;};_bacgf ,_ddb :=_gaa .Width (),_gaa .Height ();_g .Log .Debug ("\u0043\u0068\u006f\u0069\u0063\u0065\u002c\u0020\u0077\u0061\u0020\u0042S\u003a\u0020\u0025\u0076",_fcf .BS );
|
|
|
|
_ceda ,_ffa :=_c .NewContentStreamParser (_dbe (_bgab .PdfField )).Parse ();if _ffa !=nil {return nil ,_ffa ;};_cedg ,_dbbb :=_de .GetDict (_fcf .MK );if _dbbb {_gadag ,_ :=_de .GetDict (_fcf .BS );_dgd :=_adca .applyAppearanceCharacteristics (_cedg ,_gadag ,nil );
|
|
|
|
if _dgd !=nil {return nil ,_dgd ;};};_dba :=_de .MakeDict ();for _ ,_eegf :=range _bgab .Opt .Elements (){if _bgd ,_fbb :=_de .GetArray (_eegf );_fbb &&_bgd .Len ()==2{_eegf =_bgd .Get (1);};var _caad string ;if _aagba ,_fdbf :=_de .GetString (_eegf );
|
|
|
|
_fdbf {_caad =_aagba .Decoded ();}else if _dec ,_fcfa :=_de .GetName (_eegf );_fcfa {_caad =_dec .String ();}else {_g .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a \u004f\u0070\u0074\u0020\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006de\u002f\u0073\u0074\u0072\u0069\u006e\u0067 \u002d\u0020\u0025\u0054",_eegf );
|
|
|
|
return nil ,_bf .New ("\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u002f\u0073t\u0072\u0069\u006e\u0067");};if len (_caad )> 0{_accf ,_ffd :=_bee (_bgab .PdfField ,_bacgf ,_ddb ,_caad ,_adca ,_ceda ,_efcg .DR ,_cedg );if _ffd !=nil {return nil ,_ffd ;
|
|
|
|
};_dba .Set (*_de .MakeName (_caad ),_accf .ToPdfObject ());};};_bge :=_de .MakeDict ();_bge .Set ("\u004e",_dba );return _bge ,nil ;};
|
2022-06-27 19:58:38 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// AppearanceFont represents a font used for generating the appearance of a
|
|
|
|
// field in the filling/flattening process.
|
|
|
|
type AppearanceFont struct{
|
2022-07-13 21:28:43 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// Name represents the name of the font which will be added to the
|
|
|
|
// AcroForm resources (DR).
|
|
|
|
Name string ;
|
2022-07-13 21:28:43 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// Font represents the actual font used for the field appearance.
|
|
|
|
Font *_eb .PdfFont ;
|
2021-08-13 01:33:42 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// Size represents the size of the font used for the field appearance.
|
|
|
|
// If the font size is 0, the value of the FallbackSize field of the
|
|
|
|
// AppearanceFontStyle is used, if set. Otherwise, the font size is
|
|
|
|
// calculated based on the available annotation height and on the
|
|
|
|
// AutoFontSizeFraction field of the AppearanceStyle.
|
|
|
|
Size float64 ;};func (_bcde *AppearanceStyle )processDA (_bggg *_eb .PdfField ,_abc *_c .ContentStreamOperations ,_cbg ,_cgc *_eb .PdfPageResources ,_ecgc *_c .ContentCreator )(*AppearanceFont ,bool ,error ){var _fbga *AppearanceFont ;var _bfb bool ;if _bcde .Fonts !=nil {if _bcde .Fonts .Fallback !=nil {_fbga =_bcde .Fonts .Fallback ;
|
|
|
|
};if _abd :=_bcde .Fonts .FieldFallbacks ;_abd !=nil {if _agcg ,_bcb :=_abd [_bggg .PartialName ()];_bcb {_fbga =_agcg ;}else if _eagc ,_ddae :=_bggg .FullName ();_ddae ==nil {if _bfcd ,_bafa :=_abd [_eagc ];_bafa {_fbga =_bfcd ;};};};_bfb =_bcde .Fonts .ForceReplace ;
|
|
|
|
};var _bdb string ;var _cagf float64 ;var _fcdf bool ;if _abc !=nil {for _ ,_dcdf :=range *_abc {if _dcdf .Operand =="\u0054\u0066"&&len (_dcdf .Params )==2{if _gbd ,_ffc :=_de .GetNameVal (_dcdf .Params [0]);_ffc {_bdb =_gbd ;};if _edgf ,_fca :=_de .GetNumberAsFloat (_dcdf .Params [1]);
|
|
|
|
_fca ==nil {_cagf =_edgf ;};_fcdf =true ;continue ;};_ecgc .AddOperand (*_dcdf );};};var _cdf *AppearanceFont ;var _cgd _de .PdfObject ;if _bfb &&_fbga !=nil {_cdf =_fbga ;}else {if _cbg !=nil &&_bdb !=""{if _fcc ,_dega :=_cbg .GetFontByName (*_de .MakeName (_bdb ));
|
|
|
|
_dega {if _fgd ,_gae :=_eb .NewPdfFontFromPdfObject (_fcc );_gae ==nil {_cgd =_fcc ;_cdf =&AppearanceFont {Name :_bdb ,Font :_fgd ,Size :_cagf };}else {_g .Log .Debug ("\u0045\u0052\u0052\u004f\u0052:\u0020\u0063\u006f\u0075\u006c\u0064\u0020\u006e\u006f\u0074\u0020\u006c\u006fa\u0064\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0061\u006e\u0063\u0065\u0020\u0066\u006f\u006e\u0074\u003a\u0020\u0025\u0076",_gae );
|
|
|
|
};};};if _cdf ==nil &&_fbga !=nil {_cdf =_fbga ;};if _cdf ==nil {_dag ,_acgd :=_eb .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");if _acgd !=nil {return nil ,false ,_acgd ;};_cdf =&AppearanceFont {Name :"\u0048\u0065\u006c\u0076",Font :_dag ,Size :_cagf };
|
|
|
|
};};if _cdf .Size <=0&&_bcde .Fonts !=nil &&_bcde .Fonts .FallbackSize > 0{_cdf .Size =_bcde .Fonts .FallbackSize ;};_afda :=*_de .MakeName (_cdf .Name );if _cgd ==nil {_cgd =_cdf .Font .ToPdfObject ();};if _cbg !=nil &&!_cbg .HasFontByName (_afda ){_cbg .SetFontByName (_afda ,_cgd );
|
|
|
|
};if _cgc !=nil &&!_cgc .HasFontByName (_afda ){_cgc .SetFontByName (_afda ,_cgd );};return _cdf ,_fcdf ,nil ;};
|
2021-08-13 01:33:42 +00:00
|
|
|
|
2022-09-10 15:35:04 +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 };};
|
2022-07-13 21:28:43 +00:00
|
|
|
|
|
|
|
// 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).
|
2022-09-10 15:35:04 +00:00
|
|
|
CheckmarkRune rune ;BorderSize float64 ;BorderColor _eb .PdfColor ;FillColor _eb .PdfColor ;
|
2022-07-13 21:28:43 +00:00
|
|
|
|
|
|
|
// 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).
|
2022-09-10 15:35:04 +00:00
|
|
|
MarginLeft *float64 ;};
|
2022-07-13 21:28:43 +00:00
|
|
|
|
2022-09-10 15:35:04 +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 *_eb .PdfSignature ,lines []*SignatureLine ,opts *SignatureFieldOpts )(*_eb .PdfFieldSignature ,error ){if signature ==nil {return nil ,_bf .New ("\u0073\u0069\u0067na\u0074\u0075\u0072\u0065\u0020\u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u006e\u0069\u006c");
|
|
|
|
};_bbb ,_fafe :=_cbe (lines ,opts );if _fafe !=nil {return nil ,_fafe ;};_daf :=_eb .NewPdfFieldSignature (signature );_daf .Rect =_de .MakeArrayFromFloats (opts .Rect );_daf .AP =_bbb ;return _daf ,nil ;};
|
2021-08-13 01:33:42 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// NewSignatureFieldOpts returns a new initialized instance of options
|
|
|
|
// used to generate a signature appearance.
|
|
|
|
func NewSignatureFieldOpts ()*SignatureFieldOpts {return &SignatureFieldOpts {Font :_eb .DefaultFont (),FontSize :10,LineHeight :1,AutoSize :true ,TextColor :_eb .NewPdfColorDeviceGray (0),BorderColor :_eb .NewPdfColorDeviceGray (0),FillColor :_eb .NewPdfColorDeviceGray (1),Encoder :_de .NewFlateEncoder (),ImagePosition :SignatureImageLeft };
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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 (_bcgb FieldAppearance )WrapContentStream (page *_eb .PdfPage )error {_bfgf ,_ead :=page .GetAllContentStreams ();if _ead !=nil {return _ead ;};_ddd :=_c .NewContentStreamParser (_bfgf );_aecg ,_ead :=_ddd .Parse ();if _ead !=nil {return _ead ;};_aecg .WrapIfNeeded ();
|
|
|
|
_egf :=[]string {_aecg .String ()};return page .SetContentStreams (_egf ,_gaad ());};func _bfbf (_ggbe *_eb .PdfFieldButton ,_cff *_eb .PdfAnnotationWidget ,_bcag AppearanceStyle )(*_de .PdfObjectDictionary ,error ){_efg ,_afdgc :=_de .GetArray (_cff .Rect );
|
|
|
|
if !_afdgc {return nil ,_bf .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_ebeg ,_cdag :=_eb .NewPdfRectangle (*_efg );if _cdag !=nil {return nil ,_cdag ;};_agbe ,_dacef :=_ebeg .Width (),_ebeg .Height ();_aecd :=_c .NewContentCreator ();
|
|
|
|
if _bcag .BorderSize > 0{_degcac (_aecd ,_bcag ,_agbe ,_dacef );};if _bcag .DrawAlignmentReticle {_cgf :=_bcag ;_cgf .BorderSize =0.2;_feaa (_aecd ,_cgf ,_agbe ,_dacef );};_cbdbd :=_ggbe .GetFillImage ();_eda ,_cdag :=_fcdff (_agbe ,_dacef ,_cbdbd ,_bcag );
|
|
|
|
if _cdag !=nil {return nil ,_cdag ;};_gfdb ,_ffaf :=_de .GetDict (_cff .MK );if _ffaf {_gfdb .Set ("\u006c",_eda .ToPdfObject ());};_eba :=_de .MakeDict ();_eba .Set ("\u0046\u0052\u004d",_eda .ToPdfObject ());_faag :=_eb .NewPdfPageResources ();_faag .ProcSet =_de .MakeArray (_de .MakeName ("\u0050\u0044\u0046"));
|
|
|
|
_faag .XObject =_eba ;_debb :=_agbe -2;_addd :=_dacef -2;_aecd .Add_q ();_aecd .Add_re (1,1,_debb ,_addd );_aecd .Add_W ();_aecd .Add_n ();_debb -=2;_addd -=2;_aecd .Add_q ();_aecd .Add_re (2,2,_debb ,_addd );_aecd .Add_W ();_aecd .Add_n ();_bcgc :=_d .Min (_debb /float64 (_cbdbd .Width ),_addd /float64 (_cbdbd .Height ));
|
|
|
|
_aecd .Add_cm (_bcgc ,0,0,_bcgc ,(_agbe /2)-(float64 (_cbdbd .Width )*_bcgc /2)+2,2);_aecd .Add_Do ("\u0046\u0052\u004d");_aecd .Add_Q ();_aecd .Add_Q ();_ecgf :=_eb .NewXObjectForm ();_ecgf .FormType =_de .MakeInteger (1);_ecgf .Resources =_faag ;_ecgf .BBox =_de .MakeArrayFromFloats ([]float64 {0,0,_agbe ,_dacef });
|
|
|
|
_ecgf .Matrix =_de .MakeArrayFromFloats ([]float64 {1.0,0.0,0.0,1.0,0.0,0.0});_ecgf .SetContentStream (_aecd .Bytes (),_gaad ());_ffea :=_de .MakeDict ();_ffea .Set ("\u004e",_ecgf .ToPdfObject ());return _ffea ,nil ;};func _cda (_cfa *_eb .PdfAnnotationWidget ,_cfd *_eb .PdfFieldText ,_afe *_eb .PdfPageResources ,_bd AppearanceStyle )(*_de .PdfObjectDictionary ,error ){_ecg :=_eb .NewPdfPageResources ();
|
|
|
|
_ca ,_aae :=_de .GetArray (_cfa .Rect );if !_aae {return nil ,_bf .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_ef ,_bcf :=_eb .NewPdfRectangle (*_ca );if _bcf !=nil {return nil ,_bcf ;};_bef ,_bgf :=_ef .Width (),_ef .Height ();
|
|
|
|
_gd ,_bce :=_bef ,_bgf ;_fc ,_afa :=_de .GetDict (_cfa .MK );if _afa {_acc ,_ :=_de .GetDict (_cfa .BS );_ebc :=_bd .applyAppearanceCharacteristics (_fc ,_acc ,nil );if _ebc !=nil {return nil ,_ebc ;};};_acg ,_bcf :=_c .NewContentStreamParser (_dbe (_cfd .PdfField )).Parse ();
|
|
|
|
if _bcf !=nil {return nil ,_bcf ;};_aad :=_c .NewContentCreator ();if _bd .BorderSize > 0{_degcac (_aad ,_bd ,_bef ,_bgf );};if _bd .DrawAlignmentReticle {_cce :=_bd ;_cce .BorderSize =0.2;_feaa (_aad ,_cce ,_bef ,_bgf );};_aad .Add_BMC ("\u0054\u0078");
|
|
|
|
_aad .Add_q ();_bef ,_bgf =_bd .applyRotation (_fc ,_bef ,_bgf ,_aad );_aad .Add_BT ();_eg ,_fac ,_bcf :=_bd .processDA (_cfd .PdfField ,_acg ,_afe ,_ecg ,_aad );if _bcf !=nil {return nil ,_bcf ;};_df :=_eg .Font ;_bfd :=_eg .Size ;_add :=_de .MakeName (_eg .Name );
|
|
|
|
_baf :=_bfd ==0;if _baf &&_fac {_bfd =_bgf *_bd .AutoFontSizeFraction ;};_cdb :=_df .Encoder ();if _cdb ==nil {_g .Log .Debug ("\u0057\u0041RN\u003a\u0020\u0066\u006f\u006e\u0074\u0020\u0065\u006e\u0063\u006f\u0064\u0065\u0072\u0020\u0069\u0073\u0020\u006e\u0069l\u002e\u0020\u0041\u0073s\u0075\u006d\u0069\u006eg \u0069\u0064e\u006et\u0069\u0074\u0079\u0020\u0065\u006ec\u006f\u0064\u0065r\u002e\u0020O\u0075\u0074\u0070\u0075\u0074\u0020\u006d\u0061\u0079\u0020\u0062\u0065\u0020\u0069n\u0063\u006f\u0072\u0072\u0065\u0063\u0074\u002e");
|
|
|
|
_cdb =_a .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};_eed ,_bcf :=_df .GetFontDescriptor ();if _bcf !=nil {_g .Log .Debug ("\u0045\u0072ro\u0072\u003a\u0020U\u006e\u0061\u0062\u006ce t\u006f g\u0065\u0074\u0020\u0066\u006f\u006e\u0074 d\u0065\u0073\u0063\u0072\u0069\u0070\u0074o\u0072");
|
|
|
|
};var _degc string ;if _abb ,_ceef :=_de .GetString (_cfd .V );_ceef {_degc =_abb .Decoded ();};if len (_degc )==0{return nil ,nil ;};_efc :=[]string {_degc };_dbb :=false ;if _cfd .Flags ().Has (_eb .FieldFlagMultiline ){_dbb =true ;_degc =_ga .Replace (_degc ,"\u000d\u000a","\u000a",-1);
|
|
|
|
_degc =_ga .Replace (_degc ,"\u000d","\u000a",-1);_efc =_ga .Split (_degc ,"\u000a");};_ea :=make ([]string ,len (_efc ));copy (_ea ,_efc );_agcf :=_bd .MultilineLineHeight ;_faa :=0.0;_fce :=0;if _cdb !=nil {for _bfd >=0{_aada :=make ([]string ,len (_efc ));
|
|
|
|
copy (_aada ,_efc );_aea :=make ([]string ,len (_ea ));copy (_aea ,_ea );_faa =0.0;_fce =0;_fdd :=len (_aada );_ebe :=0;for _ebe < _fdd {var _gag float64 ;_ada :=-1;_degb :=_bae ;if _bd .MarginLeft !=nil {_degb =*_bd .MarginLeft ;};for _deb ,_gfg :=range _aada [_ebe ]{if _gfg ==' '{_ada =_deb ;
|
|
|
|
_gag =_degb ;};_ff ,_acf :=_df .GetRuneMetrics (_gfg );if !_acf {_g .Log .Debug ("\u0046\u006f\u006e\u0074\u0020\u0064o\u0065\u0073\u0020\u006e\u006f\u0074\u0020\u0068\u0061\u0076\u0065\u0020\u0072\u0075\u006e\u0065\u0020\u006d\u0065\u0074r\u0069\u0063\u0073\u0020\u0066\u006f\u0072\u0020\u0025\u0076\u0020\u002d\u0020\u0073k\u0069p\u0070\u0069\u006e\u0067",_gfg );
|
|
|
|
continue ;};_degb +=_ff .Wx ;if _dbb &&!_baf &&_bfd *_degb /1000.0> _bef &&_ada > 0{_cbda :=_aada [_ebe ][_ada +1:];_gbb :=_aea [_ebe ][_ada +1:];if _ebe < len (_aada )-1{_aada =append (_aada [:_ebe +1],_aada [_ebe :]...);_aada [_ebe +1]=_cbda ;_aea =append (_aea [:_ebe +1],_aea [_ebe :]...);
|
|
|
|
_aea [_ebe +1]=_gbb ;}else {_aada =append (_aada ,_cbda );_aea =append (_aea ,_gbb );};_fdd ++;_aada [_ebe ]=_aada [_ebe ][0:_ada ];_aea [_ebe ]=_aea [_ebe ][0:_ada ];_degb =_gag ;break ;};};if _degb > _faa {_faa =_degb ;};_aada [_ebe ]=string (_cdb .Encode (_aada [_ebe ]));
|
|
|
|
if len (_aada [_ebe ])> 0{_fce ++;};_ebe ++;};_gadf :=_bfd ;if _fce > 1{_gadf *=_agcf ;};_ggb :=float64 (_fce )*_gadf ;if _baf ||_ggb <=_bgf {_efc =_aada ;_ea =_aea ;break ;};_bfd --;};};_cca :=_bae ;if _bd .MarginLeft !=nil {_cca =*_bd .MarginLeft ;};
|
|
|
|
if _bfd ==0||_baf &&_faa > 0&&_cca +_faa *_bfd /1000.0> _bef {_bfd =0.95*1000.0*(_bef -_cca )/_faa ;};_eab :=_cf ;{if _fdb ,_dd :=_de .GetIntVal (_cfd .Q );_dd {switch _fdb {case 0:_eab =_cf ;case 1:_eab =_cbdb ;case 2:_eab =_ba ;default:_g .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0055\u006e\u0073\u0075\u0070\u0070\u006f\u0072t\u0065\u0064\u0020\u0071\u0075\u0061\u0064\u0064\u0069\u006e\u0067\u003a\u0020%\u0064\u0020\u002d\u0020\u0075\u0073\u0069\u006e\u0067\u0020\u006c\u0065ft\u0020\u0061\u006c\u0069\u0067\u006e\u006d\u0065\u006e\u0074",_fdb );
|
|
|
|
};};};_ede :=_bfd ;if _dbb &&_fce > 1{_ede =_agcf *_bfd ;};var _accb float64 ;if _eed !=nil {_accb ,_bcf =_eed .GetCapHeight ();if _bcf !=nil {_g .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0055\u006e\u0061\u0062\u006c\u0065 \u0074\u006f\u0020\u0067\u0065\u0074 \u0066\u006f\u006e\u0074\u0020\u0043\u0061\u0070\u0048\u0065\u0069\u0067\u0068t\u003a\u0020\u0025\u0076",_bcf );
|
|
|
|
};};if int (_accb )<=0{_g .Log .Debug ("W\u0041\u0052\u004e\u003a\u0020\u0043\u0061\u0070\u0048e\u0069\u0067\u0068\u0074\u0020\u006e\u006ft \u0061\u0076\u0061\u0069l\u0061\u0062\u006c\u0065\u0020\u002d\u0020\u0073\u0065tt\u0069\u006eg\u0020\u0074\u006f\u0020\u0031\u0030\u0030\u0030");
|
|
|
|
_accb =1000;};_gcd :=_accb /1000.0*_bfd ;_dcg :=0.0;{_aag :=float64 (_fce )*_ede ;if _baf &&_dcg +_aag > _bgf {_bfd =0.95*(_bgf -_dcg )/float64 (_fce );_ede =_bfd ;if _dbb &&_fce > 1{_ede =_agcf *_bfd ;};_gcd =_accb /1000.0*_bfd ;_aag =float64 (_fce )*_ede ;
|
|
|
|
};if _bgf > _aag {if _dbb {if _bd .MultilineVAlignMiddle {_ge :=(_bgf -(_aag +_gcd ))/2.0;_gdd :=_ge +_aag +_gcd -_ede ;_dcg =_gdd ;if _fce > 1{_dcg =_dcg +(_aag /_bfd *float64 (_fce ))-_ede -_gcd ;};if _dcg < _aag {_dcg =(_bgf -_gcd )/2.0;};}else {_dcg =_bgf -_ede ;
|
|
|
|
if _dcg > _bfd {_dcg -=_bfd *0.5;};};}else {_dcg =(_bgf -_gcd )/2.0;};};};_aad .Add_Tf (*_add ,_bfd );_aad .Add_Td (_cca ,_dcg );_eeg :=_cca ;_gfc :=_cca ;for _eee ,_cbdd :=range _efc {_bbe :=0.0;for _ ,_bad :=range _ea [_eee ]{_ebb ,_dde :=_df .GetRuneMetrics (_bad );
|
|
|
|
if !_dde {continue ;};_bbe +=_ebb .Wx ;};_ddf :=_bbe /1000.0*_bfd ;_acd :=_bef -_ddf ;var _fad float64 ;switch _eab {case _cf :_fad =_eeg ;case _cbdb :_fad =_acd /2;case _ba :_fad =_acd ;};_cca =_fad -_gfc ;if _cca > 0.0{_aad .Add_Td (_cca ,0);};_gfc =_fad ;
|
|
|
|
_aad .Add_Tj (*_de .MakeString (_cbdd ));if _eee < len (_efc )-1{_aad .Add_Td (0,-_bfd *_agcf );};};_aad .Add_ET ();_aad .Add_Q ();_aad .Add_EMC ();_ccg :=_eb .NewXObjectForm ();_ccg .Resources =_ecg ;_ccg .BBox =_de .MakeArrayFromFloats ([]float64 {0,0,_gd ,_bce });
|
|
|
|
_ccg .SetContentStream (_aad .Bytes (),_gaad ());_aga :=_de .MakeDict ();_aga .Set ("\u004e",_ccg .ToPdfObject ());return _aga ,nil ;};
|
2021-10-22 10:53:20 +00:00
|
|
|
|
2022-07-13 21:28:43 +00:00
|
|
|
// Style returns the appearance style of `fa`. If not specified, returns default style.
|
2022-09-10 15:35:04 +00:00
|
|
|
func (_fg FieldAppearance )Style ()AppearanceStyle {if _fg ._deea !=nil {return *_fg ._deea ;};_ggd :=_bae ;return AppearanceStyle {AutoFontSizeFraction :0.65,CheckmarkRune :'✔',BorderSize :0.0,BorderColor :_eb .NewPdfColorDeviceGray (0),FillColor :_eb .NewPdfColorDeviceGray (1),MultilineLineHeight :1.2,MultilineVAlignMiddle :false ,DrawAlignmentReticle :false ,AllowMK :true ,MarginLeft :&_ggd };
|
2022-07-13 21:28:43 +00:00
|
|
|
};
|
2021-10-22 10:53:20 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// SignatureFieldOpts represents a set of options used to configure
|
|
|
|
// an appearance widget dictionary.
|
|
|
|
type SignatureFieldOpts struct{
|
2022-07-13 21:28:43 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// Rect represents the area the signature annotation is displayed on.
|
|
|
|
Rect []float64 ;
|
2022-07-13 21:28:43 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// AutoSize specifies if the content of the appearance should be
|
|
|
|
// scaled to fit in the annotation rectangle.
|
|
|
|
AutoSize bool ;
|
2021-10-22 10:53:20 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// Font specifies the font of the text content.
|
|
|
|
Font *_eb .PdfFont ;
|
2021-05-11 00:01:27 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// FontSize specifies the size of the text content.
|
|
|
|
FontSize float64 ;
|
2021-04-17 13:46:54 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// LineHeight specifies the height of a line of text in the appearance annotation.
|
|
|
|
LineHeight float64 ;
|
2021-03-13 21:28:23 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// TextColor represents the color of the text content displayed.
|
|
|
|
TextColor _eb .PdfColor ;
|
2021-09-23 22:37:42 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// FillColor represents the background color of the appearance annotation area.
|
|
|
|
FillColor _eb .PdfColor ;
|
|
|
|
|
|
|
|
// BorderSize represents border size of the appearance annotation area.
|
|
|
|
BorderSize float64 ;
|
|
|
|
|
|
|
|
// BorderColor represents the border color of the appearance annotation area.
|
|
|
|
BorderColor _eb .PdfColor ;
|
|
|
|
|
|
|
|
// WatermarkImage specifies the image used as a watermark that will be rendered
|
|
|
|
// behind the signature.
|
|
|
|
WatermarkImage _gad .Image ;
|
|
|
|
|
|
|
|
// Image represents the image used for the signature appearance.
|
|
|
|
Image _gad .Image ;
|
|
|
|
|
|
|
|
// Encoder specifies the image encoder used for image signature. Defaults to flate encoder.
|
|
|
|
Encoder _de .StreamEncoder ;
|
|
|
|
|
|
|
|
// ImagePosition specifies the image location relative to the text signature.
|
|
|
|
ImagePosition SignatureImagePosition ;};func _ccfg (_gada *_eb .PdfAnnotationWidget ,_cec *_eb .PdfFieldText ,_bac *_eb .PdfPageResources ,_eef AppearanceStyle )(*_de .PdfObjectDictionary ,error ){_bcg :=_eb .NewPdfPageResources ();_gcg ,_dcd :=_de .GetArray (_gada .Rect );
|
|
|
|
if !_dcd {return nil ,_bf .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_cab ,_ebd :=_eb .NewPdfRectangle (*_gcg );if _ebd !=nil {return nil ,_ebd ;};_fgg ,_caa :=_cab .Width (),_cab .Height ();_bcga ,_dfc :=_fgg ,_caa ;
|
|
|
|
_fag ,_eea :=_de .GetDict (_gada .MK );if _eea {_adg ,_ :=_de .GetDict (_gada .BS );_gga :=_eef .applyAppearanceCharacteristics (_fag ,_adg ,nil );if _gga !=nil {return nil ,_gga ;};};_cag ,_eea :=_de .GetIntVal (_cec .MaxLen );if !_eea {return nil ,_bf .New ("\u006d\u0061\u0078\u006c\u0065\u006e\u0020\u006e\u006ft\u0020\u0073\u0065\u0074");
|
|
|
|
};if _cag <=0{return nil ,_bf .New ("\u006d\u0061\u0078\u004c\u0065\u006e\u0020\u0069\u006ev\u0061\u006c\u0069\u0064");};_dcgb :=_fgg /float64 (_cag );_fbe ,_ebd :=_c .NewContentStreamParser (_dbe (_cec .PdfField )).Parse ();if _ebd !=nil {return nil ,_ebd ;
|
|
|
|
};_agbc :=_c .NewContentCreator ();if _eef .BorderSize > 0{_degcac (_agbc ,_eef ,_fgg ,_caa );};if _eef .DrawAlignmentReticle {_ebbb :=_eef ;_ebbb .BorderSize =0.2;_feaa (_agbc ,_ebbb ,_fgg ,_caa );};_agbc .Add_BMC ("\u0054\u0078");_agbc .Add_q ();_ ,_caa =_eef .applyRotation (_fag ,_fgg ,_caa ,_agbc );
|
|
|
|
_agbc .Add_BT ();_dgf ,_cg ,_ebd :=_eef .processDA (_cec .PdfField ,_fbe ,_bac ,_bcg ,_agbc );if _ebd !=nil {return nil ,_ebd ;};_cde :=_dgf .Font ;_bacg :=_de .MakeName (_dgf .Name );_eae :=_dgf .Size ;_egb :=_eae ==0;if _egb &&_cg {_eae =_caa *_eef .AutoFontSizeFraction ;
|
|
|
|
};_dfd :=_cde .Encoder ();if _dfd ==nil {_g .Log .Debug ("\u0057\u0041RN\u003a\u0020\u0066\u006f\u006e\u0074\u0020\u0065\u006e\u0063\u006f\u0064\u0065\u0072\u0020\u0069\u0073\u0020\u006e\u0069l\u002e\u0020\u0041\u0073s\u0075\u006d\u0069\u006eg \u0069\u0064e\u006et\u0069\u0074\u0079\u0020\u0065\u006ec\u006f\u0064\u0065r\u002e\u0020O\u0075\u0074\u0070\u0075\u0074\u0020\u006d\u0061\u0079\u0020\u0062\u0065\u0020\u0069n\u0063\u006f\u0072\u0072\u0065\u0063\u0074\u002e");
|
|
|
|
_dfd =_a .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};var _ebcf string ;if _aff ,_cfg :=_de .GetString (_cec .V );_cfg {_ebcf =_aff .Decoded ();};_agbc .Add_Tf (*_bacg ,_eae );var _cbf float64 ;for _ ,_ccfd :=range _ebcf {_gef ,_bag :=_cde .GetRuneMetrics (_ccfd );
|
|
|
|
if !_bag {_g .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a \u0052\u0075\u006e\u0065\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064\u0020\u0069\u006e\u0020\u0066\u006fn\u0074\u003a\u0020\u0025\u0076\u0020\u002d\u0020\u0073\u006b\u0069\u0070\u0070\u0069n\u0067 \u006f\u0076\u0065\u0072",_ccfd );
|
|
|
|
continue ;};_ggf :=_gef .Wy ;if int (_ggf )<=0{_ggf =_gef .Wx ;};if _ggf > _cbf {_cbf =_ggf ;};};if int (_cbf )==0{_g .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0055\u006e\u0061\u0062\u006c\u0065\u0020\u0074o\u0020\u0064\u0065\u0074\u0065\u0072\u006d\u0069\u006e\u0065\u0020\u006d\u0061x\u0020\u0067\u006c\u0079\u0070\u0068\u0020\u0073\u0069\u007a\u0065\u0020- \u0075\u0073\u0069\u006e\u0067\u0020\u0031\u0030\u0030\u0030");
|
|
|
|
_cbf =1000;};_aaga ,_ebd :=_cde .GetFontDescriptor ();if _ebd !=nil {_g .Log .Debug ("\u0045\u0072ro\u0072\u003a\u0020U\u006e\u0061\u0062\u006ce t\u006f g\u0065\u0074\u0020\u0066\u006f\u006e\u0074 d\u0065\u0073\u0063\u0072\u0069\u0070\u0074o\u0072");};
|
|
|
|
var _ccge float64 ;if _aaga !=nil {_ccge ,_ebd =_aaga .GetCapHeight ();if _ebd !=nil {_g .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0055\u006e\u0061\u0062\u006c\u0065 \u0074\u006f\u0020\u0067\u0065\u0074 \u0066\u006f\u006e\u0074\u0020\u0043\u0061\u0070\u0048\u0065\u0069\u0067\u0068t\u003a\u0020\u0025\u0076",_ebd );
|
|
|
|
};};if int (_ccge )<=0{_g .Log .Debug ("W\u0041\u0052\u004e\u003a\u0020\u0043\u0061\u0070\u0048e\u0069\u0067\u0068\u0074\u0020\u006e\u006ft \u0061\u0076\u0061\u0069l\u0061\u0062\u006c\u0065\u0020\u002d\u0020\u0073\u0065tt\u0069\u006eg\u0020\u0074\u006f\u0020\u0031\u0030\u0030\u0030");
|
|
|
|
_ccge =1000.0;};_dga :=_ccge /1000.0*_eae ;_cac :=0.0;_dge :=1.0*_eae *(_cbf /1000.0);{_degca :=_dge ;if _egb &&_cac +_degca > _caa {_eae =0.95*(_caa -_cac );_dga =_ccge /1000.0*_eae ;};if _caa > _dga {_cac =(_caa -_dga )/2.0;};};_agbc .Add_Td (0,_cac );
|
|
|
|
if _cced ,_dae :=_de .GetIntVal (_cec .Q );_dae {switch _cced {case 2:if len (_ebcf )< _cag {_gfa :=float64 (_cag -len (_ebcf ))*_dcgb ;_agbc .Add_Td (_gfa ,0);};};};for _cfdd ,_aab :=range _ebcf {_dbd :=_bae ;if _eef .MarginLeft !=nil {_dbd =*_eef .MarginLeft ;
|
|
|
|
};_gee :=string (_aab );if _dfd !=nil {_cae ,_fdf :=_cde .GetRuneMetrics (_aab );if !_fdf {_g .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a \u0052\u0075\u006e\u0065\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064\u0020\u0069\u006e\u0020\u0066\u006fn\u0074\u003a\u0020\u0025\u0076\u0020\u002d\u0020\u0073\u006b\u0069\u0070\u0070\u0069n\u0067 \u006f\u0076\u0065\u0072",_aab );
|
|
|
|
continue ;};_gee =string (_dfd .Encode (_gee ));_def :=_eae *_cae .Wx /1000.0;_dcb :=(_dcgb -_def )/2;_dbd =_dcb ;};_agbc .Add_Td (_dbd ,0);_agbc .Add_Tj (*_de .MakeString (_gee ));if _cfdd !=len (_ebcf )-1{_agbc .Add_Td (_dcgb -_dbd ,0);};};_agbc .Add_ET ();
|
|
|
|
_agbc .Add_Q ();_agbc .Add_EMC ();_ade :=_eb .NewXObjectForm ();_ade .Resources =_bcg ;_ade .BBox =_de .MakeArrayFromFloats ([]float64 {0,0,_bcga ,_dfc });_ade .SetContentStream (_agbc .Bytes (),_gaad ());_aage :=_de .MakeDict ();_aage .Set ("\u004e",_ade .ToPdfObject ());
|
|
|
|
return _aage ,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 *_eb .PdfPage ,name string ,rect []float64 ,opt ComboboxFieldOptions )(*_eb .PdfFieldChoice ,error ){if page ==nil {return nil ,_bf .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
|
|
|
|
};if len (name )<=0{return nil ,_bf .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 ,_bf .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
|
|
|
|
};_ddee :=_eb .NewPdfField ();_gddb :=&_eb .PdfFieldChoice {};_ddee .SetContext (_gddb );_gddb .PdfField =_ddee ;_gddb .T =_de .MakeString (name );_gddb .Opt =_de .MakeArray ();for _ ,_gfef :=range opt .Choices {_gddb .Opt .Append (_de .MakeString (_gfef ));
|
|
|
|
};_gddb .SetFlag (_eb .FieldFlagCombo );_eff :=_eb .NewPdfAnnotationWidget ();_eff .Rect =_de .MakeArrayFromFloats (rect );_eff .P =page .ToPdfObject ();_eff .F =_de .MakeInteger (4);_eff .Parent =_gddb .ToPdfObject ();_gddb .Annotations =append (_gddb .Annotations ,_eff );
|
|
|
|
return _gddb ,nil ;};
|
2021-09-23 22:37:42 +00:00
|
|
|
|
2022-07-13 21:28:43 +00:00
|
|
|
// SetStyle applies appearance `style` to `fa`.
|
2022-09-10 15:35:04 +00:00
|
|
|
func (_cfae *ImageFieldAppearance )SetStyle (style AppearanceStyle ){_cfae ._acde =&style };
|
2022-06-27 19:58:38 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// NewTextField generates a new text field with partial name `name` at location
|
|
|
|
// specified by `rect` on given `page` and with field specific options `opt`.
|
|
|
|
func NewTextField (page *_eb .PdfPage ,name string ,rect []float64 ,opt TextFieldOptions )(*_eb .PdfFieldText ,error ){if page ==nil {return nil ,_bf .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};if len (name )<=0{return nil ,_bf .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 ,_bf .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");};_feb :=_eb .NewPdfField ();_ebfg :=&_eb .PdfFieldText {};_feb .SetContext (_ebfg );_ebfg .PdfField =_feb ;_ebfg .T =_de .MakeString (name );
|
|
|
|
if opt .MaxLen > 0{_ebfg .MaxLen =_de .MakeInteger (int64 (opt .MaxLen ));};if len (opt .Value )> 0{_ebfg .V =_de .MakeString (opt .Value );};_edcd :=_eb .NewPdfAnnotationWidget ();_edcd .Rect =_de .MakeArrayFromFloats (rect );_edcd .P =page .ToPdfObject ();
|
|
|
|
_edcd .F =_de .MakeInteger (4);_edcd .Parent =_ebfg .ToPdfObject ();_ebfg .Annotations =append (_ebfg .Annotations ,_edcd );return _ebfg ,nil ;};
|
2022-07-13 21:28:43 +00:00
|
|
|
|
2022-09-10 15:35:04 +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 *_eb .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_eb .PdfColorDeviceRGB ;Opacity float64 ;};
|
2022-07-13 21:28:43 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// ImageFieldOptions defines optional parameters for a push button with image attach capability form field.
|
|
|
|
type ImageFieldOptions struct{Image *_eb .Image ;_bceac AppearanceStyle ;};
|
|
|
|
|
|
|
|
// 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 ;_deea *AppearanceStyle ;};func (_dfab *AppearanceStyle )applyAppearanceCharacteristics (_ecc *_de .PdfObjectDictionary ,_gcde *_de .PdfObjectDictionary ,_age *_eb .PdfFont )error {if !_dfab .AllowMK {return nil ;
|
|
|
|
};if CA ,_dcbb :=_de .GetString (_ecc .Get ("\u0043\u0041"));_dcbb &&_age !=nil {_dgbb :=CA .Bytes ();if len (_dgbb )!=0{_bcc :=[]rune (_age .Encoder ().Decode (_dgbb ));if len (_bcc )==1{_dfab .CheckmarkRune =_bcc [0];};};};if BC ,_dfdf :=_de .GetArray (_ecc .Get ("\u0042\u0043"));
|
|
|
|
_dfdf {_gaac ,_gedc :=BC .ToFloat64Array ();if _gedc !=nil {return _gedc ;};switch len (_gaac ){case 1:_dfab .BorderColor =_eb .NewPdfColorDeviceGray (_gaac [0]);case 3:_dfab .BorderColor =_eb .NewPdfColorDeviceRGB (_gaac [0],_gaac [1],_gaac [2]);case 4:_dfab .BorderColor =_eb .NewPdfColorDeviceCMYK (_gaac [0],_gaac [1],_gaac [2],_gaac [3]);
|
|
|
|
default:_g .Log .Debug ("\u0045\u0052\u0052\u004f\u0052:\u0020\u0042\u0043\u0020\u002d\u0020\u0049\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072\u0020\u006f\u0066\u0020\u0063\u006f\u006c\u006f\u0072\u0020\u0063\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074\u0073\u0020\u0028\u0025\u0064)",len (_gaac ));
|
|
|
|
};if _gcde !=nil {if _gfd ,_beda :=_de .GetNumberAsFloat (_gcde .Get ("\u0057"));_beda ==nil {_dfab .BorderSize =_gfd ;};};};if BG ,_eeag :=_de .GetArray (_ecc .Get ("\u0042\u0047"));_eeag {_edfb ,_cfbg :=BG .ToFloat64Array ();if _cfbg !=nil {return _cfbg ;
|
|
|
|
};switch len (_edfb ){case 1:_dfab .FillColor =_eb .NewPdfColorDeviceGray (_edfb [0]);case 3:_dfab .FillColor =_eb .NewPdfColorDeviceRGB (_edfb [0],_edfb [1],_edfb [2]);case 4:_dfab .FillColor =_eb .NewPdfColorDeviceCMYK (_edfb [0],_edfb [1],_edfb [2],_edfb [3]);
|
|
|
|
default:_g .Log .Debug ("\u0045\u0052\u0052\u004f\u0052:\u0020\u0042\u0047\u0020\u002d\u0020\u0049\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072\u0020\u006f\u0066\u0020\u0063\u006f\u006c\u006f\u0072\u0020\u0063\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074\u0073\u0020\u0028\u0025\u0064)",len (_edfb ));
|
|
|
|
};};return nil ;};
|
2021-09-23 22:37:42 +00:00
|
|
|
|
2022-04-27 00:10:33 +00:00
|
|
|
// AppearanceFontStyle defines font style characteristics for form fields,
|
|
|
|
// used in the filling/flattening process.
|
|
|
|
type AppearanceFontStyle struct{
|
2021-09-23 22:37:42 +00:00
|
|
|
|
2022-04-27 00:10:33 +00:00
|
|
|
// Fallback represents a global font fallback, used for fields which do
|
|
|
|
// not specify a font in their default appearance (DA). The fallback is
|
|
|
|
// also used if there is a font specified in the DA, but it is not
|
|
|
|
// found in the AcroForm resources (DR).
|
|
|
|
Fallback *AppearanceFont ;
|
|
|
|
|
|
|
|
// 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.
|
2022-06-27 19:58:38 +00:00
|
|
|
ForceReplace bool ;};
|
2022-06-06 22:48:24 +00:00
|
|
|
|
2022-09-10 15:35:04 +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 *_eb .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_eb .PdfColorDeviceRGB ;Opacity float64 ;};
|
2021-12-14 01:08:28 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// TextFieldOptions defines optional parameter for a text field in a form.
|
|
|
|
type TextFieldOptions struct{MaxLen int ;Value string ;};
|
2022-02-05 21:34:53 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// CreateCircleAnnotation creates a circle/ellipse annotation object with appearance stream that can be added to
|
|
|
|
// page PDF annotations.
|
|
|
|
func CreateCircleAnnotation (circDef CircleAnnotationDef )(*_eb .PdfAnnotation ,error ){_ce :=_eb .NewPdfAnnotationCircle ();if circDef .BorderEnabled {_bff ,_ae ,_ad :=circDef .BorderColor .R (),circDef .BorderColor .G (),circDef .BorderColor .B ();_ce .C =_de .MakeArrayFromFloats ([]float64 {_bff ,_ae ,_ad });
|
|
|
|
_bgb :=_eb .NewBorderStyle ();_bgb .SetBorderWidth (circDef .BorderWidth );_ce .BS =_bgb .ToPdfObject ();};if circDef .FillEnabled {_cb ,_ee ,_aef :=circDef .FillColor .R (),circDef .FillColor .G (),circDef .FillColor .B ();_ce .IC =_de .MakeArrayFromFloats ([]float64 {_cb ,_ee ,_aef });
|
|
|
|
}else {_ce .IC =_de .MakeArrayFromIntegers ([]int {});};if circDef .Opacity < 1.0{_ce .CA =_de .MakeFloat (circDef .Opacity );};_dc ,_ec ,_ebf :=_af (circDef );if _ebf !=nil {return nil ,_ebf ;};_ce .AP =_dc ;_ce .Rect =_de .MakeArrayFromFloats ([]float64 {_ec .Llx ,_ec .Lly ,_ec .Urx ,_ec .Ury });
|
|
|
|
return _ce .PdfAnnotation ,nil ;};
|
2021-12-14 01:08:28 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// ComboboxFieldOptions defines optional parameters for a combobox form field.
|
|
|
|
type ComboboxFieldOptions struct{
|
2022-03-13 12:41:53 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// Choices is the list of string values that can be selected.
|
|
|
|
Choices []string ;};func _fcdff (_baag ,_fgc float64 ,_ggdd *_eb .Image ,_gdf AppearanceStyle )(*_eb .XObjectForm ,error ){_gacc ,_daeb :=_eb .NewXObjectImageFromImage (_ggdd ,nil ,_de .NewFlateEncoder ());if _daeb !=nil {return nil ,_daeb ;};_gacc .Decode =_de .MakeArrayFromFloats ([]float64 {0.0,1.0,0.0,1.0,0.0,1.0});
|
|
|
|
_beg :=_eb .NewPdfPageResources ();_beg .ProcSet =_de .MakeArray (_de .MakeName ("\u0050\u0044\u0046"),_de .MakeName ("\u0049\u006d\u0061\u0067\u0065\u0043"));_beg .SetXObjectImageByName (_de .PdfObjectName ("\u0049\u006d\u0030"),_gacc );_fceb :=_c .NewContentCreator ();
|
|
|
|
_fceb .Add_q ();_fceb .Add_cm (float64 (_ggdd .Width ),0,0,float64 (_ggdd .Height ),0,0);_fceb .Add_Do ("\u0049\u006d\u0030");_fceb .Add_Q ();_eeff :=_eb .NewXObjectForm ();_eeff .FormType =_de .MakeInteger (1);_eeff .BBox =_de .MakeArrayFromFloats ([]float64 {0,0,float64 (_ggdd .Width ),float64 (_ggdd .Height )});
|
|
|
|
_eeff .Resources =_beg ;_eeff .SetContentStream (_fceb .Bytes (),_gaad ());return _eeff ,nil ;};func _gaad ()_de .StreamEncoder {return _de .NewFlateEncoder ()};
|
2021-12-14 01:08:28 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// CheckboxFieldOptions defines optional parameters for a checkbox field a form.
|
|
|
|
type CheckboxFieldOptions struct{Checked bool ;};func _bee (_edg *_eb .PdfField ,_ddg ,_dfe float64 ,_cdd string ,_aec AppearanceStyle ,_bcgd *_c .ContentStreamOperations ,_caf *_eb .PdfPageResources ,_dace *_de .PdfObjectDictionary )(*_eb .XObjectForm ,error ){_ggba :=_eb .NewPdfPageResources ();
|
|
|
|
_fcfd ,_fcb :=_ddg ,_dfe ;_bagb :=_c .NewContentCreator ();if _aec .BorderSize > 0{_degcac (_bagb ,_aec ,_ddg ,_dfe );};if _aec .DrawAlignmentReticle {_edef :=_aec ;_edef .BorderSize =0.2;_feaa (_bagb ,_edef ,_ddg ,_dfe );};_bagb .Add_BMC ("\u0054\u0078");
|
|
|
|
_bagb .Add_q ();_bagb .Add_BT ();_ddg ,_dfe =_aec .applyRotation (_dace ,_ddg ,_dfe ,_bagb );_dgb ,_dbbbb ,_deef :=_aec .processDA (_edg ,_bcgd ,_caf ,_ggba ,_bagb );if _deef !=nil {return nil ,_deef ;};_eaca :=_dgb .Font ;_fba :=_dgb .Size ;_gcdb :=_de .MakeName (_dgb .Name );
|
|
|
|
_edc :=_fba ==0;if _edc &&_dbbbb {_fba =_dfe *_aec .AutoFontSizeFraction ;};_cecd :=_eaca .Encoder ();if _cecd ==nil {_g .Log .Debug ("\u0057\u0041RN\u003a\u0020\u0066\u006f\u006e\u0074\u0020\u0065\u006e\u0063\u006f\u0064\u0065\u0072\u0020\u0069\u0073\u0020\u006e\u0069l\u002e\u0020\u0041\u0073s\u0075\u006d\u0069\u006eg \u0069\u0064e\u006et\u0069\u0074\u0079\u0020\u0065\u006ec\u006f\u0064\u0065r\u002e\u0020O\u0075\u0074\u0070\u0075\u0074\u0020\u006d\u0061\u0079\u0020\u0062\u0065\u0020\u0069n\u0063\u006f\u0072\u0072\u0065\u0063\u0074\u002e");
|
|
|
|
_cecd =_a .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};if len (_cdd )==0{return nil ,nil ;};_bed :=_bae ;if _aec .MarginLeft !=nil {_bed =*_aec .MarginLeft ;};_fde :=0.0;if _cecd !=nil {for _ ,_cdg :=range _cdd {_gfe ,_cfgd :=_eaca .GetRuneMetrics (_cdg );
|
|
|
|
if !_cfgd {_g .Log .Debug ("\u0046\u006f\u006e\u0074\u0020\u0064o\u0065\u0073\u0020\u006e\u006f\u0074\u0020\u0068\u0061\u0076\u0065\u0020\u0072\u0075\u006e\u0065\u0020\u006d\u0065\u0074r\u0069\u0063\u0073\u0020\u0066\u006f\u0072\u0020\u0025\u0076\u0020\u002d\u0020\u0073k\u0069p\u0070\u0069\u006e\u0067",_cdg );
|
|
|
|
continue ;};_fde +=_gfe .Wx ;};_cdd =string (_cecd .Encode (_cdd ));};if _fba ==0||_edc &&_fde > 0&&_bed +_fde *_fba /1000.0> _ddg {_fba =0.95*1000.0*(_ddg -_bed )/_fde ;};_eegb :=1.0*_fba ;_gedf :=2.0;{_bda :=_eegb ;if _edc &&_gedf +_bda > _dfe {_fba =0.95*(_dfe -_gedf );
|
|
|
|
_eegb =1.0*_fba ;_bda =_eegb ;};if _dfe > _bda {_gedf =(_dfe -_bda )/2.0;_gedf +=1.50;};};_bagb .Add_Tf (*_gcdb ,_fba );_bagb .Add_Td (_bed ,_gedf );_bagb .Add_Tj (*_de .MakeString (_cdd ));_bagb .Add_ET ();_bagb .Add_Q ();_bagb .Add_EMC ();_dfa :=_eb .NewXObjectForm ();
|
|
|
|
_dfa .Resources =_ggba ;_dfa .BBox =_de .MakeArrayFromFloats ([]float64 {0,0,_fcfd ,_fcb });_dfa .SetContentStream (_bagb .Bytes (),_gaad ());return _dfa ,nil ;};
|
2021-09-23 22:37:42 +00:00
|
|
|
|
2022-09-10 15:35:04 +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 (_dedd ImageFieldAppearance )WrapContentStream (page *_eb .PdfPage )error {_gcdeg ,_ccbg :=page .GetAllContentStreams ();if _ccbg !=nil {return _ccbg ;};_adf :=_c .NewContentStreamParser (_gcdeg );_faac ,_ccbg :=_adf .Parse ();if _ccbg !=nil {return _ccbg ;
|
|
|
|
};_faac .WrapIfNeeded ();_baaf :=[]string {_faac .String ()};return page .SetContentStreams (_baaf ,_gaad ());};func _af (_gadc CircleAnnotationDef )(*_de .PdfObjectDictionary ,*_eb .PdfRectangle ,error ){_da :=_eb .NewXObjectForm ();_da .Resources =_eb .NewPdfPageResources ();
|
|
|
|
_cee :="";if _gadc .Opacity < 1.0{_cbd :=_de .MakeDict ();_cbd .Set ("\u0063\u0061",_de .MakeFloat (_gadc .Opacity ));_cbd .Set ("\u0043\u0041",_de .MakeFloat (_gadc .Opacity ));_cc :=_da .Resources .AddExtGState ("\u0067\u0073\u0031",_cbd );if _cc !=nil {_g .Log .Debug ("U\u006e\u0061\u0062\u006c\u0065\u0020t\u006f\u0020\u0061\u0064\u0064\u0020\u0065\u0078\u0074g\u0073\u0074\u0061t\u0065 \u0067\u0073\u0031");
|
|
|
|
return nil ,nil ,_cc ;};_cee ="\u0067\u0073\u0031";};_gg ,_f ,_cd ,_gac :=_fd (_gadc ,_cee );if _gac !=nil {return nil ,nil ,_gac ;};_gac =_da .SetContentStream (_gg ,nil );if _gac !=nil {return nil ,nil ,_gac ;};_da .BBox =_f .ToPdfObject ();_dee :=_de .MakeDict ();
|
|
|
|
_dee .Set ("\u004e",_da .ToPdfObject ());return _dee ,_cd ,nil ;};const (_cf quadding =0;_cbdb quadding =1;_ba quadding =2;_bae float64 =2.0;);func _cbe (_abe []*SignatureLine ,_bfdf *SignatureFieldOpts )(*_de .PdfObjectDictionary ,error ){if _bfdf ==nil {_bfdf =NewSignatureFieldOpts ();
|
|
|
|
};var _fgdd error ;var _gbg *_de .PdfObjectName ;_fef :=_bfdf .Font ;if _fef !=nil {_aeb ,_ :=_fef .GetFontDescriptor ();if _aeb !=nil {if _fadg ,_ffde :=_aeb .FontName .(*_de .PdfObjectName );_ffde {_gbg =_fadg ;};};if _gbg ==nil {_gbg =_de .MakeName ("\u0046\u006f\u006et\u0031");
|
|
|
|
};}else {if _fef ,_fgdd =_eb .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");_fgdd !=nil {return nil ,_fgdd ;};_gbg =_de .MakeName ("\u0048\u0065\u006c\u0076");};_dbaf :=_bfdf .FontSize ;if _dbaf <=0{_dbaf =10;};if _bfdf .LineHeight <=0{_bfdf .LineHeight =1;
|
|
|
|
};_dcaf :=_bfdf .LineHeight *_dbaf ;_gbf ,_gce :=_fef .GetRuneMetrics (' ');if !_gce {return nil ,_bf .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");
|
|
|
|
};_gddf :=_gbf .Wx ;var _fcac float64 ;var _fgdf []string ;for _ ,_dded :=range _abe {if _dded .Text ==""{continue ;};_cceg :=_dded .Text ;if _dded .Desc !=""{_cceg =_dded .Desc +"\u003a\u0020"+_cceg ;};_fgdf =append (_fgdf ,_cceg );var _gadab float64 ;
|
|
|
|
for _ ,_afb :=range _cceg {_dgfb ,_edfc :=_fef .GetRuneMetrics (_afb );if !_edfc {continue ;};_gadab +=_dgfb .Wx ;};if _gadab > _fcac {_fcac =_gadab ;};};_fcac =_fcac *_dbaf /1000.0;_bdd :=float64 (len (_fgdf ))*_dcaf ;_caed :=_bfdf .Image !=nil ;_acbe :=_bfdf .Rect ;
|
|
|
|
if _acbe ==nil {_acbe =[]float64 {0,0,_fcac ,_bdd };if _caed {_acbe [2]=_fcac *2;_acbe [3]=_bdd *2;};_bfdf .Rect =_acbe ;};_bdc :=_acbe [2]-_acbe [0];_geab :=_acbe [3]-_acbe [1];_edgc ,_gbc :=_acbe ,_acbe ;var _caec ,_aeaf float64 ;if _caed &&len (_fgdf )> 0{if _bfdf .ImagePosition <=SignatureImageRight {_bfbg :=[]float64 {_acbe [0],_acbe [1],_acbe [0]+(_bdc /2),_acbe [3]};
|
|
|
|
_fadgc :=[]float64 {_acbe [0]+(_bdc /2),_acbe [1],_acbe [2],_acbe [3]};if _bfdf .ImagePosition ==SignatureImageLeft {_edgc ,_gbc =_bfbg ,_fadgc ;}else {_edgc ,_gbc =_fadgc ,_bfbg ;};}else {_eeb :=[]float64 {_acbe [0],_acbe [1],_acbe [2],_acbe [1]+(_geab /2)};
|
|
|
|
_eead :=[]float64 {_acbe [0],_acbe [1]+(_geab /2),_acbe [2],_acbe [3]};if _bfdf .ImagePosition ==SignatureImageTop {_edgc ,_gbc =_eead ,_eeb ;}else {_edgc ,_gbc =_eeb ,_eead ;};};};_caec =_gbc [2]-_gbc [0];_aeaf =_gbc [3]-_gbc [1];var _defcf float64 ;if _bfdf .AutoSize {if _fcac > _caec ||_bdd > _aeaf {_dcf :=_d .Min (_caec /_fcac ,_aeaf /_bdd );
|
|
|
|
_dbaf *=_dcf ;};_dcaf =_bfdf .LineHeight *_dbaf ;_defcf +=(_aeaf -float64 (len (_fgdf ))*_dcaf )/2;};_dea :=_c .NewContentCreator ();_bfaa :=_eb .NewPdfPageResources ();_bfaa .SetFontByName (*_gbg ,_fef .ToPdfObject ());if _bfdf .BorderSize <=0{_bfdf .BorderSize =0;
|
|
|
|
_bfdf .BorderColor =_eb .NewPdfColorDeviceGray (1);};if _bfdf .BorderColor ==nil {_bfdf .BorderColor =_eb .NewPdfColorDeviceGray (1);};if _bfdf .FillColor ==nil {_bfdf .FillColor =_eb .NewPdfColorDeviceGray (1);};_dea .Add_q ().SetNonStrokingColor (_bfdf .FillColor ).SetStrokingColor (_bfdf .BorderColor ).Add_w (_bfdf .BorderSize ).Add_re (_acbe [0],_acbe [1],_bdc ,_geab ).Add_B ().Add_Q ();
|
|
|
|
if _bfdf .WatermarkImage !=nil {_cbcg :=[]float64 {_acbe [0],_acbe [1],_acbe [2],_acbe [3]};_defg ,_aeaa ,_fbge :=_abf (_bfdf .WatermarkImage ,"\u0049\u006d\u0061\u0067\u0065\u0057\u0061\u0074\u0065r\u006d\u0061\u0072\u006b",_bfdf ,_cbcg ,_dea );if _fbge !=nil {return nil ,_fbge ;
|
|
|
|
};_bfaa .SetXObjectImageByName (*_defg ,_aeaa );};_dea .Add_q ();_dea .Translate (_gbc [0],_gbc [3]-_dcaf -_defcf );_dea .Add_BT ();_eace :=_fef .Encoder ();for _ ,_eefb :=range _fgdf {var _fga []byte ;for _ ,_dcac :=range _eefb {if _bg .IsSpace (_dcac ){if len (_fga )> 0{_dea .SetNonStrokingColor (_bfdf .TextColor ).Add_Tf (*_gbg ,_dbaf ).Add_TL (_dcaf ).Add_TJ ([]_de .PdfObject {_de .MakeStringFromBytes (_fga )}...);
|
|
|
|
_fga =nil ;};_dea .Add_Tf (*_gbg ,_dbaf ).Add_TL (_dcaf ).Add_TJ ([]_de .PdfObject {_de .MakeFloat (-_gddf )}...);}else {_fga =append (_fga ,_eace .Encode (string (_dcac ))...);};};if len (_fga )> 0{_dea .SetNonStrokingColor (_bfdf .TextColor ).Add_Tf (*_gbg ,_dbaf ).Add_TL (_dcaf ).Add_TJ ([]_de .PdfObject {_de .MakeStringFromBytes (_fga )}...);
|
|
|
|
};_dea .Add_Td (0,-_dcaf );};_dea .Add_ET ();_dea .Add_Q ();if _caed {_eaa ,_cfabb ,_dgfa :=_abf (_bfdf .Image ,"\u0049\u006d\u0061\u0067\u0065\u0053\u0069\u0067\u006ea\u0074\u0075\u0072\u0065",_bfdf ,_edgc ,_dea );if _dgfa !=nil {return nil ,_dgfa ;};
|
|
|
|
_bfaa .SetXObjectImageByName (*_eaa ,_cfabb );};_ggg :=_eb .NewXObjectForm ();_ggg .Resources =_bfaa ;_ggg .BBox =_de .MakeArrayFromFloats (_acbe );_ggg .SetContentStream (_dea .Bytes (),_gaad ());_cbdc :=_de .MakeDict ();_cbdc .Set ("\u004e",_ggg .ToPdfObject ());
|
|
|
|
return _cbdc ,nil ;};
|
2022-03-13 12:41:53 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// 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 ;
|
2022-04-27 00:10:33 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// SignatureLine represents a line of information in the signature field appearance.
|
|
|
|
type SignatureLine struct{Desc string ;Text string ;};func _abf (_eeee _gad .Image ,_geg string ,_aded *SignatureFieldOpts ,_gaab []float64 ,_daa *_c .ContentCreator )(*_de .PdfObjectName ,*_eb .XObjectImage ,error ){_aaa ,_ggdg :=_eb .DefaultImageHandler {}.NewImageFromGoImage (_eeee );
|
|
|
|
if _ggdg !=nil {return nil ,nil ,_ggdg ;};_gdb ,_ggdg :=_eb .NewXObjectImageFromImage (_aaa ,nil ,_aded .Encoder );if _ggdg !=nil {return nil ,nil ,_ggdg ;};_edgd ,_bccb :=float64 (*_gdb .Width ),float64 (*_gdb .Height );_ffg :=_gaab [2]-_gaab [0];_gdba :=_gaab [3]-_gaab [1];
|
|
|
|
if _aded .AutoSize {_fdbg :=_d .Min (_ffg /_edgd ,_gdba /_bccb );_edgd *=_fdbg ;_bccb *=_fdbg ;_gaab [0]=_gaab [0]+(_ffg /2)-(_edgd /2);_gaab [1]=_gaab [1]+(_gdba /2)-(_bccb /2);};var _bbef *_de .PdfObjectName ;if _bec ,_ebbe :=_de .GetName (_gdb .Name );
|
|
|
|
_ebbe {_bbef =_bec ;}else {_bbef =_de .MakeName (_geg );};if _daa !=nil {_daa .Add_q ().Translate (_gaab [0],_gaab [1]).Scale (_edgd ,_bccb ).Add_Do (*_bbef ).Add_Q ();}else {return nil ,nil ,_bf .New ("\u0043\u006f\u006e\u0074en\u0074\u0043\u0072\u0065\u0061\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u0075l\u006c");
|
|
|
|
};return _bbef ,_gdb ,nil ;};
|
2022-04-27 00:10:33 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// NewCheckboxField generates a new checkbox field with partial name `name` at location `rect`
|
|
|
|
// on specified `page` and with field specific options `opt`.
|
|
|
|
func NewCheckboxField (page *_eb .PdfPage ,name string ,rect []float64 ,opt CheckboxFieldOptions )(*_eb .PdfFieldButton ,error ){if page ==nil {return nil ,_bf .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
|
|
|
|
};if len (name )<=0{return nil ,_bf .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 ,_bf .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
|
|
|
|
};_geeb ,_gcaf :=_eb .NewStandard14Font (_eb .ZapfDingbatsName );if _gcaf !=nil {return nil ,_gcaf ;};_gge :=_eb .NewPdfField ();_ddgc :=&_eb .PdfFieldButton {};_gge .SetContext (_ddgc );_ddgc .PdfField =_gge ;_ddgc .T =_de .MakeString (name );_ddgc .SetType (_eb .ButtonTypeCheckbox );
|
|
|
|
_geec :="\u004f\u0066\u0066";if opt .Checked {_geec ="\u0059\u0065\u0073";};_ddgc .V =_de .MakeName (_geec );_fggg :=_eb .NewPdfAnnotationWidget ();_fggg .Rect =_de .MakeArrayFromFloats (rect );_fggg .P =page .ToPdfObject ();_fggg .F =_de .MakeInteger (4);
|
|
|
|
_fggg .Parent =_ddgc .ToPdfObject ();_ecgg :=rect [2]-rect [0];_adec :=rect [3]-rect [1];var _bbecc _b .Buffer ;_bbecc .WriteString ("\u0071\u000a");_bbecc .WriteString ("\u0030 \u0030\u0020\u0031\u0020\u0072\u0067\n");_bbecc .WriteString ("\u0042\u0054\u000a");
|
|
|
|
_bbecc .WriteString ("\u002f\u005a\u0061D\u0062\u0020\u0031\u0032\u0020\u0054\u0066\u000a");_bbecc .WriteString ("\u0045\u0054\u000a");_bbecc .WriteString ("\u0051\u000a");_cccf :=_c .NewContentCreator ();_cccf .Add_q ();_cccf .Add_rg (0,0,1);_cccf .Add_BT ();
|
|
|
|
_cccf .Add_Tf (*_de .MakeName ("\u005a\u0061\u0044\u0062"),12);_cccf .Add_Td (0,0);_cccf .Add_ET ();_cccf .Add_Q ();_acbg :=_eb .NewXObjectForm ();_acbg .SetContentStream (_cccf .Bytes (),_de .NewRawEncoder ());_acbg .BBox =_de .MakeArrayFromFloats ([]float64 {0,0,_ecgg ,_adec });
|
|
|
|
_acbg .Resources =_eb .NewPdfPageResources ();_acbg .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_geeb .ToPdfObject ());_cccf =_c .NewContentCreator ();_cccf .Add_q ();_cccf .Add_re (0,0,_ecgg ,_adec );_cccf .Add_W ().Add_n ();_cccf .Add_rg (0,0,1);
|
|
|
|
_cccf .Translate (0,3.0);_cccf .Add_BT ();_cccf .Add_Tf (*_de .MakeName ("\u005a\u0061\u0044\u0062"),12);_cccf .Add_Td (0,0);_cccf .Add_Tj (*_de .MakeString ("\u0034"));_cccf .Add_ET ();_cccf .Add_Q ();_dgfg :=_eb .NewXObjectForm ();_dgfg .SetContentStream (_cccf .Bytes (),_de .NewRawEncoder ());
|
|
|
|
_dgfg .BBox =_de .MakeArrayFromFloats ([]float64 {0,0,_ecgg ,_adec });_dgfg .Resources =_eb .NewPdfPageResources ();_dgfg .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_geeb .ToPdfObject ());_gba :=_de .MakeDict ();_gba .Set ("\u004f\u0066\u0066",_acbg .ToPdfObject ());
|
|
|
|
_gba .Set ("\u0059\u0065\u0073",_dgfg .ToPdfObject ());_fgab :=_de .MakeDict ();_fgab .Set ("\u004e",_gba );_fggg .AP =_fgab ;_fggg .AS =_de .MakeName (_geec );_ddgc .Annotations =append (_ddgc .Annotations ,_fggg );return _ddgc ,nil ;};func _fd (_gc CircleAnnotationDef ,_deg string )([]byte ,*_eb .PdfRectangle ,*_eb .PdfRectangle ,error ){_gb :=_gab .Circle {X :_gc .X ,Y :_gc .Y ,Width :_gc .Width ,Height :_gc .Height ,FillEnabled :_gc .FillEnabled ,FillColor :_gc .FillColor ,BorderEnabled :_gc .BorderEnabled ,BorderWidth :_gc .BorderWidth ,BorderColor :_gc .BorderColor ,Opacity :_gc .Opacity };
|
|
|
|
_bc ,_aa ,_bb :=_gb .Draw (_deg );if _bb !=nil {return nil ,nil ,nil ,_bb ;};_ed :=&_eb .PdfRectangle {};_ed .Llx =_gc .X +_aa .Llx ;_ed .Lly =_gc .Y +_aa .Lly ;_ed .Urx =_gc .X +_aa .Urx ;_ed .Ury =_gc .Y +_aa .Ury ;return _bc ,_aa ,_ed ,nil ;};func _feaa (_dff *_c .ContentCreator ,_ecb AppearanceStyle ,_afdg ,_bfa float64 ){_dff .Add_q ().Add_re (0,0,_afdg ,_bfa ).Add_re (0,_bfa /2,_afdg ,_bfa /2).Add_re (0,0,_afdg ,_bfa ).Add_re (_afdg /2,0,_afdg /2,_bfa ).Add_w (_ecb .BorderSize ).SetStrokingColor (_ecb .BorderColor ).SetNonStrokingColor (_ecb .FillColor ).Add_B ().Add_Q ();
|
|
|
|
};
|
2022-04-27 00:10:33 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// CreateRectangleAnnotation creates a rectangle annotation object that can be added to page PDF annotations.
|
|
|
|
func CreateRectangleAnnotation (rectDef RectangleAnnotationDef )(*_eb .PdfAnnotation ,error ){_gff :=_eb .NewPdfAnnotationSquare ();if rectDef .BorderEnabled {_cafc ,_fbeb ,_cccfg :=rectDef .BorderColor .R (),rectDef .BorderColor .G (),rectDef .BorderColor .B ();
|
|
|
|
_gff .C =_de .MakeArrayFromFloats ([]float64 {_cafc ,_fbeb ,_cccfg });_adcc :=_eb .NewBorderStyle ();_adcc .SetBorderWidth (rectDef .BorderWidth );_gff .BS =_adcc .ToPdfObject ();};if rectDef .FillEnabled {_egc ,_fgdc ,_adab :=rectDef .FillColor .R (),rectDef .FillColor .G (),rectDef .FillColor .B ();
|
|
|
|
_gff .IC =_de .MakeArrayFromFloats ([]float64 {_egc ,_fgdc ,_adab });}else {_gff .IC =_de .MakeArrayFromIntegers ([]int {});};if rectDef .Opacity < 1.0{_gff .CA =_de .MakeFloat (rectDef .Opacity );};_cbfc ,_bcdd ,_bbfa :=_fbba (rectDef );if _bbfa !=nil {return nil ,_bbfa ;
|
|
|
|
};_gff .AP =_cbfc ;_gff .Rect =_de .MakeArrayFromFloats ([]float64 {_bcdd .Llx ,_bcdd .Lly ,_bcdd .Urx ,_bcdd .Ury });return _gff .PdfAnnotation ,nil ;};func (_gfed *AppearanceStyle )applyRotation (_ddef *_de .PdfObjectDictionary ,_eag ,_bba float64 ,_aeff *_c .ContentCreator )(float64 ,float64 ){if !_gfed .AllowMK {return _eag ,_bba ;
|
|
|
|
};if _ddef ==nil {return _eag ,_bba ;};_eec ,_ :=_de .GetNumberAsFloat (_ddef .Get ("\u0052"));if _eec ==0{return _eag ,_bba ;};_dffb :=-_eec ;_eaeca :=_gab .Path {Points :[]_gab .Point {_gab .NewPoint (0,0).Rotate (_dffb ),_gab .NewPoint (_eag ,0).Rotate (_dffb ),_gab .NewPoint (0,_bba ).Rotate (_dffb ),_gab .NewPoint (_eag ,_bba ).Rotate (_dffb )}}.GetBoundingBox ();
|
|
|
|
_aeff .RotateDeg (_eec );_aeff .Translate (_eaeca .X ,_eaeca .Y );return _eaeca .Width ,_eaeca .Height ;};func _dbe (_babf *_eb .PdfField )string {if _babf ==nil {return "";};_dgeg ,_ccc :=_babf .GetContext ().(*_eb .PdfFieldText );if !_ccc {return _dbe (_babf .Parent );
|
|
|
|
};if _dgeg .DA !=nil {return _dgeg .DA .Str ();};return _dbe (_dgeg .Parent );};func _aefe (_bdac RectangleAnnotationDef ,_fcbf string )([]byte ,*_eb .PdfRectangle ,*_eb .PdfRectangle ,error ){_ecd :=_gab .Rectangle {X :0,Y :0,Width :_bdac .Width ,Height :_bdac .Height ,FillEnabled :_bdac .FillEnabled ,FillColor :_bdac .FillColor ,BorderEnabled :_bdac .BorderEnabled ,BorderWidth :2*_bdac .BorderWidth ,BorderColor :_bdac .BorderColor ,Opacity :_bdac .Opacity };
|
|
|
|
_gbaf ,_gcga ,_agg :=_ecd .Draw (_fcbf );if _agg !=nil {return nil ,nil ,nil ,_agg ;};_fgae :=&_eb .PdfRectangle {};_fgae .Llx =_bdac .X +_gcga .Llx ;_fgae .Lly =_bdac .Y +_gcga .Lly ;_fgae .Urx =_bdac .X +_gcga .Urx ;_fgae .Ury =_bdac .Y +_gcga .Ury ;
|
|
|
|
return _gbaf ,_gcga ,_fgae ,nil ;};
|
2022-04-27 00:10:33 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`.
|
|
|
|
// Implements interface model.FieldAppearanceGenerator.
|
|
|
|
func (_eegc ImageFieldAppearance )GenerateAppearanceDict (form *_eb .PdfAcroForm ,field *_eb .PdfField ,wa *_eb .PdfAnnotationWidget )(*_de .PdfObjectDictionary ,error ){_ ,_ffb :=field .GetContext ().(*_eb .PdfFieldButton );if !_ffb {_g .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 ;};_ecf ,_fafb :=_de .GetDict (wa .AP );if _fafb &&_eegc .OnlyIfMissing {_g .Log .Trace ("\u0041\u006c\u0072\u0065a\u0064\u0079\u0020\u0070\u006f\u0070\u0075\u006c\u0061\u0074e\u0064 \u002d\u0020\u0069\u0067\u006e\u006f\u0072i\u006e\u0067");
|
|
|
|
return _ecf ,nil ;};if form .DR ==nil {form .DR =_eb .NewPdfPageResources ();};switch _bcfe :=field .GetContext ().(type ){case *_eb .PdfFieldButton :if _bcfe .IsPush (){_gcc ,_bdab :=_bfbf (_bcfe ,wa ,_eegc .Style ());if _bdab !=nil {return nil ,_bdab ;
|
|
|
|
};return _gcc ,nil ;};};return nil ,nil ;};func _aaba (_adc *_eb .PdfAnnotationWidget ,_geb *_eb .PdfFieldButton ,_eabf *_eb .PdfPageResources ,_acff AppearanceStyle )(*_de .PdfObjectDictionary ,error ){_bbf ,_cfb :=_de .GetArray (_adc .Rect );if !_cfb {return nil ,_bf .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");
|
|
|
|
};_ged ,_afd :=_eb .NewPdfRectangle (*_bbf );if _afd !=nil {return nil ,_afd ;};_dda ,_eac :=_ged .Width (),_ged .Height ();_ffe ,_dad :=_dda ,_eac ;_g .Log .Debug ("\u0043\u0068\u0065\u0063kb\u006f\u0078\u002c\u0020\u0077\u0061\u0020\u0042\u0053\u003a\u0020\u0025\u0076",_adc .BS );
|
|
|
|
_cbc ,_afd :=_eb .NewStandard14Font ("\u005a\u0061\u0070f\u0044\u0069\u006e\u0067\u0062\u0061\u0074\u0073");if _afd !=nil {return nil ,_afd ;};_bcea ,_ded :=_de .GetDict (_adc .MK );if _ded {_aca ,_ :=_de .GetDict (_adc .BS );_faf :=_acff .applyAppearanceCharacteristics (_bcea ,_aca ,_cbc );
|
|
|
|
if _faf !=nil {return nil ,_faf ;};};_bfg :=_eb .NewXObjectForm ();{_addc :=_c .NewContentCreator ();if _acff .BorderSize > 0{_degcac (_addc ,_acff ,_dda ,_eac );};if _acff .DrawAlignmentReticle {_cge :=_acff ;_cge .BorderSize =0.2;_feaa (_addc ,_cge ,_dda ,_eac );
|
|
|
|
};_dda ,_eac =_acff .applyRotation (_bcea ,_dda ,_eac ,_addc );_edf :=_acff .AutoFontSizeFraction *_eac ;_bbff ,_dac :=_cbc .GetRuneMetrics (_acff .CheckmarkRune );if !_dac {return nil ,_bf .New ("\u0067l\u0079p\u0068\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");
|
|
|
|
};_gea :=_cbc .Encoder ();_fcg :=_gea .Encode (string (_acff .CheckmarkRune ));_gca :=_bbff .Wx *_edf /1000.0;_fbg :=705.0;_deba :=_fbg /1000.0*_edf ;_deec :=_bae ;if _acff .MarginLeft !=nil {_deec =*_acff .MarginLeft ;};_bdf :=1.0;if _gca < _dda {_deec =(_dda -_gca )/2.0;
|
|
|
|
};if _deba < _eac {_bdf =(_eac -_deba )/2.0;};_addc .Add_q ().Add_g (0).Add_BT ().Add_Tf ("\u005a\u0061\u0044\u0062",_edf ).Add_Td (_deec ,_bdf ).Add_Tj (*_de .MakeStringFromBytes (_fcg )).Add_ET ().Add_Q ();_bfg .Resources =_eb .NewPdfPageResources ();
|
|
|
|
_bfg .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_cbc .ToPdfObject ());_bfg .BBox =_de .MakeArrayFromFloats ([]float64 {0,0,_ffe ,_dad });_bfg .SetContentStream (_addc .Bytes (),_gaad ());};_bcd :=_eb .NewXObjectForm ();{_aagb :=_c .NewContentCreator ();
|
|
|
|
if _acff .BorderSize > 0{_degcac (_aagb ,_acff ,_dda ,_eac );};_bcd .BBox =_de .MakeArrayFromFloats ([]float64 {0,0,_ffe ,_dad });_bcd .SetContentStream (_aagb .Bytes (),_gaad ());};_defc :=_de .MakeDict ();_defc .Set ("\u004f\u0066\u0066",_bcd .ToPdfObject ());
|
|
|
|
_defc .Set ("\u0059\u0065\u0073",_bfg .ToPdfObject ());_aeae :=_de .MakeDict ();_aeae .Set ("\u004e",_defc );return _aeae ,nil ;};
|
2022-04-27 00:10:33 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// ImageFieldAppearance implements interface model.FieldAppearanceGenerator and generates appearance streams
|
|
|
|
// for attaching an image to a button field.
|
|
|
|
type ImageFieldAppearance struct{OnlyIfMissing bool ;_acde *AppearanceStyle ;};
|
2022-04-27 00:10:33 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// SetStyle applies appearance `style` to `fa`.
|
|
|
|
func (_bab *FieldAppearance )SetStyle (style AppearanceStyle ){_bab ._deea =&style };type quadding int ;
|
2022-02-05 21:34:53 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`.
|
|
|
|
// Implements interface model.FieldAppearanceGenerator.
|
|
|
|
func (_ac FieldAppearance )GenerateAppearanceDict (form *_eb .PdfAcroForm ,field *_eb .PdfField ,wa *_eb .PdfAnnotationWidget )(*_de .PdfObjectDictionary ,error ){_g .Log .Trace ("\u0047\u0065n\u0065\u0072\u0061\u0074e\u0041\u0070p\u0065\u0061\u0072\u0061\u006e\u0063\u0065\u0044i\u0063\u0074\u0020\u0066\u006f\u0072\u0020\u0025\u0076\u0020\u0020\u0056:\u0020\u0025\u002b\u0076",field .PartialName (),field .V );
|
|
|
|
_ ,_ag :=field .GetContext ().(*_eb .PdfFieldText );_agb ,_dca :=_de .GetDict (wa .AP );if _dca &&_ac .OnlyIfMissing &&(!_ag ||!_ac .RegenerateTextFields ){_g .Log .Trace ("\u0041\u006c\u0072\u0065a\u0064\u0079\u0020\u0070\u006f\u0070\u0075\u006c\u0061\u0074e\u0064 \u002d\u0020\u0069\u0067\u006e\u006f\u0072i\u006e\u0067");
|
|
|
|
return _agb ,nil ;};if form .DR ==nil {form .DR =_eb .NewPdfPageResources ();};switch _bga :=field .GetContext ().(type ){case *_eb .PdfFieldText :_acb :=_bga ;switch {case _acb .Flags ().Has (_eb .FieldFlagPassword ):return nil ,nil ;case _acb .Flags ().Has (_eb .FieldFlagFileSelect ):return nil ,nil ;
|
|
|
|
case _acb .Flags ().Has (_eb .FieldFlagComb ):if _acb .MaxLen !=nil {_ced ,_be :=_ccfg (wa ,_acb ,form .DR ,_ac .Style ());if _be !=nil {return nil ,_be ;};return _ced ,nil ;};};_bca ,_dg :=_cda (wa ,_acb ,form .DR ,_ac .Style ());if _dg !=nil {return nil ,_dg ;
|
|
|
|
};return _bca ,nil ;case *_eb .PdfFieldButton :_db :=_bga ;if _db .IsCheckbox (){_agc ,_gf :=_aaba (wa ,_db ,form .DR ,_ac .Style ());if _gf !=nil {return nil ,_gf ;};return _agc ,nil ;};_g .Log .Debug ("\u0054\u004f\u0044\u004f\u003a\u0020\u0055\u004e\u0048\u0041\u004e\u0044\u004c\u0045\u0044 \u0062u\u0074\u0074\u006f\u006e\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u002b\u0076",_db .GetType ());
|
|
|
|
case *_eb .PdfFieldChoice :_ab :=_bga ;switch {case _ab .Flags ().Has (_eb .FieldFlagCombo ):_agca ,_ccf :=_fea (form ,wa ,_ab ,_ac .Style ());if _ccf !=nil {return nil ,_ccf ;};return _agca ,nil ;default:_g .Log .Debug ("\u0054\u004f\u0044\u004f\u003a\u0020\u0055N\u0048\u0041\u004eD\u004c\u0045\u0044\u0020c\u0068\u006f\u0069\u0063\u0065\u0020\u0066\u0069\u0065\u006c\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0066\u006c\u0061\u0067\u0073\u003a\u0020\u0025\u0073",_ab .Flags ().String ());
|
|
|
|
};default:_g .Log .Debug ("\u0054\u004f\u0044\u004f\u003a\u0020\u0055\u004e\u0048\u0041N\u0044\u004c\u0045\u0044\u0020\u0066\u0069e\u006c\u0064\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_bga );};return nil ,nil ;};func _cgfd (_aba LineAnnotationDef )(*_de .PdfObjectDictionary ,*_eb .PdfRectangle ,error ){_dgfc :=_eb .NewXObjectForm ();
|
|
|
|
_dgfc .Resources =_eb .NewPdfPageResources ();_aaf :="";if _aba .Opacity < 1.0{_abdf :=_de .MakeDict ();_abdf .Set ("\u0063\u0061",_de .MakeFloat (_aba .Opacity ));_eadc :=_dgfc .Resources .AddExtGState ("\u0067\u0073\u0031",_abdf );if _eadc !=nil {_g .Log .Debug ("U\u006e\u0061\u0062\u006c\u0065\u0020t\u006f\u0020\u0061\u0064\u0064\u0020\u0065\u0078\u0074g\u0073\u0074\u0061t\u0065 \u0067\u0073\u0031");
|
|
|
|
return nil ,nil ,_eadc ;};_aaf ="\u0067\u0073\u0031";};_aefg ,_aeee ,_ddaa ,_geac :=_ddgg (_aba ,_aaf );if _geac !=nil {return nil ,nil ,_geac ;};_geac =_dgfc .SetContentStream (_aefg ,nil );if _geac !=nil {return nil ,nil ,_geac ;};_dgfc .BBox =_aeee .ToPdfObject ();
|
|
|
|
_gagg :=_de .MakeDict ();_gagg .Set ("\u004e",_dgfc .ToPdfObject ());return _gagg ,_ddaa ,nil ;};const (SignatureImageLeft SignatureImagePosition =iota ;SignatureImageRight ;SignatureImageTop ;SignatureImageBottom ;);
|
2022-07-13 21:28:43 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// CreateLineAnnotation creates a line annotation object that can be added to page PDF annotations.
|
|
|
|
func CreateLineAnnotation (lineDef LineAnnotationDef )(*_eb .PdfAnnotation ,error ){_gaaf :=_eb .NewPdfAnnotationLine ();_gaaf .L =_de .MakeArrayFromFloats ([]float64 {lineDef .X1 ,lineDef .Y1 ,lineDef .X2 ,lineDef .Y2 });_ebg :=_de .MakeName ("\u004e\u006f\u006e\u0065");
|
|
|
|
if lineDef .LineEndingStyle1 ==_gab .LineEndingStyleArrow {_ebg =_de .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");};_bbefe :=_de .MakeName ("\u004e\u006f\u006e\u0065");if lineDef .LineEndingStyle2 ==_gab .LineEndingStyleArrow {_bbefe =_de .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");
|
|
|
|
};_gaaf .LE =_de .MakeArray (_ebg ,_bbefe );if lineDef .Opacity < 1.0{_gaaf .CA =_de .MakeFloat (lineDef .Opacity );};_abg ,_dgee ,_bgggg :=lineDef .LineColor .R (),lineDef .LineColor .G (),lineDef .LineColor .B ();_gaaf .IC =_de .MakeArrayFromFloats ([]float64 {_abg ,_dgee ,_bgggg });
|
|
|
|
_gaaf .C =_de .MakeArrayFromFloats ([]float64 {_abg ,_dgee ,_bgggg });_gde :=_eb .NewBorderStyle ();_gde .SetBorderWidth (lineDef .LineWidth );_gaaf .BS =_gde .ToPdfObject ();_bgeb ,_cbcf ,_bdcc :=_cgfd (lineDef );if _bdcc !=nil {return nil ,_bdcc ;};_gaaf .AP =_bgeb ;
|
|
|
|
_gaaf .Rect =_de .MakeArrayFromFloats ([]float64 {_cbcf .Llx ,_cbcf .Lly ,_cbcf .Urx ,_cbcf .Ury });return _gaaf .PdfAnnotation ,nil ;};func _degcac (_ggfc *_c .ContentCreator ,_bdfb AppearanceStyle ,_bfc ,_eaec float64 ){_ggfc .Add_q ().Add_re (0,0,_bfc ,_eaec ).Add_w (_bdfb .BorderSize ).SetStrokingColor (_bdfb .BorderColor ).SetNonStrokingColor (_bdfb .FillColor ).Add_B ().Add_Q ();
|
|
|
|
};
|
2022-07-13 21:28:43 +00:00
|
|
|
|
2022-09-10 15:35:04 +00:00
|
|
|
// Style returns the appearance style of `fa`. If not specified, returns default style.
|
|
|
|
func (_cfe ImageFieldAppearance )Style ()AppearanceStyle {if _cfe ._acde !=nil {return *_cfe ._acde ;};return AppearanceStyle {BorderSize :0.0,BorderColor :_eb .NewPdfColorDeviceGray (0),FillColor :_eb .NewPdfColorDeviceGray (1),DrawAlignmentReticle :false };
|
2022-07-13 21:28:43 +00:00
|
|
|
};
|
|
|
|
|
2022-09-10 15:35:04 +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 *_eb .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 _gab .LineEndingStyle ;LineEndingStyle2 _gab .LineEndingStyle ;};func _ddgg (_gfag LineAnnotationDef ,_daaf string )([]byte ,*_eb .PdfRectangle ,*_eb .PdfRectangle ,error ){_ega :=_gab .Line {X1 :0,Y1 :0,X2 :_gfag .X2 -_gfag .X1 ,Y2 :_gfag .Y2 -_gfag .Y1 ,LineColor :_gfag .LineColor ,Opacity :_gfag .Opacity ,LineWidth :_gfag .LineWidth ,LineEndingStyle1 :_gfag .LineEndingStyle1 ,LineEndingStyle2 :_gfag .LineEndingStyle2 };
|
|
|
|
_dcbd ,_cfabbb ,_afeg :=_ega .Draw (_daaf );if _afeg !=nil {return nil ,nil ,nil ,_afeg ;};_edac :=&_eb .PdfRectangle {};_edac .Llx =_gfag .X1 +_cfabbb .Llx ;_edac .Lly =_gfag .Y1 +_cfabbb .Lly ;_edac .Urx =_gfag .X1 +_cfabbb .Urx ;_edac .Ury =_gfag .Y1 +_cfabbb .Ury ;
|
|
|
|
return _dcbd ,_cfabbb ,_edac ,nil ;};func _fbba (_fbc RectangleAnnotationDef )(*_de .PdfObjectDictionary ,*_eb .PdfRectangle ,error ){_baef :=_eb .NewXObjectForm ();_baef .Resources =_eb .NewPdfPageResources ();_ddeee :="";if _fbc .Opacity < 1.0{_cgef :=_de .MakeDict ();
|
|
|
|
_cgef .Set ("\u0063\u0061",_de .MakeFloat (_fbc .Opacity ));_cgef .Set ("\u0043\u0041",_de .MakeFloat (_fbc .Opacity ));_dfeg :=_baef .Resources .AddExtGState ("\u0067\u0073\u0031",_cgef );if _dfeg !=nil {_g .Log .Debug ("U\u006e\u0061\u0062\u006c\u0065\u0020t\u006f\u0020\u0061\u0064\u0064\u0020\u0065\u0078\u0074g\u0073\u0074\u0061t\u0065 \u0067\u0073\u0031");
|
|
|
|
return nil ,nil ,_dfeg ;};_ddeee ="\u0067\u0073\u0031";};_fbgee ,_gfgf ,_acab ,_cba :=_aefe (_fbc ,_ddeee );if _cba !=nil {return nil ,nil ,_cba ;};_cba =_baef .SetContentStream (_fbgee ,nil );if _cba !=nil {return nil ,nil ,_cba ;};_baef .BBox =_gfgf .ToPdfObject ();
|
|
|
|
_afg :=_de .MakeDict ();_afg .Set ("\u004e",_baef .ToPdfObject ());return _afg ,_acab ,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 *_eb .PdfPage ,name string ,rect []float64 ,opt ImageFieldOptions )(*_eb .PdfFieldButton ,error ){if page ==nil {return nil ,_bf .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
|
|
|
|
};if len (name )<=0{return nil ,_bf .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 ,_bf .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
|
|
|
|
};_fdec :=_eb .NewPdfField ();_bffd :=&_eb .PdfFieldButton {};_bffd .PdfField =_fdec ;_fdec .SetContext (_bffd );_bffd .SetType (_eb .ButtonTypePush );_bffd .T =_de .MakeString (name );_baa :=_eb .NewPdfAnnotationWidget ();_baa .Rect =_de .MakeArrayFromFloats (rect );
|
|
|
|
_baa .P =page .ToPdfObject ();_baa .F =_de .MakeInteger (4);_baa .Parent =_bffd .ToPdfObject ();_gfb :=rect [2]-rect [0];_edec :=rect [3]-rect [1];_aagec :=opt ._bceac ;_ege :=_c .NewContentCreator ();if _aagec .BorderSize > 0{_degcac (_ege ,_aagec ,_gfb ,_edec );
|
|
|
|
};if _aagec .DrawAlignmentReticle {_eged :=_aagec ;_eged .BorderSize =0.2;_feaa (_ege ,_eged ,_gfb ,_edec );};_fec ,_edfcc :=_fcdff (_gfb ,_edec ,opt .Image ,_aagec );if _edfcc !=nil {return nil ,_edfcc ;};_gfaa ,_bfe :=_de .GetDict (_baa .MK );if _bfe {_gfaa .Set ("\u006c",_fec .ToPdfObject ());
|
|
|
|
};_dbaa :=_de .MakeDict ();_dbaa .Set ("\u0046\u0052\u004d",_fec .ToPdfObject ());_cgea :=_eb .NewPdfPageResources ();_cgea .ProcSet =_de .MakeArray (_de .MakeName ("\u0050\u0044\u0046"));_cgea .XObject =_dbaa ;_gda :=_gfb -2;_aebb :=_edec -2;_ege .Add_q ();
|
|
|
|
_ege .Add_re (1,1,_gda ,_aebb );_ege .Add_W ();_ege .Add_n ();_gda -=2;_aebb -=2;_ege .Add_q ();_ege .Add_re (2,2,_gda ,_aebb );_ege .Add_W ();_ege .Add_n ();_dfg :=_d .Min (_gda /float64 (opt .Image .Width ),_aebb /float64 (opt .Image .Height ));_ege .Add_cm (_dfg ,0,0,_dfg ,(_gfb /2)-(float64 (opt .Image .Width )*_dfg /2)+2,2);
|
|
|
|
_ege .Add_Do ("\u0046\u0052\u004d");_ege .Add_Q ();_ege .Add_Q ();_cdbf :=_eb .NewXObjectForm ();_cdbf .FormType =_de .MakeInteger (1);_cdbf .Resources =_cgea ;_cdbf .BBox =_de .MakeArrayFromFloats ([]float64 {0,0,_gfb ,_edec });_cdbf .Matrix =_de .MakeArrayFromFloats ([]float64 {1.0,0.0,0.0,1.0,0.0,0.0});
|
|
|
|
_cdbf .SetContentStream (_ege .Bytes (),_gaad ());_ceb :=_de .MakeDict ();_ceb .Set ("\u004e",_cdbf .ToPdfObject ());_baa .AP =_ceb ;_bffd .Annotations =append (_bffd .Annotations ,_baa );return _bffd ,nil ;};
|