* Parse a GDI Comment record looking for embedded PDF data.
( data: Uint8Array, view: DataView, offset: number, recordSize: number )
| 90 | * Parse a GDI Comment record looking for embedded PDF data. |
| 91 | */ |
| 92 | function parseGdiComment( |
| 93 | data: Uint8Array, |
| 94 | view: DataView, |
| 95 | offset: number, |
| 96 | recordSize: number |
| 97 | ): EmfContent | null { |
| 98 | // Record layout: type(4) + size(4) + cbData(4) + commentId(4) + ... |
| 99 | if (offset + 16 > data.length) return null |
| 100 | |
| 101 | const commentId = view.getUint32(offset + 12, true) |
| 102 | |
| 103 | if (commentId === GDIC_COMMENT_ID && offset + 20 <= data.length) { |
| 104 | const publicType = view.getUint32(offset + 16, true) |
| 105 | |
| 106 | if (publicType === GDIC_BEGINGROUP) { |
| 107 | // Search for %PDF signature in the record data |
| 108 | const recordData = data.subarray(offset + 8, offset + recordSize) |
| 109 | const pdf = extractPdfFromBuffer(recordData) |
| 110 | if (pdf) return { type: 'pdf', data: pdf } |
| 111 | } |
| 112 | |
| 113 | if (publicType === GDIC_MULTIFORMATS && offset + 24 <= data.length) { |
| 114 | // MULTIFORMATS: parse format descriptors and extract first usable one |
| 115 | const result = parseMultiformats(data, view, offset, recordSize) |
| 116 | if (result) return result |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | // Also search non-GDIC comments for raw PDF data |
| 121 | if (recordSize > 100) { |
| 122 | const recordData = data.subarray(offset + 8, offset + recordSize) |
| 123 | const pdf = extractPdfFromBuffer(recordData) |
| 124 | if (pdf) return { type: 'pdf', data: pdf } |
| 125 | } |
| 126 | |
| 127 | return null |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Parse MULTIFORMATS GDI comment — contains format descriptors pointing to embedded data. |
no test coverage detected