summaryrefslogtreecommitdiff
path: root/core/fpdftext
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2018-01-30 21:42:41 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-01-30 21:42:41 +0000
commit2334660053e044ca79a1831a6c73f69891f039e0 (patch)
tree1114eeb0e18288235dff4ff694a8c7129541a7f2 /core/fpdftext
parent90d9386825b872a0b668eac5dff3e268fa7ad16c (diff)
downloadpdfium-2334660053e044ca79a1831a6c73f69891f039e0.tar.xz
Use unsigned for char widthchromium/3335
Bug: 806612 Change-Id: I22bd9046dd37a1b596762c46a6b29a323d6e9fa1 Reviewed-on: https://pdfium-review.googlesource.com/24410 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Diffstat (limited to 'core/fpdftext')
-rw-r--r--core/fpdftext/cpdf_textpage.cpp21
-rw-r--r--core/fpdftext/cpdf_textpage.h2
2 files changed, 12 insertions, 11 deletions
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index 72097b43e1..16214269ae 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -595,18 +595,22 @@ void CPDF_TextPage::ProcessFormObject(CPDF_FormObject* pFormObj,
}
}
-int CPDF_TextPage::GetCharWidth(uint32_t charCode, CPDF_Font* pFont) const {
+uint32_t CPDF_TextPage::GetCharWidth(uint32_t charCode,
+ CPDF_Font* pFont) const {
if (charCode == CPDF_Font::kInvalidCharCode)
return 0;
- if (int w = pFont->GetCharWidthF(charCode))
+ uint32_t w = pFont->GetCharWidthF(charCode);
+ if (w > 0)
return w;
ByteString str;
pFont->AppendChar(&str, charCode);
- if (int w = pFont->GetStringWidth(str.c_str(), 1))
+ w = pFont->GetStringWidth(str.c_str(), 1);
+ if (w > 0)
return w;
+ ASSERT(pFont->GetCharBBox(charCode).Width() >= 0);
return pFont->GetCharBBox(charCode).Width();
}
@@ -1044,7 +1048,6 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) {
spacing -= matrix.TransformDistance(fabs(charSpace));
spacing -= baseSpace;
if (spacing && i > 0) {
- int last_width = 0;
float fontsize_h = pTextObj->m_TextState.GetFontSizeH();
uint32_t space_charcode = pFont->CharCodeFromUnicode(' ');
float threshold = 0;
@@ -1055,10 +1058,7 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) {
else
threshold /= 2;
if (threshold == 0) {
- threshold = fontsize_h;
- int this_width = abs(GetCharWidth(item.m_CharCode, pFont));
- threshold =
- this_width > last_width ? (float)this_width : (float)last_width;
+ threshold = static_cast<float>(GetCharWidth(item.m_CharCode, pFont));
threshold = NormalizeThreshold(threshold);
threshold = fontsize_h * threshold / 1000;
}
@@ -1275,10 +1275,11 @@ CPDF_TextPage::GenerateCharacter CPDF_TextPage::ProcessInsertObject(
}
float last_pos = PrevItem.m_Origin.x;
- int nLastWidth = GetCharWidth(PrevItem.m_CharCode, m_pPreTextObj->GetFont());
+ uint32_t nLastWidth =
+ GetCharWidth(PrevItem.m_CharCode, m_pPreTextObj->GetFont());
float last_width = nLastWidth * m_pPreTextObj->GetFontSize() / 1000;
last_width = fabs(last_width);
- int nThisWidth = GetCharWidth(item.m_CharCode, pObj->GetFont());
+ uint32_t nThisWidth = GetCharWidth(item.m_CharCode, pObj->GetFont());
float this_width = nThisWidth * pObj->GetFontSize() / 1000;
this_width = fabs(this_width);
float threshold = last_width > this_width ? last_width / 4 : this_width / 4;
diff --git a/core/fpdftext/cpdf_textpage.h b/core/fpdftext/cpdf_textpage.h
index 51d066071e..c87ab00f26 100644
--- a/core/fpdftext/cpdf_textpage.h
+++ b/core/fpdftext/cpdf_textpage.h
@@ -147,7 +147,7 @@ class CPDF_TextPage {
const CPDF_PageObjectList* pObjList,
CPDF_PageObjectList::const_iterator ObjPos);
bool IsSameTextObject(CPDF_TextObject* pTextObj1, CPDF_TextObject* pTextObj2);
- int GetCharWidth(uint32_t charCode, CPDF_Font* pFont) const;
+ uint32_t GetCharWidth(uint32_t charCode, CPDF_Font* pFont) const;
void CloseTempLine();
FPDFText_MarkedContent PreMarkedContent(PDFTEXT_Obj pObj);
void ProcessMarkedContent(PDFTEXT_Obj pObj);