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

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

Issue 1840483003: Reduce signed/unsigned comparison warnings (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: rebase Created 4 years, 8 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 | « core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp ('k') | core/fxcodec/codec/fx_codec_flate.cpp » ('j') | 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 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 if (pPageObj->IsText()) { 891 if (pPageObj->IsText()) {
892 ProcessTextObject(pPageObj->AsText(), curFormMatrix, pObjectList, it); 892 ProcessTextObject(pPageObj->AsText(), curFormMatrix, pObjectList, it);
893 } else if (pPageObj->IsForm()) { 893 } else if (pPageObj->IsForm()) {
894 ProcessFormObject(pPageObj->AsForm(), curFormMatrix); 894 ProcessFormObject(pPageObj->AsForm(), curFormMatrix);
895 } 895 }
896 } 896 }
897 } 897 }
898 } 898 }
899 899
900 int CPDF_TextPage::GetCharWidth(uint32_t charCode, CPDF_Font* pFont) const { 900 int CPDF_TextPage::GetCharWidth(uint32_t charCode, CPDF_Font* pFont) const {
901 if (charCode == -1) 901 if (charCode == CPDF_Font::kInvalidCharCode)
902 return 0; 902 return 0;
903 903
904 if (int w = pFont->GetCharWidthF(charCode)) 904 if (int w = pFont->GetCharWidthF(charCode))
905 return w; 905 return w;
906 906
907 CFX_ByteString str; 907 CFX_ByteString str;
908 pFont->AppendChar(str, charCode); 908 pFont->AppendChar(str, charCode);
909 if (int w = pFont->GetStringWidth(str, 1)) 909 if (int w = pFont->GetStringWidth(str, 1))
910 return w; 910 return w;
911 911
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 return FPDFTEXT_MC_DONE; 1142 return FPDFTEXT_MC_DONE;
1143 } 1143 }
1144 } 1144 }
1145 FX_STRSIZE nItems = actText.GetLength(); 1145 FX_STRSIZE nItems = actText.GetLength();
1146 if (nItems < 1) 1146 if (nItems < 1)
1147 return FPDFTEXT_MC_PASS; 1147 return FPDFTEXT_MC_PASS;
1148 1148
1149 CPDF_Font* pFont = pTextObj->GetFont(); 1149 CPDF_Font* pFont = pTextObj->GetFont();
1150 bExist = FALSE; 1150 bExist = FALSE;
1151 for (FX_STRSIZE i = 0; i < nItems; i++) { 1151 for (FX_STRSIZE i = 0; i < nItems; i++) {
1152 if (pFont->CharCodeFromUnicode(actText.GetAt(i)) != -1) { 1152 if (pFont->CharCodeFromUnicode(actText.GetAt(i)) !=
1153 CPDF_Font::kInvalidCharCode) {
1153 bExist = TRUE; 1154 bExist = TRUE;
1154 break; 1155 break;
1155 } 1156 }
1156 } 1157 }
1157 if (!bExist) 1158 if (!bExist)
1158 return FPDFTEXT_MC_PASS; 1159 return FPDFTEXT_MC_PASS;
1159 1160
1160 bExist = FALSE; 1161 bExist = FALSE;
1161 for (FX_STRSIZE i = 0; i < nItems; i++) { 1162 for (FX_STRSIZE i = 0; i < nItems; i++) {
1162 FX_WCHAR wChar = actText.GetAt(i); 1163 FX_WCHAR wChar = actText.GetAt(i);
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 spacing += matrix.TransformDistance(charSpace); 1411 spacing += matrix.TransformDistance(charSpace);
1411 } else if (charSpace < -0.001) { 1412 } else if (charSpace < -0.001) {
1412 spacing -= matrix.TransformDistance(FXSYS_fabs(charSpace)); 1413 spacing -= matrix.TransformDistance(FXSYS_fabs(charSpace));
1413 } 1414 }
1414 spacing -= baseSpace; 1415 spacing -= baseSpace;
1415 if (spacing && i > 0) { 1416 if (spacing && i > 0) {
1416 int last_width = 0; 1417 int last_width = 0;
1417 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); 1418 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH();
1418 uint32_t space_charcode = pFont->CharCodeFromUnicode(' '); 1419 uint32_t space_charcode = pFont->CharCodeFromUnicode(' ');
1419 FX_FLOAT threshold = 0; 1420 FX_FLOAT threshold = 0;
1420 if (space_charcode != -1) { 1421 if (space_charcode != CPDF_Font::kInvalidCharCode) {
1421 threshold = fontsize_h * pFont->GetCharWidthF(space_charcode) / 1000; 1422 threshold = fontsize_h * pFont->GetCharWidthF(space_charcode) / 1000;
1422 } 1423 }
1423 if (threshold > fontsize_h / 3) { 1424 if (threshold > fontsize_h / 3) {
1424 threshold = 0; 1425 threshold = 0;
1425 } else { 1426 } else {
1426 threshold /= 2; 1427 threshold /= 2;
1427 } 1428 }
1428 if (threshold == 0) { 1429 if (threshold == 0) {
1429 threshold = fontsize_h; 1430 threshold = fontsize_h;
1430 int this_width = FXSYS_abs(GetCharWidth(item.m_CharCode, pFont)); 1431 int this_width = FXSYS_abs(GetCharWidth(item.m_CharCode, pFont));
1431 threshold = this_width > last_width ? (FX_FLOAT)this_width 1432 threshold = this_width > last_width ? (FX_FLOAT)this_width
1432 : (FX_FLOAT)last_width; 1433 : (FX_FLOAT)last_width;
1433 threshold = _NormalizeThreshold(threshold); 1434 threshold = _NormalizeThreshold(threshold);
1434 threshold = fontsize_h * threshold / 1000; 1435 threshold = fontsize_h * threshold / 1000;
1435 } 1436 }
1436 if (threshold && (spacing && spacing >= threshold)) { 1437 if (threshold && (spacing && spacing >= threshold)) {
1437 charinfo.m_Unicode = TEXT_BLANK_CHAR; 1438 charinfo.m_Unicode = TEXT_BLANK_CHAR;
1438 charinfo.m_Flag = FPDFTEXT_CHAR_GENERATED; 1439 charinfo.m_Flag = FPDFTEXT_CHAR_GENERATED;
1439 charinfo.m_pTextObj = pTextObj; 1440 charinfo.m_pTextObj = pTextObj;
1440 charinfo.m_Index = m_TextBuf.GetLength(); 1441 charinfo.m_Index = m_TextBuf.GetLength();
1441 m_TempTextBuf.AppendChar(TEXT_BLANK_CHAR); 1442 m_TempTextBuf.AppendChar(TEXT_BLANK_CHAR);
1442 charinfo.m_CharCode = -1; 1443 charinfo.m_CharCode = CPDF_Font::kInvalidCharCode;
1443 charinfo.m_Matrix.Copy(formMatrix); 1444 charinfo.m_Matrix.Copy(formMatrix);
1444 matrix.Transform(item.m_OriginX, item.m_OriginY, charinfo.m_OriginX, 1445 matrix.Transform(item.m_OriginX, item.m_OriginY, charinfo.m_OriginX,
1445 charinfo.m_OriginY); 1446 charinfo.m_OriginY);
1446 charinfo.m_CharBox = 1447 charinfo.m_CharBox =
1447 CFX_FloatRect(charinfo.m_OriginX, charinfo.m_OriginY, 1448 CFX_FloatRect(charinfo.m_OriginX, charinfo.m_OriginY,
1448 charinfo.m_OriginX, charinfo.m_OriginY); 1449 charinfo.m_OriginX, charinfo.m_OriginY);
1449 m_TempCharList.push_back(charinfo); 1450 m_TempCharList.push_back(charinfo);
1450 } 1451 }
1451 if (item.m_CharCode == (uint32_t)-1) { 1452 if (item.m_CharCode == CPDF_Font::kInvalidCharCode) {
1452 continue; 1453 continue;
1453 } 1454 }
1454 } 1455 }
1455 spacing = 0; 1456 spacing = 0;
1456 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); 1457 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode);
1457 FX_BOOL bNoUnicode = FALSE; 1458 FX_BOOL bNoUnicode = FALSE;
1458 FX_WCHAR wChar = wstrItem.GetAt(0); 1459 FX_WCHAR wChar = wstrItem.GetAt(0);
1459 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { 1460 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) {
1460 if (wstrItem.IsEmpty()) { 1461 if (wstrItem.IsEmpty()) {
1461 wstrItem += (FX_WCHAR)item.m_CharCode; 1462 wstrItem += (FX_WCHAR)item.m_CharCode;
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1851 if (!m_TempCharList.empty()) { 1852 if (!m_TempCharList.empty()) {
1852 preChar = &m_TempCharList.back(); 1853 preChar = &m_TempCharList.back();
1853 } else if (!m_CharList.empty()) { 1854 } else if (!m_CharList.empty()) {
1854 preChar = &m_CharList.back(); 1855 preChar = &m_CharList.back();
1855 } else { 1856 } else {
1856 return FALSE; 1857 return FALSE;
1857 } 1858 }
1858 info.m_Index = m_TextBuf.GetLength(); 1859 info.m_Index = m_TextBuf.GetLength();
1859 info.m_Unicode = unicode; 1860 info.m_Unicode = unicode;
1860 info.m_pTextObj = NULL; 1861 info.m_pTextObj = NULL;
1861 info.m_CharCode = -1; 1862 info.m_CharCode = CPDF_Font::kInvalidCharCode;
1862 info.m_Flag = FPDFTEXT_CHAR_GENERATED; 1863 info.m_Flag = FPDFTEXT_CHAR_GENERATED;
1863 int preWidth = 0; 1864 int preWidth = 0;
1864 if (preChar->m_pTextObj && preChar->m_CharCode != (uint32_t)-1) 1865 if (preChar->m_pTextObj && preChar->m_CharCode != -1) {
1865 preWidth = 1866 preWidth =
1866 GetCharWidth(preChar->m_CharCode, preChar->m_pTextObj->GetFont()); 1867 GetCharWidth(preChar->m_CharCode, preChar->m_pTextObj->GetFont());
1868 }
1867 1869
1868 FX_FLOAT fFontSize = preChar->m_pTextObj ? preChar->m_pTextObj->GetFontSize() 1870 FX_FLOAT fFontSize = preChar->m_pTextObj ? preChar->m_pTextObj->GetFontSize()
1869 : preChar->m_CharBox.Height(); 1871 : preChar->m_CharBox.Height();
1870 if (!fFontSize) 1872 if (!fFontSize)
1871 fFontSize = kDefaultFontSize; 1873 fFontSize = kDefaultFontSize;
1872 1874
1873 info.m_OriginX = preChar->m_OriginX + preWidth * (fFontSize) / 1000; 1875 info.m_OriginX = preChar->m_OriginX + preWidth * (fFontSize) / 1000;
1874 info.m_OriginY = preChar->m_OriginY; 1876 info.m_OriginY = preChar->m_OriginY;
1875 info.m_CharBox = CFX_FloatRect(info.m_OriginX, info.m_OriginY, info.m_OriginX, 1877 info.m_CharBox = CFX_FloatRect(info.m_OriginX, info.m_OriginY, info.m_OriginX,
1876 info.m_OriginY); 1878 info.m_OriginY);
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
2509 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) { 2511 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) {
2510 return; 2512 return;
2511 } 2513 }
2512 CPDF_LinkExt* link = NULL; 2514 CPDF_LinkExt* link = NULL;
2513 link = m_LinkList.GetAt(index); 2515 link = m_LinkList.GetAt(index);
2514 if (!link) { 2516 if (!link) {
2515 return; 2517 return;
2516 } 2518 }
2517 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); 2519 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects);
2518 } 2520 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp ('k') | core/fxcodec/codec/fx_codec_flate.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698