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/page/cpdf_streamcontentparser.h" | 7 #include "core/fpdfapi/page/cpdf_streamcontentparser.h" |
8 | 8 |
9 #include "core/fpdfapi/font/cpdf_font.h" | 9 #include "core/fpdfapi/font/cpdf_font.h" |
10 #include "core/fpdfapi/font/cpdf_type3font.h" | 10 #include "core/fpdfapi/font/cpdf_type3font.h" |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 if (param.m_Type == ContentParam::NAME) { | 278 if (param.m_Type == ContentParam::NAME) { |
279 CPDF_Name* pName = new CPDF_Name(m_pDocument->GetByteStringPool()->Intern( | 279 CPDF_Name* pName = new CPDF_Name(m_pDocument->GetByteStringPool()->Intern( |
280 CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len))); | 280 CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len))); |
281 param.m_Type = ContentParam::OBJECT; | 281 param.m_Type = ContentParam::OBJECT; |
282 param.m_pObject = pName; | 282 param.m_pObject = pName; |
283 return pName; | 283 return pName; |
284 } | 284 } |
285 if (param.m_Type == ContentParam::OBJECT) { | 285 if (param.m_Type == ContentParam::OBJECT) { |
286 return param.m_pObject; | 286 return param.m_pObject; |
287 } | 287 } |
288 ASSERT(FALSE); | 288 ASSERT(false); |
289 return nullptr; | 289 return nullptr; |
290 } | 290 } |
291 | 291 |
292 CFX_ByteString CPDF_StreamContentParser::GetString(uint32_t index) { | 292 CFX_ByteString CPDF_StreamContentParser::GetString(uint32_t index) { |
293 if (index >= m_ParamCount) { | 293 if (index >= m_ParamCount) { |
294 return CFX_ByteString(); | 294 return CFX_ByteString(); |
295 } | 295 } |
296 int real_index = m_ParamStartPos + m_ParamCount - index - 1; | 296 int real_index = m_ParamStartPos + m_ParamCount - index - 1; |
297 if (real_index >= kParamBufSize) { | 297 if (real_index >= kParamBufSize) { |
298 real_index -= kParamBufSize; | 298 real_index -= kParamBufSize; |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 m_pSyntax->GetWordBuf()[1] == 'I') { | 580 m_pSyntax->GetWordBuf()[1] == 'I') { |
581 break; | 581 break; |
582 } | 582 } |
583 } | 583 } |
584 CPDF_ImageObject* pImgObj = AddImage(std::move(pStream)); | 584 CPDF_ImageObject* pImgObj = AddImage(std::move(pStream)); |
585 if (!pImgObj && !bGaveDictAway) | 585 if (!pImgObj && !bGaveDictAway) |
586 pDict->Release(); | 586 pDict->Release(); |
587 } | 587 } |
588 | 588 |
589 void CPDF_StreamContentParser::Handle_BeginMarkedContent() { | 589 void CPDF_StreamContentParser::Handle_BeginMarkedContent() { |
590 m_CurContentMark.AddMark(GetString(0), nullptr, FALSE); | 590 m_CurContentMark.AddMark(GetString(0), nullptr, false); |
591 } | 591 } |
592 | 592 |
593 void CPDF_StreamContentParser::Handle_BeginText() { | 593 void CPDF_StreamContentParser::Handle_BeginText() { |
594 m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0); | 594 m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0); |
595 OnChangeTextMatrix(); | 595 OnChangeTextMatrix(); |
596 m_pCurStates->m_TextX = 0; | 596 m_pCurStates->m_TextX = 0; |
597 m_pCurStates->m_TextY = 0; | 597 m_pCurStates->m_TextY = 0; |
598 m_pCurStates->m_TextLineX = 0; | 598 m_pCurStates->m_TextLineX = 0; |
599 m_pCurStates->m_TextLineY = 0; | 599 m_pCurStates->m_TextLineY = 0; |
600 } | 600 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 pFormObj->m_FormMatrix = m_pCurStates->m_CTM; | 690 pFormObj->m_FormMatrix = m_pCurStates->m_CTM; |
691 pFormObj->m_FormMatrix.Concat(m_mtContentToUser); | 691 pFormObj->m_FormMatrix.Concat(m_mtContentToUser); |
692 CPDF_AllStates status; | 692 CPDF_AllStates status; |
693 status.m_GeneralState = m_pCurStates->m_GeneralState; | 693 status.m_GeneralState = m_pCurStates->m_GeneralState; |
694 status.m_GraphState = m_pCurStates->m_GraphState; | 694 status.m_GraphState = m_pCurStates->m_GraphState; |
695 status.m_ColorState = m_pCurStates->m_ColorState; | 695 status.m_ColorState = m_pCurStates->m_ColorState; |
696 status.m_TextState = m_pCurStates->m_TextState; | 696 status.m_TextState = m_pCurStates->m_TextState; |
697 pFormObj->m_pForm->ParseContent(&status, nullptr, nullptr, m_Level + 1); | 697 pFormObj->m_pForm->ParseContent(&status, nullptr, nullptr, m_Level + 1); |
698 if (!m_pObjectHolder->BackgroundAlphaNeeded() && | 698 if (!m_pObjectHolder->BackgroundAlphaNeeded() && |
699 pFormObj->m_pForm->BackgroundAlphaNeeded()) { | 699 pFormObj->m_pForm->BackgroundAlphaNeeded()) { |
700 m_pObjectHolder->SetBackgroundAlphaNeeded(TRUE); | 700 m_pObjectHolder->SetBackgroundAlphaNeeded(true); |
701 } | 701 } |
702 pFormObj->CalcBoundingBox(); | 702 pFormObj->CalcBoundingBox(); |
703 SetGraphicStates(pFormObj.get(), true, true, true); | 703 SetGraphicStates(pFormObj.get(), true, true, true); |
704 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pFormObj)); | 704 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pFormObj)); |
705 } | 705 } |
706 | 706 |
707 CPDF_ImageObject* CPDF_StreamContentParser::AddImage(UniqueStream pStream) { | 707 CPDF_ImageObject* CPDF_StreamContentParser::AddImage(UniqueStream pStream) { |
708 if (!pStream) | 708 if (!pStream) |
709 return nullptr; | 709 return nullptr; |
710 | 710 |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1403 | 1403 |
1404 void CPDF_StreamContentParser::AddPathObject(int FillType, bool bStroke) { | 1404 void CPDF_StreamContentParser::AddPathObject(int FillType, bool bStroke) { |
1405 int PathPointCount = m_PathPointCount; | 1405 int PathPointCount = m_PathPointCount; |
1406 uint8_t PathClipType = m_PathClipType; | 1406 uint8_t PathClipType = m_PathClipType; |
1407 m_PathPointCount = 0; | 1407 m_PathPointCount = 0; |
1408 m_PathClipType = 0; | 1408 m_PathClipType = 0; |
1409 if (PathPointCount <= 1) { | 1409 if (PathPointCount <= 1) { |
1410 if (PathPointCount && PathClipType) { | 1410 if (PathPointCount && PathClipType) { |
1411 CPDF_Path path; | 1411 CPDF_Path path; |
1412 path.AppendRect(0, 0, 0, 0); | 1412 path.AppendRect(0, 0, 0, 0); |
1413 m_pCurStates->m_ClipPath.AppendPath(path, FXFILL_WINDING, TRUE); | 1413 m_pCurStates->m_ClipPath.AppendPath(path, FXFILL_WINDING, true); |
1414 } | 1414 } |
1415 return; | 1415 return; |
1416 } | 1416 } |
1417 if (PathPointCount && | 1417 if (PathPointCount && |
1418 m_pPathPoints[PathPointCount - 1].m_Flag == FXPT_MOVETO) { | 1418 m_pPathPoints[PathPointCount - 1].m_Flag == FXPT_MOVETO) { |
1419 PathPointCount--; | 1419 PathPointCount--; |
1420 } | 1420 } |
1421 CPDF_Path Path; | 1421 CPDF_Path Path; |
1422 Path.SetPointCount(PathPointCount); | 1422 Path.SetPointCount(PathPointCount); |
1423 FXSYS_memcpy(Path.GetMutablePoints(), m_pPathPoints, | 1423 FXSYS_memcpy(Path.GetMutablePoints(), m_pPathPoints, |
1424 sizeof(FX_PATHPOINT) * PathPointCount); | 1424 sizeof(FX_PATHPOINT) * PathPointCount); |
1425 CFX_Matrix matrix = m_pCurStates->m_CTM; | 1425 CFX_Matrix matrix = m_pCurStates->m_CTM; |
1426 matrix.Concat(m_mtContentToUser); | 1426 matrix.Concat(m_mtContentToUser); |
1427 if (bStroke || FillType) { | 1427 if (bStroke || FillType) { |
1428 std::unique_ptr<CPDF_PathObject> pPathObj(new CPDF_PathObject); | 1428 std::unique_ptr<CPDF_PathObject> pPathObj(new CPDF_PathObject); |
1429 pPathObj->m_bStroke = bStroke; | 1429 pPathObj->m_bStroke = bStroke; |
1430 pPathObj->m_FillType = FillType; | 1430 pPathObj->m_FillType = FillType; |
1431 pPathObj->m_Path = Path; | 1431 pPathObj->m_Path = Path; |
1432 pPathObj->m_Matrix = matrix; | 1432 pPathObj->m_Matrix = matrix; |
1433 SetGraphicStates(pPathObj.get(), true, false, true); | 1433 SetGraphicStates(pPathObj.get(), true, false, true); |
1434 pPathObj->CalcBoundingBox(); | 1434 pPathObj->CalcBoundingBox(); |
1435 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pPathObj)); | 1435 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pPathObj)); |
1436 } | 1436 } |
1437 if (PathClipType) { | 1437 if (PathClipType) { |
1438 if (!matrix.IsIdentity()) { | 1438 if (!matrix.IsIdentity()) { |
1439 Path.Transform(&matrix); | 1439 Path.Transform(&matrix); |
1440 matrix.SetIdentity(); | 1440 matrix.SetIdentity(); |
1441 } | 1441 } |
1442 m_pCurStates->m_ClipPath.AppendPath(Path, PathClipType, TRUE); | 1442 m_pCurStates->m_ClipPath.AppendPath(Path, PathClipType, true); |
1443 } | 1443 } |
1444 } | 1444 } |
1445 | 1445 |
1446 uint32_t CPDF_StreamContentParser::Parse(const uint8_t* pData, | 1446 uint32_t CPDF_StreamContentParser::Parse(const uint8_t* pData, |
1447 uint32_t dwSize, | 1447 uint32_t dwSize, |
1448 uint32_t max_cost) { | 1448 uint32_t max_cost) { |
1449 if (m_Level > kMaxFormLevel) | 1449 if (m_Level > kMaxFormLevel) |
1450 return dwSize; | 1450 return dwSize; |
1451 | 1451 |
1452 uint32_t InitObjCount = m_pObjectHolder->GetPageObjectList()->size(); | 1452 uint32_t InitObjCount = m_pObjectHolder->GetPageObjectList()->size(); |
(...skipping 24 matching lines...) Expand all Loading... |
1477 } | 1477 } |
1478 return m_pSyntax->GetPos(); | 1478 return m_pSyntax->GetPos(); |
1479 } | 1479 } |
1480 | 1480 |
1481 void CPDF_StreamContentParser::ParsePathObject() { | 1481 void CPDF_StreamContentParser::ParsePathObject() { |
1482 FX_FLOAT params[6] = {}; | 1482 FX_FLOAT params[6] = {}; |
1483 int nParams = 0; | 1483 int nParams = 0; |
1484 int last_pos = m_pSyntax->GetPos(); | 1484 int last_pos = m_pSyntax->GetPos(); |
1485 while (1) { | 1485 while (1) { |
1486 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); | 1486 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); |
1487 FX_BOOL bProcessed = TRUE; | 1487 bool bProcessed = true; |
1488 switch (type) { | 1488 switch (type) { |
1489 case CPDF_StreamParser::EndOfData: | 1489 case CPDF_StreamParser::EndOfData: |
1490 return; | 1490 return; |
1491 case CPDF_StreamParser::Keyword: { | 1491 case CPDF_StreamParser::Keyword: { |
1492 int len = m_pSyntax->GetWordSize(); | 1492 int len = m_pSyntax->GetWordSize(); |
1493 if (len == 1) { | 1493 if (len == 1) { |
1494 switch (m_pSyntax->GetWordBuf()[0]) { | 1494 switch (m_pSyntax->GetWordBuf()[0]) { |
1495 case kPathOperatorSubpath: | 1495 case kPathOperatorSubpath: |
1496 AddPathPoint(params[0], params[1], FXPT_MOVETO); | 1496 AddPathPoint(params[0], params[1], FXPT_MOVETO); |
1497 nParams = 0; | 1497 nParams = 0; |
(...skipping 18 matching lines...) Expand all Loading... |
1516 AddPathPoint(params[0], params[1], FXPT_BEZIERTO); | 1516 AddPathPoint(params[0], params[1], FXPT_BEZIERTO); |
1517 AddPathPoint(params[2], params[3], FXPT_BEZIERTO); | 1517 AddPathPoint(params[2], params[3], FXPT_BEZIERTO); |
1518 AddPathPoint(params[2], params[3], FXPT_BEZIERTO); | 1518 AddPathPoint(params[2], params[3], FXPT_BEZIERTO); |
1519 nParams = 0; | 1519 nParams = 0; |
1520 break; | 1520 break; |
1521 case kPathOperatorClosePath: | 1521 case kPathOperatorClosePath: |
1522 Handle_ClosePath(); | 1522 Handle_ClosePath(); |
1523 nParams = 0; | 1523 nParams = 0; |
1524 break; | 1524 break; |
1525 default: | 1525 default: |
1526 bProcessed = FALSE; | 1526 bProcessed = false; |
1527 break; | 1527 break; |
1528 } | 1528 } |
1529 } else if (len == 2) { | 1529 } else if (len == 2) { |
1530 if (m_pSyntax->GetWordBuf()[0] == kPathOperatorRectangle[0] && | 1530 if (m_pSyntax->GetWordBuf()[0] == kPathOperatorRectangle[0] && |
1531 m_pSyntax->GetWordBuf()[1] == kPathOperatorRectangle[1]) { | 1531 m_pSyntax->GetWordBuf()[1] == kPathOperatorRectangle[1]) { |
1532 AddPathRect(params[0], params[1], params[2], params[3]); | 1532 AddPathRect(params[0], params[1], params[2], params[3]); |
1533 nParams = 0; | 1533 nParams = 0; |
1534 } else { | 1534 } else { |
1535 bProcessed = FALSE; | 1535 bProcessed = false; |
1536 } | 1536 } |
1537 } else { | 1537 } else { |
1538 bProcessed = FALSE; | 1538 bProcessed = false; |
1539 } | 1539 } |
1540 if (bProcessed) { | 1540 if (bProcessed) { |
1541 last_pos = m_pSyntax->GetPos(); | 1541 last_pos = m_pSyntax->GetPos(); |
1542 } | 1542 } |
1543 break; | 1543 break; |
1544 } | 1544 } |
1545 case CPDF_StreamParser::Number: { | 1545 case CPDF_StreamParser::Number: { |
1546 if (nParams == 6) | 1546 if (nParams == 6) |
1547 break; | 1547 break; |
1548 | 1548 |
1549 int value; | 1549 int value; |
1550 bool bInteger = FX_atonum( | 1550 bool bInteger = FX_atonum( |
1551 CFX_ByteStringC(m_pSyntax->GetWordBuf(), m_pSyntax->GetWordSize()), | 1551 CFX_ByteStringC(m_pSyntax->GetWordBuf(), m_pSyntax->GetWordSize()), |
1552 &value); | 1552 &value); |
1553 params[nParams++] = bInteger ? (FX_FLOAT)value : *(FX_FLOAT*)&value; | 1553 params[nParams++] = bInteger ? (FX_FLOAT)value : *(FX_FLOAT*)&value; |
1554 break; | 1554 break; |
1555 } | 1555 } |
1556 default: | 1556 default: |
1557 bProcessed = FALSE; | 1557 bProcessed = false; |
1558 } | 1558 } |
1559 if (!bProcessed) { | 1559 if (!bProcessed) { |
1560 m_pSyntax->SetPos(last_pos); | 1560 m_pSyntax->SetPos(last_pos); |
1561 return; | 1561 return; |
1562 } | 1562 } |
1563 } | 1563 } |
1564 } | 1564 } |
OLD | NEW |