aboutsummaryrefslogtreecommitdiff
path: root/unipdf/annotator/annotator.go
blob: 0ba41e11031c1d44712c6d34d31b4ae1e8b40fea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
//
// 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 (_b "bytes";_fd "errors";_cb "fmt";_a "github.com/unidoc/unipdf/v4/common";_fa "github.com/unidoc/unipdf/v4/contentstream";_ff "github.com/unidoc/unipdf/v4/contentstream/draw";_gc "github.com/unidoc/unipdf/v4/core";_e "github.com/unidoc/unipdf/v4/creator";
_g "github.com/unidoc/unipdf/v4/internal/precision";_ac "github.com/unidoc/unipdf/v4/internal/textencoding";_fdg "github.com/unidoc/unipdf/v4/model";_bc "github.com/unidoc/unipdf/v4/textshaping";_eg "image";_c "math";_ae "strings";_f "time";_ec "unicode";
);func _eaaf (_febd *_fa .ContentCreator ,_edd AppearanceStyle ,_dbdd ,_dcag float64 ){_febd .Add_q ().Add_re (0,0,_dbdd ,_dcag ).Add_w (_edd .BorderSize ).SetStrokingColor (_edd .BorderColor ).SetNonStrokingColor (_edd .FillColor ).Add_B ().Add_Q ();};
func _acg (_aedc *_fdg .PdfAnnotationWidget ,_abg *_fdg .PdfFieldText ,_aga *_fdg .PdfPageResources ,_eeg AppearanceStyle )(*_gc .PdfObjectDictionary ,error ){_ecdd :=_fdg .NewPdfPageResources ();_fffg ,_fbg :=_gc .GetArray (_aedc .Rect );if !_fbg {return nil ,_fd .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");
};_aac ,_aeg :=_fdg .NewPdfRectangle (*_fffg );if _aeg !=nil {return nil ,_aeg ;};_acf ,_gbc :=_aac .Width (),_aac .Height ();_ade ,_gda :=_acf ,_gbc ;_ffbe ,_aca :=_gc .GetDict (_aedc .MK );if _aca {_bbfg ,_ :=_gc .GetDict (_aedc .BS );_aacg :=_eeg .applyAppearanceCharacteristics (_ffbe ,_bbfg ,nil );
if _aacg !=nil {return nil ,_aacg ;};};_dgb ,_aca :=_gc .GetIntVal (_abg .MaxLen );if !_aca {return nil ,_fd .New ("\u006d\u0061\u0078\u006c\u0065\u006e\u0020\u006e\u006ft\u0020\u0073\u0065\u0074");};if _dgb <=0{return nil ,_fd .New ("\u006d\u0061\u0078\u004c\u0065\u006e\u0020\u0069\u006ev\u0061\u006c\u0069\u0064");
};_edc :=_acf /float64 (_dgb );_daa ,_aeg :=_fa .NewContentStreamParser (_dfed (_abg .PdfField )).Parse ();if _aeg !=nil {return nil ,_aeg ;};_caf :=_fa .NewContentCreator ();if _eeg .BorderSize > 0{_eaaf (_caf ,_eeg ,_acf ,_gbc );};if _eeg .DrawAlignmentReticle {_bdf :=_eeg ;
_bdf .BorderSize =0.2;_efeb (_caf ,_bdf ,_acf ,_gbc );};_caf .Add_BMC ("\u0054\u0078");_caf .Add_q ();_ ,_gbc =_eeg .applyRotation (_ffbe ,_acf ,_gbc ,_caf );_caf .Add_BT ();_gge ,_efa ,_aeg :=_eeg .processDA (_abg .PdfField ,_daa ,_aga ,_ecdd ,_caf );
if _aeg !=nil {return nil ,_aeg ;};_badd :=_gge .Font ;_gdd :=_gc .MakeName (_gge .Name );_fbf :=_gge .Size ;_cda :=_fbf ==0;if _cda &&_efa {_fbf =_gbc *_eeg .AutoFontSizeFraction ;};_efefa :=_badd .Encoder ();if _efefa ==nil {_a .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");
_efefa =_ac .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};var _acae string ;if _egfc ,_dcd :=_gc .GetString (_abg .V );_dcd {_acae =_egfc .Decoded ();};_acae =_ddgda (_acae );_caf .Add_Tf (*_gdd ,_fbf );var _afce float64 ;
for _ ,_ffc :=range _acae {_eed ,_feed :=_badd .GetRuneMetrics (_ffc );if !_feed {_a .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",_ffc );
continue ;};_bgdb :=_eed .Wy ;if int (_bgdb )<=0{_bgdb =_eed .Wx ;};if _bgdb > _afce {_afce =_bgdb ;};};if int (_afce )==0{_a .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");
_afce =1000;};_bec ,_aeg :=_badd .GetFontDescriptor ();if _aeg !=nil {_a .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 _cea float64 ;if _bec !=nil {_cea ,_aeg =_bec .GetCapHeight ();if _aeg !=nil {_a .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",_aeg );
};};if int (_cea )<=0{_a .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");
_cea =1000.0;};_bdfb :=_cea /1000.0*_fbf ;_ded :=0.0;_bbc :=1.0*_fbf *(_afce /1000.0);{_cafd :=_bbc ;if _cda &&_ded +_cafd > _gbc {_fbf =0.95*(_gbc -_ded );_bdfb =_cea /1000.0*_fbf ;};if _gbc > _bdfb {_ded =(_gbc -_bdfb )/2.0;};};_caf .Add_Td (0,_ded );
if _edca ,_fedg :=_gc .GetIntVal (_abg .Q );_fedg {switch _edca {case 2:if len (_acae )< _dgb {_acced :=float64 (_dgb -len (_acae ))*_edc ;_caf .Add_Td (_acced ,0);};};};for _dfef ,_daeg :=range _acae {_acd :=_bd ;if _eeg .MarginLeft !=nil {_acd =*_eeg .MarginLeft ;
};_cgg :=string (_daeg );if _efefa !=nil {_gcfe ,_fad :=_badd .GetRuneMetrics (_daeg );if !_fad {_a .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",_daeg );
continue ;};_cgg =string (_efefa .Encode (_cgg ));_acab :=_fbf *_gcfe .Wx /1000.0;_aff :=(_edc -_acab )/2;_acd =_aff ;};_caf .Add_Td (_acd ,0);_caf .Add_Tj (*_gc .MakeString (_cgg ));if _dfef !=len (_acae )-1{_caf .Add_Td (_edc -_acd ,0);};};_caf .Add_ET ();
_caf .Add_Q ();_caf .Add_EMC ();_ccg :=_fdg .NewXObjectForm ();_ccg .Resources =_ecdd ;_ccg .BBox =_gc .MakeArrayFromFloats ([]float64 {0,0,_ade ,_gda });_ccg .SetContentStream (_caf .Bytes (),_bdggc ());_fac :=_gc .MakeDict ();_fac .Set ("\u004e",_ccg .ToPdfObject ());
return _fac ,nil ;};func (_bcd *AppearanceStyle )applyAppearanceCharacteristics (_bga *_gc .PdfObjectDictionary ,_fbfg *_gc .PdfObjectDictionary ,_fcgb *_fdg .PdfFont )error {if !_bcd .AllowMK {return nil ;};if CA ,_gade :=_gc .GetString (_bga .Get ("\u0043\u0041"));
_gade &&_fcgb !=nil {_ebb :=CA .Bytes ();if len (_ebb )!=0{_gcb :=[]rune (_fcgb .Encoder ().Decode (_ebb ));if len (_gcb )==1{_bcd .CheckmarkRune =_gcb [0];};};};if BC ,_fgd :=_gc .GetArray (_bga .Get ("\u0042\u0043"));_fgd {_daef ,_bdgg :=BC .ToFloat64Array ();
if _bdgg !=nil {return _bdgg ;};switch len (_daef ){case 1:_bcd .BorderColor =_fdg .NewPdfColorDeviceGray (_daef [0]);case 3:_bcd .BorderColor =_fdg .NewPdfColorDeviceRGB (_daef [0],_daef [1],_daef [2]);case 4:_bcd .BorderColor =_fdg .NewPdfColorDeviceCMYK (_daef [0],_daef [1],_daef [2],_daef [3]);
default:_a .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 (_daef ));
};if _fbfg !=nil {if _ddf ,_affd :=_gc .GetNumberAsFloat (_fbfg .Get ("\u0057"));_affd ==nil {_bcd .BorderSize =_ddf ;};};};if BG ,_efb :=_gc .GetArray (_bga .Get ("\u0042\u0047"));_efb {_gaf ,_bfa :=BG .ToFloat64Array ();if _bfa !=nil {return _bfa ;};
switch len (_gaf ){case 1:_bcd .FillColor =_fdg .NewPdfColorDeviceGray (_gaf [0]);case 3:_bcd .FillColor =_fdg .NewPdfColorDeviceRGB (_gaf [0],_gaf [1],_gaf [2]);case 4:_bcd .FillColor =_fdg .NewPdfColorDeviceCMYK (_gaf [0],_gaf [1],_gaf [2],_gaf [3]);
default:_a .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 (_gaf ));
};};return nil ;};

// FileAnnotationDef holds base information for constructing an file attachment annotation.
type FileAnnotationDef struct{

// Bounding box of the annotation.
X float64 ;Y float64 ;Width float64 ;Height float64 ;

// EmbeddedFile is the file information to be attached.
EmbeddedFile *_fdg .EmbeddedFile ;

// Author is the author of the attachment file.
Author string ;

// Subject is the subject of the attachment file.
Subject string ;

// Description of the file attachment that will be displayed as a comment on the PDF reader.
Description string ;

// IconName is The name of an icon that shall be used in displaying the annotation.
// Conforming readers shall provide predefined icon appearances for at least the following standard names:
//
// - Graph
// - PushPin
// - Paperclip
// - Tag
//
// Additional names may be supported as well. Default value: "PushPin".
IconName string ;

// Color is the color of the annotation.
Color *_fdg .PdfColorDeviceRGB ;

// CreationDate is the date and time when the file attachment was created.
// If not set, the current time is used.
CreationDate *_f .Time ;};func _fcbb (_bbcdc RectangleAnnotationDef )(*_gc .PdfObjectDictionary ,*_fdg .PdfRectangle ,error ){_bbfa :=_fdg .NewXObjectForm ();_bbfa .Resources =_fdg .NewPdfPageResources ();_bacb :="";if _bbcdc .Opacity < 1.0{_dgfe :=_gc .MakeDict ();
_dgfe .Set ("\u0063\u0061",_gc .MakeFloat (_bbcdc .Opacity ));_dgfe .Set ("\u0043\u0041",_gc .MakeFloat (_bbcdc .Opacity ));_aba :=_bbfa .Resources .AddExtGState ("\u0067\u0073\u0031",_dgfe );if _aba !=nil {_a .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 ,_aba ;};_bacb ="\u0067\u0073\u0031";};_fbeb ,_gdgf ,_abdbg ,_acff :=_babd (_bbcdc ,_bacb );if _acff !=nil {return nil ,nil ,_acff ;};_acff =_bbfa .SetContentStream (_fbeb ,nil );if _acff !=nil {return nil ,nil ,_acff ;};_bbfa .BBox =_gdgf .ToPdfObject ();
_agcf :=_gc .MakeDict ();_agcf .Set ("\u004e",_bbfa .ToPdfObject ());return _agcf ,_abdbg ,nil ;};func (_cdff *AppearanceStyle )processDA (_bda *_fdg .PdfField ,_cad *_fa .ContentStreamOperations ,_aeba ,_bdc *_fdg .PdfPageResources ,_fccd *_fa .ContentCreator )(*AppearanceFont ,bool ,error ){var _fdfd *AppearanceFont ;
var _aaac bool ;if _cdff .Fonts !=nil {if _cdff .Fonts .Fallback !=nil {_fdfd =_cdff .Fonts .Fallback ;};if _ggab :=_cdff .Fonts .FieldFallbacks ;_ggab !=nil {if _cfdf ,_egg :=_ggab [_bda .PartialName ()];_egg {_fdfd =_cfdf ;}else if _accd ,_beb :=_bda .FullName ();
_beb ==nil {if _fcdf ,_aag :=_ggab [_accd ];_aag {_fdfd =_fcdf ;};};};if _fdfd !=nil {_fdfd .fillName ();};_aaac =_cdff .Fonts .ForceReplace ;};var _bff string ;var _gab float64 ;var _fdgc bool ;if _cad !=nil {for _ ,_cceg :=range *_cad {if _cceg .Operand =="\u0054\u0066"&&len (_cceg .Params )==2{if _ebbf ,_ddgd :=_gc .GetNameVal (_cceg .Params [0]);
_ddgd {_bff =_ebbf ;};if _gcg ,_gdae :=_gc .GetNumberAsFloat (_cceg .Params [1]);_gdae ==nil {_gab =_gcg ;};_fdgc =true ;continue ;};_fccd .AddOperand (*_cceg );};};var _bcdg *AppearanceFont ;var _ecbg _gc .PdfObject ;if _aaac &&_fdfd !=nil {_bcdg =_fdfd ;
}else {if _aeba !=nil &&_bff !=""{if _cab ,_dabbe :=_aeba .GetFontByName (*_gc .MakeName (_bff ));_dabbe {if _dcb ,_deee :=_fdg .NewPdfFontFromPdfObject (_cab );_deee ==nil {_ecbg =_cab ;_bcdg =&AppearanceFont {Name :_bff ,Font :_dcb ,Size :_gab };}else {_a .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",_deee );
};};};if _bcdg ==nil &&_fdfd !=nil {_bcdg =_fdfd ;};if _bcdg ==nil {_ebfd ,_bcb :=_fdg .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");if _bcb !=nil {return nil ,false ,_bcb ;};_bcdg =&AppearanceFont {Name :"\u0048\u0065\u006c\u0076",Font :_ebfd ,Size :_gab };
};};if _bcdg .Size <=0&&_cdff .Fonts !=nil &&_cdff .Fonts .FallbackSize > 0{_bcdg .Size =_cdff .Fonts .FallbackSize ;};_ccc :=*_gc .MakeName (_bcdg .Name );if _ecbg ==nil {_ecbg =_bcdg .Font .ToPdfObject ();};if _aeba !=nil &&!_aeba .HasFontByName (_ccc ){_aeba .SetFontByName (_ccc ,_ecbg );
};if _bdc !=nil &&!_bdc .HasFontByName (_ccc ){_bdc .SetFontByName (_ccc ,_ecbg );};return _bcdg ,_fdgc ,nil ;};

