| 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, | 10 const uint8_t gFontSizeSteps[] = {4, 6, 8, 9, 10, 12, 14, 18, 20, |
| (...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 ClearWords(PlaceRange); | 953 ClearWords(PlaceRange); |
| 954 if (PlaceRange.BeginPos.nSecIndex != PlaceRange.EndPos.nSecIndex) { | 954 if (PlaceRange.BeginPos.nSecIndex != PlaceRange.EndPos.nSecIndex) { |
| 955 ClearEmptySections(PlaceRange); | 955 ClearEmptySections(PlaceRange); |
| 956 if (!bLastSecPos) { | 956 if (!bLastSecPos) { |
| 957 LinkLatterSection(PlaceRange.BeginPos); | 957 LinkLatterSection(PlaceRange.BeginPos); |
| 958 } | 958 } |
| 959 } | 959 } |
| 960 return PlaceRange.BeginPos; | 960 return PlaceRange.BeginPos; |
| 961 } | 961 } |
| 962 CPVT_WordPlace CPDF_VariableText::DeleteWord(const CPVT_WordPlace& place) { | 962 CPVT_WordPlace CPDF_VariableText::DeleteWord(const CPVT_WordPlace& place) { |
| 963 return ClearRightWord(AjustLineHeader(place, TRUE)); | 963 return ClearRightWord(AdjustLineHeader(place, TRUE)); |
| 964 } | 964 } |
| 965 CPVT_WordPlace CPDF_VariableText::BackSpaceWord(const CPVT_WordPlace& place) { | 965 CPVT_WordPlace CPDF_VariableText::BackSpaceWord(const CPVT_WordPlace& place) { |
| 966 return ClearLeftWord(AjustLineHeader(place, TRUE)); | 966 return ClearLeftWord(AdjustLineHeader(place, TRUE)); |
| 967 } | 967 } |
| 968 void CPDF_VariableText::SetText(const FX_WCHAR* text, | 968 void CPDF_VariableText::SetText(const FX_WCHAR* text, |
| 969 int32_t charset, | 969 int32_t charset, |
| 970 const CPVT_SecProps* pSecProps, | 970 const CPVT_SecProps* pSecProps, |
| 971 const CPVT_WordProps* pWordProps) { | 971 const CPVT_WordProps* pWordProps) { |
| 972 DeleteWords(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); | 972 DeleteWords(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); |
| 973 CFX_WideString swText = text; | 973 CFX_WideString swText = text; |
| 974 CPVT_WordPlace wp(0, 0, -1); | 974 CPVT_WordPlace wp(0, 0, -1); |
| 975 CPVT_SectionInfo secinfo; | 975 CPVT_SectionInfo secinfo; |
| 976 if (m_bRichText) { | 976 if (m_bRichText) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 nCharCount++; | 1025 nCharCount++; |
| 1026 } | 1026 } |
| 1027 } | 1027 } |
| 1028 void CPDF_VariableText::UpdateWordPlace(CPVT_WordPlace& place) const { | 1028 void CPDF_VariableText::UpdateWordPlace(CPVT_WordPlace& place) const { |
| 1029 if (place.nSecIndex < 0) { | 1029 if (place.nSecIndex < 0) { |
| 1030 place = GetBeginWordPlace(); | 1030 place = GetBeginWordPlace(); |
| 1031 } | 1031 } |
| 1032 if (place.nSecIndex >= m_SectionArray.GetSize()) { | 1032 if (place.nSecIndex >= m_SectionArray.GetSize()) { |
| 1033 place = GetEndWordPlace(); | 1033 place = GetEndWordPlace(); |
| 1034 } | 1034 } |
| 1035 place = AjustLineHeader(place, TRUE); | 1035 place = AdjustLineHeader(place, TRUE); |
| 1036 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 1036 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1037 pSection->UpdateWordPlace(place); | 1037 pSection->UpdateWordPlace(place); |
| 1038 } | 1038 } |
| 1039 } | 1039 } |
| 1040 int32_t CPDF_VariableText::WordPlaceToWordIndex( | 1040 int32_t CPDF_VariableText::WordPlaceToWordIndex( |
| 1041 const CPVT_WordPlace& place) const { | 1041 const CPVT_WordPlace& place) const { |
| 1042 CPVT_WordPlace newplace = place; | 1042 CPVT_WordPlace newplace = place; |
| 1043 UpdateWordPlace(newplace); | 1043 UpdateWordPlace(newplace); |
| 1044 int32_t nIndex = 0; | 1044 int32_t nIndex = 0; |
| 1045 int32_t i = 0; | 1045 int32_t i = 0; |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1422 } | 1422 } |
| 1423 FX_FLOAT CPDF_VariableText::GetCharSpace(const CPVT_WordInfo& WordInfo) { | 1423 FX_FLOAT CPDF_VariableText::GetCharSpace(const CPVT_WordInfo& WordInfo) { |
| 1424 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->fCharSpace | 1424 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->fCharSpace |
| 1425 : m_fCharSpace; | 1425 : m_fCharSpace; |
| 1426 } | 1426 } |
| 1427 int32_t CPDF_VariableText::GetHorzScale(const CPVT_WordInfo& WordInfo) { | 1427 int32_t CPDF_VariableText::GetHorzScale(const CPVT_WordInfo& WordInfo) { |
| 1428 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nHorzScale | 1428 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nHorzScale |
| 1429 : m_nHorzScale; | 1429 : m_nHorzScale; |
| 1430 } | 1430 } |
| 1431 void CPDF_VariableText::ClearSectionRightWords(const CPVT_WordPlace& place) { | 1431 void CPDF_VariableText::ClearSectionRightWords(const CPVT_WordPlace& place) { |
| 1432 CPVT_WordPlace wordplace = AjustLineHeader(place, TRUE); | 1432 CPVT_WordPlace wordplace = AdjustLineHeader(place, TRUE); |
| 1433 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 1433 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1434 for (int32_t w = pSection->m_WordArray.GetSize() - 1; | 1434 for (int32_t w = pSection->m_WordArray.GetSize() - 1; |
| 1435 w > wordplace.nWordIndex; w--) { | 1435 w > wordplace.nWordIndex; w--) { |
| 1436 delete pSection->m_WordArray.GetAt(w); | 1436 delete pSection->m_WordArray.GetAt(w); |
| 1437 pSection->m_WordArray.RemoveAt(w); | 1437 pSection->m_WordArray.RemoveAt(w); |
| 1438 } | 1438 } |
| 1439 } | 1439 } |
| 1440 } | 1440 } |
| 1441 CPVT_WordPlace CPDF_VariableText::AjustLineHeader(const CPVT_WordPlace& place, | 1441 CPVT_WordPlace CPDF_VariableText::AdjustLineHeader(const CPVT_WordPlace& place, |
| 1442 FX_BOOL bPrevOrNext) const { | 1442 FX_BOOL bPrevOrNext) const { |
| 1443 if (place.nWordIndex < 0 && place.nLineIndex > 0) { | 1443 if (place.nWordIndex < 0 && place.nLineIndex > 0) { |
| 1444 return bPrevOrNext ? GetPrevWordPlace(place) : GetNextWordPlace(place); | 1444 return bPrevOrNext ? GetPrevWordPlace(place) : GetNextWordPlace(place); |
| 1445 } | 1445 } |
| 1446 return place; | 1446 return place; |
| 1447 } | 1447 } |
| 1448 FX_BOOL CPDF_VariableText::ClearEmptySection(const CPVT_WordPlace& place) { | 1448 FX_BOOL CPDF_VariableText::ClearEmptySection(const CPVT_WordPlace& place) { |
| 1449 if (place.nSecIndex == 0 && m_SectionArray.GetSize() == 1) { | 1449 if (place.nSecIndex == 0 && m_SectionArray.GetSize() == 1) { |
| 1450 return FALSE; | 1450 return FALSE; |
| 1451 } | 1451 } |
| 1452 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 1452 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1453 if (pSection->m_WordArray.GetSize() == 0) { | 1453 if (pSection->m_WordArray.GetSize() == 0) { |
| 1454 delete pSection; | 1454 delete pSection; |
| 1455 m_SectionArray.RemoveAt(place.nSecIndex); | 1455 m_SectionArray.RemoveAt(place.nSecIndex); |
| 1456 return TRUE; | 1456 return TRUE; |
| 1457 } | 1457 } |
| 1458 } | 1458 } |
| 1459 return FALSE; | 1459 return FALSE; |
| 1460 } | 1460 } |
| 1461 void CPDF_VariableText::ClearEmptySections(const CPVT_WordRange& PlaceRange) { | 1461 void CPDF_VariableText::ClearEmptySections(const CPVT_WordRange& PlaceRange) { |
| 1462 CPVT_WordPlace wordplace; | 1462 CPVT_WordPlace wordplace; |
| 1463 for (int32_t s = PlaceRange.EndPos.nSecIndex; | 1463 for (int32_t s = PlaceRange.EndPos.nSecIndex; |
| 1464 s > PlaceRange.BeginPos.nSecIndex; s--) { | 1464 s > PlaceRange.BeginPos.nSecIndex; s--) { |
| 1465 wordplace.nSecIndex = s; | 1465 wordplace.nSecIndex = s; |
| 1466 ClearEmptySection(wordplace); | 1466 ClearEmptySection(wordplace); |
| 1467 } | 1467 } |
| 1468 } | 1468 } |
| 1469 void CPDF_VariableText::LinkLatterSection(const CPVT_WordPlace& place) { | 1469 void CPDF_VariableText::LinkLatterSection(const CPVT_WordPlace& place) { |
| 1470 CPVT_WordPlace oldplace = AjustLineHeader(place, TRUE); | 1470 CPVT_WordPlace oldplace = AdjustLineHeader(place, TRUE); |
| 1471 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) { | 1471 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) { |
| 1472 if (CSection* pSection = m_SectionArray.GetAt(oldplace.nSecIndex)) { | 1472 if (CSection* pSection = m_SectionArray.GetAt(oldplace.nSecIndex)) { |
| 1473 for (int32_t w = 0, sz = pNextSection->m_WordArray.GetSize(); w < sz; | 1473 for (int32_t w = 0, sz = pNextSection->m_WordArray.GetSize(); w < sz; |
| 1474 w++) { | 1474 w++) { |
| 1475 if (CPVT_WordInfo* pWord = pNextSection->m_WordArray.GetAt(w)) { | 1475 if (CPVT_WordInfo* pWord = pNextSection->m_WordArray.GetAt(w)) { |
| 1476 oldplace.nWordIndex++; | 1476 oldplace.nWordIndex++; |
| 1477 pSection->AddWord(oldplace, *pWord); | 1477 pSection->AddWord(oldplace, *pWord); |
| 1478 } | 1478 } |
| 1479 } | 1479 } |
| 1480 } | 1480 } |
| 1481 delete pNextSection; | 1481 delete pNextSection; |
| 1482 m_SectionArray.RemoveAt(place.nSecIndex + 1); | 1482 m_SectionArray.RemoveAt(place.nSecIndex + 1); |
| 1483 } | 1483 } |
| 1484 } | 1484 } |
| 1485 void CPDF_VariableText::ClearWords(const CPVT_WordRange& PlaceRange) { | 1485 void CPDF_VariableText::ClearWords(const CPVT_WordRange& PlaceRange) { |
| 1486 CPVT_WordRange NewRange; | 1486 CPVT_WordRange NewRange; |
| 1487 NewRange.BeginPos = AjustLineHeader(PlaceRange.BeginPos, TRUE); | 1487 NewRange.BeginPos = AdjustLineHeader(PlaceRange.BeginPos, TRUE); |
| 1488 NewRange.EndPos = AjustLineHeader(PlaceRange.EndPos, TRUE); | 1488 NewRange.EndPos = AdjustLineHeader(PlaceRange.EndPos, TRUE); |
| 1489 for (int32_t s = NewRange.EndPos.nSecIndex; s >= NewRange.BeginPos.nSecIndex; | 1489 for (int32_t s = NewRange.EndPos.nSecIndex; s >= NewRange.BeginPos.nSecIndex; |
| 1490 s--) { | 1490 s--) { |
| 1491 if (CSection* pSection = m_SectionArray.GetAt(s)) { | 1491 if (CSection* pSection = m_SectionArray.GetAt(s)) { |
| 1492 pSection->ClearWords(NewRange); | 1492 pSection->ClearWords(NewRange); |
| 1493 } | 1493 } |
| 1494 } | 1494 } |
| 1495 } | 1495 } |
| 1496 CPVT_WordPlace CPDF_VariableText::ClearLeftWord(const CPVT_WordPlace& place) { | 1496 CPVT_WordPlace CPDF_VariableText::ClearLeftWord(const CPVT_WordPlace& place) { |
| 1497 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 1497 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1498 CPVT_WordPlace leftplace = GetPrevWordPlace(place); | 1498 CPVT_WordPlace leftplace = GetPrevWordPlace(place); |
| 1499 if (leftplace != place) { | 1499 if (leftplace != place) { |
| 1500 if (leftplace.nSecIndex != place.nSecIndex) { | 1500 if (leftplace.nSecIndex != place.nSecIndex) { |
| 1501 if (pSection->m_WordArray.GetSize() == 0) { | 1501 if (pSection->m_WordArray.GetSize() == 0) { |
| 1502 ClearEmptySection(place); | 1502 ClearEmptySection(place); |
| 1503 } else { | 1503 } else { |
| 1504 LinkLatterSection(leftplace); | 1504 LinkLatterSection(leftplace); |
| 1505 } | 1505 } |
| 1506 } else { | 1506 } else { |
| 1507 pSection->ClearWord(place); | 1507 pSection->ClearWord(place); |
| 1508 } | 1508 } |
| 1509 } | 1509 } |
| 1510 return leftplace; | 1510 return leftplace; |
| 1511 } | 1511 } |
| 1512 return place; | 1512 return place; |
| 1513 } | 1513 } |
| 1514 CPVT_WordPlace CPDF_VariableText::ClearRightWord(const CPVT_WordPlace& place) { | 1514 CPVT_WordPlace CPDF_VariableText::ClearRightWord(const CPVT_WordPlace& place) { |
| 1515 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { | 1515 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { |
| 1516 CPVT_WordPlace rightplace = AjustLineHeader(GetNextWordPlace(place), FALSE); | 1516 CPVT_WordPlace rightplace = |
| 1517 AdjustLineHeader(GetNextWordPlace(place), FALSE); |
| 1517 if (rightplace != place) { | 1518 if (rightplace != place) { |
| 1518 if (rightplace.nSecIndex != place.nSecIndex) { | 1519 if (rightplace.nSecIndex != place.nSecIndex) { |
| 1519 LinkLatterSection(place); | 1520 LinkLatterSection(place); |
| 1520 } else { | 1521 } else { |
| 1521 pSection->ClearWord(rightplace); | 1522 pSection->ClearWord(rightplace); |
| 1522 } | 1523 } |
| 1523 } | 1524 } |
| 1524 } | 1525 } |
| 1525 return place; | 1526 return place; |
| 1526 } | 1527 } |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1820 if (pSection->m_SecInfo.pSecProps) { | 1821 if (pSection->m_SecInfo.pSecProps) { |
| 1821 *pSection->m_SecInfo.pSecProps = section.SecProps; | 1822 *pSection->m_SecInfo.pSecProps = section.SecProps; |
| 1822 } | 1823 } |
| 1823 if (pSection->m_SecInfo.pWordProps) { | 1824 if (pSection->m_SecInfo.pWordProps) { |
| 1824 *pSection->m_SecInfo.pWordProps = section.WordProps; | 1825 *pSection->m_SecInfo.pWordProps = section.WordProps; |
| 1825 } | 1826 } |
| 1826 return TRUE; | 1827 return TRUE; |
| 1827 } | 1828 } |
| 1828 return FALSE; | 1829 return FALSE; |
| 1829 } | 1830 } |
| OLD | NEW |