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/tto/fde_textout.h" | 7 #include "xfa/fde/tto/fde_textout.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 m_fFontSize(12.0f), | 23 m_fFontSize(12.0f), |
24 m_fLineSpace(m_fFontSize), | 24 m_fLineSpace(m_fFontSize), |
25 m_fLinePos(0.0f), | 25 m_fLinePos(0.0f), |
26 m_fTolerance(0.0f), | 26 m_fTolerance(0.0f), |
27 m_iAlignment(0), | 27 m_iAlignment(0), |
28 m_iTxtBkAlignment(0), | 28 m_iTxtBkAlignment(0), |
29 m_wParagraphBkChar(L'\n'), | 29 m_wParagraphBkChar(L'\n'), |
30 m_TxtColor(0xFF000000), | 30 m_TxtColor(0xFF000000), |
31 m_dwStyles(0), | 31 m_dwStyles(0), |
32 m_dwTxtBkStyles(0), | 32 m_dwTxtBkStyles(0), |
33 m_bElliChanged(FALSE), | 33 m_bElliChanged(false), |
34 m_iEllipsisWidth(0), | 34 m_iEllipsisWidth(0), |
35 m_ttoLines(5), | 35 m_ttoLines(5), |
36 m_iCurLine(0), | 36 m_iCurLine(0), |
37 m_iCurPiece(0), | 37 m_iCurPiece(0), |
38 m_iTotalLines(0) { | 38 m_iTotalLines(0) { |
39 m_Matrix.SetIdentity(); | 39 m_Matrix.SetIdentity(); |
40 m_rtClip.Reset(); | 40 m_rtClip.Reset(); |
41 m_rtLogicClip.Reset(); | 41 m_rtLogicClip.Reset(); |
42 } | 42 } |
43 | 43 |
44 CFDE_TextOut::~CFDE_TextOut() { | 44 CFDE_TextOut::~CFDE_TextOut() { |
45 m_ttoLines.RemoveAll(FALSE); | 45 m_ttoLines.RemoveAll(false); |
46 } | 46 } |
47 | 47 |
48 void CFDE_TextOut::SetFont(CFGAS_GEFont* pFont) { | 48 void CFDE_TextOut::SetFont(CFGAS_GEFont* pFont) { |
49 ASSERT(pFont); | 49 ASSERT(pFont); |
50 m_pFont = pFont; | 50 m_pFont = pFont; |
51 m_pTxtBreak->SetFont(pFont); | 51 m_pTxtBreak->SetFont(pFont); |
52 } | 52 } |
53 | 53 |
54 void CFDE_TextOut::SetFontSize(FX_FLOAT fFontSize) { | 54 void CFDE_TextOut::SetFontSize(FX_FLOAT fFontSize) { |
55 ASSERT(fFontSize > 0); | 55 ASSERT(fFontSize > 0); |
(...skipping 25 matching lines...) Expand all Loading... |
81 } | 81 } |
82 if (dwStyles & FDE_TTOSTYLE_VerticalLayout) { | 82 if (dwStyles & FDE_TTOSTYLE_VerticalLayout) { |
83 m_dwTxtBkStyles |= | 83 m_dwTxtBkStyles |= |
84 (FX_TXTLAYOUTSTYLE_VerticalChars | FX_TXTLAYOUTSTYLE_VerticalLayout); | 84 (FX_TXTLAYOUTSTYLE_VerticalChars | FX_TXTLAYOUTSTYLE_VerticalLayout); |
85 } | 85 } |
86 m_pTxtBreak->SetLayoutStyles(m_dwTxtBkStyles); | 86 m_pTxtBreak->SetLayoutStyles(m_dwTxtBkStyles); |
87 } | 87 } |
88 | 88 |
89 void CFDE_TextOut::SetTabWidth(FX_FLOAT fTabWidth) { | 89 void CFDE_TextOut::SetTabWidth(FX_FLOAT fTabWidth) { |
90 ASSERT(fTabWidth > 1.0f); | 90 ASSERT(fTabWidth > 1.0f); |
91 m_pTxtBreak->SetTabWidth(fTabWidth, FALSE); | 91 m_pTxtBreak->SetTabWidth(fTabWidth, false); |
92 } | 92 } |
93 | 93 |
94 void CFDE_TextOut::SetEllipsisString(const CFX_WideString& wsEllipsis) { | 94 void CFDE_TextOut::SetEllipsisString(const CFX_WideString& wsEllipsis) { |
95 m_bElliChanged = TRUE; | 95 m_bElliChanged = true; |
96 m_wsEllipsis = wsEllipsis; | 96 m_wsEllipsis = wsEllipsis; |
97 } | 97 } |
98 | 98 |
99 void CFDE_TextOut::SetParagraphBreakChar(FX_WCHAR wch) { | 99 void CFDE_TextOut::SetParagraphBreakChar(FX_WCHAR wch) { |
100 m_wParagraphBkChar = wch; | 100 m_wParagraphBkChar = wch; |
101 m_pTxtBreak->SetParagraphBreakChar(wch); | 101 m_pTxtBreak->SetParagraphBreakChar(wch); |
102 } | 102 } |
103 | 103 |
104 void CFDE_TextOut::SetAlignment(int32_t iAlignment) { | 104 void CFDE_TextOut::SetAlignment(int32_t iAlignment) { |
105 m_iAlignment = iAlignment; | 105 m_iAlignment = iAlignment; |
(...skipping 19 matching lines...) Expand all Loading... |
125 ASSERT(fLineSpace > 1.0f); | 125 ASSERT(fLineSpace > 1.0f); |
126 m_fLineSpace = fLineSpace; | 126 m_fLineSpace = fLineSpace; |
127 } | 127 } |
128 | 128 |
129 void CFDE_TextOut::SetDIBitmap(CFX_DIBitmap* pDIB) { | 129 void CFDE_TextOut::SetDIBitmap(CFX_DIBitmap* pDIB) { |
130 ASSERT(pDIB); | 130 ASSERT(pDIB); |
131 | 131 |
132 m_pRenderDevice.reset(); | 132 m_pRenderDevice.reset(); |
133 CFX_FxgeDevice* device = new CFX_FxgeDevice; | 133 CFX_FxgeDevice* device = new CFX_FxgeDevice; |
134 device->Attach(pDIB, false, nullptr, false); | 134 device->Attach(pDIB, false, nullptr, false); |
135 m_pRenderDevice.reset(new CFDE_RenderDevice(device, FALSE)); | 135 m_pRenderDevice.reset(new CFDE_RenderDevice(device, false)); |
136 } | 136 } |
137 | 137 |
138 void CFDE_TextOut::SetRenderDevice(CFX_RenderDevice* pDevice) { | 138 void CFDE_TextOut::SetRenderDevice(CFX_RenderDevice* pDevice) { |
139 ASSERT(pDevice); | 139 ASSERT(pDevice); |
140 m_pRenderDevice.reset(new CFDE_RenderDevice(pDevice, FALSE)); | 140 m_pRenderDevice.reset(new CFDE_RenderDevice(pDevice, false)); |
141 } | 141 } |
142 | 142 |
143 void CFDE_TextOut::SetClipRect(const CFX_Rect& rtClip) { | 143 void CFDE_TextOut::SetClipRect(const CFX_Rect& rtClip) { |
144 m_rtClip.Set((FX_FLOAT)rtClip.left, (FX_FLOAT)rtClip.top, | 144 m_rtClip.Set((FX_FLOAT)rtClip.left, (FX_FLOAT)rtClip.top, |
145 (FX_FLOAT)rtClip.Width(), (FX_FLOAT)rtClip.Height()); | 145 (FX_FLOAT)rtClip.Width(), (FX_FLOAT)rtClip.Height()); |
146 } | 146 } |
147 | 147 |
148 void CFDE_TextOut::SetClipRect(const CFX_RectF& rtClip) { | 148 void CFDE_TextOut::SetClipRect(const CFX_RectF& rtClip) { |
149 m_rtClip = rtClip; | 149 m_rtClip = rtClip; |
150 } | 150 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 233 } |
234 } | 234 } |
235 | 235 |
236 void CFDE_TextOut::CalcTextSize(const FX_WCHAR* pwsStr, | 236 void CFDE_TextOut::CalcTextSize(const FX_WCHAR* pwsStr, |
237 int32_t iLength, | 237 int32_t iLength, |
238 CFX_RectF& rect) { | 238 CFX_RectF& rect) { |
239 ASSERT(m_pFont && m_fFontSize >= 1.0f); | 239 ASSERT(m_pFont && m_fFontSize >= 1.0f); |
240 SetLineWidth(rect); | 240 SetLineWidth(rect); |
241 m_iTotalLines = 0; | 241 m_iTotalLines = 0; |
242 const FX_WCHAR* pStr = pwsStr; | 242 const FX_WCHAR* pStr = pwsStr; |
243 FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); | 243 bool bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); |
244 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); | 244 bool bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); |
245 FX_FLOAT fWidth = 0.0f; | 245 FX_FLOAT fWidth = 0.0f; |
246 FX_FLOAT fHeight = 0.0f; | 246 FX_FLOAT fHeight = 0.0f; |
247 FX_FLOAT fStartPos = bVertical ? rect.bottom() : rect.right(); | 247 FX_FLOAT fStartPos = bVertical ? rect.bottom() : rect.right(); |
248 uint32_t dwBreakStatus = 0; | 248 uint32_t dwBreakStatus = 0; |
249 FX_WCHAR wPreChar = 0; | 249 FX_WCHAR wPreChar = 0; |
250 FX_WCHAR wch; | 250 FX_WCHAR wch; |
251 FX_WCHAR wBreak = 0; | 251 FX_WCHAR wBreak = 0; |
252 while (iLength-- > 0) { | 252 while (iLength-- > 0) { |
253 wch = *pStr++; | 253 wch = *pStr++; |
254 if (wBreak == 0 && (wch == L'\n' || wch == L'\r')) { | 254 if (wBreak == 0 && (wch == L'\n' || wch == L'\r')) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } else { | 307 } else { |
308 if (rect.Width() < 1.0f) { | 308 if (rect.Width() < 1.0f) { |
309 rect.width = m_fFontSize * 1000.0f; | 309 rect.width = m_fFontSize * 1000.0f; |
310 } | 310 } |
311 fLineWidth = rect.Width(); | 311 fLineWidth = rect.Width(); |
312 } | 312 } |
313 m_pTxtBreak->SetLineWidth(fLineWidth); | 313 m_pTxtBreak->SetLineWidth(fLineWidth); |
314 } | 314 } |
315 } | 315 } |
316 | 316 |
317 FX_BOOL CFDE_TextOut::RetrieveLineWidth(uint32_t dwBreakStatus, | 317 bool CFDE_TextOut::RetrieveLineWidth(uint32_t dwBreakStatus, |
318 FX_FLOAT& fStartPos, | 318 FX_FLOAT& fStartPos, |
319 FX_FLOAT& fWidth, | 319 FX_FLOAT& fWidth, |
320 FX_FLOAT& fHeight) { | 320 FX_FLOAT& fHeight) { |
321 if (dwBreakStatus <= FX_TXTBREAK_PieceBreak) { | 321 if (dwBreakStatus <= FX_TXTBREAK_PieceBreak) { |
322 return FALSE; | 322 return false; |
323 } | 323 } |
324 FX_FLOAT fLineStep = | 324 FX_FLOAT fLineStep = |
325 (m_fLineSpace > m_fFontSize) ? m_fLineSpace : m_fFontSize; | 325 (m_fLineSpace > m_fFontSize) ? m_fLineSpace : m_fFontSize; |
326 FX_BOOL bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); | 326 bool bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); |
327 FX_FLOAT fLineWidth = 0.0f; | 327 FX_FLOAT fLineWidth = 0.0f; |
328 int32_t iCount = m_pTxtBreak->CountBreakPieces(); | 328 int32_t iCount = m_pTxtBreak->CountBreakPieces(); |
329 for (int32_t i = 0; i < iCount; i++) { | 329 for (int32_t i = 0; i < iCount; i++) { |
330 const CFX_TxtPiece* pPiece = m_pTxtBreak->GetBreakPiece(i); | 330 const CFX_TxtPiece* pPiece = m_pTxtBreak->GetBreakPiece(i); |
331 fLineWidth += (FX_FLOAT)pPiece->m_iWidth / 20000.0f; | 331 fLineWidth += (FX_FLOAT)pPiece->m_iWidth / 20000.0f; |
332 fStartPos = std::min(fStartPos, (FX_FLOAT)pPiece->m_iStartPos / 20000.0f); | 332 fStartPos = std::min(fStartPos, (FX_FLOAT)pPiece->m_iStartPos / 20000.0f); |
333 } | 333 } |
334 m_pTxtBreak->ClearBreakPieces(); | 334 m_pTxtBreak->ClearBreakPieces(); |
335 if (dwBreakStatus == FX_TXTBREAK_ParagraphBreak) { | 335 if (dwBreakStatus == FX_TXTBREAK_ParagraphBreak) { |
336 m_pTxtBreak->Reset(); | 336 m_pTxtBreak->Reset(); |
337 } | 337 } |
338 if (!bLineWrap && dwBreakStatus == FX_TXTBREAK_LineBreak) { | 338 if (!bLineWrap && dwBreakStatus == FX_TXTBREAK_LineBreak) { |
339 fWidth += fLineWidth; | 339 fWidth += fLineWidth; |
340 } else { | 340 } else { |
341 fWidth = std::max(fWidth, fLineWidth); | 341 fWidth = std::max(fWidth, fLineWidth); |
342 fHeight += fLineStep; | 342 fHeight += fLineStep; |
343 } | 343 } |
344 m_iTotalLines++; | 344 m_iTotalLines++; |
345 return TRUE; | 345 return true; |
346 } | 346 } |
347 | 347 |
348 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, | 348 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, |
349 int32_t iLength, | 349 int32_t iLength, |
350 int32_t x, | 350 int32_t x, |
351 int32_t y) { | 351 int32_t y) { |
352 CFX_RectF rtText; | 352 CFX_RectF rtText; |
353 rtText.Set((FX_FLOAT)x, (FX_FLOAT)y, m_fFontSize * 1000.0f, | 353 rtText.Set((FX_FLOAT)x, (FX_FLOAT)y, m_fFontSize * 1000.0f, |
354 m_fFontSize * 1000.0f); | 354 m_fFontSize * 1000.0f); |
355 DrawText(pwsStr, iLength, rtText); | 355 DrawText(pwsStr, iLength, rtText); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 return; | 412 return; |
413 | 413 |
414 if (rect.width < m_fFontSize || rect.height < m_fFontSize) { | 414 if (rect.width < m_fFontSize || rect.height < m_fFontSize) { |
415 return; | 415 return; |
416 } | 416 } |
417 FX_FLOAT fLineWidth = rect.width; | 417 FX_FLOAT fLineWidth = rect.width; |
418 if (m_dwStyles & FDE_TTOSTYLE_VerticalLayout) { | 418 if (m_dwStyles & FDE_TTOSTYLE_VerticalLayout) { |
419 fLineWidth = rect.height; | 419 fLineWidth = rect.height; |
420 } | 420 } |
421 m_pTxtBreak->SetLineWidth(fLineWidth); | 421 m_pTxtBreak->SetLineWidth(fLineWidth); |
422 m_ttoLines.RemoveAll(TRUE); | 422 m_ttoLines.RemoveAll(true); |
423 m_wsText.clear(); | 423 m_wsText.clear(); |
424 LoadText(pwsStr, iLength, rect); | 424 LoadText(pwsStr, iLength, rect); |
425 if (m_dwStyles & FDE_TTOSTYLE_Ellipsis) { | 425 if (m_dwStyles & FDE_TTOSTYLE_Ellipsis) { |
426 ReplaceWidthEllipsis(); | 426 ReplaceWidthEllipsis(); |
427 } | 427 } |
428 Reload(rect); | 428 Reload(rect); |
429 DoAlignment(rect); | 429 DoAlignment(rect); |
430 OnDraw(rtClip); | 430 OnDraw(rtClip); |
431 } | 431 } |
432 | 432 |
(...skipping 13 matching lines...) Expand all Loading... |
446 if (m_CharPos.size() < size) | 446 if (m_CharPos.size() < size) |
447 m_CharPos.resize(size, FXTEXT_CHARPOS()); | 447 m_CharPos.resize(size, FXTEXT_CHARPOS()); |
448 break; | 448 break; |
449 } | 449 } |
450 } | 450 } |
451 | 451 |
452 void CFDE_TextOut::LoadEllipsis() { | 452 void CFDE_TextOut::LoadEllipsis() { |
453 if (!m_bElliChanged) { | 453 if (!m_bElliChanged) { |
454 return; | 454 return; |
455 } | 455 } |
456 m_bElliChanged = FALSE; | 456 m_bElliChanged = false; |
457 m_iEllipsisWidth = 0; | 457 m_iEllipsisWidth = 0; |
458 int32_t iLength = m_wsEllipsis.GetLength(); | 458 int32_t iLength = m_wsEllipsis.GetLength(); |
459 if (iLength < 1) { | 459 if (iLength < 1) { |
460 return; | 460 return; |
461 } | 461 } |
462 ExpandBuffer(iLength, 1); | 462 ExpandBuffer(iLength, 1); |
463 const FX_WCHAR* pStr = m_wsEllipsis.c_str(); | 463 const FX_WCHAR* pStr = m_wsEllipsis.c_str(); |
464 uint32_t dwBreakStatus; | 464 uint32_t dwBreakStatus; |
465 FX_WCHAR wch; | 465 FX_WCHAR wch; |
466 while (iLength-- > 0) { | 466 while (iLength-- > 0) { |
(...skipping 23 matching lines...) Expand all Loading... |
490 } | 490 } |
491 m_pTxtBreak->ClearBreakPieces(); | 491 m_pTxtBreak->ClearBreakPieces(); |
492 } | 492 } |
493 | 493 |
494 void CFDE_TextOut::LoadText(const FX_WCHAR* pwsStr, | 494 void CFDE_TextOut::LoadText(const FX_WCHAR* pwsStr, |
495 int32_t iLength, | 495 int32_t iLength, |
496 const CFX_RectF& rect) { | 496 const CFX_RectF& rect) { |
497 FX_WCHAR* pStr = m_wsText.GetBuffer(iLength); | 497 FX_WCHAR* pStr = m_wsText.GetBuffer(iLength); |
498 int32_t iTxtLength = iLength; | 498 int32_t iTxtLength = iLength; |
499 ExpandBuffer(iTxtLength, 0); | 499 ExpandBuffer(iTxtLength, 0); |
500 FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); | 500 bool bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); |
501 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); | 501 bool bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); |
502 FX_BOOL bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); | 502 bool bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); |
503 FX_FLOAT fLineStep = | 503 FX_FLOAT fLineStep = |
504 (m_fLineSpace > m_fFontSize) ? m_fLineSpace : m_fFontSize; | 504 (m_fLineSpace > m_fFontSize) ? m_fLineSpace : m_fFontSize; |
505 FX_FLOAT fLineStop = bVertical ? rect.left : rect.bottom(); | 505 FX_FLOAT fLineStop = bVertical ? rect.left : rect.bottom(); |
506 m_fLinePos = bVertical ? rect.right() : rect.top; | 506 m_fLinePos = bVertical ? rect.right() : rect.top; |
507 if (bVertical) { | 507 if (bVertical) { |
508 fLineStep = -fLineStep; | 508 fLineStep = -fLineStep; |
509 } | 509 } |
510 m_hotKeys.RemoveAll(); | 510 m_hotKeys.RemoveAll(); |
511 int32_t iStartChar = 0; | 511 int32_t iStartChar = 0; |
512 int32_t iChars = 0; | 512 int32_t iChars = 0; |
513 int32_t iPieceWidths = 0; | 513 int32_t iPieceWidths = 0; |
514 uint32_t dwBreakStatus; | 514 uint32_t dwBreakStatus; |
515 FX_WCHAR wch; | 515 FX_WCHAR wch; |
516 FX_BOOL bRet = FALSE; | 516 bool bRet = false; |
517 while (iTxtLength-- > 0) { | 517 while (iTxtLength-- > 0) { |
518 wch = *pwsStr++; | 518 wch = *pwsStr++; |
519 if (bHotKey && wch == L'&' && *(pStr - 1) != L'&') { | 519 if (bHotKey && wch == L'&' && *(pStr - 1) != L'&') { |
520 if (iTxtLength > 0) | 520 if (iTxtLength > 0) |
521 m_hotKeys.Add(iChars); | 521 m_hotKeys.Add(iChars); |
522 continue; | 522 continue; |
523 } | 523 } |
524 *pStr++ = wch; | 524 *pStr++ = wch; |
525 iChars++; | 525 iChars++; |
526 dwBreakStatus = m_pTxtBreak->AppendChar(wch); | 526 dwBreakStatus = m_pTxtBreak->AppendChar(wch); |
527 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { | 527 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { |
528 FX_BOOL bEndofLine = | 528 bool bEndofLine = |
529 RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, FALSE, rect); | 529 RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, false, rect); |
530 if (bEndofLine && (bLineWrap || (dwBreakStatus > FX_TXTBREAK_LineBreak && | 530 if (bEndofLine && (bLineWrap || (dwBreakStatus > FX_TXTBREAK_LineBreak && |
531 !bLineWrap))) { | 531 !bLineWrap))) { |
532 iPieceWidths = 0; | 532 iPieceWidths = 0; |
533 m_iCurLine++; | 533 m_iCurLine++; |
534 m_fLinePos += fLineStep; | 534 m_fLinePos += fLineStep; |
535 } | 535 } |
536 if ((bVertical && m_fLinePos + fLineStep < fLineStop) || | 536 if ((bVertical && m_fLinePos + fLineStep < fLineStop) || |
537 (!bVertical && m_fLinePos + fLineStep > fLineStop)) { | 537 (!bVertical && m_fLinePos + fLineStep > fLineStop)) { |
538 int32_t iCurLine = m_iCurLine; | 538 int32_t iCurLine = m_iCurLine; |
539 if (bEndofLine) { | 539 if (bEndofLine) { |
540 iCurLine--; | 540 iCurLine--; |
541 } | 541 } |
542 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(iCurLine); | 542 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(iCurLine); |
543 pLine->m_bNewReload = TRUE; | 543 pLine->m_bNewReload = true; |
544 bRet = TRUE; | 544 bRet = true; |
545 break; | 545 break; |
546 } | 546 } |
547 } | 547 } |
548 } | 548 } |
549 dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | 549 dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); |
550 if (dwBreakStatus > FX_TXTBREAK_PieceBreak && !bRet) { | 550 if (dwBreakStatus > FX_TXTBREAK_PieceBreak && !bRet) { |
551 RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, FALSE, rect); | 551 RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, false, rect); |
552 } | 552 } |
553 m_pTxtBreak->ClearBreakPieces(); | 553 m_pTxtBreak->ClearBreakPieces(); |
554 m_pTxtBreak->Reset(); | 554 m_pTxtBreak->Reset(); |
555 m_wsText.ReleaseBuffer(iLength); | 555 m_wsText.ReleaseBuffer(iLength); |
556 } | 556 } |
557 | 557 |
558 FX_BOOL CFDE_TextOut::RetriecePieces(uint32_t dwBreakStatus, | 558 bool CFDE_TextOut::RetriecePieces(uint32_t dwBreakStatus, |
559 int32_t& iStartChar, | 559 int32_t& iStartChar, |
560 int32_t& iPieceWidths, | 560 int32_t& iPieceWidths, |
561 FX_BOOL bReload, | 561 bool bReload, |
562 const CFX_RectF& rect) { | 562 const CFX_RectF& rect) { |
563 FX_BOOL bSingleLine = !!(m_dwStyles & FDE_TTOSTYLE_SingleLine); | 563 bool bSingleLine = !!(m_dwStyles & FDE_TTOSTYLE_SingleLine); |
564 FX_BOOL bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); | 564 bool bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); |
565 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); | 565 bool bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); |
566 FX_FLOAT fLineStep = | 566 FX_FLOAT fLineStep = |
567 (m_fLineSpace > m_fFontSize) ? m_fLineSpace : m_fFontSize; | 567 (m_fLineSpace > m_fFontSize) ? m_fLineSpace : m_fFontSize; |
568 if (bVertical) { | 568 if (bVertical) { |
569 fLineStep = -fLineStep; | 569 fLineStep = -fLineStep; |
570 } | 570 } |
571 CFX_Char* pTC = nullptr; | 571 CFX_Char* pTC = nullptr; |
572 FX_BOOL bNeedReload = FALSE; | 572 bool bNeedReload = false; |
573 FX_FLOAT fLineWidth = bVertical ? rect.Height() : rect.Width(); | 573 FX_FLOAT fLineWidth = bVertical ? rect.Height() : rect.Width(); |
574 int32_t iLineWidth = FXSYS_round(fLineWidth * 20000.0f); | 574 int32_t iLineWidth = FXSYS_round(fLineWidth * 20000.0f); |
575 int32_t iCount = m_pTxtBreak->CountBreakPieces(); | 575 int32_t iCount = m_pTxtBreak->CountBreakPieces(); |
576 for (int32_t i = 0; i < iCount; i++) { | 576 for (int32_t i = 0; i < iCount; i++) { |
577 const CFX_TxtPiece* pPiece = m_pTxtBreak->GetBreakPiece(i); | 577 const CFX_TxtPiece* pPiece = m_pTxtBreak->GetBreakPiece(i); |
578 int32_t iPieceChars = pPiece->GetLength(); | 578 int32_t iPieceChars = pPiece->GetLength(); |
579 int32_t iChar = iStartChar; | 579 int32_t iChar = iStartChar; |
580 int32_t iWidth = 0; | 580 int32_t iWidth = 0; |
581 int32_t j = 0; | 581 int32_t j = 0; |
582 for (; j < iPieceChars; j++) { | 582 for (; j < iPieceChars; j++) { |
583 pTC = pPiece->GetCharPtr(j); | 583 pTC = pPiece->GetCharPtr(j); |
584 int32_t iCurCharWidth = pTC->m_iCharWidth > 0 ? pTC->m_iCharWidth : 0; | 584 int32_t iCurCharWidth = pTC->m_iCharWidth > 0 ? pTC->m_iCharWidth : 0; |
585 if (bSingleLine || !bLineWrap) { | 585 if (bSingleLine || !bLineWrap) { |
586 if (iLineWidth - iPieceWidths - iWidth < iCurCharWidth) { | 586 if (iLineWidth - iPieceWidths - iWidth < iCurCharWidth) { |
587 bNeedReload = TRUE; | 587 bNeedReload = true; |
588 break; | 588 break; |
589 } | 589 } |
590 } | 590 } |
591 iWidth += iCurCharWidth; | 591 iWidth += iCurCharWidth; |
592 m_CharWidths[iChar++] = iCurCharWidth; | 592 m_CharWidths[iChar++] = iCurCharWidth; |
593 } | 593 } |
594 if (j == 0 && !bReload) { | 594 if (j == 0 && !bReload) { |
595 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(m_iCurLine); | 595 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(m_iCurLine); |
596 pLine->m_bNewReload = TRUE; | 596 pLine->m_bNewReload = true; |
597 } else if (j > 0) { | 597 } else if (j > 0) { |
598 CFX_RectF rtPiece; | 598 CFX_RectF rtPiece; |
599 if (bVertical) { | 599 if (bVertical) { |
600 rtPiece.left = m_fLinePos; | 600 rtPiece.left = m_fLinePos; |
601 rtPiece.top = rect.top + (FX_FLOAT)pPiece->m_iStartPos / 20000.0f; | 601 rtPiece.top = rect.top + (FX_FLOAT)pPiece->m_iStartPos / 20000.0f; |
602 rtPiece.width = fLineStep; | 602 rtPiece.width = fLineStep; |
603 rtPiece.height = iWidth / 20000.0f; | 603 rtPiece.height = iWidth / 20000.0f; |
604 } else { | 604 } else { |
605 rtPiece.left = rect.left + (FX_FLOAT)pPiece->m_iStartPos / 20000.0f; | 605 rtPiece.left = rect.left + (FX_FLOAT)pPiece->m_iStartPos / 20000.0f; |
606 rtPiece.top = m_fLinePos; | 606 rtPiece.top = m_fLinePos; |
607 rtPiece.width = iWidth / 20000.0f; | 607 rtPiece.width = iWidth / 20000.0f; |
608 rtPiece.height = fLineStep; | 608 rtPiece.height = fLineStep; |
609 } | 609 } |
610 FDE_TTOPIECE ttoPiece; | 610 FDE_TTOPIECE ttoPiece; |
611 ttoPiece.iStartChar = iStartChar; | 611 ttoPiece.iStartChar = iStartChar; |
612 ttoPiece.iChars = j; | 612 ttoPiece.iChars = j; |
613 ttoPiece.rtPiece = rtPiece; | 613 ttoPiece.rtPiece = rtPiece; |
614 ttoPiece.dwCharStyles = pPiece->m_dwCharStyles; | 614 ttoPiece.dwCharStyles = pPiece->m_dwCharStyles; |
615 if (FX_IsOdd(pPiece->m_iBidiLevel)) { | 615 if (FX_IsOdd(pPiece->m_iBidiLevel)) { |
616 ttoPiece.dwCharStyles |= FX_TXTCHARSTYLE_OddBidiLevel; | 616 ttoPiece.dwCharStyles |= FX_TXTCHARSTYLE_OddBidiLevel; |
617 } | 617 } |
618 AppendPiece(ttoPiece, bNeedReload, (bReload && i == iCount - 1)); | 618 AppendPiece(ttoPiece, bNeedReload, (bReload && i == iCount - 1)); |
619 } | 619 } |
620 iStartChar += iPieceChars; | 620 iStartChar += iPieceChars; |
621 iPieceWidths += iWidth; | 621 iPieceWidths += iWidth; |
622 } | 622 } |
623 m_pTxtBreak->ClearBreakPieces(); | 623 m_pTxtBreak->ClearBreakPieces(); |
624 FX_BOOL bRet = bSingleLine || bLineWrap || (!bLineWrap && bNeedReload) || | 624 bool bRet = bSingleLine || bLineWrap || (!bLineWrap && bNeedReload) || |
625 dwBreakStatus == FX_TXTBREAK_ParagraphBreak; | 625 dwBreakStatus == FX_TXTBREAK_ParagraphBreak; |
626 return bRet; | 626 return bRet; |
627 } | 627 } |
628 | 628 |
629 void CFDE_TextOut::AppendPiece(const FDE_TTOPIECE& ttoPiece, | 629 void CFDE_TextOut::AppendPiece(const FDE_TTOPIECE& ttoPiece, |
630 FX_BOOL bNeedReload, | 630 bool bNeedReload, |
631 FX_BOOL bEnd) { | 631 bool bEnd) { |
632 if (m_iCurLine >= m_ttoLines.GetSize()) { | 632 if (m_iCurLine >= m_ttoLines.GetSize()) { |
633 CFDE_TTOLine ttoLine; | 633 CFDE_TTOLine ttoLine; |
634 ttoLine.m_bNewReload = bNeedReload; | 634 ttoLine.m_bNewReload = bNeedReload; |
635 m_iCurPiece = ttoLine.AddPiece(m_iCurPiece, ttoPiece); | 635 m_iCurPiece = ttoLine.AddPiece(m_iCurPiece, ttoPiece); |
636 m_iCurLine = m_ttoLines.Add(ttoLine); | 636 m_iCurLine = m_ttoLines.Add(ttoLine); |
637 } else { | 637 } else { |
638 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(m_iCurLine); | 638 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(m_iCurLine); |
639 pLine->m_bNewReload = bNeedReload; | 639 pLine->m_bNewReload = bNeedReload; |
640 m_iCurPiece = pLine->AddPiece(m_iCurPiece, ttoPiece); | 640 m_iCurPiece = pLine->AddPiece(m_iCurPiece, ttoPiece); |
641 if (bEnd) { | 641 if (bEnd) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 continue; | 702 continue; |
703 | 703 |
704 m_iCurLine = i; | 704 m_iCurLine = i; |
705 m_iCurPiece = 0; | 705 m_iCurPiece = 0; |
706 ReloadLinePiece(pLine, rect); | 706 ReloadLinePiece(pLine, rect); |
707 } | 707 } |
708 } | 708 } |
709 | 709 |
710 void CFDE_TextOut::ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect) { | 710 void CFDE_TextOut::ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect) { |
711 const FX_WCHAR* pwsStr = m_wsText.c_str(); | 711 const FX_WCHAR* pwsStr = m_wsText.c_str(); |
712 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); | 712 bool bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); |
713 int32_t iPieceWidths = 0; | 713 int32_t iPieceWidths = 0; |
714 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(0); | 714 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(0); |
715 int32_t iStartChar = pPiece->iStartChar; | 715 int32_t iStartChar = pPiece->iStartChar; |
716 m_fLinePos = bVertical ? pPiece->rtPiece.left : pPiece->rtPiece.top; | 716 m_fLinePos = bVertical ? pPiece->rtPiece.left : pPiece->rtPiece.top; |
717 int32_t iPieceCount = pLine->GetSize(); | 717 int32_t iPieceCount = pLine->GetSize(); |
718 int32_t iPieceIndex = 0; | 718 int32_t iPieceIndex = 0; |
719 uint32_t dwBreakStatus = 0; | 719 uint32_t dwBreakStatus = 0; |
720 FX_WCHAR wch; | 720 FX_WCHAR wch; |
721 while (iPieceIndex < iPieceCount) { | 721 while (iPieceIndex < iPieceCount) { |
722 int32_t iStar = iStartChar; | 722 int32_t iStar = iStartChar; |
723 int32_t iEnd = pPiece->iChars + iStar; | 723 int32_t iEnd = pPiece->iChars + iStar; |
724 while (iStar < iEnd) { | 724 while (iStar < iEnd) { |
725 wch = *(pwsStr + iStar); | 725 wch = *(pwsStr + iStar); |
726 dwBreakStatus = m_pTxtBreak->AppendChar(wch); | 726 dwBreakStatus = m_pTxtBreak->AppendChar(wch); |
727 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { | 727 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { |
728 RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, TRUE, rect); | 728 RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, true, rect); |
729 } | 729 } |
730 iStar++; | 730 iStar++; |
731 } | 731 } |
732 iPieceIndex++; | 732 iPieceIndex++; |
733 pPiece = pLine->GetPtrAt(iPieceIndex); | 733 pPiece = pLine->GetPtrAt(iPieceIndex); |
734 } | 734 } |
735 dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | 735 dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); |
736 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { | 736 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { |
737 RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, TRUE, rect); | 737 RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, true, rect); |
738 } | 738 } |
739 m_pTxtBreak->Reset(); | 739 m_pTxtBreak->Reset(); |
740 } | 740 } |
741 | 741 |
742 void CFDE_TextOut::DoAlignment(const CFX_RectF& rect) { | 742 void CFDE_TextOut::DoAlignment(const CFX_RectF& rect) { |
743 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); | 743 bool bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); |
744 FX_FLOAT fLineStopS = bVertical ? rect.right() : rect.bottom(); | 744 FX_FLOAT fLineStopS = bVertical ? rect.right() : rect.bottom(); |
745 int32_t iLines = m_ttoLines.GetSize(); | 745 int32_t iLines = m_ttoLines.GetSize(); |
746 if (iLines < 1) | 746 if (iLines < 1) |
747 return; | 747 return; |
748 FDE_TTOPIECE* pFirstPiece = m_ttoLines.GetPtrAt(iLines - 1)->GetPtrAt(0); | 748 FDE_TTOPIECE* pFirstPiece = m_ttoLines.GetPtrAt(iLines - 1)->GetPtrAt(0); |
749 if (!pFirstPiece) | 749 if (!pFirstPiece) |
750 return; | 750 return; |
751 | 751 |
752 FX_FLOAT fLineStopD = | 752 FX_FLOAT fLineStopD = |
753 bVertical ? pFirstPiece->rtPiece.right() : pFirstPiece->rtPiece.bottom(); | 753 bVertical ? pFirstPiece->rtPiece.right() : pFirstPiece->rtPiece.bottom(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 tr.pFont = m_pFont; | 829 tr.pFont = m_pFont; |
830 tr.fFontSize = m_fFontSize; | 830 tr.fFontSize = m_fFontSize; |
831 tr.dwStyles = m_dwTxtBkStyles; | 831 tr.dwStyles = m_dwTxtBkStyles; |
832 tr.dwCharStyles = pPiece->dwCharStyles; | 832 tr.dwCharStyles = pPiece->dwCharStyles; |
833 tr.wLineBreakChar = m_wParagraphBkChar; | 833 tr.wLineBreakChar = m_wParagraphBkChar; |
834 tr.pRect = &pPiece->rtPiece; | 834 tr.pRect = &pPiece->rtPiece; |
835 return tr; | 835 return tr; |
836 } | 836 } |
837 | 837 |
838 void CFDE_TextOut::DrawLine(const FDE_TTOPIECE* pPiece, CFDE_Pen*& pPen) { | 838 void CFDE_TextOut::DrawLine(const FDE_TTOPIECE* pPiece, CFDE_Pen*& pPen) { |
839 FX_BOOL bUnderLine = !!(m_dwStyles & FDE_TTOSTYLE_Underline); | 839 bool bUnderLine = !!(m_dwStyles & FDE_TTOSTYLE_Underline); |
840 FX_BOOL bStrikeOut = !!(m_dwStyles & FDE_TTOSTYLE_Strikeout); | 840 bool bStrikeOut = !!(m_dwStyles & FDE_TTOSTYLE_Strikeout); |
841 FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); | 841 bool bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); |
842 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); | 842 bool bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); |
843 if (!bUnderLine && !bStrikeOut && !bHotKey) | 843 if (!bUnderLine && !bStrikeOut && !bHotKey) |
844 return; | 844 return; |
845 | 845 |
846 if (!pPen) { | 846 if (!pPen) { |
847 pPen = new CFDE_Pen; | 847 pPen = new CFDE_Pen; |
848 pPen->SetColor(m_TxtColor); | 848 pPen->SetColor(m_TxtColor); |
849 } | 849 } |
850 std::unique_ptr<CFDE_Path> pPath(new CFDE_Path); | 850 std::unique_ptr<CFDE_Path> pPath(new CFDE_Path); |
851 int32_t iLineCount = 0; | 851 int32_t iLineCount = 0; |
852 CFX_RectF rtText = pPiece->rtPiece; | 852 CFX_RectF rtText = pPiece->rtPiece; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 iLineCount++; | 905 iLineCount++; |
906 } | 906 } |
907 } | 907 } |
908 } | 908 } |
909 } | 909 } |
910 if (iLineCount > 0) | 910 if (iLineCount > 0) |
911 m_pRenderDevice->DrawPath(pPen, 1, pPath.get(), &m_Matrix); | 911 m_pRenderDevice->DrawPath(pPen, 1, pPath.get(), &m_Matrix); |
912 } | 912 } |
913 | 913 |
914 CFDE_TTOLine::CFDE_TTOLine() | 914 CFDE_TTOLine::CFDE_TTOLine() |
915 : m_bNewReload(FALSE), m_pieces(5), m_iPieceCount(0) {} | 915 : m_bNewReload(false), m_pieces(5), m_iPieceCount(0) {} |
916 | 916 |
917 CFDE_TTOLine::CFDE_TTOLine(const CFDE_TTOLine& ttoLine) : m_pieces(5) { | 917 CFDE_TTOLine::CFDE_TTOLine(const CFDE_TTOLine& ttoLine) : m_pieces(5) { |
918 m_bNewReload = ttoLine.m_bNewReload; | 918 m_bNewReload = ttoLine.m_bNewReload; |
919 m_iPieceCount = ttoLine.m_iPieceCount; | 919 m_iPieceCount = ttoLine.m_iPieceCount; |
920 m_pieces.Copy(ttoLine.m_pieces, 0, -1); | 920 m_pieces.Copy(ttoLine.m_pieces, 0, -1); |
921 } | 921 } |
922 | 922 |
923 CFDE_TTOLine::~CFDE_TTOLine() {} | 923 CFDE_TTOLine::~CFDE_TTOLine() {} |
924 | 924 |
925 int32_t CFDE_TTOLine::AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece) { | 925 int32_t CFDE_TTOLine::AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece) { |
(...skipping 15 matching lines...) Expand all Loading... |
941 if (index >= m_iPieceCount) { | 941 if (index >= m_iPieceCount) { |
942 return nullptr; | 942 return nullptr; |
943 } | 943 } |
944 return m_pieces.GetPtrAt(index); | 944 return m_pieces.GetPtrAt(index); |
945 } | 945 } |
946 | 946 |
947 void CFDE_TTOLine::RemoveLast(int32_t iCount) { | 947 void CFDE_TTOLine::RemoveLast(int32_t iCount) { |
948 m_pieces.RemoveLast(iCount); | 948 m_pieces.RemoveLast(iCount); |
949 } | 949 } |
950 | 950 |
951 void CFDE_TTOLine::RemoveAll(FX_BOOL bLeaveMemory) { | 951 void CFDE_TTOLine::RemoveAll(bool bLeaveMemory) { |
952 m_pieces.RemoveAll(bLeaveMemory); | 952 m_pieces.RemoveAll(bLeaveMemory); |
953 } | 953 } |
OLD | NEW |