From 907a5223ea5abd09878de20cc74c59ebd0d6c3c8 Mon Sep 17 00:00:00 2001 From: thestig Date: Tue, 21 Jun 2016 14:38:27 -0700 Subject: Use FXFONT defines in place of integers. Fix nits along the way. Review-Url: https://codereview.chromium.org/2083943003 --- core/fpdfapi/fpdf_parser/cpdf_document.cpp | 2 +- core/fpdfdoc/cpvt_fontmap.cpp | 2 +- core/fpdfdoc/cpvt_wordinfo.h | 4 ++-- core/fpdfdoc/doc_form.cpp | 9 +++++---- core/fpdfdoc/doc_utils.cpp | 22 ++++++++++++---------- core/fpdfdoc/include/cpdf_variabletext.h | 7 ++++--- core/fxge/apple/fx_mac_imp.cpp | 12 ++++++------ core/fxge/ge/fx_ge_font.cpp | 3 ++- core/fxge/ge/fx_ge_fontmap.cpp | 13 +++++++------ core/fxge/ge/fx_ge_text.cpp | 4 ++-- core/fxge/include/fx_font.h | 13 +++---------- 11 files changed, 45 insertions(+), 46 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/fpdf_parser/cpdf_document.cpp b/core/fpdfapi/fpdf_parser/cpdf_document.cpp index 230b9b0d1b..485d538832 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_document.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_document.cpp @@ -261,7 +261,7 @@ uint8_t FX_GetCsFromLangCode(uint32_t uCode) { else iStart = iMid + 1; } - return 0; + return FXFONT_ANSI_CHARSET; } uint8_t FX_GetCharsetFromLang(const FX_CHAR* pLang, int32_t iLength) { diff --git a/core/fpdfdoc/cpvt_fontmap.cpp b/core/fpdfdoc/cpvt_fontmap.cpp index d4171bd147..35a56f811d 100644 --- a/core/fpdfdoc/cpvt_fontmap.cpp +++ b/core/fpdfdoc/cpvt_fontmap.cpp @@ -88,5 +88,5 @@ int32_t CPVT_FontMap::CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) { int32_t CPVT_FontMap::CharSetFromUnicode(uint16_t word, int32_t nOldCharset) { ASSERT(false); - return 0; + return FXFONT_ANSI_CHARSET; } diff --git a/core/fpdfdoc/cpvt_wordinfo.h b/core/fpdfdoc/cpvt_wordinfo.h index 3eb980f3af..1ab0df21af 100644 --- a/core/fpdfdoc/cpvt_wordinfo.h +++ b/core/fpdfdoc/cpvt_wordinfo.h @@ -13,7 +13,7 @@ struct CPVT_WordInfo { CPVT_WordInfo() : Word(0), - nCharset(0), + nCharset(FXFONT_ANSI_CHARSET), fWordX(0.0f), fWordY(0.0f), fWordTail(0.0f), @@ -34,7 +34,7 @@ struct CPVT_WordInfo { CPVT_WordInfo(const CPVT_WordInfo& word) : Word(0), - nCharset(0), + nCharset(FXFONT_ANSI_CHARSET), fWordX(0.0f), fWordY(0.0f), fWordTail(0.0f), diff --git a/core/fpdfdoc/doc_form.cpp b/core/fpdfdoc/doc_form.cpp index b2c5d8cdf7..82fcd4ceeb 100644 --- a/core/fpdfdoc/doc_form.cpp +++ b/core/fpdfdoc/doc_form.cpp @@ -416,12 +416,11 @@ CFX_ByteString CPDF_InterForm::GetNativeFont(uint8_t charSet, void* pLogFont) { CFX_ByteString csFontName; #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ LOGFONTA lf = {}; - FX_BOOL bRet; if (charSet == ANSI_CHARSET) { csFontName = "Helvetica"; return csFontName; } - bRet = FALSE; + FX_BOOL bRet = FALSE; if (charSet == SHIFTJIS_CHARSET) { bRet = RetrieveSpecificFont(charSet, DEFAULT_PITCH | FF_DONTCARE, "MS Mincho", lf); @@ -454,14 +453,16 @@ CFX_ByteString CPDF_InterForm::GetNativeFont(uint8_t charSet, void* pLogFont) { #endif return csFontName; } + CFX_ByteString CPDF_InterForm::GetNativeFont(void* pLogFont) { #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - uint8_t charSet = GetNativeCharSet(); - return GetNativeFont(charSet, pLogFont); + return GetNativeFont(GetNativeCharSet(), pLogFont); #else return CFX_ByteString(); #endif } + +// static uint8_t CPDF_InterForm::GetNativeCharSet() { #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ uint8_t charSet = ANSI_CHARSET; diff --git a/core/fpdfdoc/doc_utils.cpp b/core/fpdfdoc/doc_utils.cpp index ccef7feb57..7f79a34245 100644 --- a/core/fpdfdoc/doc_utils.cpp +++ b/core/fpdfdoc/doc_utils.cpp @@ -267,10 +267,11 @@ CFX_Matrix CPDF_DefaultAppearance::GetTextMatrix() { } return tm; } + void InitInterFormDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { - if (!pDocument) { + if (!pDocument) return; - } + if (!pFormDict) { pFormDict = new CPDF_Dictionary; uint32_t dwObjNum = pDocument->AddIndirectObject(pFormDict); @@ -287,7 +288,7 @@ void InitInterFormDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); csDefault = csBaseName; } - if (charSet != 0) { + if (charSet != FXFONT_ANSI_CHARSET) { CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet, nullptr); if (!pFont || csFontName != "Helvetica") { @@ -478,15 +479,15 @@ CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, } return nullptr; } + CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument, CFX_ByteString& csNameTag) { - csNameTag = ""; + csNameTag.clear(); uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); - CFX_SubstFont* pSubst; CPDF_Font* pFont = GetDefaultInterFormFont(pFormDict, pDocument); if (pFont) { - pSubst = pFont->GetSubstFont(); + CFX_SubstFont* pSubst = pFont->GetSubstFont(); if (pSubst && pSubst->m_Charset == (int)charSet) { FindInterFormFont(pFormDict, pFont, csNameTag); return pFont; @@ -494,6 +495,7 @@ CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, } return GetNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag); } + FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont, CFX_ByteString& csNameTag) { @@ -623,10 +625,9 @@ CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, return pFont; } CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet); - if (!csFontName.IsEmpty()) { - if (FindInterFormFont(pFormDict, pDocument, csFontName, pFont, csNameTag)) { - return pFont; - } + if (!csFontName.IsEmpty() && + FindInterFormFont(pFormDict, pDocument, csFontName, pFont, csNameTag)) { + return pFont; } pFont = CPDF_InterForm::AddNativeFont(charSet, pDocument); if (pFont) { @@ -652,6 +653,7 @@ void RemoveInterFormFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont) { CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); pFonts->RemoveAt(csTag); } + void RemoveInterFormFont(CPDF_Dictionary* pFormDict, CFX_ByteString csNameTag) { if (!pFormDict || csNameTag.IsEmpty()) { return; diff --git a/core/fpdfdoc/include/cpdf_variabletext.h b/core/fpdfdoc/include/cpdf_variabletext.h index 5e64ab29a9..36b2eb46a5 100644 --- a/core/fpdfdoc/include/cpdf_variabletext.h +++ b/core/fpdfdoc/include/cpdf_variabletext.h @@ -18,6 +18,7 @@ #include "core/fxcrt/include/fx_coordinates.h" #include "core/fxcrt/include/fx_string.h" #include "core/fxcrt/include/fx_system.h" +#include "core/fxge/include/fx_font.h" class CSection; class IPVT_FontMap; @@ -112,19 +113,19 @@ class CPDF_VariableText : private CPDF_EditContainer { void RearrangePart(const CPVT_WordRange& PlaceRange); void ResetAll(); void SetText(const FX_WCHAR* text, - int32_t charset = 1, + int32_t charset = FXFONT_DEFAULT_CHARSET, const CPVT_SecProps* pSecProps = nullptr, const CPVT_WordProps* pWordProps = nullptr); CPVT_WordPlace InsertWord(const CPVT_WordPlace& place, uint16_t word, - int32_t charset = 1, + int32_t charset = FXFONT_DEFAULT_CHARSET, const CPVT_WordProps* pWordProps = nullptr); CPVT_WordPlace InsertSection(const CPVT_WordPlace& place, const CPVT_SecProps* pSecProps = nullptr, const CPVT_WordProps* pWordProps = nullptr); CPVT_WordPlace InsertText(const CPVT_WordPlace& place, const FX_WCHAR* text, - int32_t charset = 1, + int32_t charset = FXFONT_DEFAULT_CHARSET, const CPVT_SecProps* pSecProps = nullptr, const CPVT_WordProps* pWordProps = nullptr); CPVT_WordPlace DeleteWords(const CPVT_WordRange& PlaceRange); diff --git a/core/fxge/apple/fx_mac_imp.cpp b/core/fxge/apple/fx_mac_imp.cpp index 528b7274db..489ce816cc 100644 --- a/core/fxge/apple/fx_mac_imp.cpp +++ b/core/fxge/apple/fx_mac_imp.cpp @@ -28,6 +28,9 @@ static const struct { class CFX_MacFontInfo : public CFX_FolderFontInfo { public: + CFX_MacFontInfo() {} + ~CFX_MacFontInfo() override {} + // CFX_FolderFontInfo void* MapFont(int weight, FX_BOOL bItalic, @@ -41,12 +44,12 @@ class CFX_MacFontInfo : public CFX_FolderFontInfo { #define JAPAN_MINCHO "Hiragino Mincho Pro W6" static void GetJapanesePreference(CFX_ByteString& face, int weight, - int picth_family) { + int pitch_family) { if (face.Find("Gothic") >= 0) { face = JAPAN_GOTHIC; return; } - if (!(picth_family & FXFONT_FF_ROMAN) && weight > 400) { + if (!(pitch_family & FXFONT_FF_ROMAN) && weight > 400) { face = JAPAN_GOTHIC; } else { face = JAPAN_MINCHO; @@ -93,10 +96,7 @@ void* CFX_MacFontInfo::MapFont(int weight, face = "LiSong Pro Light"; } it = m_FontList.find(face); - if (it != m_FontList.end()) - return it->second; - - return nullptr; + return it != m_FontList.end() ? it->second : nullptr; } std::unique_ptr IFX_SystemFontInfo::CreateDefault( diff --git a/core/fxge/ge/fx_ge_font.cpp b/core/fxge/ge/fx_ge_font.cpp index 3bb1580d01..fd6f8a2cf8 100644 --- a/core/fxge/ge/fx_ge_font.cpp +++ b/core/fxge/ge/fx_ge_font.cpp @@ -456,7 +456,8 @@ uint32_t CFX_UnicodeEncoding::GlyphFromCharCode(uint32_t charcode) { if (FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE) == 0) return FXFT_Get_Char_Index(face, charcode); - if (m_pFont->GetSubstFont() && m_pFont->GetSubstFont()->m_Charset == 2) { + if (m_pFont->GetSubstFont() && + m_pFont->GetSubstFont()->m_Charset == FXFONT_SYMBOL_CHARSET) { uint32_t index = 0; if (FXFT_Select_Charmap(face, FXFT_ENCODING_MS_SYMBOL) == 0) index = FXFT_Get_Char_Index(face, charcode); diff --git a/core/fxge/ge/fx_ge_fontmap.cpp b/core/fxge/ge/fx_ge_fontmap.cpp index 81e3137913..cc7e9f1aa2 100644 --- a/core/fxge/ge/fx_ge_fontmap.cpp +++ b/core/fxge/ge/fx_ge_fontmap.cpp @@ -293,7 +293,7 @@ uint8_t GetCharsetFromCodePage(uint16_t codepage) { }); if (pCharmap < pEnd && codepage == pCharmap->codepage) return pCharmap->charset; - return 1; + return FXFONT_DEFAULT_CHARSET; } CFX_ByteString GetFontFamily(CFX_ByteString fontName, int nStyle) { @@ -412,14 +412,15 @@ int32_t GetSimilarValue(int weight, CFX_SubstFont::CFX_SubstFont() { m_ExtHandle = nullptr; - m_Charset = 0; + m_Charset = FXFONT_ANSI_CHARSET; m_SubstFlags = 0; m_Weight = 0; m_ItalicAngle = 0; - m_bSubstOfCJK = FALSE; + m_bSubstCJK = false; m_WeightCJK = 0; - m_bItlicCJK = FALSE; + m_bItalicCJK = false; } + CTTFontDesc::~CTTFontDesc() { if (m_Type == 1) { if (m_SingleFace.m_pFace) { @@ -1057,14 +1058,14 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name, weight = old_weight; } } else { - pSubstFont->m_bSubstOfCJK = TRUE; + pSubstFont->m_bSubstCJK = true; if (nStyle) { pSubstFont->m_WeightCJK = weight; } else { pSubstFont->m_WeightCJK = FXFONT_FW_NORMAL; } if (nStyle & FX_FONT_STYLE_Italic) { - pSubstFont->m_bItlicCJK = TRUE; + pSubstFont->m_bItalicCJK = true; } } } else { diff --git a/core/fxge/ge/fx_ge_text.cpp b/core/fxge/ge/fx_ge_text.cpp index 9f635edacc..f09e44eefb 100644 --- a/core/fxge/ge/fx_ge_text.cpp +++ b/core/fxge/ge/fx_ge_text.cpp @@ -1092,10 +1092,10 @@ CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(CFX_Font* pFont, FX_BOOL bUseCJKSubFont = FALSE; const CFX_SubstFont* pSubstFont = pFont->GetSubstFont(); if (pSubstFont) { - bUseCJKSubFont = pSubstFont->m_bSubstOfCJK && bFontStyle; + bUseCJKSubFont = pSubstFont->m_bSubstCJK && bFontStyle; int skew = 0; if (bUseCJKSubFont) { - skew = pSubstFont->m_bItlicCJK ? -15 : 0; + skew = pSubstFont->m_bItalicCJK ? -15 : 0; } else { skew = pSubstFont->m_ItalicAngle; } diff --git a/core/fxge/include/fx_font.h b/core/fxge/include/fx_font.h index 78913c6867..f99d4a8af9 100644 --- a/core/fxge/include/fx_font.h +++ b/core/fxge/include/fx_font.h @@ -218,23 +218,16 @@ class CFX_SubstFont { CFX_SubstFont(); void* m_ExtHandle; - CFX_ByteString m_Family; - int m_Charset; - uint32_t m_SubstFlags; - int m_Weight; - int m_ItalicAngle; - - FX_BOOL m_bSubstOfCJK; - + bool m_bSubstCJK; int m_WeightCJK; - - FX_BOOL m_bItlicCJK; + bool m_bItalicCJK; }; + #define FX_FONT_FLAG_SERIF 0x01 #define FX_FONT_FLAG_FIXEDPITCH 0x02 #define FX_FONT_FLAG_ITALIC 0x04 -- cgit v1.2.3