@@ -265,21 +265,17 @@ class AnnotationFactory {
265
265
promises . push (
266
266
FreeTextAnnotation . createNewAnnotation (
267
267
xref ,
268
- evaluator ,
269
- task ,
270
268
annotation ,
271
- baseFontRef ,
272
269
results ,
273
- dependencies
270
+ dependencies ,
271
+ { evaluator, task, baseFontRef }
274
272
)
275
273
) ;
276
274
break ;
277
275
case AnnotationEditorType . INK :
278
276
promises . push (
279
277
InkAnnotation . createNewAnnotation (
280
278
xref ,
281
- evaluator ,
282
- task ,
283
279
annotation ,
284
280
results ,
285
281
dependencies
@@ -306,11 +302,18 @@ class AnnotationFactory {
306
302
for ( const annotation of annotations ) {
307
303
switch ( annotation . annotationType ) {
308
304
case AnnotationEditorType . FREETEXT :
305
+ promises . push (
306
+ FreeTextAnnotation . createNewPrintAnnotation ( xref , annotation , {
307
+ evaluator,
308
+ task,
309
+ } )
310
+ ) ;
309
311
break ;
310
312
case AnnotationEditorType . INK :
311
313
promises . push (
312
- InkAnnotation . createNewPrintAnnotation ( annotation , xref )
314
+ InkAnnotation . createNewPrintAnnotation ( xref , annotation )
313
315
) ;
316
+ break ;
314
317
}
315
318
}
316
319
@@ -1356,6 +1359,44 @@ class MarkupAnnotation extends Annotation {
1356
1359
// so `this.appearance` is not pushed yet in the `Annotation` constructor.
1357
1360
this . _streams . push ( this . appearance , appearanceStream ) ;
1358
1361
}
1362
+
1363
+ static async createNewAnnotation (
1364
+ xref ,
1365
+ annotation ,
1366
+ results ,
1367
+ dependencies ,
1368
+ params
1369
+ ) {
1370
+ const annotationRef = xref . getNewRef ( ) ;
1371
+ const apRef = xref . getNewRef ( ) ;
1372
+ const annotationDict = this . createNewDict ( annotation , xref , { apRef } ) ;
1373
+ const ap = await this . createNewAppearanceStream ( annotation , xref , params ) ;
1374
+
1375
+ const buffer = [ ] ;
1376
+ let transform = xref . encrypt
1377
+ ? xref . encrypt . createCipherTransform ( apRef . num , apRef . gen )
1378
+ : null ;
1379
+ writeObject ( apRef , ap , buffer , transform ) ;
1380
+ dependencies . push ( { ref : apRef , data : buffer . join ( "" ) } ) ;
1381
+
1382
+ buffer . length = 0 ;
1383
+ transform = xref . encrypt
1384
+ ? xref . encrypt . createCipherTransform ( annotationRef . num , annotationRef . gen )
1385
+ : null ;
1386
+ writeObject ( annotationRef , annotationDict , buffer , transform ) ;
1387
+
1388
+ results . push ( { ref : annotationRef , data : buffer . join ( "" ) } ) ;
1389
+ }
1390
+
1391
+ static async createNewPrintAnnotation ( xref , annotation , params ) {
1392
+ const ap = await this . createNewAppearanceStream ( annotation , xref , params ) ;
1393
+ const annotationDict = this . createNewDict ( annotation , xref , { ap } ) ;
1394
+
1395
+ return new this . prototype . constructor ( {
1396
+ dict : annotationDict ,
1397
+ xref,
1398
+ } ) ;
1399
+ }
1359
1400
}
1360
1401
1361
1402
class WidgetAnnotation extends Annotation {
@@ -3157,17 +3198,8 @@ class FreeTextAnnotation extends MarkupAnnotation {
3157
3198
this . data . annotationType = AnnotationType . FREETEXT ;
3158
3199
}
3159
3200
3160
- static async createNewAnnotation (
3161
- xref ,
3162
- evaluator ,
3163
- task ,
3164
- annotation ,
3165
- baseFontRef ,
3166
- results ,
3167
- dependencies
3168
- ) {
3201
+ static createNewDict ( annotation , xref , { apRef, ap } ) {
3169
3202
const { color, fontSize, rect, user, value } = annotation ;
3170
- const freetextRef = xref . getNewRef ( ) ;
3171
3203
const freetext = new Dict ( xref ) ;
3172
3204
freetext . set ( "Type" , Name . get ( "Annot" ) ) ;
3173
3205
freetext . set ( "Subtype" , Name . get ( "FreeText" ) ) ;
@@ -3184,9 +3216,35 @@ class FreeTextAnnotation extends MarkupAnnotation {
3184
3216
freetext . set ( "T" , stringToUTF8String ( user ) ) ;
3185
3217
}
3186
3218
3219
+ const n = new Dict ( xref ) ;
3220
+ freetext . set ( "AP" , n ) ;
3221
+
3222
+ if ( apRef ) {
3223
+ n . set ( "N" , apRef ) ;
3224
+ } else {
3225
+ n . set ( "N" , ap ) ;
3226
+ }
3227
+
3228
+ return freetext ;
3229
+ }
3230
+
3231
+ static async createNewAppearanceStream ( annotation , xref , params ) {
3232
+ const { baseFontRef, evaluator, task } = params ;
3233
+ const { color, fontSize, rect, value } = annotation ;
3234
+
3187
3235
const resources = new Dict ( xref ) ;
3188
3236
const font = new Dict ( xref ) ;
3189
- font . set ( "Helv" , baseFontRef ) ;
3237
+
3238
+ if ( baseFontRef ) {
3239
+ font . set ( "Helv" , baseFontRef ) ;
3240
+ } else {
3241
+ const baseFont = new Dict ( xref ) ;
3242
+ baseFont . set ( "BaseFont" , Name . get ( "Helvetica" ) ) ;
3243
+ baseFont . set ( "Type" , Name . get ( "Font" ) ) ;
3244
+ baseFont . set ( "Subtype" , Name . get ( "Type1" ) ) ;
3245
+ baseFont . set ( "Encoding" , Name . get ( "WinAnsiEncoding" ) ) ;
3246
+ font . set ( "Helv" , baseFont ) ;
3247
+ }
3190
3248
resources . set ( "Font" , font ) ;
3191
3249
3192
3250
const helv = await WidgetAnnotation . _getFontData (
@@ -3260,25 +3318,7 @@ class FreeTextAnnotation extends MarkupAnnotation {
3260
3318
const ap = new StringStream ( appearance ) ;
3261
3319
ap . dict = appearanceStreamDict ;
3262
3320
3263
- buffer . length = 0 ;
3264
- const apRef = xref . getNewRef ( ) ;
3265
- let transform = xref . encrypt
3266
- ? xref . encrypt . createCipherTransform ( apRef . num , apRef . gen )
3267
- : null ;
3268
- writeObject ( apRef , ap , buffer , transform ) ;
3269
- dependencies . push ( { ref : apRef , data : buffer . join ( "" ) } ) ;
3270
-
3271
- const n = new Dict ( xref ) ;
3272
- n . set ( "N" , apRef ) ;
3273
- freetext . set ( "AP" , n ) ;
3274
-
3275
- buffer . length = 0 ;
3276
- transform = xref . encrypt
3277
- ? xref . encrypt . createCipherTransform ( freetextRef . num , freetextRef . gen )
3278
- : null ;
3279
- writeObject ( freetextRef , freetext , buffer , transform ) ;
3280
-
3281
- results . push ( { ref : freetextRef , data : buffer . join ( "" ) } ) ;
3321
+ return ap ;
3282
3322
}
3283
3323
}
3284
3324
@@ -3642,7 +3682,7 @@ class InkAnnotation extends MarkupAnnotation {
3642
3682
}
3643
3683
}
3644
3684
3645
- static createInkDict ( annotation , xref , { apRef, ap } ) {
3685
+ static createNewDict ( annotation , xref , { apRef, ap } ) {
3646
3686
const ink = new Dict ( xref ) ;
3647
3687
ink . set ( "Type" , Name . get ( "Annot" ) ) ;
3648
3688
ink . set ( "Subtype" , Name . get ( "Ink" ) ) ;
@@ -3668,7 +3708,7 @@ class InkAnnotation extends MarkupAnnotation {
3668
3708
return ink ;
3669
3709
}
3670
3710
3671
- static createNewAppearanceStream ( annotation , xref ) {
3711
+ static async createNewAppearanceStream ( annotation , xref , params ) {
3672
3712
const [ x1 , y1 , x2 , y2 ] = annotation . rect ;
3673
3713
const w = x2 - x1 ;
3674
3714
const h = y2 - y1 ;
@@ -3707,45 +3747,6 @@ class InkAnnotation extends MarkupAnnotation {
3707
3747
3708
3748
return ap ;
3709
3749
}
3710
-
3711
- static async createNewAnnotation (
3712
- xref ,
3713
- evaluator ,
3714
- task ,
3715
- annotation ,
3716
- results ,
3717
- others
3718
- ) {
3719
- const inkRef = xref . getNewRef ( ) ;
3720
- const apRef = xref . getNewRef ( ) ;
3721
- const ink = this . createInkDict ( annotation , xref , { apRef } ) ;
3722
- const ap = this . createNewAppearanceStream ( annotation , xref ) ;
3723
-
3724
- const buffer = [ ] ;
3725
- let transform = xref . encrypt
3726
- ? xref . encrypt . createCipherTransform ( apRef . num , apRef . gen )
3727
- : null ;
3728
- writeObject ( apRef , ap , buffer , transform ) ;
3729
- others . push ( { ref : apRef , data : buffer . join ( "" ) } ) ;
3730
-
3731
- buffer . length = 0 ;
3732
- transform = xref . encrypt
3733
- ? xref . encrypt . createCipherTransform ( inkRef . num , inkRef . gen )
3734
- : null ;
3735
- writeObject ( inkRef , ink , buffer , transform ) ;
3736
-
3737
- results . push ( { ref : inkRef , data : buffer . join ( "" ) } ) ;
3738
- }
3739
-
3740
- static async createNewPrintAnnotation ( annotation , xref ) {
3741
- const ap = this . createNewAppearanceStream ( annotation , xref ) ;
3742
- const ink = this . createInkDict ( annotation , xref , { ap } ) ;
3743
-
3744
- return new InkAnnotation ( {
3745
- dict : ink ,
3746
- xref,
3747
- } ) ;
3748
- }
3749
3750
}
3750
3751
3751
3752
class HighlightAnnotation extends MarkupAnnotation {
0 commit comments