Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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/fgas/layout/fgas_textbreak.h" |
| 8 | |
| 9 | #include <algorithm> |
| 10 | |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 11 | #include "core/fxcrt/fx_arabic.h" |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 12 | #include "core/fxcrt/fx_memory.h" |
tsepez | a9caab9 | 2016-12-14 05:57:10 -0800 | [diff] [blame] | 13 | #include "third_party/base/ptr_util.h" |
npm | 4b91a2d | 2016-11-21 15:19:44 -0800 | [diff] [blame] | 14 | #include "xfa/fgas/font/cfgas_gefont.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 15 | #include "xfa/fgas/layout/fgas_linebreak.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 16 | |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 17 | namespace { |
| 18 | |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 19 | typedef CFX_BreakType (CFX_TxtBreak::*FX_TxtBreak_LPFAppendChar)( |
Dan Sinclair | 068d344 | 2017-03-13 10:15:36 -0400 | [diff] [blame] | 20 | CFX_TxtChar* pCurChar); |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 21 | const FX_TxtBreak_LPFAppendChar g_FX_TxtBreak_lpfAppendChar[16] = { |
| 22 | &CFX_TxtBreak::AppendChar_Others, &CFX_TxtBreak::AppendChar_Tab, |
| 23 | &CFX_TxtBreak::AppendChar_Others, &CFX_TxtBreak::AppendChar_Control, |
| 24 | &CFX_TxtBreak::AppendChar_Combination, &CFX_TxtBreak::AppendChar_Others, |
| 25 | &CFX_TxtBreak::AppendChar_Others, &CFX_TxtBreak::AppendChar_Arabic, |
| 26 | &CFX_TxtBreak::AppendChar_Arabic, &CFX_TxtBreak::AppendChar_Arabic, |
| 27 | &CFX_TxtBreak::AppendChar_Arabic, &CFX_TxtBreak::AppendChar_Arabic, |
| 28 | &CFX_TxtBreak::AppendChar_Arabic, &CFX_TxtBreak::AppendChar_Others, |
| 29 | &CFX_TxtBreak::AppendChar_Others, &CFX_TxtBreak::AppendChar_Others, |
| 30 | }; |
| 31 | |
Dan Sinclair | fc9b988 | 2017-03-07 09:18:18 -0500 | [diff] [blame] | 32 | bool IsCtrlCode(FX_WCHAR ch) { |
| 33 | uint32_t dwRet = (FX_GetUnicodeProperties(ch) & FX_CHARTYPEBITSMASK); |
| 34 | return dwRet == FX_CHARTYPE_Tab || dwRet == FX_CHARTYPE_Control; |
| 35 | } |
| 36 | |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 37 | const int kMinimumTabWidth = 160000; |
| 38 | |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 39 | } // namespace |
| 40 | |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 41 | CFX_TxtBreak::CFX_TxtBreak() |
| 42 | : m_iLineWidth(2000000), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 43 | m_dwLayoutStyles(0), |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 44 | m_bSingleLine(false), |
| 45 | m_bCombText(false), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 46 | m_iArabicContext(1), |
| 47 | m_iCurArabicContext(1), |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 48 | m_pFont(nullptr), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 49 | m_iFontSize(240), |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 50 | m_bEquidistant(true), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 51 | m_iTabWidth(720000), |
| 52 | m_wDefChar(0xFEFF), |
| 53 | m_wParagBreakChar(L'\n'), |
| 54 | m_iDefChar(0), |
Dan Sinclair | 9e9bab6 | 2017-03-09 16:59:12 -0500 | [diff] [blame] | 55 | m_iAlignment(CFX_TxtLineAlignment_Left), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 56 | m_dwContextCharStyles(0), |
| 57 | m_iCombWidth(360000), |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 58 | m_eCharType(FX_CHARTYPE_Unknown), |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 59 | m_pCurLine(nullptr), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 60 | m_iReady(0), |
| 61 | m_iTolerance(0), |
| 62 | m_iHorScale(100), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 63 | m_iCharSpace(0) { |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 64 | m_pCurLine = &m_TxtLine1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 65 | ResetArabicContext(); |
| 66 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 67 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 68 | CFX_TxtBreak::~CFX_TxtBreak() { |
| 69 | Reset(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 70 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 71 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 72 | void CFX_TxtBreak::SetLineWidth(FX_FLOAT fLineWidth) { |
| 73 | m_iLineWidth = FXSYS_round(fLineWidth * 20000.0f); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 74 | ASSERT(m_iLineWidth >= 20000); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 75 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 76 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 77 | void CFX_TxtBreak::SetLayoutStyles(uint32_t dwLayoutStyles) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 78 | m_dwLayoutStyles = dwLayoutStyles; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 79 | m_bSingleLine = (m_dwLayoutStyles & FX_TXTLAYOUTSTYLE_SingleLine) != 0; |
| 80 | m_bCombText = (m_dwLayoutStyles & FX_TXTLAYOUTSTYLE_CombText) != 0; |
| 81 | ResetArabicContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 82 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 83 | |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 84 | void CFX_TxtBreak::SetFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont) { |
| 85 | if (!pFont || pFont == m_pFont) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 86 | return; |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 87 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 88 | SetBreakStatus(); |
| 89 | m_pFont = pFont; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 90 | FontChanged(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 91 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 92 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 93 | void CFX_TxtBreak::SetFontSize(FX_FLOAT fFontSize) { |
| 94 | int32_t iFontSize = FXSYS_round(fFontSize * 20.0f); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 95 | if (m_iFontSize == iFontSize) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 96 | return; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 97 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 98 | SetBreakStatus(); |
| 99 | m_iFontSize = iFontSize; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 100 | FontChanged(); |
| 101 | } |
| 102 | |
| 103 | void CFX_TxtBreak::FontChanged() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 104 | m_iDefChar = 0; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 105 | if (m_wDefChar == 0xFEFF || !m_pFont) |
| 106 | return; |
| 107 | |
| 108 | m_pFont->GetCharWidth(m_wDefChar, m_iDefChar, false); |
| 109 | m_iDefChar *= m_iFontSize; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 110 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 111 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 112 | void CFX_TxtBreak::SetTabWidth(FX_FLOAT fTabWidth, bool bEquidistant) { |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 113 | m_iTabWidth = std::max(FXSYS_round(fTabWidth * 20000.0f), kMinimumTabWidth); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 114 | m_bEquidistant = bEquidistant; |
| 115 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 116 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 117 | void CFX_TxtBreak::SetDefaultChar(FX_WCHAR wch) { |
| 118 | m_wDefChar = wch; |
| 119 | m_iDefChar = 0; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 120 | if (m_wDefChar == 0xFEFF || !m_pFont) |
| 121 | return; |
| 122 | |
| 123 | m_pFont->GetCharWidth(m_wDefChar, m_iDefChar, false); |
| 124 | if (m_iDefChar < 0) |
| 125 | m_iDefChar = 0; |
| 126 | else |
| 127 | m_iDefChar *= m_iFontSize; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 128 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 129 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 130 | void CFX_TxtBreak::SetParagraphBreakChar(FX_WCHAR wch) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 131 | if (wch != L'\r' && wch != L'\n') |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 132 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 133 | m_wParagBreakChar = wch; |
| 134 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 135 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 136 | void CFX_TxtBreak::SetLineBreakTolerance(FX_FLOAT fTolerance) { |
| 137 | m_iTolerance = FXSYS_round(fTolerance * 20000.0f); |
| 138 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 139 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 140 | void CFX_TxtBreak::SetAlignment(int32_t iAlignment) { |
Dan Sinclair | 9e9bab6 | 2017-03-09 16:59:12 -0500 | [diff] [blame] | 141 | ASSERT(iAlignment >= CFX_TxtLineAlignment_Left && |
| 142 | iAlignment <= CFX_TxtLineAlignment_Justified); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 143 | m_iAlignment = iAlignment; |
| 144 | ResetArabicContext(); |
| 145 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 146 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 147 | void CFX_TxtBreak::ResetContextCharStyles() { |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 148 | m_dwContextCharStyles = m_iAlignment; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 149 | m_dwContextCharStyles |= (m_iArabicContext << 8); |
| 150 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 151 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 152 | void CFX_TxtBreak::SetCombWidth(FX_FLOAT fCombWidth) { |
| 153 | m_iCombWidth = FXSYS_round(fCombWidth * 20000.0f); |
| 154 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 155 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 156 | void CFX_TxtBreak::SetBreakStatus() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 157 | int32_t iCount = m_pCurLine->CountChars(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 158 | if (iCount < 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 159 | return; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 160 | |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 161 | CFX_TxtChar* pTC = m_pCurLine->GetCharPtr(iCount - 1); |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 162 | if (pTC->m_dwStatus == CFX_BreakType::None) |
| 163 | pTC->m_dwStatus = CFX_BreakType::Piece; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 164 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 165 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 166 | void CFX_TxtBreak::SetHorizontalScale(int32_t iScale) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 167 | if (iScale < 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 168 | iScale = 0; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 169 | if (iScale == m_iHorScale) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 170 | return; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 171 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 172 | SetBreakStatus(); |
| 173 | m_iHorScale = iScale; |
| 174 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 175 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 176 | void CFX_TxtBreak::SetCharSpace(FX_FLOAT fCharSpace) { |
| 177 | m_iCharSpace = FXSYS_round(fCharSpace * 20000.0f); |
| 178 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 179 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 180 | CFX_TxtChar* CFX_TxtBreak::GetLastChar(int32_t index, bool bOmitChar) const { |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 181 | std::vector<CFX_TxtChar>& ca = m_pCurLine->m_LineChars; |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 182 | int32_t iCount = pdfium::CollectionSize<int32_t>(ca); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 183 | if (index < 0 || index >= iCount) |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 184 | return nullptr; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 185 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 186 | int32_t iStart = iCount - 1; |
| 187 | while (iStart > -1) { |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 188 | CFX_TxtChar* pTC = &ca[iStart--]; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 189 | if (bOmitChar && pTC->GetCharType() == FX_CHARTYPE_Combination) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 190 | continue; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 191 | if (--index < 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 192 | return pTC; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 193 | } |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 194 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 195 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 196 | |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 197 | const CFX_TxtLine* CFX_TxtBreak::GetTxtLine() const { |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 198 | if (m_iReady == 1) |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 199 | return &m_TxtLine1; |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 200 | if (m_iReady == 2) |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 201 | return &m_TxtLine2; |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 202 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 203 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 204 | |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 205 | const CFX_TxtPieceArray* CFX_TxtBreak::GetTxtPieces() const { |
| 206 | const CFX_TxtLine* pTxtLine = GetTxtLine(); |
| 207 | return pTxtLine ? &pTxtLine->m_LinePieces : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 208 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 209 | |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 210 | inline FX_CHARTYPE CFX_TxtBreak::GetUnifiedCharType( |
| 211 | FX_CHARTYPE chartype) const { |
| 212 | return chartype >= FX_CHARTYPE_ArabicAlef ? FX_CHARTYPE_Arabic : chartype; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 213 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 214 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 215 | void CFX_TxtBreak::ResetArabicContext() { |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 216 | m_iCurAlignment = m_iAlignment; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 217 | ResetContextCharStyles(); |
| 218 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 219 | |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 220 | void CFX_TxtBreak::AppendChar_PageLoad(CFX_TxtChar* pCurChar, |
| 221 | uint32_t dwProps) { |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 222 | pCurChar->m_dwStatus = CFX_BreakType::None; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 223 | pCurChar->m_dwCharStyles = m_dwContextCharStyles; |
| 224 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 225 | |
Dan Sinclair | 068d344 | 2017-03-13 10:15:36 -0400 | [diff] [blame] | 226 | CFX_BreakType CFX_TxtBreak::AppendChar_Combination(CFX_TxtChar* pCurChar) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 227 | FX_WCHAR wch = pCurChar->m_wCharCode; |
| 228 | FX_WCHAR wForm; |
| 229 | int32_t iCharWidth = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 230 | pCurChar->m_iCharWidth = -1; |
| 231 | if (m_bCombText) { |
| 232 | iCharWidth = m_iCombWidth; |
| 233 | } else { |
Dan Sinclair | 068d344 | 2017-03-13 10:15:36 -0400 | [diff] [blame] | 234 | wForm = wch; |
| 235 | CFX_TxtChar* pLastChar = GetLastChar(0, false); |
| 236 | if (pLastChar && |
| 237 | (pLastChar->m_dwCharStyles & FX_TXTCHARSTYLE_ArabicShadda) == 0) { |
| 238 | bool bShadda = false; |
| 239 | if (wch == 0x0651) { |
| 240 | FX_WCHAR wLast = pLastChar->m_wCharCode; |
| 241 | if (wLast >= 0x064C && wLast <= 0x0650) { |
| 242 | wForm = FX_GetArabicFromShaddaTable(wLast); |
| 243 | bShadda = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 244 | } |
Dan Sinclair | 068d344 | 2017-03-13 10:15:36 -0400 | [diff] [blame] | 245 | } else if (wch >= 0x064C && wch <= 0x0650) { |
| 246 | if (pLastChar->m_wCharCode == 0x0651) { |
| 247 | wForm = FX_GetArabicFromShaddaTable(wch); |
| 248 | bShadda = true; |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 249 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 250 | } |
Dan Sinclair | 068d344 | 2017-03-13 10:15:36 -0400 | [diff] [blame] | 251 | if (bShadda) { |
| 252 | pLastChar->m_dwCharStyles |= FX_TXTCHARSTYLE_ArabicShadda; |
| 253 | pLastChar->m_iCharWidth = 0; |
| 254 | pCurChar->m_dwCharStyles |= FX_TXTCHARSTYLE_ArabicShadda; |
| 255 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 256 | } |
Dan Sinclair | 068d344 | 2017-03-13 10:15:36 -0400 | [diff] [blame] | 257 | if (!m_pFont->GetCharWidth(wForm, iCharWidth, false)) |
| 258 | iCharWidth = 0; |
| 259 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 260 | iCharWidth *= m_iFontSize; |
| 261 | iCharWidth = iCharWidth * m_iHorScale / 100; |
| 262 | } |
| 263 | pCurChar->m_iCharWidth = -iCharWidth; |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 264 | return CFX_BreakType::None; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 265 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 266 | |
Dan Sinclair | 068d344 | 2017-03-13 10:15:36 -0400 | [diff] [blame] | 267 | CFX_BreakType CFX_TxtBreak::AppendChar_Tab(CFX_TxtChar* pCurChar) { |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 268 | m_eCharType = FX_CHARTYPE_Tab; |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 269 | return CFX_BreakType::None; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 270 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 271 | |
Dan Sinclair | 068d344 | 2017-03-13 10:15:36 -0400 | [diff] [blame] | 272 | CFX_BreakType CFX_TxtBreak::AppendChar_Control(CFX_TxtChar* pCurChar) { |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 273 | m_eCharType = FX_CHARTYPE_Control; |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 274 | CFX_BreakType dwRet = CFX_BreakType::None; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 275 | if (!m_bSingleLine) { |
| 276 | FX_WCHAR wch = pCurChar->m_wCharCode; |
| 277 | switch (wch) { |
| 278 | case L'\v': |
| 279 | case 0x2028: |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 280 | dwRet = CFX_BreakType::Line; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 281 | break; |
| 282 | case L'\f': |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 283 | dwRet = CFX_BreakType::Page; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 284 | break; |
| 285 | case 0x2029: |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 286 | dwRet = CFX_BreakType::Paragraph; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 287 | break; |
| 288 | default: |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 289 | if (wch == m_wParagBreakChar) |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 290 | dwRet = CFX_BreakType::Paragraph; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 291 | break; |
| 292 | } |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 293 | if (dwRet != CFX_BreakType::None) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 294 | dwRet = EndBreak(dwRet); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 295 | } |
| 296 | return dwRet; |
| 297 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 298 | |
Dan Sinclair | 068d344 | 2017-03-13 10:15:36 -0400 | [diff] [blame] | 299 | CFX_BreakType CFX_TxtBreak::AppendChar_Arabic(CFX_TxtChar* pCurChar) { |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 300 | FX_CHARTYPE chartype = pCurChar->GetCharType(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 301 | int32_t& iLineWidth = m_pCurLine->m_iWidth; |
| 302 | FX_WCHAR wForm; |
| 303 | int32_t iCharWidth = 0; |
Dan Sinclair | fb906e3 | 2017-02-28 10:20:12 -0500 | [diff] [blame] | 304 | CFX_TxtChar* pLastChar = nullptr; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 305 | bool bAlef = false; |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 306 | if (!m_bCombText && m_eCharType >= FX_CHARTYPE_ArabicAlef && |
| 307 | m_eCharType <= FX_CHARTYPE_ArabicDistortion) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 308 | pLastChar = GetLastChar(1); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 309 | if (pLastChar) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 310 | iCharWidth = pLastChar->m_iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 311 | if (iCharWidth > 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 312 | iLineWidth -= iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 313 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 314 | CFX_Char* pPrevChar = GetLastChar(2); |
tsepez | e00f75c | 2016-05-06 13:15:46 -0700 | [diff] [blame] | 315 | wForm = pdfium::arabic::GetFormChar(pLastChar, pPrevChar, pCurChar); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 316 | bAlef = (wForm == 0xFEFF && |
| 317 | pLastChar->GetCharType() == FX_CHARTYPE_ArabicAlef); |
Dan Sinclair | 068d344 | 2017-03-13 10:15:36 -0400 | [diff] [blame] | 318 | m_pFont->GetCharWidth(wForm, iCharWidth, false); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 319 | |
| 320 | if (wForm == 0xFEFF) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 321 | iCharWidth = m_iDefChar; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 322 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 323 | iCharWidth *= m_iFontSize; |
| 324 | iCharWidth = iCharWidth * m_iHorScale / 100; |
| 325 | pLastChar->m_iCharWidth = iCharWidth; |
| 326 | iLineWidth += iCharWidth; |
| 327 | iCharWidth = 0; |
| 328 | } |
| 329 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 330 | |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 331 | m_eCharType = chartype; |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 332 | wForm = pdfium::arabic::GetFormChar(pCurChar, bAlef ? nullptr : pLastChar, |
| 333 | nullptr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 334 | if (m_bCombText) { |
| 335 | iCharWidth = m_iCombWidth; |
| 336 | } else { |
Dan Sinclair | 068d344 | 2017-03-13 10:15:36 -0400 | [diff] [blame] | 337 | m_pFont->GetCharWidth(wForm, iCharWidth, false); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 338 | |
| 339 | if (wForm == 0xFEFF) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 340 | iCharWidth = m_iDefChar; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 341 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 342 | iCharWidth *= m_iFontSize; |
| 343 | iCharWidth = iCharWidth * m_iHorScale / 100; |
| 344 | } |
| 345 | pCurChar->m_iCharWidth = iCharWidth; |
| 346 | iLineWidth += iCharWidth; |
| 347 | m_pCurLine->m_iArabicChars++; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 348 | if (!m_bSingleLine && iLineWidth > m_iLineWidth + m_iTolerance) |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 349 | return EndBreak(CFX_BreakType::Line); |
| 350 | return CFX_BreakType::None; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 351 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 352 | |
Dan Sinclair | 068d344 | 2017-03-13 10:15:36 -0400 | [diff] [blame] | 353 | CFX_BreakType CFX_TxtBreak::AppendChar_Others(CFX_TxtChar* pCurChar) { |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 354 | FX_CHARTYPE chartype = pCurChar->GetCharType(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 355 | int32_t& iLineWidth = m_pCurLine->m_iWidth; |
| 356 | int32_t iCharWidth = 0; |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 357 | m_eCharType = chartype; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 358 | FX_WCHAR wch = pCurChar->m_wCharCode; |
| 359 | FX_WCHAR wForm = wch; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 360 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 361 | if (m_bCombText) { |
| 362 | iCharWidth = m_iCombWidth; |
| 363 | } else { |
Dan Sinclair | 068d344 | 2017-03-13 10:15:36 -0400 | [diff] [blame] | 364 | if (!m_pFont->GetCharWidth(wForm, iCharWidth, false)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 365 | iCharWidth = m_iDefChar; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 366 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 367 | iCharWidth *= m_iFontSize; |
| 368 | iCharWidth = iCharWidth * m_iHorScale / 100; |
| 369 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 370 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 371 | iCharWidth += m_iCharSpace; |
| 372 | pCurChar->m_iCharWidth = iCharWidth; |
| 373 | iLineWidth += iCharWidth; |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 374 | if (!m_bSingleLine && chartype != FX_CHARTYPE_Space && |
| 375 | iLineWidth > m_iLineWidth + m_iTolerance) { |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 376 | return EndBreak(CFX_BreakType::Line); |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 377 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 378 | |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 379 | return CFX_BreakType::None; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 380 | } |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 381 | |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 382 | CFX_BreakType CFX_TxtBreak::AppendChar(FX_WCHAR wch) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 383 | uint32_t dwProps = kTextLayoutCodeProperties[static_cast<uint16_t>(wch)]; |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 384 | FX_CHARTYPE chartype = GetCharTypeFromProp(dwProps); |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 385 | m_pCurLine->m_LineChars.emplace_back(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 386 | |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 387 | CFX_TxtChar* pCurChar = &m_pCurLine->m_LineChars.back(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 388 | pCurChar->m_wCharCode = static_cast<uint16_t>(wch); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 389 | pCurChar->m_dwCharProps = dwProps; |
| 390 | pCurChar->m_dwCharStyles = 0; |
| 391 | pCurChar->m_iCharWidth = 0; |
| 392 | pCurChar->m_iHorizontalScale = m_iHorScale; |
Dan Sinclair | 7071943 | 2017-02-28 14:48:51 -0500 | [diff] [blame] | 393 | pCurChar->m_iVerticalScale = 100; |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 394 | pCurChar->m_dwStatus = CFX_BreakType::None; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 395 | pCurChar->m_iBidiClass = 0; |
| 396 | pCurChar->m_iBidiLevel = 0; |
| 397 | pCurChar->m_iBidiPos = 0; |
| 398 | pCurChar->m_iBidiOrder = 0; |
Dan Sinclair | 1c97fd1 | 2017-03-09 16:58:55 -0500 | [diff] [blame] | 399 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 400 | AppendChar_PageLoad(pCurChar, dwProps); |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 401 | CFX_BreakType dwRet1 = CFX_BreakType::None; |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 402 | if (chartype != FX_CHARTYPE_Combination && |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 403 | GetUnifiedCharType(m_eCharType) != GetUnifiedCharType(chartype) && |
| 404 | m_eCharType != FX_CHARTYPE_Unknown && |
| 405 | m_pCurLine->m_iWidth > m_iLineWidth + m_iTolerance && !m_bSingleLine && |
| 406 | (m_eCharType != FX_CHARTYPE_Space || chartype != FX_CHARTYPE_Control)) { |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 407 | dwRet1 = EndBreak(CFX_BreakType::Line); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 408 | int32_t iCount = m_pCurLine->CountChars(); |
| 409 | if (iCount > 0) |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 410 | pCurChar = &m_pCurLine->m_LineChars[iCount - 1]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 411 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 412 | |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 413 | CFX_BreakType dwRet2 = |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 414 | (this->*g_FX_TxtBreak_lpfAppendChar[chartype >> FX_CHARTYPEBITS])( |
Dan Sinclair | 068d344 | 2017-03-13 10:15:36 -0400 | [diff] [blame] | 415 | pCurChar); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 416 | return std::max(dwRet1, dwRet2); |
| 417 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 418 | |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 419 | bool CFX_TxtBreak::EndBreak_SplitLine(CFX_TxtLine* pNextLine, bool bAllChars) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 420 | int32_t iCount = m_pCurLine->CountChars(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 421 | bool bDone = false; |
Dan Sinclair | fb906e3 | 2017-02-28 10:20:12 -0500 | [diff] [blame] | 422 | CFX_TxtChar* pTC; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 423 | if (!m_bSingleLine && m_pCurLine->m_iWidth > m_iLineWidth + m_iTolerance) { |
| 424 | pTC = m_pCurLine->GetCharPtr(iCount - 1); |
| 425 | switch (pTC->GetCharType()) { |
| 426 | case FX_CHARTYPE_Tab: |
| 427 | case FX_CHARTYPE_Control: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 428 | case FX_CHARTYPE_Space: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 429 | break; |
| 430 | default: |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 431 | SplitTextLine(m_pCurLine, pNextLine, bAllChars); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 432 | bDone = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 433 | break; |
| 434 | } |
| 435 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 436 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 437 | iCount = m_pCurLine->CountChars(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 438 | CFX_TxtPiece tp; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 439 | if (bAllChars && !bDone) { |
| 440 | int32_t iEndPos = m_pCurLine->m_iWidth; |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 441 | GetBreakPos(m_pCurLine->m_LineChars, iEndPos, bAllChars, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 442 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 443 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 444 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 445 | |
Tom Sepez | 4a21114 | 2017-03-01 14:41:25 -0800 | [diff] [blame] | 446 | void CFX_TxtBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos, |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 447 | CFX_BreakType dwStatus) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 448 | CFX_TxtPiece tp; |
| 449 | FX_TPO tpo; |
| 450 | CFX_TxtChar* pTC; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 451 | int32_t i; |
| 452 | int32_t j; |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 453 | std::vector<CFX_TxtChar>& chars = m_pCurLine->m_LineChars; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 454 | int32_t iCount = m_pCurLine->CountChars(); |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 455 | bool bDone = m_pCurLine->m_iArabicChars > 0; |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 456 | if (bDone) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 457 | int32_t iBidiNum = 0; |
| 458 | for (i = 0; i < iCount; i++) { |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 459 | pTC = &chars[i]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 460 | pTC->m_iBidiPos = i; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 461 | if (pTC->GetCharType() != FX_CHARTYPE_Control) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 462 | iBidiNum = i; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 463 | if (i == 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 464 | pTC->m_iBidiLevel = 1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 465 | } |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 466 | FX_BidiLine(chars, iBidiNum + 1, 0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 467 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 468 | |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 469 | CFX_TxtPieceArray* pCurPieces = &m_pCurLine->m_LinePieces; |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 470 | if (bDone) { |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 471 | tp.m_dwStatus = CFX_BreakType::Piece; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 472 | tp.m_iStartPos = m_pCurLine->m_iStart; |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 473 | tp.m_pChars = &m_pCurLine->m_LineChars; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 474 | int32_t iBidiLevel = -1; |
| 475 | int32_t iCharWidth; |
| 476 | i = 0; |
| 477 | j = -1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 478 | while (i < iCount) { |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 479 | pTC = &chars[i]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 480 | if (iBidiLevel < 0) { |
| 481 | iBidiLevel = pTC->m_iBidiLevel; |
| 482 | tp.m_iWidth = 0; |
| 483 | tp.m_iBidiLevel = iBidiLevel; |
| 484 | tp.m_iBidiPos = pTC->m_iBidiOrder; |
| 485 | tp.m_dwCharStyles = pTC->m_dwCharStyles; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 486 | tp.m_iHorizontalScale = pTC->m_iHorizontalScale; |
Dan Sinclair | 7071943 | 2017-02-28 14:48:51 -0500 | [diff] [blame] | 487 | tp.m_iVerticalScale = pTC->m_iVerticalScale; |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 488 | tp.m_dwStatus = CFX_BreakType::Piece; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 489 | } |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 490 | if (iBidiLevel != pTC->m_iBidiLevel || |
| 491 | pTC->m_dwStatus != CFX_BreakType::None) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 492 | if (iBidiLevel == pTC->m_iBidiLevel) { |
| 493 | tp.m_dwStatus = pTC->m_dwStatus; |
| 494 | iCharWidth = pTC->m_iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 495 | if (iCharWidth > 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 496 | tp.m_iWidth += iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 497 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 498 | i++; |
| 499 | } |
| 500 | tp.m_iChars = i - tp.m_iStartChar; |
| 501 | pCurPieces->Add(tp); |
| 502 | tp.m_iStartPos += tp.m_iWidth; |
| 503 | tp.m_iStartChar = i; |
| 504 | tpo.index = ++j; |
| 505 | tpo.pos = tp.m_iBidiPos; |
Tom Sepez | 4a21114 | 2017-03-01 14:41:25 -0800 | [diff] [blame] | 506 | tpos->push_back(tpo); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 507 | iBidiLevel = -1; |
| 508 | } else { |
| 509 | iCharWidth = pTC->m_iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 510 | if (iCharWidth > 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 511 | tp.m_iWidth += iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 512 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 513 | i++; |
| 514 | } |
| 515 | } |
| 516 | if (i > tp.m_iStartChar) { |
| 517 | tp.m_dwStatus = dwStatus; |
| 518 | tp.m_iChars = i - tp.m_iStartChar; |
| 519 | pCurPieces->Add(tp); |
| 520 | tpo.index = ++j; |
| 521 | tpo.pos = tp.m_iBidiPos; |
Tom Sepez | 4a21114 | 2017-03-01 14:41:25 -0800 | [diff] [blame] | 522 | tpos->push_back(tpo); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 523 | } |
| 524 | if (j > -1) { |
| 525 | if (j > 0) { |
Tom Sepez | 4a21114 | 2017-03-01 14:41:25 -0800 | [diff] [blame] | 526 | std::sort(tpos->begin(), tpos->end()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 527 | int32_t iStartPos = 0; |
| 528 | for (i = 0; i <= j; i++) { |
Tom Sepez | 4a21114 | 2017-03-01 14:41:25 -0800 | [diff] [blame] | 529 | tpo = (*tpos)[i]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 530 | CFX_TxtPiece& ttp = pCurPieces->GetAt(tpo.index); |
| 531 | ttp.m_iStartPos = iStartPos; |
| 532 | iStartPos += ttp.m_iWidth; |
| 533 | } |
| 534 | } |
| 535 | CFX_TxtPiece& ttp = pCurPieces->GetAt(j); |
| 536 | ttp.m_dwStatus = dwStatus; |
| 537 | } |
| 538 | } else { |
| 539 | tp.m_dwStatus = dwStatus; |
| 540 | tp.m_iStartPos = m_pCurLine->m_iStart; |
| 541 | tp.m_iWidth = m_pCurLine->m_iWidth; |
| 542 | tp.m_iStartChar = 0; |
| 543 | tp.m_iChars = iCount; |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 544 | tp.m_pChars = &m_pCurLine->m_LineChars; |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 545 | pTC = &chars[0]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 546 | tp.m_dwCharStyles = pTC->m_dwCharStyles; |
| 547 | tp.m_iHorizontalScale = pTC->m_iHorizontalScale; |
Dan Sinclair | 7071943 | 2017-02-28 14:48:51 -0500 | [diff] [blame] | 548 | tp.m_iVerticalScale = pTC->m_iVerticalScale; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 549 | pCurPieces->Add(tp); |
Tom Sepez | 4a21114 | 2017-03-01 14:41:25 -0800 | [diff] [blame] | 550 | tpos->push_back({0, 0}); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 551 | } |
| 552 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 553 | |
Tom Sepez | 4a21114 | 2017-03-01 14:41:25 -0800 | [diff] [blame] | 554 | void CFX_TxtBreak::EndBreak_Alignment(const std::deque<FX_TPO>& tpos, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 555 | bool bAllChars, |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 556 | CFX_BreakType dwStatus) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 557 | int32_t iNetWidth = m_pCurLine->m_iWidth; |
| 558 | int32_t iGapChars = 0; |
| 559 | int32_t iCharWidth; |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 560 | CFX_TxtPieceArray* pCurPieces = &m_pCurLine->m_LinePieces; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 561 | int32_t i; |
| 562 | int32_t j; |
| 563 | int32_t iCount = pCurPieces->GetSize(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 564 | bool bFind = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 565 | FX_TPO tpo; |
| 566 | CFX_TxtChar* pTC; |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 567 | FX_CHARTYPE chartype; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 568 | for (i = iCount - 1; i > -1; i--) { |
Tom Sepez | 4a21114 | 2017-03-01 14:41:25 -0800 | [diff] [blame] | 569 | tpo = tpos[i]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 570 | CFX_TxtPiece& ttp = pCurPieces->GetAt(tpo.index); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 571 | if (!bFind) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 572 | iNetWidth = ttp.GetEndPos(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 573 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 574 | bool bArabic = FX_IsOdd(ttp.m_iBidiLevel); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 575 | j = bArabic ? 0 : ttp.m_iChars - 1; |
| 576 | while (j > -1 && j < ttp.m_iChars) { |
| 577 | pTC = ttp.GetCharPtr(j); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 578 | if (pTC->m_nBreakType == FX_LBT_DIRECT_BRK) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 579 | iGapChars++; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 580 | if (!bFind || !bAllChars) { |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 581 | chartype = pTC->GetCharType(); |
| 582 | if (chartype == FX_CHARTYPE_Space || chartype == FX_CHARTYPE_Control) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 583 | if (!bFind) { |
| 584 | iCharWidth = pTC->m_iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 585 | if (bAllChars && iCharWidth > 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 586 | iNetWidth -= iCharWidth; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 587 | } |
| 588 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 589 | bFind = true; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 590 | if (!bAllChars) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 591 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 592 | } |
| 593 | } |
| 594 | j += bArabic ? 1 : -1; |
| 595 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 596 | if (!bAllChars && bFind) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 597 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 598 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 599 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 600 | int32_t iOffset = m_iLineWidth - iNetWidth; |
Dan Sinclair | 9e9bab6 | 2017-03-09 16:59:12 -0500 | [diff] [blame] | 601 | if (iGapChars > 0 && m_iCurAlignment & CFX_TxtLineAlignment_Justified && |
| 602 | dwStatus != CFX_BreakType::Paragraph) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 603 | int32_t iStart = -1; |
| 604 | for (i = 0; i < iCount; i++) { |
Tom Sepez | 4a21114 | 2017-03-01 14:41:25 -0800 | [diff] [blame] | 605 | tpo = tpos[i]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 606 | CFX_TxtPiece& ttp = pCurPieces->GetAt(tpo.index); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 607 | if (iStart < -1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 608 | iStart = ttp.m_iStartPos; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 609 | else |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 610 | ttp.m_iStartPos = iStart; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 611 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 612 | for (j = 0; j < ttp.m_iChars; j++) { |
| 613 | pTC = ttp.GetCharPtr(j); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 614 | if (pTC->m_nBreakType != FX_LBT_DIRECT_BRK || pTC->m_iCharWidth < 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 615 | continue; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 616 | |
| 617 | int32_t k = iOffset / iGapChars; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 618 | pTC->m_iCharWidth += k; |
| 619 | ttp.m_iWidth += k; |
| 620 | iOffset -= k; |
| 621 | iGapChars--; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 622 | if (iGapChars < 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 623 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 624 | } |
| 625 | iStart += ttp.m_iWidth; |
| 626 | } |
Dan Sinclair | 9e9bab6 | 2017-03-09 16:59:12 -0500 | [diff] [blame] | 627 | } else if (m_iCurAlignment & CFX_TxtLineAlignment_Center || |
| 628 | m_iCurAlignment & CFX_TxtLineAlignment_Right) { |
| 629 | if (m_iCurAlignment & CFX_TxtLineAlignment_Center && |
| 630 | !(m_iCurAlignment & CFX_TxtLineAlignment_Right)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 631 | iOffset /= 2; |
Dan Sinclair | 9e9bab6 | 2017-03-09 16:59:12 -0500 | [diff] [blame] | 632 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 633 | if (iOffset > 0) { |
| 634 | for (i = 0; i < iCount; i++) { |
| 635 | CFX_TxtPiece& ttp = pCurPieces->GetAt(i); |
| 636 | ttp.m_iStartPos += iOffset; |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 641 | |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 642 | CFX_BreakType CFX_TxtBreak::EndBreak(CFX_BreakType dwStatus) { |
| 643 | ASSERT(dwStatus != CFX_BreakType::None); |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 644 | const CFX_TxtPieceArray* pCurPieces = &m_pCurLine->m_LinePieces; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 645 | int32_t iCount = pCurPieces->GetSize(); |
| 646 | if (iCount > 0) { |
| 647 | CFX_TxtPiece* pLastPiece = pCurPieces->GetPtrAt(--iCount); |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 648 | if (dwStatus != CFX_BreakType::Piece) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 649 | pLastPiece->m_dwStatus = dwStatus; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 650 | else |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 651 | dwStatus = pLastPiece->m_dwStatus; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 652 | return dwStatus; |
| 653 | } else { |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 654 | const CFX_TxtLine* pLastLine = GetTxtLine(); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 655 | if (pLastLine) { |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 656 | pCurPieces = &pLastLine->m_LinePieces; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 657 | iCount = pCurPieces->GetSize(); |
| 658 | if (iCount-- > 0) { |
| 659 | CFX_TxtPiece* pLastPiece = pCurPieces->GetPtrAt(iCount); |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 660 | if (dwStatus != CFX_BreakType::Piece) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 661 | pLastPiece->m_dwStatus = dwStatus; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 662 | else |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 663 | dwStatus = pLastPiece->m_dwStatus; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 664 | return dwStatus; |
| 665 | } |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 666 | return CFX_BreakType::None; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 667 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 668 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 669 | iCount = m_pCurLine->CountChars(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 670 | if (iCount < 1) |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 671 | return CFX_BreakType::None; |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 672 | |
| 673 | CFX_TxtChar* pTC = m_pCurLine->GetCharPtr(iCount - 1); |
| 674 | pTC->m_dwStatus = dwStatus; |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 675 | if (dwStatus == CFX_BreakType::Piece) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 676 | return dwStatus; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 677 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 678 | |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 679 | m_iReady = m_pCurLine == &m_TxtLine1 ? 1 : 2; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 680 | CFX_TxtLine* pNextLine = |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 681 | m_pCurLine == &m_TxtLine1 ? &m_TxtLine2 : &m_TxtLine1; |
Dan Sinclair | 9e9bab6 | 2017-03-09 16:59:12 -0500 | [diff] [blame] | 682 | bool bAllChars = m_iCurAlignment > CFX_TxtLineAlignment_Right; |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 683 | if (!EndBreak_SplitLine(pNextLine, bAllChars)) { |
Tom Sepez | 4a21114 | 2017-03-01 14:41:25 -0800 | [diff] [blame] | 684 | std::deque<FX_TPO> tpos; |
| 685 | EndBreak_BidiLine(&tpos, dwStatus); |
Dan Sinclair | 9e9bab6 | 2017-03-09 16:59:12 -0500 | [diff] [blame] | 686 | if (m_iCurAlignment > CFX_TxtLineAlignment_Left) |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 687 | EndBreak_Alignment(tpos, bAllChars, dwStatus); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 688 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 689 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 690 | m_pCurLine = pNextLine; |
Tom Sepez | 4a21114 | 2017-03-01 14:41:25 -0800 | [diff] [blame] | 691 | CFX_Char* pTC = GetLastChar(0, false); |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 692 | m_eCharType = pTC ? pTC->GetCharType() : FX_CHARTYPE_Unknown; |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 693 | if (dwStatus == CFX_BreakType::Paragraph) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 694 | m_iArabicContext = m_iCurArabicContext = 1; |
| 695 | ResetArabicContext(); |
| 696 | } |
| 697 | return dwStatus; |
| 698 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 699 | |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 700 | int32_t CFX_TxtBreak::GetBreakPos(std::vector<CFX_TxtChar>& ca, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 701 | int32_t& iEndPos, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 702 | bool bAllChars, |
| 703 | bool bOnlyBrk) { |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 704 | int32_t iLength = pdfium::CollectionSize<int32_t>(ca) - 1; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 705 | if (iLength < 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 706 | return iLength; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 707 | |
| 708 | int32_t iBreak = -1; |
| 709 | int32_t iBreakPos = -1; |
| 710 | int32_t iIndirect = -1; |
| 711 | int32_t iIndirectPos = -1; |
| 712 | int32_t iLast = -1; |
| 713 | int32_t iLastPos = -1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 714 | if (m_bSingleLine || iEndPos <= m_iLineWidth) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 715 | if (!bAllChars) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 716 | return iLength; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 717 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 718 | iBreak = iLength; |
| 719 | iBreakPos = iEndPos; |
| 720 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 721 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 722 | FX_LINEBREAKTYPE eType; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 723 | uint32_t nCodeProp; |
| 724 | uint32_t nCur; |
| 725 | uint32_t nNext; |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 726 | CFX_Char* pCur = &ca[iLength--]; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 727 | if (bAllChars) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 728 | pCur->m_nBreakType = FX_LBT_UNKNOWN; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 729 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 730 | nCodeProp = pCur->m_dwCharProps; |
| 731 | nNext = nCodeProp & 0x003F; |
| 732 | int32_t iCharWidth = pCur->m_iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 733 | if (iCharWidth > 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 734 | iEndPos -= iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 735 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 736 | while (iLength >= 0) { |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 737 | pCur = &ca[iLength]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 738 | nCodeProp = pCur->m_dwCharProps; |
| 739 | nCur = nCodeProp & 0x003F; |
| 740 | if (nCur == FX_CBP_SP) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 741 | if (nNext == FX_CBP_SP) |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 742 | eType = FX_LBT_PROHIBITED_BRK; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 743 | else |
tsepez | f49747f | 2016-06-10 15:24:47 -0700 | [diff] [blame] | 744 | eType = gs_FX_LineBreak_PairTable[nCur][nNext]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 745 | } else { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 746 | if (nNext == FX_CBP_SP) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 747 | eType = FX_LBT_PROHIBITED_BRK; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 748 | else |
tsepez | f49747f | 2016-06-10 15:24:47 -0700 | [diff] [blame] | 749 | eType = gs_FX_LineBreak_PairTable[nCur][nNext]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 750 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 751 | if (bAllChars) |
| 752 | pCur->m_nBreakType = static_cast<uint8_t>(eType); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 753 | if (!bOnlyBrk) { |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 754 | if (m_bSingleLine || iEndPos <= m_iLineWidth || nCur == FX_CBP_SP) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 755 | if (eType == FX_LBT_DIRECT_BRK && iBreak < 0) { |
| 756 | iBreak = iLength; |
| 757 | iBreakPos = iEndPos; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 758 | if (!bAllChars) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 759 | return iLength; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 760 | } else if (eType == FX_LBT_INDIRECT_BRK && iIndirect < 0) { |
| 761 | iIndirect = iLength; |
| 762 | iIndirectPos = iEndPos; |
| 763 | } |
| 764 | if (iLast < 0) { |
| 765 | iLast = iLength; |
| 766 | iLastPos = iEndPos; |
| 767 | } |
| 768 | } |
| 769 | iCharWidth = pCur->m_iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 770 | if (iCharWidth > 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 771 | iEndPos -= iCharWidth; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 772 | } |
| 773 | nNext = nCodeProp & 0x003F; |
| 774 | iLength--; |
| 775 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 776 | if (bOnlyBrk) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 777 | return 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 778 | if (iBreak > -1) { |
| 779 | iEndPos = iBreakPos; |
| 780 | return iBreak; |
| 781 | } |
| 782 | if (iIndirect > -1) { |
| 783 | iEndPos = iIndirectPos; |
| 784 | return iIndirect; |
| 785 | } |
| 786 | if (iLast > -1) { |
| 787 | iEndPos = iLastPos; |
| 788 | return iLast; |
| 789 | } |
| 790 | return 0; |
| 791 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 792 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 793 | void CFX_TxtBreak::SplitTextLine(CFX_TxtLine* pCurLine, |
| 794 | CFX_TxtLine* pNextLine, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 795 | bool bAllChars) { |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 796 | ASSERT(pCurLine && pNextLine); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 797 | int32_t iCount = pCurLine->CountChars(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 798 | if (iCount < 2) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 799 | return; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 800 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 801 | int32_t iEndPos = pCurLine->m_iWidth; |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 802 | std::vector<CFX_TxtChar>& curChars = pCurLine->m_LineChars; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 803 | int32_t iCharPos = GetBreakPos(curChars, iEndPos, bAllChars, false); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 804 | if (iCharPos < 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 805 | iCharPos = 0; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 806 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 807 | iCharPos++; |
| 808 | if (iCharPos >= iCount) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 809 | pNextLine->RemoveAll(true); |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 810 | CFX_Char* pTC = &curChars[iCharPos - 1]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 811 | pTC->m_nBreakType = FX_LBT_UNKNOWN; |
| 812 | return; |
| 813 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 814 | |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 815 | pNextLine->m_LineChars = |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 816 | std::vector<CFX_TxtChar>(curChars.begin() + iCharPos, curChars.end()); |
| 817 | curChars.erase(curChars.begin() + iCharPos, curChars.end()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 818 | pCurLine->m_iWidth = iEndPos; |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 819 | CFX_TxtChar* pTC = &curChars[iCharPos - 1]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 820 | pTC->m_nBreakType = FX_LBT_UNKNOWN; |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 821 | iCount = pdfium::CollectionSize<int>(pNextLine->m_LineChars); |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 822 | int32_t iWidth = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 823 | for (int32_t i = 0; i < iCount; i++) { |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 824 | if (pNextLine->m_LineChars[i].GetCharType() >= FX_CHARTYPE_ArabicAlef) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 825 | pCurLine->m_iArabicChars--; |
| 826 | pNextLine->m_iArabicChars++; |
| 827 | } |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 828 | iWidth += std::max(0, pNextLine->m_LineChars[i].m_iCharWidth); |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 829 | pNextLine->m_LineChars[i].m_dwStatus = CFX_BreakType::None; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 830 | } |
| 831 | pNextLine->m_iWidth = iWidth; |
| 832 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 833 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 834 | int32_t CFX_TxtBreak::CountBreakPieces() const { |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 835 | const CFX_TxtPieceArray* pTxtPieces = GetTxtPieces(); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 836 | return pTxtPieces ? pTxtPieces->GetSize() : 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 837 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 838 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 839 | const CFX_TxtPiece* CFX_TxtBreak::GetBreakPiece(int32_t index) const { |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 840 | const CFX_TxtPieceArray* pTxtPieces = GetTxtPieces(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 841 | if (!pTxtPieces) |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 842 | return nullptr; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 843 | if (index < 0 || index >= pTxtPieces->GetSize()) |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 844 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 845 | return pTxtPieces->GetPtrAt(index); |
| 846 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 847 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 848 | void CFX_TxtBreak::ClearBreakPieces() { |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 849 | const CFX_TxtLine* pTxtLine = GetTxtLine(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 850 | if (pTxtLine) |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 851 | const_cast<CFX_TxtLine*>(pTxtLine)->RemoveAll(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 852 | m_iReady = 0; |
| 853 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 854 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 855 | void CFX_TxtBreak::Reset() { |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 856 | m_eCharType = FX_CHARTYPE_Unknown; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 857 | m_iArabicContext = 1; |
| 858 | m_iCurArabicContext = 1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 859 | ResetArabicContext(); |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 860 | m_TxtLine1.RemoveAll(true); |
| 861 | m_TxtLine2.RemoveAll(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | struct FX_FORMCHAR { |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 865 | uint16_t wch; |
| 866 | uint16_t wForm; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 867 | int32_t iWidth; |
| 868 | }; |
| 869 | |
| 870 | int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun, |
| 871 | FXTEXT_CHARPOS* pCharPos, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 872 | bool bCharCode, |
Tom Sepez | e65d62c | 2017-03-01 13:18:50 -0800 | [diff] [blame] | 873 | CFX_WideString* pWSForms) const { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 874 | if (!pTxtRun || pTxtRun->iLength < 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 875 | return 0; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 876 | |
Dan Sinclair | 575898e | 2017-03-13 10:16:05 -0400 | [diff] [blame^] | 877 | CFDE_TxtEdtPage* pAccess = pTxtRun->pAccess; |
dsinclair | 705f829 | 2016-06-07 10:10:45 -0700 | [diff] [blame] | 878 | const FDE_TEXTEDITPIECE* pIdentity = pTxtRun->pIdentity; |
tsepez | d403329 | 2016-04-19 12:03:15 -0700 | [diff] [blame] | 879 | const FX_WCHAR* pStr = pTxtRun->wsStr.c_str(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 880 | int32_t* pWidths = pTxtRun->pWidths; |
| 881 | int32_t iLength = pTxtRun->iLength - 1; |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 882 | CFX_RetainPtr<CFGAS_GEFont> pFont = pTxtRun->pFont; |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 883 | uint32_t dwStyles = pTxtRun->dwStyles; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 884 | CFX_RectF rtText(*pTxtRun->pRect); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 885 | bool bRTLPiece = (pTxtRun->dwCharStyles & FX_TXTCHARSTYLE_OddBidiLevel) != 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 886 | FX_FLOAT fFontSize = pTxtRun->fFontSize; |
| 887 | int32_t iFontSize = FXSYS_round(fFontSize * 20.0f); |
| 888 | int32_t iAscent = pFont->GetAscent(); |
| 889 | int32_t iDescent = pFont->GetDescent(); |
| 890 | int32_t iMaxHeight = iAscent - iDescent; |
| 891 | FX_FLOAT fFontHeight = fFontSize; |
| 892 | FX_FLOAT fAscent = fFontHeight * (FX_FLOAT)iAscent / (FX_FLOAT)iMaxHeight; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 893 | FX_FLOAT fX = rtText.left; |
| 894 | FX_FLOAT fY; |
| 895 | FX_FLOAT fCharWidth; |
| 896 | FX_FLOAT fCharHeight; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 897 | int32_t iHorScale = pTxtRun->iHorizontalScale; |
| 898 | int32_t iVerScale = pTxtRun->iVerticalScale; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 899 | bool bSkipSpace = pTxtRun->bSkipSpace; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 900 | FX_FORMCHAR formChars[3]; |
| 901 | FX_FLOAT fYBase; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 902 | |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 903 | if (bRTLPiece) |
| 904 | fX = rtText.right(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 905 | |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 906 | fYBase = rtText.top + (rtText.height - fFontSize) / 2.0f; |
| 907 | fY = fYBase + fAscent; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 908 | |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 909 | int32_t iCount = 0; |
| 910 | int32_t iNext = 0; |
| 911 | FX_WCHAR wPrev = 0xFEFF; |
| 912 | FX_WCHAR wNext = 0xFEFF; |
| 913 | FX_WCHAR wForm = 0xFEFF; |
| 914 | FX_WCHAR wLast = 0xFEFF; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 915 | bool bShadda = false; |
| 916 | bool bLam = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 917 | for (int32_t i = 0; i <= iLength; i++) { |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 918 | int32_t iWidth; |
| 919 | FX_WCHAR wch; |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 920 | if (pAccess) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 921 | wch = pAccess->GetChar(pIdentity, i); |
| 922 | iWidth = pAccess->GetWidth(pIdentity, i); |
| 923 | } else { |
| 924 | wch = *pStr++; |
| 925 | iWidth = *pWidths++; |
| 926 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 927 | |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 928 | uint32_t dwProps = FX_GetUnicodeProperties(wch); |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 929 | FX_CHARTYPE chartype = GetCharTypeFromProp(dwProps); |
| 930 | if (chartype == FX_CHARTYPE_ArabicAlef && iWidth == 0) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 931 | wPrev = 0xFEFF; |
| 932 | wLast = wch; |
| 933 | continue; |
| 934 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 935 | |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 936 | if (chartype >= FX_CHARTYPE_ArabicAlef) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 937 | if (i < iLength) { |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 938 | if (pAccess) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 939 | iNext = i + 1; |
| 940 | while (iNext <= iLength) { |
| 941 | wNext = pAccess->GetChar(pIdentity, iNext); |
| 942 | dwProps = FX_GetUnicodeProperties(wNext); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 943 | if ((dwProps & FX_CHARTYPEBITSMASK) != FX_CHARTYPE_Combination) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 944 | break; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 945 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 946 | iNext++; |
| 947 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 948 | if (iNext > iLength) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 949 | wNext = 0xFEFF; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 950 | } else { |
| 951 | int32_t j = -1; |
| 952 | do { |
| 953 | j++; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 954 | if (i + j >= iLength) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 955 | break; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 956 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 957 | wNext = pStr[j]; |
| 958 | dwProps = FX_GetUnicodeProperties(wNext); |
| 959 | } while ((dwProps & FX_CHARTYPEBITSMASK) == FX_CHARTYPE_Combination); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 960 | if (i + j >= iLength) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 961 | wNext = 0xFEFF; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 962 | } |
| 963 | } else { |
| 964 | wNext = 0xFEFF; |
| 965 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 966 | |
tsepez | e00f75c | 2016-05-06 13:15:46 -0700 | [diff] [blame] | 967 | wForm = pdfium::arabic::GetFormChar(wch, wPrev, wNext); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 968 | bLam = (wPrev == 0x0644 && wch == 0x0644 && wNext == 0x0647); |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 969 | } else if (chartype == FX_CHARTYPE_Combination) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 970 | wForm = wch; |
| 971 | if (wch >= 0x064C && wch <= 0x0651) { |
| 972 | if (bShadda) { |
| 973 | wForm = 0xFEFF; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 974 | bShadda = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 975 | } else { |
| 976 | wNext = 0xFEFF; |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 977 | if (pAccess) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 978 | iNext = i + 1; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 979 | if (iNext <= iLength) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 980 | wNext = pAccess->GetChar(pIdentity, iNext); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 981 | } else { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 982 | if (i < iLength) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 983 | wNext = *pStr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 984 | } |
| 985 | if (wch == 0x0651) { |
| 986 | if (wNext >= 0x064C && wNext <= 0x0650) { |
| 987 | wForm = FX_GetArabicFromShaddaTable(wNext); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 988 | bShadda = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 989 | } |
| 990 | } else { |
| 991 | if (wNext == 0x0651) { |
| 992 | wForm = FX_GetArabicFromShaddaTable(wch); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 993 | bShadda = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | } |
| 997 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 998 | bShadda = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 999 | } |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 1000 | } else if (chartype == FX_CHARTYPE_Numeric) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1001 | wForm = wch; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1002 | } else if (wch == L'.') { |
| 1003 | wForm = wch; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1004 | } else if (wch == L',') { |
| 1005 | wForm = wch; |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 1006 | } else if (bRTLPiece) { |
| 1007 | wForm = FX_GetMirrorChar(wch, dwProps, bRTLPiece, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1008 | } else { |
| 1009 | wForm = wch; |
| 1010 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1011 | if (chartype != FX_CHARTYPE_Combination) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1012 | bShadda = false; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1013 | if (chartype < FX_CHARTYPE_ArabicAlef) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1014 | bLam = false; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1015 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1016 | dwProps = FX_GetUnicodeProperties(wForm); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1017 | bool bEmptyChar = |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 1018 | (chartype >= FX_CHARTYPE_Tab && chartype <= FX_CHARTYPE_Control); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1019 | if (wForm == 0xFEFF) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1020 | bEmptyChar = true; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1021 | |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 1022 | int32_t iForms = bLam ? 3 : 1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1023 | iCount += (bEmptyChar && bSkipSpace) ? 0 : iForms; |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1024 | if (!pCharPos) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1025 | if (iWidth > 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1026 | wPrev = wch; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1027 | wLast = wch; |
| 1028 | continue; |
| 1029 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1030 | |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 1031 | int32_t iCharWidth = iWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1032 | if (iCharWidth < 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1033 | iCharWidth = -iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1034 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1035 | iCharWidth /= iFontSize; |
| 1036 | formChars[0].wch = wch; |
| 1037 | formChars[0].wForm = wForm; |
| 1038 | formChars[0].iWidth = iCharWidth; |
| 1039 | if (bLam) { |
| 1040 | formChars[1].wForm = 0x0651; |
| 1041 | iCharWidth = 0; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1042 | pFont->GetCharWidth(0x0651, iCharWidth, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1043 | formChars[1].iWidth = iCharWidth; |
| 1044 | formChars[2].wForm = 0x0670; |
| 1045 | iCharWidth = 0; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1046 | pFont->GetCharWidth(0x0670, iCharWidth, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1047 | formChars[2].iWidth = iCharWidth; |
| 1048 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1049 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1050 | for (int32_t j = 0; j < iForms; j++) { |
| 1051 | wForm = (FX_WCHAR)formChars[j].wForm; |
| 1052 | iCharWidth = formChars[j].iWidth; |
| 1053 | if (j > 0) { |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 1054 | chartype = FX_CHARTYPE_Combination; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1055 | wch = wForm; |
| 1056 | wLast = (FX_WCHAR)formChars[j - 1].wForm; |
| 1057 | } |
| 1058 | if (!bEmptyChar || (bEmptyChar && !bSkipSpace)) { |
| 1059 | pCharPos->m_GlyphIndex = |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1060 | bCharCode ? wch : pFont->GetGlyphIndex(wForm, false); |
thestig | ec51ac3 | 2016-06-20 10:38:52 -0700 | [diff] [blame] | 1061 | #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1062 | pCharPos->m_ExtGID = pCharPos->m_GlyphIndex; |
thestig | ec51ac3 | 2016-06-20 10:38:52 -0700 | [diff] [blame] | 1063 | #endif |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1064 | pCharPos->m_FontCharWidth = iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1065 | if (pWSForms) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1066 | *pWSForms += wForm; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1067 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1068 | |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 1069 | int32_t iCharHeight = 1000; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1070 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1071 | fCharWidth = fFontSize * iCharWidth / 1000.0f; |
| 1072 | fCharHeight = fFontSize * iCharHeight / 1000.0f; |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 1073 | if (bRTLPiece && chartype != FX_CHARTYPE_Combination) |
| 1074 | fX -= fCharWidth; |
| 1075 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1076 | if (!bEmptyChar || (bEmptyChar && !bSkipSpace)) { |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1077 | pCharPos->m_Origin = CFX_PointF(fX, fY); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1078 | if ((dwStyles & FX_TXTLAYOUTSTYLE_CombText) != 0) { |
| 1079 | int32_t iFormWidth = iCharWidth; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1080 | pFont->GetCharWidth(wForm, iFormWidth, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1081 | FX_FLOAT fOffset = fFontSize * (iCharWidth - iFormWidth) / 2000.0f; |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 1082 | pCharPos->m_Origin.x += fOffset; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1083 | } |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1084 | |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 1085 | if (chartype == FX_CHARTYPE_Combination) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1086 | CFX_Rect rtBBox; |
tsepez | 6fd07ef | 2017-01-06 09:48:18 -0800 | [diff] [blame] | 1087 | if (pFont->GetCharBBox(wForm, &rtBBox, false)) { |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1088 | pCharPos->m_Origin.y = |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1089 | fYBase + fFontSize - |
| 1090 | fFontSize * (FX_FLOAT)rtBBox.height / (FX_FLOAT)iMaxHeight; |
| 1091 | } |
| 1092 | if (wForm == wch && wLast != 0xFEFF) { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1093 | uint32_t dwLastProps = FX_GetUnicodeProperties(wLast); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1094 | if ((dwLastProps & FX_CHARTYPEBITSMASK) == |
| 1095 | FX_CHARTYPE_Combination) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 1096 | CFX_Rect rtBox; |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1097 | if (pFont->GetCharBBox(wLast, &rtBox, false)) |
| 1098 | pCharPos->m_Origin.y -= fFontSize * rtBox.height / iMaxHeight; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1099 | } |
| 1100 | } |
| 1101 | } |
| 1102 | CFX_PointF ptOffset; |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1103 | pCharPos->m_Origin.x += ptOffset.x; |
| 1104 | pCharPos->m_Origin.y -= ptOffset.y; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1105 | } |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 1106 | if (!bRTLPiece && chartype != FX_CHARTYPE_Combination) |
| 1107 | fX += fCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1108 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1109 | if (!bEmptyChar || (bEmptyChar && !bSkipSpace)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1110 | pCharPos->m_bGlyphAdjust = true; |
Dan Sinclair | 068d344 | 2017-03-13 10:15:36 -0400 | [diff] [blame] | 1111 | pCharPos->m_AdjustMatrix[0] = -1; |
| 1112 | pCharPos->m_AdjustMatrix[1] = 0; |
| 1113 | pCharPos->m_AdjustMatrix[2] = 0; |
| 1114 | pCharPos->m_AdjustMatrix[3] = 1; |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 1115 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1116 | if (iHorScale != 100 || iVerScale != 100) { |
| 1117 | pCharPos->m_AdjustMatrix[0] = |
| 1118 | pCharPos->m_AdjustMatrix[0] * iHorScale / 100.0f; |
| 1119 | pCharPos->m_AdjustMatrix[1] = |
| 1120 | pCharPos->m_AdjustMatrix[1] * iHorScale / 100.0f; |
| 1121 | pCharPos->m_AdjustMatrix[2] = |
| 1122 | pCharPos->m_AdjustMatrix[2] * iVerScale / 100.0f; |
| 1123 | pCharPos->m_AdjustMatrix[3] = |
| 1124 | pCharPos->m_AdjustMatrix[3] * iVerScale / 100.0f; |
| 1125 | } |
| 1126 | pCharPos++; |
| 1127 | } |
| 1128 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1129 | if (iWidth > 0) |
| 1130 | wPrev = static_cast<FX_WCHAR>(formChars[0].wch); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1131 | wLast = wch; |
| 1132 | } |
| 1133 | return iCount; |
| 1134 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 1135 | |
Tom Sepez | c803cbc | 2017-03-02 12:21:15 -0800 | [diff] [blame] | 1136 | std::vector<CFX_RectF> CFX_TxtBreak::GetCharRects(const FX_TXTRUN* pTxtRun, |
| 1137 | bool bCharBBox) const { |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 1138 | if (!pTxtRun || pTxtRun->iLength < 1) |
Tom Sepez | c803cbc | 2017-03-02 12:21:15 -0800 | [diff] [blame] | 1139 | return std::vector<CFX_RectF>(); |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 1140 | |
Dan Sinclair | 575898e | 2017-03-13 10:16:05 -0400 | [diff] [blame^] | 1141 | CFDE_TxtEdtPage* pAccess = pTxtRun->pAccess; |
dsinclair | 705f829 | 2016-06-07 10:10:45 -0700 | [diff] [blame] | 1142 | const FDE_TEXTEDITPIECE* pIdentity = pTxtRun->pIdentity; |
tsepez | d403329 | 2016-04-19 12:03:15 -0700 | [diff] [blame] | 1143 | const FX_WCHAR* pStr = pTxtRun->wsStr.c_str(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1144 | int32_t* pWidths = pTxtRun->pWidths; |
| 1145 | int32_t iLength = pTxtRun->iLength; |
| 1146 | CFX_RectF rect(*pTxtRun->pRect); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1147 | FX_FLOAT fFontSize = pTxtRun->fFontSize; |
| 1148 | int32_t iFontSize = FXSYS_round(fFontSize * 20.0f); |
| 1149 | FX_FLOAT fScale = fFontSize / 1000.0f; |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 1150 | CFX_RetainPtr<CFGAS_GEFont> pFont = pTxtRun->pFont; |
| 1151 | if (!pFont) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1152 | bCharBBox = false; |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 1153 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1154 | CFX_Rect bbox; |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 1155 | if (bCharBBox) |
tsepez | 6fd07ef | 2017-01-06 09:48:18 -0800 | [diff] [blame] | 1156 | bCharBBox = pFont->GetBBox(&bbox); |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 1157 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1158 | FX_FLOAT fLeft = std::max(0.0f, bbox.left * fScale); |
| 1159 | FX_FLOAT fHeight = FXSYS_fabs(bbox.height * fScale); |
Tom Sepez | c803cbc | 2017-03-02 12:21:15 -0800 | [diff] [blame] | 1160 | bool bRTLPiece = !!(pTxtRun->dwCharStyles & FX_TXTCHARSTYLE_OddBidiLevel); |
Tom Sepez | c803cbc | 2017-03-02 12:21:15 -0800 | [diff] [blame] | 1161 | bool bSingleLine = !!(pTxtRun->dwStyles & FX_TXTLAYOUTSTYLE_SingleLine); |
| 1162 | bool bCombText = !!(pTxtRun->dwStyles & FX_TXTLAYOUTSTYLE_CombText); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1163 | FX_WCHAR wch; |
| 1164 | FX_WCHAR wLineBreakChar = pTxtRun->wLineBreakChar; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1165 | int32_t iCharSize; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1166 | FX_FLOAT fCharSize; |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 1167 | FX_FLOAT fStart = bRTLPiece ? rect.right() : rect.left; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1168 | |
Tom Sepez | c803cbc | 2017-03-02 12:21:15 -0800 | [diff] [blame] | 1169 | std::vector<CFX_RectF> rtArray(iLength); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1170 | for (int32_t i = 0; i < iLength; i++) { |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1171 | if (pAccess) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1172 | wch = pAccess->GetChar(pIdentity, i); |
| 1173 | iCharSize = pAccess->GetWidth(pIdentity, i); |
| 1174 | } else { |
| 1175 | wch = *pStr++; |
| 1176 | iCharSize = *pWidths++; |
| 1177 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1178 | fCharSize = static_cast<FX_FLOAT>(iCharSize) / 20000.0f; |
Dan Sinclair | fc9b988 | 2017-03-07 09:18:18 -0500 | [diff] [blame] | 1179 | bool bRet = (!bSingleLine && IsCtrlCode(wch)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1180 | if (!(wch == L'\v' || wch == L'\f' || wch == 0x2028 || wch == 0x2029 || |
| 1181 | (wLineBreakChar != 0xFEFF && wch == wLineBreakChar))) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1182 | bRet = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1183 | } |
| 1184 | if (bRet) { |
| 1185 | iCharSize = iFontSize * 500; |
| 1186 | fCharSize = fFontSize / 2.0f; |
| 1187 | } |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 1188 | rect.left = fStart; |
| 1189 | if (bRTLPiece) { |
| 1190 | rect.left -= fCharSize; |
| 1191 | fStart -= fCharSize; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1192 | } else { |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 1193 | fStart += fCharSize; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1194 | } |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 1195 | rect.width = fCharSize; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1196 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1197 | if (bCharBBox && !bRet) { |
| 1198 | int32_t iCharWidth = 1000; |
thestig | 2c06532 | 2016-09-26 14:16:43 -0700 | [diff] [blame] | 1199 | pFont->GetCharWidth(wch, iCharWidth, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1200 | FX_FLOAT fRTLeft = 0, fCharWidth = 0; |
| 1201 | if (iCharWidth > 0) { |
| 1202 | fCharWidth = iCharWidth * fScale; |
| 1203 | fRTLeft = fLeft; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame] | 1204 | if (bCombText) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1205 | fRTLeft = (rect.width - fCharWidth) / 2.0f; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1206 | } |
| 1207 | CFX_RectF rtBBoxF; |
Dan Sinclair | a5a3de9 | 2017-03-13 10:14:21 -0400 | [diff] [blame] | 1208 | rtBBoxF.left = rect.left + fRTLeft; |
| 1209 | rtBBoxF.top = rect.top + (rect.height - fHeight) / 2.0f; |
| 1210 | rtBBoxF.width = fCharWidth; |
| 1211 | rtBBoxF.height = fHeight; |
| 1212 | rtBBoxF.top = std::max(rtBBoxF.top, 0.0f); |
Tom Sepez | c803cbc | 2017-03-02 12:21:15 -0800 | [diff] [blame] | 1213 | rtArray[i] = rtBBoxF; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1214 | continue; |
| 1215 | } |
Tom Sepez | c803cbc | 2017-03-02 12:21:15 -0800 | [diff] [blame] | 1216 | rtArray[i] = rect; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1217 | } |
Tom Sepez | c803cbc | 2017-03-02 12:21:15 -0800 | [diff] [blame] | 1218 | return rtArray; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1219 | } |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 1220 | |
| 1221 | FX_TXTRUN::FX_TXTRUN() |
| 1222 | : pAccess(nullptr), |
| 1223 | pIdentity(nullptr), |
| 1224 | pWidths(nullptr), |
| 1225 | iLength(0), |
| 1226 | pFont(nullptr), |
| 1227 | fFontSize(12), |
| 1228 | dwStyles(0), |
| 1229 | iHorizontalScale(100), |
| 1230 | iVerticalScale(100), |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 1231 | dwCharStyles(0), |
| 1232 | pRect(nullptr), |
| 1233 | wLineBreakChar(L'\n'), |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1234 | bSkipSpace(true) {} |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 1235 | |
| 1236 | FX_TXTRUN::~FX_TXTRUN() {} |
| 1237 | |
| 1238 | FX_TXTRUN::FX_TXTRUN(const FX_TXTRUN& other) = default; |
| 1239 | |
| 1240 | CFX_TxtPiece::CFX_TxtPiece() |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 1241 | : m_dwStatus(CFX_BreakType::Piece), |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 1242 | m_iStartPos(0), |
| 1243 | m_iWidth(-1), |
| 1244 | m_iStartChar(0), |
| 1245 | m_iChars(0), |
| 1246 | m_iBidiLevel(0), |
| 1247 | m_iBidiPos(0), |
| 1248 | m_iHorizontalScale(100), |
| 1249 | m_iVerticalScale(100), |
| 1250 | m_dwCharStyles(0), |
Dan Sinclair | 1c97fd1 | 2017-03-09 16:58:55 -0500 | [diff] [blame] | 1251 | m_pChars(nullptr) {} |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 1252 | |
Dan Sinclair | 52c73c2 | 2017-03-09 13:27:29 -0500 | [diff] [blame] | 1253 | CFX_TxtLine::CFX_TxtLine() |
| 1254 | : m_LinePieces(16), m_iStart(0), m_iWidth(0), m_iArabicChars(0) {} |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 1255 | |
| 1256 | CFX_TxtLine::~CFX_TxtLine() { |
| 1257 | RemoveAll(); |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 1258 | } |