// TextFieldOptions defines optional parameter for a text field in a form.
type TextFieldOptions struct{MaxLen int ;Value string ;

// TextColor defines the color of the text in hex format. e.g #43fd23.
// If it has an invalid value a #000000 (black) color is taken as default
TextColor string ;

// FontName defines the font of the text. Helvetica font is the default one.
// It is recommended to use one of 14 standard PDF fonts.
FontName string ;

// FontSize defines the font size of the text, 12 is used by default.
FontSize int ;};func _gafa (_ecc []*SignatureLine ,_bag *SignatureFieldOpts )(*_gc .PdfObjectDictionary ,error ){if _bag ==nil {_bag =NewSignatureFieldOpts ();};var _ccf error ;var _gded *_gc .PdfObjectName ;_eddg :=_bag .Font ;if _eddg !=nil {_aedec ,_ :=_eddg .GetFontDescriptor ();
if _aedec !=nil {if _abe ,_egea :=_aedec .FontName .(*_gc .PdfObjectName );_egea {_gded =_abe ;};};if _gded ==nil {_gded =_gc .MakeName ("\u0046\u006f\u006et\u0031");};}else {if _eddg ,_ccf =_fdg .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");
_ccf !=nil {return nil ,_ccf ;};_gded =_gc .MakeName ("\u0048\u0065\u006c\u0076");};_gcdg :=_bag .FontSize ;if _gcdg <=0{_gcdg =10;};if _bag .LineHeight <=0{_bag .LineHeight =1;};_ccfa :=_bag .LineHeight *_gcdg ;_fcce ,_deae :=_eddg .GetRuneMetrics (' ');
if !_deae {return nil ,_fd .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");};_ecdf :=_fcce .Wx ;var _gega float64 ;var _ggg []string ;
for _ ,_gfa :=range _ecc {if _gfa .Text ==""{continue ;};_dace :=_gfa .Text ;if _gfa .Desc !=""{_dace =_gfa .Desc +"\u003a\u0020"+_dace ;};_ggg =append (_ggg ,_dace );var _dge float64 ;for _ ,_eeea :=range _dace {_bbfe ,_cebg :=_eddg .GetRuneMetrics (_eeea );
if !_cebg {continue ;};_dge +=_bbfe .Wx ;};if _dge > _gega {_gega =_dge ;};};_gega =_gega *_gcdg /1000.0;_abdcf :=float64 (len (_ggg ))*_ccfa ;_faff :=_bag .Image !=nil ;_gfg :=_bag .Rect ;if _gfg ==nil {_gfg =[]float64 {0,0,_gega ,_abdcf };if _faff {_gfg [2]=_gega *2;
_gfg [3]=_abdcf *2;};_bag .Rect =_gfg ;};_fbb :=_gfg [2]-_gfg [0];_ged :=_gfg [3]-_gfg [1];_fedb ,_agef :=_gfg ,_gfg ;var _dfbb ,_eeda float64 ;if _faff &&len (_ggg )> 0{if _bag .ImagePosition <=SignatureImageRight {_degc :=[]float64 {_gfg [0],_gfg [1],_gfg [0]+(_fbb /2),_gfg [3]};
_bgb :=[]float64 {_gfg [0]+(_fbb /2),_gfg [1],_gfg [2],_gfg [3]};if _bag .ImagePosition ==SignatureImageLeft {_fedb ,_agef =_degc ,_bgb ;}else {_fedb ,_agef =_bgb ,_degc ;};}else {_dgda :=[]float64 {_gfg [0],_gfg [1],_gfg [2],_gfg [1]+(_ged /2)};_eeeb :=[]float64 {_gfg [0],_gfg [1]+(_ged /2),_gfg [2],_gfg [3]};
if _bag .ImagePosition ==SignatureImageTop {_fedb ,_agef =_eeeb ,_dgda ;}else {_fedb ,_agef =_dgda ,_eeeb ;};};};_dfbb =_agef [2]-_agef [0];_eeda =_agef [3]-_agef [1];var _fgdd float64 ;if _bag .AutoSize {if _gega > _dfbb ||_abdcf > _eeda {_bgc :=_c .Min (_dfbb /_gega ,_eeda /_abdcf );
_gcdg *=_bgc ;};_ccfa =_bag .LineHeight *_gcdg ;_fgdd +=(_eeda -float64 (len (_ggg ))*_ccfa )/2;};_dcbf :=_fa .NewContentCreator ();_efce :=_fdg .NewPdfPageResources ();_efce .SetFontByName (*_gded ,_eddg .ToPdfObject ());if _bag .BorderSize <=0{_bag .BorderSize =0;
_bag .BorderColor =_fdg .NewPdfColorDeviceGray (1);};_dcbf .Add_q ();if _bag .FillColor !=nil {_dcbf .SetNonStrokingColor (_bag .FillColor );};if _bag .BorderColor !=nil {_dcbf .SetStrokingColor (_bag .BorderColor );};_eea :="";if _bag .FillOpacity < 1.0{_eccb :=0;
_eea =_cb .Sprintf ("\u0047\u0053\u0025\u0064",_eccb );for {_ ,_ccef :=_efce .GetExtGState (_gc .PdfObjectName (_eea ));if !_ccef {break ;};_eccb ++;_eea =_cb .Sprintf ("\u0047\u0053\u0025\u0064",_eccb );};_eabfb :=_gc .MakeDict ();_eabfb .Set ("\u0063\u0061",_gc .MakeFloat (_bag .FillOpacity ));
_adbea :=_efce .AddExtGState (_gc .PdfObjectName (_eea ),_gc .MakeIndirectObject (_eabfb ));if _adbea !=nil {_a .Log .Debug (_adbea .Error ());}else {_dcbf .Add_gs (_gc .PdfObjectName (_eea ));};};_dcbf .Add_w (_bag .BorderSize ).Add_re (_gfg [0],_gfg [1],_fbb ,_ged );
if _bag .FillColor !=nil &&_bag .BorderColor !=nil {_dcbf .Add_B ();}else if _bag .FillColor !=nil {_dcbf .Add_f ();}else if _bag .BorderColor !=nil {_dcbf .Add_S ();};_dcbf .Add_Q ();if _bag .WatermarkImage !=nil {_ceag :=[]float64 {_gfg [0],_gfg [1],_gfg [2],_gfg [3]};
_cgb ,_aedecf ,_bead :=_agbe (_bag .WatermarkImage ,"\u0049\u006d\u0061\u0067\u0065\u0057\u0061\u0074\u0065r\u006d\u0061\u0072\u006b",_bag ,_ceag ,_dcbf );if _bead !=nil {return nil ,_bead ;};_efce .SetXObjectImageByName (*_cgb ,_aedecf );};_dcbf .Add_q ();
_dcbf .Translate (_agef [0],_agef [3]-_ccfa -_fgdd );_dcbf .Add_BT ();_cdfe :=_eddg .Encoder ();for _ ,_cdag :=range _ggg {var _cbff []byte ;for _ ,_fcdg :=range _cdag {if _ec .IsSpace (_fcdg ){if len (_cbff )> 0{_dcbf .SetNonStrokingColor (_bag .TextColor ).Add_Tf (*_gded ,_gcdg ).Add_TL (_ccfa ).Add_TJ ([]_gc .PdfObject {_gc .MakeStringFromBytes (_cbff )}...);
_cbff =nil ;};_dcbf .Add_Tf (*_gded ,_gcdg ).Add_TL (_ccfa ).Add_TJ ([]_gc .PdfObject {_gc .MakeFloat (-_ecdf )}...);}else {_cbff =append (_cbff ,_cdfe .Encode (string (_fcdg ))...);};};if len (_cbff )> 0{_dcbf .SetNonStrokingColor (_bag .TextColor ).Add_Tf (*_gded ,_gcdg ).Add_TL (_ccfa ).Add_TJ ([]_gc .PdfObject {_gc .MakeStringFromBytes (_cbff )}...);
};_dcbf .Add_Td (0,-_ccfa );};_dcbf .Add_ET ();_dcbf .Add_Q ();if _faff {_fcda ,_fbe ,_aad :=_agbe (_bag .Image ,"\u0049\u006d\u0061\u0067\u0065\u0053\u0069\u0067\u006ea\u0074\u0075\u0072\u0065",_bag ,_fedb ,_dcbf );if _aad !=nil {return nil ,_aad ;};_efce .SetXObjectImageByName (*_fcda ,_fbe );
};_bgac :=_fdg .NewXObjectForm ();_bgac .Resources =_efce ;_bgac .BBox =_gc .MakeArrayFromFloats (_gfg );_bgac .SetContentStream (_dcbf .Bytes (),_bdggc ());_ddcd :=_gc .MakeDict ();_ddcd .Set ("\u004e",_bgac .ToPdfObject ());return _ddcd ,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 (_aefb ImageFieldAppearance )WrapContentStream (page *_fdg .PdfPage )error {_daega ,_cfca :=page .GetAllContentStreams ();if _cfca !=nil {return _cfca ;};_gfcf :=_fa .NewContentStreamParser (_daega );_bdga ,_cfca :=_gfcf .Parse ();if _cfca !=nil {return _cfca ;
};_bdga .WrapIfNeeded ();_befe :=[]string {_bdga .String ()};return page .SetContentStreams (_befe ,_bdggc ());};

// ImageFieldAppearance implements interface model.FieldAppearanceGenerator and generates appearance streams
// for attaching an image to a button field.
type ImageFieldAppearance struct{OnlyIfMissing bool ;_bbee *AppearanceStyle ;};

// GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`.
// Implements interface model.FieldAppearanceGenerator.
func (_gbf ImageFieldAppearance )GenerateAppearanceDict (form *_fdg .PdfAcroForm ,field *_fdg .PdfField ,wa *_fdg .PdfAnnotationWidget )(*_gc .PdfObjectDictionary ,error ){_ ,_abca :=field .GetContext ().(*_fdg .PdfFieldButton );if !_abca {_a .Log .Trace ("C\u006f\u0075\u006c\u0064\u0020\u006fn\u006c\u0079\u0020\u0068\u0061\u006ed\u006c\u0065\u0020\u0062\u0075\u0074\u0074o\u006e\u0020\u002d\u0020\u0069\u0067\u006e\u006f\u0072\u0069n\u0067");
return nil ,nil ;};_cac ,_cdgc :=_gc .GetDict (wa .AP );if _cdgc &&_gbf .OnlyIfMissing {_a .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 _cac ,nil ;};if form .DR ==nil {form .DR =_fdg .NewPdfPageResources ();};switch _dbbcg :=field .GetContext ().(type ){case *_fdg .PdfFieldButton :if _dbbcg .IsPush (){_egga ,_gdea :=_cbef (_dbbcg ,wa ,_gbf .Style ());if _gdea !=nil {return nil ,_gdea ;
};return _egga ,nil ;};};return nil ,nil ;};type quadding int ;

// 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 (_edf FieldAppearance )WrapContentStream (page *_fdg .PdfPage )error {_dbe ,_cfdg :=page .GetAllContentStreams ();if _cfdg !=nil {return _cfdg ;};_eefd :=_fa .NewContentStreamParser (_dbe );_ggec ,_cfdg :=_eefd .Parse ();if _cfdg !=nil {return _cfdg ;
};_ggec .WrapIfNeeded ();_dcc :=[]string {_ggec .String ()};return page .SetContentStreams (_dcc ,_bdggc ());};

// SetStyle applies appearance `style` to `fa`.
func (_ecd *FieldAppearance )SetStyle (style AppearanceStyle ){_ecd ._fae =&style };

// Style returns the appearance style of `fa`. If not specified, returns default style.
func (_bdee ImageFieldAppearance )Style ()AppearanceStyle {if _bdee ._bbee !=nil {return *_bdee ._bbee ;};return AppearanceStyle {BorderSize :0.0,BorderColor :_fdg .NewPdfColorDeviceGray (0),FillColor :_fdg .NewPdfColorDeviceGray (1),DrawAlignmentReticle :false };
};

// CheckboxFieldOptions defines optional parameters for a checkbox field a form.
type CheckboxFieldOptions struct{Checked bool ;};

