| 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_PageObjectList* pPageObjs, | 412 static void AddRectToPageObjects(CPDF_PageObjectHolder* pPageObjs, |
| 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 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 | 428 pPageObjs->GetPageObjectList()->InsertObject( |
| 429 pPageObjs->InsertObject(pPageObjs->GetLastObjectPosition(), pPathObj); | 429 pPageObjs->GetPageObjectList()->GetTailPosition(), pPathObj); |
| 430 } | 430 } |
| 431 | 431 |
| 432 static CPDF_TextObject* AddTextObjToPageObjects(CPDF_PageObjectList* pPageObjs, | 432 static CPDF_TextObject* AddTextObjToPageObjects( |
| 433 FX_COLORREF crText, | 433 CPDF_PageObjectHolder* pPageObjs, |
| 434 CPDF_Font* pFont, | 434 FX_COLORREF crText, |
| 435 FX_FLOAT fFontSize, | 435 CPDF_Font* pFont, |
| 436 FX_FLOAT fCharSpace, | 436 FX_FLOAT fFontSize, |
| 437 int32_t nHorzScale, | 437 FX_FLOAT fCharSpace, |
| 438 const CPDF_Point& point, | 438 int32_t nHorzScale, |
| 439 const CFX_ByteString& text) { | 439 const CPDF_Point& point, |
| 440 const CFX_ByteString& text) { |
| 440 CPDF_TextObject* pTxtObj = new CPDF_TextObject; | 441 CPDF_TextObject* pTxtObj = new CPDF_TextObject; |
| 441 | 442 |
| 442 CPDF_TextStateData* pTextStateData = pTxtObj->m_TextState.GetModify(); | 443 CPDF_TextStateData* pTextStateData = pTxtObj->m_TextState.GetModify(); |
| 443 pTextStateData->m_pFont = pFont; | 444 pTextStateData->m_pFont = pFont; |
| 444 pTextStateData->m_FontSize = fFontSize; | 445 pTextStateData->m_FontSize = fFontSize; |
| 445 pTextStateData->m_CharSpace = fCharSpace; | 446 pTextStateData->m_CharSpace = fCharSpace; |
| 446 pTextStateData->m_WordSpace = 0; | 447 pTextStateData->m_WordSpace = 0; |
| 447 pTextStateData->m_TextMode = 0; | 448 pTextStateData->m_TextMode = 0; |
| 448 pTextStateData->m_Matrix[0] = nHorzScale / 100.0f; | 449 pTextStateData->m_Matrix[0] = nHorzScale / 100.0f; |
| 449 pTextStateData->m_Matrix[1] = 0; | 450 pTextStateData->m_Matrix[1] = 0; |
| 450 pTextStateData->m_Matrix[2] = 0; | 451 pTextStateData->m_Matrix[2] = 0; |
| 451 pTextStateData->m_Matrix[3] = 1; | 452 pTextStateData->m_Matrix[3] = 1; |
| 452 | 453 |
| 453 FX_FLOAT rgb[3]; | 454 FX_FLOAT rgb[3]; |
| 454 rgb[0] = FXARGB_R(crText) / 255.0f; | 455 rgb[0] = FXARGB_R(crText) / 255.0f; |
| 455 rgb[1] = FXARGB_G(crText) / 255.0f; | 456 rgb[1] = FXARGB_G(crText) / 255.0f; |
| 456 rgb[2] = FXARGB_B(crText) / 255.0f; | 457 rgb[2] = FXARGB_B(crText) / 255.0f; |
| 457 pTxtObj->m_ColorState.SetFillColor( | 458 pTxtObj->m_ColorState.SetFillColor( |
| 458 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); | 459 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); |
| 459 pTxtObj->m_ColorState.SetStrokeColor( | 460 pTxtObj->m_ColorState.SetStrokeColor( |
| 460 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); | 461 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); |
| 461 | 462 |
| 462 pTxtObj->SetPosition(point.x, point.y); | 463 pTxtObj->SetPosition(point.x, point.y); |
| 463 pTxtObj->SetText(text); | 464 pTxtObj->SetText(text); |
| 464 | 465 pPageObjs->GetPageObjectList()->InsertObject( |
| 465 pPageObjs->InsertObject(pPageObjs->GetLastObjectPosition(), pTxtObj); | 466 pPageObjs->GetPageObjectList()->GetTailPosition(), pTxtObj); |
| 466 | 467 |
| 467 return pTxtObj; | 468 return pTxtObj; |
| 468 } | 469 } |
| 469 | 470 |
| 470 void IFX_Edit::GeneratePageObjects( | 471 void IFX_Edit::GeneratePageObjects( |
| 471 CPDF_PageObjectList* pPageObjects, | 472 CPDF_PageObjectHolder* pPageObjects, |
| 472 IFX_Edit* pEdit, | 473 IFX_Edit* pEdit, |
| 473 const CPDF_Point& ptOffset, | 474 const CPDF_Point& ptOffset, |
| 474 const CPVT_WordRange* pRange, | 475 const CPVT_WordRange* pRange, |
| 475 FX_COLORREF crText, | 476 FX_COLORREF crText, |
| 476 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { | 477 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { |
| 477 FX_FLOAT fFontSize = pEdit->GetFontSize(); | 478 FX_FLOAT fFontSize = pEdit->GetFontSize(); |
| 478 | 479 |
| 479 int32_t nOldFontIndex = -1; | 480 int32_t nOldFontIndex = -1; |
| 480 | 481 |
| 481 CFX_ByteTextBuf sTextBuf; | 482 CFX_ByteTextBuf sTextBuf; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 pPageObjects, crText, pFontMap->GetPDFFont(nOldFontIndex), | 526 pPageObjects, crText, pFontMap->GetPDFFont(nOldFontIndex), |
| 526 fFontSize, 0.0f, 100, | 527 fFontSize, 0.0f, 100, |
| 527 CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | 528 CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 528 sTextBuf.GetByteString())); | 529 sTextBuf.GetByteString())); |
| 529 } | 530 } |
| 530 } | 531 } |
| 531 } | 532 } |
| 532 } | 533 } |
| 533 | 534 |
| 534 void IFX_Edit::GenerateRichPageObjects( | 535 void IFX_Edit::GenerateRichPageObjects( |
| 535 CPDF_PageObjectList* pPageObjects, | 536 CPDF_PageObjectHolder* pPageObjects, |
| 536 IFX_Edit* pEdit, | 537 IFX_Edit* pEdit, |
| 537 const CPDF_Point& ptOffset, | 538 const CPDF_Point& ptOffset, |
| 538 const CPVT_WordRange* pRange, | 539 const CPVT_WordRange* pRange, |
| 539 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { | 540 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { |
| 540 FX_COLORREF crCurText = ArgbEncode(255, 0, 0, 0); | 541 FX_COLORREF crCurText = ArgbEncode(255, 0, 0, 0); |
| 541 FX_COLORREF crOld = crCurText; | 542 FX_COLORREF crOld = crCurText; |
| 542 | 543 |
| 543 CFX_ByteTextBuf sTextBuf; | 544 CFX_ByteTextBuf sTextBuf; |
| 544 CPVT_WordProps wp; | 545 CPVT_WordProps wp; |
| 545 CPDF_Point ptBT(0.0f, 0.0f); | 546 CPDF_Point ptBT(0.0f, 0.0f); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 ObjArray.Add(AddTextObjToPageObjects( | 618 ObjArray.Add(AddTextObjToPageObjects( |
| 618 pPageObjects, crOld, pFontMap->GetPDFFont(wp.nFontIndex), | 619 pPageObjects, crOld, pFontMap->GetPDFFont(wp.nFontIndex), |
| 619 wp.fFontSize, wp.fCharSpace, wp.nHorzScale, | 620 wp.fFontSize, wp.fCharSpace, wp.nHorzScale, |
| 620 CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | 621 CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 621 sTextBuf.GetByteString())); | 622 sTextBuf.GetByteString())); |
| 622 } | 623 } |
| 623 } | 624 } |
| 624 } | 625 } |
| 625 } | 626 } |
| 626 | 627 |
| 627 void IFX_Edit::GenerateUnderlineObjects(CPDF_PageObjectList* pPageObjects, | 628 void IFX_Edit::GenerateUnderlineObjects(CPDF_PageObjectHolder* pPageObjects, |
| 628 IFX_Edit* pEdit, | 629 IFX_Edit* pEdit, |
| 629 const CPDF_Point& ptOffset, | 630 const CPDF_Point& ptOffset, |
| 630 const CPVT_WordRange* pRange, | 631 const CPVT_WordRange* pRange, |
| 631 FX_COLORREF color) { | 632 FX_COLORREF color) { |
| 632 if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) { | 633 if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) { |
| 633 if (pEdit->GetFontMap()) { | 634 if (pEdit->GetFontMap()) { |
| 634 if (pRange) | 635 if (pRange) |
| 635 pIterator->SetAt(pRange->BeginPos); | 636 pIterator->SetAt(pRange->BeginPos); |
| 636 else | 637 else |
| 637 pIterator->SetAt(0); | 638 pIterator->SetAt(0); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 649 rcUnderline.left += ptOffset.x; | 650 rcUnderline.left += ptOffset.x; |
| 650 rcUnderline.right += ptOffset.x; | 651 rcUnderline.right += ptOffset.x; |
| 651 rcUnderline.top += ptOffset.y; | 652 rcUnderline.top += ptOffset.y; |
| 652 rcUnderline.bottom += ptOffset.y; | 653 rcUnderline.bottom += ptOffset.y; |
| 653 AddRectToPageObjects(pPageObjects, color, rcUnderline); | 654 AddRectToPageObjects(pPageObjects, color, rcUnderline); |
| 654 } | 655 } |
| 655 } | 656 } |
| 656 } | 657 } |
| 657 } | 658 } |
| 658 } | 659 } |
| OLD | NEW |