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 "../../../include/fpdfapi/fpdf_parser.h" | 7 #include "../../../include/fpdfapi/fpdf_parser.h" |
8 const char PDF_CharType[256] = { | 8 const char PDF_CharType[256] = { |
9 //NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO S
I | 9 //NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO S
I |
10 'W', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'W', 'W', 'R', 'W', 'W', 'R', '
R', | 10 'W', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'W', 'W', 'R', 'W', 'W', 'R', '
R', |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 { | 53 { |
54 m_pData = str.GetPtr(); | 54 m_pData = str.GetPtr(); |
55 m_dwSize = str.GetLength(); | 55 m_dwSize = str.GetLength(); |
56 m_dwCurPos = 0; | 56 m_dwCurPos = 0; |
57 } | 57 } |
58 void CPDF_SimpleParser::ParseWord(FX_LPCBYTE& pStart, FX_DWORD& dwSize, int& typ
e) | 58 void CPDF_SimpleParser::ParseWord(FX_LPCBYTE& pStart, FX_DWORD& dwSize, int& typ
e) |
59 { | 59 { |
60 pStart = NULL; | 60 pStart = NULL; |
61 dwSize = 0; | 61 dwSize = 0; |
62 type = PDFWORD_EOF; | 62 type = PDFWORD_EOF; |
63 FX_BYTE ch; | 63 uint8_t ch; |
64 char chartype; | 64 char chartype; |
65 while (1) { | 65 while (1) { |
66 if (m_dwSize <= m_dwCurPos) { | 66 if (m_dwSize <= m_dwCurPos) { |
67 return; | 67 return; |
68 } | 68 } |
69 ch = m_pData[m_dwCurPos++]; | 69 ch = m_pData[m_dwCurPos++]; |
70 chartype = PDF_CharType[ch]; | 70 chartype = PDF_CharType[ch]; |
71 while (chartype == 'W') { | 71 while (chartype == 'W') { |
72 if (m_dwSize <= m_dwCurPos) { | 72 if (m_dwSize <= m_dwCurPos) { |
73 return; | 73 return; |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 } | 315 } |
316 return PDF_NameDecode(CFX_ByteStringC(orig)); | 316 return PDF_NameDecode(CFX_ByteStringC(orig)); |
317 } | 317 } |
318 CFX_ByteString PDF_NameEncode(const CFX_ByteString& orig) | 318 CFX_ByteString PDF_NameEncode(const CFX_ByteString& orig) |
319 { | 319 { |
320 FX_LPBYTE src_buf = (FX_LPBYTE)orig.c_str(); | 320 FX_LPBYTE src_buf = (FX_LPBYTE)orig.c_str(); |
321 int src_len = orig.GetLength(); | 321 int src_len = orig.GetLength(); |
322 int dest_len = 0; | 322 int dest_len = 0; |
323 int i; | 323 int i; |
324 for (i = 0; i < src_len; i ++) { | 324 for (i = 0; i < src_len; i ++) { |
325 FX_BYTE ch = src_buf[i]; | 325 uint8_t ch = src_buf[i]; |
326 if (ch >= 0x80 || PDF_CharType[ch] == 'W' || ch == '#' || | 326 if (ch >= 0x80 || PDF_CharType[ch] == 'W' || ch == '#' || |
327 PDF_CharType[ch] == 'D') { | 327 PDF_CharType[ch] == 'D') { |
328 dest_len += 3; | 328 dest_len += 3; |
329 } else { | 329 } else { |
330 dest_len ++; | 330 dest_len ++; |
331 } | 331 } |
332 } | 332 } |
333 if (dest_len == src_len) { | 333 if (dest_len == src_len) { |
334 return orig; | 334 return orig; |
335 } | 335 } |
336 CFX_ByteString res; | 336 CFX_ByteString res; |
337 FX_LPSTR dest_buf = res.GetBuffer(dest_len); | 337 FX_LPSTR dest_buf = res.GetBuffer(dest_len); |
338 dest_len = 0; | 338 dest_len = 0; |
339 for (i = 0; i < src_len; i ++) { | 339 for (i = 0; i < src_len; i ++) { |
340 FX_BYTE ch = src_buf[i]; | 340 uint8_t ch = src_buf[i]; |
341 if (ch >= 0x80 || PDF_CharType[ch] == 'W' || ch == '#' || | 341 if (ch >= 0x80 || PDF_CharType[ch] == 'W' || ch == '#' || |
342 PDF_CharType[ch] == 'D') { | 342 PDF_CharType[ch] == 'D') { |
343 dest_buf[dest_len++] = '#'; | 343 dest_buf[dest_len++] = '#'; |
344 dest_buf[dest_len++] = "0123456789ABCDEF"[ch / 16]; | 344 dest_buf[dest_len++] = "0123456789ABCDEF"[ch / 16]; |
345 dest_buf[dest_len++] = "0123456789ABCDEF"[ch % 16]; | 345 dest_buf[dest_len++] = "0123456789ABCDEF"[ch % 16]; |
346 } else { | 346 } else { |
347 dest_buf[dest_len++] = ch; | 347 dest_buf[dest_len++] = ch; |
348 } | 348 } |
349 } | 349 } |
350 dest_buf[dest_len] = 0; | 350 dest_buf[dest_len] = 0; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 if (pFound) { | 470 if (pFound) { |
471 return pFound; | 471 return pFound; |
472 } | 472 } |
473 } | 473 } |
474 return NULL; | 474 return NULL; |
475 } | 475 } |
476 CPDF_Object* CPDF_NumberTree::LookupValue(int num) | 476 CPDF_Object* CPDF_NumberTree::LookupValue(int num) |
477 { | 477 { |
478 return SearchNumberNode(m_pRoot, num); | 478 return SearchNumberNode(m_pRoot, num); |
479 } | 479 } |
OLD | NEW |