* Parse MULTIFORMATS GDI comment — contains format descriptors pointing to embedded data.
( data: Uint8Array, view: DataView, offset: number, _recordSize: number )
| 131 | * Parse MULTIFORMATS GDI comment — contains format descriptors pointing to embedded data. |
| 132 | */ |
| 133 | function parseMultiformats( |
| 134 | data: Uint8Array, |
| 135 | view: DataView, |
| 136 | offset: number, |
| 137 | _recordSize: number |
| 138 | ): EmfContent | null { |
| 139 | // Layout from record start: |
| 140 | // +12: commentIdentifier(4), +16: publicCommentIdentifier(4) |
| 141 | // +20: outputRect(16 = RECTL) |
| 142 | // +36: countFormats(4) |
| 143 | // +40: format descriptors array, each: { signature(4), version(4), cbData(4), offData(4) } |
| 144 | if (offset + 40 > data.length) return null |
| 145 | |
| 146 | const countFormats = view.getUint32(offset + 36, true) |
| 147 | const descriptorStart = offset + 40 |
| 148 | |
| 149 | for (let i = 0; i < countFormats && i < 10; i++) { |
| 150 | const descOff = descriptorStart + i * 16 |
| 151 | if (descOff + 16 > data.length) break |
| 152 | |
| 153 | const cbData = view.getUint32(descOff + 8, true) |
| 154 | const offData = view.getUint32(descOff + 12, true) |
| 155 | |
| 156 | // offData is relative to the start of the record |
| 157 | const dataStart = offset + offData |
| 158 | if (dataStart + cbData > data.length || cbData === 0) continue |
| 159 | |
| 160 | const formatData = data.subarray(dataStart, dataStart + cbData) |
| 161 | const pdf = extractPdfFromBuffer(formatData) |
| 162 | if (pdf) return { type: 'pdf', data: pdf } |
| 163 | } |
| 164 | |
| 165 | return null |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Search for %PDF...%%EOF in a buffer and extract the PDF bytes. |
no test coverage detected