358 Commits
Author SHA1 Message Date
Caolán McNamara 37fd5b78b0 ofz#541854037 Timeout
the polygon point counts were checked against the space left in the
whole file, and a small record inside a large file could claim far
more points than it holds

so bound them by the size of the record instead

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I0770546d0d48f9b306461da5e9c0117977079483
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/12367
Reviewed-by: Noel Grandin <noel.grandin@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit 292bae6e2ee1d8749040b258cd7bf415cf6241b4)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211410
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-09-24 11:01:20 +02:00
Caolán McNamara c850b5eef5 wmf: initialize each palette entry and stop reading on stream failure
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I2f2449be83cd7d895726e2200cae15d276a0eccf
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/7869
Reviewed-by: Noel Grandin <noel.grandin@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit c0a67cf1a5e07a28db14c9309e9fde70984ab1a2)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/208699
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-07-28 10:13:29 +02:00
Caolán McNamara 552712e5df ofz: emfio, remember where the first free object slot is
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: Iadc79d94c1741167641781cdb0cc455d32385219
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/7858
Reviewed-by: Noel Grandin <noel.grandin@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit 0066c2a9ad09f6372fd9073aecba049ebce8dc7c)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/208698
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-07-28 10:13:24 +02:00
Caolán McNamara 1705455b10 ofz: emfio, return early for bogus comment counts
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: Ib745f2126b090135db4739925c21b9335bd91ab3
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/7850
Reviewed-by: Noel Grandin <noel.grandin@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit 250b57ce97f121eb02044143c9f7a805be553655)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/208697
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-07-28 10:13:19 +02:00
Caolán McNamara 6c9a60a12a ofz: emfio, return early for bogus Polygon nextpos
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I5c91676d924cd1e92baa359464c4147509a59832
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/7848
Reviewed-by: Noel Grandin <noel.grandin@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit 0021f4cfbbd204f824a3b2c0b3085c29c597831f)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/208696
Tested-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-07-28 10:13:15 +02:00
Caolán McNamara 881df727c1 ofz: emfio, return early if stream can't supply bitmap data
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: Iaba0db498fe014c5dc7acb04f0de2da7f6bfe1f7
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/7846
Reviewed-by: Noel Grandin <noel.grandin@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit 5ac7255f58fd7ab737e74274372e9c8ca8868a0e)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/208692
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Tested-by: Jenkins
2026-07-28 10:12:45 +02:00
Khaled Hosny ef3c39851d vcl: Rename Font::Set/GetAverageFontWidth to Set/GetFontWidth
It is a misnomer now, so return to the original name.

Also drop the redundant private Font::GetAverageFontSize().

Change-Id: I67495fa675091b459a4e90ac09665489cc61fdd9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/207991
Tested-by: Jenkins
Reviewed-by: Khaled Hosny <khaled@libreoffice.org>
2026-07-14 00:16:59 +02:00
Khaled Hosny aa1e992c23 vcl: Scale stretched fonts relative to the height on Windows
The font width used to mean the average character width on Windows,
like GDI’s LOGFONT lfWidth. This complicates things cross-platform, and
also DirectWrite does not expose such info.

Drop the whole average character width nonsense and align Windows to
other platforms, keeping the already existing cross-platforms
workarounds for EMF/WMF that are now applied also to Windows.