// NewFormSubmitButtonField would create a submit button in specified page according to the parameter in `FormSubmitActionOptions`.
func NewFormSubmitButtonField (page *_fdg .PdfPage ,opt FormSubmitActionOptions )(*_fdg .PdfFieldButton ,error ){_agfe :=int64 (_egeg );if opt .IsExclusionList {_agfe |=_acea ;};if opt .IncludeEmptyFields {_agfe |=_ecgga ;};if opt .SubmitAsPDF {_agfe |=_dbbc ;
};_ddfb :=_fdg .NewPdfActionSubmitForm ();_ddfb .Flags =_gc .MakeInteger (_agfe );_ddfb .F =_fdg .NewPdfFilespec ();if opt .Fields !=nil {_ddfb .Fields =opt .Fields ;};_ddfb .F .F =_gc .MakeString (opt .Url );_ddfb .F .FS =_gc .MakeName ("\u0055\u0052\u004c");
_cec ,_adec :=_eabe (page ,opt .Rectangle ,"\u0062t\u006e\u0053\u0075\u0062\u006d\u0069t",opt .Label ,opt .LabelColor ,opt .Font ,opt .FontSize ,_ddfb .ToPdfObject ());if _adec !=nil {return nil ,_adec ;};return _cec ,nil ;};const (_fgb quadding =0;_df quadding =1;
_dfg quadding =2;_bd float64 =2.0;);func _bdggc ()_gc .StreamEncoder {return _gc .NewFlateEncoder ()};func _bfac (_fadg _gc .PdfObject ,_gedb *_fdg .PdfPageResources )(*_gc .PdfObjectName ,float64 ,bool ){var (_gcdc *_gc .PdfObjectName ;_cbe float64 ;_acba bool ;
);if _dddc ,_afgf :=_gc .GetDict (_fadg );_afgf &&_dddc !=nil {_becc :=_gc .TraceToDirectObject (_dddc .Get ("\u004e"));switch _deeec :=_becc .(type ){case *_gc .PdfObjectStream :_dcf ,_gbca :=_gc .DecodeStream (_deeec );if _gbca !=nil {_a .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u0020\u0075\u006e\u0061\u0062\u006c\u0065\u0020\u0064\u0065\u0063\u006f\u0064\u0065\u0020\u0063\u006f\u006e\u0074e\u006e\u0074\u0020\u0073\u0074r\u0065\u0061m\u003a\u0020\u0025\u0076",_gbca .Error ());
return nil ,0,false ;};_gggd ,_gbca :=_fa .NewContentStreamParser (string (_dcf )).Parse ();if _gbca !=nil {_a .Log .Debug ("\u0045\u0052R\u004f\u0052\u0020\u0075n\u0061\u0062l\u0065\u0020\u0070\u0061\u0072\u0073\u0065\u0020c\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0073\u0074\u0072\u0065\u0061m\u003a\u0020\u0025\u0076",_gbca .Error ());
return nil ,0,false ;};_dec :=_fa .NewContentStreamProcessor (*_gggd );_dec .AddHandler (_fa .HandlerConditionEnumOperand ,"\u0054\u0066",func (_bdcc *_fa .ContentStreamOperation ,_abbfd _fa .GraphicsState ,_ccefd *_fdg .PdfPageResources )error {if len (_bdcc .Params )==2{if _cgff ,_bcaf :=_gc .GetName (_bdcc .Params [0]);
_bcaf {_gcdc =_cgff ;};if _fged ,_bacd :=_gc .GetNumberAsFloat (_bdcc .Params [1]);_bacd ==nil {_cbe =_fged ;};_acba =true ;return _fa .ErrEarlyExit ;};return nil ;});_dec .Process (_gedb );return _gcdc ,_cbe ,_acba ;};};return nil ,0,false ;};

// 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 *_fdg .PdfSignature ,lines []*SignatureLine ,opts *SignatureFieldOpts )(*_fdg .PdfFieldSignature ,error ){if signature ==nil {return nil ,_fd .New ("\u0073\u0069\u0067na\u0074\u0075\u0072\u0065\u0020\u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u006e\u0069\u006c");
};_fdef ,_fgdc :=_gafa (lines ,opts );if _fgdc !=nil {return nil ,_fgdc ;};_bfe :=_fdg .NewPdfFieldSignature (signature );_bfe .Rect =_gc .MakeArrayFromFloats (opts .Rect );_bfe .AP =_fdef ;return _bfe ,nil ;};func _efeb (_egbe *_fa .ContentCreator ,_fag AppearanceStyle ,_ecg ,_gcca float64 ){_egbe .Add_q ().Add_re (0,0,_ecg ,_gcca ).Add_re (0,_gcca /2,_ecg ,_gcca /2).Add_re (0,0,_ecg ,_gcca ).Add_re (_ecg /2,0,_ecg /2,_gcca ).Add_w (_fag .BorderSize ).SetStrokingColor (_fag .BorderColor ).SetNonStrokingColor (_fag .FillColor ).Add_B ().Add_Q ();
};

// InkAnnotationDef holds base information for constructing an ink annotation.
type InkAnnotationDef struct{

// Paths is the array of stroked paths which compose the annotation.
Paths []_ff .Path ;

// Color is the color of the line. Default to black.
Color *_fdg .PdfColorDeviceRGB ;

// LineWidth is the width of the line.
LineWidth 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 ;

// FallbackSize represents a global font size fallback used for fields
// which do not specify a font size in their default appearance (DA).
// The fallback size is applied only if its value is larger than zero.
FallbackSize float64 ;

// FieldFallbacks defines font fallbacks for specific fields. The map keys
// represent the names of the fields (which can be specified by their
// partial or full names). Specific field fallback fonts take precedence
// over the global font fallback.
FieldFallbacks map[string ]*AppearanceFont ;

// ForceReplace forces the replacement of fonts in the filling/flattening
// process, even if the default appearance (DA) specifies a valid font.
// If no fallback font is provided, setting this field has no effect.
ForceReplace bool ;};

// Style returns the appearance style of `fa`. If not specified, returns default style.
func (_ca FieldAppearance )Style ()AppearanceStyle {if _ca ._fae !=nil {return *_ca ._fae ;};_caa :=_bd ;return AppearanceStyle {AutoFontSizeFraction :0.65,CheckmarkRune :'✔',BorderSize :0.0,BorderColor :_fdg .NewPdfColorDeviceGray (0),FillColor :_fdg .NewPdfColorDeviceGray (1),MultilineLineHeight :1.2,MultilineVAlignMiddle :false ,DrawAlignmentReticle :false ,AllowMK :true ,MarginLeft :&_caa };
};

// SetStyle applies appearance `style` to `fa`.
func (_gfad *ImageFieldAppearance )SetStyle (style AppearanceStyle ){_gfad ._bbee =&style };func _ggfg (_cca *InkAnnotationDef )([]byte ,*_fdg .PdfRectangle ,error ){_bae :=[][]_ff .CubicBezierCurve {};for _ ,_dfea :=range _cca .Paths {if _dfea .Length ()==0{continue ;
};_agfd :=_dfea .Points ;_gdf ,_cfbc ,_accg :=_cbgf (_agfd );if _accg !=nil {return nil ,nil ,_accg ;};if len (_gdf )!=len (_cfbc ){return nil ,nil ,_fd .New ("\u0069\u006e\u0065\u0071\u0075\u0061\u006c\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020\u006f\u0066\u0020\u0063\u0061l\u0063\u0075\u006c\u0061\u0074\u0065\u0064\u0020\u0066\u0069\u0072\u0073\u0074\u0020\u0061\u006e\u0064\u0020\u0073\u0065\u0063\u006f\u006e\u0064\u0020\u0063\u006f\u006e\u0074\u0072o\u006c\u0020\u0070\u006f\u0069n\u0074");
};_dfad :=[]_ff .CubicBezierCurve {};for _aaeg :=0;_aaeg < len (_gdf );_aaeg ++{_dfad =append (_dfad ,_ff .CubicBezierCurve {P0 :_agfd [_aaeg ],P1 :_gdf [_aaeg ],P2 :_cfbc [_aaeg ],P3 :_agfd [_aaeg +1]});};if len (_dfad )> 0{_bae =append (_bae ,_dfad );
};};_abcg ,_ccggg ,_cbee :=_fbfceb (_bae ,_cca .Color ,_cca .LineWidth );if _cbee !=nil {return nil ,nil ,_cbee ;};return _abcg ,_ccggg ,nil ;};func _gfe (_eee *_fdg .PdfAnnotationWidget ,_ *_fdg .PdfFieldButton ,_ *_fdg .PdfPageResources ,_ebc AppearanceStyle )(*_gc .PdfObjectDictionary ,error ){_bedb ,_cdad :=_gc .GetArray (_eee .Rect );
if !_cdad {return nil ,_fd .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_gad ,_agae :=_fdg .NewPdfRectangle (*_bedb );if _agae !=nil {return nil ,_agae ;};_dee ,_ede :=_gad .Width (),_gad .Height ();_ggeb ,_eabf :=_dee ,_ede ;
_a .Log .Debug ("\u0043\u0068\u0065\u0063kb\u006f\u0078\u002c\u0020\u0077\u0061\u0020\u0042\u0053\u003a\u0020\u0025\u0076",_eee .BS );_aec ,_agae :=_fdg .NewStandard14Font ("\u005a\u0061\u0070f\u0044\u0069\u006e\u0067\u0062\u0061\u0074\u0073");if _agae !=nil {return nil ,_agae ;
};_eacea ,_aega :=_gc .GetDict (_eee .MK );if _aega {_acb ,_ :=_gc .GetDict (_eee .BS );_fde :=_ebc .applyAppearanceCharacteristics (_eacea ,_acb ,_aec );if _fde !=nil {return nil ,_fde ;};};_bdg :=_fdg .NewXObjectForm ();{_ffce :=_fa .NewContentCreator ();
if _ebc .BorderSize > 0{_eaaf (_ffce ,_ebc ,_dee ,_ede );};if _ebc .DrawAlignmentReticle {_fcd :=_ebc ;_fcd .BorderSize =0.2;_efeb (_ffce ,_fcd ,_dee ,_ede );};_dee ,_ede =_ebc .applyRotation (_eacea ,_dee ,_ede ,_ffce );_eef :=_ebc .AutoFontSizeFraction *_ede ;
_eff ,_gacf :=_aec .GetRuneMetrics (_ebc .CheckmarkRune );if !_gacf {return nil ,_fd .New ("\u0067l\u0079p\u0068\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");};_begd :=_aec .Encoder ();_dac :=_begd .Encode (string (_ebc .CheckmarkRune ));
_fge :=_eff .Wx *_eef /1000.0;_fcg :=705.0;_agf :=_fcg /1000.0*_eef ;_aebg :=_bd ;if _ebc .MarginLeft !=nil {_aebg =*_ebc .MarginLeft ;};_eaf :=1.0;if _fge < _dee {_aebg =(_dee -_fge )/2.0;};if _agf < _ede {_eaf =(_ede -_agf )/2.0;};_ffce .Add_q ().Add_g (0).Add_BT ().Add_Tf ("\u005a\u0061\u0044\u0062",_eef ).Add_Td (_aebg ,_eaf ).Add_Tj (*_gc .MakeStringFromBytes (_dac )).Add_ET ().Add_Q ();
_bdg .Resources =_fdg .NewPdfPageResources ();_bdg .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_aec .ToPdfObject ());_bdg .BBox =_gc .MakeArrayFromFloats ([]float64 {0,0,_ggeb ,_eabf });_bdg .SetContentStream (_ffce .Bytes (),_bdggc ());};_dgf :=_fdg .NewXObjectForm ();
{_feee :=_fa .NewContentCreator ();if _ebc .BorderSize > 0{_eaaf (_feee ,_ebc ,_dee ,_ede );};_dgf .BBox =_gc .MakeArrayFromFloats ([]float64 {0,0,_ggeb ,_eabf });_dgf .SetContentStream (_feee .Bytes (),_bdggc ());};_dabg :=_gc .PdfObjectName ("\u0059\u0065\u0073");
_dfc ,_aega :=_gc .GetDict (_eee .AP );if _aega &&_dfc !=nil {_faaa :=_gc .TraceToDirectObject (_dfc .Get ("\u004e"));switch _cde :=_faaa .(type ){case *_gc .PdfObjectDictionary :_cbag :=_cde .Keys ();for _ ,_bdgf :=range _cbag {if _bdgf !="\u004f\u0066\u0066"{_dabg =_bdgf ;
};};};};_ddge :=_gc .MakeDict ();_ddge .Set ("\u004f\u0066\u0066",_dgf .ToPdfObject ());_ddge .Set (_dabg ,_bdg .ToPdfObject ());_gea :=_gc .MakeDict ();_gea .Set ("\u004e",_ddge );return _gea ,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 ;};

// CreateFileAttachmentAnnotation creates a file attachment annotation object that can be added to the annotation list of a PDF page.
func CreateFileAttachmentAnnotation (fileDef FileAnnotationDef )(*_fdg .PdfAnnotation ,error ){_gaae :=_fdg .NewPdfFileSpecFromEmbeddedFile (fileDef .EmbeddedFile );if fileDef .Color ==nil {fileDef .Color =_fdg .NewPdfColorDeviceRGB (0.0,0.0,0.0);};if fileDef .Description ==""{fileDef .Description =fileDef .EmbeddedFile .Name ;
};if fileDef .CreationDate ==nil {_dfba :=_f .Now ();fileDef .CreationDate =&_dfba ;};if fileDef .IconName ==""{fileDef .IconName ="\u0050u\u0073\u0068\u0050\u0069\u006e";};_caee ,_gacfb :=_fdg .NewPdfDateFromTime (*fileDef .CreationDate );if _gacfb !=nil {return nil ,_gacfb ;
};_ddda :=_fdg .NewPdfAnnotationFileAttachment ();_ddda .FS =_gaae .ToPdfObject ();_ddda .C =_gc .MakeArrayFromFloats ([]float64 {fileDef .Color .R (),fileDef .Color .G (),fileDef .Color .B ()});_ddda .Contents =_gc .MakeString (fileDef .Description );
_ddda .CreationDate =_caee .ToPdfObject ();_ddda .M =_caee .ToPdfObject ();_ddda .Name =_gc .MakeName (fileDef .IconName );_ddda .Rect =_gc .MakeArrayFromFloats ([]float64 {fileDef .X ,fileDef .Y ,fileDef .X +fileDef .Width ,fileDef .Y +fileDef .Height });
_ddda .T =_gc .MakeString (fileDef .Author );_ddda .Subj =_gc .MakeString (fileDef .Subject );return _ddda .PdfAnnotation ,nil ;};

