hpdf_streams.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * << Haru Free PDF Library >> -- hpdf_streams.h
  3. *
  4. * URL: http://libharu.org
  5. *
  6. * Copyright (c) 1999-2006 Takeshi Kanno <[email protected]>
  7. * Copyright (c) 2007-2009 Antony Dovgal <[email protected]>
  8. *
  9. * Permission to use, copy, modify, distribute and sell this software
  10. * and its documentation for any purpose is hereby granted without fee,
  11. * provided that the above copyright notice appear in all copies and
  12. * that both that copyright notice and this permission notice appear
  13. * in supporting documentation.
  14. * It is provided "as is" without express or implied warranty.
  15. *
  16. * 2005.12.20 Created.
  17. *
  18. */
  19. #ifndef _HPDF_STREAMS_H
  20. #define _HPDF_STREAMS_H
  21. #include "hpdf_list.h"
  22. #include "hpdf_encrypt.h"
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. #define HPDF_STREAM_SIG_BYTES 0x5354524DL
  27. typedef enum _HPDF_StreamType {
  28. HPDF_STREAM_UNKNOWN = 0,
  29. HPDF_STREAM_CALLBACK,
  30. HPDF_STREAM_FILE,
  31. HPDF_STREAM_MEMORY
  32. } HPDF_StreamType;
  33. #define HPDF_STREAM_FILTER_NONE 0x0000
  34. #define HPDF_STREAM_FILTER_ASCIIHEX 0x0100
  35. #define HPDF_STREAM_FILTER_ASCII85 0x0200
  36. #define HPDF_STREAM_FILTER_FLATE_DECODE 0x0400
  37. #define HPDF_STREAM_FILTER_DCT_DECODE 0x0800
  38. #define HPDF_STREAM_FILTER_CCITT_DECODE 0x1000
  39. typedef enum _HPDF_WhenceMode {
  40. HPDF_SEEK_SET = 0,
  41. HPDF_SEEK_CUR,
  42. HPDF_SEEK_END
  43. } HPDF_WhenceMode;
  44. typedef struct _HPDF_Stream_Rec *HPDF_Stream;
  45. typedef HPDF_STATUS
  46. (*HPDF_Stream_Write_Func) (HPDF_Stream stream,
  47. const HPDF_BYTE *ptr,
  48. HPDF_UINT siz);
  49. typedef HPDF_STATUS
  50. (*HPDF_Stream_Read_Func) (HPDF_Stream stream,
  51. HPDF_BYTE *ptr,
  52. HPDF_UINT *siz);
  53. typedef HPDF_STATUS
  54. (*HPDF_Stream_Seek_Func) (HPDF_Stream stream,
  55. HPDF_INT pos,
  56. HPDF_WhenceMode mode);
  57. typedef HPDF_INT32
  58. (*HPDF_Stream_Tell_Func) (HPDF_Stream stream);
  59. typedef void
  60. (*HPDF_Stream_Free_Func) (HPDF_Stream stream);
  61. typedef HPDF_UINT32
  62. (*HPDF_Stream_Size_Func) (HPDF_Stream stream);
  63. typedef struct _HPDF_MemStreamAttr_Rec *HPDF_MemStreamAttr;
  64. typedef struct _HPDF_MemStreamAttr_Rec {
  65. HPDF_List buf;
  66. HPDF_UINT buf_siz;
  67. HPDF_UINT w_pos;
  68. HPDF_BYTE *w_ptr;
  69. HPDF_UINT r_ptr_idx;
  70. HPDF_UINT r_pos;
  71. HPDF_BYTE *r_ptr;
  72. } HPDF_MemStreamAttr_Rec;
  73. typedef struct _HPDF_Stream_Rec {
  74. HPDF_UINT32 sig_bytes;
  75. HPDF_StreamType type;
  76. HPDF_MMgr mmgr;
  77. HPDF_Error error;
  78. HPDF_UINT size;
  79. HPDF_Stream_Write_Func write_fn;
  80. HPDF_Stream_Read_Func read_fn;
  81. HPDF_Stream_Seek_Func seek_fn;
  82. HPDF_Stream_Free_Func free_fn;
  83. HPDF_Stream_Tell_Func tell_fn;
  84. HPDF_Stream_Size_Func size_fn;
  85. void* attr;
  86. } HPDF_Stream_Rec;
  87. HPDF_Stream
  88. HPDF_MemStream_New (HPDF_MMgr mmgr,
  89. HPDF_UINT buf_siz);
  90. HPDF_BYTE*
  91. HPDF_MemStream_GetBufPtr (HPDF_Stream stream,
  92. HPDF_UINT index,
  93. HPDF_UINT *length);
  94. HPDF_UINT
  95. HPDF_MemStream_GetBufSize (HPDF_Stream stream);
  96. HPDF_UINT
  97. HPDF_MemStream_GetBufCount (HPDF_Stream stream);
  98. HPDF_STATUS
  99. HPDF_MemStream_Rewrite (HPDF_Stream stream,
  100. HPDF_BYTE *buf,
  101. HPDF_UINT size);
  102. void
  103. HPDF_MemStream_FreeData (HPDF_Stream stream);
  104. HPDF_STATUS
  105. HPDF_Stream_WriteToStream (HPDF_Stream src,
  106. HPDF_Stream dst,
  107. HPDF_UINT filter,
  108. HPDF_Encrypt e);
  109. HPDF_Stream
  110. HPDF_FileReader_New (HPDF_MMgr mmgr,
  111. const char *fname);
  112. HPDF_Stream
  113. HPDF_FileWriter_New (HPDF_MMgr mmgr,
  114. const char *fname);
  115. HPDF_Stream
  116. HPDF_CallbackReader_New (HPDF_MMgr mmgr,
  117. HPDF_Stream_Read_Func read_fn,
  118. HPDF_Stream_Seek_Func seek_fn,
  119. HPDF_Stream_Tell_Func tell_fn,
  120. HPDF_Stream_Size_Func size_fn,
  121. void* data);
  122. HPDF_Stream
  123. HPDF_CallbackWriter_New (HPDF_MMgr mmgr,
  124. HPDF_Stream_Write_Func write_fn,
  125. void* data);
  126. void
  127. HPDF_Stream_Free (HPDF_Stream stream);
  128. HPDF_STATUS
  129. HPDF_Stream_WriteChar (HPDF_Stream stream,
  130. char value);
  131. HPDF_STATUS
  132. HPDF_Stream_WriteStr (HPDF_Stream stream,
  133. const char *value);
  134. HPDF_STATUS
  135. HPDF_Stream_WriteUChar (HPDF_Stream stream,
  136. HPDF_BYTE value);
  137. HPDF_STATUS
  138. HPDF_Stream_WriteInt (HPDF_Stream stream,
  139. HPDF_INT value);
  140. HPDF_STATUS
  141. HPDF_Stream_WriteUInt (HPDF_Stream stream,
  142. HPDF_UINT value);
  143. HPDF_STATUS
  144. HPDF_Stream_WriteReal (HPDF_Stream stream,
  145. HPDF_REAL value);
  146. HPDF_STATUS
  147. HPDF_Stream_Write (HPDF_Stream stream,
  148. const HPDF_BYTE *ptr,
  149. HPDF_UINT size);
  150. HPDF_STATUS
  151. HPDF_Stream_Read (HPDF_Stream stream,
  152. HPDF_BYTE *ptr,
  153. HPDF_UINT *size);
  154. HPDF_STATUS
  155. HPDF_Stream_ReadLn (HPDF_Stream stream,
  156. char *s,
  157. HPDF_UINT *size);
  158. HPDF_INT32
  159. HPDF_Stream_Tell (HPDF_Stream stream);
  160. HPDF_STATUS
  161. HPDF_Stream_Seek (HPDF_Stream stream,
  162. HPDF_INT pos,
  163. HPDF_WhenceMode mode);
  164. HPDF_BOOL
  165. HPDF_Stream_EOF (HPDF_Stream stream);
  166. HPDF_UINT32
  167. HPDF_Stream_Size (HPDF_Stream stream);
  168. HPDF_STATUS
  169. HPDF_Stream_Flush (HPDF_Stream stream);
  170. HPDF_STATUS
  171. HPDF_Stream_WriteEscapeName (HPDF_Stream stream,
  172. const char *value);
  173. HPDF_STATUS
  174. HPDF_Stream_WriteEscapeText2 (HPDF_Stream stream,
  175. const char *text,
  176. HPDF_UINT len);
  177. HPDF_STATUS
  178. HPDF_Stream_WriteEscapeText (HPDF_Stream stream,
  179. const char *text);
  180. HPDF_STATUS
  181. HPDF_Stream_WriteBinary (HPDF_Stream stream,
  182. const HPDF_BYTE *data,
  183. HPDF_UINT len,
  184. HPDF_Encrypt e);
  185. HPDF_STATUS
  186. HPDF_Stream_Validate (HPDF_Stream stream);
  187. #ifdef __cplusplus
  188. }
  189. #endif /* __cplusplus */
  190. #endif /* _HPDF_STREAMS_H */