2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// Copyright 2020 FoxyUtils ehf. All rights reserved.
|
|
|
|
//
|
|
|
|
// This is a commercial product and requires a license to operate.
|
|
|
|
// A trial license can be obtained at https://unidoc.io
|
|
|
|
//
|
|
|
|
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by the UniDoc End User License Agreement
|
|
|
|
// terms that can be accessed at https://unidoc.io/eula/
|
|
|
|
|
|
|
|
// Package annotator provides an interface for creating annotations with appearance
|
|
|
|
// streams. It goes beyond the models package which includes definitions of basic annotation models, in that it
|
|
|
|
// can create the appearance streams which specify the exact appearance as needed by many pdf viewers for consistent
|
|
|
|
// appearance of the annotations.
|
|
|
|
// It also contains methods for generating appearance streams for fields via widget annotations.
|
2020-11-23 22:15:56 +00:00
|
|
|
package annotator ;import (_e "bytes";_de "errors";_d "github.com/unidoc/unipdf/v3/common";_f "github.com/unidoc/unipdf/v3/contentstream";_a "github.com/unidoc/unipdf/v3/contentstream/draw";_fac "github.com/unidoc/unipdf/v3/core";_g "github.com/unidoc/unipdf/v3/internal/textencoding";_fe "github.com/unidoc/unipdf/v3/model";_fd "image";_ga "math";_ff "strings";_fa "unicode";);func _dd (_aeg CircleAnnotationDef ,_ba string )([]byte ,*_fe .PdfRectangle ,*_fe .PdfRectangle ,error ){_aa :=_a .Circle {X :_aeg .X ,Y :_aeg .Y ,Width :_aeg .Width ,Height :_aeg .Height ,FillEnabled :_aeg .FillEnabled ,FillColor :_aeg .FillColor ,BorderEnabled :_aeg .BorderEnabled ,BorderWidth :_aeg .BorderWidth ,BorderColor :_aeg .BorderColor ,Opacity :_aeg .Opacity };_egb ,_gad ,_def :=_aa .Draw (_ba );if _def !=nil {return nil ,nil ,nil ,_def ;};_egcf :=&_fe .PdfRectangle {};_egcf .Llx =_aeg .X +_gad .Llx ;_egcf .Lly =_aeg .Y +_gad .Lly ;_egcf .Urx =_aeg .X +_gad .Urx ;_egcf .Ury =_aeg .Y +_gad .Ury ;return _egb ,_gad ,_egcf ,nil ;};
|
2020-11-11 18:48:37 +00:00
|
|
|
|
2020-11-23 22:15:56 +00:00
|
|
|
// CreateLineAnnotation creates a line annotation object that can be added to page PDF annotations.
|
|
|
|
func CreateLineAnnotation (lineDef LineAnnotationDef )(*_fe .PdfAnnotation ,error ){_bdeb :=_fe .NewPdfAnnotationLine ();_bdeb .L =_fac .MakeArrayFromFloats ([]float64 {lineDef .X1 ,lineDef .Y1 ,lineDef .X2 ,lineDef .Y2 });_ecg :=_fac .MakeName ("\u004e\u006f\u006e\u0065");if lineDef .LineEndingStyle1 ==_a .LineEndingStyleArrow {_ecg =_fac .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");};_addd :=_fac .MakeName ("\u004e\u006f\u006e\u0065");if lineDef .LineEndingStyle2 ==_a .LineEndingStyleArrow {_addd =_fac .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");};_bdeb .LE =_fac .MakeArray (_ecg ,_addd );if lineDef .Opacity < 1.0{_bdeb .CA =_fac .MakeFloat (lineDef .Opacity );};_beed ,_eeda ,_ebadb :=lineDef .LineColor .R (),lineDef .LineColor .G (),lineDef .LineColor .B ();_bdeb .IC =_fac .MakeArrayFromFloats ([]float64 {_beed ,_eeda ,_ebadb });_bdeb .C =_fac .MakeArrayFromFloats ([]float64 {_beed ,_eeda ,_ebadb });_fgbe :=_fe .NewBorderStyle ();_fgbe .SetBorderWidth (lineDef .LineWidth );_bdeb .BS =_fgbe .ToPdfObject ();_gea ,_ecfg ,_bcg :=_fcb (lineDef );if _bcg !=nil {return nil ,_bcg ;};_bdeb .AP =_gea ;_bdeb .Rect =_fac .MakeArrayFromFloats ([]float64 {_ecfg .Llx ,_ecfg .Lly ,_ecfg .Urx ,_ecfg .Ury });return _bdeb .PdfAnnotation ,nil ;};func _dadd (_cdf RectangleAnnotationDef )(*_fac .PdfObjectDictionary ,*_fe .PdfRectangle ,error ){_bgb :=_fe .NewXObjectForm ();_bgb .Resources =_fe .NewPdfPageResources ();_ccg :="";if _cdf .Opacity < 1.0{_egde :=_fac .MakeDict ();_egde .Set ("\u0063\u0061",_fac .MakeFloat (_cdf .Opacity ));_egde .Set ("\u0043\u0041",_fac .MakeFloat (_cdf .Opacity ));_aega :=_bgb .Resources .AddExtGState ("\u0067\u0073\u0031",_egde );if _aega !=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 ,_aega ;};_ccg ="\u0067\u0073\u0031";};_ffdc ,_fcfcd ,_fgc ,_abge :=_gede (_cdf ,_ccg );if _abge !=nil {return nil ,nil ,_abge ;};_abge =_bgb .SetContentStream (_ffdc ,nil );if _abge !=nil {return nil ,nil ,_abge ;};_bgb .BBox =_fcfcd .ToPdfObject ();_eeeb :=_fac .MakeDict ();_eeeb .Set ("\u004e",_bgb .ToPdfObject ());return _eeeb ,_fgc ,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 *_fe .PdfPage ,name string ,rect []float64 ,opt TextFieldOptions )(*_fe .PdfFieldText ,error ){if page ==nil {return nil ,_de .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};if len (name )<=0{return nil ,_de .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 ,_de .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");};_fbb :=_fe .NewPdfField ();_eeeab :=&_fe .PdfFieldText {};_fbb .SetContext (_eeeab );_eeeab .PdfField =_fbb ;_eeeab .T =_fac .MakeString (name );if opt .MaxLen > 0{_eeeab .MaxLen =_fac .MakeInteger (int64 (opt .MaxLen ));};if len (opt .Value )> 0{_eeeab .V =_fac .MakeString (opt .Value );};_egga :=_fe .NewPdfAnnotationWidget ();_egga .Rect =_fac .MakeArrayFromFloats (rect );_egga .P =page .ToPdfObject ();_egga .F =_fac .MakeInteger (4);_egga .Parent =_eeeab .ToPdfObject ();_eeeab .Annotations =append (_eeeab .Annotations ,_egga );return _eeeab ,nil ;};func _gede (_aad RectangleAnnotationDef ,_acda string )([]byte ,*_fe .PdfRectangle ,*_fe .PdfRectangle ,error ){_adbf :=_a .Rectangle {X :0,Y :0,Width :_aad .Width ,Height :_aad .Height ,FillEnabled :_aad .FillEnabled ,FillColor :_aad .FillColor ,BorderEnabled :_aad .BorderEnabled ,BorderWidth :2*_aad .BorderWidth ,BorderColor :_aad .BorderColor ,Opacity :_aad .Opacity };_badad ,_bgc ,_gba :=_adbf .Draw (_acda );if _gba !=nil {return nil ,nil ,nil ,_gba ;};_ddgd :=&_fe .PdfRectangle {};_ddgd .Llx =_aad .X +_bgc .Llx ;_ddgd .Lly =_aad .Y +_bgc .Lly ;_ddgd .Urx =_aad .X +_bgc .Urx ;_ddgd .Ury =_aad .Y +_bgc .Ury ;return _badad ,_bgc ,_ddgd ,nil ;};const (_cf quadding =0;_bf quadding =1;_aae quadding =2;);
|
2020-11-11 18:48:37 +00:00
|
|
|
|
|
|
|
// NewSignatureLine returns a new signature line displayed as a part of the
|
|
|
|
// signature field appearance.
|
2020-11-23 22:15:56 +00:00
|
|
|
func NewSignatureLine (desc ,text string )*SignatureLine {return &SignatureLine {Desc :desc ,Text :text };};
|
2020-11-11 18:48:37 +00:00
|
|
|
|
2020-11-23 22:15:56 +00:00
|
|
|
// LineAnnotationDef defines a line between point 1 (X1,Y1) and point 2 (X2,Y2). The line ending styles can be none
|
|
|
|
// (regular line), or arrows at either end. The line also has a specified width, color and opacity.
|
|
|
|
type LineAnnotationDef struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_fe .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 _a .LineEndingStyle ;LineEndingStyle2 _a .LineEndingStyle ;};
|
2020-11-11 18:48:37 +00:00
|
|
|
|
2020-11-23 22:15:56 +00:00
|
|
|
// CircleAnnotationDef defines a circle annotation or ellipse at position (X, Y) and Width and Height.
|
|
|
|
// The annotation has various style parameters including Fill and Border options and Opacity.
|
|
|
|
type CircleAnnotationDef struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_fe .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_fe .PdfColorDeviceRGB ;Opacity float64 ;};func _faef ()_fac .StreamEncoder {return _fac .NewFlateEncoder ()};func _gca (_ffcg *_f .ContentCreator ,_fcfe AppearanceStyle ,_feg ,_adda float64 ){_ffcg .Add_q ().Add_re (0,0,_feg ,_adda ).Add_re (0,_adda /2,_feg ,_adda /2).Add_re (0,0,_feg ,_adda ).Add_re (_feg /2,0,_feg /2,_adda ).Add_w (_fcfe .BorderSize ).SetStrokingColor (_fcfe .BorderColor ).SetNonStrokingColor (_fcfe .FillColor ).Add_B ().Add_Q ();};func _egbc (_bbeb *_fe .PdfAcroForm ,_bcd *_fe .PdfAnnotationWidget ,_ebbb *_fe .PdfFieldChoice ,_feaf AppearanceStyle )(*_fac .PdfObjectDictionary ,error ){_beea ,_gfg :=_fac .GetArray (_bcd .Rect );if !_gfg {return nil ,_de .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_gbd ,_cecg :=_fe .NewPdfRectangle (*_beea );if _cecg !=nil {return nil ,_cecg ;};_bdgg ,_gebb :=_gbd .Width (),_gbd .Height ();_d .Log .Debug ("\u0043\u0068\u006f\u0069\u0063\u0065\u002c\u0020\u0077\u0061\u0020\u0042S\u003a\u0020\u0025\u0076",_bcd .BS );_cbf ,_cecg :=_f .NewContentStreamParser (_ece (_ebbb .PdfField )).Parse ();if _cecg !=nil {return nil ,_cecg ;};_ffae ,_gaec :=_fac .GetDict (_bcd .MK );if _gaec {_dbd ,_ :=_fac .GetDict (_bcd .BS );_daaa :=_feaf .applyAppearanceCharacteristics (_ffae ,_dbd ,nil );if _daaa !=nil {return nil ,_daaa ;};};_aedg :=_fac .MakeDict ();for _ ,_dgec :=range _ebbb .Opt .Elements (){if _cbe ,_gcf :=_fac .GetArray (_dgec );_gcf &&_cbe .Len ()==2{_dgec =_cbe .Get (1);};var _eee string ;if _eeaf ,_cce :=_fac .GetString (_dgec );_cce {_eee =_eeaf .Decoded ();}else if _fefc ,_fefd :=_fac .GetName (_dgec );_fefd {_eee =_fefc .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",_dgec );return nil ,_de .New ("\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u002f\u0073t\u0072\u0069\u006e\u0067");};if len (_eee )> 0{_gfb ,_ebda :=_addb (_ebbb .PdfField ,_bdgg ,_gebb ,_eee ,_feaf ,_cbf ,_bbeb .DR ,_ffae );if _ebda !=nil {return nil ,_ebda ;};_aedg .Set (*_fac .MakeName (_eee ),_gfb .ToPdfObject ());};};_gbe :=_fac .MakeDict ();_gbe .Set ("\u004e",_aedg );return _gbe ,nil ;};func _fcb (_gabg LineAnnotationDef )(*_fac .PdfObjectDictionary ,*_fe .PdfRectangle ,error ){_fbfd :=_fe .NewXObjectForm ();_fbfd .Resources =_fe .NewPdfPageResources ();_dece :="";if _gabg .Opacity < 1.0{_bbaa :=_fac .MakeDict ();_bbaa .Set ("\u0063\u0061",_fac .MakeFloat (_gabg .Opacity ));_cbbf :=_fbfd .Resources .AddExtGState ("\u0067\u0073\u0031",_bbaa );if _cbbf !=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 ,_cbbf ;};_dece ="\u0067\u0073\u0031";};_eef ,_egbb ,_cdbgb ,_ddbf :=_cfd (_gabg ,_dece );if _ddbf !=nil {return nil ,nil ,_ddbf ;};_ddbf =_fbfd .SetContentStream (_eef ,nil );if _ddbf !=nil {return nil ,nil ,_ddbf ;};_fbfd .BBox =_egbb .ToPdfObject ();_bbff :=_fac .MakeDict ();_bbff .Set ("\u004e",_fbfd .ToPdfObject ());return _bbff ,_cdbgb ,nil ;};const (SignatureImageLeft SignatureImagePosition =iota ;SignatureImageRight ;SignatureImageTop ;SignatureImageBottom ;);func _ece (_cfe *_fe .PdfField )string {if _cfe ==nil {return "";};_gggc ,_gef :=_cfe .GetContext ().(*_fe .PdfFieldText );if !_gef {return _ece (_cfe .Parent );};if _gggc .DA !=nil {return _gggc .DA .Str ();};return _ece (_gggc .Parent );};
|
2020-11-11 18:48:37 +00:00
|
|
|
|
|
|
|
// AppearanceFontStyle defines font style characteristics for form fields,
|
|
|
|
// used in the filling/flattening process.
|
|
|
|
type AppearanceFontStyle struct{
|
|
|
|
|
|
|
|
// Fallback represents a global font fallback, used for fields which do
|
|
|
|
// not specify a font in their default appearance (DA). The fallback is
|
|
|
|
// also used if there is a font specified in the DA, but it is not
|
|
|
|
// found in the AcroForm resources (DR).
|
|
|
|
Fallback *AppearanceFont ;
|
|
|
|
|
|
|
|
// FieldFallbacks defines font fallbacks for specific fields. The map keys
|
|
|
|
// represent the names of the fields (which can be specified by their
|
|
|
|
// partial or full names). Specific field fallback fonts take precedence
|
|
|
|
// over the global font fallback.
|
|
|
|
FieldFallbacks map[string ]*AppearanceFont ;
|
|
|
|
|
|
|
|
// ForceReplace forces the replacement of fonts in the filling/flattening
|
|
|
|
// process, even if the default appearance (DA) specify a valid font.
|
|
|
|
// If no fallback font is provided, setting this field has no effect.
|
2020-11-23 22:15:56 +00:00
|
|
|
ForceReplace bool ;};
|
2020-11-11 18:48:37 +00:00
|
|
|
|
|
|
|
// SignatureLine represents a line of information in the signature field appearance.
|
2020-11-23 22:15:56 +00:00
|
|
|
type SignatureLine struct{Desc string ;Text string ;};func (_acfg *AppearanceStyle )applyAppearanceCharacteristics (_ecb *_fac .PdfObjectDictionary ,_dbg *_fac .PdfObjectDictionary ,_bbf *_fe .PdfFont )error {if !_acfg .AllowMK {return nil ;};if CA ,_aedf :=_fac .GetString (_ecb .Get ("\u0043\u0041"));_aedf &&_bbf !=nil {_aggc :=CA .Bytes ();if len (_aggc )!=0{_gcac :=[]rune (_bbf .Encoder ().Decode (_aggc ));if len (_gcac )==1{_acfg .CheckmarkRune =_gcac [0];};};};if BC ,_afa :=_fac .GetArray (_ecb .Get ("\u0042\u0043"));_afa {_dbga ,_abcd :=BC .ToFloat64Array ();if _abcd !=nil {return _abcd ;};switch len (_dbga ){case 1:_acfg .BorderColor =_fe .NewPdfColorDeviceGray (_dbga [0]);case 3:_acfg .BorderColor =_fe .NewPdfColorDeviceRGB (_dbga [0],_dbga [1],_dbga [2]);case 4:_acfg .BorderColor =_fe .NewPdfColorDeviceCMYK (_dbga [0],_dbga [1],_dbga [2],_dbga [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 (_dbga ));};if _dbg !=nil {if _cfba ,_eggg :=_fac .GetNumberAsFloat (_dbg .Get ("\u0057"));_eggg ==nil {_acfg .BorderSize =_cfba ;};};};if BG ,_bfa :=_fac .GetArray (_ecb .Get ("\u0042\u0047"));_bfa {_afab ,_gfbb :=BG .ToFloat64Array ();if _gfbb !=nil {return _gfbb ;};switch len (_afab ){case 1:_acfg .FillColor =_fe .NewPdfColorDeviceGray (_afab [0]);case 3:_acfg .FillColor =_fe .NewPdfColorDeviceRGB (_afab [0],_afab [1],_afab [2]);case 4:_acfg .FillColor =_fe .NewPdfColorDeviceCMYK (_afab [0],_afab [1],_afab [2],_afab [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 (_afab ));};};return nil ;};func _cfd (_edcg LineAnnotationDef ,_gdbb string )([]byte ,*_fe .PdfRectangle ,*_fe .PdfRectangle ,error ){_gac :=_a .Line {X1 :0,Y1 :0,X2 :_edcg .X2 -_edcg .X1 ,Y2 :_edcg .Y2 -_edcg .Y1 ,LineColor :_edcg .LineColor ,Opacity :_edcg .Opacity ,LineWidth :_edcg .LineWidth ,LineEndingStyle1 :_edcg .LineEndingStyle1 ,LineEndingStyle2 :_edcg .LineEndingStyle2 };_dfdc ,_gdgf ,_gaaf :=_gac .Draw (_gdbb );if _gaaf !=nil {return nil ,nil ,nil ,_gaaf ;};_bdgdc :=&_fe .PdfRectangle {};_bdgdc .Llx =_edcg .X1 +_gdgf .Llx ;_bdgdc .Lly =_edcg .Y1 +_gdgf .Lly ;_bdgdc .Urx =_edcg .X1 +_gdgf .Urx ;_bdgdc .Ury =_edcg .Y1 +_gdgf .Ury ;return _dfdc ,_gdgf ,_bdgdc ,nil ;};
|
2020-11-11 18:48:37 +00:00
|
|
|
|
2020-11-23 22:15:56 +00:00
|
|
|
// AppearanceStyle defines style parameters for appearance stream generation.
|
|
|
|
type AppearanceStyle struct{
|
|
|
|
|
|
|
|
// How much of Rect height to fill when autosizing text.
|
|
|
|
AutoFontSizeFraction float64 ;
|
|
|
|
|
|
|
|
// CheckmarkRune is a rune used for check mark in checkboxes (for ZapfDingbats font).
|
|
|
|
CheckmarkRune rune ;BorderSize float64 ;BorderColor _fe .PdfColor ;FillColor _fe .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 ;};
|
|
|
|
|
|
|
|
// 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 ;_cad *AppearanceStyle ;};
|
|
|
|
|
|
|
|
// Style returns the appearance style of `fa`. If not specified, returns default style.
|
|
|
|
func (_dgg FieldAppearance )Style ()AppearanceStyle {if _dgg ._cad !=nil {return *_dgg ._cad ;};return AppearanceStyle {AutoFontSizeFraction :0.65,CheckmarkRune :'✔',BorderSize :0.0,BorderColor :_fe .NewPdfColorDeviceGray (0),FillColor :_fe .NewPdfColorDeviceGray (1),MultilineLineHeight :1.2,MultilineVAlignMiddle :false ,DrawAlignmentReticle :false ,AllowMK :true };};
|
|
|
|
|
|
|
|
// SetStyle applies appearance `style` to `fa`.
|
|
|
|
func (_ab *FieldAppearance )SetStyle (style AppearanceStyle ){_ab ._cad =&style };
|
|
|
|
|
|
|
|
// 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 *_fe .PdfPage ,name string ,rect []float64 ,opt ComboboxFieldOptions )(*_fe .PdfFieldChoice ,error ){if page ==nil {return nil ,_de .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};if len (name )<=0{return nil ,_de .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 ,_de .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");};_egbd :=_fe .NewPdfField ();_bfed :=&_fe .PdfFieldChoice {};_egbd .SetContext (_bfed );_bfed .PdfField =_egbd ;_bfed .T =_fac .MakeString (name );_bfed .Opt =_fac .MakeArray ();for _ ,_gdec :=range opt .Choices {_bfed .Opt .Append (_fac .MakeString (_gdec ));};_bfed .SetFlag (_fe .FieldFlagCombo );_afe :=_fe .NewPdfAnnotationWidget ();_afe .Rect =_fac .MakeArrayFromFloats (rect );_afe .P =page .ToPdfObject ();_afe .F =_fac .MakeInteger (4);_afe .Parent =_bfed .ToPdfObject ();_bfed .Annotations =append (_bfed .Annotations ,_afe );return _bfed ,nil ;};
|
|
|
|
|
|
|
|
// NewSignatureFieldOpts returns a new initialized instance of options
|
|
|
|
// used to generate a signature appearance.
|
|
|
|
func NewSignatureFieldOpts ()*SignatureFieldOpts {return &SignatureFieldOpts {Font :_fe .DefaultFont (),FontSize :10,LineHeight :1,AutoSize :true ,TextColor :_fe .NewPdfColorDeviceGray (0),BorderColor :_fe .NewPdfColorDeviceGray (0),FillColor :_fe .NewPdfColorDeviceGray (1),Encoder :_fac .NewFlateEncoder (),ImagePosition :SignatureImageLeft };};
|
|
|
|
|
|
|
|
// 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 *_fe .PdfPage ,name string ,rect []float64 ,opt CheckboxFieldOptions )(*_fe .PdfFieldButton ,error ){if page ==nil {return nil ,_de .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};if len (name )<=0{return nil ,_de .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 ,_de .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");};_bffe ,_ggde :=_fe .NewStandard14Font (_fe .ZapfDingbatsName );if _ggde !=nil {return nil ,_ggde ;};_agef :=_fe .NewPdfField ();_ddef :=&_fe .PdfFieldButton {};_agef .SetContext (_ddef );_ddef .PdfField =_agef ;_ddef .T =_fac .MakeString (name );_ddef .SetType (_fe .ButtonTypeCheckbox );_febc :="\u004f\u0066\u0066";if opt .Checked {_febc ="\u0059\u0065\u0073";};_ddef .V =_fac .MakeName (_febc );_cbb :=_fe .NewPdfAnnotationWidget ();_cbb .Rect =_fac .MakeArrayFromFloats (rect );_cbb .P =page .ToPdfObject ();_cbb .F =_fac .MakeInteger (4);_cbb .Parent =_ddef .ToPdfObject ();_dff :=rect [2]-rect [0];_eedd :=rect [3]-rect [1];var _cbbb _e .Buffer ;_cbbb .WriteString ("\u0071\u000a");_cbbb .WriteString ("\u0030 \u0030\u0020\u0031\u0020\u0072\u0067\n");_cbbb .WriteString ("\u0042\u0054\u000a");_cbbb .WriteString ("\u002f\u005a\u0061D\u0062\u0020\u0031\u0032\u0020\u0054\u0066\u000a");_cbbb .WriteString ("\u0045\u0054\u000a");_cbbb .WriteString ("\u0051\u000a");_cbg :=_f .NewContentCreator ();_cbg .Add_q ();_cbg .Add_rg (0,0,1);_cbg .Add_BT ();_cbg .Add_Tf (*_fac .MakeName ("\u005a\u0061\u0044\u0062"),12);_cbg .Add_Td (0,0);_cbg .Add_ET ();_cbg .Add_Q ();_dagd :=_fe .NewXObjectForm ();_dagd .SetContentStream (_cbg .Bytes (),_fac .NewRawEncoder ());_dagd .BBox =_fac .MakeArrayFromFloats ([]float64 {0,0,_dff ,_eedd });_dagd .Resources =_fe .NewPdfPageResources ();_dagd .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_bffe .ToPdfObject ());_cbg =_f .NewContentCreator ();_cbg .Add_q ();_cbg .Add_re (0,0,_dff ,_eedd );_cbg .Add_W ().Add_n ();_cbg .Add_rg (0,0,1);_cbg .Translate (0,3.0);_cbg .Add_BT ();_cbg .Add_Tf (*_fac .MakeName ("\u005a\u0061\u0044\u0062"),12);_cbg .Add_Td (0,0);_cbg .Add_Tj (*_fac .MakeString ("\u0034"));_cbg .Add_ET ();_cbg .Add_Q ();_aab :=_fe .NewXObjectForm ();_aab .SetContentStream (_cbg .Bytes (),_fac .NewRawEncoder ());_aab .BBox =_fac .MakeArrayFromFloats ([]float64 {0,0,_dff ,_eedd });_aab .Resources =_fe .NewPdfPageResources ();_aab .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_bffe .ToPdfObject ());_eaag :=_fac .MakeDict ();_eaag .Set ("\u004f\u0066\u0066",_dagd .ToPdfObject ());_eaag .Set ("\u0059\u0065\u0073",_aab .ToPdfObject ());_eeac :=_fac .MakeDict ();_eeac .Set ("\u004e",_eaag );_cbb .AP =_eeac ;_cbb .AS =_fac .MakeName (_febc );_ddef .Annotations =append (_ddef .Annotations ,_cbb );return _ddef ,nil ;};
|
|
|
|
|
|
|
|
// CreateCircleAnnotation creates a circle/ellipse annotation object with appearance stream that can be added to
|
|
|
|
// page PDF annotations.
|
|
|
|
func CreateCircleAnnotation (circDef CircleAnnotationDef )(*_fe .PdfAnnotation ,error ){_c :=_fe .NewPdfAnnotationCircle ();if circDef .BorderEnabled {_bb ,_ee ,_eg :=circDef .BorderColor .R (),circDef .BorderColor .G (),circDef .BorderColor .B ();_c .C =_fac .MakeArrayFromFloats ([]float64 {_bb ,_ee ,_eg });_ffc :=_fe .NewBorderStyle ();_ffc .SetBorderWidth (circDef .BorderWidth );_c .BS =_ffc .ToPdfObject ();};if circDef .FillEnabled {_ega ,_df ,_cg :=circDef .FillColor .R (),circDef .FillColor .G (),circDef .FillColor .B ();_c .IC =_fac .MakeArrayFromFloats ([]float64 {_ega ,_df ,_cg });}else {_c .IC =_fac .MakeArrayFromIntegers ([]int {});};if circDef .Opacity < 1.0{_c .CA =_fac .MakeFloat (circDef .Opacity );};_ae ,_eb ,_fc :=_cgg (circDef );if _fc !=nil {return nil ,_fc ;};_c .AP =_ae ;_c .Rect =_fac .MakeArrayFromFloats ([]float64 {_eb .Llx ,_eb .Lly ,_eb .Urx ,_eb .Ury });return _c .PdfAnnotation ,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 ;};
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2020-10-19 10:58:10 +00:00
|
|
|
// SignatureFieldOpts represents a set of options used to configure
|
|
|
|
// an appearance widget dictionary.
|
|
|
|
type SignatureFieldOpts struct{
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2020-10-19 10:58:10 +00:00
|
|
|
// Rect represents the area the signature annotation is displayed on.
|
|
|
|
Rect []float64 ;
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2020-10-19 10:58:10 +00:00
|
|
|
// AutoSize specifies if the content of the appearance should be
|
|
|
|
// scaled to fit in the annotation rectangle.
|
|
|
|
AutoSize bool ;
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2020-10-19 10:58:10 +00:00
|
|
|
// Font specifies the font of the text content.
|
2020-11-23 22:15:56 +00:00
|
|
|
Font *_fe .PdfFont ;
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2020-10-19 10:58:10 +00:00
|
|
|
// FontSize specifies the size of the text content.
|
|
|
|
FontSize float64 ;
|
2020-09-21 01:20:10 +00:00
|
|
|
|
2020-10-19 10:58:10 +00:00
|
|
|
// LineHeight specifies the height of a line of text in the appearance annotation.
|
|
|
|
LineHeight float64 ;
|
2020-09-21 01:20:10 +00:00
|
|
|
|
2020-10-19 10:58:10 +00:00
|
|
|
// TextColor represents the color of the text content displayed.
|
2020-11-23 22:15:56 +00:00
|
|
|
TextColor _fe .PdfColor ;
|
2020-10-12 14:17:59 +00:00
|
|
|
|
2020-10-19 10:58:10 +00:00
|
|
|
// FillColor represents the background color of the appearance annotation area.
|
2020-11-23 22:15:56 +00:00
|
|
|
FillColor _fe .PdfColor ;
|
2020-09-21 01:20:10 +00:00
|
|
|
|
2020-10-19 10:58:10 +00:00
|
|
|
// BorderSize represents border size of the appearance annotation area.
|
|
|
|
BorderSize float64 ;
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2020-10-19 10:58:10 +00:00
|
|
|
// BorderColor represents the border color of the appearance annotation area.
|
2020-11-23 22:15:56 +00:00
|
|
|
BorderColor _fe .PdfColor ;
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2020-10-19 10:58:10 +00:00
|
|
|
// WatermarkImage specifies the image used as a watermark that will be rendered
|
|
|
|
// behind the signature.
|
2020-11-23 22:15:56 +00:00
|
|
|
WatermarkImage _fd .Image ;
|
2020-10-12 14:17:59 +00:00
|
|
|
|
2020-10-19 10:58:10 +00:00
|
|
|
// Image represents the image used for the signature appearance.
|
2020-11-23 22:15:56 +00:00
|
|
|
Image _fd .Image ;
|
2020-10-12 14:17:59 +00:00
|
|
|
|
2020-10-19 10:58:10 +00:00
|
|
|
// Encoder specifies the image encoder used for image signature. Defaults to flate encoder.
|
2020-11-23 22:15:56 +00:00
|
|
|
Encoder _fac .StreamEncoder ;
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2020-10-19 10:58:10 +00:00
|
|
|
// ImagePosition specifies the image location relative to the text signature.
|
2020-11-23 22:15:56 +00:00
|
|
|
ImagePosition SignatureImagePosition ;};func _cgg (_be CircleAnnotationDef )(*_fac .PdfObjectDictionary ,*_fe .PdfRectangle ,error ){_gg :=_fe .NewXObjectForm ();_gg .Resources =_fe .NewPdfPageResources ();_egd :="";if _be .Opacity < 1.0{_ce :=_fac .MakeDict ();_ce .Set ("\u0063\u0061",_fac .MakeFloat (_be .Opacity ));_ce .Set ("\u0043\u0041",_fac .MakeFloat (_be .Opacity ));_deb :=_gg .Resources .AddExtGState ("\u0067\u0073\u0031",_ce );if _deb !=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 ,_deb ;};_egd ="\u0067\u0073\u0031";};_dg ,_ec ,_gc ,_ca :=_dd (_be ,_egd );if _ca !=nil {return nil ,nil ,_ca ;};_ca =_gg .SetContentStream (_dg ,nil );if _ca !=nil {return nil ,nil ,_ca ;};_gg .BBox =_ec .ToPdfObject ();_egc :=_fac .MakeDict ();_egc .Set ("\u004e",_gg .ToPdfObject ());return _egc ,_gc ,nil ;};
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2020-11-23 22:15:56 +00:00
|
|
|
// TextFieldOptions defines optional parameter for a text field in a form.
|
|
|
|
type TextFieldOptions struct{MaxLen int ;Value string ;};
|
|
|
|
|
|
|
|
// CreateRectangleAnnotation creates a rectangle annotation object that can be added to page PDF annotations.
|
|
|
|
func CreateRectangleAnnotation (rectDef RectangleAnnotationDef )(*_fe .PdfAnnotation ,error ){_fegf :=_fe .NewPdfAnnotationSquare ();if rectDef .BorderEnabled {_bdbg ,_dcdc ,_dca :=rectDef .BorderColor .R (),rectDef .BorderColor .G (),rectDef .BorderColor .B ();_fegf .C =_fac .MakeArrayFromFloats ([]float64 {_bdbg ,_dcdc ,_dca });_cdeg :=_fe .NewBorderStyle ();_cdeg .SetBorderWidth (rectDef .BorderWidth );_fegf .BS =_cdeg .ToPdfObject ();};if rectDef .FillEnabled {_fccc ,_aegeg ,_egaf :=rectDef .FillColor .R (),rectDef .FillColor .G (),rectDef .FillColor .B ();_fegf .IC =_fac .MakeArrayFromFloats ([]float64 {_fccc ,_aegeg ,_egaf });}else {_fegf .IC =_fac .MakeArrayFromIntegers ([]int {});};if rectDef .Opacity < 1.0{_fegf .CA =_fac .MakeFloat (rectDef .Opacity );};_fefg ,_bcfa ,_bbffg :=_dadd (rectDef );if _bbffg !=nil {return nil ,_bbffg ;};_fegf .AP =_fefg ;_fegf .Rect =_fac .MakeArrayFromFloats ([]float64 {_bcfa .Llx ,_bcfa .Lly ,_bcfa .Urx ,_bcfa .Ury });return _fegf .PdfAnnotation ,nil ;};func _fae (_fcg *_fe .PdfAnnotationWidget ,_ac *_fe .PdfFieldText ,_abe *_fe .PdfPageResources ,_ffca AppearanceStyle )(*_fac .PdfObjectDictionary ,error ){_dde :=_fe .NewPdfPageResources ();_bg ,_dge :=_fac .GetArray (_fcg .Rect );if !_dge {return nil ,_de .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_gaeb ,_ge :=_fe .NewPdfRectangle (*_bg );if _ge !=nil {return nil ,_ge ;};_gaebc ,_bd :=_gaeb .Width (),_gaeb .Height ();_ggc ,_aac :=_gaebc ,_bd ;_gb ,_gda :=_fac .GetDict (_fcg .MK );if _gda {_eff ,_ :=_fac .GetDict (_fcg .BS );_fg :=_ffca .applyAppearanceCharacteristics (_gb ,_eff ,nil );if _fg !=nil {return nil ,_fg ;};};_af ,_ge :=_f .NewContentStreamParser (_ece (_ac .PdfField )).Parse ();if _ge !=nil {return nil ,_ge ;};_gaf :=_f .NewContentCreator ();if _ffca .BorderSize > 0{_aggd (_gaf ,_ffca ,_gaebc ,_bd );};if _ffca .DrawAlignmentReticle {_aaa :=_ffca ;_aaa .BorderSize =0.2;_gca (_gaf ,_aaa ,_gaebc ,_bd );};_gaf .Add_BMC ("\u0054\u0078");_gaf .Add_q ();_gaebc ,_bd =_ffca .applyRotation (_gb ,_gaebc ,_bd ,_gaf );_gaf .Add_BT ();_fcc ,_fb ,_ge :=_ffca .processDA (_ac .PdfField ,_af ,_abe ,_dde ,_gaf );if _ge !=nil {return nil ,_ge ;};_dda :=_fcc .Font ;_aag :=_fcc .Size ;_ag :=_fac .MakeName (_fcc .Name );_ffg :=_aag ==0;if _ffg &&_fb {_aag =_bd *_ffca .AutoFontSizeFraction ;};_eead :=_dda .Encoder ();if _eead ==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");_eead =_g .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};_fgd ,_ge :=_dda .GetFontDescriptor ();if _ge !=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 _eaf string ;if _dfa ,_cac :=_fac .GetString (_ac .V );_cac {_eaf =_dfa .Decoded ();};if len (_eaf )==0{return nil ,nil ;};_ege :=[]string {_eaf };_cd :=false ;if _ac .Flags ().Has (_fe .FieldFlagMultiline ){_cd =true ;_eaf =_ff .Replace (_eaf ,"\u000d\u000a","\u000a",-1);_eaf =_ff .Replace (_eaf ,"\u000d","\u000a",-1);_ege =_ff .Split (_eaf ,"\u000a");};_cga :=0.0;_bfc :=0;if _eead !=nil {_eab :=len (_ege );_ged :=0;for _ged < _eab {var _dfb float64 ;_da :=-1;_gedg :=0.0;for _fgdc ,_bfb :=range _ege [_ged ]{if _bfb ==' '{_da =_fgdc ;_dfb =_gedg ;};_efg ,_bfe :=_dda .GetRuneMetrics (_bfb );if !_bfe {_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",_bfb );continue ;};_gedg +=_efg .Wx ;i
|
|
|
|
|
|
|
|
// GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`.
|
|
|
|
// Implements interface model.FieldAppearanceGenerator.
|
|
|
|
func (_gae FieldAppearance )GenerateAppearanceDict (form *_fe .PdfAcroForm ,field *_fe .PdfField ,wa *_fe .PdfAnnotationWidget )(*_fac .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 );_ ,_eec :=field .GetContext ().(*_fe .PdfFieldText );_ffd ,_cee :=_fac .GetDict (wa .AP );if _cee &&_gae .OnlyIfMissing &&(!_eec ||!_gae .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 _ffd ,nil ;};if form .DR ==nil {form .DR =_fe .NewPdfPageResources ();};switch _dea :=field .GetContext ().(type ){case *_fe .PdfFieldText :_ggd :=_dea ;switch {case _ggd .Flags ().Has (_fe .FieldFlagPassword ):return nil ,nil ;case _ggd .Flags ().Has (_fe .FieldFlagFileSelect ):return nil ,nil ;case _ggd .Flags ().Has (_fe .FieldFlagComb ):if _ggd .MaxLen !=nil {_ef ,_egcd :=_cc (wa ,_ggd ,form .DR ,_gae .Style ());if _egcd !=nil {return nil ,_egcd ;};return _ef ,nil ;};};_abc ,_gd :=_fae (wa ,_ggd ,form .DR ,_gae .Style ());if _gd !=nil {return nil ,_gd ;};return _abc ,nil ;case *_fe .PdfFieldButton :_ecc :=_dea ;if _ecc .IsCheckbox (){_bef ,_ea :=_ffe (wa ,_ecc ,form .DR ,_gae .Style ());if _ea !=nil {return nil ,_ea ;};return _bef ,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",_ecc .GetType ());case *_fe .PdfFieldChoice :_aaf :=_dea ;switch {case _aaf .Flags ().Has (_fe .FieldFlagCombo ):_ddf ,_cgc :=_egbc (form ,wa ,_aaf ,_gae .Style ());if _cgc !=nil {return nil ,_cgc ;};return _ddf ,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",_aaf .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",_dea );};return nil ,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 *_fe .PdfSignature ,lines []*SignatureLine ,opts *SignatureFieldOpts )(*_fe .PdfFieldSignature ,error ){if signature ==nil {return nil ,_de .New ("\u0073\u0069\u0067na\u0074\u0075\u0072\u0065\u0020\u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u006e\u0069\u006c");};_dbcc ,_cefa :=_dbdc (lines ,opts );if _cefa !=nil {return nil ,_cefa ;};_dedd :=_fe .NewPdfFieldSignature (signature );_dedd .Rect =_fac .MakeArrayFromFloats (opts .Rect );_dedd .AP =_dbcc ;return _dedd ,nil ;};func (_bcf *AppearanceStyle )processDA (_dfg *_fe .PdfField ,_eecc *_f .ContentStreamOperations ,_efc ,_aagb *_fe .PdfPageResources ,_gcg *_f .ContentCreator )(*AppearanceFont ,bool ,error ){var _bfbf *AppearanceFont ;var _ceea bool ;if _bcf .Fonts !=nil {if _bcf .Fonts .Fallback !=nil {_bfbf =_bcf .Fonts .Fallback ;};if _eeea :=_bcf .Fonts .FieldFallbacks ;_eeea !=nil {if _dbgb ,_agd :=_eeea [_dfg .PartialName ()];_agd {_bfbf =_dbgb ;}else if _gdfc ,_egec :=_dfg .FullName ();_egec ==nil {if _ecf ,_adb :=_eeea [_gdfc ];_adb {_bfbf =_ecf ;};};};_ceea =_bcf .Fonts .ForceReplace ;};var _ggfd string ;var _cbfb float64 ;var _gdg bool ;if _eecc !=nil {for _ ,_fcfc :=range *_eecc {if _fcfc .Operand =="\u0054\u0066"&&len (_fcfc .Params )==2{if _ebc ,_dcg :=_fac .GetNameVal (_fcfc .Params [0]);_dcg {_ggfd =_ebc ;};if _gcee ,_gfe :=_fac .GetNumberAsFloat (_fcfc .Params [1]);_gfe ==nil {_cbfb =_gcee ;};_gdg =true ;continue ;};_gcg .AddOperand (*_fcfc );};};var _agfe *AppearanceFont ;var _afc _fac .PdfObject ;if _ceea &&_bfbf !=nil {_agfe =_bfbf ;}else {if _efc !=nil &&_ggfd !=""{if _bgec ,_ceef :=_efc .GetFontByName (*_fac .MakeName (_ggfd ));_ceef {if _bba ,_ceff :=_fe .NewPdfFontFromPdfObject (_bgec );_ceff ==nil {_afc =_bgec ;_agfe =&AppearanceFont {Name :_ggfd ,Font :_bba ,Size :_cbfb };}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",_ceff );};};};if _agfe ==nil &&_bfbf !=nil {_agfe =_bfbf ;};if _agfe ==nil {_fde ,_addg :=_fe .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");if _addg !=nil {return nil ,false ,_addg ;};_agfe =&AppearanceFont {Name :"\u0048\u0065\u006c\u0076",Font :_fde ,Size :_cbfb };};};_egdc :=*_fac .MakeName (_agfe .Name );if _afc ==nil {_afc =_agfe .Font .ToPdfObject ();};if _efc !=nil &&!_efc .HasFontByName (_egdc ){_efc .SetFontByName (_egdc ,_afc );};if _aagb !=nil &&!_aagb .HasFontByName (_egdc ){_aagb .SetFontByName (_egdc ,_afc );};return _agfe ,_gdg ,nil ;};
|
2020-10-05 19:28:24 +00:00
|
|
|
|
2020-11-11 18:48:37 +00:00
|
|
|
// RectangleAnnotationDef is a rectangle defined with a specified Width and Height and a lower left corner at (X,Y).
|
|
|
|
// The rectangle can optionally have a border and a filling color.
|
|
|
|
// The Width/Height includes the border (if any specified).
|
2020-11-23 22:15:56 +00:00
|
|
|
type RectangleAnnotationDef struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_fe .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_fe .PdfColorDeviceRGB ;Opacity float64 ;};
|
2020-09-21 01:20:10 +00:00
|
|
|
|
2020-11-11 18:48:37 +00:00
|
|
|
// AppearanceFont represents a font used for generating the appearance of a
|
|
|
|
// field in the filling/flattening process.
|
|
|
|
type AppearanceFont struct{
|
2020-10-19 10:58:10 +00:00
|
|
|
|
2020-11-11 18:48:37 +00:00
|
|
|
// Name represents the name of the font which will be added to the
|
|
|
|
// AcroForm resources (DR).
|
|
|
|
Name string ;
|
2020-10-19 10:58:10 +00:00
|
|
|
|
2020-11-11 18:48:37 +00:00
|
|
|
// Font represents the actual font used for the field appearance.
|
2020-11-23 22:15:56 +00:00
|
|
|
Font *_fe .PdfFont ;
|
2020-11-11 18:48:37 +00:00
|
|
|
|
|
|
|
// 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.
|
2020-11-23 22:15:56 +00:00
|
|
|
Size float64 ;};func _cc (_fgb *_fe .PdfAnnotationWidget ,_gec *_fe .PdfFieldText ,_ffa *_fe .PdfPageResources ,_cfb AppearanceStyle )(*_fac .PdfObjectDictionary ,error ){_fff :=_fe .NewPdfPageResources ();_bc ,_agg :=_fac .GetArray (_fgb .Rect );if !_agg {return nil ,_de .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_feff ,_ddea :=_fe .NewPdfRectangle (*_bc );if _ddea !=nil {return nil ,_ddea ;};_bgd ,_db :=_feff .Width (),_feff .Height ();_gafa ,_gcd :=_bgd ,_db ;_ebd ,_bad :=_fac .GetDict (_fgb .MK );if _bad {_aedb ,_ :=_fac .GetDict (_fgb .BS );_abce :=_cfb .applyAppearanceCharacteristics (_ebd ,_aedb ,nil );if _abce !=nil {return nil ,_abce ;};};_ed ,_bad :=_fac .GetIntVal (_gec .MaxLen );if !_bad {return nil ,_de .New ("\u006d\u0061\u0078\u006c\u0065\u006e\u0020\u006e\u006ft\u0020\u0073\u0065\u0074");};if _ed <=0{return nil ,_de .New ("\u006d\u0061\u0078\u004c\u0065\u006e\u0020\u0069\u006ev\u0061\u006c\u0069\u0064");};_bdb :=_bgd /float64 (_ed );_facc ,_ddea :=_f .NewContentStreamParser (_ece (_gec .PdfField )).Parse ();if _ddea !=nil {return nil ,_ddea ;};_cggc :=_f .NewContentCreator ();if _cfb .BorderSize > 0{_aggd (_cggc ,_cfb ,_bgd ,_db );};if _cfb .DrawAlignmentReticle {_acf :=_cfb ;_acf .BorderSize =0.2;_gca (_cggc ,_acf ,_bgd ,_db );};_cggc .Add_BMC ("\u0054\u0078");_cggc .Add_q ();_ ,_db =_cfb .applyRotation (_ebd ,_bgd ,_db ,_cggc );_cggc .Add_BT ();_cdd ,_ffff ,_ddea :=_cfb .processDA (_gec .PdfField ,_facc ,_ffa ,_fff ,_cggc );if _ddea !=nil {return nil ,_ddea ;};_fgg :=_cdd .Font ;_dad :=_fac .MakeName (_cdd .Name );_eaa :=_cdd .Size ;_abea :=_eaa ==0;if _abea &&_ffff {_eaa =_db *_cfb .AutoFontSizeFraction ;};_gga :=_fgg .Encoder ();if _gga ==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");_gga =_g .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};var _aaff string ;if _baa ,_bea :=_fac .GetString (_gec .V );_bea {_aaff =_baa .Decoded ();};_cggc .Add_Tf (*_dad ,_eaa );var _bff float64 ;for _ ,_bfea :=range _aaff {_befb ,_ggae :=_fgg .GetRuneMetrics (_bfea );if !_ggae {_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",_bfea );continue ;};_fba :=_befb .Wy ;if int (_fba )<=0{_fba =_befb .Wx ;};if _fba > _bff {_bff =_fba ;};};if int (_bff )==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");_bff =1000;};_bdaf ,_ddea :=_fgg .GetFontDescriptor ();if _ddea !=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 _gce float64 ;if _bdaf !=nil {_gce ,_ddea =_bdaf .GetCapHeight ();if _ddea !=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",_ddea );};};if int (_gce )<=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");_gc
|
2020-10-19 10:58:10 +00:00
|
|
|
|
2020-11-23 22:15:56 +00:00
|
|
|
// WrapContentStream ensures that the entire content stream for a `page` is wrapped within q ... Q operands.
|
|
|
|
// Ensures that following operands that are added are not affected by additional operands that are added.
|
|
|
|
// Implements interface model.ContentStreamWrapper.
|
|
|
|
func (_bebb FieldAppearance )WrapContentStream (page *_fe .PdfPage )error {_cgbe ,_bebbc :=page .GetAllContentStreams ();if _bebbc !=nil {return _bebbc ;};_fdbb :=_f .NewContentStreamParser (_cgbe );_cdb ,_bebbc :=_fdbb .Parse ();if _bebbc !=nil {return _bebbc ;};_cdb .WrapIfNeeded ();_abcc :=[]string {_cdb .String ()};return page .SetContentStreams (_abcc ,_faef ());};
|
2020-08-31 21:12:07 +00:00
|
|
|
|
2020-11-23 22:15:56 +00:00
|
|
|
// SignatureImagePosition specifies the image signature location relative to the text signature.
|
|
|
|
// If text signature is not defined, this position will be ignored.
|
|
|
|
type SignatureImagePosition int ;func _addb (_cgbg *_fe .PdfField ,_bdgd ,_geg float64 ,_dadf string ,_dedf AppearanceStyle ,_bcc *_f .ContentStreamOperations ,_bgda *_fe .PdfPageResources ,_gdb *_fac .PdfObjectDictionary )(*_fe .XObjectForm ,error ){_bec :=_fe .NewPdfPageResources ();_gbbd ,_dfd :=_bdgd ,_geg ;_bdc :=_f .NewContentCreator ();if _dedf .BorderSize > 0{_aggd (_bdc ,_dedf ,_bdgd ,_geg );};if _dedf .DrawAlignmentReticle {_dab :=_dedf ;_dab .BorderSize =0.2;_gca (_bdc ,_dab ,_bdgd ,_geg );};_bdc .Add_BMC ("\u0054\u0078");_bdc .Add_q ();_bdc .Add_BT ();_bdgd ,_geg =_dedf .applyRotation (_gdb ,_bdgd ,_geg ,_bdc );_gab ,_abdb ,_ace :=_dedf .processDA (_cgbg ,_bcc ,_bgda ,_bec ,_bdc );if _ace !=nil {return nil ,_ace ;};_eac :=_gab .Font ;_acb :=_gab .Size ;_gcfa :=_fac .MakeName (_gab .Name );_efb :=_acb ==0;if _efb &&_abdb {_acb =_geg *_dedf .AutoFontSizeFraction ;};_fdb :=_eac .Encoder ();if _fdb ==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");_fdb =_g .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};if len (_dadf )==0{return nil ,nil ;};_ggcf :=2.0;_ebg :=0.0;if _fdb !=nil {for _ ,_cgd :=range _dadf {_ada ,_dec :=_eac .GetRuneMetrics (_cgd );if !_dec {_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",_cgd );continue ;};_ebg +=_ada .Wx ;};_dadf =string (_fdb .Encode (_dadf ));};if _acb ==0||_efb &&_ebg > 0&&_ggcf +_ebg *_acb /1000.0> _bdgd {_acb =0.95*1000.0*(_bdgd -_ggcf )/_ebg ;};_caa :=1.0*_acb ;_bdag :=2.0;{_cef :=_caa ;if _efb &&_bdag +_cef > _geg {_acb =0.95*(_geg -_bdag );_caa =1.0*_acb ;_cef =_caa ;};if _geg > _cef {_bdag =(_geg -_cef )/2.0;_bdag +=1.50;};};_bdc .Add_Tf (*_gcfa ,_acb );_bdc .Add_Td (_ggcf ,_bdag );_bdc .Add_Tj (*_fac .MakeString (_dadf ));_bdc .Add_ET ();_bdc .Add_Q ();_bdc .Add_EMC ();_aea :=_fe .NewXObjectForm ();_aea .Resources =_bec ;_aea .BBox =_fac .MakeArrayFromFloats ([]float64 {0,0,_gbbd ,_dfd });_aea .SetContentStream (_bdc .Bytes (),_faef ());return _aea ,nil ;};func _ffe (_egbg *_fe .PdfAnnotationWidget ,_daa *_fe .PdfFieldButton ,_gcb *_fe .PdfPageResources ,_ggf AppearanceStyle )(*_fac .PdfObjectDictionary ,error ){_fbe ,_abd :=_fac .GetArray (_egbg .Rect );if !_abd {return nil ,_de .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_ceg ,_eeca :=_fe .NewPdfRectangle (*_fbe );if _eeca !=nil {return nil ,_eeca ;};_cgb ,_geb :=_ceg .Width (),_ceg .Height ();_dgc ,_fge :=_cgb ,_geb ;_d .Log .Debug ("\u0043\u0068\u0065\u0063kb\u006f\u0078\u002c\u0020\u0077\u0061\u0020\u0042\u0053\u003a\u0020\u0025\u0076",_egbg .BS );_cdg ,_eeca :=_fe .NewStandard14Font ("\u005a\u0061\u0070f\u0044\u0069\u006e\u0067\u0062\u0061\u0074\u0073");if _eeca !=nil {return nil ,_eeca ;};_dedg ,_dbe :=_fac .GetDict (_egbg .MK );if _dbe {_gdf ,_ :=_fac .GetDict (_egbg .BS );_cde :=_ggf .applyAppearanceCharacteristics (_dedg ,_gdf ,_cdg );if _cde !=nil {return nil ,_cde ;};};_eed :=_fe .NewXObjectForm ();{_eggf :=_f .NewContentCreator ();if _ggf .BorderSize > 0{_aggd (_eggf ,_ggf ,_cgb ,_geb );};if _ggf .DrawAlignmentReticle {_ddd :=_ggf ;_ddd .BorderSize =0.2;_gca (_eggf ,_ddd ,_cgb ,_geb );};_cgb ,_geb =_ggf .applyRotation (_dedg ,_cgb ,_geb ,_eggf );_bgf :=_ggf .AutoFontSizeFraction *_geb ;_beb ,_efdg :=_cdg .GetRuneMetrics (_ggf .CheckmarkRune );if !_efdg {return nil ,_de .New ("\u0067l\u0079p\u0068\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");};_gafe :=_cdg .Encoder ();_bdafc :=_gafe .Encode (strin
|