Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp

Issue 1171733003: Remove typdefs for pointer types in fx_system.h (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Manual fixes. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "../../../include/fpdfapi/fpdf_parser.h" 7 #include "../../../include/fpdfapi/fpdf_parser.h"
8 #include "../../../include/fpdfapi/fpdf_module.h" 8 #include "../../../include/fpdfapi/fpdf_module.h"
9 #include "../../../include/fxcodec/fx_codec.h" 9 #include "../../../include/fxcodec/fx_codec.h"
10 #include <limits.h> 10 #include <limits.h>
11 #define _STREAM_MAX_SIZE_ 20 * 1024 * 1024 11 #define _STREAM_MAX_SIZE_ 20 * 1024 * 1024
12 FX_DWORD _A85Decode(const uint8_t* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_b uf, FX_DWORD& dest_size) 12 FX_DWORD _A85Decode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& dest_bu f, FX_DWORD& dest_size)
13 { 13 {
14 dest_size = 0; 14 dest_size = 0;
15 dest_buf = NULL; 15 dest_buf = NULL;
16 if (src_size == 0) { 16 if (src_size == 0) {
17 return 0; 17 return 0;
18 } 18 }
19 FX_DWORD zcount = 0; 19 FX_DWORD zcount = 0;
20 FX_DWORD pos = 0; 20 FX_DWORD pos = 0;
21 while (pos < src_size) { 21 while (pos < src_size) {
22 uint8_t ch = src_buf[pos]; 22 uint8_t ch = src_buf[pos];
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 75 }
76 for (i = 0; i < state - 1; i ++) { 76 for (i = 0; i < state - 1; i ++) {
77 dest_buf[dest_size++] = (uint8_t)(res >> (3 - i) * 8); 77 dest_buf[dest_size++] = (uint8_t)(res >> (3 - i) * 8);
78 } 78 }
79 } 79 }
80 if (pos < src_size && src_buf[pos] == '>') { 80 if (pos < src_size && src_buf[pos] == '>') {
81 pos ++; 81 pos ++;
82 } 82 }
83 return pos; 83 return pos;
84 } 84 }
85 FX_DWORD _HexDecode(const uint8_t* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_b uf, FX_DWORD& dest_size) 85 FX_DWORD _HexDecode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& dest_bu f, FX_DWORD& dest_size)
86 { 86 {
87 FX_DWORD i; 87 FX_DWORD i;
88 for (i = 0; i < src_size; i ++) 88 for (i = 0; i < src_size; i ++)
89 if (src_buf[i] == '>') { 89 if (src_buf[i] == '>') {
90 break; 90 break;
91 } 91 }
92 dest_buf = FX_Alloc( uint8_t, i / 2 + 1); 92 dest_buf = FX_Alloc( uint8_t, i / 2 + 1);
93 dest_size = 0; 93 dest_size = 0;
94 FX_BOOL bFirstDigit = TRUE; 94 FX_BOOL bFirstDigit = TRUE;
95 for (i = 0; i < src_size; i ++) { 95 for (i = 0; i < src_size; i ++) {
(...skipping 19 matching lines...) Expand all
115 } else { 115 } else {
116 dest_buf[dest_size ++] += digit; 116 dest_buf[dest_size ++] += digit;
117 } 117 }
118 bFirstDigit = !bFirstDigit; 118 bFirstDigit = !bFirstDigit;
119 } 119 }
120 if (!bFirstDigit) { 120 if (!bFirstDigit) {
121 dest_size ++; 121 dest_size ++;
122 } 122 }
123 return i; 123 return i;
124 } 124 }
125 FX_DWORD RunLengthDecode(const uint8_t* src_buf, FX_DWORD src_size, FX_LPBYTE& d est_buf, FX_DWORD& dest_size) 125 FX_DWORD RunLengthDecode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& de st_buf, FX_DWORD& dest_size)
126 { 126 {
127 FX_DWORD i = 0; 127 FX_DWORD i = 0;
128 FX_DWORD old; 128 FX_DWORD old;
129 dest_size = 0; 129 dest_size = 0;
130 while (i < src_size) { 130 while (i < src_size) {
131 if (src_buf[i] < 128) { 131 if (src_buf[i] < 128) {
132 old = dest_size; 132 old = dest_size;
133 dest_size += src_buf[i] + 1; 133 dest_size += src_buf[i] + 1;
134 if (dest_size < old) { 134 if (dest_size < old) {
135 return (FX_DWORD) - 1; 135 return (FX_DWORD) - 1;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } else { 175 } else {
176 break; 176 break;
177 } 177 }
178 } 178 }
179 FX_DWORD ret = i + 1; 179 FX_DWORD ret = i + 1;
180 if (ret > src_size) { 180 if (ret > src_size) {
181 ret = src_size; 181 ret = src_size;
182 } 182 }
183 return ret; 183 return ret;
184 } 184 }
185 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(FX_LPCBYTE src_buf, FX_DWORD sr c_size, int width, int height, 185 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(const uint8_t* src_buf, FX_DWOR D src_size, int width, int height,
186 const CPDF_Dictionary* pParams) 186 const CPDF_Dictionary* pParams)
187 { 187 {
188 int K = 0; 188 int K = 0;
189 FX_BOOL EndOfLine = FALSE; 189 FX_BOOL EndOfLine = FALSE;
190 FX_BOOL ByteAlign = FALSE; 190 FX_BOOL ByteAlign = FALSE;
191 FX_BOOL BlackIs1 = FALSE; 191 FX_BOOL BlackIs1 = FALSE;
192 int Columns = 1728; 192 int Columns = 1728;
193 int Rows = 0; 193 int Rows = 0;
194 if (pParams) { 194 if (pParams) {
195 K = pParams->GetInteger(FX_BSTRC("K")); 195 K = pParams->GetInteger(FX_BSTRC("K"));
(...skipping 25 matching lines...) Expand all
221 if (BitsPerComponent < 0 || 221 if (BitsPerComponent < 0 ||
222 (check > 0 && BitsPerComponent > INT_MAX / check)) { 222 (check > 0 && BitsPerComponent > INT_MAX / check)) {
223 return FALSE; 223 return FALSE;
224 } 224 }
225 check *= BitsPerComponent; 225 check *= BitsPerComponent;
226 if (check > INT_MAX - 7) { 226 if (check > INT_MAX - 7) {
227 return FALSE; 227 return FALSE;
228 } 228 }
229 return TRUE; 229 return TRUE;
230 } 230 }
231 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height, 231 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(const uint8_t* src_buf, FX_DW ORD src_size, int width, int height,
232 int nComps, int bpc, const CPDF_Dictionary* pParams) 232 int nComps, int bpc, const CPDF_Dictionary* pParams)
233 { 233 {
234 int predictor = 0; 234 int predictor = 0;
235 int Colors = 0, BitsPerComponent = 0, Columns = 0; 235 int Colors = 0, BitsPerComponent = 0, Columns = 0;
236 if (pParams) { 236 if (pParams) {
237 predictor = ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("Predictor" )); 237 predictor = ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("Predictor" ));
238 Colors = pParams->GetInteger(FX_BSTRC("Colors"), 1); 238 Colors = pParams->GetInteger(FX_BSTRC("Colors"), 1);
239 BitsPerComponent = pParams->GetInteger(FX_BSTRC("BitsPerComponent"), 8); 239 BitsPerComponent = pParams->GetInteger(FX_BSTRC("BitsPerComponent"), 8);
240 Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1); 240 Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1);
241 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) { 241 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) {
242 return NULL; 242 return NULL;
243 } 243 }
244 } 244 }
245 return CPDF_ModuleMgr::Get()->GetFlateModule()->CreateDecoder(src_buf, src_s ize, width, height, 245 return CPDF_ModuleMgr::Get()->GetFlateModule()->CreateDecoder(src_buf, src_s ize, width, height,
246 nComps, bpc, predictor, Colors, BitsPerComponent, Columns); 246 nComps, bpc, predictor, Colors, BitsPerComponent, Columns);
247 } 247 }
248 FX_DWORD FPDFAPI_FlateOrLZWDecode(FX_BOOL bLZW, const uint8_t* src_buf, FX_DWORD src_size, CPDF_Dictionary* pParams, 248 FX_DWORD FPDFAPI_FlateOrLZWDecode(FX_BOOL bLZW, const uint8_t* src_buf, FX_DWORD src_size, CPDF_Dictionary* pParams,
249 FX_DWORD estimated_size, FX_LPBYTE& dest_buf, FX_DWORD& dest_size) 249 FX_DWORD estimated_size, uint8_t*& dest_buf, F X_DWORD& dest_size)
250 { 250 {
251 int predictor = 0; 251 int predictor = 0;
252 FX_BOOL bEarlyChange = TRUE; 252 FX_BOOL bEarlyChange = TRUE;
253 int Colors = 0, BitsPerComponent = 0, Columns = 0; 253 int Colors = 0, BitsPerComponent = 0, Columns = 0;
254 if (pParams) { 254 if (pParams) {
255 predictor = ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("Predictor" )); 255 predictor = ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("Predictor" ));
256 bEarlyChange = ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("EarlyCh ange"), 1); 256 bEarlyChange = ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("EarlyCh ange"), 1);
257 Colors = pParams->GetInteger(FX_BSTRC("Colors"), 1); 257 Colors = pParams->GetInteger(FX_BSTRC("Colors"), 1);
258 BitsPerComponent = pParams->GetInteger(FX_BSTRC("BitsPerComponent"), 8); 258 BitsPerComponent = pParams->GetInteger(FX_BSTRC("BitsPerComponent"), 8);
259 Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1); 259 Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1);
260 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) { 260 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) {
261 return (FX_DWORD) - 1; 261 return (FX_DWORD) - 1;
262 } 262 }
263 } 263 }
264 return CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode(bLZW, src_b uf, src_size, 264 return CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode(bLZW, src_b uf, src_size,
265 bEarlyChange, predictor, Colors, BitsPerComponent, Columns, estimate d_size, 265 bEarlyChange, predictor, Colors, BitsPerComponent, Columns, estimate d_size,
266 dest_buf, dest_size); 266 dest_buf, dest_size);
267 } 267 }
268 FX_BOOL PDF_DataDecode(FX_LPCBYTE src_buf, FX_DWORD src_size, const CPDF_Diction ary* pDict, 268 FX_BOOL PDF_DataDecode(const uint8_t* src_buf, FX_DWORD src_size, const CPDF_Dic tionary* pDict,
269 FX_LPBYTE& dest_buf, FX_DWORD& dest_size, CFX_ByteString& ImageEncoding, 269 uint8_t*& dest_buf, FX_DWORD& dest_size, CFX_ByteString& ImageEncoding,
270 CPDF_Dictionary*& pImageParms, FX_DWORD last_estimated_si ze, FX_BOOL bImageAcc) 270 CPDF_Dictionary*& pImageParms, FX_DWORD last_estimated_si ze, FX_BOOL bImageAcc)
271 271
272 { 272 {
273 CPDF_Object* pDecoder = pDict ? pDict->GetElementValue(FX_BSTRC("Filter")) : NULL; 273 CPDF_Object* pDecoder = pDict ? pDict->GetElementValue(FX_BSTRC("Filter")) : NULL;
274 if (pDecoder == NULL || (pDecoder->GetType() != PDFOBJ_ARRAY && pDecoder->Ge tType() != PDFOBJ_NAME)) { 274 if (pDecoder == NULL || (pDecoder->GetType() != PDFOBJ_ARRAY && pDecoder->Ge tType() != PDFOBJ_NAME)) {
275 return FALSE; 275 return FALSE;
276 } 276 }
277 CPDF_Object* pParams = pDict ? pDict->GetElementValue(FX_BSTRC("DecodeParms" )) : NULL; 277 CPDF_Object* pParams = pDict ? pDict->GetElementValue(FX_BSTRC("DecodeParms" )) : NULL;
278 CFX_ByteStringArray DecoderList; 278 CFX_ByteStringArray DecoderList;
279 CFX_PtrArray ParamList; 279 CFX_PtrArray ParamList;
280 if (pDecoder->GetType() == PDFOBJ_ARRAY) { 280 if (pDecoder->GetType() == PDFOBJ_ARRAY) {
281 if (pParams && pParams->GetType() != PDFOBJ_ARRAY) { 281 if (pParams && pParams->GetType() != PDFOBJ_ARRAY) {
282 pParams = NULL; 282 pParams = NULL;
283 } 283 }
284 CPDF_Array* pDecoders = (CPDF_Array*)pDecoder; 284 CPDF_Array* pDecoders = (CPDF_Array*)pDecoder;
285 for (FX_DWORD i = 0; i < pDecoders->GetCount(); i ++) { 285 for (FX_DWORD i = 0; i < pDecoders->GetCount(); i ++) {
286 CFX_ByteStringC str = pDecoders->GetConstString(i); 286 CFX_ByteStringC str = pDecoders->GetConstString(i);
287 DecoderList.Add(str); 287 DecoderList.Add(str);
288 if (pParams) { 288 if (pParams) {
289 ParamList.Add(((CPDF_Array*)pParams)->GetDict(i)); 289 ParamList.Add(((CPDF_Array*)pParams)->GetDict(i));
290 } else { 290 } else {
291 ParamList.Add(NULL); 291 ParamList.Add(NULL);
292 } 292 }
293 } 293 }
294 } else { 294 } else {
295 DecoderList.Add(pDecoder->GetConstString()); 295 DecoderList.Add(pDecoder->GetConstString());
296 ParamList.Add(pParams ? pParams->GetDict() : NULL); 296 ParamList.Add(pParams ? pParams->GetDict() : NULL);
297 } 297 }
298 FX_LPBYTE last_buf = (FX_LPBYTE)src_buf; 298 uint8_t* last_buf = (uint8_t*)src_buf;
299 FX_DWORD last_size = src_size; 299 FX_DWORD last_size = src_size;
300 for (int i = 0; i < DecoderList.GetSize(); i ++) { 300 for (int i = 0; i < DecoderList.GetSize(); i ++) {
301 int estimated_size = i == DecoderList.GetSize() - 1 ? last_estimated_siz e : 0; 301 int estimated_size = i == DecoderList.GetSize() - 1 ? last_estimated_siz e : 0;
302 CFX_ByteString decoder = DecoderList[i]; 302 CFX_ByteString decoder = DecoderList[i];
303 CPDF_Dictionary* pParam = (CPDF_Dictionary*)ParamList[i]; 303 CPDF_Dictionary* pParam = (CPDF_Dictionary*)ParamList[i];
304 FX_LPBYTE new_buf = NULL; 304 uint8_t* new_buf = NULL;
305 FX_DWORD new_size = (FX_DWORD) - 1; 305 FX_DWORD new_size = (FX_DWORD) - 1;
306 int offset = -1; 306 int offset = -1;
307 if (decoder == FX_BSTRC("FlateDecode") || decoder == FX_BSTRC("Fl")) { 307 if (decoder == FX_BSTRC("FlateDecode") || decoder == FX_BSTRC("Fl")) {
308 if (bImageAcc && i == DecoderList.GetSize() - 1) { 308 if (bImageAcc && i == DecoderList.GetSize() - 1) {
309 ImageEncoding = FX_BSTRC("FlateDecode"); 309 ImageEncoding = FX_BSTRC("FlateDecode");
310 dest_buf = (FX_LPBYTE)last_buf; 310 dest_buf = (uint8_t*)last_buf;
311 dest_size = last_size; 311 dest_size = last_size;
312 pImageParms = pParam; 312 pImageParms = pParam;
313 return TRUE; 313 return TRUE;
314 } else { 314 } else {
315 offset = FPDFAPI_FlateOrLZWDecode(FALSE, last_buf, last_size, pP aram, estimated_size, new_buf, new_size); 315 offset = FPDFAPI_FlateOrLZWDecode(FALSE, last_buf, last_size, pP aram, estimated_size, new_buf, new_size);
316 } 316 }
317 } else if (decoder == FX_BSTRC("LZWDecode") || decoder == FX_BSTRC("LZW" )) { 317 } else if (decoder == FX_BSTRC("LZWDecode") || decoder == FX_BSTRC("LZW" )) {
318 offset = FPDFAPI_FlateOrLZWDecode(TRUE, last_buf, last_size, pParam, estimated_size, new_buf, new_size); 318 offset = FPDFAPI_FlateOrLZWDecode(TRUE, last_buf, last_size, pParam, estimated_size, new_buf, new_size);
319 } else if (decoder == FX_BSTRC("ASCII85Decode") || decoder == FX_BSTRC(" A85")) { 319 } else if (decoder == FX_BSTRC("ASCII85Decode") || decoder == FX_BSTRC(" A85")) {
320 offset = _A85Decode(last_buf, last_size, new_buf, new_size); 320 offset = _A85Decode(last_buf, last_size, new_buf, new_size);
321 } else if (decoder == FX_BSTRC("ASCIIHexDecode") || decoder == FX_BSTRC( "AHx")) { 321 } else if (decoder == FX_BSTRC("ASCIIHexDecode") || decoder == FX_BSTRC( "AHx")) {
322 offset = _HexDecode(last_buf, last_size, new_buf, new_size); 322 offset = _HexDecode(last_buf, last_size, new_buf, new_size);
323 } else if (decoder == FX_BSTRC("RunLengthDecode") || decoder == FX_BSTRC ("RL")) { 323 } else if (decoder == FX_BSTRC("RunLengthDecode") || decoder == FX_BSTRC ("RL")) {
324 if (bImageAcc && i == DecoderList.GetSize() - 1) { 324 if (bImageAcc && i == DecoderList.GetSize() - 1) {
325 ImageEncoding = FX_BSTRC("RunLengthDecode"); 325 ImageEncoding = FX_BSTRC("RunLengthDecode");
326 dest_buf = (FX_LPBYTE)last_buf; 326 dest_buf = (uint8_t*)last_buf;
327 dest_size = last_size; 327 dest_size = last_size;
328 pImageParms = pParam; 328 pImageParms = pParam;
329 return TRUE; 329 return TRUE;
330 } 330 }
331 offset = RunLengthDecode(last_buf, last_size, new_buf, new_size); 331 offset = RunLengthDecode(last_buf, last_size, new_buf, new_size);
332 } else { 332 } else {
333 if (decoder == FX_BSTRC("DCT")) { 333 if (decoder == FX_BSTRC("DCT")) {
334 decoder = "DCTDecode"; 334 decoder = "DCTDecode";
335 } else if (decoder == FX_BSTRC("CCF")) { 335 } else if (decoder == FX_BSTRC("CCF")) {
336 decoder = "CCITTFaxDecode"; 336 decoder = "CCITTFaxDecode";
337 } else if (decoder == FX_BSTRC("Crypt")) { 337 } else if (decoder == FX_BSTRC("Crypt")) {
338 continue; 338 continue;
339 } 339 }
340 ImageEncoding = decoder; 340 ImageEncoding = decoder;
341 pImageParms = pParam; 341 pImageParms = pParam;
342 dest_buf = (FX_LPBYTE)last_buf; 342 dest_buf = (uint8_t*)last_buf;
343 dest_size = last_size; 343 dest_size = last_size;
344 return TRUE; 344 return TRUE;
345 } 345 }
346 if (last_buf != src_buf) { 346 if (last_buf != src_buf) {
347 FX_Free(last_buf); 347 FX_Free(last_buf);
348 } 348 }
349 if (offset == -1) { 349 if (offset == -1) {
350 return FALSE; 350 return FALSE;
351 } 351 }
352 last_buf = new_buf; 352 last_buf = new_buf;
(...skipping 26 matching lines...) Expand all
379 0x00aa, 0x00ab, 0x00ac, 0x0000, 0x00ae, 0x00af, 0x00b0, 0x00b1, 0x00b2, 0x00 b3, 379 0x00aa, 0x00ab, 0x00ac, 0x0000, 0x00ae, 0x00af, 0x00b0, 0x00b1, 0x00b2, 0x00 b3,
380 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00 bd, 380 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00 bd,
381 0x00be, 0x00bf, 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00 c7, 381 0x00be, 0x00bf, 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00 c7,
382 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, 0x00d0, 0x00 d1, 382 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, 0x00d0, 0x00 d1,
383 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00 db, 383 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00 db,
384 0x00dc, 0x00dd, 0x00de, 0x00df, 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00 e5, 384 0x00dc, 0x00dd, 0x00de, 0x00df, 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00 e5,
385 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00 ef, 385 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00 ef,
386 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00 f9, 386 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00 f9,
387 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff 387 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff
388 }; 388 };
389 CFX_WideString PDF_DecodeText(FX_LPCBYTE src_data, FX_DWORD src_len, CFX_CharMap * pCharMap) 389 CFX_WideString PDF_DecodeText(const uint8_t* src_data, FX_DWORD src_len, CFX_Cha rMap* pCharMap)
390 { 390 {
391 CFX_WideString result; 391 CFX_WideString result;
392 if (src_len >= 2 && ((src_data[0] == 0xfe && src_data[1] == 0xff) || (src_da ta[0] == 0xff && src_data[1] == 0xfe))) { 392 if (src_len >= 2 && ((src_data[0] == 0xfe && src_data[1] == 0xff) || (src_da ta[0] == 0xff && src_data[1] == 0xfe))) {
393 FX_BOOL bBE = src_data[0] == 0xfe; 393 FX_BOOL bBE = src_data[0] == 0xfe;
394 FX_DWORD max_chars = (src_len - 2) / 2; 394 FX_DWORD max_chars = (src_len - 2) / 2;
395 if (!max_chars) { 395 if (!max_chars) {
396 return result; 396 return result;
397 } 397 }
398 if (src_data[0] == 0xff) { 398 if (src_data[0] == 0xff) {
399 bBE = !src_data[2]; 399 bBE = !src_data[2];
400 } 400 }
401 FX_LPWSTR dest_buf = result.GetBuffer(max_chars); 401 FX_WCHAR* dest_buf = result.GetBuffer(max_chars);
402 FX_LPCBYTE uni_str = src_data + 2; 402 const uint8_t* uni_str = src_data + 2;
403 int dest_pos = 0; 403 int dest_pos = 0;
404 for (FX_DWORD i = 0; i < max_chars * 2; i += 2) { 404 for (FX_DWORD i = 0; i < max_chars * 2; i += 2) {
405 FX_WORD unicode = bBE ? (uni_str[i] << 8 | uni_str[i + 1]) : (uni_st r[i + 1] << 8 | uni_str[i]); 405 FX_WORD unicode = bBE ? (uni_str[i] << 8 | uni_str[i + 1]) : (uni_st r[i + 1] << 8 | uni_str[i]);
406 if (unicode == 0x1b) { 406 if (unicode == 0x1b) {
407 i += 2; 407 i += 2;
408 while (i < max_chars * 2) { 408 while (i < max_chars * 2) {
409 FX_WORD unicode = bBE ? (uni_str[i] << 8 | uni_str[i + 1]) : (uni_str[i + 1] << 8 | uni_str[i]); 409 FX_WORD unicode = bBE ? (uni_str[i] << 8 | uni_str[i + 1]) : (uni_str[i + 1] << 8 | uni_str[i]);
410 i += 2; 410 i += 2;
411 if (unicode == 0x1b) { 411 if (unicode == 0x1b) {
412 break; 412 break;
413 } 413 }
414 } 414 }
415 } else { 415 } else {
416 dest_buf[dest_pos++] = unicode; 416 dest_buf[dest_pos++] = unicode;
417 } 417 }
418 } 418 }
419 result.ReleaseBuffer(dest_pos); 419 result.ReleaseBuffer(dest_pos);
420 } else if (pCharMap == NULL) { 420 } else if (pCharMap == NULL) {
421 FX_LPWSTR dest_buf = result.GetBuffer(src_len); 421 FX_WCHAR* dest_buf = result.GetBuffer(src_len);
422 for (FX_DWORD i = 0; i < src_len; i ++) { 422 for (FX_DWORD i = 0; i < src_len; i ++) {
423 dest_buf[i] = PDFDocEncoding[src_data[i]]; 423 dest_buf[i] = PDFDocEncoding[src_data[i]];
424 } 424 }
425 result.ReleaseBuffer(src_len); 425 result.ReleaseBuffer(src_len);
426 } else { 426 } else {
427 return (*pCharMap->m_GetWideString)(pCharMap, CFX_ByteString((FX_LPCSTR) src_data, src_len)); 427 return (*pCharMap->m_GetWideString)(pCharMap, CFX_ByteString((const FX_C HAR*)src_data, src_len));
428 } 428 }
429 return result; 429 return result;
430 } 430 }
431 CFX_ByteString PDF_EncodeText(FX_LPCWSTR pString, int len, CFX_CharMap* pCharMap ) 431 CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString, int len, CFX_CharMap* pCh arMap)
432 { 432 {
433 if (len == -1) { 433 if (len == -1) {
434 len = FXSYS_wcslen(pString); 434 len = FXSYS_wcslen(pString);
435 } 435 }
436 CFX_ByteString result; 436 CFX_ByteString result;
437 if (pCharMap == NULL) { 437 if (pCharMap == NULL) {
438 FX_LPSTR dest_buf1 = result.GetBuffer(len); 438 FX_CHAR* dest_buf1 = result.GetBuffer(len);
439 int i; 439 int i;
440 for (i = 0; i < len; i ++) { 440 for (i = 0; i < len; i ++) {
441 int code; 441 int code;
442 for (code = 0; code < 256; code ++) 442 for (code = 0; code < 256; code ++)
443 if (PDFDocEncoding[code] == pString[i]) { 443 if (PDFDocEncoding[code] == pString[i]) {
444 break; 444 break;
445 } 445 }
446 if (code == 256) { 446 if (code == 256) {
447 break; 447 break;
448 } 448 }
449 dest_buf1[i] = code; 449 dest_buf1[i] = code;
450 } 450 }
451 result.ReleaseBuffer(i); 451 result.ReleaseBuffer(i);
452 if (i == len) { 452 if (i == len) {
453 return result; 453 return result;
454 } 454 }
455 } 455 }
456 456
457 if(len > INT_MAX/2-1) 457 if(len > INT_MAX/2-1)
458 { 458 {
459 result.ReleaseBuffer(0); 459 result.ReleaseBuffer(0);
460 return result; 460 return result;
461 } 461 }
462 462
463 int encLen = len * 2 + 2; 463 int encLen = len * 2 + 2;
464 464
465 FX_LPBYTE dest_buf2 = (FX_LPBYTE)result.GetBuffer(encLen); 465 uint8_t* dest_buf2 = (uint8_t*)result.GetBuffer(encLen);
466 dest_buf2[0] = 0xfe; 466 dest_buf2[0] = 0xfe;
467 dest_buf2[1] = 0xff; 467 dest_buf2[1] = 0xff;
468 dest_buf2 += 2; 468 dest_buf2 += 2;
469 for (int i = 0; i < len; i ++) { 469 for (int i = 0; i < len; i ++) {
470 *dest_buf2++ = pString[i] >> 8; 470 *dest_buf2++ = pString[i] >> 8;
471 *dest_buf2++ = (uint8_t)pString[i]; 471 *dest_buf2++ = (uint8_t)pString[i];
472 } 472 }
473 result.ReleaseBuffer(encLen); 473 result.ReleaseBuffer(encLen);
474 return result; 474 return result;
475 } 475 }
(...skipping 20 matching lines...) Expand all
496 continue; 496 continue;
497 } else if (ch == 0x0d) { 497 } else if (ch == 0x0d) {
498 result << FX_BSTRC("\\r"); 498 result << FX_BSTRC("\\r");
499 continue; 499 continue;
500 } 500 }
501 result.AppendChar(ch); 501 result.AppendChar(ch);
502 } 502 }
503 result.AppendChar(')'); 503 result.AppendChar(')');
504 return result.GetByteString(); 504 return result.GetByteString();
505 } 505 }
506 void FlateEncode(const uint8_t* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_buf, FX_DWORD& dest_size) 506 void FlateEncode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& dest_buf, FX_DWORD& dest_size)
507 { 507 {
508 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); 508 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule();
509 if (pEncoders) { 509 if (pEncoders) {
510 pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, dest_si ze); 510 pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, dest_si ze);
511 } 511 }
512 } 512 }
513 void FlateEncode(FX_LPCBYTE src_buf, FX_DWORD src_size, int predictor, int Color s, int BitsPerComponent, int Columns, 513 void FlateEncode(const uint8_t* src_buf, FX_DWORD src_size, int predictor, int C olors, int BitsPerComponent, int Columns,
514 FX_LPBYTE& dest_buf, FX_DWORD& dest_size) 514 uint8_t*& dest_buf, FX_DWORD& dest_size)
515 { 515 {
516 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); 516 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule();
517 if (pEncoders) { 517 if (pEncoders) {
518 pEncoders->GetFlateModule()->Encode(src_buf, src_size, predictor, Colors , BitsPerComponent, Columns, dest_buf, dest_size); 518 pEncoders->GetFlateModule()->Encode(src_buf, src_size, predictor, Colors , BitsPerComponent, Columns, dest_buf, dest_size);
519 } 519 }
520 } 520 }
521 FX_DWORD FlateDecode(const uint8_t* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_ buf, FX_DWORD& dest_size) 521 FX_DWORD FlateDecode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& dest_b uf, FX_DWORD& dest_size)
522 { 522 {
523 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); 523 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule();
524 if (pEncoders) { 524 if (pEncoders) {
525 return pEncoders->GetFlateModule()->FlateOrLZWDecode(FALSE, src_buf, src _size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); 525 return pEncoders->GetFlateModule()->FlateOrLZWDecode(FALSE, src_buf, src _size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size);
526 } 526 }
527 return 0; 527 return 0;
528 } 528 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/filters_int.h ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698