OLD | NEW |
---|---|
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 <limits> | 7 #include <limits> |
8 | 8 |
9 #include "../../../include/fxge/fx_ge.h" | 9 #include "../../../include/fxge/fx_ge.h" |
10 #include "../../../include/fxge/fx_freetype.h" | 10 #include "../../../include/fxge/fx_freetype.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 FXFT_Done_Face(m_SingleFace.m_pFace); | 51 FXFT_Done_Face(m_SingleFace.m_pFace); |
52 } | 52 } |
53 } else if (m_Type == 2) { | 53 } else if (m_Type == 2) { |
54 for (int i = 0; i < 16; i++) | 54 for (int i = 0; i < 16; i++) |
55 if (m_TTCFace.m_pFaces[i]) { | 55 if (m_TTCFace.m_pFaces[i]) { |
56 FXFT_Done_Face(m_TTCFace.m_pFaces[i]); | 56 FXFT_Done_Face(m_TTCFace.m_pFaces[i]); |
57 } | 57 } |
58 } | 58 } |
59 FX_Free(m_pFontData); | 59 FX_Free(m_pFontData); |
60 } | 60 } |
61 int32_t CTTFontDesc::ReleaseFace(FXFT_Face face) { | 61 FX_BOOL CTTFontDesc::ReleaseFace(FXFT_Face face) { |
62 if (m_Type == 1) { | 62 if (m_Type == 1) { |
63 if (m_SingleFace.m_pFace != face) { | 63 if (m_SingleFace.m_pFace != face) { |
64 return -1; | 64 return FALSE; |
65 } | 65 } |
66 } else if (m_Type == 2) { | 66 } else if (m_Type == 2) { |
67 int i; | 67 int i; |
68 for (i = 0; i < 16; i++) | 68 for (i = 0; i < 16; i++) |
69 if (m_TTCFace.m_pFaces[i] == face) { | 69 if (m_TTCFace.m_pFaces[i] == face) { |
70 break; | 70 break; |
71 } | 71 } |
72 if (i == 16) { | 72 if (i == 16) { |
73 return -1; | 73 return FALSE; |
74 } | 74 } |
75 } | 75 } |
76 m_RefCount--; | 76 m_RefCount--; |
77 if (m_RefCount) { | 77 if (m_RefCount) { |
78 return m_RefCount; | 78 return FALSE; |
79 } | 79 } |
80 delete this; | 80 delete this; |
81 return 0; | 81 return TRUE; |
82 } | 82 } |
83 | 83 |
84 CFX_FontMgr::CFX_FontMgr() : m_FTLibrary(nullptr) { | 84 CFX_FontMgr::CFX_FontMgr() : m_FTLibrary(nullptr) { |
85 m_pBuiltinMapper.reset(new CFX_FontMapper(this)); | 85 m_pBuiltinMapper.reset(new CFX_FontMapper(this)); |
86 } | 86 } |
87 | 87 |
88 CFX_FontMgr::~CFX_FontMgr() { | 88 CFX_FontMgr::~CFX_FontMgr() { |
89 for (const auto& pair : m_FaceMap) | 89 for (const auto& pair : m_FaceMap) |
90 delete pair.second; | 90 delete pair.second; |
91 | 91 |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 FXFT_Face face = nullptr; | 350 FXFT_Face face = nullptr; |
351 if (FXFT_New_Face(library, filename, face_index, &face)) | 351 if (FXFT_New_Face(library, filename, face_index, &face)) |
352 return nullptr; | 352 return nullptr; |
353 return FXFT_Set_Pixel_Sizes(face, 64, 64) ? nullptr : face; | 353 return FXFT_Set_Pixel_Sizes(face, 64, 64) ? nullptr : face; |
354 } | 354 } |
355 | 355 |
356 void CFX_FontMgr::ReleaseFace(FXFT_Face face) { | 356 void CFX_FontMgr::ReleaseFace(FXFT_Face face) { |
357 if (!face) { | 357 if (!face) { |
358 return; | 358 return; |
359 } | 359 } |
360 FX_BOOL bNeedFaceDone = TRUE; | |
361 auto it = m_FaceMap.begin(); | 360 auto it = m_FaceMap.begin(); |
362 while (it != m_FaceMap.end()) { | 361 while (it != m_FaceMap.end()) { |
363 auto temp = it++; | 362 auto temp = it++; |
364 int nRet = temp->second->ReleaseFace(face); | 363 if (temp->second->ReleaseFace(face)) { |
365 if (nRet == 0) { | |
366 m_FaceMap.erase(temp); | 364 m_FaceMap.erase(temp); |
367 bNeedFaceDone = FALSE; | |
368 } else if (nRet > 0) { | |
369 bNeedFaceDone = FALSE; | |
370 } | 365 } |
371 } | 366 } |
372 if (bNeedFaceDone && !m_pBuiltinMapper->IsBuiltinFace(face)) { | |
Lei Zhang
2015/10/30 06:35:47
CFX_FontMapper::IsBuiltinFace() is dead after this
| |
373 FXFT_Done_Face(face); | |
Lei Zhang
2015/10/30 06:35:47
Better to leak than double free.
| |
374 } | |
375 } | 367 } |
376 const FoxitFonts g_FoxitFonts[14] = { | 368 const FoxitFonts g_FoxitFonts[14] = { |
377 {g_FoxitFixedFontData, 17597}, | 369 {g_FoxitFixedFontData, 17597}, |
378 {g_FoxitFixedBoldFontData, 18055}, | 370 {g_FoxitFixedBoldFontData, 18055}, |
379 {g_FoxitFixedBoldItalicFontData, 19151}, | 371 {g_FoxitFixedBoldItalicFontData, 19151}, |
380 {g_FoxitFixedItalicFontData, 18746}, | 372 {g_FoxitFixedItalicFontData, 18746}, |
381 {g_FoxitSansFontData, 15025}, | 373 {g_FoxitSansFontData, 15025}, |
382 {g_FoxitSansBoldFontData, 16344}, | 374 {g_FoxitSansBoldFontData, 16344}, |
383 {g_FoxitSansBoldItalicFontData, 16418}, | 375 {g_FoxitSansBoldItalicFontData, 16418}, |
384 {g_FoxitSansItalicFontData, 16339}, | 376 {g_FoxitSansItalicFontData, 16339}, |
(...skipping 29 matching lines...) Expand all Loading... | |
414 CFX_FontMapper::CFX_FontMapper(CFX_FontMgr* mgr) | 406 CFX_FontMapper::CFX_FontMapper(CFX_FontMgr* mgr) |
415 : m_bListLoaded(FALSE), | 407 : m_bListLoaded(FALSE), |
416 m_pFontInfo(nullptr), | 408 m_pFontInfo(nullptr), |
417 m_pFontEnumerator(nullptr), | 409 m_pFontEnumerator(nullptr), |
418 m_pFontMgr(mgr) { | 410 m_pFontMgr(mgr) { |
419 m_MMFaces[0] = nullptr; | 411 m_MMFaces[0] = nullptr; |
420 m_MMFaces[1] = nullptr; | 412 m_MMFaces[1] = nullptr; |
421 FXSYS_memset(m_FoxitFaces, 0, sizeof(m_FoxitFaces)); | 413 FXSYS_memset(m_FoxitFaces, 0, sizeof(m_FoxitFaces)); |
422 } | 414 } |
423 CFX_FontMapper::~CFX_FontMapper() { | 415 CFX_FontMapper::~CFX_FontMapper() { |
424 for (int i = 0; i < 14; i++) | 416 for (size_t i = 0; i < FX_ArraySize(m_FoxitFaces); ++i) { |
425 if (m_FoxitFaces[i]) { | 417 if (m_FoxitFaces[i]) |
426 FXFT_Done_Face(m_FoxitFaces[i]); | 418 FXFT_Done_Face(m_FoxitFaces[i]); |
427 } | 419 } |
428 if (m_MMFaces[0]) { | 420 if (m_MMFaces[0]) { |
429 FXFT_Done_Face(m_MMFaces[0]); | 421 FXFT_Done_Face(m_MMFaces[0]); |
430 } | 422 } |
431 if (m_MMFaces[1]) { | 423 if (m_MMFaces[1]) { |
432 FXFT_Done_Face(m_MMFaces[1]); | 424 FXFT_Done_Face(m_MMFaces[1]); |
433 } | 425 } |
434 if (m_pFontInfo) { | 426 if (m_pFontInfo) { |
435 m_pFontInfo->Release(); | 427 m_pFontInfo->Release(); |
436 } | 428 } |
437 } | 429 } |
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1633 int PDF_GetStandardFontName(CFX_ByteString* name) { | 1625 int PDF_GetStandardFontName(CFX_ByteString* name) { |
1634 AltFontName* found = static_cast<AltFontName*>( | 1626 AltFontName* found = static_cast<AltFontName*>( |
1635 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), | 1627 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), |
1636 sizeof(AltFontName), compareString)); | 1628 sizeof(AltFontName), compareString)); |
1637 if (!found) | 1629 if (!found) |
1638 return -1; | 1630 return -1; |
1639 | 1631 |
1640 *name = g_Base14FontNames[found->m_Index]; | 1632 *name = g_Base14FontNames[found->m_Index]; |
1641 return found->m_Index; | 1633 return found->m_Index; |
1642 } | 1634 } |
OLD | NEW |