Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: xfa/fde/cfde_txtedtpage.cpp

Issue 2208423002: Use smart pointers for class owned pointers under xfa/fde (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: one more change Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fde/cfde_txtedtpage.h ('k') | xfa/fde/css/fde_cssstyleselector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/fde/cfde_txtedtpage.h" 7 #include "xfa/fde/cfde_txtedtpage.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 11 matching lines...) Expand all
22 const double kTolerance = 0.1f; 22 const double kTolerance = 0.1f;
23 23
24 } // namespace 24 } // namespace
25 25
26 IFDE_TxtEdtPage* IFDE_TxtEdtPage::Create(CFDE_TxtEdtEngine* pEngine, 26 IFDE_TxtEdtPage* IFDE_TxtEdtPage::Create(CFDE_TxtEdtEngine* pEngine,
27 int32_t nIndex) { 27 int32_t nIndex) {
28 return new CFDE_TxtEdtPage(pEngine, nIndex); 28 return new CFDE_TxtEdtPage(pEngine, nIndex);
29 } 29 }
30 30
31 CFDE_TxtEdtPage::CFDE_TxtEdtPage(CFDE_TxtEdtEngine* pEngine, int32_t nPageIndex) 31 CFDE_TxtEdtPage::CFDE_TxtEdtPage(CFDE_TxtEdtEngine* pEngine, int32_t nPageIndex)
32 : m_pTextSet(nullptr), 32 : m_pEditEngine(pEngine),
33 m_PieceMassArr(100), 33 m_PieceMassArr(100),
34 m_pBgnParag(nullptr), 34 m_pBgnParag(nullptr),
35 m_pEndParag(nullptr), 35 m_pEndParag(nullptr),
36 m_nRefCount(0), 36 m_nRefCount(0),
37 m_nPageStart(-1), 37 m_nPageStart(-1),
38 m_nCharCount(0), 38 m_nCharCount(0),
39 m_nPageIndex(nPageIndex), 39 m_nPageIndex(nPageIndex),
40 m_bLoaded(FALSE), 40 m_bLoaded(FALSE) {
41 m_pCharWidth(nullptr) {
42 FXSYS_memset(&m_rtPage, 0, sizeof(CFX_RectF)); 41 FXSYS_memset(&m_rtPage, 0, sizeof(CFX_RectF));
43 FXSYS_memset(&m_rtPageMargin, 0, sizeof(CFX_RectF)); 42 FXSYS_memset(&m_rtPageMargin, 0, sizeof(CFX_RectF));
44 FXSYS_memset(&m_rtPageContents, 0, sizeof(CFX_RectF)); 43 FXSYS_memset(&m_rtPageContents, 0, sizeof(CFX_RectF));
45 FXSYS_memset(&m_rtPageCanvas, 0, sizeof(CFX_RectF)); 44 FXSYS_memset(&m_rtPageCanvas, 0, sizeof(CFX_RectF));
46 m_pEditEngine = static_cast<CFDE_TxtEdtEngine*>(pEngine);
47 } 45 }
48 46
49 CFDE_TxtEdtPage::~CFDE_TxtEdtPage() { 47 CFDE_TxtEdtPage::~CFDE_TxtEdtPage() {
50 m_PieceMassArr.RemoveAll(TRUE); 48 m_PieceMassArr.RemoveAll(TRUE);
51 delete m_pTextSet;
52 delete[] m_pCharWidth;
53 } 49 }
54 50
55 CFDE_TxtEdtEngine* CFDE_TxtEdtPage::GetEngine() const { 51 CFDE_TxtEdtEngine* CFDE_TxtEdtPage::GetEngine() const {
56 return m_pEditEngine; 52 return m_pEditEngine;
57 } 53 }
58 54
59 FDE_VISUALOBJTYPE CFDE_TxtEdtPage::GetType() { 55 FDE_VISUALOBJTYPE CFDE_TxtEdtPage::GetType() {
60 return FDE_VISUALOBJ_Text; 56 return FDE_VISUALOBJ_Text;
61 } 57 }
62 58
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 FX_BOOL bLineReserve = 297 FX_BOOL bLineReserve =
302 pParams->dwLayoutStyles & FDE_TEXTEDITLAYOUT_LineReserve; 298 pParams->dwLayoutStyles & FDE_TEXTEDITLAYOUT_LineReserve;
303 FX_FLOAT fLineStart = 299 FX_FLOAT fLineStart =
304 bVertial 300 bVertial
305 ? (bLineReserve ? (pParams->fPlateWidth - pParams->fLineSpace) : 0.0f) 301 ? (bLineReserve ? (pParams->fPlateWidth - pParams->fLineSpace) : 0.0f)
306 : 0.0f; 302 : 0.0f;
307 FX_FLOAT fLineStep = 303 FX_FLOAT fLineStep =
308 (bVertial && bLineReserve) ? (-pParams->fLineSpace) : pParams->fLineSpace; 304 (bVertial && bLineReserve) ? (-pParams->fLineSpace) : pParams->fLineSpace;
309 FX_FLOAT fLinePos = fLineStart; 305 FX_FLOAT fLinePos = fLineStart;
310 if (!m_pTextSet) 306 if (!m_pTextSet)
311 m_pTextSet = new CFDE_TxtEdtTextSet(this); 307 m_pTextSet.reset(new CFDE_TxtEdtTextSet(this));
312 308
313 m_PieceMassArr.RemoveAll(TRUE); 309 m_PieceMassArr.RemoveAll(TRUE);
314 uint32_t dwBreakStatus = FX_TXTBREAK_None; 310 uint32_t dwBreakStatus = FX_TXTBREAK_None;
315 int32_t nPieceStart = 0; 311 int32_t nPieceStart = 0;
316 delete[] m_pCharWidth;
317 312
318 m_pCharWidth = new int32_t[nPageEnd - nPageStart + 1]; 313 m_CharWidths.resize(nPageEnd - nPageStart + 1, 0);
319 pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); 314 pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak);
320 pBreak->ClearBreakPieces(); 315 pBreak->ClearBreakPieces();
321 m_nPageStart = nPageStart; 316 m_nPageStart = nPageStart;
322 m_nCharCount = nPageEnd - nPageStart + 1; 317 m_nCharCount = nPageEnd - nPageStart + 1;
323 FX_BOOL bReload = FALSE; 318 FX_BOOL bReload = FALSE;
324 FX_FLOAT fDefCharWidth = 0; 319 FX_FLOAT fDefCharWidth = 0;
325 std::unique_ptr<IFX_CharIter> pIter(m_pIter->Clone()); 320 std::unique_ptr<IFX_CharIter> pIter(m_pIter->Clone());
326 pIter->SetAt(nPageStart); 321 pIter->SetAt(nPageStart);
327 m_pIter->SetAt(nPageStart); 322 m_pIter->SetAt(nPageStart);
328 FX_BOOL bFirstPiece = TRUE; 323 FX_BOOL bFirstPiece = TRUE;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 if (bFirstPiece) { 382 if (bFirstPiece) {
388 m_rtPageContents = TxtEdtPiece.rtPiece; 383 m_rtPageContents = TxtEdtPiece.rtPiece;
389 bFirstPiece = FALSE; 384 bFirstPiece = FALSE;
390 } else { 385 } else {
391 m_rtPageContents.Union(TxtEdtPiece.rtPiece); 386 m_rtPageContents.Union(TxtEdtPiece.rtPiece);
392 } 387 }
393 nPieceStart += TxtEdtPiece.nCount; 388 nPieceStart += TxtEdtPiece.nCount;
394 m_PieceMassArr.Add(TxtEdtPiece); 389 m_PieceMassArr.Add(TxtEdtPiece);
395 for (int32_t k = 0; k < TxtEdtPiece.nCount; k++) { 390 for (int32_t k = 0; k < TxtEdtPiece.nCount; k++) {
396 CFX_Char* ptc = pPiece->GetCharPtr(k); 391 CFX_Char* ptc = pPiece->GetCharPtr(k);
397 m_pCharWidth[TxtEdtPiece.nStart + k] = ptc->m_iCharWidth; 392 m_CharWidths[TxtEdtPiece.nStart + k] = ptc->m_iCharWidth;
398 } 393 }
399 } 394 }
400 fLinePos += fLineStep; 395 fLinePos += fLineStep;
401 pBreak->ClearBreakPieces(); 396 pBreak->ClearBreakPieces();
402 } 397 }
403 if (pIter->GetAt() == nPageEnd && dwBreakStatus == FX_TXTBREAK_LineBreak) { 398 if (pIter->GetAt() == nPageEnd && dwBreakStatus == FX_TXTBREAK_LineBreak) {
404 bReload = TRUE; 399 bReload = TRUE;
405 pIter->Next(TRUE); 400 pIter->Next(TRUE);
406 } 401 }
407 } while (pIter->Next(FALSE) && (pIter->GetAt() <= nPageEnd)); 402 } while (pIter->Next(FALSE) && (pIter->GetAt() <= nPageEnd));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 return 0; 436 return 0;
442 } 437 }
443 438
444 void CFDE_TxtEdtPage::UnloadPage(const CFX_RectF* pClipBox) { 439 void CFDE_TxtEdtPage::UnloadPage(const CFX_RectF* pClipBox) {
445 ASSERT(m_nRefCount > 0); 440 ASSERT(m_nRefCount > 0);
446 m_nRefCount--; 441 m_nRefCount--;
447 if (m_nRefCount != 0) 442 if (m_nRefCount != 0)
448 return; 443 return;
449 444
450 m_PieceMassArr.RemoveAll(FALSE); 445 m_PieceMassArr.RemoveAll(FALSE);
451 delete m_pTextSet; 446 m_pTextSet.reset();
452 m_pTextSet = nullptr; 447 m_CharWidths.clear();
453 delete[] m_pCharWidth;
454 m_pCharWidth = nullptr;
455 if (m_pBgnParag) { 448 if (m_pBgnParag) {
456 m_pBgnParag->UnloadParag(); 449 m_pBgnParag->UnloadParag();
457 m_pBgnParag = nullptr; 450 m_pBgnParag = nullptr;
458 } 451 }
459 if (m_pEndParag) { 452 if (m_pEndParag) {
460 m_pEndParag->UnloadParag(); 453 m_pEndParag->UnloadParag();
461 m_pEndParag = nullptr; 454 m_pEndParag = nullptr;
462 } 455 }
463 m_pIter.reset(); 456 m_pIter.reset();
464 } 457 }
465 458
466 const CFX_RectF& CFDE_TxtEdtPage::GetContentsBox() { 459 const CFX_RectF& CFDE_TxtEdtPage::GetContentsBox() {
467 return m_rtPageContents; 460 return m_rtPageContents;
468 } 461 }
469 462
470 FX_POSITION CFDE_TxtEdtPage::GetFirstPosition() { 463 FX_POSITION CFDE_TxtEdtPage::GetFirstPosition() {
471 if (m_PieceMassArr.GetSize() < 1) 464 if (m_PieceMassArr.GetSize() < 1)
472 return nullptr; 465 return nullptr;
473 return (FX_POSITION)1; 466 return (FX_POSITION)1;
474 } 467 }
475 468
476 FDE_TEXTEDITPIECE* CFDE_TxtEdtPage::GetNext(FX_POSITION& pos, 469 FDE_TEXTEDITPIECE* CFDE_TxtEdtPage::GetNext(FX_POSITION& pos,
477 IFDE_VisualSet*& pVisualSet) { 470 IFDE_VisualSet*& pVisualSet) {
478 if (!m_pTextSet) { 471 if (!m_pTextSet) {
479 pos = nullptr; 472 pos = nullptr;
480 return nullptr; 473 return nullptr;
481 } 474 }
482 int32_t nPos = (int32_t)(uintptr_t)pos; 475 int32_t nPos = (int32_t)(uintptr_t)pos;
483 pVisualSet = m_pTextSet; 476 pVisualSet = m_pTextSet.get();
484 if (nPos + 1 > m_PieceMassArr.GetSize()) { 477 if (nPos + 1 > m_PieceMassArr.GetSize()) {
485 pos = nullptr; 478 pos = nullptr;
486 } else { 479 } else {
487 pos = (FX_POSITION)(uintptr_t)(nPos + 1); 480 pos = (FX_POSITION)(uintptr_t)(nPos + 1);
488 } 481 }
489 return m_PieceMassArr.GetPtrAt(nPos - 1); 482 return m_PieceMassArr.GetPtrAt(nPos - 1);
490 } 483 }
491 484
492 FX_WCHAR CFDE_TxtEdtPage::GetChar(const FDE_TEXTEDITPIECE* pIdentity, 485 FX_WCHAR CFDE_TxtEdtPage::GetChar(const FDE_TEXTEDITPIECE* pIdentity,
493 int32_t index) const { 486 int32_t index) const {
494 int32_t nIndex = m_nPageStart + pIdentity->nStart + index; 487 int32_t nIndex = m_nPageStart + pIdentity->nStart + index;
495 if (nIndex != m_pIter->GetAt()) { 488 if (nIndex != m_pIter->GetAt()) {
496 m_pIter->SetAt(nIndex); 489 m_pIter->SetAt(nIndex);
497 } 490 }
498 FX_WCHAR wChar = m_pIter->GetChar(); 491 FX_WCHAR wChar = m_pIter->GetChar();
499 m_pIter->Next(); 492 m_pIter->Next();
500 return wChar; 493 return wChar;
501 } 494 }
502 495
503 int32_t CFDE_TxtEdtPage::GetWidth(const FDE_TEXTEDITPIECE* pIdentity, 496 int32_t CFDE_TxtEdtPage::GetWidth(const FDE_TEXTEDITPIECE* pIdentity,
504 int32_t index) const { 497 int32_t index) const {
505 int32_t nWidth = m_pCharWidth[pIdentity->nStart + index]; 498 int32_t nWidth = m_CharWidths[pIdentity->nStart + index];
506 return nWidth; 499 return nWidth;
507 } 500 }
508 501
509 void CFDE_TxtEdtPage::NormalizePt2Rect(CFX_PointF& ptF, 502 void CFDE_TxtEdtPage::NormalizePt2Rect(CFX_PointF& ptF,
510 const CFX_RectF& rtF, 503 const CFX_RectF& rtF,
511 FX_FLOAT fTolerance) const { 504 FX_FLOAT fTolerance) const {
512 if (rtF.Contains(ptF.x, ptF.y)) { 505 if (rtF.Contains(ptF.x, ptF.y)) {
513 return; 506 return;
514 } 507 }
515 if (ptF.x < rtF.left) { 508 if (ptF.x < rtF.left) {
516 ptF.x = rtF.left; 509 ptF.x = rtF.left;
517 } else if (ptF.x >= rtF.right()) { 510 } else if (ptF.x >= rtF.right()) {
518 ptF.x = rtF.right() - fTolerance; 511 ptF.x = rtF.right() - fTolerance;
519 } 512 }
520 if (ptF.y < rtF.top) { 513 if (ptF.y < rtF.top) {
521 ptF.y = rtF.top; 514 ptF.y = rtF.top;
522 } else if (ptF.y >= rtF.bottom()) { 515 } else if (ptF.y >= rtF.bottom()) {
523 ptF.y = rtF.bottom() - fTolerance; 516 ptF.y = rtF.bottom() - fTolerance;
524 } 517 }
525 } 518 }
OLDNEW
« no previous file with comments | « xfa/fde/cfde_txtedtpage.h ('k') | xfa/fde/css/fde_cssstyleselector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698