OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #include "xfa/src/fee/fde_txtedtparag.h" | |
8 | |
9 #include "xfa/src/fee/fde_txtedtbuf.h" | |
10 #include "xfa/src/fee/fde_txtedtengine.h" | |
11 #include "xfa/src/fee/fx_wordbreak/fx_wordbreak.h" | |
12 #include "xfa/src/fee/ifde_txtedtbuf.h" | |
13 #include "xfa/src/fee/ifde_txtedtengine.h" | |
14 #include "xfa/src/fgas/layout/fgas_textbreak.h" | |
15 | |
16 CFDE_TxtEdtParag::CFDE_TxtEdtParag(CFDE_TxtEdtEngine* pEngine) | |
17 : m_nCharStart(0), | |
18 m_nCharCount(0), | |
19 m_nLineCount(0), | |
20 m_lpData(NULL), | |
21 m_pEngine(pEngine) { | |
22 FXSYS_assert(m_pEngine); | |
23 } | |
24 CFDE_TxtEdtParag::~CFDE_TxtEdtParag() { | |
25 if (m_lpData != NULL) { | |
26 FX_Free(m_lpData); | |
27 } | |
28 } | |
29 void CFDE_TxtEdtParag::LoadParag() { | |
30 if (m_lpData != NULL) { | |
31 ((int32_t*)m_lpData)[0]++; | |
32 return; | |
33 } | |
34 IFX_TxtBreak* pTxtBreak = m_pEngine->GetTextBreak(); | |
35 IFDE_TxtEdtBuf* pTxtBuf = m_pEngine->GetTextBuf(); | |
36 const FDE_TXTEDTPARAMS* pParam = m_pEngine->GetEditParams(); | |
37 FX_WCHAR wcAlias = 0; | |
38 if (pParam->dwMode & FDE_TEXTEDITMODE_Password) { | |
39 wcAlias = m_pEngine->GetAliasChar(); | |
40 } | |
41 IFX_CharIter* pIter = | |
42 new CFDE_TxtEdtBufIter((CFDE_TxtEdtBuf*)pTxtBuf, wcAlias); | |
43 pIter->SetAt(m_nCharStart); | |
44 int32_t nEndIndex = m_nCharStart + m_nCharCount; | |
45 CFX_ArrayTemplate<int32_t> LineBaseArr; | |
46 FX_BOOL bReload = FALSE; | |
47 FX_DWORD dwBreakStatus = FX_TXTBREAK_None; | |
48 do { | |
49 if (bReload) { | |
50 dwBreakStatus = pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | |
51 } else { | |
52 FX_WCHAR wAppend = pIter->GetChar(); | |
53 dwBreakStatus = pTxtBreak->AppendChar(wAppend); | |
54 } | |
55 if (pIter->GetAt() + 1 == nEndIndex && | |
56 dwBreakStatus < FX_TXTBREAK_LineBreak) { | |
57 dwBreakStatus = pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | |
58 } | |
59 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { | |
60 int32_t nCount = pTxtBreak->CountBreakPieces(); | |
61 int32_t nTotal = 0; | |
62 for (int32_t j = 0; j < nCount; j++) { | |
63 const CFX_TxtPiece* Piece = pTxtBreak->GetBreakPiece(j); | |
64 nTotal += Piece->GetLength(); | |
65 } | |
66 LineBaseArr.Add(nTotal); | |
67 pTxtBreak->ClearBreakPieces(); | |
68 } | |
69 if ((pIter->GetAt() + 1 == nEndIndex) && | |
70 (dwBreakStatus == FX_TXTBREAK_LineBreak)) { | |
71 bReload = TRUE; | |
72 pIter->Next(TRUE); | |
73 } | |
74 } while (pIter->Next(FALSE) && (pIter->GetAt() < nEndIndex)); | |
75 pIter->Release(); | |
76 pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | |
77 pTxtBreak->ClearBreakPieces(); | |
78 int32_t nLineCount = LineBaseArr.GetSize(); | |
79 m_nLineCount = nLineCount; | |
80 if (m_lpData == NULL) { | |
81 m_lpData = FX_Alloc(int32_t, nLineCount + 1); | |
82 } else { | |
83 m_lpData = FX_Realloc(int32_t, m_lpData, (nLineCount + 1)); | |
84 } | |
85 int32_t* pIntArr = (int32_t*)m_lpData; | |
86 pIntArr[0] = 1; | |
87 m_nLineCount = nLineCount; | |
88 pIntArr++; | |
89 for (int32_t j = 0; j < nLineCount; j++, pIntArr++) { | |
90 *pIntArr = LineBaseArr[j]; | |
91 } | |
92 LineBaseArr.RemoveAll(); | |
93 } | |
94 void CFDE_TxtEdtParag::UnloadParag() { | |
95 FXSYS_assert(m_lpData != NULL); | |
96 ((int32_t*)m_lpData)[0]--; | |
97 FXSYS_assert(((int32_t*)m_lpData)[0] >= 0); | |
98 if (((int32_t*)m_lpData)[0] == 0) { | |
99 FX_Free(m_lpData); | |
100 m_lpData = NULL; | |
101 } | |
102 } | |
103 void CFDE_TxtEdtParag::CalcLines() { | |
104 IFX_TxtBreak* pTxtBreak = m_pEngine->GetTextBreak(); | |
105 IFDE_TxtEdtBuf* pTxtBuf = m_pEngine->GetTextBuf(); | |
106 IFX_CharIter* pIter = new CFDE_TxtEdtBufIter((CFDE_TxtEdtBuf*)pTxtBuf); | |
107 int32_t nCount = 0; | |
108 FX_DWORD dwBreakStatus = FX_TXTBREAK_None; | |
109 int32_t nEndIndex = m_nCharStart + m_nCharCount; | |
110 pIter->SetAt(m_nCharStart); | |
111 FX_BOOL bReload = FALSE; | |
112 do { | |
113 if (bReload) { | |
114 dwBreakStatus = pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | |
115 } else { | |
116 FX_WCHAR wAppend = pIter->GetChar(); | |
117 dwBreakStatus = pTxtBreak->AppendChar(wAppend); | |
118 } | |
119 if (pIter->GetAt() + 1 == nEndIndex && | |
120 dwBreakStatus < FX_TXTBREAK_LineBreak) { | |
121 dwBreakStatus = pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | |
122 } | |
123 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { | |
124 nCount++; | |
125 pTxtBreak->ClearBreakPieces(); | |
126 } | |
127 if ((pIter->GetAt() + 1 == nEndIndex) && | |
128 (dwBreakStatus == FX_TXTBREAK_LineBreak)) { | |
129 bReload = TRUE; | |
130 pIter->Next(TRUE); | |
131 } | |
132 } while (pIter->Next(FALSE) && (pIter->GetAt() < nEndIndex)); | |
133 pIter->Release(); | |
134 pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | |
135 pTxtBreak->ClearBreakPieces(); | |
136 m_nLineCount = nCount; | |
137 } | |
138 void CFDE_TxtEdtParag::GetLineRange(int32_t nLineIndex, | |
139 int32_t& nStart, | |
140 int32_t& nCount) const { | |
141 int32_t* pLineBaseArr = (int32_t*)m_lpData; | |
142 FXSYS_assert(nLineIndex < m_nLineCount); | |
143 nStart = m_nCharStart; | |
144 pLineBaseArr++; | |
145 for (int32_t i = 0; i < nLineIndex; i++) { | |
146 nStart += *pLineBaseArr; | |
147 pLineBaseArr++; | |
148 } | |
149 nCount = *pLineBaseArr; | |
150 } | |
OLD | NEW |