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" |
11 #include "core/include/fxcodec/fx_codec.h" | 11 #include "core/include/fxcodec/fx_codec.h" |
| 12 #include "core/include/fxcrt/fx_ext.h" |
12 | 13 |
13 #define _STREAM_MAX_SIZE_ 20 * 1024 * 1024 | 14 #define _STREAM_MAX_SIZE_ 20 * 1024 * 1024 |
14 | 15 |
15 const FX_WORD PDFDocEncoding[256] = { | 16 const FX_WORD PDFDocEncoding[256] = { |
16 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, | 17 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, |
17 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011, | 18 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011, |
18 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x02d8, 0x02c7, 0x02c6, | 19 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x02d8, 0x02c7, 0x02c6, |
19 0x02d9, 0x02dd, 0x02db, 0x02da, 0x02dc, 0x0020, 0x0021, 0x0022, 0x0023, | 20 0x02d9, 0x02dd, 0x02db, 0x02da, 0x02dc, 0x0020, 0x0021, 0x0022, 0x0023, |
20 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, | 21 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, |
21 0x002d, 0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, | 22 0x002d, 0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 FX_DWORD src_size, | 123 FX_DWORD src_size, |
123 uint8_t*& dest_buf, | 124 uint8_t*& dest_buf, |
124 FX_DWORD& dest_size) { | 125 FX_DWORD& dest_size) { |
125 FX_DWORD i; | 126 FX_DWORD i; |
126 for (i = 0; i < src_size; i++) | 127 for (i = 0; i < src_size; i++) |
127 if (src_buf[i] == '>') { | 128 if (src_buf[i] == '>') { |
128 break; | 129 break; |
129 } | 130 } |
130 dest_buf = FX_Alloc(uint8_t, i / 2 + 1); | 131 dest_buf = FX_Alloc(uint8_t, i / 2 + 1); |
131 dest_size = 0; | 132 dest_size = 0; |
132 FX_BOOL bFirstDigit = TRUE; | 133 bool bFirst = true; |
133 for (i = 0; i < src_size; i++) { | 134 for (i = 0; i < src_size; i++) { |
134 uint8_t ch = src_buf[i]; | 135 uint8_t ch = src_buf[i]; |
135 if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t') | 136 if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t') |
136 continue; | 137 continue; |
137 | 138 |
138 int digit; | 139 if (ch == '>') { |
139 if (ch <= '9' && ch >= '0') { | 140 ++i; |
140 digit = ch - '0'; | |
141 } else if (ch <= 'f' && ch >= 'a') { | |
142 digit = ch - 'a' + 10; | |
143 } else if (ch <= 'F' && ch >= 'A') { | |
144 digit = ch - 'A' + 10; | |
145 } else if (ch == '>') { | |
146 i++; | |
147 break; | 141 break; |
148 } else { | 142 } |
| 143 if (!std::isxdigit(ch)) |
149 continue; | 144 continue; |
150 } | 145 |
151 if (bFirstDigit) { | 146 int digit = FXSYS_toHexDigit(ch); |
| 147 if (bFirst) |
152 dest_buf[dest_size] = digit * 16; | 148 dest_buf[dest_size] = digit * 16; |
153 } else { | 149 else |
154 dest_buf[dest_size++] += digit; | 150 dest_buf[dest_size++] += digit; |
155 } | 151 |
156 bFirstDigit = !bFirstDigit; | 152 bFirst = !bFirst; |
157 } | 153 } |
158 if (!bFirstDigit) { | 154 if (!bFirst) |
159 dest_size++; | 155 dest_size++; |
160 } | |
161 return i; | 156 return i; |
162 } | 157 } |
| 158 |
163 FX_DWORD RunLengthDecode(const uint8_t* src_buf, | 159 FX_DWORD RunLengthDecode(const uint8_t* src_buf, |
164 FX_DWORD src_size, | 160 FX_DWORD src_size, |
165 uint8_t*& dest_buf, | 161 uint8_t*& dest_buf, |
166 FX_DWORD& dest_size) { | 162 FX_DWORD& dest_size) { |
167 FX_DWORD i = 0; | 163 FX_DWORD i = 0; |
168 FX_DWORD old; | 164 FX_DWORD old; |
169 dest_size = 0; | 165 dest_size = 0; |
170 while (i < src_size) { | 166 while (i < src_size) { |
171 if (src_buf[i] < 128) { | 167 if (src_buf[i] < 128) { |
172 old = dest_size; | 168 old = dest_size; |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 FX_DWORD src_size, | 573 FX_DWORD src_size, |
578 uint8_t*& dest_buf, | 574 uint8_t*& dest_buf, |
579 FX_DWORD& dest_size) { | 575 FX_DWORD& dest_size) { |
580 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 576 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
581 if (pEncoders) { | 577 if (pEncoders) { |
582 return pEncoders->GetFlateModule()->FlateOrLZWDecode( | 578 return pEncoders->GetFlateModule()->FlateOrLZWDecode( |
583 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); | 579 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); |
584 } | 580 } |
585 return 0; | 581 return 0; |
586 } | 582 } |
OLD | NEW |