2017-09-09 07:09:03 +02:00
|
|
|
{ stdenv, fetchzip, fetchurl, fetchpatch, cmake, pkgconfig
|
2017-12-07 12:10:18 +01:00
|
|
|
, zlib, libpng, openjpeg
|
2017-09-09 07:09:03 +02:00
|
|
|
, enableGSL ? true, gsl
|
|
|
|
, enableGhostScript ? true, ghostscript
|
2017-10-03 20:04:56 +02:00
|
|
|
, enableMuPDF ? true, mupdf
|
2017-09-09 07:09:03 +02:00
|
|
|
, enableJPEG2K ? true, jasper
|
|
|
|
, enableDJVU ? true, djvulibre
|
|
|
|
, enableGOCR ? false, gocr # Disabled by default due to crashes
|
2018-12-30 05:13:53 +01:00
|
|
|
, enableTesseract ? true, leptonica, tesseract4
|
2017-09-09 07:09:03 +02:00
|
|
|
}:
|
|
|
|
|
|
|
|
with stdenv.lib;
|
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
2014-12-07 21:54:53 +01:00
|
|
|
name = "k2pdfopt-${version}";
|
2018-12-30 05:13:53 +01:00
|
|
|
version = "2.51a";
|
2017-09-09 07:09:03 +02:00
|
|
|
|
2018-12-30 05:13:53 +01:00
|
|
|
src = (fetchzip {
|
|
|
|
url = "http://www.willus.com/k2pdfopt/src/k2pdfopt_v2.51_src.zip";
|
|
|
|
sha256 = "133l7xkvi67s6sfk8cfh7rmavbsf7ib5fyksk1ci6b6sch3z2sw9";
|
|
|
|
});
|
|
|
|
|
|
|
|
# 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";
|
|
|
|
});
|
|
|
|
|
|
|
|
postUnpack = ''
|
|
|
|
cp -r ${v251a_src}/* $sourceRoot
|
|
|
|
'';
|
2014-10-19 09:55:06 +02:00
|
|
|
|
2017-09-09 07:09:03 +02:00
|
|
|
patches = [ ./k2pdfopt.patch ];
|
|
|
|
|
|
|
|
nativeBuildInputs = [ cmake pkgconfig ];
|
|
|
|
|
|
|
|
buildInputs =
|
|
|
|
let
|
|
|
|
mupdf_modded = mupdf.overrideAttrs (attrs: {
|
|
|
|
# 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/
|
|
|
|
'';
|
|
|
|
});
|
2018-12-30 05:13:53 +01:00
|
|
|
|
2017-09-09 07:09:03 +02:00
|
|
|
leptonica_modded = leptonica.overrideAttrs (attrs: {
|
2018-12-30 05:13:53 +01:00
|
|
|
name = "leptonica-1.74.4";
|
|
|
|
# Modified source files apply to this particular version of leptonica
|
|
|
|
version = "1.74.4";
|
|
|
|
|
|
|
|
src = fetchurl {
|
|
|
|
url = "http://www.leptonica.org/source/leptonica-1.74.4.tar.gz";
|
|
|
|
sha256 = "0fw39amgyv8v6nc7x8a4c7i37dm04i6c5zn62d24bgqnlhk59hr9";
|
|
|
|
};
|
|
|
|
|
2017-09-09 07:09:03 +02:00
|
|
|
prePatch = ''
|
2018-12-30 05:13:53 +01:00
|
|
|
cp ${src}/leptonica_mod/{allheaders.h,dewarp2.c,leptwin.c} src/
|
2017-09-09 07:09:03 +02:00
|
|
|
'';
|
2019-05-11 17:15:24 +02:00
|
|
|
patches = [
|
|
|
|
# stripped down copy of upstream commit b88c821f8d347bce0aea86d606c710303919f3d2
|
|
|
|
./leptonica-CVE-2018-3836.patch
|
|
|
|
(fetchpatch {
|
|
|
|
# CVE-2018-7186
|
|
|
|
url = "https://github.com/DanBloomberg/leptonica/commit/"
|
|
|
|
+ "ee301cb2029db8a6289c5295daa42bba7715e99a.patch";
|
|
|
|
sha256 = "0cgb7mvz2px1rg5i80wk1wxxjvzjga617d8q6j7qygkp7jm6495d";
|
|
|
|
})
|
|
|
|
(fetchpatch {
|
|
|
|
# CVE-2018-7247
|
|
|
|
url = "https://github.com/DanBloomberg/leptonica/commit/"
|
|
|
|
+ "c1079bb8e77cdd426759e466729917ca37a3ed9f.patch";
|
|
|
|
sha256 = "1z4iac5gwqggh7aa8cvyp6nl9fwd1v7wif26caxc9y5qr3jj34qf";
|
|
|
|
})
|
|
|
|
(fetchpatch {
|
|
|
|
# CVE-2018-7440
|
|
|
|
url = "https://github.com/DanBloomberg/leptonica/commit/"
|
|
|
|
+ "49ecb6c2dfd6ed5078c62f4a8eeff03e3beced3b.patch";
|
|
|
|
sha256 = "1hjmva98iaw9xj7prg7aimykyayikcwnk4hk0380007hqb35lqmy";
|
|
|
|
})
|
|
|
|
];
|
2017-09-09 07:09:03 +02:00
|
|
|
});
|
2018-12-30 05:13:53 +01:00
|
|
|
tesseract_modded = tesseract4.override {
|
|
|
|
tesseractBase = tesseract4.tesseractBase.overrideAttrs (_: {
|
2018-12-18 19:02:13 +01:00
|
|
|
prePatch = ''
|
2018-12-30 05:13:53 +01:00
|
|
|
cp ${src}/tesseract_mod/baseapi.{h,cpp} src/api/
|
|
|
|
cp ${src}/tesseract_mod/ccutil.{h,cpp} src/ccutil/
|
|
|
|
cp ${src}/tesseract_mod/genericvector.h src/ccutil/
|
|
|
|
cp ${src}/tesseract_mod/input.cpp src/lstm/
|
|
|
|
cp ${src}/tesseract_mod/lstmrecognizer.cpp src/lstm/
|
|
|
|
cp ${src}/tesseract_mod/mainblk.cpp src/ccutil/
|
|
|
|
cp ${src}/tesseract_mod/params.cpp src/ccutil/
|
|
|
|
cp ${src}/tesseract_mod/serialis.{h,cpp} src/ccutil/
|
|
|
|
cp ${src}/tesseract_mod/tesscapi.cpp src/api/
|
|
|
|
cp ${src}/tesseract_mod/tessdatamanager.cpp src/ccstruct/
|
|
|
|
cp ${src}/tesseract_mod/tessedit.cpp src/ccmain/
|
|
|
|
cp ${src}/include_mod/{tesseract.h,leptonica.h} src/api/
|
2018-12-18 19:02:13 +01:00
|
|
|
'';
|
|
|
|
patches = [ ./tesseract.patch ];
|
|
|
|
});
|
|
|
|
};
|
2017-09-09 07:09:03 +02:00
|
|
|
in
|
|
|
|
[ zlib libpng ] ++
|
|
|
|
optional enableGSL gsl ++
|
|
|
|
optional enableGhostScript ghostscript ++
|
2017-10-03 20:04:56 +02:00
|
|
|
optional enableMuPDF mupdf_modded ++
|
|
|
|
optional enableJPEG2K jasper ++
|
2017-09-09 07:09:03 +02:00
|
|
|
optional enableDJVU djvulibre ++
|
|
|
|
optional enableGOCR gocr ++
|
|
|
|
optionals enableTesseract [ leptonica_modded tesseract_modded ];
|
|
|
|
|
|
|
|
dontUseCmakeBuildDir = true;
|
|
|
|
|
|
|
|
cmakeFlags = [ "-DCMAKE_C_FLAGS=-I${src}/include_mod" ];
|
|
|
|
|
2019-01-04 20:33:50 +01:00
|
|
|
NIX_LDFLAGS = [
|
|
|
|
"-lpthread"
|
|
|
|
];
|
|
|
|
|
2017-09-09 07:09:03 +02:00
|
|
|
installPhase = ''
|
|
|
|
install -D -m 755 k2pdfopt $out/bin/k2pdfopt
|
2014-10-19 09:55:06 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with stdenv.lib; {
|
2014-11-11 14:20:43 +01:00
|
|
|
description = "Optimizes PDF/DJVU files for mobile e-readers (e.g. the Kindle) and smartphones";
|
2014-10-19 09:55:06 +02:00
|
|
|
homepage = http://www.willus.com/k2pdfopt;
|
|
|
|
license = licenses.gpl3;
|
|
|
|
platforms = platforms.linux;
|
2017-09-09 07:09:03 +02:00
|
|
|
maintainers = with maintainers; [ bosu danielfullmer ];
|
2014-10-19 09:55:06 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|