summaryrefslogtreecommitdiff
path: root/core/fxge
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxge')
-rw-r--r--core/fxge/apple/fx_mac_imp.cpp6
-rw-r--r--core/fxge/ge/cfx_folderfontinfo.cpp24
-rw-r--r--core/fxge/ge/cfx_folderfontinfo.h5
-rw-r--r--core/fxge/ge/fx_ge_linux.cpp8
-rw-r--r--core/fxge/win32/fx_win32_device.cpp2
5 files changed, 23 insertions, 22 deletions
diff --git a/core/fxge/apple/fx_mac_imp.cpp b/core/fxge/apple/fx_mac_imp.cpp
index cb1adf701f..0b32083126 100644
--- a/core/fxge/apple/fx_mac_imp.cpp
+++ b/core/fxge/apple/fx_mac_imp.cpp
@@ -88,12 +88,12 @@ void* CFX_MacFontInfo::MapFont(int weight,
new_face += " Italic";
auto it = m_FontList.find(new_face);
if (it != m_FontList.end())
- return it->second;
+ return it->second.get();
}
auto it = m_FontList.find(face);
if (it != m_FontList.end())
- return it->second;
+ return it->second.get();
if (charset == FX_CHARSET_ANSI && (pitch_family & FXFONT_FF_FIXEDPITCH))
return GetFont("Courier New");
@@ -115,7 +115,7 @@ void* CFX_MacFontInfo::MapFont(int weight,
face = "LiSong Pro Light";
}
it = m_FontList.find(face);
- return it != m_FontList.end() ? it->second : nullptr;
+ return it != m_FontList.end() ? it->second.get() : nullptr;
}
} // namespace
diff --git a/core/fxge/ge/cfx_folderfontinfo.cpp b/core/fxge/ge/cfx_folderfontinfo.cpp
index d46c7b5fef..a13af068e8 100644
--- a/core/fxge/ge/cfx_folderfontinfo.cpp
+++ b/core/fxge/ge/cfx_folderfontinfo.cpp
@@ -7,11 +7,12 @@
#include "core/fxge/ge/cfx_folderfontinfo.h"
#include <limits>
+#include <utility>
#include "core/fxcrt/fx_codepage.h"
#include "core/fxge/cfx_fontmapper.h"
#include "core/fxge/fx_font.h"
-
+#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
namespace {
@@ -102,13 +103,10 @@ int32_t GetSimilarValue(int weight,
CFX_FolderFontInfo::CFX_FolderFontInfo() {}
-CFX_FolderFontInfo::~CFX_FolderFontInfo() {
- for (const auto& pair : m_FontList)
- delete pair.second;
-}
+CFX_FolderFontInfo::~CFX_FolderFontInfo() {}
-void CFX_FolderFontInfo::AddPath(const CFX_ByteStringC& path) {
- m_PathList.push_back(CFX_ByteString(path));
+void CFX_FolderFontInfo::AddPath(const CFX_ByteString& path) {
+ m_PathList.push_back(path);
}
bool CFX_FolderFontInfo::EnumFontList(CFX_FontMapper* pMapper) {
@@ -222,8 +220,8 @@ void CFX_FolderFontInfo::ReportFace(const CFX_ByteString& path,
if (pdfium::ContainsKey(m_FontList, facename))
return;
- CFX_FontFaceInfo* pInfo =
- new CFX_FontFaceInfo(path, facename, tables, offset, filesize);
+ auto pInfo = pdfium::MakeUnique<CFX_FontFaceInfo>(path, facename, tables,
+ offset, filesize);
CFX_ByteString os2 =
FPDF_LoadTableFromTT(pFile, tables.raw_str(), nTables, 0x4f532f32);
if (os2.GetLength() >= 86) {
@@ -260,7 +258,7 @@ void CFX_FolderFontInfo::ReportFace(const CFX_ByteString& path,
if (facename.Find("Serif") > -1)
pInfo->m_Styles |= FXFONT_SERIF;
- m_FontList[facename] = pInfo;
+ m_FontList[facename] = std::move(pInfo);
}
void* CFX_FolderFontInfo::GetSubstFont(const CFX_ByteString& face) {
@@ -281,17 +279,19 @@ void* CFX_FolderFontInfo::FindFont(int weight,
CFX_FontFaceInfo* pFind = nullptr;
if (charset == FX_CHARSET_ANSI && (pitch_family & FXFONT_FF_FIXEDPITCH))
return GetFont("Courier New");
+
uint32_t charset_flag = GetCharset(charset);
int32_t iBestSimilar = 0;
for (const auto& it : m_FontList) {
const CFX_ByteString& bsName = it.first;
- CFX_FontFaceInfo* pFont = it.second;
+ CFX_FontFaceInfo* pFont = it.second.get();
if (!(pFont->m_Charsets & charset_flag) && charset != FX_CHARSET_Default)
continue;
int32_t index = bsName.Find(family);
if (bMatchName && index < 0)
continue;
+
int32_t iSimilarValue =
GetSimilarValue(weight, bItalic, pitch_family, pFont->m_Styles);
if (iSimilarValue > iBestSimilar) {
@@ -322,7 +322,7 @@ void* CFX_FolderFontInfo::MapFontByUnicode(uint32_t dwUnicode,
void* CFX_FolderFontInfo::GetFont(const char* face) {
auto it = m_FontList.find(face);
- return it != m_FontList.end() ? it->second : nullptr;
+ return it != m_FontList.end() ? it->second.get() : nullptr;
}
uint32_t CFX_FolderFontInfo::GetFontData(void* hFont,
diff --git a/core/fxge/ge/cfx_folderfontinfo.h b/core/fxge/ge/cfx_folderfontinfo.h
index ab2468ade0..6aadb1526f 100644
--- a/core/fxge/ge/cfx_folderfontinfo.h
+++ b/core/fxge/ge/cfx_folderfontinfo.h
@@ -8,6 +8,7 @@
#define CORE_FXGE_GE_CFX_FOLDERFONTINFO_H_
#include <map>
+#include <memory>
#include <vector>
#include "core/fxge/cfx_fontmapper.h"
@@ -19,7 +20,7 @@ class CFX_FolderFontInfo : public IFX_SystemFontInfo {
CFX_FolderFontInfo();
~CFX_FolderFontInfo() override;
- void AddPath(const CFX_ByteStringC& path);
+ void AddPath(const CFX_ByteString& path);
// IFX_SytemFontInfo:
bool EnumFontList(CFX_FontMapper* pMapper) override;
@@ -59,7 +60,7 @@ class CFX_FolderFontInfo : public IFX_SystemFontInfo {
const char* family,
bool bMatchName);
- std::map<CFX_ByteString, CFX_FontFaceInfo*> m_FontList;
+ std::map<CFX_ByteString, std::unique_ptr<CFX_FontFaceInfo>> m_FontList;
std::vector<CFX_ByteString> m_PathList;
CFX_FontMapper* m_pMapper;
};
diff --git a/core/fxge/ge/fx_ge_linux.cpp b/core/fxge/ge/fx_ge_linux.cpp
index 8d2c496c19..b216e12127 100644
--- a/core/fxge/ge/fx_ge_linux.cpp
+++ b/core/fxge/ge/fx_ge_linux.cpp
@@ -97,7 +97,7 @@ void* CFX_LinuxFontInfo::MapFont(int weight,
for (size_t i = 0; i < kLinuxGpNameSize; i++) {
auto it = m_FontList.find(g_LinuxGpFontList[index][i]);
if (it != m_FontList.end())
- return it->second;
+ return it->second.get();
}
break;
}
@@ -105,7 +105,7 @@ void* CFX_LinuxFontInfo::MapFont(int weight,
for (size_t i = 0; i < FX_ArraySize(g_LinuxGbFontList); ++i) {
auto it = m_FontList.find(g_LinuxGbFontList[i]);
if (it != m_FontList.end())
- return it->second;
+ return it->second.get();
}
break;
}
@@ -113,7 +113,7 @@ void* CFX_LinuxFontInfo::MapFont(int weight,
for (size_t i = 0; i < FX_ArraySize(g_LinuxB5FontList); ++i) {
auto it = m_FontList.find(g_LinuxB5FontList[i]);
if (it != m_FontList.end())
- return it->second;
+ return it->second.get();
}
break;
}
@@ -121,7 +121,7 @@ void* CFX_LinuxFontInfo::MapFont(int weight,
for (size_t i = 0; i < FX_ArraySize(g_LinuxHGFontList); ++i) {
auto it = m_FontList.find(g_LinuxHGFontList[i]);
if (it != m_FontList.end())
- return it->second;
+ return it->second.get();
}
break;
}
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp
index de2f6c4b04..c67ed526d3 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -704,7 +704,7 @@ std::unique_ptr<IFX_SystemFontInfo> IFX_SystemFontInfo::CreateDefault(
if (path_len > 0 && path_len < MAX_PATH) {
CFX_ByteString fonts_path(windows_path);
fonts_path += "\\Fonts";
- pInfoFallback->AddPath(fonts_path.AsStringC());
+ pInfoFallback->AddPath(fonts_path);
}
return std::unique_ptr<IFX_SystemFontInfo>(pInfoFallback);
}