summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnderson Torres <torres.anderson.85@protonmail.com>2020-09-03 16:46:48 -0300
committerGitHub <noreply@github.com>2020-09-03 16:46:48 -0300
commit6b043b105e72c0ac928a0dc5483b07bead737e48 (patch)
treeaac27ec35572d4f3700d820557c0c78bcdf66a6d
parent59f5cbd922f9a459ba633fed1c3e651fcf4d4882 (diff)
parent5f29d7e9a55a1ab99f6c0adffba5d9761fbda869 (diff)
Merge pull request #93631 from danielfullmer/k2pdfopt-2.52
k2pdfopt: 2.51a -> 2.53
-rw-r--r--pkgs/applications/misc/k2pdfopt/0001-Fix-CMakeLists.patch49
-rw-r--r--pkgs/applications/misc/k2pdfopt/default.nix148
-rw-r--r--pkgs/applications/misc/k2pdfopt/k2pdfopt-mupdf-1.16.1.patch151
-rw-r--r--pkgs/applications/misc/k2pdfopt/k2pdfopt.patch99
-rw-r--r--pkgs/applications/misc/k2pdfopt/leptonica.patch254
-rw-r--r--pkgs/applications/misc/k2pdfopt/mupdf.patch1060
-rw-r--r--pkgs/applications/misc/k2pdfopt/tesseract.patch675
7 files changed, 169 insertions, 2267 deletions
diff --git a/pkgs/applications/misc/k2pdfopt/0001-Fix-CMakeLists.patch b/pkgs/applications/misc/k2pdfopt/0001-Fix-CMakeLists.patch
new file mode 100644
index 000000000000..8f9271ac996b
--- /dev/null
+++ b/pkgs/applications/misc/k2pdfopt/0001-Fix-CMakeLists.patch
@@ -0,0 +1,49 @@
+From 2629af4ed00d7ca65359178203d80fb146901cdb Mon Sep 17 00:00:00 2001
+From: Daniel Fullmer <danielrf12@gmail.com>
+Date: Fri, 3 Jul 2020 21:00:45 -0700
+Subject: [PATCH 1/2] Fix CMakeLists
+
+---
+ CMakeLists.txt | 12 ++++++++----
+ 1 file changed, 8 insertions(+), 4 deletions(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index e218279..4341de9 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -57,6 +57,7 @@ endif(JPEG_FOUND)
+ include(FindJasper)
+ if(JASPER_FOUND)
+ set(HAVE_JASPER_LIB 1)
++ set(K2PDFOPT_LIB ${K2PDFOPT_LIB} ${JASPER_LIBRARY})
+ endif(JASPER_FOUND)
+
+ # paths from willuslib/wgs.c
+@@ -71,9 +72,12 @@ else()
+ message(STATUS "Could NOT find ghostscript executable")
+ endif(GHOSTSCRIPT_EXECUTABLE)
+
+-# willus.h
+-# HAVE_GSL_LIB
+-
++pkg_check_modules(GSL gsl)
++if(GSL_FOUND)
++ set(HAVE_GSL_LIB 1)
++ include_directories(SYSTEM ${GSL_INCLUDEDIR})
++ set(K2PDFOPT_LIB ${K2PDFOPT_LIB} ${GSL_LDFLAGS})
++endif(GSL_FOUND)
+
+ # libfreetype6 (>= 2.3.9), libjbig2dec0, libjpeg8 (>= 8c), libx11-6, libxext6, zlib1g (>= 1:1.2.0)
+ # MUPDF_STATIC_LDFLAGS misses mupdf-js-none, and doubles libs ...
+@@ -85,7 +89,7 @@ if(MUPDF_FOUND)
+ include_directories(SYSTEM ${MUPDF_INCLUDEDIR})
+ message(STATUS "mupdf libraries: ${MUPDF_LDFLAGS}")
+ set(K2PDFOPT_LIB ${K2PDFOPT_LIB} ${MUPDF_LDFLAGS}
+- -lmupdf-js-none -lopenjpeg -ljbig2dec -ljpeg -lfreetype
++
+ )
+ endif(MUPDF_FOUND)
+
+--
+2.27.0
+
diff --git a/pkgs/applications/misc/k2pdfopt/default.nix b/pkgs/applications/misc/k2pdfopt/default.nix
index 8899654cc4c8..431426e55fbd 100644
--- a/pkgs/applications/misc/k2pdfopt/default.nix
+++ b/pkgs/applications/misc/k2pdfopt/default.nix
@@ -1,5 +1,5 @@
-{ stdenv, fetchzip, fetchurl, fetchpatch, cmake, pkgconfig
-, zlib, libpng
+{ stdenv, runCommand, fetchzip, fetchurl, fetchpatch, fetchFromGitHub
+, cmake, pkgconfig, zlib, libpng, makeWrapper
, enableGSL ? true, gsl
, enableGhostScript ? true, ghostscript
, enableMuPDF ? true, mupdf
@@ -11,44 +11,132 @@
with stdenv.lib;
-stdenv.mkDerivation rec {
- pname = "k2pdfopt";
- version = "2.51a";
+# k2pdfopt is a pain to package. It requires modified versions of mupdf,
+# leptonica, and tesseract. Instead of shipping patches for these upstream
+# packages, k2pdfopt includes just the modified source files for these
+# packages. The individual files from the {mupdf,leptonica,tesseract}_mod/
+# directories are intended to replace the corresponding source files in the
+# upstream packages, for a particular version of that upstream package.
+#
+# There are a few ways we could approach packaging these modified versions of
+# mupdf, leptonica, and mupdf:
+# 1) Override the upstream source with a new derivation that involves copying
+# the modified source files from k2pdfopt and replacing the corresponding
+# source files in the upstream packages. Since the files are intended for a
+# particular version of the upstream package, this would not allow us to easily
+# use updates to those packages in nixpkgs.
+# 2) Manually produce patches which can be applied against the upstream
+# project, and have the same effect as replacing those files. This is what I
+# believe k2pdfopt should do this for us anyway. The benefit of creating and
+# applying patches in this way is that minor updates (esp. security fixes) to
+# upstream packages might still allow these patches to apply successfully.
+# 3) Automatically produce these patches inside a nix derivation. This is the
+# approach taken here, using the "mkPatch" provided below. This has the
+# benefit of easier review and should hopefully be simpler to update in the
+# future.
+
+let
+ # Create a patch against src based on changes applied in patchCommands
+ mkPatch = { name, src, patchCommands }: runCommand "${name}-k2pdfopt.patch" { inherit src; } ''
+ source $stdenv/setup
+ unpackPhase
- src = (fetchzip {
- url = "http://www.willus.com/k2pdfopt/src/k2pdfopt_v2.51_src.zip";
- sha256 = "133l7xkvi67s6sfk8cfh7rmavbsf7ib5fyksk1ci6b6sch3z2sw9";
- });
+ orig=$sourceRoot
+ new=$sourceRoot-modded
+ cp -r $orig/. $new/
- # Note: the v2.51a zip contains only files to be replaced in the v2.50 zip.
- v251a_src = (fetchzip {
- url = "http://www.willus.com/k2pdfopt/src/k2pdfopt_v2.51a_src.zip";
- sha256 = "0vvwblii7kgdwfxw8dzk6jbmz4dv94d7rkv18i60y8wkayj6yhl6";
- });
+ pushd $new >/dev/null
+ ${patchCommands}
+ popd >/dev/null
- postUnpack = ''
- cp -r ${v251a_src}/* $sourceRoot
+ diff -Naur $orig $new > $out || true
'';
- patches = [ ./k2pdfopt.patch ./k2pdfopt-mupdf-1.16.1.patch ];
+ pname = "k2pdfopt";
+ version = "2.53";
+ k2pdfopt_src = fetchzip {
+ url = "http://www.willus.com/${pname}/src/${pname}_v${version}_src.zip";
+ sha256 = "1fna8bg3pascjfc3hmc6xn0xi2yh7f1qp0d344mw9hqanbnykyy8";
+ };
+in stdenv.mkDerivation rec {
+ inherit pname version;
+ src = k2pdfopt_src;
+
+ patches = [
+ ./0001-Fix-CMakeLists.patch
+ ];
+
+ postPatch = ''
+ substituteInPlace willuslib/bmpdjvu.c \
+ --replace "<djvu.h>" "<libdjvu/ddjvuapi.h>"
+ '';
- nativeBuildInputs = [ cmake pkgconfig ];
+ nativeBuildInputs = [ cmake pkgconfig makeWrapper ];
buildInputs =
let
- # The patches below were constructed by taking the files from k2pdfopt in
- # the {mupdf,leptonica,tesseract}_mod/ directories, replacing the
- # corresponding files in the respective source trees, resolving any errors
- # with more recent versions of these depencencies, and running diff.
- mupdf_modded = mupdf.overrideAttrs (attrs: {
- patches = attrs.patches ++ [ ./mupdf.patch ]; # Last verified with mupdf 1.16.1
+ # We use specific versions of these sources below to match the versions
+ # used in the k2pdfopt source. Note that this does _not_ need to match the
+ # version used elsewhere in nixpkgs, since it is only used to create the
+ # patch that can then be applied to the version in nixpkgs.
+ mupdf_patch = mkPatch {
+ name = "mupdf";
+ src = fetchurl {
+ url = "https://mupdf.com/downloads/archive/mupdf-1.17.0-source.tar.gz";
+ sha256 = "13nl9nrcx2awz9l83mlv2psi1lmn3hdnfwxvwgwiwbxlkjl3zqq0";
+ };
+ patchCommands = ''
+ cp ${k2pdfopt_src}/mupdf_mod/{filter-basic,font,stext-device,string}.c ./source/fitz/
+ cp ${k2pdfopt_src}/mupdf_mod/pdf-* ./source/pdf/
+ '';
+ };
+ mupdf_modded = mupdf.overrideAttrs ({ patches ? [], ... }: {
+ patches = patches ++ [ mupdf_patch ];
+ # 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
+ '';
});
- leptonica_modded = leptonica.overrideAttrs (attrs: {
- patches = [ ./leptonica.patch ]; # Last verified with leptonica 1.78.0
+
+ leptonica_patch = mkPatch {
+ name = "leptonica";
+ src = fetchurl {
+ url = "http://www.leptonica.org/source/leptonica-1.79.0.tar.gz";
+ sha256 = "1n004gv1dj3pq1fcnfdclvvx5nang80336aa67nvs3nnqp4ncn84";
+ };
+ patchCommands = "cp -r ${k2pdfopt_src}/leptonica_mod/. ./src/";
+ };
+ leptonica_modded = leptonica.overrideAttrs ({ patches ? [], ... }: {
+ patches = patches ++ [ leptonica_patch ];
});
+
+ tesseract_patch = mkPatch {
+ name = "tesseract";
+ src = fetchFromGitHub {
+ owner = "tesseract-ocr";
+ repo = "tesseract";
+ rev = "4.1.1";
+ sha256 = "1ca27zbjpx35nxh9fha410z3jskwyj06i5hqiqdc08s2d7kdivwn";
+ };
+ patchCommands = ''
+ cp ${k2pdfopt_src}/tesseract_mod/{baseapi,tesscapi,tesseract}.* src/api/
+ cp ${k2pdfopt_src}/tesseract_mod/{tesscapi,tessedit,tesseract}.* src/ccmain/
+ cp ${k2pdfopt_src}/tesseract_mod/dotproduct{avx,fma,sse}.* src/arch/
+ cp ${k2pdfopt_src}/tesseract_mod/{intsimdmatrixsse,simddetect}.* src/arch/
+ cp ${k2pdfopt_src}/tesseract_mod/{errcode,genericvector,mainblk,params,serialis,tessdatamanager,tess_version,tprintf,unicharset}.* src/ccutil/
+ cp ${k2pdfopt_src}/tesseract_mod/{input,lstmrecognizer}.* src/lstm/
+ cp ${k2pdfopt_src}/tesseract_mod/openclwrapper.* src/opencl/
+ '';
+ };
tesseract_modded = tesseract4.override {
- tesseractBase = tesseract4.tesseractBase.overrideAttrs (_: {
- patches = [ ./tesseract.patch ]; # Last verified with tesseract 1.4
+ tesseractBase = tesseract4.tesseractBase.overrideAttrs ({ patches ? [], ... }: {
+ patches = patches ++ [ tesseract_patch ];
+ # Additional compilation fixes
+ postPatch = ''
+ echo libtesseract_api_la_SOURCES += tesscapi.cpp >> src/api/Makefile.am
+ substituteInPlace src/api/tesseract.h \
+ --replace "#include <leptonica.h>" "//#include <leptonica.h>"
+ '';
});
};
in
@@ -71,6 +159,10 @@ stdenv.mkDerivation rec {
install -D -m 755 k2pdfopt $out/bin/k2pdfopt
'';
+ preFixup = optionalString enableTesseract ''
+ wrapProgram $out/bin/k2pdfopt --set-default TESSDATA_PREFIX ${tesseract4}/share/tessdata
+ '';
+
meta = with stdenv.lib; {
description = "Optimizes PDF/DJVU files for mobile e-readers (e.g. the Kindle) and smartphones";
homepage = "http://www.willus.com/k2pdfopt";
diff --git a/pkgs/applications/misc/k2pdfopt/k2pdfopt-mupdf-1.16.1.patch b/pkgs/applications/misc/k2pdfopt/k2pdfopt-mupdf-1.16.1.patch
deleted file mode 100644
index 3a9eca30e751..000000000000
--- a/pkgs/applications/misc/k2pdfopt/k2pdfopt-mupdf-1.16.1.patch
+++ /dev/null
@@ -1,151 +0,0 @@
-diff --git a/willuslib/wmupdf.c b/willuslib/wmupdf.c
-index 81627ef..f14a96c 100644
---- a/willuslib/wmupdf.c
-+++ b/willuslib/wmupdf.c
-@@ -189,8 +189,6 @@ int wmupdf_remake_pdf(char *infile,char *outfile,WPDFPAGEINFO *pageinfo,int use_
- pdf_write_opts.do_compress=1;
- pdf_write_opts.do_linear=0;
- pdf_write_opts.do_garbage=1; /* 2 and 3 don't work for this. */
-- pdf_write_opts.continue_on_error=0;
-- pdf_write_opts.errors=NULL;
- write_failed=0;
- wpdfpageinfo_sort(pageinfo);
- xref=NULL;
-@@ -1687,8 +1685,8 @@ WPDFOUTLINE *wpdfoutline_read_from_pdf_file(char *filename)
- /* Sumatra version of MuPDF v1.4 -- use locally installed fonts */
- pdf_install_load_system_font_funcs(ctx);
- fz_try(ctx) { doc=fz_open_document(ctx,filename); }
-- fz_catch(ctx)
-- {
-+ fz_catch(ctx)
-+ {
- fz_drop_context(ctx);
- return(NULL);
- }
-@@ -1890,5 +1888,5 @@ static pdf_obj *pdf_new_string_utf8(fz_context *ctx,char *string)
- willus_mem_free((double **)&utfbuf,funcname);
- return(pdfobj);
- }
--
-+
- #endif /* HAVE_MUPDF_LIB */
-diff --git a/willuslib/wmupdfinfo.c b/willuslib/wmupdfinfo.c
-index 5c7f38c..9b9e6fd 100644
---- a/willuslib/wmupdfinfo.c
-+++ b/willuslib/wmupdfinfo.c
-@@ -237,23 +237,22 @@ static void showglobalinfo(fz_context *ctx, globals *glo,char *filename)
- pdf_obj *robj;
-
- robj=pdf_resolve_indirect(ctx,obj);
-- n=pdf_sprint_obj(ctx,NULL,0,robj,1);
-- buf=malloc(n+2);
-+ buf=pdf_sprint_obj(ctx,NULL,0,&n,robj,1,0);
- if (buf==NULL)
- {
- fz_write_printf(ctx,out,"Info object (%d %d R):\n",pdf_to_num(ctx,obj),pdf_to_gen(ctx,obj));
-- pdf_print_obj(ctx,out,robj,1);
-+ pdf_print_obj(ctx,out,robj,1,0);
- }
- else
- {
-- pdf_sprint_obj(ctx,buf,n+2,robj,1);
-+ pdf_sprint_obj(ctx,buf,n+2,&n,robj,1,0);
- display_pdf_field(ctx,out,buf,"Title","TITLE");
- display_pdf_field(ctx,out,buf,"CreationDate","CREATED");
- display_pdf_field(ctx,out,buf,"ModDate","LAST MODIFIED");
- display_pdf_field(ctx,out,buf,"Producer","PDF PRODUCER");
- display_pdf_field(ctx,out,buf,"Creator","CREATOR");
- display_file_size(ctx,out,filename);
-- free(buf);
-+ fz_free(ctx,buf);
- }
- }
- if (glo->dims==1)
-@@ -275,7 +274,7 @@ static void showglobalinfo(fz_context *ctx, globals *glo,char *filename)
- if (obj)
- {
- fz_write_printf(ctx,out, "\nEncryption object (%d %d R):\n", pdf_to_num(ctx,obj), pdf_to_gen(ctx,obj));
-- pdf_print_obj(ctx,out, pdf_resolve_indirect(ctx,obj), 1);
-+ pdf_print_obj(ctx,out, pdf_resolve_indirect(ctx,obj), 1, 0);
- }
- }
-
-@@ -396,7 +395,7 @@ gatherdimensions(fz_context *ctx, globals *glo, int page, pdf_obj *pageref, pdf_
- if (j < glo->dims)
- return;
-
-- glo->dim = fz_resize_array(ctx, glo->dim, glo->dims+1, sizeof(struct info));
-+ glo->dim = fz_realloc_array(ctx, glo->dim, glo->dims+1, struct info);
- glo->dims++;
-
- glo->dim[glo->dims - 1].page = page;
-@@ -441,7 +440,7 @@ gatherfonts(fz_context *ctx, globals *glo, int page, pdf_obj *pageref, pdf_obj *
- if (k < glo->fonts)
- continue;
-
-- glo->font = fz_resize_array(ctx, glo->font, glo->fonts+1, sizeof(struct info));
-+ glo->font = fz_realloc_array(ctx, glo->font, glo->fonts+1, struct info);
- glo->fonts++;
-
- glo->font[glo->fonts - 1].page = page;
-@@ -510,7 +509,7 @@ gatherimages(fz_context *ctx, globals *glo, int page, pdf_obj *pageref, pdf_obj
- if (k < glo->images)
- continue;
-
-- glo->image = fz_resize_array(ctx, glo->image, glo->images+1, sizeof(struct info));
-+ glo->image = fz_realloc_array(ctx, glo->image, glo->images+1, struct info);
- glo->images++;
-
- glo->image[glo->images - 1].page = page;
-@@ -568,7 +567,7 @@ gatherforms(fz_context *ctx, globals *glo, int page, pdf_obj *pageref, pdf_obj *
- if (k < glo->forms)
- continue;
-
-- glo->form = fz_resize_array(ctx, glo->form, glo->forms+1, sizeof(struct info));
-+ glo->form = fz_realloc_array(ctx, glo->form, glo->forms+1, struct info);
- glo->forms++;
-
- glo->form[glo->forms - 1].page = page;
-@@ -613,7 +612,7 @@ gatherpsobjs(fz_context *ctx, globals *glo, int page, pdf_obj *pageref, pdf_obj
- if (k < glo->psobjs)
- continue;
-
-- glo->psobj = fz_resize_array(ctx, glo->psobj, glo->psobjs+1, sizeof(struct info));
-+ glo->psobj = fz_realloc_array(ctx, glo->psobj, glo->psobjs+1, struct info);
- glo->psobjs++;
-
- glo->psobj[glo->psobjs - 1].page = page;
-@@ -656,7 +655,7 @@ gathershadings(fz_context *ctx, globals *glo, int page, pdf_obj *pageref, pdf_ob
- if (k < glo->shadings)
- continue;
-
-- glo->shading = fz_resize_array(ctx, glo->shading, glo->shadings+1, sizeof(struct info));
-+ glo->shading = fz_realloc_array(ctx, glo->shading, glo->shadings+1, struct info);
- glo->shadings++;
-
- glo->shading[glo->shadings - 1].page = page;
-@@ -724,7 +723,7 @@ gatherpatterns(fz_context *ctx, globals *glo, int page, pdf_obj *pageref, pdf_ob
- if (k < glo->patterns)
- continue;
-
-- glo->pattern = fz_resize_array(ctx, glo->pattern, glo->patterns+1, sizeof(struct info));
-+ glo->pattern = fz_realloc_array(ctx, glo->pattern, glo->patterns+1, struct info);
- glo->patterns++;
-
- glo->pattern[glo->patterns - 1].page = page;
-@@ -1216,7 +1215,7 @@ void wmupdfinfo_get(char *filename,int *pagelist,char **buf)
- if (fout==NULL)
- return;
- */
--
-+
- ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
- if (!ctx)
- {
-@@ -1307,5 +1306,5 @@ static void date_convert(char *dst,char *src)
- else if (src[i]!='\0')
- sprintf(&dst[strlen(dst)]," %s",&src[i]);
- }
--
-+
- #endif /* HAVE_MUPDF_LIB */
diff --git a/pkgs/applications/misc/k2pdfopt/k2pdfopt.patch b/pkgs/applications/misc/k2pdfopt/k2pdfopt.patch
deleted file mode 100644
index cf7e4896b803..000000000000
--- a/pkgs/applications/misc/k2pdfopt/k2pdfopt.patch
+++ /dev/null
@@ -1,99 +0,0 @@
-diff --git a/CMakeLists.txt b/CMakeLists.txt
-index 4a2378b..502c477 100644
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
-@@ -52,6 +52,7 @@ endif(JPEG_FOUND)
- include(FindJasper)
- if(JASPER_FOUND)
- set(HAVE_JASPER_LIB 1)
-+ set(K2PDFOPT_LIB ${K2PDFOPT_LIB} ${JASPER_LIBRARY})
- endif(JASPER_FOUND)
-
- # paths from willuslib/wgs.c
-@@ -66,8 +67,12 @@ else()
- message(STATUS "Could NOT find ghostscript executable")
- endif(GHOSTSCRIPT_EXECUTABLE)
-
--# willus.h
--# HAVE_GSL_LIB
-+pkg_check_modules(GSL gsl)
-+if(GSL_FOUND)
-+ set(HAVE_GSL_LIB 1)
-+ include_directories(SYSTEM ${GSL_INCLUDEDIR})
-+ set(K2PDFOPT_LIB ${K2PDFOPT_LIB} ${GSL_LDFLAGS})
-+endif(GSL_FOUND)
-
-
- # libfreetype6 (>= 2.3.9), libjbig2dec0, libjpeg8 (>= 8c), libx11-6, libxext6, zlib1g (>= 1:1.2.0)
-@@ -80,7 +85,7 @@ if(MUPDF_FOUND)
- include_directories(SYSTEM ${MUPDF_INCLUDEDIR})
- message(STATUS "mupdf libraries: ${MUPDF_LDFLAGS}")
- set(K2PDFOPT_LIB ${K2PDFOPT_LIB} ${MUPDF_LDFLAGS}
-- -lmupdf-js-none -lopenjpeg -ljbig2dec -ljpeg -lfreetype
-+
- )
- endif(MUPDF_FOUND)
-
-@@ -91,9 +96,25 @@ if(DJVU_FOUND)
- set(K2PDFOPT_LIB ${K2PDFOPT_LIB} ${DJVU_LDFLAGS})
- endif(DJVU_FOUND)
-
--# HAVE_GOCR_LIB
--# HAVE_LEPTONICA_LIB
--# HAVE_TESSERACT_LIB
-+find_library(GOCR_LIB NAMES Pgm2asc)
-+if(GOCR_LIB)
-+ set(HAVE_GOCR_LIB 1)
-+ set(K2PDFOPT_LIB ${K2PDFOPT_LIB} ${GOCR_LIB})
-+endif(GOCR_LIB)
-+
-+pkg_check_modules(LEPTONICA lept)
-+if(LEPTONICA_FOUND)
-+ set(HAVE_LEPTONICA_LIB 1)
-+ include_directories(SYSTEM ${LEPTONICA_INCLUDEDIR})
-+ set(K2PDFOPT_LIB ${K2PDFOPT_LIB} ${LEPTONICA_LDFLAGS})
-+endif(LEPTONICA_FOUND)
-+
-+pkg_check_modules(TESSERACT tesseract)
-+if(TESSERACT_FOUND)
-+ set(HAVE_TESSERACT_LIB 1)
-+ include_directories(SYSTEM ${TESSERACT_INCLUDEDIR})
-+ set(K2PDFOPT_LIB ${K2PDFOPT_LIB} ${TESSERACT_LDFLAGS})
-+endif(TESSERACT_FOUND)
-
- # ---- Describe project
-
-diff --git a/willuslib/CMakeLists.txt b/willuslib/CMakeLists.txt
-index 463bbc9..8043db5 100644
---- a/willuslib/CMakeLists.txt
-+++ b/willuslib/CMakeLists.txt
-@@ -6,7 +6,7 @@ include_directories(..)
- set(WILLUSLIB_SRC
- ansi.c array.c bmp.c bmpdjvu.c bmpmupdf.c dtcompress.c filelist.c
- fontdata.c fontrender.c gslpolyfit.c linux.c math.c mem.c ocr.c
-- ocrjocr.c ocrtess.c pdfwrite.c point2d.c render.c strbuf.c string.c
-+ ocrgocr.c ocrtess.c pdfwrite.c point2d.c render.c strbuf.c string.c
- token.c wfile.c wgs.c wgui.c willusversion.c win.c winbmp.c
- wincomdlg.c winmbox.c winshell.c wmupdf.c wmupdfinfo.c wpdf.c wsys.c
- wzfile.c wleptonica.c
-diff --git a/willuslib/ocrgocr.c b/willuslib/ocrgocr.c
-index 6027e9a..fbe10f0 100644
---- a/willuslib/ocrgocr.c
-+++ b/willuslib/ocrgocr.c
-@@ -29,6 +29,8 @@
- #ifdef HAVE_GOCR_LIB
- #include <gocr.h>
-
-+job_t *OCR_JOB;
-+
- /*
- ** bmp8 must be grayscale
- ** (x1,y1) and (x2,y2) from top left of bitmap
-@@ -63,6 +65,7 @@ void gocr_single_word_from_bmp8(char *text,int maxlen,WILLUSBITMAP *bmp8,
- h=y2-y1+1;
- dh=h+bw*2;
- job=&_job;
-+ OCR_JOB=job;
- job_init(job);
- job_init_image(job);
- // willus_mem_alloc_warn((void **)&job->src.p.p,w*h,funcname,10);
diff --git a/pkgs/applications/misc/k2pdfopt/leptonica.patch b/pkgs/applications/misc/k2pdfopt/leptonica.patch
deleted file mode 100644
index dfab99fd0130..000000000000
--- a/pkgs/applications/misc/k2pdfopt/leptonica.patch
+++ /dev/null
@@ -1,254 +0,0 @@
-From 8c11a20925686855023df90ed477957c7d7fe91e Mon Sep 17 00:00:00 2001
-From: Daniel Fullmer <danielrf12@gmail.com>
-Date: Fri, 13 Sep 2019 15:54:21 -0400
-Subject: [PATCH] Willus mod for k2pdfopt
-
----
- src/allheaders.h | 4 ++
- src/dewarp2.c | 106 ++++++++++++++++++++++++++++++++++++++++++-----
- src/leptwin.c | 6 ++-
- 3 files changed, 104 insertions(+), 12 deletions(-)
-
-diff --git a/src/allheaders.h b/src/allheaders.h
-index e68eff1..b3cc729 100644
---- a/src/allheaders.h
-+++ b/src/allheaders.h
-@@ -669,6 +669,10 @@ LEPT_DLL extern L_DEWARPA * dewarpaReadMem ( const l_uint8 *data, size_t size );
- LEPT_DLL extern l_ok dewarpaWrite ( const char *filename, L_DEWARPA *dewa );
- LEPT_DLL extern l_ok dewarpaWriteStream ( FILE *fp, L_DEWARPA *dewa );
- LEPT_DLL extern l_ok dewarpaWriteMem ( l_uint8 **pdata, size_t *psize, L_DEWARPA *dewa );
-+/* WILLUS MOD */
-+ LEPT_DLL extern l_int32 dewarpBuildPageModel_ex ( L_DEWARP *dew, const char *debugfile,l_int32 fit_order );
-+ LEPT_DLL extern l_int32 dewarpFindVertDisparity_ex ( L_DEWARP *dew, PTAA *ptaa, l_int32 rotflag,l_int32 fit_order );
-+ LEPT_DLL extern l_int32 dewarpBuildLineModel_ex ( L_DEWARP *dew, l_int32 opensize, const char *debugfile,l_int32 fit_order );
- LEPT_DLL extern l_ok dewarpBuildPageModel ( L_DEWARP *dew, const char *debugfile );
- LEPT_DLL extern l_ok dewarpFindVertDisparity ( L_DEWARP *dew, PTAA *ptaa, l_int32 rotflag );
- LEPT_DLL extern l_ok dewarpFindHorizDisparity ( L_DEWARP *dew, PTAA *ptaa );
-diff --git a/src/dewarp2.c b/src/dewarp2.c
-index 220eec1..2e29500 100644
---- a/src/dewarp2.c
-+++ b/src/dewarp2.c
-@@ -144,9 +144,17 @@ static const l_float32 L_ALLOWED_W_FRACT = 0.05; /* no bigger */
- * longest textlines.
- * </pre>
- */
-+/* WILLUS MOD */
- l_ok
--dewarpBuildPageModel(L_DEWARP *dew,
-- const char *debugfile)
-+dewarpBuildPageModel(L_DEWARP *dew,const char *debugfile)
-+{
-+return(dewarpBuildPageModel_ex(dew,debugfile,2));
-+}
-+
-+l_ok
-+dewarpBuildPageModel_ex(L_DEWARP *dew,
-+ const char *debugfile,
-+ l_int32 fit_order)
- {
- l_int32 linecount, topline, botline, ret;
- PIX *pixs, *pix1, *pix2, *pix3;
-@@ -225,7 +233,7 @@ PTAA *ptaa1, *ptaa2;
- /* Get the sampled vertical disparity from the textline centers.
- * The disparity array will push pixels vertically so that each
- * textline is flat and centered at the y-position of the mid-point. */
-- if (dewarpFindVertDisparity(dew, ptaa2, 0) != 0) {
-+ if (dewarpFindVertDisparity_ex(dew, ptaa2, 0, fit_order) != 0) {
- L_WARNING("vertical disparity not built\n", procName);
- ptaaDestroy(&ptaa2);
- return 1;
-@@ -290,13 +298,24 @@ PTAA *ptaa1, *ptaa2;
- * a pdf. Non-pix debug output goes to /tmp.
- * </pre>
- */
-+/* WILLUS MOD */
- l_ok
- dewarpFindVertDisparity(L_DEWARP *dew,
- PTAA *ptaa,
- l_int32 rotflag)
- {
-+return(dewarpFindVertDisparity_ex(dew,ptaa,rotflag,2));
-+}
-+/* WILLUS MOD -- add cubic and quartic fits and ..._ex functions */
-+l_int32
-+dewarpFindVertDisparity_ex(L_DEWARP *dew,
-+ PTAA *ptaa,
-+ l_int32 rotflag,
-+ l_int32 fit_order)
-+{
- l_int32 i, j, nlines, npts, nx, ny, sampling;
--l_float32 c0, c1, c2, x, y, midy, val, medval, meddev, minval, maxval;
-+/* WILLUS MOD */
-+l_float32 c0, c1, c2, c3, c4, x, y, midy, val, medval, meddev, minval, maxval;
- l_float32 *famidys;
- NUMA *nax, *nafit, *nacurve0, *nacurve1, *nacurves;
- NUMA *namidy, *namidys, *namidysi;
-@@ -304,11 +323,22 @@ PIX *pix1, *pix2, *pixcirc, *pixdb;
- PTA *pta, *ptad, *ptacirc;
- PTAA *ptaa0, *ptaa1, *ptaa2, *ptaa3, *ptaa4, *ptaa5, *ptaat;
- FPIX *fpix;
-+/* WILLUS MOD */
-+l_int32 fit_order1,fit_order2;
-
- PROCNAME("dewarpFindVertDisparity");
-
- if (!dew)
- return ERROR_INT("dew not defined", procName, 1);
-+/* WILLUS MOD */
-+ if (fit_order < 10)
-+ fit_order1 = fit_order2 = fit_order;
-+ else
-+ {
-+ fit_order1=fit_order % 10;
-+ fit_order2=fit_order / 10;
-+ fit_order2=fit_order2 % 10;
-+ }
- dew->vsuccess = 0;
- if (!ptaa)
- return ERROR_INT("ptaa not defined", procName, 1);
-@@ -331,12 +361,32 @@ FPIX *fpix;
- pixdb = (rotflag) ? pixRotateOrth(dew->pixs, 1) : pixClone(dew->pixs);
- for (i = 0; i < nlines; i++) { /* for each line */
- pta = ptaaGetPta(ptaa, i, L_CLONE);
-- ptaGetQuadraticLSF(pta, &c2, &c1, &c0, NULL);
-- numaAddNumber(nacurve0, c2);
-+/* WILLUS MOD */
-+if (fit_order1>3)
-+ {
-+ ptaGetQuarticLSF(pta, &c4, &c3, &c2, &c1, &c0, NULL);
-+ numaAddNumber(nacurve0, c4);
-+ }
-+else if (fit_order1==3)
-+ {
-+ ptaGetCubicLSF(pta, &c3, &c2, &c1, &c0, NULL);
-+ numaAddNumber(nacurve0, c3);
-+ }
-+else
-+ {
-+ ptaGetQuadraticLSF(pta, &c2, &c1, &c0, NULL);
-+ numaAddNumber(nacurve0, c2);
-+ }
- ptad = ptaCreate(nx);
- for (j = 0; j < nx; j++) { /* uniformly sampled in x */
- x = j * sampling;
-- applyQuadraticFit(c2, c1, c0, x, &y);
-+/* WILLUS MOD */
-+if (fit_order1>3)
-+ applyQuarticFit(c4, c3, c2, c1, c0, x, &y);
-+else if (fit_order1==3)
-+ applyCubicFit(c3, c2, c1, c0, x, &y);
-+else
-+ applyQuadraticFit(c2, c1, c0, x, &y);
- ptaAddPt(ptad, x, y);
- }
- ptaaAddPta(ptaa0, ptad, L_INSERT);
-@@ -350,7 +400,13 @@ FPIX *fpix;
- for (i = 0; i < nlines; i++) {
- pta = ptaaGetPta(ptaa, i, L_CLONE);
- ptaGetArrays(pta, &nax, NULL);
-- ptaGetQuadraticLSF(pta, NULL, NULL, NULL, &nafit);
-+/* WILLUS MOD */
-+if (fit_order1>3)
-+ptaGetQuarticLSF(pta, NULL, NULL, NULL, NULL, NULL, &nafit);
-+else if (fit_order1==3)
-+ptaGetCubicLSF(pta, NULL, NULL, NULL, NULL, &nafit);
-+else
-+ptaGetQuadraticLSF(pta, NULL, NULL, NULL, &nafit);
- ptad = ptaCreateFromNuma(nax, nafit);
- ptaaAddPta(ptaat, ptad, L_INSERT);
- ptaDestroy(&pta);
-@@ -494,11 +550,24 @@ FPIX *fpix;
- ptaa5 = ptaaCreate(nx); /* uniformly sampled across full height of image */
- for (j = 0; j < nx; j++) { /* for each column */
- pta = ptaaGetPta(ptaa4, j, L_CLONE);
-- ptaGetQuadraticLSF(pta, &c2, &c1, &c0, NULL);
-+/* WILLUS MOD */
-+/* Order higher than 2 can cause a little craziness here. */
-+if (fit_order2>3)
-+ ptaGetQuarticLSF(pta, &c4, &c3, &c2, &c1, &c0, NULL);
-+else if (fit_order2==3)
-+ ptaGetCubicLSF(pta, &c3, &c2, &c1, &c0, NULL);
-+else
-+ ptaGetQuadraticLSF(pta, &c2, &c1, &c0, NULL);
- ptad = ptaCreate(ny);
- for (i = 0; i < ny; i++) { /* uniformly sampled in y */
- y = i * sampling;
-- applyQuadraticFit(c2, c1, c0, y, &val);
-+/* WILLUS MOD */
-+if (fit_order2>3)
-+ applyQuarticFit(c4, c3, c2, c1, c0, y, &val);
-+else if (fit_order2==3)
-+ applyCubicFit(c3, c2, c1, c0, y, &val);
-+else
-+ applyQuadraticFit(c2, c1, c0, y, &val);
- ptaAddPt(ptad, y, val);
- }
- ptaaAddPta(ptaa5, ptad, L_INSERT);
-@@ -1602,11 +1671,21 @@ FPIX *fpix;
- * See notes there.
- * </pre>
- */
-+/* WILLUS MOD */
- l_ok
- dewarpBuildLineModel(L_DEWARP *dew,
- l_int32 opensize,
- const char *debugfile)
- {
-+return(dewarpBuildLineModel_ex(dew,opensize,debugfile,2));
-+}
-+
-+l_int32
-+dewarpBuildLineModel_ex(L_DEWARP *dew,
-+ l_int32 opensize,
-+ const char *debugfile,
-+ l_int32 fit_order)
-+{
- char buf[64];
- l_int32 i, j, bx, by, ret, nlines;
- BOXA *boxa;
-@@ -1695,6 +1774,8 @@ PTAA *ptaa1, *ptaa2;
-
- /* Remove all lines that are not at least 0.75 times the length
- * of the longest line. */
-+/* WILLUS MOD */
-+/*
- ptaa2 = dewarpRemoveShortLines(pix, ptaa1, 0.75, DEBUG_SHORT_LINES);
- if (debugfile) {
- pix1 = pixConvertTo32(pix);
-@@ -1704,6 +1785,8 @@ PTAA *ptaa1, *ptaa2;
- pixDestroy(&pix1);
- pixDestroy(&pix2);
- }
-+*/
-+ptaa2=ptaa1;
- ptaaDestroy(&ptaa1);
- nlines = ptaaGetCount(ptaa2);
- if (nlines < dew->minlines) {
-@@ -1717,7 +1800,8 @@ PTAA *ptaa1, *ptaa2;
- * centers. The disparity array will push pixels vertically
- * so that each line is flat and centered at the y-position
- * of the mid-point. */
-- ret = dewarpFindVertDisparity(dew, ptaa2, 1 - i);
-+/* WILLUS MOD */
-+ ret = dewarpFindVertDisparity_ex(dew, ptaa2, 1 - i, fit_order);
-
- /* If i == 0, move the result to the horizontal disparity,
- * rotating it back by -90 degrees. */
-diff --git a/src/leptwin.c b/src/leptwin.c
-index 72643a0..573d33e 100644
---- a/src/leptwin.c
-+++ b/src/leptwin.c
-@@ -364,5 +364,9 @@ PIXCMAP *cmap;
-
- return hBitmap;
- }
--
-+#else
-+/* willus mod: Avoid weird issue with OS/X library archiver when there are no symbols */
-+int leptwin_my_empty_func(void);
-+int leptwin_my_empty_func(void)
-+{return(0);}
- #endif /* _WIN32 */
---
-2.22.0
-
diff --git a/pkgs/applications/misc/k2pdfopt/mupdf.patch b/pkgs/applications/misc/k2pdfopt/mupdf.patch
deleted file mode 100644
index 0c59a1d20163..000000000000
--- a/pkgs/applications/misc/k2pdfopt/mupdf.patch
+++ /dev/null
@@ -1,1060 +0,0 @@
-From d8927c969e3387ca2669a616c0ba53bce918a031 Mon Sep 17 00:00:00 2001
-From: Daniel Fullmer <danielrf12@gmail.com>
-Date: Fri, 13 Sep 2019 15:11:45 -0400
-Subject: [PATCH] Willus mod for k2pdfopt
-
----
- source/fitz/filter-basic.c | 3 +
- source/fitz/font-win32.c | 866 +++++++++++++++++++++++++++++++++++++
- source/fitz/font.c | 3 +
- source/fitz/stext-device.c | 5 +
- source/fitz/string.c | 5 +
- source/pdf/pdf-annot.c | 14 +-
- source/pdf/pdf-link.c | 3 +
- source/pdf/pdf-parse.c | 5 +
- source/pdf/pdf-xref.c | 9 +
- 9 files changed, 912 insertions(+), 1 deletion(-)
- create mode 100644 source/fitz/font-win32.c
-
-diff --git a/source/fitz/filter-basic.c b/source/fitz/filter-basic.c
-index 0713a62e7..b8ef4d292 100644
---- a/source/fitz/filter-basic.c
-+++ b/source/fitz/filter-basic.c
-@@ -259,7 +259,10 @@ look_for_endstream:
- if (!state->warned)
- {
- state->warned = 1;
-+/* willus mod -- no warning */
-+/*
- fz_warn(ctx, "PDF stream Length incorrect");
-+*/
- }
- return *stm->rp++;
- }
-diff --git a/source/fitz/font-win32.c b/source/fitz/font-win32.c
-new file mode 100644
-index 000000000..45de8cfd3
---- /dev/null
-+++ b/source/fitz/font-win32.c
-@@ -0,0 +1,866 @@
-+/*
-+** Routines to access MS Windows system fonts.
-+** From sumatra PDF distro.
-+** Modified for MuPDF v1.9a by willus.com
-+*/
-+#include "mupdf/pdf.h"
-+
-+/*
-+ Which fonts are embedded is based on a few preprocessor definitions.
-+
-+ The base 14 fonts are always embedded.
-+ For CJK font substitution we embed DroidSansFallback.
-+
-+ Set NOCJK to skip all CJK support (this also omits embedding the CJK CMaps)
-+ Set NOCJKFONT to skip the embedded CJK font.
-+ Set NOCJKFULL to embed a smaller CJK font without CJK Extension A support.
-+*/
-+
-+#ifdef NOCJK
-+#define NOCJKFONT
-+#endif
-+
-+/* SumatraPDF: also load fonts included with Windows */
-+#ifdef _WIN32
-+
-+#ifndef UNICODE
-+#define UNICODE
-+#endif
-+#ifndef _UNICODE
-+#define _UNICODE
-+#endif
-+
-+#include <windows.h>
-+
-+// TODO: Use more of FreeType for TTF parsing (for performance reasons,
-+// the fonts can't be parsed completely, though)
-+#include <ft2build.h>
-+#include FT_TRUETYPE_IDS_H
-+#include FT_TRUETYPE_TAGS_H
-+
-+#define TTC_VERSION1 0x00010000
-+#define TTC_VERSION2 0x00020000
-+
-+#define MAX_FACENAME 128
-+
-+// Note: the font face must be the first field so that the structure
-+// can be treated like a simple string for searching
-+typedef struct pdf_fontmapMS_s
-+{
-+ char fontface[MAX_FACENAME];
-+ char fontpath[MAX_PATH];
-+ int index;
-+} pdf_fontmapMS;
-+
-+typedef struct pdf_fontlistMS_s
-+{
-+ pdf_fontmapMS *fontmap;
-+ int len;
-+ int cap;
-+} pdf_fontlistMS;
-+
-+typedef struct _tagTT_OFFSET_TABLE
-+{
-+ ULONG uVersion;
-+ USHORT uNumOfTables;
-+ USHORT uSearchRange;
-+ USHORT uEntrySelector;
-+ USHORT uRangeShift;
-+} TT_OFFSET_TABLE;
-+
-+typedef struct _tagTT_TABLE_DIRECTORY
-+{
-+ ULONG uTag; //table name
-+ ULONG uCheckSum; //Check sum
-+ ULONG uOffset; //Offset from beginning of file
-+ ULONG uLength; //length of the table in bytes
-+} TT_TABLE_DIRECTORY;