Change-Id: I750d42ad090bb9d0f776e80609b7a67b8ac38aac
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/207990
Reviewed-by: Khaled Hosny <khaled@libreoffice.org>
Tested-by: Jenkins
2026-07-14 00:16:49 +02:00
Xisco Fauli 3e607e03a4 cid#1693963: Unintended sign extension
Change-Id: I246a3f8b18143a5e62806bde8b4152f9f62468ca
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/207950
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Tested-by: Jenkins
2026-07-12 17:47:58 +02:00
Caolán McNamara b5953116c4 ofz: skip checksum check when fuzzing
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I7404322dc9cd8b7e6e4595b3867a6bf42c83b056
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/6115
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit 5c1fa7bf1ff8c2a28fba70804b41fa02e5c59c82)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/207657
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-07-06 13:56:37 +02:00
Caolán McNamara 4406da79b0 ofz: ignore an advance array shorter than the string
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I6ceec1ecbae58a714d2f45eb786e01b428e6d942
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/6114
Reviewed-by: Noel Grandin <noel.grandin@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit 6ab602ca281f507f7e637183a49dd514ffb1376b)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/207656
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-07-06 13:13:59 +02:00
Andras Timar 0447d0cc95 emfio: null-check VectorGraphicData before dereferencing in MULTIFORMATS
ReadMultiformatsComment dereferenced aGraphic.getVectorGraphicData()
unconditionally to call setSizeHint, then a few lines later acquired
the same pointer into a local and checked it for null. Reorder so
the null check happens before the first use, and reuse the local
for getType() too.

vcl::ImportPDF always installs a non-null VectorGraphicData on
success today, so this is defensive against future changes (or
edge-case ImportPDF backends that succeed without producing one)
rather than a fix for a confirmed crash. The macOS dbgutil
tinderbox report for tdf#167641 was not reproducible on two
separate macOS boxes, so the underlying issue could not be
diagnosed; this guard is the conservative belt-and-braces change.

Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: I2569f26b099f305dd98b94ef4e9ab5c9a20fef11
(cherry picked from commit 36b0369ad6205aa7383ff4e93214853ea1081d61)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/206642
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-06-16 01:19:22 +02:00
Andras Timar c043f65f66 tdf#167641 emfio: render PDF in EMR_COMMENT_MULTIFORMATS with Version=0
MS Office writes the EmrFormat.Version field as 0 in the
EMR_COMMENT_MULTIFORMATS record carrying an embedded PDF. Per
[MS-EMF] 2.3.3.4.2 EmrFormat, Version MUST be 0x00000001 only when
Signature == EPS_SIGNATURE; for any other signature it MUST be
ignored. The reader rejected anything but 1, so the embedded PDF
was dropped on the floor.

Real-world files also use an empty OutputRect (0,0,0,0); per
[MS-EMF] 2.3.3.4.3 it is in logical coordinates, so fall back to
the EMF's logical bounds (mrclBounds) when it is degenerate, so
ResolveBitmapActions has somewhere to draw the PDF bitmap.

The new fixture is the existing pdf-in-emf.pptx EMF with the two
fields patched to reproduce the regression in 776 bytes.

Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: I432f75a1cac11d84448db07c1a1815cd0be60744
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/1904
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit a5d7b2935718bf7f1f6cc0352c8d8681e6713f4b)
Cherry-pick note: the test fails on macOS in CI
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205084
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-05-13 09:57:03 +02:00
Caolán McNamara db72fb12d7 ofz: Use-of-uninitialized-value
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I5def88bee741c3792af724d1ad41585ee560c535
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/2352
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit 8828bfc6c41a8e64121a69ec7b995be4a12961fc)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205115
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-05-13 00:59:28 +02:00
Andras Timar d271bc432b tdf#116623 emfio: apply RGN_COPY region data in EMR_EXTSELECTCLIPRGN
[MS-EMF] 2.3.2.2 says the RegionData field "MUST be ignored" when
iMode is RGN_COPY, but real EMFs include data with RGN_COPY and
expect the clip to be replaced with the given region (verified
against MS Word reference rendering of test files such as
TestCreatePen.emf and a chart EMF where the colored plot lines
were leaking outside the plot frame). Treat the record like the
Win32 ExtSelectClipRgn API: a non-NULL region with RGN_COPY
replaces the clip, a NULL region (cbRgnData == 0) with RGN_COPY
resets the clip to the default null region.

Add a minimal hand-crafted EMF (TestExtSelectClipRgnCopy.emf) that
draws a (0,0)-(200,200) rectangle through a (50,50)-(150,150)
RGN_COPY clip and asserts the imported metafile wraps the rectangle
in a clip-region mask matching the requested rectangle.

