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