@@ -428,7 +428,7 @@ class AnnotationFactory {
428428 }
429429
430430 return {
431- annotations : await Promise . all ( promises ) ,
431+ annotations : ( await Promise . all ( promises ) ) . flat ( ) ,
432432 } ;
433433 }
434434
@@ -1798,7 +1798,29 @@ class MarkupAnnotation extends Annotation {
17981798 data : annotationDict ,
17991799 } ) ;
18001800
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 ;
18021824 }
18031825
18041826 static async createNewPrintAnnotation (
@@ -3880,6 +3902,22 @@ class PopupAnnotation extends Annotation {
38803902
38813903 this . data . open = ! ! dict . get ( "Open" ) ;
38823904 }
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+ }
38833921}
38843922
38853923class FreeTextAnnotation extends MarkupAnnotation {
@@ -3947,18 +3985,27 @@ class FreeTextAnnotation extends MarkupAnnotation {
39473985 }
39483986
39493987 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 ;
39523998 const freetext = oldAnnotation || new Dict ( xref ) ;
39533999 freetext . setIfNotExists ( "Type" , Name . get ( "Annot" ) ) ;
39544000 freetext . setIfNotExists ( "Subtype" , Name . get ( "FreeText" ) ) ;
4001+ freetext . set (
4002+ oldAnnotation ? "M" : "CreationDate" ,
4003+ `D:${ getModificationDate ( date ) } `
4004+ ) ;
39554005 if ( oldAnnotation ) {
3956- freetext . set ( "M" , `D:${ getModificationDate ( ) } ` ) ;
39574006 // TODO: We should try to generate a new RC from the content we've.
39584007 // For now we can just remove it to avoid any issues.
39594008 freetext . delete ( "RC" ) ;
3960- } else {
3961- freetext . set ( "CreationDate" , `D:${ getModificationDate ( ) } ` ) ;
39624009 }
39634010 freetext . setIfArray ( "Rect" , rect ) ;
39644011 const da = `/Helv ${ fontSize } Tf ${ getPdfColor ( color , /* isFill */ true ) } ` ;
@@ -4492,6 +4539,7 @@ class InkAnnotation extends MarkupAnnotation {
44924539 const {
44934540 oldAnnotation,
44944541 color,
4542+ date,
44954543 opacity,
44964544 paths,
44974545 outlines,
@@ -4503,7 +4551,10 @@ class InkAnnotation extends MarkupAnnotation {
45034551 const ink = oldAnnotation || new Dict ( xref ) ;
45044552 ink . setIfNotExists ( "Type" , Name . get ( "Annot" ) ) ;
45054553 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+ ) ;
45074558 ink . setIfArray ( "Rect" , rect ) ;
45084559 ink . setIfArray ( "InkList" , outlines ?. points || paths ?. points ) ;
45094560 ink . setIfNotExists ( "F" , 4 ) ;
@@ -4730,13 +4781,23 @@ class HighlightAnnotation extends MarkupAnnotation {
47304781 }
47314782
47324783 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 ;
47364794 const highlight = oldAnnotation || new Dict ( xref ) ;
47374795 highlight . setIfNotExists ( "Type" , Name . get ( "Annot" ) ) ;
47384796 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+ ) ;
47404801 highlight . setIfArray ( "Rect" , rect ) ;
47414802 highlight . setIfNotExists ( "F" , 4 ) ;
47424803 highlight . setIfNotExists ( "Border" , [ 0 , 0 , 0 ] ) ;
@@ -5046,12 +5107,14 @@ class StampAnnotation extends MarkupAnnotation {
50465107 }
50475108
50485109 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 ;
50515111 const stamp = oldAnnotation || new Dict ( xref ) ;
50525112 stamp . setIfNotExists ( "Type" , Name . get ( "Annot" ) ) ;
50535113 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+ ) ;
50555118 stamp . setIfArray ( "Rect" , rect ) ;
50565119 stamp . setIfNotExists ( "F" , 4 ) ;
50575120 stamp . setIfNotExists ( "Border" , [ 0 , 0 , 0 ] ) ;
0 commit comments