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 --- fpdfsdk/fpdfedit_embeddertest.cpp | 4 ++-- fpdfsdk/fpdfedittext.cpp | 7 ++++++- fpdfsdk/pwl/cpwl_edit_impl.cpp | 4 ++-- fpdfsdk/pwl/cpwl_edit_impl.h | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp index ee2fc7eb85..070c51e3b6 100644 --- a/fpdfsdk/fpdfedit_embeddertest.cpp +++ b/fpdfsdk/fpdfedit_embeddertest.cpp @@ -105,7 +105,7 @@ class FPDFEditEmbeddertest : public EmbedderTest { int cnt = static_cast(arr->GetCount()); size_t inner_idx = 0; for (cur_cid = cid; cur_cid < cid + cnt; cur_cid++) { - int width = arr->GetNumberAt(inner_idx++); + uint32_t width = arr->GetNumberAt(inner_idx++); EXPECT_EQ(width, typed_font->GetCharWidthF(cur_cid)) << " at cid " << cur_cid; } @@ -116,7 +116,7 @@ class FPDFEditEmbeddertest : public EmbedderTest { ASSERT_TRUE(next->IsNumber()); int last_cid = next->AsNumber()->GetInteger(); ASSERT_FALSE(++idx == widths_array->GetCount()); - int width = widths_array->GetNumberAt(idx); + uint32_t width = widths_array->GetNumberAt(idx); for (cur_cid = cid; cur_cid <= last_cid; cur_cid++) { EXPECT_EQ(width, typed_font->GetCharWidthF(cur_cid)) << " at cid " << cur_cid; diff --git a/fpdfsdk/fpdfedittext.cpp b/fpdfsdk/fpdfedittext.cpp index 22c6266ec1..7bbb6a857c 100644 --- a/fpdfsdk/fpdfedittext.cpp +++ b/fpdfsdk/fpdfedittext.cpp @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include +#include #include #include #include @@ -259,7 +261,10 @@ void* LoadSimpleFont(CPDF_Document* pDoc, fontDict->SetNewFor("FirstChar", static_cast(currentChar)); CPDF_Array* widthsArray = pDoc->NewIndirect(); while (true) { - widthsArray->AddNew(pFont->GetGlyphWidth(glyphIndex)); + uint32_t width = + std::min(pFont->GetGlyphWidth(glyphIndex), + static_cast(std::numeric_limits::max())); + widthsArray->AddNew(static_cast(width)); uint32_t nextChar = FXFT_Get_Next_Char(pFont->GetFace(), currentChar, &glyphIndex); // Simple fonts have 1-byte charcodes only. diff --git a/fpdfsdk/pwl/cpwl_edit_impl.cpp b/fpdfsdk/pwl/cpwl_edit_impl.cpp index 1881ba2c28..91496f0c8d 100644 --- a/fpdfsdk/pwl/cpwl_edit_impl.cpp +++ b/fpdfsdk/pwl/cpwl_edit_impl.cpp @@ -125,8 +125,8 @@ IPVT_FontMap* CPWL_EditImpl_Provider::GetFontMap() const { return m_pFontMap; } -int32_t CPWL_EditImpl_Provider::GetCharWidth(int32_t nFontIndex, - uint16_t word) { +uint32_t CPWL_EditImpl_Provider::GetCharWidth(int32_t nFontIndex, + uint16_t word) { if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { uint32_t charcode = word; diff --git a/fpdfsdk/pwl/cpwl_edit_impl.h b/fpdfsdk/pwl/cpwl_edit_impl.h index 38477db427..7f4d3e108b 100644 --- a/fpdfsdk/pwl/cpwl_edit_impl.h +++ b/fpdfsdk/pwl/cpwl_edit_impl.h @@ -423,7 +423,7 @@ class CPWL_EditImpl_Provider : public CPDF_VariableText::Provider { IPVT_FontMap* GetFontMap() const; // CPDF_VariableText::Provider: - int32_t GetCharWidth(int32_t nFontIndex, uint16_t word) override; + uint32_t GetCharWidth(int32_t nFontIndex, uint16_t word) override; int32_t GetTypeAscent(int32_t nFontIndex) override; int32_t GetTypeDescent(int32_t nFontIndex) override; int32_t GetWordFontIndex(uint16_t word, -- cgit v1.2.3