summary refs log tree commit diff
path: root/pkgs/applications/graphics/gscan2pdf/default.nix
blob: f8d50a7c79826431ed941b133208e0b57a739d92 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{ stdenv, fetchurl, perlPackages, wrapGAppsHook,
  # libs
  librsvg, sane-backends, sane-frontends,
  # runtime dependencies
  imagemagick, libtiff, djvulibre, poppler_utils, ghostscript, unpaper, pdftk,
  # test dependencies
  xvfb_run, liberation_ttf, file, tesseract }:

with stdenv.lib;

perlPackages.buildPerlPackage rec {
  pname = "gscan2pdf";
  version = "2.6.2";

  src = fetchurl {
    url = "mirror://sourceforge/gscan2pdf/${version}/${pname}-${version}.tar.xz";
    sha256 = "0z35lglf4anfczizynjp8sd1jpix5mkmm1nh39n1v94l7ahjxsww";
  };

  nativeBuildInputs = [ wrapGAppsHook ];

  buildInputs =
    [ librsvg sane-backends sane-frontends ] ++
    (with perlPackages; [
      Gtk3
      Gtk3SimpleList
      Cairo
      CairoGObject
      Glib
      GlibObjectIntrospection
      GooCanvas2
      LocaleGettext
      PDFAPI2
      ImageSane
      SetIntSpan
      PerlMagick
      ConfigGeneral
      ListMoreUtils
      HTMLParser
      ProcProcessTable
      LogLog4perl
      TryTiny
      DataUUID
      DateCalc
      IOString
      FilesysDf
      SubOverride
    ]);

  postPatch = let
    fontSubstitute = "${liberation_ttf}/share/fonts/truetype/LiberationSans-Regular.ttf";
  in ''
    # Required for the program to properly load its SVG assets
    substituteInPlace bin/gscan2pdf \
      --replace "/usr/share" "$out/share"

    # Substitute the non-free Helvetica font in the tests
    sed -i 's|-pointsize|-font ${fontSubstitute} -pointsize|g' t/*.t
  '';

  postInstall = ''
    # Remove impurity
    find $out -type f -name "*.pod" -delete

    # Add runtime dependencies
    wrapProgram "$out/bin/gscan2pdf" \
      --prefix PATH : "${imagemagick}/bin" \
      --prefix PATH : "${libtiff}/bin" \
      --prefix PATH : "${djvulibre}/bin" \
      --prefix PATH : "${poppler_utils}/bin" \
      --prefix PATH : "${ghostscript}/bin" \
      --prefix PATH : "${unpaper}/bin" \
      --prefix PATH : "${pdftk}/bin"
  '';

  enableParallelBuilding = true;

  installTargets = [ "install" ];

  outputs = [ "out" "man" ];

  checkInputs = [
    imagemagick
    libtiff
    djvulibre
    poppler_utils
    ghostscript
    unpaper
    pdftk

    xvfb_run
    file
    tesseract # tests are expecting tesseract 3.x precisely
  ];

  checkPhase = ''
    xvfb-run -s '-screen 0 800x600x24' \
      make test
  '';

  meta = {
    description = "A GUI to produce PDFs or DjVus from scanned documents";
    homepage = http://gscan2pdf.sourceforge.net/;
    license = licenses.gpl3;
    maintainers = with maintainers; [ pacien ];
  };
}