mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +08:00
191 lines
52 KiB
Go
191 lines
52 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 (_f "bytes";_gbd "errors";_c "github.com/unidoc/unipdf/v3/common";_b "github.com/unidoc/unipdf/v3/contentstream";_ca "github.com/unidoc/unipdf/v3/contentstream/draw";_fd "github.com/unidoc/unipdf/v3/core";_gb "github.com/unidoc/unipdf/v3/internal/textencoding";_fb "github.com/unidoc/unipdf/v3/model";_d "math";_e "strings";_ga "unicode";);func (_eba *AppearanceStyle )applyAppearanceCharacteristics (_fbcb *_fd .PdfObjectDictionary ,_fae *_fd .PdfObjectDictionary ,_eebc *_fb .PdfFont )error {if !_eba .AllowMK {return nil ;};if _fae !=nil {if _ced ,_fdd :=_fd .GetNumberAsFloat (_fae .Get ("\u0057"));_fdd ==nil {_eba .BorderSize =_ced ;};};if CA ,_gegf :=_fd .GetString (_fbcb .Get ("\u0043\u0041"));_gegf &&_eebc !=nil {_bgg :=CA .Bytes ();if len (_bgg )!=0{_effg :=[]rune (_eebc .Encoder ().Decode (_bgg ));if len (_effg )==1{_eba .CheckmarkRune =_effg [0];};};};if BC ,_bbcf :=_fd .GetArray (_fbcb .Get ("\u0042\u0043"));_bbcf {_eage ,_gdf :=BC .ToFloat64Array ();if _gdf !=nil {return _gdf ;};switch len (_eage ){case 1:_eba .BorderColor =_fb .NewPdfColorDeviceGray (_eage [0]);case 3:_eba .BorderColor =_fb .NewPdfColorDeviceRGB (_eage [0],_eage [1],_eage [2]);case 4:_eba .BorderColor =_fb .NewPdfColorDeviceCMYK (_eage [0],_eage [1],_eage [2],_eage [3]);default:_c .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 (_eage ));};};if BG ,_fdg :=_fd .GetArray (_fbcb .Get ("\u0042\u0047"));_fdg {_fdb ,_addb :=BG .ToFloat64Array ();if _addb !=nil {return _addb ;};switch len (_fdb ){case 1:_eba .FillColor =_fb .NewPdfColorDeviceGray (_fdb [0]);case 3:_eba .FillColor =_fb .NewPdfColorDeviceRGB (_fdb [0],_fdb [1],_fdb [2]);case 4:_eba .FillColor =_fb .NewPdfColorDeviceCMYK (_fdb [0],_fdb [1],_fdb [2],_fdb [3]);default:_c .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 (_fdb ));};};return 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 *_fb .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 _ca .LineEndingStyle ;LineEndingStyle2 _ca .LineEndingStyle ;};
|
||
|
|
||
|
// 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 ;_eg *AppearanceStyle ;};
|
||
|
|
||
|
// 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 *_fb .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 _bgbf (_ceg *_fb .PdfAcroForm ,_ceeg *_fb .PdfAnnotationWidget ,_afa *_fb .PdfFieldChoice ,_faca AppearanceStyle )(*_fd .PdfObjectDictionary ,error ){_dce ,_ece :=_fd .GetArray (_ceeg .Rect );if !_ece {return nil ,_gbd .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_fbef ,_efgd :=_fb .NewPdfRectangle (*_dce );if _efgd !=nil {return nil ,_efgd ;};_bga ,_gde :=_fbef .Width (),_fbef .Height ();_c .Log .Debug ("\u0043\u0068\u006f\u0069\u0063\u0065\u002c\u0020\u0077\u0061\u0020\u0042S\u003a\u0020\u0025\u0076",_ceeg .BS );_fdee ,_efgd :=_b .NewContentStreamParser (_efd (_afa .PdfField )).Parse ();if _efgd !=nil {return nil ,_efgd ;};_eaf ,_abf :=_fd .GetDict (_ceeg .MK );if _abf {_fecb ,_ :=_fd .GetDict (_ceeg .BS );_edgg :=_faca .applyAppearanceCharacteristics (_eaf ,_fecb ,nil );if _edgg !=nil {return nil ,_edgg ;};};_ceeb :=_fd .MakeDict ();for _ ,_gef :=range _afa .Opt .Elements (){if _bbdc ,_dbg :=_fd .GetArray (_gef );_dbg &&_bbdc .Len ()==2{_gef =_bbdc .Get (1);};var _beef string ;if _dbba ,_eebe :=_fd .GetString (_gef );_eebe {_beef =_dbba .Decoded ();}else if _gcgb ,_gbea :=_fd .GetName (_gef );_gbea {_beef =_gcgb .String ();}else {_c .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",_gef );return nil ,_gbd .New ("\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u002f\u0073t\u0072\u0069\u006e\u0067");};if len (_beef )> 0{_befg ,_dcb :=_ged (_afa .PdfField ,_bga ,_gde ,_beef ,_faca ,_fdee ,_ceg .DR ,_eaf );if _dcb !=nil {return nil ,_dcb ;};_ceeb .Set (*_fd .MakeName (_beef ),_befg .ToPdfObject ());};};_dbgb :=_fd .MakeDict ();_dbgb .Set ("\u004e",_ceeb );return _dbgb ,nil ;};const (_dd quadding =0;_fcd quadding =1;_aff quadding =2;);func _de (_fa CircleAnnotationDef )(*_fd .PdfObjectDictionary ,*_fb .PdfRectangle ,error ){_fc :=_fb .NewXObjectForm ();_fc .Resources =_fb .NewPdfPageResources ();_dbe :="";if _fa .Opacity < 1.0{_ed :=_fd .MakeDict ();_ed .Set ("\u0063\u0061",_fd .MakeFloat (_fa .Opacity ));_ed .Set ("\u0043\u0041",_fd .MakeFloat (_fa .Opacity ));_fdf :=_fc .Resources .AddExtGState ("\u0067\u0073\u0031",_ed );if _fdf !=nil {_c .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 ,_fdf ;};_dbe ="\u0067\u0073\u0031";};_bb ,_def ,_gf ,_fg :=_cf (_fa ,_dbe );if _fg !=nil {return nil ,nil ,_fg ;};_fg =_fc .SetContentStream (_bb ,nil );if _fg !=nil {return nil ,nil ,_fg ;};_fc .BBox =_def .ToPdfObject ();_bd :=_fd .MakeDict ();_bd .Set ("\u004e",_fc .ToPdfObject ());return _bd ,_gf ,nil ;};func (_bab *AppearanceStyle )applyRotation (_eac *_fd .PdfObjectDictionary ,_ceb ,_bcab float64 ,_bcbb *_b .ContentCreator )(float64 ,float64 ){if !_bab .AllowMK {return _ceb ,_bcab ;};if _eac ==nil {return _ceb ,_bcab ;};_eee ,_ :=_fd .GetNumberAsFloat (_eac .Get ("\u0052"));if _eee ==0{return _ceb ,_bcab ;};_gefg :=-_eee ;_fdba :=_ca .Path {Points :[]_ca .Point {_ca .NewPoint (0,0).Rotate (_gefg ),_ca .NewPoint (_ceb ,0).Rotate (_gefg ),_ca .NewPoint (0,_bcab ).Rotate (_gefg ),_ca .NewPoint (_ceb ,_bcab ).Rotate (_gefg )}}.GetBoundingBox ();_bcbb .RotateDeg (_eee );_bcbb .Translate (_fdba .X ,_fdba .Y );return _fdba .Width ,_fdba .Height ;};func _abfe (_bggd RectangleAnnotationDef ,_gfd string )([]byte ,*_fb .PdfRectangle ,*_fb .PdfRectangle ,error ){_befe :=_ca .Rectangle {X :0,Y :0,Width :_bggd .Width ,Height :_bggd .Height ,FillEnabled :_bggd .FillEnabled ,FillColor :_bggd .FillColor ,BorderEnabled :_bggd .BorderEnabled ,BorderWidth :2*_bggd .BorderWidth ,BorderColor :_bggd .BorderColor ,Opacity :_bggd .Opacity };_effgf ,_bbdca ,_eadb :=_befe .Draw (_gfd );if _eadb !=nil {return nil ,nil ,nil ,_eadb ;};_gdab :=&_fb .PdfRectangle {};_gdab .Llx =_bggd .X +_bbdca .Llx ;_gdab .Lly =_bggd .Y +_bbdca .Lly ;_gdab .Urx =_bggd .X +_bbdca .Urx ;_gdab .Ury =_bggd .Y +_bbdca .Ury ;return _effgf ,_bbdca ,_gd
|
||
|
|
||
|
// Style returns the appearance style of `fa`. If not specified, returns default style.
|
||
|
func (_efa FieldAppearance )Style ()AppearanceStyle {if _efa ._eg !=nil {return *_efa ._eg ;};return AppearanceStyle {AutoFontSizeFraction :0.65,CheckmarkRune :'✔',BorderSize :0.0,BorderColor :_fb .NewPdfColorDeviceGray (0),FillColor :_fb .NewPdfColorDeviceGray (1),MultilineLineHeight :1.2,MultilineVAlignMiddle :false ,DrawAlignmentReticle :false ,AllowMK :true };};
|
||
|
|
||
|
// SignatureLine represents a line of information in the signature field appearance.
|
||
|
type SignatureLine struct{Desc string ;Text string ;};
|
||
|
|
||
|
// CreateCircleAnnotation creates a circle/ellipse annotation object with appearance stream that can be added to
|
||
|
// page PDF annotations.
|
||
|
func CreateCircleAnnotation (circDef CircleAnnotationDef )(*_fb .PdfAnnotation ,error ){_gaa :=_fb .NewPdfAnnotationCircle ();if circDef .BorderEnabled {_a ,_bg ,_ae :=circDef .BorderColor .R (),circDef .BorderColor .G (),circDef .BorderColor .B ();_gaa .C =_fd .MakeArrayFromFloats ([]float64 {_a ,_bg ,_ae });_bf :=_fb .NewBorderStyle ();_bf .SetBorderWidth (circDef .BorderWidth );_gaa .BS =_bf .ToPdfObject ();};if circDef .FillEnabled {_db ,_fbe ,_aec :=circDef .FillColor .R (),circDef .FillColor .G (),circDef .FillColor .B ();_gaa .IC =_fd .MakeArrayFromFloats ([]float64 {_db ,_fbe ,_aec });}else {_gaa .IC =_fd .MakeArrayFromIntegers ([]int {});};if circDef .Opacity < 1.0{_gaa .CA =_fd .MakeFloat (circDef .Opacity );};_ff ,_ef ,_bff :=_de (circDef );if _bff !=nil {return nil ,_bff ;};_gaa .AP =_ff ;_gaa .Rect =_fd .MakeArrayFromFloats ([]float64 {_ef .Llx ,_ef .Lly ,_ef .Urx ,_ef .Ury });return _gaa .PdfAnnotation ,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 *_fb .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 _fb .PdfColor ;
|
||
|
|
||
|
// FillColor represents the background color of the appearance annotation area.
|
||
|
FillColor _fb .PdfColor ;
|
||
|
|
||
|
// BorderSize represents border size of the appearance annotation area.
|
||
|
BorderSize float64 ;
|
||
|
|
||
|
// BorderColor represents the border color of the appearance annotation area.
|
||
|
BorderColor _fb .PdfColor ;};
|
||
|
|
||
|
// 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 };};func _cc (_ee *_fb .PdfAnnotationWidget ,_aeb *_fb .PdfFieldText ,_ag *_fb .PdfPageResources ,_bcb AppearanceStyle )(*_fd .PdfObjectDictionary ,error ){_fgf :=_fb .NewPdfPageResources ();_ebg ,_bge :=_fd .GetArray (_ee .Rect );if !_bge {return nil ,_gbd .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_bcg ,_eff :=_fb .NewPdfRectangle (*_ebg );if _eff !=nil {return nil ,_eff ;};_fgg ,_fad :=_bcg .Width (),_bcg .Height ();_eea ,_fe :=_fgg ,_fad ;_be ,_ead :=_fd .GetDict (_ee .MK );if _ead {_adg ,_ :=_fd .GetDict (_ee .BS );_cgf :=_bcb .applyAppearanceCharacteristics (_be ,_adg ,nil );if _cgf !=nil {return nil ,_cgf ;};};_bfg ,_eff :=_b .NewContentStreamParser (_efd (_aeb .PdfField )).Parse ();if _eff !=nil {return nil ,_eff ;};_edca :=_b .NewContentCreator ();if _bcb .BorderSize > 0{_gfb (_edca ,_bcb ,_fgg ,_fad );};if _bcb .DrawAlignmentReticle {_cfc :=_bcb ;_cfc .BorderSize =0.2;_cgd (_edca ,_cfc ,_fgg ,_fad );};_edca .Add_BMC ("\u0054\u0078");_edca .Add_q ();_fgg ,_fad =_bcb .applyRotation (_be ,_fgg ,_fad ,_edca );_edca .Add_BT ();_baf ,_da ,_eff :=_bcb .processDA (_aeb .PdfField ,_bfg ,_ag ,_fgf ,_edca );if _eff !=nil {return nil ,_eff ;};_gg :=_baf .Font ;_caf :=_baf .Size ;_ebc :=_fd .MakeName (_baf .Name );_egd :=_caf ==0;if _egd &&_da {_caf =_fad *_bcb .AutoFontSizeFraction ;};_faf :=_gg .Encoder ();if _faf ==nil {_c .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");_faf =_gb .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};_eeb ,_eff :=_gg .GetFontDescriptor ();if _eff !=nil {_c .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 _afb string ;if _gac ,_gfa :=_fd .GetString (_aeb .V );_gfa {_afb =_gac .Decoded ();};if len (_afb )==0{return nil ,nil ;};_ec :=[]string {_afb };_ffe :=false ;if _aeb .Flags ().Has (_fb .FieldFlagMultiline ){_ffe =true ;_afb =_e .Replace (_afb ,"\u000d\u000a","\u000a",-1);_afb =_e .Replace (_afb ,"\u000d","\u000a",-1);_ec =_e .Split (_afb ,"\u000a");};_ffb :=0.0;_aebb :=0;if _faf !=nil {_faa :=len (_ec );_fca :=0;for _fca < _faa {var _ffg float64 ;_gc :=-1;_ddb :=0.0;for _ab ,_bfb :=range _ec [_fca ]{if _bfb ==' '{_gc =_ab ;_ffg =_ddb ;};_fda ,_efe :=_gg .GetRuneMetrics (_bfb );if !_efe {_c .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 ;};_ddb +=_fda .Wx ;if _ffe &&!_egd &&_caf *_ddb /1000.0> _fgg &&_gc > 0{_ge :=_ec [_fca ][_gc +1:];if _fca < len (_ec )-1{_ec [_fca +1]+=_ge ;}else {_ec =append (_ec ,_ge );_faa ++;};_ec [_fca ]=_ec [_fca ][0:_gc ];_ddb =_ffg ;break ;};};if _ddb > _ffb {_ffb =_ddb ;};_ec [_fca ]=string (_faf .Encode (_ec [_fca ]));if len (_ec [_fca ])> 0{_aebb ++;};_fca ++;};};_edg :=2.0;if _caf ==0||_egd &&_ffb > 0&&_edg +_ffb *_caf /1000.0> _fgg {_caf =0.95*1000.0*(_fgg -_edg )/_ffb ;};_cga :=_dd ;{if _bca ,_efg :=_fd .GetIntVal (_aeb .Q );_efg {switch _bca {case 0:_cga =_dd ;case 1:_cga =_fcd ;case 2:_cga =_aff ;default:_c .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",
|
||
|
|
||
|
// 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 *_fb .PdfPage ,name string ,rect []float64 ,opt CheckboxFieldOptions )(*_fb .PdfFieldButton ,error ){if page ==nil {return nil ,_gbd .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};if len (name )<=0{return nil ,_gbd .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 ,_gbd .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");};_ceff ,_dbfb :=_fb .NewStandard14Font (_fb .ZapfDingbatsName );if _dbfb !=nil {return nil ,_dbfb ;};_gfgg :=_fb .NewPdfField ();_ccd :=&_fb .PdfFieldButton {};_gfgg .SetContext (_ccd );_ccd .PdfField =_gfgg ;_ccd .T =_fd .MakeString (name );_ccd .SetType (_fb .ButtonTypeCheckbox );_ccdb :="\u004f\u0066\u0066";if opt .Checked {_ccdb ="\u0059\u0065\u0073";};_ccd .V =_fd .MakeName (_ccdb );_ggb :=_fb .NewPdfAnnotationWidget ();_ggb .Rect =_fd .MakeArrayFromFloats (rect );_ggb .P =page .ToPdfObject ();_ggb .F =_fd .MakeInteger (4);_ggb .Parent =_ccd .ToPdfObject ();_ggdc :=rect [2]-rect [0];_aed :=rect [3]-rect [1];var _gdec _f .Buffer ;_gdec .WriteString ("\u0071\u000a");_gdec .WriteString ("\u0030 \u0030\u0020\u0031\u0020\u0072\u0067\n");_gdec .WriteString ("\u0042\u0054\u000a");_gdec .WriteString ("\u002f\u005a\u0061D\u0062\u0020\u0031\u0032\u0020\u0054\u0066\u000a");_gdec .WriteString ("\u0045\u0054\u000a");_gdec .WriteString ("\u0051\u000a");_fdaf :=_b .NewContentCreator ();_fdaf .Add_q ();_fdaf .Add_rg (0,0,1);_fdaf .Add_BT ();_fdaf .Add_Tf (*_fd .MakeName ("\u005a\u0061\u0044\u0062"),12);_fdaf .Add_Td (0,0);_fdaf .Add_ET ();_fdaf .Add_Q ();_beda :=_fb .NewXObjectForm ();_beda .SetContentStream (_fdaf .Bytes (),_fd .NewRawEncoder ());_beda .BBox =_fd .MakeArrayFromFloats ([]float64 {0,0,_ggdc ,_aed });_beda .Resources =_fb .NewPdfPageResources ();_beda .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_ceff .ToPdfObject ());_fdaf =_b .NewContentCreator ();_fdaf .Add_q ();_fdaf .Add_re (0,0,_ggdc ,_aed );_fdaf .Add_W ().Add_n ();_fdaf .Add_rg (0,0,1);_fdaf .Translate (0,3.0);_fdaf .Add_BT ();_fdaf .Add_Tf (*_fd .MakeName ("\u005a\u0061\u0044\u0062"),12);_fdaf .Add_Td (0,0);_fdaf .Add_Tj (*_fd .MakeString ("\u0034"));_fdaf .Add_ET ();_fdaf .Add_Q ();_ddgb :=_fb .NewXObjectForm ();_ddgb .SetContentStream (_fdaf .Bytes (),_fd .NewRawEncoder ());_ddgb .BBox =_fd .MakeArrayFromFloats ([]float64 {0,0,_ggdc ,_aed });_ddgb .Resources =_fb .NewPdfPageResources ();_ddgb .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_ceff .ToPdfObject ());_ffeb :=_fd .MakeDict ();_ffeb .Set ("\u004f\u0066\u0066",_beda .ToPdfObject ());_ffeb .Set ("\u0059\u0065\u0073",_ddgb .ToPdfObject ());_bcdb :=_fd .MakeDict ();_bcdb .Set ("\u004e",_ffeb );_ggb .AP =_bcdb ;_ggb .AS =_fd .MakeName (_ccdb );_ccd .Annotations =append (_ccd .Annotations ,_ggb );return _ccd ,nil ;};type quadding int ;
|
||
|
|
||
|
// CheckboxFieldOptions defines optional parameters for a checkbox field a form.
|
||
|
type CheckboxFieldOptions struct{Checked bool ;};
|
||
|
|
||
|
// SetStyle applies appearance `style` to `fa`.
|
||
|
func (_ce *FieldAppearance )SetStyle (style AppearanceStyle ){_ce ._eg =&style };func _efd (_gda *_fb .PdfField )string {if _gda ==nil {return "";};_daa ,_gbac :=_gda .GetContext ().(*_fb .PdfFieldText );if !_gbac {return _efd (_gda .Parent );};if _daa .DA !=nil {return _daa .DA .Str ();};return _efd (_daa .Parent );};func _cf (_ba CircleAnnotationDef ,_eb string )([]byte ,*_fb .PdfRectangle ,*_fb .PdfRectangle ,error ){_af :=_ca .Circle {X :_ba .X ,Y :_ba .Y ,Width :_ba .Width ,Height :_ba .Height ,FillEnabled :_ba .FillEnabled ,FillColor :_ba .FillColor ,BorderEnabled :_ba .BorderEnabled ,BorderWidth :_ba .BorderWidth ,BorderColor :_ba .BorderColor ,Opacity :_ba .Opacity };_gbe ,_df ,_dfb :=_af .Draw (_eb );if _dfb !=nil {return nil ,nil ,nil ,_dfb ;};_ea :=&_fb .PdfRectangle {};_ea .Llx =_ba .X +_df .Llx ;_ea .Lly =_ba .Y +_df .Lly ;_ea .Urx =_ba .X +_df .Urx ;_ea .Ury =_ba .Y +_df .Ury ;return _gbe ,_df ,_ea ,nil ;};func _fffg (_bbeg LineAnnotationDef )(*_fd .PdfObjectDictionary ,*_fb .PdfRectangle ,error ){_acgc :=_fb .NewXObjectForm ();_acgc .Resources =_fb .NewPdfPageResources ();_deg :="";if _bbeg .Opacity < 1.0{_edfe :=_fd .MakeDict ();_edfe .Set ("\u0063\u0061",_fd .MakeFloat (_bbeg .Opacity ));_aada :=_acgc .Resources .AddExtGState ("\u0067\u0073\u0031",_edfe );if _aada !=nil {_c .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 ,_aada ;};_deg ="\u0067\u0073\u0031";};_fag ,_gbc ,_gega ,_gbgf :=_agbf (_bbeg ,_deg );if _gbgf !=nil {return nil ,nil ,_gbgf ;};_gbgf =_acgc .SetContentStream (_fag ,nil );if _gbgf !=nil {return nil ,nil ,_gbgf ;};_acgc .BBox =_gbc .ToPdfObject ();_afc :=_fd .MakeDict ();_afc .Set ("\u004e",_acgc .ToPdfObject ());return _afc ,_gega ,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 *_fb .PdfSignature ,lines []*SignatureLine ,opts *SignatureFieldOpts )(*_fb .PdfFieldSignature ,error ){if signature ==nil {return nil ,_gbd .New ("\u0073\u0069\u0067na\u0074\u0075\u0072\u0065\u0020\u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u006e\u0069\u006c");};_cebe ,_afbb :=_aee (lines ,opts );if _afbb !=nil {return nil ,_afbb ;};_ddca :=_fb .NewPdfFieldSignature (signature );_ddca .Rect =_fd .MakeArrayFromFloats (opts .Rect );_ddca .AP =_cebe ;return _ddca ,nil ;};
|
||
|
|
||
|
// CreateLineAnnotation creates a line annotation object that can be added to page PDF annotations.
|
||
|
func CreateLineAnnotation (lineDef LineAnnotationDef )(*_fb .PdfAnnotation ,error ){_aebd :=_fb .NewPdfAnnotationLine ();_aebd .L =_fd .MakeArrayFromFloats ([]float64 {lineDef .X1 ,lineDef .Y1 ,lineDef .X2 ,lineDef .Y2 });_cgfd :=_fd .MakeName ("\u004e\u006f\u006e\u0065");if lineDef .LineEndingStyle1 ==_ca .LineEndingStyleArrow {_cgfd =_fd .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");};_egcc :=_fd .MakeName ("\u004e\u006f\u006e\u0065");if lineDef .LineEndingStyle2 ==_ca .LineEndingStyleArrow {_egcc =_fd .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");};_aebd .LE =_fd .MakeArray (_cgfd ,_egcc );if lineDef .Opacity < 1.0{_aebd .CA =_fd .MakeFloat (lineDef .Opacity );};_bfbb ,_dbfg ,_aag :=lineDef .LineColor .R (),lineDef .LineColor .G (),lineDef .LineColor .B ();_aebd .IC =_fd .MakeArrayFromFloats ([]float64 {_bfbb ,_dbfg ,_aag });_aebd .C =_fd .MakeArrayFromFloats ([]float64 {_bfbb ,_dbfg ,_aag });_bedb :=_fb .NewBorderStyle ();_bedb .SetBorderWidth (lineDef .LineWidth );_aebd .BS =_bedb .ToPdfObject ();_ebac ,_gee ,_cae :=_fffg (lineDef );if _cae !=nil {return nil ,_cae ;};_aebd .AP =_ebac ;_aebd .Rect =_fd .MakeArrayFromFloats ([]float64 {_gee .Llx ,_gee .Lly ,_gee .Urx ,_gee .Ury });return _aebd .PdfAnnotation ,nil ;};
|
||
|
|
||
|
// RectangleAnnotationDef is a rectangle defined with a specified Width and Height and a lower left corner at (X,Y).
|
||
|
// The rectangle can optionally have a border and a filling color.
|
||
|
// The Width/Height includes the border (if any specified).
|
||
|
type RectangleAnnotationDef struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_fb .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_fb .PdfColorDeviceRGB ;Opacity float64 ;};
|
||
|
|
||
|
// 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 ;};
|
||
|
|
||
|
// GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`.
|
||
|
// Implements interface model.FieldAppearanceGenerator.
|
||
|
func (_afd FieldAppearance )GenerateAppearanceDict (form *_fb .PdfAcroForm ,field *_fb .PdfField ,wa *_fb .PdfAnnotationWidget )(*_fd .PdfObjectDictionary ,error ){_c .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 );_ ,_fcc :=field .GetContext ().(*_fb .PdfFieldText );_bbd ,_edc :=_fd .GetDict (wa .AP );if _edc &&_afd .OnlyIfMissing &&(!_fcc ||!_afd .RegenerateTextFields ){_c .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 _bbd ,nil ;};if form .DR ==nil {form .DR =_fb .NewPdfPageResources ();};switch _cee :=field .GetContext ().(type ){case *_fb .PdfFieldText :_cg :=_cee ;switch {case _cg .Flags ().Has (_fb .FieldFlagPassword ):return nil ,nil ;case _cg .Flags ().Has (_fb .FieldFlagFileSelect ):return nil ,nil ;case _cg .Flags ().Has (_fb .FieldFlagComb ):if _cg .MaxLen !=nil {_cag ,_bc :=_cb (wa ,_cg ,form .DR ,_afd .Style ());if _bc !=nil {return nil ,_bc ;};return _cag ,nil ;};};_gfe ,_bdg :=_cc (wa ,_cg ,form .DR ,_afd .Style ());if _bdg !=nil {return nil ,_bdg ;};return _gfe ,nil ;case *_fb .PdfFieldButton :_fdc :=_cee ;if _fdc .IsCheckbox (){_dbc ,_fgb :=_bgc (wa ,_fdc ,form .DR ,_afd .Style ());if _fgb !=nil {return nil ,_fgb ;};return _dbc ,nil ;};_c .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",_fdc .GetType ());case *_fb .PdfFieldChoice :_ac :=_cee ;switch {case _ac .Flags ().Has (_fb .FieldFlagCombo ):_ad ,_cfg :=_bgbf (form ,wa ,_ac ,_afd .Style ());if _cfg !=nil {return nil ,_cfg ;};return _ad ,nil ;default:_c .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",_ac .Flags ().String ());};default:_c .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",_cee );};return nil ,nil ;};func _agbf (_ade LineAnnotationDef ,_ccbb string )([]byte ,*_fb .PdfRectangle ,*_fb .PdfRectangle ,error ){_bcag :=_ca .Line {X1 :0,Y1 :0,X2 :_ade .X2 -_ade .X1 ,Y2 :_ade .Y2 -_ade .Y1 ,LineColor :_ade .LineColor ,Opacity :_ade .Opacity ,LineWidth :_ade .LineWidth ,LineEndingStyle1 :_ade .LineEndingStyle1 ,LineEndingStyle2 :_ade .LineEndingStyle2 };_cfb ,_bcgf ,_ffff :=_bcag .Draw (_ccbb );if _ffff !=nil {return nil ,nil ,nil ,_ffff ;};_dde :=&_fb .PdfRectangle {};_dde .Llx =_ade .X1 +_bcgf .Llx ;_dde .Lly =_ade .Y1 +_bcgf .Lly ;_dde .Urx =_ade .X1 +_bcgf .Urx ;_dde .Ury =_ade .Y1 +_bcgf .Ury ;return _cfb ,_bcgf ,_dde ,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 _fb .PdfColor ;FillColor _fb .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 ;};func _ged (_dff *_fb .PdfField ,_fdce ,_eef float64 ,_adgc string ,_bcaa AppearanceStyle ,_fcec *_b .ContentStreamOperations ,_efec *_fb .PdfPageResources ,_geg *_fd .PdfObjectDictionary )(*_fb .XObjectForm ,error ){_eefd :=_fb .NewPdfPageResources ();_cabf ,_fee :=_fdce ,_eef ;_dcg :=_b .NewContentCreator ();if _bcaa .BorderSize > 0{_gfb (_dcg ,_bcaa ,_fdce ,_eef );};if _bcaa .DrawAlignmentReticle {_bdfa :=_bcaa ;_bdfa .BorderSize =0.2;_cgd (_dcg ,_bdfa ,_fdce ,_eef );};_dcg .Add_BMC ("\u0054\u0078");_dcg .Add_q ();_dcg .Add_BT ();_fdce ,_eef =_bcaa .applyRotation (_geg ,_fdce ,_eef ,_dcg );_gfgd ,_dgg ,_bfaa :=_bcaa .processDA (_dff ,_fcec ,_efec ,_eefd ,_dcg );if _bfaa !=nil {return nil ,_bfaa ;};_dggg :=_gfgd .Font ;_ffgf :=_gfgd .Size ;_dee :=_fd .MakeName (_gfgd .Name );_aab :=_ffgf ==0;if _aab &&_dgg {_ffgf =_eef *_bcaa .AutoFontSizeFraction ;};_cge :=_dggg .Encoder ();if _cge ==nil {_c .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");_cge =_gb .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};if len (_adgc )==0{return nil ,nil ;};_eecc :=2.0;_dca :=0.0;if _cge !=nil {for _ ,_bffc :=range _adgc {_bbda ,_fga :=_dggg .GetRuneMetrics (_bffc );if !_fga {_c .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",_bffc );continue ;};_dca +=_bbda .Wx ;};_adgc =string (_cge .Encode (_adgc ));};if _ffgf ==0||_aab &&_dca > 0&&_eecc +_dca *_ffgf /1000.0> _fdce {_ffgf =0.95*1000.0*(_fdce -_eecc )/_dca ;};_dgb :=1.0*_ffgf ;_edd :=2.0;{_fgfg :=_dgb ;if _aab &&_edd +_fgfg > _eef {_ffgf =0.95*(_eef -_edd );_dgb =1.0*_ffgf ;_fgfg =_dgb ;};if _eef > _fgfg {_edd =(_eef -_fgfg )/2.0;_edd +=1.50;};};_dcg .Add_Tf (*_dee ,_ffgf );_dcg .Add_Td (_eecc ,_edd );_dcg .Add_Tj (*_fd .MakeString (_adgc ));_dcg .Add_ET ();_dcg .Add_Q ();_dcg .Add_EMC ();_bbg :=_fb .NewXObjectForm ();_bbg .Resources =_eefd ;_bbg .BBox =_fd .MakeArrayFromFloats ([]float64 {0,0,_cabf ,_fee });_bbg .SetContentStream (_dcg .Bytes (),_gddb ());return _bbg ,nil ;};
|
||
|
|
||
|
// TextFieldOptions defines optional parameter for a text field in a form.
|
||
|
type TextFieldOptions struct{MaxLen int ;Value string ;};
|
||
|
|
||
|
// NewComboboxField generates a new combobox form field with partial name `name` at location `rect`
|
||
|
// on specified `page` and with field specific options `opt`.
|
||
|
func NewComboboxField (page *_fb .PdfPage ,name string ,rect []float64 ,opt ComboboxFieldOptions )(*_fb .PdfFieldChoice ,error ){if page ==nil {return nil ,_gbd .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};if len (name )<=0{return nil ,_gbd .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 ,_gbd .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");};_dgf :=_fb .NewPdfField ();_cfe :=&_fb .PdfFieldChoice {};_dgf .SetContext (_cfe );_cfe .PdfField =_dgf ;_cfe .T =_fd .MakeString (name );_cfe .Opt =_fd .MakeArray ();for _ ,_feb :=range opt .Choices {_cfe .Opt .Append (_fd .MakeString (_feb ));};_cfe .SetFlag (_fb .FieldFlagCombo );_cafbe :=_fb .NewPdfAnnotationWidget ();_cafbe .Rect =_fd .MakeArrayFromFloats (rect );_cafbe .P =page .ToPdfObject ();_cafbe .F =_fd .MakeInteger (4);_cafbe .Parent =_cfe .ToPdfObject ();_cfe .Annotations =append (_cfe .Annotations ,_cafbe );return _cfe ,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 (_dbad FieldAppearance )WrapContentStream (page *_fb .PdfPage )error {_aga ,_aad :=page .GetAllContentStreams ();if _aad !=nil {return _aad ;};_gcc :=_b .NewContentStreamParser (_aga );_gdff ,_aad :=_gcc .Parse ();if _aad !=nil {return _aad ;};_gdff .WrapIfNeeded ();_acg :=[]string {_gdff .String ()};return page .SetContentStreams (_acg ,_gddb ());};
|
||
|
|
||
|
// CreateRectangleAnnotation creates a rectangle annotation object that can be added to page PDF annotations.
|
||
|
func CreateRectangleAnnotation (rectDef RectangleAnnotationDef )(*_fb .PdfAnnotation ,error ){_fgd :=_fb .NewPdfAnnotationSquare ();if rectDef .BorderEnabled {_dgc ,_cdc ,_gbcf :=rectDef .BorderColor .R (),rectDef .BorderColor .G (),rectDef .BorderColor .B ();_fgd .C =_fd .MakeArrayFromFloats ([]float64 {_dgc ,_cdc ,_gbcf });_ccc :=_fb .NewBorderStyle ();_ccc .SetBorderWidth (rectDef .BorderWidth );_fgd .BS =_ccc .ToPdfObject ();};if rectDef .FillEnabled {_dac ,_bgbg ,_agee :=rectDef .FillColor .R (),rectDef .FillColor .G (),rectDef .FillColor .B ();_fgd .IC =_fd .MakeArrayFromFloats ([]float64 {_dac ,_bgbg ,_agee });}else {_fgd .IC =_fd .MakeArrayFromIntegers ([]int {});};if rectDef .Opacity < 1.0{_fgd .CA =_fd .MakeFloat (rectDef .Opacity );};_dfga ,_ageb ,_bfbc :=_aadf (rectDef );if _bfbc !=nil {return nil ,_bfbc ;};_fgd .AP =_dfga ;_fgd .Rect =_fd .MakeArrayFromFloats ([]float64 {_ageb .Llx ,_ageb .Lly ,_ageb .Urx ,_ageb .Ury });return _fgd .PdfAnnotation ,nil ;};type CircleAnnotationDef struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_fb .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_fb .PdfColorDeviceRGB ;Opacity float64 ;};
|
||
|
|
||
|
// 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 ;};func (_bae *AppearanceStyle )processDA (_cafb *_fb .PdfField ,_aba *_b .ContentStreamOperations ,_gfae ,_dfac *_fb .PdfPageResources ,_aefe *_b .ContentCreator )(*AppearanceFont ,bool ,error ){var _fcad *AppearanceFont ;var _cbf bool ;if _bae .Fonts !=nil {if _bae .Fonts .Fallback !=nil {_fcad =_bae .Fonts .Fallback ;};if _dcdg :=_bae .Fonts .FieldFallbacks ;_dcdg !=nil {if _bcd ,_dceb :=_dcdg [_cafb .PartialName ()];_dceb {_fcad =_bcd ;}else if _ebb ,_geb :=_cafb .FullName ();_geb ==nil {if _eca ,_ddf :=_dcdg [_ebb ];_ddf {_fcad =_eca ;};};};_cbf =_bae .Fonts .ForceReplace ;};var _bfge string ;var _gfec float64 ;var _facac bool ;if _aba !=nil {for _ ,_afe :=range *_aba {if _afe .Operand =="\u0054\u0066"&&len (_afe .Params )==2{if _dga ,_cef :=_fd .GetNameVal (_afe .Params [0]);_cef {_bfge =_dga ;};if _gdaf ,_bfd :=_fd .GetNumberAsFloat (_afe .Params [1]);_bfd ==nil {_gfec =_gdaf ;};_facac =true ;continue ;};_aefe .AddOperand (*_afe );};};var _bdga *AppearanceFont ;var _egc _fd .PdfObject ;if _cbf &&_fcad !=nil {_bdga =_fcad ;}else {if _gfae !=nil &&_bfge !=""{if _bbfd ,_faab :=_gfae .GetFontByName (*_fd .MakeName (_bfge ));_faab {if _bgcb ,_cfa :=_fb .NewPdfFontFromPdfObject (_bbfd );_cfa ==nil {_egc =_bbfd ;_bdga =&AppearanceFont {Name :_bfge ,Font :_bgcb ,Size :_gfec };}else {_c .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",_cfa );};};};if _bdga ==nil &&_fcad !=nil {_bdga =_fcad ;};if _bdga ==nil {_fbff ,_faeb :=_fb .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");if _faeb !=nil {return nil ,false ,_faeb ;};_bdga =&AppearanceFont {Name :"\u0048\u0065\u006c\u0076",Font :_fbff ,Size :_gfec };};};_bcc :=*_fd .MakeName (_bdga .Name );if _egc ==nil {_egc =_bdga .Font .ToPdfObject ();};if _gfae !=nil &&!_gfae .HasFontByName (_bcc ){_gfae .SetFontByName (_bcc ,_egc );};if _dfac !=nil &&!_dfac .HasFontByName (_bcc ){_dfac .SetFontByName (_bcc ,_egc );};return _bdga ,_facac ,nil ;};func _cgd (_dgd *_b .ContentCreator ,_cea AppearanceStyle ,_dcd ,_ccg float64 ){_dgd .Add_q ().Add_re (0,0,_dcd ,_ccg ).Add_re (0,_ccg /2,_dcd ,_ccg /2).Add_re (0,0,_dcd ,_ccg ).Add_re (_dcd /2,0,_dcd /2,_ccg ).Add_w (_cea .BorderSize ).SetStrokingColor (_cea .BorderColor ).SetNonStrokingColor (_cea .FillColor ).Add_B ().Add_Q ();};
|
||
|
|
||
|
// NewSignatureFieldOpts returns a new initialized instance of options
|
||
|
// used to generate a signature appearance.
|
||
|
func NewSignatureFieldOpts ()*SignatureFieldOpts {return &SignatureFieldOpts {Font :_fb .DefaultFont (),FontSize :10,LineHeight :1,AutoSize :true ,TextColor :_fb .NewPdfColorDeviceGray (0),BorderColor :_fb .NewPdfColorDeviceGray (0),FillColor :_fb .NewPdfColorDeviceGray (1)};};func _gfb (_ageg *_b .ContentCreator ,_gfbe AppearanceStyle ,_eddb ,_bgf float64 ){_ageg .Add_q ().Add_re (0,0,_eddb ,_bgf ).Add_w (_gfbe .BorderSize ).SetStrokingColor (_gfbe .BorderColor ).SetNonStrokingColor (_gfbe .FillColor ).Add_B ().Add_Q ();};
|
||
|
|
||
|
// 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 *_fb .PdfPage ,name string ,rect []float64 ,opt TextFieldOptions )(*_fb .PdfFieldText ,error ){if page ==nil {return nil ,_gbd .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};if len (name )<=0{return nil ,_gbd .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 ,_gbd .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");};_efea :=_fb .NewPdfField ();_bce :=&_fb .PdfFieldText {};_efea .SetContext (_bce );_bce .PdfField =_efea ;_bce .T =_fd .MakeString (name );if opt .MaxLen > 0{_bce .MaxLen =_fd .MakeInteger (int64 (opt .MaxLen ));};if len (opt .Value )> 0{_bce .V =_fd .MakeString (opt .Value );};_addd :=_fb .NewPdfAnnotationWidget ();_addd .Rect =_fd .MakeArrayFromFloats (rect );_addd .P =page .ToPdfObject ();_addd .F =_fd .MakeInteger (4);_addd .Parent =_bce .ToPdfObject ();_bce .Annotations =append (_bce .Annotations ,_addd );return _bce ,nil ;};
|