// CreateLineAnnotation creates a line annotation object that can be added to page PDF annotations.
func CreateLineAnnotation (lineDef LineAnnotationDef )(*_fdg .PdfAnnotation ,error ){_cgbe :=_fdg .NewPdfAnnotationLine ();_cgbe .L =_gc .MakeArrayFromFloats ([]float64 {lineDef .X1 ,lineDef .Y1 ,lineDef .X2 ,lineDef .Y2 });_feea :=_gc .MakeName ("\u004e\u006f\u006e\u0065");
if lineDef .LineEndingStyle1 ==_ff .LineEndingStyleArrow {_feea =_gc .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");};_dgfa :=_gc .MakeName ("\u004e\u006f\u006e\u0065");if lineDef .LineEndingStyle2 ==_ff .LineEndingStyleArrow {_dgfa =_gc .MakeName ("C\u006c\u006f\u0073\u0065\u0064\u0041\u0072\u0072\u006f\u0077");
};_cgbe .LE =_gc .MakeArray (_feea ,_dgfa );if lineDef .Opacity < 1.0{_cgbe .CA =_gc .MakeFloat (lineDef .Opacity );};_dgfc ,_dddb ,_ecfa :=lineDef .LineColor .R (),lineDef .LineColor .G (),lineDef .LineColor .B ();_cgbe .IC =_gc .MakeArrayFromFloats ([]float64 {_dgfc ,_dddb ,_ecfa });
_cgbe .C =_gc .MakeArrayFromFloats ([]float64 {_dgfc ,_dddb ,_ecfa });_efee :=_fdg .NewBorderStyle ();_efee .SetBorderWidth (lineDef .LineWidth );_cgbe .BS =_efee .ToPdfObject ();_eacg ,_eeac ,_gcdf :=_ccb (lineDef );if _gcdf !=nil {return nil ,_gcdf ;
};_cgbe .AP =_eacg ;_cgbe .Rect =_gc .MakeArrayFromFloats ([]float64 {_eeac .Llx ,_eeac .Lly ,_eeac .Urx ,_eeac .Ury });return _cgbe .PdfAnnotation ,nil ;};

// NewFormResetButtonField would create a reset button in specified page according to the parameter in `FormResetActionOptions`.
func NewFormResetButtonField (page *_fdg .PdfPage ,opt FormResetActionOptions )(*_fdg .PdfFieldButton ,error ){_daf :=_fdg .NewPdfActionResetForm ();_daf .Fields =opt .Fields ;_daf .Flags =_gc .MakeInteger (0);if opt .IsExclusionList {_daf .Flags =_gc .MakeInteger (1);
};_agbb ,_eca :=_eabe (page ,opt .Rectangle ,"\u0062\u0074\u006e\u0052\u0065\u0073\u0065\u0074",opt .Label ,opt .LabelColor ,opt .Font ,opt .FontSize ,_daf .ToPdfObject ());if _eca !=nil {return nil ,_eca ;};return _agbb ,nil ;};func _fbfceb (_gbg [][]_ff .CubicBezierCurve ,_afcc *_fdg .PdfColorDeviceRGB ,_bbbb float64 )([]byte ,*_fdg .PdfRectangle ,error ){_gfcd :=_fa .NewContentCreator ();
_gfcd .Add_q ().SetStrokingColor (_afcc ).Add_w (_bbbb );_geed :=_ff .NewCubicBezierPath ();for _ ,_gggdd :=range _gbg {_geed .Curves =append (_geed .Curves ,_gggdd ...);for _baeg ,_cedc :=range _gggdd {if _baeg ==0{_gfcd .Add_m (_cedc .P0 .X ,_cedc .P0 .Y );
}else {_gfcd .Add_l (_cedc .P0 .X ,_cedc .P0 .Y );};_gfcd .Add_c (_cedc .P1 .X ,_cedc .P1 .Y ,_cedc .P2 .X ,_cedc .P2 .Y ,_cedc .P3 .X ,_cedc .P3 .Y );};};_gfcd .Add_S ().Add_Q ();return _gfcd .Bytes (),_geed .GetBoundingBox ().ToPdfRectangle (),nil ;};


// CircleAnnotationDef defines a circle annotation or ellipse at position (X, Y) and Width and Height.
// The annotation has various style parameters including Fill and Border options and Opacity.
type CircleAnnotationDef struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_fdg .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_fdg .PdfColorDeviceRGB ;Opacity float64 ;};func (_cdb *AppearanceStyle )applyRotation (_adbe *_gc .PdfObjectDictionary ,_geg ,_bbcd float64 ,_efc *_fa .ContentCreator )(float64 ,float64 ){if !_cdb .AllowMK {return _geg ,_bbcd ;
};if _adbe ==nil {return _geg ,_bbcd ;};_cgc ,_ :=_gc .GetNumberAsFloat (_adbe .Get ("\u0052"));if _cgc ==0{return _geg ,_bbcd ;};_aef :=-_cgc ;_bgg :=_ff .Path {Points :[]_ff .Point {_ff .NewPoint (0,0).Rotate (_aef ),_ff .NewPoint (_geg ,0).Rotate (_aef ),_ff .NewPoint (0,_bbcd ).Rotate (_aef ),_ff .NewPoint (_geg ,_bbcd ).Rotate (_aef )}}.GetBoundingBox ();
_efc .RotateDeg (_cgc );_efc .Translate (_bgg .X ,_bgg .Y );return _bgg .Width ,_bgg .Height ;};

// NewSignatureFieldOpts returns a new initialized instance of options
// used to generate a signature appearance.
func NewSignatureFieldOpts ()*SignatureFieldOpts {return &SignatureFieldOpts {Font :_fdg .DefaultFont (),FontSize :10,LineHeight :1,AutoSize :true ,TextColor :_fdg .NewPdfColorDeviceGray (0),BorderColor :_fdg .NewPdfColorDeviceGray (0),FillColor :_fdg .NewPdfColorDeviceGray (1),FillOpacity :1.0,Encoder :_gc .NewFlateEncoder (),ImagePosition :SignatureImageLeft };
};func _babd (_cbfc RectangleAnnotationDef ,_gaca string )([]byte ,*_fdg .PdfRectangle ,*_fdg .PdfRectangle ,error ){_gbb :=_ff .Rectangle {X :0,Y :0,Width :_cbfc .Width ,Height :_cbfc .Height ,FillEnabled :_cbfc .FillEnabled ,FillColor :_cbfc .FillColor ,BorderEnabled :_cbfc .BorderEnabled ,BorderWidth :2*_cbfc .BorderWidth ,BorderColor :_cbfc .BorderColor ,Opacity :_cbfc .Opacity };
_babbg ,_fceg ,_bedd :=_gbb .Draw (_gaca );if _bedd !=nil {return nil ,nil ,nil ,_bedd ;};_gaff :=&_fdg .PdfRectangle {};_gaff .Llx =_cbfc .X +_fceg .Llx ;_gaff .Lly =_cbfc .Y +_fceg .Lly ;_gaff .Urx =_cbfc .X +_fceg .Urx ;_gaff .Ury =_cbfc .Y +_fceg .Ury ;
return _babbg ,_fceg ,_gaff ,nil ;};func _eb (_ce CircleAnnotationDef ,_fed string )([]byte ,*_fdg .PdfRectangle ,*_fdg .PdfRectangle ,error ){_dg :=_ff .Circle {X :_ce .X ,Y :_ce .Y ,Width :_ce .Width ,Height :_ce .Height ,FillEnabled :_ce .FillEnabled ,FillColor :_ce .FillColor ,BorderEnabled :_ce .BorderEnabled ,BorderWidth :_ce .BorderWidth ,BorderColor :_ce .BorderColor ,Opacity :_ce .Opacity };
_accb ,_gf ,_gcc :=_dg .Draw (_fed );if _gcc !=nil {return nil ,nil ,nil ,_gcc ;};_fg :=&_fdg .PdfRectangle {};_fg .Llx =_ce .X +_gf .Llx ;_fg .Lly =_ce .Y +_gf .Lly ;_fg .Urx =_ce .X +_gf .Urx ;_fg .Ury =_ce .Y +_gf .Ury ;return _accb ,_gf ,_fg ,nil ;
};

// FormSubmitActionOptions holds options for creating a form submit button.
type FormSubmitActionOptions struct{

// Rectangle holds the button position, size, and color.
Rectangle _ff .Rectangle ;

// Url specifies the URL where the fieds will be submitted.
Url string ;

// Label specifies the text that would be displayed on the button.
Label string ;

// LabelColor specifies the button label color.
LabelColor _fdg .PdfColor ;

// Font specifies a font used for rendering the button label.
// When omitted it will fallback to use a Helvetica font.
Font *_fdg .PdfFont ;

// FontSize specifies the font size used in rendering the button label.
// The default font size is 12pt.
FontSize *float64 ;

// Fields specifies list of fields that could be submitted.
// This list may contain indirect object to fields or field names.
Fields *_gc .PdfObjectArray ;

// IsExclusionList specifies that the fields contain in `Fields` array would not be submitted.
IsExclusionList bool ;

// IncludeEmptyFields specifies if all fields would be submitted even though it's value is empty.
IncludeEmptyFields bool ;

// SubmitAsPDF specifies that the document shall be submitted as PDF.
// If set then all the other flags shall be ignored.
SubmitAsPDF bool ;};

// ImageFieldOptions defines optional parameters for a push button with image attach capability form field.
type ImageFieldOptions struct{Image *_fdg .Image ;_cfb AppearanceStyle ;};

// CreateCircleAnnotation creates a circle/ellipse annotation object with appearance stream that can be added to
// page PDF annotations.
func CreateCircleAnnotation (circDef CircleAnnotationDef )(*_fdg .PdfAnnotation ,error ){_db :=_fdg .NewPdfAnnotationCircle ();if circDef .BorderEnabled {_af ,_ad ,_bf :=circDef .BorderColor .R (),circDef .BorderColor .G (),circDef .BorderColor .B ();_db .C =_gc .MakeArrayFromFloats ([]float64 {_af ,_ad ,_bf });
_dc :=_fdg .NewBorderStyle ();_dc .SetBorderWidth (circDef .BorderWidth );_db .BS =_dc .ToPdfObject ();};if circDef .FillEnabled {_cd ,_gg ,_aa :=circDef .FillColor .R (),circDef .FillColor .G (),circDef .FillColor .B ();_db .IC =_gc .MakeArrayFromFloats ([]float64 {_cd ,_gg ,_aa });
}else {_db .IC =_gc .MakeArrayFromIntegers ([]int {});};if circDef .Opacity < 1.0{_db .CA =_gc .MakeFloat (circDef .Opacity );};_egb ,_fe ,_dba :=_de (circDef );if _dba !=nil {return nil ,_dba ;};_db .AP =_egb ;_db .Rect =_gc .MakeArrayFromFloats ([]float64 {_fe .Llx ,_fe .Lly ,_fe .Urx ,_fe .Ury });
return _db .PdfAnnotation ,nil ;};

// SignatureLine represents a line of information in the signature field appearance.
type SignatureLine struct{Desc string ;Text string ;};func _eabe (_caeb *_fdg .PdfPage ,_fbag _ff .Rectangle ,_dfaa string ,_gcae string ,_aaad _fdg .PdfColor ,_deaf *_fdg .PdfFont ,_afab *float64 ,_cgdd _gc .PdfObject )(*_fdg .PdfFieldButton ,error ){_gbcf ,_dgee :=_fbag .X ,_fbag .Y ;
_gafd :=_fbag .Width ;_bab :=_fbag .Height ;if _fbag .FillColor ==nil {_fbag .FillColor =_fdg .NewPdfColorDeviceGray (0.7);};if _aaad ==nil {_aaad =_fdg .NewPdfColorDeviceGray (0);};if _deaf ==nil {_deda ,_adaf :=_fdg .NewStandard14Font ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");
if _adaf !=nil {return nil ,_adaf ;};_deaf =_deda ;};_cffg :=_fdg .NewPdfField ();_cdfd :=&_fdg .PdfFieldButton {};_cffg .SetContext (_cdfd );_cdfd .PdfField =_cffg ;_cdfd .T =_gc .MakeString (_dfaa );_cdfd .SetType (_fdg .ButtonTypePush );_cdfd .V =_gc .MakeName ("\u004f\u0066\u0066");
_cdfd .Ff =_gc .MakeInteger (4);_accde :=_gc .MakeDict ();_accde .Set (*_gc .MakeName ("\u0043\u0041"),_gc .MakeString (_gcae ));_ggefa ,_fbec :=_deaf .GetFontDescriptor ();if _fbec !=nil {return nil ,_fbec ;};_bbd :=_gc .MakeName ("\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a");
_abga :=12.0;if _ggefa !=nil &&_ggefa .FontName !=nil {_bbd ,_ =_gc .GetName (_ggefa .FontName );};if _afab !=nil {_abga =*_afab ;};_bage :=_fa .NewContentCreator ();_bage .Add_q ();_bage .SetNonStrokingColor (_fbag .FillColor );_bage .Add_re (0,0,_gafd ,_bab );
_bage .Add_f ();_bage .Add_Q ();_bage .Add_q ();_bage .Add_BT ();_cfab :=0.0;for _ ,_gdg :=range _gcae {_cgda ,_ffcea :=_deaf .GetRuneMetrics (_gdg );if !_ffcea {_a .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",_gdg );
continue ;};_cfab +=_cgda .Wx ;};_cfab =_cfab /1000.0*_abga ;var _daec float64 ;if _ggefa !=nil {_daec ,_fbec =_ggefa .GetCapHeight ();if _fbec !=nil {_a .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",_fbec );
};};if int (_daec )<=0{_a .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");
_daec =1000;};_gagc :=_daec /1000.0*_abga ;_gccb :=(_bab -_gagc )/2.0;_fbfce :=(_gafd -_cfab )/2.0;_bage .Add_Tf (*_bbd ,_abga );_bage .SetNonStrokingColor (_aaad );_bage .Add_Td (_fbfce ,_gccb );_bage .Add_Tj (*_gc .MakeString (_gcae ));_bage .Add_ET ();
_bage .Add_Q ();_acdf :=_fdg .NewXObjectForm ();_acdf .SetContentStream (_bage .Bytes (),_gc .NewRawEncoder ());_acdf .BBox =_gc .MakeArrayFromFloats ([]float64 {0,0,_gafd ,_bab });_acdf .Resources =_fdg .NewPdfPageResources ();_acdf .Resources .SetFontByName (*_bbd ,_deaf .ToPdfObject ());
_aaff :=_gc .MakeDict ();_aaff .Set ("\u004e",_acdf .ToPdfObject ());_fcdb :=_fdg .NewPdfAnnotationWidget ();_fcdb .Rect =_gc .MakeArrayFromFloats ([]float64 {_gbcf ,_dgee ,_gbcf +_gafd ,_dgee +_bab });_fcdb .P =_caeb .ToPdfObject ();_fcdb .F =_gc .MakeInteger (4);
_fcdb .Parent =_cdfd .ToPdfObject ();_fcdb .A =_cgdd ;_fcdb .MK =_accde ;_fcdb .AP =_aaff ;_cdfd .Annotations =append (_cdfd .Annotations ,_fcdb );return _cdfd ,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 _fdg .PdfColor ;FillColor _fdg .PdfColor ;

// Multiplier for lineheight for multi line text.
MultilineLineHeight float64 ;MultilineVAlignMiddle bool ;

// Visual guide checking alignment of field contents (debugging).
DrawAlignmentReticle bool ;

// Allow field MK appearance characteristics to override style settings.
AllowMK bool ;

// Fonts holds appearance styles for fonts.
Fonts *AppearanceFontStyle ;

// MarginLeft represents the amount of space to leave on the left side of
// the form field bounding box when generating appearances (default: 2.0).
MarginLeft *float64 ;TextColor _fdg .PdfColor ;

// FieldColors holds separate set of appearance styles for fields.
FieldColors map[string ]_fdg .PdfColor ;};func _ccb (_cadc LineAnnotationDef )(*_gc .PdfObjectDictionary ,*_fdg .PdfRectangle ,error ){_dgcf :=_fdg .NewXObjectForm ();_dgcf .Resources =_fdg .NewPdfPageResources ();_egbd :="";if _cadc .Opacity < 1.0{_defb :=_gc .MakeDict ();
_defb .Set ("\u0063\u0061",_gc .MakeFloat (_cadc .Opacity ));_fgca :=_dgcf .Resources .AddExtGState ("\u0067\u0073\u0031",_defb );if _fgca !=nil {_a .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 ,_fgca ;};_egbd ="\u0067\u0073\u0031";};_aecd ,_cgbg ,_cdab ,_gafc :=_cadg (_cadc ,_egbd );if _gafc !=nil {return nil ,nil ,_gafc ;};_gafc =_dgcf .SetContentStream (_aecd ,nil );if _gafc !=nil {return nil ,nil ,_gafc ;};_dgcf .BBox =_cgbg .ToPdfObject ();
_egfe :=_gc .MakeDict ();_egfe .Set ("\u004e",_dgcf .ToPdfObject ());return _egfe ,_cdab ,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 ;_fae *AppearanceStyle ;};

