Skip to content

How it works ​

A three-phase pipeline: parse → replay → export. The header parser reads the drawing bounds (a placeable WMF is sized from its header's units per inch), the output surface is created (clamped to maxCanvasDimension), and the records are replayed in order by the GDI, EMF+ or WMF handlers. PNG and JPEG output draw onto a Canvas (OffscreenCanvas, HTMLCanvasElement, @napi-rs/canvas, or the built-in pure-JavaScript rasteriser), and JPEG is then encoded by the bundled baseline encoder (src/jpeg-encoder.ts); SVG output draws onto SvgContext, a recorder implementing the part of the Canvas 2D API the replay uses, mirrored onto a hidden raster wherever a raster operation must read the destination.

Everything below is verified against output painted by Windows itself; src/gdi-parity.fixture.test.ts holds the per-fixture bounds.

  • GDI shapes (gdi-raster.ts, gdi-raster-widen.ts): 28.4 fixed-point geometry; GDI's fill rule (ALTERNATE/WINDING); one-pixel lines by GDI's diamond rule with its tie-breaks; GDI's own Bezier flattener, ellipse, rounded-rectangle, arc (GDI's trigonometry table and SetArcDirection), chord and pie construction; cosmetic dash styles (dash 18/6, dot 3/3, ...) and geometric dashes; wide pens widened from GDI's own pen polygons with every cap and join and the miter limit; rotated, skewed and mirrored world transforms, with the pen's nib built under the matrix as Windows builds it; GM_COMPATIBLE recordings played back under non-unit and mirrored map modes, with the radials of arcs, chords and pies measured in logical space as Windows measures them. Pixel-exact on the shape fixtures. A path bracket's GDI geometry has the points, point types, figure starts and direction that Windows' GetPath reports (checked against the Windows data in Wine's gdi32 path tests).
  • Raster operations: all 256 ROP3 codes for BitBlt/StretchBlt/StretchDIBits/PatBlt, exact per bit against the destination, brush and source, with GDI's stretch modes (HALFTONE reproduces Windows' branch selection, filtered enlargements, reductions, mixed enlarge-and-reduce stretches and dithered colour adjustments, and drops the source alpha as Windows does), mirrored rectangles and rotated destinations (each device pixel mapped back to one source texel). Every SetROP2 mode, including the bitwise AND/OR/XOR family, for shapes, paths and pattern-brush fills.
  • Brushes: hatch, monochrome and DIB pattern brushes anchored to the brush origin, with the background mode; GDI+ solid, hatch, texture (bilinear, WrapMode-aware, as GDI+ samples them), linear gradients (GDI+'s own interpolation table: preset colours, blend shapes, gamma correction, every WrapMode) and path gradients (true boundary-shaped falloff, drawn as GDI+ draws it, in nested copies of the boundary whose colour steps follow GDI+'s float32 ramp; every WrapMode).
  • Clipping: every GDI and GDI+ region combine mode exact for every clip (vector where possible, otherwise scan-converted to pixel regions, which is how GDI stores them), path clips with their fill mode, and region offsets.
  • EMF+: fills, pens and clips follow the recorded SmoothingMode with GDI+'s own fill rasteriser (8 x 4-sample antialiasing, blend arithmetic) and pen widener (joins, caps, dash caps, compound lines, inset alignment); DrawImage with every InterpolationMode/PixelOffsetMode kernel (cropped sources read the kernel's radius past the source rectangle, and DrawImage and DrawImagePoints mirror a unit-scale axis differently, as GDI+ does), ImageAttributes wrap modes, drawn in record order under the live clip; embedded metafiles replayed as vectors; continuation records reassembled; compressed textures and images decoded before replay.
  • Text: see Exact text.
  • WMF: PS_INSIDEFRAME half-pixel width sweeps and mirrored line fixtures match Windows exactly; scaled shapes match too. Metric map modes default to a 96 dpi reference device; wmfReferenceDpi accepts a scalar or { x, y } to reproduce another device.

