| 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/fpdf_parser_utility.h" | 7 #include "core/fpdfapi/fpdf_parser/fpdf_parser_utility.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', | 62 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', |
| 63 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', | 63 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', |
| 64 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', | 64 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', |
| 65 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', | 65 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', |
| 66 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', | 66 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', |
| 67 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', | 67 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', |
| 68 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', | 68 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', |
| 69 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'W'}; | 69 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'W'}; |
| 70 | 70 |
| 71 int32_t GetHeaderOffset(IFX_FileRead* pFile) { | 71 int32_t GetHeaderOffset(IFX_FileRead* pFile) { |
| 72 // TODO(dsinclair): This is a complicated way of saying %PDF, simplify? | |
| 73 const FX_DWORD tag = FXDWORD_FROM_LSBFIRST(0x46445025); | |
| 74 | |
| 75 const size_t kBufSize = 4; | 72 const size_t kBufSize = 4; |
| 76 uint8_t buf[kBufSize]; | 73 uint8_t buf[kBufSize]; |
| 77 int32_t offset = 0; | 74 for (int32_t offset = 0; offset <= 1024; ++offset) { |
| 78 while (offset <= 1024) { | |
| 79 if (!pFile->ReadBlock(buf, offset, kBufSize)) | 75 if (!pFile->ReadBlock(buf, offset, kBufSize)) |
| 80 return -1; | 76 return -1; |
| 81 | 77 |
| 82 if (*(FX_DWORD*)buf == tag) | 78 if (memcmp(buf, "%PDF", 4) == 0) |
| 83 return offset; | 79 return offset; |
| 84 | |
| 85 ++offset; | |
| 86 } | 80 } |
| 87 return -1; | 81 return -1; |
| 88 } | 82 } |
| 89 | 83 |
| 90 int32_t GetDirectInteger(CPDF_Dictionary* pDict, const CFX_ByteStringC& key) { | 84 int32_t GetDirectInteger(CPDF_Dictionary* pDict, const CFX_ByteStringC& key) { |
| 91 CPDF_Number* pObj = ToNumber(pDict->GetElement(key)); | 85 CPDF_Number* pObj = ToNumber(pDict->GetElement(key)); |
| 92 return pObj ? pObj->GetInteger() : 0; | 86 return pObj ? pObj->GetInteger() : 0; |
| 93 } | 87 } |
| 94 | 88 |
| 95 CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& bstr) { | 89 CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& bstr) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 buf.AppendBlock(acc.GetData(), acc.GetSize()); | 214 buf.AppendBlock(acc.GetData(), acc.GetSize()); |
| 221 buf << "\r\nendstream"; | 215 buf << "\r\nendstream"; |
| 222 break; | 216 break; |
| 223 } | 217 } |
| 224 default: | 218 default: |
| 225 ASSERT(FALSE); | 219 ASSERT(FALSE); |
| 226 break; | 220 break; |
| 227 } | 221 } |
| 228 return buf; | 222 return buf; |
| 229 } | 223 } |
| OLD | NEW |