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" |
| 12 | #include "core/fxcrt/fx_arb.h" |
| 13 | #include "core/fxcrt/fx_memory.h" |
tsepez | a9caab9 | 2016-12-14 05:57:10 -0800 | [diff] [blame] | 14 | #include "third_party/base/ptr_util.h" |
npm | 4b91a2d | 2016-11-21 15:19:44 -0800 | [diff] [blame] | 15 | #include "xfa/fgas/font/cfgas_gefont.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 16 | #include "xfa/fgas/layout/fgas_linebreak.h" |
| 17 | #include "xfa/fgas/layout/fgas_unicode.h" |
| 18 | |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 19 | namespace { |
| 20 | |
| 21 | typedef uint32_t (CFX_TxtBreak::*FX_TxtBreak_LPFAppendChar)( |
| 22 | CFX_TxtChar* pCurChar, |
| 23 | int32_t iRotation); |
| 24 | const FX_TxtBreak_LPFAppendChar g_FX_TxtBreak_lpfAppendChar[16] = { |
| 25 | &CFX_TxtBreak::AppendChar_Others, &CFX_TxtBreak::AppendChar_Tab, |
| 26 | &CFX_TxtBreak::AppendChar_Others, &CFX_TxtBreak::AppendChar_Control, |
| 27 | &CFX_TxtBreak::AppendChar_Combination, &CFX_TxtBreak::AppendChar_Others, |
| 28 | &CFX_TxtBreak::AppendChar_Others, &CFX_TxtBreak::AppendChar_Arabic, |
| 29 | &CFX_TxtBreak::AppendChar_Arabic, &CFX_TxtBreak::AppendChar_Arabic, |
| 30 | &CFX_TxtBreak::AppendChar_Arabic, &CFX_TxtBreak::AppendChar_Arabic, |
| 31 | &CFX_TxtBreak::AppendChar_Arabic, &CFX_TxtBreak::AppendChar_Others, |
| 32 | &CFX_TxtBreak::AppendChar_Others, &CFX_TxtBreak::AppendChar_Others, |
| 33 | }; |
| 34 | |
| 35 | } // namespace |
| 36 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 37 | CFX_TxtBreak::CFX_TxtBreak(uint32_t dwPolicies) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 38 | : m_dwPolicies(dwPolicies), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 39 | m_iLineWidth(2000000), |
| 40 | m_dwLayoutStyles(0), |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 41 | m_bVertical(false), |
| 42 | m_bArabicContext(false), |
| 43 | m_bArabicShapes(false), |
| 44 | m_bRTL(false), |
| 45 | m_bSingleLine(false), |
| 46 | m_bCombText(false), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 47 | m_iArabicContext(1), |
| 48 | m_iCurArabicContext(1), |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 49 | m_pFont(nullptr), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 50 | m_iFontSize(240), |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 51 | m_bEquidistant(true), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 52 | m_iTabWidth(720000), |
| 53 | m_wDefChar(0xFEFF), |
| 54 | m_wParagBreakChar(L'\n'), |
| 55 | m_iDefChar(0), |
| 56 | m_iLineRotation(0), |
| 57 | m_iCharRotation(0), |
| 58 | m_iRotation(0), |
| 59 | m_iAlignment(FX_TXTLINEALIGNMENT_Left), |
| 60 | m_dwContextCharStyles(0), |
| 61 | m_iCombWidth(360000), |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 62 | m_pUserData(nullptr), |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 63 | m_eCharType(FX_CHARTYPE_Unknown), |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 64 | m_bArabicNumber(false), |
| 65 | m_bArabicComma(false), |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 66 | m_pCurLine(nullptr), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 67 | m_iReady(0), |
| 68 | m_iTolerance(0), |
| 69 | m_iHorScale(100), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 70 | m_iCharSpace(0) { |
| 71 | m_bPagination = (m_dwPolicies & FX_TXTBREAKPOLICY_Pagination) != 0; |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 72 | int32_t iSize = m_bPagination ? sizeof(CFX_Char) : sizeof(CFX_TxtChar); |
tsepez | a9caab9 | 2016-12-14 05:57:10 -0800 | [diff] [blame] | 73 | m_pTxtLine1 = pdfium::MakeUnique<CFX_TxtLine>(iSize); |
| 74 | m_pTxtLine2 = pdfium::MakeUnique<CFX_TxtLine>(iSize); |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 75 | m_pCurLine = m_pTxtLine1.get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 76 | ResetArabicContext(); |
| 77 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 78 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 79 | CFX_TxtBreak::~CFX_TxtBreak() { |
| 80 | Reset(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 81 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 82 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 83 | void CFX_TxtBreak::SetLineWidth(FX_FLOAT fLineWidth) { |
| 84 | m_iLineWidth = FXSYS_round(fLineWidth * 20000.0f); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 85 | ASSERT(m_iLineWidth >= 20000); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 86 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 87 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 88 | void CFX_TxtBreak::SetLinePos(FX_FLOAT fLinePos) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 89 | int32_t iLinePos = |
| 90 | std::min(std::max(FXSYS_round(fLinePos * 20000.0f), 0), m_iLineWidth); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 91 | m_pCurLine->m_iStart = iLinePos; |
| 92 | m_pCurLine->m_iWidth += iLinePos; |
| 93 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 94 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 95 | void CFX_TxtBreak::SetLayoutStyles(uint32_t dwLayoutStyles) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 96 | m_dwLayoutStyles = dwLayoutStyles; |
| 97 | m_bVertical = (m_dwLayoutStyles & FX_TXTLAYOUTSTYLE_VerticalChars) != 0; |
| 98 | m_bArabicContext = (m_dwLayoutStyles & FX_TXTLAYOUTSTYLE_ArabicContext) != 0; |
| 99 | m_bArabicShapes = (m_dwLayoutStyles & FX_TXTLAYOUTSTYLE_ArabicShapes) != 0; |
| 100 | m_bRTL = (m_dwLayoutStyles & FX_TXTLAYOUTSTYLE_RTLReadingOrder) != 0; |
| 101 | m_bSingleLine = (m_dwLayoutStyles & FX_TXTLAYOUTSTYLE_SingleLine) != 0; |
| 102 | m_bCombText = (m_dwLayoutStyles & FX_TXTLAYOUTSTYLE_CombText) != 0; |
| 103 | ResetArabicContext(); |
| 104 | m_iLineRotation = GetLineRotation(m_dwLayoutStyles); |
| 105 | m_iRotation = m_iLineRotation + m_iCharRotation; |
| 106 | m_iRotation %= 4; |
| 107 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 108 | |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 109 | void CFX_TxtBreak::SetFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont) { |
| 110 | if (!pFont || pFont == m_pFont) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 111 | return; |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 112 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 113 | SetBreakStatus(); |
| 114 | m_pFont = pFont; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 115 | FontChanged(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 116 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 117 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 118 | void CFX_TxtBreak::SetFontSize(FX_FLOAT fFontSize) { |
| 119 | int32_t iFontSize = FXSYS_round(fFontSize * 20.0f); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 120 | if (m_iFontSize == iFontSize) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 121 | return; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 122 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 123 | SetBreakStatus(); |
| 124 | m_iFontSize = iFontSize; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 125 | FontChanged(); |
| 126 | } |
| 127 | |
| 128 | void CFX_TxtBreak::FontChanged() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 129 | m_iDefChar = 0; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 130 | if (m_wDefChar == 0xFEFF || !m_pFont) |
| 131 | return; |
| 132 | |
| 133 | m_pFont->GetCharWidth(m_wDefChar, m_iDefChar, false); |
| 134 | m_iDefChar *= m_iFontSize; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 135 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 136 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 137 | void CFX_TxtBreak::SetTabWidth(FX_FLOAT fTabWidth, bool bEquidistant) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 138 | m_iTabWidth = FXSYS_round(fTabWidth * 20000.0f); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 139 | if (m_iTabWidth < FX_TXTBREAK_MinimumTabWidth) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 140 | m_iTabWidth = FX_TXTBREAK_MinimumTabWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 141 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 142 | m_bEquidistant = bEquidistant; |
| 143 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 144 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 145 | void CFX_TxtBreak::SetDefaultChar(FX_WCHAR wch) { |
| 146 | m_wDefChar = wch; |
| 147 | m_iDefChar = 0; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 148 | if (m_wDefChar == 0xFEFF || !m_pFont) |
| 149 | return; |
| 150 | |
| 151 | m_pFont->GetCharWidth(m_wDefChar, m_iDefChar, false); |
| 152 | if (m_iDefChar < 0) |
| 153 | m_iDefChar = 0; |
| 154 | else |
| 155 | m_iDefChar *= m_iFontSize; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 156 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 157 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 158 | void CFX_TxtBreak::SetParagraphBreakChar(FX_WCHAR wch) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 159 | if (wch != L'\r' && wch != L'\n') |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 160 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 161 | m_wParagBreakChar = wch; |
| 162 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 163 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 164 | void CFX_TxtBreak::SetLineBreakTolerance(FX_FLOAT fTolerance) { |
| 165 | m_iTolerance = FXSYS_round(fTolerance * 20000.0f); |
| 166 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 167 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 168 | void CFX_TxtBreak::SetCharRotation(int32_t iCharRotation) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 169 | if (iCharRotation < 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 170 | iCharRotation += (-iCharRotation / 4 + 1) * 4; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 171 | else if (iCharRotation > 3) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 172 | iCharRotation -= (iCharRotation / 4) * 4; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 173 | |
| 174 | if (m_iCharRotation == iCharRotation) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 175 | return; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 176 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 177 | SetBreakStatus(); |
| 178 | m_iCharRotation = iCharRotation; |
| 179 | m_iRotation = m_iLineRotation + m_iCharRotation; |
| 180 | m_iRotation %= 4; |
| 181 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 182 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 183 | void CFX_TxtBreak::SetAlignment(int32_t iAlignment) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 184 | ASSERT(iAlignment >= FX_TXTLINEALIGNMENT_Left && |
| 185 | iAlignment <= FX_TXTLINEALIGNMENT_Distributed); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 186 | m_iAlignment = iAlignment; |
| 187 | ResetArabicContext(); |
| 188 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 189 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 190 | void CFX_TxtBreak::ResetContextCharStyles() { |
| 191 | m_dwContextCharStyles = m_bArabicContext ? m_iCurAlignment : m_iAlignment; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 192 | if (m_bArabicNumber) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 193 | m_dwContextCharStyles |= FX_TXTCHARSTYLE_ArabicNumber; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 194 | if (m_bArabicComma) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 195 | m_dwContextCharStyles |= FX_TXTCHARSTYLE_ArabicComma; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 196 | if ((m_bArabicContext && m_bCurRTL) || (!m_bArabicContext && m_bRTL)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 197 | m_dwContextCharStyles |= FX_TXTCHARSTYLE_RTLReadingOrder; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 198 | m_dwContextCharStyles |= (m_iArabicContext << 8); |
| 199 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 200 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 201 | void CFX_TxtBreak::SetCombWidth(FX_FLOAT fCombWidth) { |
| 202 | m_iCombWidth = FXSYS_round(fCombWidth * 20000.0f); |
| 203 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 204 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 205 | void CFX_TxtBreak::SetUserData(void* pUserData) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 206 | if (m_pUserData == pUserData) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 207 | return; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 208 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 209 | SetBreakStatus(); |
| 210 | m_pUserData = pUserData; |
| 211 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 212 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 213 | void CFX_TxtBreak::SetBreakStatus() { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 214 | if (m_bPagination) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 215 | return; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 216 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 217 | int32_t iCount = m_pCurLine->CountChars(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 218 | if (iCount < 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 219 | return; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 220 | |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 221 | CFX_TxtChar* pTC = m_pCurLine->GetCharPtr(iCount - 1); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 222 | if (pTC->m_dwStatus == 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 223 | pTC->m_dwStatus = FX_TXTBREAK_PieceBreak; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 224 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 225 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 226 | void CFX_TxtBreak::SetHorizontalScale(int32_t iScale) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 227 | if (iScale < 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 228 | iScale = 0; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 229 | if (iScale == m_iHorScale) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 230 | return; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 231 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 232 | SetBreakStatus(); |
| 233 | m_iHorScale = iScale; |
| 234 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 235 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 236 | void CFX_TxtBreak::SetCharSpace(FX_FLOAT fCharSpace) { |
| 237 | m_iCharSpace = FXSYS_round(fCharSpace * 20000.0f); |
| 238 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 239 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 240 | static const int32_t gs_FX_TxtLineRotations[8] = {0, 3, 1, 0, 2, 1, 3, 2}; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 241 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 242 | int32_t CFX_TxtBreak::GetLineRotation(uint32_t dwStyles) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 243 | return gs_FX_TxtLineRotations[(dwStyles & 0x0E) >> 1]; |
| 244 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 245 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 246 | CFX_TxtChar* CFX_TxtBreak::GetLastChar(int32_t index, bool bOmitChar) const { |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 247 | std::vector<CFX_TxtChar>& ca = *m_pCurLine->m_pLineChars.get(); |
| 248 | int32_t iCount = pdfium::CollectionSize<int32_t>(ca); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 249 | if (index < 0 || index >= iCount) |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 250 | return nullptr; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 251 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 252 | int32_t iStart = iCount - 1; |
| 253 | while (iStart > -1) { |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 254 | CFX_TxtChar* pTC = &ca[iStart--]; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 255 | if (bOmitChar && pTC->GetCharType() == FX_CHARTYPE_Combination) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 256 | continue; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 257 | if (--index < 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 258 | return pTC; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 259 | } |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 260 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 261 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 262 | |
Dan Sinclair | e340953 | 2017-02-28 14:51:28 -0500 | [diff] [blame] | 263 | CFX_TxtLine* CFX_TxtBreak::GetTxtLine() const { |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 264 | if (m_iReady == 1) |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 265 | return m_pTxtLine1.get(); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 266 | if (m_iReady == 2) |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 267 | return m_pTxtLine2.get(); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 268 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 269 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 270 | |
Dan Sinclair | e340953 | 2017-02-28 14:51:28 -0500 | [diff] [blame] | 271 | CFX_TxtPieceArray* CFX_TxtBreak::GetTxtPieces() const { |
| 272 | CFX_TxtLine* pTxtLine = GetTxtLine(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 273 | return pTxtLine ? pTxtLine->m_pLinePieces.get() : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 274 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 275 | |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 276 | inline FX_CHARTYPE CFX_TxtBreak::GetUnifiedCharType( |
| 277 | FX_CHARTYPE chartype) const { |
| 278 | return chartype >= FX_CHARTYPE_ArabicAlef ? FX_CHARTYPE_Arabic : chartype; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 279 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 280 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 281 | void CFX_TxtBreak::ResetArabicContext() { |
| 282 | if (m_bArabicContext) { |
| 283 | m_bCurRTL = m_iCurArabicContext > 1; |
| 284 | m_iCurAlignment = m_iCurArabicContext > 1 ? FX_TXTLINEALIGNMENT_Right |
| 285 | : FX_TXTLINEALIGNMENT_Left; |
| 286 | m_iCurAlignment |= (m_iAlignment & FX_TXTLINEALIGNMENT_HigherMask); |
| 287 | m_bArabicNumber = m_iArabicContext >= 1 && m_bArabicShapes; |
| 288 | } else { |
| 289 | if (m_bPagination) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 290 | m_bCurRTL = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 291 | m_iCurAlignment = 0; |
| 292 | } else { |
| 293 | m_bCurRTL = m_bRTL; |
| 294 | m_iCurAlignment = m_iAlignment; |
| 295 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 296 | if (m_bRTL) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 297 | m_bArabicNumber = m_iArabicContext >= 1; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 298 | else |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 299 | m_bArabicNumber = m_iArabicContext > 1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 300 | m_bArabicNumber = m_bArabicNumber && m_bArabicShapes; |
| 301 | } |
| 302 | m_bArabicComma = m_bArabicNumber; |
| 303 | ResetContextCharStyles(); |
| 304 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 305 | |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 306 | void CFX_TxtBreak::AppendChar_PageLoad(CFX_TxtChar* pCurChar, |
| 307 | uint32_t dwProps) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 308 | if (!m_bPagination) { |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 309 | pCurChar->m_dwStatus = 0; |
| 310 | pCurChar->m_pUserData = m_pUserData; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 311 | } |
| 312 | if (m_bArabicContext || m_bArabicShapes) { |
| 313 | int32_t iBidiCls = (dwProps & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS; |
| 314 | int32_t iArabicContext = |
| 315 | (iBidiCls == FX_BIDICLASS_R || iBidiCls == FX_BIDICLASS_AL) |
| 316 | ? 2 |
| 317 | : ((iBidiCls == FX_BIDICLASS_L || iBidiCls == FX_BIDICLASS_S) ? 0 |
| 318 | : 1); |
| 319 | if (iArabicContext != m_iArabicContext && iArabicContext != 1) { |
| 320 | m_iArabicContext = iArabicContext; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 321 | if (m_iCurArabicContext == 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 322 | m_iCurArabicContext = iArabicContext; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 323 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 324 | ResetArabicContext(); |
| 325 | if (!m_bPagination) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 326 | CFX_TxtChar* pLastChar = GetLastChar(1, false); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 327 | if (pLastChar && pLastChar->m_dwStatus < 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 328 | pLastChar->m_dwStatus = FX_TXTBREAK_PieceBreak; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | } |
| 332 | pCurChar->m_dwCharStyles = m_dwContextCharStyles; |
| 333 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 334 | |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 335 | uint32_t CFX_TxtBreak::AppendChar_Combination(CFX_TxtChar* pCurChar, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 336 | int32_t iRotation) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 337 | FX_WCHAR wch = pCurChar->m_wCharCode; |
| 338 | FX_WCHAR wForm; |
| 339 | int32_t iCharWidth = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 340 | pCurChar->m_iCharWidth = -1; |
| 341 | if (m_bCombText) { |
| 342 | iCharWidth = m_iCombWidth; |
| 343 | } else { |
| 344 | if (m_bVertical != FX_IsOdd(iRotation)) { |
| 345 | iCharWidth = 1000; |
| 346 | } else { |
| 347 | wForm = wch; |
| 348 | if (!m_bPagination) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 349 | CFX_TxtChar* pLastChar = GetLastChar(0, false); |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 350 | if (pLastChar && |
| 351 | (pLastChar->m_dwCharStyles & FX_TXTCHARSTYLE_ArabicShadda) == 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 352 | bool bShadda = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 353 | if (wch == 0x0651) { |
| 354 | FX_WCHAR wLast = pLastChar->m_wCharCode; |
| 355 | if (wLast >= 0x064C && wLast <= 0x0650) { |
| 356 | wForm = FX_GetArabicFromShaddaTable(wLast); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 357 | bShadda = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 358 | } |
| 359 | } else if (wch >= 0x064C && wch <= 0x0650) { |
| 360 | if (pLastChar->m_wCharCode == 0x0651) { |
| 361 | wForm = FX_GetArabicFromShaddaTable(wch); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 362 | bShadda = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | if (bShadda) { |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 366 | pLastChar->m_dwCharStyles |= FX_TXTCHARSTYLE_ArabicShadda; |
| 367 | pLastChar->m_iCharWidth = 0; |
| 368 | pCurChar->m_dwCharStyles |= FX_TXTCHARSTYLE_ArabicShadda; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 372 | if (!m_pFont->GetCharWidth(wForm, iCharWidth, false)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 373 | iCharWidth = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 374 | } |
| 375 | iCharWidth *= m_iFontSize; |
| 376 | iCharWidth = iCharWidth * m_iHorScale / 100; |
| 377 | } |
| 378 | pCurChar->m_iCharWidth = -iCharWidth; |
| 379 | return FX_TXTBREAK_None; |
| 380 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 381 | |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 382 | uint32_t CFX_TxtBreak::AppendChar_Tab(CFX_TxtChar* pCurChar, |
| 383 | int32_t iRotation) { |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 384 | m_eCharType = FX_CHARTYPE_Tab; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 385 | if ((m_dwLayoutStyles & FX_TXTLAYOUTSTYLE_ExpandTab) == 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 386 | return FX_TXTBREAK_None; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 387 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 388 | int32_t& iLineWidth = m_pCurLine->m_iWidth; |
| 389 | int32_t iCharWidth; |
| 390 | if (m_bCombText) { |
| 391 | iCharWidth = m_iCombWidth; |
| 392 | } else { |
| 393 | if (m_bEquidistant) { |
| 394 | iCharWidth = iLineWidth; |
| 395 | iCharWidth = m_iTabWidth * (iCharWidth / m_iTabWidth + 1) - iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 396 | if (iCharWidth < FX_TXTBREAK_MinimumTabWidth) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 397 | iCharWidth += m_iTabWidth; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 398 | } else { |
| 399 | iCharWidth = m_iTabWidth; |
| 400 | } |
| 401 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 402 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 403 | pCurChar->m_iCharWidth = iCharWidth; |
| 404 | iLineWidth += iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 405 | if (!m_bSingleLine && iLineWidth >= m_iLineWidth + m_iTolerance) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 406 | return EndBreak(FX_TXTBREAK_LineBreak); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 407 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 408 | return FX_TXTBREAK_None; |
| 409 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 410 | |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 411 | uint32_t CFX_TxtBreak::AppendChar_Control(CFX_TxtChar* pCurChar, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 412 | int32_t iRotation) { |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 413 | m_eCharType = FX_CHARTYPE_Control; |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 414 | uint32_t dwRet = FX_TXTBREAK_None; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 415 | if (!m_bSingleLine) { |
| 416 | FX_WCHAR wch = pCurChar->m_wCharCode; |
| 417 | switch (wch) { |
| 418 | case L'\v': |
| 419 | case 0x2028: |
| 420 | dwRet = FX_TXTBREAK_LineBreak; |
| 421 | break; |
| 422 | case L'\f': |
| 423 | dwRet = FX_TXTBREAK_PageBreak; |
| 424 | break; |
| 425 | case 0x2029: |
| 426 | dwRet = FX_TXTBREAK_ParagraphBreak; |
| 427 | break; |
| 428 | default: |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 429 | if (wch == m_wParagBreakChar) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 430 | dwRet = FX_TXTBREAK_ParagraphBreak; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 431 | break; |
| 432 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 433 | if (dwRet != FX_TXTBREAK_None) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 434 | dwRet = EndBreak(dwRet); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 435 | } |
| 436 | return dwRet; |
| 437 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 438 | |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 439 | uint32_t CFX_TxtBreak::AppendChar_Arabic(CFX_TxtChar* pCurChar, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 440 | int32_t iRotation) { |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 441 | FX_CHARTYPE chartype = pCurChar->GetCharType(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 442 | int32_t& iLineWidth = m_pCurLine->m_iWidth; |
| 443 | FX_WCHAR wForm; |
| 444 | int32_t iCharWidth = 0; |
Dan Sinclair | fb906e3 | 2017-02-28 10:20:12 -0500 | [diff] [blame] | 445 | CFX_TxtChar* pLastChar = nullptr; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 446 | bool bAlef = false; |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 447 | if (!m_bCombText && m_eCharType >= FX_CHARTYPE_ArabicAlef && |
| 448 | m_eCharType <= FX_CHARTYPE_ArabicDistortion) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 449 | pLastChar = GetLastChar(1); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 450 | if (pLastChar) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 451 | iCharWidth = pLastChar->m_iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 452 | if (iCharWidth > 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 453 | iLineWidth -= iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 454 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 455 | CFX_Char* pPrevChar = GetLastChar(2); |
tsepez | e00f75c | 2016-05-06 13:15:46 -0700 | [diff] [blame] | 456 | wForm = pdfium::arabic::GetFormChar(pLastChar, pPrevChar, pCurChar); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 457 | bAlef = (wForm == 0xFEFF && |
| 458 | pLastChar->GetCharType() == FX_CHARTYPE_ArabicAlef); |
| 459 | int32_t iLastRotation = pLastChar->m_nRotation + m_iLineRotation; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 460 | if (m_bVertical && (pLastChar->m_dwCharProps & 0x8000) != 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 461 | iLastRotation++; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 462 | if (m_bVertical != FX_IsOdd(iLastRotation)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 463 | iCharWidth = 1000; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 464 | else |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 465 | m_pFont->GetCharWidth(wForm, iCharWidth, false); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 466 | |
| 467 | if (wForm == 0xFEFF) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 468 | iCharWidth = m_iDefChar; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 469 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 470 | iCharWidth *= m_iFontSize; |
| 471 | iCharWidth = iCharWidth * m_iHorScale / 100; |
| 472 | pLastChar->m_iCharWidth = iCharWidth; |
| 473 | iLineWidth += iCharWidth; |
| 474 | iCharWidth = 0; |
| 475 | } |
| 476 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 477 | |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 478 | m_eCharType = chartype; |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 479 | wForm = pdfium::arabic::GetFormChar(pCurChar, bAlef ? nullptr : pLastChar, |
| 480 | nullptr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 481 | if (m_bCombText) { |
| 482 | iCharWidth = m_iCombWidth; |
| 483 | } else { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 484 | if (m_bVertical != FX_IsOdd(iRotation)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 485 | iCharWidth = 1000; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 486 | else |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 487 | m_pFont->GetCharWidth(wForm, iCharWidth, false); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 488 | |
| 489 | if (wForm == 0xFEFF) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 490 | iCharWidth = m_iDefChar; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 491 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 492 | iCharWidth *= m_iFontSize; |
| 493 | iCharWidth = iCharWidth * m_iHorScale / 100; |
| 494 | } |
| 495 | pCurChar->m_iCharWidth = iCharWidth; |
| 496 | iLineWidth += iCharWidth; |
| 497 | m_pCurLine->m_iArabicChars++; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 498 | if (!m_bSingleLine && iLineWidth > m_iLineWidth + m_iTolerance) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 499 | return EndBreak(FX_TXTBREAK_LineBreak); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 500 | return FX_TXTBREAK_None; |
| 501 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 502 | |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 503 | uint32_t CFX_TxtBreak::AppendChar_Others(CFX_TxtChar* pCurChar, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 504 | int32_t iRotation) { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 505 | uint32_t dwProps = pCurChar->m_dwCharProps; |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 506 | FX_CHARTYPE chartype = pCurChar->GetCharType(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 507 | int32_t& iLineWidth = m_pCurLine->m_iWidth; |
| 508 | int32_t iCharWidth = 0; |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 509 | m_eCharType = chartype; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 510 | FX_WCHAR wch = pCurChar->m_wCharCode; |
| 511 | FX_WCHAR wForm = wch; |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 512 | if (chartype == FX_CHARTYPE_Numeric) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 513 | if (m_bArabicNumber) { |
| 514 | wForm = wch + 0x0630; |
| 515 | pCurChar->m_dwCharStyles |= FX_TXTCHARSTYLE_ArabicIndic; |
| 516 | } |
| 517 | } else if (wch == L',') { |
| 518 | if (m_bArabicShapes && m_iCurArabicContext > 0) { |
| 519 | wForm = 0x060C; |
| 520 | pCurChar->m_dwCharStyles |= FX_TXTCHARSTYLE_ArabicComma; |
| 521 | } |
| 522 | } else if (m_bCurRTL || m_bVertical) { |
| 523 | wForm = FX_GetMirrorChar(wch, dwProps, m_bCurRTL, m_bVertical); |
| 524 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 525 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 526 | if (m_bCombText) { |
| 527 | iCharWidth = m_iCombWidth; |
| 528 | } else { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 529 | if (m_bVertical != FX_IsOdd(iRotation)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 530 | iCharWidth = 1000; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 531 | else if (!m_pFont->GetCharWidth(wForm, iCharWidth, false)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 532 | iCharWidth = m_iDefChar; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 533 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 534 | iCharWidth *= m_iFontSize; |
| 535 | iCharWidth = iCharWidth * m_iHorScale / 100; |
| 536 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 537 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 538 | iCharWidth += m_iCharSpace; |
| 539 | pCurChar->m_iCharWidth = iCharWidth; |
| 540 | iLineWidth += iCharWidth; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 541 | bool bBreak = (chartype != FX_CHARTYPE_Space || |
| 542 | (m_dwPolicies & FX_TXTBREAKPOLICY_SpaceBreak) != 0); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 543 | if (!m_bSingleLine && bBreak && iLineWidth > m_iLineWidth + m_iTolerance) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 544 | return EndBreak(FX_TXTBREAK_LineBreak); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 545 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 546 | return FX_TXTBREAK_None; |
| 547 | } |
tsepez | 215507d | 2016-06-09 19:05:47 -0700 | [diff] [blame] | 548 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 549 | uint32_t CFX_TxtBreak::AppendChar(FX_WCHAR wch) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 550 | uint32_t dwProps = kTextLayoutCodeProperties[static_cast<uint16_t>(wch)]; |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 551 | FX_CHARTYPE chartype = GetCharTypeFromProp(dwProps); |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 552 | m_pCurLine->m_pLineChars->emplace_back(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 553 | |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 554 | CFX_TxtChar* pCurChar = &m_pCurLine->m_pLineChars->back(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 555 | pCurChar->m_wCharCode = static_cast<uint16_t>(wch); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 556 | pCurChar->m_nRotation = m_iCharRotation; |
| 557 | pCurChar->m_dwCharProps = dwProps; |
| 558 | pCurChar->m_dwCharStyles = 0; |
| 559 | pCurChar->m_iCharWidth = 0; |
| 560 | pCurChar->m_iHorizontalScale = m_iHorScale; |
Dan Sinclair | 7071943 | 2017-02-28 14:48:51 -0500 | [diff] [blame] | 561 | pCurChar->m_iVerticalScale = 100; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 562 | pCurChar->m_dwStatus = 0; |
| 563 | pCurChar->m_iBidiClass = 0; |
| 564 | pCurChar->m_iBidiLevel = 0; |
| 565 | pCurChar->m_iBidiPos = 0; |
| 566 | pCurChar->m_iBidiOrder = 0; |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 567 | pCurChar->m_pUserData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 568 | AppendChar_PageLoad(pCurChar, dwProps); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 569 | uint32_t dwRet1 = FX_TXTBREAK_None; |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 570 | if (chartype != FX_CHARTYPE_Combination && |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 571 | GetUnifiedCharType(m_eCharType) != GetUnifiedCharType(chartype) && |
| 572 | m_eCharType != FX_CHARTYPE_Unknown && |
| 573 | m_pCurLine->m_iWidth > m_iLineWidth + m_iTolerance && !m_bSingleLine && |
| 574 | (m_eCharType != FX_CHARTYPE_Space || chartype != FX_CHARTYPE_Control)) { |
| 575 | dwRet1 = EndBreak(FX_TXTBREAK_LineBreak); |
| 576 | int32_t iCount = m_pCurLine->CountChars(); |
| 577 | if (iCount > 0) |
| 578 | pCurChar = &(*m_pCurLine->m_pLineChars)[iCount - 1]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 579 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 580 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 581 | int32_t iRotation = m_iRotation; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 582 | if (m_bVertical && (dwProps & 0x8000) != 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 583 | iRotation = (iRotation + 1) % 4; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 584 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 585 | uint32_t dwRet2 = |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 586 | (this->*g_FX_TxtBreak_lpfAppendChar[chartype >> FX_CHARTYPEBITS])( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 587 | pCurChar, iRotation); |
| 588 | return std::max(dwRet1, dwRet2); |
| 589 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 590 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 591 | void CFX_TxtBreak::EndBreak_UpdateArabicShapes() { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 592 | ASSERT(m_bArabicShapes); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 593 | int32_t iCount = m_pCurLine->CountChars(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 594 | if (iCount < 2) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 595 | return; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 596 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 597 | int32_t& iLineWidth = m_pCurLine->m_iWidth; |
Dan Sinclair | fb906e3 | 2017-02-28 10:20:12 -0500 | [diff] [blame] | 598 | CFX_TxtChar* pCur = m_pCurLine->GetCharPtr(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 599 | bool bPrevNum = (pCur->m_dwCharStyles & FX_TXTCHARSTYLE_ArabicIndic) != 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 600 | pCur = m_pCurLine->GetCharPtr(1); |
| 601 | FX_WCHAR wch, wForm; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 602 | bool bNextNum; |
thestig | 2c06532 | 2016-09-26 14:16:43 -0700 | [diff] [blame] | 603 | int32_t i = 1; |
| 604 | int32_t iCharWidth; |
| 605 | int32_t iRotation; |
Dan Sinclair | fb906e3 | 2017-02-28 10:20:12 -0500 | [diff] [blame] | 606 | CFX_TxtChar* pNext; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 607 | do { |
| 608 | i++; |
| 609 | if (i < iCount) { |
| 610 | pNext = m_pCurLine->GetCharPtr(i); |
| 611 | bNextNum = (pNext->m_dwCharStyles & FX_TXTCHARSTYLE_ArabicIndic) != 0; |
| 612 | } else { |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 613 | pNext = nullptr; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 614 | bNextNum = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 615 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 616 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 617 | wch = pCur->m_wCharCode; |
| 618 | if (wch == L'.') { |
| 619 | if (bPrevNum && bNextNum) { |
| 620 | iRotation = m_iRotation; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 621 | if (m_bVertical && (pCur->m_dwCharProps & 0x8000) != 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 622 | iRotation = ((iRotation + 1) & 0x03); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 623 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 624 | wForm = wch == L'.' ? 0x066B : 0x066C; |
| 625 | iLineWidth -= pCur->m_iCharWidth; |
| 626 | if (m_bCombText) { |
| 627 | iCharWidth = m_iCombWidth; |
| 628 | } else { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 629 | if (m_bVertical != FX_IsOdd(iRotation)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 630 | iCharWidth = 1000; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 631 | else if (!m_pFont->GetCharWidth(wForm, iCharWidth, false)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 632 | iCharWidth = m_iDefChar; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 633 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 634 | iCharWidth *= m_iFontSize; |
| 635 | iCharWidth = iCharWidth * m_iHorScale / 100; |
| 636 | } |
| 637 | pCur->m_iCharWidth = iCharWidth; |
| 638 | iLineWidth += iCharWidth; |
| 639 | } |
| 640 | } |
| 641 | bPrevNum = (pCur->m_dwCharStyles & FX_TXTCHARSTYLE_ArabicIndic) != 0; |
| 642 | pCur = pNext; |
| 643 | } while (i < iCount); |
| 644 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 645 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 646 | bool CFX_TxtBreak::EndBreak_SplitLine(CFX_TxtLine* pNextLine, |
| 647 | bool bAllChars, |
| 648 | uint32_t dwStatus) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 649 | int32_t iCount = m_pCurLine->CountChars(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 650 | bool bDone = false; |
Dan Sinclair | fb906e3 | 2017-02-28 10:20:12 -0500 | [diff] [blame] | 651 | CFX_TxtChar* pTC; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 652 | if (!m_bSingleLine && m_pCurLine->m_iWidth > m_iLineWidth + m_iTolerance) { |
| 653 | pTC = m_pCurLine->GetCharPtr(iCount - 1); |
| 654 | switch (pTC->GetCharType()) { |
| 655 | case FX_CHARTYPE_Tab: |
| 656 | case FX_CHARTYPE_Control: |
| 657 | break; |
| 658 | case FX_CHARTYPE_Space: |
| 659 | if ((m_dwPolicies & FX_TXTBREAKPOLICY_SpaceBreak) != 0) { |
| 660 | SplitTextLine(m_pCurLine, pNextLine, !m_bPagination && bAllChars); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 661 | bDone = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 662 | } |
| 663 | break; |
| 664 | default: |
| 665 | SplitTextLine(m_pCurLine, pNextLine, !m_bPagination && bAllChars); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 666 | bDone = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 667 | break; |
| 668 | } |
| 669 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 670 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 671 | iCount = m_pCurLine->CountChars(); |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 672 | CFX_TxtPieceArray* pCurPieces = m_pCurLine->m_pLinePieces.get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 673 | CFX_TxtPiece tp; |
| 674 | if (m_bPagination) { |
| 675 | tp.m_dwStatus = dwStatus; |
| 676 | tp.m_iStartPos = m_pCurLine->m_iStart; |
| 677 | tp.m_iWidth = m_pCurLine->m_iWidth; |
| 678 | tp.m_iStartChar = 0; |
| 679 | tp.m_iChars = iCount; |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 680 | tp.m_pChars = m_pCurLine->m_pLineChars.get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 681 | tp.m_pUserData = m_pUserData; |
| 682 | pTC = m_pCurLine->GetCharPtr(0); |
| 683 | tp.m_dwCharStyles = pTC->m_dwCharStyles; |
| 684 | tp.m_iHorizontalScale = pTC->m_iHorizontalScale; |
Dan Sinclair | 7071943 | 2017-02-28 14:48:51 -0500 | [diff] [blame] | 685 | tp.m_iVerticalScale = pTC->m_iVerticalScale; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 686 | pCurPieces->Add(tp); |
| 687 | m_pCurLine = pNextLine; |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 688 | m_eCharType = FX_CHARTYPE_Unknown; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 689 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 690 | } |
| 691 | if (bAllChars && !bDone) { |
| 692 | int32_t iEndPos = m_pCurLine->m_iWidth; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 693 | GetBreakPos(*m_pCurLine->m_pLineChars.get(), iEndPos, bAllChars, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 694 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 695 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 696 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 697 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 698 | void CFX_TxtBreak::EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 699 | CFX_TxtPiece tp; |
| 700 | FX_TPO tpo; |
| 701 | CFX_TxtChar* pTC; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 702 | int32_t i; |
| 703 | int32_t j; |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 704 | std::vector<CFX_TxtChar>& chars = *m_pCurLine->m_pLineChars.get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 705 | int32_t iCount = m_pCurLine->CountChars(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 706 | bool bDone = (m_pCurLine->m_iArabicChars > 0 || m_bCurRTL); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 707 | if (!m_bPagination && bDone) { |
| 708 | int32_t iBidiNum = 0; |
| 709 | for (i = 0; i < iCount; i++) { |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 710 | pTC = &chars[i]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 711 | pTC->m_iBidiPos = i; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 712 | if (pTC->GetCharType() != FX_CHARTYPE_Control) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 713 | iBidiNum = i; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 714 | if (i == 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 715 | pTC->m_iBidiLevel = 1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 716 | } |
| 717 | FX_BidiLine(chars, iBidiNum + 1, m_bCurRTL ? 1 : 0); |
| 718 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 719 | |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 720 | CFX_TxtPieceArray* pCurPieces = m_pCurLine->m_pLinePieces.get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 721 | if (!m_bPagination && |
| 722 | (bDone || (m_dwLayoutStyles & FX_TXTLAYOUTSTYLE_MutipleFormat) != 0)) { |
| 723 | tp.m_dwStatus = FX_TXTBREAK_PieceBreak; |
| 724 | tp.m_iStartPos = m_pCurLine->m_iStart; |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 725 | tp.m_pChars = m_pCurLine->m_pLineChars.get(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 726 | int32_t iBidiLevel = -1; |
| 727 | int32_t iCharWidth; |
| 728 | i = 0; |
| 729 | j = -1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 730 | while (i < iCount) { |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 731 | pTC = &chars[i]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 732 | if (iBidiLevel < 0) { |
| 733 | iBidiLevel = pTC->m_iBidiLevel; |
| 734 | tp.m_iWidth = 0; |
| 735 | tp.m_iBidiLevel = iBidiLevel; |
| 736 | tp.m_iBidiPos = pTC->m_iBidiOrder; |
| 737 | tp.m_dwCharStyles = pTC->m_dwCharStyles; |
| 738 | tp.m_pUserData = pTC->m_pUserData; |
| 739 | tp.m_iHorizontalScale = pTC->m_iHorizontalScale; |
Dan Sinclair | 7071943 | 2017-02-28 14:48:51 -0500 | [diff] [blame] | 740 | tp.m_iVerticalScale = pTC->m_iVerticalScale; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 741 | tp.m_dwStatus = FX_TXTBREAK_PieceBreak; |
| 742 | } |
| 743 | if (iBidiLevel != pTC->m_iBidiLevel || pTC->m_dwStatus != 0) { |
| 744 | if (iBidiLevel == pTC->m_iBidiLevel) { |
| 745 | tp.m_dwStatus = pTC->m_dwStatus; |
| 746 | iCharWidth = pTC->m_iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 747 | if (iCharWidth > 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 748 | tp.m_iWidth += iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 749 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 750 | i++; |
| 751 | } |
| 752 | tp.m_iChars = i - tp.m_iStartChar; |
| 753 | pCurPieces->Add(tp); |
| 754 | tp.m_iStartPos += tp.m_iWidth; |
| 755 | tp.m_iStartChar = i; |
| 756 | tpo.index = ++j; |
| 757 | tpo.pos = tp.m_iBidiPos; |
| 758 | tpos.Add(tpo); |
| 759 | iBidiLevel = -1; |
| 760 | } else { |
| 761 | iCharWidth = pTC->m_iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 762 | if (iCharWidth > 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 763 | tp.m_iWidth += iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 764 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 765 | i++; |
| 766 | } |
| 767 | } |
| 768 | if (i > tp.m_iStartChar) { |
| 769 | tp.m_dwStatus = dwStatus; |
| 770 | tp.m_iChars = i - tp.m_iStartChar; |
| 771 | pCurPieces->Add(tp); |
| 772 | tpo.index = ++j; |
| 773 | tpo.pos = tp.m_iBidiPos; |
| 774 | tpos.Add(tpo); |
| 775 | } |
| 776 | if (j > -1) { |
| 777 | if (j > 0) { |
| 778 | FX_TEXTLAYOUT_PieceSort(tpos, 0, j); |
| 779 | int32_t iStartPos = 0; |
| 780 | for (i = 0; i <= j; i++) { |
| 781 | tpo = tpos.GetAt(i); |
| 782 | CFX_TxtPiece& ttp = pCurPieces->GetAt(tpo.index); |
| 783 | ttp.m_iStartPos = iStartPos; |
| 784 | iStartPos += ttp.m_iWidth; |
| 785 | } |
| 786 | } |
| 787 | CFX_TxtPiece& ttp = pCurPieces->GetAt(j); |
| 788 | ttp.m_dwStatus = dwStatus; |
| 789 | } |
| 790 | } else { |
| 791 | tp.m_dwStatus = dwStatus; |
| 792 | tp.m_iStartPos = m_pCurLine->m_iStart; |
| 793 | tp.m_iWidth = m_pCurLine->m_iWidth; |
| 794 | tp.m_iStartChar = 0; |
| 795 | tp.m_iChars = iCount; |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 796 | tp.m_pChars = m_pCurLine->m_pLineChars.get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 797 | tp.m_pUserData = m_pUserData; |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 798 | pTC = &chars[0]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 799 | tp.m_dwCharStyles = pTC->m_dwCharStyles; |
| 800 | tp.m_iHorizontalScale = pTC->m_iHorizontalScale; |
Dan Sinclair | 7071943 | 2017-02-28 14:48:51 -0500 | [diff] [blame] | 801 | tp.m_iVerticalScale = pTC->m_iVerticalScale; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 802 | pCurPieces->Add(tp); |
| 803 | tpo.index = 0; |
| 804 | tpo.pos = 0; |
| 805 | tpos.Add(tpo); |
| 806 | } |
| 807 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 808 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 809 | void CFX_TxtBreak::EndBreak_Alignment(CFX_TPOArray& tpos, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 810 | bool bAllChars, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 811 | uint32_t dwStatus) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 812 | int32_t iNetWidth = m_pCurLine->m_iWidth; |
| 813 | int32_t iGapChars = 0; |
| 814 | int32_t iCharWidth; |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 815 | CFX_TxtPieceArray* pCurPieces = m_pCurLine->m_pLinePieces.get(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 816 | int32_t i; |
| 817 | int32_t j; |
| 818 | int32_t iCount = pCurPieces->GetSize(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 819 | bool bFind = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 820 | FX_TPO tpo; |
| 821 | CFX_TxtChar* pTC; |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 822 | FX_CHARTYPE chartype; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 823 | for (i = iCount - 1; i > -1; i--) { |
| 824 | tpo = tpos.GetAt(i); |
| 825 | CFX_TxtPiece& ttp = pCurPieces->GetAt(tpo.index); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 826 | if (!bFind) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 827 | iNetWidth = ttp.GetEndPos(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 828 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 829 | bool bArabic = FX_IsOdd(ttp.m_iBidiLevel); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 830 | j = bArabic ? 0 : ttp.m_iChars - 1; |
| 831 | while (j > -1 && j < ttp.m_iChars) { |
| 832 | pTC = ttp.GetCharPtr(j); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 833 | if (pTC->m_nBreakType == FX_LBT_DIRECT_BRK) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 834 | iGapChars++; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 835 | if (!bFind || !bAllChars) { |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 836 | chartype = pTC->GetCharType(); |
| 837 | if (chartype == FX_CHARTYPE_Space || chartype == FX_CHARTYPE_Control) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 838 | if (!bFind) { |
| 839 | iCharWidth = pTC->m_iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 840 | if (bAllChars && iCharWidth > 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 841 | iNetWidth -= iCharWidth; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 842 | } |
| 843 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 844 | bFind = true; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 845 | if (!bAllChars) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 846 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | j += bArabic ? 1 : -1; |
| 850 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 851 | if (!bAllChars && bFind) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 852 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 853 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 854 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 855 | int32_t iOffset = m_iLineWidth - iNetWidth; |
| 856 | int32_t iLowerAlignment = (m_iCurAlignment & FX_TXTLINEALIGNMENT_LowerMask); |
| 857 | int32_t iHigherAlignment = (m_iCurAlignment & FX_TXTLINEALIGNMENT_HigherMask); |
| 858 | if (iGapChars > 0 && (iHigherAlignment == FX_TXTLINEALIGNMENT_Distributed || |
| 859 | (iHigherAlignment == FX_TXTLINEALIGNMENT_Justified && |
| 860 | dwStatus != FX_TXTBREAK_ParagraphBreak))) { |
| 861 | int32_t iStart = -1; |
| 862 | for (i = 0; i < iCount; i++) { |
| 863 | tpo = tpos.GetAt(i); |
| 864 | CFX_TxtPiece& ttp = pCurPieces->GetAt(tpo.index); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 865 | if (iStart < -1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 866 | iStart = ttp.m_iStartPos; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 867 | else |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 868 | ttp.m_iStartPos = iStart; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 869 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 870 | for (j = 0; j < ttp.m_iChars; j++) { |
| 871 | pTC = ttp.GetCharPtr(j); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 872 | if (pTC->m_nBreakType != FX_LBT_DIRECT_BRK || pTC->m_iCharWidth < 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 873 | continue; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 874 | |
| 875 | int32_t k = iOffset / iGapChars; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 876 | pTC->m_iCharWidth += k; |
| 877 | ttp.m_iWidth += k; |
| 878 | iOffset -= k; |
| 879 | iGapChars--; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 880 | if (iGapChars < 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 881 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 882 | } |
| 883 | iStart += ttp.m_iWidth; |
| 884 | } |
| 885 | } else if (iLowerAlignment > FX_TXTLINEALIGNMENT_Left) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 886 | if (iLowerAlignment == FX_TXTLINEALIGNMENT_Center) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 887 | iOffset /= 2; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 888 | if (iOffset > 0) { |
| 889 | for (i = 0; i < iCount; i++) { |
| 890 | CFX_TxtPiece& ttp = pCurPieces->GetAt(i); |
| 891 | ttp.m_iStartPos += iOffset; |
| 892 | } |
| 893 | } |
| 894 | } |
| 895 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 896 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 897 | uint32_t CFX_TxtBreak::EndBreak(uint32_t dwStatus) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 898 | ASSERT(dwStatus >= FX_TXTBREAK_PieceBreak && |
| 899 | dwStatus <= FX_TXTBREAK_PageBreak); |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 900 | CFX_TxtPieceArray* pCurPieces = m_pCurLine->m_pLinePieces.get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 901 | int32_t iCount = pCurPieces->GetSize(); |
| 902 | if (iCount > 0) { |
| 903 | CFX_TxtPiece* pLastPiece = pCurPieces->GetPtrAt(--iCount); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 904 | if (dwStatus > FX_TXTBREAK_PieceBreak) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 905 | pLastPiece->m_dwStatus = dwStatus; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 906 | else |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 907 | dwStatus = pLastPiece->m_dwStatus; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 908 | return dwStatus; |
| 909 | } else { |
Dan Sinclair | e340953 | 2017-02-28 14:51:28 -0500 | [diff] [blame] | 910 | CFX_TxtLine* pLastLine = GetTxtLine(); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 911 | if (pLastLine) { |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 912 | pCurPieces = pLastLine->m_pLinePieces.get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 913 | iCount = pCurPieces->GetSize(); |
| 914 | if (iCount-- > 0) { |
| 915 | CFX_TxtPiece* pLastPiece = pCurPieces->GetPtrAt(iCount); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 916 | if (dwStatus > FX_TXTBREAK_PieceBreak) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 917 | pLastPiece->m_dwStatus = dwStatus; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 918 | else |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 919 | dwStatus = pLastPiece->m_dwStatus; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 920 | return dwStatus; |
| 921 | } |
| 922 | return FX_TXTBREAK_None; |
| 923 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 924 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 925 | iCount = m_pCurLine->CountChars(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 926 | if (iCount < 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 927 | return FX_TXTBREAK_None; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 928 | if (!m_bPagination) { |
| 929 | CFX_TxtChar* pTC = m_pCurLine->GetCharPtr(iCount - 1); |
| 930 | pTC->m_dwStatus = dwStatus; |
| 931 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 932 | if (dwStatus <= FX_TXTBREAK_PieceBreak) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 933 | return dwStatus; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 934 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 935 | |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 936 | m_iReady = (m_pCurLine == m_pTxtLine1.get()) ? 1 : 2; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 937 | CFX_TxtLine* pNextLine = |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 938 | (m_pCurLine == m_pTxtLine1.get()) ? m_pTxtLine2.get() : m_pTxtLine1.get(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 939 | bool bAllChars = (m_iCurAlignment > FX_TXTLINEALIGNMENT_Right); |
dsinclair | 3496545 | 2016-07-18 13:14:49 -0700 | [diff] [blame] | 940 | CFX_TPOArray tpos(100); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 941 | CFX_Char* pTC; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 942 | if (m_bArabicShapes) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 943 | EndBreak_UpdateArabicShapes(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 944 | if (!EndBreak_SplitLine(pNextLine, bAllChars, dwStatus)) { |
| 945 | EndBreak_BidiLine(tpos, dwStatus); |
| 946 | if (!m_bPagination && m_iCurAlignment > FX_TXTLINEALIGNMENT_Left) |
| 947 | EndBreak_Alignment(tpos, bAllChars, dwStatus); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 948 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 949 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 950 | m_pCurLine = pNextLine; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 951 | pTC = GetLastChar(0, false); |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 952 | m_eCharType = pTC ? pTC->GetCharType() : FX_CHARTYPE_Unknown; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 953 | if (dwStatus == FX_TXTBREAK_ParagraphBreak) { |
| 954 | m_iArabicContext = m_iCurArabicContext = 1; |
| 955 | ResetArabicContext(); |
| 956 | } |
| 957 | return dwStatus; |
| 958 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 959 | |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 960 | int32_t CFX_TxtBreak::GetBreakPos(std::vector<CFX_TxtChar>& ca, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 961 | int32_t& iEndPos, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 962 | bool bAllChars, |
| 963 | bool bOnlyBrk) { |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 964 | int32_t iLength = pdfium::CollectionSize<int32_t>(ca) - 1; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 965 | if (iLength < 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 966 | return iLength; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 967 | |
| 968 | int32_t iBreak = -1; |
| 969 | int32_t iBreakPos = -1; |
| 970 | int32_t iIndirect = -1; |
| 971 | int32_t iIndirectPos = -1; |
| 972 | int32_t iLast = -1; |
| 973 | int32_t iLastPos = -1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 974 | if (m_bSingleLine || iEndPos <= m_iLineWidth) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 975 | if (!bAllChars) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 976 | return iLength; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 977 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 978 | iBreak = iLength; |
| 979 | iBreakPos = iEndPos; |
| 980 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 981 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 982 | bool bSpaceBreak = (m_dwPolicies & FX_TXTBREAKPOLICY_SpaceBreak) != 0; |
| 983 | bool bNumberBreak = (m_dwPolicies & FX_TXTBREAKPOLICY_NumberBreak) != 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 984 | FX_LINEBREAKTYPE eType; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 985 | uint32_t nCodeProp; |
| 986 | uint32_t nCur; |
| 987 | uint32_t nNext; |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 988 | CFX_Char* pCur = &ca[iLength--]; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 989 | if (bAllChars) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 990 | pCur->m_nBreakType = FX_LBT_UNKNOWN; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 991 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 992 | nCodeProp = pCur->m_dwCharProps; |
| 993 | nNext = nCodeProp & 0x003F; |
| 994 | int32_t iCharWidth = pCur->m_iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 995 | if (iCharWidth > 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 996 | iEndPos -= iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 997 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 998 | while (iLength >= 0) { |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 999 | pCur = &ca[iLength]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1000 | nCodeProp = pCur->m_dwCharProps; |
| 1001 | nCur = nCodeProp & 0x003F; |
| 1002 | if (nCur == FX_CBP_SP) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1003 | if (nNext == FX_CBP_SP) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1004 | eType = bSpaceBreak ? FX_LBT_DIRECT_BRK : FX_LBT_PROHIBITED_BRK; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1005 | else |
tsepez | f49747f | 2016-06-10 15:24:47 -0700 | [diff] [blame] | 1006 | eType = gs_FX_LineBreak_PairTable[nCur][nNext]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1007 | } else if (bNumberBreak && nCur == FX_CBP_NU && nNext == FX_CBP_NU) { |
| 1008 | eType = FX_LBT_DIRECT_BRK; |
| 1009 | } else { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1010 | if (nNext == FX_CBP_SP) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1011 | eType = FX_LBT_PROHIBITED_BRK; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1012 | else |
tsepez | f49747f | 2016-06-10 15:24:47 -0700 | [diff] [blame] | 1013 | eType = gs_FX_LineBreak_PairTable[nCur][nNext]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1014 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1015 | if (bAllChars) |
| 1016 | pCur->m_nBreakType = static_cast<uint8_t>(eType); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1017 | if (!bOnlyBrk) { |
| 1018 | if (m_bSingleLine || iEndPos <= m_iLineWidth || |
| 1019 | (nCur == FX_CBP_SP && !bSpaceBreak)) { |
| 1020 | if (eType == FX_LBT_DIRECT_BRK && iBreak < 0) { |
| 1021 | iBreak = iLength; |
| 1022 | iBreakPos = iEndPos; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1023 | if (!bAllChars) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1024 | return iLength; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1025 | } else if (eType == FX_LBT_INDIRECT_BRK && iIndirect < 0) { |
| 1026 | iIndirect = iLength; |
| 1027 | iIndirectPos = iEndPos; |
| 1028 | } |
| 1029 | if (iLast < 0) { |
| 1030 | iLast = iLength; |
| 1031 | iLastPos = iEndPos; |
| 1032 | } |
| 1033 | } |
| 1034 | iCharWidth = pCur->m_iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1035 | if (iCharWidth > 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1036 | iEndPos -= iCharWidth; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1037 | } |
| 1038 | nNext = nCodeProp & 0x003F; |
| 1039 | iLength--; |
| 1040 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1041 | if (bOnlyBrk) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1042 | return 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1043 | if (iBreak > -1) { |
| 1044 | iEndPos = iBreakPos; |
| 1045 | return iBreak; |
| 1046 | } |
| 1047 | if (iIndirect > -1) { |
| 1048 | iEndPos = iIndirectPos; |
| 1049 | return iIndirect; |
| 1050 | } |
| 1051 | if (iLast > -1) { |
| 1052 | iEndPos = iLastPos; |
| 1053 | return iLast; |
| 1054 | } |
| 1055 | return 0; |
| 1056 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 1057 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1058 | void CFX_TxtBreak::SplitTextLine(CFX_TxtLine* pCurLine, |
| 1059 | CFX_TxtLine* pNextLine, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1060 | bool bAllChars) { |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1061 | ASSERT(pCurLine && pNextLine); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1062 | int32_t iCount = pCurLine->CountChars(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1063 | if (iCount < 2) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1064 | return; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1065 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1066 | int32_t iEndPos = pCurLine->m_iWidth; |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 1067 | std::vector<CFX_TxtChar>& curChars = *pCurLine->m_pLineChars; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1068 | int32_t iCharPos = GetBreakPos(curChars, iEndPos, bAllChars, false); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1069 | if (iCharPos < 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1070 | iCharPos = 0; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1071 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1072 | iCharPos++; |
| 1073 | if (iCharPos >= iCount) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1074 | pNextLine->RemoveAll(true); |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 1075 | CFX_Char* pTC = &curChars[iCharPos - 1]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1076 | pTC->m_nBreakType = FX_LBT_UNKNOWN; |
| 1077 | return; |
| 1078 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1079 | |
| 1080 | // m_pLineChars is a unique_ptr<vector>. Assign the ref into nextChars |
| 1081 | // so we can change the m_pLineChars vector ... |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 1082 | std::vector<CFX_TxtChar>& nextChars = *pNextLine->m_pLineChars; |
| 1083 | nextChars = |
| 1084 | std::vector<CFX_TxtChar>(curChars.begin() + iCharPos, curChars.end()); |
| 1085 | curChars.erase(curChars.begin() + iCharPos, curChars.end()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1086 | pCurLine->m_iWidth = iEndPos; |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 1087 | CFX_TxtChar* pTC = &curChars[iCharPos - 1]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1088 | pTC->m_nBreakType = FX_LBT_UNKNOWN; |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 1089 | iCount = pdfium::CollectionSize<int>(nextChars); |
| 1090 | int32_t iWidth = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1091 | for (int32_t i = 0; i < iCount; i++) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1092 | if (nextChars[i].GetCharType() >= FX_CHARTYPE_ArabicAlef) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1093 | pCurLine->m_iArabicChars--; |
| 1094 | pNextLine->m_iArabicChars++; |
| 1095 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1096 | int32_t iCharWidth = nextChars[i].m_iCharWidth; |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 1097 | if (iCharWidth > 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1098 | iWidth += iCharWidth; |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 1099 | if (m_bPagination) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1100 | continue; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1101 | |
| 1102 | nextChars[i].m_dwStatus = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1103 | } |
| 1104 | pNextLine->m_iWidth = iWidth; |
| 1105 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 1106 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1107 | int32_t CFX_TxtBreak::CountBreakPieces() const { |
Dan Sinclair | e340953 | 2017-02-28 14:51:28 -0500 | [diff] [blame] | 1108 | CFX_TxtPieceArray* pTxtPieces = GetTxtPieces(); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1109 | return pTxtPieces ? pTxtPieces->GetSize() : 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1110 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 1111 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1112 | const CFX_TxtPiece* CFX_TxtBreak::GetBreakPiece(int32_t index) const { |
Dan Sinclair | e340953 | 2017-02-28 14:51:28 -0500 | [diff] [blame] | 1113 | CFX_TxtPieceArray* pTxtPieces = GetTxtPieces(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1114 | if (!pTxtPieces) |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1115 | return nullptr; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1116 | if (index < 0 || index >= pTxtPieces->GetSize()) |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1117 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1118 | return pTxtPieces->GetPtrAt(index); |
| 1119 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 1120 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1121 | void CFX_TxtBreak::ClearBreakPieces() { |
Dan Sinclair | e340953 | 2017-02-28 14:51:28 -0500 | [diff] [blame] | 1122 | CFX_TxtLine* pTxtLine = GetTxtLine(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1123 | if (pTxtLine) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1124 | pTxtLine->RemoveAll(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1125 | m_iReady = 0; |
| 1126 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 1127 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1128 | void CFX_TxtBreak::Reset() { |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 1129 | m_eCharType = FX_CHARTYPE_Unknown; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1130 | m_iArabicContext = 1; |
| 1131 | m_iCurArabicContext = 1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1132 | ResetArabicContext(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1133 | m_pTxtLine1->RemoveAll(true); |
| 1134 | m_pTxtLine2->RemoveAll(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | struct FX_FORMCHAR { |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 1138 | uint16_t wch; |
| 1139 | uint16_t wForm; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1140 | int32_t iWidth; |
| 1141 | }; |
| 1142 | |
| 1143 | int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun, |
| 1144 | FXTEXT_CHARPOS* pCharPos, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1145 | bool bCharCode, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1146 | CFX_WideString* pWSForms, |
| 1147 | FX_AdjustCharDisplayPos pAdjustPos) const { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1148 | if (!pTxtRun || pTxtRun->iLength < 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1149 | return 0; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1150 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1151 | IFX_TxtAccess* pAccess = pTxtRun->pAccess; |
dsinclair | 705f829 | 2016-06-07 10:10:45 -0700 | [diff] [blame] | 1152 | const FDE_TEXTEDITPIECE* pIdentity = pTxtRun->pIdentity; |
tsepez | d403329 | 2016-04-19 12:03:15 -0700 | [diff] [blame] | 1153 | const FX_WCHAR* pStr = pTxtRun->wsStr.c_str(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1154 | int32_t* pWidths = pTxtRun->pWidths; |
| 1155 | int32_t iLength = pTxtRun->iLength - 1; |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 1156 | CFX_RetainPtr<CFGAS_GEFont> pFont = pTxtRun->pFont; |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1157 | uint32_t dwStyles = pTxtRun->dwStyles; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1158 | CFX_RectF rtText(*pTxtRun->pRect); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1159 | bool bRTLPiece = (pTxtRun->dwCharStyles & FX_TXTCHARSTYLE_OddBidiLevel) != 0; |
| 1160 | bool bArabicNumber = |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1161 | (pTxtRun->dwCharStyles & FX_TXTCHARSTYLE_ArabicNumber) != 0; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1162 | bool bArabicComma = |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1163 | (pTxtRun->dwCharStyles & FX_TXTCHARSTYLE_ArabicComma) != 0; |
| 1164 | FX_FLOAT fFontSize = pTxtRun->fFontSize; |
| 1165 | int32_t iFontSize = FXSYS_round(fFontSize * 20.0f); |
| 1166 | int32_t iAscent = pFont->GetAscent(); |
| 1167 | int32_t iDescent = pFont->GetDescent(); |
| 1168 | int32_t iMaxHeight = iAscent - iDescent; |
| 1169 | FX_FLOAT fFontHeight = fFontSize; |
| 1170 | FX_FLOAT fAscent = fFontHeight * (FX_FLOAT)iAscent / (FX_FLOAT)iMaxHeight; |
| 1171 | FX_FLOAT fDescent = fFontHeight * (FX_FLOAT)iDescent / (FX_FLOAT)iMaxHeight; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1172 | bool bVerticalDoc = (dwStyles & FX_TXTLAYOUTSTYLE_VerticalLayout) != 0; |
| 1173 | bool bVerticalChar = (dwStyles & FX_TXTLAYOUTSTYLE_VerticalChars) != 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1174 | int32_t iRotation = GetLineRotation(dwStyles) + pTxtRun->iCharRotation; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1175 | FX_FLOAT fX = rtText.left; |
| 1176 | FX_FLOAT fY; |
| 1177 | FX_FLOAT fCharWidth; |
| 1178 | FX_FLOAT fCharHeight; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1179 | int32_t iHorScale = pTxtRun->iHorizontalScale; |
| 1180 | int32_t iVerScale = pTxtRun->iVerticalScale; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1181 | bool bSkipSpace = pTxtRun->bSkipSpace; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1182 | FX_FORMCHAR formChars[3]; |
| 1183 | FX_FLOAT fYBase; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1184 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1185 | if (bVerticalDoc) { |
| 1186 | fX += (rtText.width - fFontSize) / 2.0f; |
| 1187 | fYBase = bRTLPiece ? rtText.bottom() : rtText.top; |
| 1188 | fY = fYBase; |
| 1189 | } else { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1190 | if (bRTLPiece) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1191 | fX = rtText.right(); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1192 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1193 | fYBase = rtText.top + (rtText.height - fFontSize) / 2.0f; |
| 1194 | fY = fYBase + fAscent; |
| 1195 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1196 | |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 1197 | int32_t iCount = 0; |
| 1198 | int32_t iNext = 0; |
| 1199 | FX_WCHAR wPrev = 0xFEFF; |
| 1200 | FX_WCHAR wNext = 0xFEFF; |
| 1201 | FX_WCHAR wForm = 0xFEFF; |
| 1202 | FX_WCHAR wLast = 0xFEFF; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1203 | bool bShadda = false; |
| 1204 | bool bLam = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1205 | for (int32_t i = 0; i <= iLength; i++) { |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 1206 | int32_t iWidth; |
| 1207 | FX_WCHAR wch; |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1208 | if (pAccess) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1209 | wch = pAccess->GetChar(pIdentity, i); |
| 1210 | iWidth = pAccess->GetWidth(pIdentity, i); |
| 1211 | } else { |
| 1212 | wch = *pStr++; |
| 1213 | iWidth = *pWidths++; |
| 1214 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1215 | |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 1216 | uint32_t dwProps = FX_GetUnicodeProperties(wch); |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 1217 | FX_CHARTYPE chartype = GetCharTypeFromProp(dwProps); |
| 1218 | if (chartype == FX_CHARTYPE_ArabicAlef && iWidth == 0) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1219 | wPrev = 0xFEFF; |
| 1220 | wLast = wch; |
| 1221 | continue; |
| 1222 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1223 | |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 1224 | if (chartype >= FX_CHARTYPE_ArabicAlef) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1225 | if (i < iLength) { |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1226 | if (pAccess) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1227 | iNext = i + 1; |
| 1228 | while (iNext <= iLength) { |
| 1229 | wNext = pAccess->GetChar(pIdentity, iNext); |
| 1230 | dwProps = FX_GetUnicodeProperties(wNext); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1231 | if ((dwProps & FX_CHARTYPEBITSMASK) != FX_CHARTYPE_Combination) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1232 | break; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1233 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1234 | iNext++; |
| 1235 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1236 | if (iNext > iLength) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1237 | wNext = 0xFEFF; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1238 | } else { |
| 1239 | int32_t j = -1; |
| 1240 | do { |
| 1241 | j++; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1242 | if (i + j >= iLength) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1243 | break; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1244 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1245 | wNext = pStr[j]; |
| 1246 | dwProps = FX_GetUnicodeProperties(wNext); |
| 1247 | } while ((dwProps & FX_CHARTYPEBITSMASK) == FX_CHARTYPE_Combination); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1248 | if (i + j >= iLength) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1249 | wNext = 0xFEFF; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1250 | } |
| 1251 | } else { |
| 1252 | wNext = 0xFEFF; |
| 1253 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1254 | |
tsepez | e00f75c | 2016-05-06 13:15:46 -0700 | [diff] [blame] | 1255 | wForm = pdfium::arabic::GetFormChar(wch, wPrev, wNext); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1256 | bLam = (wPrev == 0x0644 && wch == 0x0644 && wNext == 0x0647); |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 1257 | } else if (chartype == FX_CHARTYPE_Combination) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1258 | wForm = wch; |
| 1259 | if (wch >= 0x064C && wch <= 0x0651) { |
| 1260 | if (bShadda) { |
| 1261 | wForm = 0xFEFF; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1262 | bShadda = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1263 | } else { |
| 1264 | wNext = 0xFEFF; |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1265 | if (pAccess) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1266 | iNext = i + 1; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1267 | if (iNext <= iLength) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1268 | wNext = pAccess->GetChar(pIdentity, iNext); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1269 | } else { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1270 | if (i < iLength) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1271 | wNext = *pStr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1272 | } |
| 1273 | if (wch == 0x0651) { |
| 1274 | if (wNext >= 0x064C && wNext <= 0x0650) { |
| 1275 | wForm = FX_GetArabicFromShaddaTable(wNext); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1276 | bShadda = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1277 | } |
| 1278 | } else { |
| 1279 | if (wNext == 0x0651) { |
| 1280 | wForm = FX_GetArabicFromShaddaTable(wch); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1281 | bShadda = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1282 | } |
| 1283 | } |
| 1284 | } |
| 1285 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1286 | bShadda = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1287 | } |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 1288 | } else if (chartype == FX_CHARTYPE_Numeric) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1289 | wForm = wch; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1290 | if (bArabicNumber) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1291 | wForm += 0x0630; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1292 | } else if (wch == L'.') { |
| 1293 | wForm = wch; |
| 1294 | if (bArabicNumber) { |
| 1295 | wNext = 0xFEFF; |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1296 | if (pAccess) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1297 | iNext = i + 1; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1298 | if (iNext <= iLength) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1299 | wNext = pAccess->GetChar(pIdentity, iNext); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1300 | } else { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1301 | if (i < iLength) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1302 | wNext = *pStr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1303 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1304 | if (wNext >= L'0' && wNext <= L'9') |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1305 | wForm = 0x066B; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1306 | } |
| 1307 | } else if (wch == L',') { |
| 1308 | wForm = wch; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1309 | if (bArabicComma) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1310 | wForm = 0x060C; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1311 | } else if (bRTLPiece || bVerticalChar) { |
| 1312 | wForm = FX_GetMirrorChar(wch, dwProps, bRTLPiece, bVerticalChar); |
| 1313 | } else { |
| 1314 | wForm = wch; |
| 1315 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1316 | if (chartype != FX_CHARTYPE_Combination) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1317 | bShadda = false; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1318 | if (chartype < FX_CHARTYPE_ArabicAlef) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1319 | bLam = false; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1320 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1321 | dwProps = FX_GetUnicodeProperties(wForm); |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 1322 | int32_t iCharRotation = iRotation; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1323 | if (bVerticalChar && (dwProps & 0x8000) != 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1324 | iCharRotation++; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1325 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1326 | iCharRotation %= 4; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1327 | bool bEmptyChar = |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 1328 | (chartype >= FX_CHARTYPE_Tab && chartype <= FX_CHARTYPE_Control); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1329 | if (wForm == 0xFEFF) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1330 | bEmptyChar = true; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1331 | |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 1332 | int32_t iForms = bLam ? 3 : 1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1333 | iCount += (bEmptyChar && bSkipSpace) ? 0 : iForms; |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1334 | if (!pCharPos) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1335 | if (iWidth > 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1336 | wPrev = wch; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1337 | wLast = wch; |
| 1338 | continue; |
| 1339 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1340 | |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 1341 | int32_t iCharWidth = iWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1342 | if (iCharWidth < 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1343 | iCharWidth = -iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1344 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1345 | iCharWidth /= iFontSize; |
| 1346 | formChars[0].wch = wch; |
| 1347 | formChars[0].wForm = wForm; |
| 1348 | formChars[0].iWidth = iCharWidth; |
| 1349 | if (bLam) { |
| 1350 | formChars[1].wForm = 0x0651; |
| 1351 | iCharWidth = 0; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1352 | pFont->GetCharWidth(0x0651, iCharWidth, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1353 | formChars[1].iWidth = iCharWidth; |
| 1354 | formChars[2].wForm = 0x0670; |
| 1355 | iCharWidth = 0; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1356 | pFont->GetCharWidth(0x0670, iCharWidth, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1357 | formChars[2].iWidth = iCharWidth; |
| 1358 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1359 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1360 | for (int32_t j = 0; j < iForms; j++) { |
| 1361 | wForm = (FX_WCHAR)formChars[j].wForm; |
| 1362 | iCharWidth = formChars[j].iWidth; |
| 1363 | if (j > 0) { |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 1364 | chartype = FX_CHARTYPE_Combination; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1365 | wch = wForm; |
| 1366 | wLast = (FX_WCHAR)formChars[j - 1].wForm; |
| 1367 | } |
| 1368 | if (!bEmptyChar || (bEmptyChar && !bSkipSpace)) { |
| 1369 | pCharPos->m_GlyphIndex = |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1370 | bCharCode ? wch : pFont->GetGlyphIndex(wForm, false); |
thestig | ec51ac3 | 2016-06-20 10:38:52 -0700 | [diff] [blame] | 1371 | #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1372 | pCharPos->m_ExtGID = pCharPos->m_GlyphIndex; |
thestig | ec51ac3 | 2016-06-20 10:38:52 -0700 | [diff] [blame] | 1373 | #endif |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1374 | pCharPos->m_FontCharWidth = iCharWidth; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1375 | if (pWSForms) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1376 | *pWSForms += wForm; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1377 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1378 | |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 1379 | int32_t iCharHeight; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1380 | if (bVerticalDoc) { |
| 1381 | iCharHeight = iCharWidth; |
| 1382 | iCharWidth = 1000; |
| 1383 | } else { |
| 1384 | iCharHeight = 1000; |
| 1385 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1386 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1387 | fCharWidth = fFontSize * iCharWidth / 1000.0f; |
| 1388 | fCharHeight = fFontSize * iCharHeight / 1000.0f; |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 1389 | if (bRTLPiece && chartype != FX_CHARTYPE_Combination) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1390 | if (bVerticalDoc) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1391 | fY -= fCharHeight; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1392 | else |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1393 | fX -= fCharWidth; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1394 | } |
| 1395 | if (!bEmptyChar || (bEmptyChar && !bSkipSpace)) { |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1396 | pCharPos->m_Origin = CFX_PointF(fX, fY); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1397 | if ((dwStyles & FX_TXTLAYOUTSTYLE_CombText) != 0) { |
| 1398 | int32_t iFormWidth = iCharWidth; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1399 | pFont->GetCharWidth(wForm, iFormWidth, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1400 | FX_FLOAT fOffset = fFontSize * (iCharWidth - iFormWidth) / 2000.0f; |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1401 | if (bVerticalDoc) |
| 1402 | pCharPos->m_Origin.y += fOffset; |
| 1403 | else |
| 1404 | pCharPos->m_Origin.x += fOffset; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1405 | } |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1406 | |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 1407 | if (chartype == FX_CHARTYPE_Combination) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1408 | CFX_Rect rtBBox; |
tsepez | 6fd07ef | 2017-01-06 09:48:18 -0800 | [diff] [blame] | 1409 | if (pFont->GetCharBBox(wForm, &rtBBox, false)) { |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1410 | pCharPos->m_Origin.y = |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1411 | fYBase + fFontSize - |
| 1412 | fFontSize * (FX_FLOAT)rtBBox.height / (FX_FLOAT)iMaxHeight; |
| 1413 | } |
| 1414 | if (wForm == wch && wLast != 0xFEFF) { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1415 | uint32_t dwLastProps = FX_GetUnicodeProperties(wLast); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1416 | if ((dwLastProps & FX_CHARTYPEBITSMASK) == |
| 1417 | FX_CHARTYPE_Combination) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 1418 | CFX_Rect rtBox; |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1419 | if (pFont->GetCharBBox(wLast, &rtBox, false)) |
| 1420 | pCharPos->m_Origin.y -= fFontSize * rtBox.height / iMaxHeight; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1421 | } |
| 1422 | } |
| 1423 | } |
| 1424 | CFX_PointF ptOffset; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1425 | bool bAdjusted = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1426 | if (pAdjustPos) { |
| 1427 | bAdjusted = pAdjustPos(wForm, bCharCode, pFont, fFontSize, |
| 1428 | bVerticalChar, ptOffset); |
| 1429 | } |
| 1430 | if (!bAdjusted && bVerticalChar && (dwProps & 0x00010000) != 0) { |
| 1431 | CFX_Rect rtBBox; |
tsepez | 6fd07ef | 2017-01-06 09:48:18 -0800 | [diff] [blame] | 1432 | if (pFont->GetCharBBox(wForm, &rtBBox, false)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1433 | ptOffset.x = fFontSize * (850 - rtBBox.right()) / iMaxHeight; |
| 1434 | ptOffset.y = fFontSize * (iAscent - rtBBox.top - 150) / iMaxHeight; |
| 1435 | } |
| 1436 | } |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1437 | pCharPos->m_Origin.x += ptOffset.x; |
| 1438 | pCharPos->m_Origin.y -= ptOffset.y; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1439 | } |
weili | a2c06e4 | 2016-05-20 17:09:48 -0700 | [diff] [blame] | 1440 | if (!bRTLPiece && chartype != FX_CHARTYPE_Combination) { |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1441 | if (bVerticalDoc) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1442 | fY += fCharHeight; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1443 | else |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1444 | fX += fCharWidth; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1445 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1446 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1447 | if (!bEmptyChar || (bEmptyChar && !bSkipSpace)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1448 | pCharPos->m_bGlyphAdjust = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1449 | if (bVerticalDoc) { |
| 1450 | if (iCharRotation == 0) { |
| 1451 | pCharPos->m_AdjustMatrix[0] = -1; |
| 1452 | pCharPos->m_AdjustMatrix[1] = 0; |
| 1453 | pCharPos->m_AdjustMatrix[2] = 0; |
| 1454 | pCharPos->m_AdjustMatrix[3] = 1; |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1455 | pCharPos->m_Origin.y += fAscent; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1456 | } else if (iCharRotation == 1) { |
| 1457 | pCharPos->m_AdjustMatrix[0] = 0; |
| 1458 | pCharPos->m_AdjustMatrix[1] = -1; |
| 1459 | pCharPos->m_AdjustMatrix[2] = -1; |
| 1460 | pCharPos->m_AdjustMatrix[3] = 0; |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1461 | pCharPos->m_Origin.x -= fDescent; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1462 | } else if (iCharRotation == 2) { |
| 1463 | pCharPos->m_AdjustMatrix[0] = 1; |
| 1464 | pCharPos->m_AdjustMatrix[1] = 0; |
| 1465 | pCharPos->m_AdjustMatrix[2] = 0; |
| 1466 | pCharPos->m_AdjustMatrix[3] = -1; |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1467 | pCharPos->m_Origin.x += fCharWidth; |
| 1468 | pCharPos->m_Origin.y += fAscent; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1469 | } else { |
| 1470 | pCharPos->m_AdjustMatrix[0] = 0; |
| 1471 | pCharPos->m_AdjustMatrix[1] = 1; |
| 1472 | pCharPos->m_AdjustMatrix[2] = 1; |
| 1473 | pCharPos->m_AdjustMatrix[3] = 0; |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1474 | pCharPos->m_Origin.x += fAscent; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1475 | } |
| 1476 | } else { |
| 1477 | if (iCharRotation == 0) { |
| 1478 | pCharPos->m_AdjustMatrix[0] = -1; |
| 1479 | pCharPos->m_AdjustMatrix[1] = 0; |
| 1480 | pCharPos->m_AdjustMatrix[2] = 0; |
| 1481 | pCharPos->m_AdjustMatrix[3] = 1; |
| 1482 | } else if (iCharRotation == 1) { |
| 1483 | pCharPos->m_AdjustMatrix[0] = 0; |
| 1484 | pCharPos->m_AdjustMatrix[1] = -1; |
| 1485 | pCharPos->m_AdjustMatrix[2] = -1; |
| 1486 | pCharPos->m_AdjustMatrix[3] = 0; |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1487 | pCharPos->m_Origin.x -= fDescent; |
| 1488 | pCharPos->m_Origin.y -= fAscent + fDescent; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1489 | } else if (iCharRotation == 2) { |
| 1490 | pCharPos->m_AdjustMatrix[0] = 1; |
| 1491 | pCharPos->m_AdjustMatrix[1] = 0; |
| 1492 | pCharPos->m_AdjustMatrix[2] = 0; |
| 1493 | pCharPos->m_AdjustMatrix[3] = -1; |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1494 | pCharPos->m_Origin.x += fCharWidth; |
| 1495 | pCharPos->m_Origin.y -= fAscent; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1496 | } else { |
| 1497 | pCharPos->m_AdjustMatrix[0] = 0; |
| 1498 | pCharPos->m_AdjustMatrix[1] = 1; |
| 1499 | pCharPos->m_AdjustMatrix[2] = 1; |
| 1500 | pCharPos->m_AdjustMatrix[3] = 0; |
Dan Sinclair | 2c02fae | 2017-02-16 13:42:11 -0500 | [diff] [blame] | 1501 | pCharPos->m_Origin.x += fAscent; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1502 | } |
| 1503 | } |
| 1504 | if (iHorScale != 100 || iVerScale != 100) { |
| 1505 | pCharPos->m_AdjustMatrix[0] = |
| 1506 | pCharPos->m_AdjustMatrix[0] * iHorScale / 100.0f; |
| 1507 | pCharPos->m_AdjustMatrix[1] = |
| 1508 | pCharPos->m_AdjustMatrix[1] * iHorScale / 100.0f; |
| 1509 | pCharPos->m_AdjustMatrix[2] = |
| 1510 | pCharPos->m_AdjustMatrix[2] * iVerScale / 100.0f; |
| 1511 | pCharPos->m_AdjustMatrix[3] = |
| 1512 | pCharPos->m_AdjustMatrix[3] * iVerScale / 100.0f; |
| 1513 | } |
| 1514 | pCharPos++; |
| 1515 | } |
| 1516 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1517 | if (iWidth > 0) |
| 1518 | wPrev = static_cast<FX_WCHAR>(formChars[0].wch); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1519 | wLast = wch; |
| 1520 | } |
| 1521 | return iCount; |
| 1522 | } |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 1523 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1524 | int32_t CFX_TxtBreak::GetCharRects(const FX_TXTRUN* pTxtRun, |
tsepez | 3d32876 | 2017-01-24 06:12:34 -0800 | [diff] [blame] | 1525 | std::vector<CFX_RectF>* rtArray, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1526 | bool bCharBBox) const { |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 1527 | if (!pTxtRun || pTxtRun->iLength < 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1528 | return 0; |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 1529 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1530 | IFX_TxtAccess* pAccess = pTxtRun->pAccess; |
dsinclair | 705f829 | 2016-06-07 10:10:45 -0700 | [diff] [blame] | 1531 | const FDE_TEXTEDITPIECE* pIdentity = pTxtRun->pIdentity; |
tsepez | d403329 | 2016-04-19 12:03:15 -0700 | [diff] [blame] | 1532 | const FX_WCHAR* pStr = pTxtRun->wsStr.c_str(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1533 | int32_t* pWidths = pTxtRun->pWidths; |
| 1534 | int32_t iLength = pTxtRun->iLength; |
| 1535 | CFX_RectF rect(*pTxtRun->pRect); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1536 | bool bRTLPiece = (pTxtRun->dwCharStyles & FX_TXTCHARSTYLE_OddBidiLevel) != 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1537 | FX_FLOAT fFontSize = pTxtRun->fFontSize; |
| 1538 | int32_t iFontSize = FXSYS_round(fFontSize * 20.0f); |
| 1539 | FX_FLOAT fScale = fFontSize / 1000.0f; |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 1540 | CFX_RetainPtr<CFGAS_GEFont> pFont = pTxtRun->pFont; |
| 1541 | if (!pFont) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1542 | bCharBBox = false; |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 1543 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1544 | CFX_Rect bbox; |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 1545 | if (bCharBBox) |
tsepez | 6fd07ef | 2017-01-06 09:48:18 -0800 | [diff] [blame] | 1546 | bCharBBox = pFont->GetBBox(&bbox); |
tsepez | e647799 | 2017-01-05 12:57:00 -0800 | [diff] [blame] | 1547 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1548 | FX_FLOAT fLeft = std::max(0.0f, bbox.left * fScale); |
| 1549 | FX_FLOAT fHeight = FXSYS_fabs(bbox.height * fScale); |
tsepez | 3d32876 | 2017-01-24 06:12:34 -0800 | [diff] [blame] | 1550 | rtArray->clear(); |
| 1551 | rtArray->resize(iLength); |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1552 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1553 | bool bVertical = (pTxtRun->dwStyles & FX_TXTLAYOUTSTYLE_VerticalLayout) != 0; |
| 1554 | bool bSingleLine = (pTxtRun->dwStyles & FX_TXTLAYOUTSTYLE_SingleLine) != 0; |
| 1555 | bool bCombText = (pTxtRun->dwStyles & FX_TXTLAYOUTSTYLE_CombText) != 0; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1556 | FX_WCHAR wch; |
| 1557 | FX_WCHAR wLineBreakChar = pTxtRun->wLineBreakChar; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1558 | int32_t iCharSize; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1559 | FX_FLOAT fCharSize; |
| 1560 | FX_FLOAT fStart; |
| 1561 | if (bVertical) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1562 | fStart = bRTLPiece ? rect.bottom() : rect.top; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1563 | else |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1564 | fStart = bRTLPiece ? rect.right() : rect.left; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1565 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1566 | for (int32_t i = 0; i < iLength; i++) { |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1567 | if (pAccess) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1568 | wch = pAccess->GetChar(pIdentity, i); |
| 1569 | iCharSize = pAccess->GetWidth(pIdentity, i); |
| 1570 | } else { |
| 1571 | wch = *pStr++; |
| 1572 | iCharSize = *pWidths++; |
| 1573 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1574 | fCharSize = static_cast<FX_FLOAT>(iCharSize) / 20000.0f; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1575 | bool bRet = (!bSingleLine && FX_IsCtrlCode(wch)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1576 | if (!(wch == L'\v' || wch == L'\f' || wch == 0x2028 || wch == 0x2029 || |
| 1577 | (wLineBreakChar != 0xFEFF && wch == wLineBreakChar))) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1578 | bRet = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1579 | } |
| 1580 | if (bRet) { |
| 1581 | iCharSize = iFontSize * 500; |
| 1582 | fCharSize = fFontSize / 2.0f; |
| 1583 | } |
| 1584 | if (bVertical) { |
| 1585 | rect.top = fStart; |
| 1586 | if (bRTLPiece) { |
| 1587 | rect.top -= fCharSize; |
| 1588 | fStart -= fCharSize; |
| 1589 | } else { |
| 1590 | fStart += fCharSize; |
| 1591 | } |
| 1592 | rect.height = fCharSize; |
| 1593 | } else { |
| 1594 | rect.left = fStart; |
| 1595 | if (bRTLPiece) { |
| 1596 | rect.left -= fCharSize; |
| 1597 | fStart -= fCharSize; |
| 1598 | } else { |
| 1599 | fStart += fCharSize; |
| 1600 | } |
| 1601 | rect.width = fCharSize; |
| 1602 | } |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1603 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1604 | if (bCharBBox && !bRet) { |
| 1605 | int32_t iCharWidth = 1000; |
thestig | 2c06532 | 2016-09-26 14:16:43 -0700 | [diff] [blame] | 1606 | pFont->GetCharWidth(wch, iCharWidth, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1607 | FX_FLOAT fRTLeft = 0, fCharWidth = 0; |
| 1608 | if (iCharWidth > 0) { |
| 1609 | fCharWidth = iCharWidth * fScale; |
| 1610 | fRTLeft = fLeft; |
Dan Sinclair | 17f3118 | 2017-03-01 09:31:51 -0500 | [diff] [blame^] | 1611 | if (bCombText) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1612 | fRTLeft = (rect.width - fCharWidth) / 2.0f; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1613 | } |
| 1614 | CFX_RectF rtBBoxF; |
| 1615 | if (bVertical) { |
| 1616 | rtBBoxF.top = rect.left + fRTLeft; |
| 1617 | rtBBoxF.left = rect.top + (rect.height - fHeight) / 2.0f; |
| 1618 | rtBBoxF.height = fCharWidth; |
| 1619 | rtBBoxF.width = fHeight; |
| 1620 | rtBBoxF.left = std::max(rtBBoxF.left, 0.0f); |
| 1621 | } else { |
| 1622 | rtBBoxF.left = rect.left + fRTLeft; |
| 1623 | rtBBoxF.top = rect.top + (rect.height - fHeight) / 2.0f; |
| 1624 | rtBBoxF.width = fCharWidth; |
| 1625 | rtBBoxF.height = fHeight; |
| 1626 | rtBBoxF.top = std::max(rtBBoxF.top, 0.0f); |
| 1627 | } |
tsepez | 3d32876 | 2017-01-24 06:12:34 -0800 | [diff] [blame] | 1628 | (*rtArray)[i] = rtBBoxF; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1629 | continue; |
| 1630 | } |
tsepez | 3d32876 | 2017-01-24 06:12:34 -0800 | [diff] [blame] | 1631 | (*rtArray)[i] = rect; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1632 | } |
| 1633 | return iLength; |
| 1634 | } |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 1635 | |
| 1636 | FX_TXTRUN::FX_TXTRUN() |
| 1637 | : pAccess(nullptr), |
| 1638 | pIdentity(nullptr), |
| 1639 | pWidths(nullptr), |
| 1640 | iLength(0), |
| 1641 | pFont(nullptr), |
| 1642 | fFontSize(12), |
| 1643 | dwStyles(0), |
| 1644 | iHorizontalScale(100), |
| 1645 | iVerticalScale(100), |
| 1646 | iCharRotation(0), |
| 1647 | dwCharStyles(0), |
| 1648 | pRect(nullptr), |
| 1649 | wLineBreakChar(L'\n'), |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1650 | bSkipSpace(true) {} |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 1651 | |
| 1652 | FX_TXTRUN::~FX_TXTRUN() {} |
| 1653 | |
| 1654 | FX_TXTRUN::FX_TXTRUN(const FX_TXTRUN& other) = default; |
| 1655 | |
| 1656 | CFX_TxtPiece::CFX_TxtPiece() |
| 1657 | : m_dwStatus(FX_TXTBREAK_PieceBreak), |
| 1658 | m_iStartPos(0), |
| 1659 | m_iWidth(-1), |
| 1660 | m_iStartChar(0), |
| 1661 | m_iChars(0), |
| 1662 | m_iBidiLevel(0), |
| 1663 | m_iBidiPos(0), |
| 1664 | m_iHorizontalScale(100), |
| 1665 | m_iVerticalScale(100), |
| 1666 | m_dwCharStyles(0), |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1667 | m_pChars(nullptr), |
| 1668 | m_pUserData(nullptr) {} |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 1669 | |
| 1670 | CFX_TxtLine::CFX_TxtLine(int32_t iBlockSize) |
tsepez | 33316fc | 2017-01-24 12:17:40 -0800 | [diff] [blame] | 1671 | : m_pLineChars(new std::vector<CFX_TxtChar>), |
weili | 1b4f6b3 | 2016-08-04 16:37:48 -0700 | [diff] [blame] | 1672 | m_pLinePieces(new CFX_TxtPieceArray(16)), |
| 1673 | m_iStart(0), |
| 1674 | m_iWidth(0), |
| 1675 | m_iArabicChars(0) {} |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 1676 | |
| 1677 | CFX_TxtLine::~CFX_TxtLine() { |
| 1678 | RemoveAll(); |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 1679 | } |