Skip to content

Commit 8d1cc34

Browse files
authored
k2pdfopt: fix build against mupdf >= 1.25.0 (#397905)
2 parents 8c178c8 + b4c2e8e commit 8d1cc34

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

pkgs/by-name/k2/k2pdfopt/package.nix

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
runCommand,
55
fetchzip,
66
fetchurl,
7+
fetchpatch,
78
fetchFromGitHub,
89
cmake,
910
jbig2dec,
@@ -117,13 +118,43 @@ stdenv.mkDerivation rec {
117118
cp ${k2pdfopt_src}/mupdf_mod/pdf-* ./source/pdf/
118119
'';
119120
};
121+
# mupdf_patch no longer applies cleanly against mupdf 1.25.0 or later, due to a conflicting
122+
# hunk (mupdf_conflict) introduced in commit bd8d337939f36f55b96cb6984f5c7bbf2f488ce0 of mupdf.
123+
# This merge conflict can be resolved as desired by reverting mupdf_conflict, applying mupdf_patch,
124+
# and finally reapplying mupdf_conflict, with an increased fuzz factor (see mupdf_modded below).
125+
# TODO: remove workaround with conflicting hunk when mupdf in k2pdfopt is updated to 1.25.0 or later
126+
mupdf_conflict =
127+
hash: revert:
128+
fetchpatch {
129+
name = "mupdf-conflicting-hunk" + (lib.optionalString revert "-reverted") + ".patch";
130+
url = "https://github.com/ArtifexSoftware/mupdf/commit/bd8d337939f36f55b96cb6984f5c7bbf2f488ce0.patch";
131+
inherit hash revert;
132+
includes = [ "source/fitz/stext-device.c" ];
133+
postFetch = ''
134+
filterdiff -#6 "$out" > "$tmpfile"
135+
mv "$tmpfile" "$out"
136+
'';
137+
};
120138
mupdf_modded = mupdf.overrideAttrs (
121139
{
122140
patches ? [ ],
123141
...
124142
}:
125143
{
126-
patches = patches ++ [ mupdf_patch ];
144+
# The fuzz factor is increased to automatically resolve the merge conflict.
145+
patchFlags = [
146+
"-p1"
147+
"-F3"
148+
];
149+
# Reverting and reapplying the conflicting hunk is necessary, otherwise the result will be faulty.
150+
patches = patches ++ [
151+
# revert conflicting hunk
152+
(mupdf_conflict "sha256-24tl9YBuZBYhb12yY3T0lKsA7NswfK0QcMYhb2IpepA=" true)
153+
# apply modifications
154+
mupdf_patch
155+
# reapply conflicting hunk
156+
(mupdf_conflict "sha256-bnBV7LyX1w/BXxBFF1bkA8x+/0I9Am33o8GiAeEKHYQ=" false)
157+
];
127158
# This function is missing in font.c, see font-win32.c
128159
postPatch = ''
129160
echo "void pdf_install_load_system_font_funcs(fz_context *ctx) {}" >> source/fitz/font.c

0 commit comments

Comments
 (0)