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_txtedtpage.h" | 7 #include "xfa/fde/cfde_txtedtpage.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 m_pTextSet->GetCharRects(pPiece, rectArr, bBBox); | 76 m_pTextSet->GetCharRects(pPiece, rectArr, bBBox); |
77 rect = rectArr[nIndex - pPiece->nStart]; | 77 rect = rectArr[nIndex - pPiece->nStart]; |
78 return pPiece->nBidiLevel; | 78 return pPiece->nBidiLevel; |
79 } | 79 } |
80 } | 80 } |
81 ASSERT(0); | 81 ASSERT(0); |
82 return 0; | 82 return 0; |
83 } | 83 } |
84 | 84 |
85 int32_t CFDE_TxtEdtPage::GetCharIndex(const CFX_PointF& fPoint, bool& bBefore) { | 85 int32_t CFDE_TxtEdtPage::GetCharIndex(const CFX_PointF& fPoint, bool& bBefore) { |
86 bool bVertical = m_pEditEngine->GetEditParams()->dwLayoutStyles & | |
87 FDE_TEXTEDITLAYOUT_DocVertical; | |
88 CFX_PointF ptF = fPoint; | 86 CFX_PointF ptF = fPoint; |
89 NormalizePt2Rect(ptF, m_rtPageContents, kTolerance); | 87 NormalizePt2Rect(ptF, m_rtPageContents, kTolerance); |
90 int32_t nCount = m_PieceMassArr.GetSize(); | 88 int32_t nCount = m_PieceMassArr.GetSize(); |
91 CFX_RectF rtLine; | 89 CFX_RectF rtLine; |
92 int32_t nBgn = 0; | 90 int32_t nBgn = 0; |
93 int32_t nEnd = 0; | 91 int32_t nEnd = 0; |
94 bool bInLine = false; | 92 bool bInLine = false; |
95 int32_t i = 0; | 93 int32_t i = 0; |
96 for (i = 0; i < nCount; i++) { | 94 for (i = 0; i < nCount; i++) { |
97 const FDE_TEXTEDITPIECE* pPiece = m_PieceMassArr.GetPtrAt(i); | 95 const FDE_TEXTEDITPIECE* pPiece = m_PieceMassArr.GetPtrAt(i); |
98 if (!bInLine && (bVertical ? (pPiece->rtPiece.left <= ptF.x && | 96 if (!bInLine && |
99 pPiece->rtPiece.right() > ptF.x) | 97 (pPiece->rtPiece.top <= ptF.y && pPiece->rtPiece.bottom() > ptF.y)) { |
100 : (pPiece->rtPiece.top <= ptF.y && | |
101 pPiece->rtPiece.bottom() > ptF.y))) { | |
102 nBgn = nEnd = i; | 98 nBgn = nEnd = i; |
103 rtLine = pPiece->rtPiece; | 99 rtLine = pPiece->rtPiece; |
104 bInLine = true; | 100 bInLine = true; |
105 } else if (bInLine) { | 101 } else if (bInLine) { |
106 if (bVertical ? (!(pPiece->rtPiece.left <= ptF.x && | 102 if (pPiece->rtPiece.bottom() <= ptF.y || pPiece->rtPiece.top > ptF.y) { |
107 pPiece->rtPiece.right() > ptF.x)) | |
108 : (pPiece->rtPiece.bottom() <= ptF.y || | |
109 pPiece->rtPiece.top > ptF.y)) { | |
110 nEnd = i - 1; | 103 nEnd = i - 1; |
111 break; | 104 break; |
112 } else { | 105 } else { |
113 rtLine.Union(pPiece->rtPiece); | 106 rtLine.Union(pPiece->rtPiece); |
114 } | 107 } |
115 } | 108 } |
116 } | 109 } |
117 NormalizePt2Rect(ptF, rtLine, kTolerance); | 110 NormalizePt2Rect(ptF, rtLine, kTolerance); |
118 int32_t nCaret = 0; | 111 int32_t nCaret = 0; |
119 FDE_TEXTEDITPIECE* pPiece = nullptr; | 112 FDE_TEXTEDITPIECE* pPiece = nullptr; |
(...skipping 15 matching lines...) Expand all Loading... |
135 if (wChar == L'\n' || wChar == L'\r') { | 128 if (wChar == L'\n' || wChar == L'\r') { |
136 if (wChar == L'\n') { | 129 if (wChar == L'\n') { |
137 if (m_pEditEngine->GetTextBuf()->GetCharByIndex(nCaret - 1) == | 130 if (m_pEditEngine->GetTextBuf()->GetCharByIndex(nCaret - 1) == |
138 L'\r') { | 131 L'\r') { |
139 nCaret--; | 132 nCaret--; |
140 } | 133 } |
141 } | 134 } |
142 bBefore = true; | 135 bBefore = true; |
143 return nCaret; | 136 return nCaret; |
144 } | 137 } |
145 if (bVertical | 138 if (ptF.x > ((rectArr[j].left + rectArr[j].right()) / 2)) { |
146 ? (ptF.y > ((rectArr[j].top + rectArr[j].bottom()) / 2)) | |
147 : (ptF.x > ((rectArr[j].left + rectArr[j].right()) / 2))) { | |
148 bBefore = FX_IsOdd(pPiece->nBidiLevel); | 139 bBefore = FX_IsOdd(pPiece->nBidiLevel); |
149 } else { | 140 } else { |
150 bBefore = !FX_IsOdd(pPiece->nBidiLevel); | 141 bBefore = !FX_IsOdd(pPiece->nBidiLevel); |
151 } | 142 } |
152 return nCaret; | 143 return nCaret; |
153 } | 144 } |
154 } | 145 } |
155 } | 146 } |
156 } | 147 } |
157 bBefore = true; | 148 bBefore = true; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 static_cast<CFDE_TxtEdtParag*>(m_pEditEngine->GetParag(nBgnParag)); | 277 static_cast<CFDE_TxtEdtParag*>(m_pEditEngine->GetParag(nBgnParag)); |
287 m_pBgnParag->LoadParag(); | 278 m_pBgnParag->LoadParag(); |
288 m_pBgnParag->GetLineRange(nStartLine - nStartLineInParag, nPageStart, nTemp); | 279 m_pBgnParag->GetLineRange(nStartLine - nStartLineInParag, nPageStart, nTemp); |
289 nEndParag = m_pEditEngine->Line2Parag(nBgnParag, nStartLineInParag, nEndLine, | 280 nEndParag = m_pEditEngine->Line2Parag(nBgnParag, nStartLineInParag, nEndLine, |
290 nEndLineInParag); | 281 nEndLineInParag); |
291 m_pEndParag = | 282 m_pEndParag = |
292 static_cast<CFDE_TxtEdtParag*>(m_pEditEngine->GetParag(nEndParag)); | 283 static_cast<CFDE_TxtEdtParag*>(m_pEditEngine->GetParag(nEndParag)); |
293 m_pEndParag->LoadParag(); | 284 m_pEndParag->LoadParag(); |
294 m_pEndParag->GetLineRange(nEndLine - nEndLineInParag, nPageEnd, nTemp); | 285 m_pEndParag->GetLineRange(nEndLine - nEndLineInParag, nPageEnd, nTemp); |
295 nPageEnd += (nTemp - 1); | 286 nPageEnd += (nTemp - 1); |
296 bool bVertial = pParams->dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical; | 287 |
297 bool bLineReserve = | 288 FX_FLOAT fLineStart = 0.0f; |
298 !!(pParams->dwLayoutStyles & FDE_TEXTEDITLAYOUT_LineReserve); | 289 FX_FLOAT fLineStep = pParams->fLineSpace; |
299 FX_FLOAT fLineStart = | |
300 bVertial | |
301 ? (bLineReserve ? (pParams->fPlateWidth - pParams->fLineSpace) : 0.0f) | |
302 : 0.0f; | |
303 FX_FLOAT fLineStep = | |
304 (bVertial && bLineReserve) ? (-pParams->fLineSpace) : pParams->fLineSpace; | |
305 FX_FLOAT fLinePos = fLineStart; | 290 FX_FLOAT fLinePos = fLineStart; |
306 if (!m_pTextSet) | 291 if (!m_pTextSet) |
307 m_pTextSet = pdfium::MakeUnique<CFDE_TxtEdtTextSet>(this); | 292 m_pTextSet = pdfium::MakeUnique<CFDE_TxtEdtTextSet>(this); |
308 | 293 |
309 m_PieceMassArr.RemoveAll(true); | 294 m_PieceMassArr.RemoveAll(true); |
310 uint32_t dwBreakStatus = FX_TXTBREAK_None; | 295 uint32_t dwBreakStatus = FX_TXTBREAK_None; |
311 int32_t nPieceStart = 0; | 296 int32_t nPieceStart = 0; |
312 | 297 |
313 m_CharWidths.resize(nPageEnd - nPageStart + 1, 0); | 298 m_CharWidths.resize(nPageEnd - nPageStart + 1, 0); |
314 pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | 299 pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 fParaBreakWidth += fDefCharWidth; | 344 fParaBreakWidth += fDefCharWidth; |
360 } | 345 } |
361 } else if (TxtEdtPiece.nCount >= 1) { | 346 } else if (TxtEdtPiece.nCount >= 1) { |
362 FX_WCHAR wChar = pBuf->GetCharByIndex( | 347 FX_WCHAR wChar = pBuf->GetCharByIndex( |
363 m_nPageStart + TxtEdtPiece.nStart + TxtEdtPiece.nCount - 1); | 348 m_nPageStart + TxtEdtPiece.nStart + TxtEdtPiece.nCount - 1); |
364 if (wChar == wRtChar) { | 349 if (wChar == wRtChar) { |
365 fParaBreakWidth += fDefCharWidth; | 350 fParaBreakWidth += fDefCharWidth; |
366 } | 351 } |
367 } | 352 } |
368 } | 353 } |
369 if (pParams->dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical) { | 354 |
370 TxtEdtPiece.rtPiece.left = fLinePos; | 355 TxtEdtPiece.rtPiece.left = (FX_FLOAT)pPiece->m_iStartPos / 20000.0f; |
371 TxtEdtPiece.rtPiece.top = (FX_FLOAT)pPiece->m_iStartPos / 20000.0f; | 356 TxtEdtPiece.rtPiece.top = fLinePos; |
372 TxtEdtPiece.rtPiece.width = pParams->fLineSpace; | 357 TxtEdtPiece.rtPiece.width = |
373 TxtEdtPiece.rtPiece.height = | 358 (FX_FLOAT)pPiece->m_iWidth / 20000.0f + fParaBreakWidth; |
374 (FX_FLOAT)pPiece->m_iWidth / 20000.0f + fParaBreakWidth; | 359 TxtEdtPiece.rtPiece.height = pParams->fLineSpace; |
375 } else { | 360 |
376 TxtEdtPiece.rtPiece.left = (FX_FLOAT)pPiece->m_iStartPos / 20000.0f; | |
377 TxtEdtPiece.rtPiece.top = fLinePos; | |
378 TxtEdtPiece.rtPiece.width = | |
379 (FX_FLOAT)pPiece->m_iWidth / 20000.0f + fParaBreakWidth; | |
380 TxtEdtPiece.rtPiece.height = pParams->fLineSpace; | |
381 } | |
382 if (bFirstPiece) { | 361 if (bFirstPiece) { |
383 m_rtPageContents = TxtEdtPiece.rtPiece; | 362 m_rtPageContents = TxtEdtPiece.rtPiece; |
384 bFirstPiece = false; | 363 bFirstPiece = false; |
385 } else { | 364 } else { |
386 m_rtPageContents.Union(TxtEdtPiece.rtPiece); | 365 m_rtPageContents.Union(TxtEdtPiece.rtPiece); |
387 } | 366 } |
388 nPieceStart += TxtEdtPiece.nCount; | 367 nPieceStart += TxtEdtPiece.nCount; |
389 m_PieceMassArr.Add(TxtEdtPiece); | 368 m_PieceMassArr.Add(TxtEdtPiece); |
390 for (int32_t k = 0; k < TxtEdtPiece.nCount; k++) { | 369 for (int32_t k = 0; k < TxtEdtPiece.nCount; k++) { |
391 CFX_Char* ptc = pPiece->GetCharPtr(k); | 370 CFX_Char* ptc = pPiece->GetCharPtr(k); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 ptF.x = rtF.left; | 488 ptF.x = rtF.left; |
510 } else if (ptF.x >= rtF.right()) { | 489 } else if (ptF.x >= rtF.right()) { |
511 ptF.x = rtF.right() - fTolerance; | 490 ptF.x = rtF.right() - fTolerance; |
512 } | 491 } |
513 if (ptF.y < rtF.top) { | 492 if (ptF.y < rtF.top) { |
514 ptF.y = rtF.top; | 493 ptF.y = rtF.top; |
515 } else if (ptF.y >= rtF.bottom()) { | 494 } else if (ptF.y >= rtF.bottom()) { |
516 ptF.y = rtF.bottom() - fTolerance; | 495 ptF.y = rtF.bottom() - fTolerance; |
517 } | 496 } |
518 } | 497 } |
OLD | NEW |