forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPDFException.cpp
More file actions
273 lines (263 loc) · 12.2 KB
/
PDFException.cpp
File metadata and controls
273 lines (263 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
//
// PDFException.cpp
//
// $Id: //poco/Main/PDF/src/PDFException.cpp#8 $
//
// Library: PDF
// Package: PDFCore
// Module: PDFException
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/PDF/PDFException.h"
#include "Poco/Format.h"
#include <string>
#include <typeinfo>
namespace Poco {
namespace PDF {
void HPDF_Error_Handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, void* user_data)
{
switch (error_no)
{
case HPDF_ARRAY_COUNT_ERR:
throw InvalidArgumentException("Internal error. The consistency of the data was lost.");
case HPDF_ARRAY_ITEM_NOT_FOUND:
throw NotFoundException("Internal error. The consistency of the data was lost.");
case HPDF_ARRAY_ITEM_UNEXPECTED_TYPE:
throw InvalidArgumentException("Internal error. The consistency of the data was lost.");
case HPDF_BINARY_LENGTH_ERR:
throw InvalidArgumentException("The length of the data exceeds HPDF_LIMIT_MAX_STRING_LEN.");
case HPDF_CANNOT_GET_PALLET:
throw NotFoundException("Cannot get a pallet data from PNG image.");
case HPDF_DICT_COUNT_ERR:
throw InvalidArgumentException("The count of elements of a dictionary exceeds HPDF_LIMIT_MAX_DICT_ELEMENT");
case HPDF_DICT_ITEM_NOT_FOUND:
throw NotFoundException("Internal error. The consistency of the data was lost.");
case HPDF_DICT_ITEM_UNEXPECTED_TYPE:
throw InvalidArgumentException("Internal error. The consistency of the data was lost.");
case HPDF_DICT_STREAM_LENGTH_NOT_FOUND:
throw NotFoundException("Internal error. The consistency of the data was lost.");
case HPDF_DOC_ENCRYPTDICT_NOT_FOUND:
throw NotFoundException("HPDF_SetPermission() OR HPDF_SetEncryptMode() was called before a password is set.");
case HPDF_DOC_INVALID_OBJECT:
throw IllegalStateException("Internal error. The consistency of the data was lost.");
case HPDF_DUPLICATE_REGISTRATION:
throw IllegalStateException("Tried to register a font that has been registered.");
case HPDF_EXCEED_JWW_CODE_NUM_LIMIT:
throw IllegalStateException("Cannot register a character to the japanese word wrap characters list.");
case HPDF_ENCRYPT_INVALID_PASSWORD:
throw IllegalStateException("Tried to set the owner password to NULL.");
case HPDF_ERR_UNKNOWN_CLASS:
throw InvalidArgumentException("Internal error. The consistency of the data was lost.");
case HPDF_EXCEED_GSTATE_LIMIT:
throw IllegalStateException("The depth of the stack exceeded HPDF_LIMIT_MAX_GSTATE.");
case HPDF_FAILD_TO_ALLOC_MEM:
throw IllegalStateException("Memory allocation failed.");
case HPDF_FILE_IO_ERROR:
throw IOException("File processing failed. (A detailed code is set.)");
case HPDF_FILE_OPEN_ERROR:
throw IOException("Cannot open a file. (A detailed code is set.)");
case HPDF_FONT_EXISTS:
throw IllegalStateException("Tried to load a font that has been registered.");
case HPDF_FONT_INVALID_WIDTHS_TABLE:
throw IllegalStateException("The format of a font-file is invalid. Internal error. The consistency of the data was lost.");
case HPDF_INVALID_AFM_HEADER:
throw IllegalStateException("Cannot recognize a header of an afm file.");
case HPDF_INVALID_ANNOTATION:
throw IllegalStateException("The specified annotation handle is invalid.");
case HPDF_INVALID_BIT_PER_COMPONENT:
throw IllegalStateException("Bit-per-component of a image which was set as mask-image is invalid.");
case HPDF_INVALID_CHAR_MATRICS_DATA:
throw IllegalStateException("Cannot recognize char-matrics-data of an afm file.");
case HPDF_INVALID_COLOR_SPACE:
switch (detail_no)
{
case 1:
throw InvalidArgumentException("The color_space parameter of HPDF_LoadRawImage is invalid.");
case 2:
throw InvalidArgumentException("Color-space of a image which was set as mask-image is invalid.");
case 3:
throw InvalidArgumentException("The function which is invalid in the present color-space was invoked.");
default:
throw PDFException();
}
case HPDF_INVALID_COMPRESSION_MODE:
throw InvalidArgumentException("Invalid value was set when invoking HPDF_SetCommpressionMode().");
case HPDF_INVALID_DATE_TIME:
throw InvalidArgumentException("An invalid date-time value was set.");
case HPDF_INVALID_DESTINATION:
throw InvalidArgumentException("An invalid destination handle was set.");
case HPDF_INVALID_DOCUMENT:
throw InvalidArgumentException("An invalid document handle is set.");
case HPDF_INVALID_DOCUMENT_STATE:
throw IllegalStateException("The function which is invalid in the present state was invoked.");
case HPDF_INVALID_ENCODER:
throw InvalidArgumentException("An invalid encoder handle is set.");
case HPDF_INVALID_ENCODER_TYPE:
throw InvalidArgumentException("A combination between font and encoder is wrong.");
case HPDF_INVALID_ENCODING_NAME:
throw InvalidArgumentException("An Invalid encoding name is specified.");
case HPDF_INVALID_ENCRYPT_KEY_LEN:
throw InvalidArgumentException("The lengh of the key of encryption is invalid.");
case HPDF_INVALID_FONTDEF_DATA:
switch (detail_no)
{
case 1:
throw InvalidArgumentException("An invalid font handle was set.");
case 2:
throw InvalidArgumentException("Unsupported font format.");
default:
throw PDFException();
}
case HPDF_INVALID_FONTDEF_TYPE:
throw IllegalStateException("Internal error. The consistency of the data was lost.");
case HPDF_INVALID_FONT_NAME:
throw NotFoundException("A font which has the specified name is not found.");
case HPDF_INVALID_IMAGE:
throw InvalidArgumentException("Unsupported image format.");
case HPDF_INVALID_JPEG_DATA:
throw InvalidArgumentException("Unsupported image format.");
case HPDF_INVALID_N_DATA:
throw IOException("Cannot read a postscript-name from an afm file.");
case HPDF_INVALID_OBJECT:
switch (detail_no)
{
case 1:
throw IllegalStateException("An invalid object is set.");
case 2:
throw IllegalStateException("Internal error. The consistency of the data was lost.");
default:
throw PDFException();
}
case HPDF_INVALID_OBJ_ID:
throw InvalidArgumentException("Internal error. The consistency of the data was lost.");
case HPDF_INVALID_OPERATION:
switch (detail_no)
{
case 1:
throw IllegalStateException("Invoked HPDF_Image_SetColorMask() against the image-object which was set a mask-image.");
default:
throw PDFException();
}
case HPDF_INVALID_OUTLINE:
throw InvalidArgumentException("An invalid outline-handle was specified.");
case HPDF_INVALID_PAGE:
throw InvalidArgumentException("An invalid page-handle was specified.");
case HPDF_INVALID_PAGES:
throw InvalidArgumentException("An invalid pages-handle was specified. (internel error)");
case HPDF_INVALID_PARAMETER:
throw InvalidArgumentException("An invalid value is set.");
case HPDF_INVALID_PNG_IMAGE:
throw InvalidArgumentException("Invalid PNG image format.");
case HPDF_INVALID_STREAM:
throw InvalidArgumentException("Internal error. The consistency of the data was lost.");
case HPDF_MISSING_FILE_NAME_ENTRY:
throw InvalidArgumentException("Internal error. The \"_FILE_NAME\" entry for delayed loading is missing.");
case HPDF_INVALID_TTC_FILE:
throw InvalidArgumentException("Invalid .TTC file format.");
case HPDF_INVALID_TTC_INDEX:
throw InvalidArgumentException("The index parameter was exceed the number of included fonts");
case HPDF_INVALID_WX_DATA:
throw IOException("Cannot read a width-data from an afm file.");
case HPDF_ITEM_NOT_FOUND:
throw NotFoundException("Internal error. The consistency of the data was lost.");
case HPDF_LIBPNG_ERROR:
throw IOException("An error has returned from PNGLIB while loading an image.");
case HPDF_NAME_INVALID_VALUE:
throw InvalidArgumentException("Internal error. The consistency of the data was lost.");
case HPDF_NAME_OUT_OF_RANGE:
throw InvalidArgumentException("Internal error. The consistency of the data was lost.");
case HPDF_PAGES_MISSING_KIDS_ENTRY:
throw IllegalStateException("Internal error. The consistency of the data was lost.");
case HPDF_PAGE_CANNOT_FIND_OBJECT:
throw NotFoundException("Internal error. The consistency of the data was lost.");
case HPDF_PAGE_CANNOT_GET_ROOT_PAGES:
throw InvalidArgumentException("Internal error. The consistency of the data was lost.");
case HPDF_PAGE_CANNOT_RESTORE_GSTATE:
throw IllegalStateException("There are no graphics-states to be restored.");
case HPDF_PAGE_CANNOT_SET_PARENT:
throw IllegalStateException("Internal error. The consistency of the data was lost.");
case HPDF_PAGE_FONT_NOT_FOUND:
throw NotFoundException("The current font is not set.");
case HPDF_PAGE_INVALID_FONT:
throw InvalidArgumentException("An invalid font-handle was spacified.");
case HPDF_PAGE_INVALID_FONT_SIZE:
throw InvalidArgumentException("An invalid font-size was set.");
case HPDF_PAGE_INVALID_GMODE:
throw InvalidArgumentException("See Graphics mode.");
case HPDF_PAGE_INVALID_INDEX:
throw InvalidArgumentException("Internal error. The consistency of the data was lost.");
case HPDF_PAGE_INVALID_ROTATE_VALUE:
throw InvalidArgumentException("The specified value is not a multiple of 90.");
case HPDF_PAGE_INVALID_SIZE:
throw InvalidArgumentException("An invalid page-size was set.");
case HPDF_PAGE_INVALID_XOBJECT:
throw InvalidArgumentException("An invalid image-handle was set.");
case HPDF_PAGE_OUT_OF_RANGE:
throw RangeException("The specified value is out of range.");
case HPDF_REAL_OUT_OF_RANGE:
throw RangeException("The specified value is out of range.");
case HPDF_STREAM_EOF:
throw IllegalStateException("Unexpected EOF marker was detected.");
case HPDF_STREAM_READLN_CONTINUE:
throw IllegalStateException("Internal error. The consistency of the data was lost.");
case HPDF_STRING_OUT_OF_RANGE:
throw RangeException("The length of the specified text is too long.");
case HPDF_THIS_FUNC_WAS_SKIPPED:
throw IllegalStateException("The execution of a function was skipped because of other errors.");
case HPDF_TTF_CANNOT_EMBEDDING_FONT:
throw IllegalStateException("This font cannot be embedded. (restricted by license)");
case HPDF_TTF_INVALID_CMAP:
throw InvalidArgumentException("Unsupported ttf format. (cannot find unicode cmap.)");
case HPDF_TTF_INVALID_FOMAT:
throw InvalidArgumentException("Unsupported ttf format.");
case HPDF_TTF_MISSING_TABLE:
throw InvalidArgumentException("Unsupported ttf format. (cannot find a necessary table)");
case HPDF_UNSUPPORTED_FONT_TYPE:
throw InvalidArgumentException("Internal error. The consistency of the data was lost.");
case HPDF_UNSUPPORTED_FUNC:
switch (detail_no)
{
case 1:
throw IllegalStateException("The library is not configured to use PNGLIB.");
case 2:
throw IllegalStateException("Internal error. The consistency of the data was lost.");
default:
throw PDFException();
}
case HPDF_UNSUPPORTED_JPEG_FORMAT:
throw InvalidArgumentException("Unsupported JPEG format.");
case HPDF_UNSUPPORTED_TYPE1_FONT:
throw IllegalStateException("Failed to parse .PFB file.");
case HPDF_XREF_COUNT_ERR:
throw IllegalStateException("Internal error. The consistency of the data was lost.");
case HPDF_ZLIB_ERROR:
throw IllegalStateException("An error has occurred while executing a function of Zlib.");
case HPDF_INVALID_PAGE_INDEX:
throw IllegalStateException("An error returned from Zlib.");
case HPDF_INVALID_URI:
throw InvalidArgumentException("An invalid URI was set.");
case HPDF_PAGE_LAYOUT_OUT_OF_RANGE:
throw RangeException("An invalid page-layout was set.");
case HPDF_PAGE_MODE_OUT_OF_RANGE:
throw RangeException("An invalid page-mode was set.");
case HPDF_PAGE_NUM_STYLE_OUT_OF_RANGE:
throw RangeException("An invalid page-num-style was set.");
case HPDF_ANNOT_INVALID_ICON:
throw InvalidArgumentException("An invalid icon was set.");
case HPDF_ANNOT_INVALID_BORDER_STYLE:
throw InvalidArgumentException("An invalid border-style was set.");
case HPDF_PAGE_INVALID_DIRECTION:
throw InvalidArgumentException("An invalid page-direction was set.");
case HPDF_INVALID_FONT:
throw InvalidArgumentException("An invalid font-handle was specified. ");
default:
throw PDFException();
}
}
POCO_IMPLEMENT_EXCEPTION(PDFException, Poco::RuntimeException, "PDF Base Exception")
POCO_IMPLEMENT_EXCEPTION(PDFCreateException, PDFException, "PDF creation failed")
} } // namespace Poco::PDF