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 ++----- fpdfsdk/cfx_systemhandler.cpp | 19 +++++----- fpdfsdk/cfx_systemhandler.h | 9 +---- fpdfsdk/formfiller/cba_fontmap.cpp | 27 +++++++------ fpdfsdk/formfiller/cffl_combobox.cpp | 2 +- fpdfsdk/formfiller/cffl_textfield.cpp | 2 +- fpdfsdk/fpdf_sysfontinfo.cpp | 61 ++++++++++++++++-------------- fpdfsdk/pdfwindow/PWL_Edit.cpp | 2 +- fpdfsdk/pdfwindow/PWL_FontMap.cpp | 6 +-- xfa/fde/fde_gedevice.cpp | 4 +- xfa/fgas/font/fgas_gefont.cpp | 48 +++++++---------------- xfa/fgas/font/fgas_gefont.h | 2 - xfa/fgas/font/fgas_stdfontmgr.cpp | 50 ++++++++++-------------- xfa/fgas/font/fgas_stdfontmgr.h | 4 +- 24 files changed, 145 insertions(+), 182 deletions(-) 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 diff --git a/fpdfsdk/cfx_systemhandler.cpp b/fpdfsdk/cfx_systemhandler.cpp index c0fd140c9b..d6ec4f0cf0 100644 --- a/fpdfsdk/cfx_systemhandler.cpp +++ b/fpdfsdk/cfx_systemhandler.cpp @@ -6,6 +6,8 @@ #include "fpdfsdk/cfx_systemhandler.h" +#include + #include "core/fxge/include/fx_ge.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/include/fsdk_mgr.h" @@ -13,13 +15,13 @@ namespace { int CharSet2CP(int charset) { - if (charset == 128) + if (charset == FXFONT_SHIFTJIS_CHARSET) return 932; - if (charset == 134) + if (charset == FXFONT_GB2312_CHARSET) return 936; - if (charset == 129) + if (charset == FXFONT_HANGEUL_CHARSET) return 949; - if (charset == 136) + if (charset == FXFONT_CHINESEBIG5_CHARSET) return 950; return 0; } @@ -78,8 +80,7 @@ bool CFX_SystemHandler::IsSelectionImplemented() const { return false; } -bool CFX_SystemHandler::FindNativeTrueTypeFont(int32_t nCharset, - CFX_ByteString sFontFaceName) { +bool CFX_SystemHandler::FindNativeTrueTypeFont(CFX_ByteString sFontFaceName) { CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); if (!pFontMgr) return false; @@ -106,11 +107,9 @@ CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF( if (!pDoc) return nullptr; - CFX_Font* pFXFont = new CFX_Font(); + std::unique_ptr pFXFont(new CFX_Font); pFXFont->LoadSubst(sFontFaceName, TRUE, 0, 0, 0, CharSet2CP(nCharset), FALSE); - CPDF_Font* pFont = pDoc->AddFont(pFXFont, nCharset, FALSE); - delete pFXFont; - return pFont; + return pDoc->AddFont(pFXFont.get(), nCharset, FALSE); } int32_t CFX_SystemHandler::SetTimer(int32_t uElapse, diff --git a/fpdfsdk/cfx_systemhandler.h b/fpdfsdk/cfx_systemhandler.h index e77120adef..76da223310 100644 --- a/fpdfsdk/cfx_systemhandler.h +++ b/fpdfsdk/cfx_systemhandler.h @@ -49,8 +49,7 @@ class CPDFDoc_Environment; class CFX_SystemHandler { public: - explicit CFX_SystemHandler(CPDFDoc_Environment* pEnv) - : m_pEnv(pEnv), m_nCharSet(-1) {} + explicit CFX_SystemHandler(CPDFDoc_Environment* pEnv) : m_pEnv(pEnv) {} ~CFX_SystemHandler() {} void InvalidateRect(FX_HWND hWnd, FX_RECT rect); @@ -59,7 +58,7 @@ class CFX_SystemHandler { void SetCursor(int32_t nCursorType); - bool FindNativeTrueTypeFont(int32_t nCharset, CFX_ByteString sFontFaceName); + bool FindNativeTrueTypeFont(CFX_ByteString sFontFaceName); CPDF_Font* AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName, uint8_t nCharset); @@ -71,12 +70,8 @@ class CFX_SystemHandler { FX_SYSTEMTIME GetLocalTime(); - int32_t GetCharSet() const { return m_nCharSet; } - void SetCharSet(int32_t nCharSet) { m_nCharSet = nCharSet; } - private: CPDFDoc_Environment* const m_pEnv; - int m_nCharSet; }; #endif // FPDFSDK_CFX_SYSTEMHANDLER_H_ diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp index 9102b7bf9a..b8c8865d44 100644 --- a/fpdfsdk/formfiller/cba_fontmap.cpp +++ b/fpdfsdk/formfiller/cba_fontmap.cpp @@ -79,24 +79,23 @@ void CBA_FontMap::SetDefaultFont(CPDF_Font* pFont, CPDF_Font* CBA_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, int32_t nCharset) { - if (m_pAnnotDict->GetStringBy("Subtype") == "Widget") { - CPDF_Document* pDocument = GetDocument(); - CPDF_Dictionary* pRootDict = pDocument->GetRoot(); - if (!pRootDict) - return nullptr; + if (m_pAnnotDict->GetStringBy("Subtype") != "Widget") + return nullptr; - CPDF_Dictionary* pAcroFormDict = pRootDict->GetDictBy("AcroForm"); - if (!pAcroFormDict) - return nullptr; + CPDF_Document* pDocument = GetDocument(); + CPDF_Dictionary* pRootDict = pDocument->GetRoot(); + if (!pRootDict) + return nullptr; - CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR"); - if (!pDRDict) - return nullptr; + CPDF_Dictionary* pAcroFormDict = pRootDict->GetDictBy("AcroForm"); + if (!pAcroFormDict) + return nullptr; - return FindResFontSameCharset(pDRDict, sFontAlias, nCharset); - } + CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR"); + if (!pDRDict) + return nullptr; - return nullptr; + return FindResFontSameCharset(pDRDict, sFontAlias, nCharset); } CPDF_Document* CBA_FontMap::GetDocument() { diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp index d489a243d9..262c485138 100644 --- a/fpdfsdk/formfiller/cffl_combobox.cpp +++ b/fpdfsdk/formfiller/cffl_combobox.cpp @@ -257,7 +257,7 @@ void CFFL_ComboBox::OnSetFocus(CPWL_Wnd* pWnd) { if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) { CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; - pEdit->SetCharSet(134); + pEdit->SetCharSet(FXFONT_GB2312_CHARSET); pEdit->SetCodePage(936); pEdit->SetReadyToInput(); diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp index be1f36b697..4f32f42ac7 100644 --- a/fpdfsdk/formfiller/cffl_textfield.cpp +++ b/fpdfsdk/formfiller/cffl_textfield.cpp @@ -269,7 +269,7 @@ void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) { ASSERT(m_pApp); if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) { CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; - pEdit->SetCharSet(134); + pEdit->SetCharSet(FXFONT_GB2312_CHARSET); pEdit->SetCodePage(936); pEdit->SetReadyToInput(); diff --git a/fpdfsdk/fpdf_sysfontinfo.cpp b/fpdfsdk/fpdf_sysfontinfo.cpp index 2a309d9785..b149726839 100644 --- a/fpdfsdk/fpdf_sysfontinfo.cpp +++ b/fpdfsdk/fpdf_sysfontinfo.cpp @@ -33,25 +33,25 @@ class CFX_ExternalFontInfo final : public IFX_SystemFontInfo { int pitch_family, const FX_CHAR* family, int& iExact) override { - if (m_pInfo->MapFont) - return m_pInfo->MapFont(m_pInfo, weight, bItalic, charset, pitch_family, - family, &iExact); - return nullptr; + if (!m_pInfo->MapFont) + return nullptr; + return m_pInfo->MapFont(m_pInfo, weight, bItalic, charset, pitch_family, + family, &iExact); } void* GetFont(const FX_CHAR* family) override { - if (m_pInfo->GetFont) - return m_pInfo->GetFont(m_pInfo, family); - return nullptr; + if (!m_pInfo->GetFont) + return nullptr; + return m_pInfo->GetFont(m_pInfo, family); } uint32_t GetFontData(void* hFont, uint32_t table, uint8_t* buffer, uint32_t size) override { - if (m_pInfo->GetFontData) - return m_pInfo->GetFontData(m_pInfo, hFont, table, buffer, size); - return 0; + if (!m_pInfo->GetFontData) + return 0; + return m_pInfo->GetFontData(m_pInfo, hFont, table, buffer, size); } FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name) override { @@ -68,11 +68,11 @@ class CFX_ExternalFontInfo final : public IFX_SystemFontInfo { } FX_BOOL GetFontCharset(void* hFont, int& charset) override { - if (m_pInfo->GetFontCharset) { - charset = m_pInfo->GetFontCharset(m_pInfo, hFont); - return TRUE; - } - return FALSE; + if (!m_pInfo->GetFontCharset) + return FALSE; + + charset = m_pInfo->GetFontCharset(m_pInfo, hFont); + return TRUE; } void DeleteFont(void* hFont) override { @@ -87,7 +87,8 @@ class CFX_ExternalFontInfo final : public IFX_SystemFontInfo { DLLEXPORT void STDCALL FPDF_AddInstalledFont(void* mapper, const char* name, int charset) { - ((CFX_FontMapper*)mapper)->AddInstalledFont(name, charset); + CFX_FontMapper* pMapper = reinterpret_cast(mapper); + pMapper->AddInstalledFont(name, charset); } DLLEXPORT void STDCALL FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfoExt) { @@ -114,8 +115,8 @@ static void DefaultRelease(struct _FPDF_SYSFONTINFO* pThis) { } static void DefaultEnumFonts(struct _FPDF_SYSFONTINFO* pThis, void* pMapper) { - ((FPDF_SYSFONTINFO_DEFAULT*)pThis) - ->m_pFontInfo->EnumFontList((CFX_FontMapper*)pMapper); + auto* pDefault = static_cast(pThis); + pDefault->m_pFontInfo->EnumFontList((CFX_FontMapper*)pMapper); } static void* DefaultMapFont(struct _FPDF_SYSFONTINFO* pThis, @@ -125,13 +126,14 @@ static void* DefaultMapFont(struct _FPDF_SYSFONTINFO* pThis, int pitch_family, const char* family, int* bExact) { - return ((FPDF_SYSFONTINFO_DEFAULT*)pThis) - ->m_pFontInfo->MapFont(weight, bItalic, charset, pitch_family, family, - *bExact); + auto* pDefault = static_cast(pThis); + return pDefault->m_pFontInfo->MapFont(weight, bItalic, charset, pitch_family, + family, *bExact); } void* DefaultGetFont(struct _FPDF_SYSFONTINFO* pThis, const char* family) { - return ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->GetFont(family); + auto* pDefault = static_cast(pThis); + return pDefault->m_pFontInfo->GetFont(family); } static unsigned long DefaultGetFontData(struct _FPDF_SYSFONTINFO* pThis, @@ -139,8 +141,8 @@ static unsigned long DefaultGetFontData(struct _FPDF_SYSFONTINFO* pThis, unsigned int table, unsigned char* buffer, unsigned long buf_size) { - return ((FPDF_SYSFONTINFO_DEFAULT*)pThis) - ->m_pFontInfo->GetFontData(hFont, table, buffer, buf_size); + auto* pDefault = static_cast(pThis); + return pDefault->m_pFontInfo->GetFontData(hFont, table, buffer, buf_size); } static unsigned long DefaultGetFaceName(struct _FPDF_SYSFONTINFO* pThis, @@ -148,8 +150,8 @@ static unsigned long DefaultGetFaceName(struct _FPDF_SYSFONTINFO* pThis, char* buffer, unsigned long buf_size) { CFX_ByteString name; - if (!((FPDF_SYSFONTINFO_DEFAULT*)pThis) - ->m_pFontInfo->GetFaceName(hFont, name)) + auto* pDefault = static_cast(pThis); + if (!pDefault->m_pFontInfo->GetFaceName(hFont, name)) return 0; if (name.GetLength() >= (long)buf_size) return name.GetLength() + 1; @@ -159,14 +161,15 @@ static unsigned long DefaultGetFaceName(struct _FPDF_SYSFONTINFO* pThis, static int DefaultGetFontCharset(struct _FPDF_SYSFONTINFO* pThis, void* hFont) { int charset; - if (!((FPDF_SYSFONTINFO_DEFAULT*)pThis) - ->m_pFontInfo->GetFontCharset(hFont, charset)) + auto* pDefault = static_cast(pThis); + if (!pDefault->m_pFontInfo->GetFontCharset(hFont, charset)) return 0; return charset; } static void DefaultDeleteFont(struct _FPDF_SYSFONTINFO* pThis, void* hFont) { - ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->DeleteFont(hFont); + auto* pDefault = static_cast(pThis); + pDefault->m_pFontInfo->DeleteFont(hFont); } DLLEXPORT FPDF_SYSFONTINFO* STDCALL FPDF_GetDefaultSystemFontInfo() { diff --git a/fpdfsdk/pdfwindow/PWL_Edit.cpp b/fpdfsdk/pdfwindow/PWL_Edit.cpp index 21d4b033ab..e7a4ac9dd3 100644 --- a/fpdfsdk/pdfwindow/PWL_Edit.cpp +++ b/fpdfsdk/pdfwindow/PWL_Edit.cpp @@ -464,7 +464,7 @@ void CPWL_Edit::OnKillFocus() { m_pEdit->SelectNone(); SetCaret(FALSE, CFX_FloatPoint(0.0f, 0.0f), CFX_FloatPoint(0.0f, 0.0f)); - SetCharSet(0); + SetCharSet(FXFONT_ANSI_CHARSET); if (!IsReadOnly()) { if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler()) diff --git a/fpdfsdk/pdfwindow/PWL_FontMap.cpp b/fpdfsdk/pdfwindow/PWL_FontMap.cpp index d4eab01cfd..e810ec6a8c 100644 --- a/fpdfsdk/pdfwindow/PWL_FontMap.cpp +++ b/fpdfsdk/pdfwindow/PWL_FontMap.cpp @@ -281,10 +281,10 @@ CFX_ByteString CPWL_FontMap::GetNativeFont(int32_t nCharset) { CFX_ByteString sFontName = GetDefaultFontByCharset(nCharset); if (m_pSystemHandler) { - if (m_pSystemHandler->FindNativeTrueTypeFont(nCharset, sFontName)) + if (m_pSystemHandler->FindNativeTrueTypeFont(sFontName)) return sFontName; - sFontName = ""; + sFontName.clear(); } return sFontName; } @@ -437,8 +437,6 @@ CFX_ByteString CPWL_FontMap::GetDefaultFontByCharset(int32_t nCharset) { } int32_t CPWL_FontMap::CharSetFromUnicode(uint16_t word, int32_t nOldCharset) { - if (m_pSystemHandler && (-1 != m_pSystemHandler->GetCharSet())) - return m_pSystemHandler->GetCharSet(); // to avoid CJK Font to show ASCII if (word < 0x7F) return ANSI_CHARSET; diff --git a/xfa/fde/fde_gedevice.cpp b/xfa/fde/fde_gedevice.cpp index 98f2492b79..ba72e7d014 100644 --- a/xfa/fde/fde_gedevice.cpp +++ b/xfa/fde/fde_gedevice.cpp @@ -137,9 +137,9 @@ FX_BOOL CFDE_RenderDevice::DrawString(CFDE_Brush* pBrush, CFX_SubstFont SubstFxFont; FxFont.SetSubstFont(&SubstFxFont); SubstFxFont.m_Weight = dwFontStyle & FX_FONTSTYLE_Bold ? 700 : 400; - SubstFxFont.m_WeightCJK = SubstFxFont.m_Weight; SubstFxFont.m_ItalicAngle = dwFontStyle & FX_FONTSTYLE_Italic ? -12 : 0; - SubstFxFont.m_bItlicCJK = !!(dwFontStyle & FX_FONTSTYLE_Italic); + SubstFxFont.m_WeightCJK = SubstFxFont.m_Weight; + SubstFxFont.m_bItalicCJK = !!(dwFontStyle & FX_FONTSTYLE_Italic); #endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ for (int32_t i = 0; i < iCount; ++i) { diff --git a/xfa/fgas/font/fgas_gefont.cpp b/xfa/fgas/font/fgas_gefont.cpp index c07455556c..7863ef715b 100644 --- a/xfa/fgas/font/fgas_gefont.cpp +++ b/xfa/fgas/font/fgas_gefont.cpp @@ -83,8 +83,7 @@ CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr) m_pCharWidthMap(NULL), m_pRectArray(NULL), m_pBBoxMap(NULL), - m_pProvider(NULL), - m_wCharSet(0xFFFF) { + m_pProvider(NULL) { } CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles) @@ -103,8 +102,7 @@ CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles) m_pCharWidthMap(NULL), m_pRectArray(NULL), m_pBBoxMap(NULL), - m_pProvider(NULL), - m_wCharSet(0xFFFF) { + m_pProvider(NULL) { ASSERT(src.m_pFont); m_pFont = new CFX_Font; m_pFont->LoadClone(src.m_pFont); @@ -189,11 +187,6 @@ FX_BOOL CFGAS_GEFont::LoadFontInternal(const FX_WCHAR* pszFontFamily, } int32_t iWeight = (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; - uint16_t wCharSet = FX_GetCharsetFromCodePage(wCodePage); - if (wCharSet == 0xFFFF) { - wCharSet = FXSYS_GetACP(); - } - m_wCharSet = wCharSet; m_pFont = new CFX_Font; if ((dwFlags & FXFONT_ITALIC) && (dwFlags & FXFONT_BOLD)) { csFontFamily += ",BoldItalic"; @@ -203,24 +196,19 @@ FX_BOOL CFGAS_GEFont::LoadFontInternal(const FX_WCHAR* pszFontFamily, csFontFamily += ",Italic"; } m_pFont->LoadSubst(csFontFamily, TRUE, dwFlags, iWeight, 0, wCodePage); - FX_BOOL bRet = m_pFont->GetFace() != nullptr; - if (bRet) { - bRet = InitFont(); - } - return bRet; + if (!m_pFont->GetFace()) + return false; + return InitFont(); } FX_BOOL CFGAS_GEFont::LoadFontInternal(const uint8_t* pBuffer, int32_t length) { - if (m_pFont) { + if (m_pFont) return FALSE; - } + m_pFont = new CFX_Font; - FX_BOOL bRet = m_pFont->LoadEmbedded(pBuffer, length); - if (bRet) { - bRet = InitFont(); - } - m_wCharSet = 0xFFFF; - return bRet; + if (!m_pFont->LoadEmbedded(pBuffer, length)) + return FALSE; + return InitFont(); } FX_BOOL CFGAS_GEFont::LoadFontInternal(IFX_Stream* pFontStream, @@ -240,7 +228,6 @@ FX_BOOL CFGAS_GEFont::LoadFontInternal(IFX_Stream* pFontStream, m_pFileRead->Release(); m_pFileRead = nullptr; } - m_wCharSet = 0xFFFF; return bRet; } #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ @@ -251,7 +238,6 @@ FX_BOOL CFGAS_GEFont::LoadFontInternal(CFX_Font* pExtFont) { } m_pFont = pExtFont; m_bExtFont = TRUE; - m_wCharSet = 0xFFFF; return InitFont(); } @@ -272,21 +258,13 @@ FX_BOOL CFGAS_GEFont::InitFont() { return TRUE; } + CFGAS_GEFont* CFGAS_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) { - if (GetFontStyles() == dwFontStyles) { + if (GetFontStyles() == dwFontStyles) return Retain(); - } return new CFGAS_GEFont(*this, dwFontStyles); } -uint8_t CFGAS_GEFont::GetCharSet() const { - if (m_wCharSet != 0xFFFF) { - return (uint8_t)m_wCharSet; - } - if (!m_pFont->GetSubstFont()) { - return FX_CHARSET_Default; - } - return m_pFont->GetSubstFont()->m_Charset; -} + void CFGAS_GEFont::GetFamilyName(CFX_WideString& wsFamily) const { if (!m_pFont->GetSubstFont() || m_pFont->GetSubstFont()->m_Family.GetLength() == 0) { diff --git a/xfa/fgas/font/fgas_gefont.h b/xfa/fgas/font/fgas_gefont.h index 30f1c99159..5d7b664cf9 100644 --- a/xfa/fgas/font/fgas_gefont.h +++ b/xfa/fgas/font/fgas_gefont.h @@ -39,7 +39,6 @@ class CFGAS_GEFont { CFGAS_GEFont* Derive(uint32_t dwFontStyles, uint16_t wCodePage = 0); void GetFamilyName(CFX_WideString& wsFamily) const; uint32_t GetFontStyles() const; - uint8_t GetCharSet() const; FX_BOOL GetCharWidth(FX_WCHAR wUnicode, int32_t& iWidth, FX_BOOL bCharCode = FALSE); @@ -103,7 +102,6 @@ class CFGAS_GEFont { CFX_MassArrayTemplate* m_pRectArray; CFX_MapPtrToPtr* m_pBBoxMap; CXFA_PDFFontMgr* m_pProvider; - uint16_t m_wCharSet; CFX_ArrayTemplate m_SubstFonts; std::map m_FontMapper; }; diff --git a/xfa/fgas/font/fgas_stdfontmgr.cpp b/xfa/fgas/font/fgas_stdfontmgr.cpp index 00b1028a76..34f5078962 100644 --- a/xfa/fgas/font/fgas_stdfontmgr.cpp +++ b/xfa/fgas/font/fgas_stdfontmgr.cpp @@ -1163,32 +1163,26 @@ void CFGAS_FontMgrImp::RegisterFace(FXFT_Face pFace, if ((pFace->face_flags & FT_FACE_FLAG_SCALABLE) == 0) return; - CFX_FontDescriptor* pFont = new CFX_FontDescriptor; + std::unique_ptr pFont(new CFX_FontDescriptor); pFont->m_dwFontStyles |= FXFT_Is_Face_Bold(pFace) ? FX_FONTSTYLE_Bold : 0; pFont->m_dwFontStyles |= FXFT_Is_Face_Italic(pFace) ? FX_FONTSTYLE_Italic : 0; pFont->m_dwFontStyles |= GetFlags(pFace); - CFX_ArrayTemplate Charsets; - GetCharsets(pFace, Charsets); + std::vector charsets = GetCharsets(pFace); GetUSBCSB(pFace, pFont->m_dwUsb, pFont->m_dwCsb); FT_ULong dwTag; - uint8_t* pTable = nullptr; FT_ENC_TAG(dwTag, 'n', 'a', 'm', 'e'); + std::vector table; unsigned long nLength = 0; unsigned int error = FXFT_Load_Sfnt_Table(pFace, dwTag, 0, nullptr, &nLength); if (error == 0 && nLength != 0) { - pTable = FX_Alloc(uint8_t, nLength); - error = FXFT_Load_Sfnt_Table(pFace, dwTag, 0, pTable, nullptr); - if (0 != error) { - FX_Free(pTable); - pTable = nullptr; - } + table.resize(nLength); + if (FXFT_Load_Sfnt_Table(pFace, dwTag, 0, table.data(), nullptr)) + table.clear(); } - GetNames(pTable, pFont->m_wsFamilyNames); - if (pTable) - FX_Free(pTable); + GetNames(table.empty() ? nullptr : table.data(), pFont->m_wsFamilyNames); pFont->m_wsFamilyNames.Add(CFX_ByteString(pFace->family_name).UTF8Decode()); pFont->m_wsFaceName = @@ -1196,7 +1190,7 @@ void CFGAS_FontMgrImp::RegisterFace(FXFT_Face pFace, : CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(pFace)); pFont->m_nFaceIndex = pFace->face_index; - Fonts.Add(pFont); + Fonts.Add(pFont.release()); } void CFGAS_FontMgrImp::RegisterFaces(IFX_FileRead* pFontStream, @@ -1346,30 +1340,28 @@ FX_BIT2CHARSET g_FX_Bit2Charset4[16] = { {1 << 14, FX_CHARSET_Default}, {1 << 15, FX_CHARSET_US}, }; -#define CODEPAGERANGE_IMPLEMENT(n) \ - for (int32_t i = 0; i < 16; i++) { \ - if ((a##n & g_FX_Bit2Charset##n[i].wBit) != 0) { \ - Charsets.Add(g_FX_Bit2Charset##n[i].wCharset); \ - } \ +#define CODEPAGERANGE_IMPLEMENT(n) \ + for (int32_t i = 0; i < 16; i++) { \ + if ((a##n & g_FX_Bit2Charset##n[i].wBit) != 0) \ + charsets.push_back(g_FX_Bit2Charset##n[i].wCharset); \ } -void CFGAS_FontMgrImp::GetCharsets(FXFT_Face pFace, - CFX_ArrayTemplate& Charsets) { - Charsets.RemoveAll(); +std::vector CFGAS_FontMgrImp::GetCharsets(FXFT_Face pFace) const { + std::vector charsets; TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); - if (NULL != pOS2) { - uint16_t a1, a2, a3, a4; - a1 = pOS2->ulCodePageRange1 & 0x0000ffff; + if (pOS2) { + uint16_t a1 = pOS2->ulCodePageRange1 & 0xffff; CODEPAGERANGE_IMPLEMENT(1); - a2 = (pOS2->ulCodePageRange1 >> 16) & 0x0000ffff; + uint16_t a2 = (pOS2->ulCodePageRange1 >> 16) & 0xffff; CODEPAGERANGE_IMPLEMENT(2); - a3 = pOS2->ulCodePageRange2 & 0x0000ffff; + uint16_t a3 = pOS2->ulCodePageRange2 & 0xffff; CODEPAGERANGE_IMPLEMENT(3); - a4 = (pOS2->ulCodePageRange2 >> 16) & 0x0000ffff; + uint16_t a4 = (pOS2->ulCodePageRange2 >> 16) & 0xffff; CODEPAGERANGE_IMPLEMENT(4); } else { - Charsets.Add(FX_CHARSET_Default); + charsets.push_back(FX_CHARSET_Default); } + return charsets; } #undef CODEPAGERANGE_IMPLEMENT diff --git a/xfa/fgas/font/fgas_stdfontmgr.h b/xfa/fgas/font/fgas_stdfontmgr.h index 66b1412d10..f66729e21b 100644 --- a/xfa/fgas/font/fgas_stdfontmgr.h +++ b/xfa/fgas/font/fgas_stdfontmgr.h @@ -7,6 +7,8 @@ #ifndef XFA_FGAS_FONT_FGAS_STDFONTMGR_H_ #define XFA_FGAS_FONT_FGAS_STDFONTMGR_H_ +#include + #include "core/fxcrt/include/fx_ext.h" #include "core/fxge/include/fx_freetype.h" #include "third_party/freetype/include/freetype/fttypes.h" @@ -194,7 +196,7 @@ class CFGAS_FontMgrImp : public IFGAS_FontMgr { void RegisterFaces(IFX_FileRead* pFontStream, const CFX_WideString* pFaceName); void GetNames(const uint8_t* name_table, CFX_WideStringArray& Names); - void GetCharsets(FXFT_Face pFace, CFX_ArrayTemplate& Charsets); + std::vector GetCharsets(FXFT_Face pFace) const; void GetUSBCSB(FXFT_Face pFace, uint32_t* USB, uint32_t* CSB); uint32_t GetFlags(FXFT_Face pFace); CFX_FontDescriptors m_InstalledFonts; -- cgit v1.2.3