MCPcopy Index your code
hub / github.com/simstudioai/sim / parseEmfContent

Function parseEmfContent

apps/sim/lib/pptx-renderer/utils/emf-parser.ts:42–87  ·  view source on GitHub ↗
(data: Uint8Array)

Source from the content-addressed store, hash-verified

40 * Parse an EMF file and extract its embedded content.
41 */
42export function parseEmfContent(data: Uint8Array): EmfContent {
43 if (data.length < 44) return { type: 'unsupported' }
44
45 const view = new DataView(data.buffer, data.byteOffset, data.byteLength)
46
47 // Validate EMF signature at offset 40
48 if (view.getUint32(40, true) !== EMF_SIGNATURE) {
49 return { type: 'unsupported' }
50 }
51
52 let offset = 0
53 let recordCount = 0
54
55 while (offset + 8 <= data.length) {
56 const recordType = view.getUint32(offset, true)
57 const recordSize = view.getUint32(offset + 4, true)
58
59 // Sanity check record size
60 if (recordSize < 8 || offset + recordSize > data.length) break
61
62 recordCount++
63
64 if (recordType === EMR_EOF) break
65
66 // Check GDI Comment records for embedded PDF
67 if (recordType === EMR_COMMENT && recordSize > 16) {
68 const result = parseGdiComment(data, view, offset, recordSize)
69 if (result) return result
70 }
71
72 // Check STRETCHDIBITS for embedded bitmaps
73 if (recordType === EMR_STRETCHDIBITS && recordSize > 80) {
74 const result = parseStretchDibits(data, view, offset, recordSize)
75 if (result) return result
76 }
77
78 offset += recordSize
79 }
80
81 // Only HEADER + EOF → empty
82 if (recordCount <= 2) {
83 return { type: 'empty' }
84 }
85
86 return { type: 'unsupported' }
87}
88
89/**
90 * Parse a GDI Comment record looking for embedded PDF data.

Callers 1

renderEmfFunction · 0.90

Calls 2

parseGdiCommentFunction · 0.85
parseStretchDibitsFunction · 0.85

Tested by

no test coverage detected