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

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

Issue 1515613006: Merge to XFA: Replace several more CFX_MapPtrToPtr with std::set or std::map (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
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
« no previous file with comments | « core/src/fpdfdoc/doc_annot.cpp ('k') | core/src/fxge/ge/text_int.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_Matrix* pMatrix, 1251 const CFX_Matrix* 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(CFX_Font* pFont, 1277 const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(CFX_Font* pFont,
1283 FX_DWORD glyph_index, 1278 FX_DWORD glyph_index,
1284 FX_BOOL bFontStyle, 1279 FX_BOOL bFontStyle,
1285 const CFX_Matrix* pMatrix, 1280 const CFX_Matrix* pMatrix,
1286 int dest_width, 1281 int dest_width,
1287 int anti_alias, 1282 int anti_alias,
1288 int& text_flags) { 1283 int& text_flags) {
1289 if (glyph_index == (FX_DWORD)-1) { 1284 if (glyph_index == (FX_DWORD)-1) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 bFontStyle, dest_width, anti_alias); 1326 bFontStyle, dest_width, anti_alias);
1332 #else 1327 #else
1333 if (text_flags & FXTEXT_NO_NATIVETEXT) { 1328 if (text_flags & FXTEXT_NO_NATIVETEXT) {
1334 return LookUpGlyphBitmap(pFont, pMatrix, FaceGlyphsKey, glyph_index, 1329 return LookUpGlyphBitmap(pFont, pMatrix, FaceGlyphsKey, glyph_index,
1335 bFontStyle, dest_width, anti_alias); 1330 bFontStyle, dest_width, anti_alias);
1336 } 1331 }
1337 CFX_GlyphBitmap* pGlyphBitmap; 1332 CFX_GlyphBitmap* pGlyphBitmap;
1338 auto it = m_SizeMap.find(FaceGlyphsKey); 1333 auto it = m_SizeMap.find(FaceGlyphsKey);
1339 if (it != m_SizeMap.end()) { 1334 if (it != m_SizeMap.end()) {
1340 CFX_SizeGlyphCache* pSizeCache = it->second; 1335 CFX_SizeGlyphCache* pSizeCache = it->second;
1341 if (pSizeCache->m_GlyphMap.Lookup((void*)(uintptr_t)glyph_index, 1336 auto it2 = pSizeCache->m_GlyphMap.find(glyph_index);
1342 (void*&)pGlyphBitmap)) { 1337 if (it2 != pSizeCache->m_GlyphMap.end())
1343 return pGlyphBitmap; 1338 return it2->second;
1344 } 1339
1345 pGlyphBitmap = RenderGlyph_Nativetext(pFont, glyph_index, pMatrix, 1340 pGlyphBitmap = RenderGlyph_Nativetext(pFont, glyph_index, pMatrix,
1346 dest_width, anti_alias); 1341 dest_width, anti_alias);
1347 if (pGlyphBitmap) { 1342 if (pGlyphBitmap) {
1348 pSizeCache->m_GlyphMap.SetAt((void*)(uintptr_t)glyph_index, pGlyphBitmap); 1343 pSizeCache->m_GlyphMap[glyph_index] = pGlyphBitmap;
1349 return pGlyphBitmap; 1344 return pGlyphBitmap;
1350 } 1345 }
1351 } else { 1346 } else {
1352 pGlyphBitmap = RenderGlyph_Nativetext(pFont, glyph_index, pMatrix, 1347 pGlyphBitmap = RenderGlyph_Nativetext(pFont, glyph_index, pMatrix,
1353 dest_width, anti_alias); 1348 dest_width, anti_alias);
1354 if (pGlyphBitmap) { 1349 if (pGlyphBitmap) {
1355 CFX_SizeGlyphCache* pSizeCache = new CFX_SizeGlyphCache; 1350 CFX_SizeGlyphCache* pSizeCache = new CFX_SizeGlyphCache;
1356 m_SizeMap[FaceGlyphsKey] = pSizeCache; 1351 m_SizeMap[FaceGlyphsKey] = pSizeCache;
1357 pSizeCache->m_GlyphMap.SetAt((void*)(uintptr_t)glyph_index, pGlyphBitmap); 1352 pSizeCache->m_GlyphMap[glyph_index] = pGlyphBitmap;
1358 return pGlyphBitmap; 1353 return pGlyphBitmap;
1359 } 1354 }
1360 } 1355 }
1361 if (pFont->GetSubstFont()) 1356 if (pFont->GetSubstFont())
1362 keygen.Generate(9, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000), 1357 keygen.Generate(9, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),
1363 (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000), 1358 (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000),
1364 dest_width, anti_alias, pFont->GetSubstFont()->m_Weight, 1359 dest_width, anti_alias, pFont->GetSubstFont()->m_Weight,
1365 pFont->GetSubstFont()->m_ItalicAngle, pFont->IsVertical()); 1360 pFont->GetSubstFont()->m_ItalicAngle, pFont->IsVertical());
1366 else 1361 else
1367 keygen.Generate(6, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000), 1362 keygen.Generate(6, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),
1368 (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000), 1363 (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000),
1369 dest_width, anti_alias); 1364 dest_width, anti_alias);
1370 CFX_ByteStringC FaceGlyphsKey2(keygen.m_Key, keygen.m_KeyLen); 1365 CFX_ByteStringC FaceGlyphsKey2(keygen.m_Key, keygen.m_KeyLen);
1371 text_flags |= FXTEXT_NO_NATIVETEXT; 1366 text_flags |= FXTEXT_NO_NATIVETEXT;
1372 return LookUpGlyphBitmap(pFont, pMatrix, FaceGlyphsKey2, glyph_index, 1367 return LookUpGlyphBitmap(pFont, pMatrix, FaceGlyphsKey2, glyph_index,
1373 bFontStyle, dest_width, anti_alias); 1368 bFontStyle, dest_width, anti_alias);
1374 #endif 1369 #endif
1375 } 1370 }
1376 CFX_SizeGlyphCache::~CFX_SizeGlyphCache() { 1371 CFX_SizeGlyphCache::~CFX_SizeGlyphCache() {
1377 FX_POSITION pos = m_GlyphMap.GetStartPosition(); 1372 for (const auto& pair : m_GlyphMap) {
1378 void* Key; 1373 delete pair.second;
1379 CFX_GlyphBitmap* pGlyphBitmap = NULL;
1380 while (pos) {
1381 m_GlyphMap.GetNextAssoc(pos, Key, (void*&)pGlyphBitmap);
1382 delete pGlyphBitmap;
1383 } 1374 }
1384 m_GlyphMap.RemoveAll(); 1375 m_GlyphMap.clear();
1385 } 1376 }
1386 #define CONTRAST_RAMP_STEP 1 1377 #define CONTRAST_RAMP_STEP 1
1387 void CFX_Font::AdjustMMParams(int glyph_index, int dest_width, int weight) { 1378 void CFX_Font::AdjustMMParams(int glyph_index, int dest_width, int weight) {
1388 FXFT_MM_Var pMasters = NULL; 1379 FXFT_MM_Var pMasters = NULL;
1389 FXFT_Get_MM_Var(m_Face, &pMasters); 1380 FXFT_Get_MM_Var(m_Face, &pMasters);
1390 if (pMasters == NULL) { 1381 if (pMasters == NULL) {
1391 return; 1382 return;
1392 } 1383 }
1393 long coords[2]; 1384 long coords[2];
1394 if (weight == 0) { 1385 if (weight == 0) {
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 dest_pitch); 1636 dest_pitch);
1646 _GammaAdjust(pDestBuf, bmwidth, bmheight, dest_pitch, 1637 _GammaAdjust(pDestBuf, bmwidth, bmheight, dest_pitch,
1647 CFX_GEModule::Get()->GetTextGammaTable()); 1638 CFX_GEModule::Get()->GetTextGammaTable());
1648 } 1639 }
1649 } 1640 }
1650 return pGlyphBitmap; 1641 return pGlyphBitmap;
1651 } 1642 }
1652 const CFX_PathData* CFX_FaceCache::LoadGlyphPath(CFX_Font* pFont, 1643 const CFX_PathData* CFX_FaceCache::LoadGlyphPath(CFX_Font* pFont,
1653 FX_DWORD glyph_index, 1644 FX_DWORD glyph_index,
1654 int dest_width) { 1645 int dest_width) {
1655 if (m_Face == NULL || glyph_index == (FX_DWORD)-1) { 1646 if (!m_Face || glyph_index == (FX_DWORD)-1)
1656 return NULL; 1647 return nullptr;
1648
1649 FX_DWORD key = glyph_index;
1650 if (pFont->GetSubstFont()) {
1651 key += (((pFont->GetSubstFont()->m_Weight / 16) << 15) +
1652 ((pFont->GetSubstFont()->m_ItalicAngle / 2) << 21) +
1653 ((dest_width / 16) << 25) + (pFont->IsVertical() << 31));
1657 } 1654 }
1658 CFX_PathData* pGlyphPath = NULL; 1655 auto it = m_PathMap.find(key);
1659 void* key; 1656 if (it != m_PathMap.end())
1660 if (pFont->GetSubstFont()) { 1657 return it->second;
1661 key = (void*)(uintptr_t)( 1658
1662 glyph_index + ((pFont->GetSubstFont()->m_Weight / 16) << 15) + 1659 CFX_PathData* pGlyphPath = pFont->LoadGlyphPath(glyph_index, dest_width);
1663 ((pFont->GetSubstFont()->m_ItalicAngle / 2) << 21) + 1660 m_PathMap[key] = pGlyphPath;
1664 ((dest_width / 16) << 25) + (pFont->IsVertical() << 31));
1665 } else {
1666 key = (void*)(uintptr_t)glyph_index;
1667 }
1668 if (m_PathMap.Lookup(key, (void*&)pGlyphPath)) {
1669 return pGlyphPath;
1670 }
1671 pGlyphPath = pFont->LoadGlyphPath(glyph_index, dest_width);
1672 m_PathMap.SetAt(key, pGlyphPath);
1673 return pGlyphPath; 1661 return pGlyphPath;
1674 } 1662 }
1675 typedef struct { 1663 typedef struct {
1676 FX_BOOL m_bCount; 1664 FX_BOOL m_bCount;
1677 int m_PointCount; 1665 int m_PointCount;
1678 FX_PATHPOINT* m_pPoints; 1666 FX_PATHPOINT* m_pPoints;
1679 int m_CurX; 1667 int m_CurX;
1680 int m_CurY; 1668 int m_CurY;
1681 FX_FLOAT m_CoordUnit; 1669 FX_FLOAT m_CoordUnit;
1682 } OUTLINE_PARAMS; 1670 } OUTLINE_PARAMS;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1872 void _CFX_UniqueKeyGen::Generate(int count, ...) { 1860 void _CFX_UniqueKeyGen::Generate(int count, ...) {
1873 va_list argList; 1861 va_list argList;
1874 va_start(argList, count); 1862 va_start(argList, count);
1875 for (int i = 0; i < count; i++) { 1863 for (int i = 0; i < count; i++) {
1876 int p = va_arg(argList, int); 1864 int p = va_arg(argList, int);
1877 ((FX_DWORD*)m_Key)[i] = p; 1865 ((FX_DWORD*)m_Key)[i] = p;
1878 } 1866 }
1879 va_end(argList); 1867 va_end(argList);
1880 m_KeyLen = count * sizeof(FX_DWORD); 1868 m_KeyLen = count * sizeof(FX_DWORD);
1881 } 1869 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_annot.cpp ('k') | core/src/fxge/ge/text_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698