[poppler] cpp/poppler-global.cpp cpp/poppler-global.h cpp/poppler-private.cpp cpp/poppler-private.h

Albert Astals Cid aacid at kemper.freedesktop.org
Sun Dec 14 05:59:15 PST 2014


 cpp/poppler-global.cpp  |   29 +++++++++++++++++++++++++++++
 cpp/poppler-global.h    |    5 +++++
 cpp/poppler-private.cpp |   15 ++++++++++++---
 cpp/poppler-private.h   |    3 +++
 4 files changed, 49 insertions(+), 3 deletions(-)

New commits:
commit c9c90d50e3708f6fac313aa8b458aef6dba5dcfb
Author: Hans-Peter Deifel <hpdeifel at gmx.de>
Date:   Fri Dec 12 13:09:51 2014 +0100

    cpp: New API to set debug output function
    
    Adds the global function set_debug_error_function, that allows users
    to install their own function to print internal poppler errors.

diff --git a/cpp/poppler-global.cpp b/cpp/poppler-global.cpp
index 176c0c8..b0edeb8 100644
--- a/cpp/poppler-global.cpp
+++ b/cpp/poppler-global.cpp
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2009-2010, Pino Toscano <pino at kde.org>
  * Copyright (C) 2010, Hib Eris <hib at hiberis.nl>
+ * Copyright (C) 2014, Hans-Peter Deifel <hpdeifel at gmx.de>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -334,3 +335,31 @@ std::ostream& poppler::operator<<(std::ostream& stream, const byte_array &array)
     stream << "]";
     return stream;
 }
+
+/**
+ \typedef poppler::debug_func
+
+ Debug/error function.
+
+ This function type is used for debugging & error output;
+ the first parameter is the actual message, the second is the unaltered
+ closure argument which was passed to the set_debug_error_function() call.
+
+ \since 0.30.0
+ */
+
+/**
+ Set a new debug/error output function.
+
+ If not set, by default error and debug messages will be sent to stderr.
+
+ \param debug_function the new debug function
+ \param closure user data which will be passed as-is to the debug function
+
+ \since 0.30.0
+ */
+void poppler::set_debug_error_function(debug_func debug_function, void *closure)
+{
+    poppler::detail::user_debug_function = debug_function;
+    poppler::detail::debug_closure = closure;
+}
diff --git a/cpp/poppler-global.h b/cpp/poppler-global.h
index 5650182..eb7ec24 100644
--- a/cpp/poppler-global.h
+++ b/cpp/poppler-global.h
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2009-2010, Pino Toscano <pino at kde.org>
  * Copyright (C) 2010, Patrick Spendrin <ps_ml at gmx.de>
+ * Copyright (C) 2014, Hans-Peter Deifel <hpdeifel at gmx.de>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -106,6 +107,10 @@ POPPLER_CPP_EXPORT time_type convert_date(const std::string &date);
 
 POPPLER_CPP_EXPORT std::ostream& operator<<(std::ostream& stream, const byte_array &array);
 
+typedef void(*debug_func)(const std::string &, void *);
+
+POPPLER_CPP_EXPORT void set_debug_error_function(debug_func debug_function, void *closure);
+
 }
 
 #endif
diff --git a/cpp/poppler-private.cpp b/cpp/poppler-private.cpp
index 3bee619..3c3fe95 100644
--- a/cpp/poppler-private.cpp
+++ b/cpp/poppler-private.cpp
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2009-2010, Pino Toscano <pino at kde.org>
  * Copyright (C) 2013 Adrian Johnson <ajohnson at redneon.com>
+ * Copyright (C) 2014, Hans-Peter Deifel <hpdeifel at gmx.de>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -29,16 +30,24 @@
 
 using namespace poppler;
 
+static void stderr_debug_function(const std::string &msg, void * /*data*/)
+{
+    std::cerr << "poppler/" << msg;
+}
+
+debug_func detail::user_debug_function = stderr_debug_function;
+void *detail::debug_closure = 0;
+
 void detail::error_function(void * /*data*/, ErrorCategory /*category*/, Goffset pos, char *msg)
 {
     std::ostringstream oss;
     if (pos >= 0) {
-        oss << "poppler/error (" << pos << "): ";
+        oss << "error (" << pos << "): ";
     } else {
-        oss << "poppler/error: ";
+        oss << "error: ";
     }
     oss << msg;
-    std::cerr << oss.str();
+    detail::user_debug_function(oss.str(), detail::debug_closure);
 }
 
 rectf detail::pdfrectangle_to_rectf(const PDFRectangle &pdfrect)
diff --git a/cpp/poppler-private.h b/cpp/poppler-private.h
index 3e8873f..8d315c8 100644
--- a/cpp/poppler-private.h
+++ b/cpp/poppler-private.h
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2009, Pino Toscano <pino at kde.org>
  * Copyright (C) 2013 Adrian Johnson <ajohnson at redneon.com>
+ * Copyright (C) 2014, Hans-Peter Deifel <hpdeifel at gmx.de>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -39,6 +40,8 @@ namespace poppler
 namespace detail
 {
 
+extern debug_func user_debug_function;
+extern void *debug_closure;
 void error_function(void *data, ErrorCategory category, Goffset pos, char *msg);
 
 rectf pdfrectangle_to_rectf(const PDFRectangle &pdfrect);


More information about the poppler mailing list