default.nix (2466B)
1 { lib, stdenv, fetchurl, qmake, unzip, leptonica, tesseract4, wrapQtAppsHook }: 2 3 stdenv.mkDerivation rec { 4 pname = "capture2text"; 5 version = "4.6.2"; 6 7 src = fetchurl { 8 url = "mirror://sourceforge/capture2text/SourceCode/Capture2Text_v${version}/Capture2Text_v${version}_Source_Code.zip"; 9 hash = "sha256-FeQ5E2lW+QOcg6Qi1I75W4BkQmfDiZtJ7+U2K08Ji2U="; 10 }; 11 12 postPatch = '' 13 substituteInPlace Capture2Text.pro \ 14 --replace-fail "QMAKE_CXXFLAGS" "#QMAKE_CXXFLAGS" \ 15 --replace-fail "-lpvt.cppan.demo.danbloomberg.leptonica-1.74.4" "-llept" \ 16 --replace-fail "-luser32" "-ltesseract" 17 18 # Fix app description 19 substituteInPlace CommandLine.cpp \ 20 --replace-fail "Capture2Text_CLI.exe" "capture2text" 21 22 # Locate dictionaries in $XDG_DATA_DIR/Capture2Text/Capture2Text/tessdata 23 # Initialize tesseract without specifying tessdata path 24 sed -i '1 i #include <QStandardPaths>' OcrEngine.cpp 25 substituteInPlace OcrEngine.cpp \ 26 --replace-fail "QCoreApplication::applicationDirPath()" \ 27 "QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)" \ 28 --replace-fail "exeDirpath.toLocal8Bit().constData()" "NULL" 29 30 # See https://github.com/DanBloomberg/leptonica/commit/990a76de210636dfc4c976c7d3c6d63500e363b9 31 substituteInPlace PreProcess.cpp \ 32 --replace-fail "pixAverageInRect(binarizeForNegPixs, &negRect, &pixelAvg)" \ 33 "pixAverageInRect(binarizeForNegPixs, NULL, &negRect, 0, 255, 1, &pixelAvg)" 34 ''; 35 36 buildInputs = [ leptonica tesseract4 ]; 37 38 nativeBuildInputs = [ qmake unzip wrapQtAppsHook ]; 39 40 qmakeFlags = [ 41 "CONFIG+=console" 42 "INCLUDEPATH+=${leptonica}/include/leptonica" 43 "INCLUDEPATH+=${tesseract4}/include/tesseract" 44 ]; 45 46 installPhase = 47 if stdenv.isDarwin then '' 48 mkdir -p $out/Applications $out/bin 49 mv Capture2Text_CLI.app $out/Applications 50 ln -s $out/Applications/Capture2Text_CLI.app/Contents/MacOS/Capture2Text_CLI $out/bin/capture2text 51 '' else '' 52 install -Dm755 Capture2Text_CLI -t $out/bin 53 ln -s $out/bin/Capture2Text_CLI $out/bin/capture2text 54 ''; 55 56 meta = with lib; { 57 description = "Capture2Text enables users to quickly OCR a portion of the screen using a keyboard shortcut"; 58 homepage = "http://capture2text.sourceforge.net/"; 59 license = licenses.gpl3Plus; 60 maintainers = [ maintainers.sikmir ]; 61 platforms = platforms.unix; 62 broken = true; 63 }; 64 }