summaryrefslogtreecommitdiff
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
parent90d9386825b872a0b668eac5dff3e268fa7ad16c (diff)
downloadpdfium-chromium/3335.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>
-rw-r--r--core/fpdfapi/font/cpdf_cidfont.cpp4
-rw-r--r--core/fpdfapi/font/cpdf_cidfont.h2
-rw-r--r--core/fpdfapi/font/cpdf_font.cpp4
-rw-r--r--core/fpdfapi/font/cpdf_font.h4
-rw-r--r--core/fpdfapi/font/cpdf_simplefont.cpp2
-rw-r--r--core/fpdfapi/font/cpdf_simplefont.h2
-rw-r--r--core/fpdfapi/font/cpdf_type3char.h4
-rw-r--r--core/fpdfapi/font/cpdf_type3font.cpp2
-rw-r--r--core/fpdfapi/font/cpdf_type3font.h4
-rw-r--r--core/fpdfapi/render/cpdf_charposlist.cpp5
-rw-r--r--core/fpdfdoc/cpdf_variabletext.cpp10
-rw-r--r--core/fpdfdoc/cpdf_variabletext.h4
-rw-r--r--core/fpdftext/cpdf_textpage.cpp21
-rw-r--r--core/fpdftext/cpdf_textpage.h2
-rw-r--r--core/fxge/apple/fx_apple_platform.cpp2
-rw-r--r--core/fxge/cfx_facecache.cpp8
-rw-r--r--core/fxge/cfx_facecache.h12
-rw-r--r--core/fxge/cfx_font.cpp12
-rw-r--r--core/fxge/cfx_font.h12
-rw-r--r--core/fxge/cfx_renderdevice.h2
-rw-r--r--core/fxge/skia/fx_skia_device_unittest.cpp2
-rw-r--r--fpdfsdk/fpdfedit_embeddertest.cpp4
-rw-r--r--fpdfsdk/fpdfedittext.cpp7
-rw-r--r--fpdfsdk/pwl/cpwl_edit_impl.cpp4
-rw-r--r--fpdfsdk/pwl/cpwl_edit_impl.h2
-rw-r--r--fxbarcode/oned/BC_OneDimWriter.cpp6
-rw-r--r--xfa/fgas/font/cfgas_pdffontmgr.cpp5
-rw-r--r--xfa/fgas/layout/cfx_rtfbreak.cpp2
-rw-r--r--xfa/fgas/layout/cfx_txtbreak.cpp2
29 files changed, 82 insertions, 70 deletions
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp
index 21f8addf8f..f17af41eda 100644
--- a/core/fpdfapi/font/cpdf_cidfont.cpp
+++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -514,7 +514,7 @@ FX_RECT CPDF_CIDFont::GetCharBBox(uint32_t charcode) {
return rect;
}
-int CPDF_CIDFont::GetCharWidthF(uint32_t charcode) {
+uint32_t CPDF_CIDFont::GetCharWidthF(uint32_t charcode) {
if (charcode < 0x80 && m_bAnsiWidthsFixed)
return (charcode >= 32 && charcode < 127) ? 500 : 0;
@@ -524,7 +524,7 @@ int CPDF_CIDFont::GetCharWidthF(uint32_t charcode) {
for (size_t i = 0; i < size; i += 3) {
const uint32_t* pEntry = pList + i;
if (IsMetricForCID(pEntry, cid))
- return static_cast<int>(pEntry[2]);
+ return pEntry[2];
}
return m_DefaultWidth;
}
diff --git a/core/fpdfapi/font/cpdf_cidfont.h b/core/fpdfapi/font/cpdf_cidfont.h
index f6ff83d8fa..68fce2ccb6 100644
--- a/core/fpdfapi/font/cpdf_cidfont.h
+++ b/core/fpdfapi/font/cpdf_cidfont.h
@@ -44,7 +44,7 @@ class CPDF_CIDFont : public CPDF_Font {
const CPDF_CIDFont* AsCIDFont() const override;
CPDF_CIDFont* AsCIDFont() override;
int GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) override;
- int GetCharWidthF(uint32_t charcode) override;
+ uint32_t GetCharWidthF(uint32_t charcode) override;
FX_RECT GetCharBBox(uint32_t charcode) override;
uint32_t GetNextChar(const char* pString,
int nStrLen,
diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp
index 8d35739d78..013cdded20 100644
--- a/core/fpdfapi/font/cpdf_font.cpp
+++ b/core/fpdfapi/font/cpdf_font.cpp
@@ -285,9 +285,9 @@ void CPDF_Font::LoadUnicodeMap() const {
m_pToUnicodeMap->Load(pStream);
}
-int CPDF_Font::GetStringWidth(const char* pString, int size) {
+uint32_t CPDF_Font::GetStringWidth(const char* pString, int size) {
int offset = 0;
- int width = 0;
+ uint32_t width = 0;
while (offset < size) {
uint32_t charcode = GetNextChar(pString, size, offset);
width += GetCharWidthF(charcode);
diff --git a/core/fpdfapi/font/cpdf_font.h b/core/fpdfapi/font/cpdf_font.h
index 0468bcb32a..db99efdd1b 100644
--- a/core/fpdfapi/font/cpdf_font.h
+++ b/core/fpdfapi/font/cpdf_font.h
@@ -75,11 +75,11 @@ class CPDF_Font {
void GetFontBBox(FX_RECT& rect) const { rect = m_FontBBox; }
int GetTypeAscent() const { return m_Ascent; }
int GetTypeDescent() const { return m_Descent; }
- int GetStringWidth(const char* pString, int size);
+ uint32_t GetStringWidth(const char* pString, int size);
uint32_t FallbackFontFromCharcode(uint32_t charcode);
int FallbackGlyphFromCharcode(int fallbackFont, uint32_t charcode);
- virtual int GetCharWidthF(uint32_t charcode) = 0;
+ virtual uint32_t GetCharWidthF(uint32_t charcode) = 0;
virtual FX_RECT GetCharBBox(uint32_t charcode) = 0;
CPDF_Document* GetDocument() const { return m_pDocument.Get(); }
diff --git a/core/fpdfapi/font/cpdf_simplefont.cpp b/core/fpdfapi/font/cpdf_simplefont.cpp
index 92965b0948..89f6fe1205 100644
--- a/core/fpdfapi/font/cpdf_simplefont.cpp
+++ b/core/fpdfapi/font/cpdf_simplefont.cpp
@@ -80,7 +80,7 @@ void CPDF_SimpleFont::LoadCharMetrics(int charcode) {
}
}
-int CPDF_SimpleFont::GetCharWidthF(uint32_t charcode) {
+uint32_t CPDF_SimpleFont::GetCharWidthF(uint32_t charcode) {
if (charcode > 0xff)
charcode = 0;
diff --git a/core/fpdfapi/font/cpdf_simplefont.h b/core/fpdfapi/font/cpdf_simplefont.h
index 5291211b24..9cb730d1a1 100644
--- a/core/fpdfapi/font/cpdf_simplefont.h
+++ b/core/fpdfapi/font/cpdf_simplefont.h
@@ -20,7 +20,7 @@ class CPDF_SimpleFont : public CPDF_Font {
~CPDF_SimpleFont() override;
// CPDF_Font
- int GetCharWidthF(uint32_t charcode) override;
+ uint32_t GetCharWidthF(uint32_t charcode) override;
FX_RECT GetCharBBox(uint32_t charcode) override;
int GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) override;
bool IsUnicodeCompatible() const override;
diff --git a/core/fpdfapi/font/cpdf_type3char.h b/core/fpdfapi/font/cpdf_type3char.h
index c9c5555cf4..28baffed3a 100644
--- a/core/fpdfapi/font/cpdf_type3char.h
+++ b/core/fpdfapi/font/cpdf_type3char.h
@@ -38,7 +38,7 @@ class CPDF_Type3Char {
CPDF_Form* form() { return m_pForm.get(); }
bool colored() const { return m_bColored; }
- int width() const { return m_Width; }
+ uint32_t width() const { return m_Width; }
const CFX_Matrix& matrix() const { return m_ImageMatrix; }
const FX_RECT& bbox() const { return m_BBox; }
@@ -46,7 +46,7 @@ class CPDF_Type3Char {
std::unique_ptr<CPDF_Form> m_pForm;
RetainPtr<CFX_DIBitmap> m_pBitmap;
bool m_bColored = false;
- int m_Width = 0;
+ uint32_t m_Width = 0;
CFX_Matrix m_ImageMatrix;
FX_RECT m_BBox;
};
diff --git a/core/fpdfapi/font/cpdf_type3font.cpp b/core/fpdfapi/font/cpdf_type3font.cpp
index b3eaef0e06..824d6f45d0 100644
--- a/core/fpdfapi/font/cpdf_type3font.cpp
+++ b/core/fpdfapi/font/cpdf_type3font.cpp
@@ -130,7 +130,7 @@ CPDF_Type3Char* CPDF_Type3Font::LoadChar(uint32_t charcode) {
return pCachedChar;
}
-int CPDF_Type3Font::GetCharWidthF(uint32_t charcode) {
+uint32_t CPDF_Type3Font::GetCharWidthF(uint32_t charcode) {
if (charcode >= FX_ArraySize(m_CharWidthL))
charcode = 0;
diff --git a/core/fpdfapi/font/cpdf_type3font.h b/core/fpdfapi/font/cpdf_type3font.h
index 3f2e018c88..67400d5710 100644
--- a/core/fpdfapi/font/cpdf_type3font.h
+++ b/core/fpdfapi/font/cpdf_type3font.h
@@ -26,7 +26,7 @@ class CPDF_Type3Font : public CPDF_SimpleFont {
bool IsType3Font() const override;
const CPDF_Type3Font* AsType3Font() const override;
CPDF_Type3Font* AsType3Font() override;
- int GetCharWidthF(uint32_t charcode) override;
+ uint32_t GetCharWidthF(uint32_t charcode) override;
FX_RECT GetCharBBox(uint32_t charcode) override;
void SetPageResources(CPDF_Dictionary* pResources) {
@@ -47,7 +47,7 @@ class CPDF_Type3Font : public CPDF_SimpleFont {
// CPDF_SimpleFont:
void LoadGlyphMap() override;
- int m_CharWidthL[256];
+ uint32_t m_CharWidthL[256];
UnownedPtr<CPDF_Dictionary> m_pCharProcs;
UnownedPtr<CPDF_Dictionary> m_pPageResources;
UnownedPtr<CPDF_Dictionary> m_pFontResources;
diff --git a/core/fpdfapi/render/cpdf_charposlist.cpp b/core/fpdfapi/render/cpdf_charposlist.cpp
index c0c700c0ca..ddb215c48b 100644
--- a/core/fpdfapi/render/cpdf_charposlist.cpp
+++ b/core/fpdfapi/render/cpdf_charposlist.cpp
@@ -69,8 +69,8 @@ void CPDF_CharPosList::Load(const std::vector<uint32_t>& charCodes,
float scalingFactor = 1.0f;
if (!pFont->IsEmbedded() && pFont->HasFontWidths() && !bVertWriting &&
!pCurrentFont->GetSubstFont()->m_bFlagMM) {
- int pdfGlyphWidth = pFont->GetCharWidthF(CharCode);
- int ftGlyphWidth =
+ uint32_t pdfGlyphWidth = pFont->GetCharWidthF(CharCode);
+ uint32_t ftGlyphWidth =
pCurrentFont ? pCurrentFont->GetGlyphWidth(charpos.m_GlyphIndex) : 0;
if (ftGlyphWidth && pdfGlyphWidth > ftGlyphWidth + 1) {
// Move the initial x position by half of the excess (transformed to
@@ -80,7 +80,6 @@ void CPDF_CharPosList::Load(const std::vector<uint32_t>& charCodes,
} else if (pdfGlyphWidth && ftGlyphWidth &&
pdfGlyphWidth < ftGlyphWidth) {
scalingFactor = static_cast<float>(pdfGlyphWidth) / ftGlyphWidth;
- ASSERT(scalingFactor >= 0.0f);
charpos.m_AdjustMatrix[0] = scalingFactor;
charpos.m_AdjustMatrix[1] = 0.0f;
charpos.m_AdjustMatrix[2] = 0.0f;
diff --git a/core/fpdfdoc/cpdf_variabletext.cpp b/core/fpdfdoc/cpdf_variabletext.cpp
index 74ea239cc6..38c631d820 100644
--- a/core/fpdfdoc/cpdf_variabletext.cpp
+++ b/core/fpdfdoc/cpdf_variabletext.cpp
@@ -38,8 +38,8 @@ CPDF_VariableText::Provider::Provider(IPVT_FontMap* pFontMap)
CPDF_VariableText::Provider::~Provider() {}
-int32_t CPDF_VariableText::Provider::GetCharWidth(int32_t nFontIndex,
- uint16_t word) {
+uint32_t CPDF_VariableText::Provider::GetCharWidth(int32_t nFontIndex,
+ uint16_t word) {
if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) {
uint32_t charcode = pPDFFont->CharCodeFromUnicode(word);
if (charcode != CPDF_Font::kInvalidCharCode)
@@ -917,9 +917,9 @@ CPVT_FloatRect CPDF_VariableText::RearrangeSections(
return rcRet;
}
-int32_t CPDF_VariableText::GetCharWidth(int32_t nFontIndex,
- uint16_t Word,
- uint16_t SubWord) {
+uint32_t CPDF_VariableText::GetCharWidth(int32_t nFontIndex,
+ uint16_t Word,
+ uint16_t SubWord) {
if (!m_pVTProvider)
return 0;
uint16_t word = SubWord ? SubWord : Word;
diff --git a/core/fpdfdoc/cpdf_variabletext.h b/core/fpdfdoc/cpdf_variabletext.h
index a939dcb0e1..786ad10f3e 100644
--- a/core/fpdfdoc/cpdf_variabletext.h
+++ b/core/fpdfdoc/cpdf_variabletext.h
@@ -53,7 +53,7 @@ class CPDF_VariableText {
explicit Provider(IPVT_FontMap* pFontMap);
virtual ~Provider();
- virtual int32_t GetCharWidth(int32_t nFontIndex, uint16_t word);
+ virtual uint32_t GetCharWidth(int32_t nFontIndex, uint16_t word);
virtual int32_t GetTypeAscent(int32_t nFontIndex);
virtual int32_t GetTypeDescent(int32_t nFontIndex);
virtual int32_t GetWordFontIndex(uint16_t word,
@@ -165,7 +165,7 @@ class CPDF_VariableText {
float GetLineIndent();
private:
- int32_t GetCharWidth(int32_t nFontIndex, uint16_t Word, uint16_t SubWord);
+ uint32_t GetCharWidth(int32_t nFontIndex, uint16_t Word, uint16_t SubWord);
int32_t GetTypeAscent(int32_t nFontIndex);
int32_t GetTypeDescent(int32_t nFontIndex);
int32_t GetWordFontIndex(uint16_t word, int32_t charset, int32_t nFontIndex);
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);
diff --git a/core/fxge/apple/fx_apple_platform.cpp b/core/fxge/apple/fx_apple_platform.cpp
index 3c142c6984..1801814e66 100644
--- a/core/fxge/apple/fx_apple_platform.cpp
+++ b/core/fxge/apple/fx_apple_platform.cpp
@@ -169,7 +169,7 @@ std::unique_ptr<CFX_GlyphBitmap> CFX_FaceCache::RenderGlyph_Nativetext(
const CFX_Font* pFont,
uint32_t glyph_index,
const CFX_Matrix* pMatrix,
- int dest_width,
+ uint32_t dest_width,
int anti_alias) {
return nullptr;
}
diff --git a/core/fxge/cfx_facecache.cpp b/core/fxge/cfx_facecache.cpp
index 4f373fff89..ea72905f1b 100644
--- a/core/fxge/cfx_facecache.cpp
+++ b/core/fxge/cfx_facecache.cpp
@@ -73,7 +73,7 @@ std::unique_ptr<CFX_GlyphBitmap> CFX_FaceCache::RenderGlyph(
uint32_t glyph_index,
bool bFontStyle,
const CFX_Matrix* pMatrix,
- int dest_width,
+ uint32_t dest_width,
int anti_alias) {
if (!m_Face)
return nullptr;
@@ -193,7 +193,7 @@ std::unique_ptr<CFX_GlyphBitmap> CFX_FaceCache::RenderGlyph(
const CFX_PathData* CFX_FaceCache::LoadGlyphPath(const CFX_Font* pFont,
uint32_t glyph_index,
- int dest_width) {
+ uint32_t dest_width) {
if (!m_Face || glyph_index == kInvalidGlyphIndex)
return nullptr;
@@ -216,7 +216,7 @@ const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(const CFX_Font* pFont,
uint32_t glyph_index,
bool bFontStyle,
const CFX_Matrix* pMatrix,
- int dest_width,
+ uint32_t dest_width,
int anti_alias,
int& text_flags) {
if (glyph_index == kInvalidGlyphIndex)
@@ -339,7 +339,7 @@ CFX_GlyphBitmap* CFX_FaceCache::LookUpGlyphBitmap(
const ByteString& FaceGlyphsKey,
uint32_t glyph_index,
bool bFontStyle,
- int dest_width,
+ uint32_t dest_width,
int anti_alias) {
SizeGlyphCache* pSizeCache;
auto it = m_SizeMap.find(FaceGlyphsKey);
diff --git a/core/fxge/cfx_facecache.h b/core/fxge/cfx_facecache.h
index a39da88b01..4ff4c41b1d 100644
--- a/core/fxge/cfx_facecache.h
+++ b/core/fxge/cfx_facecache.h
@@ -30,12 +30,12 @@ class CFX_FaceCache {
uint32_t glyph_index,
bool bFontStyle,
const CFX_Matrix* pMatrix,
- int dest_width,
+ uint32_t dest_width,
int anti_alias,
int& text_flags);
const CFX_PathData* LoadGlyphPath(const CFX_Font* pFont,
uint32_t glyph_index,
- int dest_width);
+ uint32_t dest_width);
#if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_
CFX_TypeFace* GetDeviceCache(const CFX_Font* pFont);
@@ -44,26 +44,26 @@ class CFX_FaceCache {
private:
using SizeGlyphCache = std::map<uint32_t, std::unique_ptr<CFX_GlyphBitmap>>;
// <glyph_index, width, weight, angle, vertical>
- using PathMapKey = std::tuple<uint32_t, int, int, int, bool>;
+ using PathMapKey = std::tuple<uint32_t, uint32_t, int, int, bool>;
std::unique_ptr<CFX_GlyphBitmap> RenderGlyph(const CFX_Font* pFont,
uint32_t glyph_index,
bool bFontStyle,
const CFX_Matrix* pMatrix,
- int dest_width,
+ uint32_t dest_width,
int anti_alias);
std::unique_ptr<CFX_GlyphBitmap> RenderGlyph_Nativetext(
const CFX_Font* pFont,
uint32_t glyph_index,
const CFX_Matrix* pMatrix,
- int dest_width,
+ uint32_t dest_width,
int anti_alias);
CFX_GlyphBitmap* LookUpGlyphBitmap(const CFX_Font* pFont,
const CFX_Matrix* pMatrix,
const ByteString& FaceGlyphsKey,
uint32_t glyph_index,
bool bFontStyle,
- int dest_width,
+ uint32_t dest_width,
int anti_alias);
void InitPlatform();
void DestroyPlatform();
diff --git a/core/fxge/cfx_font.cpp b/core/fxge/cfx_font.cpp
index 6d969a345c..ece3f96bed 100644
--- a/core/fxge/cfx_font.cpp
+++ b/core/fxge/cfx_font.cpp
@@ -295,7 +295,7 @@ bool CFX_Font::LoadFile(const RetainPtr<IFX_SeekableReadStream>& pFile,
}
#endif // PDF_ENABLE_XFA
-int CFX_Font::GetGlyphWidth(uint32_t glyph_index) {
+uint32_t CFX_Font::GetGlyphWidth(uint32_t glyph_index) {
if (!m_Face)
return 0;
if (m_pSubstFont && m_pSubstFont->m_bFlagMM)
@@ -307,7 +307,7 @@ int CFX_Font::GetGlyphWidth(uint32_t glyph_index) {
return 0;
int horiAdvance = FXFT_Get_Glyph_HoriAdvance(m_Face);
- if (horiAdvance < kThousandthMinInt || horiAdvance > kThousandthMaxInt)
+ if (horiAdvance < 0 || horiAdvance > kThousandthMaxInt)
return 0;
return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), horiAdvance);
@@ -501,7 +501,7 @@ void CFX_Font::ClearFaceCache() {
}
void CFX_Font::AdjustMMParams(int glyph_index,
- int dest_width,
+ uint32_t dest_width,
int weight) const {
FXFT_MM_Var pMasters = nullptr;
FXFT_Get_MM_Var(m_Face, &pMasters);
@@ -544,7 +544,7 @@ void CFX_Font::AdjustMMParams(int glyph_index,
}
CFX_PathData* CFX_Font::LoadGlyphPathImpl(uint32_t glyph_index,
- int dest_width) const {
+ uint32_t dest_width) const {
if (!m_Face)
return nullptr;
FXFT_Set_Pixel_Sizes(m_Face, 0, 64);
@@ -613,7 +613,7 @@ CFX_PathData* CFX_Font::LoadGlyphPathImpl(uint32_t glyph_index,
const CFX_GlyphBitmap* CFX_Font::LoadGlyphBitmap(uint32_t glyph_index,
bool bFontStyle,
const CFX_Matrix* pMatrix,
- int dest_width,
+ uint32_t dest_width,
int anti_alias,
int& text_flags) const {
return GetFaceCache()->LoadGlyphBitmap(this, glyph_index, bFontStyle, pMatrix,
@@ -621,7 +621,7 @@ const CFX_GlyphBitmap* CFX_Font::LoadGlyphBitmap(uint32_t glyph_index,
}
const CFX_PathData* CFX_Font::LoadGlyphPath(uint32_t glyph_index,
- int dest_width) const {
+ uint32_t dest_width) const {
return GetFaceCache()->LoadGlyphPath(this, glyph_index, dest_width);
}
diff --git a/core/fxge/cfx_font.h b/core/fxge/cfx_font.h
index c8c4cf7a5f..3739cad9f3 100644
--- a/core/fxge/cfx_font.h
+++ b/core/fxge/cfx_font.h
@@ -52,16 +52,17 @@ class CFX_Font {
const CFX_GlyphBitmap* LoadGlyphBitmap(uint32_t glyph_index,
bool bFontStyle,
const CFX_Matrix* pMatrix,
- int dest_width,
+ uint32_t dest_width,
int anti_alias,
int& text_flags) const;
- const CFX_PathData* LoadGlyphPath(uint32_t glyph_index, int dest_width) const;
+ const CFX_PathData* LoadGlyphPath(uint32_t glyph_index,
+ uint32_t dest_width) const;
#if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_
CFX_TypeFace* GetDeviceCache() const;
#endif
- int GetGlyphWidth(uint32_t glyph_index);
+ uint32_t GetGlyphWidth(uint32_t glyph_index);
int GetAscent() const;
int GetDescent() const;
bool GetGlyphBBox(uint32_t glyph_index, FX_RECT& bbox);
@@ -83,9 +84,10 @@ class CFX_Font {
#endif
uint8_t* GetFontData() const { return m_pFontData; }
uint32_t GetSize() const { return m_dwSize; }
- void AdjustMMParams(int glyph_index, int width, int weight) const;
+ void AdjustMMParams(int glyph_index, uint32_t width, int weight) const;
- CFX_PathData* LoadGlyphPathImpl(uint32_t glyph_index, int dest_width) const;
+ CFX_PathData* LoadGlyphPathImpl(uint32_t glyph_index,
+ uint32_t dest_width) const;
static const size_t kAngleSkewArraySize = 30;
static const char s_AngleSkew[kAngleSkewArraySize];
diff --git a/core/fxge/cfx_renderdevice.h b/core/fxge/cfx_renderdevice.h
index d8cb9a6952..d3ebed41c4 100644
--- a/core/fxge/cfx_renderdevice.h
+++ b/core/fxge/cfx_renderdevice.h
@@ -76,7 +76,7 @@ class FXTEXT_CHARPOS {
CFX_PointF m_Origin;
uint32_t m_Unicode;
uint32_t m_GlyphIndex;
- int32_t m_FontCharWidth;
+ uint32_t m_FontCharWidth;
#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
uint32_t m_ExtGID;
#endif
diff --git a/core/fxge/skia/fx_skia_device_unittest.cpp b/core/fxge/skia/fx_skia_device_unittest.cpp
index 7cb28cfb49..66db939539 100644
--- a/core/fxge/skia/fx_skia_device_unittest.cpp
+++ b/core/fxge/skia/fx_skia_device_unittest.cpp
@@ -38,7 +38,7 @@ void CommonTest(CFX_SkiaDeviceDriver* driver, const State& state) {
FXTEXT_CHARPOS charPos[1];
charPos[0].m_Origin = CFX_PointF(0, 1);
charPos[0].m_GlyphIndex = 1;
- charPos[0].m_FontCharWidth = 4;
+ charPos[0].m_FontCharWidth = 4u;
CFX_Font font;
float fontSize = 1;
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<int>(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 <algorithm>
+#include <limits>
#include <map>
#include <memory>
#include <utility>
@@ -259,7 +261,10 @@ void* LoadSimpleFont(CPDF_Document* pDoc,
fontDict->SetNewFor<CPDF_Number>("FirstChar", static_cast<int>(currentChar));
CPDF_Array* widthsArray = pDoc->NewIndirect<CPDF_Array>();
while (true) {
- widthsArray->AddNew<CPDF_Number>(pFont->GetGlyphWidth(glyphIndex));
+ uint32_t width =
+ std::min(pFont->GetGlyphWidth(glyphIndex),
+ static_cast<uint32_t>(std::numeric_limits<int>::max()));
+ widthsArray->AddNew<CPDF_Number>(static_cast<int>(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,
diff --git a/fxbarcode/oned/BC_OneDimWriter.cpp b/fxbarcode/oned/BC_OneDimWriter.cpp
index 0fa23bb91e..040257b425 100644
--- a/fxbarcode/oned/BC_OneDimWriter.cpp
+++ b/fxbarcode/oned/BC_OneDimWriter.cpp
@@ -142,9 +142,9 @@ void CBC_OneDimWriter::CalcTextInfo(const ByteString& text,
float charWidth = 0;
for (size_t j = 0; j < length; j++) {
pCharCode[j] = encoding->CharCodeFromUnicode(text[j]);
- int32_t glyp_code = encoding->GlyphFromCharCode(pCharCode[j]);
- int32_t glyp_value = cFont->GetGlyphWidth(glyp_code);
- float temp = (float)((glyp_value)*fontSize / 1000.0);
+ int32_t glyph_code = encoding->GlyphFromCharCode(pCharCode[j]);
+ uint32_t glyph_value = cFont->GetGlyphWidth(glyph_code);
+ float temp = glyph_value * fontSize / 1000.0;
charWidth += temp;
}
charsLen = charWidth;
diff --git a/xfa/fgas/font/cfgas_pdffontmgr.cpp b/xfa/fgas/font/cfgas_pdffontmgr.cpp
index 4d34ac8284..e2fb905f66 100644
--- a/xfa/fgas/font/cfgas_pdffontmgr.cpp
+++ b/xfa/fgas/font/cfgas_pdffontmgr.cpp
@@ -194,7 +194,10 @@ bool CFGAS_PDFFontMgr::GetCharWidth(const RetainPtr<CFGAS_GEFont>& pFont,
return false;
CPDF_Font* pPDFFont = it->second;
- *pWidth = pPDFFont->GetCharWidthF(pPDFFont->CharCodeFromUnicode(wUnicode));
+ // TODO(npm): CFGAS_GEFont::GetCharWidth currently uses -1 as a special value,
+ // so |pWidth| cannot be changed to unsigned until this behavior is changed.
+ *pWidth = static_cast<int32_t>(
+ pPDFFont->GetCharWidthF(pPDFFont->CharCodeFromUnicode(wUnicode)));
return true;
}
diff --git a/xfa/fgas/layout/cfx_rtfbreak.cpp b/xfa/fgas/layout/cfx_rtfbreak.cpp
index 3ef0ef2624..9497e5fde6 100644
--- a/xfa/fgas/layout/cfx_rtfbreak.cpp
+++ b/xfa/fgas/layout/cfx_rtfbreak.cpp
@@ -702,7 +702,7 @@ int32_t CFX_RTFBreak::GetDisplayPos(const FX_RTFTEXTOBJ* pText,
continue;
}
- int32_t iCharWidth = abs(iWidth);
+ uint32_t iCharWidth = abs(iWidth);
bool bEmptyChar =
(dwCharType >= FX_CHARTYPE_Tab && dwCharType <= FX_CHARTYPE_Control);
if (!bEmptyChar)
diff --git a/xfa/fgas/layout/cfx_txtbreak.cpp b/xfa/fgas/layout/cfx_txtbreak.cpp
index b028c9baf6..b0199922c4 100644
--- a/xfa/fgas/layout/cfx_txtbreak.cpp
+++ b/xfa/fgas/layout/cfx_txtbreak.cpp
@@ -831,6 +831,8 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
pCharPos->m_ExtGID = pCharPos->m_GlyphIndex;
#endif
+ // TODO(npm): change widths in this method to unsigned to avoid implicit
+ // cast in the following line.
pCharPos->m_FontCharWidth = iCharWidth;
}