// FormResetActionOptions holds options for creating a form reset button.
type FormResetActionOptions struct{

// Rectangle holds the button position, size, and color.
Rectangle _ff .Rectangle ;

// Label specifies the text that would be displayed on the button.
Label string ;

// LabelColor specifies the button label color.
LabelColor _fdg .PdfColor ;

// Font specifies a font used for rendering the button label.
// When omitted it will fallback to use a Helvetica font.
Font *_fdg .PdfFont ;

// FontSize specifies the font size used in rendering the button label.
// The default font size is 12pt.
FontSize *float64 ;

// Fields specifies list of fields that could be resetted.
// This list may contain indirect object to fields or field names.
Fields *_gc .PdfObjectArray ;

// IsExclusionList specifies that the fields in the `Fields` array would be excluded form reset process.
IsExclusionList bool ;};func _de (_ege CircleAnnotationDef )(*_gc .PdfObjectDictionary ,*_fdg .PdfRectangle ,error ){_bg :=_fdg .NewXObjectForm ();_bg .Resources =_fdg .NewPdfPageResources ();_ba :="";if _ege .Opacity < 1.0{_gcd :=_gc .MakeDict ();_gcd .Set ("\u0063\u0061",_gc .MakeFloat (_ege .Opacity ));
_gcd .Set ("\u0043\u0041",_gc .MakeFloat (_ege .Opacity ));_ga :=_bg .Resources .AddExtGState ("\u0067\u0073\u0031",_gcd );if _ga !=nil {_a .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 ,_ga ;};_ba ="\u0067\u0073\u0031";};_ea ,_fc ,_ge ,_acc :=_eb (_ege ,_ba );if _acc !=nil {return nil ,nil ,_acc ;};_acc =_bg .SetContentStream (_ea ,nil );if _acc !=nil {return nil ,nil ,_acc ;};_bg .BBox =_fc .ToPdfObject ();_da :=_gc .MakeDict ();
_da .Set ("\u004e",_bg .ToPdfObject ());return _da ,_ge ,nil ;};func _cbgf (_cdaa []_ff .Point )(_gff []_ff .Point ,_fda []_ff .Point ,_egd error ){_gbac :=len (_cdaa )-1;if len (_cdaa )< 1{return nil ,nil ,_fd .New ("\u0061\u0074\u0020\u006c\u0065\u0061\u0073\u0074\u0020\u0074\u0077\u006f\u0020\u0070\u006f\u0069\u006e\u0074s \u0072e\u0071\u0075\u0069\u0072\u0065\u0064\u0020\u0074\u006f\u0020\u0063\u0061l\u0063\u0075\u006c\u0061\u0074\u0065\u0020\u0063\u0075\u0072\u0076\u0065\u0020\u0063\u006f\u006e\u0074r\u006f\u006c\u0020\u0070\u006f\u0069\u006e\u0074\u0073");
};if _gbac ==1{_ffgd :=_ff .Point {X :(2*_cdaa [0].X +_cdaa [1].X )/3,Y :(2*_cdaa [0].Y +_cdaa [1].Y )/3};_gff =append (_gff ,_ffgd );_fda =append (_fda ,_ff .Point {X :2*_ffgd .X -_cdaa [0].X ,Y :2*_ffgd .Y -_cdaa [0].Y });return _gff ,_fda ,nil ;};_efcf :=make ([]float64 ,_gbac );
for _fgee :=1;_fgee < _gbac -1;_fgee ++{_efcf [_fgee ]=4*_cdaa [_fgee ].X +2*_cdaa [_fgee +1].X ;};_efcf [0]=_cdaa [0].X +2*_cdaa [1].X ;_efcf [_gbac -1]=(8*_cdaa [_gbac -1].X +_cdaa [_gbac ].X )/2.0;_agbg :=_cgca (_efcf );for _aebb :=1;_aebb < _gbac -1;
_aebb ++{_efcf [_aebb ]=4*_cdaa [_aebb ].Y +2*_cdaa [_aebb +1].Y ;};_efcf [0]=_cdaa [0].Y +2*_cdaa [1].Y ;_efcf [_gbac -1]=(8*_cdaa [_gbac -1].Y +_cdaa [_gbac ].Y )/2.0;_abdb :=_cgca (_efcf );_gff =make ([]_ff .Point ,_gbac );_fda =make ([]_ff .Point ,_gbac );
for _cbdb :=0;_cbdb < _gbac ;_cbdb ++{_gff [_cbdb ]=_ff .Point {X :_g .RoundDefault (_agbg [_cbdb ]),Y :_g .RoundDefault (_abdb [_cbdb ])};if _cbdb < _gbac -1{_fda [_cbdb ]=_ff .Point {X :_g .RoundDefault (2*_cdaa [_cbdb +1].X -_agbg [_cbdb +1]),Y :_g .RoundDefault (2*_cdaa [_cbdb +1].Y -_abdb [_cbdb +1])};
}else {_fda [_cbdb ]=_ff .Point {X :_g .RoundDefault ((_cdaa [_gbac ].X +_agbg [_gbac -1])/2),Y :_g .RoundDefault ((_cdaa [_gbac ].Y +_abdb [_gbac -1])/2)};};};return _gff ,_fda ,nil ;};

