| 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/include/fpdfapi/fpdf_pageobj.h" | 7 #include "core/include/fpdfapi/fpdf_pageobj.h" |
| 8 #include "core/include/fpdfapi/fpdf_render.h" | 8 #include "core/include/fpdfapi/fpdf_render.h" |
| 9 #include "fpdfsdk/include/fx_systemhandler.h" | 9 #include "fpdfsdk/include/fx_systemhandler.h" |
| 10 #include "fpdfsdk/include/fxedit/fx_edit.h" | 10 #include "fpdfsdk/include/fxedit/fx_edit.h" |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 pDevice, CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | 402 pDevice, CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 403 pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, pUser2Device, | 403 pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, pUser2Device, |
| 404 sTextBuf.GetByteString(), crOld, 0, wp.nHorzScale); | 404 sTextBuf.GetByteString(), crOld, 0, wp.nHorzScale); |
| 405 } | 405 } |
| 406 } | 406 } |
| 407 } | 407 } |
| 408 | 408 |
| 409 pDevice->RestoreState(); | 409 pDevice->RestoreState(); |
| 410 } | 410 } |
| 411 | 411 |
| 412 static void AddRectToPageObjects(CPDF_PageObjectHolder* pPageObjs, | 412 static void AddRectToPageObjects(CPDF_PageObjectHolder* pObjectHolder, |
| 413 FX_COLORREF crFill, | 413 FX_COLORREF crFill, |
| 414 const CPDF_Rect& rcFill) { | 414 const CPDF_Rect& rcFill) { |
| 415 CPDF_PathObject* pPathObj = new CPDF_PathObject; | 415 std::unique_ptr<CPDF_PathObject> pPathObj(new CPDF_PathObject); |
| 416 CPDF_PathData* pPathData = pPathObj->m_Path.GetModify(); | 416 CPDF_PathData* pPathData = pPathObj->m_Path.GetModify(); |
| 417 pPathData->AppendRect(rcFill.left, rcFill.bottom, rcFill.right, rcFill.top); | 417 pPathData->AppendRect(rcFill.left, rcFill.bottom, rcFill.right, rcFill.top); |
| 418 | 418 |
| 419 FX_FLOAT rgb[3]; | 419 FX_FLOAT rgb[3]; |
| 420 rgb[0] = FXARGB_R(crFill) / 255.0f; | 420 rgb[0] = FXARGB_R(crFill) / 255.0f; |
| 421 rgb[1] = FXARGB_G(crFill) / 255.0f; | 421 rgb[1] = FXARGB_G(crFill) / 255.0f; |
| 422 rgb[2] = FXARGB_B(crFill) / 255.0f; | 422 rgb[2] = FXARGB_B(crFill) / 255.0f; |
| 423 pPathObj->m_ColorState.SetFillColor( | 423 pPathObj->m_ColorState.SetFillColor( |
| 424 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); | 424 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); |
| 425 | 425 |
| 426 pPathObj->m_FillType = FXFILL_ALTERNATE; | 426 pPathObj->m_FillType = FXFILL_ALTERNATE; |
| 427 pPathObj->m_bStroke = FALSE; | 427 pPathObj->m_bStroke = FALSE; |
| 428 pPageObjs->GetPageObjectList()->InsertObject( | 428 pObjectHolder->GetPageObjectList()->push_back(std::move(pPathObj)); |
| 429 pPageObjs->GetPageObjectList()->GetTailPosition(), pPathObj); | |
| 430 } | 429 } |
| 431 | 430 |
| 432 static CPDF_TextObject* AddTextObjToPageObjects( | 431 static CPDF_TextObject* AddTextObjToPageObjects( |
| 433 CPDF_PageObjectHolder* pPageObjs, | 432 CPDF_PageObjectHolder* pObjectHolder, |
| 434 FX_COLORREF crText, | 433 FX_COLORREF crText, |
| 435 CPDF_Font* pFont, | 434 CPDF_Font* pFont, |
| 436 FX_FLOAT fFontSize, | 435 FX_FLOAT fFontSize, |
| 437 FX_FLOAT fCharSpace, | 436 FX_FLOAT fCharSpace, |
| 438 int32_t nHorzScale, | 437 int32_t nHorzScale, |
| 439 const CPDF_Point& point, | 438 const CPDF_Point& point, |
| 440 const CFX_ByteString& text) { | 439 const CFX_ByteString& text) { |
| 441 CPDF_TextObject* pTxtObj = new CPDF_TextObject; | 440 std::unique_ptr<CPDF_TextObject> pTxtObj(new CPDF_TextObject); |
| 442 | |
| 443 CPDF_TextStateData* pTextStateData = pTxtObj->m_TextState.GetModify(); | 441 CPDF_TextStateData* pTextStateData = pTxtObj->m_TextState.GetModify(); |
| 444 pTextStateData->m_pFont = pFont; | 442 pTextStateData->m_pFont = pFont; |
| 445 pTextStateData->m_FontSize = fFontSize; | 443 pTextStateData->m_FontSize = fFontSize; |
| 446 pTextStateData->m_CharSpace = fCharSpace; | 444 pTextStateData->m_CharSpace = fCharSpace; |
| 447 pTextStateData->m_WordSpace = 0; | 445 pTextStateData->m_WordSpace = 0; |
| 448 pTextStateData->m_TextMode = 0; | 446 pTextStateData->m_TextMode = 0; |
| 449 pTextStateData->m_Matrix[0] = nHorzScale / 100.0f; | 447 pTextStateData->m_Matrix[0] = nHorzScale / 100.0f; |
| 450 pTextStateData->m_Matrix[1] = 0; | 448 pTextStateData->m_Matrix[1] = 0; |
| 451 pTextStateData->m_Matrix[2] = 0; | 449 pTextStateData->m_Matrix[2] = 0; |
| 452 pTextStateData->m_Matrix[3] = 1; | 450 pTextStateData->m_Matrix[3] = 1; |
| 453 | 451 |
| 454 FX_FLOAT rgb[3]; | 452 FX_FLOAT rgb[3]; |
| 455 rgb[0] = FXARGB_R(crText) / 255.0f; | 453 rgb[0] = FXARGB_R(crText) / 255.0f; |
| 456 rgb[1] = FXARGB_G(crText) / 255.0f; | 454 rgb[1] = FXARGB_G(crText) / 255.0f; |
| 457 rgb[2] = FXARGB_B(crText) / 255.0f; | 455 rgb[2] = FXARGB_B(crText) / 255.0f; |
| 458 pTxtObj->m_ColorState.SetFillColor( | 456 pTxtObj->m_ColorState.SetFillColor( |
| 459 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); | 457 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); |
| 460 pTxtObj->m_ColorState.SetStrokeColor( | 458 pTxtObj->m_ColorState.SetStrokeColor( |
| 461 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); | 459 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); |
| 462 | 460 |
| 463 pTxtObj->SetPosition(point.x, point.y); | 461 pTxtObj->SetPosition(point.x, point.y); |
| 464 pTxtObj->SetText(text); | 462 pTxtObj->SetText(text); |
| 465 pPageObjs->GetPageObjectList()->InsertObject( | |
| 466 pPageObjs->GetPageObjectList()->GetTailPosition(), pTxtObj); | |
| 467 | 463 |
| 468 return pTxtObj; | 464 CPDF_TextObject* pRet = pTxtObj.get(); |
| 465 pObjectHolder->GetPageObjectList()->push_back(std::move(pTxtObj)); |
| 466 return pRet; |
| 469 } | 467 } |
| 470 | 468 |
| 471 void IFX_Edit::GeneratePageObjects( | 469 void IFX_Edit::GeneratePageObjects( |
| 472 CPDF_PageObjectHolder* pPageObjects, | 470 CPDF_PageObjectHolder* pObjectHolder, |
| 473 IFX_Edit* pEdit, | 471 IFX_Edit* pEdit, |
| 474 const CPDF_Point& ptOffset, | 472 const CPDF_Point& ptOffset, |
| 475 const CPVT_WordRange* pRange, | 473 const CPVT_WordRange* pRange, |
| 476 FX_COLORREF crText, | 474 FX_COLORREF crText, |
| 477 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { | 475 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { |
| 478 FX_FLOAT fFontSize = pEdit->GetFontSize(); | 476 FX_FLOAT fFontSize = pEdit->GetFontSize(); |
| 479 | 477 |
| 480 int32_t nOldFontIndex = -1; | 478 int32_t nOldFontIndex = -1; |
| 481 | 479 |
| 482 CFX_ByteTextBuf sTextBuf; | 480 CFX_ByteTextBuf sTextBuf; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 497 CPVT_WordPlace place = pIterator->GetAt(); | 495 CPVT_WordPlace place = pIterator->GetAt(); |
| 498 if (pRange && place.WordCmp(pRange->EndPos) > 0) | 496 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 499 break; | 497 break; |
| 500 | 498 |
| 501 CPVT_Word word; | 499 CPVT_Word word; |
| 502 if (pIterator->GetWord(word)) { | 500 if (pIterator->GetWord(word)) { |
| 503 if (place.LineCmp(oldplace) != 0 || | 501 if (place.LineCmp(oldplace) != 0 || |
| 504 nOldFontIndex != word.nFontIndex) { | 502 nOldFontIndex != word.nFontIndex) { |
| 505 if (sTextBuf.GetLength() > 0) { | 503 if (sTextBuf.GetLength() > 0) { |
| 506 ObjArray.Add(AddTextObjToPageObjects( | 504 ObjArray.Add(AddTextObjToPageObjects( |
| 507 pPageObjects, crText, pFontMap->GetPDFFont(nOldFontIndex), | 505 pObjectHolder, crText, pFontMap->GetPDFFont(nOldFontIndex), |
| 508 fFontSize, 0.0f, 100, | 506 fFontSize, 0.0f, 100, |
| 509 CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | 507 CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 510 sTextBuf.GetByteString())); | 508 sTextBuf.GetByteString())); |
| 511 | 509 |
| 512 sTextBuf.Clear(); | 510 sTextBuf.Clear(); |
| 513 } | 511 } |
| 514 | 512 |
| 515 ptBT = word.ptWord; | 513 ptBT = word.ptWord; |
| 516 nOldFontIndex = word.nFontIndex; | 514 nOldFontIndex = word.nFontIndex; |
| 517 } | 515 } |
| 518 | 516 |
| 519 sTextBuf << GetPDFWordString(pFontMap, word.nFontIndex, word.Word, 0); | 517 sTextBuf << GetPDFWordString(pFontMap, word.nFontIndex, word.Word, 0); |
| 520 oldplace = place; | 518 oldplace = place; |
| 521 } | 519 } |
| 522 } | 520 } |
| 523 | 521 |
| 524 if (sTextBuf.GetLength() > 0) { | 522 if (sTextBuf.GetLength() > 0) { |
| 525 ObjArray.Add(AddTextObjToPageObjects( | 523 ObjArray.Add(AddTextObjToPageObjects( |
| 526 pPageObjects, crText, pFontMap->GetPDFFont(nOldFontIndex), | 524 pObjectHolder, crText, pFontMap->GetPDFFont(nOldFontIndex), |
| 527 fFontSize, 0.0f, 100, | 525 fFontSize, 0.0f, 100, |
| 528 CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | 526 CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 529 sTextBuf.GetByteString())); | 527 sTextBuf.GetByteString())); |
| 530 } | 528 } |
| 531 } | 529 } |
| 532 } | 530 } |
| 533 } | 531 } |
| 534 | 532 |
| 535 void IFX_Edit::GenerateRichPageObjects( | 533 void IFX_Edit::GenerateRichPageObjects( |
| 536 CPDF_PageObjectHolder* pPageObjects, | 534 CPDF_PageObjectHolder* pObjectHolder, |
| 537 IFX_Edit* pEdit, | 535 IFX_Edit* pEdit, |
| 538 const CPDF_Point& ptOffset, | 536 const CPDF_Point& ptOffset, |
| 539 const CPVT_WordRange* pRange, | 537 const CPVT_WordRange* pRange, |
| 540 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { | 538 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { |
| 541 FX_COLORREF crCurText = ArgbEncode(255, 0, 0, 0); | 539 FX_COLORREF crCurText = ArgbEncode(255, 0, 0, 0); |
| 542 FX_COLORREF crOld = crCurText; | 540 FX_COLORREF crOld = crCurText; |
| 543 | 541 |
| 544 CFX_ByteTextBuf sTextBuf; | 542 CFX_ByteTextBuf sTextBuf; |
| 545 CPVT_WordProps wp; | 543 CPVT_WordProps wp; |
| 546 CPDF_Point ptBT(0.0f, 0.0f); | 544 CPDF_Point ptBT(0.0f, 0.0f); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 567 | 565 |
| 568 crCurText = ArgbEncode(255, word.WordProps.dwWordColor); | 566 crCurText = ArgbEncode(255, word.WordProps.dwWordColor); |
| 569 | 567 |
| 570 if (place.LineCmp(oldplace) != 0 || | 568 if (place.LineCmp(oldplace) != 0 || |
| 571 word.WordProps.fCharSpace > 0.0f || | 569 word.WordProps.fCharSpace > 0.0f || |
| 572 word.WordProps.nHorzScale != 100 || | 570 word.WordProps.nHorzScale != 100 || |
| 573 FXSYS_memcmp(&word.WordProps, &wp, sizeof(CPVT_WordProps)) != 0 || | 571 FXSYS_memcmp(&word.WordProps, &wp, sizeof(CPVT_WordProps)) != 0 || |
| 574 crOld != crCurText) { | 572 crOld != crCurText) { |
| 575 if (sTextBuf.GetLength() > 0) { | 573 if (sTextBuf.GetLength() > 0) { |
| 576 ObjArray.Add(AddTextObjToPageObjects( | 574 ObjArray.Add(AddTextObjToPageObjects( |
| 577 pPageObjects, crOld, pFontMap->GetPDFFont(wp.nFontIndex), | 575 pObjectHolder, crOld, pFontMap->GetPDFFont(wp.nFontIndex), |
| 578 wp.fFontSize, wp.fCharSpace, wp.nHorzScale, | 576 wp.fFontSize, wp.fCharSpace, wp.nHorzScale, |
| 579 CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | 577 CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 580 sTextBuf.GetByteString())); | 578 sTextBuf.GetByteString())); |
| 581 | 579 |
| 582 sTextBuf.Clear(); | 580 sTextBuf.Clear(); |
| 583 } | 581 } |
| 584 | 582 |
| 585 wp = word.WordProps; | 583 wp = word.WordProps; |
| 586 ptBT = word.ptWord; | 584 ptBT = word.ptWord; |
| 587 crOld = crCurText; | 585 crOld = crCurText; |
| 588 } | 586 } |
| 589 | 587 |
| 590 sTextBuf << GetPDFWordString(pFontMap, word.WordProps.nFontIndex, | 588 sTextBuf << GetPDFWordString(pFontMap, word.WordProps.nFontIndex, |
| 591 word.Word, 0); | 589 word.Word, 0); |
| 592 | 590 |
| 593 if (word.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) { | 591 if (word.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) { |
| 594 CPDF_Rect rcUnderline = GetUnderLineRect(word); | 592 CPDF_Rect rcUnderline = GetUnderLineRect(word); |
| 595 rcUnderline.left += ptOffset.x; | 593 rcUnderline.left += ptOffset.x; |
| 596 rcUnderline.right += ptOffset.x; | 594 rcUnderline.right += ptOffset.x; |
| 597 rcUnderline.top += ptOffset.y; | 595 rcUnderline.top += ptOffset.y; |
| 598 rcUnderline.bottom += ptOffset.y; | 596 rcUnderline.bottom += ptOffset.y; |
| 599 | 597 |
| 600 AddRectToPageObjects(pPageObjects, crCurText, rcUnderline); | 598 AddRectToPageObjects(pObjectHolder, crCurText, rcUnderline); |
| 601 } | 599 } |
| 602 | 600 |
| 603 if (word.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) { | 601 if (word.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) { |
| 604 CPDF_Rect rcCrossout = GetCrossoutRect(word); | 602 CPDF_Rect rcCrossout = GetCrossoutRect(word); |
| 605 rcCrossout.left += ptOffset.x; | 603 rcCrossout.left += ptOffset.x; |
| 606 rcCrossout.right += ptOffset.x; | 604 rcCrossout.right += ptOffset.x; |
| 607 rcCrossout.top += ptOffset.y; | 605 rcCrossout.top += ptOffset.y; |
| 608 rcCrossout.bottom += ptOffset.y; | 606 rcCrossout.bottom += ptOffset.y; |
| 609 | 607 |
| 610 AddRectToPageObjects(pPageObjects, crCurText, rcCrossout); | 608 AddRectToPageObjects(pObjectHolder, crCurText, rcCrossout); |
| 611 } | 609 } |
| 612 | 610 |
| 613 oldplace = place; | 611 oldplace = place; |
| 614 } | 612 } |
| 615 } | 613 } |
| 616 | 614 |
| 617 if (sTextBuf.GetLength() > 0) { | 615 if (sTextBuf.GetLength() > 0) { |
| 618 ObjArray.Add(AddTextObjToPageObjects( | 616 ObjArray.Add(AddTextObjToPageObjects( |
| 619 pPageObjects, crOld, pFontMap->GetPDFFont(wp.nFontIndex), | 617 pObjectHolder, crOld, pFontMap->GetPDFFont(wp.nFontIndex), |
| 620 wp.fFontSize, wp.fCharSpace, wp.nHorzScale, | 618 wp.fFontSize, wp.fCharSpace, wp.nHorzScale, |
| 621 CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | 619 CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 622 sTextBuf.GetByteString())); | 620 sTextBuf.GetByteString())); |
| 623 } | 621 } |
| 624 } | 622 } |
| 625 } | 623 } |
| 626 } | 624 } |
| 627 | 625 |
| 628 void IFX_Edit::GenerateUnderlineObjects(CPDF_PageObjectHolder* pPageObjects, | 626 void IFX_Edit::GenerateUnderlineObjects(CPDF_PageObjectHolder* pObjectHolder, |
| 629 IFX_Edit* pEdit, | 627 IFX_Edit* pEdit, |
| 630 const CPDF_Point& ptOffset, | 628 const CPDF_Point& ptOffset, |
| 631 const CPVT_WordRange* pRange, | 629 const CPVT_WordRange* pRange, |
| 632 FX_COLORREF color) { | 630 FX_COLORREF color) { |
| 633 if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) { | 631 if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) { |
| 634 if (pEdit->GetFontMap()) { | 632 if (pEdit->GetFontMap()) { |
| 635 if (pRange) | 633 if (pRange) |
| 636 pIterator->SetAt(pRange->BeginPos); | 634 pIterator->SetAt(pRange->BeginPos); |
| 637 else | 635 else |
| 638 pIterator->SetAt(0); | 636 pIterator->SetAt(0); |
| 639 | 637 |
| 640 CPVT_WordPlace oldplace; | 638 CPVT_WordPlace oldplace; |
| 641 | 639 |
| 642 while (pIterator->NextWord()) { | 640 while (pIterator->NextWord()) { |
| 643 CPVT_WordPlace place = pIterator->GetAt(); | 641 CPVT_WordPlace place = pIterator->GetAt(); |
| 644 if (pRange && place.WordCmp(pRange->EndPos) > 0) | 642 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 645 break; | 643 break; |
| 646 | 644 |
| 647 CPVT_Word word; | 645 CPVT_Word word; |
| 648 if (pIterator->GetWord(word)) { | 646 if (pIterator->GetWord(word)) { |
| 649 CPDF_Rect rcUnderline = GetUnderLineRect(word); | 647 CPDF_Rect rcUnderline = GetUnderLineRect(word); |
| 650 rcUnderline.left += ptOffset.x; | 648 rcUnderline.left += ptOffset.x; |
| 651 rcUnderline.right += ptOffset.x; | 649 rcUnderline.right += ptOffset.x; |
| 652 rcUnderline.top += ptOffset.y; | 650 rcUnderline.top += ptOffset.y; |
| 653 rcUnderline.bottom += ptOffset.y; | 651 rcUnderline.bottom += ptOffset.y; |
| 654 AddRectToPageObjects(pPageObjects, color, rcUnderline); | 652 AddRectToPageObjects(pObjectHolder, color, rcUnderline); |
| 655 } | 653 } |
| 656 } | 654 } |
| 657 } | 655 } |
| 658 } | 656 } |
| 659 } | 657 } |
| OLD | NEW |