Chromium Code Reviews| 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 "xfa/fgas/font/fgas_gefont.h" | 7 #include "xfa/fgas/font/fgas_gefont.h" |
| 8 | 8 |
| 9 #include "xfa/fgas/crt/fgas_codepage.h" | 9 #include "xfa/fgas/crt/fgas_codepage.h" |
| 10 #include "xfa/fgas/font/fgas_fontutils.h" | 10 #include "xfa/fgas/font/fgas_fontutils.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 m_pFontMgr(pFontMgr), | 98 m_pFontMgr(pFontMgr), |
| 99 m_iRefCount(1), | 99 m_iRefCount(1), |
| 100 m_bExtFont(FALSE), | 100 m_bExtFont(FALSE), |
| 101 m_pStream(NULL), | 101 m_pStream(NULL), |
| 102 m_pFileRead(NULL), | 102 m_pFileRead(NULL), |
| 103 m_pFontEncoding(NULL), | 103 m_pFontEncoding(NULL), |
| 104 m_pCharWidthMap(NULL), | 104 m_pCharWidthMap(NULL), |
| 105 m_pRectArray(NULL), | 105 m_pRectArray(NULL), |
| 106 m_pBBoxMap(NULL), | 106 m_pBBoxMap(NULL), |
| 107 m_pProvider(NULL), | 107 m_pProvider(NULL), |
| 108 m_wCharSet(0xFFFF), | 108 m_wCharSet(0xFFFF) { |
| 109 m_FontMapper(16) { | |
| 110 } | 109 } |
| 111 | 110 |
| 112 CFX_GEFont::CFX_GEFont(const CFX_GEFont& src, uint32_t dwFontStyles) | 111 CFX_GEFont::CFX_GEFont(const CFX_GEFont& src, uint32_t dwFontStyles) |
| 113 : | 112 : |
| 114 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 113 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 115 m_bUseLogFontStyle(FALSE), | 114 m_bUseLogFontStyle(FALSE), |
| 116 m_dwLogFontStyle(0), | 115 m_dwLogFontStyle(0), |
| 117 #endif | 116 #endif |
| 118 m_pFont(NULL), | 117 m_pFont(NULL), |
| 119 m_pFontMgr(src.m_pFontMgr), | 118 m_pFontMgr(src.m_pFontMgr), |
| 120 m_iRefCount(1), | 119 m_iRefCount(1), |
| 121 m_bExtFont(FALSE), | 120 m_bExtFont(FALSE), |
| 122 m_pStream(NULL), | 121 m_pStream(NULL), |
| 123 m_pFileRead(NULL), | 122 m_pFileRead(NULL), |
| 124 m_pFontEncoding(NULL), | 123 m_pFontEncoding(NULL), |
| 125 m_pCharWidthMap(NULL), | 124 m_pCharWidthMap(NULL), |
| 126 m_pRectArray(NULL), | 125 m_pRectArray(NULL), |
| 127 m_pBBoxMap(NULL), | 126 m_pBBoxMap(NULL), |
| 128 m_pProvider(NULL), | 127 m_pProvider(NULL), |
| 129 m_wCharSet(0xFFFF), | 128 m_wCharSet(0xFFFF) { |
| 130 m_FontMapper(16) { | 129 ASSERT(src.m_pFont); |
| 131 m_pFont = new CFX_Font; | 130 m_pFont = new CFX_Font; |
| 132 ASSERT(m_pFont != NULL); | |
| 133 ASSERT(src.m_pFont != NULL); | |
| 134 m_pFont->LoadClone(src.m_pFont); | 131 m_pFont->LoadClone(src.m_pFont); |
| 135 CFX_SubstFont* pSubst = m_pFont->GetSubstFont(); | 132 CFX_SubstFont* pSubst = m_pFont->GetSubstFont(); |
| 136 if (!pSubst) { | 133 if (!pSubst) { |
| 137 pSubst = new CFX_SubstFont; | 134 pSubst = new CFX_SubstFont; |
| 138 m_pFont->SetSubstFont(pSubst); | 135 m_pFont->SetSubstFont(pSubst); |
| 139 } | 136 } |
| 140 pSubst->m_Weight = | 137 pSubst->m_Weight = |
| 141 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; | 138 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; |
| 142 if (dwFontStyles & FX_FONTSTYLE_Italic) { | 139 if (dwFontStyles & FX_FONTSTYLE_Italic) { |
| 143 pSubst->m_SubstFlags |= FXFONT_SUBST_ITALIC; | 140 pSubst->m_SubstFlags |= FXFONT_SUBST_ITALIC; |
| 144 } | 141 } |
| 145 InitFont(); | 142 InitFont(); |
| 146 } | 143 } |
| 147 | 144 |
| 148 CFX_GEFont::~CFX_GEFont() { | 145 CFX_GEFont::~CFX_GEFont() { |
| 149 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++) | 146 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++) |
| 150 m_SubstFonts[i]->Release(); | 147 m_SubstFonts[i]->Release(); |
| 151 | 148 |
| 152 m_SubstFonts.RemoveAll(); | 149 m_SubstFonts.RemoveAll(); |
| 153 m_FontMapper.RemoveAll(); | 150 m_FontMapper.clear(); |
| 154 if (m_pFileRead) | 151 if (m_pFileRead) |
| 155 m_pFileRead->Release(); | 152 m_pFileRead->Release(); |
| 156 | 153 |
| 157 if (m_pStream) | 154 if (m_pStream) |
| 158 m_pStream->Release(); | 155 m_pStream->Release(); |
| 159 | 156 |
| 160 delete m_pFontEncoding; | 157 delete m_pFontEncoding; |
|
Lei Zhang
2016/05/20 20:42:21
BTW, lots of unique_ptr candidates.
Tom Sepez
2016/05/20 21:32:15
Ack, followup someday.
| |
| 161 delete m_pCharWidthMap; | 158 delete m_pCharWidthMap; |
| 162 delete m_pRectArray; | 159 delete m_pRectArray; |
| 163 delete m_pBBoxMap; | 160 delete m_pBBoxMap; |
| 164 if (!m_bExtFont) | 161 if (!m_bExtFont) |
| 165 delete m_pFont; | 162 delete m_pFont; |
| 166 } | 163 } |
| 167 | 164 |
| 168 void CFX_GEFont::Release() { | 165 void CFX_GEFont::Release() { |
| 169 if (--m_iRefCount < 1) { | 166 if (--m_iRefCount < 1) { |
| 170 if (m_pFontMgr != NULL) { | 167 if (m_pFontMgr != NULL) { |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 return iGlyphIndex; | 470 return iGlyphIndex; |
| 474 } | 471 } |
| 475 const FGAS_FONTUSB* pFontUSB = FGAS_GetUnicodeBitField(wUnicode); | 472 const FGAS_FONTUSB* pFontUSB = FGAS_GetUnicodeBitField(wUnicode); |
| 476 if (pFontUSB == NULL) { | 473 if (pFontUSB == NULL) { |
| 477 return 0xFFFF; | 474 return 0xFFFF; |
| 478 } | 475 } |
| 479 uint16_t wBitField = pFontUSB->wBitField; | 476 uint16_t wBitField = pFontUSB->wBitField; |
| 480 if (wBitField >= 128) { | 477 if (wBitField >= 128) { |
| 481 return 0xFFFF; | 478 return 0xFFFF; |
| 482 } | 479 } |
| 483 IFX_Font* pFont = NULL; | 480 auto it = m_FontMapper.find(wUnicode); |
| 484 m_FontMapper.Lookup((void*)(uintptr_t)wUnicode, (void*&)pFont); | 481 IFX_Font* pFont = it != m_FontMapper.end() ? it->second : nullptr; |
| 485 if (pFont != NULL && pFont != (IFX_Font*)this) { | 482 if (pFont && pFont != this) { |
| 486 iGlyphIndex = | 483 iGlyphIndex = |
| 487 ((CFX_GEFont*)pFont)->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); | 484 ((CFX_GEFont*)pFont)->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); |
| 488 if (iGlyphIndex != 0xFFFF) { | 485 if (iGlyphIndex != 0xFFFF) { |
| 489 int32_t i = m_SubstFonts.Find(pFont); | 486 int32_t i = m_SubstFonts.Find(pFont); |
| 490 if (i > -1) { | 487 if (i > -1) { |
| 491 iGlyphIndex |= ((i + 1) << 24); | 488 iGlyphIndex |= ((i + 1) << 24); |
| 492 if (ppFont != NULL) { | 489 if (ppFont) |
| 493 *ppFont = pFont; | 490 *ppFont = pFont; |
| 494 } | |
| 495 return iGlyphIndex; | 491 return iGlyphIndex; |
| 496 } | 492 } |
| 497 } | 493 } |
| 498 } | 494 } |
| 499 if (m_pFontMgr != NULL && bRecursive) { | 495 if (m_pFontMgr && bRecursive) { |
| 500 CFX_WideString wsFamily; | 496 CFX_WideString wsFamily; |
| 501 GetFamilyName(wsFamily); | 497 GetFamilyName(wsFamily); |
| 502 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 498 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 503 IFX_Font* pFont = m_pFontMgr->GetDefFontByUnicode(wUnicode, GetFontStyles(), | 499 IFX_Font* pFont = m_pFontMgr->GetDefFontByUnicode(wUnicode, GetFontStyles(), |
| 504 wsFamily.c_str()); | 500 wsFamily.c_str()); |
| 505 #else | 501 #else |
| 506 IFX_Font* pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), | 502 IFX_Font* pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), |
| 507 wsFamily.c_str()); | 503 wsFamily.c_str()); |
| 508 if (NULL == pFont) { | 504 if (!pFont) |
| 509 pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), NULL); | 505 pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), NULL); |
| 510 } | |
| 511 #endif | 506 #endif |
| 512 if (pFont != NULL) { | 507 if (pFont) { |
| 513 if (pFont == (IFX_Font*)this) { | 508 if (pFont == this) { |
| 514 pFont->Release(); | 509 pFont->Release(); |
| 515 return 0xFFFF; | 510 return 0xFFFF; |
| 516 } | 511 } |
| 517 m_FontMapper.SetAt((void*)(uintptr_t)wUnicode, (void*)pFont); | 512 m_FontMapper[wUnicode] = pFont; |
| 518 int32_t i = m_SubstFonts.GetSize(); | 513 int32_t i = m_SubstFonts.GetSize(); |
| 519 m_SubstFonts.Add(pFont); | 514 m_SubstFonts.Add(pFont); |
| 520 iGlyphIndex = | 515 iGlyphIndex = |
| 521 ((CFX_GEFont*)pFont)->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); | 516 ((CFX_GEFont*)pFont)->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); |
| 522 if (iGlyphIndex != 0xFFFF) { | 517 if (iGlyphIndex != 0xFFFF) { |
| 523 iGlyphIndex |= ((i + 1) << 24); | 518 iGlyphIndex |= ((i + 1) << 24); |
| 524 if (ppFont != NULL) { | 519 if (ppFont) |
| 525 *ppFont = pFont; | 520 *ppFont = pFont; |
| 526 } | |
| 527 return iGlyphIndex; | 521 return iGlyphIndex; |
| 528 } | 522 } |
| 529 } | 523 } |
| 530 } | 524 } |
| 531 return 0xFFFF; | 525 return 0xFFFF; |
| 532 } | 526 } |
| 533 int32_t CFX_GEFont::GetAscent() const { | 527 int32_t CFX_GEFont::GetAscent() const { |
| 534 return m_pFont->GetAscent(); | 528 return m_pFont->GetAscent(); |
| 535 } | 529 } |
| 536 int32_t CFX_GEFont::GetDescent() const { | 530 int32_t CFX_GEFont::GetDescent() const { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 550 } | 544 } |
| 551 if (m_pRectArray != NULL) { | 545 if (m_pRectArray != NULL) { |
| 552 m_pRectArray->RemoveAll(); | 546 m_pRectArray->RemoveAll(); |
| 553 } | 547 } |
| 554 } | 548 } |
| 555 IFX_Font* CFX_GEFont::GetSubstFont(int32_t iGlyphIndex) const { | 549 IFX_Font* CFX_GEFont::GetSubstFont(int32_t iGlyphIndex) const { |
| 556 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; | 550 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; |
| 557 return iGlyphIndex == 0 ? const_cast<CFX_GEFont*>(this) | 551 return iGlyphIndex == 0 ? const_cast<CFX_GEFont*>(this) |
| 558 : m_SubstFonts[iGlyphIndex - 1]; | 552 : m_SubstFonts[iGlyphIndex - 1]; |
| 559 } | 553 } |
| OLD | NEW |