Update existing test expectations to reflect the new clip-region
group/mask wrappers that now appear in the metafile primitive tree
where RGN_COPY data is present (testCreatePen, testPolyPolygon,
testTextMapMode, testEmfPlusSetPageTransform,
testDrawImagePointsWithMetafile, testSine).

Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: Id123157b64b75d817b4736443eac14804b04bb89
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/2206
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit 1c2ff94b6079451a7047a2afb45467d6fe31cb4f)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205072
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2026-05-12 07:40:42 +02:00
Andras Timar 6bfe01ec89 emfio: handle pattern brush in non-rectangular shape primitives
DrawPolygon and DrawRect already route Pattern fill style through
ImplEmitPatternFill, but DrawEllipse, DrawRoundRect, DrawPie,
DrawChord, and DrawPolyPolygon still emit their plain Meta*Action
which leaves the shape unfilled. Route Pattern fill through the
helper for those too, converting the shape to its polygon
equivalent and emitting the clipped MetaWallpaperAction.

Add a unit test that draws an ellipse with a DIB pattern brush and
asserts the wallpaper is emitted in the metafile dump. Without the
fix the ellipse renders as a hairline outline only.

Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: I2d4e273029770ddc727bc24d9b3205fe079fafd6
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/2205
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit e87013a0457d270d442841610f4a3430e82f1274)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205041
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-05-11 12:25:29 +02:00
Andras Timar 7ed015807a emfio: invalidate fill style cache on SETBKMODE for hatched brushes
UpdateFillStyle short-circuits when maLatestFillStyle == maFillStyle,
but for a hatched brush the emitted MetaFillColorAction depends on
mnBkMode (bk color when OPAQUE, transparent when TRANSPARENT). With
no brush change between two rectangles separated only by SETBKMODE,
the second rectangle inherits the previous OPAQUE bk color fill, so
the gaps between hatch lines stay opaque.

Make SetBkMode invalidate maLatestFillStyle.aFillColor (using the
same sentinel that ResetInternalState uses) when the mode actually
changes, forcing the next UpdateFillStyle to re-emit a fresh
MetaFillColorAction with the correct bk-mode-dependent fill.

Add a unit test with a minimal hand-crafted WMF that draws two
rectangles using the same hatched brush across a SETBKMODE flip
and asserts that both a #ff0000 (OPAQUE bk color) and a #000000
(TRANSPARENT) fillcolor are emitted in the metafile.

Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: I34b8984989f3ce9108464ad5a8c379174a988b59
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/2204
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit 41ddf034e276a5493f4fd56be61702a8b28e9649)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205040
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-05-11 11:57:59 +02:00
Andras Timar acc568fd2a emfio: render WMF DIB pattern brushes as tiled bitmap fills
META_DIBCREATEPATTERNBRUSH with Style=BS_PATTERN was dropped on the
floor with a SAL_WARN, and BS_DIBPATTERN averaged the bitmap to a
solid color, so neither produced a real pattern fill. Read both
variants into a real Bitmap (DIB or, for BS_PATTERN, a 1bpp Bitmap16)
and store it as a Pattern WinMtfFillStyle. Real-world generators
emit a DIB even with Style=BS_PATTERN, so peek the leading DWORD to
decide between DIB and Bitmap16. The same Bitmap16 helper handles
the obsolete META_CREATEPATTERNBRUSH record (32-byte legacy BITMAP +
reserved padding per MS-WMF 2.3.4.4).

The Pattern fill type was only handled in DrawPolygon, and that path
emitted XPATHFILL_SEQ_BEGIN/END comments with no actual paint
primitives. wmfemfhelper does not consume those comments, so the
PNG/drawinglayer rendering path saw nothing. Replace the comment
emission with a clip-region wrapped MetaWallpaperAction (Tile style)
which is fully consumed downstream. Factor the emission into
ImplEmitPatternFill and call it from DrawRect too, where Pattern
was previously not handled at all.

WinMtfFillStyle::operator== did not compare aBmp, so successive
pattern brushes with different bitmaps but identical solid-fill
fields compared equal and UpdateFillStyle short-circuited, leaving
maLatestFillStyle pointing at the previous bitmap. Include aBmp in
the equality check.

