1# This file contains a formula for installing Poppler on Mac OS X using the
2# Homebrew package manager:
3#
4#     http://brew.sh/
5#
6# To install Poppler using this formula:
7#
8#     brew install path/to/this/poppler.rb
9#
10# Changes compared to Homebrew's standard Poppler formula:
11#
12#   - TeXworks-specific patches are applied to
13#        - help Qt apps find the poppler-data directory.
14#        - use native Mac OS X font handling (instead of fontconfig)
15class Poppler < Formula
16  desc "PDF rendering library (based on the xpdf-3.0 code base)"
17  homepage "https://poppler.freedesktop.org/"
18  url "https://poppler.freedesktop.org/poppler-0.54.0.tar.xz"
19  sha256 "10cca9a67cc2e6f4f9024192b1067c444218bf94430891f43dc819d78536ca31"
20
21# BEGIN TEXWORKS MODIFICATION
22#  bottle do
23#    rebuild 1
24#    sha256 "5b6de69e6ab1996332934e21b3a5220990e2a5943775d002ee8e5c2447b93758" => :sierra
25#    sha256 "44fcbb473c78c5ce034b65885fcb2e05d4ef0b2d537a043b7d2b6d44d075907b" => :el_capitan
26#    sha256 "47787f7ffa8f69dea50ebb1391186d8146386ad46f2f6b69e3786b7271caeb9d" => :yosemite
27#  end
28  version '0.54.0-texworks'
29
30  TEXWORKS_SOURCE_DIR = Pathname.new(__FILE__).realpath.dirname.join('../../..')
31  TEXWORKS_PATCH_DIR = TEXWORKS_SOURCE_DIR + 'lib-patches/'
32  patch do
33    url "file://" + TEXWORKS_PATCH_DIR + 'poppler-0001-Fix-bogus-memory-allocation-in-SplashFTFont-makeGlyp.patch'
34    sha256 "3b40b066995756a0c80badfe47e701bb0438305f3b8eb15b67875c7de38c7290"
35  end
36  patch do
37    url "file://" + TEXWORKS_PATCH_DIR + 'poppler-0002-Native-Mac-font-handling.patch'
38    sha256 "41cedfe209c203833574ace4c60c0440840cb03f7ba687a27a3a350b0d868cc4"
39  end
40  patch do
41    url "file://" + TEXWORKS_PATCH_DIR + 'poppler-0003-Add-support-for-persistent-GlobalParams.patch'
42    sha256 "6c17fe4d91c7c5d77e265af48c511db31fce73370cd2af4cbacc218435c9c86a"
43  end
44
45  depends_on "autoconf" => :build
46  depends_on "automake" => :build
47  depends_on "libtool" => :build
48# END TEXWORKS MODIFICATION
49
50  option "with-qt", "Build Qt5 backend"
51  option "with-little-cms2", "Use color management system"
52
53  deprecated_option "with-qt4" => "with-qt"
54  deprecated_option "with-qt5" => "with-qt"
55  deprecated_option "with-lcms2" => "with-little-cms2"
56
57  depends_on "pkg-config" => :build
58  depends_on "cairo"
59  depends_on "fontconfig"
60  depends_on "freetype"
61  depends_on "gettext"
62  depends_on "glib"
63  depends_on "gobject-introspection"
64  depends_on "jpeg"
65  depends_on "libpng"
66  depends_on "libtiff"
67  depends_on "openjpeg"
68  depends_on "qt" => :optional
69  depends_on "little-cms2" => :optional
70
71  conflicts_with "pdftohtml", "pdf2image", "xpdf",
72    :because => "poppler, pdftohtml, pdf2image, and xpdf install conflicting executables"
73
74  resource "font-data" do
75    url "https://poppler.freedesktop.org/poppler-data-0.4.7.tar.gz"
76    sha256 "e752b0d88a7aba54574152143e7bf76436a7ef51977c55d6bd9a48dccde3a7de"
77  end
78
79  needs :cxx11 if build.with?("qt") || MacOS.version < :mavericks
80
81  def install
82    ENV.cxx11 if build.with?("qt") || MacOS.version < :mavericks
83    ENV["LIBOPENJPEG_CFLAGS"] = "-I#{Formula["openjpeg"].opt_include}/openjpeg-2.1"
84
85    args = %W[
86      --disable-dependency-tracking
87      --prefix=#{prefix}
88      --enable-xpdf-headers
89      --enable-poppler-glib
90      --disable-gtk-test
91      --enable-introspection=yes
92      --disable-poppler-qt4
93    ]
94
95    if build.with? "qt"
96      args << "--enable-poppler-qt5"
97    else
98      args << "--disable-poppler-qt5"
99    end
100
101    args << "--enable-cms=lcms2" if build.with? "little-cms2"
102
103# BEGIN TEXWORKS MODIFICATION
104    # We changed the config file (to add native font handling), so we need to
105    # update the configure script
106    system "autoreconf", "-ivf"
107# END TEXWORKS MODIFICATION
108
109    system "./configure", *args
110    system "make", "install"
111    resource("font-data").stage do
112      system "make", "install", "prefix=#{prefix}"
113    end
114  end
115
116  test do
117    system "#{bin}/pdfinfo", test_fixtures("test.pdf")
118  end
119end
120