Subject: [PATCH 3/5] gnu: Add plutovg.

From: Nguyễn Gia Phong <[email-masked]>
Date: Wed, 5 Mar 2025 17:44:06 +0900

* gnu/packages/image.scm (plutovg): New variable.
* gnu/packages/patches/plutovg-unbundle-stb.patch: New file.
* gnu/local.mk (dist_patch_DATA): Register patch.

Change-Id: I5b4be1c85c9ceb3ca991cf336b808367c9f832eb
---
 gnu/local.mk                                  |  1 +
 gnu/packages/image.scm                        | 26 ++++++++++++++++
 .../patches/plutovg-unbundle-stb.patch        | 31 +++++++++++++++++++
 3 files changed, 58 insertions(+)
 create mode 100644 gnu/packages/patches/plutovg-unbundle-stb.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index a7a3238669d2..a8c3631ada0a 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1991,6 +1991,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/plasma-framework-fix-KF5PlasmaMacros.cmake.patch \
   %D%/packages/patches/plasp-fix-normalization.patch \
   %D%/packages/patches/plasp-include-iostream.patch \
+  %D%/packages/patches/plutovg-unbundle-stb.patch		\
   %D%/packages/patches/pocketfft-cpp-prefer-preprocessor-if.patch			\
   %D%/packages/patches/pokerth-boost.patch			\
   %D%/packages/patches/ppsspp-disable-upgrade-and-gold.patch		\
diff --git a/gnu/packages/image.scm b/gnu/packages/image.scm
index 5d294176277e..12c9eb01bc07 100644
--- a/gnu/packages/image.scm
+++ b/gnu/packages/image.scm
@@ -39,6 +39,7 @@
 ;;; Copyright © 2023-2024 Nicolas Goaziou <[email-masked]>
 ;;; Copyright © 2023, 2025 Artyom V. Poptsov <[email-masked]>
 ;;; Copyright © 2024 chris <[email-masked]>
+;;; Copyright © 2025 Nguyễn Gia Phong <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -96,6 +97,7 @@ (define-module (gnu packages image)
   #:use-module (gnu packages qt)
   #:use-module (gnu packages ragel)
   #:use-module (gnu packages sphinx)
+  #:use-module (gnu packages stb)
   #:use-module (gnu packages swig)
   #:use-module (gnu packages textutils)
   #:use-module (gnu packages video)
@@ -2849,6 +2851,30 @@ (define-public phockup
 @file{unknown}.")
     (license license:expat)))
 
+(define-public plutovg
+  (package
+    (name "plutovg")
+    (version "0.0.13")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/sammycage/plutovg")
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
+       (sha256 (base32 "0y2w0qhs89bnh440z1xj65vg4c71rlwinxgs3p8bvh2fmbi7lqff"))
+       (patches (search-patches "plutovg-unbundle-stb.patch"))
+       (snippet '(begin
+                   (delete-file "source/plutovg-stb-image.h")
+                   (delete-file "source/plutovg-stb-image-write.h")
+                   (delete-file "source/plutovg-stb-truetype.h")))))
+    (build-system meson-build-system)
+    (inputs (list stb-image stb-image-write stb-truetype))
+    (home-page "https://github.com/sammycage/plutovg")
+    (synopsis "Tiny 2D vector graphics library in C")
+    (description "PlutoVG is a standalone 2D vector graphics library in C.")
+    (license license:expat)))
+
 (define-public spng
   (package
    (name "spng")
diff --git a/gnu/packages/patches/plutovg-unbundle-stb.patch b/gnu/packages/patches/plutovg-unbundle-stb.patch
new file mode 100644
index 000000000000..13ea69c76bed
--- /dev/null
+++ b/gnu/packages/patches/plutovg-unbundle-stb.patch
@@ -0,0 +1,31 @@
+diff --git a/source/plutovg-font.c b/source/plutovg-font.c
+index 2e67033cb4b3..7d2dc4b7bdec 100644
+--- a/source/plutovg-font.c
++++ b/source/plutovg-font.c
+@@ -6,7 +6,7 @@
+ 
+ #define STBTT_STATIC
+ #define STB_TRUETYPE_IMPLEMENTATION
+-#include "plutovg-stb-truetype.h"
++#include "stb_truetype.h"
+ 
+ static int plutovg_text_iterator_length(const void* data, int length, plutovg_text_encoding_t encoding)
+ {
+diff --git a/source/plutovg-surface.c b/source/plutovg-surface.c
+index 79263cec4d66..cc2cb524b57a 100644
+--- a/source/plutovg-surface.c
++++ b/source/plutovg-surface.c
+@@ -3,11 +3,11 @@
+ 
+ #define STB_IMAGE_WRITE_STATIC
+ #define STB_IMAGE_WRITE_IMPLEMENTATION
+-#include "plutovg-stb-image-write.h"
++#include "stb_image_write.h"
+ 
+ #define STB_IMAGE_STATIC
+ #define STB_IMAGE_IMPLEMENTATION
+-#include "plutovg-stb-image.h"
++#include "stb_image.h"
+ 
+ static plutovg_surface_t* plutovg_surface_create_uninitialized(int width, int height)
+ {
-- 
2.48.1