OLD | NEW |
---|---|
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/fpdfdoc/include/cpdf_variabletext.h" | |
8 | |
7 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
8 #include "core/fpdfdoc/cpvt_wordinfo.h" | 10 #include "core/fpdfdoc/cpvt_wordinfo.h" |
9 #include "core/fpdfdoc/csection.h" | 11 #include "core/fpdfdoc/csection.h" |
10 #include "core/fpdfdoc/include/cpdf_variabletext.h" | |
11 #include "core/fpdfdoc/include/cpvt_section.h" | 12 #include "core/fpdfdoc/include/cpvt_section.h" |
12 #include "core/fpdfdoc/include/cpvt_word.h" | 13 #include "core/fpdfdoc/include/cpvt_word.h" |
13 #include "core/fpdfdoc/include/ipvt_fontmap.h" | 14 #include "core/fpdfdoc/include/ipvt_fontmap.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 const float kDefaultFontSize = 18.0f; | 18 const float kDefaultFontSize = 18.0f; |
18 const float kFontScale = 0.001f; | 19 const float kFontScale = 0.001f; |
19 const uint8_t kReturnLength = 1; | 20 const uint8_t kReturnLength = 1; |
20 const float kScalePercent = 0.01f; | 21 const float kScalePercent = 0.01f; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 return 0; | 64 return 0; |
64 } | 65 } |
65 if (CPDF_Font* pSysFont = m_pFontMap->GetPDFFont(1)) { | 66 if (CPDF_Font* pSysFont = m_pFontMap->GetPDFFont(1)) { |
66 if (pSysFont->CharCodeFromUnicode(word) != CPDF_Font::kInvalidCharCode) | 67 if (pSysFont->CharCodeFromUnicode(word) != CPDF_Font::kInvalidCharCode) |
67 return 1; | 68 return 1; |
68 } | 69 } |
69 return -1; | 70 return -1; |
70 } | 71 } |
71 | 72 |
72 FX_BOOL CPDF_VariableText::Provider::IsLatinWord(uint16_t word) { | 73 FX_BOOL CPDF_VariableText::Provider::IsLatinWord(uint16_t word) { |
73 if ((word >= 0x61 && word <= 0x7A) || (word >= 0x41 && word <= 0x5A) || | 74 return (word >= 0x61 && word <= 0x7A) || (word >= 0x41 && word <= 0x5A) || |
74 word == 0x2D || word == 0x27) { | 75 word == 0x2D || word == 0x27; |
75 return TRUE; | |
76 } | |
77 return FALSE; | |
78 } | 76 } |
79 | 77 |
80 int32_t CPDF_VariableText::Provider::GetDefaultFontIndex() { | 78 int32_t CPDF_VariableText::Provider::GetDefaultFontIndex() { |
81 return 0; | 79 return 0; |
82 } | 80 } |
83 | 81 |
84 CPDF_VariableText::Iterator::Iterator(CPDF_VariableText* pVT) | 82 CPDF_VariableText::Iterator::Iterator(CPDF_VariableText* pVT) |
85 : m_CurPos(-1, -1, -1), m_pVT(pVT) {} | 83 : m_CurPos(-1, -1, -1), m_pVT(pVT) {} |
86 | 84 |
87 CPDF_VariableText::Iterator::~Iterator() {} | 85 CPDF_VariableText::Iterator::~Iterator() {} |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 ASSERT(m_pVT); | 155 ASSERT(m_pVT); |
158 if (m_CurPos.nSecIndex > 0) { | 156 if (m_CurPos.nSecIndex > 0) { |
159 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1, 0, -1); | 157 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1, 0, -1); |
160 return TRUE; | 158 return TRUE; |
161 } | 159 } |
162 return FALSE; | 160 return FALSE; |
163 } | 161 } |
164 | 162 |
165 FX_BOOL CPDF_VariableText::Iterator::GetWord(CPVT_Word& word) const { | 163 FX_BOOL CPDF_VariableText::Iterator::GetWord(CPVT_Word& word) const { |
166 word.WordPlace = m_CurPos; | 164 word.WordPlace = m_CurPos; |
167 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | 165 CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex); |
168 if (pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { | 166 if (!pSection) |
169 if (CPVT_WordInfo* pWord = | 167 return FALSE; |
170 pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) { | |
171 word.Word = pWord->Word; | |
172 word.nCharset = pWord->nCharset; | |
173 word.fWidth = m_pVT->GetWordWidth(*pWord); | |
174 word.ptWord = m_pVT->InToOut( | |
175 CFX_FloatPoint(pWord->fWordX + pSection->m_SecInfo.rcSection.left, | |
176 pWord->fWordY + pSection->m_SecInfo.rcSection.top)); | |
177 word.fAscent = m_pVT->GetWordAscent(*pWord); | |
178 word.fDescent = m_pVT->GetWordDescent(*pWord); | |
179 if (pWord->pWordProps) | |
180 word.WordProps = *pWord->pWordProps; | |
181 | 168 |
182 word.nFontIndex = m_pVT->GetWordFontIndex(*pWord); | 169 if (!pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) |
183 word.fFontSize = m_pVT->GetWordFontSize(*pWord); | 170 return FALSE; |
184 return TRUE; | 171 |
185 } | 172 const CPVT_WordInfo* pWord = pSection->GetWord(m_CurPos.nWordIndex); |
186 } | 173 if (!pWord) |
187 } | 174 return FALSE; |
188 return FALSE; | 175 |
176 word.Word = pWord->Word; | |
177 word.nCharset = pWord->nCharset; | |
178 word.fWidth = m_pVT->GetWordWidth(*pWord); | |
179 word.ptWord = m_pVT->InToOut( | |
180 CFX_FloatPoint(pWord->fWordX + pSection->m_SecInfo.rcSection.left, | |
181 pWord->fWordY + pSection->m_SecInfo.rcSection.top)); | |
182 word.fAscent = m_pVT->GetWordAscent(*pWord); | |
183 word.fDescent = m_pVT->GetWordDescent(*pWord); | |
184 if (pWord->pWordProps) | |
185 word.WordProps = *pWord->pWordProps; | |
186 | |
187 word.nFontIndex = m_pVT->GetWordFontIndex(*pWord); | |
188 word.fFontSize = m_pVT->GetWordFontSize(*pWord); | |
189 return TRUE; | |
189 } | 190 } |
190 | 191 |
191 FX_BOOL CPDF_VariableText::Iterator::SetWord(const CPVT_Word& word) { | 192 FX_BOOL CPDF_VariableText::Iterator::SetWord(const CPVT_Word& word) { |
192 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | 193 CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex); |
193 if (CPVT_WordInfo* pWord = | 194 if (!pSection) |
194 pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) { | 195 return FALSE; |
195 if (pWord->pWordProps) | 196 |
196 *pWord->pWordProps = word.WordProps; | 197 const CPVT_WordInfo* pWord = pSection->GetWord(m_CurPos.nWordIndex); |
197 return TRUE; | 198 if (!pWord) |
198 } | 199 return FALSE; |
199 } | 200 |
200 return FALSE; | 201 if (pWord->pWordProps) |
202 *pWord->pWordProps = word.WordProps; | |
203 return TRUE; | |
201 } | 204 } |
202 | 205 |
203 FX_BOOL CPDF_VariableText::Iterator::GetLine(CPVT_Line& line) const { | 206 FX_BOOL CPDF_VariableText::Iterator::GetLine(CPVT_Line& line) const { |
204 ASSERT(m_pVT); | 207 ASSERT(m_pVT); |
205 line.lineplace = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex, -1); | 208 line.lineplace = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex, -1); |
206 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { | 209 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) { |
207 if (CLine* pLine = pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { | 210 if (CLine* pLine = pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) { |
208 line.ptLine = m_pVT->InToOut(CFX_FloatPoint( | 211 line.ptLine = m_pVT->InToOut(CFX_FloatPoint( |
209 pLine->m_LineInfo.fLineX + pSection->m_SecInfo.rcSection.left, | 212 pLine->m_LineInfo.fLineX + pSection->m_SecInfo.rcSection.left, |
210 pLine->m_LineInfo.fLineY + pSection->m_SecInfo.rcSection.top)); | 213 pLine->m_LineInfo.fLineY + pSection->m_SecInfo.rcSection.top)); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) | 328 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) |
326 return place; | 329 return place; |
327 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) | 330 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) |
328 return place; | 331 return place; |
329 if (!m_bMultiLine) | 332 if (!m_bMultiLine) |
330 return place; | 333 return place; |
331 | 334 |
332 CPVT_WordPlace wordplace = place; | 335 CPVT_WordPlace wordplace = place; |
333 UpdateWordPlace(wordplace); | 336 UpdateWordPlace(wordplace); |
334 CPVT_WordPlace newplace = place; | 337 CPVT_WordPlace newplace = place; |
335 if (CSection* pSection = m_SectionArray.GetAt(wordplace.nSecIndex)) { | 338 CSection* pSection = m_SectionArray.GetAt(wordplace.nSecIndex); |
336 CPVT_WordPlace NewPlace(wordplace.nSecIndex + 1, 0, -1); | 339 if (!pSection) |
337 CPVT_SectionInfo secinfo; | 340 return newplace; |
338 if (m_bRichText) { | 341 |
339 if (pSecProps) | 342 CPVT_WordPlace NewPlace(wordplace.nSecIndex + 1, 0, -1); |
340 secinfo.pSecProps = new CPVT_SecProps(*pSecProps); | 343 CPVT_SectionInfo secinfo; |
341 if (pWordProps) | 344 if (m_bRichText) { |
342 secinfo.pWordProps = new CPVT_WordProps(*pWordProps); | 345 if (pSecProps) |
346 secinfo.pSecProps = new CPVT_SecProps(*pSecProps); | |
347 if (pWordProps) | |
348 secinfo.pWordProps = new CPVT_WordProps(*pWordProps); | |
349 } | |
350 AddSection(NewPlace, secinfo); | |
351 newplace = NewPlace; | |
352 if (CSection* pNewSection = m_SectionArray.GetAt(NewPlace.nSecIndex)) { | |
353 for (int32_t i = wordplace.nWordIndex + 1; i < pSection->GetNumberOfWords(); | |
354 ++i) { | |
355 const CPVT_WordInfo* pWord = pSection->GetWord(i); | |
356 NewPlace.nWordIndex++; | |
357 pNewSection->AddWord(NewPlace, *pWord); | |
343 } | 358 } |
344 AddSection(NewPlace, secinfo); | |
345 newplace = NewPlace; | |
346 if (CSection* pNewSection = m_SectionArray.GetAt(NewPlace.nSecIndex)) { | |
347 for (int32_t w = wordplace.nWordIndex + 1, | |
348 sz = pSection->m_WordArray.GetSize(); | |
349 w < sz; w++) { | |
350 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(w)) { | |
351 NewPlace.nWordIndex++; | |
352 pNewSection->AddWord(NewPlace, *pWord); | |
353 } | |
354 } | |
355 } | |
356 ClearSectionRightWords(wordplace); | |
357 } | 359 } |
360 ClearSectionRightWords(wordplace); | |
358 return newplace; | 361 return newplace; |
359 } | 362 } |
360 | 363 |
361 CPVT_WordPlace CPDF_VariableText::InsertText(const CPVT_WordPlace& place, | 364 CPVT_WordPlace CPDF_VariableText::InsertText(const CPVT_WordPlace& place, |
362 const FX_WCHAR* text, | 365 const FX_WCHAR* text, |
363 int32_t charset, | 366 int32_t charset, |
364 const CPVT_SecProps* pSecProps, | 367 const CPVT_SecProps* pSecProps, |
365 const CPVT_WordProps* pProps) { | 368 const CPVT_WordProps* pProps) { |
366 CFX_WideString swText = text; | 369 CFX_WideString swText = text; |
367 CPVT_WordPlace wp = place; | 370 CPVT_WordPlace wp = place; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
492 int32_t CPDF_VariableText::WordPlaceToWordIndex( | 495 int32_t CPDF_VariableText::WordPlaceToWordIndex( |
493 const CPVT_WordPlace& place) const { | 496 const CPVT_WordPlace& place) const { |
494 CPVT_WordPlace newplace = place; | 497 CPVT_WordPlace newplace = place; |
495 UpdateWordPlace(newplace); | 498 UpdateWordPlace(newplace); |
496 int32_t nIndex = 0; | 499 int32_t nIndex = 0; |
497 int32_t i = 0; | 500 int32_t i = 0; |
498 int32_t sz = 0; | 501 int32_t sz = 0; |
499 for (i = 0, sz = m_SectionArray.GetSize(); i < sz && i < newplace.nSecIndex; | 502 for (i = 0, sz = m_SectionArray.GetSize(); i < sz && i < newplace.nSecIndex; |
500 i++) { | 503 i++) { |
501 if (CSection* pSection = m_SectionArray.GetAt(i)) { | 504 if (CSection* pSection = m_SectionArray.GetAt(i)) { |
502 nIndex += pSection->m_WordArray.GetSize(); | 505 nIndex += pSection->GetNumberOfWords(); |
503 if (i != m_SectionArray.GetSize() - 1) | 506 if (i != m_SectionArray.GetSize() - 1) |
504 nIndex += kReturnLength; | 507 nIndex += kReturnLength; |
505 } | 508 } |
506 } | 509 } |
507 if (i >= 0 && i < m_SectionArray.GetSize()) | 510 if (i >= 0 && i < m_SectionArray.GetSize()) |
508 nIndex += newplace.nWordIndex + kReturnLength; | 511 nIndex += newplace.nWordIndex + kReturnLength; |
509 return nIndex; | 512 return nIndex; |
510 } | 513 } |
511 | 514 |
512 CPVT_WordPlace CPDF_VariableText::WordIndexToWordPlace(int32_t index) const { | 515 CPVT_WordPlace CPDF_VariableText::WordIndexToWordPlace(int32_t index) const { |
513 CPVT_WordPlace place = GetBeginWordPlace(); | 516 CPVT_WordPlace place = GetBeginWordPlace(); |
514 int32_t nOldIndex = 0, nIndex = 0; | 517 int32_t nOldIndex = 0, nIndex = 0; |
515 FX_BOOL bFind = FALSE; | 518 FX_BOOL bFind = FALSE; |
516 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) { | 519 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) { |
517 if (CSection* pSection = m_SectionArray.GetAt(i)) { | 520 if (CSection* pSection = m_SectionArray.GetAt(i)) { |
518 nIndex += pSection->m_WordArray.GetSize(); | 521 nIndex += pSection->GetNumberOfWords(); |
519 if (nIndex == index) { | 522 if (nIndex == index) { |
520 place = pSection->GetEndWordPlace(); | 523 place = pSection->GetEndWordPlace(); |
521 bFind = TRUE; | 524 bFind = TRUE; |
522 break; | 525 break; |
523 } else if (nIndex > index) { | 526 } |
527 if (nIndex > index) { | |
524 place.nSecIndex = i; | 528 place.nSecIndex = i; |
525 place.nWordIndex = index - nOldIndex - 1; | 529 place.nWordIndex = index - nOldIndex - 1; |
526 pSection->UpdateWordPlace(place); | 530 pSection->UpdateWordPlace(place); |
527 bFind = TRUE; | 531 bFind = TRUE; |
528 break; | 532 break; |
529 } | 533 } |
530 if (i != m_SectionArray.GetSize() - 1) | 534 if (i != m_SectionArray.GetSize() - 1) |
531 nIndex += kReturnLength; | 535 nIndex += kReturnLength; |
532 nOldIndex = nIndex; | 536 nOldIndex = nIndex; |
533 } | 537 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
689 const CPVT_WordPlace& place) const { | 693 const CPVT_WordPlace& place) const { |
690 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) | 694 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) |
691 return pSection->GetEndWordPlace(); | 695 return pSection->GetEndWordPlace(); |
692 return place; | 696 return place; |
693 } | 697 } |
694 | 698 |
695 int32_t CPDF_VariableText::GetTotalWords() const { | 699 int32_t CPDF_VariableText::GetTotalWords() const { |
696 int32_t nTotal = 0; | 700 int32_t nTotal = 0; |
697 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) { | 701 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) { |
698 if (CSection* pSection = m_SectionArray.GetAt(i)) | 702 if (CSection* pSection = m_SectionArray.GetAt(i)) |
699 nTotal += (pSection->m_WordArray.GetSize() + kReturnLength); | 703 nTotal += (pSection->GetNumberOfWords() + kReturnLength); |
700 } | 704 } |
701 | 705 |
702 return nTotal - kReturnLength; | 706 return nTotal - kReturnLength; |
703 } | 707 } |
704 | 708 |
705 void CPDF_VariableText::ResetSectionArray() { | 709 void CPDF_VariableText::ResetSectionArray() { |
706 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) | 710 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) |
707 delete m_SectionArray.GetAt(s); | 711 delete m_SectionArray.GetAt(s); |
708 | 712 |
709 m_SectionArray.RemoveAll(); | 713 m_SectionArray.RemoveAll(); |
(...skipping 12 matching lines...) Expand all Loading... | |
722 if (nSecIndex == m_SectionArray.GetSize()) | 726 if (nSecIndex == m_SectionArray.GetSize()) |
723 m_SectionArray.Add(pSection); | 727 m_SectionArray.Add(pSection); |
724 else | 728 else |
725 m_SectionArray.InsertAt(nSecIndex, pSection); | 729 m_SectionArray.InsertAt(nSecIndex, pSection); |
726 | 730 |
727 return place; | 731 return place; |
728 } | 732 } |
729 | 733 |
730 CPVT_WordPlace CPDF_VariableText::AddLine(const CPVT_WordPlace& place, | 734 CPVT_WordPlace CPDF_VariableText::AddLine(const CPVT_WordPlace& place, |
731 const CPVT_LineInfo& lineinfo) { | 735 const CPVT_LineInfo& lineinfo) { |
732 if (m_SectionArray.IsEmpty()) | 736 if (m_SectionArray.GetSize() == 0) |
733 return place; | 737 return place; |
734 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) | 738 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) |
735 return pSection->AddLine(lineinfo); | 739 return pSection->AddLine(lineinfo); |
736 return place; | 740 return place; |
737 } | 741 } |
738 | 742 |
739 CPVT_WordPlace CPDF_VariableText::AddWord(const CPVT_WordPlace& place, | 743 CPVT_WordPlace CPDF_VariableText::AddWord(const CPVT_WordPlace& place, |
740 const CPVT_WordInfo& wordinfo) { | 744 const CPVT_WordInfo& wordinfo) { |
741 if (m_SectionArray.GetSize() <= 0) { | 745 if (m_SectionArray.GetSize() <= 0) |
742 return place; | 746 return place; |
743 } | 747 |
744 CPVT_WordPlace newplace = place; | 748 CPVT_WordPlace newplace = place; |
745 newplace.nSecIndex = | 749 newplace.nSecIndex = |
746 std::max(std::min(newplace.nSecIndex, m_SectionArray.GetSize() - 1), 0); | 750 std::max(std::min(newplace.nSecIndex, m_SectionArray.GetSize() - 1), 0); |
747 if (CSection* pSection = m_SectionArray.GetAt(newplace.nSecIndex)) | 751 if (CSection* pSection = m_SectionArray.GetAt(newplace.nSecIndex)) |
748 return pSection->AddWord(newplace, wordinfo); | 752 return pSection->AddWord(newplace, wordinfo); |
749 return place; | 753 return place; |
750 } | 754 } |
751 | 755 |
752 FX_BOOL CPDF_VariableText::GetWordInfo(const CPVT_WordPlace& place, | 756 FX_BOOL CPDF_VariableText::GetWordInfo(const CPVT_WordPlace& place, |
753 CPVT_WordInfo& wordinfo) { | 757 CPVT_WordInfo& wordinfo) { |
754 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 758 CSection* pSection = m_SectionArray.GetAt(place.nSecIndex); |
755 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(place.nWordIndex)) { | 759 if (!pSection) |
756 wordinfo = *pWord; | 760 return FALSE; |
757 return TRUE; | 761 |
758 } | 762 const CPVT_WordInfo* pWord = pSection->GetWord(place.nWordIndex); |
759 } | 763 if (!pWord) |
760 return FALSE; | 764 return FALSE; |
765 | |
766 wordinfo = *pWord; | |
767 return TRUE; | |
761 } | 768 } |
762 | 769 |
763 FX_BOOL CPDF_VariableText::SetWordInfo(const CPVT_WordPlace& place, | 770 FX_BOOL CPDF_VariableText::SetWordInfo(const CPVT_WordPlace& place, |
764 const CPVT_WordInfo& wordinfo) { | 771 const CPVT_WordInfo& wordinfo) { |
765 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 772 CSection* pSection = m_SectionArray.GetAt(place.nSecIndex); |
766 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(place.nWordIndex)) { | 773 if (!pSection) |
767 *pWord = wordinfo; | 774 return FALSE; |
768 return TRUE; | 775 |
769 } | 776 CPVT_WordInfo* pWord = pSection->GetWord(place.nWordIndex); |
770 } | 777 if (!pWord) |
771 return FALSE; | 778 return FALSE; |
779 | |
780 *pWord = wordinfo; | |
781 return TRUE; | |
772 } | 782 } |
773 | 783 |
774 FX_BOOL CPDF_VariableText::GetLineInfo(const CPVT_WordPlace& place, | 784 FX_BOOL CPDF_VariableText::GetLineInfo(const CPVT_WordPlace& place, |
775 CPVT_LineInfo& lineinfo) { | 785 CPVT_LineInfo& lineinfo) { |
776 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 786 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
777 if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex)) { | 787 if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex)) { |
778 lineinfo = pLine->m_LineInfo; | 788 lineinfo = pLine->m_LineInfo; |
779 return TRUE; | 789 return TRUE; |
780 } | 790 } |
781 } | 791 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
899 : m_fCharSpace; | 909 : m_fCharSpace; |
900 } | 910 } |
901 | 911 |
902 int32_t CPDF_VariableText::GetHorzScale(const CPVT_WordInfo& WordInfo) { | 912 int32_t CPDF_VariableText::GetHorzScale(const CPVT_WordInfo& WordInfo) { |
903 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nHorzScale | 913 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nHorzScale |
904 : m_nHorzScale; | 914 : m_nHorzScale; |
905 } | 915 } |
906 | 916 |
907 void CPDF_VariableText::ClearSectionRightWords(const CPVT_WordPlace& place) { | 917 void CPDF_VariableText::ClearSectionRightWords(const CPVT_WordPlace& place) { |
908 CPVT_WordPlace wordplace = AdjustLineHeader(place, TRUE); | 918 CPVT_WordPlace wordplace = AdjustLineHeader(place, TRUE); |
909 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 919 CSection* pSection = m_SectionArray.GetAt(place.nSecIndex); |
910 for (int32_t w = pSection->m_WordArray.GetSize() - 1; | 920 if (pSection) |
911 w > wordplace.nWordIndex; w--) { | 921 pSection->ClearRightWords(wordplace.nWordIndex); |
dsinclair
2016/05/16 14:12:27
ClearRightWords is ... confusing. ClearWordsFrom m
| |
912 delete pSection->m_WordArray.GetAt(w); | |
913 pSection->m_WordArray.RemoveAt(w); | |
914 } | |
915 } | |
916 } | 922 } |
917 | 923 |
918 CPVT_WordPlace CPDF_VariableText::AdjustLineHeader(const CPVT_WordPlace& place, | 924 CPVT_WordPlace CPDF_VariableText::AdjustLineHeader(const CPVT_WordPlace& place, |
919 FX_BOOL bPrevOrNext) const { | 925 FX_BOOL bPrevOrNext) const { |
920 if (place.nWordIndex < 0 && place.nLineIndex > 0) | 926 if (place.nWordIndex < 0 && place.nLineIndex > 0) |
921 return bPrevOrNext ? GetPrevWordPlace(place) : GetNextWordPlace(place); | 927 return bPrevOrNext ? GetPrevWordPlace(place) : GetNextWordPlace(place); |
922 return place; | 928 return place; |
923 } | 929 } |
924 | 930 |
925 FX_BOOL CPDF_VariableText::ClearEmptySection(const CPVT_WordPlace& place) { | 931 FX_BOOL CPDF_VariableText::ClearEmptySection(const CPVT_WordPlace& place) { |
926 if (place.nSecIndex == 0 && m_SectionArray.GetSize() == 1) | 932 if (place.nSecIndex == 0 && m_SectionArray.GetSize() == 1) |
927 return FALSE; | 933 return FALSE; |
928 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 934 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
929 if (pSection->m_WordArray.GetSize() == 0) { | 935 if (pSection->IsWordArrayEmpty()) { |
dsinclair
2016/05/16 14:12:27
Can this use GetSize() == 0? We got rid of IsEmpty
| |
930 delete pSection; | 936 delete pSection; |
931 m_SectionArray.RemoveAt(place.nSecIndex); | 937 m_SectionArray.RemoveAt(place.nSecIndex); |
932 return TRUE; | 938 return TRUE; |
933 } | 939 } |
934 } | 940 } |
935 return FALSE; | 941 return FALSE; |
936 } | 942 } |
937 | 943 |
938 void CPDF_VariableText::ClearEmptySections(const CPVT_WordRange& PlaceRange) { | 944 void CPDF_VariableText::ClearEmptySections(const CPVT_WordRange& PlaceRange) { |
939 CPVT_WordPlace wordplace; | 945 CPVT_WordPlace wordplace; |
940 for (int32_t s = PlaceRange.EndPos.nSecIndex; | 946 for (int32_t s = PlaceRange.EndPos.nSecIndex; |
941 s > PlaceRange.BeginPos.nSecIndex; s--) { | 947 s > PlaceRange.BeginPos.nSecIndex; s--) { |
942 wordplace.nSecIndex = s; | 948 wordplace.nSecIndex = s; |
943 ClearEmptySection(wordplace); | 949 ClearEmptySection(wordplace); |
944 } | 950 } |
945 } | 951 } |
946 | 952 |
947 void CPDF_VariableText::LinkLatterSection(const CPVT_WordPlace& place) { | 953 void CPDF_VariableText::LinkLatterSection(const CPVT_WordPlace& place) { |
948 CPVT_WordPlace oldplace = AdjustLineHeader(place, TRUE); | 954 CPVT_WordPlace oldplace = AdjustLineHeader(place, TRUE); |
949 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) { | 955 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) { |
950 if (CSection* pSection = m_SectionArray.GetAt(oldplace.nSecIndex)) { | 956 if (CSection* pSection = m_SectionArray.GetAt(oldplace.nSecIndex)) { |
951 for (int32_t w = 0, sz = pNextSection->m_WordArray.GetSize(); w < sz; | 957 for (int32_t i = 0; i < pNextSection->GetNumberOfWords(); ++i) { |
952 w++) { | 958 const CPVT_WordInfo* pWord = pNextSection->GetWord(i); |
dsinclair
2016/05/16 14:12:27
It's no longer possible for pWord to be nullptr?
| |
953 if (CPVT_WordInfo* pWord = pNextSection->m_WordArray.GetAt(w)) { | 959 oldplace.nWordIndex++; |
954 oldplace.nWordIndex++; | 960 pSection->AddWord(oldplace, *pWord); |
955 pSection->AddWord(oldplace, *pWord); | |
956 } | |
957 } | 961 } |
958 } | 962 } |
959 delete pNextSection; | 963 delete pNextSection; |
960 m_SectionArray.RemoveAt(place.nSecIndex + 1); | 964 m_SectionArray.RemoveAt(place.nSecIndex + 1); |
961 } | 965 } |
962 } | 966 } |
963 | 967 |
964 void CPDF_VariableText::ClearWords(const CPVT_WordRange& PlaceRange) { | 968 void CPDF_VariableText::ClearWords(const CPVT_WordRange& PlaceRange) { |
965 CPVT_WordRange NewRange; | 969 CPVT_WordRange NewRange; |
966 NewRange.BeginPos = AdjustLineHeader(PlaceRange.BeginPos, TRUE); | 970 NewRange.BeginPos = AdjustLineHeader(PlaceRange.BeginPos, TRUE); |
967 NewRange.EndPos = AdjustLineHeader(PlaceRange.EndPos, TRUE); | 971 NewRange.EndPos = AdjustLineHeader(PlaceRange.EndPos, TRUE); |
968 for (int32_t s = NewRange.EndPos.nSecIndex; s >= NewRange.BeginPos.nSecIndex; | 972 for (int32_t s = NewRange.EndPos.nSecIndex; s >= NewRange.BeginPos.nSecIndex; |
969 s--) { | 973 s--) { |
970 if (CSection* pSection = m_SectionArray.GetAt(s)) | 974 if (CSection* pSection = m_SectionArray.GetAt(s)) |
971 pSection->ClearWords(NewRange); | 975 pSection->ClearWords(NewRange); |
972 } | 976 } |
973 } | 977 } |
974 | 978 |
975 CPVT_WordPlace CPDF_VariableText::ClearLeftWord(const CPVT_WordPlace& place) { | 979 CPVT_WordPlace CPDF_VariableText::ClearLeftWord(const CPVT_WordPlace& place) { |
976 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 980 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
977 CPVT_WordPlace leftplace = GetPrevWordPlace(place); | 981 CPVT_WordPlace leftplace = GetPrevWordPlace(place); |
978 if (leftplace != place) { | 982 if (leftplace != place) { |
979 if (leftplace.nSecIndex != place.nSecIndex) { | 983 if (leftplace.nSecIndex != place.nSecIndex) { |
980 if (pSection->m_WordArray.GetSize() == 0) | 984 if (pSection->IsWordArrayEmpty()) |
981 ClearEmptySection(place); | 985 ClearEmptySection(place); |
982 else | 986 else |
983 LinkLatterSection(leftplace); | 987 LinkLatterSection(leftplace); |
984 } else { | 988 } else { |
985 pSection->ClearWord(place); | 989 pSection->ClearWord(place); |
986 } | 990 } |
987 } | 991 } |
988 return leftplace; | 992 return leftplace; |
989 } | 993 } |
990 return place; | 994 return place; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1046 continue; | 1050 continue; |
1047 } else { | 1051 } else { |
1048 nLeft = nMid + 1; | 1052 nLeft = nMid + 1; |
1049 nMid = (nLeft + nRight) / 2; | 1053 nMid = (nLeft + nRight) / 2; |
1050 continue; | 1054 continue; |
1051 } | 1055 } |
1052 } | 1056 } |
1053 return (FX_FLOAT)gFontSizeSteps[nMid]; | 1057 return (FX_FLOAT)gFontSizeSteps[nMid]; |
1054 } | 1058 } |
1055 | 1059 |
1056 FX_BOOL CPDF_VariableText::IsBigger(FX_FLOAT fFontSize) { | 1060 bool CPDF_VariableText::IsBigger(FX_FLOAT fFontSize) const { |
1057 FX_BOOL bBigger = FALSE; | 1061 CFX_PointF szTotal; |
1058 CPVT_Size szTotal; | |
1059 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { | 1062 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { |
1060 if (CSection* pSection = m_SectionArray.GetAt(s)) { | 1063 if (CSection* pSection = m_SectionArray.GetAt(s)) { |
1061 CPVT_Size size = pSection->GetSectionSize(fFontSize); | 1064 CFX_PointF size = pSection->GetSectionSize(fFontSize); |
1062 szTotal.x = std::max(size.x, szTotal.x); | 1065 szTotal.x = std::max(size.x, szTotal.x); |
1063 szTotal.y += size.y; | 1066 szTotal.y += size.y; |
1064 if (IsFloatBigger(szTotal.x, GetPlateWidth()) || | 1067 if (IsFloatBigger(szTotal.x, GetPlateWidth()) || |
1065 IsFloatBigger(szTotal.y, GetPlateHeight())) { | 1068 IsFloatBigger(szTotal.y, GetPlateHeight())) { |
1066 bBigger = TRUE; | 1069 return true; |
1067 break; | |
1068 } | 1070 } |
1069 } | 1071 } |
1070 } | 1072 } |
1071 return bBigger; | 1073 return false; |
1072 } | 1074 } |
1073 | 1075 |
1074 CPVT_FloatRect CPDF_VariableText::RearrangeSections( | 1076 CPVT_FloatRect CPDF_VariableText::RearrangeSections( |
1075 const CPVT_WordRange& PlaceRange) { | 1077 const CPVT_WordRange& PlaceRange) { |
1076 CPVT_WordPlace place; | 1078 CPVT_WordPlace place; |
1077 FX_FLOAT fPosY = 0; | 1079 FX_FLOAT fPosY = 0; |
1078 FX_FLOAT fOldHeight; | 1080 FX_FLOAT fOldHeight; |
1079 int32_t nSSecIndex = PlaceRange.BeginPos.nSecIndex; | 1081 int32_t nSSecIndex = PlaceRange.BeginPos.nSecIndex; |
1080 int32_t nESecIndex = PlaceRange.EndPos.nSecIndex; | 1082 int32_t nESecIndex = PlaceRange.EndPos.nSecIndex; |
1081 CPVT_FloatRect rcRet; | 1083 CPVT_FloatRect rcRet; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1152 m_pVTIterator = new CPDF_VariableText::Iterator(this); | 1154 m_pVTIterator = new CPDF_VariableText::Iterator(this); |
1153 return m_pVTIterator; | 1155 return m_pVTIterator; |
1154 } | 1156 } |
1155 | 1157 |
1156 CPDF_VariableText::Provider* CPDF_VariableText::SetProvider( | 1158 CPDF_VariableText::Provider* CPDF_VariableText::SetProvider( |
1157 CPDF_VariableText::Provider* pProvider) { | 1159 CPDF_VariableText::Provider* pProvider) { |
1158 CPDF_VariableText::Provider* pOld = m_pVTProvider; | 1160 CPDF_VariableText::Provider* pOld = m_pVTProvider; |
1159 m_pVTProvider = pProvider; | 1161 m_pVTProvider = pProvider; |
1160 return pOld; | 1162 return pOld; |
1161 } | 1163 } |
OLD | NEW |