summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-04-21 16:26:34 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-24 21:17:48 +0000
commit39b83dd0ce7d828f6a17a2e6529ceb5ffc819207 (patch)
treea07d9cbab1d8a91407f988a208f8419cfdf5cdb2
parented991c7d9d5bede7e3bb93ff6571512d875716dd (diff)
downloadpdfium-39b83dd0ce7d828f6a17a2e6529ceb5ffc819207.tar.xz
Use unique_ptr in CFX_SizeGlyphCache
Fix illegal leading underscore in class name while at it. Change-Id: Idd138eb42f4a0676552aa02d7dda4c29d1877348 Reviewed-on: https://pdfium-review.googlesource.com/4438 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
-rw-r--r--core/fxge/apple/fx_apple_platform.cpp4
-rw-r--r--core/fxge/cfx_facecache.h23
-rw-r--r--core/fxge/ge/cfx_facecache.cpp50
-rw-r--r--core/fxge/ge/fx_ge_text.cpp9
-rw-r--r--core/fxge/ge/fx_text_int.h7
5 files changed, 50 insertions, 43 deletions
diff --git a/core/fxge/apple/fx_apple_platform.cpp b/core/fxge/apple/fx_apple_platform.cpp
index 818e19e7d4..1a56b183cf 100644
--- a/core/fxge/apple/fx_apple_platform.cpp
+++ b/core/fxge/apple/fx_apple_platform.cpp
@@ -4,6 +4,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include <memory>
+
#include "core/fxcrt/fx_system.h"
#ifndef _SKIA_SUPPORT_
@@ -162,7 +164,7 @@ void CFX_FaceCache::InitPlatform() {}
void CFX_FaceCache::DestroyPlatform() {}
-CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph_Nativetext(
+std::unique_ptr<CFX_GlyphBitmap> CFX_FaceCache::RenderGlyph_Nativetext(
const CFX_Font* pFont,
uint32_t glyph_index,
const CFX_Matrix* pMatrix,
diff --git a/core/fxge/cfx_facecache.h b/core/fxge/cfx_facecache.h
index 44ed0b287a..5857a6310b 100644
--- a/core/fxge/cfx_facecache.h
+++ b/core/fxge/cfx_facecache.h
@@ -33,17 +33,18 @@ class CFX_FaceCache {
#endif
private:
- CFX_GlyphBitmap* RenderGlyph(const CFX_Font* pFont,
- uint32_t glyph_index,
- bool bFontStyle,
- const CFX_Matrix* pMatrix,
- int dest_width,
- int anti_alias);
- CFX_GlyphBitmap* RenderGlyph_Nativetext(const CFX_Font* pFont,
- uint32_t glyph_index,
- const CFX_Matrix* pMatrix,
- int dest_width,
- int anti_alias);
+ std::unique_ptr<CFX_GlyphBitmap> RenderGlyph(const CFX_Font* pFont,
+ uint32_t glyph_index,
+ bool bFontStyle,
+ const CFX_Matrix* pMatrix,
+ int dest_width,
+ int anti_alias);
+ std::unique_ptr<CFX_GlyphBitmap> RenderGlyph_Nativetext(
+ const CFX_Font* pFont,
+ uint32_t glyph_index,
+ const CFX_Matrix* pMatrix,
+ int dest_width,
+ int anti_alias);
CFX_GlyphBitmap* LookUpGlyphBitmap(const CFX_Font* pFont,
const CFX_Matrix* pMatrix,
const CFX_ByteString& FaceGlyphsKey,
diff --git a/core/fxge/ge/cfx_facecache.cpp b/core/fxge/ge/cfx_facecache.cpp
index 0e1dea4bb3..0969cdf10c 100644
--- a/core/fxge/ge/cfx_facecache.cpp
+++ b/core/fxge/ge/cfx_facecache.cpp
@@ -9,6 +9,7 @@
#include <algorithm>
#include <limits>
#include <memory>
+#include <utility>
#include "core/fxcrt/fx_codepage.h"
#include "core/fxge/cfx_fontmgr.h"
@@ -18,6 +19,7 @@
#include "core/fxge/fx_freetype.h"
#include "core/fxge/ge/fx_text_int.h"
#include "third_party/base/numerics/safe_math.h"
+#include "third_party/base/ptr_util.h"
#if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_
#include "third_party/skia/include/core/SkStream.h"
@@ -97,12 +99,13 @@ CFX_FaceCache::~CFX_FaceCache() {
#endif
}
-CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(const CFX_Font* pFont,
- uint32_t glyph_index,
- bool bFontStyle,
- const CFX_Matrix* pMatrix,
- int dest_width,
- int anti_alias) {
+std::unique_ptr<CFX_GlyphBitmap> CFX_FaceCache::RenderGlyph(
+ const CFX_Font* pFont,
+ uint32_t glyph_index,
+ bool bFontStyle,
+ const CFX_Matrix* pMatrix,
+ int dest_width,
+ int anti_alias) {
if (!m_Face)
return nullptr;
@@ -188,7 +191,7 @@ CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(const CFX_Font* pFont,
if (bmwidth > 2048 || bmheight > 2048)
return nullptr;
int dib_width = bmwidth;
- CFX_GlyphBitmap* pGlyphBitmap = new CFX_GlyphBitmap;
+ auto pGlyphBitmap = pdfium::MakeUnique<CFX_GlyphBitmap>();
pGlyphBitmap->m_pBitmap->Create(
dib_width, bmheight,
anti_alias == FXFT_RENDER_MODE_MONO ? FXDIB_1bppMask : FXDIB_8bppMask);
@@ -270,7 +273,7 @@ const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(const CFX_Font* pFont,
if (glyph_index == kInvalidGlyphIndex)
return nullptr;
- _CFX_UniqueKeyGen keygen;
+ CFX_UniqueKeyGen keygen;
int nMatrixA = static_cast<int>(pMatrix->a * 10000);
int nMatrixB = static_cast<int>(pMatrix->b * 10000);
int nMatrixC = static_cast<int>(pMatrix->c * 10000);
@@ -317,29 +320,31 @@ const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(const CFX_Font* pFont,
return LookUpGlyphBitmap(pFont, pMatrix, FaceGlyphsKey, glyph_index,
bFontStyle, dest_width, anti_alias);
}
- CFX_GlyphBitmap* pGlyphBitmap;
+ std::unique_ptr<CFX_GlyphBitmap> pGlyphBitmap;
auto it = m_SizeMap.find(FaceGlyphsKey);
if (it != m_SizeMap.end()) {
CFX_SizeGlyphCache* pSizeCache = it->second.get();
auto it2 = pSizeCache->m_GlyphMap.find(glyph_index);
if (it2 != pSizeCache->m_GlyphMap.end())
- return it2->second;
+ return it2->second.get();
pGlyphBitmap = RenderGlyph_Nativetext(pFont, glyph_index, pMatrix,
dest_width, anti_alias);
if (pGlyphBitmap) {
- pSizeCache->m_GlyphMap[glyph_index] = pGlyphBitmap;
- return pGlyphBitmap;
+ CFX_GlyphBitmap* pResult = pGlyphBitmap.get();
+ pSizeCache->m_GlyphMap[glyph_index] = std::move(pGlyphBitmap);
+ return pResult;
}
} else {
pGlyphBitmap = RenderGlyph_Nativetext(pFont, glyph_index, pMatrix,
dest_width, anti_alias);
if (pGlyphBitmap) {
- CFX_SizeGlyphCache* pSizeCache = new CFX_SizeGlyphCache;
- m_SizeMap[FaceGlyphsKey] =
- std::unique_ptr<CFX_SizeGlyphCache>(pSizeCache);
- pSizeCache->m_GlyphMap[glyph_index] = pGlyphBitmap;
- return pGlyphBitmap;
+ auto pNewCache = pdfium::MakeUnique<CFX_SizeGlyphCache>();
+ CFX_SizeGlyphCache* pSizeCache = pNewCache.get();
+ m_SizeMap[FaceGlyphsKey] = std::move(pNewCache);
+ CFX_GlyphBitmap* pResult = pGlyphBitmap.get();
+ pSizeCache->m_GlyphMap[glyph_index] = std::move(pGlyphBitmap);
+ return pResult;
}
}
if (pFont->GetSubstFont()) {
@@ -398,10 +403,11 @@ CFX_GlyphBitmap* CFX_FaceCache::LookUpGlyphBitmap(
}
auto it2 = pSizeCache->m_GlyphMap.find(glyph_index);
if (it2 != pSizeCache->m_GlyphMap.end())
- return it2->second;
+ return it2->second.get();
- CFX_GlyphBitmap* pGlyphBitmap = RenderGlyph(pFont, glyph_index, bFontStyle,
- pMatrix, dest_width, anti_alias);
- pSizeCache->m_GlyphMap[glyph_index] = pGlyphBitmap;
- return pGlyphBitmap;
+ std::unique_ptr<CFX_GlyphBitmap> pGlyphBitmap = RenderGlyph(
+ pFont, glyph_index, bFontStyle, pMatrix, dest_width, anti_alias);
+ CFX_GlyphBitmap* pResult = pGlyphBitmap.get();
+ pSizeCache->m_GlyphMap[glyph_index] = std::move(pGlyphBitmap);
+ return pResult;
}
diff --git a/core/fxge/ge/fx_ge_text.cpp b/core/fxge/ge/fx_ge_text.cpp
index b451b543fc..8024452265 100644
--- a/core/fxge/ge/fx_ge_text.cpp
+++ b/core/fxge/ge/fx_ge_text.cpp
@@ -107,14 +107,9 @@ FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs,
CFX_SizeGlyphCache::CFX_SizeGlyphCache() {}
-CFX_SizeGlyphCache::~CFX_SizeGlyphCache() {
- for (const auto& pair : m_GlyphMap) {
- delete pair.second;
- }
- m_GlyphMap.clear();
-}
+CFX_SizeGlyphCache::~CFX_SizeGlyphCache() {}
-void _CFX_UniqueKeyGen::Generate(int count, ...) {
+void CFX_UniqueKeyGen::Generate(int count, ...) {
va_list argList;
va_start(argList, count);
for (int i = 0; i < count; i++) {
diff --git a/core/fxge/ge/fx_text_int.h b/core/fxge/ge/fx_text_int.h
index 8ea01f91d6..dcd54cead0 100644
--- a/core/fxge/ge/fx_text_int.h
+++ b/core/fxge/ge/fx_text_int.h
@@ -8,12 +8,14 @@
#define CORE_FXGE_GE_FX_TEXT_INT_H_
#include <map>
+#include <memory>
#include "core/fxge/fx_font.h"
#include "core/fxge/fx_freetype.h"
-struct _CFX_UniqueKeyGen {
+struct CFX_UniqueKeyGen {
void Generate(int count, ...);
+
char m_Key[128];
int m_KeyLen;
};
@@ -22,7 +24,8 @@ class CFX_SizeGlyphCache {
public:
CFX_SizeGlyphCache();
~CFX_SizeGlyphCache();
- std::map<uint32_t, CFX_GlyphBitmap*> m_GlyphMap;
+
+ std::map<uint32_t, std::unique_ptr<CFX_GlyphBitmap>> m_GlyphMap;
};
#endif // CORE_FXGE_GE_FX_TEXT_INT_H_