Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Side by Side Diff: core/fpdftext/fpdf_text_int.cpp

Issue 1815453002: Handle empty objects in IsSameTextObject() and free from warning (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: address comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "core/fpdftext/fpdf_text_int.h" 7 #include "core/fpdftext/fpdf_text_int.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cctype> 10 #include <cctype>
(...skipping 1784 matching lines...) Expand 10 before | Expand all | Expand 10 after
1795 } 1795 }
1796 if (pTextObj2->GetFontSize() != pTextObj1->GetFontSize()) { 1796 if (pTextObj2->GetFontSize() != pTextObj1->GetFontSize()) {
1797 return FALSE; 1797 return FALSE;
1798 } 1798 }
1799 } 1799 }
1800 int nPreCount = pTextObj2->CountItems(); 1800 int nPreCount = pTextObj2->CountItems();
1801 int nCurCount = pTextObj1->CountItems(); 1801 int nCurCount = pTextObj1->CountItems();
1802 if (nPreCount != nCurCount) { 1802 if (nPreCount != nCurCount) {
1803 return FALSE; 1803 return FALSE;
1804 } 1804 }
1805 CPDF_TextObjectItem itemPer, itemCur; 1805 // If both objects have no items, consider them same.
1806 if (!nPreCount)
1807 return TRUE;
1808
1809 CPDF_TextObjectItem itemPer = {0, 0.0f, 0.0f};
1810 CPDF_TextObjectItem itemCur = {0, 0.0f, 0.0f};
1806 for (int i = 0; i < nPreCount; i++) { 1811 for (int i = 0; i < nPreCount; i++) {
1807 pTextObj2->GetItemInfo(i, &itemPer); 1812 pTextObj2->GetItemInfo(i, &itemPer);
1808 pTextObj1->GetItemInfo(i, &itemCur); 1813 pTextObj1->GetItemInfo(i, &itemCur);
1809 if (itemCur.m_CharCode != itemPer.m_CharCode) { 1814 if (itemCur.m_CharCode != itemPer.m_CharCode) {
1810 return FALSE; 1815 return FALSE;
1811 } 1816 }
1812 } 1817 }
1813 if (FXSYS_fabs(pTextObj1->GetPosX() - pTextObj2->GetPosX()) > 1818 if (FXSYS_fabs(pTextObj1->GetPosX() - pTextObj2->GetPosX()) >
1814 GetCharWidth(itemPer.m_CharCode, pTextObj2->GetFont()) * 1819 GetCharWidth(itemPer.m_CharCode, pTextObj2->GetFont()) *
1815 pTextObj2->GetFontSize() / 1000 * 0.9 || 1820 pTextObj2->GetFontSize() / 1000 * 0.9 ||
1816 FXSYS_fabs(pTextObj1->GetPosY() - pTextObj2->GetPosY()) > 1821 FXSYS_fabs(pTextObj1->GetPosY() - pTextObj2->GetPosY()) >
1817 std::max(std::max(rcPreObj.Height(), rcPreObj.Width()), 1822 std::max(std::max(rcPreObj.Height(), rcPreObj.Width()),
1818 pTextObj2->GetFontSize()) / 1823 pTextObj2->GetFontSize()) /
1819 8) { 1824 8) {
1820 return FALSE; 1825 return FALSE;
1821 } 1826 }
1822 return TRUE; 1827 return TRUE;
1823 } 1828 }
1829
1824 FX_BOOL CPDF_TextPage::IsSameAsPreTextObject( 1830 FX_BOOL CPDF_TextPage::IsSameAsPreTextObject(
1825 CPDF_TextObject* pTextObj, 1831 CPDF_TextObject* pTextObj,
1826 const CPDF_PageObjectList* pObjList, 1832 const CPDF_PageObjectList* pObjList,
1827 CPDF_PageObjectList::const_iterator iter) { 1833 CPDF_PageObjectList::const_iterator iter) {
1828 int i = 0; 1834 int i = 0;
1829 while (i < 5 && iter != pObjList->begin()) { 1835 while (i < 5 && iter != pObjList->begin()) {
1830 --iter; 1836 --iter;
1831 CPDF_PageObject* pOtherObj = iter->get(); 1837 CPDF_PageObject* pOtherObj = iter->get();
1832 if (pOtherObj == pTextObj || !pOtherObj->IsText()) 1838 if (pOtherObj == pTextObj || !pOtherObj->IsText())
1833 continue; 1839 continue;
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
2501 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) { 2507 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) {
2502 return; 2508 return;
2503 } 2509 }
2504 CPDF_LinkExt* link = NULL; 2510 CPDF_LinkExt* link = NULL;
2505 link = m_LinkList.GetAt(index); 2511 link = m_LinkList.GetAt(index);
2506 if (!link) { 2512 if (!link) {
2507 return; 2513 return;
2508 } 2514 }
2509 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); 2515 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects);
2510 } 2516 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698