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 "core/fxge/include/cfx_substfont.h" | 9 #include "core/fxge/include/cfx_substfont.h" |
10 #include "core/fxge/include/cfx_unicodeencoding.h" | 10 #include "core/fxge/include/cfx_unicodeencoding.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 } | 70 } |
71 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 71 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
72 | 72 |
73 CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr) | 73 CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr) |
74 : | 74 : |
75 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 75 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
76 m_bUseLogFontStyle(FALSE), | 76 m_bUseLogFontStyle(FALSE), |
77 m_dwLogFontStyle(0), | 77 m_dwLogFontStyle(0), |
78 #endif | 78 #endif |
79 m_pFont(nullptr), | 79 m_pFont(nullptr), |
80 m_pSrcFont(nullptr), | |
80 m_pFontMgr(pFontMgr), | 81 m_pFontMgr(pFontMgr), |
81 m_iRefCount(1), | 82 m_iRefCount(1), |
82 m_bExtFont(FALSE), | 83 m_bExtFont(FALSE), |
83 m_pProvider(nullptr) { | 84 m_pProvider(nullptr) { |
84 } | 85 } |
85 | 86 |
86 CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles) | 87 CFGAS_GEFont::CFGAS_GEFont(CFGAS_GEFont* src, uint32_t dwFontStyles) |
87 : | 88 : |
88 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 89 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
89 m_bUseLogFontStyle(FALSE), | 90 m_bUseLogFontStyle(FALSE), |
90 m_dwLogFontStyle(0), | 91 m_dwLogFontStyle(0), |
91 #endif | 92 #endif |
92 m_pFont(nullptr), | 93 m_pFont(nullptr), |
93 m_pFontMgr(src.m_pFontMgr), | 94 m_pSrcFont(src), |
95 m_pFontMgr(src->m_pFontMgr), | |
94 m_iRefCount(1), | 96 m_iRefCount(1), |
95 m_bExtFont(FALSE), | 97 m_bExtFont(FALSE), |
96 m_pProvider(nullptr) { | 98 m_pProvider(nullptr) { |
97 ASSERT(src.m_pFont); | 99 ASSERT(src->m_pFont); |
dsinclair
2016/09/08 18:27:22
Can we change the src-> to m_pSrcFont-> in here to
Wei Li
2016/09/08 18:42:01
Done.
| |
100 m_pSrcFont->Retain(); | |
98 m_pFont = new CFX_Font; | 101 m_pFont = new CFX_Font; |
99 m_pFont->LoadClone(src.m_pFont); | 102 m_pFont->LoadClone(src->m_pFont); |
100 CFX_SubstFont* pSubst = m_pFont->GetSubstFont(); | 103 CFX_SubstFont* pSubst = m_pFont->GetSubstFont(); |
101 if (!pSubst) { | 104 if (!pSubst) { |
102 pSubst = new CFX_SubstFont; | 105 pSubst = new CFX_SubstFont; |
103 m_pFont->SetSubstFont(std::unique_ptr<CFX_SubstFont>(pSubst)); | 106 m_pFont->SetSubstFont(std::unique_ptr<CFX_SubstFont>(pSubst)); |
104 } | 107 } |
105 pSubst->m_Weight = | 108 pSubst->m_Weight = |
106 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; | 109 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; |
107 if (dwFontStyles & FX_FONTSTYLE_Italic) { | 110 if (dwFontStyles & FX_FONTSTYLE_Italic) { |
108 pSubst->m_SubstFlags |= FXFONT_SUBST_ITALIC; | 111 pSubst->m_SubstFlags |= FXFONT_SUBST_ITALIC; |
109 } | 112 } |
110 InitFont(); | 113 InitFont(); |
111 } | 114 } |
112 | 115 |
113 CFGAS_GEFont::~CFGAS_GEFont() { | 116 CFGAS_GEFont::~CFGAS_GEFont() { |
114 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++) | 117 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++) |
115 m_SubstFonts[i]->Release(); | 118 m_SubstFonts[i]->Release(); |
116 | 119 |
117 m_SubstFonts.RemoveAll(); | 120 m_SubstFonts.RemoveAll(); |
118 m_FontMapper.clear(); | 121 m_FontMapper.clear(); |
119 | 122 |
120 if (!m_bExtFont) | 123 if (!m_bExtFont) |
121 delete m_pFont; | 124 delete m_pFont; |
125 | |
126 // If it is a shallow copy of another source font, | |
127 // decrease the refcount of the source font. | |
128 if (m_pSrcFont) | |
129 m_pSrcFont->Release(); | |
122 } | 130 } |
123 | 131 |
124 void CFGAS_GEFont::Release() { | 132 void CFGAS_GEFont::Release() { |
125 if (--m_iRefCount < 1) { | 133 if (--m_iRefCount < 1) { |
126 if (m_pFontMgr) { | 134 if (m_pFontMgr) { |
127 m_pFontMgr->RemoveFont(this); | 135 m_pFontMgr->RemoveFont(this); |
128 } | 136 } |
129 delete this; | 137 delete this; |
130 } | 138 } |
131 } | 139 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 m_pRectArray.reset(new CFX_MassArrayTemplate<CFX_Rect>(16)); | 240 m_pRectArray.reset(new CFX_MassArrayTemplate<CFX_Rect>(16)); |
233 if (!m_pBBoxMap) | 241 if (!m_pBBoxMap) |
234 m_pBBoxMap.reset(new CFX_MapPtrToPtr(16)); | 242 m_pBBoxMap.reset(new CFX_MapPtrToPtr(16)); |
235 | 243 |
236 return TRUE; | 244 return TRUE; |
237 } | 245 } |
238 | 246 |
239 CFGAS_GEFont* CFGAS_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) { | 247 CFGAS_GEFont* CFGAS_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) { |
240 if (GetFontStyles() == dwFontStyles) | 248 if (GetFontStyles() == dwFontStyles) |
241 return Retain(); | 249 return Retain(); |
242 return new CFGAS_GEFont(*this, dwFontStyles); | 250 return new CFGAS_GEFont(this, dwFontStyles); |
243 } | 251 } |
244 | 252 |
245 void CFGAS_GEFont::GetFamilyName(CFX_WideString& wsFamily) const { | 253 void CFGAS_GEFont::GetFamilyName(CFX_WideString& wsFamily) const { |
246 if (!m_pFont->GetSubstFont() || | 254 if (!m_pFont->GetSubstFont() || |
247 m_pFont->GetSubstFont()->m_Family.GetLength() == 0) { | 255 m_pFont->GetSubstFont()->m_Family.GetLength() == 0) { |
248 wsFamily = CFX_WideString::FromLocal(m_pFont->GetFamilyName().AsStringC()); | 256 wsFamily = CFX_WideString::FromLocal(m_pFont->GetFamilyName().AsStringC()); |
249 } else { | 257 } else { |
250 wsFamily = CFX_WideString::FromLocal( | 258 wsFamily = CFX_WideString::FromLocal( |
251 m_pFont->GetSubstFont()->m_Family.AsStringC()); | 259 m_pFont->GetSubstFont()->m_Family.AsStringC()); |
252 } | 260 } |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 } | 459 } |
452 if (m_pRectArray) { | 460 if (m_pRectArray) { |
453 m_pRectArray->RemoveAll(FALSE); | 461 m_pRectArray->RemoveAll(FALSE); |
454 } | 462 } |
455 } | 463 } |
456 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { | 464 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { |
457 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; | 465 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; |
458 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) | 466 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) |
459 : m_SubstFonts[iGlyphIndex - 1]; | 467 : m_SubstFonts[iGlyphIndex - 1]; |
460 } | 468 } |
OLD | NEW |