| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 } | 188 } |
| 189 m_dwCurPos ++; | 189 m_dwCurPos ++; |
| 190 } | 190 } |
| 191 if (m_dwCurPos < m_dwSize) { | 191 if (m_dwCurPos < m_dwSize) { |
| 192 m_dwCurPos ++; | 192 m_dwCurPos ++; |
| 193 } | 193 } |
| 194 return CFX_ByteStringC(pStart, (FX_STRSIZE)(m_dwCurPos - (pStart - m_pDa
ta))); | 194 return CFX_ByteStringC(pStart, (FX_STRSIZE)(m_dwCurPos - (pStart - m_pDa
ta))); |
| 195 } | 195 } |
| 196 return CFX_ByteStringC(pStart, dwSize); | 196 return CFX_ByteStringC(pStart, dwSize); |
| 197 } | 197 } |
| 198 bool CPDF_SimpleParser::SearchToken(const CFX_ByteStringC& token) | 198 FX_BOOL CPDF_SimpleParser::SearchToken(const CFX_ByteStringC& token) |
| 199 { | 199 { |
| 200 int token_len = token.GetLength(); | 200 int token_len = token.GetLength(); |
| 201 while (m_dwCurPos < m_dwSize - token_len) { | 201 while (m_dwCurPos < m_dwSize - token_len) { |
| 202 if (FXSYS_memcmp(m_pData + m_dwCurPos, token.GetPtr(), token_len) == 0)
{ | 202 if (FXSYS_memcmp(m_pData + m_dwCurPos, token.GetPtr(), token_len) == 0)
{ |
| 203 break; | 203 break; |
| 204 } | 204 } |
| 205 m_dwCurPos ++; | 205 m_dwCurPos ++; |
| 206 } | 206 } |
| 207 if (m_dwCurPos == m_dwSize - token_len) { | 207 if (m_dwCurPos == m_dwSize - token_len) { |
| 208 return false; | 208 return FALSE; |
| 209 } | 209 } |
| 210 m_dwCurPos += token_len; | 210 m_dwCurPos += token_len; |
| 211 return true; | 211 return TRUE; |
| 212 } | 212 } |
| 213 bool CPDF_SimpleParser::SkipWord(const CFX_ByteStringC& token) | 213 FX_BOOL CPDF_SimpleParser::SkipWord(const CFX_ByteStringC& token) |
| 214 { | 214 { |
| 215 while (1) { | 215 while (1) { |
| 216 CFX_ByteStringC word = GetWord(); | 216 CFX_ByteStringC word = GetWord(); |
| 217 if (word.IsEmpty()) { | 217 if (word.IsEmpty()) { |
| 218 return false; | 218 return FALSE; |
| 219 } | 219 } |
| 220 if (word == token) { | 220 if (word == token) { |
| 221 return true; | 221 return TRUE; |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 return false; | 224 return FALSE; |
| 225 } | 225 } |
| 226 bool CPDF_SimpleParser::FindTagPair(const CFX_ByteStringC& start_token, const CF
X_ByteStringC& end_token, | 226 FX_BOOL CPDF_SimpleParser::FindTagPair(const CFX_ByteStringC& start_token, const
CFX_ByteStringC& end_token, |
| 227 FX_DWORD& start_pos, FX_DWORD& end_pos) | 227 FX_DWORD& start_pos, FX_DWORD& end_pos) |
| 228 { | 228 { |
| 229 if (!start_token.IsEmpty()) { | 229 if (!start_token.IsEmpty()) { |
| 230 if (!SkipWord(start_token)) { | 230 if (!SkipWord(start_token)) { |
| 231 return false; | 231 return FALSE; |
| 232 } | 232 } |
| 233 start_pos = m_dwCurPos; | 233 start_pos = m_dwCurPos; |
| 234 } | 234 } |
| 235 while (1) { | 235 while (1) { |
| 236 end_pos = m_dwCurPos; | 236 end_pos = m_dwCurPos; |
| 237 CFX_ByteStringC word = GetWord(); | 237 CFX_ByteStringC word = GetWord(); |
| 238 if (word.IsEmpty()) { | 238 if (word.IsEmpty()) { |
| 239 return false; | 239 return FALSE; |
| 240 } | 240 } |
| 241 if (word == end_token) { | 241 if (word == end_token) { |
| 242 return true; | 242 return TRUE; |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 return false; | 245 return FALSE; |
| 246 } | 246 } |
| 247 bool CPDF_SimpleParser::FindTagParam(const CFX_ByteStringC& token, int nParams) | 247 FX_BOOL CPDF_SimpleParser::FindTagParam(const CFX_ByteStringC& token, int nParam
s) |
| 248 { | 248 { |
| 249 nParams ++; | 249 nParams ++; |
| 250 FX_DWORD* pBuf = FX_Alloc(FX_DWORD, nParams); | 250 FX_DWORD* pBuf = FX_Alloc(FX_DWORD, nParams); |
| 251 int buf_index = 0; | 251 int buf_index = 0; |
| 252 int buf_count = 0; | 252 int buf_count = 0; |
| 253 while (1) { | 253 while (1) { |
| 254 pBuf[buf_index++] = m_dwCurPos; | 254 pBuf[buf_index++] = m_dwCurPos; |
| 255 if (buf_index == nParams) { | 255 if (buf_index == nParams) { |
| 256 buf_index = 0; | 256 buf_index = 0; |
| 257 } | 257 } |
| 258 buf_count ++; | 258 buf_count ++; |
| 259 if (buf_count > nParams) { | 259 if (buf_count > nParams) { |
| 260 buf_count = nParams; | 260 buf_count = nParams; |
| 261 } | 261 } |
| 262 CFX_ByteStringC word = GetWord(); | 262 CFX_ByteStringC word = GetWord(); |
| 263 if (word.IsEmpty()) { | 263 if (word.IsEmpty()) { |
| 264 FX_Free(pBuf); | 264 FX_Free(pBuf); |
| 265 return false; | 265 return FALSE; |
| 266 } | 266 } |
| 267 if (word == token) { | 267 if (word == token) { |
| 268 if (buf_count < nParams) { | 268 if (buf_count < nParams) { |
| 269 continue; | 269 continue; |
| 270 } | 270 } |
| 271 m_dwCurPos = pBuf[buf_index]; | 271 m_dwCurPos = pBuf[buf_index]; |
| 272 FX_Free(pBuf); | 272 FX_Free(pBuf); |
| 273 return true; | 273 return TRUE; |
| 274 } | 274 } |
| 275 } | 275 } |
| 276 return false; | 276 return FALSE; |
| 277 } | 277 } |
| 278 static int _hex2dec(char ch) | 278 static int _hex2dec(char ch) |
| 279 { | 279 { |
| 280 if (ch >= '0' && ch <= '9') { | 280 if (ch >= '0' && ch <= '9') { |
| 281 return ch - '0'; | 281 return ch - '0'; |
| 282 } | 282 } |
| 283 if (ch >= 'a' && ch <= 'f') { | 283 if (ch >= 'a' && ch <= 'f') { |
| 284 return ch - 'a' + 10; | 284 return ch - 'a' + 10; |
| 285 } | 285 } |
| 286 if (ch >= 'A' && ch <= 'F') { | 286 if (ch >= 'A' && ch <= 'F') { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 switch (pObj->GetType()) { | 361 switch (pObj->GetType()) { |
| 362 case PDFOBJ_NULL: | 362 case PDFOBJ_NULL: |
| 363 buf << FX_BSTRC(" null"); | 363 buf << FX_BSTRC(" null"); |
| 364 break; | 364 break; |
| 365 case PDFOBJ_BOOLEAN: | 365 case PDFOBJ_BOOLEAN: |
| 366 case PDFOBJ_NUMBER: | 366 case PDFOBJ_NUMBER: |
| 367 buf << " " << pObj->GetString(); | 367 buf << " " << pObj->GetString(); |
| 368 break; | 368 break; |
| 369 case PDFOBJ_STRING: { | 369 case PDFOBJ_STRING: { |
| 370 CFX_ByteString str = pObj->GetString(); | 370 CFX_ByteString str = pObj->GetString(); |
| 371 bool bHex = ((CPDF_String*)pObj)->IsHex(); | 371 FX_BOOL bHex = ((CPDF_String*)pObj)->IsHex(); |
| 372 buf << PDF_EncodeString(str, bHex); | 372 buf << PDF_EncodeString(str, bHex); |
| 373 break; | 373 break; |
| 374 } | 374 } |
| 375 case PDFOBJ_NAME: { | 375 case PDFOBJ_NAME: { |
| 376 CFX_ByteString str = pObj->GetString(); | 376 CFX_ByteString str = pObj->GetString(); |
| 377 buf << FX_BSTRC("/") << PDF_NameEncode(str); | 377 buf << FX_BSTRC("/") << PDF_NameEncode(str); |
| 378 break; | 378 break; |
| 379 } | 379 } |
| 380 case PDFOBJ_REFERENCE: { | 380 case PDFOBJ_REFERENCE: { |
| 381 CPDF_Reference* p = (CPDF_Reference*)pObj; | 381 CPDF_Reference* p = (CPDF_Reference*)pObj; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 410 buf << pValue; | 410 buf << pValue; |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 buf << FX_BSTRC(">>"); | 413 buf << FX_BSTRC(">>"); |
| 414 break; | 414 break; |
| 415 } | 415 } |
| 416 case PDFOBJ_STREAM: { | 416 case PDFOBJ_STREAM: { |
| 417 CPDF_Stream* p = (CPDF_Stream*)pObj; | 417 CPDF_Stream* p = (CPDF_Stream*)pObj; |
| 418 buf << p->GetDict() << FX_BSTRC("stream\r\n"); | 418 buf << p->GetDict() << FX_BSTRC("stream\r\n"); |
| 419 CPDF_StreamAcc acc; | 419 CPDF_StreamAcc acc; |
| 420 acc.LoadAllData(p, true); | 420 acc.LoadAllData(p, TRUE); |
| 421 buf.AppendBlock(acc.GetData(), acc.GetSize()); | 421 buf.AppendBlock(acc.GetData(), acc.GetSize()); |
| 422 buf << FX_BSTRC("\r\nendstream"); | 422 buf << FX_BSTRC("\r\nendstream"); |
| 423 break; | 423 break; |
| 424 } | 424 } |
| 425 default: | 425 default: |
| 426 ASSERT(false); | 426 ASSERT(FALSE); |
| 427 break; | 427 break; |
| 428 } | 428 } |
| 429 return buf; | 429 return buf; |
| 430 } | 430 } |
| 431 FX_FLOAT PDF_ClipFloat(FX_FLOAT f) | 431 FX_FLOAT PDF_ClipFloat(FX_FLOAT f) |
| 432 { | 432 { |
| 433 if (f < 0) { | 433 if (f < 0) { |
| 434 return 0; | 434 return 0; |
| 435 } | 435 } |
| 436 if (f > 1.0f) { | 436 if (f > 1.0f) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 if (pFound) { | 471 if (pFound) { |
| 472 return pFound; | 472 return pFound; |
| 473 } | 473 } |
| 474 } | 474 } |
| 475 return NULL; | 475 return NULL; |
| 476 } | 476 } |
| 477 CPDF_Object* CPDF_NumberTree::LookupValue(int num) | 477 CPDF_Object* CPDF_NumberTree::LookupValue(int num) |
| 478 { | 478 { |
| 479 return SearchNumberNode(m_pRoot, num); | 479 return SearchNumberNode(m_pRoot, num); |
| 480 } | 480 } |
| OLD | NEW |