summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2017-01-09 06:54:27 -0800
committerCommit bot <commit-bot@chromium.org>2017-01-09 06:54:27 -0800
commit5037839bb0b91792b81a3e455dead1314fcc7a6d (patch)
treef34f8e39155290f4c69e7a7b4eff5252f93a86ac
parent591ed144f8dfe4b2915f01f1cc725f584d498a3f (diff)
downloadpdfium-5037839bb0b91792b81a3e455dead1314fcc7a6d.tar.xz
Tidy cfgas_fontmgr, remove custom sorting code.
Review-Url: https://codereview.chromium.org/2610813010
-rw-r--r--core/fxcrt/fx_ext.h23
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.cpp83
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.h28
3 files changed, 47 insertions, 87 deletions
diff --git a/core/fxcrt/fx_ext.h b/core/fxcrt/fx_ext.h
index 737ea849c9..20580760c6 100644
--- a/core/fxcrt/fx_ext.h
+++ b/core/fxcrt/fx_ext.h
@@ -99,27 +99,4 @@ void FX_GUID_ToString(FX_LPCGUID pGUID,
bool bSeparator = true);
#endif // PDF_ENABLE_XFA
-template <class baseType>
-class CFX_SSortTemplate {
- public:
- void ShellSort(baseType* pArray, int32_t iCount) {
- ASSERT(pArray && iCount > 0);
- int32_t i, j, gap;
- baseType v1, v2;
- gap = iCount >> 1;
- while (gap > 0) {
- for (i = gap; i < iCount; i++) {
- j = i - gap;
- v1 = pArray[i];
- while (j > -1 && (v2 = pArray[j]) > v1) {
- pArray[j + gap] = v2;
- j -= gap;
- }
- pArray[j + gap] = v1;
- }
- gap >>= 1;
- }
- }
-};
-
#endif // CORE_FXCRT_FX_EXT_H_
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index 9d3954fb1e..72f7b88f95 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -6,6 +6,7 @@
#include "xfa/fgas/font/cfgas_fontmgr.h"
+#include <algorithm>
#include <memory>
#include <utility>
@@ -572,10 +573,7 @@ std::unique_ptr<CFGAS_FontMgr> CFGAS_FontMgr::Create(
CFGAS_FontMgr::CFGAS_FontMgr(CFX_FontSourceEnum_File* pFontEnum)
: m_pFontSource(pFontEnum) {}
-CFGAS_FontMgr::~CFGAS_FontMgr() {
- for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++)
- delete m_InstalledFonts[i];
-}
+CFGAS_FontMgr::~CFGAS_FontMgr() {}
bool CFGAS_FontMgr::EnumFontsFromFontMapper() {
CFX_FontMapper* pFontMapper =
@@ -598,7 +596,7 @@ bool CFGAS_FontMgr::EnumFontsFromFontMapper() {
CFX_WideString::FromLocal(pFontMapper->GetFaceName(i).c_str());
RegisterFaces(pFontStream, &wsFaceName);
}
- return m_InstalledFonts.GetSize() != 0;
+ return !m_InstalledFonts.empty();
}
bool CFGAS_FontMgr::EnumFontsFromFiles() {
@@ -611,7 +609,7 @@ bool CFGAS_FontMgr::EnumFontsFromFiles() {
if (pFontStream)
RegisterFaces(pFontStream, nullptr);
}
- return m_InstalledFonts.GetSize() != 0;
+ return !m_InstalledFonts.empty();
}
bool CFGAS_FontMgr::EnumFonts() {
@@ -637,18 +635,19 @@ CFX_RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByCodePage(
if (!pFontArray->empty())
return (*pFontArray)[0];
- CFX_FontDescriptorInfos* sortedFonts = m_Hash2CandidateList[dwHash].get();
- if (!sortedFonts) {
- auto pNewFonts = pdfium::MakeUnique<CFX_FontDescriptorInfos>();
- sortedFonts = pNewFonts.get();
- MatchFonts(*sortedFonts, wCodePage, dwFontStyles,
+ std::vector<CFX_FontDescriptorInfo>* sortedFontInfos =
+ m_Hash2CandidateList[dwHash].get();
+ if (!sortedFontInfos) {
+ auto pNewFonts = pdfium::MakeUnique<std::vector<CFX_FontDescriptorInfo>>();
+ sortedFontInfos = pNewFonts.get();
+ MatchFonts(sortedFontInfos, wCodePage, dwFontStyles,
CFX_WideString(pszFontFamily), 0);
m_Hash2CandidateList[dwHash] = std::move(pNewFonts);
}
- if (sortedFonts->GetSize() == 0)
+ if (sortedFontInfos->empty())
return nullptr;
- CFX_FontDescriptor* pDesc = sortedFonts->GetAt(0).pFont;
+ CFX_FontDescriptor* pDesc = (*sortedFontInfos)[0].pFont;
CFX_RetainPtr<CFGAS_GEFont> pFont =
LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr);
if (!pFont)
@@ -681,16 +680,17 @@ CFX_RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByUnicode(
if (VerifyUnicode((*pFonts)[i], wUnicode))
return (*pFonts)[i];
}
- CFX_FontDescriptorInfos* sortedFonts = m_Hash2CandidateList[dwHash].get();
- if (!sortedFonts) {
- auto pNewFonts = pdfium::MakeUnique<CFX_FontDescriptorInfos>();
- sortedFonts = pNewFonts.get();
- MatchFonts(*sortedFonts, wCodePage, dwFontStyles,
+ std::vector<CFX_FontDescriptorInfo>* sortedFontInfos =
+ m_Hash2CandidateList[dwHash].get();
+ if (!sortedFontInfos) {
+ auto pNewFonts = pdfium::MakeUnique<std::vector<CFX_FontDescriptorInfo>>();
+ sortedFontInfos = pNewFonts.get();
+ MatchFonts(sortedFontInfos, wCodePage, dwFontStyles,
CFX_WideString(pszFontFamily), wUnicode);
m_Hash2CandidateList[dwHash] = std::move(pNewFonts);
}
- for (int32_t i = 0; i < sortedFonts->GetSize(); ++i) {
- CFX_FontDescriptor* pDesc = sortedFonts->GetAt(i).pFont;
+ for (const auto& info : *sortedFontInfos) {
+ CFX_FontDescriptor* pDesc = info.pFont;
if (!VerifyUnicode(pDesc, wUnicode))
continue;
CFX_RetainPtr<CFGAS_GEFont> pFont =
@@ -874,36 +874,23 @@ CFX_RetainPtr<IFX_SeekableReadStream> CFGAS_FontMgr::CreateFontStream(
return nullptr;
}
-int32_t CFGAS_FontMgr::MatchFonts(CFX_FontDescriptorInfos& MatchedFonts,
- uint16_t wCodePage,
- uint32_t dwFontStyles,
- const CFX_WideString& FontName,
- FX_WCHAR wcUnicode) {
- MatchedFonts.RemoveAll();
- CFX_WideString wsNormalizedFontName = FontName;
-
- CFX_FontDescriptor* pFont = nullptr;
- int32_t nCount = m_InstalledFonts.GetSize();
- for (int32_t i = 0; i < nCount; i++) {
- pFont = m_InstalledFonts[i];
- int32_t nPenalty = CalcPenalty(pFont, wCodePage, dwFontStyles,
- wsNormalizedFontName, wcUnicode);
+void CFGAS_FontMgr::MatchFonts(
+ std::vector<CFX_FontDescriptorInfo>* pMatchedFonts,
+ uint16_t wCodePage,
+ uint32_t dwFontStyles,
+ const CFX_WideString& FontName,
+ FX_WCHAR wcUnicode) {
+ pMatchedFonts->clear();
+ for (const auto& pFont : m_InstalledFonts) {
+ int32_t nPenalty =
+ CalcPenalty(pFont.get(), wCodePage, dwFontStyles, FontName, wcUnicode);
if (nPenalty >= 0xffff)
continue;
-
- FX_FontDescriptorInfo FontInfo;
- FontInfo.pFont = pFont;
- FontInfo.nPenalty = nPenalty;
- MatchedFonts.Add(FontInfo);
- if (MatchedFonts.GetSize() == 0xffff)
+ pMatchedFonts->push_back({pFont.get(), nPenalty});
+ if (pMatchedFonts->size() == 0xffff)
break;
}
- if (MatchedFonts.GetSize() == 0)
- return 0;
-
- CFX_SSortTemplate<FX_FontDescriptorInfo> ssort;
- ssort.ShellSort(MatchedFonts.GetData(), MatchedFonts.GetSize());
- return MatchedFonts.GetSize();
+ std::sort(pMatchedFonts->begin(), pMatchedFonts->end());
}
int32_t CFGAS_FontMgr::CalcPenalty(CFX_FontDescriptor* pInstalled,
@@ -1003,7 +990,7 @@ void CFGAS_FontMgr::RegisterFace(FXFT_Face pFace,
if ((pFace->face_flags & FT_FACE_FLAG_SCALABLE) == 0)
return;
- std::unique_ptr<CFX_FontDescriptor> pFont(new CFX_FontDescriptor);
+ auto pFont = pdfium::MakeUnique<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);
@@ -1029,7 +1016,7 @@ void CFGAS_FontMgr::RegisterFace(FXFT_Face pFace,
pFaceName ? *pFaceName
: CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(pFace));
pFont->m_nFaceIndex = pFace->face_index;
- m_InstalledFonts.Add(pFont.release());
+ m_InstalledFonts.push_back(std::move(pFont));
}
void CFGAS_FontMgr::RegisterFaces(
diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h
index 20efa3296b..303d73404b 100644
--- a/xfa/fgas/font/cfgas_fontmgr.h
+++ b/xfa/fgas/font/cfgas_fontmgr.h
@@ -146,26 +146,22 @@ class CFX_FontDescriptor {
uint32_t m_dwCsb[2];
};
-typedef CFX_ArrayTemplate<CFX_FontDescriptor*> CFX_FontDescriptors;
-
-struct FX_FontDescriptorInfo {
+class CFX_FontDescriptorInfo {
public:
CFX_FontDescriptor* pFont;
int32_t nPenalty;
- bool operator>(const FX_FontDescriptorInfo& other) const {
+ bool operator>(const CFX_FontDescriptorInfo& other) const {
return nPenalty > other.nPenalty;
}
- bool operator<(const FX_FontDescriptorInfo& other) const {
+ bool operator<(const CFX_FontDescriptorInfo& other) const {
return nPenalty < other.nPenalty;
}
- bool operator==(const FX_FontDescriptorInfo& other) const {
+ bool operator==(const CFX_FontDescriptorInfo& other) const {
return nPenalty == other.nPenalty;
}
};
-typedef CFX_ArrayTemplate<FX_FontDescriptorInfo> CFX_FontDescriptorInfos;
-
struct FX_HandleParentPath {
FX_HandleParentPath() {}
FX_HandleParentPath(const FX_HandleParentPath& x) {
@@ -226,11 +222,11 @@ class CFGAS_FontMgr {
bool VerifyUnicode(const CFX_RetainPtr<CFGAS_GEFont>& pFont,
FX_WCHAR wcUnicode);
int32_t IsPartName(const CFX_WideString& Name1, const CFX_WideString& Name2);
- int32_t MatchFonts(CFX_FontDescriptorInfos& MatchedFonts,
- uint16_t wCodePage,
- uint32_t dwFontStyles,
- const CFX_WideString& FontName,
- FX_WCHAR wcUnicode = 0xFFFE);
+ void MatchFonts(std::vector<CFX_FontDescriptorInfo>* MatchedFonts,
+ uint16_t wCodePage,
+ uint32_t dwFontStyles,
+ const CFX_WideString& FontName,
+ FX_WCHAR wcUnicode = 0xFFFE);
int32_t CalcPenalty(CFX_FontDescriptor* pInstalled,
uint16_t wCodePage,
uint32_t dwFontStyles,
@@ -248,14 +244,14 @@ class CFGAS_FontMgr {
CFX_RetainPtr<IFX_SeekableReadStream> CreateFontStream(
const CFX_ByteString& bsFaceName);
- CFX_FontDescriptors m_InstalledFonts;
- std::map<uint32_t, std::unique_ptr<CFX_FontDescriptorInfos>>
+ CFX_FontSourceEnum_File* const m_pFontSource;
+ std::vector<std::unique_ptr<CFX_FontDescriptor>> m_InstalledFonts;
+ std::map<uint32_t, std::unique_ptr<std::vector<CFX_FontDescriptorInfo>>>
m_Hash2CandidateList;
std::map<uint32_t, std::vector<CFX_RetainPtr<CFGAS_GEFont>>> m_Hash2Fonts;
std::map<CFX_RetainPtr<CFGAS_GEFont>, CFX_RetainPtr<IFX_SeekableReadStream>>
m_IFXFont2FileRead;
std::set<FX_WCHAR> m_FailedUnicodesSet;
- CFX_FontSourceEnum_File* const m_pFontSource;
};
#endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_