Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: core/src/fxge/ge/fx_ge_text.cpp

Issue 1520643002: Replace several more CFX_MapPtrToPtr with std::set or std::map (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/include/fxge/fx_ge.h" 7 #include "core/include/fxge/fx_ge.h"
8 #include "core/include/fxge/fx_freetype.h" 8 #include "core/include/fxge/fx_freetype.h"
9 #include "core/include/fxcodec/fx_codec.h" 9 #include "core/include/fxcodec/fx_codec.h"
10 #include "text_int.h" 10 #include "text_int.h"
(...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 } 1231 }
1232 } 1232 }
1233 1233
1234 CFX_FaceCache::CFX_FaceCache(FXFT_Face face) : m_Face(face) {} 1234 CFX_FaceCache::CFX_FaceCache(FXFT_Face face) : m_Face(face) {}
1235 1235
1236 CFX_FaceCache::~CFX_FaceCache() { 1236 CFX_FaceCache::~CFX_FaceCache() {
1237 for (const auto& pair : m_SizeMap) { 1237 for (const auto& pair : m_SizeMap) {
1238 delete pair.second; 1238 delete pair.second;
1239 } 1239 }
1240 m_SizeMap.clear(); 1240 m_SizeMap.clear();
1241 FX_POSITION pos = m_PathMap.GetStartPosition(); 1241 for (const auto& pair : m_PathMap) {
1242 void* key1; 1242 delete pair.second;
1243 CFX_PathData* pPath;
1244 while (pos) {
1245 m_PathMap.GetNextAssoc(pos, key1, (void*&)pPath);
1246 delete pPath;
1247 } 1243 }
1248 m_PathMap.RemoveAll(); 1244 m_PathMap.clear();
1249 } 1245 }
1250 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ 1246 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_
1251 void CFX_FaceCache::InitPlatform() {} 1247 void CFX_FaceCache::InitPlatform() {}
1252 #endif 1248 #endif
1253 CFX_GlyphBitmap* CFX_FaceCache::LookUpGlyphBitmap( 1249 CFX_GlyphBitmap* CFX_FaceCache::LookUpGlyphBitmap(
1254 CFX_Font* pFont, 1250 CFX_Font* pFont,
1255 const CFX_AffineMatrix* pMatrix, 1251 const CFX_AffineMatrix* pMatrix,
1256 CFX_ByteStringC& FaceGlyphsKey, 1252 CFX_ByteStringC& FaceGlyphsKey,
1257 FX_DWORD glyph_index, 1253 FX_DWORD glyph_index,
1258 FX_BOOL bFontStyle, 1254 FX_BOOL bFontStyle,
1259 int dest_width, 1255 int dest_width,
1260 int anti_alias) { 1256 int anti_alias) {
1261 CFX_SizeGlyphCache* pSizeCache; 1257 CFX_SizeGlyphCache* pSizeCache;
1262 auto it = m_SizeMap.find(FaceGlyphsKey); 1258 auto it = m_SizeMap.find(FaceGlyphsKey);
1263 if (it == m_SizeMap.end()) { 1259 if (it == m_SizeMap.end()) {
1264 pSizeCache = new CFX_SizeGlyphCache; 1260 pSizeCache = new CFX_SizeGlyphCache;
1265 m_SizeMap[FaceGlyphsKey] = pSizeCache; 1261 m_SizeMap[FaceGlyphsKey] = pSizeCache;
1266 } else { 1262 } else {
1267 pSizeCache = it->second; 1263 pSizeCache = it->second;
1268 } 1264 }
1269 CFX_GlyphBitmap* pGlyphBitmap = NULL; 1265 auto it2 = pSizeCache->m_GlyphMap.find(glyph_index);
1270 if (pSizeCache->m_GlyphMap.Lookup((void*)(uintptr_t)glyph_index, 1266 if (it2 != pSizeCache->m_GlyphMap.end())
1271 (void*&)pGlyphBitmap)) { 1267 return it2->second;
1272 return pGlyphBitmap; 1268
1273 } 1269 CFX_GlyphBitmap* pGlyphBitmap = RenderGlyph(pFont, glyph_index, bFontStyle,
1274 pGlyphBitmap = RenderGlyph(pFont, glyph_index, bFontStyle, pMatrix, 1270 pMatrix, dest_width, anti_alias);
1275 dest_width, anti_alias); 1271 if (!pGlyphBitmap)
1276 if (pGlyphBitmap == NULL) { 1272 return nullptr;
1277 return NULL; 1273
1278 } 1274 pSizeCache->m_GlyphMap[glyph_index] = pGlyphBitmap;
1279 pSizeCache->m_GlyphMap.SetAt((void*)(uintptr_t)glyph_index, pGlyphBitmap);
1280 return pGlyphBitmap; 1275 return pGlyphBitmap;
1281 } 1276 }
1282 const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap( 1277 const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(
1283 CFX_Font* pFont, 1278 CFX_Font* pFont,
1284 FX_DWORD glyph_index, 1279 FX_DWORD glyph_index,
1285 FX_BOOL bFontStyle, 1280 FX_BOOL bFontStyle,
1286 const CFX_AffineMatrix* pMatrix, 1281 const CFX_AffineMatrix* pMatrix,
1287 int dest_width, 1282 int dest_width,
1288 int anti_alias, 1283 int anti_alias,
1289 int& text_flags) { 1284 int& text_flags) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 keygen.Generate(6, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000), 1363 keygen.Generate(6, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),
1369 (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000), 1364 (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000),
1370 dest_width, anti_alias); 1365 dest_width, anti_alias);
1371 CFX_ByteStringC FaceGlyphsKey2(keygen.m_Key, keygen.m_KeyLen); 1366 CFX_ByteStringC FaceGlyphsKey2(keygen.m_Key, keygen.m_KeyLen);
1372 text_flags |= FXTEXT_NO_NATIVETEXT; 1367 text_flags |= FXTEXT_NO_NATIVETEXT;
1373 return LookUpGlyphBitmap(pFont, pMatrix, FaceGlyphsKey2, glyph_index, 1368 return LookUpGlyphBitmap(pFont, pMatrix, FaceGlyphsKey2, glyph_index,
1374 bFontStyle, dest_width, anti_alias); 1369 bFontStyle, dest_width, anti_alias);
1375 #endif 1370 #endif
1376 } 1371 }
1377 CFX_SizeGlyphCache::~CFX_SizeGlyphCache() { 1372 CFX_SizeGlyphCache::~CFX_SizeGlyphCache() {
1378 FX_POSITION pos = m_GlyphMap.GetStartPosition(); 1373 for (const auto& pair : m_GlyphMap) {
1379 void* Key; 1374 delete pair.second;
1380 CFX_GlyphBitmap* pGlyphBitmap = NULL;
1381 while (pos) {
1382 m_GlyphMap.GetNextAssoc(pos, Key, (void*&)pGlyphBitmap);
1383 delete pGlyphBitmap;
1384 } 1375 }
1385 m_GlyphMap.RemoveAll(); 1376 m_GlyphMap.clear();
1386 } 1377 }
1387 #define CONTRAST_RAMP_STEP 1 1378 #define CONTRAST_RAMP_STEP 1
1388 void CFX_Font::AdjustMMParams(int glyph_index, int dest_width, int weight) { 1379 void CFX_Font::AdjustMMParams(int glyph_index, int dest_width, int weight) {
1389 FXFT_MM_Var pMasters = NULL; 1380 FXFT_MM_Var pMasters = NULL;
1390 FXFT_Get_MM_Var(m_Face, &pMasters); 1381 FXFT_Get_MM_Var(m_Face, &pMasters);
1391 if (pMasters == NULL) { 1382 if (pMasters == NULL) {
1392 return; 1383 return;
1393 } 1384 }
1394 long coords[2]; 1385 long coords[2];
1395 if (weight == 0) { 1386 if (weight == 0) {
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 dest_pitch); 1637 dest_pitch);
1647 _GammaAdjust(pDestBuf, bmwidth, bmheight, dest_pitch, 1638 _GammaAdjust(pDestBuf, bmwidth, bmheight, dest_pitch,
1648 CFX_GEModule::Get()->GetTextGammaTable()); 1639 CFX_GEModule::Get()->GetTextGammaTable());
1649 } 1640 }
1650 } 1641 }
1651 return pGlyphBitmap; 1642 return pGlyphBitmap;
1652 } 1643 }
1653 const CFX_PathData* CFX_FaceCache::LoadGlyphPath(CFX_Font* pFont, 1644 const CFX_PathData* CFX_FaceCache::LoadGlyphPath(CFX_Font* pFont,
1654 FX_DWORD glyph_index, 1645 FX_DWORD glyph_index,
1655 int dest_width) { 1646 int dest_width) {
1656 if (m_Face == NULL || glyph_index == (FX_DWORD)-1) { 1647 if (!m_Face || glyph_index == (FX_DWORD)-1)
1657 return NULL; 1648 return nullptr;
1649
1650 FX_DWORD key = glyph_index;
1651 if (pFont->GetSubstFont()) {
1652 key += (((pFont->GetSubstFont()->m_Weight / 16) << 15) +
1653 ((pFont->GetSubstFont()->m_ItalicAngle / 2) << 21) +
1654 ((dest_width / 16) << 25) + (pFont->IsVertical() << 31));
1658 } 1655 }
1659 CFX_PathData* pGlyphPath = NULL; 1656 auto it = m_PathMap.find(key);
1660 void* key; 1657 if (it != m_PathMap.end())
1661 if (pFont->GetSubstFont()) { 1658 return it->second;
1662 key = (void*)(uintptr_t)( 1659
1663 glyph_index + ((pFont->GetSubstFont()->m_Weight / 16) << 15) + 1660 CFX_PathData* pGlyphPath = pFont->LoadGlyphPath(glyph_index, dest_width);
1664 ((pFont->GetSubstFont()->m_ItalicAngle / 2) << 21) + 1661 m_PathMap[key] = pGlyphPath;
1665 ((dest_width / 16) << 25) + (pFont->IsVertical() << 31));
1666 } else {
1667 key = (void*)(uintptr_t)glyph_index;
1668 }
1669 if (m_PathMap.Lookup(key, (void*&)pGlyphPath)) {
1670 return pGlyphPath;
1671 }
1672 pGlyphPath = pFont->LoadGlyphPath(glyph_index, dest_width);
1673 m_PathMap.SetAt(key, pGlyphPath);
1674 return pGlyphPath; 1662 return pGlyphPath;
1675 } 1663 }
1676 typedef struct { 1664 typedef struct {
1677 FX_BOOL m_bCount; 1665 FX_BOOL m_bCount;
1678 int m_PointCount; 1666 int m_PointCount;
1679 FX_PATHPOINT* m_pPoints; 1667 FX_PATHPOINT* m_pPoints;
1680 int m_CurX; 1668 int m_CurX;
1681 int m_CurY; 1669 int m_CurY;
1682 FX_FLOAT m_CoordUnit; 1670 FX_FLOAT m_CoordUnit;
1683 } OUTLINE_PARAMS; 1671 } OUTLINE_PARAMS;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1873 void _CFX_UniqueKeyGen::Generate(int count, ...) { 1861 void _CFX_UniqueKeyGen::Generate(int count, ...) {
1874 va_list argList; 1862 va_list argList;
1875 va_start(argList, count); 1863 va_start(argList, count);
1876 for (int i = 0; i < count; i++) { 1864 for (int i = 0; i < count; i++) {
1877 int p = va_arg(argList, int); 1865 int p = va_arg(argList, int);
1878 ((FX_DWORD*)m_Key)[i] = p; 1866 ((FX_DWORD*)m_Key)[i] = p;
1879 } 1867 }
1880 va_end(argList); 1868 va_end(argList);
1881 m_KeyLen = count * sizeof(FX_DWORD); 1869 m_KeyLen = count * sizeof(FX_DWORD);
1882 } 1870 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698