Add a unit test with a minimal hand-crafted WMF that asserts the
expected wallpaper sequence in the metafile dump.

Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: Ia2662de9cac5fcf1a7153237f9974467b8f849de
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/2203
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit 66dcbef6b5ceec8d9ccd4542509d5f9d7fdce2c1)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205039
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-05-11 11:34:08 +02:00
Caolán McNamara c8f5c789e8 ofz: Use-of-uninitialized-value
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: Ia4aca5af7e5de2e27492135e37a49540c62f09a1
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/1940
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit d21827b4c295afcd9aef02b2a5b725d1dd2f9711)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204882
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2026-05-09 12:47:00 +02:00
Caolán McNamara fa0d87b427 ofz#496751918 Out-of-memory
Change-Id: Ie0a3857669f8283a6d15460cbcd8453b6c3325b0
Reviewed-on: https://gerrit.collaboraoffice.com/c/core/+/1057
Reviewed-by: Noel Grandin <noel.grandin@collabora.com>
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit a7f72dd3b242e6390169bfe0131e7e31a87ceeec)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204400
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-04-27 16:04:31 +02:00
Caolán McNamara cc32ab7342 ofz#496349582 Integer-overflow
Change-Id: I537f96838f402f20b537440a5cf94967814a64ce
Reviewed-on: https://gerrit.collaboraoffice.com/c/core/+/1052
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
(cherry picked from commit 4c4f052a5f3700c332ede70bc71dda3529266ba5)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204398
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Tested-by: Jenkins
2026-04-27 16:03:44 +02:00
Andras Timar 14be550da2 emfio: implement BS_HATCHED brushes and pens
Handle BS_HATCHED brush style in EMR_CREATEBRUSHINDIRECT,
W_META_CREATEBRUSHINDIRECT, and EMR_EXTCREATEPEN.

For brushes (hatch indices 0-5), map Windows hatch styles
(HS_HORIZONTAL..HS_DIAGCROSS) to VCL Hatch objects and emit
MetaHatchAction in all polygon/polypolygon fill paths.

For EMF-specific hatch indices 6-11, use the appropriate color
source per [MS-EMF] 2.1.17: brush color (6-7), text color (8-9),
or background color (10-11) as solid fills.

For wide geometric pens with BS_HATCHED (EMR_EXTCREATEPEN),
create stroke area geometry via createAreaGeometry and render
the hatch pattern inside the pen stroke area, replacing the
normal MetaPolyLineAction/MetaLineAction. This covers all
drawing paths including LineTo, DrawPolyLine, DrawPolygon,
DrawPolyPolygon, DrawRect, DrawRoundRect, DrawEllipse, DrawArc,
DrawPie, DrawChord, DrawPolyBezier, and StrokeAndFillPath.

Change-Id: Ie8482ac53b6d4d263793488ce10a97fa1716c68d
Reviewed-on: https://gerrit.collaboraoffice.com/c/core/+/325
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit 8808d550d12afb3e7abc4fe6a3145d80fc5bdde4)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204389
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Tested-by: Jenkins
2026-04-27 08:58:20 +02:00
Andras Timar 857fd268e8 emfio: implement EMR_SETPOLYFILLMODE and W_META_SETPOLYFILLMODE
The polygon fill mode (ALTERNATE vs WINDING) was ignored in both EMF
and WMF readers.  ALTERNATE (even-odd) is the default; WINDING
(non-zero winding) appears in 2541/6939 EMF files and 135/467 WMF
files that set the mode.  Self-intersecting polygons like pentagram
stars render differently under the two rules.

Store the fill mode state in MtfTools with save/restore in Push/Pop,
wire up the record handlers, and fix the hardcoded fillNonZero in
DrawPolygon pattern fills to respect the current mode.

Add a unit test with a pentagram star EMF using WINDING mode.

