| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "core/fpdfdoc/cpvt_wordinfo.h" |
| 10 #include "core/fpdfdoc/csection.h" |
| 11 #include "core/fpdfdoc/include/cpdf_variabletext.h" |
| 9 #include "core/fpdfdoc/pdf_vt.h" | 12 #include "core/fpdfdoc/pdf_vt.h" |
| 10 #include "core/include/fpdfdoc/fpdf_doc.h" | 13 #include "core/include/fpdfdoc/fpdf_doc.h" |
| 11 #include "core/include/fpdfdoc/fpdf_vt.h" | |
| 12 #include "core/include/fpdfdoc/fpdf_vt.h" | |
| 13 | 14 |
| 14 const uint8_t gFontSizeSteps[] = {4, 6, 8, 9, 10, 12, 14, 18, 20, | |
| 15 25, 30, 35, 40, 45, 50, 55, 60, 70, | |
| 16 80, 90, 100, 110, 120, 130, 144}; | |
| 17 #define PVT_RETURN_LENGTH 1 | |
| 18 #define PVT_DEFAULT_FONTSIZE 18.0f | |
| 19 #define PVTWORD_SCRIPT_NORMAL 0 | |
| 20 #define PVTWORD_SCRIPT_SUPER 1 | |
| 21 #define PVTWORD_SCRIPT_SUB 2 | |
| 22 #define PVT_FONTSCALE 0.001f | |
| 23 #define PVT_PERCENT 0.01f | |
| 24 #define PVT_HALF 0.5f | |
| 25 CLine::CLine() {} | 15 CLine::CLine() {} |
| 26 CLine::~CLine() {} | 16 CLine::~CLine() {} |
| 27 CPVT_WordPlace CLine::GetBeginWordPlace() const { | 17 CPVT_WordPlace CLine::GetBeginWordPlace() const { |
| 28 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, -1); | 18 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, -1); |
| 29 } | 19 } |
| 30 CPVT_WordPlace CLine::GetEndWordPlace() const { | 20 CPVT_WordPlace CLine::GetEndWordPlace() const { |
| 31 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, | 21 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, |
| 32 m_LineInfo.nEndWordIndex); | 22 m_LineInfo.nEndWordIndex); |
| 33 } | 23 } |
| 34 CPVT_WordPlace CLine::GetPrevWordPlace(const CPVT_WordPlace& place) const { | 24 CPVT_WordPlace CLine::GetPrevWordPlace(const CPVT_WordPlace& place) const { |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 int32_t nMid = (nLeft + nRight) / 2; | 227 int32_t nMid = (nLeft + nRight) / 2; |
| 238 while (nLeft < nRight) { | 228 while (nLeft < nRight) { |
| 239 if (nMid == nLeft) { | 229 if (nMid == nLeft) { |
| 240 break; | 230 break; |
| 241 } | 231 } |
| 242 if (nMid == nRight) { | 232 if (nMid == nRight) { |
| 243 nMid--; | 233 nMid--; |
| 244 break; | 234 break; |
| 245 } | 235 } |
| 246 if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) { | 236 if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) { |
| 247 if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * PVT_HALF) { | 237 if (fx > |
| 238 pWord->fWordX + m_pVT->GetWordWidth(*pWord) * VARIABLETEXT_HALF) { |
| 248 nLeft = nMid; | 239 nLeft = nMid; |
| 249 nMid = (nLeft + nRight) / 2; | 240 nMid = (nLeft + nRight) / 2; |
| 250 continue; | 241 continue; |
| 251 } else { | 242 } else { |
| 252 nRight = nMid; | 243 nRight = nMid; |
| 253 nMid = (nLeft + nRight) / 2; | 244 nMid = (nLeft + nRight) / 2; |
| 254 continue; | 245 continue; |
| 255 } | 246 } |
| 256 } else { | 247 } else { |
| 257 break; | 248 break; |
| 258 } | 249 } |
| 259 } | 250 } |
| 260 if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) { | 251 if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) { |
| 261 if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * PVT_HALF) { | 252 if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * VARIABLETEXT_HALF) { |
| 262 wordplace.nWordIndex = nMid; | 253 wordplace.nWordIndex = nMid; |
| 263 } | 254 } |
| 264 } | 255 } |
| 265 return wordplace; | 256 return wordplace; |
| 266 } | 257 } |
| 267 void CSection::ClearLeftWords(int32_t nWordIndex) { | 258 void CSection::ClearLeftWords(int32_t nWordIndex) { |
| 268 for (int32_t i = nWordIndex; i >= 0; i--) { | 259 for (int32_t i = nWordIndex; i >= 0; i--) { |
| 269 delete m_WordArray.GetAt(i); | 260 delete m_WordArray.GetAt(i); |
| 270 m_WordArray.RemoveAt(i); | 261 m_WordArray.RemoveAt(i); |
| 271 } | 262 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 int32_t nStart = 0; | 310 int32_t nStart = 0; |
| 320 FX_FLOAT fNodeWidth = m_pVT->GetPlateWidth() / | 311 FX_FLOAT fNodeWidth = m_pVT->GetPlateWidth() / |
| 321 (m_pVT->m_nCharArray <= 0 ? 1 : m_pVT->m_nCharArray); | 312 (m_pVT->m_nCharArray <= 0 ? 1 : m_pVT->m_nCharArray); |
| 322 if (CLine* pLine = m_pSection->m_LineArray.GetAt(0)) { | 313 if (CLine* pLine = m_pSection->m_LineArray.GetAt(0)) { |
| 323 x = 0.0f; | 314 x = 0.0f; |
| 324 y += m_pVT->GetLineLeading(m_pSection->m_SecInfo); | 315 y += m_pVT->GetLineLeading(m_pSection->m_SecInfo); |
| 325 y += fLineAscent; | 316 y += fLineAscent; |
| 326 nStart = 0; | 317 nStart = 0; |
| 327 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { | 318 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { |
| 328 case 0: | 319 case 0: |
| 329 pLine->m_LineInfo.fLineX = fNodeWidth * PVT_HALF; | 320 pLine->m_LineInfo.fLineX = fNodeWidth * VARIABLETEXT_HALF; |
| 330 break; | 321 break; |
| 331 case 1: | 322 case 1: |
| 332 nStart = (m_pVT->m_nCharArray - m_pSection->m_WordArray.GetSize()) / 2; | 323 nStart = (m_pVT->m_nCharArray - m_pSection->m_WordArray.GetSize()) / 2; |
| 333 pLine->m_LineInfo.fLineX = fNodeWidth * nStart - fNodeWidth * PVT_HALF; | 324 pLine->m_LineInfo.fLineX = |
| 325 fNodeWidth * nStart - fNodeWidth * VARIABLETEXT_HALF; |
| 334 break; | 326 break; |
| 335 case 2: | 327 case 2: |
| 336 nStart = m_pVT->m_nCharArray - m_pSection->m_WordArray.GetSize(); | 328 nStart = m_pVT->m_nCharArray - m_pSection->m_WordArray.GetSize(); |
| 337 pLine->m_LineInfo.fLineX = fNodeWidth * nStart - fNodeWidth * PVT_HALF; | 329 pLine->m_LineInfo.fLineX = |
| 330 fNodeWidth * nStart - fNodeWidth * VARIABLETEXT_HALF; |
| 338 break; | 331 break; |
| 339 } | 332 } |
| 340 for (int32_t w = 0, sz = m_pSection->m_WordArray.GetSize(); w < sz; w++) { | 333 for (int32_t w = 0, sz = m_pSection->m_WordArray.GetSize(); w < sz; w++) { |
| 341 if (w >= m_pVT->m_nCharArray) { | 334 if (w >= m_pVT->m_nCharArray) { |
| 342 break; | 335 break; |
| 343 } | 336 } |
| 344 fNextWidth = 0; | 337 fNextWidth = 0; |
| 345 if (CPVT_WordInfo* pNextWord = | 338 if (CPVT_WordInfo* pNextWord = |
| 346 (CPVT_WordInfo*)m_pSection->m_WordArray.GetAt(w + 1)) { | 339 (CPVT_WordInfo*)m_pSection->m_WordArray.GetAt(w + 1)) { |
| 347 pNextWord->fWordTail = 0; | 340 pNextWord->fWordTail = 0; |
| 348 fNextWidth = m_pVT->GetWordWidth(*pNextWord); | 341 fNextWidth = m_pVT->GetWordWidth(*pNextWord); |
| 349 } | 342 } |
| 350 if (CPVT_WordInfo* pWord = | 343 if (CPVT_WordInfo* pWord = |
| 351 (CPVT_WordInfo*)m_pSection->m_WordArray.GetAt(w)) { | 344 (CPVT_WordInfo*)m_pSection->m_WordArray.GetAt(w)) { |
| 352 pWord->fWordTail = 0; | 345 pWord->fWordTail = 0; |
| 353 FX_FLOAT fWordWidth = m_pVT->GetWordWidth(*pWord); | 346 FX_FLOAT fWordWidth = m_pVT->GetWordWidth(*pWord); |
| 354 FX_FLOAT fWordAscent = m_pVT->GetWordAscent(*pWord); | 347 FX_FLOAT fWordAscent = m_pVT->GetWordAscent(*pWord); |
| 355 FX_FLOAT fWordDescent = m_pVT->GetWordDescent(*pWord); | 348 FX_FLOAT fWordDescent = m_pVT->GetWordDescent(*pWord); |
| 356 x = (FX_FLOAT)(fNodeWidth * (w + nStart + 0.5) - fWordWidth * PVT_HALF); | 349 x = (FX_FLOAT)(fNodeWidth * (w + nStart + 0.5) - |
| 350 fWordWidth * VARIABLETEXT_HALF); |
| 357 pWord->fWordX = x; | 351 pWord->fWordX = x; |
| 358 pWord->fWordY = y; | 352 pWord->fWordY = y; |
| 359 if (w == 0) { | 353 if (w == 0) { |
| 360 pLine->m_LineInfo.fLineX = x; | 354 pLine->m_LineInfo.fLineX = x; |
| 361 } | 355 } |
| 362 if (w != m_pSection->m_WordArray.GetSize() - 1) { | 356 if (w != m_pSection->m_WordArray.GetSize() - 1) { |
| 363 pWord->fWordTail = | 357 pWord->fWordTail = |
| 364 (fNodeWidth - (fWordWidth + fNextWidth) * PVT_HALF > 0 | 358 (fNodeWidth - (fWordWidth + fNextWidth) * VARIABLETEXT_HALF > 0 |
| 365 ? fNodeWidth - (fWordWidth + fNextWidth) * PVT_HALF | 359 ? fNodeWidth - (fWordWidth + fNextWidth) * VARIABLETEXT_HALF |
| 366 : 0); | 360 : 0); |
| 367 } else { | 361 } else { |
| 368 pWord->fWordTail = 0; | 362 pWord->fWordTail = 0; |
| 369 } | 363 } |
| 370 x += fWordWidth; | 364 x += fWordWidth; |
| 371 fLineAscent = std::max(fLineAscent, fWordAscent); | 365 fLineAscent = std::max(fLineAscent, fWordAscent); |
| 372 fLineDescent = std::min(fLineDescent, fWordDescent); | 366 fLineDescent = std::min(fLineDescent, fWordDescent); |
| 373 } | 367 } |
| 374 } | 368 } |
| 375 pLine->m_LineInfo.nBeginWordIndex = 0; | 369 pLine->m_LineInfo.nBeginWordIndex = 0; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 FX_FLOAT fMinX = 0.0f, fMinY = 0.0f, fMaxX = 0.0f, fMaxY = 0.0f; | 699 FX_FLOAT fMinX = 0.0f, fMinY = 0.0f, fMaxX = 0.0f, fMaxY = 0.0f; |
| 706 FX_FLOAT fPosX = 0.0f, fPosY = 0.0f; | 700 FX_FLOAT fPosX = 0.0f, fPosY = 0.0f; |
| 707 FX_FLOAT fLineIndent = m_pVT->GetLineIndent(m_pSection->m_SecInfo); | 701 FX_FLOAT fLineIndent = m_pVT->GetLineIndent(m_pSection->m_SecInfo); |
| 708 FX_FLOAT fTypesetWidth = std::max(m_pVT->GetPlateWidth() - fLineIndent, 0.0f); | 702 FX_FLOAT fTypesetWidth = std::max(m_pVT->GetPlateWidth() - fLineIndent, 0.0f); |
| 709 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { | 703 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { |
| 710 default: | 704 default: |
| 711 case 0: | 705 case 0: |
| 712 fMinX = 0.0f; | 706 fMinX = 0.0f; |
| 713 break; | 707 break; |
| 714 case 1: | 708 case 1: |
| 715 fMinX = (fTypesetWidth - m_rcRet.Width()) * PVT_HALF; | 709 fMinX = (fTypesetWidth - m_rcRet.Width()) * VARIABLETEXT_HALF; |
| 716 break; | 710 break; |
| 717 case 2: | 711 case 2: |
| 718 fMinX = fTypesetWidth - m_rcRet.Width(); | 712 fMinX = fTypesetWidth - m_rcRet.Width(); |
| 719 break; | 713 break; |
| 720 } | 714 } |
| 721 fMaxX = fMinX + m_rcRet.Width(); | 715 fMaxX = fMinX + m_rcRet.Width(); |
| 722 fMinY = 0.0f; | 716 fMinY = 0.0f; |
| 723 fMaxY = m_rcRet.Height(); | 717 fMaxY = m_rcRet.Height(); |
| 724 int32_t nTotalLines = m_pSection->m_LineArray.GetSize(); | 718 int32_t nTotalLines = m_pSection->m_LineArray.GetSize(); |
| 725 if (nTotalLines > 0) { | 719 if (nTotalLines > 0) { |
| 726 m_pSection->m_SecInfo.nTotalLine = nTotalLines; | 720 m_pSection->m_SecInfo.nTotalLine = nTotalLines; |
| 727 for (int32_t l = 0; l < nTotalLines; l++) { | 721 for (int32_t l = 0; l < nTotalLines; l++) { |
| 728 if (CLine* pLine = m_pSection->m_LineArray.GetAt(l)) { | 722 if (CLine* pLine = m_pSection->m_LineArray.GetAt(l)) { |
| 729 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { | 723 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) { |
| 730 default: | 724 default: |
| 731 case 0: | 725 case 0: |
| 732 fPosX = 0; | 726 fPosX = 0; |
| 733 break; | 727 break; |
| 734 case 1: | 728 case 1: |
| 735 fPosX = (fTypesetWidth - pLine->m_LineInfo.fLineWidth) * PVT_HALF; | 729 fPosX = (fTypesetWidth - pLine->m_LineInfo.fLineWidth) * |
| 730 VARIABLETEXT_HALF; |
| 736 break; | 731 break; |
| 737 case 2: | 732 case 2: |
| 738 fPosX = fTypesetWidth - pLine->m_LineInfo.fLineWidth; | 733 fPosX = fTypesetWidth - pLine->m_LineInfo.fLineWidth; |
| 739 break; | 734 break; |
| 740 } | 735 } |
| 741 fPosX += fLineIndent; | 736 fPosX += fLineIndent; |
| 742 fPosY += m_pVT->GetLineLeading(m_pSection->m_SecInfo); | 737 fPosY += m_pVT->GetLineLeading(m_pSection->m_SecInfo); |
| 743 fPosY += pLine->m_LineInfo.fLineAscent; | 738 fPosY += pLine->m_LineInfo.fLineAscent; |
| 744 pLine->m_LineInfo.fLineX = fPosX - fMinX; | 739 pLine->m_LineInfo.fLineX = fPosX - fMinX; |
| 745 pLine->m_LineInfo.fLineY = fPosY - fMinY; | 740 pLine->m_LineInfo.fLineY = fPosY - fMinY; |
| 746 for (int32_t w = pLine->m_LineInfo.nBeginWordIndex; | 741 for (int32_t w = pLine->m_LineInfo.nBeginWordIndex; |
| 747 w <= pLine->m_LineInfo.nEndWordIndex; w++) { | 742 w <= pLine->m_LineInfo.nEndWordIndex; w++) { |
| 748 if (CPVT_WordInfo* pWord = m_pSection->m_WordArray.GetAt(w)) { | 743 if (CPVT_WordInfo* pWord = m_pSection->m_WordArray.GetAt(w)) { |
| 749 pWord->fWordX = fPosX - fMinX; | 744 pWord->fWordX = fPosX - fMinX; |
| 750 if (pWord->pWordProps) { | 745 if (pWord->pWordProps) { |
| 751 switch (pWord->pWordProps->nScriptType) { | 746 switch (pWord->pWordProps->nScriptType) { |
| 752 default: | 747 default: |
| 753 case PVTWORD_SCRIPT_NORMAL: | 748 case CPDF_VariableText::ScriptType::Normal: |
| 754 pWord->fWordY = fPosY - fMinY; | 749 pWord->fWordY = fPosY - fMinY; |
| 755 break; | 750 break; |
| 756 case PVTWORD_SCRIPT_SUPER: | 751 case CPDF_VariableText::ScriptType::Super: |
| 757 pWord->fWordY = fPosY - m_pVT->GetWordAscent(*pWord) - fMinY; | 752 pWord->fWordY = fPosY - m_pVT->GetWordAscent(*pWord) - fMinY; |
| 758 break; | 753 break; |
| 759 case PVTWORD_SCRIPT_SUB: | 754 case CPDF_VariableText::ScriptType::Sub: |
| 760 pWord->fWordY = fPosY - m_pVT->GetWordDescent(*pWord) - fMinY; | 755 pWord->fWordY = fPosY - m_pVT->GetWordDescent(*pWord) - fMinY; |
| 761 break; | 756 break; |
| 762 } | 757 } |
| 763 } else { | 758 } else { |
| 764 pWord->fWordY = fPosY - fMinY; | 759 pWord->fWordY = fPosY - fMinY; |
| 765 } | 760 } |
| 766 fPosX += m_pVT->GetWordWidth(*pWord); | 761 fPosX += m_pVT->GetWordWidth(*pWord); |
| 767 } | 762 } |
| 768 } | 763 } |
| 769 fPosY += (-pLine->m_LineInfo.fLineDescent); | 764 fPosY += (-pLine->m_LineInfo.fLineDescent); |
| 770 } | 765 } |
| 771 } | 766 } |
| 772 } | 767 } |
| 773 m_rcRet = CPVT_FloatRect(fMinX, fMinY, fMaxX, fMaxY); | 768 m_rcRet = CPVT_FloatRect(fMinX, fMinY, fMaxX, fMaxY); |
| 774 } | 769 } |
| 775 CPDF_VariableText::CPDF_VariableText() | |
| 776 : m_nLimitChar(0), | |
| 777 m_nCharArray(0), | |
| 778 m_bMultiLine(FALSE), | |
| 779 m_bLimitWidth(FALSE), | |
| 780 m_bAutoFontSize(FALSE), | |
| 781 m_nAlignment(0), | |
| 782 m_fLineLeading(0.0f), | |
| 783 m_fCharSpace(0.0f), | |
| 784 m_nHorzScale(100), | |
| 785 m_wSubWord(0), | |
| 786 m_fFontSize(0.0f), | |
| 787 m_bInitial(FALSE), | |
| 788 m_bRichText(FALSE), | |
| 789 m_pVTProvider(NULL), | |
| 790 m_pVTIterator(NULL) {} | |
| 791 CPDF_VariableText::~CPDF_VariableText() { | |
| 792 delete m_pVTIterator; | |
| 793 m_pVTIterator = NULL; | |
| 794 ResetAll(); | |
| 795 } | |
| 796 void CPDF_VariableText::Initialize() { | |
| 797 if (!m_bInitial) { | |
| 798 CPVT_SectionInfo secinfo; | |
| 799 if (m_bRichText) { | |
| 800 secinfo.pSecProps = new CPVT_SecProps(0.0f, 0.0f, 0); | |
| 801 secinfo.pWordProps = new CPVT_WordProps(GetDefaultFontIndex(), | |
| 802 PVT_DEFAULT_FONTSIZE, 0, 0, 0); | |
| 803 } | |
| 804 CPVT_WordPlace place; | |
| 805 place.nSecIndex = 0; | |
| 806 AddSection(place, secinfo); | |
| 807 CPVT_LineInfo lineinfo; | |
| 808 lineinfo.fLineAscent = GetFontAscent(GetDefaultFontIndex(), GetFontSize()); | |
| 809 lineinfo.fLineDescent = | |
| 810 GetFontDescent(GetDefaultFontIndex(), GetFontSize()); | |
| 811 AddLine(place, lineinfo); | |
| 812 if (CSection* pSection = m_SectionArray.GetAt(0)) { | |
| 813 pSection->ResetLinePlace(); | |
| 814 } | |
| 815 m_bInitial = TRUE; | |
| 816 } | |
| 817 } | |
| 818 void CPDF_VariableText::ResetAll() { | |
| 819 m_bInitial = FALSE; | |
| 820 ResetSectionArray(); | |
| 821 } | |
| 822 CPVT_WordPlace CPDF_VariableText::InsertWord(const CPVT_WordPlace& place, | |
| 823 uint16_t word, | |
| 824 int32_t charset, | |
| 825 const CPVT_WordProps* pWordProps) { | |
| 826 int32_t nTotlaWords = GetTotalWords(); | |
| 827 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) { | |
| 828 return place; | |
| 829 } | |
| 830 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) { | |
| 831 return place; | |
| 832 } | |
| 833 CPVT_WordPlace newplace = place; | |
| 834 newplace.nWordIndex++; | |
| 835 if (m_bRichText) { | |
| 836 CPVT_WordProps* pNewProps = | |
| 837 pWordProps ? new CPVT_WordProps(*pWordProps) : new CPVT_WordProps(); | |
| 838 pNewProps->nFontIndex = | |
| 839 GetWordFontIndex(word, charset, pWordProps->nFontIndex); | |
| 840 return AddWord(newplace, CPVT_WordInfo(word, charset, -1, pNewProps)); | |
| 841 } | |
| 842 int32_t nFontIndex = | |
| 843 GetSubWord() > 0 ? GetDefaultFontIndex() | |
| 844 : GetWordFontIndex(word, charset, GetDefaultFontIndex()); | |
| 845 return AddWord(newplace, CPVT_WordInfo(word, charset, nFontIndex, NULL)); | |
| 846 } | |
| 847 CPVT_WordPlace CPDF_VariableText::InsertSection( | |
| 848 const CPVT_WordPlace& place, | |
| 849 const CPVT_SecProps* pSecProps, | |
| 850 const CPVT_WordProps* pWordProps) { | |
| 851 int32_t nTotlaWords = GetTotalWords(); | |
| 852 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) { | |
| 853 return place; | |
| 854 } | |
| 855 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) { | |
| 856 return place; | |
| 857 } | |
| 858 if (!m_bMultiLine) { | |
| 859 return place; | |
| 860 } | |
| 861 CPVT_WordPlace wordplace = place; | |
| 862 UpdateWordPlace(wordplace); | |
| 863 CPVT_WordPlace newplace = place; | |
| 864 if (CSection* pSection = m_SectionArray.GetAt(wordplace.nSecIndex)) { | |
| 865 CPVT_WordPlace NewPlace(wordplace.nSecIndex + 1, 0, -1); | |
| 866 CPVT_SectionInfo secinfo; | |
| 867 if (m_bRichText) { | |
| 868 if (pSecProps) { | |
| 869 secinfo.pSecProps = new CPVT_SecProps(*pSecProps); | |
| 870 } | |
| 871 if (pWordProps) { | |
| 872 secinfo.pWordProps = new CPVT_WordProps(*pWordProps); | |
| 873 } | |
| 874 } | |
| 875 AddSection(NewPlace, secinfo); | |
| 876 newplace = NewPlace; | |
| 877 if (CSection* pNewSection = m_SectionArray.GetAt(NewPlace.nSecIndex)) { | |
| 878 for (int32_t w = wordplace.nWordIndex + 1, | |
| 879 sz = pSection->m_WordArray.GetSize(); | |
| 880 w < sz; w++) { | |
| 881 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(w)) { | |
| 882 NewPlace.nWordIndex++; | |
| 883 pNewSection->AddWord(NewPlace, *pWord); | |
| 884 } | |
| 885 } | |
| 886 } | |
| 887 ClearSectionRightWords(wordplace); | |
| 888 } | |
| 889 return newplace; | |
| 890 } | |
| 891 CPVT_WordPlace CPDF_VariableText::InsertText(const CPVT_WordPlace& place, | |
| 892 const FX_WCHAR* text, | |
| 893 int32_t charset, | |
| 894 const CPVT_SecProps* pSecProps, | |
| 895 const CPVT_WordProps* pProps) { | |
| 896 CFX_WideString swText = text; | |
| 897 CPVT_WordPlace wp = place; | |
| 898 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { | |
| 899 CPVT_WordPlace oldwp = wp; | |
| 900 uint16_t word = swText.GetAt(i); | |
| 901 switch (word) { | |
| 902 case 0x0D: | |
| 903 if (m_bMultiLine) { | |
| 904 if (swText.GetAt(i + 1) == 0x0A) { | |
| 905 i += 1; | |
| 906 } | |
| 907 wp = InsertSection(wp, pSecProps, pProps); | |
| 908 } | |
| 909 break; | |
| 910 case 0x0A: | |
| 911 if (m_bMultiLine) { | |
| 912 if (swText.GetAt(i + 1) == 0x0D) { | |
| 913 i += 1; | |
| 914 } | |
| 915 wp = InsertSection(wp, pSecProps, pProps); | |
| 916 } | |
| 917 break; | |
| 918 case 0x09: | |
| 919 word = 0x20; | |
| 920 default: | |
| 921 wp = InsertWord(wp, word, charset, pProps); | |
| 922 break; | |
| 923 } | |
| 924 if (wp == oldwp) { | |
| 925 break; | |
| 926 } | |
| 927 } | |
| 928 return wp; | |
| 929 } | |
| 930 CPVT_WordPlace CPDF_VariableText::DeleteWords( | |
| 931 const CPVT_WordRange& PlaceRange) { | |
| 932 FX_BOOL bLastSecPos = FALSE; | |
| 933 if (CSection* pSection = m_SectionArray.GetAt(PlaceRange.EndPos.nSecIndex)) { | |
| 934 bLastSecPos = (PlaceRange.EndPos == pSection->GetEndWordPlace()); | |
| 935 } | |
| 936 ClearWords(PlaceRange); | |
| 937 if (PlaceRange.BeginPos.nSecIndex != PlaceRange.EndPos.nSecIndex) { | |
| 938 ClearEmptySections(PlaceRange); | |
| 939 if (!bLastSecPos) { | |
| 940 LinkLatterSection(PlaceRange.BeginPos); | |
| 941 } | |
| 942 } | |
| 943 return PlaceRange.BeginPos; | |
| 944 } | |
| 945 CPVT_WordPlace CPDF_VariableText::DeleteWord(const CPVT_WordPlace& place) { | |
| 946 return ClearRightWord(AdjustLineHeader(place, TRUE)); | |
| 947 } | |
| 948 CPVT_WordPlace CPDF_VariableText::BackSpaceWord(const CPVT_WordPlace& place) { | |
| 949 return ClearLeftWord(AdjustLineHeader(place, TRUE)); | |
| 950 } | |
| 951 void CPDF_VariableText::SetText(const FX_WCHAR* text, | |
| 952 int32_t charset, | |
| 953 const CPVT_SecProps* pSecProps, | |
| 954 const CPVT_WordProps* pWordProps) { | |
| 955 DeleteWords(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); | |
| 956 CFX_WideString swText = text; | |
| 957 CPVT_WordPlace wp(0, 0, -1); | |
| 958 CPVT_SectionInfo secinfo; | |
| 959 if (m_bRichText) { | |
| 960 if (pSecProps) { | |
| 961 secinfo.pSecProps = new CPVT_SecProps(*pSecProps); | |
| 962 } | |
| 963 if (pWordProps) { | |
| 964 secinfo.pWordProps = new CPVT_WordProps(*pWordProps); | |
| 965 } | |
| 966 } | |
| 967 if (CSection* pSection = m_SectionArray.GetAt(0)) { | |
| 968 pSection->m_SecInfo = secinfo; | |
| 969 } | |
| 970 int32_t nCharCount = 0; | |
| 971 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { | |
| 972 if (m_nLimitChar > 0 && nCharCount >= m_nLimitChar) { | |
| 973 break; | |
| 974 } | |
| 975 if (m_nCharArray > 0 && nCharCount >= m_nCharArray) { | |
| 976 break; | |
| 977 } | |
| 978 uint16_t word = swText.GetAt(i); | |
| 979 switch (word) { | |
| 980 case 0x0D: | |
| 981 if (m_bMultiLine) { | |
| 982 if (swText.GetAt(i + 1) == 0x0A) { | |
| 983 i += 1; | |
| 984 } | |
| 985 wp.nSecIndex++; | |
| 986 wp.nLineIndex = 0; | |
| 987 wp.nWordIndex = -1; | |
| 988 AddSection(wp, secinfo); | |
| 989 } | |
| 990 break; | |
| 991 case 0x0A: | |
| 992 if (m_bMultiLine) { | |
| 993 if (swText.GetAt(i + 1) == 0x0D) { | |
| 994 i += 1; | |
| 995 } | |
| 996 wp.nSecIndex++; | |
| 997 wp.nLineIndex = 0; | |
| 998 wp.nWordIndex = -1; | |
| 999 AddSection(wp, secinfo); | |
| 1000 } | |
| 1001 break; | |
| 1002 case 0x09: | |
| 1003 word = 0x20; | |
| 1004 default: | |
| 1005 wp = InsertWord(wp, word, charset, pWordProps); | |
| 1006 break; | |
| 1007 } | |
| 1008 nCharCount++; | |
| 1009 } | |
| 1010 } | |
| 1011 void CPDF_VariableText::UpdateWordPlace(CPVT_WordPlace& place) const { | |
| 1012 if (place.nSecIndex < 0) { | |
| 1013 place = GetBeginWordPlace(); | |
| 1014 } | |
| 1015 if (place.nSecIndex >= m_SectionArray.GetSize()) { | |
| 1016 place = GetEndWordPlace(); | |
| 1017 } | |
| 1018 place = AdjustLineHeader(place, TRUE); | |
| 1019 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1020 pSection->UpdateWordPlace(place); | |
| 1021 } | |
| 1022 } | |
| 1023 int32_t CPDF_VariableText::WordPlaceToWordIndex( | |
| 1024 const CPVT_WordPlace& place) const { | |
| 1025 CPVT_WordPlace newplace = place; | |
| 1026 UpdateWordPlace(newplace); | |
| 1027 int32_t nIndex = 0; | |
| 1028 int32_t i = 0; | |
| 1029 int32_t sz = 0; | |
| 1030 for (i = 0, sz = m_SectionArray.GetSize(); i < sz && i < newplace.nSecIndex; | |
| 1031 i++) { | |
| 1032 if (CSection* pSection = m_SectionArray.GetAt(i)) { | |
| 1033 nIndex += pSection->m_WordArray.GetSize(); | |
| 1034 if (i != m_SectionArray.GetSize() - 1) { | |
| 1035 nIndex += PVT_RETURN_LENGTH; | |
| 1036 } | |
| 1037 } | |
| 1038 } | |
| 1039 if (i >= 0 && i < m_SectionArray.GetSize()) { | |
| 1040 nIndex += newplace.nWordIndex + PVT_RETURN_LENGTH; | |
| 1041 } | |
| 1042 return nIndex; | |
| 1043 } | |
| 1044 CPVT_WordPlace CPDF_VariableText::WordIndexToWordPlace(int32_t index) const { | |
| 1045 CPVT_WordPlace place = GetBeginWordPlace(); | |
| 1046 int32_t nOldIndex = 0, nIndex = 0; | |
| 1047 FX_BOOL bFind = FALSE; | |
| 1048 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) { | |
| 1049 if (CSection* pSection = m_SectionArray.GetAt(i)) { | |
| 1050 nIndex += pSection->m_WordArray.GetSize(); | |
| 1051 if (nIndex == index) { | |
| 1052 place = pSection->GetEndWordPlace(); | |
| 1053 bFind = TRUE; | |
| 1054 break; | |
| 1055 } else if (nIndex > index) { | |
| 1056 place.nSecIndex = i; | |
| 1057 place.nWordIndex = index - nOldIndex - 1; | |
| 1058 pSection->UpdateWordPlace(place); | |
| 1059 bFind = TRUE; | |
| 1060 break; | |
| 1061 } | |
| 1062 if (i != m_SectionArray.GetSize() - 1) { | |
| 1063 nIndex += PVT_RETURN_LENGTH; | |
| 1064 } | |
| 1065 nOldIndex = nIndex; | |
| 1066 } | |
| 1067 } | |
| 1068 if (!bFind) { | |
| 1069 place = GetEndWordPlace(); | |
| 1070 } | |
| 1071 return place; | |
| 1072 } | |
| 1073 CPVT_WordPlace CPDF_VariableText::GetBeginWordPlace() const { | |
| 1074 return m_bInitial ? CPVT_WordPlace(0, 0, -1) : CPVT_WordPlace(); | |
| 1075 } | |
| 1076 CPVT_WordPlace CPDF_VariableText::GetEndWordPlace() const { | |
| 1077 if (CSection* pSection = m_SectionArray.GetAt(m_SectionArray.GetSize() - 1)) { | |
| 1078 return pSection->GetEndWordPlace(); | |
| 1079 } | |
| 1080 return CPVT_WordPlace(); | |
| 1081 } | |
| 1082 CPVT_WordPlace CPDF_VariableText::GetPrevWordPlace( | |
| 1083 const CPVT_WordPlace& place) const { | |
| 1084 if (place.nSecIndex < 0) { | |
| 1085 return GetBeginWordPlace(); | |
| 1086 } | |
| 1087 if (place.nSecIndex >= m_SectionArray.GetSize()) { | |
| 1088 return GetEndWordPlace(); | |
| 1089 } | |
| 1090 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1091 if (place.WordCmp(pSection->GetBeginWordPlace()) <= 0) { | |
| 1092 if (CSection* pPrevSection = m_SectionArray.GetAt(place.nSecIndex - 1)) { | |
| 1093 return pPrevSection->GetEndWordPlace(); | |
| 1094 } | |
| 1095 return GetBeginWordPlace(); | |
| 1096 } | |
| 1097 return pSection->GetPrevWordPlace(place); | |
| 1098 } | |
| 1099 return place; | |
| 1100 } | |
| 1101 CPVT_WordPlace CPDF_VariableText::GetNextWordPlace( | |
| 1102 const CPVT_WordPlace& place) const { | |
| 1103 if (place.nSecIndex < 0) { | |
| 1104 return GetBeginWordPlace(); | |
| 1105 } | |
| 1106 if (place.nSecIndex >= m_SectionArray.GetSize()) { | |
| 1107 return GetEndWordPlace(); | |
| 1108 } | |
| 1109 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1110 if (place.WordCmp(pSection->GetEndWordPlace()) >= 0) { | |
| 1111 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) { | |
| 1112 return pNextSection->GetBeginWordPlace(); | |
| 1113 } | |
| 1114 return GetEndWordPlace(); | |
| 1115 } | |
| 1116 return pSection->GetNextWordPlace(place); | |
| 1117 } | |
| 1118 return place; | |
| 1119 } | |
| 1120 CPVT_WordPlace CPDF_VariableText::SearchWordPlace( | |
| 1121 const CFX_FloatPoint& point) const { | |
| 1122 CFX_FloatPoint pt = OutToIn(point); | |
| 1123 CPVT_WordPlace place = GetBeginWordPlace(); | |
| 1124 int32_t nLeft = 0; | |
| 1125 int32_t nRight = m_SectionArray.GetSize() - 1; | |
| 1126 int32_t nMid = m_SectionArray.GetSize() / 2; | |
| 1127 FX_BOOL bUp = TRUE; | |
| 1128 FX_BOOL bDown = TRUE; | |
| 1129 while (nLeft <= nRight) { | |
| 1130 if (CSection* pSection = m_SectionArray.GetAt(nMid)) { | |
| 1131 if (IsFloatBigger(pt.y, pSection->m_SecInfo.rcSection.top)) { | |
| 1132 bUp = FALSE; | |
| 1133 } | |
| 1134 if (IsFloatBigger(pSection->m_SecInfo.rcSection.bottom, pt.y)) { | |
| 1135 bDown = FALSE; | |
| 1136 } | |
| 1137 if (IsFloatSmaller(pt.y, pSection->m_SecInfo.rcSection.top)) { | |
| 1138 nRight = nMid - 1; | |
| 1139 nMid = (nLeft + nRight) / 2; | |
| 1140 continue; | |
| 1141 } else if (IsFloatBigger(pt.y, pSection->m_SecInfo.rcSection.bottom)) { | |
| 1142 nLeft = nMid + 1; | |
| 1143 nMid = (nLeft + nRight) / 2; | |
| 1144 continue; | |
| 1145 } else { | |
| 1146 place = pSection->SearchWordPlace( | |
| 1147 CFX_FloatPoint(pt.x - pSection->m_SecInfo.rcSection.left, | |
| 1148 pt.y - pSection->m_SecInfo.rcSection.top)); | |
| 1149 place.nSecIndex = nMid; | |
| 1150 return place; | |
| 1151 } | |
| 1152 } else { | |
| 1153 break; | |
| 1154 } | |
| 1155 } | |
| 1156 if (bUp) { | |
| 1157 place = GetBeginWordPlace(); | |
| 1158 } | |
| 1159 if (bDown) { | |
| 1160 place = GetEndWordPlace(); | |
| 1161 } | |
| 1162 return place; | |
| 1163 } | |
| 1164 CPVT_WordPlace CPDF_VariableText::GetUpWordPlace( | |
| 1165 const CPVT_WordPlace& place, | |
| 1166 const CFX_FloatPoint& point) const { | |
| 1167 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1168 CPVT_WordPlace temp = place; | |
| 1169 CFX_FloatPoint pt = OutToIn(point); | |
| 1170 if (temp.nLineIndex-- > 0) { | |
| 1171 return pSection->SearchWordPlace( | |
| 1172 pt.x - pSection->m_SecInfo.rcSection.left, temp); | |
| 1173 } | |
| 1174 if (temp.nSecIndex-- > 0) { | |
| 1175 if (CSection* pLastSection = m_SectionArray.GetAt(temp.nSecIndex)) { | |
| 1176 temp.nLineIndex = pLastSection->m_LineArray.GetSize() - 1; | |
| 1177 return pLastSection->SearchWordPlace( | |
| 1178 pt.x - pLastSection->m_SecInfo.rcSection.left, temp); | |
| 1179 } | |
| 1180 } | |
| 1181 } | |
| 1182 return place; | |
| 1183 } | |
| 1184 CPVT_WordPlace CPDF_VariableText::GetDownWordPlace( | |
| 1185 const CPVT_WordPlace& place, | |
| 1186 const CFX_FloatPoint& point) const { | |
| 1187 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1188 CPVT_WordPlace temp = place; | |
| 1189 CFX_FloatPoint pt = OutToIn(point); | |
| 1190 if (temp.nLineIndex++ < pSection->m_LineArray.GetSize() - 1) { | |
| 1191 return pSection->SearchWordPlace( | |
| 1192 pt.x - pSection->m_SecInfo.rcSection.left, temp); | |
| 1193 } | |
| 1194 if (temp.nSecIndex++ < m_SectionArray.GetSize() - 1) { | |
| 1195 if (CSection* pNextSection = m_SectionArray.GetAt(temp.nSecIndex)) { | |
| 1196 temp.nLineIndex = 0; | |
| 1197 return pNextSection->SearchWordPlace( | |
| 1198 pt.x - pSection->m_SecInfo.rcSection.left, temp); | |
| 1199 } | |
| 1200 } | |
| 1201 } | |
| 1202 return place; | |
| 1203 } | |
| 1204 CPVT_WordPlace CPDF_VariableText::GetLineBeginPlace( | |
| 1205 const CPVT_WordPlace& place) const { | |
| 1206 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, -1); | |
| 1207 } | |
| 1208 CPVT_WordPlace CPDF_VariableText::GetLineEndPlace( | |
| 1209 const CPVT_WordPlace& place) const { | |
| 1210 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1211 if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex)) | |
| 1212 return pLine->GetEndWordPlace(); | |
| 1213 } | |
| 1214 return place; | |
| 1215 } | |
| 1216 CPVT_WordPlace CPDF_VariableText::GetSectionBeginPlace( | |
| 1217 const CPVT_WordPlace& place) const { | |
| 1218 return CPVT_WordPlace(place.nSecIndex, 0, -1); | |
| 1219 } | |
| 1220 CPVT_WordPlace CPDF_VariableText::GetSectionEndPlace( | |
| 1221 const CPVT_WordPlace& place) const { | |
| 1222 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1223 return pSection->GetEndWordPlace(); | |
| 1224 } | |
| 1225 return place; | |
| 1226 } | |
| 1227 int32_t CPDF_VariableText::GetTotalWords() const { | |
| 1228 int32_t nTotal = 0; | |
| 1229 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) | |
| 1230 if (CSection* pSection = m_SectionArray.GetAt(i)) { | |
| 1231 nTotal += (pSection->m_WordArray.GetSize() + PVT_RETURN_LENGTH); | |
| 1232 } | |
| 1233 return nTotal - PVT_RETURN_LENGTH; | |
| 1234 } | |
| 1235 void CPDF_VariableText::ResetSectionArray() { | |
| 1236 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { | |
| 1237 delete m_SectionArray.GetAt(s); | |
| 1238 } | |
| 1239 m_SectionArray.RemoveAll(); | |
| 1240 } | |
| 1241 CPVT_WordPlace CPDF_VariableText::AddSection(const CPVT_WordPlace& place, | |
| 1242 const CPVT_SectionInfo& secinfo) { | |
| 1243 if (IsValid() && !m_bMultiLine) { | |
| 1244 return place; | |
| 1245 } | |
| 1246 int32_t nSecIndex = | |
| 1247 std::max(std::min(place.nSecIndex, m_SectionArray.GetSize()), 0); | |
| 1248 CSection* pSection = new CSection(this); | |
| 1249 pSection->m_SecInfo = secinfo; | |
| 1250 pSection->SecPlace.nSecIndex = nSecIndex; | |
| 1251 if (nSecIndex == m_SectionArray.GetSize()) { | |
| 1252 m_SectionArray.Add(pSection); | |
| 1253 } else { | |
| 1254 m_SectionArray.InsertAt(nSecIndex, pSection); | |
| 1255 } | |
| 1256 return place; | |
| 1257 } | |
| 1258 CPVT_WordPlace CPDF_VariableText::AddLine(const CPVT_WordPlace& place, | |
| 1259 const CPVT_LineInfo& lineinfo) { | |
| 1260 if (m_SectionArray.IsEmpty()) { | |
| 1261 return place; | |
| 1262 } | |
| 1263 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1264 return pSection->AddLine(lineinfo); | |
| 1265 } | |
| 1266 return place; | |
| 1267 } | |
| 1268 CPVT_WordPlace CPDF_VariableText::AddWord(const CPVT_WordPlace& place, | |
| 1269 const CPVT_WordInfo& wordinfo) { | |
| 1270 if (m_SectionArray.GetSize() <= 0) { | |
| 1271 return place; | |
| 1272 } | |
| 1273 CPVT_WordPlace newplace = place; | |
| 1274 newplace.nSecIndex = | |
| 1275 std::max(std::min(newplace.nSecIndex, m_SectionArray.GetSize() - 1), 0); | |
| 1276 if (CSection* pSection = m_SectionArray.GetAt(newplace.nSecIndex)) { | |
| 1277 return pSection->AddWord(newplace, wordinfo); | |
| 1278 } | |
| 1279 return place; | |
| 1280 } | |
| 1281 FX_BOOL CPDF_VariableText::GetWordInfo(const CPVT_WordPlace& place, | |
| 1282 CPVT_WordInfo& wordinfo) { | |
| 1283 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1284 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(place.nWordIndex)) { | |
| 1285 wordinfo = *pWord; | |
| 1286 return TRUE; | |
| 1287 } | |
| 1288 } | |
| 1289 return FALSE; | |
| 1290 } | |
| 1291 FX_BOOL CPDF_VariableText::SetWordInfo(const CPVT_WordPlace& place, | |
| 1292 const CPVT_WordInfo& wordinfo) { | |
| 1293 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1294 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(place.nWordIndex)) { | |
| 1295 *pWord = wordinfo; | |
| 1296 return TRUE; | |
| 1297 } | |
| 1298 } | |
| 1299 return FALSE; | |
| 1300 } | |
| 1301 FX_BOOL CPDF_VariableText::GetLineInfo(const CPVT_WordPlace& place, | |
| 1302 CPVT_LineInfo& lineinfo) { | |
| 1303 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1304 if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex)) { | |
| 1305 lineinfo = pLine->m_LineInfo; | |
| 1306 return TRUE; | |
| 1307 } | |
| 1308 } | |
| 1309 return FALSE; | |
| 1310 } | |
| 1311 FX_BOOL CPDF_VariableText::GetSectionInfo(const CPVT_WordPlace& place, | |
| 1312 CPVT_SectionInfo& secinfo) { | |
| 1313 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1314 secinfo = pSection->m_SecInfo; | |
| 1315 return TRUE; | |
| 1316 } | |
| 1317 return FALSE; | |
| 1318 } | |
| 1319 CFX_FloatRect CPDF_VariableText::GetContentRect() const { | |
| 1320 return InToOut(CPVT_FloatRect(CPDF_EditContainer::GetContentRect())); | |
| 1321 } | |
| 1322 FX_FLOAT CPDF_VariableText::GetWordFontSize(const CPVT_WordInfo& WordInfo, | |
| 1323 FX_BOOL bFactFontSize) { | |
| 1324 return m_bRichText && WordInfo.pWordProps | |
| 1325 ? (WordInfo.pWordProps->nScriptType == PVTWORD_SCRIPT_NORMAL || | |
| 1326 bFactFontSize | |
| 1327 ? WordInfo.pWordProps->fFontSize | |
| 1328 : WordInfo.pWordProps->fFontSize * PVT_HALF) | |
| 1329 : GetFontSize(); | |
| 1330 } | |
| 1331 int32_t CPDF_VariableText::GetWordFontIndex(const CPVT_WordInfo& WordInfo) { | |
| 1332 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nFontIndex | |
| 1333 : WordInfo.nFontIndex; | |
| 1334 } | |
| 1335 FX_FLOAT CPDF_VariableText::GetWordWidth(int32_t nFontIndex, | |
| 1336 uint16_t Word, | |
| 1337 uint16_t SubWord, | |
| 1338 FX_FLOAT fCharSpace, | |
| 1339 int32_t nHorzScale, | |
| 1340 FX_FLOAT fFontSize, | |
| 1341 FX_FLOAT fWordTail, | |
| 1342 int32_t nWordStyle) { | |
| 1343 return (GetCharWidth(nFontIndex, Word, SubWord, nWordStyle) * fFontSize * | |
| 1344 PVT_FONTSCALE + | |
| 1345 fCharSpace) * | |
| 1346 nHorzScale * PVT_PERCENT + | |
| 1347 fWordTail; | |
| 1348 } | |
| 1349 FX_FLOAT CPDF_VariableText::GetWordWidth(const CPVT_WordInfo& WordInfo) { | |
| 1350 return GetWordWidth( | |
| 1351 GetWordFontIndex(WordInfo), WordInfo.Word, GetSubWord(), | |
| 1352 GetCharSpace(WordInfo), GetHorzScale(WordInfo), GetWordFontSize(WordInfo), | |
| 1353 WordInfo.fWordTail, | |
| 1354 WordInfo.pWordProps ? WordInfo.pWordProps->nWordStyle : 0); | |
| 1355 } | |
| 1356 FX_FLOAT CPDF_VariableText::GetLineAscent(const CPVT_SectionInfo& SecInfo) { | |
| 1357 return m_bRichText && SecInfo.pWordProps | |
| 1358 ? GetFontAscent(SecInfo.pWordProps->nFontIndex, | |
| 1359 SecInfo.pWordProps->fFontSize) | |
| 1360 : GetFontAscent(GetDefaultFontIndex(), GetFontSize()); | |
| 1361 } | |
| 1362 FX_FLOAT CPDF_VariableText::GetLineDescent(const CPVT_SectionInfo& SecInfo) { | |
| 1363 return m_bRichText && SecInfo.pWordProps | |
| 1364 ? GetFontDescent(SecInfo.pWordProps->nFontIndex, | |
| 1365 SecInfo.pWordProps->fFontSize) | |
| 1366 : GetFontDescent(GetDefaultFontIndex(), GetFontSize()); | |
| 1367 } | |
| 1368 FX_FLOAT CPDF_VariableText::GetFontAscent(int32_t nFontIndex, | |
| 1369 FX_FLOAT fFontSize) { | |
| 1370 return (FX_FLOAT)GetTypeAscent(nFontIndex) * fFontSize * PVT_FONTSCALE; | |
| 1371 } | |
| 1372 FX_FLOAT CPDF_VariableText::GetFontDescent(int32_t nFontIndex, | |
| 1373 FX_FLOAT fFontSize) { | |
| 1374 return (FX_FLOAT)GetTypeDescent(nFontIndex) * fFontSize * PVT_FONTSCALE; | |
| 1375 } | |
| 1376 FX_FLOAT CPDF_VariableText::GetWordAscent(const CPVT_WordInfo& WordInfo, | |
| 1377 FX_FLOAT fFontSize) { | |
| 1378 return GetFontAscent(GetWordFontIndex(WordInfo), fFontSize); | |
| 1379 } | |
| 1380 FX_FLOAT CPDF_VariableText::GetWordDescent(const CPVT_WordInfo& WordInfo, | |
| 1381 FX_FLOAT fFontSize) { | |
| 1382 return GetFontDescent(GetWordFontIndex(WordInfo), fFontSize); | |
| 1383 } | |
| 1384 FX_FLOAT CPDF_VariableText::GetWordAscent(const CPVT_WordInfo& WordInfo, | |
| 1385 FX_BOOL bFactFontSize) { | |
| 1386 return GetFontAscent(GetWordFontIndex(WordInfo), | |
| 1387 GetWordFontSize(WordInfo, bFactFontSize)); | |
| 1388 } | |
| 1389 FX_FLOAT CPDF_VariableText::GetWordDescent(const CPVT_WordInfo& WordInfo, | |
| 1390 FX_BOOL bFactFontSize) { | |
| 1391 return GetFontDescent(GetWordFontIndex(WordInfo), | |
| 1392 GetWordFontSize(WordInfo, bFactFontSize)); | |
| 1393 } | |
| 1394 FX_FLOAT CPDF_VariableText::GetLineLeading(const CPVT_SectionInfo& SecInfo) { | |
| 1395 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->fLineLeading | |
| 1396 : m_fLineLeading; | |
| 1397 } | |
| 1398 FX_FLOAT CPDF_VariableText::GetLineIndent(const CPVT_SectionInfo& SecInfo) { | |
| 1399 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->fLineIndent | |
| 1400 : 0.0f; | |
| 1401 } | |
| 1402 int32_t CPDF_VariableText::GetAlignment(const CPVT_SectionInfo& SecInfo) { | |
| 1403 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->nAlignment | |
| 1404 : m_nAlignment; | |
| 1405 } | |
| 1406 FX_FLOAT CPDF_VariableText::GetCharSpace(const CPVT_WordInfo& WordInfo) { | |
| 1407 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->fCharSpace | |
| 1408 : m_fCharSpace; | |
| 1409 } | |
| 1410 int32_t CPDF_VariableText::GetHorzScale(const CPVT_WordInfo& WordInfo) { | |
| 1411 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nHorzScale | |
| 1412 : m_nHorzScale; | |
| 1413 } | |
| 1414 void CPDF_VariableText::ClearSectionRightWords(const CPVT_WordPlace& place) { | |
| 1415 CPVT_WordPlace wordplace = AdjustLineHeader(place, TRUE); | |
| 1416 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1417 for (int32_t w = pSection->m_WordArray.GetSize() - 1; | |
| 1418 w > wordplace.nWordIndex; w--) { | |
| 1419 delete pSection->m_WordArray.GetAt(w); | |
| 1420 pSection->m_WordArray.RemoveAt(w); | |
| 1421 } | |
| 1422 } | |
| 1423 } | |
| 1424 CPVT_WordPlace CPDF_VariableText::AdjustLineHeader(const CPVT_WordPlace& place, | |
| 1425 FX_BOOL bPrevOrNext) const { | |
| 1426 if (place.nWordIndex < 0 && place.nLineIndex > 0) { | |
| 1427 return bPrevOrNext ? GetPrevWordPlace(place) : GetNextWordPlace(place); | |
| 1428 } | |
| 1429 return place; | |
| 1430 } | |
| 1431 FX_BOOL CPDF_VariableText::ClearEmptySection(const CPVT_WordPlace& place) { | |
| 1432 if (place.nSecIndex == 0 && m_SectionArray.GetSize() == 1) { | |
| 1433 return FALSE; | |
| 1434 } | |
| 1435 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1436 if (pSection->m_WordArray.GetSize() == 0) { | |
| 1437 delete pSection; | |
| 1438 m_SectionArray.RemoveAt(place.nSecIndex); | |
| 1439 return TRUE; | |
| 1440 } | |
| 1441 } | |
| 1442 return FALSE; | |
| 1443 } | |
| 1444 void CPDF_VariableText::ClearEmptySections(const CPVT_WordRange& PlaceRange) { | |
| 1445 CPVT_WordPlace wordplace; | |
| 1446 for (int32_t s = PlaceRange.EndPos.nSecIndex; | |
| 1447 s > PlaceRange.BeginPos.nSecIndex; s--) { | |
| 1448 wordplace.nSecIndex = s; | |
| 1449 ClearEmptySection(wordplace); | |
| 1450 } | |
| 1451 } | |
| 1452 void CPDF_VariableText::LinkLatterSection(const CPVT_WordPlace& place) { | |
| 1453 CPVT_WordPlace oldplace = AdjustLineHeader(place, TRUE); | |
| 1454 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) { | |
| 1455 if (CSection* pSection = m_SectionArray.GetAt(oldplace.nSecIndex)) { | |
| 1456 for (int32_t w = 0, sz = pNextSection->m_WordArray.GetSize(); w < sz; | |
| 1457 w++) { | |
| 1458 if (CPVT_WordInfo* pWord = pNextSection->m_WordArray.GetAt(w)) { | |
| 1459 oldplace.nWordIndex++; | |
| 1460 pSection->AddWord(oldplace, *pWord); | |
| 1461 } | |
| 1462 } | |
| 1463 } | |
| 1464 delete pNextSection; | |
| 1465 m_SectionArray.RemoveAt(place.nSecIndex + 1); | |
| 1466 } | |
| 1467 } | |
| 1468 void CPDF_VariableText::ClearWords(const CPVT_WordRange& PlaceRange) { | |
| 1469 CPVT_WordRange NewRange; | |
| 1470 NewRange.BeginPos = AdjustLineHeader(PlaceRange.BeginPos, TRUE); | |
| 1471 NewRange.EndPos = AdjustLineHeader(PlaceRange.EndPos, TRUE); | |
| 1472 for (int32_t s = NewRange.EndPos.nSecIndex; s >= NewRange.BeginPos.nSecIndex; | |
| 1473 s--) { | |
| 1474 if (CSection* pSection = m_SectionArray.GetAt(s)) { | |
| 1475 pSection->ClearWords(NewRange); | |
| 1476 } | |
| 1477 } | |
| 1478 } | |
| 1479 CPVT_WordPlace CPDF_VariableText::ClearLeftWord(const CPVT_WordPlace& place) { | |
| 1480 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1481 CPVT_WordPlace leftplace = GetPrevWordPlace(place); | |
| 1482 if (leftplace != place) { | |
| 1483 if (leftplace.nSecIndex != place.nSecIndex) { | |
| 1484 if (pSection->m_WordArray.GetSize() == 0) { | |
| 1485 ClearEmptySection(place); | |
| 1486 } else { | |
| 1487 LinkLatterSection(leftplace); | |
| 1488 } | |
| 1489 } else { | |
| 1490 pSection->ClearWord(place); | |
| 1491 } | |
| 1492 } | |
| 1493 return leftplace; | |
| 1494 } | |
| 1495 return place; | |
| 1496 } | |
| 1497 CPVT_WordPlace CPDF_VariableText::ClearRightWord(const CPVT_WordPlace& place) { | |
| 1498 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | |
| 1499 CPVT_WordPlace rightplace = | |
| 1500 AdjustLineHeader(GetNextWordPlace(place), FALSE); | |
| 1501 if (rightplace != place) { | |
| 1502 if (rightplace.nSecIndex != place.nSecIndex) { | |
| 1503 LinkLatterSection(place); | |
| 1504 } else { | |
| 1505 pSection->ClearWord(rightplace); | |
| 1506 } | |
| 1507 } | |
| 1508 } | |
| 1509 return place; | |
| 1510 } | |
| 1511 void CPDF_VariableText::RearrangeAll() { | |
| 1512 Rearrange(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); | |
| 1513 } | |
| 1514 void CPDF_VariableText::RearrangePart(const CPVT_WordRange& PlaceRange) { | |
| 1515 Rearrange(PlaceRange); | |
| 1516 } | |
| 1517 CPVT_FloatRect CPDF_VariableText::Rearrange(const CPVT_WordRange& PlaceRange) { | |
| 1518 CPVT_FloatRect rcRet; | |
| 1519 if (IsValid()) { | |
| 1520 if (m_bAutoFontSize) { | |
| 1521 SetFontSize(GetAutoFontSize()); | |
| 1522 rcRet = RearrangeSections( | |
| 1523 CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); | |
| 1524 } else { | |
| 1525 rcRet = RearrangeSections(PlaceRange); | |
| 1526 } | |
| 1527 } | |
| 1528 SetContentRect(rcRet); | |
| 1529 return rcRet; | |
| 1530 } | |
| 1531 FX_FLOAT CPDF_VariableText::GetAutoFontSize() { | |
| 1532 int32_t nTotal = sizeof(gFontSizeSteps) / sizeof(uint8_t); | |
| 1533 if (IsMultiLine()) { | |
| 1534 nTotal /= 4; | |
| 1535 } | |
| 1536 if (nTotal <= 0) { | |
| 1537 return 0; | |
| 1538 } | |
| 1539 if (GetPlateWidth() <= 0) { | |
| 1540 return 0; | |
| 1541 } | |
| 1542 int32_t nLeft = 0; | |
| 1543 int32_t nRight = nTotal - 1; | |
| 1544 int32_t nMid = nTotal / 2; | |
| 1545 while (nLeft <= nRight) { | |
| 1546 if (IsBigger(gFontSizeSteps[nMid])) { | |
| 1547 nRight = nMid - 1; | |
| 1548 nMid = (nLeft + nRight) / 2; | |
| 1549 continue; | |
| 1550 } else { | |
| 1551 nLeft = nMid + 1; | |
| 1552 nMid = (nLeft + nRight) / 2; | |
| 1553 continue; | |
| 1554 } | |
| 1555 } | |
| 1556 return (FX_FLOAT)gFontSizeSteps[nMid]; | |
| 1557 } | |
| 1558 FX_BOOL CPDF_VariableText::IsBigger(FX_FLOAT fFontSize) { | |
| 1559 FX_BOOL bBigger = FALSE; | |
| 1560 CPVT_Size szTotal; | |
| 1561 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { | |
| 1562 if (CSection* pSection = m_SectionArray.GetAt(s)) { | |
| 1563 CPVT_Size size = pSection->GetSectionSize(fFontSize); | |
| 1564 szTotal.x = std::max(size.x, szTotal.x); | |
| 1565 szTotal.y += size.y; | |
| 1566 if (IsFloatBigger(szTotal.x, GetPlateWidth()) || | |
| 1567 IsFloatBigger(szTotal.y, GetPlateHeight())) { | |
| 1568 bBigger = TRUE; | |
| 1569 break; | |
| 1570 } | |
| 1571 } | |
| 1572 } | |
| 1573 return bBigger; | |
| 1574 } | |
| 1575 CPVT_FloatRect CPDF_VariableText::RearrangeSections( | |
| 1576 const CPVT_WordRange& PlaceRange) { | |
| 1577 CPVT_WordPlace place; | |
| 1578 FX_FLOAT fPosY = 0; | |
| 1579 FX_FLOAT fOldHeight; | |
| 1580 int32_t nSSecIndex = PlaceRange.BeginPos.nSecIndex; | |
| 1581 int32_t nESecIndex = PlaceRange.EndPos.nSecIndex; | |
| 1582 CPVT_FloatRect rcRet; | |
| 1583 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { | |
| 1584 place.nSecIndex = s; | |
| 1585 if (CSection* pSection = m_SectionArray.GetAt(s)) { | |
| 1586 pSection->SecPlace = place; | |
| 1587 CPVT_FloatRect rcSec = pSection->m_SecInfo.rcSection; | |
| 1588 if (s >= nSSecIndex) { | |
| 1589 if (s <= nESecIndex) { | |
| 1590 rcSec = pSection->Rearrange(); | |
| 1591 rcSec.top += fPosY; | |
| 1592 rcSec.bottom += fPosY; | |
| 1593 } else { | |
| 1594 fOldHeight = pSection->m_SecInfo.rcSection.bottom - | |
| 1595 pSection->m_SecInfo.rcSection.top; | |
| 1596 rcSec.top = fPosY; | |
| 1597 rcSec.bottom = fPosY + fOldHeight; | |
| 1598 } | |
| 1599 pSection->m_SecInfo.rcSection = rcSec; | |
| 1600 pSection->ResetLinePlace(); | |
| 1601 } | |
| 1602 if (s == 0) { | |
| 1603 rcRet = rcSec; | |
| 1604 } else { | |
| 1605 rcRet.left = std::min(rcSec.left, rcRet.left); | |
| 1606 rcRet.top = std::min(rcSec.top, rcRet.top); | |
| 1607 rcRet.right = std::max(rcSec.right, rcRet.right); | |
| 1608 rcRet.bottom = std::max(rcSec.bottom, rcRet.bottom); | |
| 1609 } | |
| 1610 fPosY += rcSec.Height(); | |
| 1611 } | |
| 1612 } | |
| 1613 return rcRet; | |
| 1614 } | |
| 1615 int32_t CPDF_VariableText::GetCharWidth(int32_t nFontIndex, | |
| 1616 uint16_t Word, | |
| 1617 uint16_t SubWord, | |
| 1618 int32_t nWordStyle) { | |
| 1619 if (!m_pVTProvider) { | |
| 1620 return 0; | |
| 1621 } | |
| 1622 if (SubWord > 0) { | |
| 1623 return m_pVTProvider->GetCharWidth(nFontIndex, SubWord, nWordStyle); | |
| 1624 } | |
| 1625 return m_pVTProvider->GetCharWidth(nFontIndex, Word, nWordStyle); | |
| 1626 } | |
| 1627 int32_t CPDF_VariableText::GetTypeAscent(int32_t nFontIndex) { | |
| 1628 return m_pVTProvider ? m_pVTProvider->GetTypeAscent(nFontIndex) : 0; | |
| 1629 } | |
| 1630 int32_t CPDF_VariableText::GetTypeDescent(int32_t nFontIndex) { | |
| 1631 return m_pVTProvider ? m_pVTProvider->GetTypeDescent(nFontIndex) : 0; | |
| 1632 } | |
| 1633 int32_t CPDF_VariableText::GetWordFontIndex(uint16_t word, | |
| 1634 int32_t charset, | |
| 1635 int32_t nFontIndex) { | |
| 1636 return m_pVTProvider | |
| 1637 ? m_pVTProvider->GetWordFontIndex(word, charset, nFontIndex) | |
| 1638 : -1; | |
| 1639 } | |
| 1640 int32_t CPDF_VariableText::GetDefaultFontIndex() { | |
| 1641 return m_pVTProvider ? m_pVTProvider->GetDefaultFontIndex() : -1; | |
| 1642 } | |
| 1643 FX_BOOL CPDF_VariableText::IsLatinWord(uint16_t word) { | |
| 1644 return m_pVTProvider ? m_pVTProvider->IsLatinWord(word) : FALSE; | |
| 1645 } | |
| 1646 IPDF_VariableText::Iterator* CPDF_VariableText::GetIterator() { | |
| 1647 if (!m_pVTIterator) { | |
| 1648 m_pVTIterator = new CPDF_VariableText_Iterator(this); | |
| 1649 } | |
| 1650 return m_pVTIterator; | |
| 1651 } | |
| 1652 IPDF_VariableText::Provider* CPDF_VariableText::SetProvider( | |
| 1653 IPDF_VariableText::Provider* pProvider) { | |
| 1654 IPDF_VariableText::Provider* pOld = m_pVTProvider; | |
| 1655 m_pVTProvider = pProvider; | |
| 1656 return pOld; | |
| 1657 } | |
| 1658 CPDF_VariableText_Iterator::CPDF_VariableText_Iterator(CPDF_VariableText* pVT) | |
| 1659 : m_CurPos(-1, -1, -1), m_pVT(pVT) {} | |
| 1660 CPDF_VariableText_Iterator::~CPDF_VariableText_Iterator() {} | |
| 1661 void CPDF_VariableText_Iterator::SetAt(int32_t nWordIndex) { | |
| 1662 m_CurPos = m_pVT->WordIndexToWordPlace(nWordIndex); | |
| 1663 } | |
| 1664 void CPDF_VariableText_Iterator::SetAt(const CPVT_WordPlace& place) { | |
| 1665 ASSERT(m_pVT); | |
| 1666 m_CurPos = place; | |
| 1667 } | |
| 1668 FX_BOOL CPDF_VariableText_Iterator::NextWord() { | |
| 1669 if (m_CurPos == m_pVT->GetEndWordPlace()) { | |
| 1670 return FALSE; | |
| 1671 } | |
| 1672 m_CurPos = m_pVT->GetNextWordPlace(m_CurPos); | |
| 1673 return TRUE; | |
| 1674 } | |
| 1675 FX_BOOL CPDF_VariableText_Iterator::PrevWord() { | |
| 1676 if (m_CurPos == m_pVT->GetBeginWordPlace()) { | |
| 1677 return FALSE; | |
| 1678 } | |
| 1679 m_CurPos = m_pVT->GetPrevWordPlace(m_CurPos); | |
| 1680 return TRUE; | |
| 1681 } | |
| 1682 FX_BOOL CPDF_VariableText_Iterator::NextLine() { | |
| 1683 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1684 if (m_CurPos.nLineIndex < pSection->m_LineArray.GetSize() - 1) { | |
| 1685 m_CurPos = | |
| 1686 CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex + 1, -1); | |
| 1687 return TRUE; | |
| 1688 } | |
| 1689 if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) { | |
| 1690 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1); | |
| 1691 return TRUE; | |
| 1692 } | |
| 1693 } | |
| 1694 return FALSE; | |
| 1695 } | |
| 1696 FX_BOOL CPDF_VariableText_Iterator::PrevLine() { | |
| 1697 if (m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1698 if (m_CurPos.nLineIndex > 0) { | |
| 1699 m_CurPos = | |
| 1700 CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex - 1, -1); | |
| 1701 return TRUE; | |
| 1702 } | |
| 1703 if (m_CurPos.nSecIndex > 0) { | |
| 1704 if (CSection* pLastSection = | |
| 1705 m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex - 1)) { | |
| 1706 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1, | |
| 1707 pLastSection->m_LineArray.GetSize() - 1, -1); | |
| 1708 return TRUE; | |
| 1709 } | |
| 1710 } | |
| 1711 } | |
| 1712 return FALSE; | |
| 1713 } | |
| 1714 FX_BOOL CPDF_VariableText_Iterator::NextSection() { | |
| 1715 if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) { | |
| 1716 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1); | |
| 1717 return TRUE; | |
| 1718 } | |
| 1719 return FALSE; | |
| 1720 } | |
| 1721 FX_BOOL CPDF_VariableText_Iterator::PrevSection() { | |
| 1722 ASSERT(m_pVT); | |
| 1723 if (m_CurPos.nSecIndex > 0) { | |
| 1724 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1, 0, -1); | |
| 1725 return TRUE; | |
| 1726 } | |
| 1727 return FALSE; | |
| 1728 } | |
| 1729 FX_BOOL CPDF_VariableText_Iterator::GetWord(CPVT_Word& word) const { | |
| 1730 word.WordPlace = m_CurPos; | |
| 1731 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1732 if (pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { | |
| 1733 if (CPVT_WordInfo* pWord = | |
| 1734 pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) { | |
| 1735 word.Word = pWord->Word; | |
| 1736 word.nCharset = pWord->nCharset; | |
| 1737 word.fWidth = m_pVT->GetWordWidth(*pWord); | |
| 1738 word.ptWord = m_pVT->InToOut( | |
| 1739 CFX_FloatPoint(pWord->fWordX + pSection->m_SecInfo.rcSection.left, | |
| 1740 pWord->fWordY + pSection->m_SecInfo.rcSection.top)); | |
| 1741 word.fAscent = m_pVT->GetWordAscent(*pWord); | |
| 1742 word.fDescent = m_pVT->GetWordDescent(*pWord); | |
| 1743 if (pWord->pWordProps) { | |
| 1744 word.WordProps = *pWord->pWordProps; | |
| 1745 } | |
| 1746 word.nFontIndex = m_pVT->GetWordFontIndex(*pWord); | |
| 1747 word.fFontSize = m_pVT->GetWordFontSize(*pWord); | |
| 1748 return TRUE; | |
| 1749 } | |
| 1750 } | |
| 1751 } | |
| 1752 return FALSE; | |
| 1753 } | |
| 1754 FX_BOOL CPDF_VariableText_Iterator::SetWord(const CPVT_Word& word) { | |
| 1755 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1756 if (CPVT_WordInfo* pWord = | |
| 1757 pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) { | |
| 1758 if (pWord->pWordProps) { | |
| 1759 *pWord->pWordProps = word.WordProps; | |
| 1760 } | |
| 1761 return TRUE; | |
| 1762 } | |
| 1763 } | |
| 1764 return FALSE; | |
| 1765 } | |
| 1766 FX_BOOL CPDF_VariableText_Iterator::GetLine(CPVT_Line& line) const { | |
| 1767 ASSERT(m_pVT); | |
| 1768 line.lineplace = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex, -1); | |
| 1769 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1770 if (CLine* pLine = pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { | |
| 1771 line.ptLine = m_pVT->InToOut(CFX_FloatPoint( | |
| 1772 pLine->m_LineInfo.fLineX + pSection->m_SecInfo.rcSection.left, | |
| 1773 pLine->m_LineInfo.fLineY + pSection->m_SecInfo.rcSection.top)); | |
| 1774 line.fLineWidth = pLine->m_LineInfo.fLineWidth; | |
| 1775 line.fLineAscent = pLine->m_LineInfo.fLineAscent; | |
| 1776 line.fLineDescent = pLine->m_LineInfo.fLineDescent; | |
| 1777 line.lineEnd = pLine->GetEndWordPlace(); | |
| 1778 return TRUE; | |
| 1779 } | |
| 1780 } | |
| 1781 return FALSE; | |
| 1782 } | |
| 1783 FX_BOOL CPDF_VariableText_Iterator::GetSection(CPVT_Section& section) const { | |
| 1784 section.secplace = CPVT_WordPlace(m_CurPos.nSecIndex, 0, -1); | |
| 1785 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1786 section.rcSection = m_pVT->InToOut(pSection->m_SecInfo.rcSection); | |
| 1787 if (pSection->m_SecInfo.pSecProps) { | |
| 1788 section.SecProps = *pSection->m_SecInfo.pSecProps; | |
| 1789 } | |
| 1790 if (pSection->m_SecInfo.pWordProps) { | |
| 1791 section.WordProps = *pSection->m_SecInfo.pWordProps; | |
| 1792 } | |
| 1793 return TRUE; | |
| 1794 } | |
| 1795 return FALSE; | |
| 1796 } | |
| 1797 FX_BOOL CPDF_VariableText_Iterator::SetSection(const CPVT_Section& section) { | |
| 1798 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | |
| 1799 if (pSection->m_SecInfo.pSecProps) { | |
| 1800 *pSection->m_SecInfo.pSecProps = section.SecProps; | |
| 1801 } | |
| 1802 if (pSection->m_SecInfo.pWordProps) { | |
| 1803 *pSection->m_SecInfo.pWordProps = section.WordProps; | |
| 1804 } | |
| 1805 return TRUE; | |
| 1806 } | |
| 1807 return FALSE; | |
| 1808 } | |
| OLD | NEW |