summaryrefslogtreecommitdiff
path: root/core/fpdftext/cpdf_textpage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdftext/cpdf_textpage.cpp')
-rw-r--r--core/fpdftext/cpdf_textpage.cpp21
1 files changed, 11 insertions, 10 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;