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