From 2334660053e044ca79a1831a6c73f69891f039e0 Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Tue, 30 Jan 2018 21:42:41 +0000 Subject: Use unsigned for char width MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: 806612 Change-Id: I22bd9046dd37a1b596762c46a6b29a323d6e9fa1 Reviewed-on: https://pdfium-review.googlesource.com/24410 Reviewed-by: dsinclair Commit-Queue: Nicolás Peña Moreno --- core/fpdftext/cpdf_textpage.cpp | 21 +++++++++++---------- core/fpdftext/cpdf_textpage.h | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'core/fpdftext') 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(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); -- cgit v1.2.3