diff --git a/package/libgtk4/0001-gtk-print-gtkprintoperation-unix-portal-.c-add-CAIRO.patch b/package/libgtk4/0001-gtk-print-gtkprintoperation-unix-portal-.c-add-CAIRO.patch
new file mode 100644
index 0000000000..70622b6412
--- /dev/null
+++ b/package/libgtk4/0001-gtk-print-gtkprintoperation-unix-portal-.c-add-CAIRO.patch
@@ -0,0 +1,198 @@
+From 44c2d24ea45d3014458e7d4f77fb6332b9746436 Mon Sep 17 00:00:00 2001
+From: Thomas Devoogdt <thomas@devoogdt.com>
+Date: Sun, 15 Sep 2024 19:50:51 +0200
+Subject: [PATCH] gtk/print/gtkprintoperation{,-unix,-portal}.c: add CAIRO_HAS
+ checks
+
+This is similar to the checks in tools/gtk-rendernode-tool-render.c.
+
+resolves #5072
+
+Signed-off-by: Thomas Devoogdt <thomas@devoogdt.com>
+(cherry picked from commit ffc8f34dfd560f36659aa1d5b5684fa97c4f4ebc)
+Upstream: https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/7717
+---
+ gtk/print/gtkprintoperation-portal.c |  9 +++++++++
+ gtk/print/gtkprintoperation-unix.c   | 17 +++++++++++++++++
+ gtk/print/gtkprintoperation.c        | 10 +++++++++-
+ 3 files changed, 35 insertions(+), 1 deletion(-)
+
+diff --git a/gtk/print/gtkprintoperation-portal.c b/gtk/print/gtkprintoperation-portal.c
+index afc276067b..3b91bf0830 100644
+--- a/gtk/print/gtkprintoperation-portal.c
++++ b/gtk/print/gtkprintoperation-portal.c
+@@ -24,8 +24,13 @@
+ #include <sys/stat.h>
+ #include <fcntl.h>
+ 
++#include <cairo.h>
++#ifdef CAIRO_HAS_PDF_SURFACE
+ #include <cairo-pdf.h>
++#endif
++#ifdef CAIRO_HAS_PS_SURFACE
+ #include <cairo-ps.h>
++#endif
+ 
+ #include <gio/gunixfdlist.h>
+ 
+@@ -147,6 +152,7 @@ portal_start_page (GtkPrintOperation *op,
+     {
+       if (type == CAIRO_SURFACE_TYPE_PS)
+         {
++#ifdef CAIRO_HAS_PS_SURFACE
+           cairo_ps_surface_set_size (op_portal->surface, w, h);
+           cairo_ps_surface_dsc_begin_page_setup (op_portal->surface);
+           switch (gtk_page_setup_get_orientation (page_setup))
+@@ -164,15 +170,18 @@ portal_start_page (GtkPrintOperation *op,
+               default:
+                 break;
+             }
++#endif
+          }
+       else if (type == CAIRO_SURFACE_TYPE_PDF)
+         {
++#ifdef CAIRO_HAS_PDF_SURFACE
+           if (!op->priv->manual_orientation)
+             {
+               w = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
+               h = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
+             }
+           cairo_pdf_surface_set_size (op_portal->surface, w, h);
++#endif
+         }
+     }
+ }
+diff --git a/gtk/print/gtkprintoperation-unix.c b/gtk/print/gtkprintoperation-unix.c
+index cf52c56463..b61b9f5fd9 100644
+--- a/gtk/print/gtkprintoperation-unix.c
++++ b/gtk/print/gtkprintoperation-unix.c
+@@ -36,8 +36,13 @@
+ #include "gtkprintoperation-private.h"
+ #include "gtkprintoperation-portal.h"
+ 
++#include <cairo.h>
++#ifdef CAIRO_HAS_PDF_SURFACE
+ #include <cairo-pdf.h>
++#endif
++#ifdef CAIRO_HAS_PS_SURFACE
+ #include <cairo-ps.h>
++#endif
+ #include "gtkprintunixdialog.h"
+ #include "gtkpagesetupunixdialog.h"
+ #include "gtkprintbackendprivate.h"
+@@ -90,6 +95,7 @@ unix_start_page (GtkPrintOperation *op,
+     {
+       if (type == CAIRO_SURFACE_TYPE_PS)
+         {
++#ifdef CAIRO_HAS_PS_SURFACE
+           cairo_ps_surface_set_size (op_unix->surface, w, h);
+           cairo_ps_surface_dsc_begin_page_setup (op_unix->surface);
+           switch (gtk_page_setup_get_orientation (page_setup))
+@@ -106,15 +112,18 @@ unix_start_page (GtkPrintOperation *op,
+               default:
+                 break;
+             }
++#endif
+          }
+       else if (type == CAIRO_SURFACE_TYPE_PDF)
+         {
++#ifdef CAIRO_HAS_PDF_SURFACE
+           if (!op->priv->manual_orientation)
+             {
+               w = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
+               h = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
+             }
+           cairo_pdf_surface_set_size (op_unix->surface, w, h);
++#endif
+         }
+     }
+ }
+@@ -746,6 +755,7 @@ gtk_print_operation_unix_run_dialog_async (GtkPrintOperation          *op,
+     }
+ }
+ 
++#ifdef CAIRO_HAS_PDF_SURFACE
+ static cairo_status_t
+ write_preview (void                *closure,
+                const unsigned char *data,
+@@ -817,6 +827,7 @@ gtk_print_operation_unix_create_preview_surface (GtkPrintOperation *op,
+ 
+   return surface;
+ }
++#endif
+ 
+ static void
+ gtk_print_operation_unix_preview_start_page (GtkPrintOperation *op,
+@@ -838,11 +849,13 @@ gtk_print_operation_unix_resize_preview_surface (GtkPrintOperation *op,
+                                                  GtkPageSetup      *page_setup,
+                                                  cairo_surface_t   *surface)
+ {
++#ifdef CAIRO_HAS_PDF_SURFACE
+   double w, h;
+ 
+   w = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
+   h = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
+   cairo_pdf_surface_set_size (surface, w, h);
++#endif
+ }
+ 
+ static GtkPrintOperationResult
+@@ -1292,7 +1305,11 @@ _gtk_print_operation_platform_backend_create_preview_surface (GtkPrintOperation
+ 							      double            *dpi_y,
+ 							      char             **target)
+ {
++#ifdef CAIRO_HAS_PDF_SURFACE
+   return gtk_print_operation_unix_create_preview_surface (op, page_setup, dpi_x, dpi_y, target);
++#else
++  return NULL;
++#endif
+ }
+ 
+ void
+diff --git a/gtk/print/gtkprintoperation.c b/gtk/print/gtkprintoperation.c
+index 8aa8976a10..bacd7b21ed 100644
+--- a/gtk/print/gtkprintoperation.c
++++ b/gtk/print/gtkprintoperation.c
+@@ -23,7 +23,10 @@
+ #include <math.h>
+ #include <string.h>
+ 
++#include <cairo.h>
++#ifdef CAIRO_HAS_PDF_SURFACE
+ #include <cairo-pdf.h>
++#endif
+ 
+ #include <glib/gi18n-lib.h>
+ #include "gtkmarshalers.h"
+@@ -1953,6 +1956,7 @@ create_page_setup (GtkPrintOperation *op)
+   return page_setup;
+ }
+ 
++#ifdef CAIRO_HAS_PDF_SURFACE
+ static void 
+ pdf_start_page (GtkPrintOperation *op,
+ 		GtkPrintContext   *print_context,
+@@ -2063,7 +2067,7 @@ run_pdf (GtkPrintOperation  *op,
+   
+   return GTK_PRINT_OPERATION_RESULT_APPLY; 
+ }
+-
++#endif
+ 
+ static void
+ clamp_page_ranges (PrintPagesData *data)
+@@ -3096,7 +3100,11 @@ gtk_print_operation_run (GtkPrintOperation        *op,
+        */
+       priv->is_sync = TRUE;
+       g_return_val_if_fail (priv->export_filename != NULL, GTK_PRINT_OPERATION_RESULT_ERROR);
++#ifdef CAIRO_HAS_PDF_SURFACE
+       result = run_pdf (op, parent, &do_print);
++#else
++      result = GTK_PRINT_OPERATION_RESULT_ERROR;
++#endif
+     }
+   else if (action == GTK_PRINT_OPERATION_ACTION_PREVIEW)
+     {
+-- 
+2.43.0
+
diff --git a/package/libgtk4/0002-modules-printbackends-gtkprintbackendfile.c-add-CAIR.patch b/package/libgtk4/0002-modules-printbackends-gtkprintbackendfile.c-add-CAIR.patch
new file mode 100644
index 0000000000..7d583f564b
--- /dev/null
+++ b/package/libgtk4/0002-modules-printbackends-gtkprintbackendfile.c-add-CAIR.patch
@@ -0,0 +1,219 @@
+From 50962fdeba34a38ce20895623041dda88f231ad2 Mon Sep 17 00:00:00 2001
+From: Thomas Devoogdt <thomas@devoogdt.com>
+Date: Sun, 15 Sep 2024 19:52:48 +0200
+Subject: [PATCH] modules/printbackends/gtkprintbackendfile.c: add CAIRO_HAS
+ checks
+
+This is similar to the checks in tools/gtk-rendernode-tool-render.c.
+
+resolves #5072
+
+Signed-off-by: Thomas Devoogdt <thomas@devoogdt.com>
+(cherry picked from commit 9f855eecb11924e78350fcfd1e8b4ecfddf490d4)
+Upstream: https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/7717
+---
+ modules/printbackends/gtkprintbackendfile.c | 55 +++++++++++++++++++++
+ 1 file changed, 55 insertions(+)
+
+diff --git a/modules/printbackends/gtkprintbackendfile.c b/modules/printbackends/gtkprintbackendfile.c
+index eb0b00ce3b..ddfd8d4425 100644
+--- a/modules/printbackends/gtkprintbackendfile.c
++++ b/modules/printbackends/gtkprintbackendfile.c
+@@ -27,10 +27,17 @@
+ #include <string.h>
+ 
+ #include <errno.h>
++
+ #include <cairo.h>
++#ifdef CAIRO_HAS_PDF_SURFACE
+ #include <cairo-pdf.h>
++#endif
++#ifdef CAIRO_HAS_PS_SURFACE
+ #include <cairo-ps.h>
++#endif
++#ifdef CAIRO_HAS_SVG_SURFACE
+ #include <cairo-svg.h>
++#endif
+ 
+ #include <glib/gi18n-lib.h>
+ 
+@@ -60,17 +67,29 @@ struct _GtkPrintBackendFile
+ 
+ typedef enum
+ {
++#ifdef CAIRO_HAS_PDF_SURFACE
+   FORMAT_PDF,
++#endif
++#ifdef CAIRO_HAS_PS_SURFACE
+   FORMAT_PS,
++#endif
++#ifdef CAIRO_HAS_SVG_SURFACE
+   FORMAT_SVG,
++#endif
+   N_FORMATS
+ } OutputFormat;
+ 
+ static const char * formats[N_FORMATS] =
+ {
++#ifdef CAIRO_HAS_PDF_SURFACE
+   "pdf",
++#endif
++#ifdef CAIRO_HAS_PS_SURFACE
+   "ps",
++#endif
++#ifdef CAIRO_HAS_SVG_SURFACE
+   "svg"
++#endif
+ };
+ 
+ static GObjectClass *backend_parent_class;
+@@ -220,15 +239,21 @@ output_file_from_settings (GtkPrintSettings *settings,
+             {
+               default:
+               case N_FORMATS:
++#ifdef CAIRO_HAS_PDF_SURFACE
+               case FORMAT_PDF:
+                 extension = "pdf";
+                 break;
++#endif
++#ifdef CAIRO_HAS_PS_SURFACE
+               case FORMAT_PS:
+                 extension = "ps";
+                 break;
++#endif
++#ifdef CAIRO_HAS_SVG_SURFACE
+               case FORMAT_SVG:
+                 extension = "svg";
+                 break;
++#endif
+             }
+         }
+ 
+@@ -325,8 +350,10 @@ file_printer_create_cairo_surface (GtkPrinter       *printer,
+ {
+   cairo_surface_t *surface;
+   OutputFormat format;
++#ifdef CAIRO_HAS_SVG_SURFACE
+   const cairo_svg_version_t *versions;
+   int num_versions = 0;
++#endif
+ 
+   format = format_from_settings (settings);
+ 
+@@ -334,18 +361,24 @@ file_printer_create_cairo_surface (GtkPrinter       *printer,
+     {
+       default:
+       case N_FORMATS:
++#ifdef CAIRO_HAS_PDF_SURFACE
+       case FORMAT_PDF:
+         surface = cairo_pdf_surface_create_for_stream (_cairo_write, cache_io, width, height);
+         break;
++#endif
++#ifdef CAIRO_HAS_PS_SURFACE
+       case FORMAT_PS:
+         surface = cairo_ps_surface_create_for_stream (_cairo_write, cache_io, width, height);
+         break;
++#endif
++#ifdef CAIRO_HAS_SVG_SURFACE
+       case FORMAT_SVG:
+         surface = cairo_svg_surface_create_for_stream (_cairo_write, cache_io, width, height);
+         cairo_svg_get_versions (&versions, &num_versions);
+         if (num_versions > 0)
+           cairo_svg_surface_restrict_to_version (surface, versions[num_versions - 1]);
+         break;
++#endif
+     }
+ 
+   cairo_surface_set_fallback_resolution (surface,
+@@ -550,15 +583,21 @@ set_printer_format_from_option_set (GtkPrinter          *printer,
+ 
+ 	  switch (i)
+ 	    {
++#ifdef CAIRO_HAS_PDF_SURFACE
+ 	      case FORMAT_PDF:
+ 		gtk_printer_set_accepts_pdf (printer, TRUE);
+ 		gtk_printer_set_accepts_ps (printer, FALSE);
+ 		break;
++#endif
++#ifdef CAIRO_HAS_PS_SURFACE
+ 	      case FORMAT_PS:
+ 		gtk_printer_set_accepts_pdf (printer, FALSE);
+ 		gtk_printer_set_accepts_ps (printer, TRUE);
+ 		break;
++#endif
++#ifdef CAIRO_HAS_SVG_SURFACE
+ 	      case FORMAT_SVG:
++#endif
+ 	      default:
+ 		gtk_printer_set_accepts_pdf (printer, FALSE);
+ 		gtk_printer_set_accepts_ps (printer, FALSE);
+@@ -660,6 +699,7 @@ file_printer_get_options (GtkPrinter           *printer,
+ 
+   if (capabilities & (GTK_PRINT_CAPABILITY_GENERATE_PDF | GTK_PRINT_CAPABILITY_GENERATE_PS))
+     {
++#ifdef CAIRO_HAS_PDF_SURFACE
+       if (capabilities & GTK_PRINT_CAPABILITY_GENERATE_PDF)
+         {
+ 	  if (format == FORMAT_PDF || format == N_FORMATS)
+@@ -671,6 +711,8 @@ file_printer_get_options (GtkPrinter           *printer,
+ 	  display_format_names[n_formats] = _(format_names[FORMAT_PDF]);
+ 	  n_formats++;
+ 	}
++#endif
++#ifdef CAIRO_HAS_PS_SURFACE
+       if (capabilities & GTK_PRINT_CAPABILITY_GENERATE_PS)
+         {
+ 	  if (format == FORMAT_PS || format == N_FORMATS)
+@@ -679,6 +721,7 @@ file_printer_get_options (GtkPrinter           *printer,
+           display_format_names[n_formats] = _(format_names[FORMAT_PS]);
+ 	  n_formats++;
+ 	}
++#endif
+     }
+   else
+     {
+@@ -686,15 +729,21 @@ file_printer_get_options (GtkPrinter           *printer,
+         {
+           default:
+           case N_FORMATS:
++#ifdef CAIRO_HAS_PDF_SURFACE
+           case FORMAT_PDF:
+             current_format = FORMAT_PDF;
+             break;
++#endif
++#ifdef CAIRO_HAS_PS_SURFACE
+           case FORMAT_PS:
+             current_format = FORMAT_PS;
+             break;
++#endif
++#ifdef CAIRO_HAS_SVG_SURFACE
+           case FORMAT_SVG:
+             current_format = FORMAT_SVG;            
+             break;
++#endif
+         }
+ 
+       for (n_formats = 0; n_formats < N_FORMATS; ++n_formats)
+@@ -802,13 +851,19 @@ file_printer_prepare_for_print (GtkPrinter       *printer,
+   format = format_from_settings (settings);
+   switch (format)
+     {
++#ifdef CAIRO_HAS_PDF_SURFACE
+       case FORMAT_PDF:
++#endif
+       case N_FORMATS:
+ 	gtk_print_job_set_rotate (print_job, FALSE);
+         break;
+       default:
++#ifdef CAIRO_HAS_PS_SURFACE
+       case FORMAT_PS:
++#endif
++#ifdef CAIRO_HAS_SVG_SURFACE
+       case FORMAT_SVG:
++#endif
+ 	gtk_print_job_set_rotate (print_job, TRUE);
+         break;
+     }
+-- 
+2.43.0
+
diff --git a/package/libgtk4/0003-gsk-gskrendernodeparser.c-add-CAIRO_HAS-check.patch b/package/libgtk4/0003-gsk-gskrendernodeparser.c-add-CAIRO_HAS-check.patch
new file mode 100644
index 0000000000..fb3ab3b9af
--- /dev/null
+++ b/package/libgtk4/0003-gsk-gskrendernodeparser.c-add-CAIRO_HAS-check.patch
@@ -0,0 +1,31 @@
+From 853e852d9f8de5c474c64a0f6b56924ccffe54a3 Mon Sep 17 00:00:00 2001
+From: Thomas Devoogdt <thomas@devoogdt.com>
+Date: Sun, 15 Sep 2024 20:51:20 +0200
+Subject: [PATCH] gsk/gskrendernodeparser.c: add CAIRO_HAS check
+
+resolves #5072
+
+Signed-off-by: Thomas Devoogdt <thomas@devoogdt.com>
+(cherry picked from commit 3610ac0fd1e6e17e280b17cde7d9b1c995ede351)
+Upstream: https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/7717
+---
+ gsk/gskrendernodeparser.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/gsk/gskrendernodeparser.c b/gsk/gskrendernodeparser.c
+index 9f7602d98d..aa24163f23 100644
+--- a/gsk/gskrendernodeparser.c
++++ b/gsk/gskrendernodeparser.c
+@@ -4415,7 +4415,9 @@ render_node_print (Printer       *p,
+         if (surface != NULL)
+           {
+             array = g_byte_array_new ();
++#if CAIRO_HAS_PNG_FUNCTIONS
+             cairo_surface_write_to_png_stream (surface, cairo_write_array, array);
++#endif
+ 
+             _indent (p);
+             g_string_append (p->str, "pixels: url(\"data:image/png;base64,");
+-- 
+2.43.0
+
diff --git a/package/libgtk4/Config.in b/package/libgtk4/Config.in
index 99553fc44e..2f597ea872 100644
--- a/package/libgtk4/Config.in
+++ b/package/libgtk4/Config.in
@@ -27,6 +27,7 @@ config BR2_PACKAGE_LIBGTK4
 	select BR2_PACKAGE_GRAPHENE
 	select BR2_PACKAGE_LIBEPOXY
 	select BR2_PACKAGE_LIBGLIB2
+	select BR2_PACKAGE_LIBPNG
 	select BR2_PACKAGE_PANGO
 	select BR2_PACKAGE_TIFF
 	# At least one backend is required
diff --git a/package/libgtk4/libgtk4.mk b/package/libgtk4/libgtk4.mk
index b00a2facad..2fba4e7610 100644
--- a/package/libgtk4/libgtk4.mk
+++ b/package/libgtk4/libgtk4.mk
@@ -21,6 +21,7 @@ LIBGTK4_DEPENDENCIES = \
 	graphene \
 	libepoxy \
 	libglib2 \
+	libpng \
 	pango \
 	$(TARGET_NLS_DEPENDENCIES)
 
