OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/cpdf_syntax_parser.h" | 7 #include "core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 210 |
211 CFX_ByteTextBuf buf; | 211 CFX_ByteTextBuf buf; |
212 int32_t parlevel = 0; | 212 int32_t parlevel = 0; |
213 int32_t status = 0; | 213 int32_t status = 0; |
214 int32_t iEscCode = 0; | 214 int32_t iEscCode = 0; |
215 while (1) { | 215 while (1) { |
216 switch (status) { | 216 switch (status) { |
217 case 0: | 217 case 0: |
218 if (ch == ')') { | 218 if (ch == ')') { |
219 if (parlevel == 0) { | 219 if (parlevel == 0) { |
220 return buf.AsStringC(); | 220 return buf.MakeString(); |
221 } | 221 } |
222 parlevel--; | 222 parlevel--; |
223 buf.AppendChar(')'); | 223 buf.AppendChar(')'); |
224 } else if (ch == '(') { | 224 } else if (ch == '(') { |
225 parlevel++; | 225 parlevel++; |
226 buf.AppendChar('('); | 226 buf.AppendChar('('); |
227 } else if (ch == '\\') { | 227 } else if (ch == '\\') { |
228 status = 1; | 228 status = 1; |
229 } else { | 229 } else { |
230 buf.AppendChar(ch); | 230 buf.AppendChar(ch); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 if (ch != '\n') | 283 if (ch != '\n') |
284 continue; | 284 continue; |
285 break; | 285 break; |
286 } | 286 } |
287 | 287 |
288 if (!GetNextChar(ch)) | 288 if (!GetNextChar(ch)) |
289 break; | 289 break; |
290 } | 290 } |
291 | 291 |
292 GetNextChar(ch); | 292 GetNextChar(ch); |
293 return buf.AsStringC(); | 293 return buf.MakeString(); |
294 } | 294 } |
295 | 295 |
296 CFX_ByteString CPDF_SyntaxParser::ReadHexString() { | 296 CFX_ByteString CPDF_SyntaxParser::ReadHexString() { |
297 uint8_t ch; | 297 uint8_t ch; |
298 if (!GetNextChar(ch)) | 298 if (!GetNextChar(ch)) |
299 return CFX_ByteString(); | 299 return CFX_ByteString(); |
300 | 300 |
301 CFX_ByteTextBuf buf; | 301 CFX_ByteTextBuf buf; |
302 bool bFirst = true; | 302 bool bFirst = true; |
303 uint8_t code = 0; | 303 uint8_t code = 0; |
(...skipping 11 matching lines...) Expand all Loading... |
315 } | 315 } |
316 bFirst = !bFirst; | 316 bFirst = !bFirst; |
317 } | 317 } |
318 | 318 |
319 if (!GetNextChar(ch)) | 319 if (!GetNextChar(ch)) |
320 break; | 320 break; |
321 } | 321 } |
322 if (!bFirst) | 322 if (!bFirst) |
323 buf.AppendByte(code); | 323 buf.AppendByte(code); |
324 | 324 |
325 return buf.AsStringC(); | 325 return buf.MakeString(); |
326 } | 326 } |
327 | 327 |
328 void CPDF_SyntaxParser::ToNextLine() { | 328 void CPDF_SyntaxParser::ToNextLine() { |
329 uint8_t ch; | 329 uint8_t ch; |
330 while (GetNextChar(ch)) { | 330 while (GetNextChar(ch)) { |
331 if (ch == '\n') | 331 if (ch == '\n') |
332 break; | 332 break; |
333 | 333 |
334 if (ch == '\r') { | 334 if (ch == '\r') { |
335 GetNextChar(ch); | 335 GetNextChar(ch); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 if (key.IsEmpty()) | 463 if (key.IsEmpty()) |
464 continue; | 464 continue; |
465 | 465 |
466 if (key == "/Contents") | 466 if (key == "/Contents") |
467 dwSignValuePos = m_Pos; | 467 dwSignValuePos = m_Pos; |
468 | 468 |
469 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, true); | 469 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, true); |
470 if (!pObj) | 470 if (!pObj) |
471 continue; | 471 continue; |
472 | 472 |
473 CFX_ByteStringC keyNoSlash(key.raw_str() + 1, key.GetLength() - 1); | 473 CFX_ByteString keyNoSlash(key.raw_str() + 1, key.GetLength() - 1); |
474 pDict->SetAt(keyNoSlash, pObj); | 474 pDict->SetAt(keyNoSlash, pObj); |
475 } | 475 } |
476 | 476 |
477 // Only when this is a signature dictionary and has contents, we reset the | 477 // Only when this is a signature dictionary and has contents, we reset the |
478 // contents to the un-decrypted form. | 478 // contents to the un-decrypted form. |
479 if (pDict->IsSignatureDict() && dwSignValuePos) { | 479 if (pDict->IsSignatureDict() && dwSignValuePos) { |
480 CFX_AutoRestorer<FX_FILESIZE> save_pos(&m_Pos); | 480 CFX_AutoRestorer<FX_FILESIZE> save_pos(&m_Pos); |
481 m_Pos = dwSignValuePos; | 481 m_Pos = dwSignValuePos; |
482 pDict->SetAt("Contents", GetObject(pObjList, objnum, gennum, false)); | 482 pDict->SetAt("Contents", GetObject(pObjList, objnum, gennum, false)); |
483 } | 483 } |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 if (limit && m_Pos == limit) | 982 if (limit && m_Pos == limit) |
983 return -1; | 983 return -1; |
984 } | 984 } |
985 return -1; | 985 return -1; |
986 } | 986 } |
987 | 987 |
988 void CPDF_SyntaxParser::SetEncrypt( | 988 void CPDF_SyntaxParser::SetEncrypt( |
989 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) { | 989 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) { |
990 m_pCryptoHandler = std::move(pCryptoHandler); | 990 m_pCryptoHandler = std::move(pCryptoHandler); |
991 } | 991 } |
OLD | NEW |