@@ -428,7 +428,7 @@ class AnnotationFactory {
428
428
}
429
429
430
430
return {
431
- annotations : await Promise . all ( promises ) ,
431
+ annotations : ( await Promise . all ( promises ) ) . flat ( ) ,
432
432
} ;
433
433
}
434
434
@@ -1798,7 +1798,29 @@ class MarkupAnnotation extends Annotation {
1798
1798
data : annotationDict ,
1799
1799
} ) ;
1800
1800
1801
- return { ref : annotationRef } ;
1801
+ const retRef = { ref : annotationRef } ;
1802
+ if ( annotation . popup ) {
1803
+ const popup = annotation . popup ;
1804
+ if ( popup . deleted ) {
1805
+ annotationDict . delete ( "Popup" ) ;
1806
+ annotationDict . delete ( "Contents" ) ;
1807
+ annotationDict . delete ( "RC" ) ;
1808
+ return retRef ;
1809
+ }
1810
+ const popupRef = ( popup . ref ||= xref . getNewTemporaryRef ( ) ) ;
1811
+ popup . parent = annotationRef ;
1812
+ const popupDict = PopupAnnotation . createNewDict ( popup , xref ) ;
1813
+ changes . put ( popupRef , { data : popupDict } ) ;
1814
+ annotationDict . setIfDefined (
1815
+ "Contents" ,
1816
+ stringToAsciiOrUTF16BE ( popup . contents )
1817
+ ) ;
1818
+ annotationDict . set ( "Popup" , popupRef ) ;
1819
+
1820
+ return [ retRef , { ref : popupRef } ] ;
1821
+ }
1822
+
1823
+ return retRef ;
1802
1824
}
1803
1825
1804
1826
static async createNewPrintAnnotation (
@@ -3880,6 +3902,22 @@ class PopupAnnotation extends Annotation {
3880
3902
3881
3903
this . data . open = ! ! dict . get ( "Open" ) ;
3882
3904
}
3905
+
3906
+ static createNewDict ( annotation , xref , _params ) {
3907
+ const { oldAnnotation, rect, parent } = annotation ;
3908
+ const popup = oldAnnotation || new Dict ( xref ) ;
3909
+ popup . setIfNotExists ( "Type" , Name . get ( "Annot" ) ) ;
3910
+ popup . setIfNotExists ( "Subtype" , Name . get ( "Popup" ) ) ;
3911
+ popup . setIfNotExists ( "Open" , false ) ;
3912
+ popup . setIfArray ( "Rect" , rect ) ;
3913
+ popup . set ( "Parent" , parent ) ;
3914
+
3915
+ return popup ;
3916
+ }
3917
+
3918
+ static async createNewAppearanceStream ( annotation , xref , params ) {
3919
+ return null ;
3920
+ }
3883
3921
}
3884
3922
3885
3923
class FreeTextAnnotation extends MarkupAnnotation {
@@ -3947,18 +3985,27 @@ class FreeTextAnnotation extends MarkupAnnotation {
3947
3985
}
3948
3986
3949
3987
static createNewDict ( annotation , xref , { apRef, ap } ) {
3950
- const { color, fontSize, oldAnnotation, rect, rotation, user, value } =
3951
- annotation ;
3988
+ const {
3989
+ color,
3990
+ date,
3991
+ fontSize,
3992
+ oldAnnotation,
3993
+ rect,
3994
+ rotation,
3995
+ user,
3996
+ value,
3997
+ } = annotation ;
3952
3998
const freetext = oldAnnotation || new Dict ( xref ) ;
3953
3999
freetext . setIfNotExists ( "Type" , Name . get ( "Annot" ) ) ;
3954
4000
freetext . setIfNotExists ( "Subtype" , Name . get ( "FreeText" ) ) ;
4001
+ freetext . set (
4002
+ oldAnnotation ? "M" : "CreationDate" ,
4003
+ `D:${ getModificationDate ( date ) } `
4004
+ ) ;
3955
4005
if ( oldAnnotation ) {
3956
- freetext . set ( "M" , `D:${ getModificationDate ( ) } ` ) ;
3957
4006
// TODO: We should try to generate a new RC from the content we've.
3958
4007
// For now we can just remove it to avoid any issues.
3959
4008
freetext . delete ( "RC" ) ;
3960
- } else {
3961
- freetext . set ( "CreationDate" , `D:${ getModificationDate ( ) } ` ) ;
3962
4009
}
3963
4010
freetext . setIfArray ( "Rect" , rect ) ;
3964
4011
const da = `/Helv ${ fontSize } Tf ${ getPdfColor ( color , /* isFill */ true ) } ` ;
@@ -4492,6 +4539,7 @@ class InkAnnotation extends MarkupAnnotation {
4492
4539
const {
4493
4540
oldAnnotation,
4494
4541
color,
4542
+ date,
4495
4543
opacity,
4496
4544
paths,
4497
4545
outlines,
@@ -4503,7 +4551,10 @@ class InkAnnotation extends MarkupAnnotation {
4503
4551
const ink = oldAnnotation || new Dict ( xref ) ;
4504
4552
ink . setIfNotExists ( "Type" , Name . get ( "Annot" ) ) ;
4505
4553
ink . setIfNotExists ( "Subtype" , Name . get ( "Ink" ) ) ;
4506
- ink . set ( oldAnnotation ? "M" : "CreationDate" , `D:${ getModificationDate ( ) } ` ) ;
4554
+ ink . set (
4555
+ oldAnnotation ? "M" : "CreationDate" ,
4556
+ `D:${ getModificationDate ( date ) } `
4557
+ ) ;
4507
4558
ink . setIfArray ( "Rect" , rect ) ;
4508
4559
ink . setIfArray ( "InkList" , outlines ?. points || paths ?. points ) ;
4509
4560
ink . setIfNotExists ( "F" , 4 ) ;
@@ -4730,13 +4781,23 @@ class HighlightAnnotation extends MarkupAnnotation {
4730
4781
}
4731
4782
4732
4783
static createNewDict ( annotation , xref , { apRef, ap } ) {
4733
- const { color, oldAnnotation, opacity, rect, rotation, user, quadPoints } =
4734
- annotation ;
4735
- const date = `D:${ getModificationDate ( ) } ` ;
4784
+ const {
4785
+ color,
4786
+ date,
4787
+ oldAnnotation,
4788
+ opacity,
4789
+ rect,
4790
+ rotation,
4791
+ user,
4792
+ quadPoints,
4793
+ } = annotation ;
4736
4794
const highlight = oldAnnotation || new Dict ( xref ) ;
4737
4795
highlight . setIfNotExists ( "Type" , Name . get ( "Annot" ) ) ;
4738
4796
highlight . setIfNotExists ( "Subtype" , Name . get ( "Highlight" ) ) ;
4739
- highlight . set ( oldAnnotation ? "M" : "CreationDate" , date ) ;
4797
+ highlight . set (
4798
+ oldAnnotation ? "M" : "CreationDate" ,
4799
+ `D:${ getModificationDate ( date ) } `
4800
+ ) ;
4740
4801
highlight . setIfArray ( "Rect" , rect ) ;
4741
4802
highlight . setIfNotExists ( "F" , 4 ) ;
4742
4803
highlight . setIfNotExists ( "Border" , [ 0 , 0 , 0 ] ) ;
@@ -5046,12 +5107,14 @@ class StampAnnotation extends MarkupAnnotation {
5046
5107
}
5047
5108
5048
5109
static createNewDict ( annotation , xref , { apRef, ap } ) {
5049
- const { oldAnnotation, rect, rotation, user } = annotation ;
5050
- const date = `D:${ getModificationDate ( annotation . date ) } ` ;
5110
+ const { date, oldAnnotation, rect, rotation, user } = annotation ;
5051
5111
const stamp = oldAnnotation || new Dict ( xref ) ;
5052
5112
stamp . setIfNotExists ( "Type" , Name . get ( "Annot" ) ) ;
5053
5113
stamp . setIfNotExists ( "Subtype" , Name . get ( "Stamp" ) ) ;
5054
- stamp . set ( oldAnnotation ? "M" : "CreationDate" , date ) ;
5114
+ stamp . set (
5115
+ oldAnnotation ? "M" : "CreationDate" ,
5116
+ `D:${ getModificationDate ( date ) } `
5117
+ ) ;
5055
5118
stamp . setIfArray ( "Rect" , rect ) ;
5056
5119
stamp . setIfNotExists ( "F" , 4 ) ;
5057
5120
stamp . setIfNotExists ( "Border" , [ 0 , 0 , 0 ] ) ;
0 commit comments