mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +08:00
609 lines
88 KiB
Go
609 lines
88 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 (_a "bytes";_bc "errors";_d "fmt";_f "github.com/unidoc/unipdf/v3/common";_e "github.com/unidoc/unipdf/v3/contentstream";_fg "github.com/unidoc/unipdf/v3/contentstream/draw";_bf "github.com/unidoc/unipdf/v3/core";_b "github.com/unidoc/unipdf/v3/creator";
|
|
_cf "github.com/unidoc/unipdf/v3/internal/textencoding";_bg "github.com/unidoc/unipdf/v3/model";_cfa "image";_db "math";_ed "strings";_be "time";_bb "unicode";);func _abbe (_adc *_bg .PdfAcroForm ,_ceb *_bg .PdfAnnotationWidget ,_bag *_bg .PdfFieldChoice ,_cacd AppearanceStyle )(*_bf .PdfObjectDictionary ,error ){_gcge ,_abcd :=_bf .GetArray (_ceb .Rect );
|
|
if !_abcd {return nil ,_bc .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_cbage ,_bdff :=_bg .NewPdfRectangle (*_gcge );if _bdff !=nil {return nil ,_bdff ;};_cdg ,_geg :=_cbage .Width (),_cbage .Height ();_f .Log .Debug ("\u0043\u0068\u006f\u0069\u0063\u0065\u002c\u0020\u0077\u0061\u0020\u0042S\u003a\u0020\u0025\u0076",_ceb .BS );
|
|
_fab ,_bdff :=_e .NewContentStreamParser (_efcf (_bag .PdfField )).Parse ();if _bdff !=nil {return nil ,_bdff ;};_cdfd ,_fbe :=_bf .GetDict (_ceb .MK );if _fbe {_bbfg ,_ :=_bf .GetDict (_ceb .BS );_agc :=_cacd .applyAppearanceCharacteristics (_cdfd ,_bbfg ,nil );
|
|
if _agc !=nil {return nil ,_agc ;};};_dedb :=_bf .MakeDict ();for _ ,_fcg :=range _bag .Opt .Elements (){if _bbfb ,_dbg :=_bf .GetArray (_fcg );_dbg &&_bbfb .Len ()==2{_fcg =_bbfb .Get (1);};var _afbd string ;if _eba ,_dge :=_bf .GetString (_fcg );_dge {_afbd =_eba .Decoded ();
|
|
}else if _dbfb ,_eabb :=_bf .GetName (_fcg );_eabb {_afbd =_dbfb .String ();}else {_f .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",_fcg );
|
|
return nil ,_bc .New ("\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u002f\u0073t\u0072\u0069\u006e\u0067");};if len (_afbd )> 0{_caac ,_bfe :=_fcbg (_bag .PdfField ,_cdg ,_geg ,_afbd ,_cacd ,_fab ,_adc .DR ,_cdfd );if _bfe !=nil {return nil ,_bfe ;
|
|
};_dedb .Set (*_bf .MakeName (_afbd ),_caac .ToPdfObject ());};};_aab :=_bf .MakeDict ();_aab .Set ("\u004e",_dedb );return _aab ,nil ;};type quadding int ;
|
|
|
|
// 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 *_bg .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 _cbcb (_cga *InkAnnotationDef )([]byte ,*_bg .PdfRectangle ,error ){_fdeef :=[][]_fg .CubicBezierCurve {};for _ ,_daffb :=range _cga .Paths {if _daffb .Length ()==0{continue ;};_cefe :=_daffb .Points ;_ccab ,_dee ,_gbbd :=_aaabf (_cefe );
|
|
if _gbbd !=nil {return nil ,nil ,_gbbd ;};if len (_ccab )!=len (_dee ){return nil ,nil ,_bc .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");
|
|
};_aee :=[]_fg .CubicBezierCurve {};for _cgbg :=0;_cgbg < len (_ccab );_cgbg ++{_aee =append (_aee ,_fg .CubicBezierCurve {P0 :_cefe [_cgbg ],P1 :_ccab [_cgbg ],P2 :_dee [_cgbg ],P3 :_cefe [_cgbg +1]});};if len (_aee )> 0{_fdeef =append (_fdeef ,_aee );
|
|
};};_fdfff ,_cbdfa ,_dcea :=_edd (_fdeef ,_cga .Color ,_cga .LineWidth );if _dcea !=nil {return nil ,nil ,_dcea ;};return _fdfff ,_cbdfa ,nil ;};func (_dceg *AppearanceStyle )applyRotation (_gdee *_bf .PdfObjectDictionary ,_aag ,_cgdg float64 ,_cged *_e .ContentCreator )(float64 ,float64 ){if !_dceg .AllowMK {return _aag ,_cgdg ;
|
|
};if _gdee ==nil {return _aag ,_cgdg ;};_acd ,_ :=_bf .GetNumberAsFloat (_gdee .Get ("\u0052"));if _acd ==0{return _aag ,_cgdg ;};_dafc :=-_acd ;_dbd :=_fg .Path {Points :[]_fg .Point {_fg .NewPoint (0,0).Rotate (_dafc ),_fg .NewPoint (_aag ,0).Rotate (_dafc ),_fg .NewPoint (0,_cgdg ).Rotate (_dafc ),_fg .NewPoint (_aag ,_cgdg ).Rotate (_dafc )}}.GetBoundingBox ();
|
|
_cged .RotateDeg (_acd );_cged .Translate (_dbd .X ,_dbd .Y );return _dbd .Width ,_dbd .Height ;};func _bgc (_bac CircleAnnotationDef ,_bfc string )([]byte ,*_bg .PdfRectangle ,*_bg .PdfRectangle ,error ){_gd :=_fg .Circle {X :_bac .X ,Y :_bac .Y ,Width :_bac .Width ,Height :_bac .Height ,FillEnabled :_bac .FillEnabled ,FillColor :_bac .FillColor ,BorderEnabled :_bac .BorderEnabled ,BorderWidth :_bac .BorderWidth ,BorderColor :_bac .BorderColor ,Opacity :_bac .Opacity };
|
|
_fb ,_gfb ,_fbb :=_gd .Draw (_bfc );if _fbb !=nil {return nil ,nil ,nil ,_fbb ;};_cbc :=&_bg .PdfRectangle {};_cbc .Llx =_bac .X +_gfb .Llx ;_cbc .Lly =_bac .Y +_gfb .Lly ;_cbc .Urx =_bac .X +_gfb .Urx ;_cbc .Ury =_bac .Y +_gfb .Ury ;return _fb ,_gfb ,_cbc ,nil ;
|
|
};func _fcbfb (_agec LineAnnotationDef )(*_bf .PdfObjectDictionary ,*_bg .PdfRectangle ,error ){_ccdac :=_bg .NewXObjectForm ();_ccdac .Resources =_bg .NewPdfPageResources ();_gbce :="";if _agec .Opacity < 1.0{_geb :=_bf .MakeDict ();_geb .Set ("\u0063\u0061",_bf .MakeFloat (_agec .Opacity ));
|
|
_ddfc :=_ccdac .Resources .AddExtGState ("\u0067\u0073\u0031",_geb );if _ddfc !=nil {_f .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 ,_ddfc ;
|
|
};_gbce ="\u0067\u0073\u0031";};_edaga ,_fccb ,_gaec ,_bcdb :=_bbbbe (_agec ,_gbce );if _bcdb !=nil {return nil ,nil ,_bcdb ;};_bcdb =_ccdac .SetContentStream (_edaga ,nil );if _bcdb !=nil {return nil ,nil ,_bcdb ;};_ccdac .BBox =_fccb .ToPdfObject ();
|
|
_ecgd :=_bf .MakeDict ();_ecgd .Set ("\u004e",_ccdac .ToPdfObject ());return _ecgd ,_gaec ,nil ;};
|
|
|
|
// NewFormSubmitButtonField would create a submit button in specified page according to the parameter in `FormSubmitActionOptions`.
|
|
func NewFormSubmitButtonField (page *_bg .PdfPage ,opt FormSubmitActionOptions )(*_bg .PdfFieldButton ,error ){_dccb :=int64 (_cebdc );if opt .IsExclusionList {_dccb |=_gbd ;};if opt .IncludeEmptyFields {_dccb |=_fagd ;};if opt .SubmitAsPDF {_dccb |=_ccae ;
|
|
};_dcd :=_bg .NewPdfActionSubmitForm ();_dcd .Flags =_bf .MakeInteger (_dccb );_dcd .F =_bg .NewPdfFilespec ();if opt .Fields !=nil {_dcd .Fields =opt .Fields ;};_dcd .F .F =_bf .MakeString (opt .Url );_dcd .F .FS =_bf .MakeName ("\u0055\u0052\u004c");
|
|
_fcbd ,_caacb :=_eggd (page ,opt .Rectangle ,"\u0062t\u006e\u0053\u0075\u0062\u006d\u0069t",opt .Label ,opt .LabelColor ,opt .Font ,opt .FontSize ,_dcd .ToPdfObject ());if _caacb !=nil {return nil ,_caacb ;};return _fcbd ,nil ;};
|
|
|
|
// ImageFieldOptions defines optional parameters for a push button with image attach capability form field.
|
|
type ImageFieldOptions struct{Image *_bg .Image ;_acaa AppearanceStyle ;};
|
|
|
|
// 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 (_egbf ImageFieldAppearance )WrapContentStream (page *_bg .PdfPage )error {_dfd ,_adea :=page .GetAllContentStreams ();if _adea !=nil {return _adea ;};_efeg :=_e .NewContentStreamParser (_dfd );_bbba ,_adea :=_efeg .Parse ();if _adea !=nil {return _adea ;
|
|
};_bbba .WrapIfNeeded ();_edadd :=[]string {_bbba .String ()};return page .SetContentStreams (_edadd ,_eabc ());};func _eabc ()_bf .StreamEncoder {return _bf .NewFlateEncoder ()};func _bbgc (_cca *_bg .PdfAnnotationWidget ,_eaba *_bg .PdfFieldButton ,_bea *_bg .PdfPageResources ,_aga AppearanceStyle )(*_bf .PdfObjectDictionary ,error ){_aced ,_gcc :=_bf .GetArray (_cca .Rect );
|
|
if !_gcc {return nil ,_bc .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_cacc ,_ecgeb :=_bg .NewPdfRectangle (*_aced );if _ecgeb !=nil {return nil ,_ecgeb ;};_agaa ,_bbbb :=_cacc .Width (),_cacc .Height ();_debb ,_dcgd :=_agaa ,_bbbb ;
|
|
_f .Log .Debug ("\u0043\u0068\u0065\u0063kb\u006f\u0078\u002c\u0020\u0077\u0061\u0020\u0042\u0053\u003a\u0020\u0025\u0076",_cca .BS );_becg ,_ecgeb :=_bg .NewStandard14Font ("\u005a\u0061\u0070f\u0044\u0069\u006e\u0067\u0062\u0061\u0074\u0073");if _ecgeb !=nil {return nil ,_ecgeb ;
|
|
};_bdf ,_fcfb :=_bf .GetDict (_cca .MK );if _fcfb {_dafda ,_ :=_bf .GetDict (_cca .BS );_dce :=_aga .applyAppearanceCharacteristics (_bdf ,_dafda ,_becg );if _dce !=nil {return nil ,_dce ;};};_gcf :=_bg .NewXObjectForm ();{_dec :=_e .NewContentCreator ();
|
|
if _aga .BorderSize > 0{_ebaf (_dec ,_aga ,_agaa ,_bbbb );};if _aga .DrawAlignmentReticle {_efbg :=_aga ;_efbg .BorderSize =0.2;_dabd (_dec ,_efbg ,_agaa ,_bbbb );};_agaa ,_bbbb =_aga .applyRotation (_bdf ,_agaa ,_bbbb ,_dec );_cgg :=_aga .AutoFontSizeFraction *_bbbb ;
|
|
_ddgc ,_egdb :=_becg .GetRuneMetrics (_aga .CheckmarkRune );if !_egdb {return nil ,_bc .New ("\u0067l\u0079p\u0068\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");};_fea :=_becg .Encoder ();_bfca :=_fea .Encode (string (_aga .CheckmarkRune ));
|
|
_aeb :=_ddgc .Wx *_cgg /1000.0;_fcff :=705.0;_fbf :=_fcff /1000.0*_cgg ;_fada :=_cbb ;if _aga .MarginLeft !=nil {_fada =*_aga .MarginLeft ;};_fdb :=1.0;if _aeb < _agaa {_fada =(_agaa -_aeb )/2.0;};if _fbf < _bbbb {_fdb =(_bbbb -_fbf )/2.0;};_dec .Add_q ().Add_g (0).Add_BT ().Add_Tf ("\u005a\u0061\u0044\u0062",_cgg ).Add_Td (_fada ,_fdb ).Add_Tj (*_bf .MakeStringFromBytes (_bfca )).Add_ET ().Add_Q ();
|
|
_gcf .Resources =_bg .NewPdfPageResources ();_gcf .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_becg .ToPdfObject ());_gcf .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_debb ,_dcgd });_gcf .SetContentStream (_dec .Bytes (),_eabc ());};_edgb :=_bg .NewXObjectForm ();
|
|
{_daag :=_e .NewContentCreator ();if _aga .BorderSize > 0{_ebaf (_daag ,_aga ,_agaa ,_bbbb );};_edgb .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_debb ,_dcgd });_edgb .SetContentStream (_daag .Bytes (),_eabc ());};_ddef :=_bf .PdfObjectName ("\u0059\u0065\u0073");
|
|
_baaa ,_fcfb :=_bf .GetDict (_cca .PdfAnnotation .AP );if _fcfb &&_baaa !=nil {_fff :=_bf .TraceToDirectObject (_baaa .Get ("\u004e"));switch _bfg :=_fff .(type ){case *_bf .PdfObjectDictionary :_gfaa :=_bfg .Keys ();for _ ,_fdee :=range _gfaa {if _fdee !="\u004f\u0066\u0066"{_ddef =_fdee ;
|
|
};};};};_gdd :=_bf .MakeDict ();_gdd .Set ("\u004f\u0066\u0066",_edgb .ToPdfObject ());_gdd .Set (_ddef ,_gcf .ToPdfObject ());_gfff :=_bf .MakeDict ();_gfff .Set ("\u004e",_gdd );return _gfff ,nil ;};
|
|
|
|
// CreateCircleAnnotation creates a circle/ellipse annotation object with appearance stream that can be added to
|
|
// page PDF annotations.
|
|
func CreateCircleAnnotation (circDef CircleAnnotationDef )(*_bg .PdfAnnotation ,error ){_bcg :=_bg .NewPdfAnnotationCircle ();if circDef .BorderEnabled {_g ,_fd ,_ag :=circDef .BorderColor .R (),circDef .BorderColor .G (),circDef .BorderColor .B ();_bcg .C =_bf .MakeArrayFromFloats ([]float64 {_g ,_fd ,_ag });
|
|
_ba :=_bg .NewBorderStyle ();_ba .SetBorderWidth (circDef .BorderWidth );_bcg .BS =_ba .ToPdfObject ();};if circDef .FillEnabled {_af ,_afg ,_dbc :=circDef .FillColor .R (),circDef .FillColor .G (),circDef .FillColor .B ();_bcg .IC =_bf .MakeArrayFromFloats ([]float64 {_af ,_afg ,_dbc });
|
|
}else {_bcg .IC =_bf .MakeArrayFromIntegers ([]int {});};if circDef .Opacity < 1.0{_bcg .CA =_bf .MakeFloat (circDef .Opacity );};_cc ,_fa ,_eg :=_ae (circDef );if _eg !=nil {return nil ,_eg ;};_bcg .AP =_cc ;_bcg .Rect =_bf .MakeArrayFromFloats ([]float64 {_fa .Llx ,_fa .Lly ,_fa .Urx ,_fa .Ury });
|
|
return _bcg .PdfAnnotation ,nil ;};func _ebbg (_bca []*SignatureLine ,_ggc *SignatureFieldOpts )(*_bf .PdfObjectDictionary ,error ){if _ggc ==nil {_ggc =NewSignatureFieldOpts ();};var _abd error ;var _fdff *_bf .PdfObjectName ;_acfg :=_ggc .Font ;if _acfg !=nil {_ebafb ,_ :=_acfg .GetFontDescriptor ();
|
|
if _ebafb !=nil {if _fede ,_gagf :=_ebafb .FontName .(*_bf .PdfObjectName );_gagf {_fdff =_fede ;};};if _fdff ==nil {_fdff =_bf .MakeName ("\u0046\u006f\u006et\u0031");};}else {if _acfg ,_abd =_bg .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");
|
|
_abd !=nil {return nil ,_abd ;};_fdff =_bf .MakeName ("\u0048\u0065\u006c\u0076");};_ccfg :=_ggc .FontSize ;if _ccfg <=0{_ccfg =10;};if _ggc .LineHeight <=0{_ggc .LineHeight =1;};_gbfb :=_ggc .LineHeight *_ccfg ;_edc ,_cfff :=_acfg .GetRuneMetrics (' ');
|
|
if !_cfff {return nil ,_bc .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");};_gbbb :=_edc .Wx ;var _egb float64 ;var _dbe []string ;
|
|
for _ ,_gfae :=range _bca {if _gfae .Text ==""{continue ;};_faea :=_gfae .Text ;if _gfae .Desc !=""{_faea =_gfae .Desc +"\u003a\u0020"+_faea ;};_dbe =append (_dbe ,_faea );var _fabaf float64 ;for _ ,_ced :=range _faea {_bfa ,_cadf :=_acfg .GetRuneMetrics (_ced );
|
|
if !_cadf {continue ;};_fabaf +=_bfa .Wx ;};if _fabaf > _egb {_egb =_fabaf ;};};_egb =_egb *_ccfg /1000.0;_ada :=float64 (len (_dbe ))*_gbfb ;_ccc :=_ggc .Image !=nil ;_eff :=_ggc .Rect ;if _eff ==nil {_eff =[]float64 {0,0,_egb ,_ada };if _ccc {_eff [2]=_egb *2;
|
|
_eff [3]=_ada *2;};_ggc .Rect =_eff ;};_dgcf :=_eff [2]-_eff [0];_bbd :=_eff [3]-_eff [1];_cdgg ,_ggge :=_eff ,_eff ;var _ecd ,_cfge float64 ;if _ccc &&len (_dbe )> 0{if _ggc .ImagePosition <=SignatureImageRight {_face :=[]float64 {_eff [0],_eff [1],_eff [0]+(_dgcf /2),_eff [3]};
|
|
_cfdf :=[]float64 {_eff [0]+(_dgcf /2),_eff [1],_eff [2],_eff [3]};if _ggc .ImagePosition ==SignatureImageLeft {_cdgg ,_ggge =_face ,_cfdf ;}else {_cdgg ,_ggge =_cfdf ,_face ;};}else {_bab :=[]float64 {_eff [0],_eff [1],_eff [2],_eff [1]+(_bbd /2)};_geceg :=[]float64 {_eff [0],_eff [1]+(_bbd /2),_eff [2],_eff [3]};
|
|
if _ggc .ImagePosition ==SignatureImageTop {_cdgg ,_ggge =_geceg ,_bab ;}else {_cdgg ,_ggge =_bab ,_geceg ;};};};_ecd =_ggge [2]-_ggge [0];_cfge =_ggge [3]-_ggge [1];var _dged float64 ;if _ggc .AutoSize {if _egb > _ecd ||_ada > _cfge {_fef :=_db .Min (_ecd /_egb ,_cfge /_ada );
|
|
_ccfg *=_fef ;};_gbfb =_ggc .LineHeight *_ccfg ;_dged +=(_cfge -float64 (len (_dbe ))*_gbfb )/2;};_eeac :=_e .NewContentCreator ();_dgedf :=_bg .NewPdfPageResources ();_dgedf .SetFontByName (*_fdff ,_acfg .ToPdfObject ());if _ggc .BorderSize <=0{_ggc .BorderSize =0;
|
|
_ggc .BorderColor =_bg .NewPdfColorDeviceGray (1);};_eeac .Add_q ();if _ggc .FillColor !=nil {_eeac .SetNonStrokingColor (_ggc .FillColor );};if _ggc .BorderColor !=nil {_eeac .SetStrokingColor (_ggc .BorderColor );};_eeac .Add_w (_ggc .BorderSize ).Add_re (_eff [0],_eff [1],_dgcf ,_bbd );
|
|
if _ggc .FillColor !=nil &&_ggc .BorderColor !=nil {_eeac .Add_B ();}else if _ggc .FillColor !=nil {_eeac .Add_f ();}else if _ggc .BorderColor !=nil {_eeac .Add_S ();};_eeac .Add_Q ();if _ggc .WatermarkImage !=nil {_eaa :=[]float64 {_eff [0],_eff [1],_eff [2],_eff [3]};
|
|
_dda ,_eaab ,_gceb :=_ccbg (_ggc .WatermarkImage ,"\u0049\u006d\u0061\u0067\u0065\u0057\u0061\u0074\u0065r\u006d\u0061\u0072\u006b",_ggc ,_eaa ,_eeac );if _gceb !=nil {return nil ,_gceb ;};_dgedf .SetXObjectImageByName (*_dda ,_eaab );};_eeac .Add_q ();
|
|
_eeac .Translate (_ggge [0],_ggge [3]-_gbfb -_dged );_eeac .Add_BT ();_fee :=_acfg .Encoder ();for _ ,_cebf :=range _dbe {var _gda []byte ;for _ ,_efd :=range _cebf {if _bb .IsSpace (_efd ){if len (_gda )> 0{_eeac .SetNonStrokingColor (_ggc .TextColor ).Add_Tf (*_fdff ,_ccfg ).Add_TL (_gbfb ).Add_TJ ([]_bf .PdfObject {_bf .MakeStringFromBytes (_gda )}...);
|
|
_gda =nil ;};_eeac .Add_Tf (*_fdff ,_ccfg ).Add_TL (_gbfb ).Add_TJ ([]_bf .PdfObject {_bf .MakeFloat (-_gbbb )}...);}else {_gda =append (_gda ,_fee .Encode (string (_efd ))...);};};if len (_gda )> 0{_eeac .SetNonStrokingColor (_ggc .TextColor ).Add_Tf (*_fdff ,_ccfg ).Add_TL (_gbfb ).Add_TJ ([]_bf .PdfObject {_bf .MakeStringFromBytes (_gda )}...);
|
|
};_eeac .Add_Td (0,-_gbfb );};_eeac .Add_ET ();_eeac .Add_Q ();if _ccc {_bae ,_daff ,_dabf :=_ccbg (_ggc .Image ,"\u0049\u006d\u0061\u0067\u0065\u0053\u0069\u0067\u006ea\u0074\u0075\u0072\u0065",_ggc ,_cdgg ,_eeac );if _dabf !=nil {return nil ,_dabf ;};
|
|
_dgedf .SetXObjectImageByName (*_bae ,_daff );};_dcf :=_bg .NewXObjectForm ();_dcf .Resources =_dgedf ;_dcf .BBox =_bf .MakeArrayFromFloats (_eff );_dcf .SetContentStream (_eeac .Bytes (),_eabc ());_bdb :=_bf .MakeDict ();_bdb .Set ("\u004e",_dcf .ToPdfObject ());
|
|
return _bdb ,nil ;};func (_ac *AppearanceFont )fillName (){if _ac .Font ==nil ||_ac .Name !=""{return ;};_cg :=_ac .Font .FontDescriptor ();if _cg ==nil ||_cg .FontName ==nil {return ;};_ac .Name =_cg .FontName .String ();};
|
|
|
|
// FileAnnotationDef holds base information for constructing an file attachment annotation.
|
|
type FileAnnotationDef struct{
|
|
|
|
// Bounding box of the annotation.
|
|
X float64 ;Y float64 ;Width float64 ;Height float64 ;
|
|
|
|
// EmbeddedFile is the file information to be attached.
|
|
EmbeddedFile *_bg .EmbeddedFile ;
|
|
|
|
// Author is the author of the attachment file.
|
|
Author string ;
|
|
|
|
// Subject is the subject of the attachment file.
|
|
Subject string ;
|
|
|
|
// Description of the file attachment that will be displayed as a comment on the PDF reader.
|
|
Description string ;
|
|
|
|
// IconName is The name of an icon that shall be used in displaying the annotation.
|
|
// Conforming readers shall provide predefined icon appearances for at least the following standard names:
|
|
//
|
|
// - Graph
|
|
// - PushPin
|
|
// - Paperclip
|
|
// - Tag
|
|
//
|
|
// Additional names may be supported as well. Default value: "PushPin".
|
|
IconName string ;
|
|
|
|
// Color is the color of the annotation.
|
|
Color *_bg .PdfColorDeviceRGB ;
|
|
|
|
// CreationDate is the date and time when the file attachment was created.
|
|
// If not set, the current time is used.
|
|
CreationDate *_be .Time ;};
|
|
|
|
// 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 *_bg .PdfPage ,name string ,rect []float64 ,opt CheckboxFieldOptions )(*_bg .PdfFieldButton ,error ){if page ==nil {return nil ,_bc .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
|
|
};if len (name )<=0{return nil ,_bc .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 ,_bc .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
|
|
};_aaa ,_cbaa :=_bg .NewStandard14Font (_bg .ZapfDingbatsName );if _cbaa !=nil {return nil ,_cbaa ;};_gcef :=_bg .NewPdfField ();_aagg :=&_bg .PdfFieldButton {};_gcef .SetContext (_aagg );_aagg .PdfField =_gcef ;_aagg .T =_bf .MakeString (name );_aagg .SetType (_bg .ButtonTypeCheckbox );
|
|
_gfe :="\u004f\u0066\u0066";if opt .Checked {_gfe ="\u0059\u0065\u0073";};_aagg .V =_bf .MakeName (_gfe );_eeaeb :=_bg .NewPdfAnnotationWidget ();_eeaeb .Rect =_bf .MakeArrayFromFloats (rect );_eeaeb .P =page .ToPdfObject ();_eeaeb .F =_bf .MakeInteger (4);
|
|
_eeaeb .Parent =_aagg .ToPdfObject ();_dadd :=rect [2]-rect [0];_bffe :=rect [3]-rect [1];var _ecea _a .Buffer ;_ecea .WriteString ("\u0071\u000a");_ecea .WriteString ("\u0030 \u0030\u0020\u0031\u0020\u0072\u0067\n");_ecea .WriteString ("\u0042\u0054\u000a");
|
|
_ecea .WriteString ("\u002f\u005a\u0061D\u0062\u0020\u0031\u0032\u0020\u0054\u0066\u000a");_ecea .WriteString ("\u0045\u0054\u000a");_ecea .WriteString ("\u0051\u000a");_cfbc :=_e .NewContentCreator ();_cfbc .Add_q ();_cfbc .Add_rg (0,0,1);_cfbc .Add_BT ();
|
|
_cfbc .Add_Tf (*_bf .MakeName ("\u005a\u0061\u0044\u0062"),12);_cfbc .Add_Td (0,0);_cfbc .Add_ET ();_cfbc .Add_Q ();_eabdg :=_bg .NewXObjectForm ();_eabdg .SetContentStream (_cfbc .Bytes (),_bf .NewRawEncoder ());_eabdg .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_dadd ,_bffe });
|
|
_eabdg .Resources =_bg .NewPdfPageResources ();_eabdg .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_aaa .ToPdfObject ());_cfbc =_e .NewContentCreator ();_cfbc .Add_q ();_cfbc .Add_re (0,0,_dadd ,_bffe );_cfbc .Add_W ().Add_n ();_cfbc .Add_rg (0,0,1);
|
|
_cfbc .Translate (0,3.0);_cfbc .Add_BT ();_cfbc .Add_Tf (*_bf .MakeName ("\u005a\u0061\u0044\u0062"),12);_cfbc .Add_Td (0,0);_cfbc .Add_Tj (*_bf .MakeString ("\u0034"));_cfbc .Add_ET ();_cfbc .Add_Q ();_agbd :=_bg .NewXObjectForm ();_agbd .SetContentStream (_cfbc .Bytes (),_bf .NewRawEncoder ());
|
|
_agbd .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_dadd ,_bffe });_agbd .Resources =_bg .NewPdfPageResources ();_agbd .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_aaa .ToPdfObject ());_ecbb :=_bf .MakeDict ();_ecbb .Set ("\u004f\u0066\u0066",_eabdg .ToPdfObject ());
|
|
_ecbb .Set ("\u0059\u0065\u0073",_agbd .ToPdfObject ());_edag :=_bf .MakeDict ();_edag .Set ("\u004e",_ecbb );_eeaeb .AP =_edag ;_eeaeb .AS =_bf .MakeName (_gfe );_aagg .Annotations =append (_aagg .Annotations ,_eeaeb );return _aagg ,nil ;};
|
|
|
|
// ImageFieldAppearance implements interface model.FieldAppearanceGenerator and generates appearance streams
|
|
// for attaching an image to a button field.
|
|
type ImageFieldAppearance struct{OnlyIfMissing bool ;_gafb *AppearanceStyle ;};
|
|
|
|
// 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 *_bg .PdfPage ,name string ,rect []float64 ,opt ImageFieldOptions )(*_bg .PdfFieldButton ,error ){if page ==nil {return nil ,_bc .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
|
|
};if len (name )<=0{return nil ,_bc .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 ,_bc .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
|
|
};_fcbf :=_bg .NewPdfField ();_dcab :=&_bg .PdfFieldButton {};_dcab .PdfField =_fcbf ;_fcbf .SetContext (_dcab );_dcab .SetType (_bg .ButtonTypePush );_dcab .T =_bf .MakeString (name );_acde :=_bg .NewPdfAnnotationWidget ();_acde .Rect =_bf .MakeArrayFromFloats (rect );
|
|
_acde .P =page .ToPdfObject ();_acde .F =_bf .MakeInteger (4);_acde .Parent =_dcab .ToPdfObject ();_bcga :=rect [2]-rect [0];_ebdff :=rect [3]-rect [1];_cbagb :=opt ._acaa ;_fgec :=_e .NewContentCreator ();if _cbagb .BorderSize > 0{_ebaf (_fgec ,_cbagb ,_bcga ,_ebdff );
|
|
};if _cbagb .DrawAlignmentReticle {_ffae :=_cbagb ;_ffae .BorderSize =0.2;_dabd (_fgec ,_ffae ,_bcga ,_ebdff );};_dbdf ,_edfc :=_abgc (_bcga ,_ebdff ,opt .Image ,_cbagb );if _edfc !=nil {return nil ,_edfc ;};_deg ,_adce :=_bf .GetDict (_acde .MK );if _adce {_deg .Set ("\u006c",_dbdf .ToPdfObject ());
|
|
};_bfgf :=_bf .MakeDict ();_bfgf .Set ("\u0046\u0052\u004d",_dbdf .ToPdfObject ());_cgde :=_bg .NewPdfPageResources ();_cgde .ProcSet =_bf .MakeArray (_bf .MakeName ("\u0050\u0044\u0046"));_cgde .XObject =_bfgf ;_acgc :=_bcga -2;_dfgg :=_ebdff -2;_fgec .Add_q ();
|
|
_fgec .Add_re (1,1,_acgc ,_dfgg );_fgec .Add_W ();_fgec .Add_n ();_acgc -=2;_dfgg -=2;_fgec .Add_q ();_fgec .Add_re (2,2,_acgc ,_dfgg );_fgec .Add_W ();_fgec .Add_n ();_ffc :=_db .Min (_acgc /float64 (opt .Image .Width ),_dfgg /float64 (opt .Image .Height ));
|
|
_fgec .Add_cm (_ffc ,0,0,_ffc ,(_bcga /2)-(float64 (opt .Image .Width )*_ffc /2)+2,2);_fgec .Add_Do ("\u0046\u0052\u004d");_fgec .Add_Q ();_fgec .Add_Q ();_cgce :=_bg .NewXObjectForm ();_cgce .FormType =_bf .MakeInteger (1);_cgce .Resources =_cgde ;_cgce .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_bcga ,_ebdff });
|
|
_cgce .Matrix =_bf .MakeArrayFromFloats ([]float64 {1.0,0.0,0.0,1.0,0.0,0.0});_cgce .SetContentStream (_fgec .Bytes (),_eabc ());_bdfe :=_bf .MakeDict ();_bdfe .Set ("\u004e",_cgce .ToPdfObject ());_acde .AP =_bdfe ;_dcab .Annotations =append (_dcab .Annotations ,_acde );
|
|
return _dcab ,nil ;};func _ccbg (_dcge _cfa .Image ,_ddac string ,_ddefa *SignatureFieldOpts ,_ddfe []float64 ,_fgb *_e .ContentCreator )(*_bf .PdfObjectName ,*_bg .XObjectImage ,error ){_dgce ,_gccb :=_bg .DefaultImageHandler {}.NewImageFromGoImage (_dcge );
|
|
if _gccb !=nil {return nil ,nil ,_gccb ;};_acge ,_gccb :=_bg .NewXObjectImageFromImage (_dgce ,nil ,_ddefa .Encoder );if _gccb !=nil {return nil ,nil ,_gccb ;};_fbgb ,_ece :=float64 (*_acge .Width ),float64 (*_acge .Height );_dcaf :=_ddfe [2]-_ddfe [0];
|
|
_cegd :=_ddfe [3]-_ddfe [1];if _ddefa .AutoSize {_fdffd :=_db .Min (_dcaf /_fbgb ,_cegd /_ece );_fbgb *=_fdffd ;_ece *=_fdffd ;_ddfe [0]=_ddfe [0]+(_dcaf /2)-(_fbgb /2);_ddfe [1]=_ddfe [1]+(_cegd /2)-(_ece /2);};var _beae *_bf .PdfObjectName ;if _fgbe ,_feff :=_bf .GetName (_acge .Name );
|
|
_feff {_beae =_fgbe ;}else {_beae =_bf .MakeName (_ddac );};if _fgb !=nil {_fgb .Add_q ().Translate (_ddfe [0],_ddfe [1]).Scale (_fbgb ,_ece ).Add_Do (*_beae ).Add_Q ();}else {return nil ,nil ,_bc .New ("\u0043\u006f\u006e\u0074en\u0074\u0043\u0072\u0065\u0061\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u0075l\u006c");
|
|
};return _beae ,_acge ,nil ;};const (_gc quadding =0;_bgge quadding =1;_fc quadding =2;_cbb float64 =2.0;);func _abgc (_cdde ,_dga float64 ,_bdgg *_bg .Image ,_adfd AppearanceStyle )(*_bg .XObjectForm ,error ){_fgege ,_fddf :=_bg .NewXObjectImageFromImage (_bdgg ,nil ,_bf .NewFlateEncoder ());
|
|
if _fddf !=nil {return nil ,_fddf ;};_fgege .Decode =_bf .MakeArrayFromFloats ([]float64 {0.0,1.0,0.0,1.0,0.0,1.0});_gadg :=_bg .NewPdfPageResources ();_gadg .ProcSet =_bf .MakeArray (_bf .MakeName ("\u0050\u0044\u0046"),_bf .MakeName ("\u0049\u006d\u0061\u0067\u0065\u0043"));
|
|
_gadg .SetXObjectImageByName (_bf .PdfObjectName ("\u0049\u006d\u0030"),_fgege );_dfeg :=_e .NewContentCreator ();_dfeg .Add_q ();_dfeg .Add_cm (float64 (_bdgg .Width ),0,0,float64 (_bdgg .Height ),0,0);_dfeg .Add_Do ("\u0049\u006d\u0030");_dfeg .Add_Q ();
|
|
_daeg :=_bg .NewXObjectForm ();_daeg .FormType =_bf .MakeInteger (1);_daeg .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,float64 (_bdgg .Width ),float64 (_bdgg .Height )});_daeg .Resources =_gadg ;_daeg .SetContentStream (_dfeg .Bytes (),_eabc ());return _daeg ,nil ;
|
|
};func _aaabf (_fdage []_fg .Point )(_acdc []_fg .Point ,_ggeg []_fg .Point ,_fcgb error ){_gbbe :=len (_fdage )-1;if len (_fdage )< 1{return nil ,nil ,_bc .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 _gbbe ==1{_eaga :=_fg .Point {X :(2*_fdage [0].X +_fdage [1].X )/3,Y :(2*_fdage [0].Y +_fdage [1].Y )/3};_acdc =append (_acdc ,_eaga );_ggeg =append (_ggeg ,_fg .Point {X :2*_eaga .X -_fdage [0].X ,Y :2*_eaga .Y -_fdage [0].Y });return _acdc ,_ggeg ,nil ;
|
|
};_cefd :=make ([]float64 ,_gbbe );for _gfbbe :=1;_gfbbe < _gbbe -1;_gfbbe ++{_cefd [_gfbbe ]=4*_fdage [_gfbbe ].X +2*_fdage [_gfbbe +1].X ;};_cefd [0]=_fdage [0].X +2*_fdage [1].X ;_cefd [_gbbe -1]=(8*_fdage [_gbbe -1].X +_fdage [_gbbe ].X )/2.0;_faead :=_aacgb (_cefd );
|
|
for _ddgf :=1;_ddgf < _gbbe -1;_ddgf ++{_cefd [_ddgf ]=4*_fdage [_ddgf ].Y +2*_fdage [_ddgf +1].Y ;};_cefd [0]=_fdage [0].Y +2*_fdage [1].Y ;_cefd [_gbbe -1]=(8*_fdage [_gbbe -1].Y +_fdage [_gbbe ].Y )/2.0;_bagba :=_aacgb (_cefd );_acdc =make ([]_fg .Point ,_gbbe );
|
|
_ggeg =make ([]_fg .Point ,_gbbe );for _ddacb :=0;_ddacb < _gbbe ;_ddacb ++{_acdc [_ddacb ]=_fg .Point {X :_faead [_ddacb ],Y :_bagba [_ddacb ]};if _ddacb < _gbbe -1{_ggeg [_ddacb ]=_fg .Point {X :2*_fdage [_ddacb +1].X -_faead [_ddacb +1],Y :2*_fdage [_ddacb +1].Y -_bagba [_ddacb +1]};
|
|
}else {_ggeg [_ddacb ]=_fg .Point {X :(_fdage [_gbbe ].X +_faead [_gbbe -1])/2,Y :(_fdage [_gbbe ].Y +_bagba [_gbbe -1])/2};};};return _acdc ,_ggeg ,nil ;};
|
|
|
|
// NewSignatureFieldOpts returns a new initialized instance of options
|
|
// used to generate a signature appearance.
|
|
func NewSignatureFieldOpts ()*SignatureFieldOpts {return &SignatureFieldOpts {Font :_bg .DefaultFont (),FontSize :10,LineHeight :1,AutoSize :true ,TextColor :_bg .NewPdfColorDeviceGray (0),BorderColor :_bg .NewPdfColorDeviceGray (0),FillColor :_bg .NewPdfColorDeviceGray (1),Encoder :_bf .NewFlateEncoder (),ImagePosition :SignatureImageLeft };
|
|
};
|
|
|
|
// 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 *_bg .PdfPage ,name string ,rect []float64 ,opt TextFieldOptions )(*_bg .PdfFieldText ,error ){if page ==nil {return nil ,_bc .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};if len (name )<=0{return nil ,_bc .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 ,_bc .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");};_dfe :=_bg .NewPdfField ();_dffg :=&_bg .PdfFieldText {};_dfe .SetContext (_dffg );_dffg .PdfField =_dfe ;_dffg .T =_bf .MakeString (name );
|
|
if opt .MaxLen > 0{_dffg .MaxLen =_bf .MakeInteger (int64 (opt .MaxLen ));};if len (opt .Value )> 0{_dffg .V =_bf .MakeString (opt .Value );};if opt .TextColor !=""{_gad :=_b .ColorRGBFromHex (opt .TextColor );_efbc ,_adac ,_gbee :=_gad .ToRGB ();_edadg :=_d .Sprintf ("\u002f\u0048\u0065lv\u0065\u0074\u0069\u0063\u0061\u0020\u0031\u0032\u0020T\u0066 \u0025.\u0033f\u0020\u0025\u002e\u0033\u0066\u0020\u0025\u002e\u0033\u0066\u0020\u0072\u0067",_efbc ,_adac ,_gbee );
|
|
_dffg .DA =_bf .MakeString (_edadg );};_dfe .SetContext (_dffg );_fadcf :=_bg .NewPdfAnnotationWidget ();_fadcf .Rect =_bf .MakeArrayFromFloats (rect );_fadcf .P =page .ToPdfObject ();_fadcf .F =_bf .MakeInteger (4);_fadcf .Parent =_dffg .ToPdfObject ();
|
|
_dffg .Annotations =append (_dffg .Annotations ,_fadcf );return _dffg ,nil ;};func _efcf (_fca *_bg .PdfField )string {if _fca ==nil {return "";};_bbc ,_ffg :=_fca .GetContext ().(*_bg .PdfFieldText );if !_ffg {return _efcf (_fca .Parent );};if _bbc .DA !=nil {return _bbc .DA .Str ();
|
|
};return _efcf (_bbc .Parent );};
|
|
|
|
// 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 ;};
|
|
|
|
// 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 _bg .PdfColor ;FillColor _bg .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 ;TextColor _bg .PdfColor ;};func _aacgb (_dadb []float64 )[]float64 {var (_dgb =len (_dadb );_bdcdc =make ([]float64 ,_dgb );_gac =make ([]float64 ,_dgb ););_fcaa :=2.0;_bdcdc [0]=_dadb [0]/_fcaa ;for _cbdge :=1;_cbdge < _dgb ;_cbdge ++{_gac [_cbdge ]=1/_fcaa ;
|
|
if _cbdge < _dgb -1{_fcaa =4.0;}else {_fcaa =3.5;};_fcaa -=_gac [_cbdge ];_bdcdc [_cbdge ]=(_dadb [_cbdge ]-_bdcdc [_cbdge -1])/_fcaa ;};for _eed :=1;_eed < _dgb ;_eed ++{_bdcdc [_dgb -_eed -1]-=_gac [_dgb -_eed ]*_bdcdc [_dgb -_eed ];};return _bdcdc ;
|
|
};
|
|
|
|
// 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 *_bg .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 _fg .LineEndingStyle ;LineEndingStyle2 _fg .LineEndingStyle ;};func _fcbg (_dea *_bg .PdfField ,_fce ,_bdgd float64 ,_bgbd string ,_caf AppearanceStyle ,_bbff *_e .ContentStreamOperations ,_dbgc *_bg .PdfPageResources ,_cgeg *_bf .PdfObjectDictionary )(*_bg .XObjectForm ,error ){_fgeg :=_bg .NewPdfPageResources ();
|
|
_gga ,_gdfb :=_fce ,_bdgd ;_affb :=_e .NewContentCreator ();if _caf .BorderSize > 0{_ebaf (_affb ,_caf ,_fce ,_bdgd );};if _caf .DrawAlignmentReticle {_ecgee :=_caf ;_ecgee .BorderSize =0.2;_dabd (_affb ,_ecgee ,_fce ,_bdgd );};_affb .Add_BMC ("\u0054\u0078");
|
|
_affb .Add_q ();_affb .Add_BT ();_fce ,_bdgd =_caf .applyRotation (_cgeg ,_fce ,_bdgd ,_affb );_gcfe ,_adde ,_ccf :=_caf .processDA (_dea ,_bbff ,_dbgc ,_fgeg ,_affb );if _ccf !=nil {return nil ,_ccf ;};_feg :=_gcfe .Font ;_dgfc :=_gcfe .Size ;_adg :=_bf .MakeName (_gcfe .Name );
|
|
_fbdd :=_dgfc ==0;if _fbdd &&_adde {_dgfc =_bdgd *_caf .AutoFontSizeFraction ;};_cgc :=_feg .Encoder ();if _cgc ==nil {_f .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");
|
|
_cgc =_cf .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};if len (_bgbd )==0{return nil ,nil ;};_dfa :=_cbb ;if _caf .MarginLeft !=nil {_dfa =*_caf .MarginLeft ;};_cde :=0.0;if _cgc !=nil {for _ ,_faba :=range _bgbd {_gdb ,_eeae :=_feg .GetRuneMetrics (_faba );
|
|
if !_eeae {_f .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",_faba );
|
|
continue ;};_cde +=_gdb .Wx ;};_bgbd =string (_cgc .Encode (_bgbd ));};if _dgfc ==0||_fbdd &&_cde > 0&&_dfa +_cde *_dgfc /1000.0> _fce {_dgfc =0.95*1000.0*(_fce -_dfa )/_cde ;};_ebgg :=1.0*_dgfc ;_cebd :=2.0;{_bagb :=_ebgg ;if _fbdd &&_cebd +_bagb > _bdgd {_dgfc =0.95*(_bdgd -_cebd );
|
|
_ebgg =1.0*_dgfc ;_bagb =_ebgg ;};if _bdgd > _bagb {_cebd =(_bdgd -_bagb )/2.0;_cebd +=1.50;};};_affb .Add_Tf (*_adg ,_dgfc );_affb .Add_Td (_dfa ,_cebd );_affb .Add_Tj (*_bf .MakeString (_bgbd ));_affb .Add_ET ();_affb .Add_Q ();_affb .Add_EMC ();_fac :=_bg .NewXObjectForm ();
|
|
_fac .Resources =_fgeg ;_fac .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_gga ,_gdfb });_fac .SetContentStream (_affb .Bytes (),_eabc ());return _fac ,nil ;};
|
|
|
|
// 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 ;
|
|
|
|
// FormResetActionOptions holds options for creating a form reset button.
|
|
type FormResetActionOptions struct{
|
|
|
|
// Rectangle holds the button position, size, and color.
|
|
Rectangle _fg .Rectangle ;
|
|
|
|
// Label specifies the text that would be displayed on the button.
|
|
Label string ;
|
|
|
|
// LabelColor specifies the button label color.
|
|
LabelColor _bg .PdfColor ;
|
|
|
|
// Font specifies a font used for rendering the button label.
|
|
// When omitted it will fallback to use a Helvetica font.
|
|
Font *_bg .PdfFont ;
|
|
|
|
// FontSize specifies the font size used in rendering the button label.
|
|
// The default font size is 12pt.
|
|
FontSize *float64 ;
|
|
|
|
// Fields specifies list of fields that could be resetted.
|
|
// This list may contain indirect object to fields or field names.
|
|
Fields *_bf .PdfObjectArray ;
|
|
|
|
// IsExclusionList specifies that the fields in the `Fields` array would be excluded form reset process.
|
|
IsExclusionList bool ;};func _cbde (_fabe _bf .PdfObject ,_bcag *_bg .PdfPageResources )(*_bf .PdfObjectName ,float64 ,bool ){var (_gbe *_bf .PdfObjectName ;_cadd float64 ;_bbag bool ;);if _cgf ,_dgdd :=_bf .GetDict (_fabe );_dgdd &&_cgf !=nil {_bfde :=_bf .TraceToDirectObject (_cgf .Get ("\u004e"));
|
|
switch _dfge :=_bfde .(type ){case *_bf .PdfObjectStream :_eee ,_bcbe :=_bf .DecodeStream (_dfge );if _bcbe !=nil {_f .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",_bcbe .Error ());
|
|
return nil ,0,false ;};_bbge ,_bcbe :=_e .NewContentStreamParser (string (_eee )).Parse ();if _bcbe !=nil {_f .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",_bcbe .Error ());
|
|
return nil ,0,false ;};_ebdf :=_e .NewContentStreamProcessor (*_bbge );_ebdf .AddHandler (_e .HandlerConditionEnumOperand ,"\u0054\u0066",func (_ccd *_e .ContentStreamOperation ,_bcdg _e .GraphicsState ,_ffa *_bg .PdfPageResources )error {if len (_ccd .Params )==2{if _cdgf ,_bad :=_bf .GetName (_ccd .Params [0]);
|
|
_bad {_gbe =_cdgf ;};if _eag ,_bbeb :=_bf .GetNumberAsFloat (_ccd .Params [1]);_bbeb ==nil {_cadd =_eag ;};_bbag =true ;return _e .ErrEarlyExit ;};return nil ;});_ebdf .Process (_bcag );return _gbe ,_cadd ,_bbag ;};};return nil ,0,false ;};
|
|
|
|
// 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 *_bg .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 _bg .PdfColor ;
|
|
|
|
// FillColor represents the background color of the appearance annotation area.
|
|
FillColor _bg .PdfColor ;
|
|
|
|
// BorderSize represents border size of the appearance annotation area.
|
|
BorderSize float64 ;
|
|
|
|
// BorderColor represents the border color of the appearance annotation area.
|
|
BorderColor _bg .PdfColor ;
|
|
|
|
// WatermarkImage specifies the image used as a watermark that will be rendered
|
|
// behind the signature.
|
|
WatermarkImage _cfa .Image ;
|
|
|
|
// Image represents the image used for the signature appearance.
|
|
Image _cfa .Image ;
|
|
|
|
// Encoder specifies the image encoder used for image signature. Defaults to flate encoder.
|
|
Encoder _bf .StreamEncoder ;
|
|
|
|
// ImagePosition specifies the image location relative to the text signature.
|
|
ImagePosition SignatureImagePosition ;};
|
|
|
|
// 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 *_bg .PdfSignature ,lines []*SignatureLine ,opts *SignatureFieldOpts )(*_bg .PdfFieldSignature ,error ){if signature ==nil {return nil ,_bc .New ("\u0073\u0069\u0067na\u0074\u0075\u0072\u0065\u0020\u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u006e\u0069\u006c");
|
|
};_bge ,_bafa :=_ebbg (lines ,opts );if _bafa !=nil {return nil ,_bafa ;};_eef :=_bg .NewPdfFieldSignature (signature );_eef .Rect =_bf .MakeArrayFromFloats (opts .Rect );_eef .AP =_bge ;return _eef ,nil ;};const (_gbd =1;_fagd =2;_cebdc =4;_fffa =8;_fgc =16;
|
|
_bbdc =32;_gege =64;_edgcg =128;_ccae =256;_baad =512;_fdffa =1024;_fdd =2048;_eagf =4096;);
|
|
|
|
// 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 *_bg .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_bg .PdfColorDeviceRGB ;Opacity float64 ;};func _ae (_fdc CircleAnnotationDef )(*_bf .PdfObjectDictionary ,*_bg .PdfRectangle ,error ){_cb :=_bg .NewXObjectForm ();
|
|
_cb .Resources =_bg .NewPdfPageResources ();_fe :="";if _fdc .Opacity < 1.0{_ege :=_bf .MakeDict ();_ege .Set ("\u0063\u0061",_bf .MakeFloat (_fdc .Opacity ));_ege .Set ("\u0043\u0041",_bf .MakeFloat (_fdc .Opacity ));_gf :=_cb .Resources .AddExtGState ("\u0067\u0073\u0031",_ege );
|
|
if _gf !=nil {_f .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 ,_gf ;};_fe ="\u0067\u0073\u0031";};_bcc ,_eda ,_bgg ,_gg :=_bgc (_fdc ,_fe );
|
|
if _gg !=nil {return nil ,nil ,_gg ;};_gg =_cb .SetContentStream (_bcc ,nil );if _gg !=nil {return nil ,nil ,_gg ;};_cb .BBox =_eda .ToPdfObject ();_gb :=_bf .MakeDict ();_gb .Set ("\u004e",_cb .ToPdfObject ());return _gb ,_bgg ,nil ;};const (SignatureImageLeft SignatureImagePosition =iota ;
|
|
SignatureImageRight ;SignatureImageTop ;SignatureImageBottom ;);
|
|
|
|
// 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 (_dgd FieldAppearance )WrapContentStream (page *_bg .PdfPage )error {_gea ,_cgdb :=page .GetAllContentStreams ();if _cgdb !=nil {return _cgdb ;};_cbbc :=_e .NewContentStreamParser (_gea );_abbd ,_cgdb :=_cbbc .Parse ();if _cgdb !=nil {return _cgdb ;
|
|
};_abbd .WrapIfNeeded ();_bdcf :=[]string {_abbd .String ()};return page .SetContentStreams (_bdcf ,_eabc ());};
|
|
|
|
// NewFormResetButtonField would create a reset button in specified page according to the parameter in `FormResetActionOptions`.
|
|
func NewFormResetButtonField (page *_bg .PdfPage ,opt FormResetActionOptions )(*_bg .PdfFieldButton ,error ){_becb :=_bg .NewPdfActionResetForm ();_becb .Fields =opt .Fields ;_becb .Flags =_bf .MakeInteger (0);if opt .IsExclusionList {_becb .Flags =_bf .MakeInteger (1);
|
|
};_ebec ,_addc :=_eggd (page ,opt .Rectangle ,"\u0062\u0074\u006e\u0052\u0065\u0073\u0065\u0074",opt .Label ,opt .LabelColor ,opt .Font ,opt .FontSize ,_becb .ToPdfObject ());if _addc !=nil {return nil ,_addc ;};return _ebec ,nil ;};
|
|
|
|
// CheckboxFieldOptions defines optional parameters for a checkbox field a form.
|
|
type CheckboxFieldOptions struct{Checked bool ;};func _ebaf (_bccg *_e .ContentCreator ,_bdc AppearanceStyle ,_eca ,_acc float64 ){_bccg .Add_q ().Add_re (0,0,_eca ,_acc ).Add_w (_bdc .BorderSize ).SetStrokingColor (_bdc .BorderColor ).SetNonStrokingColor (_bdc .FillColor ).Add_B ().Add_Q ();
|
|
};func _fffc (_aacgd *_bg .PdfFieldButton ,_dfcf *_bg .PdfAnnotationWidget ,_ccda AppearanceStyle )(*_bf .PdfObjectDictionary ,error ){_dbbe ,_gfbb :=_bf .GetArray (_dfcf .Rect );if !_gfbb {return nil ,_bc .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");
|
|
};_bdcb ,_eaf :=_bg .NewPdfRectangle (*_dbbe );if _eaf !=nil {return nil ,_eaf ;};_aaga ,_cgfa :=_bdcb .Width (),_bdcb .Height ();_bbab :=_e .NewContentCreator ();if _ccda .BorderSize > 0{_ebaf (_bbab ,_ccda ,_aaga ,_cgfa );};if _ccda .DrawAlignmentReticle {_dccg :=_ccda ;
|
|
_dccg .BorderSize =0.2;_dabd (_bbab ,_dccg ,_aaga ,_cgfa );};_gagfg :=_aacgd .GetFillImage ();_cdfe ,_eaf :=_abgc (_aaga ,_cgfa ,_gagfg ,_ccda );if _eaf !=nil {return nil ,_eaf ;};_abde ,_ede :=_bf .GetDict (_dfcf .MK );if _ede {_abde .Set ("\u006c",_cdfe .ToPdfObject ());
|
|
};_fgcc :=_bf .MakeDict ();_fgcc .Set ("\u0046\u0052\u004d",_cdfe .ToPdfObject ());_dcb :=_bg .NewPdfPageResources ();_dcb .ProcSet =_bf .MakeArray (_bf .MakeName ("\u0050\u0044\u0046"));_dcb .XObject =_fgcc ;_dbaf :=_aaga -2;_aadb :=_cgfa -2;_bbab .Add_q ();
|
|
_bbab .Add_re (1,1,_dbaf ,_aadb );_bbab .Add_W ();_bbab .Add_n ();_dbaf -=2;_aadb -=2;_bbab .Add_q ();_bbab .Add_re (2,2,_dbaf ,_aadb );_bbab .Add_W ();_bbab .Add_n ();_gfc :=_db .Min (_dbaf /float64 (_gagfg .Width ),_aadb /float64 (_gagfg .Height ));_bbab .Add_cm (_gfc ,0,0,_gfc ,(_aaga /2)-(float64 (_gagfg .Width )*_gfc /2)+2,2);
|
|
_bbab .Add_Do ("\u0046\u0052\u004d");_bbab .Add_Q ();_bbab .Add_Q ();_dcec :=_bg .NewXObjectForm ();_dcec .FormType =_bf .MakeInteger (1);_dcec .Resources =_dcb ;_dcec .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_aaga ,_cgfa });_dcec .Matrix =_bf .MakeArrayFromFloats ([]float64 {1.0,0.0,0.0,1.0,0.0,0.0});
|
|
_dcec .SetContentStream (_bbab .Bytes (),_eabc ());_ecac :=_bf .MakeDict ();_ecac .Set ("\u004e",_dcec .ToPdfObject ());return _ecac ,nil ;};func (_cbgc *AppearanceStyle )applyAppearanceCharacteristics (_eecg *_bf .PdfObjectDictionary ,_fadc *_bf .PdfObjectDictionary ,_dcga *_bg .PdfFont )error {if !_cbgc .AllowMK {return nil ;
|
|
};if CA ,_dcad :=_bf .GetString (_eecg .Get ("\u0043\u0041"));_dcad &&_dcga !=nil {_fdaa :=CA .Bytes ();if len (_fdaa )!=0{_cgd :=[]rune (_dcga .Encoder ().Decode (_fdaa ));if len (_cgd )==1{_cbgc .CheckmarkRune =_cgd [0];};};};if BC ,_ddec :=_bf .GetArray (_eecg .Get ("\u0042\u0043"));
|
|
_ddec {_bfcd ,_bba :=BC .ToFloat64Array ();if _bba !=nil {return _bba ;};switch len (_bfcd ){case 1:_cbgc .BorderColor =_bg .NewPdfColorDeviceGray (_bfcd [0]);case 3:_cbgc .BorderColor =_bg .NewPdfColorDeviceRGB (_bfcd [0],_bfcd [1],_bfcd [2]);case 4:_cbgc .BorderColor =_bg .NewPdfColorDeviceCMYK (_bfcd [0],_bfcd [1],_bfcd [2],_bfcd [3]);
|
|
default:_f .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 (_bfcd ));
|
|
};if _fadc !=nil {if _ddb ,_cbbf :=_bf .GetNumberAsFloat (_fadc .Get ("\u0057"));_cbbf ==nil {_cbgc .BorderSize =_ddb ;};};};if BG ,_caacg :=_bf .GetArray (_eecg .Get ("\u0042\u0047"));_caacg {_eeag ,_eeg :=BG .ToFloat64Array ();if _eeg !=nil {return _eeg ;
|
|
};switch len (_eeag ){case 1:_cbgc .FillColor =_bg .NewPdfColorDeviceGray (_eeag [0]);case 3:_cbgc .FillColor =_bg .NewPdfColorDeviceRGB (_eeag [0],_eeag [1],_eeag [2]);case 4:_cbgc .FillColor =_bg .NewPdfColorDeviceCMYK (_eeag [0],_eeag [1],_eeag [2],_eeag [3]);
|
|
default:_f .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 (_eeag ));
|
|
};};return 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 *_bg .PdfPage ,name string ,rect []float64 ,opt ComboboxFieldOptions )(*_bg .PdfFieldChoice ,error ){if page ==nil {return nil ,_bc .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
|
|
};if len (name )<=0{return nil ,_bc .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 ,_bc .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
|
|
};_dgeb :=_bg .NewPdfField ();_efcb :=&_bg .PdfFieldChoice {};_dgeb .SetContext (_efcb );_efcb .PdfField =_dgeb ;_efcb .T =_bf .MakeString (name );_efcb .Opt =_bf .MakeArray ();for _ ,_cda :=range opt .Choices {_efcb .Opt .Append (_bf .MakeString (_cda ));
|
|
};_efcb .SetFlag (_bg .FieldFlagCombo );_bdcd :=_bg .NewPdfAnnotationWidget ();_bdcd .Rect =_bf .MakeArrayFromFloats (rect );_bdcd .P =page .ToPdfObject ();_bdcd .F =_bf .MakeInteger (4);_bdcd .Parent =_efcb .ToPdfObject ();_efcb .Annotations =append (_efcb .Annotations ,_bdcd );
|
|
return _efcb ,nil ;};
|
|
|
|
// Style returns the appearance style of `fa`. If not specified, returns default style.
|
|
func (_babb ImageFieldAppearance )Style ()AppearanceStyle {if _babb ._gafb !=nil {return *_babb ._gafb ;};return AppearanceStyle {BorderSize :0.0,BorderColor :_bg .NewPdfColorDeviceGray (0),FillColor :_bg .NewPdfColorDeviceGray (1),DrawAlignmentReticle :false };
|
|
};func _ebgd (_ebfg *InkAnnotationDef )(*_bf .PdfObjectDictionary ,*_bg .PdfRectangle ,error ){_abae :=_bg .NewXObjectForm ();_cbe ,_fedg ,_fcfbb :=_cbcb (_ebfg );if _fcfbb !=nil {return nil ,nil ,_fcfbb ;};_fcfbb =_abae .SetContentStream (_cbe ,nil );
|
|
if _fcfbb !=nil {return nil ,nil ,_fcfbb ;};_abae .BBox =_fedg .ToPdfObject ();_abae .Resources =_bg .NewPdfPageResources ();_abae .Resources .ProcSet =_bf .MakeArray (_bf .MakeName ("\u0050\u0044\u0046"));_bdad :=_bf .MakeDict ();_bdad .Set ("\u004e",_abae .ToPdfObject ());
|
|
return _bdad ,_fedg ,nil ;};
|
|
|
|
// SetStyle applies appearance `style` to `fa`.
|
|
func (_cbg *FieldAppearance )SetStyle (style AppearanceStyle ){_cbg ._dbce =&style };
|
|
|
|
// InkAnnotationDef holds base information for constructing an ink annotation.
|
|
type InkAnnotationDef struct{
|
|
|
|
// Paths is the array of stroked paths which compose the annotation.
|
|
Paths []_fg .Path ;
|
|
|
|
// Color is the color of the line. Default to black.
|
|
Color *_bg .PdfColorDeviceRGB ;
|
|
|
|
// LineWidth is the width of the line.
|
|
LineWidth float64 ;};func _eggd (_fgg *_bg .PdfPage ,_bgccf _fg .Rectangle ,_afgb string ,_agd string ,_fdag _bg .PdfColor ,_caaa *_bg .PdfFont ,_bffa *float64 ,_begdg _bf .PdfObject )(*_bg .PdfFieldButton ,error ){_bbbe ,_gcd :=_bgccf .X ,_bgccf .Y ;_ffe :=_bgccf .Width ;
|
|
_bfec :=_bgccf .Height ;if _bgccf .FillColor ==nil {_bgccf .FillColor =_bg .NewPdfColorDeviceGray (0.7);};if _fdag ==nil {_fdag =_bg .NewPdfColorDeviceGray (0);};if _caaa ==nil {_gef ,_adf :=_bg .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");
|
|
if _adf !=nil {return nil ,_adf ;};_caaa =_gef ;};_fagf :=_bg .NewPdfField ();_aaf :=&_bg .PdfFieldButton {};_fagf .SetContext (_aaf );_aaf .PdfField =_fagf ;_aaf .T =_bf .MakeString (_afgb );_aaf .SetType (_bg .ButtonTypePush );_aaf .V =_bf .MakeName ("\u004f\u0066\u0066");
|
|
_aaf .Ff =_bf .MakeInteger (4);_caaf :=_bf .MakeDict ();_caaf .Set (*_bf .MakeName ("\u0043\u0041"),_bf .MakeString (_agd ));_aabb ,_adcg :=_caaa .GetFontDescriptor ();if _adcg !=nil {return nil ,_adcg ;};_abg :=_bf .MakeName ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");
|
|
_bda :=12.0;if _aabb !=nil &&_aabb .FontName !=nil {_abg ,_ =_bf .GetName (_aabb .FontName );};if _bffa !=nil {_bda =*_bffa ;};_aaab :=_e .NewContentCreator ();_aaab .Add_q ();_aaab .SetNonStrokingColor (_bgccf .FillColor );_aaab .Add_re (0,0,_ffe ,_bfec );
|
|
_aaab .Add_f ();_aaab .Add_Q ();_aaab .Add_q ();_aaab .Add_BT ();_daaf :=0.0;for _ ,_eecge :=range _agd {_ebfb ,_efda :=_caaa .GetRuneMetrics (_eecge );if !_efda {_f .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",_eecge );
|
|
continue ;};_daaf +=_ebfb .Wx ;};_daaf =_daaf /1000.0*_bda ;var _fbbc float64 ;if _aabb !=nil {_fbbc ,_adcg =_aabb .GetCapHeight ();if _adcg !=nil {_f .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",_adcg );
|
|
};};if int (_fbbc )<=0{_f .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");
|
|
_fbbc =1000;};_aefa :=_fbbc /1000.0*_bda ;_eabe :=(_bfec -_aefa )/2.0;_cdcd :=(_ffe -_daaf )/2.0;_aaab .Add_Tf (*_abg ,_bda );_aaab .SetNonStrokingColor (_fdag );_aaab .Add_Td (_cdcd ,_eabe );_aaab .Add_Tj (*_bf .MakeString (_agd ));_aaab .Add_ET ();_aaab .Add_Q ();
|
|
_acff :=_bg .NewXObjectForm ();_acff .SetContentStream (_aaab .Bytes (),_bf .NewRawEncoder ());_acff .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_ffe ,_bfec });_acff .Resources =_bg .NewPdfPageResources ();_acff .Resources .SetFontByName (*_abg ,_caaa .ToPdfObject ());
|
|
_eaee :=_bf .MakeDict ();_eaee .Set ("\u004e",_acff .ToPdfObject ());_geca :=_bg .NewPdfAnnotationWidget ();_geca .Rect =_bf .MakeArrayFromFloats ([]float64 {_bbbe ,_gcd ,_bbbe +_ffe ,_gcd +_bfec });_geca .P =_fgg .ToPdfObject ();_geca .F =_bf .MakeInteger (4);
|
|
_geca .Parent =_aaf .ToPdfObject ();_geca .A =_begdg ;_geca .MK =_caaf ;_geca .AP =_eaee ;_aaf .Annotations =append (_aaf .Annotations ,_geca );return _aaf ,nil ;};
|
|
|
|
// GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`.
|
|
// Implements interface model.FieldAppearanceGenerator.
|
|
func (_bcde ImageFieldAppearance )GenerateAppearanceDict (form *_bg .PdfAcroForm ,field *_bg .PdfField ,wa *_bg .PdfAnnotationWidget )(*_bf .PdfObjectDictionary ,error ){_ ,_fagg :=field .GetContext ().(*_bg .PdfFieldButton );if !_fagg {_f .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 ;};_caccg ,_gfeg :=_bf .GetDict (wa .AP );if _gfeg &&_bcde .OnlyIfMissing {_f .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 _caccg ,nil ;};if form .DR ==nil {form .DR =_bg .NewPdfPageResources ();};switch _ceba :=field .GetContext ().(type ){case *_bg .PdfFieldButton :if _ceba .IsPush (){_ggfg ,_edab :=_fffc (_ceba ,wa ,_bcde .Style ());if _edab !=nil {return nil ,_edab ;
|
|
};return _ggfg ,nil ;};};return nil ,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 ;};
|
|
|
|
// Style returns the appearance style of `fa`. If not specified, returns default style.
|
|
func (_aa FieldAppearance )Style ()AppearanceStyle {if _aa ._dbce !=nil {return *_aa ._dbce ;};_de :=_cbb ;return AppearanceStyle {AutoFontSizeFraction :0.65,CheckmarkRune :'✔',BorderSize :0.0,BorderColor :_bg .NewPdfColorDeviceGray (0),FillColor :_bg .NewPdfColorDeviceGray (1),MultilineLineHeight :1.2,MultilineVAlignMiddle :false ,DrawAlignmentReticle :false ,AllowMK :true ,MarginLeft :&_de };
|
|
};
|
|
|
|
// CreateFileAttachmentAnnotation creates a file attachment annotation object that can be added to the annotation list of a PDF page.
|
|
func CreateFileAttachmentAnnotation (fileDef FileAnnotationDef )(*_bg .PdfAnnotation ,error ){_daac :=_bg .NewPdfFileSpecFromEmbeddedFile (fileDef .EmbeddedFile );if fileDef .Color ==nil {fileDef .Color =_bg .NewPdfColorDeviceRGB (0.0,0.0,0.0);};if fileDef .Description ==""{fileDef .Description =fileDef .EmbeddedFile .Name ;
|
|
};if fileDef .CreationDate ==nil {_efe :=_be .Now ();fileDef .CreationDate =&_efe ;};if fileDef .IconName ==""{fileDef .IconName ="\u0050u\u0073\u0068\u0050\u0069\u006e";};_ddd ,_bdbe :=_bg .NewPdfDateFromTime (*fileDef .CreationDate );if _bdbe !=nil {return nil ,_bdbe ;
|
|
};_bgag :=_bg .NewPdfAnnotationFileAttachment ();_bgag .FS =_daac .ToPdfObject ();_bgag .C =_bf .MakeArrayFromFloats ([]float64 {fileDef .Color .R (),fileDef .Color .G (),fileDef .Color .B ()});_bgag .Contents =_bf .MakeString (fileDef .Description );_bgag .CreationDate =_ddd .ToPdfObject ();
|
|
_bgag .M =_ddd .ToPdfObject ();_bgag .Name =_bf .MakeName (fileDef .IconName );_bgag .Rect =_bf .MakeArrayFromFloats ([]float64 {fileDef .X ,fileDef .Y ,fileDef .X +fileDef .Width ,fileDef .Y +fileDef .Height });_bgag .T =_bf .MakeString (fileDef .Author );
|
|
_bgag .Subj =_bf .MakeString (fileDef .Subject );return _bgag .PdfAnnotation ,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 ;_dbce *AppearanceStyle ;};func _ccgg (_dabe RectangleAnnotationDef ,_cccd string )([]byte ,*_bg .PdfRectangle ,*_bg .PdfRectangle ,error ){_caee :=_fg .Rectangle {X :0,Y :0,Width :_dabe .Width ,Height :_dabe .Height ,FillEnabled :_dabe .FillEnabled ,FillColor :_dabe .FillColor ,BorderEnabled :_dabe .BorderEnabled ,BorderWidth :2*_dabe .BorderWidth ,BorderColor :_dabe .BorderColor ,Opacity :_dabe .Opacity };
|
|
_dgdf ,_fgbd ,_afe :=_caee .Draw (_cccd );if _afe !=nil {return nil ,nil ,nil ,_afe ;};_cfbcb :=&_bg .PdfRectangle {};_cfbcb .Llx =_dabe .X +_fgbd .Llx ;_cfbcb .Lly =_dabe .Y +_fgbd .Lly ;_cfbcb .Urx =_dabe .X +_fgbd .Urx ;_cfbcb .Ury =_dabe .Y +_fgbd .Ury ;
|
|
return _dgdf ,_fgbd ,_cfbcb ,nil ;};
|
|
|
|
// TextFieldOptions defines optional parameter for a text field in a form.
|
|
type TextFieldOptions struct{MaxLen int ;Value string ;
|
|
|
|
// TextColor defines the color of the text in hex format. e.g #43fd23.
|
|
// If it has an invalid value a #000000 (black) color is taken as default
|
|
TextColor string ;};
|
|
|
|
// SetStyle applies appearance `style` to `fa`.
|
|
func (_egeg *ImageFieldAppearance )SetStyle (style AppearanceStyle ){_egeg ._gafb =&style };func (_bdcc *AppearanceStyle )processDA (_ffb *_bg .PdfField ,_ebe *_e .ContentStreamOperations ,_abag ,_gag *_bg .PdfPageResources ,_ebee *_e .ContentCreator )(*AppearanceFont ,bool ,error ){var _addf *AppearanceFont ;
|
|
var _eeb bool ;if _bdcc .Fonts !=nil {if _bdcc .Fonts .Fallback !=nil {_addf =_bdcc .Fonts .Fallback ;};if _bffb :=_bdcc .Fonts .FieldFallbacks ;_bffb !=nil {if _gae ,_ebb :=_bffb [_ffb .PartialName ()];_ebb {_addf =_gae ;}else if _dad ,_abaa :=_ffb .FullName ();
|
|
_abaa ==nil {if _bgdfg ,_faf :=_bffb [_dad ];_faf {_addf =_bgdfg ;};};};if _addf !=nil {_addf .fillName ();};_eeb =_bdcc .Fonts .ForceReplace ;};var _bfd string ;var _gce float64 ;var _gcfb bool ;if _ebe !=nil {for _ ,_cfg :=range *_ebe {if _cfg .Operand =="\u0054\u0066"&&len (_cfg .Params )==2{if _dcc ,_caad :=_bf .GetNameVal (_cfg .Params [0]);
|
|
_caad {_bfd =_dcc ;};if _ccb ,_dbac :=_bf .GetNumberAsFloat (_cfg .Params [1]);_dbac ==nil {_gce =_ccb ;};_gcfb =true ;continue ;};_ebee .AddOperand (*_cfg );};};var _caceb *AppearanceFont ;var _addfe _bf .PdfObject ;if _eeb &&_addf !=nil {_caceb =_addf ;
|
|
}else {if _abag !=nil &&_bfd !=""{if _bgfa ,_dac :=_abag .GetFontByName (*_bf .MakeName (_bfd ));_dac {if _dae ,_beb :=_bg .NewPdfFontFromPdfObject (_bgfa );_beb ==nil {_addfe =_bgfa ;_caceb =&AppearanceFont {Name :_bfd ,Font :_dae ,Size :_gce };}else {_f .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",_beb );
|
|
};};};if _caceb ==nil &&_addf !=nil {_caceb =_addf ;};if _caceb ==nil {_fbg ,_cef :=_bg .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");if _cef !=nil {return nil ,false ,_cef ;};_caceb =&AppearanceFont {Name :"\u0048\u0065\u006c\u0076",Font :_fbg ,Size :_gce };
|
|
};};if _caceb .Size <=0&&_bdcc .Fonts !=nil &&_bdcc .Fonts .FallbackSize > 0{_caceb .Size =_bdcc .Fonts .FallbackSize ;};_aed :=*_bf .MakeName (_caceb .Name );if _addfe ==nil {_addfe =_caceb .Font .ToPdfObject ();};if _abag !=nil &&!_abag .HasFontByName (_aed ){_abag .SetFontByName (_aed ,_addfe );
|
|
};if _gag !=nil &&!_gag .HasFontByName (_aed ){_gag .SetFontByName (_aed ,_addfe );};return _caceb ,_gcfb ,nil ;};func _bbbbe (_adab LineAnnotationDef ,_cdcc string )([]byte ,*_bg .PdfRectangle ,*_bg .PdfRectangle ,error ){_fffb :=_fg .Line {X1 :0,Y1 :0,X2 :_adab .X2 -_adab .X1 ,Y2 :_adab .Y2 -_adab .Y1 ,LineColor :_adab .LineColor ,Opacity :_adab .Opacity ,LineWidth :_adab .LineWidth ,LineEndingStyle1 :_adab .LineEndingStyle1 ,LineEndingStyle2 :_adab .LineEndingStyle2 };
|
|
_fbc ,_eaad ,_ggb :=_fffb .Draw (_cdcc );if _ggb !=nil {return nil ,nil ,nil ,_ggb ;};_gbg :=&_bg .PdfRectangle {};_gbg .Llx =_adab .X1 +_eaad .Llx ;_gbg .Lly =_adab .Y1 +_eaad .Lly ;_gbg .Urx =_adab .X1 +_eaad .Urx ;_gbg .Ury =_adab .Y1 +_eaad .Ury ;return _fbc ,_eaad ,_gbg ,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 };};
|
|
|
|
// FormSubmitActionOptions holds options for creating a form submit button.
|
|
type FormSubmitActionOptions struct{
|
|
|
|
// Rectangle holds the button position, size, and color.
|
|
Rectangle _fg .Rectangle ;
|
|
|
|
// Url specifies the URL where the fieds will be submitted.
|
|
Url string ;
|
|
|
|
// Label specifies the text that would be displayed on the button.
|
|
Label string ;
|
|
|
|
// LabelColor specifies the button label color.
|
|
LabelColor _bg .PdfColor ;
|
|
|
|
// Font specifies a font used for rendering the button label.
|
|
// When omitted it will fallback to use a Helvetica font.
|
|
Font *_bg .PdfFont ;
|
|
|
|
// FontSize specifies the font size used in rendering the button label.
|
|
// The default font size is 12pt.
|
|
FontSize *float64 ;
|
|
|
|
// Fields specifies list of fields that could be submitted.
|
|
// This list may contain indirect object to fields or field names.
|
|
Fields *_bf .PdfObjectArray ;
|
|
|
|
// IsExclusionList specifies that the fields contain in `Fields` array would not be submitted.
|
|
IsExclusionList bool ;
|
|
|
|
// IncludeEmptyFields specifies if all fields would be submitted even though it's value is empty.
|
|
IncludeEmptyFields bool ;
|
|
|
|
// SubmitAsPDF specifies that the document shall be submitted as PDF.
|
|
// If set then all the other flags shall be ignored.
|
|
SubmitAsPDF bool ;};
|
|
|
|
// CreateInkAnnotation creates an ink annotation object that can be added to the annotation list of a PDF page.
|
|
func CreateInkAnnotation (inkDef InkAnnotationDef )(*_bg .PdfAnnotation ,error ){_fffcg :=_bg .NewPdfAnnotationInk ();_dega :=_bf .MakeArray ();for _ ,_dffbd :=range inkDef .Paths {if _dffbd .Length ()==0{continue ;};_begg :=[]float64 {};for _ ,_abfc :=range _dffbd .Points {_begg =append (_begg ,_abfc .X ,_abfc .Y );
|
|
};_dega .Append (_bf .MakeArrayFromFloats (_begg ));};_fffcg .InkList =_dega ;if inkDef .Color ==nil {inkDef .Color =_bg .NewPdfColorDeviceRGB (0.0,0.0,0.0);};_fffcg .C =_bf .MakeArrayFromFloats ([]float64 {inkDef .Color .R (),inkDef .Color .G (),inkDef .Color .B ()});
|
|
_dffbg ,_dcgf ,_adda :=_ebgd (&inkDef );if _adda !=nil {return nil ,_adda ;};_fffcg .AP =_dffbg ;_fffcg .Rect =_bf .MakeArrayFromFloats ([]float64 {_dcgf .Llx ,_dcgf .Lly ,_dcgf .Urx ,_dcgf .Ury });return _fffcg .PdfAnnotation ,nil ;};func _bbea (_bgcb RectangleAnnotationDef )(*_bf .PdfObjectDictionary ,*_bg .PdfRectangle ,error ){_baed :=_bg .NewXObjectForm ();
|
|
_baed .Resources =_bg .NewPdfPageResources ();_fded :="";if _bgcb .Opacity < 1.0{_fbfg :=_bf .MakeDict ();_fbfg .Set ("\u0063\u0061",_bf .MakeFloat (_bgcb .Opacity ));_fbfg .Set ("\u0043\u0041",_bf .MakeFloat (_bgcb .Opacity ));_bdcdcc :=_baed .Resources .AddExtGState ("\u0067\u0073\u0031",_fbfg );
|
|
if _bdcdcc !=nil {_f .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 ,_bdcdcc ;};_fded ="\u0067\u0073\u0031";};_edac ,_ddbc ,_cgaf ,_egdd :=_ccgg (_bgcb ,_fded );
|
|
if _egdd !=nil {return nil ,nil ,_egdd ;};_egdd =_baed .SetContentStream (_edac ,nil );if _egdd !=nil {return nil ,nil ,_egdd ;};_baed .BBox =_ddbc .ToPdfObject ();_fecg :=_bf .MakeDict ();_fecg .Set ("\u004e",_baed .ToPdfObject ());return _fecg ,_cgaf ,nil ;
|
|
};func _cge (_cbdg *_bg .PdfAnnotationWidget ,_ebd *_bg .PdfFieldText ,_dbb *_bg .PdfPageResources ,_aegf AppearanceStyle )(*_bf .PdfObjectDictionary ,error ){_dffb :=_bg .NewPdfPageResources ();_dgf ,_ded :=_bf .GetArray (_cbdg .Rect );if !_ded {return nil ,_bc .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");
|
|
};_eabd ,_dfgb :=_bg .NewPdfRectangle (*_dgf );if _dfgb !=nil {return nil ,_dfgb ;};_fcf ,_dafd :=_eabd .Width (),_eabd .Height ();_cbag ,_bacf :=_fcf ,_dafd ;_bgcc ,_bec :=_bf .GetDict (_cbdg .MK );if _bec {_dab ,_ :=_bf .GetDict (_cbdg .BS );_fcd :=_aegf .applyAppearanceCharacteristics (_bgcc ,_dab ,nil );
|
|
if _fcd !=nil {return nil ,_fcd ;};};_eae ,_bec :=_bf .GetIntVal (_ebd .MaxLen );if !_bec {return nil ,_bc .New ("\u006d\u0061\u0078\u006c\u0065\u006e\u0020\u006e\u006ft\u0020\u0073\u0065\u0074");};if _eae <=0{return nil ,_bc .New ("\u006d\u0061\u0078\u004c\u0065\u006e\u0020\u0069\u006ev\u0061\u006c\u0069\u0064");
|
|
};_cace :=_fcf /float64 (_eae );_ff ,_dfgb :=_e .NewContentStreamParser (_efcf (_ebd .PdfField )).Parse ();if _dfgb !=nil {return nil ,_dfgb ;};_dbff :=_e .NewContentCreator ();if _aegf .BorderSize > 0{_ebaf (_dbff ,_aegf ,_fcf ,_dafd );};if _aegf .DrawAlignmentReticle {_fda :=_aegf ;
|
|
_fda .BorderSize =0.2;_dabd (_dbff ,_fda ,_fcf ,_dafd );};_dbff .Add_BMC ("\u0054\u0078");_dbff .Add_q ();_ ,_dafd =_aegf .applyRotation (_bgcc ,_fcf ,_dafd ,_dbff );_dbff .Add_BT ();_agba ,_cgb ,_dfgb :=_aegf .processDA (_ebd .PdfField ,_ff ,_dbb ,_dffb ,_dbff );
|
|
if _dfgb !=nil {return nil ,_dfgb ;};_eac :=_agba .Font ;_affe :=_bf .MakeName (_agba .Name );_cea :=_agba .Size ;_fdad :=_cea ==0;if _fdad &&_cgb {_cea =_dafd *_aegf .AutoFontSizeFraction ;};_bcfb :=_eac .Encoder ();if _bcfb ==nil {_f .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");
|
|
_bcfb =_cf .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};var _adee string ;if _gca ,_egc :=_bf .GetString (_ebd .V );_egc {_adee =_gca .Decoded ();};_dbff .Add_Tf (*_affe ,_cea );var _aca float64 ;for _ ,_fcdg :=range _adee {_ecb ,_cfd :=_eac .GetRuneMetrics (_fcdg );
|
|
if !_cfd {_f .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",_fcdg );
|
|
continue ;};_cdd :=_ecb .Wy ;if int (_cdd )<=0{_cdd =_ecb .Wx ;};if _cdd > _aca {_aca =_cdd ;};};if int (_aca )==0{_f .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");
|
|
_aca =1000;};_ggggd ,_dfgb :=_eac .GetFontDescriptor ();if _dfgb !=nil {_f .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 _efb float64 ;if _ggggd !=nil {_efb ,_dfgb =_ggggd .GetCapHeight ();if _dfgb !=nil {_f .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",_dfgb );
|
|
};};if int (_efb )<=0{_f .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");
|
|
_efb =1000.0;};_aef :=_efb /1000.0*_cea ;_gece :=0.0;_ace :=1.0*_cea *(_aca /1000.0);{_faa :=_ace ;if _fdad &&_gece +_faa > _dafd {_cea =0.95*(_dafd -_gece );_aef =_efb /1000.0*_cea ;};if _dafd > _aef {_gece =(_dafd -_aef )/2.0;};};_dbff .Add_Td (0,_gece );
|
|
if _dcg ,_dca :=_bf .GetIntVal (_ebd .Q );_dca {switch _dcg {case 2:if len (_adee )< _eae {_ebdb :=float64 (_eae -len (_adee ))*_cace ;_dbff .Add_Td (_ebdb ,0);};};};for _dgc ,_bgac :=range _adee {_abb :=_cbb ;if _aegf .MarginLeft !=nil {_abb =*_aegf .MarginLeft ;
|
|
};_eec :=string (_bgac );if _bcfb !=nil {_aacb ,_dedg :=_eac .GetRuneMetrics (_bgac );if !_dedg {_f .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",_bgac );
|
|
continue ;};_eec =string (_bcfb .Encode (_eec ));_aeaa :=_cea *_aacb .Wx /1000.0;_edf :=(_cace -_aeaa )/2;_abb =_edf ;};_dbff .Add_Td (_abb ,0);_dbff .Add_Tj (*_bf .MakeString (_eec ));if _dgc !=len (_adee )-1{_dbff .Add_Td (_cace -_abb ,0);};};_dbff .Add_ET ();
|
|
_dbff .Add_Q ();_dbff .Add_EMC ();_bbg :=_bg .NewXObjectForm ();_bbg .Resources =_dffb ;_bbg .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_cbag ,_bacf });_bbg .SetContentStream (_dbff .Bytes (),_eabc ());_dfc :=_bf .MakeDict ();_dfc .Set ("\u004e",_bbg .ToPdfObject ());
|
|
return _dfc ,nil ;};func _edd (_fegb [][]_fg .CubicBezierCurve ,_bdd *_bg .PdfColorDeviceRGB ,_gggdd float64 )([]byte ,*_bg .PdfRectangle ,error ){_edec :=_e .NewContentCreator ();_edec .Add_q ().SetStrokingColor (_bdd ).Add_w (_gggdd );_aeag :=_fg .NewCubicBezierPath ();
|
|
for _ ,_ddad :=range _fegb {_aeag .Curves =append (_aeag .Curves ,_ddad ...);for _ebfa ,_edgcc :=range _ddad {if _ebfa ==0{_edec .Add_m (_edgcc .P0 .X ,_edgcc .P0 .Y );}else {_edec .Add_l (_edgcc .P0 .X ,_edgcc .P0 .Y );};_edec .Add_c (_edgcc .P1 .X ,_edgcc .P1 .Y ,_edgcc .P2 .X ,_edgcc .P2 .Y ,_edgcc .P3 .X ,_edgcc .P3 .Y );
|
|
};};_edec .Add_S ().Add_Q ();return _edec .Bytes (),_aeag .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
|
|
|
// 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 *_bg .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_bg .PdfColorDeviceRGB ;Opacity float64 ;};
|
|
|
|
// SignatureLine represents a line of information in the signature field appearance.
|
|
type SignatureLine struct{Desc string ;Text string ;};func _dabd (_acf *_e .ContentCreator ,_ffgd AppearanceStyle ,_cbfb ,_fagb float64 ){_acf .Add_q ().Add_re (0,0,_cbfb ,_fagb ).Add_re (0,_fagb /2,_cbfb ,_fagb /2).Add_re (0,0,_cbfb ,_fagb ).Add_re (_cbfb /2,0,_cbfb /2,_fagb ).Add_w (_ffgd .BorderSize ).SetStrokingColor (_ffgd .BorderColor ).SetNonStrokingColor (_ffgd .FillColor ).Add_B ().Add_Q ();
|
|
};
|
|
|
|
// CreateLineAnnotation creates a line annotation object that can be added to page PDF annotations.
|
|
func CreateLineAnnotation (lineDef LineAnnotationDef )(*_bg .PdfAnnotation ,error ){_efdag :=_bg .NewPdfAnnotationLine ();_efdag .L =_bf .MakeArrayFromFloats ([]float64 {lineDef .X1 ,lineDef .Y1 ,lineDef .X2 ,lineDef .Y2 });_cggc :=_bf .MakeName ("\u004e\u006f\u006e\u0065");
|
|
if lineDef .LineEndingStyle1 ==_fg .LineEndingStyleArrow {_cggc =_bf .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");};_bebg :=_bf .MakeName ("\u004e\u006f\u006e\u0065");if lineDef .LineEndingStyle2 ==_fg .LineEndingStyleArrow {_bebg =_bf .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");
|
|
};_efdag .LE =_bf .MakeArray (_cggc ,_bebg );if lineDef .Opacity < 1.0{_efdag .CA =_bf .MakeFloat (lineDef .Opacity );};_ccbb ,_eecgb ,_ecda :=lineDef .LineColor .R (),lineDef .LineColor .G (),lineDef .LineColor .B ();_efdag .IC =_bf .MakeArrayFromFloats ([]float64 {_ccbb ,_eecgb ,_ecda });
|
|
_efdag .C =_bf .MakeArrayFromFloats ([]float64 {_ccbb ,_eecgb ,_ecda });_ddecf :=_bg .NewBorderStyle ();_ddecf .SetBorderWidth (lineDef .LineWidth );_efdag .BS =_ddecf .ToPdfObject ();_aafb ,_cgfb ,_dada :=_fcbfb (lineDef );if _dada !=nil {return nil ,_dada ;
|
|
};_efdag .AP =_aafb ;_efdag .Rect =_bf .MakeArrayFromFloats ([]float64 {_cgfb .Llx ,_cgfb .Lly ,_cgfb .Urx ,_cgfb .Ury });return _efdag .PdfAnnotation ,nil ;};
|
|
|
|
// CreateRectangleAnnotation creates a rectangle annotation object that can be added to page PDF annotations.
|
|
func CreateRectangleAnnotation (rectDef RectangleAnnotationDef )(*_bg .PdfAnnotation ,error ){_gafa :=_bg .NewPdfAnnotationSquare ();if rectDef .BorderEnabled {_ddeg ,_gbcd ,_dffa :=rectDef .BorderColor .R (),rectDef .BorderColor .G (),rectDef .BorderColor .B ();
|
|
_gafa .C =_bf .MakeArrayFromFloats ([]float64 {_ddeg ,_gbcd ,_dffa });_babbd :=_bg .NewBorderStyle ();_babbd .SetBorderWidth (rectDef .BorderWidth );_gafa .BS =_babbd .ToPdfObject ();};if rectDef .FillEnabled {_ebecc ,_gcee ,_babe :=rectDef .FillColor .R (),rectDef .FillColor .G (),rectDef .FillColor .B ();
|
|
_gafa .IC =_bf .MakeArrayFromFloats ([]float64 {_ebecc ,_gcee ,_babe });}else {_gafa .IC =_bf .MakeArrayFromIntegers ([]int {});};if rectDef .Opacity < 1.0{_gafa .CA =_bf .MakeFloat (rectDef .Opacity );};_cab ,_aadd ,_dcbg :=_bbea (rectDef );if _dcbg !=nil {return nil ,_dcbg ;
|
|
};_gafa .AP =_cab ;_gafa .Rect =_bf .MakeArrayFromFloats ([]float64 {_aadd .Llx ,_aadd .Lly ,_aadd .Urx ,_aadd .Ury });return _gafa .PdfAnnotation ,nil ;};
|
|
|
|
// GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`.
|
|
// Implements interface model.FieldAppearanceGenerator.
|
|
func (_ggg FieldAppearance )GenerateAppearanceDict (form *_bg .PdfAcroForm ,field *_bg .PdfField ,wa *_bg .PdfAnnotationWidget )(*_bf .PdfObjectDictionary ,error ){_f .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 );
|
|
_ ,_egf :=field .GetContext ().(*_bg .PdfFieldText );_ec ,_fec :=_bf .GetDict (wa .AP );if _fec &&_ggg .OnlyIfMissing &&(!_egf ||!_ggg .RegenerateTextFields ){_f .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 _ec ,nil ;};if form .DR ==nil {form .DR =_bg .NewPdfPageResources ();};switch _gggg :=field .GetContext ().(type ){case *_bg .PdfFieldText :_cfbb :=_gggg ;if _ab :=_efcf (_cfbb .PdfField );_ab ==""{_cfbb .DA =form .DA ;};if _ggg ._dbce !=nil &&_ggg ._dbce .TextColor !=nil {_ggd :=_e .ContentStreamOperations {};
|
|
_da :=_efcf (_cfbb .PdfField );_fbd ,_daf :=_e .NewContentStreamParser (_da ).Parse ();if _daf !=nil {return nil ,_daf ;};for _ ,_ad :=range *_fbd {if _ad .Operand =="\u0067"||_ad .Operand =="\u0072\u0067"{continue ;};_ggd =append (_ggd ,_ad );};_dd :=_ggg ._dbce .TextColor ;
|
|
_ge ,_df :=_dd .(*_bg .PdfColorDeviceRGB );if !_df {return nil ,_daf ;};_aac ,_ca ,_ef :=_bf .MakeFloat (_ge [0]),_bf .MakeFloat (_ge [1]),_bf .MakeFloat (_ge [2]);_ecf :=&_e .ContentStreamOperation {Params :[]_bf .PdfObject {_aac ,_ca ,_ef },Operand :"\u0072\u0067"};
|
|
_ggd =append (_ggd ,_ecf );_bcd :=_ggd .String ();_bcd =_ed .Replace (_bcd ,"\u000a","\u0020",-1);_bcd =_ed .Trim (_bcd ,"\u0020");_cfbb .DA =_bf .MakeHexString (_bcd );};switch {case _cfbb .Flags ().Has (_bg .FieldFlagPassword ):return nil ,nil ;case _cfbb .Flags ().Has (_bg .FieldFlagFileSelect ):return nil ,nil ;
|
|
case _cfbb .Flags ().Has (_bg .FieldFlagComb ):if _cfbb .MaxLen !=nil {_baa ,_gcg :=_cge (wa ,_cfbb ,form .DR ,_ggg .Style ());if _gcg !=nil {return nil ,_gcg ;};return _baa ,nil ;};};_bgf ,_dfg :=_gec (wa ,_cfbb ,form .DR ,_ggg .Style ());if _dfg !=nil {return nil ,_dfg ;
|
|
};return _bgf ,nil ;case *_bg .PdfFieldButton :_acg :=_gggg ;if _acg .IsCheckbox (){_ce ,_gcb :=_bbgc (wa ,_acg ,form .DR ,_ggg .Style ());if _gcb !=nil {return nil ,_gcb ;};return _ce ,nil ;};_f .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",_acg .GetType ());
|
|
case *_bg .PdfFieldChoice :_dbf :=_gggg ;switch {case _dbf .Flags ().Has (_bg .FieldFlagCombo ):_bga ,_add :=_abbe (form ,wa ,_dbf ,_ggg .Style ());if _add !=nil {return nil ,_add ;};return _bga ,nil ;default:_f .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",_dbf .Flags ().String ());
|
|
};default:_f .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",_gggg );};return nil ,nil ;};func _gec (_egg *_bg .PdfAnnotationWidget ,_age *_bg .PdfFieldText ,_ceg *_bg .PdfPageResources ,_ecfe AppearanceStyle )(*_bf .PdfObjectDictionary ,error ){_ega :=_bg .NewPdfPageResources ();
|
|
_baf ,_fdf :=_bf .GetArray (_egg .Rect );if !_fdf {return nil ,_bc .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_aff ,_cd :=_bg .NewPdfRectangle (*_baf );if _cd !=nil {return nil ,_cd ;};_cac ,_dba :=_aff .Width (),_aff .Height ();
|
|
_fed ,_afb :=_cac ,_dba ;_eb :=true ;_fdfc :=_bg .NewXObjectForm ();_fdfc .BBox =_bf .MakeArrayFromFloats ([]float64 {0,0,_fed ,_afb });if _egg .AP !=nil {if _cba ,_dff :=_bf .GetDict (_egg .AP );_dff &&_cba !=nil {_ecg :=_bf .TraceToDirectObject (_cba .Get ("\u004e"));
|
|
switch _ecge :=_ecg .(type ){case *_bf .PdfObjectStream :_agb ,_bgd :=_bf .DecodeStream (_ecge );if _bgd !=nil {_f .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",_bgd .Error ());
|
|
break ;};_beg ,_bgd :=_e .NewContentStreamParser (string (_agb )).Parse ();if _bgd !=nil {_f .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",_bgd .Error ());
|
|
break ;};_bccf :=_e .NewContentStreamProcessor (*_beg );_bccf .AddHandler (_e .HandlerConditionEnumAllOperands ,"",func (_fbbf *_e .ContentStreamOperation ,_edg _e .GraphicsState ,_fdg *_bg .PdfPageResources )error {if _fbbf .Operand =="\u0054\u006a"||_fbbf .Operand =="\u0054\u004a"{if len (_fbbf .Params )==1{if _fae ,_bgged :=_bf .GetString (_fbbf .Params [0]);
|
|
_bgged {_eb =_ed .TrimSpace (_fae .Str ())=="";};return _e .ErrEarlyExit ;};return nil ;};return nil ;});_bccf .Process (_ega );if !_eb {if _abf ,_gbc :=_bf .GetDict (_ecge .Get ("\u0052e\u0073\u006f\u0075\u0072\u0063\u0065s"));_gbc {_ega ,_bgd =_bg .NewPdfPageResourcesFromDict (_abf );
|
|
if _bgd !=nil {return nil ,_bgd ;};};if _afbg ,_aad :=_bf .GetArray (_ecge .Get ("\u004d\u0061\u0074\u0072\u0069\u0078"));_aad {_fdfc .Matrix =_afbg ;};_fdfc .SetContentStream (_agb ,_eabc ());};};};};if _eb {_bbb ,_ddg :=_bf .GetDict (_egg .MK );if _ddg {_bege ,_ :=_bf .GetDict (_egg .BS );
|
|
_bcf :=_ecfe .applyAppearanceCharacteristics (_bbb ,_bege ,nil );if _bcf !=nil {return nil ,_bcf ;};};_cbd ,_cff :=_e .NewContentStreamParser (_efcf (_age .PdfField )).Parse ();if _cff !=nil {return nil ,_cff ;};_gfa :=_e .NewContentCreator ();if _ecfe .BorderSize > 0{_ebaf (_gfa ,_ecfe ,_cac ,_dba );
|
|
};if _ecfe .DrawAlignmentReticle {_cbf :=_ecfe ;_cbf .BorderSize =0.2;_dabd (_gfa ,_cbf ,_cac ,_dba );};_gfa .Add_BMC ("\u0054\u0078");_gfa .Add_q ();_cac ,_dba =_ecfe .applyRotation (_bbb ,_cac ,_dba ,_gfa );_gfa .Add_BT ();_ade ,_egd ,_cff :=_ecfe .processDA (_age .PdfField ,_cbd ,_ceg ,_ega ,_gfa );
|
|
if _cff !=nil {return nil ,_cff ;};_bbf :=_ade .Font ;_fcb :=_ade .Size ;_ea :=_bf .MakeName (_ade .Name );if _age .Flags ().Has (_bg .FieldFlagMultiline )&&_age .MaxLen !=nil {_f .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 _dde ,_bgb ,_edgc :=_cbde (_egg .PdfAnnotation .AP ,_ceg );_edgc {_ea =_dde ;_fcb =_bgb ;_egd =true ;};};_gde :=_fcb ==0;if _gde &&_egd {_fcb =_dba *_ecfe .AutoFontSizeFraction ;};_cae :=_bbf .Encoder ();if _cae ==nil {_f .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");
|
|
_cae =_cf .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};_bgdf ,_cff :=_bbf .GetFontDescriptor ();if _cff !=nil {_f .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 _gba string ;if _caa ,_abe :=_bf .GetString (_age .V );_abe {_gba =_caa .Decoded ();};if len (_gba )==0{return nil ,nil ;};_fgf :=[]string {_gba };_fad :=false ;if _age .Flags ().Has (_bg .FieldFlagMultiline ){_fad =true ;_gba =_ed .Replace (_gba ,"\u000d\u000a","\u000a",-1);
|
|
_gba =_ed .Replace (_gba ,"\u000d","\u000a",-1);_fgf =_ed .Split (_gba ,"\u000a");};_aae :=make ([]string ,len (_fgf ));copy (_aae ,_fgf );_fcc :=_ecfe .MultilineLineHeight ;_aec :=0.0;_gggd :=0;if _cae !=nil {for _fcb >=0{_cfad :=make ([]string ,len (_fgf ));
|
|
copy (_cfad ,_fgf );_cad :=make ([]string ,len (_aae ));copy (_cad ,_aae );_aec =0.0;_gggd =0;_gcba :=len (_cfad );_begd :=0;for _begd < _gcba {var _gff float64 ;_daa :=-1;_ggf :=_cbb ;if _ecfe .MarginLeft !=nil {_ggf =*_ecfe .MarginLeft ;};for _bafg ,_fge :=range _cfad [_begd ]{if _fge ==' '{_daa =_bafg ;
|
|
};_ga ,_ebg :=_bbf .GetRuneMetrics (_fge );if !_ebg {_f .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",_fge );
|
|
continue ;};_gff =_ggf ;_ggf +=_ga .Wx ;if _fad &&!_gde &&_fcb *_ggf /1000.0> _cac {_dg :=_bafg ;_ddf :=_bafg ;if _daa > 0{_dg =_daa +1;_ddf =_daa ;};_bce :=_cfad [_begd ][_dg :];_cbdf :=_cad [_begd ][_dg :];if _begd < len (_cfad )-1{_cfad =append (_cfad [:_begd +1],_cfad [_begd :]...);
|
|
_cfad [_begd +1]=_bce ;_cad =append (_cad [:_begd +1],_cad [_begd :]...);_cad [_begd +1]=_cbdf ;}else {_cfad =append (_cfad ,_bce );_cad =append (_cad ,_cbdf );};_cfad [_begd ]=_cfad [_begd ][0:_ddf ];_cad [_begd ]=_cad [_begd ][0:_ddf ];_gcba ++;_ggf =_gff ;
|
|
break ;};};if _ggf > _aec {_aec =_ggf ;};_cfad [_begd ]=string (_cae .Encode (_cfad [_begd ]));if len (_cfad [_begd ])> 0{_gggd ++;};_begd ++;};_cbgf :=_fcb ;if _gggd > 1{_cbgf *=_fcc ;};_cdf :=float64 (_gggd )*_cbgf ;if _gde ||_cdf <=_dba {_fgf =_cfad ;
|
|
_aae =_cad ;break ;};_fcb --;};};_cbab :=_cbb ;if _ecfe .MarginLeft !=nil {_cbab =*_ecfe .MarginLeft ;};if _fcb ==0||_gde &&_aec > 0&&_cbab +_aec *_fcb /1000.0> _cac {_fcb =0.95*1000.0*(_cac -_cbab )/_aec ;};_fde :=_gc ;{if _bff ,_bcb :=_bf .GetIntVal (_age .Q );
|
|
_bcb {switch _bff {case 0:_fde =_gc ;case 1:_fde =_bgge ;case 2:_fde =_fc ;default:_f .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",_bff );
|
|
};};};_ebf :=_fcb ;if _fad &&_gggd > 1{_ebf =_fcc *_fcb ;};var _gbf float64 ;if _bgdf !=nil {_gbf ,_cff =_bgdf .GetCapHeight ();if _cff !=nil {_f .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",_cff );
|
|
};};if int (_gbf )<=0{_f .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");
|
|
_gbf =1000;};_gaf :=_gbf /1000.0*_fcb ;_gdc :=0.0;{_ee :=float64 (_gggd )*_ebf ;if _gde &&_gdc +_ee > _dba {_fcb =0.95*(_dba -_gdc )/float64 (_gggd );_ebf =_fcb ;if _fad &&_gggd > 1{_ebf =_fcc *_fcb ;};_gaf =_gbf /1000.0*_fcb ;_ee =float64 (_gggd )*_ebf ;
|
|
};if _dba > _ee {if _fad {if _ecfe .MultilineVAlignMiddle {_bd :=(_dba -(_ee +_gaf ))/2.0;_edad :=_bd +_ee +_gaf -_ebf ;_gdc =_edad ;if _gggd > 1{_gdc =_gdc +(_ee /_fcb *float64 (_gggd ))-_ebf -_gaf ;};if _gdc < _ee {_gdc =(_dba -_gaf )/2.0;};}else {_gdc =_dba -_ebf ;
|
|
if _gdc > _fcb {_dbag :=0.0;if _fad &&_ecfe .MultilineLineHeight > 1&&_gggd > 1{_dbag =_ecfe .MultilineLineHeight -1;};_gdc -=_fcb *(0.5-_dbag );};};}else {_gdc =(_dba -_gaf )/2.0;};};};if _ecfe .TextColor !=nil {_dag :=_ecfe .TextColor ;_gfd ,_gge :=_dag .(*_bg .PdfColorDeviceRGB );
|
|
if !_gge {_gfd =_bg .NewPdfColorDeviceRGB (0,0,0);};_gfa .Add_rg (_gfd .R (),_gfd .G (),_gfd .B ());}else {for _ ,_abc :=range *_cbd {if _abc .Operand =="\u0072\u0067"||_abc .Operand =="\u0067"{_gfa .AddOperand (*_abc );};};};_gfa .Add_Tf (*_ea ,_fcb );
|
|
_gfa .Add_Td (_cbab ,_gdc );_gafd :=_cbab ;_eea :=_cbab ;for _cdc ,_dc :=range _fgf {_eab :=0.0;for _ ,_efg :=range _aae [_cdc ]{_gbb ,_bbe :=_bbf .GetRuneMetrics (_efg );if !_bbe {continue ;};_eab +=_gbb .Wx ;};_ddfd :=_eab /1000.0*_fcb ;_begb :=_cac -_ddfd ;
|
|
var _deb float64 ;switch _fde {case _gc :_deb =_gafd ;case _bgge :_deb =_begb /2;case _fc :_deb =_begb ;};_cbab =_deb -_eea ;if _cbab > 0.0{_gfa .Add_Td (_cbab ,0);};_eea =_deb ;_gfa .Add_Tj (*_bf .MakeString (_dc ));if _cdc < len (_fgf )-1{_gfa .Add_Td (0,-_fcb *_fcc );
|
|
};};_gfa .Add_ET ();_gfa .Add_Q ();_gfa .Add_EMC ();_fdfc .SetContentStream (_gfa .Bytes (),_eabc ());};_fdfc .Resources =_ega ;_cbdfg :=_bf .MakeDict ();_cbdfg .Set ("\u004e",_fdfc .ToPdfObject ());return _cbdfg ,nil ;}; |