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

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

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: sigh Created 5 years, 4 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, uint8_t*& dest_bu f, FX_DWORD& dest_size) 12 FX_DWORD _A85Decode(const uint8_t* src_buf,
13 { 13 FX_DWORD src_size,
14 dest_size = 0; 14 uint8_t*& dest_buf,
15 dest_buf = NULL; 15 FX_DWORD& dest_size) {
16 if (src_size == 0) { 16 dest_size = 0;
17 return 0; 17 dest_buf = NULL;
18 } 18 if (src_size == 0) {
19 FX_DWORD zcount = 0; 19 return 0;
20 FX_DWORD pos = 0; 20 }
21 while (pos < src_size) { 21 FX_DWORD zcount = 0;
22 uint8_t ch = src_buf[pos]; 22 FX_DWORD pos = 0;
23 if (ch < '!' && ch != '\n' && ch != '\r' && ch != ' ' && ch != '\t') { 23 while (pos < src_size) {
24 break; 24 uint8_t ch = src_buf[pos];
25 if (ch < '!' && ch != '\n' && ch != '\r' && ch != ' ' && ch != '\t') {
26 break;
27 }
28 if (ch == 'z') {
29 zcount++;
30 } else if (ch > 'u') {
31 break;
32 }
33 pos++;
34 }
35 if (pos == 0) {
36 return 0;
37 }
38 if (zcount > UINT_MAX / 4) {
39 return (FX_DWORD)-1;
40 }
41 if (zcount * 4 > UINT_MAX - (pos - zcount)) {
42 return (FX_DWORD)-1;
43 }
44 dest_buf = FX_Alloc(uint8_t, zcount * 4 + (pos - zcount));
45 int state = 0;
46 uint32_t res = 0;
47 pos = dest_size = 0;
48 while (pos < src_size) {
49 uint8_t ch = src_buf[pos++];
50 if (ch == '\n' || ch == '\r' || ch == ' ' || ch == '\t') {
51 continue;
52 }
53 if (ch == 'z') {
54 FXSYS_memset(dest_buf + dest_size, 0, 4);
55 state = 0;
56 res = 0;
57 dest_size += 4;
58 } else {
59 if (ch < '!' || ch > 'u') {
60 break;
61 }
62 res = res * 85 + ch - 33;
63 state++;
64 if (state == 5) {
65 for (int i = 0; i < 4; i++) {
66 dest_buf[dest_size++] = (uint8_t)(res >> (3 - i) * 8);
25 } 67 }
26 if (ch == 'z') { 68 state = 0;
27 zcount ++; 69 res = 0;
28 } else if (ch > 'u') { 70 }
29 break; 71 }
30 } 72 }
31 pos ++; 73 if (state) {
32 } 74 int i;
33 if (pos == 0) { 75 for (i = state; i < 5; i++) {
34 return 0; 76 res = res * 85 + 84;
35 } 77 }
36 if (zcount > UINT_MAX / 4) { 78 for (i = 0; i < state - 1; i++) {
37 return (FX_DWORD) - 1; 79 dest_buf[dest_size++] = (uint8_t)(res >> (3 - i) * 8);
38 } 80 }
39 if (zcount * 4 > UINT_MAX - (pos - zcount)) { 81 }
40 return (FX_DWORD) - 1; 82 if (pos < src_size && src_buf[pos] == '>') {
41 } 83 pos++;
42 dest_buf = FX_Alloc(uint8_t, zcount * 4 + (pos - zcount)); 84 }
43 int state = 0; 85 return pos;
44 uint32_t res = 0; 86 }
45 pos = dest_size = 0; 87 FX_DWORD _HexDecode(const uint8_t* src_buf,
46 while (pos < src_size) { 88 FX_DWORD src_size,
47 uint8_t ch = src_buf[pos++]; 89 uint8_t*& dest_buf,
48 if (ch == '\n' || ch == '\r' || ch == ' ' || ch == '\t') { 90 FX_DWORD& dest_size) {
49 continue; 91 FX_DWORD i;
50 } 92 for (i = 0; i < src_size; i++)
51 if (ch == 'z') { 93 if (src_buf[i] == '>') {
52 FXSYS_memset(dest_buf + dest_size, 0, 4); 94 break;
53 state = 0; 95 }
54 res = 0; 96 dest_buf = FX_Alloc(uint8_t, i / 2 + 1);
55 dest_size += 4; 97 dest_size = 0;
56 } else { 98 FX_BOOL bFirstDigit = TRUE;
57 if (ch < '!' || ch > 'u') { 99 for (i = 0; i < src_size; i++) {
58 break; 100 uint8_t ch = src_buf[i];
59 } 101 if (ch == ' ' || ch == '\n' || ch == '\t' || ch == '\r') {
60 res = res * 85 + ch - 33; 102 continue;
61 state ++; 103 }
62 if (state == 5) { 104 int digit;
63 for (int i = 0; i < 4; i ++) { 105 if (ch <= '9' && ch >= '0') {
64 dest_buf[dest_size++] = (uint8_t)(res >> (3 - i) * 8); 106 digit = ch - '0';
65 } 107 } else if (ch <= 'f' && ch >= 'a') {
66 state = 0; 108 digit = ch - 'a' + 10;
67 res = 0; 109 } else if (ch <= 'F' && ch >= 'A') {
68 } 110 digit = ch - 'A' + 10;
69 } 111 } else if (ch == '>') {
70 } 112 i++;
71 if (state) { 113 break;
72 int i; 114 } else {
73 for (i = state; i < 5; i ++) { 115 continue;
74 res = res * 85 + 84; 116 }
75 } 117 if (bFirstDigit) {
76 for (i = 0; i < state - 1; i ++) { 118 dest_buf[dest_size] = digit * 16;
77 dest_buf[dest_size++] = (uint8_t)(res >> (3 - i) * 8); 119 } else {
78 } 120 dest_buf[dest_size++] += digit;
79 } 121 }
80 if (pos < src_size && src_buf[pos] == '>') { 122 bFirstDigit = !bFirstDigit;
81 pos ++; 123 }
82 } 124 if (!bFirstDigit) {
83 return pos; 125 dest_size++;
84 } 126 }
85 FX_DWORD _HexDecode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& dest_bu f, FX_DWORD& dest_size) 127 return i;
86 { 128 }
87 FX_DWORD i; 129 FX_DWORD RunLengthDecode(const uint8_t* src_buf,
88 for (i = 0; i < src_size; i ++) 130 FX_DWORD src_size,
89 if (src_buf[i] == '>') { 131 uint8_t*& dest_buf,
90 break; 132 FX_DWORD& dest_size) {
91 } 133 FX_DWORD i = 0;
92 dest_buf = FX_Alloc( uint8_t, i / 2 + 1); 134 FX_DWORD old;
93 dest_size = 0; 135 dest_size = 0;
94 FX_BOOL bFirstDigit = TRUE; 136 while (i < src_size) {
95 for (i = 0; i < src_size; i ++) { 137 if (src_buf[i] < 128) {
96 uint8_t ch = src_buf[i]; 138 old = dest_size;
97 if (ch == ' ' || ch == '\n' || ch == '\t' || ch == '\r') { 139 dest_size += src_buf[i] + 1;
98 continue; 140 if (dest_size < old) {
99 } 141 return (FX_DWORD)-1;
100 int digit; 142 }
101 if (ch <= '9' && ch >= '0') { 143 i += src_buf[i] + 2;
102 digit = ch - '0'; 144 } else if (src_buf[i] > 128) {
103 } else if (ch <= 'f' && ch >= 'a') { 145 old = dest_size;
104 digit = ch - 'a' + 10; 146 dest_size += 257 - src_buf[i];
105 } else if (ch <= 'F' && ch >= 'A') { 147 if (dest_size < old) {
106 digit = ch - 'A' + 10; 148 return (FX_DWORD)-1;
107 } else if (ch == '>') { 149 }
108 i ++; 150 i += 2;
109 break; 151 } else {
110 } else { 152 break;
111 continue; 153 }
112 } 154 }
113 if (bFirstDigit) { 155 if (dest_size >= _STREAM_MAX_SIZE_) {
114 dest_buf[dest_size] = digit * 16; 156 return -1;
115 } else { 157 }
116 dest_buf[dest_size ++] += digit; 158 dest_buf = FX_Alloc(uint8_t, dest_size);
117 } 159 i = 0;
118 bFirstDigit = !bFirstDigit; 160 int dest_count = 0;
119 } 161 while (i < src_size) {
120 if (!bFirstDigit) { 162 if (src_buf[i] < 128) {
121 dest_size ++; 163 FX_DWORD copy_len = src_buf[i] + 1;
122 } 164 FX_DWORD buf_left = src_size - i - 1;
123 return i; 165 if (buf_left < copy_len) {
124 } 166 FX_DWORD delta = copy_len - buf_left;
125 FX_DWORD RunLengthDecode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& de st_buf, FX_DWORD& dest_size) 167 copy_len = buf_left;
126 { 168 FXSYS_memset(dest_buf + dest_count + copy_len, '\0', delta);
127 FX_DWORD i = 0; 169 }
128 FX_DWORD old; 170 FXSYS_memcpy(dest_buf + dest_count, src_buf + i + 1, copy_len);
129 dest_size = 0; 171 dest_count += src_buf[i] + 1;
130 while (i < src_size) { 172 i += src_buf[i] + 2;
131 if (src_buf[i] < 128) { 173 } else if (src_buf[i] > 128) {
132 old = dest_size; 174 int fill = 0;
133 dest_size += src_buf[i] + 1; 175 if (i < src_size - 1) {
134 if (dest_size < old) { 176 fill = src_buf[i + 1];
135 return (FX_DWORD) - 1; 177 }
136 } 178 FXSYS_memset(dest_buf + dest_count, fill, 257 - src_buf[i]);
137 i += src_buf[i] + 2; 179 dest_count += 257 - src_buf[i];
138 } else if (src_buf[i] > 128) { 180 i += 2;
139 old = dest_size; 181 } else {
140 dest_size += 257 - src_buf[i]; 182 break;
141 if (dest_size < old) { 183 }
142 return (FX_DWORD) - 1; 184 }
143 } 185 FX_DWORD ret = i + 1;
144 i += 2; 186 if (ret > src_size) {
145 } else { 187 ret = src_size;
146 break; 188 }
147 } 189 return ret;
148 } 190 }
149 if (dest_size >= _STREAM_MAX_SIZE_) { 191 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(
150 return -1; 192 const uint8_t* src_buf,
151 } 193 FX_DWORD src_size,
152 dest_buf = FX_Alloc( uint8_t, dest_size); 194 int width,
153 i = 0; 195 int height,
154 int dest_count = 0; 196 const CPDF_Dictionary* pParams) {
155 while (i < src_size) { 197 int K = 0;
156 if (src_buf[i] < 128) { 198 FX_BOOL EndOfLine = FALSE;
157 FX_DWORD copy_len = src_buf[i] + 1; 199 FX_BOOL ByteAlign = FALSE;
158 FX_DWORD buf_left = src_size - i - 1; 200 FX_BOOL BlackIs1 = FALSE;
159 if (buf_left < copy_len) { 201 int Columns = 1728;
160 FX_DWORD delta = copy_len - buf_left; 202 int Rows = 0;
161 copy_len = buf_left; 203 if (pParams) {
162 FXSYS_memset(dest_buf + dest_count + copy_len, '\0', delta); 204 K = pParams->GetInteger(FX_BSTRC("K"));
163 } 205 EndOfLine = pParams->GetInteger(FX_BSTRC("EndOfLine"));
164 FXSYS_memcpy(dest_buf + dest_count, src_buf + i + 1, copy_len); 206 ByteAlign = pParams->GetInteger(FX_BSTRC("EncodedByteAlign"));
165 dest_count += src_buf[i] + 1; 207 BlackIs1 = pParams->GetInteger(FX_BSTRC("BlackIs1"));
166 i += src_buf[i] + 2; 208 Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1728);
167 } else if (src_buf[i] > 128) { 209 Rows = pParams->GetInteger(FX_BSTRC("Rows"));
168 int fill = 0; 210 if (Rows > USHRT_MAX) {
169 if (i < src_size - 1) { 211 Rows = 0;
170 fill = src_buf[i + 1]; 212 }
171 } 213 if (Columns <= 0 || Rows < 0 || Columns > USHRT_MAX || Rows > USHRT_MAX) {
172 FXSYS_memset(dest_buf + dest_count, fill, 257 - src_buf[i]); 214 return NULL;
173 dest_count += 257 - src_buf[i]; 215 }
174 i += 2; 216 }
175 } else { 217 return CPDF_ModuleMgr::Get()->GetFaxModule()->CreateDecoder(
176 break; 218 src_buf, src_size, width, height, K, EndOfLine, ByteAlign, BlackIs1,
177 } 219 Columns, Rows);
178 } 220 }
179 FX_DWORD ret = i + 1; 221 static FX_BOOL CheckFlateDecodeParams(int Colors,
180 if (ret > src_size) { 222 int BitsPerComponent,
181 ret = src_size; 223 int Columns) {
182 } 224 if (Columns < 0) {
183 return ret; 225 return FALSE;
184 } 226 }
185 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(const uint8_t* src_buf, FX_DWOR D src_size, int width, int height, 227 int check = Columns;
186 const CPDF_Dictionary* pParams) 228 if (Colors < 0 || (check > 0 && Colors > INT_MAX / check)) {
187 { 229 return FALSE;
188 int K = 0; 230 }
189 FX_BOOL EndOfLine = FALSE; 231 check *= Colors;
190 FX_BOOL ByteAlign = FALSE; 232 if (BitsPerComponent < 0 ||
191 FX_BOOL BlackIs1 = FALSE; 233 (check > 0 && BitsPerComponent > INT_MAX / check)) {
192 int Columns = 1728; 234 return FALSE;
193 int Rows = 0; 235 }
194 if (pParams) { 236 check *= BitsPerComponent;
195 K = pParams->GetInteger(FX_BSTRC("K")); 237 if (check > INT_MAX - 7) {
196 EndOfLine = pParams->GetInteger(FX_BSTRC("EndOfLine")); 238 return FALSE;
197 ByteAlign = pParams->GetInteger(FX_BSTRC("EncodedByteAlign")); 239 }
198 BlackIs1 = pParams->GetInteger(FX_BSTRC("BlackIs1")); 240 return TRUE;
199 Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1728); 241 }
200 Rows = pParams->GetInteger(FX_BSTRC("Rows")); 242 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(
201 if (Rows > USHRT_MAX) { 243 const uint8_t* src_buf,
202 Rows = 0; 244 FX_DWORD src_size,
203 } 245 int width,
204 if (Columns <= 0 || Rows < 0 || Columns > USHRT_MAX || Rows > USHRT_MAX) { 246 int height,
205 return NULL; 247 int nComps,
206 } 248 int bpc,
207 } 249 const CPDF_Dictionary* pParams) {
208 return CPDF_ModuleMgr::Get()->GetFaxModule()->CreateDecoder(src_buf, src_siz e, width, height, 250 int predictor = 0;
209 K, EndOfLine, ByteAlign, BlackIs1, Columns, Rows); 251 int Colors = 0, BitsPerComponent = 0, Columns = 0;
210 } 252 if (pParams) {
211 static FX_BOOL CheckFlateDecodeParams(int Colors, int BitsPerComponent, int Colu mns) 253 predictor = ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("Predictor"));
212 { 254 Colors = pParams->GetInteger(FX_BSTRC("Colors"), 1);
213 if (Columns < 0) { 255 BitsPerComponent = pParams->GetInteger(FX_BSTRC("BitsPerComponent"), 8);
214 return FALSE; 256 Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1);
215 } 257 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) {
216 int check = Columns; 258 return NULL;
217 if (Colors < 0 || (check > 0 && Colors > INT_MAX / check)) { 259 }
218 return FALSE; 260 }
219 } 261 return CPDF_ModuleMgr::Get()->GetFlateModule()->CreateDecoder(
220 check *= Colors; 262 src_buf, src_size, width, height, nComps, bpc, predictor, Colors,
221 if (BitsPerComponent < 0 || 263 BitsPerComponent, Columns);
222 (check > 0 && BitsPerComponent > INT_MAX / check)) { 264 }
223 return FALSE; 265 FX_DWORD FPDFAPI_FlateOrLZWDecode(FX_BOOL bLZW,
224 } 266 const uint8_t* src_buf,
225 check *= BitsPerComponent; 267 FX_DWORD src_size,
226 if (check > INT_MAX - 7) { 268 CPDF_Dictionary* pParams,
227 return FALSE; 269 FX_DWORD estimated_size,
228 } 270 uint8_t*& dest_buf,
229 return TRUE; 271 FX_DWORD& dest_size) {
230 } 272 int predictor = 0;
231 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(const uint8_t* src_buf, FX_DW ORD src_size, int width, int height, 273 FX_BOOL bEarlyChange = TRUE;
232 int nComps, int bpc, const CPDF_Dictionary* pParams) 274 int Colors = 0, BitsPerComponent = 0, Columns = 0;
233 { 275 if (pParams) {
234 int predictor = 0; 276 predictor = ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("Predictor"));
235 int Colors = 0, BitsPerComponent = 0, Columns = 0; 277 bEarlyChange =
236 if (pParams) { 278 ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("EarlyChange"), 1);
237 predictor = ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("Predictor" )); 279 Colors = pParams->GetInteger(FX_BSTRC("Colors"), 1);
238 Colors = pParams->GetInteger(FX_BSTRC("Colors"), 1); 280 BitsPerComponent = pParams->GetInteger(FX_BSTRC("BitsPerComponent"), 8);
239 BitsPerComponent = pParams->GetInteger(FX_BSTRC("BitsPerComponent"), 8); 281 Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1);
240 Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1); 282 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) {
241 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) { 283 return (FX_DWORD)-1;
242 return NULL; 284 }
243 } 285 }
244 } 286 return CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode(
245 return CPDF_ModuleMgr::Get()->GetFlateModule()->CreateDecoder(src_buf, src_s ize, width, height, 287 bLZW, src_buf, src_size, bEarlyChange, predictor, Colors,
246 nComps, bpc, predictor, Colors, BitsPerComponent, Columns); 288 BitsPerComponent, Columns, estimated_size, dest_buf, dest_size);
247 } 289 }
248 FX_DWORD FPDFAPI_FlateOrLZWDecode(FX_BOOL bLZW, const uint8_t* src_buf, FX_DWORD src_size, CPDF_Dictionary* pParams, 290 FX_BOOL PDF_DataDecode(const uint8_t* src_buf,
249 FX_DWORD estimated_size, uint8_t*& dest_buf, F X_DWORD& dest_size) 291 FX_DWORD src_size,
250 { 292 const CPDF_Dictionary* pDict,
251 int predictor = 0; 293 uint8_t*& dest_buf,
252 FX_BOOL bEarlyChange = TRUE; 294 FX_DWORD& dest_size,
253 int Colors = 0, BitsPerComponent = 0, Columns = 0; 295 CFX_ByteString& ImageEncoding,
254 if (pParams) { 296 CPDF_Dictionary*& pImageParms,
255 predictor = ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("Predictor" )); 297 FX_DWORD last_estimated_size,
256 bEarlyChange = ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("EarlyCh ange"), 1); 298 FX_BOOL bImageAcc)
257 Colors = pParams->GetInteger(FX_BSTRC("Colors"), 1);
258 BitsPerComponent = pParams->GetInteger(FX_BSTRC("BitsPerComponent"), 8);
259 Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1);
260 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) {
261 return (FX_DWORD) - 1;
262 }
263 }
264 return CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode(bLZW, src_b uf, src_size,
265 bEarlyChange, predictor, Colors, BitsPerComponent, Columns, estimate d_size,
266 dest_buf, dest_size);
267 }
268 FX_BOOL PDF_DataDecode(const uint8_t* src_buf, FX_DWORD src_size, const CPDF_Dic tionary* pDict,
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)
271 299
272 { 300 {
273 CPDF_Object* pDecoder = pDict ? pDict->GetElementValue(FX_BSTRC("Filter")) : NULL; 301 CPDF_Object* pDecoder =
274 if (pDecoder == NULL || (pDecoder->GetType() != PDFOBJ_ARRAY && pDecoder->Ge tType() != PDFOBJ_NAME)) { 302 pDict ? pDict->GetElementValue(FX_BSTRC("Filter")) : NULL;
275 return FALSE; 303 if (pDecoder == NULL || (pDecoder->GetType() != PDFOBJ_ARRAY &&
276 } 304 pDecoder->GetType() != PDFOBJ_NAME)) {
277 CPDF_Object* pParams = pDict ? pDict->GetElementValue(FX_BSTRC("DecodeParms" )) : NULL; 305 return FALSE;
278 CFX_ByteStringArray DecoderList; 306 }
279 CFX_PtrArray ParamList; 307 CPDF_Object* pParams =
280 if (pDecoder->GetType() == PDFOBJ_ARRAY) { 308 pDict ? pDict->GetElementValue(FX_BSTRC("DecodeParms")) : NULL;
281 if (pParams && pParams->GetType() != PDFOBJ_ARRAY) { 309 CFX_ByteStringArray DecoderList;
282 pParams = NULL; 310 CFX_PtrArray ParamList;
311 if (pDecoder->GetType() == PDFOBJ_ARRAY) {
312 if (pParams && pParams->GetType() != PDFOBJ_ARRAY) {
313 pParams = NULL;
314 }
315 CPDF_Array* pDecoders = (CPDF_Array*)pDecoder;
316 for (FX_DWORD i = 0; i < pDecoders->GetCount(); i++) {
317 CFX_ByteStringC str = pDecoders->GetConstString(i);
318 DecoderList.Add(str);
319 if (pParams) {
320 ParamList.Add(((CPDF_Array*)pParams)->GetDict(i));
321 } else {
322 ParamList.Add(NULL);
323 }
324 }
325 } else {
326 DecoderList.Add(pDecoder->GetConstString());
327 ParamList.Add(pParams ? pParams->GetDict() : NULL);
328 }
329 uint8_t* last_buf = (uint8_t*)src_buf;
330 FX_DWORD last_size = src_size;
331 for (int i = 0; i < DecoderList.GetSize(); i++) {
332 int estimated_size =
333 i == DecoderList.GetSize() - 1 ? last_estimated_size : 0;
334 CFX_ByteString decoder = DecoderList[i];
335 CPDF_Dictionary* pParam = (CPDF_Dictionary*)ParamList[i];
336 uint8_t* new_buf = NULL;
337 FX_DWORD new_size = (FX_DWORD)-1;
338 int offset = -1;
339 if (decoder == FX_BSTRC("FlateDecode") || decoder == FX_BSTRC("Fl")) {
340 if (bImageAcc && i == DecoderList.GetSize() - 1) {
341 ImageEncoding = FX_BSTRC("FlateDecode");
342 dest_buf = (uint8_t*)last_buf;
343 dest_size = last_size;
344 pImageParms = pParam;
345 return TRUE;
346 }
347 offset = FPDFAPI_FlateOrLZWDecode(FALSE, last_buf, last_size, pParam,
348 estimated_size, new_buf, new_size);
349 } else if (decoder == FX_BSTRC("LZWDecode") || decoder == FX_BSTRC("LZW")) {
350 offset = FPDFAPI_FlateOrLZWDecode(TRUE, last_buf, last_size, pParam,
351 estimated_size, new_buf, new_size);
352 } else if (decoder == FX_BSTRC("ASCII85Decode") ||
353 decoder == FX_BSTRC("A85")) {
354 offset = _A85Decode(last_buf, last_size, new_buf, new_size);
355 } else if (decoder == FX_BSTRC("ASCIIHexDecode") ||
356 decoder == FX_BSTRC("AHx")) {
357 offset = _HexDecode(last_buf, last_size, new_buf, new_size);
358 } else if (decoder == FX_BSTRC("RunLengthDecode") ||
359 decoder == FX_BSTRC("RL")) {
360 if (bImageAcc && i == DecoderList.GetSize() - 1) {
361 ImageEncoding = FX_BSTRC("RunLengthDecode");
362 dest_buf = (uint8_t*)last_buf;
363 dest_size = last_size;
364 pImageParms = pParam;
365 return TRUE;
366 }
367 offset = RunLengthDecode(last_buf, last_size, new_buf, new_size);
368 } else {
369 if (decoder == FX_BSTRC("DCT")) {
370 decoder = "DCTDecode";
371 } else if (decoder == FX_BSTRC("CCF")) {
372 decoder = "CCITTFaxDecode";
373 } else if (decoder == FX_BSTRC("Crypt")) {
374 continue;
375 }
376 ImageEncoding = decoder;
377 pImageParms = pParam;
378 dest_buf = (uint8_t*)last_buf;
379 dest_size = last_size;
380 return TRUE;
381 }
382 if (last_buf != src_buf) {
383 FX_Free(last_buf);
384 }
385 if (offset == -1) {
386 return FALSE;
387 }
388 last_buf = new_buf;
389 last_size = new_size;
390 }
391 ImageEncoding = "";
392 pImageParms = NULL;
393 dest_buf = last_buf;
394 dest_size = last_size;
395 return TRUE;
396 }
397 extern const FX_WORD PDFDocEncoding[256] = {
398 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008,
399 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011,
400 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x02d8, 0x02c7, 0x02c6,
401 0x02d9, 0x02dd, 0x02db, 0x02da, 0x02dc, 0x0020, 0x0021, 0x0022, 0x0023,
402 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c,
403 0x002d, 0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035,
404 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e,
405 0x003f, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
406 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, 0x0050,
407 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059,
408 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, 0x0060, 0x0061, 0x0062,
409 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b,
410 0x006c, 0x006d, 0x006e, 0x006f, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074,
411 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d,
412 0x007e, 0x0000, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x0192,
413 0x2044, 0x2039, 0x203a, 0x2212, 0x2030, 0x201e, 0x201c, 0x201d, 0x2018,
414 0x2019, 0x201a, 0x2122, 0xfb01, 0xfb02, 0x0141, 0x0152, 0x0160, 0x0178,
415 0x017d, 0x0131, 0x0142, 0x0153, 0x0161, 0x017e, 0x0000, 0x20ac, 0x00a1,
416 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa,
417 0x00ab, 0x00ac, 0x0000, 0x00ae, 0x00af, 0x00b0, 0x00b1, 0x00b2, 0x00b3,
418 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc,
419 0x00bd, 0x00be, 0x00bf, 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5,
420 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce,
421 0x00cf, 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7,
422 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, 0x00e0,
423 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9,
424 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, 0x00f0, 0x00f1, 0x00f2,
425 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb,
426 0x00fc, 0x00fd, 0x00fe, 0x00ff};
427 CFX_WideString PDF_DecodeText(const uint8_t* src_data,
428 FX_DWORD src_len,
429 CFX_CharMap* pCharMap) {
430 CFX_WideString result;
431 if (src_len >= 2 && ((src_data[0] == 0xfe && src_data[1] == 0xff) ||
432 (src_data[0] == 0xff && src_data[1] == 0xfe))) {
433 FX_BOOL bBE = src_data[0] == 0xfe;
434 FX_DWORD max_chars = (src_len - 2) / 2;
435 if (!max_chars) {
436 return result;
437 }
438 if (src_data[0] == 0xff) {
439 bBE = !src_data[2];
440 }
441 FX_WCHAR* dest_buf = result.GetBuffer(max_chars);
442 const uint8_t* uni_str = src_data + 2;
443 int dest_pos = 0;
444 for (FX_DWORD i = 0; i < max_chars * 2; i += 2) {
445 FX_WORD unicode = bBE ? (uni_str[i] << 8 | uni_str[i + 1])
446 : (uni_str[i + 1] << 8 | uni_str[i]);
447 if (unicode == 0x1b) {
448 i += 2;
449 while (i < max_chars * 2) {
450 FX_WORD unicode = bBE ? (uni_str[i] << 8 | uni_str[i + 1])
451 : (uni_str[i + 1] << 8 | uni_str[i]);
452 i += 2;
453 if (unicode == 0x1b) {
454 break;
455 }
283 } 456 }
284 CPDF_Array* pDecoders = (CPDF_Array*)pDecoder; 457 } else {
285 for (FX_DWORD i = 0; i < pDecoders->GetCount(); i ++) { 458 dest_buf[dest_pos++] = unicode;
286 CFX_ByteStringC str = pDecoders->GetConstString(i); 459 }
287 DecoderList.Add(str); 460 }
288 if (pParams) { 461 result.ReleaseBuffer(dest_pos);
289 ParamList.Add(((CPDF_Array*)pParams)->GetDict(i)); 462 } else if (pCharMap == NULL) {
290 } else { 463 FX_WCHAR* dest_buf = result.GetBuffer(src_len);
291 ParamList.Add(NULL); 464 for (FX_DWORD i = 0; i < src_len; i++) {
292 } 465 dest_buf[i] = PDFDocEncoding[src_data[i]];
466 }
467 result.ReleaseBuffer(src_len);
468 } else {
469 return (*pCharMap->m_GetWideString)(
470 pCharMap, CFX_ByteString((const FX_CHAR*)src_data, src_len));
471 }
472 return result;
473 }
474 CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString,
475 int len,
476 CFX_CharMap* pCharMap) {
477 if (len == -1) {
478 len = FXSYS_wcslen(pString);
479 }
480 CFX_ByteString result;
481 if (pCharMap == NULL) {
482 FX_CHAR* dest_buf1 = result.GetBuffer(len);
483 int i;
484 for (i = 0; i < len; i++) {
485 int code;
486 for (code = 0; code < 256; code++)
487 if (PDFDocEncoding[code] == pString[i]) {
488 break;
293 } 489 }
294 } else { 490 if (code == 256) {
295 DecoderList.Add(pDecoder->GetConstString()); 491 break;
296 ParamList.Add(pParams ? pParams->GetDict() : NULL); 492 }
297 } 493 dest_buf1[i] = code;
298 uint8_t* last_buf = (uint8_t*)src_buf; 494 }
299 FX_DWORD last_size = src_size; 495 result.ReleaseBuffer(i);
300 for (int i = 0; i < DecoderList.GetSize(); i ++) { 496 if (i == len) {
301 int estimated_size = i == DecoderList.GetSize() - 1 ? last_estimated_siz e : 0; 497 return result;
302 CFX_ByteString decoder = DecoderList[i]; 498 }
303 CPDF_Dictionary* pParam = (CPDF_Dictionary*)ParamList[i]; 499 }
304 uint8_t* new_buf = NULL; 500
305 FX_DWORD new_size = (FX_DWORD) - 1; 501 if (len > INT_MAX / 2 - 1) {
306 int offset = -1; 502 result.ReleaseBuffer(0);
307 if (decoder == FX_BSTRC("FlateDecode") || decoder == FX_BSTRC("Fl")) {
308 if (bImageAcc && i == DecoderList.GetSize() - 1) {
309 ImageEncoding = FX_BSTRC("FlateDecode");
310 dest_buf = (uint8_t*)last_buf;
311 dest_size = last_size;
312 pImageParms = pParam;
313 return TRUE;
314 }
315 offset = FPDFAPI_FlateOrLZWDecode(FALSE, last_buf, last_size, pParam , estimated_size, new_buf, new_size);
316 } else if (decoder == FX_BSTRC("LZWDecode") || decoder == FX_BSTRC("LZW" )) {
317 offset = FPDFAPI_FlateOrLZWDecode(TRUE, last_buf, last_size, pParam, estimated_size, new_buf, new_size);
318 } else if (decoder == FX_BSTRC("ASCII85Decode") || decoder == FX_BSTRC(" A85")) {
319 offset = _A85Decode(last_buf, last_size, new_buf, new_size);
320 } else if (decoder == FX_BSTRC("ASCIIHexDecode") || decoder == FX_BSTRC( "AHx")) {
321 offset = _HexDecode(last_buf, last_size, new_buf, new_size);
322 } else if (decoder == FX_BSTRC("RunLengthDecode") || decoder == FX_BSTRC ("RL")) {
323 if (bImageAcc && i == DecoderList.GetSize() - 1) {
324 ImageEncoding = FX_BSTRC("RunLengthDecode");
325 dest_buf = (uint8_t*)last_buf;
326 dest_size = last_size;
327 pImageParms = pParam;
328 return TRUE;
329 }
330 offset = RunLengthDecode(last_buf, last_size, new_buf, new_size);
331 } else {
332 if (decoder == FX_BSTRC("DCT")) {
333 decoder = "DCTDecode";
334 } else if (decoder == FX_BSTRC("CCF")) {
335 decoder = "CCITTFaxDecode";
336 } else if (decoder == FX_BSTRC("Crypt")) {
337 continue;
338 }
339 ImageEncoding = decoder;
340 pImageParms = pParam;
341 dest_buf = (uint8_t*)last_buf;
342 dest_size = last_size;
343 return TRUE;
344 }
345 if (last_buf != src_buf) {
346 FX_Free(last_buf);
347 }
348 if (offset == -1) {
349 return FALSE;
350 }
351 last_buf = new_buf;
352 last_size = new_size;
353 }
354 ImageEncoding = "";
355 pImageParms = NULL;
356 dest_buf = last_buf;
357 dest_size = last_size;
358 return TRUE;
359 }
360 extern const FX_WORD PDFDocEncoding[256] = {
361 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x00 09,
362 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011, 0x0012, 0x00 13,
363 0x0014, 0x0015, 0x0016, 0x0017, 0x02d8, 0x02c7, 0x02c6, 0x02d9, 0x02dd, 0x02 db,
364 0x02da, 0x02dc, 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x00 27,
365 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, 0x0030, 0x00 31,
366 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x00 3b,
367 0x003c, 0x003d, 0x003e, 0x003f, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x00 45,
368 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x00 4f,
369 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x00 59,
370 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, 0x0060, 0x0061, 0x0062, 0x00 63,
371 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x00 6d,
372 0x006e, 0x006f, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x00 77,
373 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x0000, 0x2022, 0x20 20,
374 0x2021, 0x2026, 0x2014, 0x2013, 0x0192, 0x2044, 0x2039, 0x203a, 0x2212, 0x20 30,
375 0x201e, 0x201c, 0x201d, 0x2018, 0x2019, 0x201a, 0x2122, 0xfb01, 0xfb02, 0x01 41,
376 0x0152, 0x0160, 0x0178, 0x017d, 0x0131, 0x0142, 0x0153, 0x0161, 0x017e, 0x00 00,
377 0x20ac, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00 a9,
378 0x00aa, 0x00ab, 0x00ac, 0x0000, 0x00ae, 0x00af, 0x00b0, 0x00b1, 0x00b2, 0x00 b3,
379 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00 bd,
380 0x00be, 0x00bf, 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00 c7,
381 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, 0x00d0, 0x00 d1,
382 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00 db,
383 0x00dc, 0x00dd, 0x00de, 0x00df, 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00 e5,
384 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00 ef,
385 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00 f9,
386 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff
387 };
388 CFX_WideString PDF_DecodeText(const uint8_t* src_data, FX_DWORD src_len, CFX_Cha rMap* pCharMap)
389 {
390 CFX_WideString result;
391 if (src_len >= 2 && ((src_data[0] == 0xfe && src_data[1] == 0xff) || (src_da ta[0] == 0xff && src_data[1] == 0xfe))) {
392 FX_BOOL bBE = src_data[0] == 0xfe;
393 FX_DWORD max_chars = (src_len - 2) / 2;
394 if (!max_chars) {
395 return result;
396 }
397 if (src_data[0] == 0xff) {
398 bBE = !src_data[2];
399 }
400 FX_WCHAR* dest_buf = result.GetBuffer(max_chars);
401 const uint8_t* uni_str = src_data + 2;
402 int dest_pos = 0;
403 for (FX_DWORD i = 0; i < max_chars * 2; i += 2) {
404 FX_WORD unicode = bBE ? (uni_str[i] << 8 | uni_str[i + 1]) : (uni_st r[i + 1] << 8 | uni_str[i]);
405 if (unicode == 0x1b) {
406 i += 2;
407 while (i < max_chars * 2) {
408 FX_WORD unicode = bBE ? (uni_str[i] << 8 | uni_str[i + 1]) : (uni_str[i + 1] << 8 | uni_str[i]);
409 i += 2;
410 if (unicode == 0x1b) {
411 break;
412 }
413 }
414 } else {
415 dest_buf[dest_pos++] = unicode;
416 }
417 }
418 result.ReleaseBuffer(dest_pos);
419 } else if (pCharMap == NULL) {
420 FX_WCHAR* dest_buf = result.GetBuffer(src_len);
421 for (FX_DWORD i = 0; i < src_len; i ++) {
422 dest_buf[i] = PDFDocEncoding[src_data[i]];
423 }
424 result.ReleaseBuffer(src_len);
425 } else {
426 return (*pCharMap->m_GetWideString)(pCharMap, CFX_ByteString((const FX_C HAR*)src_data, src_len));
427 }
428 return result; 503 return result;
429 } 504 }
430 CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString, int len, CFX_CharMap* pCh arMap)
431 {
432 if (len == -1) {
433 len = FXSYS_wcslen(pString);
434 }
435 CFX_ByteString result;
436 if (pCharMap == NULL) {
437 FX_CHAR* dest_buf1 = result.GetBuffer(len);
438 int i;
439 for (i = 0; i < len; i ++) {
440 int code;
441 for (code = 0; code < 256; code ++)
442 if (PDFDocEncoding[code] == pString[i]) {
443 break;
444 }
445 if (code == 256) {
446 break;
447 }
448 dest_buf1[i] = code;
449 }
450 result.ReleaseBuffer(i);
451 if (i == len) {
452 return result;
453 }
454 }
455 505
456 if(len > INT_MAX/2-1) 506 int encLen = len * 2 + 2;
457 {
458 result.ReleaseBuffer(0);
459 return result;
460 }
461 507
462 int encLen = len * 2 + 2; 508 uint8_t* dest_buf2 = (uint8_t*)result.GetBuffer(encLen);
463 509 dest_buf2[0] = 0xfe;
464 uint8_t* dest_buf2 = (uint8_t*)result.GetBuffer(encLen); 510 dest_buf2[1] = 0xff;
465 dest_buf2[0] = 0xfe; 511 dest_buf2 += 2;
466 dest_buf2[1] = 0xff; 512 for (int i = 0; i < len; i++) {
467 dest_buf2 += 2; 513 *dest_buf2++ = pString[i] >> 8;
468 for (int i = 0; i < len; i ++) { 514 *dest_buf2++ = (uint8_t)pString[i];
469 *dest_buf2++ = pString[i] >> 8; 515 }
470 *dest_buf2++ = (uint8_t)pString[i]; 516 result.ReleaseBuffer(encLen);
471 } 517 return result;
472 result.ReleaseBuffer(encLen); 518 }
473 return result; 519 CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, FX_BOOL bHex) {
474 } 520 CFX_ByteTextBuf result;
475 CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, FX_BOOL bHex) 521 int srclen = src.GetLength();
476 { 522 if (bHex) {
477 CFX_ByteTextBuf result; 523 result.AppendChar('<');
478 int srclen = src.GetLength(); 524 for (int i = 0; i < srclen; i++) {
479 if (bHex) { 525 result.AppendChar("0123456789ABCDEF"[src[i] / 16]);
480 result.AppendChar('<'); 526 result.AppendChar("0123456789ABCDEF"[src[i] % 16]);
481 for (int i = 0; i < srclen; i ++) { 527 }
482 result.AppendChar("0123456789ABCDEF"[src[i] / 16]); 528 result.AppendChar('>');
483 result.AppendChar("0123456789ABCDEF"[src[i] % 16]);
484 }
485 result.AppendChar('>');
486 return result.GetByteString();
487 }
488 result.AppendChar('(');
489 for (int i = 0; i < srclen; i ++) {
490 uint8_t ch = src[i];
491 if (ch == ')' || ch == '\\' || ch == '(') {
492 result.AppendChar('\\');
493 } else if (ch == 0x0a) {
494 result << FX_BSTRC("\\n");
495 continue;
496 } else if (ch == 0x0d) {
497 result << FX_BSTRC("\\r");
498 continue;
499 }
500 result.AppendChar(ch);
501 }
502 result.AppendChar(')');
503 return result.GetByteString(); 529 return result.GetByteString();
504 } 530 }
505 void FlateEncode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& dest_buf, FX_DWORD& dest_size) 531 result.AppendChar('(');
506 { 532 for (int i = 0; i < srclen; i++) {
507 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); 533 uint8_t ch = src[i];
508 if (pEncoders) { 534 if (ch == ')' || ch == '\\' || ch == '(') {
509 pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, dest_si ze); 535 result.AppendChar('\\');
510 } 536 } else if (ch == 0x0a) {
511 } 537 result << FX_BSTRC("\\n");
512 void FlateEncode(const uint8_t* src_buf, FX_DWORD src_size, int predictor, int C olors, int BitsPerComponent, int Columns, 538 continue;
513 uint8_t*& dest_buf, FX_DWORD& dest_size) 539 } else if (ch == 0x0d) {
514 { 540 result << FX_BSTRC("\\r");
515 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); 541 continue;
516 if (pEncoders) { 542 }
517 pEncoders->GetFlateModule()->Encode(src_buf, src_size, predictor, Colors , BitsPerComponent, Columns, dest_buf, dest_size); 543 result.AppendChar(ch);
518 } 544 }
519 } 545 result.AppendChar(')');
520 FX_DWORD FlateDecode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& dest_b uf, FX_DWORD& dest_size) 546 return result.GetByteString();
521 { 547 }
522 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); 548 void FlateEncode(const uint8_t* src_buf,
523 if (pEncoders) { 549 FX_DWORD src_size,
524 return pEncoders->GetFlateModule()->FlateOrLZWDecode(FALSE, src_buf, src _size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); 550 uint8_t*& dest_buf,
525 } 551 FX_DWORD& dest_size) {
526 return 0; 552 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule();
527 } 553 if (pEncoders) {
554 pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, dest_size);
555 }
556 }
557 void FlateEncode(const uint8_t* src_buf,
558 FX_DWORD src_size,
559 int predictor,
560 int Colors,
561 int BitsPerComponent,
562 int Columns,
563 uint8_t*& dest_buf,
564 FX_DWORD& dest_size) {
565 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule();
566 if (pEncoders) {
567 pEncoders->GetFlateModule()->Encode(src_buf, src_size, predictor, Colors,
568 BitsPerComponent, Columns, dest_buf,
569 dest_size);
570 }
571 }
572 FX_DWORD FlateDecode(const uint8_t* src_buf,
573 FX_DWORD src_size,
574 uint8_t*& dest_buf,
575 FX_DWORD& dest_size) {
576 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule();
577 if (pEncoders) {
578 return pEncoders->GetFlateModule()->FlateOrLZWDecode(
579 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size);
580 }
581 return 0;
582 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698