Change-Id: I1d9127b79cc6c3b67f39bebe2c82e806c9db4ce8
Reviewed-on: https://gerrit.collaboraoffice.com/c/core/+/324
Tested-by: Andras Timar <andras.timar@collabora.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204388
Tested-by: Jenkins
2026-04-27 08:58:11 +02:00
Andras Timar d8f87cb61f emfio: implement EMR_GRADIENTFILL for rectangle modes
Read the TriVertex array and GradientRectangle indices, then emit
MetaGradientAction with a linear gradient for each rectangle pair.

- GRADIENT_FILL_RECT_H (0): horizontal, left-to-right
- GRADIENT_FILL_RECT_V (1): vertical, top-to-bottom
- GRADIENT_FILL_TRIANGLE (2): logged as TODO (Gouraud shading has
  no direct VCL primitive)

COLOR16 values are converted to 8-bit via >> 8; Alpha is ignored
per the [MS-EMF] spec.

Change-Id: I9bb525eb16fe63908b0160ff029c270765edda15
Reviewed-on: https://gerrit.collaboraoffice.com/c/core/+/323
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
(cherry picked from commit b13431518550e387318190b6827eaf10427aa745)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204387
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-04-27 08:58:03 +02:00
Andras Timar c80a393bc7 emfio: implement EMR_CREATEMONOBRUSH
same structure as CREATEDIBPATTERNBRUSHPT

Change-Id: Iaf8129c6150df4e5786eeb0676e7e19a9bb041d2
Reviewed-on: https://gerrit.collaboraoffice.com/c/core/+/322
Tested-by: Andras Timar <andras.timar@collabora.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit 838c5c042b817006b889b7ebd00a8ec2d14365fa)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204386
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-04-27 08:57:56 +02:00
Andras Timar 2ac3353184 emfio: implement EMR_EXCLUDECLIPRECT
Wire up EMR_EXCLUDECLIPRECT (record type 29) in the EMF reader.
ExcludeClipRect() was already implemented in MtfTools and used by the
WMF reader, but missing from the EMF record dispatch. This record
subtracts a rectangle from the current clipping region, creating a
"hole" that prevents drawing in that area.

Present in 291 of 6,939 real-world EMF files (4.2%).

Change-Id: I7bff53473c19453605e5fd88fdeff101f213fd85
Reviewed-on: https://gerrit.collaboraoffice.com/c/core/+/320
Tested-by: Andras Timar <andras.timar@collabora.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit 38e963b2b4b12471b2530e11208a543f403bf4f2)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204247
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-04-27 01:03:44 +02:00
Andras Timar f7cc19ac92 emfio: rename EMR_ALPHADIBBLEND to EMR_SETLAYOUT and log non-zero values
Record 115 (0x73) was incorrectly named EMR_ALPHADIBBLEND, from a
pre-Windows 2000 draft of the EMF spec. The final [MS-EMF] spec defines
it as EMR_SETLAYOUT, which controls the DC layout direction (LTR/RTL).

For now just rename and log when a non-zero LayoutMode is encountered
(SAL_WARN), so we can observe real-world usage before deciding how to
implement the actual coordinate mirroring and text direction changes.

6939 EMF files from public bug trackers were analyzed, 2143 files
contained EMR_SETLAYOUT but none of them contain LayoutMode other
than 0.

Change-Id: Ic4116fcd4a079d09684deb792e2f0ddc646248eb
Reviewed-on: https://gerrit.collaboraoffice.com/c/core/+/319
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
(cherry picked from commit ab2b4437b178d5d397844cfeeeff43fd88b5cc9f)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204246
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Tested-by: Jenkins
2026-04-27 01:03:37 +02:00
Andras Timar 5db6c203f3 tdf#168107 emfio: render ETO_GLYPH_INDEX text as glyph outlines
also tdf#137440 and tdf#102780

EMF files with pre-shaped text (e.g. Arabic) use ETO_GLYPH_INDEX in
EMR_EXTTEXTOUTW records. The string data in these records contains
font-specific glyph indices (16-bit IDs), not Unicode codepoints.

