From b4c2e8ef4f3123940833fcb34c6777440750a8ff Mon Sep 17 00:00:00 2001 From: Martin Joerg Date: Fri, 11 Apr 2025 10:37:51 +0000 Subject: [PATCH] k2pdfopt: fix build against mupdf >= 1.25.0 fixes #376898 --- pkgs/by-name/k2/k2pdfopt/package.nix | 33 +++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/k2/k2pdfopt/package.nix b/pkgs/by-name/k2/k2pdfopt/package.nix index 8feb2b25d2b5..a7da6638c61b 100644 --- a/pkgs/by-name/k2/k2pdfopt/package.nix +++ b/pkgs/by-name/k2/k2pdfopt/package.nix @@ -4,6 +4,7 @@ runCommand, fetchzip, fetchurl, + fetchpatch, fetchFromGitHub, cmake, jbig2dec, @@ -117,13 +118,43 @@ stdenv.mkDerivation rec { cp ${k2pdfopt_src}/mupdf_mod/pdf-* ./source/pdf/ ''; }; + # mupdf_patch no longer applies cleanly against mupdf 1.25.0 or later, due to a conflicting + # hunk (mupdf_conflict) introduced in commit bd8d337939f36f55b96cb6984f5c7bbf2f488ce0 of mupdf. + # This merge conflict can be resolved as desired by reverting mupdf_conflict, applying mupdf_patch, + # and finally reapplying mupdf_conflict, with an increased fuzz factor (see mupdf_modded below). + # TODO: remove workaround with conflicting hunk when mupdf in k2pdfopt is updated to 1.25.0 or later + mupdf_conflict = + hash: revert: + fetchpatch { + name = "mupdf-conflicting-hunk" + (lib.optionalString revert "-reverted") + ".patch"; + url = "https://github.com/ArtifexSoftware/mupdf/commit/bd8d337939f36f55b96cb6984f5c7bbf2f488ce0.patch"; + inherit hash revert; + includes = [ "source/fitz/stext-device.c" ]; + postFetch = '' + filterdiff -#6 "$out" > "$tmpfile" + mv "$tmpfile" "$out" + ''; + }; mupdf_modded = mupdf.overrideAttrs ( { patches ? [ ], ... }: { - patches = patches ++ [ mupdf_patch ]; + # The fuzz factor is increased to automatically resolve the merge conflict. + patchFlags = [ + "-p1" + "-F3" + ]; + # Reverting and reapplying the conflicting hunk is necessary, otherwise the result will be faulty. + patches = patches ++ [ + # revert conflicting hunk + (mupdf_conflict "sha256-24tl9YBuZBYhb12yY3T0lKsA7NswfK0QcMYhb2IpepA=" true) + # apply modifications + mupdf_patch + # reapply conflicting hunk + (mupdf_conflict "sha256-bnBV7LyX1w/BXxBFF1bkA8x+/0I9Am33o8GiAeEKHYQ=" false) + ]; # This function is missing in font.c, see font-win32.c postPatch = '' echo "void pdf_install_load_system_font_funcs(fz_context *ctx) {}" >> source/fitz/font.c