summaryrefslogtreecommitdiff
path: root/core/fxge/cttfontdesc.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-04-30 21:02:03 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-30 21:02:03 +0000
commitda65a8ea74d2748c93015fb5521da678e29e6548 (patch)
treec9455640dd3e89a43ab4cf7e3bf17ed475033b5d /core/fxge/cttfontdesc.cpp
parentf213df4a87ede709db1f311bbad3c68fbccf159c (diff)
downloadpdfium-da65a8ea74d2748c93015fb5521da678e29e6548.tar.xz
Saner memory managment in cttfontdesc, part 1.
A subsequent patch will tackle the ad-hoc ref counting, but we can tidy this before going down that hole. Decouple CTTFontDesc creation from face setting. Remove union and treat single-entry case as vector's first element. Pass unique_ptr to prove memory ownership. Change-Id: Ic427798da04f3afbb65a56ee10045b9f22457a73 Reviewed-on: https://pdfium-review.googlesource.com/31730 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxge/cttfontdesc.cpp')
-rw-r--r--core/fxge/cttfontdesc.cpp43
1 files changed, 12 insertions, 31 deletions
diff --git a/core/fxge/cttfontdesc.cpp b/core/fxge/cttfontdesc.cpp
index 97a12732e7..3d0b27b159 100644
--- a/core/fxge/cttfontdesc.cpp
+++ b/core/fxge/cttfontdesc.cpp
@@ -6,35 +6,26 @@
#include "core/fxge/cttfontdesc.h"
+#include <utility>
+
#include "core/fxge/fx_freetype.h"
#include "third_party/base/stl_util.h"
-CTTFontDesc::CTTFontDesc(uint8_t* pData, FXFT_Face face)
- : m_bIsTTC(false), m_pFontData(pData), m_SingleFace(face) {}
-
-CTTFontDesc::CTTFontDesc(uint8_t* pData, size_t index, FXFT_Face face)
- : m_bIsTTC(true), m_pFontData(pData) {
+CTTFontDesc::CTTFontDesc(std::unique_ptr<uint8_t, FxFreeDeleter> pData)
+ : m_pFontData(std::move(pData)) {
for (size_t i = 0; i < FX_ArraySize(m_TTCFaces); i++)
m_TTCFaces[i] = nullptr;
- SetTTCFace(index, face);
}
CTTFontDesc::~CTTFontDesc() {
ASSERT(m_RefCount == 0);
- if (m_bIsTTC) {
- for (size_t i = 0; i < FX_ArraySize(m_TTCFaces); i++) {
- if (m_TTCFaces[i])
- FXFT_Done_Face(m_TTCFaces[i]);
- }
- } else {
- if (m_SingleFace)
- FXFT_Done_Face(m_SingleFace);
+ for (size_t i = 0; i < FX_ArraySize(m_TTCFaces); i++) {
+ if (m_TTCFaces[i])
+ FXFT_Done_Face(m_TTCFaces[i]);
}
- FX_Free(m_pFontData);
}
-void CTTFontDesc::SetTTCFace(size_t index, FXFT_Face face) {
- ASSERT(m_bIsTTC);
+void CTTFontDesc::SetFace(size_t index, FXFT_Face face) {
ASSERT(index < FX_ArraySize(m_TTCFaces));
m_TTCFaces[index] = face;
}
@@ -45,24 +36,14 @@ void CTTFontDesc::AddRef() {
}
CTTFontDesc::ReleaseStatus CTTFontDesc::ReleaseFace(FXFT_Face face) {
- if (m_bIsTTC) {
- if (!pdfium::ContainsValue(m_TTCFaces, face))
- return kNotAppropriate;
- } else {
- if (m_SingleFace != face)
- return kNotAppropriate;
- }
+ if (!pdfium::ContainsValue(m_TTCFaces, face))
+ return kNotAppropriate;
+
ASSERT(m_RefCount > 0);
return --m_RefCount == 0 ? kReleased : kNotReleased;
}
-FXFT_Face CTTFontDesc::SingleFace() const {
- ASSERT(!m_bIsTTC);
- return m_SingleFace;
-}
-
-FXFT_Face CTTFontDesc::TTCFace(size_t index) const {
- ASSERT(m_bIsTTC);
+FXFT_Face CTTFontDesc::GetFace(size_t index) const {
ASSERT(index < FX_ArraySize(m_TTCFaces));
return m_TTCFaces[index];
}