OLD | NEW |
---|---|
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 | 8 |
9 #include "core/include/fpdfapi/fpdf_module.h" | 9 #include "core/include/fpdfapi/fpdf_module.h" |
10 #include "core/include/fpdfapi/fpdf_parser.h" | 10 #include "core/include/fpdfapi/fpdf_parser.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, | 42 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, |
43 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, 0x00f0, 0x00f1, 0x00f2, | 43 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, 0x00f0, 0x00f1, 0x00f2, |
44 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, | 44 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, |
45 0x00fc, 0x00fd, 0x00fe, 0x00ff}; | 45 0x00fc, 0x00fd, 0x00fe, 0x00ff}; |
46 | 46 |
47 FX_DWORD A85Decode(const uint8_t* src_buf, | 47 FX_DWORD A85Decode(const uint8_t* src_buf, |
48 FX_DWORD src_size, | 48 FX_DWORD src_size, |
49 uint8_t*& dest_buf, | 49 uint8_t*& dest_buf, |
50 FX_DWORD& dest_size) { | 50 FX_DWORD& dest_size) { |
51 dest_size = 0; | 51 dest_size = 0; |
52 dest_buf = NULL; | 52 dest_buf = nullptr; |
53 if (src_size == 0) { | 53 if (src_size == 0) |
54 return 0; | 54 return 0; |
55 } | 55 |
56 // Count legal characters and zeros. | |
56 FX_DWORD zcount = 0; | 57 FX_DWORD zcount = 0; |
57 FX_DWORD pos = 0; | 58 FX_DWORD pos = 0; |
58 while (pos < src_size) { | 59 while (pos < src_size) { |
59 uint8_t ch = src_buf[pos]; | 60 uint8_t ch = src_buf[pos]; |
60 if (ch < '!' && ch != '\n' && ch != '\r' && ch != ' ' && ch != '\t') { | |
61 break; | |
62 } | |
63 if (ch == 'z') { | 61 if (ch == 'z') { |
64 zcount++; | 62 zcount++; |
65 } else if (ch > 'u') { | 63 } else if ((ch < '!' || ch > 'u') && !PDFCharIsLineEnding(ch) && |
64 ch != ' ' && ch != '\t') { | |
66 break; | 65 break; |
67 } | 66 } |
68 pos++; | 67 pos++; |
69 } | 68 } |
70 if (pos == 0) { | 69 // No content to decode. |
70 if (pos == 0) | |
71 return 0; | 71 return 0; |
72 } | 72 |
73 if (zcount > UINT_MAX / 4) { | 73 if (zcount > (UINT_MAX - (pos - zcount)) / 4) { |
74 return (FX_DWORD)-1; | |
75 } | |
76 if (zcount * 4 > UINT_MAX - (pos - zcount)) { | |
77 return (FX_DWORD)-1; | 74 return (FX_DWORD)-1; |
78 } | 75 } |
79 dest_buf = FX_Alloc(uint8_t, zcount * 4 + (pos - zcount)); | 76 dest_buf = FX_Alloc(uint8_t, zcount * 4 + (pos - zcount)); |
Lei Zhang
2016/02/06 01:22:02
I looked at this just now - isn't this just: zcoun
Wei Li
2016/02/06 02:18:59
Now let's make it right :)
| |
80 int state = 0; | 77 size_t state = 0; |
81 uint32_t res = 0; | 78 uint32_t res = 0; |
82 pos = dest_size = 0; | 79 pos = dest_size = 0; |
83 while (pos < src_size) { | 80 while (pos < src_size) { |
84 uint8_t ch = src_buf[pos++]; | 81 uint8_t ch = src_buf[pos++]; |
85 if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t') | 82 if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t') |
86 continue; | 83 continue; |
87 | 84 |
88 if (ch == 'z') { | 85 if (ch == 'z') { |
89 FXSYS_memset(dest_buf + dest_size, 0, 4); | 86 FXSYS_memset(dest_buf + dest_size, 0, 4); |
90 state = 0; | 87 state = 0; |
91 res = 0; | 88 res = 0; |
92 dest_size += 4; | 89 dest_size += 4; |
93 } else { | 90 } else if (ch >= '!' && ch <= 'u') { |
94 if (ch < '!' || ch > 'u') { | |
95 break; | |
96 } | |
97 res = res * 85 + ch - 33; | 91 res = res * 85 + ch - 33; |
98 state++; | 92 state++; |
99 if (state == 5) { | 93 if (state == 5) { |
100 for (int i = 0; i < 4; i++) { | 94 for (size_t i = 0; i < 4; i++) { |
101 dest_buf[dest_size++] = (uint8_t)(res >> (3 - i) * 8); | 95 dest_buf[dest_size++] = (uint8_t)(res >> (3 - i) * 8); |
102 } | 96 } |
103 state = 0; | 97 state = 0; |
104 res = 0; | 98 res = 0; |
105 } | 99 } |
100 } else { | |
101 // The end or illegal character. | |
102 break; | |
106 } | 103 } |
107 } | 104 } |
105 // Handle partial group. | |
108 if (state) { | 106 if (state) { |
109 int i; | 107 for (size_t i = state; i < 5; i++) |
110 for (i = state; i < 5; i++) { | |
111 res = res * 85 + 84; | 108 res = res * 85 + 84; |
112 } | 109 for (size_t i = 0; i < state - 1; i++) |
113 for (i = 0; i < state - 1; i++) { | |
114 dest_buf[dest_size++] = (uint8_t)(res >> (3 - i) * 8); | 110 dest_buf[dest_size++] = (uint8_t)(res >> (3 - i) * 8); |
115 } | |
116 } | 111 } |
117 if (pos < src_size && src_buf[pos] == '>') { | 112 if (pos < src_size && src_buf[pos] == '>') |
118 pos++; | 113 pos++; |
119 } | |
120 return pos; | 114 return pos; |
121 } | 115 } |
116 | |
122 FX_DWORD HexDecode(const uint8_t* src_buf, | 117 FX_DWORD HexDecode(const uint8_t* src_buf, |
123 FX_DWORD src_size, | 118 FX_DWORD src_size, |
124 uint8_t*& dest_buf, | 119 uint8_t*& dest_buf, |
125 FX_DWORD& dest_size) { | 120 FX_DWORD& dest_size) { |
126 FX_DWORD i; | 121 dest_size = 0; |
127 for (i = 0; i < src_size; i++) | 122 if (src_size == 0) { |
128 if (src_buf[i] == '>') { | 123 dest_buf = nullptr; |
129 break; | 124 return 0; |
130 } | 125 } |
126 | |
127 FX_DWORD i = 0; | |
128 // Find the end of data. | |
129 while (i < src_size && src_buf[i] != '>') | |
130 i++; | |
131 | |
131 dest_buf = FX_Alloc(uint8_t, i / 2 + 1); | 132 dest_buf = FX_Alloc(uint8_t, i / 2 + 1); |
132 dest_size = 0; | |
133 bool bFirst = true; | 133 bool bFirst = true; |
134 for (i = 0; i < src_size; i++) { | 134 for (i = 0; i < src_size; i++) { |
135 uint8_t ch = src_buf[i]; | 135 uint8_t ch = src_buf[i]; |
136 if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t') | 136 if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t') |
137 continue; | 137 continue; |
138 | 138 |
139 if (ch == '>') { | 139 if (ch == '>') { |
140 ++i; | 140 ++i; |
141 break; | 141 break; |
142 } | 142 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 } else { | 211 } else { |
212 break; | 212 break; |
213 } | 213 } |
214 } | 214 } |
215 FX_DWORD ret = i + 1; | 215 FX_DWORD ret = i + 1; |
216 if (ret > src_size) { | 216 if (ret > src_size) { |
217 ret = src_size; | 217 ret = src_size; |
218 } | 218 } |
219 return ret; | 219 return ret; |
220 } | 220 } |
221 | |
221 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder( | 222 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder( |
222 const uint8_t* src_buf, | 223 const uint8_t* src_buf, |
223 FX_DWORD src_size, | 224 FX_DWORD src_size, |
224 int width, | 225 int width, |
225 int height, | 226 int height, |
226 const CPDF_Dictionary* pParams) { | 227 const CPDF_Dictionary* pParams) { |
227 int K = 0; | 228 int K = 0; |
228 FX_BOOL EndOfLine = FALSE; | 229 FX_BOOL EndOfLine = FALSE; |
229 FX_BOOL ByteAlign = FALSE; | 230 FX_BOOL ByteAlign = FALSE; |
230 FX_BOOL BlackIs1 = FALSE; | 231 FX_BOOL BlackIs1 = FALSE; |
231 int Columns = 1728; | 232 int Columns = 1728; |
232 int Rows = 0; | 233 int Rows = 0; |
233 if (pParams) { | 234 if (pParams) { |
234 K = pParams->GetIntegerBy("K"); | 235 K = pParams->GetIntegerBy("K"); |
235 EndOfLine = pParams->GetIntegerBy("EndOfLine"); | 236 EndOfLine = pParams->GetIntegerBy("EndOfLine"); |
236 ByteAlign = pParams->GetIntegerBy("EncodedByteAlign"); | 237 ByteAlign = pParams->GetIntegerBy("EncodedByteAlign"); |
237 BlackIs1 = pParams->GetIntegerBy("BlackIs1"); | 238 BlackIs1 = pParams->GetIntegerBy("BlackIs1"); |
238 Columns = pParams->GetIntegerBy("Columns", 1728); | 239 Columns = pParams->GetIntegerBy("Columns", 1728); |
239 Rows = pParams->GetIntegerBy("Rows"); | 240 Rows = pParams->GetIntegerBy("Rows"); |
240 if (Rows > USHRT_MAX) { | 241 if (Rows > USHRT_MAX) { |
241 Rows = 0; | 242 Rows = 0; |
242 } | 243 } |
243 if (Columns <= 0 || Rows < 0 || Columns > USHRT_MAX || Rows > USHRT_MAX) { | 244 if (Columns <= 0 || Rows < 0 || Columns > USHRT_MAX || Rows > USHRT_MAX) { |
244 return NULL; | 245 return nullptr; |
245 } | 246 } |
246 } | 247 } |
247 return CPDF_ModuleMgr::Get()->GetFaxModule()->CreateDecoder( | 248 return CPDF_ModuleMgr::Get()->GetFaxModule()->CreateDecoder( |
248 src_buf, src_size, width, height, K, EndOfLine, ByteAlign, BlackIs1, | 249 src_buf, src_size, width, height, K, EndOfLine, ByteAlign, BlackIs1, |
249 Columns, Rows); | 250 Columns, Rows); |
250 } | 251 } |
252 | |
251 static FX_BOOL CheckFlateDecodeParams(int Colors, | 253 static FX_BOOL CheckFlateDecodeParams(int Colors, |
252 int BitsPerComponent, | 254 int BitsPerComponent, |
253 int Columns) { | 255 int Columns) { |
254 if (Columns < 0) { | 256 if (Columns < 0) { |
255 return FALSE; | 257 return FALSE; |
256 } | 258 } |
257 int check = Columns; | 259 int check = Columns; |
258 if (Colors < 0 || (check > 0 && Colors > INT_MAX / check)) { | 260 if (Colors < 0 || (check > 0 && Colors > INT_MAX / check)) { |
259 return FALSE; | 261 return FALSE; |
260 } | 262 } |
261 check *= Colors; | 263 check *= Colors; |
262 if (BitsPerComponent < 0 || | 264 if (BitsPerComponent < 0 || |
263 (check > 0 && BitsPerComponent > INT_MAX / check)) { | 265 (check > 0 && BitsPerComponent > INT_MAX / check)) { |
264 return FALSE; | 266 return FALSE; |
265 } | 267 } |
266 check *= BitsPerComponent; | 268 check *= BitsPerComponent; |
267 if (check > INT_MAX - 7) { | 269 if (check > INT_MAX - 7) { |
268 return FALSE; | 270 return FALSE; |
269 } | 271 } |
270 return TRUE; | 272 return TRUE; |
271 } | 273 } |
274 | |
272 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder( | 275 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder( |
273 const uint8_t* src_buf, | 276 const uint8_t* src_buf, |
274 FX_DWORD src_size, | 277 FX_DWORD src_size, |
275 int width, | 278 int width, |
276 int height, | 279 int height, |
277 int nComps, | 280 int nComps, |
278 int bpc, | 281 int bpc, |
279 const CPDF_Dictionary* pParams) { | 282 const CPDF_Dictionary* pParams) { |
280 int predictor = 0; | 283 int predictor = 0; |
281 int Colors = 0, BitsPerComponent = 0, Columns = 0; | 284 int Colors = 0, BitsPerComponent = 0, Columns = 0; |
282 if (pParams) { | 285 if (pParams) { |
283 predictor = pParams->GetIntegerBy("Predictor"); | 286 predictor = pParams->GetIntegerBy("Predictor"); |
284 Colors = pParams->GetIntegerBy("Colors", 1); | 287 Colors = pParams->GetIntegerBy("Colors", 1); |
285 BitsPerComponent = pParams->GetIntegerBy("BitsPerComponent", 8); | 288 BitsPerComponent = pParams->GetIntegerBy("BitsPerComponent", 8); |
286 Columns = pParams->GetIntegerBy("Columns", 1); | 289 Columns = pParams->GetIntegerBy("Columns", 1); |
287 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) { | 290 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) { |
288 return NULL; | 291 return nullptr; |
289 } | 292 } |
290 } | 293 } |
291 return CPDF_ModuleMgr::Get()->GetFlateModule()->CreateDecoder( | 294 return CPDF_ModuleMgr::Get()->GetFlateModule()->CreateDecoder( |
292 src_buf, src_size, width, height, nComps, bpc, predictor, Colors, | 295 src_buf, src_size, width, height, nComps, bpc, predictor, Colors, |
293 BitsPerComponent, Columns); | 296 BitsPerComponent, Columns); |
294 } | 297 } |
298 | |
295 FX_DWORD FPDFAPI_FlateOrLZWDecode(FX_BOOL bLZW, | 299 FX_DWORD FPDFAPI_FlateOrLZWDecode(FX_BOOL bLZW, |
296 const uint8_t* src_buf, | 300 const uint8_t* src_buf, |
297 FX_DWORD src_size, | 301 FX_DWORD src_size, |
298 CPDF_Dictionary* pParams, | 302 CPDF_Dictionary* pParams, |
299 FX_DWORD estimated_size, | 303 FX_DWORD estimated_size, |
300 uint8_t*& dest_buf, | 304 uint8_t*& dest_buf, |
301 FX_DWORD& dest_size) { | 305 FX_DWORD& dest_size) { |
302 int predictor = 0; | 306 int predictor = 0; |
303 FX_BOOL bEarlyChange = TRUE; | 307 FX_BOOL bEarlyChange = TRUE; |
304 int Colors = 0, BitsPerComponent = 0, Columns = 0; | 308 int Colors = 0, BitsPerComponent = 0, Columns = 0; |
305 if (pParams) { | 309 if (pParams) { |
306 predictor = pParams->GetIntegerBy("Predictor"); | 310 predictor = pParams->GetIntegerBy("Predictor"); |
307 bEarlyChange = pParams->GetIntegerBy("EarlyChange", 1); | 311 bEarlyChange = pParams->GetIntegerBy("EarlyChange", 1); |
308 Colors = pParams->GetIntegerBy("Colors", 1); | 312 Colors = pParams->GetIntegerBy("Colors", 1); |
309 BitsPerComponent = pParams->GetIntegerBy("BitsPerComponent", 8); | 313 BitsPerComponent = pParams->GetIntegerBy("BitsPerComponent", 8); |
310 Columns = pParams->GetIntegerBy("Columns", 1); | 314 Columns = pParams->GetIntegerBy("Columns", 1); |
311 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) { | 315 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) { |
312 return (FX_DWORD)-1; | 316 return (FX_DWORD)-1; |
313 } | 317 } |
314 } | 318 } |
315 return CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode( | 319 return CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode( |
316 bLZW, src_buf, src_size, bEarlyChange, predictor, Colors, | 320 bLZW, src_buf, src_size, bEarlyChange, predictor, Colors, |
317 BitsPerComponent, Columns, estimated_size, dest_buf, dest_size); | 321 BitsPerComponent, Columns, estimated_size, dest_buf, dest_size); |
318 } | 322 } |
323 | |
319 FX_BOOL PDF_DataDecode(const uint8_t* src_buf, | 324 FX_BOOL PDF_DataDecode(const uint8_t* src_buf, |
320 FX_DWORD src_size, | 325 FX_DWORD src_size, |
321 const CPDF_Dictionary* pDict, | 326 const CPDF_Dictionary* pDict, |
322 uint8_t*& dest_buf, | 327 uint8_t*& dest_buf, |
323 FX_DWORD& dest_size, | 328 FX_DWORD& dest_size, |
324 CFX_ByteString& ImageEncoding, | 329 CFX_ByteString& ImageEncoding, |
325 CPDF_Dictionary*& pImageParms, | 330 CPDF_Dictionary*& pImageParms, |
326 FX_DWORD last_estimated_size, | 331 FX_DWORD last_estimated_size, |
327 FX_BOOL bImageAcc) { | 332 FX_BOOL bImageAcc) { |
328 CPDF_Object* pDecoder = pDict ? pDict->GetElementValue("Filter") : nullptr; | 333 CPDF_Object* pDecoder = pDict ? pDict->GetElementValue("Filter") : nullptr; |
(...skipping 17 matching lines...) Expand all Loading... | |
346 } else { | 351 } else { |
347 DecoderList.Add(pDecoder->GetConstString()); | 352 DecoderList.Add(pDecoder->GetConstString()); |
348 ParamList.Add(pParams ? pParams->GetDict() : nullptr); | 353 ParamList.Add(pParams ? pParams->GetDict() : nullptr); |
349 } | 354 } |
350 uint8_t* last_buf = (uint8_t*)src_buf; | 355 uint8_t* last_buf = (uint8_t*)src_buf; |
351 FX_DWORD last_size = src_size; | 356 FX_DWORD last_size = src_size; |
352 for (int i = 0; i < DecoderList.GetSize(); i++) { | 357 for (int i = 0; i < DecoderList.GetSize(); i++) { |
353 int estimated_size = | 358 int estimated_size = |
354 i == DecoderList.GetSize() - 1 ? last_estimated_size : 0; | 359 i == DecoderList.GetSize() - 1 ? last_estimated_size : 0; |
355 CFX_ByteString decoder = DecoderList[i]; | 360 CFX_ByteString decoder = DecoderList[i]; |
356 // Use ToDictionary here because we can push NULL into the ParamList. | 361 // Use ToDictionary here because we can push nullptr into the ParamList. |
357 CPDF_Dictionary* pParam = ToDictionary(ParamList[i]); | 362 CPDF_Dictionary* pParam = ToDictionary(ParamList[i]); |
358 uint8_t* new_buf = nullptr; | 363 uint8_t* new_buf = nullptr; |
359 FX_DWORD new_size = (FX_DWORD)-1; | 364 FX_DWORD new_size = (FX_DWORD)-1; |
360 int offset = -1; | 365 int offset = -1; |
361 if (decoder == "FlateDecode" || decoder == "Fl") { | 366 if (decoder == "FlateDecode" || decoder == "Fl") { |
362 if (bImageAcc && i == DecoderList.GetSize() - 1) { | 367 if (bImageAcc && i == DecoderList.GetSize() - 1) { |
363 ImageEncoding = "FlateDecode"; | 368 ImageEncoding = "FlateDecode"; |
364 dest_buf = (uint8_t*)last_buf; | 369 dest_buf = (uint8_t*)last_buf; |
365 dest_size = last_size; | 370 dest_size = last_size; |
366 pImageParms = pParam; | 371 pImageParms = pParam; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 } | 415 } |
411 last_buf = new_buf; | 416 last_buf = new_buf; |
412 last_size = new_size; | 417 last_size = new_size; |
413 } | 418 } |
414 ImageEncoding = ""; | 419 ImageEncoding = ""; |
415 pImageParms = nullptr; | 420 pImageParms = nullptr; |
416 dest_buf = last_buf; | 421 dest_buf = last_buf; |
417 dest_size = last_size; | 422 dest_size = last_size; |
418 return TRUE; | 423 return TRUE; |
419 } | 424 } |
425 | |
420 CFX_WideString PDF_DecodeText(const uint8_t* src_data, | 426 CFX_WideString PDF_DecodeText(const uint8_t* src_data, |
421 FX_DWORD src_len, | 427 FX_DWORD src_len, |
422 CFX_CharMap* pCharMap) { | 428 CFX_CharMap* pCharMap) { |
423 CFX_WideString result; | 429 CFX_WideString result; |
424 if (src_len >= 2 && ((src_data[0] == 0xfe && src_data[1] == 0xff) || | 430 if (src_len >= 2 && ((src_data[0] == 0xfe && src_data[1] == 0xff) || |
425 (src_data[0] == 0xff && src_data[1] == 0xfe))) { | 431 (src_data[0] == 0xff && src_data[1] == 0xfe))) { |
426 FX_BOOL bBE = src_data[0] == 0xfe; | 432 FX_BOOL bBE = src_data[0] == 0xfe; |
427 FX_DWORD max_chars = (src_len - 2) / 2; | 433 FX_DWORD max_chars = (src_len - 2) / 2; |
428 if (!max_chars) { | 434 if (!max_chars) { |
429 return result; | 435 return result; |
(...skipping 27 matching lines...) Expand all Loading... | |
457 for (FX_DWORD i = 0; i < src_len; i++) { | 463 for (FX_DWORD i = 0; i < src_len; i++) { |
458 dest_buf[i] = PDFDocEncoding[src_data[i]]; | 464 dest_buf[i] = PDFDocEncoding[src_data[i]]; |
459 } | 465 } |
460 result.ReleaseBuffer(src_len); | 466 result.ReleaseBuffer(src_len); |
461 } else { | 467 } else { |
462 return (*pCharMap->m_GetWideString)( | 468 return (*pCharMap->m_GetWideString)( |
463 pCharMap, CFX_ByteString((const FX_CHAR*)src_data, src_len)); | 469 pCharMap, CFX_ByteString((const FX_CHAR*)src_data, src_len)); |
464 } | 470 } |
465 return result; | 471 return result; |
466 } | 472 } |
473 | |
467 CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString, | 474 CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString, |
468 int len, | 475 int len, |
469 CFX_CharMap* pCharMap) { | 476 CFX_CharMap* pCharMap) { |
470 if (len == -1) { | 477 if (len == -1) { |
471 len = FXSYS_wcslen(pString); | 478 len = FXSYS_wcslen(pString); |
472 } | 479 } |
473 CFX_ByteString result; | 480 CFX_ByteString result; |
474 if (!pCharMap) { | 481 if (!pCharMap) { |
475 FX_CHAR* dest_buf1 = result.GetBuffer(len); | 482 FX_CHAR* dest_buf1 = result.GetBuffer(len); |
476 int i; | 483 int i; |
(...skipping 25 matching lines...) Expand all Loading... | |
502 dest_buf2[0] = 0xfe; | 509 dest_buf2[0] = 0xfe; |
503 dest_buf2[1] = 0xff; | 510 dest_buf2[1] = 0xff; |
504 dest_buf2 += 2; | 511 dest_buf2 += 2; |
505 for (int i = 0; i < len; i++) { | 512 for (int i = 0; i < len; i++) { |
506 *dest_buf2++ = pString[i] >> 8; | 513 *dest_buf2++ = pString[i] >> 8; |
507 *dest_buf2++ = (uint8_t)pString[i]; | 514 *dest_buf2++ = (uint8_t)pString[i]; |
508 } | 515 } |
509 result.ReleaseBuffer(encLen); | 516 result.ReleaseBuffer(encLen); |
510 return result; | 517 return result; |
511 } | 518 } |
519 | |
512 CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, FX_BOOL bHex) { | 520 CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, FX_BOOL bHex) { |
513 CFX_ByteTextBuf result; | 521 CFX_ByteTextBuf result; |
514 int srclen = src.GetLength(); | 522 int srclen = src.GetLength(); |
515 if (bHex) { | 523 if (bHex) { |
516 result.AppendChar('<'); | 524 result.AppendChar('<'); |
517 for (int i = 0; i < srclen; i++) { | 525 for (int i = 0; i < srclen; i++) { |
518 result.AppendChar("0123456789ABCDEF"[src[i] / 16]); | 526 result.AppendChar("0123456789ABCDEF"[src[i] / 16]); |
519 result.AppendChar("0123456789ABCDEF"[src[i] % 16]); | 527 result.AppendChar("0123456789ABCDEF"[src[i] % 16]); |
520 } | 528 } |
521 result.AppendChar('>'); | 529 result.AppendChar('>'); |
522 return result.GetByteString(); | 530 return result.GetByteString(); |
523 } | 531 } |
524 result.AppendChar('('); | 532 result.AppendChar('('); |
525 for (int i = 0; i < srclen; i++) { | 533 for (int i = 0; i < srclen; i++) { |
526 uint8_t ch = src[i]; | 534 uint8_t ch = src[i]; |
527 if (ch == ')' || ch == '\\' || ch == '(') { | 535 if (ch == ')' || ch == '\\' || ch == '(') { |
528 result.AppendChar('\\'); | 536 result.AppendChar('\\'); |
529 } else if (ch == 0x0a) { | 537 } else if (ch == 0x0a) { |
530 result << "\\n"; | 538 result << "\\n"; |
531 continue; | 539 continue; |
532 } else if (ch == 0x0d) { | 540 } else if (ch == 0x0d) { |
533 result << "\\r"; | 541 result << "\\r"; |
534 continue; | 542 continue; |
535 } | 543 } |
536 result.AppendChar(ch); | 544 result.AppendChar(ch); |
537 } | 545 } |
538 result.AppendChar(')'); | 546 result.AppendChar(')'); |
539 return result.GetByteString(); | 547 return result.GetByteString(); |
540 } | 548 } |
549 | |
541 void FlateEncode(const uint8_t* src_buf, | 550 void FlateEncode(const uint8_t* src_buf, |
542 FX_DWORD src_size, | 551 FX_DWORD src_size, |
543 uint8_t*& dest_buf, | 552 uint8_t*& dest_buf, |
544 FX_DWORD& dest_size) { | 553 FX_DWORD& dest_size) { |
545 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 554 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
546 if (pEncoders) { | 555 if (pEncoders) { |
547 pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, dest_size); | 556 pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, dest_size); |
548 } | 557 } |
549 } | 558 } |
559 | |
550 void FlateEncode(const uint8_t* src_buf, | 560 void FlateEncode(const uint8_t* src_buf, |
551 FX_DWORD src_size, | 561 FX_DWORD src_size, |
552 int predictor, | 562 int predictor, |
553 int Colors, | 563 int Colors, |
554 int BitsPerComponent, | 564 int BitsPerComponent, |
555 int Columns, | 565 int Columns, |
556 uint8_t*& dest_buf, | 566 uint8_t*& dest_buf, |
557 FX_DWORD& dest_size) { | 567 FX_DWORD& dest_size) { |
558 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 568 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
559 if (pEncoders) { | 569 if (pEncoders) { |
560 pEncoders->GetFlateModule()->Encode(src_buf, src_size, predictor, Colors, | 570 pEncoders->GetFlateModule()->Encode(src_buf, src_size, predictor, Colors, |
561 BitsPerComponent, Columns, dest_buf, | 571 BitsPerComponent, Columns, dest_buf, |
562 dest_size); | 572 dest_size); |
563 } | 573 } |
564 } | 574 } |
575 | |
565 FX_DWORD FlateDecode(const uint8_t* src_buf, | 576 FX_DWORD FlateDecode(const uint8_t* src_buf, |
566 FX_DWORD src_size, | 577 FX_DWORD src_size, |
567 uint8_t*& dest_buf, | 578 uint8_t*& dest_buf, |
568 FX_DWORD& dest_size) { | 579 FX_DWORD& dest_size) { |
569 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 580 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
570 if (pEncoders) { | 581 if (pEncoders) { |
571 return pEncoders->GetFlateModule()->FlateOrLZWDecode( | 582 return pEncoders->GetFlateModule()->FlateOrLZWDecode( |
572 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); | 583 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); |
573 } | 584 } |
574 return 0; | 585 return 0; |
575 } | 586 } |
OLD | NEW |