Previously, emfio read these glyph indices as Unicode text via
read_uInt16s_ToOUString, then passed them to DrawText which creates
a MetaTextArrayAction. On playback, VCL/HarfBuzz would shape these
fake "characters" again, producing double-shaped garbage output.

Fix this by detecting ETO_GLYPH_INDEX and rendering the pre-shaped
glyphs as filled polypolygon outlines, bypassing text shaping entirely.

Implementation:

- Add OutputDevice::GetGlyphOutlines() as a new VCL public API that
  takes raw glyph IDs and returns per-glyph B2DPolyPolygon outlines
  by calling LogicalFontInstance::GetGlyphOutline() directly. This is
  needed because LogicalFontInstance is in VCL's private headers and
  not accessible from emfio.

- Add MtfTools::DrawGlyphs() in emfio that mirrors the DrawText()
  setup (position/DX/DY mapping, font/color/alignment MetaActions)
  but instead of emitting MetaTextArrayAction, it obtains glyph
  outlines via GetGlyphOutlines() on a VirtualDevice, positions each
  glyph using the DX/DY array, and emits the combined result as a
  filled MetaPolyPolygonAction with the text color.

- Branch in emfreader.cxx: when ETO_GLYPH_INDEX is set on the Unicode
  variant (EMR_EXTTEXTOUTW), read glyph indices as sal_uInt16 values
  and call DrawGlyphs() instead of DrawText().

- Since glyph indices are font-specific, DrawGlyphs() checks font
  availability via IsFontAvailable() before rendering. If the required
  font is not installed, it returns false and the code falls back to
  the standard DrawText() path (same as before this change).

- Remove the stale SAL_WARN_IF for ETO_PDY|ETO_GLYPH_INDEX, since
  both flags are now handled.

Change-Id: Ib6e0a0b1accfe61ff871c391d02f4c529764438c
Reviewed-on: https://gerrit.collaboraoffice.com/c/core/+/318
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit b260c2a6d8313c80720e34a366f01bcd0e429f47)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204245
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Tested-by: Jenkins
2026-04-24 15:50:37 +02:00
Noel Grandin e77b23fa1c Fraction->double in MapMode
Change-Id: I865fe1c2b0377eebda6f9f19e163928cbe7c9056
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/202631
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2026-03-26 13:23:37 +01:00
Bartosz Kosiorek 3407985249 tdf#103859 emfio: Update variable types to match EMF specification
This patch corrects several variable types across the EMF reader
to strictly align with the official Enhanced Metafile specification,
improving memory safety and fixing minor logging bugs.

Change-Id: I1cc1351248bcdb40220c33441e363aaa226f1ea1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/202625
Tested-by: Jenkins
Reviewed-by: Bartosz Kosiorek <gang65@poczta.onet.pl>
2026-03-24 19:52:59 +01:00
Caolán McNamara d70bf770a8 ofz#494703925 Out-of-memory, etc
possibly since:

commit aad62f783b
Date:   Sun Feb 8 12:09:12 2026 +0100

    tdf#142226 emfio: implement EMR_SMALLTEXTOUT

Change-Id: Ic45575e9993a1f16e9221418c421a3f2500ded27
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/202387
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
2026-03-23 10:04:13 +01:00
Bartosz Kosiorek f0a3081314 tdf119973 tdf160063 emfio: Reset GDI trackers on EMF+ GetDC record
When an EMF+ Dual Mode file switches back to GDI records via
EmfPlusRecordType::GetDC (0x4004), the GDI parser (MtfTools)
might have outdated information about the current state of the
VCL MetaFile, as EMF+ records could have modified it in the meantime.

By introducing ResetInternalState(), we invalidate the "latest"
trackers for fill style, line style, and text attributes. This
forces the parser to re-emit the necessary GDI actions (like
SetFillColor) for the subsequent GDI records, preventing issues
like incorrect colors (e.g., black shapes instead of white).

