/*---------------------------------------------------------------------------*
| PDFlib - A library for generating PDF on the fly |
+---------------------------------------------------------------------------+
| Copyright (c) 1997-2002 PDFlib GmbH and Thomas Merz. All rights reserved. |
+---------------------------------------------------------------------------+
| This software is NOT in the public domain. It can be used under two |
| substantially different licensing terms: |
| |
| The commercial license is available for a fee, and allows you to |
| - ship a commercial product based on PDFlib |
| - implement commercial Web services with PDFlib |
| - distribute (free or commercial) software when the source code is |
| not made available |
| Details can be found in the file PDFlib-license.pdf. |
| |
| The "Aladdin Free Public License" doesn't require any license fee, |
| and allows you to |
| - develop and distribute PDFlib-based software for which the complete |
| source code is made available |
| - redistribute PDFlib non-commercially under certain conditions |
| - redistribute PDFlib on digital media for a fee if the complete |
| contents of the media are freely redistributable |
| Details can be found in the file aladdin-license.pdf. |
| |
| These conditions extend to ports to other programming languages. |
| PDFlib is distributed with no warranty of any kind. Commercial users, |
| however, will receive warranty and support statements in writing. |
*---------------------------------------------------------------------------*/
// $Id: pdflib.cpp,v 1.13.2.4 2002/01/07 18:26:29 tm Exp $
//
// Implementation of C++ wrapper for PDFlib
//
//
#include "stdafx.h"
#include "pdflib.hpp"
#define CHAR(s) (s).c_str()
#ifdef PDF_THROWS_CPP_EXCEPTIONS
PDFlib::Exception::Exception(string msg, void *opaque)
: m_msg(msg),
m_opaque(opaque)
{ }
string PDFlib::Exception::get_message() { return m_msg; }
const void *PDFlib::Exception::get_opaque() { return m_opaque; }
PDFlib::MemoryException::MemoryException(string msg, void *opaque)
: PDFlib::Exception(msg, opaque)
{ }
PDFlib::IOException::IOException(string msg, void *opaque)
: PDFlib::Exception(msg, opaque)
{ }
PDFlib::RuntimeException::RuntimeException(string msg, void *opaque)
: PDFlib::Exception(msg, opaque)
{ }
PDFlib::IndexException::IndexException(string msg, void *opaque)
: PDFlib::Exception(msg, opaque)
{ }
PDFlib::TypeException::TypeException(string msg, void *opaque)
: PDFlib::Exception(msg, opaque)
{ }
PDFlib::DivisionByZeroException::DivisionByZeroException(string msg, void *opaque)
: PDFlib::Exception(msg, opaque)
{ }
PDFlib::OverflowException::OverflowException(string msg, void *opaque)
: PDFlib::Exception(msg, opaque)
{ }
PDFlib::SyntaxException::SyntaxException(string msg, void *opaque)
: PDFlib::Exception(msg, opaque)
{ }
PDFlib::ValueException::ValueException(string msge, void *opaque)
: PDFlib::Exception(msge, opaque)
{ }
PDFlib::SystemException::SystemException(string msg, void *opaque)
: PDFlib::Exception(msg, opaque)
{ }
PDFlib::NonfatalException::NonfatalException(string msg, void *opaque)
: PDFlib::Exception(msg, opaque)
{ }
PDFlib::UnknownException::UnknownException(string msg, void *opaque)
: PDFlib::Exception(msg, opaque)
{ }
void PDFlib::throw_exception() PDF_THROWS(PDFlib::Exception)
{
switch (err_info.type)
{
case PDF_MemoryError:
throw MemoryException(err_info.msg, err_info.opaque);
case PDF_IOError:
throw IOException(err_info.msg, err_info.opaque);
case PDF_RuntimeError:
throw RuntimeException(err_info.msg, err_info.opaque);
case PDF_IndexError:
throw IndexException(err_info.msg, err_info.opaque);
case PDF_TypeError:
throw TypeException(err_info.msg, err_info.opaque);
case PDF_DivisionByZero:
throw DivisionByZeroException(err_info.msg, err_info.opaque);
case PDF_OverflowError:
throw OverflowException(err_info.msg, err_info.opaque);
case PDF_SyntaxError:
throw SyntaxException(err_info.msg, err_info.opaque);
case PDF_ValueError:
throw ValueException(err_info.msg, err_info.opaque);
case PDF_SystemError:
throw SystemException(err_info.msg, err_info.opaque);
case PDF_NonfatalError:
throw NonfatalException(err_info.msg, err_info.opaque);
default:
throw UnknownException(err_info.msg, err_info.opaque);
}
}
#define PDF_TRY if (setjmp(err_info.jbuf) == 0)
#define PDF_CATCH else throw_exception()
#else
#define PDF_TRY
#define PDF_CATCH
#endif // PDF_THROWS_CPP_EXCEPTIONS
#ifdef PDF_THROWS_CPP_EXCEPTIONS
PDFlib::PDFlib(
allocproc_t allocproc,
reallocproc_t reallocproc,
freeproc_t freeproc,
void *opaque) PDF_THROWS(PDFlib::Exception)
{
PDF_boot();
err_info.opaque = opaque;
PDF_TRY
{
p = ::PDF_new2(pdf_cpp_errorhandler,
allocproc, reallocproc, freeproc, (void *) &err_info);
}
PDF_CATCH;
PDF_set_parameter(p, "binding", "C++");
}
#else // PDF_THROWS_CPP_EXCEPTIONS
PDFlib::PDFlib(
errorproc_t errorproc,
allocproc_t allocproc,
reallocproc_t reallocproc,
freeproc_t freeproc,
void *opaque)
{
PDF_boot();
p = ::PDF_new2(errorproc, allocproc, reallocproc, freeproc, opaque);
PDF_set_parameter(p, "binding", "C++");
}
#endif // PDF_THROWS_CPP_EXCEPTIONS
PDFlib::~PDFlib() PDF_THROWS_NOTHING
{
PDF_TRY ::PDF_delete(p);
::PDF_shutdown();
}
void *
PDFlib::get_opaque() PDF_THROWS(PDFlib::Exception)
{
PDF_TRY return ::PDF_get_opaque(p);
PDF_CATCH;
return 0; // compilers love it
}
int
PDFlib::get_majorversion() PDF_THROWS_NOTHING
{
return ::PDF_get_majorversion();
}
int
PDFlib::get_minorversion() PDF_THROWS_NOTHING
{
return ::PDF_get_minorversion();
}
int
PDFlib::open(string filename) PDF_THROWS(PDFlib::Exception)
{
PDF_TRY return ::PDF_open_file(p, CHAR(filename));
PDF_CATCH;
return 0; // compilers love it
}
int
PDFlib::open(FILE *fp) PDF_THROWS(PDFlib::Exception)
{
PDF_TRY return ::PDF_open_fp(p, fp);
PDF_CATCH;
return 0; // compilers love it
}
void
PDFlib::open(writeproc_t writeproc) PDF_THROWS(PDFlib::Exception)
{
PDF_TRY ::PDF_open_mem(p, writeproc);
PDF_CATCH;
}
void
PDFlib::close() PDF_THROWS(PDFlib::Exception)
{
PDF_TRY ::PDF_close(p);
PDF_CATCH;
}
const char *
PDFlib::get_buffer(long *size) PDF_THROWS(PDFlib::Exception)
{
PDF_TRY return ::PDF_get_buffer(p, size);
PDF_CATCH;
return 0; // compilers love it
}
void
PDFlib::begin_page(float width, float height) PDF_THROWS(PDFlib::Exception)
{
PDF_TRY ::PDF_begin_page(p, width, height);
PDF_CATCH;
}
void
PDFlib::end_page() PDF_THROWS(PDFlib::Exception)
{
PDF_TRY ::PDF_end_page(p);
PDF_CATCH;
}
void
PDFlib::set_parameter(string key, string value) PDF_THROWS(PDFlib::Exception)
{
PDF_TRY ::PDF_set_parameter(p, CHAR(key), CHAR(value));
PDF_CATCH;
}
string
PDFlib::get_parameter(string key, float mod) PDF_THROWS(PDFlib::Exception)
{
PDF_TRY return ::PDF_get_parameter(p, CHAR(key), mod);
PDF_CATCH;
return ""; // com
PDFLib v4.0.2.0珍藏版
4星 · 超过85%的资源 需积分: 30 156 浏览量
2011-09-02
16:31:53
上传
评论 10
收藏 193KB RAR 举报
pushebp163
- 粉丝: 2
- 资源: 6
最新资源
- 基于Python实现的自动化办公项目.zip
- 基于python实现的基于PyQt5和爬虫的小说阅读系统.zip
- 机械设计整经机上纱自动化sw20非常好的设计图纸100%好用.zip
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
前往页