summaryrefslogtreecommitdiff
path: root/xfa/fgas/font
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-03-02 10:36:58 -0800
committerChromium commit bot <commit-bot@chromium.org>2017-03-02 19:07:33 +0000
commitcb5eb3bdb0ed36571d313b38dad59e5bde65f4a7 (patch)
tree5e6beeee3f4dffb1a0eaeee6e8a5ec0cc96dc423 /xfa/fgas/font
parent4df55209c2f922f33c2f69fadfff5d30026e89d2 (diff)
downloadpdfium-cb5eb3bdb0ed36571d313b38dad59e5bde65f4a7.tar.xz
Use std::deque for CFX_FontDescriptors
Change-Id: Ic6edc7740513075c2a738cc8897460af17bb0103 Reviewed-on: https://pdfium-review.googlesource.com/2895 Commit-Queue: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fgas/font')
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.cpp71
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.h7
2 files changed, 38 insertions, 40 deletions
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index 57b499fb10..aa41318f5d 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -47,49 +47,49 @@ int32_t GetSimilarityScore(FX_FONTDESCRIPTOR const* pFont,
return iValue;
}
-FX_FONTDESCRIPTOR const* MatchDefaultFont(FX_FONTMATCHPARAMS* pParams,
- const CFX_FontDescriptors& fonts) {
- FX_FONTDESCRIPTOR const* pBestFont = nullptr;
+const FX_FONTDESCRIPTOR* MatchDefaultFont(
+ FX_FONTMATCHPARAMS* pParams,
+ const std::deque<FX_FONTDESCRIPTOR>& fonts) {
+ const FX_FONTDESCRIPTOR* pBestFont = nullptr;
int32_t iBestSimilar = 0;
bool bMatchStyle = (pParams->dwMatchFlags & FX_FONTMATCHPARA_MatchStyle) > 0;
- for (int32_t i = 0; i < fonts.GetSize(); ++i) {
- FX_FONTDESCRIPTOR const* pFont = fonts.GetPtrAt(i);
- if ((pFont->dwFontStyles & FX_FONTSTYLE_BoldItalic) ==
+ for (const auto& font : fonts) {
+ if ((font.dwFontStyles & FX_FONTSTYLE_BoldItalic) ==
FX_FONTSTYLE_BoldItalic) {
continue;
}
if (pParams->pwsFamily) {
- if (FXSYS_wcsicmp(pParams->pwsFamily, pFont->wsFontFace))
+ if (FXSYS_wcsicmp(pParams->pwsFamily, font.wsFontFace))
continue;
- if (pFont->uCharSet == FX_CHARSET_Symbol)
- return pFont;
+ if (font.uCharSet == FX_CHARSET_Symbol)
+ return &font;
}
- if (pFont->uCharSet == FX_CHARSET_Symbol)
+ if (font.uCharSet == FX_CHARSET_Symbol)
continue;
if (pParams->wCodePage != 0xFFFF) {
- if (FX_GetCodePageFromCharset(pFont->uCharSet) != pParams->wCodePage)
+ if (FX_GetCodePageFromCharset(font.uCharSet) != pParams->wCodePage)
continue;
} else {
if (pParams->dwUSB < 128) {
uint32_t dwByte = pParams->dwUSB / 32;
uint32_t dwUSB = 1 << (pParams->dwUSB % 32);
- if ((pFont->FontSignature.fsUsb[dwByte] & dwUSB) == 0)
+ if ((font.FontSignature.fsUsb[dwByte] & dwUSB) == 0)
continue;
}
}
if (bMatchStyle) {
- if ((pFont->dwFontStyles & 0x0F) == (pParams->dwFontStyles & 0x0F))
- return pFont;
+ if ((font.dwFontStyles & 0x0F) == (pParams->dwFontStyles & 0x0F))
+ return &font;
continue;
}
if (pParams->pwsFamily) {
- if (FXSYS_wcsicmp(pParams->pwsFamily, pFont->wsFontFace) == 0)
- return pFont;
+ if (FXSYS_wcsicmp(pParams->pwsFamily, font.wsFontFace) == 0)
+ return &font;
}
- int32_t iSimilarValue = GetSimilarityScore(pFont, pParams->dwFontStyles);
+ int32_t iSimilarValue = GetSimilarityScore(&font, pParams->dwFontStyles);
if (iBestSimilar < iSimilarValue) {
iBestSimilar = iSimilarValue;
- pBestFont = pFont;
+ pBestFont = &font;
}
}
return iBestSimilar < 1 ? nullptr : pBestFont;
@@ -105,12 +105,10 @@ std::unique_ptr<CFGAS_FontMgr> CFGAS_FontMgr::Create(
CFGAS_FontMgr::CFGAS_FontMgr(FX_LPEnumAllFonts pEnumerator)
: m_pEnumerator(pEnumerator), m_FontFaces(100) {
if (m_pEnumerator)
- m_pEnumerator(m_FontFaces, nullptr, 0xFEFF);
+ m_pEnumerator(&m_FontFaces, nullptr, 0xFEFF);
}
-CFGAS_FontMgr::~CFGAS_FontMgr() {
- m_FontFaces.RemoveAll(false);
-}
+CFGAS_FontMgr::~CFGAS_FontMgr() {}
CFX_RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByCodePage(
uint16_t wCodePage,
@@ -264,7 +262,7 @@ void CFGAS_FontMgr::RemoveFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont) {
m_Fonts.erase(it);
}
-FX_FONTDESCRIPTOR const* CFGAS_FontMgr::FindFont(const FX_WCHAR* pszFontFamily,
+const FX_FONTDESCRIPTOR* CFGAS_FontMgr::FindFont(const FX_WCHAR* pszFontFamily,
uint32_t dwFontStyles,
uint32_t dwMatchFlags,
uint16_t wCodePage,
@@ -278,25 +276,26 @@ FX_FONTDESCRIPTOR const* CFGAS_FontMgr::FindFont(const FX_WCHAR* pszFontFamily,
params.pwsFamily = pszFontFamily;
params.dwFontStyles = dwFontStyles;
params.dwMatchFlags = dwMatchFlags;
- FX_FONTDESCRIPTOR const* pDesc = MatchDefaultFont(&params, m_FontFaces);
+ const FX_FONTDESCRIPTOR* pDesc = MatchDefaultFont(&params, m_FontFaces);
if (pDesc)
return pDesc;
+
if (!pszFontFamily || !m_pEnumerator)
return nullptr;
- CFX_FontDescriptors namedFonts(100);
- m_pEnumerator(namedFonts, pszFontFamily, wUnicode);
+ std::deque<FX_FONTDESCRIPTOR> namedFonts;
+ m_pEnumerator(&namedFonts, pszFontFamily, wUnicode);
params.pwsFamily = nullptr;
pDesc = MatchDefaultFont(&params, namedFonts);
if (!pDesc)
return nullptr;
- for (int32_t i = m_FontFaces.GetSize() - 1; i >= 0; i--) {
- FX_FONTDESCRIPTOR const* pMatch = m_FontFaces.GetPtrAt(i);
- if (*pMatch == *pDesc)
- return pMatch;
- }
- int index = m_FontFaces.Add(*pDesc);
- return m_FontFaces.GetPtrAt(index);
+
+ auto it = std::find(m_FontFaces.rbegin(), m_FontFaces.rend(), *pDesc);
+ if (it != m_FontFaces.rend())
+ return &*it;
+
+ m_FontFaces.push_back(*pDesc);
+ return &m_FontFaces.back();
}
uint32_t FX_GetGdiFontStyles(const LOGFONTW& lf) {
@@ -330,12 +329,12 @@ static int32_t CALLBACK FX_GdiFontEnumProc(ENUMLOGFONTEX* lpelfe,
pFont->wsFontFace[31] = 0;
FXSYS_memcpy(&pFont->FontSignature, &lpntme->ntmFontSig,
sizeof(lpntme->ntmFontSig));
- ((CFX_FontDescriptors*)lParam)->Add(*pFont);
+ reinterpret_cast<std::deque<FX_FONTDESCRIPTOR>*>(lParam)->push_back(*pFont);
FX_Free(pFont);
return 1;
}
-static void FX_EnumGdiFonts(CFX_FontDescriptors& fonts,
+static void FX_EnumGdiFonts(std::deque<FX_FONTDESCRIPTOR>* fonts,
const FX_WCHAR* pwsFaceName,
FX_WCHAR wUnicode) {
HDC hDC = ::GetDC(nullptr);
@@ -347,7 +346,7 @@ static void FX_EnumGdiFonts(CFX_FontDescriptors& fonts,
lfFind.lfFaceName[31] = 0;
}
EnumFontFamiliesExW(hDC, (LPLOGFONTW)&lfFind,
- (FONTENUMPROCW)FX_GdiFontEnumProc, (LPARAM)&fonts, 0);
+ (FONTENUMPROCW)FX_GdiFontEnumProc, (LPARAM)fonts, 0);
::ReleaseDC(nullptr, hDC);
}
diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h
index 1dadfd347e..dffdb8a665 100644
--- a/xfa/fgas/font/cfgas_fontmgr.h
+++ b/xfa/fgas/font/cfgas_fontmgr.h
@@ -7,6 +7,7 @@
#ifndef XFA_FGAS_FONT_CFGAS_FONTMGR_H_
#define XFA_FGAS_FONT_CFGAS_FONTMGR_H_
+#include <deque>
#include <map>
#include <memory>
#include <set>
@@ -70,8 +71,6 @@ struct FX_FONTDESCRIPTOR {
FX_FONTSIGNATURE FontSignature;
};
-typedef CFX_MassArrayTemplate<FX_FONTDESCRIPTOR> CFX_FontDescriptors;
-
inline bool operator==(const FX_FONTDESCRIPTOR& left,
const FX_FONTDESCRIPTOR& right) {
return left.uCharSet == right.uCharSet &&
@@ -80,7 +79,7 @@ inline bool operator==(const FX_FONTDESCRIPTOR& left,
FXSYS_wcscmp(left.wsFontFace, right.wsFontFace) == 0;
}
-typedef void (*FX_LPEnumAllFonts)(CFX_FontDescriptors& fonts,
+typedef void (*FX_LPEnumAllFonts)(std::deque<FX_FONTDESCRIPTOR>* fonts,
const FX_WCHAR* pwsFaceName,
FX_WCHAR wUnicode);
@@ -119,7 +118,7 @@ class CFGAS_FontMgr {
FX_WCHAR wUnicode = 0);
FX_LPEnumAllFonts m_pEnumerator;
- CFX_FontDescriptors m_FontFaces;
+ std::deque<FX_FONTDESCRIPTOR> m_FontFaces;
std::vector<CFX_RetainPtr<CFGAS_GEFont>> m_Fonts;
std::map<uint32_t, CFX_RetainPtr<CFGAS_GEFont>> m_CPFonts;
std::map<uint32_t, CFX_RetainPtr<CFGAS_GEFont>> m_FamilyFonts;