Commit graph

8271 commits

Author SHA1 Message Date
calixteman
b13698ff65 Merge branch 'issue907' into 'master'
Fix invalid pdf generation with too many objects in object stream

See merge request cairo/cairo!642
2026-04-03 07:29:19 +00:00
Luca Bacci
1adaf1e7c5 recording surface: Implement finish via reset
Rather than the other way round.

Fixes #928
2026-03-02 18:51:00 +01:00
Emmanuele Bassi
7cd2141f09 Merge branch 'dwrite' into 'master'
DWrite: Add support for COLRv1 fonts

Closes #903

See merge request cairo/cairo!625
2026-03-02 10:08:30 +00:00
Behdad Esfahbod
f0674b4c98 [rectanble Handle overflow in _cairo_box_from_doubles 2026-02-07 13:01:49 -07:00
Albert Astals Cid
b94bf30f03 _cairo_pdf_surface_finish: Fix leak in error conditions
Make sure surface->object_stream.stream is cleaned up even if things
failed

In poppler oss-fuzz tests we are getting this leak reported

Direct leak of 64 byte(s) in 1 object(s) allocated from:
	    #0 0x5747417eabd9 in __interceptor_calloc /src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:74:3
	    #1 0x574742706f5b in _cairo_memory_stream_create cairo/src/cairo-output-stream.c:741:14
	    #2 0x5747426757b8 in _cairo_pdf_surface_open_object_stream cairo/src/cairo-pdf-surface.c:2307:34
	    #3 0x57474266b880 in _cairo_pdf_surface_finish cairo/src/cairo-pdf-surface.c:2700:14
	    #4 0x57474261afc6 in _cairo_surface_finish cairo/src/cairo-surface.c:1043:11
	    #5 0x57474261afc6 in cairo_surface_finish cairo/src/cairo-surface.c:1092:5
	    #6 0x57474270808a in _cairo_paginated_surface_finish cairo/src/cairo-paginated-surface.c:215:2
	    #7 0x5747426175c2 in _cairo_surface_finish cairo/src/cairo-surface.c:1043:11
	    #8 0x5747426175c2 in cairo_surface_destroy cairo/src/cairo-surface.c:978:2

This fixes it.

_cairo_pdf_surface_finish was succeeding past
_cairo_pdf_surface_open_object_stream that allocates surface->object_stream.stream,
failing when calling _cairo_pdf_surface_emit_font_subsets
and that memory was never freed
2026-01-24 11:37:50 +01:00
Alvin Wong
5833de29f3 Add missing mutex cleanup in _cairo_recording_surface_finish 2025-12-17 16:35:49 +00:00
calixteman
fc35ffb77e Fix invalid pdf generation with too many objects in object stream
Fixes cairo issue #907.

In the xref table, the generation number is limited to 65535 (2^16 - 1)
and it's used to identify objects in object streams.
When generating a pdf with more than 65536 objects in object streams,
the generation number overflows and restarts at 0, which causes
invalid references in the xref table.
2025-11-16 22:37:53 +01:00
Emmanuele Bassi
a4d5a24d60 Merge branch 'fix-msc-ver-compare' into 'master'
Check if _MSC_VER macro is defined

See merge request cairo/cairo!611
2025-07-14 14:42:26 +00:00
Emmanuele Bassi
6ac5348308 The GDI coordinate system is inverted compared to cairo's here, so the
delta-y value needs to be negated, otherwise glyph runs with non-zero 
y-advances will shift in the wrong direction.

See mozilla bug https://bugzilla.mozilla.org/show_bug.cgi?id=1962816 and
earlier https://bugzilla.mozilla.org/show_bug.cgi?id=454098 where this was
first discovered & fixed, but unfortunately was not upstreamed at that 
time.
2025-07-14 14:41:40 +00:00
Jonathan Kew
503505666f Fix sign of delta-y for ExtTextOutW 2025-07-14 14:41:40 +00:00
Luca Bacci
1aaa23aefb DWrite: Add support for COLRv1 fonts
Fixes https://gitlab.freedesktop.org/cairo/cairo/-/issues/903
2025-07-14 16:34:07 +02:00
Luca Bacci
457ab827c9 Add definition for IDWriteFactory8 2025-07-14 16:34:06 +02:00
Luca Bacci
2a306f8e5f Always include dwrite-extra.hpp 2025-07-14 16:34:05 +02:00
Luca Bacci
53c3702686 dwrite-extra.hpp: Fix check for mingw-w64 workaround 2025-07-14 16:34:04 +02:00
Luca Bacci
02763155e8 dwrite-extra.hpp: Rework a bit 2025-07-14 16:34:03 +02:00
Luca Bacci
27411659d8 Rename dwrite / d2d1 polyfill headers to .hpp extension
They are only usable from C++ now
2025-07-14 16:34:02 +02:00
Luca Bacci
6ec91df76e Check which ID2D1DeviceContext subclasses are defined in d2d1_3.h
...and make d2d1-extra.h provide the missing definitions
2025-07-14 16:34:01 +02:00
Luca Bacci
306396ff53 Add definitions for ID2D1DeviceContext7 in d2d1-extra.h
We're going to make use of ID2D1DeviceContext7::DrawPaintGlyphRun()
for COLRv1 fonts.
2025-07-14 16:33:59 +02:00
Luca Bacci
b1bc5a73f6 DWrite: don't set component-alpha for A8 mask
It was just a copy-paste leftover. Component-alpha makes sense
only for color images.
2025-07-14 16:33:59 +02:00
Luca Bacci
7f82b13fbf Fix typo 2025-07-14 16:33:58 +02:00
Luca Bacci
c7a3e6c519 Check if _MSC_VER macro is defined
Original patch from MSYS2:
https://github.com/msys2/MINGW-packages/blob/36dd8e0bdf/mingw-w64-cairo/0030-ucrt-clang-fixes.patch
2025-07-14 15:53:52 +02:00
Uli Schlachter
2f21b3874c Merge branch 'fix-clipping-crash' into 'master'
Fix a crash in the clipping code

See merge request cairo/cairo!622
2025-07-14 13:01:46 +00:00
Uli Schlachter
55cb75c4df Merge branch 'winsdk_26100_fix' into 'master'
Add check for clang to cairo attribute handling code

See merge request cairo/cairo!612
2025-07-05 09:02:29 +00:00
Luca Bacci
76a0978d7b Fix check for InitOnceComplete failure
...also include <windows.h>

Fixes ff4f2f43
2025-07-02 13:26:00 +02:00
Ryan VanderMeulen
ef42ed0ec8 Add check for clang to cairo attribute handling code 2025-07-01 12:14:08 -04:00
Tim-Philipp Müller
0bf0265009 Merge branch 'compiler-features' into 'master'
Rework compiler features detection

See merge request cairo/cairo!627
2025-07-01 12:32:05 +00:00
Luca Bacci
d4f1ba74d0 Win32: Fix init once condition
Fixes !626
2025-06-19 10:15:37 +02:00
Tim-Philipp Müller
3ffb6d5c07 Merge branch 'win32-fixes' into 'master'
Win32 Fixes

Closes #897

See merge request cairo/cairo!626
2025-06-16 17:15:07 +00:00
Luca Bacci
6989158f4c Drop support for very old GCC versions
They don't support C11 anyway. Additionally, CLang defines a very
conservative __GNUC__ value (which is also configurable via the
-fgnuc-version= command-line argument)
2025-06-16 18:52:39 +02:00
Luca Bacci
ff4f2f4301 Win32: Implement init_once with InitOnceBeginInitialize / InitOnceComplete 2025-06-16 18:50:13 +02:00
Luca Bacci
ee554c8610 DWrite: Fix switch for grid-fit mode
Ooops!
2025-06-16 17:52:15 +02:00
Luca Bacci
d9a11c3736 Win32: Use cairo_atomic_once_t to initialize TLS slot
We were using the double-checked locking pattern, which requires
memory fences to be safe on architectures with weak memory
guarantess (e.g ARM64)

Fixes https://gitlab.freedesktop.org/cairo/cairo/-/issues/897
2025-06-16 17:51:53 +02:00
Matthias Clasen
1d3347a690 Fix a crash in the clipping code
When cairo_is_all_clipped return true, we must not attempt
to change any of the clip fields, since it is pointing to
the static const __cairo_clip_all.

Moving the check for ->region into the 'if' is fine, since
it will always be NULL for _cairo_clip_all.

This was causing a crash in inkscape, see
https://gitlab.com/inkscape/inkscape/-/issues/5631
2025-05-28 18:12:16 -04:00
correctmost
a1c31f5ed5 xcb: Fix a -Wuse-after-free=3 warning with GCC
Closes #898
2025-05-26 21:20:15 -04:00
Emmanuele Bassi
22206ba5dd Post-release version bump to 1.18.5 2025-03-08 13:23:25 +00:00
Emmanuele Bassi
4541e0cd3a Release Cairo 1.18.4 2025-03-08 13:23:25 +00:00
Luca Bacci
4d141f08fb DWrite: Add fallback for OS versions up to Windows 8
IDWriteGlyphRunAnalysis supports gray-scale antialiasing only when
created via IDWriteFactory2 (and newer), introduced in Windows 8.1

Fallback to using DIrect2D on A8 targets when IDWriteFactory2 is
not available.
2025-02-10 17:18:46 +01:00
Luca Bacci
78fca779ba DWrite: Get glyph coverage using IDWriteGlyphRunAnalysis 2025-02-10 17:18:40 +01:00
Emmanuele Bassi
fe87f1c3fb Merge branch 'win32-cleanup' into 'master'
Win32 cleanup

See merge request cairo/cairo!605
2025-01-30 09:29:01 +00:00
Emmanuele Bassi
e2a52c0870 Merge branch 'dwrite-font-variations' into 'master'
DWrite: Add support for font variations

Closes #877

See merge request cairo/cairo!601
2025-01-30 09:26:49 +00:00
Emmanuele Bassi
ed7b0a54b9 Merge branch 'dwrite-fix-warnings' into 'master'
DWrite: Fix warnings

See merge request cairo/cairo!603
2025-01-30 09:25:57 +00:00
Luca Bacci
e0287e09f4 DWrite/GeometryRecorder: Add final specifier 2025-01-21 13:55:27 +01:00
Luca Bacci
46153a0408 DWrite/GeometryRecorder: Complete implementation of QueryInterface
...by checking for IUnknown.

This makes GeometryRecorder::QueryInterface compliant with the
rules of COM.

QueryInterface for IUnknown has a special meaning in COM: it's
used to check whether two interface pointers refer to the same
object.
2025-01-21 13:55:26 +01:00
Luca Bacci
59197e7791 DWrite/GeometryRecorder: Add noexcept specifier
STDMETHOD / IFACEMETHOD macros already add __declspec(nothrow), but
noexcept is better. From MSDN [1]:

  We recommend that all new code use the noexcept operator rather than
  __declspec(nothrow).
  This attribute tells the compiler that the declared function and the
  functions it calls never throw an exception. However, it does not
  enforce the directive. In other words, it never causes std::terminate
  to be invoked, unlike noexcept, or in std:c++17 mode (Visual Studio
  2017 version 15.5 and later), throw().

See also [2]:

  Non-throwing functions are permitted to call potentially-throwing
  functions. Whenever an exception is thrown and the search for a handler
  encounters the outermost block of a non-throwing function, the function
  std::terminate is called:

  extern void f(); // potentially-throwing

  void g() noexcept {
    f();      // valid, even if f throws
    throw 42; // valid, effectively a call to std::terminate
  }

References:

 [1] https://learn.microsoft.com/en-us/cpp/cpp/nothrow-cpp?view=msvc-170
 [2] https://en.cppreference.com/w/cpp/language/noexcept_spec
2025-01-21 13:55:19 +01:00
Luca Bacci
8107086c6a DWrite/GeometryRecorder: Add override specifier
IFACEMETHOD already adds the __override / __allowed(on_function) SAL
annotation (only on Windows SDK, not mingw-w64), which is understood
by some code analysis tools [1]. Since we're compiling in C++11 mode,
we can add the override specifier, so that the compiler is informed
as well.

[1] https://devblogs.microsoft.com/oldnewthing/20200911-00/?p=104205
2025-01-21 12:16:35 +01:00
Luca Bacci
bdac729974 DWrite/GeometryRecorder: Use IFACEMETHOD consistently
Fixes the following warnings on CLang:

  ../cairo/src/win32/cairo-dwrite-font.cpp:869:27: warning: exception specification
  of overriding function is more lax than base version [-Wmicrosoft-exception-spec]
    869 |     IFACEMETHODIMP_(void) SetFillMode(D2D1_FILL_MODE fillMode)
        |                           ^
  D:/msys64/clang64/include/d2d1.h:1491:22: note: overridden virtual function is here
   1491 |     STDMETHOD_(void, SetFillMode)(D2D1_FILL_MODE fillMode) PURE;
        |

COM objects are usually implemented like that:

1. The class is defined with only method declarations. For that,
   one should use IFACEMETHOD macros.
2. Then methods are implemented (defined), outside of the class
   definition. For that, one should use the IFACEMETHODIMP macros

If one really wants to provide inline method definitions (that is,
inside the class definition), then IFACEMETHOD macros should be used
(and not IFACEMETHODIMP, though it's a definition / implementation).
2025-01-21 12:02:51 +01:00
Luca Bacci
864ede8e1a Win32: Load system DLLs from System32 2025-01-21 11:59:09 +01:00
Luca Bacci
995c09ba67 Win32: Avoid library finalization on process termination
Library finalization should be done only for explicit library
unloads (dlclose / FreeLibrary), not for process termination.
2025-01-21 11:32:06 +01:00
Luca Bacci
1e5740c756 Revert "win32: Initialize mutexes for static builds for win32"
This reverts commit 5f90f0a706.

This is not needed anymore now that we have TLS callbacks.
2025-01-21 11:32:06 +01:00
Luca Bacci
3921eb96be Win32: Use TLS callback for module initialization and finalization
TLS callbacks are pretty much like DllMain but work also in
static builds.
2025-01-21 11:19:29 +01:00