Change-Id: I1665daba2d9a2105f135e2b638af48d2b14150eb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201720
Tested-by: Jenkins
Reviewed-by: Bartosz Kosiorek <gang65@poczta.onet.pl>
2026-03-15 17:46:51 +01:00
Andrea Gelmini 6cdefb0806 Fix typo
Change-Id: Ibf6a768e07ee7892b74264732a261e364e13cfac
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199966
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Tested-by: Jenkins
2026-02-26 18:26:23 +01:00
Caolán McNamara 3dfbc9df7d ofz: Use-of-uninitialized-value
there's a switch off this value before the mpInputStream->good() guard

Change-Id: I8ac7ce45336d9edbfae2308af39632c9322b2526
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199992
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
2026-02-22 20:42:22 +01:00
Bartosz Kosiorek b6857c1f16 tdf#138087 tdf#142548 EMF Fix font scaling and orientation in GM_COMPATIBLE
When importing EMF files, certain records (like EXTTEXTOUTW) in
GM_COMPATIBLE mode were not respecting non-proportional scaling
or single-axis mirroring. This resulted in text that was too wide/narrow
or rotated in the wrong direction.

Key changes:
- Added font width scaling based on the ratio between fXScale and fYScale.
- Handled 180-degree rotation when both axes are negative.
- Corrected font orientation for single-axis mirroring by inverting the
  angle (3600 - orientation) to compensate for the reversed chirality
  of the coordinate system.

Change-Id: Ib1126c192a80b973f343f25bf20ec119d94d71a8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199770
Tested-by: Jenkins
Reviewed-by: Bartosz Kosiorek <gang65@poczta.onet.pl>
2026-02-21 08:30:48 +01:00
Andras Timar aa616d930e Revert tdf#159306 EMF: fix PS_COSMETIC pen width regression
Commit be9d6e414e4b forced all PS_COSMETIC pen widths to 1 in both
EMR_CREATEPEN and EMR_EXTCREATEPEN handlers. Since PS_COSMETIC is
0x00000000 (same value as PS_SOLID), the check
"if (nPenStyle == PS_COSMETIC)" matched every simple PS_SOLID pen,
causing all line widths to be lost. This made all lines render as
hairlines regardless of the actual width specified in the EMF file.

The style sanitization check for invalid PS_STYLE_MASK values is
retained, but the width forcing is removed. Pen widths from the
file are now used as-is: width=0 produces a hairline, width>=1
produces a scaled line. This effectively reverts to the behavior
established by tdf#140271 (commit 8932c8906ff3), which recognized
that real-world EMF producers use EMR_CREATEPEN with widths > 1
and expect them to be honored.

Change-Id: I9a3acf83ce03b4e646e9b95fe0db54f8ce403a49
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198904
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Jenkins
2026-02-09 06:43:06 +01:00
Andras Timar aad62f783b tdf#142226 emfio: implement EMR_SMALLTEXTOUT
Change-Id: Ib031c0d771045b80c99274974de8267e759e8557
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198903
Tested-by: Jenkins
Reviewed-by: Andras Timar <andras.timar@collabora.com>
2026-02-08 19:20:56 +01:00
Andras Timar eddbe3b36d tdf#126965 emfio: fix opaque background on underlined text...
when BkMode is TRANSPARENT

In DrawText, the font's fill color was unconditionally set to maBkColor
before checking the background mode. When BkMode is TRANSPARENT, VCL's
underline rendering uses the font's fill color directly, ignoring the
transparency flag, causing an unwanted opaque background behind
underlined text.

Set COL_TRANSPARENT as the fill color when BkMode is TRANSPARENT, and
only use maBkColor when OPAQUE.

Change-Id: I0e94d2a1beae8ce2feecb0f7c0f8e03b36d2d80a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198889
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Jenkins
2026-02-07 23:43:38 +01:00
Gabor Kelemen 47fe1cce1b tdf#146619 Use more forward declarations in include/vcl/[h-p]*
Found after running bin/find-unneeded-includes --headersfwd include/vcl/[n-p]*

