From e170ad557d5f13daeeac047dfaa79347bbe5062f Mon Sep 17 00:00:00 2001
From: Jakub Wilk <jwilk@jwilk.net>
Date: Wed, 16 Feb 2022 09:08:11 +0000
Subject: [PATCH] pdf-backend: fix compat with Poppler > 22.02.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fixes:

    pdf-backend.cc: In constructor ‘pdf::Document::Document(const string&)’:
    pdf-backend.cc:133:64: error: no matching function for call to ‘PDFDoc::PDFDoc(pdf::String*, std::nullptr_t, std::nullptr_t)’

https://cgit.freedesktop.org/poppler/poppler/commit/?id=07889cdfd8a261dc
---
 pdf-backend.cc | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/pdf-backend.cc b/pdf-backend.cc
index 3c871b1..c74053d 100644
--- a/pdf-backend.cc
+++ b/pdf-backend.cc
@@ -129,8 +129,27 @@ void pdf::Environment::set_antialias(bool value)
  * ===================
  */
 
+template <typename T>
+class unique_ptr_adapter
+{
+protected:
+  std::unique_ptr<T> uptr;
+public:
+  unique_ptr_adapter(T *ptr)
+  : uptr(ptr)
+  { }
+  operator std::unique_ptr<T> ()
+  {
+    return std::move(this->uptr);
+  }
+  operator T* ()
+  {
+    return this->uptr.release();
+  }
+};
+
 pdf::Document::Document(const std::string &file_name)
-: ::PDFDoc(new pdf::String(file_name.c_str()), nullptr, nullptr)
+: ::PDFDoc(unique_ptr_adapter<pdf::String>(new pdf::String(file_name.c_str())), nullptr, nullptr)
 {
   if (!this->isOk())
     throw LoadError();

From 81b635e014ebd0240a8719cc39b6a1b759cc6a98 Mon Sep 17 00:00:00 2001
From: Jakub Wilk <jwilk@jwilk.net>
Date: Wed, 16 Feb 2022 09:10:28 +0000
Subject: [PATCH] main: use pdf::link::Destination copy constructor.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fixes:

  main.cc: In function ‘int get_page_for_goto_link(pdf::link::GoTo*, pdf::Catalog*)’:
  main.cc:92:27: error: ‘const Destination’ {aka ‘const class LinkDest’} has no member named ‘copy’

https://cgit.freedesktop.org/poppler/poppler/commit/?id=7a429c3cf9fba67e
---
 main.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/main.cc b/main.cc
index 2b42d16..bb5fd57 100644
--- a/pdf2djvu.cc
+++ b/pdf2djvu.cc
@@ -89,7 +89,7 @@ static int get_page_for_goto_link(pdf::link::GoTo *goto_link, pdf::Catalog *cata
 #endif
   }
   else
-    dest.reset(orig_dest->copy());
+    dest.reset(new pdf::link::Destination(*orig_dest));
   if (dest.get() != nullptr)
   {
     int page;

From 956fedc7e0831126b9006efedad5519c14201c52 Mon Sep 17 00:00:00 2001
From: Jakub Wilk <jwilk@jwilk.net>
Date: Thu, 17 Feb 2022 00:26:41 +0100
Subject: [PATCH] pdf-backend: fix compat with Poppler > 22.02.

Fixes:

    pdf-backend.cc:152:3: error: no matching constructor for initialization of '::PDFDoc'
    /usr/include/poppler/PDFDoc.h:132:14: note: candidate constructor not viable: no known conversion from 'nullptr_t' to 'const std::optional<GooString>' for 2nd argument

https://cgit.freedesktop.org/poppler/poppler/commit/?id=4f2abd3efa1ee013
---
 pdf-backend.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pdf-backend.cc b/pdf-backend.cc
index c74053d..ba85da2 100644
--- a/pdf-backend.cc
+++ b/pdf-backend.cc
@@ -149,7 +149,7 @@ class unique_ptr_adapter
 };
 
 pdf::Document::Document(const std::string &file_name)
-: ::PDFDoc(unique_ptr_adapter<pdf::String>(new pdf::String(file_name.c_str())), nullptr, nullptr)
+: ::PDFDoc(unique_ptr_adapter<pdf::String>(new pdf::String(file_name.c_str())))
 {
   if (!this->isOk())
     throw LoadError();
