mORMot2 DailyDaily read of upstream commits

External-database batch races close as EMF rendering hardens

The most important fix closes a race in TRestStorageExternal: a regular write from one thread can no longer fail silently or join another thread’s active BATCH. The final follow-up performs the ownership check under the reentrant storage lock. A broad Windows rendering series also corrects EMF-to-PDF paths, clips, fonts and mirrored geometry, while GDI+ playback gains matching record-layout and state-restoration fixes.

TL;DR

  • Concurrent regular writes now wait for another thread’s external-database BATCH instead of failing or joining it.
  • The batch-owner decision is made under the reentrant storage lock, removing the remaining unsynchronised field read.
  • EMF-to-PDF paths and clip regions now follow the graphics state active when GDI actually paints or restores them.
  • ANSI text, mirrored boxes, scaled rotations and malformed TrueType tables receive targeted PDF fixes.
  • FPC 3.2.2 Win64 reads fixed-width EMF brush and pen records correctly in both PDF and GDI+ paths.

Upgrade advice

For services that share TRestStorageExternal across threads, take the complete 57e2526de090afe6ece88d614b557555dd3c4d76 head so the locking follow-up accompanies the original batch fix; stress mixed BATCH and regular writes. Windows PDF or EMF users should also retest path clipping, locale-specific text, mirrored shapes and FPC Win64 colours. The raw payload records no superseded_by successor.

Commits25
Lines+7001 -867
Read7 min

21 of 21 entries · 25 commits upstream

Stories
# Entry Category Units
1 High Concurrent writes no longer enter another thread’s external-database batch TRestStorageExternal now routes EngineAdd, EngineUpdate, EngineDelete and EngineDeleteWhere through InBatchOfCurrentThread. A regular write from another thread takes the normal locked path instead of failing or appending to the active BATCH, and regular writes no longer reuse that batch’s fBatchOptions. BatchFromOtherThread adds a SQLite-backed regression test. Fixes mormot.orm.sql 1fc8504f+127-7

orm: fixed TRestStorageExternal regular writes from another thread during a BATCH

Impact

External SQL backends that share one TRestStorageExternal across threads no longer silently lose an update or contaminate another thread’s batch. Delphi and FPC application APIs are unchanged, but concurrent write behaviour is corrected.

Dimitris Kounalakis · 15:49 UTC · view the commit on GitHub →

2 High Batch ownership is decided while holding the storage lock InBatchOfCurrentThread no longer reads fBatchMethod and fBatchThread without synchronization. It acquires the reentrant storage lock, where fBatchMethod <> mNone identifies the owner; the explicit fBatchThread field introduced by the preceding fix is removed. Fixes mormot.orm.sql c6048bcd+12-9

orm: InBatchOfCurrentThread checks fBatchMethod within the storage lock

Impact

The final implementation removes the remaining data race in the batch-owner test. Other threads wait until the active batch releases the lock, while its owner re-enters immediately; Delphi and FPC callers need no code changes.

Dimitris Kounalakis · 18:01 UTC · view the commit on GitHub →

3 Medium PDF path painting now uses the clip and pen active at paint time TPdfEnum buffers geometry between EMR_BEGINPATH and EMR_ENDPATH in a separate TPdfStream. StrokePath, FillPath and StrokeAndFillPath then apply the current clip, pen and brush before replaying and painting that geometry; abort, clip-path and end-of-metafile records discard it. GStateRestored also clears all cached graphics-state values. Fixes mormot.ui.pdf 4bc5c2be+406-63

ui: pdf - a GDI path is painted under the clip and with the pen of its painting record

Impact

EMF-to-PDF output now matches GDI for clips or pens changed inside a path bracket and avoids premature or duplicate painting of shapes. The change affects Windows rendering only; Delphi and FPC call sites stay compatible.

Worth a look

Retest EMF files that combine BeginPath with clipping, pen changes, text, bitmaps, alternate fills or StrokeAndFillPath. Text outlines inside paths remain explicitly unsupported.

Sven Harazim · 15:32 UTC · view the commit on GitHub →

4 Medium PDF clip regions survive RestoreDC and keep graphics state balanced TPdfEnumState now records the active EMR_EXTSELECTCLIPRGN and SetMetaRgn regions as PDF boxes. SelectClip reapplies the saved region after RestoreDC, closes obsolete q scopes with Q, and resets cached pen and fill values; path handling delays clip changes until the path is finished. Fixes mormot.ui.pdf 851ad20c+385-20

ui: pdf - EMR_RESTOREDC restores the clip of EMR_EXTSELECTCLIPRGN, q and Q balanced

Impact

Nested clipping and saved DC states no longer leave a stale inner clip or unbalanced PDF operators. Existing Delphi and FPC APIs are unchanged; generated PDF content changes for affected EMF records.

Worth a look

Compare PDFs made from EMF files using SaveDC, RestoreDC, ExtSelectClipRgn, SetMetaRgn and path painting, especially nested clips.

Sven Harazim · 13:36 UTC · view the commit on GitHub →

5 Medium GDI+ RestoreDC restores the requested depth and clip transform TGdiplusEnum.RestoreDC now honours negative iRelative depth, ignores invalid targets, frees every discarded clip region, restores the saved transform before reapplying its clip and grows the DC-state array dynamically. EnumerateEnd also frees DC[i].ClipRegion rather than repeating DC[nDC]. Fixes mormot.lib.gdiplus d80a4a6b+249-20

gdiplus: EMR_RESTOREDC restores the depth it names, and the saved clip under its own transform

Impact

Nested EMF state restores no longer shrink a saved clip under a temporary world scale or fail beyond eleven levels. Delphi and FPC callers remain source-compatible.

Worth a look

Retest GDI+ EMF previews with nested SaveDC/RestoreDC, clipping and temporary world transforms.

Sven Harazim · 06:03 UTC · view the commit on GitHub →

6 Medium Mirrored PDF shapes keep their recorded edge BoxInclI and RoundRectI now add the signed device pixel to the recorded right and bottom edges before normalizing mirrored coordinates. DevPixelX and DevPixelY become signed, RoundRectI passes corners in TPdfCanvas order, and EMR_ROUNDRECT no longer mutates the source record. Fixes mormot.ui.pdf 7e1833d1+193-8

ui: pdf - the boxes of #686 under a mirrored axis

Impact

Rectangle, Ellipse and RoundRect output under a mirrored axis no longer shifts by one device pixel. Delphi and FPC interfaces are unchanged; only affected EMF-to-PDF geometry changes.

Worth a look

Retest EMF exports with negative viewport extents or other mirrored axes.

Sven Harazim · 08:42 UTC · PR #686 · view the commit on GitHub →

7 Medium GDI+ applies viewport mapping before the playback transform TGdiplusEnum.ScaleMatrix now computes window-to-viewport translation in floating point and composes row-vector matrices as World x Map x Dest. This removes MulDiv rounding and applies the destination playback transform after the logical mapping. Fixes mormot.lib.gdiplus aceee0f7+90-6

gdiplus: the window/viewport mapping, then the playback transform, without rounding

Impact

EMF previews with non-zero window or viewport origins and a playback scale now align with GDI instead of accumulating rounding or transform-order errors. Delphi and FPC APIs are unchanged.

Worth a look

Compare GDI+ previews that combine viewport origins, window origins and destination scaling.

Sven Harazim · 06:03 UTC · view the commit on GitHub →

8 Medium TrueType subset reduction validates every input and output table bound ReduceTTF now checks the 12-byte table-directory header, every directory entry, each retained table in the input subset and each write in the result. It validates checkSumAdjustment in head and computes searchRange, entrySelector and rangeShift from the actual number of retained tables. Fixes mormot.ui.pdf 5646c26b+76-13

ui: pdf - ReduceTTF reads within the subset and writes within its result (#673, row 22)

Impact

Malformed or unusually deduplicated font subsets no longer risk out-of-bounds reads or writes during PDF font embedding. The routine is internal, so Delphi and FPC application code remains source-compatible.

Worth a look

Regenerate PDFs that embed uncommon TrueType subsets and compare font rendering and file validity.

Sven Harazim · 08:42 UTC · PR #673 · view the commit on GitHub →

9 Medium Repeated bitmap rendering no longer mutates the source EMF For EMR_STRETCHDIBITS under a flipped transform, TPdfEnum copies the bounded bitmap header before negating biHeight instead of modifying the const record returned by EnumEnhMetaFile. The related mirrored-box change likewise stops editing EMR_ROUNDRECT in place. Fixes mormot.ui.pdf ac12db42+71-5

ui: pdf - EMR_STRETCHDIBITS flips a copy of its header (#673, row 20)

Impact

Rendering the same metafile more than once now keeps bitmap orientation stable. Delphi and FPC callers need no changes; only repeat rendering of flipped bitmap records is affected.

Worth a look

Render the same EMF twice when it contains flipped EMR_STRETCHDIBITS records and compare the outputs.

Sven Harazim · 08:41 UTC · PR #673 · view the commit on GitHub →

10 Medium Scaled rotations avoid invalid inverse-trigonometric inputs ScaleMatrix and TextOut now derive rotation with ArcTan2(eM12, eM11) instead of passing scaled matrix components to ArcSin or ArcCos. Values above one therefore no longer raise EInvalidOp on Delphi or yield NaN on FPC. Fixes mormot.ui.pdf 8e60a6ad+62-4

ui: pdf - a scaled rotation is drawn without ArcSin/ArcCos past 1 (#673, row 18)

Impact

Rotated text and graphics under a world scale render instead of failing on Delphi or appearing upright on FPC. No public API changes are introduced.

Sven Harazim · 08:41 UTC · PR #673 · view the commit on GitHub →

11 Medium Missing printer DPI falls back safely instead of dividing by zero CurrentPrinterRes retains the 300 dpi default when CreateDC or GetDeviceCaps fails, and RenderMetaFile retries if either axis is zero or negative. CurrentPrinterRes and CurrentPrinterPaperSize also pass GetProfileString the character count rather than a byte count on Unicode compilers. Fixes mormot.ui.pdf d9a99cf3+55-6

ui: pdf - a printer resolution of 0 is asked again, not divided by (#673, row 21)

Impact

EMF-to-PDF conversion in printer-less or failing printer environments avoids a divide-by-zero path and unsafe buffer length. Both Delphi and FPC keep the same public API.

Sven Harazim · 08:41 UTC · PR #673 · view the commit on GitHub →

12 Medium PDF font mapping rejects malformed format 4 cmap bounds TPdfTtf now receives the exact cmap byte length from GetTtfData and validates its header, subtable directory, format 4 arrays, segment ranges and idRangeOffset glyph accesses. Invalid segments produce no glyph instead of a negative count or out-of-bounds access. Fixes mormot.ui.pdf c4e1f0d6+25-8

ui: pdf - TPdfTtf reads the format 4 cmap within its table (#673, row 14)

Impact

Defensive parsing prevents malformed TrueType cmap data from causing memory errors during PDF font embedding. Normal GDI-loaded fonts render as before, and Delphi/FPC application APIs do not change.

Sven Harazim · 08:41 UTC · PR #673 · view the commit on GitHub →

13 Medium ANSI EMF text is decoded with the selected font’s charset TPdfEnum.TextOut now distinguishes EMR_EXTTEXTOUTA from the Unicode record, converts its byte string through the selected font charset’s code page and preserves glyph-index records. Per-byte dx advances are dropped only when multibyte conversion changes the character count. Compiler & platform mormot.ui.pdf 7fc8ed0e+254-8

ui: pdf - EMR_EXTTEXTOUTA reads its bytes in the code page of the font (#673, row 19)

Impact

ANSI, Greek, Shift-JIS and OEM text in EMF-to-PDF output is no longer read as pairs of WideChar values. The correction is shared by Delphi and FPC without changing application-facing signatures.

Worth a look

Compare non-Unicode EMF text under the actual Windows locales and fonts used in production.

Sven Harazim · 08:41 UTC · PR #673 · view the commit on GitHub →

14 Medium FPC Win64 PDF brushes and extended pens read the 32-bit EMF layout TPdfEnum introduces TEmrCreateBrushIndirect32 and TEmrExtCreatePen32 and uses them instead of FPC 3.2.2’s native-pointer LOGBRUSH and EXTLOGPEN declarations. This keeps lbColor and extended-pen fields at their on-disk EMF offsets. Compiler & platform mormot.ui.pdf 2055447a+70-8

ui: pdf - EMR_CREATEBRUSHINDIRECT and EMR_EXTCREATEPEN read in their EMF layout (FPC 3.2.2 on Win64)

Impact

PDF conversion on FPC 3.2.2 Win64 no longer renders every indirect brush and extended pen as black. Delphi and newer FPC layouts keep the same result and require no caller changes.

Sven Harazim · 08:42 UTC · view the commit on GitHub →

15 Medium Stock-font ANSI text uses the font’s own Windows code page mormot.ui.pdf adds the public FontCharSetCodePage and StockFontCodePage helpers. TPdfEnum uses GetObjectW to derive a selected stock font’s charset, then decodes EMR_EXTTEXTOUTA bytes with that charset’s code page instead of assuming CP_ACP, except for documented fallbacks. Compiler & platform mormot.ui.pdf 2fcdaf61+59-17

ui: pdf - a stock font reads its bytes in the code page of its own charset

Impact

On Windows systems whose ANSI page is not 1252, stock-font text in exported PDFs is decoded correctly. Delphi and FPC gain two source-compatible helper functions; existing signatures are untouched.

Worth a look

Retest EMR_EXTTEXTOUTA output that selects ANSI_FIXED_FONT, ANSI_VAR_FONT, OEM_FIXED_FONT or locale-specific system fonts.

Public API

  • FontCharSetCodePageadded — Public helper maps a Windows font charset to the code page used by ExtTextOutA.
  • StockFontCodePageadded — Public helper resolves the code page of a Windows stock font.

Sven Harazim · 10:13 UTC · view the commit on GitHub →

16 Medium FPC Win64 GDI+ conversion reads EMF brush and pen records correctly mormot.lib.gdiplus adds compiler-independent TEmrCreateBrushIndirect32 and TEmrExtCreatePen32 layouts. CreatePenObj and brush creation read those fixed-width records instead of FPC 3.2.2 Win64’s pointer-sized declarations. Compiler & platform mormot.lib.gdiplus 3ca285f1+51-9

gdiplus: EMR_CREATEBRUSHINDIRECT and EMR_EXTCREATEPEN read in their EMF layout (FPC 3.2.2 on Win64)

Impact

GDI+ EMF preview on FPC 3.2.2 Win64 no longer turns indirect brushes black or misreads extended pens. Delphi and newer FPC builds keep compatible behaviour.

Sven Harazim · 06:03 UTC · view the commit on GitHub →

17 Low AlphaBlend records no longer turn pure blue pixels transparent TPdfEnum stops passing the EMR_ALPHABLEND BLENDFUNCTION value to DrawBitmap as if it were a transparent colour. The record is rendered opaque for now; constant and per-pixel alpha remain unsupported. Fixes mormot.ui.pdf 618e24d5+151-1

ui: pdf - EMR_ALPHABLEND draws its bitmap opaque (#673, row 15)

Impact

Opaque AlphaBlend bitmaps no longer acquire holes where pixels happen to match the packed blend value. Delphi and FPC APIs are unchanged, but true alpha blending is still unavailable.

Sven Harazim · 08:41 UTC · PR #673 · view the commit on GitHub →

18 Low RestoreDC honours the requested depth beyond 32 saved states TPdfEnum replaces its fixed 32-slot DC array with a dynamically grown stack. RestoreDC now consumes the record’s negative iRelative value, ignores invalid targets as GDI does and restores the named state rather than always popping one. Fixes mormot.ui.pdf 450a3e83+77-9

ui: pdf - EMR_RESTOREDC restores the state it names, however deep (#673, row 17)

Impact

Deeply nested EMF save/restore sequences now recover the intended graphics state. Delphi and FPC application code is unaffected; generated PDFs differ only for such metafiles.

Sven Harazim · 08:41 UTC · PR #673 · view the commit on GitHub →

19 Low PS_NULL pens stop drawing in GDI+ EMF previews CreatePenObj now assigns handle 0 to EMR_CREATEPEN and EMR_EXTCREATEPEN records whose style is PS_NULL, matching the stock NULL_PEN. It no longer creates a visible solid GDI+ pen from their colour and width. Fixes mormot.lib.gdiplus 169490f1+73-3

gdiplus: a PS_NULL pen draws nothing

Impact

Shapes intended to have no outline no longer gain one in GDI+ EMF conversion. There is no source-level effect for Delphi or FPC callers.

Sven Harazim · 06:03 UTC · view the commit on GitHub →

20 Low EMF poly-polylines remain open in PDF output TPdfEnum.PolyPoly closes only EMR_POLYPOLYGON and EMR_POLYPOLYGON16 figures. EMR_POLYPOLYLINE and EMR_POLYPOLYLINE16 no longer receive an extra segment back to each subline’s first point. Fixes mormot.ui.pdf f768636f+55-2

ui: pdf - the polylines of EMR_POLYPOLYLINE stay open (#673, row 16)

Impact

Multi-part polylines exported from EMF no longer become closed polygons. There is no application-code impact for Delphi or FPC; only the rendered path changes.

Sven Harazim · 08:41 UTC · PR #673 · view the commit on GitHub →

21 Low The Win32 PDF metafile checksum now matches the corrected box geometry MetafileRenderingAndOrientation updates its Delphi Win32, code-page-1252 expected hash from FE2D27CA to 456748FC. The fixture change records the one-device-pixel rectangle and ellipse correction from pull request 686. Tests 78501a4a+1-1

test: ui pdf - the expected hash of the metafile rendered since #686

Impact

This is a test expectation only and introduces no additional runtime or API change for Delphi or FPC applications.

Sven Harazim · 08:41 UTC · PR #686 · view the commit on GitHub →

Upstream activity commits per day · last 60 days
Commits1007
Active days49/60
Busiest2026-09-30
Peak60
2026-09-30: 60 commits2026-10-01: 26 commits2026-10-02: 30 commits2026-10-03: 32 commits2026-10-04: 15 commits2026-10-05: 1 commit2026-10-06: 26 commits2026-10-07: 37 commits2026-10-08: 27 commits2026-10-09: 35 commits2026-10-10: 12 commits2026-10-11: 2 commits2026-10-12: 40 commits2026-10-13: 31 commits2026-10-14: 23 commits2026-10-15: 16 commits2026-10-16: 27 commits2026-10-17: 0 commits2026-10-18: 0 commits2026-10-19: 0 commits2026-10-20: 0 commits2026-10-21: 0 commits2026-10-22: 3 commits2026-10-23: 6 commits2026-10-24: 29 commits2026-10-25: 7 commits2026-10-26: 25 commits2026-10-27: 4 commits2026-10-28: 8 commits2026-10-29: 17 commits2026-10-30: 20 commits2026-10-31: 0 commits2026-11-01: 0 commits2026-11-02: 16 commits2026-11-03: 32 commits2026-11-04: 15 commits2026-11-05: 32 commits2026-11-06: 26 commits2026-11-07: 19 commits2026-11-08: 2 commits2026-11-09: 29 commits2026-11-10: 17 commits2026-11-11: 8 commits2026-11-12: 38 commits2026-11-13: 39 commits2026-11-14: 9 commits2026-11-15: 6 commits2026-11-16: 21 commits2026-11-17: 30 commits2026-11-18: 37 commits2026-11-19: 28 commits2026-11-20: 31 commits2026-11-21: 0 commits2026-11-22: 0 commits2026-11-23: 1 commit2026-11-24: 6 commits2026-11-25: 3 commits2026-11-26: 3 commits2026-11-27: 0 commits2026-11-28: 0 commits
2026-09-302026-11-28