Skip to content

fix: EMRTEXT wire layout — ptlReference is POINTL not WmfRect16 - #6

Merged
ronaldtse merged 1 commit into
mainfrom
feat/fix-emrtext-layout
Jul 24, 2026
Merged

fix: EMRTEXT wire layout — ptlReference is POINTL not WmfRect16#6
ronaldtse merged 1 commit into
mainfrom
feat/fix-emrtext-layout

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Critical wire layout fix discovered by studying libemf2svg's U_EMRTEXT struct definition. ptlReference (POINTL: two int32) was being parsed as WmfRect16 (four int16). Text positions were completely wrong.

Companion to emfsvg PR that takes advantage of this fix to reach 81.1% byte ratio vs libemf2svg.

Round-trip: 208/208 byte-identical.

After studying libemf2svg's emf2svg_rec_drawing.c and the U_EMRTEXT
struct in libUEMF, discovered the wire layout was wrong.

Previous (incorrect):
  int16 wmf_rect_left/top/right/bottom  (WmfRect16, 8 bytes)

Correct (per MS-EMF 2.2.6 EMRTEXT):
  point_l ptl_reference  (POINTL, 8 bytes — int32 x, int32 y)
  uint32 n_chars
  uint32 off_string
  uint32 f_options
  rectl rcl              (RECTL, 16 bytes — clipping rectangle)
  uint32 off_dx

The ptlReference is the text anchor point — the most critical field
for text positioning. Was previously parsed as 4 int16 values
(wmf_rect_left/top/right/bottom) which mapped to the wrong bytes,
causing all text to be positioned at incorrect coordinates.

Round-trip verified: 208/208 byte-identical.
@ronaldtse
ronaldtse merged commit d5c9550 into main Jul 24, 2026
@ronaldtse
ronaldtse deleted the feat/fix-emrtext-layout branch July 24, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant