| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "../../include/fpdfdoc/fpdf_doc.h" | 7 #include "../../include/fpdfdoc/fpdf_doc.h" |
| 8 #include "../../include/fpdfdoc/fpdf_vt.h" | 8 #include "../../include/fpdfdoc/fpdf_vt.h" |
| 9 #include "pdf_vt.h" | 9 #include "pdf_vt.h" |
| 10 const uint8_t gFontSizeSteps[] = { 4, 6, 8, 9, 10, 12, 14, 18, 20, 25,
30, 35, 40, 45, 50, 55, 60, 70, 80, 90, 100, 110, 120, 130, 144}; | 10 const uint8_t gFontSizeSteps[] = {4, 6, 8, 9, 10, 12, 14, 18, 20, |
| 11 #define PVT_RETURN_LENGTH 1 | 11 25, 30, 35, 40, 45, 50, 55, 60, 70, |
| 12 #define PVT_DEFAULT_FONTSIZE 18.0f | 12 80, 90, 100, 110, 120, 130, 144}; |
| 13 #define PVTWORD_SCRIPT_NORMAL 0 | 13 #define PVT_RETURN_LENGTH 1 |
| 14 #define PVTWORD_SCRIPT_SUPER 1 | 14 #define PVT_DEFAULT_FONTSIZE 18.0f |
| 15 #define PVTWORD_SCRIPT_SUB 2 | 15 #define PVTWORD_SCRIPT_NORMAL 0 |
| 16 #define PVT_FONTSCALE 0.001f | 16 #define PVTWORD_SCRIPT_SUPER 1 |
| 17 #define PVT_PERCENT 0.01f | 17 #define PVTWORD_SCRIPT_SUB 2 |
| 18 #define PVT_HALF 0.5f | 18 #define PVT_FONTSCALE 0.001f |
| 19 CLine::CLine() | 19 #define PVT_PERCENT 0.01f |
| 20 { | 20 #define PVT_HALF 0.5f |
| 21 } | 21 CLine::CLine() {} |
| 22 CLine::~CLine() | 22 CLine::~CLine() {} |
| 23 { | 23 CPVT_WordPlace CLine::GetBeginWordPlace() const { |
| 24 } | 24 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, -1); |
| 25 CPVT_WordPlace CLine::GetBeginWordPlace() const | 25 } |
| 26 { | 26 CPVT_WordPlace CLine::GetEndWordPlace() const { |
| 27 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, -1); | 27 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, |
| 28 } | 28 m_LineInfo.nEndWordIndex); |
| 29 CPVT_WordPlace CLine::GetEndWordPlace() const | 29 } |
| 30 { | 30 CPVT_WordPlace CLine::GetPrevWordPlace(const CPVT_WordPlace& place) const { |
| 31 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, m_LineInfo.
nEndWordIndex); | 31 if (place.nWordIndex > m_LineInfo.nEndWordIndex) { |
| 32 } | 32 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, |
| 33 CPVT_WordPlace CLine::GetPrevWordPlace(const CPVT_WordPlace & place) const | 33 m_LineInfo.nEndWordIndex); |
| 34 { | 34 } |
| 35 if (place.nWordIndex > m_LineInfo.nEndWordIndex) { | 35 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, |
| 36 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, m_LineInfo.nEnd
WordIndex); | 36 place.nWordIndex - 1); |
| 37 } | 37 } |
| 38 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, place.nWordIndex -
1); | 38 CPVT_WordPlace CLine::GetNextWordPlace(const CPVT_WordPlace& place) const { |
| 39 } | 39 if (place.nWordIndex < m_LineInfo.nBeginWordIndex) { |
| 40 CPVT_WordPlace CLine::GetNextWordPlace(const CPVT_WordPlace & place) const | 40 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, |
| 41 { | 41 m_LineInfo.nBeginWordIndex); |
| 42 if (place.nWordIndex < m_LineInfo.nBeginWordIndex) { | 42 } |
| 43 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, m_LineInfo.nBeg
inWordIndex); | 43 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, |
| 44 } | 44 place.nWordIndex + 1); |
| 45 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, place.nWordIndex +
1); | 45 } |
| 46 } | 46 CSection::CSection(CPDF_VariableText* pVT) : m_pVT(pVT) {} |
| 47 CSection::CSection(CPDF_VariableText * pVT) : m_pVT(pVT) | 47 CSection::~CSection() { |
| 48 { | 48 ResetAll(); |
| 49 } | 49 } |
| 50 CSection::~CSection() | 50 void CSection::ResetAll() { |
| 51 { | 51 ResetWordArray(); |
| 52 ResetAll(); | 52 ResetLineArray(); |
| 53 } | 53 } |
| 54 void CSection::ResetAll() | 54 void CSection::ResetLineArray() { |
| 55 { | 55 m_LineArray.RemoveAll(); |
| 56 } |
| 57 void CSection::ResetWordArray() { |
| 58 for (int32_t i = 0, sz = m_WordArray.GetSize(); i < sz; i++) { |
| 59 delete m_WordArray.GetAt(i); |
| 60 } |
| 61 m_WordArray.RemoveAll(); |
| 62 } |
| 63 void CSection::ResetLinePlace() { |
| 64 for (int32_t i = 0, sz = m_LineArray.GetSize(); i < sz; i++) { |
| 65 if (CLine* pLine = m_LineArray.GetAt(i)) { |
| 66 pLine->LinePlace = CPVT_WordPlace(SecPlace.nSecIndex, i, -1); |
| 67 } |
| 68 } |
| 69 } |
| 70 CPVT_WordPlace CSection::AddWord(const CPVT_WordPlace& place, |
| 71 const CPVT_WordInfo& wordinfo) { |
| 72 CPVT_WordInfo* pWord = new CPVT_WordInfo(wordinfo); |
| 73 int32_t nWordIndex = |
| 74 FPDF_MAX(FPDF_MIN(place.nWordIndex, m_WordArray.GetSize()), 0); |
| 75 if (nWordIndex == m_WordArray.GetSize()) { |
| 76 m_WordArray.Add(pWord); |
| 77 } else { |
| 78 m_WordArray.InsertAt(nWordIndex, pWord); |
| 79 } |
| 80 return place; |
| 81 } |
| 82 CPVT_WordPlace CSection::AddLine(const CPVT_LineInfo& lineinfo) { |
| 83 return CPVT_WordPlace(SecPlace.nSecIndex, m_LineArray.Add(lineinfo), -1); |
| 84 } |
| 85 CPVT_FloatRect CSection::Rearrange() { |
| 86 ASSERT(m_pVT != NULL); |
| 87 if (m_pVT->m_nCharArray > 0) { |
| 88 return CTypeset(this).CharArray(); |
| 89 } |
| 90 return CTypeset(this).Typeset(); |
| 91 } |
| 92 CPVT_Size CSection::GetSectionSize(FX_FLOAT fFontSize) { |
| 93 return CTypeset(this).GetEditSize(fFontSize); |
| 94 } |
| 95 CPVT_WordPlace CSection::GetBeginWordPlace() const { |
| 96 if (CLine* pLine = m_LineArray.GetAt(0)) { |
| 97 return pLine->GetBeginWordPlace(); |
| 98 } |
| 99 return SecPlace; |
| 100 } |
| 101 CPVT_WordPlace CSection::GetEndWordPlace() const { |
| 102 if (CLine* pLine = m_LineArray.GetAt(m_LineArray.GetSize() - 1)) { |
| 103 return pLine->GetEndWordPlace(); |
| 104 } |
| 105 return SecPlace; |
| 106 } |
| 107 CPVT_WordPlace CSection::GetPrevWordPlace(const CPVT_WordPlace& place) const { |
| 108 if (place.nLineIndex < 0) { |
| 109 return GetBeginWordPlace(); |
| 110 } |
| 111 if (place.nLineIndex >= m_LineArray.GetSize()) { |
| 112 return GetEndWordPlace(); |
| 113 } |
| 114 if (CLine* pLine = m_LineArray.GetAt(place.nLineIndex)) { |
| 115 if (place.nWordIndex == pLine->m_LineInfo.nBeginWordIndex) { |
| 116 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, -1); |
| 117 } |
| 118 if (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) { |
| 119 if (CLine* pPrevLine = m_LineArray.GetAt(place.nLineIndex - 1)) { |
| 120 return pPrevLine->GetEndWordPlace(); |
| 121 } |
| 122 } else { |
| 123 return pLine->GetPrevWordPlace(place); |
| 124 } |
| 125 } |
| 126 return place; |
| 127 } |
| 128 CPVT_WordPlace CSection::GetNextWordPlace(const CPVT_WordPlace& place) const { |
| 129 if (place.nLineIndex < 0) { |
| 130 return GetBeginWordPlace(); |
| 131 } |
| 132 if (place.nLineIndex >= m_LineArray.GetSize()) { |
| 133 return GetEndWordPlace(); |
| 134 } |
| 135 if (CLine* pLine = m_LineArray.GetAt(place.nLineIndex)) { |
| 136 if (place.nWordIndex >= pLine->m_LineInfo.nEndWordIndex) { |
| 137 if (CLine* pNextLine = m_LineArray.GetAt(place.nLineIndex + 1)) { |
| 138 return pNextLine->GetBeginWordPlace(); |
| 139 } |
| 140 } else { |
| 141 return pLine->GetNextWordPlace(place); |
| 142 } |
| 143 } |
| 144 return place; |
| 145 } |
| 146 void CSection::UpdateWordPlace(CPVT_WordPlace& place) const { |
| 147 int32_t nLeft = 0; |
| 148 int32_t nRight = m_LineArray.GetSize() - 1; |
| 149 int32_t nMid = (nLeft + nRight) / 2; |
| 150 while (nLeft <= nRight) { |
| 151 if (CLine* pLine = m_LineArray.GetAt(nMid)) { |
| 152 if (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) { |
| 153 nRight = nMid - 1; |
| 154 nMid = (nLeft + nRight) / 2; |
| 155 } else if (place.nWordIndex > pLine->m_LineInfo.nEndWordIndex) { |
| 156 nLeft = nMid + 1; |
| 157 nMid = (nLeft + nRight) / 2; |
| 158 } else { |
| 159 place.nLineIndex = nMid; |
| 160 return; |
| 161 } |
| 162 } else { |
| 163 break; |
| 164 } |
| 165 } |
| 166 } |
| 167 CPVT_WordPlace CSection::SearchWordPlace(const CPDF_Point& point) const { |
| 168 ASSERT(m_pVT != NULL); |
| 169 CPVT_WordPlace place = GetBeginWordPlace(); |
| 170 FX_BOOL bUp = TRUE; |
| 171 FX_BOOL bDown = TRUE; |
| 172 int32_t nLeft = 0; |
| 173 int32_t nRight = m_LineArray.GetSize() - 1; |
| 174 int32_t nMid = m_LineArray.GetSize() / 2; |
| 175 FX_FLOAT fTop = 0; |
| 176 FX_FLOAT fBottom = 0; |
| 177 while (nLeft <= nRight) { |
| 178 if (CLine* pLine = m_LineArray.GetAt(nMid)) { |
| 179 fTop = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineAscent - |
| 180 m_pVT->GetLineLeading(m_SecInfo); |
| 181 fBottom = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineDescent; |
| 182 if (IsFloatBigger(point.y, fTop)) { |
| 183 bUp = FALSE; |
| 184 } |
| 185 if (IsFloatSmaller(point.y, fBottom)) { |
| 186 bDown = FALSE; |
| 187 } |
| 188 if (IsFloatSmaller(point.y, fTop)) { |
| 189 nRight = nMid - 1; |
| 190 nMid = (nLeft + nRight) / 2; |
| 191 continue; |
| 192 } else if (IsFloatBigger(point.y, fBottom)) { |
| 193 nLeft = nMid + 1; |
| 194 nMid = (nLeft + nRight) / 2; |
| 195 continue; |
| 196 } else { |
| 197 place = SearchWordPlace( |
| 198 point.x, |
| 199 CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()), |
| 200 pLine->GetEndWordPlace())); |
| 201 place.nLineIndex = nMid; |
| 202 return place; |
| 203 } |
| 204 } |
| 205 } |
| 206 if (bUp) { |
| 207 place = GetBeginWordPlace(); |
| 208 } |
| 209 if (bDown) { |
| 210 place = GetEndWordPlace(); |
| 211 } |
| 212 return place; |
| 213 } |
| 214 CPVT_WordPlace CSection::SearchWordPlace( |
| 215 FX_FLOAT fx, |
| 216 const CPVT_WordPlace& lineplace) const { |
| 217 if (CLine* pLine = m_LineArray.GetAt(lineplace.nLineIndex)) { |
| 218 return SearchWordPlace( |
| 219 fx - m_SecInfo.rcSection.left, |
| 220 CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()), |
| 221 pLine->GetEndWordPlace())); |
| 222 } |
| 223 return GetBeginWordPlace(); |
| 224 } |
| 225 CPVT_WordPlace CSection::SearchWordPlace(FX_FLOAT fx, |
| 226 const CPVT_WordRange& range) const { |
| 227 CPVT_WordPlace wordplace = range.BeginPos; |
| 228 wordplace.nWordIndex = -1; |
| 229 if (!m_pVT) { |
| 230 return wordplace; |
| 231 } |
| 232 int32_t nLeft = range.BeginPos.nWordIndex; |
| 233 int32_t nRight = range.EndPos.nWordIndex + 1; |
| 234 int32_t nMid = (nLeft + nRight) / 2; |
| 235 while (nLeft < nRight) { |
| 236 if (nMid == nLeft) { |
| 237 break; |
| 238 } |
| 239 if (nMid == nRight) { |
| 240 nMid--; |
| 241 break; |
| 242 } |
| 243 if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) { |
| 244 if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * PVT_HALF) { |
| 245 nLeft = nMid; |
| 246 nMid = (nLeft + nRight) / 2; |
| 247 continue; |
| 248 } else { |
| 249 nRight = nMid; |
| 250 nMid = (nLeft + nRight) / 2; |
| 251 continue; |
| 252 } |
| 253 } else { |
| 254 break; |
| 255 } |
| 256 } |
| 257 if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) { |
| 258 if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * PVT_HALF) { |
| 259 wordplace.nWordIndex = nMid; |
| 260 } |
| 261 } |
| 262 return wordplace; |
| 263 } |
| 264 void CSection::ClearLeftWords(int32_t nWordIndex) { |
| 265 for (int32_t i = nWordIndex; i >= 0; i--) { |
| 266 delete m_WordArray.GetAt(i); |
| 267 m_WordArray.RemoveAt(i); |
| 268 } |
| 269 } |
| 270 void CSection::ClearRightWords(int32_t nWordIndex) { |
| 271 for (int32_t i = m_WordArray.GetSize() - 1; i > nWordIndex; i--) { |
| 272 delete m_WordArray.GetAt(i); |
| 273 m_WordArray.RemoveAt(i); |
| 274 } |
| 275 } |
| 276 void CSection::ClearMidWords(int32_t nBeginIndex, int32_t nEndIndex) { |
| 277 for (int32_t i = nEndIndex; i > nBeginIndex; i--) { |
| 278 delete m_WordArray.GetAt(i); |
| 279 m_WordArray.RemoveAt(i); |
| 280 } |
| 281 } |
| 282 void CSection::ClearWords(const CPVT_WordRange& PlaceRange) { |
| 283 CPVT_WordPlace SecBeginPos = GetBeginWordPlace(); |
| 284 CPVT_WordPlace SecEndPos = GetEndWordPlace(); |
| 285 if (PlaceRange.BeginPos.WordCmp(SecBeginPos) >= 0) { |
| 286 if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) { |
| 287 ClearMidWords(PlaceRange.BeginPos.nWordIndex, |
| 288 PlaceRange.EndPos.nWordIndex); |
| 289 } else { |
| 290 ClearRightWords(PlaceRange.BeginPos.nWordIndex); |
| 291 } |
| 292 } else if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) { |
| 293 ClearLeftWords(PlaceRange.EndPos.nWordIndex); |
| 294 } else { |
| 56 ResetWordArray(); | 295 ResetWordArray(); |
| 57 ResetLineArray(); | 296 } |
| 58 } | 297 } |
| 59 void CSection::ResetLineArray() | 298 void CSection::ClearWord(const CPVT_WordPlace& place) { |
| 60 { | 299 delete m_WordArray.GetAt(place.nWordIndex); |
| 61 m_LineArray.RemoveAll(); | 300 m_WordArray.RemoveAt(place.nWordIndex); |
| 62 } | 301 } |
| 63 void CSection::ResetWordArray() | 302 CTypeset::CTypeset(CSection* pSection) |
| 64 { | 303 : m_rcRet(0.0f, 0.0f, 0.0f, 0.0f), |
| 65 for (int32_t i = 0, sz = m_WordArray.GetSize(); i < sz; i++) { | 304 m_pVT(pSection->m_pVT), |
| 66 delete m_WordArray.GetAt(i); | 305 m_pSection(pSection) {} |
| 67 } | 306 CTypeset::~CTypeset() {} |
| 68 m_WordArray.RemoveAll(); | 307 CPVT_FloatRect CTypeset::CharArray() { |
| 69 } | 308 ASSERT(m_pSection != NULL); |
| 70 void CSection::ResetLinePlace() | 309 ASSERT(m_pVT != NULL); |
| 71 { | 310 FX_FLOAT fLineAscent = |
| 72 for (int32_t i = 0, sz = m_LineArray.GetSize(); i < sz; i++) { | 311 m_pVT->GetFontAscent(m_pVT->GetDefaultFontIndex(), m_pVT->GetFontSize()); |
| 73 if (CLine * pLine = m_LineArray.GetAt(i)) { | 312 FX_FLOAT fLineDescent = |
| 74 pLine->LinePlace = CPVT_WordPlace(SecPlace.nSecIndex, i, -1); | 313 m_pVT->GetFontDescent(m_pVT->GetDefaultFontIndex(), m_pVT->GetFontSize()); |
| 314 m_rcRet.Default(); |
| 315 FX_FLOAT x = 0.0f, y = 0.0f; |
| 316 FX_FLOAT fNextWidth; |
| 317 int32_t nStart = 0; |
| 318 FX_FLOAT fNodeWidth = m_pVT->GetPlateWidth() / |
| 319 (m_pVT->m_nCharArray <= 0 ? 1 : m_pVT->m_nCharArray); |
| 320 if (CLine* pLine = m_pSection->m_LineArray.GetAt(0)) { |
| 321 x = 0.0f; |
| 322 y += m_pVT->GetLineLeading(m_pSection->m_SecInfo); |
| 323 y += fLineAscent; |
| 324 nStart = 0; |
| 325 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { |
| 326 case 0: |
| 327 pLine->m_LineInfo.fLineX = fNodeWidth * PVT_HALF; |
| 328 break; |
| 329 case 1: |
| 330 nStart = (m_pVT->m_nCharArray - m_pSection->m_WordArray.GetSize()) / 2; |
| 331 pLine->m_LineInfo.fLineX = fNodeWidth * nStart - fNodeWidth * PVT_HALF; |
| 332 break; |
| 333 case 2: |
| 334 nStart = m_pVT->m_nCharArray - m_pSection->m_WordArray.GetSize(); |
| 335 pLine->m_LineInfo.fLineX = fNodeWidth * nStart - fNodeWidth * PVT_HALF; |
| 336 break; |
| 337 } |
| 338 for (int32_t w = 0, sz = m_pSection->m_WordArray.GetSize(); w < sz; w++) { |
| 339 if (w >= m_pVT->m_nCharArray) { |
| 340 break; |
| 341 } |
| 342 fNextWidth = 0; |
| 343 if (CPVT_WordInfo* pNextWord = |
| 344 (CPVT_WordInfo*)m_pSection->m_WordArray.GetAt(w + 1)) { |
| 345 pNextWord->fWordTail = 0; |
| 346 fNextWidth = m_pVT->GetWordWidth(*pNextWord); |
| 347 } |
| 348 if (CPVT_WordInfo* pWord = |
| 349 (CPVT_WordInfo*)m_pSection->m_WordArray.GetAt(w)) { |
| 350 pWord->fWordTail = 0; |
| 351 FX_FLOAT fWordWidth = m_pVT->GetWordWidth(*pWord); |
| 352 FX_FLOAT fWordAscent = m_pVT->GetWordAscent(*pWord); |
| 353 FX_FLOAT fWordDescent = m_pVT->GetWordDescent(*pWord); |
| 354 x = (FX_FLOAT)(fNodeWidth * (w + nStart + 0.5) - fWordWidth * PVT_HALF); |
| 355 pWord->fWordX = x; |
| 356 pWord->fWordY = y; |
| 357 if (w == 0) { |
| 358 pLine->m_LineInfo.fLineX = x; |
| 75 } | 359 } |
| 76 } | 360 if (w != m_pSection->m_WordArray.GetSize() - 1) |
| 77 } | 361 pWord->fWordTail = |
| 78 CPVT_WordPlace CSection::AddWord(const CPVT_WordPlace & place, const CPVT_WordIn
fo & wordinfo) | 362 (fNodeWidth - (fWordWidth + fNextWidth) * PVT_HALF > 0 |
| 79 { | 363 ? fNodeWidth - (fWordWidth + fNextWidth) * PVT_HALF |
| 80 CPVT_WordInfo * pWord = new CPVT_WordInfo(wordinfo); | 364 : 0); |
| 81 int32_t nWordIndex = FPDF_MAX(FPDF_MIN(place.nWordIndex, m_WordArray.GetSize
()), 0); | 365 else { |
| 82 if (nWordIndex == m_WordArray.GetSize()) { | 366 pWord->fWordTail = 0; |
| 83 m_WordArray.Add(pWord); | 367 } |
| 368 x += fWordWidth; |
| 369 fLineAscent = FPDF_MAX(fLineAscent, fWordAscent); |
| 370 fLineDescent = FPDF_MIN(fLineDescent, fWordDescent); |
| 371 } |
| 372 } |
| 373 pLine->m_LineInfo.nBeginWordIndex = 0; |
| 374 pLine->m_LineInfo.nEndWordIndex = m_pSection->m_WordArray.GetSize() - 1; |
| 375 pLine->m_LineInfo.fLineY = y; |
| 376 pLine->m_LineInfo.fLineWidth = x - pLine->m_LineInfo.fLineX; |
| 377 pLine->m_LineInfo.fLineAscent = fLineAscent; |
| 378 pLine->m_LineInfo.fLineDescent = fLineDescent; |
| 379 y += (-fLineDescent); |
| 380 } |
| 381 return m_rcRet = CPVT_FloatRect(0, 0, x, y); |
| 382 } |
| 383 CPVT_Size CTypeset::GetEditSize(FX_FLOAT fFontSize) { |
| 384 ASSERT(m_pSection != NULL); |
| 385 ASSERT(m_pVT != NULL); |
| 386 SplitLines(FALSE, fFontSize); |
| 387 return CPVT_Size(m_rcRet.Width(), m_rcRet.Height()); |
| 388 } |
| 389 CPVT_FloatRect CTypeset::Typeset() { |
| 390 ASSERT(m_pSection != NULL); |
| 391 ASSERT(m_pVT != NULL); |
| 392 m_pSection->m_LineArray.Empty(); |
| 393 SplitLines(TRUE, 0.0f); |
| 394 m_pSection->m_LineArray.Clear(); |
| 395 OutputLines(); |
| 396 return m_rcRet; |
| 397 } |
| 398 static int special_chars[128] = { |
| 399 0x0000, 0x000C, 0x0008, 0x000C, 0x0008, 0x0000, 0x0020, 0x0000, 0x0000, |
| 400 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 401 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 402 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0008, 0x0008, 0x0000, |
| 403 0x0010, 0x0000, 0x0000, 0x0028, 0x000C, 0x0008, 0x0000, 0x0000, 0x0028, |
| 404 0x0028, 0x0028, 0x0028, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, |
| 405 0x0002, 0x0002, 0x0002, 0x0002, 0x0008, 0x0008, 0x0000, 0x0000, 0x0000, |
| 406 0x0008, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, |
| 407 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, |
| 408 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, |
| 409 0x0001, 0x000C, 0x0000, 0x0008, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, |
| 410 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, |
| 411 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, |
| 412 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x000C, 0x0000, 0x0008, |
| 413 0x0000, 0x0000, |
| 414 }; |
| 415 static FX_BOOL IsLatin(FX_WORD word) { |
| 416 if (word <= 0x007F) { |
| 417 if (special_chars[word] & 0x0001) { |
| 418 return TRUE; |
| 419 } |
| 420 } |
| 421 if ((word >= 0x00C0 && word <= 0x00FF) || |
| 422 (word >= 0x0100 && word <= 0x024F) || |
| 423 (word >= 0x1E00 && word <= 0x1EFF) || |
| 424 (word >= 0x2C60 && word <= 0x2C7F) || |
| 425 (word >= 0xA720 && word <= 0xA7FF) || |
| 426 (word >= 0xFF21 && word <= 0xFF3A) || |
| 427 (word >= 0xFF41 && word <= 0xFF5A)) { |
| 428 return TRUE; |
| 429 } |
| 430 return FALSE; |
| 431 } |
| 432 static FX_BOOL IsDigit(FX_DWORD word) { |
| 433 return (word >= 0x0030 && word <= 0x0039) ? TRUE : FALSE; |
| 434 } |
| 435 static FX_BOOL IsCJK(FX_DWORD word) { |
| 436 if ((word >= 0x1100 && word <= 0x11FF) || |
| 437 (word >= 0x2E80 && word <= 0x2FFF) || |
| 438 (word >= 0x3040 && word <= 0x9FBF) || |
| 439 (word >= 0xAC00 && word <= 0xD7AF) || |
| 440 (word >= 0xF900 && word <= 0xFAFF) || |
| 441 (word >= 0xFE30 && word <= 0xFE4F) || |
| 442 (word >= 0x20000 && word <= 0x2A6DF) || |
| 443 (word >= 0x2F800 && word <= 0x2FA1F)) { |
| 444 return TRUE; |
| 445 } |
| 446 if (word >= 0x3000 && word <= 0x303F) { |
| 447 if (word == 0x3005 || word == 0x3006 || word == 0x3021 || word == 0x3022 || |
| 448 word == 0x3023 || word == 0x3024 || word == 0x3025 || word == 0x3026 || |
| 449 word == 0x3027 || word == 0x3028 || word == 0x3029 || word == 0x3031 || |
| 450 word == 0x3032 || word == 0x3033 || word == 0x3034 || word == 0x3035) { |
| 451 return TRUE; |
| 452 } |
| 453 return FALSE; |
| 454 } |
| 455 if (word >= 0xFF66 && word <= 0xFF9D) { |
| 456 return TRUE; |
| 457 } |
| 458 return FALSE; |
| 459 } |
| 460 static FX_BOOL IsPunctuation(FX_DWORD word) { |
| 461 if (word <= 0x007F) { |
| 462 if ((special_chars[word] >> 3) & 1) { |
| 463 return TRUE; |
| 464 } |
| 465 } else if (word >= 0x0080 && word <= 0x00FF) { |
| 466 if (word == 0x0082 || word == 0x0084 || word == 0x0085 || word == 0x0091 || |
| 467 word == 0x0092 || word == 0x0093 || word <= 0x0094 || word == 0x0096 || |
| 468 word == 0x00B4 || word == 0x00B8) { |
| 469 return TRUE; |
| 470 } |
| 471 } else if (word >= 0x2000 && word <= 0x206F) { |
| 472 if (word == 0x2010 || word == 0x2011 || word == 0x2012 || word == 0x2013 || |
| 473 word == 0x2018 || word == 0x2019 || word == 0x201A || word == 0x201B || |
| 474 word == 0x201C || word == 0x201D || word == 0x201E || word == 0x201F || |
| 475 word == 0x2032 || word == 0x2033 || word == 0x2034 || word == 0x2035 || |
| 476 word == 0x2036 || word == 0x2037 || word == 0x203C || word == 0x203D || |
| 477 word == 0x203E || word == 0x2044) { |
| 478 return TRUE; |
| 479 } |
| 480 } else if (word >= 0x3000 && word <= 0x303F) { |
| 481 if (word == 0x3001 || word == 0x3002 || word == 0x3003 || word == 0x3005 || |
| 482 word == 0x3009 || word == 0x300A || word == 0x300B || word == 0x300C || |
| 483 word == 0x300D || word == 0x300F || word == 0x300E || word == 0x3010 || |
| 484 word == 0x3011 || word == 0x3014 || word == 0x3015 || word == 0x3016 || |
| 485 word == 0x3017 || word == 0x3018 || word == 0x3019 || word == 0x301A || |
| 486 word == 0x301B || word == 0x301D || word == 0x301E || word == 0x301F) { |
| 487 return TRUE; |
| 488 } |
| 489 } else if (word >= 0xFE50 && word <= 0xFE6F) { |
| 490 if ((word >= 0xFE50 && word <= 0xFE5E) || word == 0xFE63) { |
| 491 return TRUE; |
| 492 } |
| 493 } else if (word >= 0xFF00 && word <= 0xFFEF) { |
| 494 if (word == 0xFF01 || word == 0xFF02 || word == 0xFF07 || word == 0xFF08 || |
| 495 word == 0xFF09 || word == 0xFF0C || word == 0xFF0E || word == 0xFF0F || |
| 496 word == 0xFF1A || word == 0xFF1B || word == 0xFF1F || word == 0xFF3B || |
| 497 word == 0xFF3D || word == 0xFF40 || word == 0xFF5B || word == 0xFF5C || |
| 498 word == 0xFF5D || word == 0xFF61 || word == 0xFF62 || word == 0xFF63 || |
| 499 word == 0xFF64 || word == 0xFF65 || word == 0xFF9E || word == 0xFF9F) { |
| 500 return TRUE; |
| 501 } |
| 502 } |
| 503 return FALSE; |
| 504 } |
| 505 static FX_BOOL IsConnectiveSymbol(FX_DWORD word) { |
| 506 if (word <= 0x007F) { |
| 507 if ((special_chars[word] >> 5) & 1) { |
| 508 return TRUE; |
| 509 } |
| 510 } |
| 511 return FALSE; |
| 512 } |
| 513 static FX_BOOL IsOpenStylePunctuation(FX_DWORD word) { |
| 514 if (word <= 0x007F) { |
| 515 if ((special_chars[word] >> 2) & 1) { |
| 516 return TRUE; |
| 517 } |
| 518 } else if (word == 0x300A || word == 0x300C || word == 0x300E || |
| 519 word == 0x3010 || word == 0x3014 || word == 0x3016 || |
| 520 word == 0x3018 || word == 0x301A || word == 0xFF08 || |
| 521 word == 0xFF3B || word == 0xFF5B || word == 0xFF62) { |
| 522 return TRUE; |
| 523 } |
| 524 return FALSE; |
| 525 } |
| 526 static FX_BOOL IsCurrencySymbol(FX_WORD word) { |
| 527 if (word == 0x0024 || word == 0x0080 || word == 0x00A2 || word == 0x00A3 || |
| 528 word == 0x00A4 || word == 0x00A5 || (word >= 0x20A0 && word <= 0x20CF) || |
| 529 word == 0xFE69 || word == 0xFF04 || word == 0xFFE0 || word == 0xFFE1 || |
| 530 word == 0xFFE5 || word == 0xFFE6) { |
| 531 return TRUE; |
| 532 } |
| 533 return FALSE; |
| 534 } |
| 535 static FX_BOOL IsPrefixSymbol(FX_WORD word) { |
| 536 if (IsCurrencySymbol(word)) { |
| 537 return TRUE; |
| 538 } |
| 539 if (word == 0x2116) { |
| 540 return TRUE; |
| 541 } |
| 542 return FALSE; |
| 543 } |
| 544 static FX_BOOL IsSpace(FX_WORD word) { |
| 545 return (word == 0x0020 || word == 0x3000) ? TRUE : FALSE; |
| 546 } |
| 547 static FX_BOOL NeedDivision(FX_WORD prevWord, FX_WORD curWord) { |
| 548 if ((IsLatin(prevWord) || IsDigit(prevWord)) && |
| 549 (IsLatin(curWord) || IsDigit(curWord))) { |
| 550 return FALSE; |
| 551 } |
| 552 if (IsSpace(curWord) || IsPunctuation(curWord)) { |
| 553 return FALSE; |
| 554 } |
| 555 if (IsConnectiveSymbol(prevWord) || IsConnectiveSymbol(curWord)) { |
| 556 return FALSE; |
| 557 } |
| 558 if (IsSpace(prevWord) || IsPunctuation(prevWord)) { |
| 559 return TRUE; |
| 560 } |
| 561 if (IsPrefixSymbol(prevWord)) { |
| 562 return FALSE; |
| 563 } |
| 564 if (IsPrefixSymbol(curWord) || IsCJK(curWord)) { |
| 565 return TRUE; |
| 566 } |
| 567 if (IsCJK(prevWord)) { |
| 568 return TRUE; |
| 569 } |
| 570 return FALSE; |
| 571 } |
| 572 void CTypeset::SplitLines(FX_BOOL bTypeset, FX_FLOAT fFontSize) { |
| 573 ASSERT(m_pVT != NULL); |
| 574 ASSERT(m_pSection != NULL); |
| 575 int32_t nLineHead = 0; |
| 576 int32_t nLineTail = 0; |
| 577 FX_FLOAT fMaxX = 0.0f, fMaxY = 0.0f; |
| 578 FX_FLOAT fLineWidth = 0.0f, fBackupLineWidth = 0.0f; |
| 579 FX_FLOAT fLineAscent = 0.0f, fBackupLineAscent = 0.0f; |
| 580 FX_FLOAT fLineDescent = 0.0f, fBackupLineDescent = 0.0f; |
| 581 int32_t nWordStartPos = 0; |
| 582 FX_BOOL bFullWord = FALSE; |
| 583 int32_t nLineFullWordIndex = 0; |
| 584 int32_t nCharIndex = 0; |
| 585 CPVT_LineInfo line; |
| 586 FX_FLOAT fWordWidth = 0; |
| 587 FX_FLOAT fTypesetWidth = FPDF_MAX( |
| 588 m_pVT->GetPlateWidth() - m_pVT->GetLineIndent(m_pSection->m_SecInfo), |
| 589 0.0f); |
| 590 int32_t nTotalWords = m_pSection->m_WordArray.GetSize(); |
| 591 FX_BOOL bOpened = FALSE; |
| 592 if (nTotalWords > 0) { |
| 593 int32_t i = 0; |
| 594 while (i < nTotalWords) { |
| 595 CPVT_WordInfo* pWord = m_pSection->m_WordArray.GetAt(i); |
| 596 CPVT_WordInfo* pOldWord = pWord; |
| 597 if (i > 0) { |
| 598 pOldWord = m_pSection->m_WordArray.GetAt(i - 1); |
| 599 } |
| 600 if (pWord) { |
| 601 if (bTypeset) { |
| 602 fLineAscent = |
| 603 FPDF_MAX(fLineAscent, m_pVT->GetWordAscent(*pWord, TRUE)); |
| 604 fLineDescent = |
| 605 FPDF_MIN(fLineDescent, m_pVT->GetWordDescent(*pWord, TRUE)); |
| 606 fWordWidth = m_pVT->GetWordWidth(*pWord); |
| 607 } else { |
| 608 fLineAscent = |
| 609 FPDF_MAX(fLineAscent, m_pVT->GetWordAscent(*pWord, fFontSize)); |
| 610 fLineDescent = |
| 611 FPDF_MIN(fLineDescent, m_pVT->GetWordDescent(*pWord, fFontSize)); |
| 612 fWordWidth = m_pVT->GetWordWidth( |
| 613 pWord->nFontIndex, pWord->Word, m_pVT->m_wSubWord, |
| 614 m_pVT->m_fCharSpace, m_pVT->m_nHorzScale, fFontSize, |
| 615 pWord->fWordTail, 0); |
| 616 } |
| 617 if (!bOpened) { |
| 618 if (IsOpenStylePunctuation(pWord->Word)) { |
| 619 bOpened = TRUE; |
| 620 bFullWord = TRUE; |
| 621 } else if (pOldWord != NULL) { |
| 622 if (NeedDivision(pOldWord->Word, pWord->Word)) { |
| 623 bFullWord = TRUE; |
| 624 } |
| 625 } |
| 626 } else { |
| 627 if (!IsSpace(pWord->Word) && !IsOpenStylePunctuation(pWord->Word)) { |
| 628 bOpened = FALSE; |
| 629 } |
| 630 } |
| 631 if (bFullWord) { |
| 632 bFullWord = FALSE; |
| 633 if (nCharIndex > 0) { |
| 634 nLineFullWordIndex++; |
| 635 } |
| 636 nWordStartPos = i; |
| 637 fBackupLineWidth = fLineWidth; |
| 638 fBackupLineAscent = fLineAscent; |
| 639 fBackupLineDescent = fLineDescent; |
| 640 } |
| 641 nCharIndex++; |
| 642 } |
| 643 if (m_pVT->m_bLimitWidth && fTypesetWidth > 0 && |
| 644 fLineWidth + fWordWidth > fTypesetWidth) { |
| 645 if (nLineFullWordIndex > 0) { |
| 646 i = nWordStartPos; |
| 647 fLineWidth = fBackupLineWidth; |
| 648 fLineAscent = fBackupLineAscent; |
| 649 fLineDescent = fBackupLineDescent; |
| 650 } |
| 651 if (nCharIndex == 1) { |
| 652 fLineWidth = fWordWidth; |
| 653 i++; |
| 654 } |
| 655 nLineTail = i - 1; |
| 656 if (bTypeset) { |
| 657 line.nBeginWordIndex = nLineHead; |
| 658 line.nEndWordIndex = nLineTail; |
| 659 line.nTotalWord = nLineTail - nLineHead + 1; |
| 660 line.fLineWidth = fLineWidth; |
| 661 line.fLineAscent = fLineAscent; |
| 662 line.fLineDescent = fLineDescent; |
| 663 m_pSection->AddLine(line); |
| 664 } |
| 665 fMaxY += (fLineAscent + m_pVT->GetLineLeading(m_pSection->m_SecInfo)); |
| 666 fMaxY += (-fLineDescent); |
| 667 fMaxX = FPDF_MAX(fLineWidth, fMaxX); |
| 668 nLineHead = i; |
| 669 fLineWidth = 0.0f; |
| 670 fLineAscent = 0.0f; |
| 671 fLineDescent = 0.0f; |
| 672 nCharIndex = 0; |
| 673 nLineFullWordIndex = 0; |
| 674 bFullWord = FALSE; |
| 675 } else { |
| 676 fLineWidth += fWordWidth; |
| 677 i++; |
| 678 } |
| 679 } |
| 680 if (nLineHead <= nTotalWords - 1) { |
| 681 nLineTail = nTotalWords - 1; |
| 682 if (bTypeset) { |
| 683 line.nBeginWordIndex = nLineHead; |
| 684 line.nEndWordIndex = nLineTail; |
| 685 line.nTotalWord = nLineTail - nLineHead + 1; |
| 686 line.fLineWidth = fLineWidth; |
| 687 line.fLineAscent = fLineAscent; |
| 688 line.fLineDescent = fLineDescent; |
| 689 m_pSection->AddLine(line); |
| 690 } |
| 691 fMaxY += (fLineAscent + m_pVT->GetLineLeading(m_pSection->m_SecInfo)); |
| 692 fMaxY += (-fLineDescent); |
| 693 fMaxX = FPDF_MAX(fLineWidth, fMaxX); |
| 694 } |
| 695 } else { |
| 696 if (bTypeset) { |
| 697 fLineAscent = m_pVT->GetLineAscent(m_pSection->m_SecInfo); |
| 698 fLineDescent = m_pVT->GetLineDescent(m_pSection->m_SecInfo); |
| 84 } else { | 699 } else { |
| 85 m_WordArray.InsertAt(nWordIndex, pWord); | 700 fLineAscent = |
| 86 } | 701 m_pVT->GetFontAscent(m_pVT->GetDefaultFontIndex(), fFontSize); |
| 87 return place; | 702 fLineDescent = |
| 88 } | 703 m_pVT->GetFontDescent(m_pVT->GetDefaultFontIndex(), fFontSize); |
| 89 CPVT_WordPlace CSection::AddLine(const CPVT_LineInfo & lineinfo) | 704 } |
| 90 { | 705 if (bTypeset) { |
| 91 return CPVT_WordPlace(SecPlace.nSecIndex, m_LineArray.Add(lineinfo), -1); | 706 line.nBeginWordIndex = -1; |
| 92 } | 707 line.nEndWordIndex = -1; |
| 93 CPVT_FloatRect CSection::Rearrange() | 708 line.nTotalWord = 0; |
| 94 { | 709 line.fLineWidth = 0; |
| 95 ASSERT(m_pVT != NULL); | 710 line.fLineAscent = fLineAscent; |
| 96 if (m_pVT->m_nCharArray > 0) { | 711 line.fLineDescent = fLineDescent; |
| 97 return CTypeset(this).CharArray(); | 712 m_pSection->AddLine(line); |
| 98 } | 713 } |
| 99 return CTypeset(this).Typeset(); | 714 fMaxY += (m_pVT->GetLineLeading(m_pSection->m_SecInfo) + fLineAscent + |
| 100 } | 715 (-fLineDescent)); |
| 101 CPVT_Size CSection::GetSectionSize(FX_FLOAT fFontSize) | 716 } |
| 102 { | 717 m_rcRet = CPVT_FloatRect(0, 0, fMaxX, fMaxY); |
| 103 return CTypeset(this).GetEditSize(fFontSize); | 718 } |
| 104 } | 719 void CTypeset::OutputLines() { |
| 105 CPVT_WordPlace CSection::GetBeginWordPlace() const | 720 ASSERT(m_pVT != NULL); |
| 106 { | 721 ASSERT(m_pSection != NULL); |
| 107 if (CLine * pLine = m_LineArray.GetAt(0)) { | 722 FX_FLOAT fMinX = 0.0f, fMinY = 0.0f, fMaxX = 0.0f, fMaxY = 0.0f; |
| 108 return pLine->GetBeginWordPlace(); | 723 FX_FLOAT fPosX = 0.0f, fPosY = 0.0f; |
| 109 } | 724 FX_FLOAT fLineIndent = m_pVT->GetLineIndent(m_pSection->m_SecInfo); |
| 110 return SecPlace; | 725 FX_FLOAT fTypesetWidth = FPDF_MAX(m_pVT->GetPlateWidth() - fLineIndent, 0.0f); |
| 111 } | 726 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { |
| 112 CPVT_WordPlace CSection::GetEndWordPlace() const | 727 default: |
| 113 { | 728 case 0: |
| 114 if (CLine * pLine = m_LineArray.GetAt(m_LineArray.GetSize() - 1)) { | 729 fMinX = 0.0f; |
| 115 return pLine->GetEndWordPlace(); | 730 break; |
| 116 } | 731 case 1: |
| 117 return SecPlace; | 732 fMinX = (fTypesetWidth - m_rcRet.Width()) * PVT_HALF; |
| 118 } | 733 break; |
| 119 CPVT_WordPlace CSection::GetPrevWordPlace(const CPVT_WordPlace & place) const | 734 case 2: |
| 120 { | 735 fMinX = fTypesetWidth - m_rcRet.Width(); |
| 121 if (place.nLineIndex < 0) { | 736 break; |
| 122 return GetBeginWordPlace(); | 737 } |
| 123 } | 738 fMaxX = fMinX + m_rcRet.Width(); |
| 124 if (place.nLineIndex >= m_LineArray.GetSize()) { | 739 fMinY = 0.0f; |
| 125 return GetEndWordPlace(); | 740 fMaxY = m_rcRet.Height(); |
| 126 } | 741 int32_t nTotalLines = m_pSection->m_LineArray.GetSize(); |
| 127 if (CLine * pLine = m_LineArray.GetAt(place.nLineIndex)) { | 742 if (nTotalLines > 0) { |
| 128 if (place.nWordIndex == pLine->m_LineInfo.nBeginWordIndex) { | 743 m_pSection->m_SecInfo.nTotalLine = nTotalLines; |
| 129 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, -1); | 744 for (int32_t l = 0; l < nTotalLines; l++) { |
| 130 } | 745 if (CLine* pLine = m_pSection->m_LineArray.GetAt(l)) { |
| 131 if (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) { | 746 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { |
| 132 if (CLine * pPrevLine = m_LineArray.GetAt(place.nLineIndex - 1)) { | 747 default: |
| 133 return pPrevLine->GetEndWordPlace(); | 748 case 0: |
| 134 } | 749 fPosX = 0; |
| 135 } else { | 750 break; |
| 136 return pLine->GetPrevWordPlace(place); | 751 case 1: |
| 137 } | 752 fPosX = (fTypesetWidth - pLine->m_LineInfo.fLineWidth) * PVT_HALF; |
| 138 } | 753 break; |
| 139 return place; | 754 case 2: |
| 140 } | 755 fPosX = fTypesetWidth - pLine->m_LineInfo.fLineWidth; |
| 141 CPVT_WordPlace CSection::GetNextWordPlace(const CPVT_WordPlace & place) const | |
| 142 { | |
| 143 if (place.nLineIndex < 0) { | |
| 144 return GetBeginWordPlace(); | |
| 145 } | |
| 146 if (place.nLineIndex >= m_LineArray.GetSize()) { | |
| 147 return GetEndWordPlace(); | |
| 148 } | |
| 149 if (CLine * pLine = m_LineArray.GetAt(place.nLineIndex)) { | |
| 150 if (place.nWordIndex >= pLine->m_LineInfo.nEndWordIndex) { | |
| 151 if (CLine * pNextLine = m_LineArray.GetAt(place.nLineIndex + 1)) { | |
| 152 return pNextLine->GetBeginWordPlace(); | |
| 153 } | |
| 154 } else { | |
| 155 return pLine->GetNextWordPlace(place); | |
| 156 } | |
| 157 } | |
| 158 return place; | |
| 159 } | |
| 160 void CSection::UpdateWordPlace(CPVT_WordPlace & place) const | |
| 161 { | |
| 162 int32_t nLeft = 0; | |
| 163 int32_t nRight = m_LineArray.GetSize() - 1; | |
| 164 int32_t nMid = (nLeft + nRight) / 2; | |
| 165 while (nLeft <= nRight) { | |
| 166 if (CLine * pLine = m_LineArray.GetAt(nMid)) { | |
| 167 if (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) { | |
| 168 nRight = nMid - 1; | |
| 169 nMid = (nLeft + nRight) / 2; | |
| 170 } else if (place.nWordIndex > pLine->m_LineInfo.nEndWordIndex) { | |
| 171 nLeft = nMid + 1; | |
| 172 nMid = (nLeft + nRight) / 2; | |
| 173 } else { | |
| 174 place.nLineIndex = nMid; | |
| 175 return; | |
| 176 } | |
| 177 } else { | |
| 178 break; | 756 break; |
| 179 } | 757 } |
| 180 } | 758 fPosX += fLineIndent; |
| 181 } | 759 fPosY += m_pVT->GetLineLeading(m_pSection->m_SecInfo); |
| 182 CPVT_WordPlace CSection::SearchWordPlace(const CPDF_Point & point) const | 760 fPosY += pLine->m_LineInfo.fLineAscent; |
| 183 { | 761 pLine->m_LineInfo.fLineX = fPosX - fMinX; |
| 184 ASSERT(m_pVT != NULL); | 762 pLine->m_LineInfo.fLineY = fPosY - fMinY; |
| 185 CPVT_WordPlace place = GetBeginWordPlace(); | 763 for (int32_t w = pLine->m_LineInfo.nBeginWordIndex; |
| 186 FX_BOOL bUp = TRUE; | 764 w <= pLine->m_LineInfo.nEndWordIndex; w++) { |
| 187 FX_BOOL bDown = TRUE; | 765 if (CPVT_WordInfo* pWord = m_pSection->m_WordArray.GetAt(w)) { |
| 188 int32_t nLeft = 0; | 766 pWord->fWordX = fPosX - fMinX; |
| 189 int32_t nRight = m_LineArray.GetSize() - 1; | 767 if (pWord->pWordProps) { |
| 190 int32_t nMid = m_LineArray.GetSize() / 2; | 768 switch (pWord->pWordProps->nScriptType) { |
| 191 FX_FLOAT fTop = 0; | 769 default: |
| 192 FX_FLOAT fBottom = 0; | 770 case PVTWORD_SCRIPT_NORMAL: |
| 193 while (nLeft <= nRight) { | 771 pWord->fWordY = fPosY - fMinY; |
| 194 if (CLine * pLine = m_LineArray.GetAt(nMid)) { | 772 break; |
| 195 fTop = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineAscent - m_
pVT->GetLineLeading(m_SecInfo); | 773 case PVTWORD_SCRIPT_SUPER: |
| 196 fBottom = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineDescent; | 774 pWord->fWordY = fPosY - m_pVT->GetWordAscent(*pWord) - fMinY; |
| 197 if (IsFloatBigger(point.y, fTop)) { | 775 break; |
| 198 bUp = FALSE; | 776 case PVTWORD_SCRIPT_SUB: |
| 777 pWord->fWordY = fPosY - m_pVT->GetWordDescent(*pWord) - fMinY; |
| 778 break; |
| 779 } |
| 780 } else { |
| 781 pWord->fWordY = fPosY - fMinY; |
| 199 } | 782 } |
| 200 if (IsFloatSmaller(point.y, fBottom)) { | 783 fPosX += m_pVT->GetWordWidth(*pWord); |
| 201 bDown = FALSE; | 784 } |
| 202 } | |
| 203 if (IsFloatSmaller(point.y, fTop)) { | |
| 204 nRight = nMid - 1; | |
| 205 nMid = (nLeft + nRight) / 2; | |
| 206 continue; | |
| 207 } else if (IsFloatBigger(point.y, fBottom)) { | |
| 208 nLeft = nMid + 1; | |
| 209 nMid = (nLeft + nRight) / 2; | |
| 210 continue; | |
| 211 } else { | |
| 212 place = SearchWordPlace(point.x, | |
| 213 CPVT_WordRange(pLine->GetNextWordPlace(p
Line->GetBeginWordPlace()), pLine->GetEndWordPlace()) | |
| 214 ); | |
| 215 place.nLineIndex = nMid; | |
| 216 return place; | |
| 217 } | |
| 218 } | 785 } |
| 219 } | 786 fPosY += (-pLine->m_LineInfo.fLineDescent); |
| 220 if (bUp) { | 787 } |
| 221 place = GetBeginWordPlace(); | 788 } |
| 222 } | 789 } |
| 223 if (bDown) { | 790 m_rcRet = CPVT_FloatRect(fMinX, fMinY, fMaxX, fMaxY); |
| 224 place = GetEndWordPlace(); | 791 } |
| 225 } | 792 CPDF_VariableText::CPDF_VariableText() |
| 226 return place; | 793 : m_nLimitChar(0), |
| 227 } | 794 m_nCharArray(0), |
| 228 CPVT_WordPlace CSection::SearchWordPlace(FX_FLOAT fx, const CPVT_WordPlace & lin
eplace) const | 795 m_bMultiLine(FALSE), |
| 229 { | 796 m_bLimitWidth(FALSE), |
| 230 if (CLine * pLine = m_LineArray.GetAt(lineplace.nLineIndex)) { | 797 m_bAutoFontSize(FALSE), |
| 231 return SearchWordPlace(fx - m_SecInfo.rcSection.left, | 798 m_nAlignment(0), |
| 232 CPVT_WordRange(pLine->GetNextWordPlace(pLine->Get
BeginWordPlace()), pLine->GetEndWordPlace())); | 799 m_fLineLeading(0.0f), |
| 233 } | 800 m_fCharSpace(0.0f), |
| 234 return GetBeginWordPlace(); | 801 m_nHorzScale(100), |
| 235 } | 802 m_wSubWord(0), |
| 236 CPVT_WordPlace CSection::SearchWordPlace(FX_FLOAT fx, const CPVT_WordRange & ran
ge) const | 803 m_fFontSize(0.0f), |
| 237 { | 804 m_bInitial(FALSE), |
| 238 CPVT_WordPlace wordplace = range.BeginPos; | 805 m_bRichText(FALSE), |
| 239 wordplace.nWordIndex = -1; | 806 m_pVTProvider(NULL), |
| 240 if (!m_pVT) { | 807 m_pVTIterator(NULL) {} |
| 241 return wordplace; | 808 CPDF_VariableText::~CPDF_VariableText() { |
| 242 } | 809 delete m_pVTIterator; |
| 243 int32_t nLeft = range.BeginPos.nWordIndex; | 810 m_pVTIterator = NULL; |
| 244 int32_t nRight = range.EndPos.nWordIndex + 1; | 811 ResetAll(); |
| 245 int32_t nMid = (nLeft + nRight) / 2; | 812 } |
| 246 while (nLeft < nRight) { | 813 void CPDF_VariableText::Initialize() { |
| 247 if (nMid == nLeft) { | 814 if (!m_bInitial) { |
| 248 break; | |
| 249 } | |
| 250 if (nMid == nRight) { | |
| 251 nMid--; | |
| 252 break; | |
| 253 } | |
| 254 if (CPVT_WordInfo * pWord = m_WordArray.GetAt(nMid)) { | |
| 255 if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * PVT_HALF) { | |
| 256 nLeft = nMid; | |
| 257 nMid = (nLeft + nRight) / 2; | |
| 258 continue; | |
| 259 } else { | |
| 260 nRight = nMid; | |
| 261 nMid = (nLeft + nRight) / 2; | |
| 262 continue; | |
| 263 } | |
| 264 } else { | |
| 265 break; | |
| 266 } | |
| 267 } | |
| 268 if (CPVT_WordInfo * pWord = m_WordArray.GetAt(nMid)) { | |
| 269 if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * PVT_HALF) { | |
| 270 wordplace.nWordIndex = nMid; | |
| 271 } | |
| 272 } | |
| 273 return wordplace; | |
| 274 } | |
| 275 void CSection::ClearLeftWords(int32_t nWordIndex) | |
| 276 { | |
| 277 for (int32_t i = nWordIndex; i >= 0; i--) { | |
| 278 delete m_WordArray.GetAt(i); | |
| 279 m_WordArray.RemoveAt(i); | |
| 280 } | |
| 281 } | |
| 282 void CSection::ClearRightWords(int32_t nWordIndex) | |
| 283 { | |
| 284 for (int32_t i = m_WordArray.GetSize() - 1; i > nWordIndex; i--) { | |
| 285 delete m_WordArray.GetAt(i); | |
| 286 m_WordArray.RemoveAt(i); | |
| 287 } | |
| 288 } | |
| 289 void CSection::ClearMidWords(int32_t nBeginIndex, int32_t nEndIndex) | |
| 290 { | |
| 291 for (int32_t i = nEndIndex; i > nBeginIndex; i--) { | |
| 292 delete m_WordArray.GetAt(i); | |
| 293 m_WordArray.RemoveAt(i); | |
| 294 } | |
| 295 } | |
| 296 void CSection::ClearWords(const CPVT_WordRange & PlaceRange) | |
| 297 { | |
| 298 CPVT_WordPlace SecBeginPos = GetBeginWordPlace(); | |
| 299 CPVT_WordPlace SecEndPos = GetEndWordPlace(); | |
| 300 if (PlaceRange.BeginPos.WordCmp(SecBeginPos) >= 0) { | |
| 301 if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) { | |
| 302 ClearMidWords(PlaceRange.BeginPos.nWordIndex, PlaceRange.EndPos.nWor
dIndex); | |
| 303 } else { | |
| 304 ClearRightWords(PlaceRange.BeginPos.nWordIndex); | |
| 305 } | |
| 306 } else if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) { | |
| 307 ClearLeftWords(PlaceRange.EndPos.nWordIndex); | |
| 308 } else { | |
| 309 ResetWordArray(); | |
| 310 } | |
| 311 } | |
| 312 void CSection::ClearWord(const CPVT_WordPlace & place) | |
| 313 { | |
| 314 delete m_WordArray.GetAt(place.nWordIndex); | |
| 315 m_WordArray.RemoveAt(place.nWordIndex); | |
| 316 } | |
| 317 CTypeset::CTypeset(CSection * pSection) : m_rcRet(0.0f, 0.0f, 0.0f, 0.0f), m_pVT
(pSection->m_pVT), m_pSection(pSection) | |
| 318 { | |
| 319 } | |
| 320 CTypeset::~CTypeset() | |
| 321 { | |
| 322 } | |
| 323 CPVT_FloatRect CTypeset::CharArray() | |
| 324 { | |
| 325 ASSERT(m_pSection != NULL); | |
| 326 ASSERT(m_pVT != NULL); | |
| 327 FX_FLOAT fLineAscent = m_pVT->GetFontAscent(m_pVT->GetDefaultFontIndex(), m_
pVT->GetFontSize()); | |
| 328 FX_FLOAT fLineDescent = m_pVT->GetFontDescent(m_pVT->GetDefaultFontIndex(),
m_pVT->GetFontSize()); | |
| 329 m_rcRet.Default(); | |
| 330 FX_FLOAT x = 0.0f, y = 0.0f; | |
| 331 FX_FLOAT fNextWidth; | |
| 332 int32_t nStart = 0; | |
| 333 FX_FLOAT fNodeWidth = m_pVT->GetPlateWidth() / (m_pVT->m_nCharArray <= 0 ? 1
: m_pVT->m_nCharArray); | |
| 334 if (CLine * pLine = m_pSection->m_LineArray.GetAt(0)) { | |
| 335 x = 0.0f; | |
| 336 y += m_pVT->GetLineLeading(m_pSection->m_SecInfo); | |
| 337 y += fLineAscent; | |
| 338 nStart = 0; | |
| 339 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { | |
| 340 case 0: | |
| 341 pLine->m_LineInfo.fLineX = fNodeWidth * PVT_HALF; | |
| 342 break; | |
| 343 case 1: | |
| 344 nStart = (m_pVT->m_nCharArray - m_pSection->m_WordArray.GetSize(
)) / 2; | |
| 345 pLine->m_LineInfo.fLineX = fNodeWidth * nStart - fNodeWidth * PV
T_HALF; | |
| 346 break; | |
| 347 case 2: | |
| 348 nStart = m_pVT->m_nCharArray - m_pSection->m_WordArray.GetSize()
; | |
| 349 pLine->m_LineInfo.fLineX = fNodeWidth * nStart - fNodeWidth * PV
T_HALF; | |
| 350 break; | |
| 351 } | |
| 352 for (int32_t w = 0, sz = m_pSection->m_WordArray.GetSize(); w < sz; w++)
{ | |
| 353 if (w >= m_pVT->m_nCharArray) { | |
| 354 break; | |
| 355 } | |
| 356 fNextWidth = 0; | |
| 357 if (CPVT_WordInfo * pNextWord = (CPVT_WordInfo *)m_pSection->m_WordA
rray.GetAt(w + 1)) { | |
| 358 pNextWord->fWordTail = 0; | |
| 359 fNextWidth = m_pVT->GetWordWidth(*pNextWord); | |
| 360 } | |
| 361 if (CPVT_WordInfo * pWord = (CPVT_WordInfo *)m_pSection->m_WordArray
.GetAt(w)) { | |
| 362 pWord->fWordTail = 0; | |
| 363 FX_FLOAT fWordWidth = m_pVT->GetWordWidth(*pWord); | |
| 364 FX_FLOAT fWordAscent = m_pVT->GetWordAscent(*pWord); | |
| 365 FX_FLOAT fWordDescent = m_pVT->GetWordDescent(*pWord); | |
| 366 x = (FX_FLOAT)(fNodeWidth * (w + nStart + 0.5) - fWordWidth * PV
T_HALF); | |
| 367 pWord->fWordX = x; | |
| 368 pWord->fWordY = y; | |
| 369 if (w == 0) { | |
| 370 pLine->m_LineInfo.fLineX = x; | |
| 371 } | |
| 372 if (w != m_pSection->m_WordArray.GetSize() - 1) | |
| 373 pWord->fWordTail = (fNodeWidth - (fWordWidth + fNextWidth) *
PVT_HALF > 0 ? | |
| 374 fNodeWidth - (fWordWidth + fNextWidth) *
PVT_HALF : 0); | |
| 375 else { | |
| 376 pWord->fWordTail = 0; | |
| 377 } | |
| 378 x += fWordWidth; | |
| 379 fLineAscent = FPDF_MAX(fLineAscent, fWordAscent); | |
| 380 fLineDescent = FPDF_MIN(fLineDescent, fWordDescent); | |
| 381 } | |
| 382 } | |
| 383 pLine->m_LineInfo.nBeginWordIndex = 0; | |
| 384 pLine->m_LineInfo.nEndWordIndex = m_pSection->m_WordArray.GetSize() - 1; | |
| 385 pLine->m_LineInfo.fLineY = y; | |
| 386 pLine->m_LineInfo.fLineWidth = x - pLine->m_LineInfo.fLineX; | |
| 387 pLine->m_LineInfo.fLineAscent = fLineAscent; | |
| 388 pLine->m_LineInfo.fLineDescent = fLineDescent; | |
| 389 y += (-fLineDescent); | |
| 390 } | |
| 391 return m_rcRet = CPVT_FloatRect(0, 0, x, y); | |
| 392 } | |
| 393 CPVT_Size CTypeset::GetEditSize(FX_FLOAT fFontSize) | |
| 394 { | |
| 395 ASSERT(m_pSection != NULL); | |
| 396 ASSERT(m_pVT != NULL); | |
| 397 SplitLines(FALSE, fFontSize); | |
| 398 return CPVT_Size(m_rcRet.Width(), m_rcRet.Height()); | |
| 399 } | |
| 400 CPVT_FloatRect CTypeset::Typeset() | |
| 401 { | |
| 402 ASSERT(m_pSection != NULL); | |
| 403 ASSERT(m_pVT != NULL); | |
| 404 m_pSection->m_LineArray.Empty(); | |
| 405 SplitLines(TRUE, 0.0f); | |
| 406 m_pSection->m_LineArray.Clear(); | |
| 407 OutputLines(); | |
| 408 return m_rcRet; | |
| 409 } | |
| 410 static int special_chars[128] = { | |
| 411 0x0000, 0x000C, 0x0008, 0x000C, 0x0008, 0x0000, 0x0020, 0x0000, | |
| 412 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, | |
| 413 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, | |
| 414 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, | |
| 415 0x0000, 0x0008, 0x0008, 0x0000, 0x0010, 0x0000, 0x0000, 0x0028, | |
| 416 0x000C, 0x0008, 0x0000, 0x0000, 0x0028, 0x0028, 0x0028, 0x0028, | |
| 417 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, | |
| 418 0x0002, 0x0002, 0x0008, 0x0008, 0x0000, 0x0000, 0x0000, 0x0008, | |
| 419 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, | |
| 420 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, | |
| 421 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, | |
| 422 0x0001, 0x0001, 0x0001, 0x000C, 0x0000, 0x0008, 0x0000, 0x0000, | |
| 423 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, | |
| 424 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, | |
| 425 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, | |
| 426 0x0001, 0x0001, 0x0001, 0x000C, 0x0000, 0x0008, 0x0000, 0x0000, | |
| 427 }; | |
| 428 static FX_BOOL IsLatin(FX_WORD word) | |
| 429 { | |
| 430 if (word <= 0x007F) { | |
| 431 if (special_chars[word] & 0x0001) { | |
| 432 return TRUE; | |
| 433 } | |
| 434 } | |
| 435 if ((word >= 0x00C0 && word <= 0x00FF) || | |
| 436 (word >= 0x0100 && word <= 0x024F) || | |
| 437 (word >= 0x1E00 && word <= 0x1EFF) || | |
| 438 (word >= 0x2C60 && word <= 0x2C7F) || | |
| 439 (word >= 0xA720 && word <= 0xA7FF) || | |
| 440 (word >= 0xFF21 && word <= 0xFF3A) || | |
| 441 (word >= 0xFF41 && word <= 0xFF5A)) { | |
| 442 return TRUE; | |
| 443 } | |
| 444 return FALSE; | |
| 445 } | |
| 446 static FX_BOOL IsDigit(FX_DWORD word) | |
| 447 { | |
| 448 return (word >= 0x0030 && word <= 0x0039) ? TRUE : FALSE; | |
| 449 } | |
| 450 static FX_BOOL IsCJK(FX_DWORD word) | |
| 451 { | |
| 452 if ((word >= 0x1100 && word <= 0x11FF) || | |
| 453 (word >= 0x2E80 && word <= 0x2FFF) || | |
| 454 (word >= 0x3040 && word <= 0x9FBF) || | |
| 455 (word >= 0xAC00 && word <= 0xD7AF) || | |
| 456 (word >= 0xF900 && word <= 0xFAFF) || | |
| 457 (word >= 0xFE30 && word <= 0xFE4F) || | |
| 458 (word >= 0x20000 && word <= 0x2A6DF) || | |
| 459 (word >= 0x2F800 && word <= 0x2FA1F)) { | |
| 460 return TRUE; | |
| 461 } | |
| 462 if (word >= 0x3000 && word <= 0x303F) { | |
| 463 if (word == 0x3005 || word == 0x3006 || word == 0x3021 || word == 0x3022
|| | |
| 464 word == 0x3023 || word == 0x3024 || word == 0x3025 || word == 0x
3026 || | |
| 465 word == 0x3027 || word == 0x3028 || word == 0x3029 || word == 0x
3031 || | |
| 466 word == 0x3032 || word == 0x3033 || word == 0x3034 || word == 0x
3035) { | |
| 467 return TRUE; | |
| 468 } | |
| 469 return FALSE; | |
| 470 } | |
| 471 if (word >= 0xFF66 && word <= 0xFF9D) { | |
| 472 return TRUE; | |
| 473 } | |
| 474 return FALSE; | |
| 475 } | |
| 476 static FX_BOOL IsPunctuation(FX_DWORD word) | |
| 477 { | |
| 478 if (word <= 0x007F) { | |
| 479 if ((special_chars[word] >> 3) & 1) { | |
| 480 return TRUE; | |
| 481 } | |
| 482 } else if (word >= 0x0080 && word <= 0x00FF) { | |
| 483 if (word == 0x0082 || word == 0x0084 || word == 0x0085 || word == 0x0091
|| | |
| 484 word == 0x0092 || word == 0x0093 || word <= 0x0094 || word == 0x
0096 || | |
| 485 word == 0x00B4 || word == 0x00B8) { | |
| 486 return TRUE; | |
| 487 } | |
| 488 } else if (word >= 0x2000 && word <= 0x206F) { | |
| 489 if (word == 0x2010 || word == 0x2011 || word == 0x2012 || word == 0x2013
|| | |
| 490 word == 0x2018 || word == 0x2019 || word == 0x201A || word == 0x
201B || | |
| 491 word == 0x201C || word == 0x201D || word == 0x201E || word == 0x
201F || | |
| 492 word == 0x2032 || word == 0x2033 || word == 0x2034 || word == 0x
2035 || | |
| 493 word == 0x2036 || word == 0x2037 || word == 0x203C || word == 0x
203D || | |
| 494 word == 0x203E || word == 0x2044) { | |
| 495 return TRUE; | |
| 496 } | |
| 497 } else if (word >= 0x3000 && word <= 0x303F) { | |
| 498 if (word == 0x3001 || word == 0x3002 || word == 0x3003 || word == 0x3005
|| | |
| 499 word == 0x3009 || word == 0x300A || word == 0x300B || word == 0x
300C || | |
| 500 word == 0x300D || word == 0x300F || word == 0x300E || word == 0x
3010 || | |
| 501 word == 0x3011 || word == 0x3014 || word == 0x3015 || word == 0x
3016 || | |
| 502 word == 0x3017 || word == 0x3018 || word == 0x3019 || word == 0x
301A || | |
| 503 word == 0x301B || word == 0x301D || word == 0x301E || word == 0x
301F) { | |
| 504 return TRUE; | |
| 505 } | |
| 506 } else if (word >= 0xFE50 && word <= 0xFE6F) { | |
| 507 if ((word >= 0xFE50 && word <= 0xFE5E) || word == 0xFE63) { | |
| 508 return TRUE; | |
| 509 } | |
| 510 } else if (word >= 0xFF00 && word <= 0xFFEF) { | |
| 511 if (word == 0xFF01 || word == 0xFF02 || word == 0xFF07 || word == 0xFF08
|| | |
| 512 word == 0xFF09 || word == 0xFF0C || word == 0xFF0E || word == 0x
FF0F || | |
| 513 word == 0xFF1A || word == 0xFF1B || word == 0xFF1F || word == 0x
FF3B || | |
| 514 word == 0xFF3D || word == 0xFF40 || word == 0xFF5B || word == 0x
FF5C || | |
| 515 word == 0xFF5D || word == 0xFF61 || word == 0xFF62 || word == 0x
FF63 || | |
| 516 word == 0xFF64 || word == 0xFF65 || word == 0xFF9E || word == 0x
FF9F) { | |
| 517 return TRUE; | |
| 518 } | |
| 519 } | |
| 520 return FALSE; | |
| 521 } | |
| 522 static FX_BOOL IsConnectiveSymbol(FX_DWORD word) | |
| 523 { | |
| 524 if (word <= 0x007F) { | |
| 525 if ((special_chars[word] >> 5) & 1) { | |
| 526 return TRUE; | |
| 527 } | |
| 528 } | |
| 529 return FALSE; | |
| 530 } | |
| 531 static FX_BOOL IsOpenStylePunctuation(FX_DWORD word) | |
| 532 { | |
| 533 if (word <= 0x007F) { | |
| 534 if ((special_chars[word] >> 2) & 1) { | |
| 535 return TRUE; | |
| 536 } | |
| 537 } else if (word == 0x300A || word == 0x300C || word == 0x300E || word == 0x3
010 || | |
| 538 word == 0x3014 || word == 0x3016 || word == 0x3018 || word == 0x3
01A || | |
| 539 word == 0xFF08 || word == 0xFF3B || word == 0xFF5B || word == 0xF
F62) { | |
| 540 return TRUE; | |
| 541 } | |
| 542 return FALSE; | |
| 543 } | |
| 544 static FX_BOOL IsCurrencySymbol(FX_WORD word) | |
| 545 { | |
| 546 if (word == 0x0024 || word == 0x0080 || word == 0x00A2 || word == 0x00A3 || | |
| 547 word == 0x00A4 || word == 0x00A5 || (word >= 0x20A0 && word <= 0x20C
F) || | |
| 548 word == 0xFE69 || word == 0xFF04 || word == 0xFFE0 || word == 0xFFE1
|| | |
| 549 word == 0xFFE5 || word == 0xFFE6) { | |
| 550 return TRUE; | |
| 551 } | |
| 552 return FALSE; | |
| 553 } | |
| 554 static FX_BOOL IsPrefixSymbol(FX_WORD word) | |
| 555 { | |
| 556 if (IsCurrencySymbol(word)) { | |
| 557 return TRUE; | |
| 558 } | |
| 559 if (word == 0x2116) { | |
| 560 return TRUE; | |
| 561 } | |
| 562 return FALSE; | |
| 563 } | |
| 564 static FX_BOOL IsSpace(FX_WORD word) | |
| 565 { | |
| 566 return (word == 0x0020 || word == 0x3000) ? TRUE : FALSE; | |
| 567 } | |
| 568 static FX_BOOL NeedDivision(FX_WORD prevWord, FX_WORD curWord) | |
| 569 { | |
| 570 if ((IsLatin(prevWord) || IsDigit(prevWord)) && (IsLatin(curWord) || IsDigit
(curWord))) { | |
| 571 return FALSE; | |
| 572 } | |
| 573 if (IsSpace(curWord) || IsPunctuation(curWord)) { | |
| 574 return FALSE; | |
| 575 } | |
| 576 if (IsConnectiveSymbol(prevWord) || IsConnectiveSymbol(curWord)) { | |
| 577 return FALSE; | |
| 578 } | |
| 579 if (IsSpace(prevWord) || IsPunctuation(prevWord)) { | |
| 580 return TRUE; | |
| 581 } | |
| 582 if (IsPrefixSymbol(prevWord)) { | |
| 583 return FALSE; | |
| 584 } | |
| 585 if (IsPrefixSymbol(curWord) || IsCJK(curWord)) { | |
| 586 return TRUE; | |
| 587 } | |
| 588 if (IsCJK(prevWord)) { | |
| 589 return TRUE; | |
| 590 } | |
| 591 return FALSE; | |
| 592 } | |
| 593 void CTypeset::SplitLines(FX_BOOL bTypeset, FX_FLOAT fFontSize) | |
| 594 { | |
| 595 ASSERT(m_pVT != NULL); | |
| 596 ASSERT(m_pSection != NULL); | |
| 597 int32_t nLineHead = 0; | |
| 598 int32_t nLineTail = 0; | |
| 599 FX_FLOAT fMaxX = 0.0f, fMaxY = 0.0f; | |
| 600 FX_FLOAT fLineWidth = 0.0f, fBackupLineWidth = 0.0f; | |
| 601 FX_FLOAT fLineAscent = 0.0f, fBackupLineAscent = 0.0f; | |
| 602 FX_FLOAT fLineDescent = 0.0f, fBackupLineDescent = 0.0f; | |
| 603 int32_t nWordStartPos = 0; | |
| 604 FX_BOOL bFullWord = FALSE; | |
| 605 int32_t nLineFullWordIndex = 0; | |
| 606 int32_t nCharIndex = 0; | |
| 607 CPVT_LineInfo line; | |
| 608 FX_FLOAT fWordWidth = 0; | |
| 609 FX_FLOAT fTypesetWidth = FPDF_MAX(m_pVT->GetPlateWidth() - m_pVT->GetLineInd
ent(m_pSection->m_SecInfo), 0.0f); | |
| 610 int32_t nTotalWords = m_pSection->m_WordArray.GetSize(); | |
| 611 FX_BOOL bOpened = FALSE; | |
| 612 if (nTotalWords > 0) { | |
| 613 int32_t i = 0; | |
| 614 while (i < nTotalWords) { | |
| 615 CPVT_WordInfo * pWord = m_pSection->m_WordArray.GetAt(i); | |
| 616 CPVT_WordInfo* pOldWord = pWord; | |
| 617 if (i > 0) { | |
| 618 pOldWord = m_pSection->m_WordArray.GetAt(i - 1); | |
| 619 } | |
| 620 if (pWord) { | |
| 621 if (bTypeset) { | |
| 622 fLineAscent = FPDF_MAX(fLineAscent, m_pVT->GetWordAscent(*pW
ord, TRUE)); | |
| 623 fLineDescent = FPDF_MIN(fLineDescent, m_pVT->GetWordDescent(
*pWord, TRUE)); | |
| 624 fWordWidth = m_pVT->GetWordWidth(*pWord); | |
| 625 } else { | |
| 626 fLineAscent = FPDF_MAX(fLineAscent, m_pVT->GetWordAscent(*pW
ord, fFontSize)); | |
| 627 fLineDescent = FPDF_MIN(fLineDescent, m_pVT->GetWordDescent(
*pWord, fFontSize)); | |
| 628 fWordWidth = m_pVT->GetWordWidth(pWord->nFontIndex, | |
| 629 pWord->Word, | |
| 630 m_pVT->m_wSubWord, | |
| 631 m_pVT->m_fCharSpace, | |
| 632 m_pVT->m_nHorzScale, | |
| 633 fFontSize, | |
| 634 pWord->fWordTail, | |
| 635 0); | |
| 636 } | |
| 637 if (!bOpened) { | |
| 638 if (IsOpenStylePunctuation(pWord->Word)) { | |
| 639 bOpened = TRUE; | |
| 640 bFullWord = TRUE; | |
| 641 } else if (pOldWord != NULL) { | |
| 642 if (NeedDivision(pOldWord->Word, pWord->Word)) { | |
| 643 bFullWord = TRUE; | |
| 644 } | |
| 645 } | |
| 646 } else { | |
| 647 if (!IsSpace(pWord->Word) && !IsOpenStylePunctuation(pWord->
Word)) { | |
| 648 bOpened = FALSE; | |
| 649 } | |
| 650 } | |
| 651 if (bFullWord) { | |
| 652 bFullWord = FALSE; | |
| 653 if (nCharIndex > 0) { | |
| 654 nLineFullWordIndex ++; | |
| 655 } | |
| 656 nWordStartPos = i; | |
| 657 fBackupLineWidth = fLineWidth; | |
| 658 fBackupLineAscent = fLineAscent; | |
| 659 fBackupLineDescent = fLineDescent; | |
| 660 } | |
| 661 nCharIndex++; | |
| 662 } | |
| 663 if (m_pVT->m_bLimitWidth && fTypesetWidth > 0 && | |
| 664 fLineWidth + fWordWidth > fTypesetWidth) { | |
| 665 if (nLineFullWordIndex > 0) { | |
| 666 i = nWordStartPos; | |
| 667 fLineWidth = fBackupLineWidth; | |
| 668 fLineAscent = fBackupLineAscent; | |
| 669 fLineDescent = fBackupLineDescent; | |
| 670 } | |
| 671 if (nCharIndex == 1) { | |
| 672 fLineWidth = fWordWidth; | |
| 673 i++; | |
| 674 } | |
| 675 nLineTail = i - 1; | |
| 676 if (bTypeset) { | |
| 677 line.nBeginWordIndex = nLineHead; | |
| 678 line.nEndWordIndex = nLineTail; | |
| 679 line.nTotalWord = nLineTail - nLineHead + 1; | |
| 680 line.fLineWidth = fLineWidth; | |
| 681 line.fLineAscent = fLineAscent; | |
| 682 line.fLineDescent = fLineDescent; | |
| 683 m_pSection->AddLine(line); | |
| 684 } | |
| 685 fMaxY += (fLineAscent + m_pVT->GetLineLeading(m_pSection->m_SecI
nfo)); | |
| 686 fMaxY += (-fLineDescent); | |
| 687 fMaxX = FPDF_MAX(fLineWidth, fMaxX); | |
| 688 nLineHead = i; | |
| 689 fLineWidth = 0.0f; | |
| 690 fLineAscent = 0.0f; | |
| 691 fLineDescent = 0.0f; | |
| 692 nCharIndex = 0; | |
| 693 nLineFullWordIndex = 0; | |
| 694 bFullWord = FALSE; | |
| 695 } else { | |
| 696 fLineWidth += fWordWidth; | |
| 697 i++; | |
| 698 } | |
| 699 } | |
| 700 if (nLineHead <= nTotalWords - 1) { | |
| 701 nLineTail = nTotalWords - 1; | |
| 702 if (bTypeset) { | |
| 703 line.nBeginWordIndex = nLineHead; | |
| 704 line.nEndWordIndex = nLineTail; | |
| 705 line.nTotalWord = nLineTail - nLineHead + 1; | |
| 706 line.fLineWidth = fLineWidth; | |
| 707 line.fLineAscent = fLineAscent; | |
| 708 line.fLineDescent = fLineDescent; | |
| 709 m_pSection->AddLine(line); | |
| 710 } | |
| 711 fMaxY += (fLineAscent + m_pVT->GetLineLeading(m_pSection->m_SecInfo)
); | |
| 712 fMaxY += (-fLineDescent); | |
| 713 fMaxX = FPDF_MAX(fLineWidth, fMaxX); | |
| 714 } | |
| 715 } else { | |
| 716 if (bTypeset) { | |
| 717 fLineAscent = m_pVT->GetLineAscent(m_pSection->m_SecInfo); | |
| 718 fLineDescent = m_pVT->GetLineDescent(m_pSection->m_SecInfo); | |
| 719 } else { | |
| 720 fLineAscent = m_pVT->GetFontAscent(m_pVT->GetDefaultFontIndex(), fFo
ntSize); | |
| 721 fLineDescent = m_pVT->GetFontDescent(m_pVT->GetDefaultFontIndex(), f
FontSize); | |
| 722 } | |
| 723 if (bTypeset) { | |
| 724 line.nBeginWordIndex = -1; | |
| 725 line.nEndWordIndex = -1; | |
| 726 line.nTotalWord = 0; | |
| 727 line.fLineWidth = 0; | |
| 728 line.fLineAscent = fLineAscent; | |
| 729 line.fLineDescent = fLineDescent; | |
| 730 m_pSection->AddLine(line); | |
| 731 } | |
| 732 fMaxY += (m_pVT->GetLineLeading(m_pSection->m_SecInfo) + fLineAscent + (
-fLineDescent)); | |
| 733 } | |
| 734 m_rcRet = CPVT_FloatRect(0, 0, fMaxX, fMaxY); | |
| 735 } | |
| 736 void CTypeset::OutputLines() | |
| 737 { | |
| 738 ASSERT(m_pVT != NULL); | |
| 739 ASSERT(m_pSection != NULL); | |
| 740 FX_FLOAT fMinX = 0.0f, fMinY = 0.0f, fMaxX = 0.0f, fMaxY = 0.0f; | |
| 741 FX_FLOAT fPosX = 0.0f, fPosY = 0.0f; | |
| 742 FX_FLOAT fLineIndent = m_pVT->GetLineIndent(m_pSection->m_SecInfo); | |
| 743 FX_FLOAT fTypesetWidth = FPDF_MAX(m_pVT->GetPlateWidth() - fLineIndent, 0.0f
); | |
| 744 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { | |
| 745 default: | |
| 746 case 0: | |
| 747 fMinX = 0.0f; | |
| 748 break; | |
| 749 case 1: | |
| 750 fMinX = (fTypesetWidth - m_rcRet.Width()) * PVT_HALF; | |
| 751 break; | |
| 752 case 2: | |
| 753 fMinX = fTypesetWidth - m_rcRet.Width(); | |
| 754 break; | |
| 755 } | |
| 756 fMaxX = fMinX + m_rcRet.Width(); | |
| 757 fMinY = 0.0f; | |
| 758 fMaxY = m_rcRet.Height(); | |
| 759 int32_t nTotalLines = m_pSection->m_LineArray.GetSize(); | |
| 760 if (nTotalLines > 0) { | |
| 761 m_pSection->m_SecInfo.nTotalLine = nTotalLines; | |
| 762 for (int32_t l = 0; l < nTotalLines; l++) { | |
| 763 if (CLine * pLine = m_pSection->m_LineArray.GetAt(l)) { | |
| 764 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { | |
| 765 default: | |
| 766 case 0: | |
| 767 fPosX = 0; | |
| 768 break; | |
| 769 case 1: | |
| 770 fPosX = (fTypesetWidth - pLine->m_LineInfo.fLineWidth) *
PVT_HALF; | |
| 771 break; | |
| 772 case 2: | |
| 773 fPosX = fTypesetWidth - pLine->m_LineInfo.fLineWidth; | |
| 774 break; | |
| 775 } | |
| 776 fPosX += fLineIndent; | |
| 777 fPosY += m_pVT->GetLineLeading(m_pSection->m_SecInfo); | |
| 778 fPosY += pLine->m_LineInfo.fLineAscent; | |
| 779 pLine->m_LineInfo.fLineX = fPosX - fMinX; | |
| 780 pLine->m_LineInfo.fLineY = fPosY - fMinY; | |
| 781 for (int32_t w = pLine->m_LineInfo.nBeginWordIndex; w <= pLine->
m_LineInfo.nEndWordIndex; w++) { | |
| 782 if (CPVT_WordInfo * pWord = m_pSection->m_WordArray.GetAt(w)
) { | |
| 783 pWord->fWordX = fPosX - fMinX; | |
| 784 if (pWord->pWordProps) { | |
| 785 switch (pWord->pWordProps->nScriptType) { | |
| 786 default: | |
| 787 case PVTWORD_SCRIPT_NORMAL: | |
| 788 pWord->fWordY = fPosY - fMinY; | |
| 789 break; | |
| 790 case PVTWORD_SCRIPT_SUPER: | |
| 791 pWord->fWordY = fPosY - m_pVT->GetWordAscent
(*pWord) - fMinY; | |
| 792 break; | |
| 793 case PVTWORD_SCRIPT_SUB: | |
| 794 pWord->fWordY = fPosY - m_pVT->GetWordDescen
t(*pWord) - fMinY; | |
| 795 break; | |
| 796 } | |
| 797 } else { | |
| 798 pWord->fWordY = fPosY - fMinY; | |
| 799 } | |
| 800 fPosX += m_pVT->GetWordWidth(*pWord); | |
| 801 } | |
| 802 } | |
| 803 fPosY += (-pLine->m_LineInfo.fLineDescent); | |
| 804 } | |
| 805 } | |
| 806 } | |
| 807 m_rcRet = CPVT_FloatRect(fMinX, fMinY, fMaxX, fMaxY); | |
| 808 } | |
| 809 CPDF_VariableText::CPDF_VariableText() : | |
| 810 m_nLimitChar(0), | |
| 811 m_nCharArray(0), | |
| 812 m_bMultiLine(FALSE), | |
| 813 m_bLimitWidth(FALSE), | |
| 814 m_bAutoFontSize(FALSE), | |
| 815 m_nAlignment(0), | |
| 816 m_fLineLeading(0.0f), | |
| 817 m_fCharSpace(0.0f), | |
| 818 m_nHorzScale(100), | |
| 819 m_wSubWord(0), | |
| 820 m_fFontSize(0.0f), | |
| 821 m_bInitial(FALSE), | |
| 822 m_bRichText(FALSE), | |
| 823 m_pVTProvider(NULL), | |
| 824 m_pVTIterator(NULL) | |
| 825 { | |
| 826 } | |
| 827 CPDF_VariableText::~CPDF_VariableText() | |
| 828 { | |
| 829 delete m_pVTIterator; | |
| 830 m_pVTIterator = NULL; | |
| 831 ResetAll(); | |
| 832 } | |
| 833 void CPDF_VariableText::Initialize() | |
| 834 { | |
| 835 if (!m_bInitial) { | |
| 836 CPVT_SectionInfo secinfo; | |
| 837 if (m_bRichText) { | |
| 838 secinfo.pSecProps = new CPVT_SecProps(0.0f, 0.0f, 0); | |
| 839 secinfo.pWordProps = new CPVT_WordProps(GetDefaultFontIndex(), PVT_D
EFAULT_FONTSIZE, 0, 0, 0); | |
| 840 } | |
| 841 CPVT_WordPlace place; | |
| 842 place.nSecIndex = 0; | |
| 843 AddSection(place, secinfo); | |
| 844 CPVT_LineInfo lineinfo; | |
| 845 lineinfo.fLineAscent = GetFontAscent(GetDefaultFontIndex(), GetFontSize(
)); | |
| 846 lineinfo.fLineDescent = GetFontDescent(GetDefaultFontIndex(), GetFontSiz
e()); | |
| 847 AddLine(place, lineinfo); | |
| 848 if (CSection * pSection = m_SectionArray.GetAt(0)) { | |
| 849 pSection->ResetLinePlace(); | |
| 850 } | |
| 851 m_bInitial = TRUE; | |
| 852 } | |
| 853 } | |
| 854 void CPDF_VariableText::ResetAll() | |
| 855 { | |
| 856 m_bInitial = FALSE; | |
| 857 ResetSectionArray(); | |
| 858 } | |
| 859 CPVT_WordPlace CPDF_VariableText::InsertWord(const CPVT_WordPlace & place, FX_WO
RD word, int32_t charset, | |
| 860 const CPVT_WordProps * pWordProps) | |
| 861 { | |
| 862 int32_t nTotlaWords = GetTotalWords(); | |
| 863 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) { | |
| 864 return place; | |
| 865 } | |
| 866 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) { | |
| 867 return place; | |
| 868 } | |
| 869 CPVT_WordPlace newplace = place; | |
| 870 newplace.nWordIndex ++; | |
| 871 if (m_bRichText) { | |
| 872 CPVT_WordProps * pNewProps = pWordProps ? new CPVT_WordProps(*pWordProps
) : new CPVT_WordProps(); | |
| 873 pNewProps->nFontIndex = GetWordFontIndex(word, charset, pWordProps->nFon
tIndex); | |
| 874 return AddWord(newplace, CPVT_WordInfo(word, charset, -1, pNewProps)); | |
| 875 } | |
| 876 int32_t nFontIndex = GetSubWord() > 0 ? GetDefaultFontIndex() : GetWordFontI
ndex(word, charset, GetDefaultFontIndex()); | |
| 877 return AddWord(newplace, CPVT_WordInfo(word, charset, nFontIndex, NULL)); | |
| 878 } | |
| 879 CPVT_WordPlace CPDF_VariableText::InsertSection(const CPVT_WordPlace & place, co
nst CPVT_SecProps * pSecProps, | |
| 880 const CPVT_WordProps * pWordProps) | |
| 881 { | |
| 882 int32_t nTotlaWords = GetTotalWords(); | |
| 883 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) { | |
| 884 return place; | |
| 885 } | |
| 886 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) { | |
| 887 return place; | |
| 888 } | |
| 889 if (!m_bMultiLine) { | |
| 890 return place; | |
| 891 } | |
| 892 CPVT_WordPlace wordplace = place; | |
| 893 UpdateWordPlace(wordplace); | |
| 894 CPVT_WordPlace newplace = place; | |
| 895 if (CSection * pSection = m_SectionArray.GetAt(wordplace.nSecIndex)) { | |
| 896 CPVT_WordPlace NewPlace(wordplace.nSecIndex + 1, 0, -1); | |
| 897 CPVT_SectionInfo secinfo; | |
| 898 if (m_bRichText) { | |
| 899 if (pSecProps) { | |
| 900 secinfo.pSecProps = new CPVT_SecProps(*pSecProps); | |
| 901 } | |
| 902 if (pWordProps) { | |
| 903 secinfo.pWordProps = new CPVT_WordProps(*pWordProps); | |
| 904 } | |
| 905 } | |
| 906 AddSection(NewPlace, secinfo); | |
| 907 newplace = NewPlace; | |
| 908 if (CSection * pNewSection = m_SectionArray.GetAt(NewPlace.nSecIndex)) { | |
| 909 for (int32_t w = wordplace.nWordIndex + 1, sz = pSection->m_WordArra
y.GetSize(); w < sz; w++) { | |
| 910 if (CPVT_WordInfo * pWord = pSection->m_WordArray.GetAt(w)) { | |
| 911 NewPlace.nWordIndex++; | |
| 912 pNewSection->AddWord(NewPlace, *pWord); | |
| 913 } | |
| 914 } | |
| 915 } | |
| 916 ClearSectionRightWords(wordplace); | |
| 917 } | |
| 918 return newplace; | |
| 919 } | |
| 920 CPVT_WordPlace CPDF_VariableText::InsertText(const CPVT_WordPlace & place, const
FX_WCHAR* text, int32_t charset, | |
| 921 const CPVT_SecProps * pSecProps, const CPVT_WordProps * pProps) | |
| 922 { | |
| 923 CFX_WideString swText = text; | |
| 924 CPVT_WordPlace wp = place; | |
| 925 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { | |
| 926 CPVT_WordPlace oldwp = wp; | |
| 927 FX_WORD word = swText.GetAt(i); | |
| 928 switch (word) { | |
| 929 case 0x0D: | |
| 930 if (m_bMultiLine) { | |
| 931 if (swText.GetAt(i + 1) == 0x0A) { | |
| 932 i += 1; | |
| 933 } | |
| 934 wp = InsertSection(wp, pSecProps, pProps); | |
| 935 } | |
| 936 break; | |
| 937 case 0x0A: | |
| 938 if (m_bMultiLine) { | |
| 939 if (swText.GetAt(i + 1) == 0x0D) { | |
| 940 i += 1; | |
| 941 } | |
| 942 wp = InsertSection(wp, pSecProps, pProps); | |
| 943 } | |
| 944 break; | |
| 945 case 0x09: | |
| 946 word = 0x20; | |
| 947 default: | |
| 948 wp = InsertWord(wp, word, charset, pProps); | |
| 949 break; | |
| 950 } | |
| 951 if (wp == oldwp) { | |
| 952 break; | |
| 953 } | |
| 954 } | |
| 955 return wp; | |
| 956 } | |
| 957 CPVT_WordPlace CPDF_VariableText::DeleteWords(const CPVT_WordRange & PlaceRange) | |
| 958 { | |
| 959 FX_BOOL bLastSecPos = FALSE; | |
| 960 if (CSection * pSection = m_SectionArray.GetAt(PlaceRange.EndPos.nSecIndex))
{ | |
| 961 bLastSecPos = (PlaceRange.EndPos == pSection->GetEndWordPlace()); | |
| 962 } | |
| 963 ClearWords(PlaceRange); | |
| 964 if (PlaceRange.BeginPos.nSecIndex != PlaceRange.EndPos.nSecIndex) { | |
| 965 ClearEmptySections(PlaceRange); | |
| 966 if (!bLastSecPos) { | |
| 967 LinkLatterSection(PlaceRange.BeginPos); | |
| 968 } | |
| 969 } | |
| 970 return PlaceRange.BeginPos; | |
| 971 } | |
| 972 CPVT_WordPlace CPDF_VariableText::DeleteWord(const CPVT_WordPlace & place) | |
| 973 { | |
| 974 return ClearRightWord(AjustLineHeader(place, TRUE)); | |
| 975 } | |
| 976 CPVT_WordPlace CPDF_VariableText::BackSpaceWord(const CPVT_WordPlace & place) | |
| 977 { | |
| 978 return ClearLeftWord(AjustLineHeader(place, TRUE)); | |
| 979 } | |
| 980 void CPDF_VariableText::SetText(const FX_WCHAR* text, int32_t charset, const CPV
T_SecProps * pSecProps, | |
| 981 const CPVT_WordProps * pWordProps) | |
| 982 { | |
| 983 DeleteWords(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); | |
| 984 CFX_WideString swText = text; | |
| 985 CPVT_WordPlace wp(0, 0, -1); | |
| 986 CPVT_SectionInfo secinfo; | 815 CPVT_SectionInfo secinfo; |
| 987 if (m_bRichText) { | 816 if (m_bRichText) { |
| 988 if (pSecProps) { | 817 secinfo.pSecProps = new CPVT_SecProps(0.0f, 0.0f, 0); |
| 989 secinfo.pSecProps = new CPVT_SecProps(*pSecProps); | 818 secinfo.pWordProps = new CPVT_WordProps(GetDefaultFontIndex(), |
| 819 PVT_DEFAULT_FONTSIZE, 0, 0, 0); |
| 820 } |
| 821 CPVT_WordPlace place; |
| 822 place.nSecIndex = 0; |
| 823 AddSection(place, secinfo); |
| 824 CPVT_LineInfo lineinfo; |
| 825 lineinfo.fLineAscent = GetFontAscent(GetDefaultFontIndex(), GetFontSize()); |
| 826 lineinfo.fLineDescent = |
| 827 GetFontDescent(GetDefaultFontIndex(), GetFontSize()); |
| 828 AddLine(place, lineinfo); |
| 829 if (CSection* pSection = m_SectionArray.GetAt(0)) { |
| 830 pSection->ResetLinePlace(); |
| 831 } |
| 832 m_bInitial = TRUE; |
| 833 } |
| 834 } |
| 835 void CPDF_VariableText::ResetAll() { |
| 836 m_bInitial = FALSE; |
| 837 ResetSectionArray(); |
| 838 } |
| 839 CPVT_WordPlace CPDF_VariableText::InsertWord(const CPVT_WordPlace& place, |
| 840 FX_WORD word, |
| 841 int32_t charset, |
| 842 const CPVT_WordProps* pWordProps) { |
| 843 int32_t nTotlaWords = GetTotalWords(); |
| 844 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) { |
| 845 return place; |
| 846 } |
| 847 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) { |
| 848 return place; |
| 849 } |
| 850 CPVT_WordPlace newplace = place; |
| 851 newplace.nWordIndex++; |
| 852 if (m_bRichText) { |
| 853 CPVT_WordProps* pNewProps = |
| 854 pWordProps ? new CPVT_WordProps(*pWordProps) : new CPVT_WordProps(); |
| 855 pNewProps->nFontIndex = |
| 856 GetWordFontIndex(word, charset, pWordProps->nFontIndex); |
| 857 return AddWord(newplace, CPVT_WordInfo(word, charset, -1, pNewProps)); |
| 858 } |
| 859 int32_t nFontIndex = |
| 860 GetSubWord() > 0 ? GetDefaultFontIndex() |
| 861 : GetWordFontIndex(word, charset, GetDefaultFontIndex()); |
| 862 return AddWord(newplace, CPVT_WordInfo(word, charset, nFontIndex, NULL)); |
| 863 } |
| 864 CPVT_WordPlace CPDF_VariableText::InsertSection( |
| 865 const CPVT_WordPlace& place, |
| 866 const CPVT_SecProps* pSecProps, |
| 867 const CPVT_WordProps* pWordProps) { |
| 868 int32_t nTotlaWords = GetTotalWords(); |
| 869 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) { |
| 870 return place; |
| 871 } |
| 872 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) { |
| 873 return place; |
| 874 } |
| 875 if (!m_bMultiLine) { |
| 876 return place; |
| 877 } |
| 878 CPVT_WordPlace wordplace = place; |
| 879 UpdateWordPlace(wordplace); |
| 880 CPVT_WordPlace newplace = place; |
| 881 if (CSection* pSection = m_SectionArray.GetAt(wordplace.nSecIndex)) { |
| 882 CPVT_WordPlace NewPlace(wordplace.nSecIndex + 1, 0, -1); |
| 883 CPVT_SectionInfo secinfo; |
| 884 if (m_bRichText) { |
| 885 if (pSecProps) { |
| 886 secinfo.pSecProps = new CPVT_SecProps(*pSecProps); |
| 887 } |
| 888 if (pWordProps) { |
| 889 secinfo.pWordProps = new CPVT_WordProps(*pWordProps); |
| 890 } |
| 891 } |
| 892 AddSection(NewPlace, secinfo); |
| 893 newplace = NewPlace; |
| 894 if (CSection* pNewSection = m_SectionArray.GetAt(NewPlace.nSecIndex)) { |
| 895 for (int32_t w = wordplace.nWordIndex + 1, |
| 896 sz = pSection->m_WordArray.GetSize(); |
| 897 w < sz; w++) { |
| 898 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(w)) { |
| 899 NewPlace.nWordIndex++; |
| 900 pNewSection->AddWord(NewPlace, *pWord); |
| 990 } | 901 } |
| 991 if (pWordProps) { | 902 } |
| 992 secinfo.pWordProps = new CPVT_WordProps(*pWordProps); | 903 } |
| 904 ClearSectionRightWords(wordplace); |
| 905 } |
| 906 return newplace; |
| 907 } |
| 908 CPVT_WordPlace CPDF_VariableText::InsertText(const CPVT_WordPlace& place, |
| 909 const FX_WCHAR* text, |
| 910 int32_t charset, |
| 911 const CPVT_SecProps* pSecProps, |
| 912 const CPVT_WordProps* pProps) { |
| 913 CFX_WideString swText = text; |
| 914 CPVT_WordPlace wp = place; |
| 915 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { |
| 916 CPVT_WordPlace oldwp = wp; |
| 917 FX_WORD word = swText.GetAt(i); |
| 918 switch (word) { |
| 919 case 0x0D: |
| 920 if (m_bMultiLine) { |
| 921 if (swText.GetAt(i + 1) == 0x0A) { |
| 922 i += 1; |
| 923 } |
| 924 wp = InsertSection(wp, pSecProps, pProps); |
| 993 } | 925 } |
| 994 } | 926 break; |
| 995 if (CSection * pSection = m_SectionArray.GetAt(0)) { | 927 case 0x0A: |
| 996 pSection->m_SecInfo = secinfo; | 928 if (m_bMultiLine) { |
| 997 } | 929 if (swText.GetAt(i + 1) == 0x0D) { |
| 998 int32_t nCharCount = 0; | 930 i += 1; |
| 999 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { | 931 } |
| 1000 if (m_nLimitChar > 0 && nCharCount >= m_nLimitChar) { | 932 wp = InsertSection(wp, pSecProps, pProps); |
| 1001 break; | |
| 1002 } | 933 } |
| 1003 if (m_nCharArray > 0 && nCharCount >= m_nCharArray) { | 934 break; |
| 1004 break; | 935 case 0x09: |
| 936 word = 0x20; |
| 937 default: |
| 938 wp = InsertWord(wp, word, charset, pProps); |
| 939 break; |
| 940 } |
| 941 if (wp == oldwp) { |
| 942 break; |
| 943 } |
| 944 } |
| 945 return wp; |
| 946 } |
| 947 CPVT_WordPlace CPDF_VariableText::DeleteWords( |
| 948 const CPVT_WordRange& PlaceRange) { |
| 949 FX_BOOL bLastSecPos = FALSE; |
| 950 if (CSection* pSection = m_SectionArray.GetAt(PlaceRange.EndPos.nSecIndex)) { |
| 951 bLastSecPos = (PlaceRange.EndPos == pSection->GetEndWordPlace()); |
| 952 } |
| 953 ClearWords(PlaceRange); |
| 954 if (PlaceRange.BeginPos.nSecIndex != PlaceRange.EndPos.nSecIndex) { |
| 955 ClearEmptySections(PlaceRange); |
| 956 if (!bLastSecPos) { |
| 957 LinkLatterSection(PlaceRange.BeginPos); |
| 958 } |
| 959 } |
| 960 return PlaceRange.BeginPos; |
| 961 } |
| 962 CPVT_WordPlace CPDF_VariableText::DeleteWord(const CPVT_WordPlace& place) { |
| 963 return ClearRightWord(AjustLineHeader(place, TRUE)); |
| 964 } |
| 965 CPVT_WordPlace CPDF_VariableText::BackSpaceWord(const CPVT_WordPlace& place) { |
| 966 return ClearLeftWord(AjustLineHeader(place, TRUE)); |
| 967 } |
| 968 void CPDF_VariableText::SetText(const FX_WCHAR* text, |
| 969 int32_t charset, |
| 970 const CPVT_SecProps* pSecProps, |
| 971 const CPVT_WordProps* pWordProps) { |
| 972 DeleteWords(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); |
| 973 CFX_WideString swText = text; |
| 974 CPVT_WordPlace wp(0, 0, -1); |
| 975 CPVT_SectionInfo secinfo; |
| 976 if (m_bRichText) { |
| 977 if (pSecProps) { |
| 978 secinfo.pSecProps = new CPVT_SecProps(*pSecProps); |
| 979 } |
| 980 if (pWordProps) { |
| 981 secinfo.pWordProps = new CPVT_WordProps(*pWordProps); |
| 982 } |
| 983 } |
| 984 if (CSection* pSection = m_SectionArray.GetAt(0)) { |
| 985 pSection->m_SecInfo = secinfo; |
| 986 } |
| 987 int32_t nCharCount = 0; |
| 988 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { |
| 989 if (m_nLimitChar > 0 && nCharCount >= m_nLimitChar) { |
| 990 break; |
| 991 } |
| 992 if (m_nCharArray > 0 && nCharCount >= m_nCharArray) { |
| 993 break; |
| 994 } |
| 995 FX_WORD word = swText.GetAt(i); |
| 996 switch (word) { |
| 997 case 0x0D: |
| 998 if (m_bMultiLine) { |
| 999 if (swText.GetAt(i + 1) == 0x0A) { |
| 1000 i += 1; |
| 1001 } |
| 1002 wp.nSecIndex++; |
| 1003 wp.nLineIndex = 0; |
| 1004 wp.nWordIndex = -1; |
| 1005 AddSection(wp, secinfo); |
| 1005 } | 1006 } |
| 1006 FX_WORD word = swText.GetAt(i); | 1007 break; |
| 1007 switch (word) { | 1008 case 0x0A: |
| 1008 case 0x0D: | 1009 if (m_bMultiLine) { |
| 1009 if (m_bMultiLine) { | 1010 if (swText.GetAt(i + 1) == 0x0D) { |
| 1010 if (swText.GetAt(i + 1) == 0x0A) { | 1011 i += 1; |
| 1011 i += 1; | 1012 } |
| 1012 } | 1013 wp.nSecIndex++; |
| 1013 wp.nSecIndex ++; | 1014 wp.nLineIndex = 0; |
| 1014 wp.nLineIndex = 0; | 1015 wp.nWordIndex = -1; |
| 1015 wp.nWordIndex = -1; | 1016 AddSection(wp, secinfo); |
| 1016 AddSection(wp, secinfo); | |
| 1017 } | |
| 1018 break; | |
| 1019 case 0x0A: | |
| 1020 if (m_bMultiLine) { | |
| 1021 if (swText.GetAt(i + 1) == 0x0D) { | |
| 1022 i += 1; | |
| 1023 } | |
| 1024 wp.nSecIndex ++; | |
| 1025 wp.nLineIndex = 0; | |
| 1026 wp.nWordIndex = -1; | |
| 1027 AddSection(wp, secinfo); | |
| 1028 } | |
| 1029 break; | |
| 1030 case 0x09: | |
| 1031 word = 0x20; | |
| 1032 default: | |
| 1033 wp = InsertWord(wp, word, charset, pWordProps); | |
| 1034 break; | |
| 1035 } | 1017 } |
| 1036 nCharCount++; | 1018 break; |
| 1037 } | 1019 case 0x09: |
| 1038 } | 1020 word = 0x20; |
| 1039 void CPDF_VariableText::UpdateWordPlace(CPVT_WordPlace & place) const | 1021 default: |
| 1040 { | 1022 wp = InsertWord(wp, word, charset, pWordProps); |
| 1041 if (place.nSecIndex < 0) { | 1023 break; |
| 1042 place = GetBeginWordPlace(); | 1024 } |
| 1043 } | 1025 nCharCount++; |
| 1044 if (place.nSecIndex >= m_SectionArray.GetSize()) { | 1026 } |
| 1045 place = GetEndWordPlace(); | 1027 } |
| 1046 } | 1028 void CPDF_VariableText::UpdateWordPlace(CPVT_WordPlace& place) const { |
| 1047 place = AjustLineHeader(place, TRUE); | 1029 if (place.nSecIndex < 0) { |
| 1048 if (CSection * pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 1030 place = GetBeginWordPlace(); |
| 1031 } |
| 1032 if (place.nSecIndex >= m_SectionArray.GetSize()) { |
| 1033 place = GetEndWordPlace(); |
| 1034 } |
| 1035 place = AjustLineHeader(place, TRUE); |
| 1036 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1037 pSection->UpdateWordPlace(place); |
| 1038 } |
| 1039 } |
| 1040 int32_t CPDF_VariableText::WordPlaceToWordIndex( |
| 1041 const CPVT_WordPlace& place) const { |
| 1042 CPVT_WordPlace newplace = place; |
| 1043 UpdateWordPlace(newplace); |
| 1044 int32_t nIndex = 0; |
| 1045 int32_t i = 0; |
| 1046 int32_t sz = 0; |
| 1047 for (i = 0, sz = m_SectionArray.GetSize(); i < sz && i < newplace.nSecIndex; |
| 1048 i++) { |
| 1049 if (CSection* pSection = m_SectionArray.GetAt(i)) { |
| 1050 nIndex += pSection->m_WordArray.GetSize(); |
| 1051 if (i != m_SectionArray.GetSize() - 1) { |
| 1052 nIndex += PVT_RETURN_LENGTH; |
| 1053 } |
| 1054 } |
| 1055 } |
| 1056 if (i >= 0 && i < m_SectionArray.GetSize()) { |
| 1057 nIndex += newplace.nWordIndex + PVT_RETURN_LENGTH; |
| 1058 } |
| 1059 return nIndex; |
| 1060 } |
| 1061 CPVT_WordPlace CPDF_VariableText::WordIndexToWordPlace(int32_t index) const { |
| 1062 CPVT_WordPlace place = GetBeginWordPlace(); |
| 1063 int32_t nOldIndex = 0, nIndex = 0; |
| 1064 FX_BOOL bFind = FALSE; |
| 1065 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) { |
| 1066 if (CSection* pSection = m_SectionArray.GetAt(i)) { |
| 1067 nIndex += pSection->m_WordArray.GetSize(); |
| 1068 if (nIndex == index) { |
| 1069 place = pSection->GetEndWordPlace(); |
| 1070 bFind = TRUE; |
| 1071 break; |
| 1072 } else if (nIndex > index) { |
| 1073 place.nSecIndex = i; |
| 1074 place.nWordIndex = index - nOldIndex - 1; |
| 1049 pSection->UpdateWordPlace(place); | 1075 pSection->UpdateWordPlace(place); |
| 1050 } | 1076 bFind = TRUE; |
| 1051 } | 1077 break; |
| 1052 int32_t CPDF_VariableText::WordPlaceToWordIndex(const CPVT_WordPlace & place) co
nst | 1078 } |
| 1053 { | 1079 if (i != m_SectionArray.GetSize() - 1) { |
| 1054 CPVT_WordPlace newplace = place; | 1080 nIndex += PVT_RETURN_LENGTH; |
| 1055 UpdateWordPlace(newplace); | 1081 } |
| 1056 int32_t nIndex = 0; | 1082 nOldIndex = nIndex; |
| 1057 int32_t i = 0; | 1083 } |
| 1058 int32_t sz = 0; | 1084 } |
| 1059 for (i = 0, sz = m_SectionArray.GetSize(); i < sz && i < newplace.nSecIndex;
i++) { | 1085 if (!bFind) { |
| 1060 if (CSection * pSection = m_SectionArray.GetAt(i)) { | 1086 place = GetEndWordPlace(); |
| 1061 nIndex += pSection->m_WordArray.GetSize(); | 1087 } |
| 1062 if (i != m_SectionArray.GetSize() - 1) { | 1088 return place; |
| 1063 nIndex += PVT_RETURN_LENGTH; | 1089 } |
| 1064 } | 1090 CPVT_WordPlace CPDF_VariableText::GetBeginWordPlace() const { |
| 1091 return m_bInitial ? CPVT_WordPlace(0, 0, -1) : CPVT_WordPlace(); |
| 1092 } |
| 1093 CPVT_WordPlace CPDF_VariableText::GetEndWordPlace() const { |
| 1094 if (CSection* pSection = m_SectionArray.GetAt(m_SectionArray.GetSize() - 1)) { |
| 1095 return pSection->GetEndWordPlace(); |
| 1096 } |
| 1097 return CPVT_WordPlace(); |
| 1098 } |
| 1099 CPVT_WordPlace CPDF_VariableText::GetPrevWordPlace( |
| 1100 const CPVT_WordPlace& place) const { |
| 1101 if (place.nSecIndex < 0) { |
| 1102 return GetBeginWordPlace(); |
| 1103 } |
| 1104 if (place.nSecIndex >= m_SectionArray.GetSize()) { |
| 1105 return GetEndWordPlace(); |
| 1106 } |
| 1107 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1108 if (place.WordCmp(pSection->GetBeginWordPlace()) <= 0) { |
| 1109 if (CSection* pPrevSection = m_SectionArray.GetAt(place.nSecIndex - 1)) { |
| 1110 return pPrevSection->GetEndWordPlace(); |
| 1111 } |
| 1112 return GetBeginWordPlace(); |
| 1113 } |
| 1114 return pSection->GetPrevWordPlace(place); |
| 1115 } |
| 1116 return place; |
| 1117 } |
| 1118 CPVT_WordPlace CPDF_VariableText::GetNextWordPlace( |
| 1119 const CPVT_WordPlace& place) const { |
| 1120 if (place.nSecIndex < 0) { |
| 1121 return GetBeginWordPlace(); |
| 1122 } |
| 1123 if (place.nSecIndex >= m_SectionArray.GetSize()) { |
| 1124 return GetEndWordPlace(); |
| 1125 } |
| 1126 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1127 if (place.WordCmp(pSection->GetEndWordPlace()) >= 0) { |
| 1128 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) { |
| 1129 return pNextSection->GetBeginWordPlace(); |
| 1130 } |
| 1131 return GetEndWordPlace(); |
| 1132 } |
| 1133 return pSection->GetNextWordPlace(place); |
| 1134 } |
| 1135 return place; |
| 1136 } |
| 1137 CPVT_WordPlace CPDF_VariableText::SearchWordPlace( |
| 1138 const CPDF_Point& point) const { |
| 1139 CPDF_Point pt = OutToIn(point); |
| 1140 CPVT_WordPlace place = GetBeginWordPlace(); |
| 1141 int32_t nLeft = 0; |
| 1142 int32_t nRight = m_SectionArray.GetSize() - 1; |
| 1143 int32_t nMid = m_SectionArray.GetSize() / 2; |
| 1144 FX_BOOL bUp = TRUE; |
| 1145 FX_BOOL bDown = TRUE; |
| 1146 while (nLeft <= nRight) { |
| 1147 if (CSection* pSection = m_SectionArray.GetAt(nMid)) { |
| 1148 if (IsFloatBigger(pt.y, pSection->m_SecInfo.rcSection.top)) { |
| 1149 bUp = FALSE; |
| 1150 } |
| 1151 if (IsFloatBigger(pSection->m_SecInfo.rcSection.bottom, pt.y)) { |
| 1152 bDown = FALSE; |
| 1153 } |
| 1154 if (IsFloatSmaller(pt.y, pSection->m_SecInfo.rcSection.top)) { |
| 1155 nRight = nMid - 1; |
| 1156 nMid = (nLeft + nRight) / 2; |
| 1157 continue; |
| 1158 } else if (IsFloatBigger(pt.y, pSection->m_SecInfo.rcSection.bottom)) { |
| 1159 nLeft = nMid + 1; |
| 1160 nMid = (nLeft + nRight) / 2; |
| 1161 continue; |
| 1162 } else { |
| 1163 place = pSection->SearchWordPlace( |
| 1164 CPDF_Point(pt.x - pSection->m_SecInfo.rcSection.left, |
| 1165 pt.y - pSection->m_SecInfo.rcSection.top)); |
| 1166 place.nSecIndex = nMid; |
| 1167 return place; |
| 1168 } |
| 1169 } else { |
| 1170 break; |
| 1171 } |
| 1172 } |
| 1173 if (bUp) { |
| 1174 place = GetBeginWordPlace(); |
| 1175 } |
| 1176 if (bDown) { |
| 1177 place = GetEndWordPlace(); |
| 1178 } |
| 1179 return place; |
| 1180 } |
| 1181 CPVT_WordPlace CPDF_VariableText::GetUpWordPlace( |
| 1182 const CPVT_WordPlace& place, |
| 1183 const CPDF_Point& point) const { |
| 1184 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1185 CPVT_WordPlace temp = place; |
| 1186 CPDF_Point pt = OutToIn(point); |
| 1187 if (temp.nLineIndex-- > 0) { |
| 1188 return pSection->SearchWordPlace( |
| 1189 pt.x - pSection->m_SecInfo.rcSection.left, temp); |
| 1190 } |
| 1191 if (temp.nSecIndex-- > 0) { |
| 1192 if (CSection* pLastSection = m_SectionArray.GetAt(temp.nSecIndex)) { |
| 1193 temp.nLineIndex = pLastSection->m_LineArray.GetSize() - 1; |
| 1194 return pLastSection->SearchWordPlace( |
| 1195 pt.x - pLastSection->m_SecInfo.rcSection.left, temp); |
| 1196 } |
| 1197 } |
| 1198 } |
| 1199 return place; |
| 1200 } |
| 1201 CPVT_WordPlace CPDF_VariableText::GetDownWordPlace( |
| 1202 const CPVT_WordPlace& place, |
| 1203 const CPDF_Point& point) const { |
| 1204 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1205 CPVT_WordPlace temp = place; |
| 1206 CPDF_Point pt = OutToIn(point); |
| 1207 if (temp.nLineIndex++ < pSection->m_LineArray.GetSize() - 1) { |
| 1208 return pSection->SearchWordPlace( |
| 1209 pt.x - pSection->m_SecInfo.rcSection.left, temp); |
| 1210 } |
| 1211 if (temp.nSecIndex++ < m_SectionArray.GetSize() - 1) { |
| 1212 if (CSection* pNextSection = m_SectionArray.GetAt(temp.nSecIndex)) { |
| 1213 temp.nLineIndex = 0; |
| 1214 return pNextSection->SearchWordPlace( |
| 1215 pt.x - pSection->m_SecInfo.rcSection.left, temp); |
| 1216 } |
| 1217 } |
| 1218 } |
| 1219 return place; |
| 1220 } |
| 1221 CPVT_WordPlace CPDF_VariableText::GetLineBeginPlace( |
| 1222 const CPVT_WordPlace& place) const { |
| 1223 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, -1); |
| 1224 } |
| 1225 CPVT_WordPlace CPDF_VariableText::GetLineEndPlace( |
| 1226 const CPVT_WordPlace& place) const { |
| 1227 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1228 if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex)) |
| 1229 return pLine->GetEndWordPlace(); |
| 1230 } |
| 1231 return place; |
| 1232 } |
| 1233 CPVT_WordPlace CPDF_VariableText::GetSectionBeginPlace( |
| 1234 const CPVT_WordPlace& place) const { |
| 1235 return CPVT_WordPlace(place.nSecIndex, 0, -1); |
| 1236 } |
| 1237 CPVT_WordPlace CPDF_VariableText::GetSectionEndPlace( |
| 1238 const CPVT_WordPlace& place) const { |
| 1239 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1240 return pSection->GetEndWordPlace(); |
| 1241 } |
| 1242 return place; |
| 1243 } |
| 1244 int32_t CPDF_VariableText::GetTotalWords() const { |
| 1245 int32_t nTotal = 0; |
| 1246 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) |
| 1247 if (CSection* pSection = m_SectionArray.GetAt(i)) { |
| 1248 nTotal += (pSection->m_WordArray.GetSize() + PVT_RETURN_LENGTH); |
| 1249 } |
| 1250 return nTotal - PVT_RETURN_LENGTH; |
| 1251 } |
| 1252 void CPDF_VariableText::ResetSectionArray() { |
| 1253 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { |
| 1254 delete m_SectionArray.GetAt(s); |
| 1255 } |
| 1256 m_SectionArray.RemoveAll(); |
| 1257 } |
| 1258 CPVT_WordPlace CPDF_VariableText::AddSection(const CPVT_WordPlace& place, |
| 1259 const CPVT_SectionInfo& secinfo) { |
| 1260 if (IsValid() && !m_bMultiLine) { |
| 1261 return place; |
| 1262 } |
| 1263 int32_t nSecIndex = |
| 1264 FPDF_MAX(FPDF_MIN(place.nSecIndex, m_SectionArray.GetSize()), 0); |
| 1265 CSection* pSection = new CSection(this); |
| 1266 pSection->m_SecInfo = secinfo; |
| 1267 pSection->SecPlace.nSecIndex = nSecIndex; |
| 1268 if (nSecIndex == m_SectionArray.GetSize()) { |
| 1269 m_SectionArray.Add(pSection); |
| 1270 } else { |
| 1271 m_SectionArray.InsertAt(nSecIndex, pSection); |
| 1272 } |
| 1273 return place; |
| 1274 } |
| 1275 CPVT_WordPlace CPDF_VariableText::AddLine(const CPVT_WordPlace& place, |
| 1276 const CPVT_LineInfo& lineinfo) { |
| 1277 if (m_SectionArray.IsEmpty()) { |
| 1278 return place; |
| 1279 } |
| 1280 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1281 return pSection->AddLine(lineinfo); |
| 1282 } |
| 1283 return place; |
| 1284 } |
| 1285 CPVT_WordPlace CPDF_VariableText::AddWord(const CPVT_WordPlace& place, |
| 1286 const CPVT_WordInfo& wordinfo) { |
| 1287 if (m_SectionArray.GetSize() <= 0) { |
| 1288 return place; |
| 1289 } |
| 1290 CPVT_WordPlace newplace = place; |
| 1291 newplace.nSecIndex = |
| 1292 FPDF_MAX(FPDF_MIN(newplace.nSecIndex, m_SectionArray.GetSize() - 1), 0); |
| 1293 if (CSection* pSection = m_SectionArray.GetAt(newplace.nSecIndex)) { |
| 1294 return pSection->AddWord(newplace, wordinfo); |
| 1295 } |
| 1296 return place; |
| 1297 } |
| 1298 FX_BOOL CPDF_VariableText::GetWordInfo(const CPVT_WordPlace& place, |
| 1299 CPVT_WordInfo& wordinfo) { |
| 1300 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1301 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(place.nWordIndex)) { |
| 1302 wordinfo = *pWord; |
| 1303 return TRUE; |
| 1304 } |
| 1305 } |
| 1306 return FALSE; |
| 1307 } |
| 1308 FX_BOOL CPDF_VariableText::SetWordInfo(const CPVT_WordPlace& place, |
| 1309 const CPVT_WordInfo& wordinfo) { |
| 1310 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1311 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(place.nWordIndex)) { |
| 1312 *pWord = wordinfo; |
| 1313 return TRUE; |
| 1314 } |
| 1315 } |
| 1316 return FALSE; |
| 1317 } |
| 1318 FX_BOOL CPDF_VariableText::GetLineInfo(const CPVT_WordPlace& place, |
| 1319 CPVT_LineInfo& lineinfo) { |
| 1320 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1321 if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex)) { |
| 1322 lineinfo = pLine->m_LineInfo; |
| 1323 return TRUE; |
| 1324 } |
| 1325 } |
| 1326 return FALSE; |
| 1327 } |
| 1328 FX_BOOL CPDF_VariableText::GetSectionInfo(const CPVT_WordPlace& place, |
| 1329 CPVT_SectionInfo& secinfo) { |
| 1330 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1331 secinfo = pSection->m_SecInfo; |
| 1332 return TRUE; |
| 1333 } |
| 1334 return FALSE; |
| 1335 } |
| 1336 CPDF_Rect CPDF_VariableText::GetContentRect() const { |
| 1337 return InToOut(CPDF_EditContainer::GetContentRect()); |
| 1338 } |
| 1339 FX_FLOAT CPDF_VariableText::GetWordFontSize(const CPVT_WordInfo& WordInfo, |
| 1340 FX_BOOL bFactFontSize) { |
| 1341 return m_bRichText && WordInfo.pWordProps |
| 1342 ? (WordInfo.pWordProps->nScriptType == PVTWORD_SCRIPT_NORMAL || |
| 1343 bFactFontSize |
| 1344 ? WordInfo.pWordProps->fFontSize |
| 1345 : WordInfo.pWordProps->fFontSize * PVT_HALF) |
| 1346 : GetFontSize(); |
| 1347 } |
| 1348 int32_t CPDF_VariableText::GetWordFontIndex(const CPVT_WordInfo& WordInfo) { |
| 1349 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nFontIndex |
| 1350 : WordInfo.nFontIndex; |
| 1351 } |
| 1352 FX_FLOAT CPDF_VariableText::GetWordWidth(int32_t nFontIndex, |
| 1353 FX_WORD Word, |
| 1354 FX_WORD SubWord, |
| 1355 FX_FLOAT fCharSpace, |
| 1356 int32_t nHorzScale, |
| 1357 FX_FLOAT fFontSize, |
| 1358 FX_FLOAT fWordTail, |
| 1359 int32_t nWordStyle) { |
| 1360 return (GetCharWidth(nFontIndex, Word, SubWord, nWordStyle) * fFontSize * |
| 1361 PVT_FONTSCALE + |
| 1362 fCharSpace) * |
| 1363 nHorzScale * PVT_PERCENT + |
| 1364 fWordTail; |
| 1365 } |
| 1366 FX_FLOAT CPDF_VariableText::GetWordWidth(const CPVT_WordInfo& WordInfo) { |
| 1367 return GetWordWidth( |
| 1368 GetWordFontIndex(WordInfo), WordInfo.Word, GetSubWord(), |
| 1369 GetCharSpace(WordInfo), GetHorzScale(WordInfo), GetWordFontSize(WordInfo), |
| 1370 WordInfo.fWordTail, |
| 1371 WordInfo.pWordProps ? WordInfo.pWordProps->nWordStyle : 0); |
| 1372 } |
| 1373 FX_FLOAT CPDF_VariableText::GetLineAscent(const CPVT_SectionInfo& SecInfo) { |
| 1374 return m_bRichText && SecInfo.pWordProps |
| 1375 ? GetFontAscent(SecInfo.pWordProps->nFontIndex, |
| 1376 SecInfo.pWordProps->fFontSize) |
| 1377 : GetFontAscent(GetDefaultFontIndex(), GetFontSize()); |
| 1378 } |
| 1379 FX_FLOAT CPDF_VariableText::GetLineDescent(const CPVT_SectionInfo& SecInfo) { |
| 1380 return m_bRichText && SecInfo.pWordProps |
| 1381 ? GetFontDescent(SecInfo.pWordProps->nFontIndex, |
| 1382 SecInfo.pWordProps->fFontSize) |
| 1383 : GetFontDescent(GetDefaultFontIndex(), GetFontSize()); |
| 1384 } |
| 1385 FX_FLOAT CPDF_VariableText::GetFontAscent(int32_t nFontIndex, |
| 1386 FX_FLOAT fFontSize) { |
| 1387 return (FX_FLOAT)GetTypeAscent(nFontIndex) * fFontSize * PVT_FONTSCALE; |
| 1388 } |
| 1389 FX_FLOAT CPDF_VariableText::GetFontDescent(int32_t nFontIndex, |
| 1390 FX_FLOAT fFontSize) { |
| 1391 return (FX_FLOAT)GetTypeDescent(nFontIndex) * fFontSize * PVT_FONTSCALE; |
| 1392 } |
| 1393 FX_FLOAT CPDF_VariableText::GetWordAscent(const CPVT_WordInfo& WordInfo, |
| 1394 FX_FLOAT fFontSize) { |
| 1395 return GetFontAscent(GetWordFontIndex(WordInfo), fFontSize); |
| 1396 } |
| 1397 FX_FLOAT CPDF_VariableText::GetWordDescent(const CPVT_WordInfo& WordInfo, |
| 1398 FX_FLOAT fFontSize) { |
| 1399 return GetFontDescent(GetWordFontIndex(WordInfo), fFontSize); |
| 1400 } |
| 1401 FX_FLOAT CPDF_VariableText::GetWordAscent(const CPVT_WordInfo& WordInfo, |
| 1402 FX_BOOL bFactFontSize) { |
| 1403 return GetFontAscent(GetWordFontIndex(WordInfo), |
| 1404 GetWordFontSize(WordInfo, bFactFontSize)); |
| 1405 } |
| 1406 FX_FLOAT CPDF_VariableText::GetWordDescent(const CPVT_WordInfo& WordInfo, |
| 1407 FX_BOOL bFactFontSize) { |
| 1408 return GetFontDescent(GetWordFontIndex(WordInfo), |
| 1409 GetWordFontSize(WordInfo, bFactFontSize)); |
| 1410 } |
| 1411 FX_FLOAT CPDF_VariableText::GetLineLeading(const CPVT_SectionInfo& SecInfo) { |
| 1412 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->fLineLeading |
| 1413 : m_fLineLeading; |
| 1414 } |
| 1415 FX_FLOAT CPDF_VariableText::GetLineIndent(const CPVT_SectionInfo& SecInfo) { |
| 1416 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->fLineIndent |
| 1417 : 0.0f; |
| 1418 } |
| 1419 int32_t CPDF_VariableText::GetAlignment(const CPVT_SectionInfo& SecInfo) { |
| 1420 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->nAlignment |
| 1421 : m_nAlignment; |
| 1422 } |
| 1423 FX_FLOAT CPDF_VariableText::GetCharSpace(const CPVT_WordInfo& WordInfo) { |
| 1424 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->fCharSpace |
| 1425 : m_fCharSpace; |
| 1426 } |
| 1427 int32_t CPDF_VariableText::GetHorzScale(const CPVT_WordInfo& WordInfo) { |
| 1428 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nHorzScale |
| 1429 : m_nHorzScale; |
| 1430 } |
| 1431 void CPDF_VariableText::ClearSectionRightWords(const CPVT_WordPlace& place) { |
| 1432 CPVT_WordPlace wordplace = AjustLineHeader(place, TRUE); |
| 1433 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1434 for (int32_t w = pSection->m_WordArray.GetSize() - 1; |
| 1435 w > wordplace.nWordIndex; w--) { |
| 1436 delete pSection->m_WordArray.GetAt(w); |
| 1437 pSection->m_WordArray.RemoveAt(w); |
| 1438 } |
| 1439 } |
| 1440 } |
| 1441 CPVT_WordPlace CPDF_VariableText::AjustLineHeader(const CPVT_WordPlace& place, |
| 1442 FX_BOOL bPrevOrNext) const { |
| 1443 if (place.nWordIndex < 0 && place.nLineIndex > 0) { |
| 1444 return bPrevOrNext ? GetPrevWordPlace(place) : GetNextWordPlace(place); |
| 1445 } |
| 1446 return place; |
| 1447 } |
| 1448 FX_BOOL CPDF_VariableText::ClearEmptySection(const CPVT_WordPlace& place) { |
| 1449 if (place.nSecIndex == 0 && m_SectionArray.GetSize() == 1) { |
| 1450 return FALSE; |
| 1451 } |
| 1452 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1453 if (pSection->m_WordArray.GetSize() == 0) { |
| 1454 delete pSection; |
| 1455 m_SectionArray.RemoveAt(place.nSecIndex); |
| 1456 return TRUE; |
| 1457 } |
| 1458 } |
| 1459 return FALSE; |
| 1460 } |
| 1461 void CPDF_VariableText::ClearEmptySections(const CPVT_WordRange& PlaceRange) { |
| 1462 CPVT_WordPlace wordplace; |
| 1463 for (int32_t s = PlaceRange.EndPos.nSecIndex; |
| 1464 s > PlaceRange.BeginPos.nSecIndex; s--) { |
| 1465 wordplace.nSecIndex = s; |
| 1466 ClearEmptySection(wordplace); |
| 1467 } |
| 1468 } |
| 1469 void CPDF_VariableText::LinkLatterSection(const CPVT_WordPlace& place) { |
| 1470 CPVT_WordPlace oldplace = AjustLineHeader(place, TRUE); |
| 1471 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) { |
| 1472 if (CSection* pSection = m_SectionArray.GetAt(oldplace.nSecIndex)) { |
| 1473 for (int32_t w = 0, sz = pNextSection->m_WordArray.GetSize(); w < sz; |
| 1474 w++) { |
| 1475 if (CPVT_WordInfo* pWord = pNextSection->m_WordArray.GetAt(w)) { |
| 1476 oldplace.nWordIndex++; |
| 1477 pSection->AddWord(oldplace, *pWord); |
| 1065 } | 1478 } |
| 1066 } | 1479 } |
| 1067 if (i >= 0 && i < m_SectionArray.GetSize()) { | 1480 } |
| 1068 nIndex += newplace.nWordIndex + PVT_RETURN_LENGTH; | 1481 delete pNextSection; |
| 1069 } | 1482 m_SectionArray.RemoveAt(place.nSecIndex + 1); |
| 1070 return nIndex; | 1483 } |
| 1071 } | 1484 } |
| 1072 CPVT_WordPlace CPDF_VariableText::WordIndexToWordPlace(int32_t index) const | 1485 void CPDF_VariableText::ClearWords(const CPVT_WordRange& PlaceRange) { |
| 1073 { | 1486 CPVT_WordRange NewRange; |
| 1074 CPVT_WordPlace place = GetBeginWordPlace(); | 1487 NewRange.BeginPos = AjustLineHeader(PlaceRange.BeginPos, TRUE); |
| 1075 int32_t nOldIndex = 0 , nIndex = 0; | 1488 NewRange.EndPos = AjustLineHeader(PlaceRange.EndPos, TRUE); |
| 1076 FX_BOOL bFind = FALSE; | 1489 for (int32_t s = NewRange.EndPos.nSecIndex; s >= NewRange.BeginPos.nSecIndex; |
| 1077 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) { | 1490 s--) { |
| 1078 if (CSection * pSection = m_SectionArray.GetAt(i)) { | 1491 if (CSection* pSection = m_SectionArray.GetAt(s)) { |
| 1079 nIndex += pSection->m_WordArray.GetSize(); | 1492 pSection->ClearWords(NewRange); |
| 1080 if (nIndex == index) { | 1493 } |
| 1081 place = pSection->GetEndWordPlace(); | 1494 } |
| 1082 bFind = TRUE; | 1495 } |
| 1083 break; | 1496 CPVT_WordPlace CPDF_VariableText::ClearLeftWord(const CPVT_WordPlace& place) { |
| 1084 } else if (nIndex > index) { | 1497 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1085 place.nSecIndex = i; | 1498 CPVT_WordPlace leftplace = GetPrevWordPlace(place); |
| 1086 place.nWordIndex = index - nOldIndex - 1; | 1499 if (leftplace != place) { |
| 1087 pSection->UpdateWordPlace(place); | 1500 if (leftplace.nSecIndex != place.nSecIndex) { |
| 1088 bFind = TRUE; | 1501 if (pSection->m_WordArray.GetSize() == 0) { |
| 1089 break; | 1502 ClearEmptySection(place); |
| 1090 } | 1503 } else { |
| 1091 if (i != m_SectionArray.GetSize() - 1) { | 1504 LinkLatterSection(leftplace); |
| 1092 nIndex += PVT_RETURN_LENGTH; | |
| 1093 } | |
| 1094 nOldIndex = nIndex; | |
| 1095 } | 1505 } |
| 1096 } | 1506 } else { |
| 1097 if (!bFind) { | 1507 pSection->ClearWord(place); |
| 1098 place = GetEndWordPlace(); | 1508 } |
| 1099 } | 1509 } |
| 1100 return place; | 1510 return leftplace; |
| 1101 } | 1511 } |
| 1102 CPVT_WordPlace CPDF_VariableText::GetBeginWordPlace() const | 1512 return place; |
| 1103 { | 1513 } |
| 1104 return m_bInitial ? CPVT_WordPlace(0, 0, -1) : CPVT_WordPlace(); | 1514 CPVT_WordPlace CPDF_VariableText::ClearRightWord(const CPVT_WordPlace& place) { |
| 1105 } | 1515 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1106 CPVT_WordPlace CPDF_VariableText::GetEndWordPlace() const | 1516 CPVT_WordPlace rightplace = AjustLineHeader(GetNextWordPlace(place), FALSE); |
| 1107 { | 1517 if (rightplace != place) { |
| 1108 if (CSection * pSection = m_SectionArray.GetAt(m_SectionArray.GetSize() - 1)
) { | 1518 if (rightplace.nSecIndex != place.nSecIndex) { |
| 1109 return pSection->GetEndWordPlace(); | 1519 LinkLatterSection(place); |
| 1110 } | 1520 } else { |
| 1111 return CPVT_WordPlace(); | 1521 pSection->ClearWord(rightplace); |
| 1112 } | 1522 } |
| 1113 CPVT_WordPlace CPDF_VariableText::GetPrevWordPlace(const CPVT_WordPlace & place)
const | 1523 } |
| 1114 { | 1524 } |
| 1115 if( place.nSecIndex < 0) { | 1525 return place; |
| 1116 return GetBeginWordPlace(); | 1526 } |
| 1117 } | 1527 void CPDF_VariableText::RearrangeAll() { |
| 1118 if (place.nSecIndex >= m_SectionArray.GetSize()) { | 1528 Rearrange(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); |
| 1119 return GetEndWordPlace(); | 1529 } |
| 1120 } | 1530 void CPDF_VariableText::RearrangePart(const CPVT_WordRange& PlaceRange) { |
| 1121 if (CSection * pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 1531 Rearrange(PlaceRange); |
| 1122 if (place.WordCmp(pSection->GetBeginWordPlace()) <= 0) { | 1532 } |
| 1123 if (CSection * pPrevSection = m_SectionArray.GetAt(place.nSecIndex -
1)) { | 1533 CPVT_FloatRect CPDF_VariableText::Rearrange(const CPVT_WordRange& PlaceRange) { |
| 1124 return pPrevSection->GetEndWordPlace(); | 1534 CPVT_FloatRect rcRet; |
| 1125 } | 1535 if (IsValid()) { |
| 1126 return GetBeginWordPlace(); | 1536 if (m_bAutoFontSize) { |
| 1537 SetFontSize(GetAutoFontSize()); |
| 1538 rcRet = RearrangeSections( |
| 1539 CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); |
| 1540 } else { |
| 1541 rcRet = RearrangeSections(PlaceRange); |
| 1542 } |
| 1543 } |
| 1544 SetContentRect(rcRet); |
| 1545 return rcRet; |
| 1546 } |
| 1547 FX_FLOAT CPDF_VariableText::GetAutoFontSize() { |
| 1548 int32_t nTotal = sizeof(gFontSizeSteps) / sizeof(uint8_t); |
| 1549 if (IsMultiLine()) { |
| 1550 nTotal /= 4; |
| 1551 } |
| 1552 if (nTotal <= 0) { |
| 1553 return 0; |
| 1554 } |
| 1555 if (GetPlateWidth() <= 0) { |
| 1556 return 0; |
| 1557 } |
| 1558 int32_t nLeft = 0; |
| 1559 int32_t nRight = nTotal - 1; |
| 1560 int32_t nMid = nTotal / 2; |
| 1561 while (nLeft <= nRight) { |
| 1562 if (IsBigger(gFontSizeSteps[nMid])) { |
| 1563 nRight = nMid - 1; |
| 1564 nMid = (nLeft + nRight) / 2; |
| 1565 continue; |
| 1566 } else { |
| 1567 nLeft = nMid + 1; |
| 1568 nMid = (nLeft + nRight) / 2; |
| 1569 continue; |
| 1570 } |
| 1571 } |
| 1572 return (FX_FLOAT)gFontSizeSteps[nMid]; |
| 1573 } |
| 1574 FX_BOOL CPDF_VariableText::IsBigger(FX_FLOAT fFontSize) { |
| 1575 FX_BOOL bBigger = FALSE; |
| 1576 CPVT_Size szTotal; |
| 1577 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { |
| 1578 if (CSection* pSection = m_SectionArray.GetAt(s)) { |
| 1579 CPVT_Size size = pSection->GetSectionSize(fFontSize); |
| 1580 szTotal.x = FPDF_MAX(size.x, szTotal.x); |
| 1581 szTotal.y += size.y; |
| 1582 if (IsFloatBigger(szTotal.x, GetPlateWidth()) || |
| 1583 IsFloatBigger(szTotal.y, GetPlateHeight())) { |
| 1584 bBigger = TRUE; |
| 1585 break; |
| 1586 } |
| 1587 } |
| 1588 } |
| 1589 return bBigger; |
| 1590 } |
| 1591 CPVT_FloatRect CPDF_VariableText::RearrangeSections( |
| 1592 const CPVT_WordRange& PlaceRange) { |
| 1593 CPVT_WordPlace place; |
| 1594 FX_FLOAT fPosY = 0; |
| 1595 FX_FLOAT fOldHeight; |
| 1596 int32_t nSSecIndex = PlaceRange.BeginPos.nSecIndex; |
| 1597 int32_t nESecIndex = PlaceRange.EndPos.nSecIndex; |
| 1598 CPVT_FloatRect rcRet; |
| 1599 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { |
| 1600 place.nSecIndex = s; |
| 1601 if (CSection* pSection = m_SectionArray.GetAt(s)) { |
| 1602 pSection->SecPlace = place; |
| 1603 CPVT_FloatRect rcSec = pSection->m_SecInfo.rcSection; |
| 1604 if (s >= nSSecIndex) { |
| 1605 if (s <= nESecIndex) { |
| 1606 rcSec = pSection->Rearrange(); |
| 1607 rcSec.top += fPosY; |
| 1608 rcSec.bottom += fPosY; |
| 1609 } else { |
| 1610 fOldHeight = pSection->m_SecInfo.rcSection.bottom - |
| 1611 pSection->m_SecInfo.rcSection.top; |
| 1612 rcSec.top = fPosY; |
| 1613 rcSec.bottom = fPosY + fOldHeight; |
| 1127 } | 1614 } |
| 1128 return pSection->GetPrevWordPlace(place); | 1615 pSection->m_SecInfo.rcSection = rcSec; |
| 1129 } | 1616 pSection->ResetLinePlace(); |
| 1130 return place; | 1617 } |
| 1131 } | 1618 if (s == 0) { |
| 1132 CPVT_WordPlace CPDF_VariableText::GetNextWordPlace(const CPVT_WordPlace & place)
const | 1619 rcRet = rcSec; |
| 1133 { | 1620 } else { |
| 1134 if (place.nSecIndex < 0) { | 1621 rcRet.left = FPDF_MIN(rcSec.left, rcRet.left); |
| 1135 return GetBeginWordPlace(); | 1622 rcRet.top = FPDF_MIN(rcSec.top, rcRet.top); |
| 1136 } | 1623 rcRet.right = FPDF_MAX(rcSec.right, rcRet.right); |
| 1137 if (place.nSecIndex >= m_SectionArray.GetSize()) { | 1624 rcRet.bottom = FPDF_MAX(rcSec.bottom, rcRet.bottom); |
| 1138 return GetEndWordPlace(); | 1625 } |
| 1139 } | 1626 fPosY += rcSec.Height(); |
| 1140 if (CSection * pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 1627 } |
| 1141 if (place.WordCmp(pSection->GetEndWordPlace()) >= 0) { | 1628 } |
| 1142 if (CSection * pNextSection = m_SectionArray.GetAt(place.nSecIndex +
1)) { | 1629 return rcRet; |
| 1143 return pNextSection->GetBeginWordPlace(); | 1630 } |
| 1144 } | 1631 int32_t CPDF_VariableText::GetCharWidth(int32_t nFontIndex, |
| 1145 return GetEndWordPlace(); | 1632 FX_WORD Word, |
| 1633 FX_WORD SubWord, |
| 1634 int32_t nWordStyle) { |
| 1635 if (!m_pVTProvider) { |
| 1636 return 0; |
| 1637 } |
| 1638 if (SubWord > 0) { |
| 1639 return m_pVTProvider->GetCharWidth(nFontIndex, SubWord, nWordStyle); |
| 1640 } |
| 1641 return m_pVTProvider->GetCharWidth(nFontIndex, Word, nWordStyle); |
| 1642 } |
| 1643 int32_t CPDF_VariableText::GetTypeAscent(int32_t nFontIndex) { |
| 1644 return m_pVTProvider ? m_pVTProvider->GetTypeAscent(nFontIndex) : 0; |
| 1645 } |
| 1646 int32_t CPDF_VariableText::GetTypeDescent(int32_t nFontIndex) { |
| 1647 return m_pVTProvider ? m_pVTProvider->GetTypeDescent(nFontIndex) : 0; |
| 1648 } |
| 1649 int32_t CPDF_VariableText::GetWordFontIndex(FX_WORD word, |
| 1650 int32_t charset, |
| 1651 int32_t nFontIndex) { |
| 1652 return m_pVTProvider |
| 1653 ? m_pVTProvider->GetWordFontIndex(word, charset, nFontIndex) |
| 1654 : -1; |
| 1655 } |
| 1656 int32_t CPDF_VariableText::GetDefaultFontIndex() { |
| 1657 return m_pVTProvider ? m_pVTProvider->GetDefaultFontIndex() : -1; |
| 1658 } |
| 1659 FX_BOOL CPDF_VariableText::IsLatinWord(FX_WORD word) { |
| 1660 return m_pVTProvider ? m_pVTProvider->IsLatinWord(word) : FALSE; |
| 1661 } |
| 1662 IPDF_VariableText_Iterator* CPDF_VariableText::GetIterator() { |
| 1663 if (!m_pVTIterator) { |
| 1664 m_pVTIterator = new CPDF_VariableText_Iterator(this); |
| 1665 } |
| 1666 return m_pVTIterator; |
| 1667 } |
| 1668 IPDF_VariableText_Provider* CPDF_VariableText::SetProvider( |
| 1669 IPDF_VariableText_Provider* pProvider) { |
| 1670 IPDF_VariableText_Provider* pOld = m_pVTProvider; |
| 1671 m_pVTProvider = pProvider; |
| 1672 return pOld; |
| 1673 } |
| 1674 CPDF_VariableText_Iterator::CPDF_VariableText_Iterator(CPDF_VariableText* pVT) |
| 1675 : m_CurPos(-1, -1, -1), m_pVT(pVT) {} |
| 1676 CPDF_VariableText_Iterator::~CPDF_VariableText_Iterator() {} |
| 1677 void CPDF_VariableText_Iterator::SetAt(int32_t nWordIndex) { |
| 1678 ASSERT(m_pVT != NULL); |
| 1679 m_CurPos = m_pVT->WordIndexToWordPlace(nWordIndex); |
| 1680 } |
| 1681 void CPDF_VariableText_Iterator::SetAt(const CPVT_WordPlace& place) { |
| 1682 ASSERT(m_pVT != NULL); |
| 1683 m_CurPos = place; |
| 1684 } |
| 1685 FX_BOOL CPDF_VariableText_Iterator::NextWord() { |
| 1686 if (m_CurPos == m_pVT->GetEndWordPlace()) { |
| 1687 return FALSE; |
| 1688 } |
| 1689 m_CurPos = m_pVT->GetNextWordPlace(m_CurPos); |
| 1690 return TRUE; |
| 1691 } |
| 1692 FX_BOOL CPDF_VariableText_Iterator::PrevWord() { |
| 1693 if (m_CurPos == m_pVT->GetBeginWordPlace()) { |
| 1694 return FALSE; |
| 1695 } |
| 1696 m_CurPos = m_pVT->GetPrevWordPlace(m_CurPos); |
| 1697 return TRUE; |
| 1698 } |
| 1699 FX_BOOL CPDF_VariableText_Iterator::NextLine() { |
| 1700 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { |
| 1701 if (m_CurPos.nLineIndex < pSection->m_LineArray.GetSize() - 1) { |
| 1702 m_CurPos = |
| 1703 CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex + 1, -1); |
| 1704 return TRUE; |
| 1705 } |
| 1706 if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) { |
| 1707 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1); |
| 1708 return TRUE; |
| 1709 } |
| 1710 } |
| 1711 return FALSE; |
| 1712 } |
| 1713 FX_BOOL CPDF_VariableText_Iterator::PrevLine() { |
| 1714 if (m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { |
| 1715 if (m_CurPos.nLineIndex > 0) { |
| 1716 m_CurPos = |
| 1717 CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex - 1, -1); |
| 1718 return TRUE; |
| 1719 } |
| 1720 if (m_CurPos.nSecIndex > 0) { |
| 1721 if (CSection* pLastSection = |
| 1722 m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex - 1)) { |
| 1723 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1, |
| 1724 pLastSection->m_LineArray.GetSize() - 1, -1); |
| 1725 return TRUE; |
| 1726 } |
| 1727 } |
| 1728 } |
| 1729 return FALSE; |
| 1730 } |
| 1731 FX_BOOL CPDF_VariableText_Iterator::NextSection() { |
| 1732 if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) { |
| 1733 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1); |
| 1734 return TRUE; |
| 1735 } |
| 1736 return FALSE; |
| 1737 } |
| 1738 FX_BOOL CPDF_VariableText_Iterator::PrevSection() { |
| 1739 ASSERT(m_pVT != NULL); |
| 1740 if (m_CurPos.nSecIndex > 0) { |
| 1741 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1, 0, -1); |
| 1742 return TRUE; |
| 1743 } |
| 1744 return FALSE; |
| 1745 } |
| 1746 FX_BOOL CPDF_VariableText_Iterator::GetWord(CPVT_Word& word) const { |
| 1747 ASSERT(m_pVT != NULL); |
| 1748 word.WordPlace = m_CurPos; |
| 1749 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { |
| 1750 if (pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { |
| 1751 if (CPVT_WordInfo* pWord = |
| 1752 pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) { |
| 1753 word.Word = pWord->Word; |
| 1754 word.nCharset = pWord->nCharset; |
| 1755 word.fWidth = m_pVT->GetWordWidth(*pWord); |
| 1756 word.ptWord = m_pVT->InToOut( |
| 1757 CPDF_Point(pWord->fWordX + pSection->m_SecInfo.rcSection.left, |
| 1758 pWord->fWordY + pSection->m_SecInfo.rcSection.top)); |
| 1759 word.fAscent = m_pVT->GetWordAscent(*pWord); |
| 1760 word.fDescent = m_pVT->GetWordDescent(*pWord); |
| 1761 if (pWord->pWordProps) { |
| 1762 word.WordProps = *pWord->pWordProps; |
| 1146 } | 1763 } |
| 1147 return pSection->GetNextWordPlace(place); | 1764 word.nFontIndex = m_pVT->GetWordFontIndex(*pWord); |
| 1148 } | 1765 word.fFontSize = m_pVT->GetWordFontSize(*pWord); |
| 1149 return place; | |
| 1150 } | |
| 1151 CPVT_WordPlace CPDF_VariableText::SearchWordPlace(const CPDF_Point & point) cons
t | |
| 1152 { | |
| 1153 CPDF_Point pt = OutToIn(point); | |
| 1154 CPVT_WordPlace place = GetBeginWordPlace(); | |
| 1155 int32_t nLeft = 0; | |
| 1156 int32_t nRight = m_SectionArray.GetSize() - 1; | |
| 1157 int32_t nMid = m_SectionArray.GetSize() / 2; | |
| 1158 FX_BOOL bUp = TRUE; | |
| 1159 FX_BOOL bDown = TRUE; | |
| 1160 while (nLeft <= nRight) { | |
| 1161 if (CSection * pSection = m_SectionArray.GetAt(nMid)) { | |
| 1162 if (IsFloatBigger(pt.y, pSection->m_SecInfo.rcSection.top)) { | |
| 1163 bUp = FALSE; | |
| 1164 } | |
| 1165 if (IsFloatBigger(pSection->m_SecInfo.rcSection.bottom, pt.y)) { | |
| 1166 bDown = FALSE; | |
| 1167 } | |
| 1168 if (IsFloatSmaller(pt.y, pSection->m_SecInfo.rcSection.top)) { | |
| 1169 nRight = nMid - 1; | |
| 1170 nMid = (nLeft + nRight) / 2; | |
| 1171 continue; | |
| 1172 } else if (IsFloatBigger(pt.y, pSection->m_SecInfo.rcSection.bottom)
) { | |
| 1173 nLeft = nMid + 1; | |
| 1174 nMid = (nLeft + nRight) / 2; | |
| 1175 continue; | |
| 1176 } else { | |
| 1177 place = pSection->SearchWordPlace( | |
| 1178 CPDF_Point(pt.x - pSection->m_SecInfo.rcSection.left
, pt.y - pSection->m_SecInfo.rcSection.top) | |
| 1179 ); | |
| 1180 place.nSecIndex = nMid; | |
| 1181 return place; | |
| 1182 } | |
| 1183 } else { | |
| 1184 break; | |
| 1185 } | |
| 1186 } | |
| 1187 if (bUp) { | |
| 1188 place = GetBeginWordPlace(); | |
| 1189 } | |
| 1190 if (bDown) { | |
| 1191 place = GetEndWordPlace(); | |
| 1192 } | |
| 1193 return place; | |
| 1194 } | |
| 1195 CPVT_WordPlace CPDF_VariableText::GetUpWordPlace(const CPVT_WordPlace & place, c
onst CPDF_Point & point) const | |
| 1196 { | |
| 1197 if (CSection * pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1198 CPVT_WordPlace temp = place; | |
| 1199 CPDF_Point pt = OutToIn(point); | |
| 1200 if (temp.nLineIndex-- > 0) { | |
| 1201 return pSection->SearchWordPlace(pt.x - pSection->m_SecInfo.rcSectio
n.left, temp); | |
| 1202 } | |
| 1203 if (temp.nSecIndex-- > 0) { | |
| 1204 if (CSection * pLastSection = m_SectionArray.GetAt(temp.nSecIndex))
{ | |
| 1205 temp.nLineIndex = pLastSection->m_LineArray.GetSize() - 1; | |
| 1206 return pLastSection->SearchWordPlace(pt.x - pLastSection->m_SecI
nfo.rcSection.left, temp); | |
| 1207 } | |
| 1208 } | |
| 1209 } | |
| 1210 return place; | |
| 1211 } | |
| 1212 CPVT_WordPlace CPDF_VariableText::GetDownWordPlace(const CPVT_WordPlace & place,
const CPDF_Point & point) const | |
| 1213 { | |
| 1214 if (CSection * pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1215 CPVT_WordPlace temp = place; | |
| 1216 CPDF_Point pt = OutToIn(point); | |
| 1217 if (temp.nLineIndex++ < pSection->m_LineArray.GetSize() - 1) { | |
| 1218 return pSection->SearchWordPlace(pt.x - pSection->m_SecInfo.rcSectio
n.left, temp); | |
| 1219 } | |
| 1220 if (temp.nSecIndex++ < m_SectionArray.GetSize() - 1) { | |
| 1221 if (CSection * pNextSection = m_SectionArray.GetAt(temp.nSecIndex))
{ | |
| 1222 temp.nLineIndex = 0; | |
| 1223 return pNextSection->SearchWordPlace(pt.x - pSection->m_SecInfo.
rcSection.left, temp); | |
| 1224 } | |
| 1225 } | |
| 1226 } | |
| 1227 return place; | |
| 1228 } | |
| 1229 CPVT_WordPlace CPDF_VariableText::GetLineBeginPlace(const CPVT_WordPlace & place
) const | |
| 1230 { | |
| 1231 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, -1); | |
| 1232 } | |
| 1233 CPVT_WordPlace CPDF_VariableText::GetLineEndPlace(const CPVT_WordPlace & place)
const | |
| 1234 { | |
| 1235 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1236 if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex)) | |
| 1237 return pLine->GetEndWordPlace(); | |
| 1238 } | |
| 1239 return place; | |
| 1240 } | |
| 1241 CPVT_WordPlace CPDF_VariableText::GetSectionBeginPlace(const CPVT_WordPlace & pl
ace) const | |
| 1242 { | |
| 1243 return CPVT_WordPlace(place.nSecIndex, 0, -1); | |
| 1244 } | |
| 1245 CPVT_WordPlace CPDF_VariableText::GetSectionEndPlace(const CPVT_WordPlace & plac
e) const | |
| 1246 { | |
| 1247 if (CSection * pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1248 return pSection->GetEndWordPlace(); | |
| 1249 } | |
| 1250 return place; | |
| 1251 } | |
| 1252 int32_t CPDF_VariableText::GetTotalWords() const | |
| 1253 { | |
| 1254 int32_t nTotal = 0; | |
| 1255 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) | |
| 1256 if (CSection * pSection = m_SectionArray.GetAt(i)) { | |
| 1257 nTotal += (pSection->m_WordArray.GetSize() + PVT_RETURN_LENGTH); | |
| 1258 } | |
| 1259 return nTotal - PVT_RETURN_LENGTH; | |
| 1260 } | |
| 1261 void CPDF_VariableText::ResetSectionArray() | |
| 1262 { | |
| 1263 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { | |
| 1264 delete m_SectionArray.GetAt(s); | |
| 1265 } | |
| 1266 m_SectionArray.RemoveAll(); | |
| 1267 } | |
| 1268 CPVT_WordPlace CPDF_VariableText::AddSection(const CPVT_WordPlace & place, const
CPVT_SectionInfo & secinfo) | |
| 1269 { | |
| 1270 if (IsValid() && !m_bMultiLine) { | |
| 1271 return place; | |
| 1272 } | |
| 1273 int32_t nSecIndex = FPDF_MAX(FPDF_MIN(place.nSecIndex, m_SectionArray.GetSiz
e()), 0); | |
| 1274 CSection * pSection = new CSection(this); | |
| 1275 pSection->m_SecInfo = secinfo; | |
| 1276 pSection->SecPlace.nSecIndex = nSecIndex; | |
| 1277 if (nSecIndex == m_SectionArray.GetSize()) { | |
| 1278 m_SectionArray.Add(pSection); | |
| 1279 } else { | |
| 1280 m_SectionArray.InsertAt(nSecIndex, pSection); | |
| 1281 } | |
| 1282 return place; | |
| 1283 } | |
| 1284 CPVT_WordPlace CPDF_VariableText::AddLine(const CPVT_WordPlace & place, const CP
VT_LineInfo & lineinfo) | |
| 1285 { | |
| 1286 if (m_SectionArray.IsEmpty()) { | |
| 1287 return place; | |
| 1288 } | |
| 1289 if (CSection * pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1290 return pSection->AddLine(lineinfo); | |
| 1291 } | |
| 1292 return place; | |
| 1293 } | |
| 1294 CPVT_WordPlace CPDF_VariableText::AddWord(const CPVT_WordPlace & place, const CP
VT_WordInfo & wordinfo) | |
| 1295 { | |
| 1296 if (m_SectionArray.GetSize() <= 0) { | |
| 1297 return place; | |
| 1298 } | |
| 1299 CPVT_WordPlace newplace = place; | |
| 1300 newplace.nSecIndex = FPDF_MAX(FPDF_MIN(newplace.nSecIndex, m_SectionArray.Ge
tSize() - 1), 0); | |
| 1301 if (CSection * pSection = m_SectionArray.GetAt(newplace.nSecIndex)) { | |
| 1302 return pSection->AddWord(newplace, wordinfo); | |
| 1303 } | |
| 1304 return place; | |
| 1305 } | |
| 1306 FX_BOOL CPDF_VariableText::GetWordInfo(const CPVT_WordPlace & place, CPVT_WordIn
fo & wordinfo) | |
| 1307 { | |
| 1308 if (CSection * pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1309 if (CPVT_WordInfo * pWord = pSection->m_WordArray.GetAt(place.nWordIndex
)) { | |
| 1310 wordinfo = *pWord; | |
| 1311 return TRUE; | |
| 1312 } | |
| 1313 } | |
| 1314 return FALSE; | |
| 1315 } | |
| 1316 FX_BOOL CPDF_VariableText::SetWordInfo(const CPVT_WordPlace & place, const CPVT_
WordInfo & wordinfo) | |
| 1317 { | |
| 1318 if (CSection * pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1319 if (CPVT_WordInfo * pWord = pSection->m_WordArray.GetAt(place.nWordIndex
)) { | |
| 1320 *pWord = wordinfo; | |
| 1321 return TRUE; | |
| 1322 } | |
| 1323 } | |
| 1324 return FALSE; | |
| 1325 } | |
| 1326 FX_BOOL CPDF_VariableText::GetLineInfo(const CPVT_WordPlace & place, CPVT_LineIn
fo & lineinfo) | |
| 1327 { | |
| 1328 if (CSection * pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1329 if (CLine * pLine = pSection->m_LineArray.GetAt(place.nLineIndex)) { | |
| 1330 lineinfo = pLine->m_LineInfo; | |
| 1331 return TRUE; | |
| 1332 } | |
| 1333 } | |
| 1334 return FALSE; | |
| 1335 } | |
| 1336 FX_BOOL CPDF_VariableText::GetSectionInfo(const CPVT_WordPlace & place, CPVT_Sec
tionInfo & secinfo) | |
| 1337 { | |
| 1338 if (CSection * pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1339 secinfo = pSection->m_SecInfo; | |
| 1340 return TRUE; | 1766 return TRUE; |
| 1341 } | 1767 } |
| 1342 return FALSE; | 1768 } |
| 1343 } | 1769 } |
| 1344 CPDF_Rect CPDF_VariableText::GetContentRect() const | 1770 return FALSE; |
| 1345 { | 1771 } |
| 1346 return InToOut(CPDF_EditContainer::GetContentRect()); | 1772 FX_BOOL CPDF_VariableText_Iterator::SetWord(const CPVT_Word& word) { |
| 1347 } | 1773 ASSERT(m_pVT != NULL); |
| 1348 FX_FLOAT CPDF_VariableText::GetWordFontSize(const CPVT_WordInfo & WordInfo, FX_B
OOL bFactFontSize) | 1774 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { |
| 1349 { | 1775 if (CPVT_WordInfo* pWord = |
| 1350 return m_bRichText && WordInfo.pWordProps ? (WordInfo.pWordProps->nScriptTyp
e == PVTWORD_SCRIPT_NORMAL || bFactFontSize ? WordInfo.pWordProps->fFontSize : W
ordInfo.pWordProps->fFontSize * PVT_HALF) : GetFontSize(); | 1776 pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) { |
| 1351 } | 1777 if (pWord->pWordProps) { |
| 1352 int32_t CPDF_VariableText::GetWordFontIndex(const CPVT_WordInfo & WordInfo) | 1778 *pWord->pWordProps = word.WordProps; |
| 1353 { | 1779 } |
| 1354 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nFontIndex
: WordInfo.nFontIndex; | 1780 return TRUE; |
| 1355 } | 1781 } |
| 1356 FX_FLOAT CPDF_VariableText::GetWordWidth(int32_t nFontIndex, FX_WORD Word, FX_WO
RD SubWord, | 1782 } |
| 1357 FX_FLOAT fCharSpace, int32_t nHorzScale, | 1783 return FALSE; |
| 1358 FX_FLOAT fFontSize, FX_FLOAT fWordTail, int32_t nWordStyle) | 1784 } |
| 1359 { | 1785 FX_BOOL CPDF_VariableText_Iterator::GetLine(CPVT_Line& line) const { |
| 1360 return (GetCharWidth(nFontIndex, Word, SubWord, nWordStyle) * fFontSize * PV
T_FONTSCALE + fCharSpace) * nHorzScale * PVT_PERCENT + fWordTail; | 1786 ASSERT(m_pVT != NULL); |
| 1361 } | 1787 line.lineplace = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex, -1); |
| 1362 FX_FLOAT CPDF_VariableText::GetWordWidth(const CPVT_WordInfo & WordInfo) | 1788 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { |
| 1363 { | 1789 if (CLine* pLine = pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { |
| 1364 return GetWordWidth(GetWordFontIndex(WordInfo), WordInfo.Word, GetSubWord(),
GetCharSpace(WordInfo), GetHorzScale(WordInfo), | 1790 line.ptLine = m_pVT->InToOut(CPDF_Point( |
| 1365 GetWordFontSize(WordInfo), WordInfo.fWordTail, | 1791 pLine->m_LineInfo.fLineX + pSection->m_SecInfo.rcSection.left, |
| 1366 WordInfo.pWordProps ? WordInfo.pWordProps->nWordStyle :
0); | 1792 pLine->m_LineInfo.fLineY + pSection->m_SecInfo.rcSection.top)); |
| 1367 } | 1793 line.fLineWidth = pLine->m_LineInfo.fLineWidth; |
| 1368 FX_FLOAT CPDF_VariableText::GetLineAscent(const CPVT_SectionInfo & SecInfo) | 1794 line.fLineAscent = pLine->m_LineInfo.fLineAscent; |
| 1369 { | 1795 line.fLineDescent = pLine->m_LineInfo.fLineDescent; |
| 1370 return m_bRichText && SecInfo.pWordProps ? GetFontAscent(SecInfo.pWordProps-
>nFontIndex, SecInfo.pWordProps->fFontSize) : | 1796 line.lineEnd = pLine->GetEndWordPlace(); |
| 1371 GetFontAscent(GetDefaultFontIndex(), GetFontSize()); | 1797 return TRUE; |
| 1372 } | 1798 } |
| 1373 FX_FLOAT CPDF_VariableText::GetLineDescent(const CPVT_SectionInfo & SecInfo) | 1799 } |
| 1374 { | 1800 return FALSE; |
| 1375 return m_bRichText && SecInfo.pWordProps ? GetFontDescent(SecInfo.pWordProps
->nFontIndex, SecInfo.pWordProps->fFontSize) : | 1801 } |
| 1376 GetFontDescent(GetDefaultFontIndex(), GetFontSize()); | 1802 FX_BOOL CPDF_VariableText_Iterator::GetSection(CPVT_Section& section) const { |
| 1377 } | 1803 ASSERT(m_pVT != NULL); |
| 1378 FX_FLOAT CPDF_VariableText::GetFontAscent(int32_t nFontIndex, FX_FLOAT fFontSize
) | 1804 section.secplace = CPVT_WordPlace(m_CurPos.nSecIndex, 0, -1); |
| 1379 { | 1805 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { |
| 1380 return (FX_FLOAT)GetTypeAscent(nFontIndex) * fFontSize * PVT_FONTSCALE; | 1806 section.rcSection = m_pVT->InToOut(pSection->m_SecInfo.rcSection); |
| 1381 } | 1807 if (pSection->m_SecInfo.pSecProps) { |
| 1382 FX_FLOAT CPDF_VariableText::GetFontDescent(int32_t nFontIndex, FX_FLOAT fFontSiz
e) | 1808 section.SecProps = *pSection->m_SecInfo.pSecProps; |
| 1383 { | 1809 } |
| 1384 return (FX_FLOAT)GetTypeDescent(nFontIndex) * fFontSize * PVT_FONTSCALE; | 1810 if (pSection->m_SecInfo.pWordProps) { |
| 1385 } | 1811 section.WordProps = *pSection->m_SecInfo.pWordProps; |
| 1386 FX_FLOAT CPDF_VariableText::GetWordAscent(const CPVT_WordInfo & WordInfo, FX_FLO
AT fFontSize) | 1812 } |
| 1387 { | |
| 1388 return GetFontAscent(GetWordFontIndex(WordInfo), fFontSize); | |
| 1389 } | |
| 1390 FX_FLOAT CPDF_VariableText::GetWordDescent(const CPVT_WordInfo & WordInfo, FX_FL
OAT fFontSize) | |
| 1391 { | |
| 1392 return GetFontDescent(GetWordFontIndex(WordInfo), fFontSize); | |
| 1393 } | |
| 1394 FX_FLOAT CPDF_VariableText::GetWordAscent(const CPVT_WordInfo & WordInfo, FX_BOO
L bFactFontSize) | |
| 1395 { | |
| 1396 return GetFontAscent(GetWordFontIndex(WordInfo), GetWordFontSize(WordInfo, b
FactFontSize)); | |
| 1397 } | |
| 1398 FX_FLOAT CPDF_VariableText::GetWordDescent(const CPVT_WordInfo & WordInfo, FX_BO
OL bFactFontSize) | |
| 1399 { | |
| 1400 return GetFontDescent(GetWordFontIndex(WordInfo), GetWordFontSize(WordInfo,
bFactFontSize)); | |
| 1401 } | |
| 1402 FX_FLOAT CPDF_VariableText::GetLineLeading(const CPVT_SectionInfo & SecInfo) | |
| 1403 { | |
| 1404 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->fLineLeading :
m_fLineLeading; | |
| 1405 } | |
| 1406 FX_FLOAT CPDF_VariableText::GetLineIndent(const CPVT_SectionInfo & SecInfo) | |
| 1407 { | |
| 1408 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->fLineIndent : 0
.0f; | |
| 1409 } | |
| 1410 int32_t CPDF_VariableText::GetAlignment(const CPVT_SectionInfo& SecInfo) | |
| 1411 { | |
| 1412 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->nAlignment : m_
nAlignment; | |
| 1413 } | |
| 1414 FX_FLOAT CPDF_VariableText::GetCharSpace(const CPVT_WordInfo & WordInfo) | |
| 1415 { | |
| 1416 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->fCharSpace
: m_fCharSpace; | |
| 1417 } | |
| 1418 int32_t CPDF_VariableText::GetHorzScale(const CPVT_WordInfo & WordInfo) | |
| 1419 { | |
| 1420 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nHorzScale
: m_nHorzScale; | |
| 1421 } | |
| 1422 void CPDF_VariableText::ClearSectionRightWords(const CPVT_WordPlace & place) | |
| 1423 { | |
| 1424 CPVT_WordPlace wordplace = AjustLineHeader(place, TRUE); | |
| 1425 if (CSection * pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1426 for (int32_t w = pSection->m_WordArray.GetSize() - 1; w > wordplace.nWor
dIndex; w--) { | |
| 1427 delete pSection->m_WordArray.GetAt(w); | |
| 1428 pSection->m_WordArray.RemoveAt(w); | |
| 1429 } | |
| 1430 } | |
| 1431 } | |
| 1432 CPVT_WordPlace CPDF_VariableText::AjustLineHeader(const CPVT_WordPlace & place,
FX_BOOL bPrevOrNext) const | |
| 1433 { | |
| 1434 if (place.nWordIndex < 0 && place.nLineIndex > 0) { | |
| 1435 return bPrevOrNext ? GetPrevWordPlace(place) : GetNextWordPlace(place); | |
| 1436 } | |
| 1437 return place; | |
| 1438 } | |
| 1439 FX_BOOL CPDF_VariableText::ClearEmptySection(const CPVT_WordPlace & place) | |
| 1440 { | |
| 1441 if (place.nSecIndex == 0 && m_SectionArray.GetSize() == 1) { | |
| 1442 return FALSE; | |
| 1443 } | |
| 1444 if (CSection * pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1445 if (pSection->m_WordArray.GetSize() == 0) { | |
| 1446 delete pSection; | |
| 1447 m_SectionArray.RemoveAt(place.nSecIndex); | |
| 1448 return TRUE; | |
| 1449 } | |
| 1450 } | |
| 1451 return FALSE; | |
| 1452 } | |
| 1453 void CPDF_VariableText::ClearEmptySections(const CPVT_WordRange & PlaceRange) | |
| 1454 { | |
| 1455 CPVT_WordPlace wordplace; | |
| 1456 for (int32_t s = PlaceRange.EndPos.nSecIndex; s > PlaceRange.BeginPos.nSecIn
dex; s--) { | |
| 1457 wordplace.nSecIndex = s; | |
| 1458 ClearEmptySection(wordplace); | |
| 1459 } | |
| 1460 } | |
| 1461 void CPDF_VariableText::LinkLatterSection(const CPVT_WordPlace & place) | |
| 1462 { | |
| 1463 CPVT_WordPlace oldplace = AjustLineHeader(place, TRUE); | |
| 1464 if (CSection * pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) { | |
| 1465 if (CSection * pSection = m_SectionArray.GetAt(oldplace.nSecIndex)) { | |
| 1466 for (int32_t w = 0, sz = pNextSection->m_WordArray.GetSize(); w < sz
; w++) { | |
| 1467 if (CPVT_WordInfo * pWord = pNextSection->m_WordArray.GetAt(w))
{ | |
| 1468 oldplace.nWordIndex ++; | |
| 1469 pSection->AddWord(oldplace, *pWord); | |
| 1470 } | |
| 1471 } | |
| 1472 } | |
| 1473 delete pNextSection; | |
| 1474 m_SectionArray.RemoveAt(place.nSecIndex + 1); | |
| 1475 } | |
| 1476 } | |
| 1477 void CPDF_VariableText::ClearWords(const CPVT_WordRange & PlaceRange) | |
| 1478 { | |
| 1479 CPVT_WordRange NewRange; | |
| 1480 NewRange.BeginPos = AjustLineHeader(PlaceRange.BeginPos, TRUE); | |
| 1481 NewRange.EndPos = AjustLineHeader(PlaceRange.EndPos, TRUE); | |
| 1482 for (int32_t s = NewRange.EndPos.nSecIndex; s >= NewRange.BeginPos.nSecIndex
; s--) { | |
| 1483 if (CSection * pSection = m_SectionArray.GetAt(s)) { | |
| 1484 pSection->ClearWords(NewRange); | |
| 1485 } | |
| 1486 } | |
| 1487 } | |
| 1488 CPVT_WordPlace CPDF_VariableText::ClearLeftWord(const CPVT_WordPlace & place) | |
| 1489 { | |
| 1490 if (CSection * pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1491 CPVT_WordPlace leftplace = GetPrevWordPlace(place); | |
| 1492 if (leftplace != place) { | |
| 1493 if (leftplace.nSecIndex != place.nSecIndex) { | |
| 1494 if (pSection->m_WordArray.GetSize() == 0) { | |
| 1495 ClearEmptySection(place); | |
| 1496 } else { | |
| 1497 LinkLatterSection(leftplace); | |
| 1498 } | |
| 1499 } else { | |
| 1500 pSection->ClearWord(place); | |
| 1501 } | |
| 1502 } | |
| 1503 return leftplace; | |
| 1504 } | |
| 1505 return place; | |
| 1506 } | |
| 1507 CPVT_WordPlace CPDF_VariableText::ClearRightWord(const CPVT_WordPlace & place) | |
| 1508 { | |
| 1509 if (CSection * pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1510 CPVT_WordPlace rightplace = AjustLineHeader(GetNextWordPlace(place), FAL
SE); | |
| 1511 if (rightplace != place) { | |
| 1512 if(rightplace.nSecIndex != place.nSecIndex) { | |
| 1513 LinkLatterSection(place); | |
| 1514 } else { | |
| 1515 pSection->ClearWord(rightplace); | |
| 1516 } | |
| 1517 } | |
| 1518 } | |
| 1519 return place; | |
| 1520 } | |
| 1521 void CPDF_VariableText::RearrangeAll() | |
| 1522 { | |
| 1523 Rearrange(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); | |
| 1524 } | |
| 1525 void CPDF_VariableText::RearrangePart(const CPVT_WordRange & PlaceRange) | |
| 1526 { | |
| 1527 Rearrange(PlaceRange); | |
| 1528 } | |
| 1529 CPVT_FloatRect CPDF_VariableText::Rearrange(const CPVT_WordRange & PlaceRange) | |
| 1530 { | |
| 1531 CPVT_FloatRect rcRet; | |
| 1532 if (IsValid()) { | |
| 1533 if (m_bAutoFontSize) { | |
| 1534 SetFontSize(GetAutoFontSize()); | |
| 1535 rcRet = RearrangeSections(CPVT_WordRange(GetBeginWordPlace(), GetEnd
WordPlace())); | |
| 1536 } else { | |
| 1537 rcRet = RearrangeSections(PlaceRange); | |
| 1538 } | |
| 1539 } | |
| 1540 SetContentRect(rcRet); | |
| 1541 return rcRet; | |
| 1542 } | |
| 1543 FX_FLOAT CPDF_VariableText::GetAutoFontSize() | |
| 1544 { | |
| 1545 int32_t nTotal = sizeof(gFontSizeSteps) / sizeof(uint8_t); | |
| 1546 if (IsMultiLine()) { | |
| 1547 nTotal /= 4; | |
| 1548 } | |
| 1549 if (nTotal <= 0) { | |
| 1550 return 0; | |
| 1551 } | |
| 1552 if (GetPlateWidth() <= 0) { | |
| 1553 return 0; | |
| 1554 } | |
| 1555 int32_t nLeft = 0; | |
| 1556 int32_t nRight = nTotal - 1; | |
| 1557 int32_t nMid = nTotal / 2; | |
| 1558 while (nLeft <= nRight) { | |
| 1559 if (IsBigger(gFontSizeSteps[nMid])) { | |
| 1560 nRight = nMid - 1; | |
| 1561 nMid = (nLeft + nRight) / 2; | |
| 1562 continue; | |
| 1563 } else { | |
| 1564 nLeft = nMid + 1; | |
| 1565 nMid = (nLeft + nRight) / 2; | |
| 1566 continue; | |
| 1567 } | |
| 1568 } | |
| 1569 return (FX_FLOAT)gFontSizeSteps[nMid]; | |
| 1570 } | |
| 1571 FX_BOOL CPDF_VariableText::IsBigger(FX_FLOAT fFontSize) | |
| 1572 { | |
| 1573 FX_BOOL bBigger = FALSE; | |
| 1574 CPVT_Size szTotal; | |
| 1575 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { | |
| 1576 if (CSection * pSection = m_SectionArray.GetAt(s)) { | |
| 1577 CPVT_Size size = pSection->GetSectionSize(fFontSize); | |
| 1578 szTotal.x = FPDF_MAX(size.x, szTotal.x); | |
| 1579 szTotal.y += size.y; | |
| 1580 if (IsFloatBigger(szTotal.x, GetPlateWidth()) | |
| 1581 || IsFloatBigger(szTotal.y, GetPlateHeight()) | |
| 1582 ) { | |
| 1583 bBigger = TRUE; | |
| 1584 break; | |
| 1585 } | |
| 1586 } | |
| 1587 } | |
| 1588 return bBigger; | |
| 1589 } | |
| 1590 CPVT_FloatRect CPDF_VariableText::RearrangeSections(const CPVT_WordRange & Place
Range) | |
| 1591 { | |
| 1592 CPVT_WordPlace place; | |
| 1593 FX_FLOAT fPosY = 0; | |
| 1594 FX_FLOAT fOldHeight; | |
| 1595 int32_t nSSecIndex = PlaceRange.BeginPos.nSecIndex; | |
| 1596 int32_t nESecIndex = PlaceRange.EndPos.nSecIndex; | |
| 1597 CPVT_FloatRect rcRet; | |
| 1598 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { | |
| 1599 place.nSecIndex = s; | |
| 1600 if (CSection * pSection = m_SectionArray.GetAt(s)) { | |
| 1601 pSection->SecPlace = place; | |
| 1602 CPVT_FloatRect rcSec = pSection->m_SecInfo.rcSection; | |
| 1603 if (s >= nSSecIndex) { | |
| 1604 if (s <= nESecIndex) { | |
| 1605 rcSec = pSection->Rearrange(); | |
| 1606 rcSec.top += fPosY; | |
| 1607 rcSec.bottom += fPosY; | |
| 1608 } else { | |
| 1609 fOldHeight = pSection->m_SecInfo.rcSection.bottom - pSection
->m_SecInfo.rcSection.top; | |
| 1610 rcSec.top = fPosY; | |
| 1611 rcSec.bottom = fPosY + fOldHeight; | |
| 1612 } | |
| 1613 pSection->m_SecInfo.rcSection = rcSec; | |
| 1614 pSection->ResetLinePlace(); | |
| 1615 } | |
| 1616 if (s == 0) { | |
| 1617 rcRet = rcSec; | |
| 1618 } else { | |
| 1619 rcRet.left = FPDF_MIN(rcSec.left, rcRet.left); | |
| 1620 rcRet.top = FPDF_MIN(rcSec.top, rcRet.top); | |
| 1621 rcRet.right = FPDF_MAX(rcSec.right, rcRet.right); | |
| 1622 rcRet.bottom = FPDF_MAX(rcSec.bottom, rcRet.bottom); | |
| 1623 } | |
| 1624 fPosY += rcSec.Height(); | |
| 1625 } | |
| 1626 } | |
| 1627 return rcRet; | |
| 1628 } | |
| 1629 int32_t CPDF_VariableText::GetCharWidth(int32_t nFontIndex, FX_WORD Word, FX_WOR
D SubWord, int32_t nWordStyle) | |
| 1630 { | |
| 1631 if (!m_pVTProvider) { | |
| 1632 return 0; | |
| 1633 } | |
| 1634 if (SubWord > 0) { | |
| 1635 return m_pVTProvider->GetCharWidth(nFontIndex, SubWord, nWordStyle); | |
| 1636 } | |
| 1637 return m_pVTProvider->GetCharWidth(nFontIndex, Word, nWordStyle); | |
| 1638 } | |
| 1639 int32_t CPDF_VariableText::GetTypeAscent(int32_t nFontIndex) | |
| 1640 { | |
| 1641 return m_pVTProvider ? m_pVTProvider->GetTypeAscent(nFontIndex) : 0; | |
| 1642 } | |
| 1643 int32_t CPDF_VariableText::GetTypeDescent(int32_t nFontIndex) | |
| 1644 { | |
| 1645 return m_pVTProvider ? m_pVTProvider->GetTypeDescent(nFontIndex) : 0; | |
| 1646 } | |
| 1647 int32_t CPDF_VariableText::GetWordFontIndex(FX_WORD word, int32_t charset, int32
_t nFontIndex) | |
| 1648 { | |
| 1649 return m_pVTProvider ? m_pVTProvider->GetWordFontIndex(word, charset, nFontI
ndex) : -1; | |
| 1650 } | |
| 1651 int32_t CPDF_VariableText::GetDefaultFontIndex() | |
| 1652 { | |
| 1653 return m_pVTProvider ? m_pVTProvider->GetDefaultFontIndex() : -1; | |
| 1654 } | |
| 1655 FX_BOOL CPDF_VariableText::IsLatinWord(FX_WORD word) | |
| 1656 { | |
| 1657 return m_pVTProvider ? m_pVTProvider->IsLatinWord(word) : FALSE; | |
| 1658 } | |
| 1659 IPDF_VariableText_Iterator * CPDF_VariableText::GetIterator() | |
| 1660 { | |
| 1661 if (!m_pVTIterator) { | |
| 1662 m_pVTIterator = new CPDF_VariableText_Iterator(this); | |
| 1663 } | |
| 1664 return m_pVTIterator; | |
| 1665 } | |
| 1666 IPDF_VariableText_Provider* CPDF_VariableText::SetProvider(IPDF_VariableText
_Provider * pProvider) | |
| 1667 { | |
| 1668 IPDF_VariableText_Provider* pOld = m_pVTProvider; | |
| 1669 m_pVTProvider = pProvider; | |
| 1670 return pOld; | |
| 1671 } | |
| 1672 CPDF_VariableText_Iterator::CPDF_VariableText_Iterator(CPDF_VariableText * pVT): | |
| 1673 m_CurPos(-1, -1, -1), | |
| 1674 m_pVT(pVT) | |
| 1675 { | |
| 1676 } | |
| 1677 CPDF_VariableText_Iterator::~CPDF_VariableText_Iterator() | |
| 1678 { | |
| 1679 } | |
| 1680 void CPDF_VariableText_Iterator::SetAt(int32_t nWordIndex) | |
| 1681 { | |
| 1682 ASSERT(m_pVT != NULL); | |
| 1683 m_CurPos = m_pVT->WordIndexToWordPlace(nWordIndex); | |
| 1684 } | |
| 1685 void CPDF_VariableText_Iterator::SetAt(const CPVT_WordPlace & place) | |
| 1686 { | |
| 1687 ASSERT(m_pVT != NULL); | |
| 1688 m_CurPos = place; | |
| 1689 } | |
| 1690 FX_BOOL CPDF_VariableText_Iterator::NextWord() | |
| 1691 { | |
| 1692 if (m_CurPos == m_pVT->GetEndWordPlace()) { | |
| 1693 return FALSE; | |
| 1694 } | |
| 1695 m_CurPos = m_pVT->GetNextWordPlace(m_CurPos); | |
| 1696 return TRUE; | 1813 return TRUE; |
| 1697 } | 1814 } |
| 1698 FX_BOOL»CPDF_VariableText_Iterator::PrevWord() | 1815 return FALSE; |
| 1699 { | 1816 } |
| 1700 if (m_CurPos == m_pVT->GetBeginWordPlace()) { | 1817 FX_BOOL CPDF_VariableText_Iterator::SetSection(const CPVT_Section& section) { |
| 1701 return FALSE; | 1818 ASSERT(m_pVT != NULL); |
| 1702 } | 1819 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { |
| 1703 m_CurPos = m_pVT->GetPrevWordPlace(m_CurPos); | 1820 if (pSection->m_SecInfo.pSecProps) { |
| 1821 *pSection->m_SecInfo.pSecProps = section.SecProps; |
| 1822 } |
| 1823 if (pSection->m_SecInfo.pWordProps) { |
| 1824 *pSection->m_SecInfo.pWordProps = section.WordProps; |
| 1825 } |
| 1704 return TRUE; | 1826 return TRUE; |
| 1705 } | 1827 } |
| 1706 FX_BOOL»CPDF_VariableText_Iterator::NextLine() | 1828 return FALSE; |
| 1707 { | 1829 } |
| 1708 if (CSection * pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1709 if (m_CurPos.nLineIndex < pSection->m_LineArray.GetSize() - 1) { | |
| 1710 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex +
1, -1); | |
| 1711 return TRUE; | |
| 1712 } | |
| 1713 if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) { | |
| 1714 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1); | |
| 1715 return TRUE; | |
| 1716 } | |
| 1717 } | |
| 1718 return FALSE; | |
| 1719 } | |
| 1720 FX_BOOL»CPDF_VariableText_Iterator::PrevLine() | |
| 1721 { | |
| 1722 if (m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1723 if (m_CurPos.nLineIndex > 0) { | |
| 1724 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex -
1, -1); | |
| 1725 return TRUE; | |
| 1726 } | |
| 1727 if (m_CurPos.nSecIndex > 0) { | |
| 1728 if (CSection * pLastSection = m_pVT->m_SectionArray.GetAt(m_CurPos.n
SecIndex - 1)) { | |
| 1729 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1, pLastSection->
m_LineArray.GetSize() - 1, -1); | |
| 1730 return TRUE; | |
| 1731 } | |
| 1732 } | |
| 1733 } | |
| 1734 return FALSE; | |
| 1735 } | |
| 1736 FX_BOOL»CPDF_VariableText_Iterator::NextSection() | |
| 1737 { | |
| 1738 if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) { | |
| 1739 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1); | |
| 1740 return TRUE; | |
| 1741 } | |
| 1742 return FALSE; | |
| 1743 } | |
| 1744 FX_BOOL»CPDF_VariableText_Iterator::PrevSection() | |
| 1745 { | |
| 1746 ASSERT(m_pVT != NULL); | |
| 1747 if (m_CurPos.nSecIndex > 0) { | |
| 1748 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1, 0, -1); | |
| 1749 return TRUE; | |
| 1750 } | |
| 1751 return FALSE; | |
| 1752 } | |
| 1753 FX_BOOL»CPDF_VariableText_Iterator::GetWord(CPVT_Word & word) const | |
| 1754 { | |
| 1755 ASSERT(m_pVT != NULL); | |
| 1756 word.WordPlace = m_CurPos; | |
| 1757 if (CSection * pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1758 if (pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { | |
| 1759 if (CPVT_WordInfo * pWord = pSection->m_WordArray.GetAt(m_CurPos.nWo
rdIndex)) { | |
| 1760 word.Word = pWord->Word; | |
| 1761 word.nCharset = pWord->nCharset; | |
| 1762 word.fWidth = m_pVT->GetWordWidth(*pWord); | |
| 1763 word.ptWord = m_pVT->InToOut( | |
| 1764 CPDF_Point(pWord->fWordX + pSection->m_SecInfo
.rcSection.left, | |
| 1765 pWord->fWordY + pSection->m_SecInfo
.rcSection.top) ); | |
| 1766 word.fAscent = m_pVT->GetWordAscent(*pWord); | |
| 1767 word.fDescent = m_pVT->GetWordDescent(*pWord); | |
| 1768 if (pWord->pWordProps) { | |
| 1769 word.WordProps = *pWord->pWordProps; | |
| 1770 } | |
| 1771 word.nFontIndex = m_pVT->GetWordFontIndex(*pWord); | |
| 1772 word.fFontSize = m_pVT->GetWordFontSize(*pWord); | |
| 1773 return TRUE; | |
| 1774 } | |
| 1775 } | |
| 1776 } | |
| 1777 return FALSE; | |
| 1778 } | |
| 1779 FX_BOOL»CPDF_VariableText_Iterator::SetWord(const CPVT_Word & word) | |
| 1780 { | |
| 1781 ASSERT(m_pVT != NULL); | |
| 1782 if (CSection * pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1783 if (CPVT_WordInfo * pWord = pSection->m_WordArray.GetAt(m_CurPos.nWordIn
dex)) { | |
| 1784 if (pWord->pWordProps) { | |
| 1785 *pWord->pWordProps = word.WordProps; | |
| 1786 } | |
| 1787 return TRUE; | |
| 1788 } | |
| 1789 } | |
| 1790 return FALSE; | |
| 1791 } | |
| 1792 FX_BOOL»CPDF_VariableText_Iterator::GetLine(CPVT_Line & line) const | |
| 1793 { | |
| 1794 ASSERT(m_pVT != NULL); | |
| 1795 line.lineplace = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex, -1)
; | |
| 1796 if (CSection * pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1797 if (CLine * pLine = pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { | |
| 1798 line.ptLine = m_pVT->InToOut( | |
| 1799 CPDF_Point(pLine->m_LineInfo.fLineX + pSection->m_
SecInfo.rcSection.left, | |
| 1800 pLine->m_LineInfo.fLineY + pSection->m_
SecInfo.rcSection.top) ); | |
| 1801 line.fLineWidth = pLine->m_LineInfo.fLineWidth; | |
| 1802 line.fLineAscent = pLine->m_LineInfo.fLineAscent; | |
| 1803 line.fLineDescent = pLine->m_LineInfo.fLineDescent; | |
| 1804 line.lineEnd = pLine->GetEndWordPlace(); | |
| 1805 return TRUE; | |
| 1806 } | |
| 1807 } | |
| 1808 return FALSE; | |
| 1809 } | |
| 1810 FX_BOOL»CPDF_VariableText_Iterator::GetSection(CPVT_Section & section) const | |
| 1811 { | |
| 1812 ASSERT(m_pVT != NULL); | |
| 1813 section.secplace = CPVT_WordPlace(m_CurPos.nSecIndex, 0, -1); | |
| 1814 if (CSection * pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1815 section.rcSection = m_pVT->InToOut(pSection->m_SecInfo.rcSection); | |
| 1816 if (pSection->m_SecInfo.pSecProps) { | |
| 1817 section.SecProps = *pSection->m_SecInfo.pSecProps; | |
| 1818 } | |
| 1819 if (pSection->m_SecInfo.pWordProps) { | |
| 1820 section.WordProps = *pSection->m_SecInfo.pWordProps; | |
| 1821 } | |
| 1822 return TRUE; | |
| 1823 } | |
| 1824 return FALSE; | |
| 1825 } | |
| 1826 FX_BOOL»CPDF_VariableText_Iterator::SetSection(const CPVT_Section & section) | |
| 1827 { | |
| 1828 ASSERT(m_pVT != NULL); | |
| 1829 if (CSection * pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1830 if (pSection->m_SecInfo.pSecProps) { | |
| 1831 *pSection->m_SecInfo.pSecProps = section.SecProps; | |
| 1832 } | |
| 1833 if (pSection->m_SecInfo.pWordProps) { | |
| 1834 *pSection->m_SecInfo.pWordProps = section.WordProps; | |
| 1835 } | |
| 1836 return TRUE; | |
| 1837 } | |
| 1838 return FALSE; | |
| 1839 } | |
| OLD | NEW |