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