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

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

Issue 1252613002: FX_BOOL considered harmful. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Manual edits. Created 5 years, 5 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>
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 84 }
85 FX_DWORD _HexDecode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& dest_bu f, 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 bool bFirstDigit = true;
95 for (i = 0; i < src_size; i ++) { 95 for (i = 0; i < src_size; i ++) {
96 uint8_t ch = src_buf[i]; 96 uint8_t ch = src_buf[i];
97 if (ch == ' ' || ch == '\n' || ch == '\t' || ch == '\r') { 97 if (ch == ' ' || ch == '\n' || ch == '\t' || ch == '\r') {
98 continue; 98 continue;
99 } 99 }
100 int digit; 100 int digit;
101 if (ch <= '9' && ch >= '0') { 101 if (ch <= '9' && ch >= '0') {
102 digit = ch - '0'; 102 digit = ch - '0';
103 } else if (ch <= 'f' && ch >= 'a') { 103 } else if (ch <= 'f' && ch >= 'a') {
104 digit = ch - 'a' + 10; 104 digit = ch - 'a' + 10;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(const uint8_t* src_buf, FX_DWOR D src_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 bool EndOfLine = false;
190 FX_BOOL ByteAlign = FALSE; 190 bool ByteAlign = false;
191 FX_BOOL BlackIs1 = FALSE; 191 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"));
196 EndOfLine = pParams->GetInteger(FX_BSTRC("EndOfLine")); 196 EndOfLine = pParams->GetInteger(FX_BSTRC("EndOfLine"));
197 ByteAlign = pParams->GetInteger(FX_BSTRC("EncodedByteAlign")); 197 ByteAlign = pParams->GetInteger(FX_BSTRC("EncodedByteAlign"));
198 BlackIs1 = pParams->GetInteger(FX_BSTRC("BlackIs1")); 198 BlackIs1 = pParams->GetInteger(FX_BSTRC("BlackIs1"));
199 Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1728); 199 Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1728);
200 Rows = pParams->GetInteger(FX_BSTRC("Rows")); 200 Rows = pParams->GetInteger(FX_BSTRC("Rows"));
201 if (Rows > USHRT_MAX) { 201 if (Rows > USHRT_MAX) {
202 Rows = 0; 202 Rows = 0;
203 } 203 }
204 if (Columns <= 0 || Rows < 0 || Columns > USHRT_MAX || Rows > USHRT_MAX) { 204 if (Columns <= 0 || Rows < 0 || Columns > USHRT_MAX || Rows > USHRT_MAX) {
205 return NULL; 205 return NULL;
206 } 206 }
207 } 207 }
208 return CPDF_ModuleMgr::Get()->GetFaxModule()->CreateDecoder(src_buf, src_siz e, width, height, 208 return CPDF_ModuleMgr::Get()->GetFaxModule()->CreateDecoder(src_buf, src_siz e, width, height,
209 K, EndOfLine, ByteAlign, BlackIs1, Columns, Rows); 209 K, EndOfLine, ByteAlign, BlackIs1, Columns, Rows);
210 } 210 }
211 static FX_BOOL CheckFlateDecodeParams(int Colors, int BitsPerComponent, int Colu mns) 211 static bool CheckFlateDecodeParams(int Colors, int BitsPerComponent, int Columns )
212 { 212 {
213 if (Columns < 0) { 213 if (Columns < 0) {
214 return FALSE; 214 return false;
215 } 215 }
216 int check = Columns; 216 int check = Columns;
217 if (Colors < 0 || (check > 0 && Colors > INT_MAX / check)) { 217 if (Colors < 0 || (check > 0 && Colors > INT_MAX / check)) {
218 return FALSE; 218 return false;
219 } 219 }
220 check *= Colors; 220 check *= Colors;
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(const uint8_t* src_buf, FX_DW ORD 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(bool bLZW, const uint8_t* src_buf, FX_DWORD sr c_size, CPDF_Dictionary* pParams,
249 FX_DWORD estimated_size, uint8_t*& dest_buf, F X_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 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(const uint8_t* src_buf, FX_DWORD src_size, const CPDF_Dic tionary* pDict, 268 bool PDF_DataDecode(const uint8_t* src_buf, FX_DWORD src_size, const CPDF_Dictio nary* pDict,
269 uint8_t*& 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, 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 ++) {
(...skipping 17 matching lines...) Expand all
303 CPDF_Dictionary* pParam = (CPDF_Dictionary*)ParamList[i]; 303 CPDF_Dictionary* pParam = (CPDF_Dictionary*)ParamList[i];
304 uint8_t* 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 = (uint8_t*)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 = (uint8_t*)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 = (uint8_t*)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;
353 last_size = new_size; 353 last_size = new_size;
354 } 354 }
355 ImageEncoding = ""; 355 ImageEncoding = "";
356 pImageParms = NULL; 356 pImageParms = NULL;
357 dest_buf = last_buf; 357 dest_buf = last_buf;
358 dest_size = last_size; 358 dest_size = last_size;
359 return TRUE; 359 return true;
360 } 360 }
361 extern const FX_WORD PDFDocEncoding[256] = { 361 extern const FX_WORD PDFDocEncoding[256] = {
362 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x00 09, 362 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x00 09,
363 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011, 0x0012, 0x00 13, 363 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011, 0x0012, 0x00 13,
364 0x0014, 0x0015, 0x0016, 0x0017, 0x02d8, 0x02c7, 0x02c6, 0x02d9, 0x02dd, 0x02 db, 364 0x0014, 0x0015, 0x0016, 0x0017, 0x02d8, 0x02c7, 0x02c6, 0x02d9, 0x02dd, 0x02 db,
365 0x02da, 0x02dc, 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x00 27, 365 0x02da, 0x02dc, 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x00 27,
366 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, 0x0030, 0x00 31, 366 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, 0x0030, 0x00 31,
367 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x00 3b, 367 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x00 3b,
368 0x003c, 0x003d, 0x003e, 0x003f, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x00 45, 368 0x003c, 0x003d, 0x003e, 0x003f, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x00 45,
369 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x00 4f, 369 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x00 4f,
(...skipping 13 matching lines...) Expand all
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(const uint8_t* src_data, FX_DWORD src_len, CFX_Cha rMap* 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 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_WCHAR* dest_buf = result.GetBuffer(max_chars); 401 FX_WCHAR* dest_buf = result.GetBuffer(max_chars);
402 const uint8_t* uni_str = src_data + 2; 402 const uint8_t* uni_str = src_data + 2;
403 int dest_pos = 0; 403 int dest_pos = 0;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
476 CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, FX_BOOL bHex) 476 CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, bool bHex)
477 { 477 {
478 CFX_ByteTextBuf result; 478 CFX_ByteTextBuf result;
479 int srclen = src.GetLength(); 479 int srclen = src.GetLength();
480 if (bHex) { 480 if (bHex) {
481 result.AppendChar('<'); 481 result.AppendChar('<');
482 for (int i = 0; i < srclen; i ++) { 482 for (int i = 0; i < srclen; i ++) {
483 result.AppendChar("0123456789ABCDEF"[src[i] / 16]); 483 result.AppendChar("0123456789ABCDEF"[src[i] / 16]);
484 result.AppendChar("0123456789ABCDEF"[src[i] % 16]); 484 result.AppendChar("0123456789ABCDEF"[src[i] % 16]);
485 } 485 }
486 result.AppendChar('>'); 486 result.AppendChar('>');
(...skipping 28 matching lines...) Expand all
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, uint8_t*& dest_b uf, 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