| 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 "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" | 7 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" |
| 8 | 8 |
| 9 #include <limits.h> | 9 #include <limits.h> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, FX_BOOL bHex) { | 523 CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, FX_BOOL bHex) { |
| 524 CFX_ByteTextBuf result; | 524 CFX_ByteTextBuf result; |
| 525 int srclen = src.GetLength(); | 525 int srclen = src.GetLength(); |
| 526 if (bHex) { | 526 if (bHex) { |
| 527 result.AppendChar('<'); | 527 result.AppendChar('<'); |
| 528 for (int i = 0; i < srclen; i++) { | 528 for (int i = 0; i < srclen; i++) { |
| 529 result.AppendChar("0123456789ABCDEF"[src[i] / 16]); | 529 result.AppendChar("0123456789ABCDEF"[src[i] / 16]); |
| 530 result.AppendChar("0123456789ABCDEF"[src[i] % 16]); | 530 result.AppendChar("0123456789ABCDEF"[src[i] % 16]); |
| 531 } | 531 } |
| 532 result.AppendChar('>'); | 532 result.AppendChar('>'); |
| 533 return result.GetByteString(); | 533 return result.AsStringC(); |
| 534 } | 534 } |
| 535 result.AppendChar('('); | 535 result.AppendChar('('); |
| 536 for (int i = 0; i < srclen; i++) { | 536 for (int i = 0; i < srclen; i++) { |
| 537 uint8_t ch = src[i]; | 537 uint8_t ch = src[i]; |
| 538 if (ch == ')' || ch == '\\' || ch == '(') { | 538 if (ch == ')' || ch == '\\' || ch == '(') { |
| 539 result.AppendChar('\\'); | 539 result.AppendChar('\\'); |
| 540 } else if (ch == 0x0a) { | 540 } else if (ch == 0x0a) { |
| 541 result << "\\n"; | 541 result << "\\n"; |
| 542 continue; | 542 continue; |
| 543 } else if (ch == 0x0d) { | 543 } else if (ch == 0x0d) { |
| 544 result << "\\r"; | 544 result << "\\r"; |
| 545 continue; | 545 continue; |
| 546 } | 546 } |
| 547 result.AppendChar(ch); | 547 result.AppendChar(ch); |
| 548 } | 548 } |
| 549 result.AppendChar(')'); | 549 result.AppendChar(')'); |
| 550 return result.GetByteString(); | 550 return result.AsStringC(); |
| 551 } | 551 } |
| 552 | 552 |
| 553 void FlateEncode(const uint8_t* src_buf, | 553 void FlateEncode(const uint8_t* src_buf, |
| 554 uint32_t src_size, | 554 uint32_t src_size, |
| 555 uint8_t*& dest_buf, | 555 uint8_t*& dest_buf, |
| 556 uint32_t& dest_size) { | 556 uint32_t& dest_size) { |
| 557 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 557 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
| 558 if (pEncoders) { | 558 if (pEncoders) { |
| 559 pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, dest_size); | 559 pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, dest_size); |
| 560 } | 560 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 580 uint32_t src_size, | 580 uint32_t src_size, |
| 581 uint8_t*& dest_buf, | 581 uint8_t*& dest_buf, |
| 582 uint32_t& dest_size) { | 582 uint32_t& dest_size) { |
| 583 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 583 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
| 584 if (pEncoders) { | 584 if (pEncoders) { |
| 585 return pEncoders->GetFlateModule()->FlateOrLZWDecode( | 585 return pEncoders->GetFlateModule()->FlateOrLZWDecode( |
| 586 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); | 586 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); |
| 587 } | 587 } |
| 588 return 0; | 588 return 0; |
| 589 } | 589 } |
| OLD | NEW |