Change-Id: If6436f3ef8300693c3869c2521e2fa2aa8a4edc8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196397
Tested-by: Jenkins
Reviewed-by: Gabor Kelemen <gabor.kelemen@collabora.com>
2026-01-14 10:19:31 +01:00
Gabor Kelemen b63115f3fa tdf#146619 Use more forward declarations in include/vcl/[d-g]*
Found after running bin/find-unneeded-includes --headersfwd include/vcl/[d-g]*

This shaves off about 150M input

Change-Id: I2b15257451d4b392dca3e5d07f4a443ee653b04c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196395
Tested-by: Jenkins
Reviewed-by: Gabor Kelemen <gabor.kelemen@collabora.com>
2026-01-11 21:38:37 +01:00
Caolán McNamara cd48c84319 ofz#472735025 Integer-overflow
Change-Id: If7b76626d43435d4e079a11080b87c76f8b5db81
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196420
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
2026-01-02 20:03:34 +01:00
Noel Grandin 4e2b089020 loplugin:stringloop
resurrect the plugin and run it over the codebase

Change-Id: I443a75961124aabd1e62b3c4bc166d52e4621b52
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194870
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins
2025-12-01 14:25:01 +01:00
Noel Grandin c2a0e06b63 new loplugin:stringplusequal
which simplifies O[U]String expressions like
   A = A + foo
into
   A += foo

mostly because then they get spotted by other string plugins.

Change-Id: I2b81b701144acdf18743b52cb0befa7f90fd9528
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194191
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2025-11-20 07:26:33 +01:00
Caolán McNamara 3b4b323c7f cid#1667077 Variable copied when it could be moved
Change-Id: I142c97c8e392770ae4a66f0945b580c1d141e5ef
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192370
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Tested-by: Jenkins
2025-10-14 14:16:46 +02:00
Caolán McNamara 8788657853 drop some more COVERITY stuff
Change-Id: Ib2ac522e2ae5143fee86cb93f1e779f241129087
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192153
Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
2025-10-10 11:13:00 +02:00
Bartosz Kosiorek b33cc5a738 tdf#159306 WMF/EMF Fix PS_COSMETIC lines display
Change-Id: I3a2572a76aae61bcf8552e4623168cd72411373a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190816
Tested-by: Jenkins
Reviewed-by: Bartosz Kosiorek <gang65@poczta.onet.pl>
2025-09-12 00:46:24 +02:00
Noel Grandin 6d0e5ddede remove BitmapEx
all use-sites have been converted to Bitmap

Change-Id: I1a8842217a266eef100bd387ab013b004e532256
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190618
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins
2025-09-05 19:45:45 +02:00
Bartosz Kosiorek cd410d0f38 tdf#103859 EMF Fix size of the corners in ROUNDRECT record
After EMF_ROUNDRECT rendering comparison of Office 365 and
Libreoffice, it appears that radius of corners in LO is twice too large.
EMF_ROUNDRECT implementation has to be aligned and
conversion from ellipse width and height to ellipse vertical
and horizontal radius have been applied (values was divided by 2).

After apply this patch the ROUNDRECT looks identical as in Office.

The issue is also visible in previous version of LO (24.2.7).

Change-Id: I861fcd0e8d8a39d946215cc08ecc95403cd23fad
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190391
Reviewed-by: Bartosz Kosiorek <gang65@poczta.onet.pl>
Tested-by: Jenkins
2025-08-31 04:49:40 +02:00
Noel Grandin f6a200a970 BitmapEx->Bitmap in emfio
now that Bitmap supports transparency

Change-Id: I6af3dce6d6dcb79aebb7aaa9a9dbebf0264b493a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190417
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2025-08-30 22:01:49 +02:00
Noel Grandin 3ab47e263e BitmapEx->Bitmap in MetaBmpExScaleAction
now that Bitmap supports transparency

Disable part of the redaction test. I have
verified that the visual result of auto-image redaction
is the same before and after this change, but we
seem to end up with more rectangles than before.

Probably something weird inside the EMF/WMF machinery.
(see the fixMetaFile function).

Change-Id: I85f308ae66ddf7592e41fde1ab9e49f9c882146e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190338
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2025-08-29 17:52:53 +02:00