Commit c9c90d50 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel Committed by Albert Astals Cid
Browse files

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.
parent fa8f276a
/*
* Copyright (C) 2009-2010, Pino Toscano <pino@kde.org>
* Copyright (C) 2010, Hib Eris <hib@hiberis.nl>
* Copyright (C) 2014, Hans-Peter Deifel <hpdeifel@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;
}
/*
* Copyright (C) 2009-2010, Pino Toscano <pino@kde.org>
* Copyright (C) 2010, Patrick Spendrin <ps_ml@gmx.de>
* Copyright (C) 2014, Hans-Peter Deifel <hpdeifel@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
/*
* Copyright (C) 2009-2010, Pino Toscano <pino@kde.org>
* Copyright (C) 2013 Adrian Johnson <ajohnson@redneon.com>
* Copyright (C) 2014, Hans-Peter Deifel <hpdeifel@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)
......
/*
* Copyright (C) 2009, Pino Toscano <pino@kde.org>
* Copyright (C) 2013 Adrian Johnson <ajohnson@redneon.com>
* Copyright (C) 2014, Hans-Peter Deifel <hpdeifel@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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment