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 "xfa/fee/fde_txtedtpage.h" | 7 #include "xfa/fee/fde_txtedtpage.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 FXSYS_memset(&m_rtPageMargin, 0, sizeof(CFX_RectF)); | 136 FXSYS_memset(&m_rtPageMargin, 0, sizeof(CFX_RectF)); |
137 FXSYS_memset(&m_rtPageContents, 0, sizeof(CFX_RectF)); | 137 FXSYS_memset(&m_rtPageContents, 0, sizeof(CFX_RectF)); |
138 FXSYS_memset(&m_rtPageCanvas, 0, sizeof(CFX_RectF)); | 138 FXSYS_memset(&m_rtPageCanvas, 0, sizeof(CFX_RectF)); |
139 m_pEditEngine = (CFDE_TxtEdtEngine*)pEngine; | 139 m_pEditEngine = (CFDE_TxtEdtEngine*)pEngine; |
140 } | 140 } |
141 | 141 |
142 CFDE_TxtEdtPage::~CFDE_TxtEdtPage() { | 142 CFDE_TxtEdtPage::~CFDE_TxtEdtPage() { |
143 m_PieceMassArr.RemoveAll(TRUE); | 143 m_PieceMassArr.RemoveAll(TRUE); |
144 delete m_pTextSet; | 144 delete m_pTextSet; |
145 delete[] m_pCharWidth; | 145 delete[] m_pCharWidth; |
146 if (m_pIter) | |
147 m_pIter->Release(); | |
148 } | 146 } |
149 | 147 |
150 void CFDE_TxtEdtPage::Release() { | 148 void CFDE_TxtEdtPage::Release() { |
151 delete this; | 149 delete this; |
152 } | 150 } |
153 CFDE_TxtEdtEngine* CFDE_TxtEdtPage::GetEngine() const { | 151 CFDE_TxtEdtEngine* CFDE_TxtEdtPage::GetEngine() const { |
154 return m_pEditEngine; | 152 return m_pEditEngine; |
155 } | 153 } |
156 FDE_VISUALOBJTYPE CFDE_TxtEdtPage::GetType() { | 154 FDE_VISUALOBJTYPE CFDE_TxtEdtPage::GetType() { |
157 return FDE_VISUALOBJ_Text; | 155 return FDE_VISUALOBJ_Text; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 } | 348 } |
351 CFDE_TxtEdtBuf* pBuf = m_pEditEngine->GetTextBuf(); | 349 CFDE_TxtEdtBuf* pBuf = m_pEditEngine->GetTextBuf(); |
352 FX_BOOL bBefore; | 350 FX_BOOL bBefore; |
353 int32_t nIndex = GetCharIndex(fPoint, bBefore); | 351 int32_t nIndex = GetCharIndex(fPoint, bBefore); |
354 if (nIndex == m_pEditEngine->GetTextBufLength()) { | 352 if (nIndex == m_pEditEngine->GetTextBufLength()) { |
355 nIndex = m_pEditEngine->GetTextBufLength() - 1; | 353 nIndex = m_pEditEngine->GetTextBufLength() - 1; |
356 } | 354 } |
357 if (nIndex < 0) { | 355 if (nIndex < 0) { |
358 return -1; | 356 return -1; |
359 } | 357 } |
360 CFX_WordBreak* pIter = new CFX_WordBreak; | 358 std::unique_ptr<CFX_WordBreak> pIter(new CFX_WordBreak); |
361 pIter->Attach(new CFDE_TxtEdtBufIter((CFDE_TxtEdtBuf*)pBuf)); | 359 pIter->Attach(new CFDE_TxtEdtBufIter((CFDE_TxtEdtBuf*)pBuf)); |
362 pIter->SetAt(nIndex); | 360 pIter->SetAt(nIndex); |
363 nCount = pIter->GetWordLength(); | 361 nCount = pIter->GetWordLength(); |
364 int32_t nRet = pIter->GetWordPos(); | 362 return pIter->GetWordPos(); |
365 pIter->Release(); | |
366 return nRet; | |
367 } | 363 } |
368 FX_BOOL CFDE_TxtEdtPage::IsLoaded(const CFX_RectF* pClipBox) { | 364 FX_BOOL CFDE_TxtEdtPage::IsLoaded(const CFX_RectF* pClipBox) { |
369 return m_bLoaded; | 365 return m_bLoaded; |
370 } | 366 } |
371 int32_t CFDE_TxtEdtPage::LoadPage(const CFX_RectF* pClipBox, | 367 int32_t CFDE_TxtEdtPage::LoadPage(const CFX_RectF* pClipBox, |
372 IFX_Pause* pPause) { | 368 IFX_Pause* pPause) { |
373 if (m_nRefCount > 0) { | 369 if (m_nRefCount > 0) { |
374 m_nRefCount++; | 370 m_nRefCount++; |
375 return m_nRefCount; | 371 return m_nRefCount; |
376 } | 372 } |
377 CFDE_TxtEdtBuf* pBuf = m_pEditEngine->GetTextBuf(); | 373 CFDE_TxtEdtBuf* pBuf = m_pEditEngine->GetTextBuf(); |
378 const FDE_TXTEDTPARAMS* pParams = m_pEditEngine->GetEditParams(); | 374 const FDE_TXTEDTPARAMS* pParams = m_pEditEngine->GetEditParams(); |
379 if (m_pIter != NULL) { | |
380 m_pIter->Release(); | |
381 } | |
382 FX_WCHAR wcAlias = 0; | 375 FX_WCHAR wcAlias = 0; |
383 if (pParams->dwMode & FDE_TEXTEDITMODE_Password) { | 376 if (pParams->dwMode & FDE_TEXTEDITMODE_Password) { |
384 wcAlias = m_pEditEngine->GetAliasChar(); | 377 wcAlias = m_pEditEngine->GetAliasChar(); |
385 } | 378 } |
386 m_pIter = new CFDE_TxtEdtBufIter((CFDE_TxtEdtBuf*)pBuf, wcAlias); | 379 m_pIter.reset( |
| 380 new CFDE_TxtEdtBufIter(static_cast<CFDE_TxtEdtBuf*>(pBuf), wcAlias)); |
387 CFX_TxtBreak* pBreak = m_pEditEngine->GetTextBreak(); | 381 CFX_TxtBreak* pBreak = m_pEditEngine->GetTextBreak(); |
388 pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | 382 pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); |
389 pBreak->ClearBreakPieces(); | 383 pBreak->ClearBreakPieces(); |
390 int32_t nPageLineCount = m_pEditEngine->GetPageLineCount(); | 384 int32_t nPageLineCount = m_pEditEngine->GetPageLineCount(); |
391 int32_t nStartLine = nPageLineCount * m_nPageIndex; | 385 int32_t nStartLine = nPageLineCount * m_nPageIndex; |
392 int32_t nEndLine = std::min((nStartLine + nPageLineCount - 1), | 386 int32_t nEndLine = std::min((nStartLine + nPageLineCount - 1), |
393 (m_pEditEngine->GetLineCount() - 1)); | 387 (m_pEditEngine->GetLineCount() - 1)); |
394 int32_t nPageStart, nPageEnd, nTemp, nBgnParag, nStartLineInParag, nEndParag, | 388 int32_t nPageStart, nPageEnd, nTemp, nBgnParag, nStartLineInParag, nEndParag, |
395 nEndLineInParag; | 389 nEndLineInParag; |
396 nBgnParag = m_pEditEngine->Line2Parag(0, 0, nStartLine, nStartLineInParag); | 390 nBgnParag = m_pEditEngine->Line2Parag(0, 0, nStartLine, nStartLineInParag); |
(...skipping 25 matching lines...) Expand all Loading... |
422 if (m_pCharWidth != NULL) { | 416 if (m_pCharWidth != NULL) { |
423 delete[] m_pCharWidth; | 417 delete[] m_pCharWidth; |
424 } | 418 } |
425 m_pCharWidth = new int32_t[nPageEnd - nPageStart + 1]; | 419 m_pCharWidth = new int32_t[nPageEnd - nPageStart + 1]; |
426 pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | 420 pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); |
427 pBreak->ClearBreakPieces(); | 421 pBreak->ClearBreakPieces(); |
428 m_nPageStart = nPageStart; | 422 m_nPageStart = nPageStart; |
429 m_nCharCount = nPageEnd - nPageStart + 1; | 423 m_nCharCount = nPageEnd - nPageStart + 1; |
430 FX_BOOL bReload = FALSE; | 424 FX_BOOL bReload = FALSE; |
431 FX_FLOAT fDefCharWidth = 0; | 425 FX_FLOAT fDefCharWidth = 0; |
432 IFX_CharIter* pIter = m_pIter->Clone(); | 426 std::unique_ptr<IFX_CharIter> pIter(m_pIter->Clone()); |
433 pIter->SetAt(nPageStart); | 427 pIter->SetAt(nPageStart); |
434 m_pIter->SetAt(nPageStart); | 428 m_pIter->SetAt(nPageStart); |
435 FX_BOOL bFirstPiece = TRUE; | 429 FX_BOOL bFirstPiece = TRUE; |
436 do { | 430 do { |
437 if (bReload) { | 431 if (bReload) { |
438 dwBreakStatus = pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | 432 dwBreakStatus = pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); |
439 } else { | 433 } else { |
440 FX_WCHAR wAppend = pIter->GetChar(); | 434 FX_WCHAR wAppend = pIter->GetChar(); |
441 dwBreakStatus = pBreak->AppendChar(wAppend); | 435 dwBreakStatus = pBreak->AppendChar(wAppend); |
442 } | 436 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 } | 530 } |
537 m_rtPageContents.Offset(-fOffset, 0.0f); | 531 m_rtPageContents.Offset(-fOffset, 0.0f); |
538 } | 532 } |
539 if (m_pEditEngine->GetEditParams()->dwLayoutStyles & | 533 if (m_pEditEngine->GetEditParams()->dwLayoutStyles & |
540 FDE_TEXTEDITLAYOUT_LastLineHeight) { | 534 FDE_TEXTEDITLAYOUT_LastLineHeight) { |
541 m_rtPageContents.height -= pParams->fLineSpace - pParams->fFontSize; | 535 m_rtPageContents.height -= pParams->fLineSpace - pParams->fFontSize; |
542 int32_t nCount = m_PieceMassArr.GetSize(); | 536 int32_t nCount = m_PieceMassArr.GetSize(); |
543 FDE_TEXTEDITPIECE* pPiece = m_PieceMassArr.GetPtrAt(nCount - 1); | 537 FDE_TEXTEDITPIECE* pPiece = m_PieceMassArr.GetPtrAt(nCount - 1); |
544 pPiece->rtPiece.height = pParams->fFontSize; | 538 pPiece->rtPiece.height = pParams->fFontSize; |
545 } | 539 } |
546 pIter->Release(); | |
547 m_nRefCount = 1; | 540 m_nRefCount = 1; |
548 m_bLoaded = TRUE; | 541 m_bLoaded = TRUE; |
549 return 0; | 542 return 0; |
550 } | 543 } |
551 | 544 |
552 void CFDE_TxtEdtPage::UnloadPage(const CFX_RectF* pClipBox) { | 545 void CFDE_TxtEdtPage::UnloadPage(const CFX_RectF* pClipBox) { |
553 ASSERT(m_nRefCount > 0); | 546 ASSERT(m_nRefCount > 0); |
554 m_nRefCount--; | 547 m_nRefCount--; |
555 if (m_nRefCount != 0) | 548 if (m_nRefCount != 0) |
556 return; | 549 return; |
557 | 550 |
558 m_PieceMassArr.RemoveAll(); | 551 m_PieceMassArr.RemoveAll(); |
559 delete m_pTextSet; | 552 delete m_pTextSet; |
560 m_pTextSet = nullptr; | 553 m_pTextSet = nullptr; |
561 delete[] m_pCharWidth; | 554 delete[] m_pCharWidth; |
562 m_pCharWidth = nullptr; | 555 m_pCharWidth = nullptr; |
563 if (m_pBgnParag) | 556 if (m_pBgnParag) { |
564 m_pBgnParag->UnloadParag(); | 557 m_pBgnParag->UnloadParag(); |
565 if (m_pEndParag) | 558 m_pBgnParag = nullptr; |
| 559 } |
| 560 if (m_pEndParag) { |
566 m_pEndParag->UnloadParag(); | 561 m_pEndParag->UnloadParag(); |
567 if (m_pIter) { | 562 m_pEndParag = nullptr; |
568 m_pIter->Release(); | |
569 m_pIter = nullptr; | |
570 } | 563 } |
571 m_pBgnParag = nullptr; | 564 m_pIter.reset(); |
572 m_pEndParag = nullptr; | |
573 } | 565 } |
574 | 566 |
575 const CFX_RectF& CFDE_TxtEdtPage::GetContentsBox() { | 567 const CFX_RectF& CFDE_TxtEdtPage::GetContentsBox() { |
576 return m_rtPageContents; | 568 return m_rtPageContents; |
577 } | 569 } |
578 FX_POSITION CFDE_TxtEdtPage::GetFirstPosition(FDE_HVISUALOBJ hCanvas) { | 570 FX_POSITION CFDE_TxtEdtPage::GetFirstPosition(FDE_HVISUALOBJ hCanvas) { |
579 if (m_PieceMassArr.GetSize() < 1) { | 571 if (m_PieceMassArr.GetSize() < 1) { |
580 return NULL; | 572 return NULL; |
581 } | 573 } |
582 return (FX_POSITION)1; | 574 return (FX_POSITION)1; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 ptF.x = rtF.left; | 618 ptF.x = rtF.left; |
627 } else if (ptF.x >= rtF.right()) { | 619 } else if (ptF.x >= rtF.right()) { |
628 ptF.x = rtF.right() - fTolerance; | 620 ptF.x = rtF.right() - fTolerance; |
629 } | 621 } |
630 if (ptF.y < rtF.top) { | 622 if (ptF.y < rtF.top) { |
631 ptF.y = rtF.top; | 623 ptF.y = rtF.top; |
632 } else if (ptF.y >= rtF.bottom()) { | 624 } else if (ptF.y >= rtF.bottom()) { |
633 ptF.y = rtF.bottom() - fTolerance; | 625 ptF.y = rtF.bottom() - fTolerance; |
634 } | 626 } |
635 } | 627 } |
OLD | NEW |