summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-08-17 20:44:22 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-17 20:44:22 +0000
commitcffa651acfa7ca1d90aecea728e94c5c3dcdfe79 (patch)
tree11f2db075105c99e6967a5476d3803739092fb96
parent16208a0ef769a84c7e96ff5d55a16637ca01de03 (diff)
downloadpdfium-cffa651acfa7ca1d90aecea728e94c5c3dcdfe79.tar.xz
Change CFPF_SkiaFontMgr::m_FontFaces to store unique_ptrs.
Instead of raw pointers. Change-Id: Ie46af37bbe3fe287bdff25249afaeb90589c85b3 Reviewed-on: https://pdfium-review.googlesource.com/40552 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r--core/fxge/android/cfpf_skiafont.cpp2
-rw-r--r--core/fxge/android/cfpf_skiafont.h4
-rw-r--r--core/fxge/android/cfpf_skiafontmgr.cpp30
-rw-r--r--core/fxge/android/cfpf_skiafontmgr.h6
4 files changed, 22 insertions, 20 deletions
diff --git a/core/fxge/android/cfpf_skiafont.cpp b/core/fxge/android/cfpf_skiafont.cpp
index 24984e8d9f..0118f9512e 100644
--- a/core/fxge/android/cfpf_skiafont.cpp
+++ b/core/fxge/android/cfpf_skiafont.cpp
@@ -171,7 +171,7 @@ uint32_t CFPF_SkiaFont::GetFontData(uint32_t dwTable,
}
bool CFPF_SkiaFont::InitFont(CFPF_SkiaFontMgr* pFontMgr,
- CFPF_SkiaPathFont* pFont,
+ const CFPF_SkiaPathFont* pFont,
const ByteStringView& bsFamily,
uint32_t dwStyle,
uint8_t uCharset) {
diff --git a/core/fxge/android/cfpf_skiafont.h b/core/fxge/android/cfpf_skiafont.h
index 260e4222a5..d80378ec75 100644
--- a/core/fxge/android/cfpf_skiafont.h
+++ b/core/fxge/android/cfpf_skiafont.h
@@ -37,14 +37,14 @@ class CFPF_SkiaFont {
uint32_t GetFontData(uint32_t dwTable, uint8_t* pBuffer, uint32_t dwSize);
bool InitFont(CFPF_SkiaFontMgr* pFontMgr,
- CFPF_SkiaPathFont* pFont,
+ const CFPF_SkiaPathFont* pFont,
const ByteStringView& bsFamily,
uint32_t dwStyle,
uint8_t uCharset);
private:
UnownedPtr<CFPF_SkiaFontMgr> m_pFontMgr;
- UnownedPtr<CFPF_SkiaPathFont> m_pFont;
+ UnownedPtr<const CFPF_SkiaPathFont> m_pFont;
FXFT_Face m_Face = nullptr;
uint32_t m_dwStyle = 0;
uint8_t m_uCharset = 0;
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp
index b091ae9fd7..6edc334a9d 100644
--- a/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -21,6 +21,7 @@
#include "core/fxge/android/cfpf_skiafont.h"
#include "core/fxge/android/cfpf_skiapathfont.h"
#include "core/fxge/fx_freetype.h"
+#include "third_party/base/ptr_util.h"
namespace {
@@ -232,8 +233,6 @@ CFPF_SkiaFontMgr::~CFPF_SkiaFontMgr() {
pair.second->Release();
}
m_FamilyFonts.clear();
- for (auto it = m_FontFaces.begin(); it != m_FontFaces.end(); ++it)
- delete *it;
m_FontFaces.clear();
if (m_FTLibrary)
FXFT_Done_FreeType(m_FTLibrary);
@@ -276,11 +275,11 @@ CFPF_SkiaFont* CFPF_SkiaFontMgr::CreateFont(const ByteStringView& bsFamilyname,
}
int32_t nExpectVal = FPF_SKIAMATCHWEIGHT_NAME1 + FPF_SKIAMATCHWEIGHT_1 * 3 +
FPF_SKIAMATCHWEIGHT_2 * 2;
- CFPF_SkiaPathFont* pBestFont = nullptr;
+ const CFPF_SkiaPathFont* pBestFont = nullptr;
int32_t nMax = -1;
int32_t nGlyphNum = 0;
for (auto it = m_FontFaces.rbegin(); it != m_FontFaces.rend(); ++it) {
- CFPF_SkiaPathFont* pFont = *it;
+ const CFPF_SkiaPathFont* pFont = it->get();
if (!(pFont->m_dwCharsets & FPF_SkiaGetCharset(uCharset)))
continue;
int32_t nFind = 0;
@@ -307,19 +306,19 @@ CFPF_SkiaFont* CFPF_SkiaFontMgr::CreateFont(const ByteStringView& bsFamilyname,
if (uCharset == FX_CHARSET_Default || bMaybeSymbol) {
if (nFind > nMax && bMatchedName) {
nMax = nFind;
- pBestFont = *it;
+ pBestFont = it->get();
}
} else if (FPF_SkiaIsCJK(uCharset)) {
if (bMatchedName || pFont->m_iGlyphNum > nGlyphNum) {
- pBestFont = *it;
+ pBestFont = it->get();
nGlyphNum = pFont->m_iGlyphNum;
}
} else if (nFind > nMax) {
nMax = nFind;
- pBestFont = *it;
+ pBestFont = it->get();
}
if (nExpectVal <= nFind) {
- pBestFont = *it;
+ pBestFont = it->get();
break;
}
}
@@ -381,16 +380,16 @@ void CFPF_SkiaFontMgr::ScanFile(const ByteString& file) {
FXFT_Face face = GetFontFace(file.AsStringView(), 0);
if (!face)
return;
- CFPF_SkiaPathFont* pFont = new CFPF_SkiaPathFont;
- pFont->SetPath(file.c_str());
- ReportFace(face, pFont);
- m_FontFaces.push_back(pFont);
+
+ m_FontFaces.push_back(ReportFace(face, file));
FXFT_Done_Face(face);
}
-void CFPF_SkiaFontMgr::ReportFace(FXFT_Face face, CFPF_SkiaPathFont* pFont) {
- if (!face || !pFont)
- return;
+std::unique_ptr<CFPF_SkiaPathFont> CFPF_SkiaFontMgr::ReportFace(
+ FXFT_Face face,
+ const ByteString& file) {
+ auto pFont = pdfium::MakeUnique<CFPF_SkiaPathFont>();
+ pFont->SetPath(file.c_str());
pFont->SetFamily(FXFT_Get_Face_Family_Name(face));
if (FXFT_Is_Face_Bold(face))
pFont->m_dwStyle |= FXFONT_BOLD;
@@ -413,4 +412,5 @@ void CFPF_SkiaFontMgr::ReportFace(FXFT_Face face, CFPF_SkiaPathFont* pFont) {
pFont->m_dwCharsets = FPF_SkiaGetFaceCharset(pOS2);
pFont->m_iFaceIndex = face->face_index;
pFont->m_iGlyphNum = face->num_glyphs;
+ return pFont;
}
diff --git a/core/fxge/android/cfpf_skiafontmgr.h b/core/fxge/android/cfpf_skiafontmgr.h
index af2d3acfc8..99aafd7bd2 100644
--- a/core/fxge/android/cfpf_skiafontmgr.h
+++ b/core/fxge/android/cfpf_skiafontmgr.h
@@ -8,6 +8,7 @@
#define CORE_FXGE_ANDROID_CFPF_SKIAFONTMGR_H_
#include <map>
+#include <memory>
#include <vector>
#include "core/fxcrt/fx_string.h"
@@ -35,11 +36,12 @@ class CFPF_SkiaFontMgr {
private:
void ScanPath(const ByteString& path);
void ScanFile(const ByteString& file);
- void ReportFace(FXFT_Face face, CFPF_SkiaPathFont* pFont);
+ std::unique_ptr<CFPF_SkiaPathFont> ReportFace(FXFT_Face face,
+ const ByteString& file);
bool m_bLoaded = false;
FXFT_Library m_FTLibrary = nullptr;
- std::vector<CFPF_SkiaPathFont*> m_FontFaces;
+ std::vector<std::unique_ptr<CFPF_SkiaPathFont>> m_FontFaces;
std::map<uint32_t, CFPF_SkiaFont*> m_FamilyFonts;
};