Supported records ​

  • EMF: Record playback includes logical palettes (PALETTEINDEX, DIBPALETTEINDEX, PALETTERGB, DIB_PAL_COLORS), EMR_ALPHABLEND (Windows' exact integer blend), EMR_TRANSPARENTBLT, EMR_MASKBLT, EMR_PLGBLT, EMR_SETDIBITSTODEVICE, EMR_GRADIENTFILL (rectangles and triangles), EMR_FILLRGN / EMR_FRAMERGN / EMR_INVERTRGN / EMR_PAINTRGN, EMR_EXTFLOODFILL, EMR_ANGLEARC, EMR_POLYDRAW(16), EMR_FLATTENPATH / EMR_WIDENPATH / EMR_ABORTPATH, alongside shapes, paths, EMR_EXTTEXTOUTA/W, EMR_POLYTEXTOUTA/W, EMR_SMALLTEXTOUT, text justification, blits, clipping and transforms. Colour space, ICM, OpenGL, escape and font-driver records are consumed without effect, as on a Windows display.
  • EMF+: every record in MS-EMFPLUS (Beziers, cardinal curves, regions, containers, save/restore, compositing mode, rendering origin, text contrast, StrokeFillPath, the terminal-server SetTSGraphics / SetTSClip, MultiFormat* played as GDI+ plays them), with 32-bit, compressed 16-bit and relative point data, and every object type (solid, hatch, texture and gradient brushes; pens with caps, joins, dash styles, dash caps, compound lines and custom line caps; paths, regions, bitmap and metafile images, fonts, string formats, image attributes). Several encodings follow what GDI+ actually does where it differs from MS-EMFPLUS (relative points, StrokeFillPath, SetTSGraphics, SetTSClip).
  • WMF: META_ANIMATEPALETTE, META_ARC, META_BITBLT, META_CHORD, META_CREATEBITMAP, META_CREATEBITMAPINDIRECT, META_CREATEBRUSH, META_CREATEBRUSHINDIRECT, META_CREATEFONTINDIRECT, META_CREATEPALETTE, META_CREATEPATTERNBRUSH, META_CREATEPENINDIRECT, META_CREATEREGION, META_DELETEOBJECT, META_DIBBITBLT, META_DIBCREATEPATTERNBRUSH, META_DIBSTRETCHBLT, META_ELLIPSE, META_EOF, META_ESCAPE, META_EXCLUDECLIPRECT, META_EXTFLOODFILL, META_EXTTEXTOUT, META_FILLREGION, META_FLOODFILL, META_FRAMEREGION, META_INTERSECTCLIPRECT, META_INVERTREGION, META_LINETO, META_MOVETO, META_OFFSETCLIPRGN, META_OFFSETVIEWPORTORG, META_OFFSETWINDOWORG, META_PAINTREGION, META_PATBLT, META_PIE, META_POLYGON, META_POLYLINE, META_POLYPOLYGON, META_REALIZEPALETTE, META_RECTANGLE, META_RESIZEPALETTE, META_RESTOREDC, META_ROUNDRECT, META_SAVEDC, META_SCALEVIEWPORTEXT, META_SCALEWINDOWEXT, META_SELECTCLIPREGION, META_SELECTOBJECT, META_SELECTPALETTE, META_SETBKCOLOR, META_SETBKMODE, META_SETDIBTODEV, META_SETLAYOUT, META_SETMAPMODE, META_SETMAPPERFLAGS, META_SETPALENTRIES, META_SETPIXEL, META_SETPOLYFILLMODE, META_SETRELABS, META_SETROP2, META_SETSTRETCHBLTMODE, META_SETTEXTALIGN, META_SETTEXTCHAREXTRA, META_SETTEXTCOLOR, META_SETTEXTJUSTIFICATION, META_SETVIEWPORTEXT, META_SETVIEWPORTORG, META_SETWINDOWEXT, META_SETWINDOWORG, META_STRETCHBLT, META_STRETCHDIB, META_TEXTOUT. Where Windows no longer plays a record the way MS-WMF describes it (Win16 device bitmaps in META_BITBLT / META_STRETCHBLT, META_CREATEPATTERNBRUSH, banded META_SETDIBTODEV), the converter follows Windows.

Released under the Apache-2.0 License.