// GenerateAppearanceDict generates an appearance dictionary for widget annotation `wa` for the `field` in `form`.
// Implements interface model.FieldAppearanceGenerator.
func (_bca FieldAppearance )GenerateAppearanceDict (form *_fdg .PdfAcroForm ,field *_fdg .PdfField ,wa *_fdg .PdfAnnotationWidget )(*_gc .PdfObjectDictionary ,error ){_a .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 );
_ ,_eab :=field .GetContext ().(*_fdg .PdfFieldText );_add ,_cbd :=_gc .GetDict (wa .AP );if _cbd &&_bca .OnlyIfMissing &&(!_eab ||!_bca .RegenerateTextFields ){_a .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 _add ,nil ;};if form .DR ==nil {form .DR =_fdg .NewPdfPageResources ();};switch _cg :=field .GetContext ().(type ){case *_fdg .PdfFieldText :_ed :=_cg ;if _bb :=_dfed (_ed .PdfField );_bb ==""{_ed .DA =form .DA ;};if _bca ._fae !=nil {if _bca ._fae .FieldColors !=nil &&_bca ._fae .FieldColors [field .PartialName ()]!=nil {_dfgg :=_bca ._fae .FieldColors [field .PartialName ()];
_ab ,_ag :=_gd (_ed ,_dfgg );if _ag !=nil {return nil ,_ag ;};_ed .DA =_ab ;}else if _bca ._fae .TextColor !=nil {_cdc ,_ffe :=_gd (_ed ,_bca ._fae .TextColor );if _ffe !=nil {return nil ,_ffe ;};_ed .DA =_cdc ;};};switch {case _ed .Flags ().Has (_fdg .FieldFlagPassword ):return nil ,nil ;
case _ed .Flags ().Has (_fdg .FieldFlagFileSelect ):return nil ,nil ;case _ed .Flags ().Has (_fdg .FieldFlagComb ):if _ed .MaxLen !=nil {_fcf ,_eac :=_acg (wa ,_ed ,form .DR ,_bca .Style ());if _eac !=nil {return nil ,_eac ;};return _fcf ,nil ;};};_ef ,_be :=_accef (wa ,_ed ,form .DR ,_bca .Style ());
if _be !=nil {return nil ,_be ;};return _ef ,nil ;case *_fdg .PdfFieldButton :_dgg :=_cg ;if _dgg .IsCheckbox (){_gga ,_bcf :=_gfe (wa ,_dgg ,form .DR ,_bca .Style ());if _bcf !=nil {return nil ,_bcf ;};return _gga ,nil ;};_a .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",_dgg .GetType ());
case *_fdg .PdfFieldChoice :_cba :=_cg ;switch {case _cba .Flags ().Has (_fdg .FieldFlagCombo ):_abb ,_ee :=_dce (form ,wa ,_cba ,_bca .Style ());if _ee !=nil {return nil ,_ee ;};return _abb ,nil ;default:_a .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",_cba .Flags ().String ());
};default:_a .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",_cg );};return nil ,nil ;};

// CreateInkAnnotation creates an ink annotation object that can be added to the annotation list of a PDF page.
func CreateInkAnnotation (inkDef InkAnnotationDef )(*_fdg .PdfAnnotation ,error ){_dbbcgf :=_fdg .NewPdfAnnotationInk ();_aada :=_gc .MakeArray ();for _ ,_ebab :=range inkDef .Paths {if _ebab .Length ()==0{continue ;};_bcfa :=[]float64 {};for _ ,_baga :=range _ebab .Points {_ecfb :=_g .RoundDefault (_baga .X );
_cga :=_g .RoundDefault (_baga .Y );_bcfa =append (_bcfa ,_ecfb ,_cga );};_aada .Append (_gc .MakeArrayFromFloats (_bcfa ));};_dbbcgf .InkList =_aada ;if inkDef .Color ==nil {inkDef .Color =_fdg .NewPdfColorDeviceRGB (0.0,0.0,0.0);};_dbbcgf .C =_gc .MakeArrayFromFloats ([]float64 {inkDef .Color .R (),inkDef .Color .G (),inkDef .Color .B ()});
_bgad ,_bdgc ,_bdcf :=_babb (&inkDef );if _bdcf !=nil {return nil ,_bdcf ;};_dbbcgf .AP =_bgad ;_dbbcgf .Rect =_gc .MakeArrayFromFloats ([]float64 {_bdgc .Llx ,_bdgc .Lly ,_bdgc .Urx ,_bdgc .Ury });return _dbbcgf .PdfAnnotation ,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 *_fdg .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 _ff .LineEndingStyle ;LineEndingStyle2 _ff .LineEndingStyle ;};func _gcfd (_dfbc *_fdg .PdfField ,_dgfd ,_edg float64 ,_gfee string ,_bbfc AppearanceStyle ,_gbab *_fa .ContentStreamOperations ,_feg *_fdg .PdfPageResources ,_bdb *_gc .PdfObjectDictionary )(*_fdg .XObjectForm ,error ){_ddga :=_fdg .NewPdfPageResources ();
_agc ,_ceb :=_dgfd ,_edg ;_dgfb :=_fa .NewContentCreator ();if _bbfc .BorderSize > 0{_eaaf (_dgfb ,_bbfc ,_dgfd ,_edg );};if _bbfc .DrawAlignmentReticle {_abde :=_bbfc ;_abde .BorderSize =0.2;_efeb (_dgfb ,_abde ,_dgfd ,_edg );};_dgfb .Add_BMC ("\u0054\u0078");
_dgfb .Add_q ();_dgfb .Add_BT ();_dgfd ,_edg =_bbfc .applyRotation (_bdb ,_dgfd ,_edg ,_dgfb );_ebf ,_fafb ,_ggef :=_bbfc .processDA (_dfbc ,_gbab ,_feg ,_ddga ,_dgfb );if _ggef !=nil {return nil ,_ggef ;};_gddf :=_ebf .Font ;_ffg :=_ebf .Size ;_bac :=_gc .MakeName (_ebf .Name );
_bdbf :=_ffg ==0;if _bdbf &&_fafb {_ffg =_edg *_bbfc .AutoFontSizeFraction ;};_ecf :=_gddf .Encoder ();if _ecf ==nil {_a .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");
_ecf =_ac .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};if len (_gfee )==0{return nil ,nil ;};_ced :=_bd ;if _bbfc .MarginLeft !=nil {_ced =*_bbfc .MarginLeft ;};_bcage :=0.0;if _ecf !=nil {for _ ,_dgga :=range _gfee {_bdbc ,_fdf :=_gddf .GetRuneMetrics (_dgga );
if !_fdf {_a .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",_dgga );
continue ;};_bcage +=_bdbc .Wx ;};_gfee =string (_ecf .Encode (_gfee ));};if _ffg ==0||_bdbf &&_bcage > 0&&_ced +_bcage *_ffg /1000.0> _dgfd {_ffg =0.95*1000.0*(_dgfd -_ced )/_bcage ;};_dfa :=1.0*_ffg ;_fdfa :=2.0;{_abfd :=_dfa ;if _bdbf &&_fdfa +_abfd > _edg {_ffg =0.95*(_edg -_fdfa );
_dfa =1.0*_ffg ;_abfd =_dfa ;};if _edg > _abfd {_fdfa =(_edg -_abfd )/2.0;_fdfa +=1.50;};};_dgfb .Add_Tf (*_bac ,_ffg );_dgfb .Add_Td (_ced ,_fdfa );_dgfb .Add_Tj (*_gc .MakeString (_gfee ));_dgfb .Add_ET ();_dgfb .Add_Q ();_dgfb .Add_EMC ();_aegae :=_fdg .NewXObjectForm ();
_aegae .Resources =_ddga ;_aegae .BBox =_gc .MakeArrayFromFloats ([]float64 {0,0,_agc ,_ceb });_aegae .SetContentStream (_dgfb .Bytes (),_bdggc ());return _aegae ,nil ;};func _dce (_dabb *_fdg .PdfAcroForm ,_ggf *_fdg .PdfAnnotationWidget ,_abf *_fdg .PdfFieldChoice ,_cge AppearanceStyle )(*_gc .PdfObjectDictionary ,error ){_aaa ,_dcdb :=_gc .GetArray (_ggf .Rect );
if !_dcdb {return nil ,_fd .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_ddc ,_ggfe :=_fdg .NewPdfRectangle (*_aaa );if _ggfe !=nil {return nil ,_ggfe ;};_fgg ,_gfb :=_ddc .Width (),_ddc .Height ();_a .Log .Debug ("\u0043\u0068\u006f\u0069\u0063\u0065\u002c\u0020\u0077\u0061\u0020\u0042S\u003a\u0020\u0025\u0076",_ggf .BS );
_fca ,_ggfe :=_fa .NewContentStreamParser (_dfed (_abf .PdfField )).Parse ();if _ggfe !=nil {return nil ,_ggfe ;};_ggdb ,_ggfed :=_gc .GetDict (_ggf .MK );if _ggfed {_gdb ,_ :=_gc .GetDict (_ggf .BS );_bdfbd :=_cge .applyAppearanceCharacteristics (_ggdb ,_gdb ,nil );
if _bdfbd !=nil {return nil ,_bdfbd ;};};_gfcb :=_gc .MakeDict ();for _ ,_ddd :=range _abf .Opt .Elements (){if _ace ,_fgc :=_gc .GetArray (_ddd );_fgc &&_ace .Len ()==2{_ddd =_ace .Get (1);};var _eeb string ;if _cbcd ,_age :=_gc .GetString (_ddd );_age {_eeb =_cbcd .Decoded ();
}else if _gfec ,_faea :=_gc .GetName (_ddd );_faea {_eeb =_gfec .String ();}else {_a .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",_ddd );
return nil ,_fd .New ("\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u002f\u0073t\u0072\u0069\u006e\u0067");};if len (_eeb )> 0{_dfgb ,_fgad :=_gcfd (_abf .PdfField ,_fgg ,_gfb ,_eeb ,_cge ,_fca ,_dabb .DR ,_ggdb );if _fgad !=nil {return nil ,_fgad ;
};_gfcb .Set (*_gc .MakeName (_eeb ),_dfgb .ToPdfObject ());};};_gccg :=_gc .MakeDict ();_gccg .Set ("\u004e",_gfcb );return _gccg ,nil ;};

// CreateRectangleAnnotation creates a rectangle annotation object that can be added to page PDF annotations.
func CreateRectangleAnnotation (rectDef RectangleAnnotationDef )(*_fdg .PdfAnnotation ,error ){_bcdfe :=_fdg .NewPdfAnnotationSquare ();if rectDef .BorderEnabled {_afb ,_fgce ,_cfabg :=rectDef .BorderColor .R (),rectDef .BorderColor .G (),rectDef .BorderColor .B ();
_bcdfe .C =_gc .MakeArrayFromFloats ([]float64 {_afb ,_fgce ,_cfabg });_gfeb :=_fdg .NewBorderStyle ();_gfeb .SetBorderWidth (rectDef .BorderWidth );_bcdfe .BS =_gfeb .ToPdfObject ();};if rectDef .FillEnabled {_gaeb ,_acaf ,_gbgb :=rectDef .FillColor .R (),rectDef .FillColor .G (),rectDef .FillColor .B ();
_bcdfe .IC =_gc .MakeArrayFromFloats ([]float64 {_gaeb ,_acaf ,_gbgb });}else {_bcdfe .IC =_gc .MakeArrayFromIntegers ([]int {});};if rectDef .Opacity < 1.0{_bcdfe .CA =_gc .MakeFloat (rectDef .Opacity );};_cbae ,_ggddd ,_dddbe :=_fcbb (rectDef );if _dddbe !=nil {return nil ,_dddbe ;
};_bcdfe .AP =_cbae ;_bcdfe .Rect =_gc .MakeArrayFromFloats ([]float64 {_ggddd .Llx ,_ggddd .Lly ,_ggddd .Urx ,_ggddd .Ury });return _bcdfe .PdfAnnotation ,nil ;};

// NewComboboxField generates a new combobox form field with partial name `name` at location `rect`
// on specified `page` and with field specific options `opt`.
func NewComboboxField (page *_fdg .PdfPage ,name string ,rect []float64 ,opt ComboboxFieldOptions )(*_fdg .PdfFieldChoice ,error ){if page ==nil {return nil ,_fd .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
};if len (name )<=0{return nil ,_fd .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 ,_fd .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
};_bgbg :=_fdg .NewPdfField ();_egfg :=&_fdg .PdfFieldChoice {};_bgbg .SetContext (_egfg );_egfg .PdfField =_bgbg ;_egfg .T =_gc .MakeString (name );_egfg .Opt =_gc .MakeArray ();for _ ,_cfdd :=range opt .Choices {_egfg .Opt .Append (_gc .MakeString (_cfdd ));
};_egfg .SetFlag (_fdg .FieldFlagCombo );_bde :=_fdg .NewPdfAnnotationWidget ();_bde .Rect =_gc .MakeArrayFromFloats (rect );_bde .P =page .ToPdfObject ();_bde .F =_gc .MakeInteger (4);_bde .Parent =_egfg .ToPdfObject ();_egfg .Annotations =append (_egfg .Annotations ,_bde );
return _egfg ,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 *_fdg .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_fdg .PdfColorDeviceRGB ;Opacity float64 ;};

// 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 *_fdg .PdfPage ,name string ,rect []float64 ,opt TextFieldOptions )(*_fdg .PdfFieldText ,error ){if page ==nil {return nil ,_fd .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");};
if len (name )<=0{return nil ,_fd .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 ,_fd .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
};_bdbd :=_fdg .NewPdfField ();_gadg :=&_fdg .PdfFieldText {};_bdbd .SetContext (_gadg );_gadg .PdfField =_bdbd ;_gadg .T =_gc .MakeString (name );if opt .MaxLen > 0{_gadg .MaxLen =_gc .MakeInteger (int64 (opt .MaxLen ));};if len (opt .Value )> 0{_gadg .V =_gc .MakeString (opt .Value );
};if opt .TextColor !=""{_adg :=_e .ColorRGBFromHex (opt .TextColor );_gedc ,_dddd ,_ebcb :=_adg .ToRGB ();_bef :=12;if opt .FontSize > 0{_bef =opt .FontSize ;};_gbaa :="\u0048e\u006c\u0076\u0065\u0074\u0069\u0063a";if opt .FontName !=""{_gbaa =opt .FontName ;
};_ada :=_cb .Sprintf ("/\u0025\u0073\u0020\u0025\u0064\u0020T\u0066\u0020\u0025\u002e\u0033\u0066\u0020\u0025\u002e3\u0066\u0020\u0025.\u0033f\u0020\u0072\u0067",_gbaa ,_bef ,_gedc ,_dddd ,_ebcb );_gadg .DA =_gc .MakeString (_ada );};_bdbd .SetContext (_gadg );
_edcd :=_fdg .NewPdfAnnotationWidget ();_edcd .Rect =_gc .MakeArrayFromFloats (rect );_edcd .P =page .ToPdfObject ();_edcd .F =_gc .MakeInteger (4);_edcd .Parent =_gadg .ToPdfObject ();_gadg .Annotations =append (_gadg .Annotations ,_edcd );return _gadg ,nil ;
};const (SignatureImageLeft SignatureImagePosition =iota ;SignatureImageRight ;SignatureImageTop ;SignatureImageBottom ;);func _cgca (_abgg []float64 )[]float64 {var (_cdaac =len (_abgg );_bcc =make ([]float64 ,_cdaac );_gec =make ([]float64 ,_cdaac );
);_cgga :=2.0;_bcc [0]=_abgg [0]/_cgga ;for _fbbg :=1;_fbbg < _cdaac ;_fbbg ++{_gec [_fbbg ]=1/_cgga ;if _fbbg < _cdaac -1{_cgga =4.0;}else {_cgga =3.5;};_cgga -=_gec [_fbbg ];_bcc [_fbbg ]=(_abgg [_fbbg ]-_bcc [_fbbg -1])/_cgga ;};for _bfc :=1;_bfc < _cdaac ;
_bfc ++{_bcc [_cdaac -_bfc -1]-=_gec [_cdaac -_bfc ]*_bcc [_cdaac -_bfc ];};return _bcc ;};func _gd (_afg *_fdg .PdfFieldText ,_ggd _fdg .PdfColor )(*_gc .PdfObjectString ,error ){_bad :=_fa .ContentStreamOperations {};_dd :=_dfed (_afg .PdfField );_acce ,_cdd :=_fa .NewContentStreamParser (_dd ).Parse ();
if _cdd !=nil {return nil ,_cdd ;};for _ ,_efe :=range *_acce {if _efe .Operand =="\u0067"||_efe .Operand =="\u0072\u0067"{continue ;};_bad =append (_bad ,_efe );};_bed ,_dgd :=_ggd .(*_fdg .PdfColorDeviceRGB );if !_dgd {return nil ,_cdd ;};_dda ,_bedc ,_abbf :=_gc .MakeFloat (_bed [0]),_gc .MakeFloat (_bed [1]),_gc .MakeFloat (_bed [2]);
_abc :=&_fa .ContentStreamOperation {Params :[]_gc .PdfObject {_dda ,_bedc ,_abbf },Operand :"\u0072\u0067"};_bad =append (_bad ,_abc );_ecdg :=_bad .String ();_ecdg =_ae .ReplaceAll (_ecdg ,"\u000a","\u0020");_ecdg =_ae .Trim (_ecdg ,"\u0020");return _gc .MakeHexString (_ecdg ),nil ;
};func _cbef (_bdgff *_fdg .PdfFieldButton ,_ccgg *_fdg .PdfAnnotationWidget ,_bbfef AppearanceStyle )(*_gc .PdfObjectDictionary ,error ){_bedcc ,_deaab :=_gc .GetArray (_ccgg .Rect );if !_deaab {return nil ,_fd .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");
};_ecbd ,_daedg :=_fdg .NewPdfRectangle (*_bedcc );if _daedg !=nil {return nil ,_daedg ;};_bbab ,_eece :=_ecbd .Width (),_ecbd .Height ();_eddd :=_fa .NewContentCreator ();if _bbfef .BorderSize > 0{_eaaf (_eddd ,_bbfef ,_bbab ,_eece );};if _bbfef .DrawAlignmentReticle {_fcdd :=_bbfef ;
_fcdd .BorderSize =0.2;_efeb (_eddd ,_fcdd ,_bbab ,_eece );};_adfe :=_bdgff .GetFillImage ();_abecb ,_daedg :=_aee (_bbab ,_eece ,_adfe ,_bbfef );if _daedg !=nil {return nil ,_daedg ;};_agff ,_bcdf :=_gc .GetDict (_ccgg .MK );if _bcdf {_agff .Set ("\u006c",_abecb .ToPdfObject ());
};_aae :=_gc .MakeDict ();_aae .Set ("\u0046\u0052\u004d",_abecb .ToPdfObject ());_gdc :=_fdg .NewPdfPageResources ();_gdc .ProcSet =_gc .MakeArray (_gc .MakeName ("\u0050\u0044\u0046"));_gdc .XObject =_aae ;_gcdb :=_bbab -2;_dddda :=_eece -2;_eddd .Add_q ();
_eddd .Add_re (1,1,_gcdb ,_dddda );_eddd .Add_W ();_eddd .Add_n ();_gcdb -=2;_dddda -=2;_eddd .Add_q ();_eddd .Add_re (2,2,_gcdb ,_dddda );_eddd .Add_W ();_eddd .Add_n ();_efcg :=_c .Min (_gcdb /float64 (_adfe .Width ),_dddda /float64 (_adfe .Height ));
_eddd .Add_cm (_efcg ,0,0,_efcg ,(_bbab /2)-(float64 (_adfe .Width )*_efcg /2)+2,2);_eddd .Add_Do ("\u0046\u0052\u004d");_eddd .Add_Q ();_eddd .Add_Q ();_gcge :=_fdg .NewXObjectForm ();_gcge .FormType =_gc .MakeInteger (1);_gcge .Resources =_gdc ;_gcge .BBox =_gc .MakeArrayFromFloats ([]float64 {0,0,_bbab ,_eece });
_gcge .Matrix =_gc .MakeArrayFromFloats ([]float64 {1.0,0.0,0.0,1.0,0.0,0.0});_gcge .SetContentStream (_eddd .Bytes (),_bdggc ());_bfda :=_gc .MakeDict ();_bfda .Set ("\u004e",_gcge .ToPdfObject ());return _bfda ,nil ;};func _aee (_ ,_ float64 ,_fbgd *_fdg .Image ,_ AppearanceStyle )(*_fdg .XObjectForm ,error ){_cbab ,_edebe :=_fdg .NewXObjectImageFromImage (_fbgd ,nil ,_gc .NewFlateEncoder ());
if _edebe !=nil {return nil ,_edebe ;};_cbab .Decode =_gc .MakeArrayFromFloats ([]float64 {0.0,1.0,0.0,1.0,0.0,1.0});_fggb :=_fdg .NewPdfPageResources ();_fggb .ProcSet =_gc .MakeArray (_gc .MakeName ("\u0050\u0044\u0046"),_gc .MakeName ("\u0049\u006d\u0061\u0067\u0065\u0043"));
_fggb .SetXObjectImageByName (_gc .PdfObjectName ("\u0049\u006d\u0030"),_cbab );_ebac :=_fa .NewContentCreator ();_ebac .Add_q ();_ebac .Add_cm (float64 (_fbgd .Width ),0,0,float64 (_fbgd .Height ),0,0);_ebac .Add_Do ("\u0049\u006d\u0030");_ebac .Add_Q ();
_ceac :=_fdg .NewXObjectForm ();_ceac .FormType =_gc .MakeInteger (1);_ceac .BBox =_gc .MakeArrayFromFloats ([]float64 {0,0,float64 (_fbgd .Width ),float64 (_fbgd .Height )});_ceac .Resources =_fggb ;_ceac .SetContentStream (_ebac .Bytes (),_bdggc ());
return _ceac ,nil ;};

// NewImageField generates a new image field with partial name `name` at location `rect`
// on specified `page` and with field specific options `opt`.
func NewImageField (page *_fdg .PdfPage ,name string ,rect []float64 ,opt ImageFieldOptions )(*_fdg .PdfFieldButton ,error ){if page ==nil {return nil ,_fd .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
};if len (name )<=0{return nil ,_fd .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 ,_fd .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
};_bede :=_fdg .NewPdfField ();_eebb :=&_fdg .PdfFieldButton {};_eebb .PdfField =_bede ;_bede .SetContext (_eebb );_eebb .SetType (_fdg .ButtonTypePush );_eebb .T =_gc .MakeString (name );_eefa :=_fdg .NewPdfAnnotationWidget ();_eefa .Rect =_gc .MakeArrayFromFloats (rect );
_eefa .P =page .ToPdfObject ();_eefa .F =_gc .MakeInteger (4);_eefa .Parent =_eebb .ToPdfObject ();_acabd :=rect [2]-rect [0];_gaba :=rect [3]-rect [1];_dbag :=opt ._cfb ;_deeg :=_fa .NewContentCreator ();if _dbag .BorderSize > 0{_eaaf (_deeg ,_dbag ,_acabd ,_gaba );
};if _dbag .DrawAlignmentReticle {_dbda :=_dbag ;_dbda .BorderSize =0.2;_efeb (_deeg ,_dbda ,_acabd ,_gaba );};_bge ,_dcbfe :=_aee (_acabd ,_gaba ,opt .Image ,_dbag );if _dcbfe !=nil {return nil ,_dcbfe ;};_bcaa ,_dfag :=_gc .GetDict (_eefa .MK );if _dfag {_bcaa .Set ("\u006c",_bge .ToPdfObject ());
};_bba :=_gc .MakeDict ();_bba .Set ("\u0046\u0052\u004d",_bge .ToPdfObject ());_adcd :=_fdg .NewPdfPageResources ();_adcd .ProcSet =_gc .MakeArray (_gc .MakeName ("\u0050\u0044\u0046"));_adcd .XObject =_bba ;_deab :=_acabd -2;_aea :=_gaba -2;_deeg .Add_q ();
_deeg .Add_re (1,1,_deab ,_aea );_deeg .Add_W ();_deeg .Add_n ();_deab -=2;_aea -=2;_deeg .Add_q ();_deeg .Add_re (2,2,_deab ,_aea );_deeg .Add_W ();_deeg .Add_n ();_dbge :=_c .Min (_deab /float64 (opt .Image .Width ),_aea /float64 (opt .Image .Height ));
_deeg .Add_cm (_dbge ,0,0,_dbge ,(_acabd /2)-(float64 (opt .Image .Width )*_dbge /2)+2,2);_deeg .Add_Do ("\u0046\u0052\u004d");_deeg .Add_Q ();_deeg .Add_Q ();_efdd :=_fdg .NewXObjectForm ();_efdd .FormType =_gc .MakeInteger (1);_efdd .Resources =_adcd ;
_efdd .BBox =_gc .MakeArrayFromFloats ([]float64 {0,0,_acabd ,_gaba });_efdd .Matrix =_gc .MakeArrayFromFloats ([]float64 {1.0,0.0,0.0,1.0,0.0,0.0});_efdd .SetContentStream (_deeg .Bytes (),_bdggc ());_fdgg :=_gc .MakeDict ();_fdgg .Set ("\u004e",_efdd .ToPdfObject ());
_eefa .AP =_fdgg ;_eebb .Annotations =append (_eebb .Annotations ,_eefa );return _eebb ,nil ;};func _dfed (_dfcg *_fdg .PdfField )string {if _dfcg ==nil {return "";};_fbfc ,_fdb :=_dfcg .GetContext ().(*_fdg .PdfFieldText );if !_fdb {return _dfed (_dfcg .Parent );
};if _fbfc .DA !=nil {return _fbfc .DA .Str ();};return _dfed (_fbfc .Parent );};func (_aed *AppearanceFont )fillName (){if _aed .Font ==nil ||_aed .Name !=""{return ;};_bfb :=_aed .Font .FontDescriptor ();if _bfb ==nil ||_bfb .FontName ==nil {return ;
};_aed .Name =_bfb .FontName .String ();};func _cadg (_gcaf LineAnnotationDef ,_gaef string )([]byte ,*_fdg .PdfRectangle ,*_fdg .PdfRectangle ,error ){_daecc :=_ff .Line {X1 :0,Y1 :0,X2 :_gcaf .X2 -_gcaf .X1 ,Y2 :_gcaf .Y2 -_gcaf .Y1 ,LineColor :_gcaf .LineColor ,Opacity :_gcaf .Opacity ,LineWidth :_gcaf .LineWidth ,LineEndingStyle1 :_gcaf .LineEndingStyle1 ,LineEndingStyle2 :_gcaf .LineEndingStyle2 };
_cgcf ,_ddbd ,_edcb :=_daecc .Draw (_gaef );if _edcb !=nil {return nil ,nil ,nil ,_edcb ;};_egdg :=&_fdg .PdfRectangle {};_egdg .Llx =_gcaf .X1 +_ddbd .Llx ;_egdg .Lly =_gcaf .Y1 +_ddbd .Lly ;_egdg .Urx =_gcaf .X1 +_ddbd .Urx ;_egdg .Ury =_gcaf .Y1 +_ddbd .Ury ;
return _cgcf ,_ddbd ,_egdg ,nil ;};func _babb (_aggg *InkAnnotationDef )(*_gc .PdfObjectDictionary ,*_fdg .PdfRectangle ,error ){_cafe :=_fdg .NewXObjectForm ();_cfba ,_acef ,_bcageg :=_ggfg (_aggg );if _bcageg !=nil {return nil ,nil ,_bcageg ;};_bcageg =_cafe .SetContentStream (_cfba ,nil );
if _bcageg !=nil {return nil ,nil ,_bcageg ;};_cafe .BBox =_acef .ToPdfObject ();_cafe .Resources =_fdg .NewPdfPageResources ();_cafe .Resources .ProcSet =_gc .MakeArray (_gc .MakeName ("\u0050\u0044\u0046"));_ddbg :=_gc .MakeDict ();_ddbg .Set ("\u004e",_cafe .ToPdfObject ());
return _ddbg ,_acef ,nil ;};const (_acea =1;_ecgga =2;_egeg =4;_dbcc =8;_geff =16;_ccec =32;_bfbe =64;_egc =128;_dbbc =256;_ebfc =512;_dbbg =1024;_dbf =2048;_faed =4096;);

// 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 _agbe (_edeb _eg .Image ,_edde string ,_gfga *SignatureFieldOpts ,_eddgf []float64 ,_cdgb *_fa .ContentCreator )(*_gc .PdfObjectName ,*_fdg .XObjectImage ,error ){_ggag ,_ddgg :=_fdg .DefaultImageHandler {}.NewImageFromGoImage (_edeb );
if _ddgg !=nil {return nil ,nil ,_ddgg ;};_cgce ,_ddgg :=_fdg .NewXObjectImageFromImage (_ggag ,nil ,_gfga .Encoder );if _ddgg !=nil {return nil ,nil ,_ddgg ;};_agg ,_acee :=float64 (*_cgce .Width ),float64 (*_cgce .Height );_cgf :=_eddgf [2]-_eddgf [0];
_bgdbg :=_eddgf [3]-_eddgf [1];if _gfga .AutoSize {_fba :=_c .Min (_cgf /_agg ,_bgdbg /_acee );_agg *=_fba ;_acee *=_fba ;_eddgf [0]=_eddgf [0]+(_cgf /2)-(_agg /2);_eddgf [1]=_eddgf [1]+(_bgdbg /2)-(_acee /2);};var _gdef *_gc .PdfObjectName ;if _cgd ,_dabf :=_gc .GetName (_cgce .Name );
_dabf {_gdef =_cgd ;}else {_gdef =_gc .MakeName (_edde );};if _cdgb !=nil {_cdgb .Add_q ().Translate (_eddgf [0],_eddgf [1]).Scale (_agg ,_acee ).Add_Do (*_gdef ).Add_Q ();}else {return nil ,nil ,_fd .New ("\u0043\u006f\u006e\u0074en\u0074\u0043\u0072\u0065\u0061\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u0075l\u006c");
};return _gdef ,_cgce ,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 *_fdg .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 _fdg .PdfColor ;

// FillColor represents the background color of the appearance annotation area.
FillColor _fdg .PdfColor ;

// FillOpacity sets the opacity of the background of the appearance annotation area.
// Range is 0.0 - 1.0. Default is 1.0, opaque.
FillOpacity float64 ;

// BorderSize represents border size of the appearance annotation area.
BorderSize float64 ;

// BorderColor represents the border color of the appearance annotation area.
BorderColor _fdg .PdfColor ;

// WatermarkImage specifies the image used as a watermark that will be rendered
// behind the signature.
WatermarkImage _eg .Image ;

// Image represents the image used for the signature appearance.
Image _eg .Image ;

// Encoder specifies the image encoder used for image signature. Defaults to flate encoder.
Encoder _gc .StreamEncoder ;

// ImagePosition specifies the image location relative to the text signature.
ImagePosition SignatureImagePosition ;};

// 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 *_fdg .PdfFont ;

// Size represents the size of the font used for the field appearance.
// If the font size is 0, the value of the FallbackSize field of the
// AppearanceFontStyle is used, if set. Otherwise, the font size is
// calculated based on the available annotation height and on the
// AutoFontSizeFraction field of the AppearanceStyle.
Size float64 ;};

// 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 };};

// 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 *_fdg .PdfPage ,name string ,rect []float64 ,opt CheckboxFieldOptions )(*_fdg .PdfFieldButton ,error ){if page ==nil {return nil ,_fd .New ("\u0070a\u0067e\u0020\u006e\u006f\u0074\u0020s\u0070\u0065c\u0069\u0066\u0069\u0065\u0064");
};if len (name )<=0{return nil ,_fd .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 ,_fd .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006e\u0067\u0065");
};_bfdc ,_ddgf :=_fdg .NewStandard14Font (_fdg .ZapfDingbatsName );if _ddgf !=nil {return nil ,_ddgf ;};_gfdd :=_fdg .NewPdfField ();_daed :=&_fdg .PdfFieldButton {};_gfdd .SetContext (_daed );_daed .PdfField =_gfdd ;_daed .T =_gc .MakeString (name );_daed .SetType (_fdg .ButtonTypeCheckbox );
_cff :="\u004f\u0066\u0066";if opt .Checked {_cff ="\u0059\u0065\u0073";};_daed .V =_gc .MakeName (_cff );_fgdg :=_fdg .NewPdfAnnotationWidget ();_fgdg .Rect =_gc .MakeArrayFromFloats (rect );_fgdg .P =page .ToPdfObject ();_fgdg .F =_gc .MakeInteger (4);
_fgdg .Parent =_daed .ToPdfObject ();_cgbf :=rect [2]-rect [0];_ggaf :=rect [3]-rect [1];var _dacee _b .Buffer ;_dacee .WriteString ("\u0071\u000a");_dacee .WriteString ("\u0030 \u0030\u0020\u0031\u0020\u0072\u0067\n");_dacee .WriteString ("\u0042\u0054\u000a");
_dacee .WriteString ("\u002f\u005a\u0061D\u0062\u0020\u0031\u0032\u0020\u0054\u0066\u000a");_dacee .WriteString ("\u0045\u0054\u000a");_dacee .WriteString ("\u0051\u000a");_bce :=_fa .NewContentCreator ();_bce .Add_q ();_bce .Add_rg (0,0,1);_bce .Add_BT ();
_bce .Add_Tf (*_gc .MakeName ("\u005a\u0061\u0044\u0062"),12);_bce .Add_Td (0,0);_bce .Add_ET ();_bce .Add_Q ();_cfe :=_fdg .NewXObjectForm ();_cfe .SetContentStream (_bce .Bytes (),_gc .NewRawEncoder ());_cfe .BBox =_gc .MakeArrayFromFloats ([]float64 {0,0,_cgbf ,_ggaf });
_cfe .Resources =_fdg .NewPdfPageResources ();_cfe .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_bfdc .ToPdfObject ());_bce =_fa .NewContentCreator ();_bce .Add_q ();_bce .Add_re (0,0,_cgbf ,_ggaf );_bce .Add_W ().Add_n ();_bce .Add_rg (0,0,1);
_bce .Translate (0,3.0);_bce .Add_BT ();_bce .Add_Tf (*_gc .MakeName ("\u005a\u0061\u0044\u0062"),12);_bce .Add_Td (0,0);_bce .Add_Tj (*_gc .MakeString ("\u0034"));_bce .Add_ET ();_bce .Add_Q ();_gbabe :=_fdg .NewXObjectForm ();_gbabe .SetContentStream (_bce .Bytes (),_gc .NewRawEncoder ());
_gbabe .BBox =_gc .MakeArrayFromFloats ([]float64 {0,0,_cgbf ,_ggaf });_gbabe .Resources =_fdg .NewPdfPageResources ();_gbabe .Resources .SetFontByName ("\u005a\u0061\u0044\u0062",_bfdc .ToPdfObject ());_abec :=_gc .MakeDict ();_abec .Set ("\u004f\u0066\u0066",_cfe .ToPdfObject ());
_abec .Set ("\u0059\u0065\u0073",_gbabe .ToPdfObject ());_dcg :=_gc .MakeDict ();_dcg .Set ("\u004e",_abec );_fgdg .AP =_dcg ;_fgdg .AS =_gc .MakeName (_cff );_daed .Annotations =append (_daed .Annotations ,_fgdg );return _daed ,nil ;};func _accef (_baa *_fdg .PdfAnnotationWidget ,_cbc *_fdg .PdfFieldText ,_eec *_fdg .PdfPageResources ,_dfb AppearanceStyle )(*_gc .PdfObjectDictionary ,error ){_adf :=_fdg .NewPdfPageResources ();
_dad ,_bcg :=_gc .GetArray (_baa .Rect );if !_bcg {return nil ,_fd .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0052\u0065\u0063\u0074");};_bbe ,_dga :=_fdg .NewPdfRectangle (*_dad );if _dga !=nil {return nil ,_dga ;};_fede ,_afc :=_bbe .Width (),_bbe .Height ();
_eacf ,_gae :=_fede ,_afc ;_gb :=true ;_fec :=_fdg .NewXObjectForm ();_fec .BBox =_gc .MakeArrayFromFloats ([]float64 {0,0,_eacf ,_gae });if _baa .AP !=nil {if _accf ,_gfc :=_gc .GetDict (_baa .AP );_gfc &&_accf !=nil {_abbd :=_gc .TraceToDirectObject (_accf .Get ("\u004e"));
switch _gac :=_abbd .(type ){case *_gc .PdfObjectStream :_faf ,_ffb :=_gc .DecodeStream (_gac );if _ffb !=nil {_a .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u0020\u0075\u006e\u0061\u0062\u006c\u0065\u0020\u0064\u0065\u0063\u006f\u0064\u0065\u0020\u0063\u006f\u006e\u0074e\u006e\u0074\u0020\u0073\u0074r\u0065\u0061m\u003a\u0020\u0025\u0076",_ffb .Error ());
break ;};_afcf ,_ffb :=_fa .NewContentStreamParser (string (_faf )).Parse ();if _ffb !=nil {_a .Log .Debug ("\u0045\u0052R\u004f\u0052\u0020\u0075n\u0061\u0062l\u0065\u0020\u0070\u0061\u0072\u0073\u0065\u0020c\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0073\u0074\u0072\u0065\u0061m\u003a\u0020\u0025\u0076",_ffb .Error ());
break ;};_dag :=_fa .NewContentStreamProcessor (*_afcf );_dag .AddHandler (_fa .HandlerConditionEnumAllOperands ,"",func (_deb *_fa .ContentStreamOperation ,_cc _fa .GraphicsState ,_dfbg *_fdg .PdfPageResources )error {if _deb .Operand =="\u0054\u006a"||_deb .Operand =="\u0054\u004a"{if len (_deb .Params )==1{if _eaba ,_dfge :=_gc .GetString (_deb .Params [0]);
_dfge {_gb =_ae .TrimSpace (_eaba .Str ())=="";};return _fa .ErrEarlyExit ;};return nil ;};return nil ;});_dag .Process (_adf );if !_gb {if _aedf ,_gde :=_gc .GetDict (_gac .Get ("\u0052e\u0073\u006f\u0075\u0072\u0063\u0065s"));_gde {_adf ,_ffb =_fdg .NewPdfPageResourcesFromDict (_aedf );
if _ffb !=nil {return nil ,_ffb ;};};if _def ,_fff :=_gc .GetArray (_gac .Get ("\u004d\u0061\u0074\u0072\u0069\u0078"));_fff {_fec .Matrix =_def ;};_fec .SetContentStream (_faf ,_bdggc ());};};};};if _gb {_bea ,_dde :=_gc .GetDict (_baa .MK );if _dde {_eace ,_ :=_gc .GetDict (_baa .BS );
_dea :=_dfb .applyAppearanceCharacteristics (_bea ,_eace ,nil );if _dea !=nil {return nil ,_dea ;};};_ggdd ,_dbb :=_fa .NewContentStreamParser (_dfed (_cbc .PdfField )).Parse ();if _dbb !=nil {return nil ,_dbb ;};_aab :=_fa .NewContentCreator ();if _dfb .BorderSize > 0{_eaaf (_aab ,_dfb ,_fede ,_afc );
};if _dfb .DrawAlignmentReticle {_efd :=_dfb ;_efd .BorderSize =0.2;_efeb (_aab ,_efd ,_fede ,_afc );};_aab .Add_BMC ("\u0054\u0078");_aab .Add_q ();_fede ,_afc =_dfb .applyRotation (_bea ,_fede ,_afc ,_aab );_aab .Add_BT ();_efef ,_bcag ,_dbb :=_dfb .processDA (_cbc .PdfField ,_ggdd ,_eec ,_adf ,_aab );
if _dbb !=nil {return nil ,_dbb ;};_dagd :=_efef .Font ;_bcae :=_efef .Size ;_cce :=_gc .MakeName (_efef .Name );if _cbc .Flags ().Has (_fdg .FieldFlagMultiline )&&_cbc .MaxLen !=nil {_a .Log .Debug ("\u004c\u006f\u006f\u006b\u0020\u0066\u006f\u0072\u0020\u0041\u0050\u0020\u0064\u0069\u0063\u0074\u0069\u006fn\u0061\u0072\u0079\u0020\u0066\u006f\u0072 \u004e\u0020\u006f\u0062\u006a\u0065\u0063\u0074\u0020\u0063\u006fn\u0074\u0065\u006e\u0074\u0020\u0073\u0074\u0072\u0065\u0061\u006d");
if _fcb ,_gca ,_gcf :=_bfac (_baa .AP ,_eec );_gcf {_cce =_fcb ;_bcae =_gca ;_bcag =true ;};};_dff :=_bcae ==0;if _dff &&_bcag {_bcae =_afc *_dfb .AutoFontSizeFraction ;};_cdg :=_dagd .Encoder ();if _cdg ==nil {_a .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");
_cdg =_ac .NewIdentityTextEncoder ("\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079\u002d\u0048");};_addd ,_dbb :=_dagd .GetFontDescriptor ();if _dbb !=nil {_a .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 _cf string ;if _egbg ,_bfd :=_gc .GetString (_cbc .V );_bfd {_cf =_egbg .Decoded ();};if len (_cf )==0{return nil ,nil ;};_cf =_ddgda (_cf );_fdd :=[]string {_cf };_abd :=false ;if _cbc .Flags ().Has (_fdg .FieldFlagMultiline ){_abd =true ;_cf =_ae .ReplaceAll (_cf ,"\u000d\u000a","\u000a");
_cf =_ae .ReplaceAll (_cf ,"\u000d","\u000a");_fdd =_ae .Split (_cf ,"\u000a");};_bgd :=make ([]string ,len (_fdd ));copy (_bgd ,_fdd );_dgc :=_dfb .MultilineLineHeight ;_fcfg :=0.0;_bbf :=0;if _cdg !=nil {for _bcae >=0{_cdde :=make ([]string ,len (_fdd ));
copy (_cdde ,_fdd );_gee :=make ([]string ,len (_bgd ));copy (_gee ,_bgd );_fcfg =0.0;_bbf =0;_aaf :=len (_cdde );_ecb :=0;for _ecb < _aaf {var _dae float64 ;_ffd :=-1;_gaa :=_bd ;if _dfb .MarginLeft !=nil {_gaa =*_dfb .MarginLeft ;};for _dbd ,_dca :=range _cdde [_ecb ]{if _dca ==' '{_ffd =_dbd ;
};_cfa ,_gbd :=_dagd .GetRuneMetrics (_dca );if !_gbd {_a .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",_dca );
continue ;};_dae =_gaa ;_gaa +=_cfa .Wx ;if _abd &&!_dff &&_bcae *_gaa /1000.0> _fede {_beg :=_dbd ;_abdc :=_dbd ;if _ffd > 0{_beg =_ffd +1;_abdc =_ffd ;};_gag :=_cdde [_ecb ][_beg :];_gba :=_gee [_ecb ][_beg :];if _ecb < len (_cdde )-1{_cdde =append (_cdde [:_ecb +1],_cdde [_ecb :]...);
_cdde [_ecb +1]=_gag ;_gee =append (_gee [:_ecb +1],_gee [_ecb :]...);_gee [_ecb +1]=_gba ;}else {_cdde =append (_cdde ,_gag );_gee =append (_gee ,_gba );};_cdde [_ecb ]=_cdde [_ecb ][0:_abdc ];_gee [_ecb ]=_gee [_ecb ][0:_abdc ];_aaf ++;_gaa =_dae ;break ;
};};if _gaa > _fcfg {_fcfg =_gaa ;};_cdde [_ecb ]=string (_cdg .Encode (_cdde [_ecb ]));if len (_cdde [_ecb ])> 0{_bbf ++;};_ecb ++;};_cfc :=_bcae ;if _bbf > 1{_cfc *=_dgc ;};_adc :=float64 (_bbf )*_cfc ;if _dff ||_adc <=_afc {_fdd =_cdde ;_bgd =_gee ;
break ;};_bcae --;};};_gcaa :=_bd ;if _dfb .MarginLeft !=nil {_gcaa =*_dfb .MarginLeft ;};if _bcae ==0||_dff &&_fcfg > 0&&_gcaa +_fcfg *_bcae /1000.0> _fede {_bcae =0.95*1000.0*(_fede -_gcaa )/_fcfg ;};_fcc :=_fgb ;{if _cae ,_aede :=_gc .GetIntVal (_cbc .Q );
_aede {switch _cae {case 0:_fcc =_fgb ;case 1:_fcc =_df ;case 2:_fcc =_dfg ;default:_a .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",_cae );
};};};_aeb :=_bcae ;if _abd &&_bbf > 1{_aeb =_dgc *_bcae ;};var _cbf float64 ;if _addd !=nil {_cbf ,_dbb =_addd .GetCapHeight ();if _dbb !=nil {_a .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",_dbb );
};};if int (_cbf )<=0{_a .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");
_cbf =1000;};_eecb :=_cbf /1000.0*_bcae ;_gfd :=0.0;{_adb :=float64 (_bbf )*_aeb ;if _dff &&_gfd +_adb > _afc {_bcae =0.95*(_afc -_gfd )/float64 (_bbf );_aeb =_bcae ;if _abd &&_bbf > 1{_aeb =_dgc *_bcae ;};_eecb =_cbf /1000.0*_bcae ;_adb =float64 (_bbf )*_aeb ;
};if _afc > _adb {if _abd {if _dfb .MultilineVAlignMiddle {_ebd :=(_afc -(_adb +_eecb ))/2.0;_fee :=_ebd +_adb +_eecb -_aeb ;_gfd =_fee ;if _bbf > 1{_gfd =_gfd +(_adb /_bcae *float64 (_bbf ))-_aeb -_eecb ;};if _gfd < _adb {_gfd =(_afc -_eecb )/2.0;};}else {_gfd =_afc -_aeb ;
if _gfd > _bcae {_adfa :=0.0;if _abd &&_dfb .MultilineLineHeight > 1&&_bbf > 1{_adfa =_dfb .MultilineLineHeight -1;};_gfd -=_bcae *(0.5-_adfa );};};}else {_gfd =(_afc -_eecb )/2.0;};};};if _dfb .TextColor !=nil {_cbg :=_dfb .TextColor ;_ddg ,_gacg :=_cbg .(*_fdg .PdfColorDeviceRGB );
if !_gacg {_ddg =_fdg .NewPdfColorDeviceRGB (0,0,0);};_aab .Add_rg (_ddg .R (),_ddg .G (),_ddg .B ());}else {for _ ,_feb :=range *_ggdd {if _feb .Operand =="\u0072\u0067"||_feb .Operand =="\u0067"{_aab .AddOperand (*_feb );};};};_aab .Add_Tf (*_cce ,_bcae );
_aab .Add_Td (_gcaa ,_gfd );_dab :=_gcaa ;_ddae :=_gcaa ;for _eba ,_cef :=range _fdd {_faa :=0.0;for _ ,_dfe :=range _bgd [_eba ]{_deaa ,_fce :=_dagd .GetRuneMetrics (_dfe );if !_fce {continue ;};_faa +=_deaa .Wx ;};_eae :=_faa /1000.0*_bcae ;_egf :=_fede -_eae ;
var _efdf float64 ;switch _fcc {case _fgb :_efdf =_dab ;case _df :_efdf =_egf /2;case _dfg :_efdf =_egf ;};_gcaa =_efdf -_ddae ;if _gcaa > 0.0{_aab .Add_Td (_gcaa ,0);};_ddae =_efdf ;_aab .Add_Tj (*_gc .MakeString (_cef ));if _eba < len (_fdd )-1{_aab .Add_Td (0,-_bcae *_dgc );
};};_aab .Add_ET ();_aab .Add_Q ();_aab .Add_EMC ();_fec .SetContentStream (_aab .Bytes (),_bdggc ());};_fec .Resources =_adf ;_ddb :=_gc .MakeDict ();_ddb .Set ("\u004e",_fec .ToPdfObject ());return _ddb ,nil ;};func _ddgda (_bcab string )string {if len (_bcab )==0{return _bcab ;
};_ecgg :=_gc .IsTextWriteDirectionLTR (_bcab );if !_ecgg {_eaef ,_eaefd :=_bc .ArabicShape (_bcab );if _eaefd !=nil {_a .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u0020\u0061\u0070\u0070\u006c\u0079\u0069\u006e\u0067\u0020\u0041\u0072\u0061\u0062\u0069\u0063\u0020\u0074\u0065x\u0074\u0020\u0073\u0068\u0061p\u0069\u006eg\u003a\u0020\u0025\u0076",_eaefd .Error ());
return _bcab ;};return _gc .FormatWriteDirectionLTR (_eaef ,false );};return _bcab ;};