mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +08:00
212 lines
56 KiB
Go
212 lines
56 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 (_ff "bytes";_b "errors";_d "github.com/unidoc/unipdf/v3/common";_a "github.com/unidoc/unipdf/v3/contentstream";_dbe "github.com/unidoc/unipdf/v3/contentstream/draw";_bd "github.com/unidoc/unipdf/v3/core";_e "github.com/unidoc/unipdf/v3/internal/textencoding";_gc "github.com/unidoc/unipdf/v3/model";_ed "image";_g "math";_db "strings";_fc "unicode";);func _cd (_cc CircleAnnotationDef ,_ab string )([]byte ,*_gc .PdfRectangle ,*_gc .PdfRectangle ,error ){_ebg :=_dbe .Circle {X :_cc .X ,Y :_cc .Y ,Width :_cc .Width ,Height :_cc .Height ,FillEnabled :_cc .FillEnabled ,FillColor :_cc .FillColor ,BorderEnabled :_cc .BorderEnabled ,BorderWidth :_cc .BorderWidth ,BorderColor :_cc .BorderColor ,Opacity :_cc .Opacity };_cf ,_bbfc ,_fe :=_ebg .Draw (_ab );if _fe !=nil {return nil ,nil ,nil ,_fe ;};_aa :=&_gc .PdfRectangle {};_aa .Llx =_cc .X +_bbfc .Llx ;_aa .Lly =_cc .Y +_bbfc .Lly ;_aa .Urx =_cc .X +_bbfc .Urx ;_aa .Ury =_cc .Y +_bbfc .Ury ;return _cf ,_bbfc ,_aa ,nil ;};
|
|
|
|
// NewTextField generates a new text field with partial name `name` at location
|
|
// specified by `rect` on given `page` and with field specific options `opt`.
|
|
func NewTextField (page *_gc .PdfPage ,name string ,rect []float64 ,opt TextFieldOptions )(*_gc .PdfFieldText ,error ){if page ==nil {return nil ,_b .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};if len (name )<=0{return nil ,_b .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 ,_b .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");};_dff :=_gc .NewPdfField ();_gcbe :=&_gc .PdfFieldText {};_dff .SetContext (_gcbe );_gcbe .PdfField =_dff ;_gcbe .T =_bd .MakeString (name );if opt .MaxLen > 0{_gcbe .MaxLen =_bd .MakeInteger (int64 (opt .MaxLen ));};if len (opt .Value )> 0{_gcbe .V =_bd .MakeString (opt .Value );};_eae :=_gc .NewPdfAnnotationWidget ();_eae .Rect =_bd .MakeArrayFromFloats (rect );_eae .P =page .ToPdfObject ();_eae .F =_bd .MakeInteger (4);_eae .Parent =_gcbe .ToPdfObject ();_gcbe .Annotations =append (_gcbe .Annotations ,_eae );return _gcbe ,nil ;};
|
|
|
|
// AppearanceStyle defines style parameters for appearance stream generation.
|
|
type AppearanceStyle struct{
|
|
|
|
// How much of Rect height to fill when autosizing text.
|
|
AutoFontSizeFraction float64 ;
|
|
|
|
// CheckmarkRune is a rune used for check mark in checkboxes (for ZapfDingbats font).
|
|
CheckmarkRune rune ;BorderSize float64 ;BorderColor _gc .PdfColor ;FillColor _gc .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 ;};
|
|
|
|
// CheckboxFieldOptions defines optional parameters for a checkbox field a form.
|
|
type CheckboxFieldOptions struct{Checked bool ;};const (SignatureImageLeft SignatureImagePosition =iota ;SignatureImageRight ;SignatureImageTop ;SignatureImageBottom ;);func _acg (_fgbe *_a .ContentCreator ,_cag AppearanceStyle ,_cfba ,_cfbe float64 ){_fgbe .Add_q ().Add_re (0,0,_cfba ,_cfbe ).Add_re (0,_cfbe /2,_cfba ,_cfbe /2).Add_re (0,0,_cfba ,_cfbe ).Add_re (_cfba /2,0,_cfba /2,_cfbe ).Add_w (_cag .BorderSize ).SetStrokingColor (_cag .BorderColor ).SetNonStrokingColor (_cag .FillColor ).Add_B ().Add_Q ();};
|
|
|
|
// Style returns the appearance style of `fa`. If not specified, returns default style.
|
|
func (_cce FieldAppearance )Style ()AppearanceStyle {if _cce ._gb !=nil {return *_cce ._gb ;};return AppearanceStyle {AutoFontSizeFraction :0.65,CheckmarkRune :'✔',BorderSize :0.0,BorderColor :_gc .NewPdfColorDeviceGray (0),FillColor :_gc .NewPdfColorDeviceGray (1),MultilineLineHeight :1.2,MultilineVAlignMiddle :false ,DrawAlignmentReticle :false ,AllowMK :true };};func _dgcd (_gfbb RectangleAnnotationDef )(*_bd .PdfObjectDictionary ,*_gc .PdfRectangle ,error ){_dged :=_gc .NewXObjectForm ();_dged .Resources =_gc .NewPdfPageResources ();_cfad :="";if _gfbb .Opacity < 1.0{_aeg :=_bd .MakeDict ();_aeg .Set ("\u0063\u0061",_bd .MakeFloat (_gfbb .Opacity ));_aeg .Set ("\u0043\u0041",_bd .MakeFloat (_gfbb .Opacity ));_adeb :=_dged .Resources .AddExtGState ("\u0067\u0073\u0031",_aeg );if _adeb !=nil {_d .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 ,_adeb ;};_cfad ="\u0067\u0073\u0031";};_cfef ,_ccf ,_cfc ,_cee :=_eaga (_gfbb ,_cfad );if _cee !=nil {return nil ,nil ,_cee ;};_cee =_dged .SetContentStream (_cfef ,nil );if _cee !=nil {return nil ,nil ,_cee ;};_dged .BBox =_ccf .ToPdfObject ();_deb :=_bd .MakeDict ();_deb .Set ("\u004e",_dged .ToPdfObject ());return _deb ,_cfc ,nil ;};func _gecg (_eab *_a .ContentCreator ,_abbe AppearanceStyle ,_bfc ,_caf float64 ){_eab .Add_q ().Add_re (0,0,_bfc ,_caf ).Add_w (_abbe .BorderSize ).SetStrokingColor (_abbe .BorderColor ).SetNonStrokingColor (_abbe .FillColor ).Add_B ().Add_Q ();};func _bcdg (_ebeg LineAnnotationDef )(*_bd .PdfObjectDictionary ,*_gc .PdfRectangle ,error ){_dbg :=_gc .NewXObjectForm ();_dbg .Resources =_gc .NewPdfPageResources ();_adgf :="";if _ebeg .Opacity < 1.0{_dcbb :=_bd .MakeDict ();_dcbb .Set ("\u0063\u0061",_bd .MakeFloat (_ebeg .Opacity ));_fbg :=_dbg .Resources .AddExtGState ("\u0067\u0073\u0031",_dcbb );if _fbg !=nil {_d .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 ,_fbg ;};_adgf ="\u0067\u0073\u0031";};_dbegb ,_cfbg ,_gaed ,_eecc :=_agead (_ebeg ,_adgf );if _eecc !=nil {return nil ,nil ,_eecc ;};_eecc =_dbg .SetContentStream (_dbegb ,nil );if _eecc !=nil {return nil ,nil ,_eecc ;};_dbg .BBox =_cfbg .ToPdfObject ();_ggag :=_bd .MakeDict ();_ggag .Set ("\u004e",_dbg .ToPdfObject ());return _ggag ,_gaed ,nil ;};func _eaga (_cgb RectangleAnnotationDef ,_caff string )([]byte ,*_gc .PdfRectangle ,*_gc .PdfRectangle ,error ){_fecd :=_dbe .Rectangle {X :0,Y :0,Width :_cgb .Width ,Height :_cgb .Height ,FillEnabled :_cgb .FillEnabled ,FillColor :_cgb .FillColor ,BorderEnabled :_cgb .BorderEnabled ,BorderWidth :2*_cgb .BorderWidth ,BorderColor :_cgb .BorderColor ,Opacity :_cgb .Opacity };_acgb ,_ffae ,_gfegd :=_fecd .Draw (_caff );if _gfegd !=nil {return nil ,nil ,nil ,_gfegd ;};_efae :=&_gc .PdfRectangle {};_efae .Llx =_cgb .X +_ffae .Llx ;_efae .Lly =_cgb .Y +_ffae .Lly ;_efae .Urx =_cgb .X +_ffae .Urx ;_efae .Ury =_cgb .Y +_ffae .Ury ;return _acgb ,_ffae ,_efae ,nil ;};func _agead (_feg LineAnnotationDef ,_baac string )([]byte ,*_gc .PdfRectangle ,*_gc .PdfRectangle ,error ){_cba :=_dbe .Line {X1 :0,Y1 :0,X2 :_feg .X2 -_feg .X1 ,Y2 :_feg .Y2 -_feg .Y1 ,LineColor :_feg .LineColor ,Opacity :_feg .Opacity ,LineWidth :_feg .LineWidth ,LineEndingStyle1 :_feg .LineEndingStyle1 ,LineEndingStyle2 :_feg .LineEndingStyle2 };_gcfb ,_gbg ,_ggbd :=_cba .Draw (_baac );if _ggbd !=nil {return nil ,nil ,nil ,_ggbd ;};_aafe :=&_gc .PdfRectangle {};_aafe .Llx =_feg .X1 +_gbg .Llx ;_aafe .Lly =_feg .Y1 +_gbg .Lly ;_aafe .Urx =_feg .X1 +_gbg .Urx ;_aafe .Ury =_feg .Y1 +_gbg .Ury ;return _gcfb ,_gbg ,_aafe ,nil ;};
|
|
|
|
// NewSignatureField returns a new signature field with a visible appearance
|
|
// containing the specified signature lines and styled according to the
|
|
// specified options.
|
|
func NewSignatureField (signature *_gc .PdfSignature ,lines []*SignatureLine ,opts *SignatureFieldOpts )(*_gc .PdfFieldSignature ,error ){if signature ==nil {return nil ,_b .New ("\u0073\u0069\u0067na\u0074\u0075\u0072\u0065\u0020\u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u006e\u0069\u006c");};_bef ,_bda :=_aagg (lines ,opts );if _bda !=nil {return nil ,_bda ;};_gcfc :=_gc .NewPdfFieldSignature (signature );_gcfc .Rect =_bd .MakeArrayFromFloats (opts .Rect );_gcfc .AP =_bef ;return _gcfc ,nil ;};func _eded ()_bd .StreamEncoder {return _bd .NewFlateEncoder ()};
|
|
|
|
// CreateLineAnnotation creates a line annotation object that can be added to page PDF annotations.
|
|
func CreateLineAnnotation (lineDef LineAnnotationDef )(*_gc .PdfAnnotation ,error ){_fbbc :=_gc .NewPdfAnnotationLine ();_fbbc .L =_bd .MakeArrayFromFloats ([]float64 {lineDef .X1 ,lineDef .Y1 ,lineDef .X2 ,lineDef .Y2 });_dfde :=_bd .MakeName ("\u004e\u006f\u006e\u0065");if lineDef .LineEndingStyle1 ==_dbe .LineEndingStyleArrow {_dfde =_bd .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");};_dfcb :=_bd .MakeName ("\u004e\u006f\u006e\u0065");if lineDef .LineEndingStyle2 ==_dbe .LineEndingStyleArrow {_dfcb =_bd .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");};_fbbc .LE =_bd .MakeArray (_dfde ,_dfcb );if lineDef .Opacity < 1.0{_fbbc .CA =_bd .MakeFloat (lineDef .Opacity );};_abdd ,_fgag ,_ddad :=lineDef .LineColor .R (),lineDef .LineColor .G (),lineDef .LineColor .B ();_fbbc .IC =_bd .MakeArrayFromFloats ([]float64 {_abdd ,_fgag ,_ddad });_fbbc .C =_bd .MakeArrayFromFloats ([]float64 {_abdd ,_fgag ,_ddad });_aedb :=_gc .NewBorderStyle ();_aedb .SetBorderWidth (lineDef .LineWidth );_fbbc .BS =_aedb .ToPdfObject ();_cde ,_egaf ,_bfcc :=_bcdg (lineDef );if _bfcc !=nil {return nil ,_bfcc ;};_fbbc .AP =_cde ;_fbbc .Rect =_bd .MakeArrayFromFloats ([]float64 {_egaf .Llx ,_egaf .Lly ,_egaf .Urx ,_egaf .Ury });return _fbbc .PdfAnnotation ,nil ;};func _aagg (_cge []*SignatureLine ,_ebgc *SignatureFieldOpts )(*_bd .PdfObjectDictionary ,error ){if _ebgc ==nil {_ebgc =NewSignatureFieldOpts ();};var _cdga error ;var _dcag *_bd .PdfObjectName ;_bdcca :=_ebgc .Font ;if _bdcca !=nil {_bccf ,_ :=_bdcca .GetFontDescriptor ();if _bccf !=nil {if _aedc ,_afd :=_bccf .FontName .(*_bd .PdfObjectName );_afd {_dcag =_aedc ;};};if _dcag ==nil {_dcag =_bd .MakeName ("\u0046\u006f\u006et\u0031");};}else {if _bdcca ,_cdga =_gc .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");_cdga !=nil {return nil ,_cdga ;};_dcag =_bd .MakeName ("\u0048\u0065\u006c\u0076");};_dac :=_ebgc .FontSize ;if _dac <=0{_dac =10;};if _ebgc .LineHeight <=0{_ebgc .LineHeight =1;};_gcf :=_ebgc .LineHeight *_dac ;_geed ,_abd :=_bdcca .GetRuneMetrics (' ');if !_abd {return nil ,_b .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");};_bffec :=_geed .Wx ;var _bbff float64 ;var _baeg []string ;for _ ,_agea :=range _cge {if _agea .Text ==""{continue ;};_gedb :=_agea .Text ;if _agea .Desc !=""{_gedb =_agea .Desc +"\u003a\u0020"+_gedb ;};_baeg =append (_baeg ,_gedb );var _fcdd float64 ;for _ ,_cfaf :=range _gedb {_gfb ,_cbf :=_bdcca .GetRuneMetrics (_cfaf );if !_cbf {continue ;};_fcdd +=_gfb .Wx ;};if _fcdd > _bbff {_bbff =_fcdd ;};};_bbff =_bbff *_dac /1000.0;_ega :=float64 (len (_baeg ))*_gcf ;_bdbe :=_ebgc .Image !=nil ;_dcbd :=_ebgc .Rect ;if _dcbd ==nil {_dcbd =[]float64 {0,0,_bbff ,_ega };if _bdbe {_dcbd [2]=_bbff *2;_dcbd [3]=_ega *2;};_ebgc .Rect =_dcbd ;};_gaca :=_dcbd [2]-_dcbd [0];_eec :=_dcbd [3]-_dcbd [1];_ddg ,_abeb :=_dcbd ,_dcbd ;var _bdfd ,_aagc float64 ;if _bdbe &&len (_baeg )> 0{if _ebgc .ImagePosition <=SignatureImageRight {_ggfg :=[]float64 {_dcbd [0],_dcbd [1],_dcbd [0]+(_gaca /2),_dcbd [3]};_bab :=[]float64 {_dcbd [0]+(_gaca /2),_dcbd [1],_dcbd [2],_dcbd [3]};if _ebgc .ImagePosition ==SignatureImageLeft {_ddg ,_abeb =_ggfg ,_bab ;}else {_ddg ,_abeb =_bab ,_ggfg ;};}else {_fdee :=[]float64 {_dcbd [0],_dcbd [1],_dcbd [2],_dcbd [1]+(_eec /2)};_bde :=[]float64 {_dcbd [0],_dcbd [1]+(_eec /2),_dcbd [2],_dcbd [3]};if _ebgc .ImagePosition ==SignatureImageTop {_ddg ,_abeb =_bde ,_fdee ;}else {_ddg ,_abeb =_fdee ,_bde ;};};};_bdfd =_abeb [2]-_abeb [0];_aagc =_abeb [3]-_abeb [1];var _acbb float64 ;if _ebgc .AutoSize {if _bbff > _bdfd ||_ega > _aagc {_ceg :=_g .Min (_bdfd /_bbff ,_aagc /_ega );_dac *=_ceg ;};_gcf =_ebgc .LineHeight *_dac ;_acbb +=(_aagc -float64 (len (_baeg ))*_gcf )/2;};_caag :=_a .NewContentCreator ();_fcea :=_gc .NewPdfPageResources ();_fcea .SetFontByName (*_dcag ,_bdcca .ToPdfObject ());if _ebgc .BorderSize <=0{_ebgc .BorderSize =0;_ebgc .BorderColor =_gc .NewPdfColorDeviceGray (1);};if _ebgc .BorderColor ==nil {_ebgc .BorderColor =_gc .NewPdfColorDeviceGray (1);};if _ebgc .FillColor ==nil {_ebgc .FillColor =_gc .NewPdfColorDeviceGray (1);};_caag .Add_q ().SetNonStrokingColor (_ebgc .FillColor ).SetStrokingColor (_ebgc .BorderColor ).Add_w (_ebgc .BorderSize ).Add_re (_dcbd [0],_dcbd [1],_gaca ,_eec ).Add_B ().Add_Q ();if _ebgc .WatermarkImage !=nil {_cdfe :=[]float64 {_dcbd [0],_dcbd [1],_dcbd [2],_dcbd [3]};_fcddd ,_eaag ,_gfaeg :=_bgcd (_ebgc .WatermarkImage ,"\u0049\u006d\u0061\u0067\u0065\u0057\u0061\u0074\u0065r\u006d\u0061\u0072\u006b",_ebgc ,_cdfe ,_caag );if _gfaeg !=nil {return nil ,_gfaeg ;};_fcea .SetXObjectImageByName (*_fcddd ,_eaag );};_caag .Add_q ();_caag .Translate (_abeb [0],_abeb [3]-_gcf -_acbb );_caag .Add_BT ();_gdf :=_bdcca .Encoder ();for _ ,_cegf :=range _baeg {var _daa []byte ;for _ ,_dbdb :=range _cegf {if _fc .IsSpace (_dbdb ){if len (_daa )> 0{_caag .SetNonStrokingColor (_ebgc .TextColor ).Add_Tf (*_dcag ,_dac ).Add_TL (_gcf ).Add_TJ ([]_bd .PdfObject {_bd .MakeStringFromBytes (_daa )}...);_daa =nil ;};_caag .Add_Tf (*_dcag ,_dac ).Add_TL (_gcf ).Add_TJ ([]_bd .PdfObject {_bd .MakeFloat (-_bffec )}...);}else {_daa =append (_daa ,_gdf .Encode (string (_dbdb ))...);};};if len (_daa )> 0{_caag .SetNonStrokingColor (_ebgc .TextColor ).Add_Tf (*_dcag ,_dac ).Add_TL (_gcf ).Add_TJ ([]_bd .PdfObject {_bd .MakeStringFromBytes (_daa )}...);};_caag .Add_Td (0,-_gcf );};_caag .Add_ET ();_caag .Add_Q ();if _bdbe {_egbd ,_aff ,_gaa :=_bgcd (_ebgc .Image ,"\u0049\u006d\u0061\u0067\u0065\u0053\u0069\u0067\u006ea\u0074\u0075\u0072\u0065",_ebgc ,_ddg ,_caag );if _gaa !=nil {return nil ,_gaa ;};_fcea .SetXObjectImageByName (*_egbd ,_aff );};_fdf :=_gc .NewXObjectForm ();_fdf .Resources =_fcea ;_fdf .BBox =_bd .MakeArrayFromFloats (_dcbd );_fdf .SetContentStream (_caag .Bytes (),_eded ());_dcd :=_bd .MakeDict ();_dcd .Set ("\u004e",_fdf .ToPdfObject ());return _dcd ,nil ;};func _bb (_bbf CircleAnnotationDef )(*_bd .PdfObjectDictionary ,*_gc .PdfRectangle ,error ){_bc :=_gc .NewXObjectForm ();_bc .Resources =_gc .NewPdfPageResources ();_eb :="";if _bbf .Opacity < 1.0{_bdc :=_bd .MakeDict ();_bdc .Set ("\u0063\u0061",_bd .MakeFloat (_bbf .Opacity ));_bdc .Set ("\u0043\u0041",_bd .MakeFloat (_bbf .Opacity ));_bgg :=_bc .Resources .AddExtGState ("\u0067\u0073\u0031",_bdc );if _bgg !=nil {_d .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 ,_bgg ;};_eb ="\u0067\u0073\u0031";};_gef ,_ffa ,_gg ,_ac :=_cd (_bbf ,_eb );if _ac !=nil {return nil ,nil ,_ac ;};_ac =_bc .SetContentStream (_gef ,nil );if _ac !=nil {return nil ,nil ,_ac ;};_bc .BBox =_ffa .ToPdfObject ();_ce :=_bd .MakeDict ();_ce .Set ("\u004e",_bc .ToPdfObject ());return _ce ,_gg ,nil ;};func _baa (_gfd *_gc .PdfAnnotationWidget ,_baaa *_gc .PdfFieldButton ,_fgc *_gc .PdfPageResources ,_dfbd AppearanceStyle )(*_bd .PdfObjectDictionary ,error ){_dec ,_bae :=_bd .GetArray (_gfd .Rect );if !_bae {return nil ,_b .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_dcc ,_ebe :=_gc .NewPdfRectangle (*_dec );if _ebe !=nil {return nil ,_ebe ;};_bbfe ,_bfd :=_dcc .Width (),_dcc .Height ();_bfa ,_acd :=_bbfe ,_bfd ;_d .Log .Debug ("\u0043\u0068\u0065\u0063kb\u006f\u0078\u002c\u0020\u0077\u0061\u0020\u0042\u0053\u003a\u0020\u0025\u0076",_gfd .BS );_bgbg ,_ebe :=_gc .NewStandard14Font ("\u005a\u0061\u0070f\u0044\u0069\u006e\u0067\u0062\u0061\u0074\u0073");if _ebe !=nil {return nil ,_ebe ;};_deaf ,_ffg :=_bd .GetDict (_gfd .MK );if _ffg {_bgf ,_ :=_bd .GetDict (_gfd .BS );_egb :=_dfbd .applyAppearanceCharacteristics (_deaf ,_bgf ,_bgbg );if _egb !=nil {return nil ,_egb ;};};_gabe :=_gc .NewXObjectForm ();{_eag :=_a .NewContentCreator ();if _dfbd .BorderSize > 0{_gecg (_eag ,_dfbd ,_bbfe ,_bfd );};if _dfbd .DrawAlignmentReticle {_gde :=_dfbd ;_gde .BorderSize =0.2;_acg (_eag ,_gde ,_bbfe ,_bfd );};_bbfe ,_bfd =_dfbd .applyRotation (_deaf ,_bbfe ,_bfd ,_eag );_ffge :=_dfbd .AutoFontSizeFraction *_bfd ;_cdb ,_ggdf :=_bgbg .GetRuneMetrics (_dfbd .CheckmarkRune );if !_ggdf {return nil ,_b .New ("\u0067l\u0079p\u0068\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");};_fca :=_bgbg .Encoder ();_bbg :=_fca .Encode (string (_dfbd .CheckmarkRune ));_dd :=_cdb .Wx *_ffge /1000.0;_efd :=705.0;_eebb :=_efd /1000.0*_ffge ;_dda :=2.0;_defb :=1.0;if _dd < _bbfe {_dda =(_bbfe -_dd )/2.0;};if _eebb < _bfd {_defb =(_bfd -_eebb )/2.0;};_eag .Add_q ().Add_g (0).Add_BT ().Add_Tf ("\u005a\u0061\u0044\u0062",_ffge ).Add_Td (_dda ,_defb ).Add_Tj (*_bd .MakeStringFromBytes (_bbg )).Add_ET ().Add_Q ();_gabe .Resources =_gc .NewPdfPageResources ();_gabe .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_bgbg .ToPdfObject ());_gabe .BBox =_bd .MakeArrayFromFloats ([]float64 {0,0,_bfa ,_acd });_gabe .SetContentStream (_eag .Bytes (),_eded ());};_cgd :=_gc .NewXObjectForm ();{_bccg :=_a .NewContentCreator ();if _dfbd .BorderSize > 0{_gecg (_bccg ,_dfbd ,_bbfe ,_bfd );};_cgd .BBox =_bd .MakeArrayFromFloats ([]float64 {0,0,_bfa ,_acd });_cgd .SetContentStream (_bccg .Bytes (),_eded ());};_fcgf :=_bd .MakeDict ();_fcgf .Set ("\u004f\u0066\u0066",_cgd .ToPdfObject ());_fcgf .Set ("\u0059\u0065\u0073",_gabe .ToPdfObject ());_dccb :=_bd .MakeDict ();_dccb .Set ("\u004e",_fcgf );return _dccb ,nil ;};
|
|
|
|
// 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 *_gc .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 _dbe .LineEndingStyle ;LineEndingStyle2 _dbe .LineEndingStyle ;};func (_abed *AppearanceStyle )applyRotation (_ffbc *_bd .PdfObjectDictionary ,_cgag ,_aace float64 ,_bgbf *_a .ContentCreator )(float64 ,float64 ){if !_abed .AllowMK {return _cgag ,_aace ;};if _ffbc ==nil {return _cgag ,_aace ;};_cab ,_ :=_bd .GetNumberAsFloat (_ffbc .Get ("\u0052"));if _cab ==0{return _cgag ,_aace ;};_beb :=-_cab ;_ddc :=_dbe .Path {Points :[]_dbe .Point {_dbe .NewPoint (0,0).Rotate (_beb ),_dbe .NewPoint (_cgag ,0).Rotate (_beb ),_dbe .NewPoint (0,_aace ).Rotate (_beb ),_dbe .NewPoint (_cgag ,_aace ).Rotate (_beb )}}.GetBoundingBox ();_bgbf .RotateDeg (_cab );_bgbf .Translate (_ddc .X ,_ddc .Y );return _ddc .Width ,_ddc .Height ;};
|
|
|
|
// SignatureLine represents a line of information in the signature field appearance.
|
|
type SignatureLine struct{Desc string ;Text string ;};const (_bgd quadding =0;_gd quadding =1;_ec quadding =2;);func (_abcg *AppearanceStyle )processDA (_ddcg *_gc .PdfField ,_baef *_a .ContentStreamOperations ,_ccg ,_fcd *_gc .PdfPageResources ,_fdg *_a .ContentCreator )(*AppearanceFont ,bool ,error ){var _gag *AppearanceFont ;var _bgc bool ;if _abcg .Fonts !=nil {if _abcg .Fonts .Fallback !=nil {_gag =_abcg .Fonts .Fallback ;};if _aeaac :=_abcg .Fonts .FieldFallbacks ;_aeaac !=nil {if _bccgd ,_bffe :=_aeaac [_ddcg .PartialName ()];_bffe {_gag =_bccgd ;}else if _cfe ,_ebga :=_ddcg .FullName ();_ebga ==nil {if _bega ,_bbaa :=_aeaac [_cfe ];_bbaa {_gag =_bega ;};};};_bgc =_abcg .Fonts .ForceReplace ;};var _aabg string ;var _fdad float64 ;var _fcfe bool ;if _baef !=nil {for _ ,_adcd :=range *_baef {if _adcd .Operand =="\u0054\u0066"&&len (_adcd .Params )==2{if _bac ,_bdcc :=_bd .GetNameVal (_adcd .Params [0]);_bdcc {_aabg =_bac ;};if _ffe ,_gcbg :=_bd .GetNumberAsFloat (_adcd .Params [1]);_gcbg ==nil {_fdad =_ffe ;};_fcfe =true ;continue ;};_fdg .AddOperand (*_adcd );};};var _agb *AppearanceFont ;var _ggb _bd .PdfObject ;if _bgc &&_gag !=nil {_agb =_gag ;}else {if _ccg !=nil &&_aabg !=""{if _bad ,_fbb :=_ccg .GetFontByName (*_bd .MakeName (_aabg ));_fbb {if _cdf ,_ccga :=_gc .NewPdfFontFromPdfObject (_bad );_ccga ==nil {_ggb =_bad ;_agb =&AppearanceFont {Name :_aabg ,Font :_cdf ,Size :_fdad };}else {_d .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",_ccga );};};};if _agb ==nil &&_gag !=nil {_agb =_gag ;};if _agb ==nil {_efb ,_dggd :=_gc .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");if _dggd !=nil {return nil ,false ,_dggd ;};_agb =&AppearanceFont {Name :"\u0048\u0065\u006c\u0076",Font :_efb ,Size :_fdad };};};_dfef :=*_bd .MakeName (_agb .Name );if _ggb ==nil {_ggb =_agb .Font .ToPdfObject ();};if _ccg !=nil &&!_ccg .HasFontByName (_dfef ){_ccg .SetFontByName (_dfef ,_ggb );};if _fcd !=nil &&!_fcd .HasFontByName (_dfef ){_fcd .SetFontByName (_dfef ,_ggb );};return _agb ,_fcfe ,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 ;
|
|
|
|
// FieldFallbacks defines font fallbacks for specific fields. The map keys
|
|
// represent the names of the fields (which can be specified by their
|
|
// partial or full names). Specific field fallback fonts take precedence
|
|
// over the global font fallback.
|
|
FieldFallbacks map[string ]*AppearanceFont ;
|
|
|
|
// ForceReplace forces the replacement of fonts in the filling/flattening
|
|
// process, even if the default appearance (DA) specify a valid font.
|
|
// If no fallback font is provided, setting this field has no effect.
|
|
ForceReplace bool ;};
|
|
|
|
// SetStyle applies appearance `style` to `fa`.
|
|
func (_gbb *FieldAppearance )SetStyle (style AppearanceStyle ){_gbb ._gb =&style };
|
|
|
|
// 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 };};
|
|
|
|
// GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`.
|
|
// Implements interface model.FieldAppearanceGenerator.
|
|
func (_fb FieldAppearance )GenerateAppearanceDict (form *_gc .PdfAcroForm ,field *_gc .PdfField ,wa *_gc .PdfAnnotationWidget )(*_bd .PdfObjectDictionary ,error ){_d .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 );_ ,_dc :=field .GetContext ().(*_gc .PdfFieldText );_ggf ,_ffd :=_bd .GetDict (wa .AP );if _ffd &&_fb .OnlyIfMissing &&(!_dc ||!_fb .RegenerateTextFields ){_d .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 _ggf ,nil ;};if form .DR ==nil {form .DR =_gc .NewPdfPageResources ();};switch _dca :=field .GetContext ().(type ){case *_gc .PdfFieldText :_fec :=_dca ;switch {case _fec .Flags ().Has (_gc .FieldFlagPassword ):return nil ,nil ;case _fec .Flags ().Has (_gc .FieldFlagFileSelect ):return nil ,nil ;case _fec .Flags ().Has (_gc .FieldFlagComb ):if _fec .MaxLen !=nil {_eff ,_dg :=_aae (wa ,_fec ,form .DR ,_fb .Style ());if _dg !=nil {return nil ,_dg ;};return _eff ,nil ;};};_dcad ,_cfb :=_bdcf (wa ,_fec ,form .DR ,_fb .Style ());if _cfb !=nil {return nil ,_cfb ;};return _dcad ,nil ;case *_gc .PdfFieldButton :_df :=_dca ;if _df .IsCheckbox (){_ag ,_gee :=_baa (wa ,_df ,form .DR ,_fb .Style ());if _gee !=nil {return nil ,_gee ;};return _ag ,nil ;};_d .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",_df .GetType ());case *_gc .PdfFieldChoice :_ea :=_dca ;switch {case _ea .Flags ().Has (_gc .FieldFlagCombo ):_ad ,_ca :=_bec (form ,wa ,_ea ,_fb .Style ());if _ca !=nil {return nil ,_ca ;};return _ad ,nil ;default:_d .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",_ea .Flags ().String ());};default:_d .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",_dca );};return nil ,nil ;};
|
|
|
|
// 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 *_gc .PdfFont ;
|
|
|
|
// Size represents the size of the font used for the field appearance.
|
|
// If size is 0, a default font size will be used.
|
|
// The default font size is calculated using the available annotation
|
|
// height and the AutoFontSizeFraction of the AppearanceStyle.
|
|
Size float64 ;};func _aafg (_gfee *_gc .PdfField ,_edf ,_gbd float64 ,_aead string ,_ccbc AppearanceStyle ,_edfd *_a .ContentStreamOperations ,_dfbdd *_gc .PdfPageResources ,_cffa *_bd .PdfObjectDictionary )(*_gc .XObjectForm ,error ){_dag :=_gc .NewPdfPageResources ();_agab ,_eged :=_edf ,_gbd ;_dfbee :=_a .NewContentCreator ();if _ccbc .BorderSize > 0{_gecg (_dfbee ,_ccbc ,_edf ,_gbd );};if _ccbc .DrawAlignmentReticle {_cbe :=_ccbc ;_cbe .BorderSize =0.2;_acg (_dfbee ,_cbe ,_edf ,_gbd );};_dfbee .Add_BMC ("\u0054\u0078");_dfbee .Add_q ();_dfbee .Add_BT ();_edf ,_gbd =_ccbc .applyRotation (_cffa ,_edf ,_gbd ,_dfbee );_gec ,_bdg ,_eee :=_ccbc .processDA (_gfee ,_edfd ,_dfbdd ,_dag ,_dfbee );if _eee !=nil {return nil ,_eee ;};_bbgfe :=_gec .Font ;_aba :=_gec .Size ;_fbag :=_bd .MakeName (_gec .Name );_afc :=_aba ==0;if _afc &&_bdg {_aba =_gbd *_ccbc .AutoFontSizeFraction ;};_bagg :=_bbgfe .Encoder ();if _bagg ==nil {_d .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");_bagg =_e .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};if len (_aead )==0{return nil ,nil ;};_dagd :=2.0;_gfae :=0.0;if _bagg !=nil {for _ ,_aeaa :=range _aead {_aede ,_dbc :=_bbgfe .GetRuneMetrics (_aeaa );if !_dbc {_d .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",_aeaa );continue ;};_gfae +=_aede .Wx ;};_aead =string (_bagg .Encode (_aead ));};if _aba ==0||_afc &&_gfae > 0&&_dagd +_gfae *_aba /1000.0> _edf {_aba =0.95*1000.0*(_edf -_dagd )/_gfae ;};_dga :=1.0*_aba ;_gba :=2.0;{_dfe :=_dga ;if _afc &&_gba +_dfe > _gbd {_aba =0.95*(_gbd -_gba );_dga =1.0*_aba ;_dfe =_dga ;};if _gbd > _dfe {_gba =(_gbd -_dfe )/2.0;_gba +=1.50;};};_dfbee .Add_Tf (*_fbag ,_aba );_dfbee .Add_Td (_dagd ,_gba );_dfbee .Add_Tj (*_bd .MakeString (_aead ));_dfbee .Add_ET ();_dfbee .Add_Q ();_dfbee .Add_EMC ();_dcga :=_gc .NewXObjectForm ();_dcga .Resources =_dag ;_dcga .BBox =_bd .MakeArrayFromFloats ([]float64 {0,0,_agab ,_eged });_dcga .SetContentStream (_dfbee .Bytes (),_eded ());return _dcga ,nil ;};func _bec (_bbac *_gc .PdfAcroForm ,_fecg *_gc .PdfAnnotationWidget ,_gcbbc *_gc .PdfFieldChoice ,_bea AppearanceStyle )(*_bd .PdfObjectDictionary ,error ){_dfd ,_geee :=_bd .GetArray (_fecg .Rect );if !_geee {return nil ,_b .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_geg ,_edg :=_gc .NewPdfRectangle (*_dfd );if _edg !=nil {return nil ,_edg ;};_eca ,_fde :=_geg .Width (),_geg .Height ();_d .Log .Debug ("\u0043\u0068\u006f\u0069\u0063\u0065\u002c\u0020\u0077\u0061\u0020\u0042S\u003a\u0020\u0025\u0076",_fecg .BS );_bcgd ,_edg :=_a .NewContentStreamParser (_baad (_gcbbc .PdfField )).Parse ();if _edg !=nil {return nil ,_edg ;};_gfgd ,_bbgf :=_bd .GetDict (_fecg .MK );if _bbgf {_dcgb ,_ :=_bd .GetDict (_fecg .BS );_ecc :=_bea .applyAppearanceCharacteristics (_gfgd ,_dcgb ,nil );if _ecc !=nil {return nil ,_ecc ;};};_gae :=_bd .MakeDict ();for _ ,_cga :=range _gcbbc .Opt .Elements (){if _ffag ,_gfga :=_bd .GetArray (_cga );_gfga &&_ffag .Len ()==2{_cga =_ffag .Get (1);};var _dfbe string ;if _dee ,_bcf :=_bd .GetString (_cga );_bcf {_dfbe =_dee .Decoded ();}else if _agaf ,_gbeg :=_bd .GetName (_cga );_gbeg {_dfbe =_agaf .String ();}else {_d .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",_cga );return nil ,_b .New ("\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u002f\u0073t\u0072\u0069\u006e\u0067");};if len (_dfbe )> 0{_adff ,_effd :=_aafg (_gcbbc .PdfField ,_eca ,_fde ,_dfbe ,_bea ,_bcgd ,_bbac .DR ,_gfgd );if _effd !=nil {return nil ,_effd ;};_gae .Set (*_bd .MakeName (_dfbe ),_adff .ToPdfObject ());};};_fda :=_bd .MakeDict ();_fda .Set ("\u004e",_gae );return _fda ,nil ;};
|
|
|
|
// WrapContentStream ensures that the entire content stream for a `page` is wrapped within q ... Q operands.
|
|
// Ensures that following operands that are added are not affected by additional operands that are added.
|
|
// Implements interface model.ContentStreamWrapper.
|
|
func (_dbcb FieldAppearance )WrapContentStream (page *_gc .PdfPage )error {_fcfb ,_eeg :=page .GetAllContentStreams ();if _eeg !=nil {return _eeg ;};_cabb :=_a .NewContentStreamParser (_fcfb );_gcce ,_eeg :=_cabb .Parse ();if _eeg !=nil {return _eeg ;};_gcce .WrapIfNeeded ();_baga :=[]string {_gcce .String ()};return page .SetContentStreams (_baga ,_eded ());};
|
|
|
|
// 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 *_gc .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_gc .PdfColorDeviceRGB ;Opacity float64 ;};func (_cgaf *AppearanceStyle )applyAppearanceCharacteristics (_efc *_bd .PdfObjectDictionary ,_dgbe *_bd .PdfObjectDictionary ,_aag *_gc .PdfFont )error {if !_cgaf .AllowMK {return nil ;};if CA ,_ced :=_bd .GetString (_efc .Get ("\u0043\u0041"));_ced &&_aag !=nil {_ebba :=CA .Bytes ();if len (_ebba )!=0{_dbd :=[]rune (_aag .Encoder ().Decode (_ebba ));if len (_dbd )==1{_cgaf .CheckmarkRune =_dbd [0];};};};if BC ,_eaac :=_bd .GetArray (_efc .Get ("\u0042\u0043"));_eaac {_cfa ,_gdc :=BC .ToFloat64Array ();if _gdc !=nil {return _gdc ;};switch len (_cfa ){case 1:_cgaf .BorderColor =_gc .NewPdfColorDeviceGray (_cfa [0]);case 3:_cgaf .BorderColor =_gc .NewPdfColorDeviceRGB (_cfa [0],_cfa [1],_cfa [2]);case 4:_cgaf .BorderColor =_gc .NewPdfColorDeviceCMYK (_cfa [0],_cfa [1],_cfa [2],_cfa [3]);default:_d .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 (_cfa ));};if _dgbe !=nil {if _age ,_aab :=_bd .GetNumberAsFloat (_dgbe .Get ("\u0057"));_aab ==nil {_cgaf .BorderSize =_age ;};};};if BG ,_bbc :=_bd .GetArray (_efc .Get ("\u0042\u0047"));_bbc {_edeb ,_abae :=BG .ToFloat64Array ();if _abae !=nil {return _abae ;};switch len (_edeb ){case 1:_cgaf .FillColor =_gc .NewPdfColorDeviceGray (_edeb [0]);case 3:_cgaf .FillColor =_gc .NewPdfColorDeviceRGB (_edeb [0],_edeb [1],_edeb [2]);case 4:_cgaf .FillColor =_gc .NewPdfColorDeviceCMYK (_edeb [0],_edeb [1],_edeb [2],_edeb [3]);default:_d .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 (_edeb ));};};return nil ;};
|
|
|
|
// 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 ;};
|
|
|
|
// 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 *_gc .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_gc .PdfColorDeviceRGB ;Opacity float64 ;};
|
|
|
|
// 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 ;
|
|
|
|
// TextFieldOptions defines optional parameter for a text field in a form.
|
|
type TextFieldOptions struct{MaxLen int ;Value string ;};func _bgcd (_cedc _ed .Image ,_bdec string ,_cbfd *SignatureFieldOpts ,_feee []float64 ,_bgfc *_a .ContentCreator )(*_bd .PdfObjectName ,*_gc .XObjectImage ,error ){_efad ,_eabd :=_gc .DefaultImageHandler {}.NewImageFromGoImage (_cedc );if _eabd !=nil {return nil ,nil ,_eabd ;};_gcac ,_eabd :=_gc .NewXObjectImageFromImage (_efad ,nil ,_cbfd .Encoder );if _eabd !=nil {return nil ,nil ,_eabd ;};_geeda ,_ggc :=float64 (*_gcac .Width ),float64 (*_gcac .Height );_fad :=_feee [2]-_feee [0];_gce :=_feee [3]-_feee [1];if _cbfd .AutoSize {_acda :=_g .Min (_fad /_geeda ,_gce /_ggc );_geeda *=_acda ;_ggc *=_acda ;_feee [0]=_feee [0]+(_fad /2)-(_geeda /2);_feee [1]=_feee [1]+(_gce /2)-(_ggc /2);};var _geea *_bd .PdfObjectName ;if _ggbb ,_gfeg :=_bd .GetName (_gcac .Name );_gfeg {_geea =_ggbb ;}else {_geea =_bd .MakeName (_bdec );};if _bgfc !=nil {_bgfc .Add_q ().Translate (_feee [0],_feee [1]).Scale (_geeda ,_ggc ).Add_Do (*_geea ).Add_Q ();}else {return nil ,nil ,_b .New ("\u0043\u006f\u006e\u0074en\u0074\u0043\u0072\u0065\u0061\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u0075l\u006c");};return _geea ,_gcac ,nil ;};
|
|
|
|
// SignatureFieldOpts represents a set of options used to configure
|
|
// an appearance widget dictionary.
|
|
type SignatureFieldOpts struct{
|
|
|
|
// Rect represents the area the signature annotation is displayed on.
|
|
Rect []float64 ;
|
|
|
|
// AutoSize specifies if the content of the appearance should be
|
|
// scaled to fit in the annotation rectangle.
|
|
AutoSize bool ;
|
|
|
|
// Font specifies the font of the text content.
|
|
Font *_gc .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 _gc .PdfColor ;
|
|
|
|
// FillColor represents the background color of the appearance annotation area.
|
|
FillColor _gc .PdfColor ;
|
|
|
|
// BorderSize represents border size of the appearance annotation area.
|
|
BorderSize float64 ;
|
|
|
|
// BorderColor represents the border color of the appearance annotation area.
|
|
BorderColor _gc .PdfColor ;
|
|
|
|
// WatermarkImage specifies the image used as a watermark that will be rendered
|
|
// behind the signature.
|
|
WatermarkImage _ed .Image ;
|
|
|
|
// Image represents the image used for the signature appearance.
|
|
Image _ed .Image ;
|
|
|
|
// Encoder specifies the image encoder used for image signature. Defaults to flate encoder.
|
|
Encoder _bd .StreamEncoder ;
|
|
|
|
// ImagePosition specifies the image location relative to the text signature.
|
|
ImagePosition SignatureImagePosition ;};
|
|
|
|
// NewSignatureFieldOpts returns a new initialized instance of options
|
|
// used to generate a signature appearance.
|
|
func NewSignatureFieldOpts ()*SignatureFieldOpts {return &SignatureFieldOpts {Font :_gc .DefaultFont (),FontSize :10,LineHeight :1,AutoSize :true ,TextColor :_gc .NewPdfColorDeviceGray (0),BorderColor :_gc .NewPdfColorDeviceGray (0),FillColor :_gc .NewPdfColorDeviceGray (1),Encoder :_bd .NewFlateEncoder (),ImagePosition :SignatureImageLeft };};
|
|
|
|
// CreateCircleAnnotation creates a circle/ellipse annotation object with appearance stream that can be added to
|
|
// page PDF annotations.
|
|
func CreateCircleAnnotation (circDef CircleAnnotationDef )(*_gc .PdfAnnotation ,error ){_ge :=_gc .NewPdfAnnotationCircle ();if circDef .BorderEnabled {_eg ,_fg ,_ba :=circDef .BorderColor .R (),circDef .BorderColor .G (),circDef .BorderColor .B ();_ge .C =_bd .MakeArrayFromFloats ([]float64 {_eg ,_fg ,_ba });_bdb :=_gc .NewBorderStyle ();_bdb .SetBorderWidth (circDef .BorderWidth );_ge .BS =_bdb .ToPdfObject ();};if circDef .FillEnabled {_ee ,_bg ,_bgb :=circDef .FillColor .R (),circDef .FillColor .G (),circDef .FillColor .B ();_ge .IC =_bd .MakeArrayFromFloats ([]float64 {_ee ,_bg ,_bgb });}else {_ge .IC =_bd .MakeArrayFromIntegers ([]int {});};if circDef .Opacity < 1.0{_ge .CA =_bd .MakeFloat (circDef .Opacity );};_c ,_ef ,_dba :=_bb (circDef );if _dba !=nil {return nil ,_dba ;};_ge .AP =_c ;_ge .Rect =_bd .MakeArrayFromFloats ([]float64 {_ef .Llx ,_ef .Lly ,_ef .Urx ,_ef .Ury });return _ge .PdfAnnotation ,nil ;};
|
|
|
|
// 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 *_gc .PdfPage ,name string ,rect []float64 ,opt CheckboxFieldOptions )(*_gc .PdfFieldButton ,error ){if page ==nil {return nil ,_b .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};if len (name )<=0{return nil ,_b .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 ,_b .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");};_bgdd ,_eaef :=_gc .NewStandard14Font (_gc .ZapfDingbatsName );if _eaef !=nil {return nil ,_eaef ;};_abac :=_gc .NewPdfField ();_bee :=&_gc .PdfFieldButton {};_abac .SetContext (_bee );_bee .PdfField =_abac ;_bee .T =_bd .MakeString (name );_bee .SetType (_gc .ButtonTypeCheckbox );_egce :="\u004f\u0066\u0066";if opt .Checked {_egce ="\u0059\u0065\u0073";};_bee .V =_bd .MakeName (_egce );_fdda :=_gc .NewPdfAnnotationWidget ();_fdda .Rect =_bd .MakeArrayFromFloats (rect );_fdda .P =page .ToPdfObject ();_fdda .F =_bd .MakeInteger (4);_fdda .Parent =_bee .ToPdfObject ();_ebef :=rect [2]-rect [0];_bfae :=rect [3]-rect [1];var _agccg _ff .Buffer ;_agccg .WriteString ("\u0071\u000a");_agccg .WriteString ("\u0030 \u0030\u0020\u0031\u0020\u0072\u0067\n");_agccg .WriteString ("\u0042\u0054\u000a");_agccg .WriteString ("\u002f\u005a\u0061D\u0062\u0020\u0031\u0032\u0020\u0054\u0066\u000a");_agccg .WriteString ("\u0045\u0054\u000a");_agccg .WriteString ("\u0051\u000a");_fgg :=_a .NewContentCreator ();_fgg .Add_q ();_fgg .Add_rg (0,0,1);_fgg .Add_BT ();_fgg .Add_Tf (*_bd .MakeName ("\u005a\u0061\u0044\u0062"),12);_fgg .Add_Td (0,0);_fgg .Add_ET ();_fgg .Add_Q ();_edd :=_gc .NewXObjectForm ();_edd .SetContentStream (_fgg .Bytes (),_bd .NewRawEncoder ());_edd .BBox =_bd .MakeArrayFromFloats ([]float64 {0,0,_ebef ,_bfae });_edd .Resources =_gc .NewPdfPageResources ();_edd .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_bgdd .ToPdfObject ());_fgg =_a .NewContentCreator ();_fgg .Add_q ();_fgg .Add_re (0,0,_ebef ,_bfae );_fgg .Add_W ().Add_n ();_fgg .Add_rg (0,0,1);_fgg .Translate (0,3.0);_fgg .Add_BT ();_fgg .Add_Tf (*_bd .MakeName ("\u005a\u0061\u0044\u0062"),12);_fgg .Add_Td (0,0);_fgg .Add_Tj (*_bd .MakeString ("\u0034"));_fgg .Add_ET ();_fgg .Add_Q ();_ggg :=_gc .NewXObjectForm ();_ggg .SetContentStream (_fgg .Bytes (),_bd .NewRawEncoder ());_ggg .BBox =_bd .MakeArrayFromFloats ([]float64 {0,0,_ebef ,_bfae });_ggg .Resources =_gc .NewPdfPageResources ();_ggg .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_bgdd .ToPdfObject ());_aedeb :=_bd .MakeDict ();_aedeb .Set ("\u004f\u0066\u0066",_edd .ToPdfObject ());_aedeb .Set ("\u0059\u0065\u0073",_ggg .ToPdfObject ());_ffdg :=_bd .MakeDict ();_ffdg .Set ("\u004e",_aedeb );_fdda .AP =_ffdg ;_fdda .AS =_bd .MakeName (_egce );_bee .Annotations =append (_bee .Annotations ,_fdda );return _bee ,nil ;};func _bdcf (_gf *_gc .PdfAnnotationWidget ,_ead *_gc .PdfFieldText ,_ggd *_gc .PdfPageResources ,_cg AppearanceStyle )(*_bd .PdfObjectDictionary ,error ){_af :=_gc .NewPdfPageResources ();_dgg ,_cced :=_bd .GetArray (_gf .Rect );if !_cced {return nil ,_b .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_bdf ,_gge :=_gc .NewPdfRectangle (*_dgg );if _gge !=nil {return nil ,_gge ;};_agg ,_cff :=_bdf .Width (),_bdf .Height ();_eeb ,_ae :=_agg ,_cff ;_gfa ,_bbfg :=_bd .GetDict (_gf .MK );if _bbfg {_bf ,_ :=_bd .GetDict (_gf .BS );_cdc :=_cg .applyAppearanceCharacteristics (_gfa ,_bf ,nil );if _cdc !=nil {return nil ,_cdc ;};};_bddd ,_gge :=_a .NewContentStreamParser (_baad (_ead .PdfField )).Parse ();if _gge !=nil {return nil ,_gge ;};_eac :=_a .NewContentCreator ();if _cg .BorderSize > 0{_gecg (_eac ,_cg ,_agg ,_cff );};if _cg .DrawAlignmentReticle {_ade :=_cg ;_ade .BorderSize =0.2;_acg (_eac ,_ade ,_agg ,_cff );};_eac .Add_BMC ("\u0054\u0078");_eac .Add_q ();_agg ,_cff =_cg .applyRotation (_gfa ,_agg ,_cff ,_eac );_eac .Add_BT ();_adf ,_fbc ,_gge :=_cg .processDA (_ead .PdfField ,_bddd ,_ggd ,_af ,_eac );if _gge !=nil {return nil ,_gge ;};_fcg :=_adf .Font ;_bag :=_adf .Size ;_dgb :=_bd .MakeName (_adf .Name );_fba :=_bag ==0;if _fba &&_fbc {_bag =_cff *_cg .AutoFontSizeFraction ;};_geb :=_fcg .Encoder ();if _geb ==nil {_d .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");_geb =_e .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};_dfb ,_gge :=_fcg .GetFontDescriptor ();if _gge !=nil {_d .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 _bdbd string ;if _de ,_fff :=_bd .GetString (_ead .V );_fff {_bdbd =_de .Decoded ();};if len (_bdbd )==0{return nil ,nil ;};_gfe :=[]string {_bdbd };_adea :=false ;if _ead .Flags ().Has (_gc .FieldFlagMultiline ){_adea =true ;_bdbd =_db .Replace (_bdbd ,"\u000d\u000a","\u000a",-1);_bdbd =_db .Replace (_bdbd ,"\u000d","\u000a",-1);_gfe =_db .Split (_bdbd ,"\u000a");};_bggf :=0.0;_fgb :=0;if _geb !=nil {_ecb :=len (_gfe );_gfeb :=0;for _gfeb < _ecb {var _ged float64 ;_bge :=-1;_ebb :=0.0;for _eaca ,_gda :=range _gfe [_gfeb ]{if _gda ==' '{_bge =_eaca ;_ged =_ebb ;};_ccb ,_adg :=_fcg .GetRuneMetrics (_gda );if !_adg {_d .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",_gda );continue ;};_ebb +=_ccb .Wx ;if _adea &&!_fba &&_bag *_ebb /1000.0> _agg &&_bge > 0{_caa :=_gfe [_gfeb ][_bge +1:];if _gfeb < len (_gfe )-1{_gfe =append (_gfe [:_gfeb +1],_gfe [_gfeb :]...);_gfe [_gfeb +1]=_caa ;}else {_gfe =append (_gfe ,_caa );};_ecb ++;_gfe [_gfeb ]=_gfe [_gfeb ][0:_bge ];_ebb =_ged ;break ;};};if _ebb > _bggf {_bggf =_ebb ;};_gfe [_gfeb ]=string (_geb .Encode (_gfe [_gfeb ]));if len (_gfe [_gfeb ])> 0{_fgb ++;};_gfeb ++;};};_ecg :=2.0;if _bag ==0||_fba &&_bggf > 0&&_ecg +_bggf *_bag /1000.0> _agg {_bag =0.95*1000.0*(_agg -_ecg )/_bggf ;};_fgd :=_bgd ;{if _cda ,_gede :=_bd .GetIntVal (_ead .Q );_gede {switch _cda {case 0:_fgd =_bgd ;case 1:_fgd =_gd ;case 2:_fgd =_ec ;default:_d .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",_cda );};};};_aef :=_cg .MultilineLineHeight ;_dcb :=_bag ;if _adea &&_fgb > 1{_dcb =_aef *_bag ;};var _gcc float64 ;if _dfb !=nil {_gcc ,_gge =_dfb .GetCapHeight ();if _gge !=nil {_d .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",_gge );};};if int (_gcc )<=0{_d .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");_gcc =1000;};_da :=_gcc /1000.0*_bag ;_fd :=0.0;{_fee :=float64 (_fgb )*_dcb ;if _fba &&_fd +_fee > _cff {_bag =0.95*(_cff -_fd )/float64 (_fgb );_dcb =_bag ;if _adea &&_fgb > 1{_dcb =_aef *_bag ;};_da =_gcc /1000.0*_bag ;_fee =float64 (_fgb )*_dcb ;};if _cff > _fee {if _adea {if _cg .MultilineVAlignMiddle {_dce :=(_cff -_fee )/2.0;_bcd :=_dce +_fee -_dcb ;_fd =_bcd ;}else {_fd =_cff -_dcb ;_fd -=_bag *0.5;};}else {_fd =(_cff -_da )/2.0;};};};_eac .Add_Tf (*_dgb ,_bag );_eac .Add_Td (_ecg ,_fd );_aed :=_ecg ;_dgf :=_ecg ;for _bdcb ,_abb :=range _gfe {_cec :=0.0;for _ ,_gga :=range _abb {_def ,_ga :=_fcg .GetRuneMetrics (_gga );if !_ga {continue ;};_cec +=_def .Wx ;};_ede :=_cec /1000.0*_bag ;_abg :=_agg -_ede ;var _bff float64 ;switch _fgd {case _bgd :_bff =_aed ;case _gd :_bff =_abg /2;case _ec :_bff =_abg ;};_ecg =_bff -_dgf ;if _ecg > 0.0{_eac .Add_Td (_ecg ,0);};_dgf =_bff ;_eac .Add_Tj (*_bd .MakeString (_abb ));if _bdcb < len (_gfe )-1{_eac .Add_Td (0,-_dcb *_aef );};};_eac .Add_ET ();_eac .Add_Q ();_eac .Add_EMC ();_dge :=_gc .NewXObjectForm ();_dge .Resources =_af ;_dge .BBox =_bd .MakeArrayFromFloats ([]float64 {0,0,_eeb ,_ae });_dge .SetContentStream (_eac .Bytes (),_eded ());_fffb :=_bd .MakeDict ();_fffb .Set ("\u004e",_dge .ToPdfObject ());return _fffb ,nil ;};func _baad (_ecaf *_gc .PdfField )string {if _ecaf ==nil {return "";};_efa ,_dccc :=_ecaf .GetContext ().(*_gc .PdfFieldText );if !_dccc {return _baad (_ecaf .Parent );};if _efa .DA !=nil {return _efa .DA .Str ();};return _baad (_efa .Parent );};
|
|
|
|
// 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 *_gc .PdfPage ,name string ,rect []float64 ,opt ComboboxFieldOptions )(*_gc .PdfFieldChoice ,error ){if page ==nil {return nil ,_b .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};if len (name )<=0{return nil ,_b .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 ,_b .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");};_cceg :=_gc .NewPdfField ();_cbec :=&_gc .PdfFieldChoice {};_cceg .SetContext (_cbec );_cbec .PdfField =_cceg ;_cbec .T =_bd .MakeString (name );_cbec .Opt =_bd .MakeArray ();for _ ,_eea :=range opt .Choices {_cbec .Opt .Append (_bd .MakeString (_eea ));};_cbec .SetFlag (_gc .FieldFlagCombo );_dbb :=_gc .NewPdfAnnotationWidget ();_dbb .Rect =_bd .MakeArrayFromFloats (rect );_dbb .P =page .ToPdfObject ();_dbb .F =_bd .MakeInteger (4);_dbb .Parent =_cbec .ToPdfObject ();_cbec .Annotations =append (_cbec .Annotations ,_dbb );return _cbec ,nil ;};func _aae (_ffb *_gc .PdfAnnotationWidget ,_ded *_gc .PdfFieldText ,_ecf *_gc .PdfPageResources ,_gfad AppearanceStyle )(*_bd .PdfObjectDictionary ,error ){_fce :=_gc .NewPdfPageResources ();_ece ,_gbe :=_bd .GetArray (_ffb .Rect );if !_gbe {return nil ,_b .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_dea ,_gfg :=_gc .NewPdfRectangle (*_ece );if _gfg !=nil {return nil ,_gfg ;};_ecgg ,_abc :=_dea .Width (),_dea .Height ();_bcg ,_fcc :=_ecgg ,_abc ;_gca ,_dbeg :=_bd .GetDict (_ffb .MK );if _dbeg {_bba ,_ :=_bd .GetDict (_ffb .BS );_agc :=_gfad .applyAppearanceCharacteristics (_gca ,_bba ,nil );if _agc !=nil {return nil ,_agc ;};};_cb ,_dbeg :=_bd .GetIntVal (_ded .MaxLen );if !_dbeg {return nil ,_b .New ("\u006d\u0061\u0078\u006c\u0065\u006e\u0020\u006e\u006ft\u0020\u0073\u0065\u0074");};if _cb <=0{return nil ,_b .New ("\u006d\u0061\u0078\u004c\u0065\u006e\u0020\u0069\u006ev\u0061\u006c\u0069\u0064");};_afe :=_ecgg /float64 (_cb );_ebd ,_gfg :=_a .NewContentStreamParser (_baad (_ded .PdfField )).Parse ();if _gfg !=nil {return nil ,_gfg ;};_gab :=_a .NewContentCreator ();if _gfad .BorderSize > 0{_gecg (_gab ,_gfad ,_ecgg ,_abc );};if _gfad .DrawAlignmentReticle {_eaa :=_gfad ;_eaa .BorderSize =0.2;_acg (_gab ,_eaa ,_ecgg ,_abc );};_gab .Add_BMC ("\u0054\u0078");_gab .Add_q ();_ ,_abc =_gfad .applyRotation (_gca ,_ecgg ,_abc ,_gab );_gab .Add_BT ();_agcc ,_eba ,_gfg :=_gfad .processDA (_ded .PdfField ,_ebd ,_ecf ,_fce ,_gab );if _gfg !=nil {return nil ,_gfg ;};_adc :=_agcc .Font ;_dfc :=_bd .MakeName (_agcc .Name );_ege :=_agcc .Size ;_fcf :=_ege ==0;if _fcf &&_eba {_ege =_abc *_gfad .AutoFontSizeFraction ;};_gcb :=_adc .Encoder ();if _gcb ==nil {_d .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");_gcb =_e .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};var _fa string ;if _bdfc ,_eed :=_bd .GetString (_ded .V );_eed {_fa =_bdfc .Decoded ();};_gab .Add_Tf (*_dfc ,_ege );var _aac float64 ;for _ ,_gbbc :=range _fa {_aaf ,_dbf :=_adc .GetRuneMetrics (_gbbc );if !_dbf {_d .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",_gbbc );continue ;};_dgba :=_aaf .Wy ;if int (_dgba )<=0{_dgba =_aaf .Wx ;};if _dgba > _aac {_aac =_dgba ;};};if int (_aac )==0{_d .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");_aac =1000;};_bddg ,_gfg :=_adc .GetFontDescriptor ();if _gfg !=nil {_d .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 _efg float64 ;if _bddg !=nil {_efg ,_gfg =_bddg .GetCapHeight ();if _gfg !=nil {_d .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",_gfg );};};if int (_efg )<=0{_d .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");_efg =1000.0;};_cdd :=_efg /1000.0*_ege ;_abe :=0.0;_aea :=1.0*_ege *(_aac /1000.0);{_aga :=_aea ;if _fcf &&_abe +_aga > _abc {_ege =0.95*(_abc -_abe );_cdd =_efg /1000.0*_ege ;};if _abc > _cdd {_abe =(_abc -_cdd )/2.0;};};_gab .Add_Td (0,_abe );if _cca ,_dgc :=_bd .GetIntVal (_ded .Q );_dgc {switch _cca {case 2:if len (_fa )< _cb {_gcbb :=float64 (_cb -len (_fa ))*_afe ;_gab .Add_Td (_gcbb ,0);};};};for _dcg ,_aacd :=range _fa {_gac :=2.0;_beg :=string (_aacd );if _gcb !=nil {_bcgc ,_bcc :=_adc .GetRuneMetrics (_aacd );if !_bcc {_d .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",_aacd );continue ;};_beg =string (_gcb .Encode (_beg ));_cgg :=_ege *_bcgc .Wx /1000.0;_cdg :=(_afe -_cgg )/2;_gac =_cdg ;};_gab .Add_Td (_gac ,0);_gab .Add_Tj (*_bd .MakeString (_beg ));if _dcg !=len (_fa )-1{_gab .Add_Td (_afe -_gac ,0);};};_gab .Add_ET ();_gab .Add_Q ();_gab .Add_EMC ();_ecbe :=_gc .NewXObjectForm ();_ecbe .Resources =_fce ;_ecbe .BBox =_bd .MakeArrayFromFloats ([]float64 {0,0,_bcg ,_fcc });_ecbe .SetContentStream (_gab .Bytes (),_eded ());_gff :=_bd .MakeDict ();_gff .Set ("\u004e",_ecbe .ToPdfObject ());return _gff ,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 ;_gb *AppearanceStyle ;};
|
|
|
|
// CreateRectangleAnnotation creates a rectangle annotation object that can be added to page PDF annotations.
|
|
func CreateRectangleAnnotation (rectDef RectangleAnnotationDef )(*_gc .PdfAnnotation ,error ){_ffbf :=_gc .NewPdfAnnotationSquare ();if rectDef .BorderEnabled {_beec ,_cea ,_dcbe :=rectDef .BorderColor .R (),rectDef .BorderColor .G (),rectDef .BorderColor .B ();_ffbf .C =_bd .MakeArrayFromFloats ([]float64 {_beec ,_cea ,_dcbe });_gecgc :=_gc .NewBorderStyle ();_gecgc .SetBorderWidth (rectDef .BorderWidth );_ffbf .BS =_gecgc .ToPdfObject ();};if rectDef .FillEnabled {_ebbad ,_ffdf ,_daag :=rectDef .FillColor .R (),rectDef .FillColor .G (),rectDef .FillColor .B ();_ffbf .IC =_bd .MakeArrayFromFloats ([]float64 {_ebbad ,_ffdf ,_daag });}else {_ffbf .IC =_bd .MakeArrayFromIntegers ([]int {});};if rectDef .Opacity < 1.0{_ffbf .CA =_bd .MakeFloat (rectDef .Opacity );};_fegg ,_edc ,_deaa :=_dgcd (rectDef );if _deaa !=nil {return nil ,_deaa ;};_ffbf .AP =_fegg ;_ffbf .Rect =_bd .MakeArrayFromFloats ([]float64 {_edc .Llx ,_edc .Lly ,_edc .Urx ,_edc .Ury });return _ffbf .PdfAnnotation ,nil ;};type quadding int ; |