Fix nits on some font code.
Change-Id: I80be0de1a7d9ba502b4468bc13a4595566f8fb30
Reviewed-on: https://pdfium-review.googlesource.com/20432
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_type1font.cpp b/core/fpdfapi/font/cpdf_type1font.cpp
index 21d9da4..77987bb 100644
--- a/core/fpdfapi/font/cpdf_type1font.cpp
+++ b/core/fpdfapi/font/cpdf_type1font.cpp
@@ -154,9 +154,9 @@
}
}
FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE);
- if (m_BaseEncoding == 0) {
+ if (m_BaseEncoding == 0)
m_BaseEncoding = PDFFONT_ENCODING_STANDARD;
- }
+
for (int charcode = 0; charcode < 256; charcode++) {
const char* name =
GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode);
@@ -193,7 +193,7 @@
if (name) {
m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
m_GlyphIndex[charcode] =
- FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name);
+ FXFT_Get_Name_Index(m_Font.GetFace(), const_cast<char*>(name));
SetExtGID(name, charcode);
} else {
m_GlyphIndex[charcode] =
@@ -208,46 +208,46 @@
FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode],
name_glyph, 256);
name_glyph[255] = 0;
- if (unicode == 0 && name_glyph[0] != 0) {
+ if (unicode == 0 && name_glyph[0] != 0)
unicode = PDF_UnicodeFromAdobeName(name_glyph);
- }
+
m_Encoding.m_Unicodes[charcode] = unicode;
SetExtGID(name_glyph, charcode);
}
}
return;
}
- bool bUnicode = false;
- if (0 == FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE)) {
- bUnicode = true;
- }
+
+ bool bUnicode =
+ FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE) == 0;
for (int charcode = 0; charcode < 256; charcode++) {
const char* name =
GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode);
- if (!name) {
+ if (!name)
continue;
- }
+
m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
const char* pStrUnicode = GlyphNameRemap(name);
if (pStrUnicode &&
- 0 == FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name)) {
+ FXFT_Get_Name_Index(m_Font.GetFace(), const_cast<char*>(name)) == 0) {
name = pStrUnicode;
}
m_GlyphIndex[charcode] =
- FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name);
+ FXFT_Get_Name_Index(m_Font.GetFace(), const_cast<char*>(name));
SetExtGID(name, charcode);
- if (m_GlyphIndex[charcode] == 0) {
- if (strcmp(name, ".notdef") != 0 && strcmp(name, "space") != 0) {
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(
- m_Font.GetFace(),
- bUnicode ? m_Encoding.m_Unicodes[charcode] : charcode);
- CalcExtGID(charcode);
- } else {
- m_Encoding.m_Unicodes[charcode] = 0x20;
- m_GlyphIndex[charcode] =
- bUnicode ? FXFT_Get_Char_Index(m_Font.GetFace(), 0x20) : 0xffff;
- CalcExtGID(charcode);
- }
+ if (m_GlyphIndex[charcode] != 0)
+ continue;
+
+ if (strcmp(name, ".notdef") != 0 && strcmp(name, "space") != 0) {
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(
+ m_Font.GetFace(),
+ bUnicode ? m_Encoding.m_Unicodes[charcode] : charcode);
+ CalcExtGID(charcode);
+ } else {
+ m_Encoding.m_Unicodes[charcode] = 0x20;
+ m_GlyphIndex[charcode] =
+ bUnicode ? FXFT_Get_Char_Index(m_Font.GetFace(), 0x20) : 0xffff;
+ CalcExtGID(charcode);
}
}
return;
@@ -260,7 +260,7 @@
if (name) {
m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
m_GlyphIndex[charcode] =
- FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name);
+ FXFT_Get_Name_Index(m_Font.GetFace(), const_cast<char*>(name));
} else {
m_GlyphIndex[charcode] =
FXFT_Get_Char_Index(m_Font.GetFace(), charcode);
@@ -273,9 +273,8 @@
FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode],
name_glyph, 256);
name_glyph[255] = 0;
- if (name_glyph[0] != 0) {
+ if (name_glyph[0] != 0)
unicode = PDF_UnicodeFromAdobeName(name_glyph);
- }
}
m_Encoding.m_Unicodes[charcode] = unicode;
}
@@ -288,26 +287,27 @@
#endif
return;
}
- bool bUnicode = false;
- if (0 == FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE)) {
- bUnicode = true;
- }
+
+ bool bUnicode =
+ FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE) == 0;
for (int charcode = 0; charcode < 256; charcode++) {
const char* name = GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode);
- if (!name) {
+ if (!name)
continue;
- }
+
m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
- m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name);
- if (m_GlyphIndex[charcode] == 0) {
- if (strcmp(name, ".notdef") != 0 && strcmp(name, "space") != 0) {
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(
- m_Font.GetFace(),
- bUnicode ? m_Encoding.m_Unicodes[charcode] : charcode);
- } else {
- m_Encoding.m_Unicodes[charcode] = 0x20;
- m_GlyphIndex[charcode] = 0xffff;
- }
+ m_GlyphIndex[charcode] =
+ FXFT_Get_Name_Index(m_Font.GetFace(), const_cast<char*>(name));
+ if (m_GlyphIndex[charcode] != 0)
+ continue;
+
+ if (strcmp(name, ".notdef") != 0 && strcmp(name, "space") != 0) {
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(
+ m_Font.GetFace(),
+ bUnicode ? m_Encoding.m_Unicodes[charcode] : charcode);
+ } else {
+ m_Encoding.m_Unicodes[charcode] = 0x20;
+ m_GlyphIndex[charcode] = 0xffff;
}
}
#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index 406a822..0aa4123 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -250,21 +250,20 @@
return std::make_tuple(false, FXFONT_NORMAL, 0);
}
-bool CheckSupportThirdPartFont(ByteString name, int& PitchFamily) {
- if (name == "MyriadPro") {
- PitchFamily &= ~FXFONT_FF_ROMAN;
- return true;
- }
- return false;
+bool CheckSupportThirdPartFont(const ByteString& name, int* PitchFamily) {
+ if (name != "MyriadPro")
+ return false;
+ *PitchFamily &= ~FXFONT_FF_ROMAN;
+ return true;
}
-void UpdatePitchFamily(uint32_t flags, int& PitchFamily) {
+void UpdatePitchFamily(uint32_t flags, int* PitchFamily) {
if (FontStyleIsSerif(flags))
- PitchFamily |= FXFONT_FF_ROMAN;
+ *PitchFamily |= FXFONT_FF_ROMAN;
if (FontStyleIsScript(flags))
- PitchFamily |= FXFONT_FF_SCRIPT;
+ *PitchFamily |= FXFONT_FF_SCRIPT;
if (FontStyleIsFixedPitch(flags))
- PitchFamily |= FXFONT_FF_FIXEDPITCH;
+ *PitchFamily |= FXFONT_FF_FIXEDPITCH;
}
} // namespace
@@ -485,7 +484,7 @@
nStyle |= styleType;
}
}
- UpdatePitchFamily(flags, PitchFamily);
+ UpdatePitchFamily(flags, &PitchFamily);
}
int old_weight = weight;
@@ -563,7 +562,7 @@
}
if (match.IsEmpty() && iBaseFont >= kNumStandardFonts) {
if (!bCJK) {
- if (!CheckSupportThirdPartFont(family, PitchFamily)) {
+ if (!CheckSupportThirdPartFont(family, &PitchFamily)) {
bItalic = italic_angle != 0;
weight = old_weight;
}
@@ -707,7 +706,7 @@
bool bItalic = (flags & FXFONT_ITALIC) != 0;
int PitchFamily = 0;
- UpdatePitchFamily(flags, PitchFamily);
+ UpdatePitchFamily(flags, &PitchFamily);
void* hFont =
m_pFontInfo->MapFontByUnicode(dwUnicode, weight, bItalic, PitchFamily);
if (!hFont)