about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/misc/k2pdfopt
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2019-01-07 02:18:36 +0000
committerAlyssa Ross <hi@alyssa.is>2019-01-07 02:18:47 +0000
commit36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2 (patch)
treeb3faaf573407b32aa645237a4d16b82778a39a92 /nixpkgs/pkgs/applications/misc/k2pdfopt
parent4e31070265257dc67d120c27e0f75c2344fdfa9a (diff)
parentabf060725d7614bd3b9f96764262dfbc2f9c2199 (diff)
downloadnixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.gz
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.bz2
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.lz
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.xz
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.zst
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.zip
Add 'nixpkgs/' from commit 'abf060725d7614bd3b9f96764262dfbc2f9c2199'
git-subtree-dir: nixpkgs
git-subtree-mainline: 4e31070265257dc67d120c27e0f75c2344fdfa9a
git-subtree-split: abf060725d7614bd3b9f96764262dfbc2f9c2199
Diffstat (limited to 'nixpkgs/pkgs/applications/misc/k2pdfopt')
-rw-r--r--nixpkgs/pkgs/applications/misc/k2pdfopt/default.nix119
-rw-r--r--nixpkgs/pkgs/applications/misc/k2pdfopt/k2pdfopt.patch99
-rw-r--r--nixpkgs/pkgs/applications/misc/k2pdfopt/load-jpx.patch29
-rw-r--r--nixpkgs/pkgs/applications/misc/k2pdfopt/tesseract.patch13
4 files changed, 260 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/applications/misc/k2pdfopt/default.nix b/nixpkgs/pkgs/applications/misc/k2pdfopt/default.nix
new file mode 100644
index 000000000000..8f69abd3a987
--- /dev/null
+++ b/nixpkgs/pkgs/applications/misc/k2pdfopt/default.nix
@@ -0,0 +1,119 @@
+{ stdenv, fetchzip, fetchurl, fetchpatch, cmake, pkgconfig
+, zlib, libpng, openjpeg
+, enableGSL ? true, gsl
+, enableGhostScript ? true, ghostscript
+, enableMuPDF ? true, mupdf
+, enableJPEG2K ? true, jasper
+, enableDJVU ? true, djvulibre
+, enableGOCR ? false, gocr # Disabled by default due to crashes
+, enableTesseract ? true, leptonica, tesseract
+}:
+
+with stdenv.lib;
+
+stdenv.mkDerivation rec {
+  name = "k2pdfopt-${version}";
+  version = "2.42";
+
+  src = fetchzip {
+    url = "http://www.willus.com/k2pdfopt/src/k2pdfopt_v${version}_src.zip";
+    sha256 = "1zag4jmkr0qrcpqqb5davmvdrabhdyz87q4zz0xpfkl6xw2dn9bk";
+  };
+
+  patches = [ ./k2pdfopt.patch ];
+
+  nativeBuildInputs = [ cmake pkgconfig ];
+
+  buildInputs =
+  let
+    mupdf_modded = mupdf.overrideAttrs (attrs: {
+      name = "mupdf-1.10a";
+      version = "1.10a";
+      src = fetchurl {
+        url = "https://mupdf.com/downloads/archive/mupdf-1.10a-source.tar.gz";
+        sha256 = "0dm8wcs8i29aibzkqkrn8kcnk4q0kd1v66pg48h5c3qqp4v1zk5a";
+      };
+      # Excluded the pdf-*.c files, since they mostly just broke the #includes
+      prePatch = ''
+        cp ${src}/mupdf_mod/{font,stext-device,string}.c source/fitz/
+        cp ${src}/mupdf_mod/font-win32.c source/pdf/
+      '';
+      # Patches from previous 1.10a version in nixpkgs
+      patches = [
+        # Compatibility with new openjpeg
+        ./load-jpx.patch
+
+        (fetchurl {
+         name = "CVE-2017-5896.patch";
+         url = "http://git.ghostscript.com/?p=mupdf.git;a=patch;h=2c4e5867ee699b1081527bc6c6ea0e99a35a5c27";
+         sha256 = "14k7x47ifx82sds1c06ibzbmcparfg80719jhgwjk6w1vkh4r693";
+        })
+
+        (fetchpatch {
+          name = "mupdf-1.10a-shared_libs-1.patch";
+          url = "https://ftp.osuosl.org/pub/blfs/conglomeration/mupdf/mupdf-1.10a-shared_libs-1.patch";
+          sha256 = "0kg4vahp7hlyyj5hl18brk8s8xcbqrx19pqjzkfq6ha8mqa3k4ab";
+        })
+      ];
+
+      # Override this since the jpeg directory was renamed libjpeg in mupdf 1.11
+      preConfigure = ''
+        # Don't remove mujs because upstream version is incompatible
+        rm -rf thirdparty/{curl,freetype,glfw,harfbuzz,jbig2dec,jpeg,openjpeg,zlib}
+      '';
+      postPatch = let
+        # OpenJPEG version is hardcoded in package source
+        openJpegVersion = with stdenv;
+          lib.concatStringsSep "." (lib.lists.take 2
+          (lib.splitString "." (lib.getVersion openjpeg)));
+        in ''
+          sed -i "s/__OPENJPEG__VERSION__/${openJpegVersion}/" source/fitz/load-jpx.c
+        '';
+    });
+    leptonica_modded = leptonica.overrideAttrs (attrs: {
+      prePatch = ''
+        cp ${src}/leptonica_mod/* src/
+      '';
+    });
+    tesseract_modded = tesseract.override {
+      tesseractBase = tesseract.tesseractBase.overrideAttrs (_: {
+        prePatch = ''
+          cp ${src}/tesseract_mod/{ambigs.cpp,ccutil.h,ccutil.cpp} ccutil/
+          cp ${src}/tesseract_mod/dawg.cpp api/
+          cp ${src}/tesseract_mod/{imagedata.cpp,tessdatamanager.cpp} ccstruct/
+          cp ${src}/tesseract_mod/openclwrapper.h opencl/
+          cp ${src}/tesseract_mod/{tessedit.cpp,thresholder.cpp} ccmain/
+          cp ${src}/tesseract_mod/tess_lang_mod_edge.h cube/
+          cp ${src}/tesseract_mod/tesscapi.cpp api/
+          cp ${src}/include_mod/{tesseract.h,leptonica.h} api/
+        '';
+        patches = [ ./tesseract.patch ];
+      });
+    };
+  in
+    [ zlib libpng ] ++
+    optional enableGSL gsl ++
+    optional enableGhostScript ghostscript ++
+    optional enableMuPDF mupdf_modded ++
+    optional enableJPEG2K jasper ++
+    optional enableDJVU djvulibre ++
+    optional enableGOCR gocr ++
+    optionals enableTesseract [ leptonica_modded tesseract_modded ];
+
+  dontUseCmakeBuildDir = true;
+
+  cmakeFlags = [ "-DCMAKE_C_FLAGS=-I${src}/include_mod" ];
+
+  installPhase = ''
+    install -D -m 755 k2pdfopt $out/bin/k2pdfopt
+  '';
+
+  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;
+    license = licenses.gpl3;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ bosu danielfullmer ];
+  };
+}
+
diff --git a/nixpkgs/pkgs/applications/misc/k2pdfopt/k2pdfopt.patch b/nixpkgs/pkgs/applications/misc/k2pdfopt/k2pdfopt.patch
new file mode 100644
index 000000000000..cf7e4896b803
--- /dev/null
+++ b/nixpkgs/pkgs/applications/misc/k2pdfopt/k2pdfopt.patch
@@ -0,0 +1,99 @@
+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/nixpkgs/pkgs/applications/misc/k2pdfopt/load-jpx.patch b/nixpkgs/pkgs/applications/misc/k2pdfopt/load-jpx.patch
new file mode 100644
index 000000000000..02a3799d040a
--- /dev/null
+++ b/nixpkgs/pkgs/applications/misc/k2pdfopt/load-jpx.patch
@@ -0,0 +1,29 @@
+--- a/source/fitz/load-jpx.c
++++ b/source/fitz/load-jpx.c
+@@ -484,12 +484,16 @@
+ /* Without the definition of OPJ_STATIC, compilation fails on windows
+  * due to the use of __stdcall. We believe it is required on some
+  * linux toolchains too. */
++#ifdef __cplusplus
++extern "C"
++{
+ #define OPJ_STATIC
+ #ifndef _MSC_VER
+ #define OPJ_HAVE_STDINT_H
+ #endif
++#endif
+ 
+-#include <openjpeg.h>
++#include <openjpeg-__OPENJPEG__VERSION__/openjpeg.h>
+ 
+ /* OpenJPEG does not provide a safe mechanism to intercept
+  * allocations. In the latest version all allocations go
+@@ -971,4 +975,8 @@
+ 	fz_drop_pixmap(ctx, img);
+ }
+ 
++#ifdef __cplusplus
++}
++#endif
++
+ #endif /* HAVE_LURATECH */
diff --git a/nixpkgs/pkgs/applications/misc/k2pdfopt/tesseract.patch b/nixpkgs/pkgs/applications/misc/k2pdfopt/tesseract.patch
new file mode 100644
index 000000000000..4827daa1a905
--- /dev/null
+++ b/nixpkgs/pkgs/applications/misc/k2pdfopt/tesseract.patch
@@ -0,0 +1,13 @@
+diff --git a/api/Makefile.am b/api/Makefile.am
+index d8c1e54..46ead13 100644
+--- a/api/Makefile.am
++++ b/api/Makefile.am
+@@ -42,7 +42,7 @@ libtesseract_api_la_CPPFLAGS = $(AM_CPPFLAGS)
+ if VISIBILITY
+ libtesseract_api_la_CPPFLAGS += -DTESS_EXPORTS
+ endif
+-libtesseract_api_la_SOURCES = baseapi.cpp capi.cpp renderer.cpp pdfrenderer.cpp
++libtesseract_api_la_SOURCES = baseapi.cpp capi.cpp renderer.cpp pdfrenderer.cpp tesscapi.cpp
+ 
+ lib_LTLIBRARIES += libtesseract.la
+ libtesseract_la_LDFLAGS =