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/fde/cfde_txtedtparag.h" | 7 #include "xfa/fde/cfde_txtedtparag.h" |
8 | 8 |
9 #include "xfa/fde/cfde_txtedtbuf.h" | 9 #include "xfa/fde/cfde_txtedtbuf.h" |
10 #include "xfa/fde/cfde_txtedtbufiter.h" | 10 #include "xfa/fde/cfde_txtedtbufiter.h" |
11 #include "xfa/fde/cfde_txtedtengine.h" | 11 #include "xfa/fde/cfde_txtedtengine.h" |
12 #include "xfa/fde/ifde_txtedtengine.h" | 12 #include "xfa/fde/ifde_txtedtengine.h" |
13 #include "xfa/fgas/layout/fgas_textbreak.h" | 13 #include "xfa/fgas/layout/fgas_textbreak.h" |
14 #include "xfa/fde/ifx_chariter.h" | 14 #include "xfa/fde/ifx_chariter.h" |
15 | 15 |
16 CFDE_TxtEdtParag::CFDE_TxtEdtParag(CFDE_TxtEdtEngine* pEngine) | 16 CFDE_TxtEdtParag::CFDE_TxtEdtParag(CFDE_TxtEdtEngine* pEngine) |
17 : m_nCharStart(0), | 17 : m_nCharStart(0), |
18 m_nCharCount(0), | 18 m_nCharCount(0), |
19 m_nLineCount(0), | 19 m_nLineCount(0), |
20 m_lpData(NULL), | 20 m_lpData(nullptr), |
21 m_pEngine(pEngine) { | 21 m_pEngine(pEngine) { |
22 ASSERT(m_pEngine); | 22 ASSERT(m_pEngine); |
23 } | 23 } |
24 | 24 |
25 CFDE_TxtEdtParag::~CFDE_TxtEdtParag() { | 25 CFDE_TxtEdtParag::~CFDE_TxtEdtParag() { |
26 if (m_lpData) | 26 if (m_lpData) |
27 FX_Free(m_lpData); | 27 FX_Free(m_lpData); |
28 } | 28 } |
29 | 29 |
30 void CFDE_TxtEdtParag::LoadParag() { | 30 void CFDE_TxtEdtParag::LoadParag() { |
31 if (m_lpData != NULL) { | 31 if (m_lpData) { |
32 ((int32_t*)m_lpData)[0]++; | 32 ((int32_t*)m_lpData)[0]++; |
33 return; | 33 return; |
34 } | 34 } |
35 CFX_TxtBreak* pTxtBreak = m_pEngine->GetTextBreak(); | 35 CFX_TxtBreak* pTxtBreak = m_pEngine->GetTextBreak(); |
36 CFDE_TxtEdtBuf* pTxtBuf = m_pEngine->GetTextBuf(); | 36 CFDE_TxtEdtBuf* pTxtBuf = m_pEngine->GetTextBuf(); |
37 const FDE_TXTEDTPARAMS* pParam = m_pEngine->GetEditParams(); | 37 const FDE_TXTEDTPARAMS* pParam = m_pEngine->GetEditParams(); |
38 FX_WCHAR wcAlias = 0; | 38 FX_WCHAR wcAlias = 0; |
39 if (pParam->dwMode & FDE_TEXTEDITMODE_Password) { | 39 if (pParam->dwMode & FDE_TEXTEDITMODE_Password) { |
40 wcAlias = m_pEngine->GetAliasChar(); | 40 wcAlias = m_pEngine->GetAliasChar(); |
41 } | 41 } |
(...skipping 28 matching lines...) Expand all Loading... |
70 if ((pIter->GetAt() + 1 == nEndIndex) && | 70 if ((pIter->GetAt() + 1 == nEndIndex) && |
71 (dwBreakStatus == FX_TXTBREAK_LineBreak)) { | 71 (dwBreakStatus == FX_TXTBREAK_LineBreak)) { |
72 bReload = TRUE; | 72 bReload = TRUE; |
73 pIter->Next(TRUE); | 73 pIter->Next(TRUE); |
74 } | 74 } |
75 } while (pIter->Next(FALSE) && (pIter->GetAt() < nEndIndex)); | 75 } while (pIter->Next(FALSE) && (pIter->GetAt() < nEndIndex)); |
76 pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | 76 pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); |
77 pTxtBreak->ClearBreakPieces(); | 77 pTxtBreak->ClearBreakPieces(); |
78 int32_t nLineCount = LineBaseArr.GetSize(); | 78 int32_t nLineCount = LineBaseArr.GetSize(); |
79 m_nLineCount = nLineCount; | 79 m_nLineCount = nLineCount; |
80 if (m_lpData == NULL) { | 80 if (m_lpData) |
| 81 m_lpData = FX_Realloc(int32_t, m_lpData, (nLineCount + 1)); |
| 82 else |
81 m_lpData = FX_Alloc(int32_t, nLineCount + 1); | 83 m_lpData = FX_Alloc(int32_t, nLineCount + 1); |
82 } else { | 84 |
83 m_lpData = FX_Realloc(int32_t, m_lpData, (nLineCount + 1)); | |
84 } | |
85 int32_t* pIntArr = (int32_t*)m_lpData; | 85 int32_t* pIntArr = (int32_t*)m_lpData; |
86 pIntArr[0] = 1; | 86 pIntArr[0] = 1; |
87 m_nLineCount = nLineCount; | 87 m_nLineCount = nLineCount; |
88 pIntArr++; | 88 pIntArr++; |
89 for (int32_t j = 0; j < nLineCount; j++, pIntArr++) { | 89 for (int32_t j = 0; j < nLineCount; j++, pIntArr++) { |
90 *pIntArr = LineBaseArr[j]; | 90 *pIntArr = LineBaseArr[j]; |
91 } | 91 } |
92 LineBaseArr.RemoveAll(); | 92 LineBaseArr.RemoveAll(); |
93 } | 93 } |
94 | 94 |
95 void CFDE_TxtEdtParag::UnloadParag() { | 95 void CFDE_TxtEdtParag::UnloadParag() { |
96 ASSERT(m_lpData != NULL); | |
97 ((int32_t*)m_lpData)[0]--; | 96 ((int32_t*)m_lpData)[0]--; |
98 ASSERT(((int32_t*)m_lpData)[0] >= 0); | 97 ASSERT(((int32_t*)m_lpData)[0] >= 0); |
99 if (((int32_t*)m_lpData)[0] == 0) { | 98 if (((int32_t*)m_lpData)[0] == 0) { |
100 FX_Free(m_lpData); | 99 FX_Free(m_lpData); |
101 m_lpData = NULL; | 100 m_lpData = nullptr; |
102 } | 101 } |
103 } | 102 } |
104 | 103 |
105 void CFDE_TxtEdtParag::CalcLines() { | 104 void CFDE_TxtEdtParag::CalcLines() { |
106 CFX_TxtBreak* pTxtBreak = m_pEngine->GetTextBreak(); | 105 CFX_TxtBreak* pTxtBreak = m_pEngine->GetTextBreak(); |
107 CFDE_TxtEdtBuf* pTxtBuf = m_pEngine->GetTextBuf(); | 106 CFDE_TxtEdtBuf* pTxtBuf = m_pEngine->GetTextBuf(); |
108 int32_t nCount = 0; | 107 int32_t nCount = 0; |
109 uint32_t dwBreakStatus = FX_TXTBREAK_None; | 108 uint32_t dwBreakStatus = FX_TXTBREAK_None; |
110 int32_t nEndIndex = m_nCharStart + m_nCharCount; | 109 int32_t nEndIndex = m_nCharStart + m_nCharCount; |
111 std::unique_ptr<IFX_CharIter> pIter( | 110 std::unique_ptr<IFX_CharIter> pIter( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 int32_t* pLineBaseArr = (int32_t*)m_lpData; | 143 int32_t* pLineBaseArr = (int32_t*)m_lpData; |
145 ASSERT(nLineIndex < m_nLineCount); | 144 ASSERT(nLineIndex < m_nLineCount); |
146 nStart = m_nCharStart; | 145 nStart = m_nCharStart; |
147 pLineBaseArr++; | 146 pLineBaseArr++; |
148 for (int32_t i = 0; i < nLineIndex; i++) { | 147 for (int32_t i = 0; i < nLineIndex; i++) { |
149 nStart += *pLineBaseArr; | 148 nStart += *pLineBaseArr; |
150 pLineBaseArr++; | 149 pLineBaseArr++; |
151 } | 150 } |
152 nCount = *pLineBaseArr; | 151 nCount = *pLineBaseArr; |
153 } | 152 } |
OLD | NEW |