pdflib.hpp
上传用户:lqriiqpl
上传日期:2022-07-04
资源大小:258k
文件大小:11k
源码类别:

文件操作

开发平台:

Visual C++

  1. /*---------------------------------------------------------------------------*
  2.  |              PDFlib - A library for generating PDF on the fly             |
  3.  +---------------------------------------------------------------------------+
  4.  | Copyright (c) 1997-2002 PDFlib GmbH and Thomas Merz. All rights reserved. |
  5.  +---------------------------------------------------------------------------+
  6.  |    This software is NOT in the public domain.  It can be used under two   |
  7.  |    substantially different licensing terms:                               |
  8.  |                                                                           |
  9.  |    The commercial license is available for a fee, and allows you to       |
  10.  |    - ship a commercial product based on PDFlib                            |
  11.  |    - implement commercial Web services with PDFlib                        |
  12.  |    - distribute (free or commercial) software when the source code is     |
  13.  |      not made available                                                   |
  14.  |    Details can be found in the file PDFlib-license.pdf.                   |
  15.  |                                                                           |
  16.  |    The "Aladdin Free Public License" doesn't require any license fee,     |
  17.  |    and allows you to                                                      |
  18.  |    - develop and distribute PDFlib-based software for which the complete  |
  19.  |      source code is made available                                        |
  20.  |    - redistribute PDFlib non-commercially under certain conditions        |
  21.  |    - redistribute PDFlib on digital media for a fee if the complete       |
  22.  |      contents of the media are freely redistributable                     |
  23.  |    Details can be found in the file aladdin-license.pdf.                  |
  24.  |                                                                           |
  25.  |    These conditions extend to ports to other programming languages.       |
  26.  |    PDFlib is distributed with no warranty of any kind. Commercial users,  |
  27.  |    however, will receive warranty and support statements in writing.      |
  28.  *---------------------------------------------------------------------------*/
  29. // $Id: pdflib.hpp,v 1.14.2.7 2002/01/07 18:26:29 tm Exp $
  30. //
  31. // C++ wrapper for PDFlib
  32. //
  33. //
  34. #ifndef PDFLIB_HPP
  35. #define PDFLIB_HPP
  36. #include <string>
  37. using namespace std;
  38. // We use PDF as a C++ class name, therefore hide the actual C struct
  39. // name for PDFlib usage with C++.
  40. #define PDF PDF_c
  41. #include "pdflib.h"
  42. #ifdef PDF_THROWS_CPP_EXCEPTIONS
  43. #include "except.h"
  44. #endif
  45. #undef PDF
  46. // #define PDF_THROWS_CPP_EXCEPTIONS
  47. #ifdef PDF_THROWS_CPP_EXCEPTIONS
  48. #define PDF_THROWS(x) throw (x)
  49. #define PDF_THROWS_NOTHING throw ()
  50. #else
  51. #define PDFlib PDF
  52. #define PDF_THROWS(x)
  53. #define PDF_THROWS_NOTHING
  54. #endif
  55. // The C++ class wrapper for PDFlib
  56. class PDFlib {
  57. public:
  58. #ifdef PDF_THROWS_CPP_EXCEPTIONS
  59.     class Exception
  60.     {
  61.     public:
  62. Exception(string msg, void *opaque);
  63. string get_message();
  64. const void *get_opaque();
  65.     private:
  66. string m_msg;
  67. const void *m_opaque;
  68.     }; // Exception
  69.     class MemoryException : public Exception
  70.     {
  71.     public:
  72. MemoryException(string msg, void *opaque);
  73.     };
  74.     class IOException : public Exception
  75.     {
  76.     public:
  77. IOException(string msg, void *opaque);
  78.     };
  79.     class RuntimeException : public Exception
  80.     {
  81.     public:
  82. RuntimeException(string msg, void *opaque);
  83.     };
  84.     class IndexException : public Exception
  85.     {
  86.     public:
  87. IndexException(string msg, void *opaque);
  88.     };
  89.     class TypeException : public Exception
  90.     {
  91.     public:
  92. TypeException(string msg, void *opaque);
  93.     };
  94.     class DivisionByZeroException : public Exception
  95.     {
  96.     public:
  97. DivisionByZeroException(string msg, void *opaque);
  98.     };
  99.     class OverflowException : public Exception
  100.     {
  101.     public:
  102. OverflowException(string msg, void *opaque);
  103.     };
  104.     class SyntaxException : public Exception
  105.     {
  106.     public:
  107. SyntaxException(string msg, void *opaque);
  108.     };
  109.     class ValueException : public Exception
  110.     {
  111.     public:
  112. ValueException(string msg, void *opaque);
  113.     };
  114.     class SystemException : public Exception
  115.     {
  116.     public:
  117. SystemException(string msg, void *opaque);
  118.     };
  119.     class NonfatalException : public Exception
  120.     {
  121.     public:
  122. NonfatalException(string msg, void *opaque);
  123.     };
  124.     class UnknownException : public Exception
  125.     {
  126.     public:
  127. UnknownException(string msg, void *opaque);
  128.     };
  129.     PDFlib(allocproc_t allocproc = NULL,
  130. reallocproc_t reallocproc = NULL,
  131. freeproc_t freeproc = NULL,
  132. void *opaque = NULL) PDF_THROWS(Exception);
  133. #else // PDF_THROWS_CPP_EXCEPTIONS
  134.     PDFlib(errorproc_t errorproc = NULL,
  135. allocproc_t allocproc = NULL,
  136. reallocproc_t reallocproc = NULL,
  137. freeproc_t freeproc = NULL,
  138. void *opaque = NULL);
  139. #endif // PDF_THROWS_CPP_EXCEPTIONS
  140.     ~PDFlib() PDF_THROWS_NOTHING;
  141.     void * get_opaque() PDF_THROWS(Exception);
  142.     static int get_majorversion() PDF_THROWS_NOTHING;
  143.     static int get_minorversion() PDF_THROWS_NOTHING;
  144.     // Overloaded generic open and close methods
  145.     int  open(string filename) PDF_THROWS(Exception);
  146.     int  open(FILE *fp) PDF_THROWS(Exception);
  147.     void open(writeproc_t writeproc) PDF_THROWS(Exception);
  148.     void close() PDF_THROWS(Exception);
  149.     const char *get_buffer(long *size) PDF_THROWS(Exception);
  150.     void begin_page(float width, float height) PDF_THROWS(Exception);
  151.     void end_page() PDF_THROWS(Exception);
  152.     void set_parameter(string key, string value) PDF_THROWS(Exception);
  153.     string get_parameter(string key, float mod) PDF_THROWS(Exception);
  154.     float get_value(string key, float mod) PDF_THROWS(Exception);
  155.     void set_value(string key, float value) PDF_THROWS(Exception);
  156.     void show(string text) PDF_THROWS(Exception);
  157.     void show_xy(string text, float x, float y) PDF_THROWS(Exception);
  158.     void continue_text(string text) PDF_THROWS(Exception);
  159.     int show_boxed(string text, float left, float top,
  160. float width, float height, string hmode, string reserved)
  161. PDF_THROWS(Exception);
  162.     void set_text_pos(float x, float y) PDF_THROWS(Exception);
  163.     float stringwidth(string text, int font, float size)
  164. PDF_THROWS(Exception);
  165.     int  findfont(string fontname, string encoding, int embed)
  166. PDF_THROWS(Exception);
  167.     void setfont(int font, float fontsize) PDF_THROWS(Exception);
  168.     void save() PDF_THROWS(Exception);
  169.     void restore() PDF_THROWS(Exception);
  170.     void translate(float tx, float ty) PDF_THROWS(Exception);
  171.     void scale(float sx, float sy) PDF_THROWS(Exception);
  172.     void rotate(float phi) PDF_THROWS(Exception);
  173.     void skew(float alpha, float beta) PDF_THROWS(Exception);
  174.     void concat(float a, float b, float c, float d, float e, float f)
  175. PDF_THROWS(Exception);
  176.     void setdash(float b, float w) PDF_THROWS(Exception);
  177.     void setpolydash(float *darray, int length) PDF_THROWS(Exception);
  178.     void setflat(float flat) PDF_THROWS(Exception);
  179.     void setlinejoin(int join) PDF_THROWS(Exception);
  180.     void setlinecap(int cap) PDF_THROWS(Exception);
  181.     void setmiterlimit(float miter) PDF_THROWS(Exception);
  182.     void setlinewidth(float width) PDF_THROWS(Exception);
  183.     void moveto(float x, float y) PDF_THROWS(Exception);
  184.     void lineto(float x, float y) PDF_THROWS(Exception);
  185.     void curveto(float x1, float y1, float x2, float y2, float x3, float y3)
  186. PDF_THROWS(Exception);
  187.     void circle(float x, float y, float r) PDF_THROWS(Exception);
  188.     void arc(float x, float y, float r, float alpha1, float alpha2)
  189. PDF_THROWS(Exception);
  190.     void arcn(float x, float y, float r, float alpha1, float alpha2)
  191. PDF_THROWS(Exception);
  192.     void rect(float x, float y, float width, float height)
  193. PDF_THROWS(Exception);
  194.     void closepath() PDF_THROWS(Exception);
  195.     void stroke() PDF_THROWS(Exception);
  196.     void closepath_stroke() PDF_THROWS(Exception);
  197.     void fill() PDF_THROWS(Exception);
  198.     void fill_stroke() PDF_THROWS(Exception);
  199.     void closepath_fill_stroke() PDF_THROWS(Exception);
  200.     void clip() PDF_THROWS(Exception);
  201.     void endpath() PDF_THROWS(Exception);
  202.     void setgray_fill(float g) PDF_THROWS(Exception);
  203.     void setgray_stroke(float g) PDF_THROWS(Exception);
  204.     void setgray(float g) PDF_THROWS(Exception);
  205.     void setrgbcolor_fill(float red, float green, float blue)
  206. PDF_THROWS(Exception);
  207.     void setrgbcolor_stroke(float red, float green, float blue)
  208. PDF_THROWS(Exception);
  209.     void setrgbcolor(float red, float green, float blue) PDF_THROWS(Exception);
  210.     int begin_template(float width, float height) PDF_THROWS(Exception);
  211.     void end_template() PDF_THROWS(Exception);
  212.     void place_image(int image, float x, float y, float scale)
  213. PDF_THROWS(Exception);
  214.     int open_image(string type, string source, const char *data,
  215. long len, int width, int height, int components, int bpc,
  216. string params) PDF_THROWS(Exception);
  217.     int open_image_file(string type, string filename,
  218.      string stringparam, int intparam) PDF_THROWS(Exception);
  219.     void close_image(int image) PDF_THROWS(Exception);
  220.     int open_CCITT(string filename, int width, int height,
  221.      bool BitReverse, int K, bool BlackIs1) PDF_THROWS(Exception);
  222.     int add_bookmark(string text, int parent, bool open)
  223. PDF_THROWS(Exception);
  224.     void set_info(string key, string value) PDF_THROWS(Exception);
  225.     void attach_file(float llx, float lly, float urx, float ury,
  226.      string filename, string description, string author,
  227. string mimetype, string icon) PDF_THROWS(Exception);
  228.     void add_note(float llx, float lly, float urx, float ury,
  229.      string contents, string title, string icon, bool open)
  230. PDF_THROWS(Exception);
  231.     void add_pdflink(float llx, float lly, float urx, float ury,
  232.      string filename, int page, string dest) PDF_THROWS(Exception);
  233.     void add_launchlink(float llx, float lly, float urx, float ury,
  234.      string filename) PDF_THROWS(Exception);
  235.     void add_locallink(float llx, float lly, float urx, float ury,
  236.      int page, string dest) PDF_THROWS(Exception);
  237.     void add_weblink(float llx, float lly, float urx, float ury, string url)
  238. PDF_THROWS(Exception);
  239.     void set_border_style(string style, float width) PDF_THROWS(Exception);
  240.     void set_border_color(float red, float green, float blue)
  241. PDF_THROWS(Exception);
  242.     void set_border_dash(float d1, float d2) PDF_THROWS(Exception);
  243.     int open_pdi(string filename, string stringparam, int intparam)
  244. PDF_THROWS(Exception);
  245.     void close_pdi(int doc) PDF_THROWS(Exception);
  246.     int open_pdi_page(int doc, int page, string label) PDF_THROWS(Exception);
  247.     void place_pdi_page(int page, float x, float y, float sx, float sy)
  248. PDF_THROWS(Exception);
  249.     void close_pdi_page(int page) PDF_THROWS(Exception);
  250.     string get_pdi_parameter(string key, int doc, int page, int index,
  251. int *len) PDF_THROWS(Exception);
  252.     float get_pdi_value(string key, int doc, int page, int index)
  253. PDF_THROWS(Exception);
  254.     int begin_pattern(float width, float height, float xstep, float ystep,
  255. int painttype) PDF_THROWS(Exception);
  256.     void end_pattern() PDF_THROWS(Exception);
  257.     int makespotcolor(string spotname, int len) PDF_THROWS(Exception);
  258.     void setcolor(string type, string colorspace,
  259. float c1, float c2, float c3, float c4) PDF_THROWS(Exception);
  260.     void add_thumbnail(int image) PDF_THROWS(Exception);
  261.     void initgraphics() PDF_THROWS(Exception);
  262.     void setmatrix(float a, float b, float c, float d, float e, float f)
  263. PDF_THROWS(Exception);
  264. private:
  265.     PDF_c *p;
  266. #ifdef PDF_THROWS_CPP_EXCEPTIONS
  267.     void throw_exception() PDF_THROWS(Exception);
  268.     pdf_err_info err_info;
  269. #endif
  270. };
  271. #endif // PDFLIB_HPP