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