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