From 1cb4d6b14cc9375dc04f57d3f2149eccb9e327a8 Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Fri, 24 Aug 2018 17:55:00 +0000 Subject: Cleanup CalculateBaseSpace in CPDF_TextPage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iaa3e8d88083d7ac15762ff2d5d74a378f626483c Reviewed-on: https://pdfium-review.googlesource.com/41350 Reviewed-by: Henrique Nakashima Commit-Queue: Nicolás Peña Moreno --- core/fpdftext/cpdf_textpage.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp index 8375d1f8cc..7ddf6d9282 100644 --- a/core/fpdftext/cpdf_textpage.cpp +++ b/core/fpdftext/cpdf_textpage.cpp @@ -48,26 +48,27 @@ float NormalizeThreshold(float threshold, int t1, int t2, int t3) { float CalculateBaseSpace(const CPDF_TextObject* pTextObj, const CFX_Matrix& matrix) { - float baseSpace = 0.0; const size_t nItems = pTextObj->CountItems(); - if (pTextObj->m_TextState.GetCharSpace() && nItems >= 3) { - bool bAllChar = true; - float spacing = - matrix.TransformDistance(pTextObj->m_TextState.GetCharSpace()); - baseSpace = spacing; - for (size_t i = 0; i < nItems; ++i) { - CPDF_TextObjectItem item; - pTextObj->GetItemInfo(i, &item); - if (item.m_CharCode == static_cast(-1)) { - float fontsize_h = pTextObj->m_TextState.GetFontSizeH(); - float kerning = -fontsize_h * item.m_Origin.x / 1000; - baseSpace = std::min(baseSpace, kerning + spacing); - bAllChar = false; - } + if (!pTextObj->m_TextState.GetCharSpace() || nItems < 3) + return 0.0f; + + bool bAllChar = true; + float spacing = + matrix.TransformDistance(pTextObj->m_TextState.GetCharSpace()); + float baseSpace = spacing; + for (size_t i = 0; i < nItems; ++i) { + CPDF_TextObjectItem item; + pTextObj->GetItemInfo(i, &item); + if (item.m_CharCode == static_cast(-1)) { + float fontsize_h = pTextObj->m_TextState.GetFontSizeH(); + float kerning = -fontsize_h * item.m_Origin.x / 1000; + baseSpace = std::min(baseSpace, kerning + spacing); + bAllChar = false; } - if (baseSpace < 0.0 || (nItems == 3 && !bAllChar)) - baseSpace = 0.0; } + if (baseSpace < 0.0 || (nItems == 3 && !bAllChar)) + return 0.0f; + return baseSpace; } @@ -90,7 +91,7 @@ size_t Unicode_GetNormalization(wchar_t wch, wchar_t* pDst) { wFind >>= 12; const uint16_t* pMap = g_UnicodeData_Normalization_Maps[wFind - 2] + wch; if (wFind == 4) - wFind = (wchar_t)(*pMap++); + wFind = static_cast(*pMap++); if (pDst) { wchar_t n = wFind; -- cgit v1.2.3