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

Side by Side Diff: xfa/fgas/layout/fgas_rtfbreak.cpp

Issue 2362063003: Clean up xfa_fontmgr.cpp. (Closed)
Patch Set: nits Created 4 years, 2 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/fgas/layout/fgas_rtfbreak.h ('k') | xfa/fgas/layout/fgas_textbreak.cpp » ('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/fgas/layout/fgas_rtfbreak.h" 7 #include "xfa/fgas/layout/fgas_rtfbreak.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "core/fxcrt/include/fx_arabic.h" 11 #include "core/fxcrt/include/fx_arabic.h"
12 #include "core/fxcrt/include/fx_arb.h" 12 #include "core/fxcrt/include/fx_arb.h"
13 #include "xfa/fgas/font/fgas_gefont.h" 13 #include "xfa/fgas/font/fgas_gefont.h"
14 #include "xfa/fgas/layout/fgas_linebreak.h" 14 #include "xfa/fgas/layout/fgas_linebreak.h"
15 #include "xfa/fgas/layout/fgas_unicode.h" 15 #include "xfa/fgas/layout/fgas_unicode.h"
16 16
17 CFX_RTFBreak::CFX_RTFBreak(uint32_t dwPolicies) 17 CFX_RTFBreak::CFX_RTFBreak(uint32_t dwPolicies)
18 : m_dwPolicies(dwPolicies), 18 : m_dwPolicies(dwPolicies),
19 m_iBoundaryStart(0), 19 m_iBoundaryStart(0),
20 m_iBoundaryEnd(2000000), 20 m_iBoundaryEnd(2000000),
21 m_dwLayoutStyles(0), 21 m_dwLayoutStyles(0),
22 m_bPagination(FALSE), 22 m_bPagination(false),
23 m_bVertical(FALSE), 23 m_bVertical(false),
24 m_bSingleLine(FALSE), 24 m_bSingleLine(false),
25 m_bCharCode(FALSE), 25 m_bCharCode(false),
26 m_pFont(nullptr), 26 m_pFont(nullptr),
27 m_iFontHeight(240), 27 m_iFontHeight(240),
28 m_iFontSize(240), 28 m_iFontSize(240),
29 m_iTabWidth(720000), 29 m_iTabWidth(720000),
30 m_PositionedTabs(), 30 m_PositionedTabs(),
31 m_bOrphanLine(FALSE), 31 m_bOrphanLine(FALSE),
32 m_wDefChar(0xFEFF), 32 m_wDefChar(0xFEFF),
33 m_iDefChar(0), 33 m_iDefChar(0),
34 m_wLineBreakChar(L'\n'), 34 m_wLineBreakChar(L'\n'),
35 m_iHorizontalScale(100), 35 m_iHorizontalScale(100),
36 m_iVerticalScale(100), 36 m_iVerticalScale(100),
37 m_iLineRotation(0), 37 m_iLineRotation(0),
38 m_iCharRotation(0), 38 m_iCharRotation(0),
39 m_iRotation(0), 39 m_iRotation(0),
40 m_iCharSpace(0), 40 m_iCharSpace(0),
41 m_bWordSpace(FALSE), 41 m_bWordSpace(FALSE),
42 m_iWordSpace(0), 42 m_iWordSpace(0),
43 m_bRTL(FALSE), 43 m_bRTL(FALSE),
44 m_iAlignment(FX_RTFLINEALIGNMENT_Left), 44 m_iAlignment(FX_RTFLINEALIGNMENT_Left),
45 m_pUserData(nullptr), 45 m_pUserData(nullptr),
46 m_eCharType(FX_CHARTYPE_Unknown), 46 m_eCharType(FX_CHARTYPE_Unknown),
47 m_dwIdentity(0), 47 m_dwIdentity(0),
48 m_RTFLine1(), 48 m_RTFLine1(),
49 m_RTFLine2(), 49 m_RTFLine2(),
50 m_pCurLine(nullptr), 50 m_pCurLine(nullptr),
51 m_iReady(0), 51 m_iReady(0),
52 m_iTolerance(0) { 52 m_iTolerance(0) {
53 m_pCurLine = &m_RTFLine1; 53 m_pCurLine = &m_RTFLine1;
54 } 54 }
55
55 CFX_RTFBreak::~CFX_RTFBreak() { 56 CFX_RTFBreak::~CFX_RTFBreak() {
56 Reset(); 57 Reset();
57 m_PositionedTabs.RemoveAll(); 58 m_PositionedTabs.RemoveAll();
58 if (m_pUserData) { 59 if (m_pUserData)
59 m_pUserData->Release(); 60 m_pUserData->Release();
60 }
61 } 61 }
62
62 void CFX_RTFBreak::SetLineBoundary(FX_FLOAT fLineStart, FX_FLOAT fLineEnd) { 63 void CFX_RTFBreak::SetLineBoundary(FX_FLOAT fLineStart, FX_FLOAT fLineEnd) {
63 if (fLineStart > fLineEnd) 64 if (fLineStart > fLineEnd)
64 return; 65 return;
66
65 m_iBoundaryStart = FXSYS_round(fLineStart * 20000.0f); 67 m_iBoundaryStart = FXSYS_round(fLineStart * 20000.0f);
66 m_iBoundaryEnd = FXSYS_round(fLineEnd * 20000.0f); 68 m_iBoundaryEnd = FXSYS_round(fLineEnd * 20000.0f);
67 m_pCurLine->m_iStart = std::min(m_pCurLine->m_iStart, m_iBoundaryEnd); 69 m_pCurLine->m_iStart = std::min(m_pCurLine->m_iStart, m_iBoundaryEnd);
68 m_pCurLine->m_iStart = std::max(m_pCurLine->m_iStart, m_iBoundaryStart); 70 m_pCurLine->m_iStart = std::max(m_pCurLine->m_iStart, m_iBoundaryStart);
69 } 71 }
72
70 void CFX_RTFBreak::SetLineStartPos(FX_FLOAT fLinePos) { 73 void CFX_RTFBreak::SetLineStartPos(FX_FLOAT fLinePos) {
71 int32_t iLinePos = FXSYS_round(fLinePos * 20000.0f); 74 int32_t iLinePos = FXSYS_round(fLinePos * 20000.0f);
72 iLinePos = std::min(iLinePos, m_iBoundaryEnd); 75 iLinePos = std::min(iLinePos, m_iBoundaryEnd);
73 iLinePos = std::max(iLinePos, m_iBoundaryStart); 76 iLinePos = std::max(iLinePos, m_iBoundaryStart);
74 m_pCurLine->m_iStart = iLinePos; 77 m_pCurLine->m_iStart = iLinePos;
75 } 78 }
79
76 void CFX_RTFBreak::SetLayoutStyles(uint32_t dwLayoutStyles) { 80 void CFX_RTFBreak::SetLayoutStyles(uint32_t dwLayoutStyles) {
77 if (m_dwLayoutStyles == dwLayoutStyles) { 81 if (m_dwLayoutStyles == dwLayoutStyles)
78 return; 82 return;
79 } 83
80 SetBreakStatus(); 84 SetBreakStatus();
81 m_dwLayoutStyles = dwLayoutStyles; 85 m_dwLayoutStyles = dwLayoutStyles;
82 m_bPagination = (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_Pagination) != 0; 86 m_bPagination = (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_Pagination) != 0;
83 m_bVertical = (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_VerticalChars) != 0; 87 m_bVertical = (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_VerticalChars) != 0;
84 m_bSingleLine = (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_SingleLine) != 0; 88 m_bSingleLine = (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_SingleLine) != 0;
85 m_bCharCode = (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_MBCSCode) != 0; 89 m_bCharCode = (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_MBCSCode) != 0;
86 m_iLineRotation = GetLineRotation(m_dwLayoutStyles); 90 m_iLineRotation = GetLineRotation(m_dwLayoutStyles);
87 m_iRotation = m_iLineRotation + m_iCharRotation; 91 m_iRotation = m_iLineRotation + m_iCharRotation;
88 m_iRotation %= 4; 92 m_iRotation %= 4;
89 } 93 }
94
90 void CFX_RTFBreak::SetFont(CFGAS_GEFont* pFont) { 95 void CFX_RTFBreak::SetFont(CFGAS_GEFont* pFont) {
91 if (!pFont) { 96 if (!pFont) {
92 return; 97 return;
93 } 98 }
94 if (m_pFont == pFont) { 99 if (m_pFont == pFont) {
95 return; 100 return;
96 } 101 }
97 SetBreakStatus(); 102 SetBreakStatus();
98 m_pFont = pFont; 103 m_pFont = pFont;
99 m_iDefChar = 0; 104 m_iDefChar = 0;
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Control, 338 &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Control,
334 &CFX_RTFBreak::AppendChar_Combination, &CFX_RTFBreak::AppendChar_Others, 339 &CFX_RTFBreak::AppendChar_Combination, &CFX_RTFBreak::AppendChar_Others,
335 &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Arabic, 340 &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Arabic,
336 &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Arabic, 341 &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Arabic,
337 &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Arabic, 342 &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Arabic,
338 &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Others, 343 &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Others,
339 &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Others, 344 &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Others,
340 }; 345 };
341 uint32_t CFX_RTFBreak::AppendChar(FX_WCHAR wch) { 346 uint32_t CFX_RTFBreak::AppendChar(FX_WCHAR wch) {
342 ASSERT(m_pFont && m_pCurLine); 347 ASSERT(m_pFont && m_pCurLine);
343 if (m_bCharCode) { 348 if (m_bCharCode)
344 return AppendChar_CharCode(wch); 349 return AppendChar_CharCode(wch);
345 } 350
346 uint32_t dwProps = kTextLayoutCodeProperties[(uint16_t)wch]; 351 uint32_t dwProps = kTextLayoutCodeProperties[(uint16_t)wch];
347 FX_CHARTYPE chartype = GetCharTypeFromProp(dwProps); 352 FX_CHARTYPE chartype = GetCharTypeFromProp(dwProps);
348 CFX_RTFCharArray& tca = m_pCurLine->m_LineChars; 353 CFX_RTFCharArray& tca = m_pCurLine->m_LineChars;
349 CFX_RTFChar* pCurChar = tca.AddSpace(); 354 CFX_RTFChar* pCurChar = tca.AddSpace();
350 pCurChar->m_dwStatus = 0; 355 pCurChar->m_dwStatus = 0;
351 pCurChar->m_wCharCode = wch; 356 pCurChar->m_wCharCode = wch;
352 pCurChar->m_dwCharProps = dwProps; 357 pCurChar->m_dwCharProps = dwProps;
353 pCurChar->m_dwCharStyles = 0; 358 pCurChar->m_dwCharStyles = 0;
354 pCurChar->m_dwLayoutStyles = 0; 359 pCurChar->m_dwLayoutStyles = 0;
355 pCurChar->m_iFontSize = m_iFontSize; 360 pCurChar->m_iFontSize = m_iFontSize;
(...skipping 25 matching lines...) Expand all
381 int32_t iRotation = m_iRotation; 386 int32_t iRotation = m_iRotation;
382 if (m_bVertical && (dwProps & 0x8000) != 0) { 387 if (m_bVertical && (dwProps & 0x8000) != 0) {
383 iRotation = (iRotation + 1) % 4; 388 iRotation = (iRotation + 1) % 4;
384 } 389 }
385 uint32_t dwRet2 = 390 uint32_t dwRet2 =
386 (this->*g_FX_RTFBreak_lpfAppendChar[chartype >> FX_CHARTYPEBITS])( 391 (this->*g_FX_RTFBreak_lpfAppendChar[chartype >> FX_CHARTYPEBITS])(
387 pCurChar, iRotation); 392 pCurChar, iRotation);
388 m_eCharType = chartype; 393 m_eCharType = chartype;
389 return std::max(dwRet1, dwRet2); 394 return std::max(dwRet1, dwRet2);
390 } 395 }
396
391 uint32_t CFX_RTFBreak::AppendChar_CharCode(FX_WCHAR wch) { 397 uint32_t CFX_RTFBreak::AppendChar_CharCode(FX_WCHAR wch) {
392 ASSERT(m_pFont && m_pCurLine); 398 ASSERT(m_pFont && m_pCurLine);
393 ASSERT(m_bCharCode); 399 ASSERT(m_bCharCode);
394 m_pCurLine->m_iMBCSChars++; 400 m_pCurLine->m_iMBCSChars++;
395 CFX_RTFCharArray& tca = m_pCurLine->m_LineChars; 401 CFX_RTFCharArray& tca = m_pCurLine->m_LineChars;
396 CFX_RTFChar* pCurChar = tca.AddSpace(); 402 CFX_RTFChar* pCurChar = tca.AddSpace();
397 pCurChar->m_dwStatus = 0; 403 pCurChar->m_dwStatus = 0;
398 pCurChar->m_wCharCode = wch; 404 pCurChar->m_wCharCode = wch;
399 pCurChar->m_dwCharProps = 0; 405 pCurChar->m_dwCharProps = 0;
400 pCurChar->m_dwCharStyles = 0; 406 pCurChar->m_dwCharStyles = 0;
401 pCurChar->m_dwLayoutStyles = m_dwLayoutStyles; 407 pCurChar->m_dwLayoutStyles = m_dwLayoutStyles;
402 pCurChar->m_iFontSize = m_iFontSize; 408 pCurChar->m_iFontSize = m_iFontSize;
403 pCurChar->m_iFontHeight = m_iFontHeight; 409 pCurChar->m_iFontHeight = m_iFontHeight;
404 pCurChar->m_iHorizontalScale = m_iHorizontalScale; 410 pCurChar->m_iHorizontalScale = m_iHorizontalScale;
405 pCurChar->m_iVertialScale = m_iVerticalScale; 411 pCurChar->m_iVertialScale = m_iVerticalScale;
406 pCurChar->m_nRotation = m_iCharRotation; 412 pCurChar->m_nRotation = m_iCharRotation;
407 pCurChar->m_iCharWidth = 0; 413 pCurChar->m_iCharWidth = 0;
408 pCurChar->m_dwIdentity = m_dwIdentity; 414 pCurChar->m_dwIdentity = m_dwIdentity;
409 if (m_pUserData) { 415 if (m_pUserData)
410 m_pUserData->Retain(); 416 m_pUserData->Retain();
411 } 417
412 pCurChar->m_pUserData = m_pUserData; 418 pCurChar->m_pUserData = m_pUserData;
413 int32_t iCharWidth = 0; 419 int32_t iCharWidth = 0;
414 if (m_bVertical != FX_IsOdd(m_iRotation)) { 420 if (m_bVertical != FX_IsOdd(m_iRotation)) {
415 iCharWidth = 1000; 421 iCharWidth = 1000;
416 } else { 422 } else {
417 if (!m_pFont->GetCharWidth(wch, iCharWidth, TRUE)) { 423 if (!m_pFont->GetCharWidth(wch, iCharWidth, TRUE)) {
418 iCharWidth = m_iDefChar; 424 iCharWidth = m_iDefChar;
419 } 425 }
420 } 426 }
421 iCharWidth *= m_iFontSize; 427 iCharWidth *= m_iFontSize;
422 iCharWidth = iCharWidth * m_iHorizontalScale / 100; 428 iCharWidth = iCharWidth * m_iHorizontalScale / 100;
423 iCharWidth += m_iCharSpace; 429 iCharWidth += m_iCharSpace;
424 pCurChar->m_iCharWidth = iCharWidth; 430 pCurChar->m_iCharWidth = iCharWidth;
425 m_pCurLine->m_iWidth += iCharWidth; 431 m_pCurLine->m_iWidth += iCharWidth;
426 m_eCharType = FX_CHARTYPE_Unknown; 432 m_eCharType = FX_CHARTYPE_Unknown;
427 if (!m_bSingleLine && 433 if (!m_bSingleLine &&
428 m_pCurLine->GetLineEnd() > m_iBoundaryEnd + m_iTolerance) { 434 m_pCurLine->GetLineEnd() > m_iBoundaryEnd + m_iTolerance) {
429 return EndBreak(FX_RTFBREAK_LineBreak); 435 return EndBreak(FX_RTFBREAK_LineBreak);
430 } 436 }
431 return FX_RTFBREAK_None; 437 return FX_RTFBREAK_None;
432 } 438 }
439
433 uint32_t CFX_RTFBreak::AppendChar_Combination(CFX_RTFChar* pCurChar, 440 uint32_t CFX_RTFBreak::AppendChar_Combination(CFX_RTFChar* pCurChar,
434 int32_t iRotation) { 441 int32_t iRotation) {
435 int32_t iCharWidth = 0; 442 int32_t iCharWidth = 0;
436 if (m_bVertical != FX_IsOdd(iRotation)) { 443 if (m_bVertical != FX_IsOdd(iRotation)) {
437 iCharWidth = 1000; 444 iCharWidth = 1000;
438 } else { 445 } else {
439 if (!m_pFont->GetCharWidth(pCurChar->m_wCharCode, iCharWidth, 446 if (!m_pFont->GetCharWidth(pCurChar->m_wCharCode, iCharWidth,
440 m_bCharCode)) { 447 m_bCharCode)) {
441 iCharWidth = 0; 448 iCharWidth = 0;
442 } 449 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 dwRet2 = FX_RTFBREAK_ParagraphBreak; 504 dwRet2 = FX_RTFBREAK_ParagraphBreak;
498 } 505 }
499 break; 506 break;
500 } 507 }
501 if (dwRet2 != FX_RTFBREAK_None) { 508 if (dwRet2 != FX_RTFBREAK_None) {
502 dwRet2 = EndBreak(dwRet2); 509 dwRet2 = EndBreak(dwRet2);
503 } 510 }
504 } 511 }
505 return dwRet2; 512 return dwRet2;
506 } 513 }
514
507 uint32_t CFX_RTFBreak::AppendChar_Arabic(CFX_RTFChar* pCurChar, 515 uint32_t CFX_RTFBreak::AppendChar_Arabic(CFX_RTFChar* pCurChar,
508 int32_t iRotation) { 516 int32_t iRotation) {
509 CFX_RTFChar* pLastChar = nullptr; 517 CFX_RTFChar* pLastChar = nullptr;
510 int32_t& iLineWidth = m_pCurLine->m_iWidth; 518 int32_t& iLineWidth = m_pCurLine->m_iWidth;
511 int32_t iCharWidth = 0; 519 int32_t iCharWidth = 0;
512 FX_WCHAR wForm; 520 FX_WCHAR wForm;
513 FX_BOOL bAlef = FALSE; 521 FX_BOOL bAlef = FALSE;
514 if (m_eCharType >= FX_CHARTYPE_ArabicAlef && 522 if (m_eCharType >= FX_CHARTYPE_ArabicAlef &&
515 m_eCharType <= FX_CHARTYPE_ArabicDistortion) { 523 m_eCharType <= FX_CHARTYPE_ArabicDistortion) {
516 pLastChar = GetLastChar(1); 524 pLastChar = GetLastChar(1);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 iCharWidth = iCharWidth * m_iHorizontalScale / 100; 563 iCharWidth = iCharWidth * m_iHorizontalScale / 100;
556 pCurChar->m_iCharWidth = iCharWidth; 564 pCurChar->m_iCharWidth = iCharWidth;
557 iLineWidth += iCharWidth; 565 iLineWidth += iCharWidth;
558 m_pCurLine->m_iArabicChars++; 566 m_pCurLine->m_iArabicChars++;
559 if (!m_bSingleLine && !m_bOrphanLine && 567 if (!m_bSingleLine && !m_bOrphanLine &&
560 m_pCurLine->GetLineEnd() > m_iBoundaryEnd + m_iTolerance) { 568 m_pCurLine->GetLineEnd() > m_iBoundaryEnd + m_iTolerance) {
561 return EndBreak(FX_RTFBREAK_LineBreak); 569 return EndBreak(FX_RTFBREAK_LineBreak);
562 } 570 }
563 return FX_RTFBREAK_None; 571 return FX_RTFBREAK_None;
564 } 572 }
573
565 uint32_t CFX_RTFBreak::AppendChar_Others(CFX_RTFChar* pCurChar, 574 uint32_t CFX_RTFBreak::AppendChar_Others(CFX_RTFChar* pCurChar,
566 int32_t iRotation) { 575 int32_t iRotation) {
567 FX_CHARTYPE chartype = pCurChar->GetCharType(); 576 FX_CHARTYPE chartype = pCurChar->GetCharType();
568 FX_WCHAR wForm; 577 FX_WCHAR wForm;
569 if (chartype == FX_CHARTYPE_Numeric) { 578 if (chartype == FX_CHARTYPE_Numeric) {
570 if (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_ArabicNumber) { 579 if (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_ArabicNumber)
571 wForm = pCurChar->m_wCharCode + 0x0630; 580 wForm = pCurChar->m_wCharCode + 0x0630;
572 } else { 581 else
573 wForm = pCurChar->m_wCharCode; 582 wForm = pCurChar->m_wCharCode;
574 }
575 } else if (m_bRTL || m_bVertical) { 583 } else if (m_bRTL || m_bVertical) {
576 wForm = FX_GetMirrorChar(pCurChar->m_wCharCode, pCurChar->m_dwCharProps, 584 wForm = FX_GetMirrorChar(pCurChar->m_wCharCode, pCurChar->m_dwCharProps,
577 m_bRTL, m_bVertical); 585 m_bRTL, m_bVertical);
578 } else { 586 } else {
579 wForm = pCurChar->m_wCharCode; 587 wForm = pCurChar->m_wCharCode;
580 } 588 }
581 int32_t iCharWidth = 0; 589 int32_t iCharWidth = 0;
582 if (m_bVertical != FX_IsOdd(iRotation)) { 590 if (m_bVertical == FX_IsOdd(iRotation)) {
591 if (!m_pFont->GetCharWidth(wForm, iCharWidth, m_bCharCode))
592 iCharWidth = m_iDefChar;
593 } else {
583 iCharWidth = 1000; 594 iCharWidth = 1000;
584 } else {
585 if (!m_pFont->GetCharWidth(wForm, iCharWidth, m_bCharCode)) {
586 iCharWidth = m_iDefChar;
587 }
588 } 595 }
589 iCharWidth *= m_iFontSize; 596 iCharWidth *= m_iFontSize;
590 iCharWidth = iCharWidth * m_iHorizontalScale / 100; 597 iCharWidth *= m_iHorizontalScale / 100;
591 iCharWidth += m_iCharSpace; 598 iCharWidth += m_iCharSpace;
592 if (chartype == FX_CHARTYPE_Space && m_bWordSpace) { 599 if (chartype == FX_CHARTYPE_Space && m_bWordSpace)
593 iCharWidth += m_iWordSpace; 600 iCharWidth += m_iWordSpace;
594 } 601
595 pCurChar->m_iCharWidth = iCharWidth; 602 pCurChar->m_iCharWidth = iCharWidth;
596 m_pCurLine->m_iWidth += iCharWidth; 603 m_pCurLine->m_iWidth += iCharWidth;
597 FX_BOOL bBreak = (chartype != FX_CHARTYPE_Space || 604 bool bBreak = (chartype != FX_CHARTYPE_Space ||
598 (m_dwPolicies & FX_RTFBREAKPOLICY_SpaceBreak) != 0); 605 (m_dwPolicies & FX_RTFBREAKPOLICY_SpaceBreak) != 0);
599 if (!m_bSingleLine && !m_bOrphanLine && bBreak && 606 if (!m_bSingleLine && !m_bOrphanLine && bBreak &&
600 m_pCurLine->GetLineEnd() > m_iBoundaryEnd + m_iTolerance) { 607 m_pCurLine->GetLineEnd() > m_iBoundaryEnd + m_iTolerance) {
601 return EndBreak(FX_RTFBREAK_LineBreak); 608 return EndBreak(FX_RTFBREAK_LineBreak);
602 } 609 }
603 return FX_RTFBREAK_None; 610 return FX_RTFBREAK_None;
604 } 611 }
612
605 uint32_t CFX_RTFBreak::EndBreak(uint32_t dwStatus) { 613 uint32_t CFX_RTFBreak::EndBreak(uint32_t dwStatus) {
606 ASSERT(dwStatus >= FX_RTFBREAK_PieceBreak && 614 ASSERT(dwStatus >= FX_RTFBREAK_PieceBreak &&
607 dwStatus <= FX_RTFBREAK_PageBreak); 615 dwStatus <= FX_RTFBREAK_PageBreak);
608 m_dwIdentity++; 616 m_dwIdentity++;
609 CFX_RTFPieceArray* pCurPieces = &m_pCurLine->m_LinePieces; 617 CFX_RTFPieceArray* pCurPieces = &m_pCurLine->m_LinePieces;
610 int32_t iCount = pCurPieces->GetSize(); 618 int32_t iCount = pCurPieces->GetSize();
611 if (iCount > 0) { 619 if (iCount > 0) {
612 CFX_RTFPiece* pLastPiece = pCurPieces->GetPtrAt(--iCount); 620 CFX_RTFPiece* pLastPiece = pCurPieces->GetPtrAt(--iCount);
613 if (dwStatus > FX_RTFBREAK_PieceBreak) { 621 if (dwStatus > FX_RTFBREAK_PieceBreak)
614 pLastPiece->m_dwStatus = dwStatus; 622 pLastPiece->m_dwStatus = dwStatus;
615 } else { 623 else
616 dwStatus = pLastPiece->m_dwStatus; 624 dwStatus = pLastPiece->m_dwStatus;
617 }
618 return dwStatus; 625 return dwStatus;
619 } else { 626 }
620 CFX_RTFLine* pLastLine = GetRTFLine(TRUE); 627
621 if (pLastLine) { 628 CFX_RTFLine* pLastLine = GetRTFLine(TRUE);
622 pCurPieces = &pLastLine->m_LinePieces; 629 if (pLastLine) {
623 iCount = pCurPieces->GetSize(); 630 pCurPieces = &pLastLine->m_LinePieces;
624 if (iCount-- > 0) { 631 iCount = pCurPieces->GetSize();
625 CFX_RTFPiece* pLastPiece = pCurPieces->GetPtrAt(iCount); 632 if (iCount-- > 0) {
626 if (dwStatus > FX_RTFBREAK_PieceBreak) { 633 CFX_RTFPiece* pLastPiece = pCurPieces->GetPtrAt(iCount);
627 pLastPiece->m_dwStatus = dwStatus; 634 if (dwStatus > FX_RTFBREAK_PieceBreak)
628 } else { 635 pLastPiece->m_dwStatus = dwStatus;
629 dwStatus = pLastPiece->m_dwStatus; 636 else
630 } 637 dwStatus = pLastPiece->m_dwStatus;
631 return dwStatus;
632 }
633 return FX_RTFBREAK_None;
634 }
635 iCount = m_pCurLine->CountChars();
636 if (iCount < 1) {
637 return FX_RTFBREAK_None;
638 }
639 CFX_RTFChar& tc = m_pCurLine->GetChar(iCount - 1);
640 tc.m_dwStatus = dwStatus;
641 if (dwStatus <= FX_RTFBREAK_PieceBreak) {
642 return dwStatus; 638 return dwStatus;
643 } 639 }
640 return FX_RTFBREAK_None;
644 } 641 }
642 iCount = m_pCurLine->CountChars();
643 if (iCount < 1)
644 return FX_RTFBREAK_None;
645
646 CFX_RTFChar& tc = m_pCurLine->GetChar(iCount - 1);
647 tc.m_dwStatus = dwStatus;
648 if (dwStatus <= FX_RTFBREAK_PieceBreak)
649 return dwStatus;
650
645 m_iReady = (m_pCurLine == &m_RTFLine1) ? 1 : 2; 651 m_iReady = (m_pCurLine == &m_RTFLine1) ? 1 : 2;
646 CFX_RTFLine* pNextLine = 652 CFX_RTFLine* pNextLine =
647 (m_pCurLine == &m_RTFLine1) ? &m_RTFLine2 : &m_RTFLine1; 653 (m_pCurLine == &m_RTFLine1) ? &m_RTFLine2 : &m_RTFLine1;
648 FX_BOOL bAllChars = (m_iAlignment > FX_RTFLINEALIGNMENT_Right); 654 FX_BOOL bAllChars = (m_iAlignment > FX_RTFLINEALIGNMENT_Right);
649 CFX_TPOArray tpos(100); 655 CFX_TPOArray tpos(100);
650 if (EndBreak_SplitLine(pNextLine, bAllChars, dwStatus)) { 656 if (!EndBreak_SplitLine(pNextLine, bAllChars, dwStatus)) {
651 goto EndBreak_Ret; 657 if (!m_bCharCode)
658 EndBreak_BidiLine(tpos, dwStatus);
659
660 if (!m_bPagination && m_iAlignment > FX_RTFLINEALIGNMENT_Left)
661 EndBreak_Alignment(tpos, bAllChars, dwStatus);
652 } 662 }
653 if (!m_bCharCode) { 663
654 EndBreak_BidiLine(tpos, dwStatus);
655 }
656 if (!m_bPagination && m_iAlignment > FX_RTFLINEALIGNMENT_Left) {
657 EndBreak_Alignment(tpos, bAllChars, dwStatus);
658 }
659 EndBreak_Ret:
660 m_pCurLine = pNextLine; 664 m_pCurLine = pNextLine;
661 m_pCurLine->m_iStart = m_iBoundaryStart; 665 m_pCurLine->m_iStart = m_iBoundaryStart;
662 CFX_RTFChar* pTC = GetLastChar(0); 666 CFX_RTFChar* pTC = GetLastChar(0);
663 m_eCharType = pTC ? pTC->GetCharType() : FX_CHARTYPE_Unknown; 667 m_eCharType = pTC ? pTC->GetCharType() : FX_CHARTYPE_Unknown;
664 return dwStatus; 668 return dwStatus;
665 } 669 }
670
666 FX_BOOL CFX_RTFBreak::EndBreak_SplitLine(CFX_RTFLine* pNextLine, 671 FX_BOOL CFX_RTFBreak::EndBreak_SplitLine(CFX_RTFLine* pNextLine,
667 FX_BOOL bAllChars, 672 FX_BOOL bAllChars,
668 uint32_t dwStatus) { 673 uint32_t dwStatus) {
669 FX_BOOL bDone = FALSE; 674 FX_BOOL bDone = FALSE;
670 if (!m_bSingleLine && !m_bOrphanLine && 675 if (!m_bSingleLine && !m_bOrphanLine &&
671 m_pCurLine->GetLineEnd() > m_iBoundaryEnd + m_iTolerance) { 676 m_pCurLine->GetLineEnd() > m_iBoundaryEnd + m_iTolerance) {
672 CFX_RTFChar& tc = m_pCurLine->GetChar(m_pCurLine->CountChars() - 1); 677 CFX_RTFChar& tc = m_pCurLine->GetChar(m_pCurLine->CountChars() - 1);
673 switch (tc.GetCharType()) { 678 switch (tc.GetCharType()) {
674 case FX_CHARTYPE_Tab: 679 case FX_CHARTYPE_Tab:
675 if ((m_dwPolicies & FX_RTFBREAKPOLICY_TabBreak) != 0) { 680 if ((m_dwPolicies & FX_RTFBREAKPOLICY_TabBreak) != 0) {
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 iOffset /= 2; 926 iOffset /= 2;
922 } 927 }
923 if (iOffset > 0) { 928 if (iOffset > 0) {
924 for (i = 0; i < iCount; i++) { 929 for (i = 0; i < iCount; i++) {
925 CFX_RTFPiece& ttp = pCurPieces->GetAt(i); 930 CFX_RTFPiece& ttp = pCurPieces->GetAt(i);
926 ttp.m_iStartPos += iOffset; 931 ttp.m_iStartPos += iOffset;
927 } 932 }
928 } 933 }
929 } 934 }
930 } 935 }
936
931 int32_t CFX_RTFBreak::GetBreakPos(CFX_RTFCharArray& tca, 937 int32_t CFX_RTFBreak::GetBreakPos(CFX_RTFCharArray& tca,
932 int32_t& iEndPos, 938 int32_t& iEndPos,
933 FX_BOOL bAllChars, 939 FX_BOOL bAllChars,
934 FX_BOOL bOnlyBrk) { 940 FX_BOOL bOnlyBrk) {
935 int32_t iLength = tca.GetSize() - 1; 941 int32_t iLength = tca.GetSize() - 1;
936 if (iLength < 1) { 942 if (iLength < 1)
937 return iLength; 943 return iLength;
938 } 944
939 int32_t iBreak = -1, iBreakPos = -1, iIndirect = -1, iIndirectPos = -1, 945 int32_t iBreak = -1, iBreakPos = -1, iIndirect = -1, iIndirectPos = -1,
940 iLast = -1, iLastPos = -1; 946 iLast = -1, iLastPos = -1;
941 if (m_bSingleLine || m_bOrphanLine || iEndPos <= m_iBoundaryEnd) { 947 if (m_bSingleLine || m_bOrphanLine || iEndPos <= m_iBoundaryEnd) {
942 if (!bAllChars || m_bCharCode) { 948 if (!bAllChars || m_bCharCode)
943 return iLength; 949 return iLength;
944 } 950
945 iBreak = iLength; 951 iBreak = iLength;
946 iBreakPos = iEndPos; 952 iBreakPos = iEndPos;
947 } 953 }
948 CFX_RTFChar* pCharArray = tca.GetData(); 954 CFX_RTFChar* pCharArray = tca.GetData();
949 if (m_bCharCode) { 955 if (m_bCharCode) {
950 const CFX_RTFChar* pChar; 956 const CFX_RTFChar* pChar;
951 int32_t iCharWidth; 957 int32_t iCharWidth;
952 while (iLength > 0) { 958 while (iLength > 0) {
953 if (iEndPos <= m_iBoundaryEnd) { 959 if (iEndPos <= m_iBoundaryEnd)
954 break; 960 break;
955 } 961
956 pChar = pCharArray + iLength--; 962 pChar = pCharArray + iLength--;
957 iCharWidth = pChar->m_iCharWidth; 963 iCharWidth = pChar->m_iCharWidth;
958 if (iCharWidth > 0) { 964 if (iCharWidth > 0)
959 iEndPos -= iCharWidth; 965 iEndPos -= iCharWidth;
960 }
961 } 966 }
962 return iLength; 967 return iLength;
963 } 968 }
964 FX_BOOL bSpaceBreak = (m_dwPolicies & FX_RTFBREAKPOLICY_SpaceBreak) != 0; 969 FX_BOOL bSpaceBreak = (m_dwPolicies & FX_RTFBREAKPOLICY_SpaceBreak) != 0;
965 FX_BOOL bTabBreak = (m_dwPolicies & FX_RTFBREAKPOLICY_TabBreak) != 0; 970 FX_BOOL bTabBreak = (m_dwPolicies & FX_RTFBREAKPOLICY_TabBreak) != 0;
966 FX_BOOL bNumberBreak = (m_dwPolicies & FX_RTFBREAKPOLICY_NumberBreak) != 0; 971 FX_BOOL bNumberBreak = (m_dwPolicies & FX_RTFBREAKPOLICY_NumberBreak) != 0;
967 FX_BOOL bInfixBreak = (m_dwPolicies & FX_RTFBREAKPOLICY_InfixBreak) != 0; 972 FX_BOOL bInfixBreak = (m_dwPolicies & FX_RTFBREAKPOLICY_InfixBreak) != 0;
968 FX_LINEBREAKTYPE eType; 973 FX_LINEBREAKTYPE eType;
969 uint32_t nCodeProp, nCur, nNext; 974 uint32_t nCodeProp, nCur, nNext;
970 CFX_RTFChar* pCur = pCharArray + iLength--; 975 CFX_RTFChar* pCur = pCharArray + iLength--;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 iLastPos = iEndPos; 1038 iLastPos = iEndPos;
1034 } 1039 }
1035 } 1040 }
1036 if (iCharWidth > 0) { 1041 if (iCharWidth > 0) {
1037 iEndPos -= iCharWidth; 1042 iEndPos -= iCharWidth;
1038 } 1043 }
1039 } 1044 }
1040 nNext = nCodeProp & 0x003F; 1045 nNext = nCodeProp & 0x003F;
1041 iLength--; 1046 iLength--;
1042 } 1047 }
1043 if (bOnlyBrk) { 1048 if (bOnlyBrk)
1044 return 0; 1049 return 0;
1045 } 1050
1046 if (iBreak > -1) { 1051 if (iBreak > -1) {
1047 iEndPos = iBreakPos; 1052 iEndPos = iBreakPos;
1048 return iBreak; 1053 return iBreak;
1049 } 1054 }
1050 if (iIndirect > -1) { 1055 if (iIndirect > -1) {
1051 iEndPos = iIndirectPos; 1056 iEndPos = iIndirectPos;
1052 return iIndirect; 1057 return iIndirect;
1053 } 1058 }
1054 if (iLast > -1) { 1059 if (iLast > -1) {
1055 iEndPos = iLastPos; 1060 iEndPos = iLastPos;
1056 return iLast; 1061 return iLast;
1057 } 1062 }
1058 return 0; 1063 return 0;
1059 } 1064 }
1065
1060 void CFX_RTFBreak::SplitTextLine(CFX_RTFLine* pCurLine, 1066 void CFX_RTFBreak::SplitTextLine(CFX_RTFLine* pCurLine,
1061 CFX_RTFLine* pNextLine, 1067 CFX_RTFLine* pNextLine,
1062 FX_BOOL bAllChars) { 1068 FX_BOOL bAllChars) {
1063 ASSERT(pCurLine && pNextLine); 1069 ASSERT(pCurLine && pNextLine);
1064 int32_t iCount = pCurLine->CountChars(); 1070 int32_t iCount = pCurLine->CountChars();
1065 if (iCount < 2) { 1071 if (iCount < 2) {
1066 return; 1072 return;
1067 } 1073 }
1068 int32_t iEndPos = pCurLine->GetLineEnd(); 1074 int32_t iEndPos = pCurLine->GetLineEnd();
1069 CFX_RTFCharArray& curChars = pCurLine->m_LineChars; 1075 CFX_RTFCharArray& curChars = pCurLine->m_LineChars;
(...skipping 28 matching lines...) Expand all
1098 pCurLine->m_iArabicChars--; 1104 pCurLine->m_iArabicChars--;
1099 pNextLine->m_iArabicChars++; 1105 pNextLine->m_iArabicChars++;
1100 } 1106 }
1101 if (tc->m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_MBCSCode) { 1107 if (tc->m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_MBCSCode) {
1102 pCurLine->m_iMBCSChars--; 1108 pCurLine->m_iMBCSChars--;
1103 pNextLine->m_iMBCSChars++; 1109 pNextLine->m_iMBCSChars++;
1104 } 1110 }
1105 tc->m_dwStatus = 0; 1111 tc->m_dwStatus = 0;
1106 } 1112 }
1107 } 1113 }
1114
1108 int32_t CFX_RTFBreak::CountBreakPieces() const { 1115 int32_t CFX_RTFBreak::CountBreakPieces() const {
1109 CFX_RTFPieceArray* pRTFPieces = GetRTFPieces(TRUE); 1116 CFX_RTFPieceArray* pRTFPieces = GetRTFPieces(TRUE);
1110 return pRTFPieces ? pRTFPieces->GetSize() : 0; 1117 return pRTFPieces ? pRTFPieces->GetSize() : 0;
1111 } 1118 }
1119
1112 const CFX_RTFPiece* CFX_RTFBreak::GetBreakPiece(int32_t index) const { 1120 const CFX_RTFPiece* CFX_RTFBreak::GetBreakPiece(int32_t index) const {
1113 CFX_RTFPieceArray* pRTFPieces = GetRTFPieces(TRUE); 1121 CFX_RTFPieceArray* pRTFPieces = GetRTFPieces(TRUE);
1114 if (!pRTFPieces) { 1122 if (!pRTFPieces)
1115 return nullptr; 1123 return nullptr;
1116 } 1124
1117 if (index < 0 || index >= pRTFPieces->GetSize()) { 1125 if (index < 0 || index >= pRTFPieces->GetSize())
1118 return nullptr; 1126 return nullptr;
1119 } 1127
1120 return pRTFPieces->GetPtrAt(index); 1128 return pRTFPieces->GetPtrAt(index);
1121 } 1129 }
1130
1122 void CFX_RTFBreak::GetLineRect(CFX_RectF& rect) const { 1131 void CFX_RTFBreak::GetLineRect(CFX_RectF& rect) const {
1123 rect.top = 0; 1132 rect.top = 0;
1124 CFX_RTFLine* pRTFLine = GetRTFLine(TRUE); 1133 CFX_RTFLine* pRTFLine = GetRTFLine(TRUE);
1125 if (!pRTFLine) { 1134 if (!pRTFLine) {
1126 rect.left = ((FX_FLOAT)m_iBoundaryStart) / 20000.0f; 1135 rect.left = ((FX_FLOAT)m_iBoundaryStart) / 20000.0f;
1127 rect.width = rect.height = 0; 1136 rect.width = rect.height = 0;
1128 return; 1137 return;
1129 } 1138 }
1130 rect.left = ((FX_FLOAT)pRTFLine->m_iStart) / 20000.0f; 1139 rect.left = ((FX_FLOAT)pRTFLine->m_iStart) / 20000.0f;
1131 rect.width = ((FX_FLOAT)pRTFLine->m_iWidth) / 20000.0f; 1140 rect.width = ((FX_FLOAT)pRTFLine->m_iWidth) / 20000.0f;
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
1473 if (bRTLPiece) { 1482 if (bRTLPiece) {
1474 rect.left -= fCharSize; 1483 rect.left -= fCharSize;
1475 fStart -= fCharSize; 1484 fStart -= fCharSize;
1476 } else { 1485 } else {
1477 fStart += fCharSize; 1486 fStart += fCharSize;
1478 } 1487 }
1479 rect.width = fCharSize; 1488 rect.width = fCharSize;
1480 } 1489 }
1481 if (bCharBBox && !bRet) { 1490 if (bCharBBox && !bRet) {
1482 int32_t iCharWidth = 1000; 1491 int32_t iCharWidth = 1000;
1483 pFont->GetCharWidth(wch, iCharWidth); 1492 pFont->GetCharWidth(wch, iCharWidth, false);
1484 FX_FLOAT fRTLeft = 0, fCharWidth = 0; 1493 FX_FLOAT fRTLeft = 0, fCharWidth = 0;
1485 if (iCharWidth > 0) { 1494 if (iCharWidth > 0) {
1486 fCharWidth = iCharWidth * fScale; 1495 fCharWidth = iCharWidth * fScale;
1487 fRTLeft = fLeft; 1496 fRTLeft = fLeft;
1488 if (bCombText) { 1497 if (bCombText) {
1489 fRTLeft = (rect.width - fCharWidth) / 2.0f; 1498 fRTLeft = (rect.width - fCharWidth) / 2.0f;
1490 } 1499 }
1491 } 1500 }
1492 CFX_RectF rtBBoxF; 1501 CFX_RectF rtBBoxF;
1493 if (bVertical) { 1502 if (bVertical) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 iLength(0), 1558 iLength(0),
1550 pFont(nullptr), 1559 pFont(nullptr),
1551 fFontSize(12.0f), 1560 fFontSize(12.0f),
1552 dwLayoutStyles(0), 1561 dwLayoutStyles(0),
1553 iCharRotation(0), 1562 iCharRotation(0),
1554 iBidiLevel(0), 1563 iBidiLevel(0),
1555 pRect(nullptr), 1564 pRect(nullptr),
1556 wLineBreakChar(L'\n'), 1565 wLineBreakChar(L'\n'),
1557 iHorizontalScale(100), 1566 iHorizontalScale(100),
1558 iVerticalScale(100) {} 1567 iVerticalScale(100) {}
OLDNEW
« no previous file with comments | « xfa/fgas/layout/fgas_rtfbreak.h ('k') | xfa/fgas/layout/fgas_textbreak.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698