| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2015 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_stdfontmgr.h" | 7 #include "xfa/fgas/font/fgas_stdfontmgr.h" |
| 8 | 8 |
| 9 #include "core/fxcrt/include/fx_stream.h" | 9 #include "core/fxcrt/include/fx_stream.h" |
| 10 #include "core/fxge/include/fx_ge.h" | 10 #include "core/fxge/include/fx_ge.h" |
| 11 #include "xfa/fgas/crt/fgas_codepage.h" | 11 #include "xfa/fgas/crt/fgas_codepage.h" |
| 12 #include "xfa/fgas/font/fgas_fontutils.h" | 12 #include "xfa/fgas/font/fgas_fontutils.h" |
| 13 #include "xfa/fgas/font/fgas_gefont.h" |
| 13 | 14 |
| 14 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 15 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 15 IFGAS_FontMgr* IFGAS_FontMgr::Create(FX_LPEnumAllFonts pEnumerator) { | 16 IFGAS_FontMgr* IFGAS_FontMgr::Create(FX_LPEnumAllFonts pEnumerator) { |
| 16 return new CFGAS_StdFontMgrImp(pEnumerator); | 17 return new CFGAS_StdFontMgrImp(pEnumerator); |
| 17 } | 18 } |
| 18 CFGAS_StdFontMgrImp::CFGAS_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator) | 19 CFGAS_StdFontMgrImp::CFGAS_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator) |
| 19 : m_pEnumerator(pEnumerator), | 20 : m_pEnumerator(pEnumerator), |
| 20 m_FontFaces(), | 21 m_FontFaces(), |
| 21 m_CPFonts(8), | 22 m_CPFonts(8), |
| 22 m_FamilyFonts(16), | 23 m_FamilyFonts(16), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 36 m_FamilyFonts.RemoveAll(); | 37 m_FamilyFonts.RemoveAll(); |
| 37 m_UnicodeFonts.RemoveAll(); | 38 m_UnicodeFonts.RemoveAll(); |
| 38 m_BufferFonts.RemoveAll(); | 39 m_BufferFonts.RemoveAll(); |
| 39 m_FileFonts.RemoveAll(); | 40 m_FileFonts.RemoveAll(); |
| 40 m_StreamFonts.RemoveAll(); | 41 m_StreamFonts.RemoveAll(); |
| 41 m_DeriveFonts.RemoveAll(); | 42 m_DeriveFonts.RemoveAll(); |
| 42 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) | 43 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) |
| 43 m_Fonts[i]->Release(); | 44 m_Fonts[i]->Release(); |
| 44 } | 45 } |
| 45 | 46 |
| 46 IFGAS_Font* CFGAS_StdFontMgrImp::GetDefFontByCodePage( | 47 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByCodePage( |
| 47 uint16_t wCodePage, | 48 uint16_t wCodePage, |
| 48 uint32_t dwFontStyles, | 49 uint32_t dwFontStyles, |
| 49 const FX_WCHAR* pszFontFamily) { | 50 const FX_WCHAR* pszFontFamily) { |
| 50 uint32_t dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); | 51 uint32_t dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); |
| 51 IFGAS_Font* pFont = NULL; | 52 CFGAS_GEFont* pFont = NULL; |
| 52 if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { | 53 if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { |
| 53 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; | 54 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; |
| 54 } | 55 } |
| 55 FX_FONTDESCRIPTOR const* pFD; | 56 FX_FONTDESCRIPTOR const* pFD; |
| 56 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) { | 57 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) { |
| 57 if ((pFD = FindFont(NULL, dwFontStyles, TRUE, wCodePage)) == NULL) { | 58 if ((pFD = FindFont(NULL, dwFontStyles, TRUE, wCodePage)) == NULL) { |
| 58 if ((pFD = FindFont(NULL, dwFontStyles, FALSE, wCodePage)) == NULL) | 59 if ((pFD = FindFont(NULL, dwFontStyles, FALSE, wCodePage)) == NULL) |
| 59 return NULL; | 60 return NULL; |
| 60 } | 61 } |
| 61 } | 62 } |
| 62 ASSERT(pFD); | 63 ASSERT(pFD); |
| 63 pFont = IFGAS_Font::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); | 64 pFont = |
| 65 CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); |
| 64 if (pFont) { | 66 if (pFont) { |
| 65 m_Fonts.Add(pFont); | 67 m_Fonts.Add(pFont); |
| 66 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 68 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 67 dwHash = FGAS_GetFontFamilyHash(pFD->wsFontFace, dwFontStyles, wCodePage); | 69 dwHash = FGAS_GetFontFamilyHash(pFD->wsFontFace, dwFontStyles, wCodePage); |
| 68 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 70 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 69 return LoadFont(pFont, dwFontStyles, wCodePage); | 71 return LoadFont(pFont, dwFontStyles, wCodePage); |
| 70 } | 72 } |
| 71 return NULL; | 73 return NULL; |
| 72 } | 74 } |
| 73 IFGAS_Font* CFGAS_StdFontMgrImp::GetDefFontByCharset( | 75 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByCharset( |
| 74 uint8_t nCharset, | 76 uint8_t nCharset, |
| 75 uint32_t dwFontStyles, | 77 uint32_t dwFontStyles, |
| 76 const FX_WCHAR* pszFontFamily) { | 78 const FX_WCHAR* pszFontFamily) { |
| 77 return GetDefFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, | 79 return GetDefFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, |
| 78 pszFontFamily); | 80 pszFontFamily); |
| 79 } | 81 } |
| 80 | 82 |
| 81 IFGAS_Font* CFGAS_StdFontMgrImp::GetDefFontByUnicode( | 83 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByUnicode( |
| 82 FX_WCHAR wUnicode, | 84 FX_WCHAR wUnicode, |
| 83 uint32_t dwFontStyles, | 85 uint32_t dwFontStyles, |
| 84 const FX_WCHAR* pszFontFamily) { | 86 const FX_WCHAR* pszFontFamily) { |
| 85 const FGAS_FONTUSB* pRet = FGAS_GetUnicodeBitField(wUnicode); | 87 const FGAS_FONTUSB* pRet = FGAS_GetUnicodeBitField(wUnicode); |
| 86 if (pRet->wBitField == 999) | 88 if (pRet->wBitField == 999) |
| 87 return nullptr; | 89 return nullptr; |
| 88 | 90 |
| 89 uint32_t dwHash = | 91 uint32_t dwHash = |
| 90 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, pRet->wBitField); | 92 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, pRet->wBitField); |
| 91 IFGAS_Font* pFont = nullptr; | 93 CFGAS_GEFont* pFont = nullptr; |
| 92 if (m_UnicodeFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) | 94 if (m_UnicodeFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) |
| 93 return pFont ? LoadFont(pFont, dwFontStyles, pRet->wCodePage) : nullptr; | 95 return pFont ? LoadFont(pFont, dwFontStyles, pRet->wCodePage) : nullptr; |
| 94 | 96 |
| 95 FX_FONTDESCRIPTOR const* pFD = | 97 FX_FONTDESCRIPTOR const* pFD = |
| 96 FindFont(pszFontFamily, dwFontStyles, FALSE, pRet->wCodePage, | 98 FindFont(pszFontFamily, dwFontStyles, FALSE, pRet->wCodePage, |
| 97 pRet->wBitField, wUnicode); | 99 pRet->wBitField, wUnicode); |
| 98 if (!pFD && pszFontFamily) { | 100 if (!pFD && pszFontFamily) { |
| 99 pFD = FindFont(nullptr, dwFontStyles, FALSE, pRet->wCodePage, | 101 pFD = FindFont(nullptr, dwFontStyles, FALSE, pRet->wCodePage, |
| 100 pRet->wBitField, wUnicode); | 102 pRet->wBitField, wUnicode); |
| 101 } | 103 } |
| 102 if (!pFD) | 104 if (!pFD) |
| 103 return nullptr; | 105 return nullptr; |
| 104 | 106 |
| 105 uint16_t wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); | 107 uint16_t wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); |
| 106 const FX_WCHAR* pFontFace = pFD->wsFontFace; | 108 const FX_WCHAR* pFontFace = pFD->wsFontFace; |
| 107 pFont = IFGAS_Font::LoadFont(pFontFace, dwFontStyles, wCodePage, this); | 109 pFont = CFGAS_GEFont::LoadFont(pFontFace, dwFontStyles, wCodePage, this); |
| 108 if (pFont) { | 110 if (pFont) { |
| 109 m_Fonts.Add(pFont); | 111 m_Fonts.Add(pFont); |
| 110 m_UnicodeFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 112 m_UnicodeFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 111 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); | 113 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); |
| 112 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 114 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 113 dwHash = FGAS_GetFontFamilyHash(pFontFace, dwFontStyles, wCodePage); | 115 dwHash = FGAS_GetFontFamilyHash(pFontFace, dwFontStyles, wCodePage); |
| 114 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 116 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 115 return LoadFont(pFont, dwFontStyles, wCodePage); | 117 return LoadFont(pFont, dwFontStyles, wCodePage); |
| 116 } | 118 } |
| 117 return nullptr; | 119 return nullptr; |
| 118 } | 120 } |
| 119 | 121 |
| 120 IFGAS_Font* CFGAS_StdFontMgrImp::GetDefFontByLanguage( | 122 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByLanguage( |
| 121 uint16_t wLanguage, | 123 uint16_t wLanguage, |
| 122 uint32_t dwFontStyles, | 124 uint32_t dwFontStyles, |
| 123 const FX_WCHAR* pszFontFamily) { | 125 const FX_WCHAR* pszFontFamily) { |
| 124 return GetDefFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), | 126 return GetDefFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), |
| 125 dwFontStyles, pszFontFamily); | 127 dwFontStyles, pszFontFamily); |
| 126 } | 128 } |
| 127 IFGAS_Font* CFGAS_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFontFamily, | 129 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFontFamily, |
| 128 uint32_t dwFontStyles, | 130 uint32_t dwFontStyles, |
| 129 uint16_t wCodePage) { | 131 uint16_t wCodePage) { |
| 130 uint32_t dwHash = | 132 uint32_t dwHash = |
| 131 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, wCodePage); | 133 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, wCodePage); |
| 132 IFGAS_Font* pFont = NULL; | 134 CFGAS_GEFont* pFont = NULL; |
| 133 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { | 135 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { |
| 134 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; | 136 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; |
| 135 } | 137 } |
| 136 FX_FONTDESCRIPTOR const* pFD = NULL; | 138 FX_FONTDESCRIPTOR const* pFD = NULL; |
| 137 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) { | 139 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) { |
| 138 if ((pFD = FindFont(pszFontFamily, dwFontStyles, FALSE, wCodePage)) == | 140 if ((pFD = FindFont(pszFontFamily, dwFontStyles, FALSE, wCodePage)) == |
| 139 NULL) { | 141 NULL) { |
| 140 return NULL; | 142 return NULL; |
| 141 } | 143 } |
| 142 } | 144 } |
| 143 ASSERT(pFD); | 145 ASSERT(pFD); |
| 144 if (wCodePage == 0xFFFF) { | 146 if (wCodePage == 0xFFFF) { |
| 145 wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); | 147 wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); |
| 146 } | 148 } |
| 147 pFont = IFGAS_Font::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); | 149 pFont = |
| 150 CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); |
| 148 if (pFont) { | 151 if (pFont) { |
| 149 m_Fonts.Add(pFont); | 152 m_Fonts.Add(pFont); |
| 150 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 153 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 151 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); | 154 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); |
| 152 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 155 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 153 return LoadFont(pFont, dwFontStyles, wCodePage); | 156 return LoadFont(pFont, dwFontStyles, wCodePage); |
| 154 } | 157 } |
| 155 return NULL; | 158 return NULL; |
| 156 } | 159 } |
| 157 IFGAS_Font* CFGAS_StdFontMgrImp::LoadFont(const uint8_t* pBuffer, | 160 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(const uint8_t* pBuffer, |
| 158 int32_t iLength) { | 161 int32_t iLength) { |
| 159 ASSERT(pBuffer && iLength > 0); | 162 ASSERT(pBuffer && iLength > 0); |
| 160 IFGAS_Font* pFont = NULL; | 163 CFGAS_GEFont* pFont = NULL; |
| 161 if (m_BufferFonts.Lookup((void*)pBuffer, (void*&)pFont)) { | 164 if (m_BufferFonts.Lookup((void*)pBuffer, (void*&)pFont)) { |
| 162 if (pFont) { | 165 if (pFont) { |
| 163 return pFont->Retain(); | 166 return pFont->Retain(); |
| 164 } | 167 } |
| 165 } | 168 } |
| 166 pFont = IFGAS_Font::LoadFont(pBuffer, iLength, this); | 169 pFont = CFGAS_GEFont::LoadFont(pBuffer, iLength, this); |
| 167 if (pFont) { | 170 if (pFont) { |
| 168 m_Fonts.Add(pFont); | 171 m_Fonts.Add(pFont); |
| 169 m_BufferFonts.SetAt((void*)pBuffer, pFont); | 172 m_BufferFonts.SetAt((void*)pBuffer, pFont); |
| 170 return pFont->Retain(); | 173 return pFont->Retain(); |
| 171 } | 174 } |
| 172 return NULL; | 175 return NULL; |
| 173 } | 176 } |
| 174 IFGAS_Font* CFGAS_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFileName) { | 177 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFileName) { |
| 175 ASSERT(pszFileName); | 178 ASSERT(pszFileName); |
| 176 uint32_t dwHash = FX_HashCode_GetW(pszFileName, false); | 179 uint32_t dwHash = FX_HashCode_GetW(pszFileName, false); |
| 177 IFGAS_Font* pFont = NULL; | 180 CFGAS_GEFont* pFont = NULL; |
| 178 if (m_FileFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { | 181 if (m_FileFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { |
| 179 if (pFont) { | 182 if (pFont) { |
| 180 return pFont->Retain(); | 183 return pFont->Retain(); |
| 181 } | 184 } |
| 182 } | 185 } |
| 183 pFont = IFGAS_Font::LoadFont(pszFileName, NULL); | 186 pFont = CFGAS_GEFont::LoadFont(pszFileName); |
| 184 if (pFont) { | 187 if (pFont) { |
| 185 m_Fonts.Add(pFont); | 188 m_Fonts.Add(pFont); |
| 186 m_FileFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 189 m_FileFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 187 return pFont->Retain(); | 190 return pFont->Retain(); |
| 188 } | 191 } |
| 189 return NULL; | 192 return NULL; |
| 190 } | 193 } |
| 191 IFGAS_Font* CFGAS_StdFontMgrImp::LoadFont(IFX_Stream* pFontStream, | 194 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(IFX_Stream* pFontStream, |
| 192 const FX_WCHAR* pszFontAlias, | 195 const FX_WCHAR* pszFontAlias, |
| 193 uint32_t dwFontStyles, | 196 uint32_t dwFontStyles, |
| 194 uint16_t wCodePage, | 197 uint16_t wCodePage, |
| 195 FX_BOOL bSaveStream) { | 198 FX_BOOL bSaveStream) { |
| 196 ASSERT(pFontStream && pFontStream->GetLength() > 0); | 199 ASSERT(pFontStream && pFontStream->GetLength() > 0); |
| 197 IFGAS_Font* pFont = NULL; | 200 CFGAS_GEFont* pFont = NULL; |
| 198 if (m_StreamFonts.Lookup((void*)pFontStream, (void*&)pFont)) { | 201 if (m_StreamFonts.Lookup((void*)pFontStream, (void*&)pFont)) { |
| 199 if (pFont) { | 202 if (pFont) { |
| 200 if (pszFontAlias) { | 203 if (pszFontAlias) { |
| 201 uint32_t dwHash = | 204 uint32_t dwHash = |
| 202 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); | 205 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); |
| 203 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 206 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 204 } | 207 } |
| 205 return LoadFont(pFont, dwFontStyles, wCodePage); | 208 return LoadFont(pFont, dwFontStyles, wCodePage); |
| 206 } | 209 } |
| 207 } | 210 } |
| 208 pFont = IFGAS_Font::LoadFont(pFontStream, this, bSaveStream); | 211 pFont = CFGAS_GEFont::LoadFont(pFontStream, this, bSaveStream); |
| 209 if (pFont) { | 212 if (pFont) { |
| 210 m_Fonts.Add(pFont); | 213 m_Fonts.Add(pFont); |
| 211 m_StreamFonts.SetAt((void*)pFontStream, (void*)pFont); | 214 m_StreamFonts.SetAt((void*)pFontStream, (void*)pFont); |
| 212 if (pszFontAlias) { | 215 if (pszFontAlias) { |
| 213 uint32_t dwHash = | 216 uint32_t dwHash = |
| 214 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); | 217 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); |
| 215 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 218 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 216 } | 219 } |
| 217 return LoadFont(pFont, dwFontStyles, wCodePage); | 220 return LoadFont(pFont, dwFontStyles, wCodePage); |
| 218 } | 221 } |
| 219 return NULL; | 222 return NULL; |
| 220 } | 223 } |
| 221 IFGAS_Font* CFGAS_StdFontMgrImp::LoadFont(IFGAS_Font* pSrcFont, | 224 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(CFGAS_GEFont* pSrcFont, |
| 222 uint32_t dwFontStyles, | 225 uint32_t dwFontStyles, |
| 223 uint16_t wCodePage) { | 226 uint16_t wCodePage) { |
| 224 ASSERT(pSrcFont); | 227 ASSERT(pSrcFont); |
| 225 if (pSrcFont->GetFontStyles() == dwFontStyles) { | 228 if (pSrcFont->GetFontStyles() == dwFontStyles) { |
| 226 return pSrcFont->Retain(); | 229 return pSrcFont->Retain(); |
| 227 } | 230 } |
| 228 void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles, | 231 void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles, |
| 229 (void*)(uintptr_t)wCodePage}; | 232 (void*)(uintptr_t)wCodePage}; |
| 230 uint32_t dwHash = FX_HashCode_GetA( | 233 uint32_t dwHash = FX_HashCode_GetA( |
| 231 CFX_ByteStringC((uint8_t*)buffer, sizeof(buffer)), false); | 234 CFX_ByteStringC((uint8_t*)buffer, sizeof(buffer)), false); |
| 232 IFGAS_Font* pFont = NULL; | 235 CFGAS_GEFont* pFont = NULL; |
| 233 if (m_DeriveFonts.GetCount() > 0) { | 236 if (m_DeriveFonts.GetCount() > 0) { |
| 234 m_DeriveFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont); | 237 m_DeriveFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont); |
| 235 if (pFont) { | 238 if (pFont) { |
| 236 return pFont->Retain(); | 239 return pFont->Retain(); |
| 237 } | 240 } |
| 238 } | 241 } |
| 239 pFont = pSrcFont->Derive(dwFontStyles, wCodePage); | 242 pFont = pSrcFont->Derive(dwFontStyles, wCodePage); |
| 240 if (pFont) { | 243 if (pFont) { |
| 241 m_DeriveFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 244 m_DeriveFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 242 int32_t index = m_Fonts.Find(pFont); | 245 int32_t index = m_Fonts.Find(pFont); |
| 243 if (index < 0) { | 246 if (index < 0) { |
| 244 m_Fonts.Add(pFont); | 247 m_Fonts.Add(pFont); |
| 245 pFont->Retain(); | 248 pFont->Retain(); |
| 246 } | 249 } |
| 247 return pFont; | 250 return pFont; |
| 248 } | 251 } |
| 249 return NULL; | 252 return NULL; |
| 250 } | 253 } |
| 251 | 254 |
| 252 void CFGAS_StdFontMgrImp::ClearFontCache() { | 255 void CFGAS_StdFontMgrImp::ClearFontCache() { |
| 253 for (int32_t i = 0; i < m_Fonts.GetSize(); i++) | 256 for (int32_t i = 0; i < m_Fonts.GetSize(); i++) |
| 254 m_Fonts[i]->Reset(); | 257 m_Fonts[i]->Reset(); |
| 255 } | 258 } |
| 256 | 259 |
| 257 void CFGAS_StdFontMgrImp::RemoveFont(CFX_MapPtrToPtr& fontMap, | 260 void CFGAS_StdFontMgrImp::RemoveFont(CFX_MapPtrToPtr& fontMap, |
| 258 IFGAS_Font* pFont) { | 261 CFGAS_GEFont* pFont) { |
| 259 FX_POSITION pos = fontMap.GetStartPosition(); | 262 FX_POSITION pos = fontMap.GetStartPosition(); |
| 260 void* pKey; | 263 void* pKey; |
| 261 void* pFind; | 264 void* pFind; |
| 262 while (pos) { | 265 while (pos) { |
| 263 pFind = NULL; | 266 pFind = NULL; |
| 264 fontMap.GetNextAssoc(pos, pKey, pFind); | 267 fontMap.GetNextAssoc(pos, pKey, pFind); |
| 265 if (pFind != (void*)pFont) { | 268 if (pFind != (void*)pFont) { |
| 266 continue; | 269 continue; |
| 267 } | 270 } |
| 268 fontMap.RemoveKey(pKey); | 271 fontMap.RemoveKey(pKey); |
| 269 break; | 272 break; |
| 270 } | 273 } |
| 271 } | 274 } |
| 272 void CFGAS_StdFontMgrImp::RemoveFont(IFGAS_Font* pFont) { | 275 void CFGAS_StdFontMgrImp::RemoveFont(CFGAS_GEFont* pFont) { |
| 273 RemoveFont(m_CPFonts, pFont); | 276 RemoveFont(m_CPFonts, pFont); |
| 274 RemoveFont(m_FamilyFonts, pFont); | 277 RemoveFont(m_FamilyFonts, pFont); |
| 275 RemoveFont(m_UnicodeFonts, pFont); | 278 RemoveFont(m_UnicodeFonts, pFont); |
| 276 RemoveFont(m_BufferFonts, pFont); | 279 RemoveFont(m_BufferFonts, pFont); |
| 277 RemoveFont(m_FileFonts, pFont); | 280 RemoveFont(m_FileFonts, pFont); |
| 278 RemoveFont(m_StreamFonts, pFont); | 281 RemoveFont(m_StreamFonts, pFont); |
| 279 RemoveFont(m_DeriveFonts, pFont); | 282 RemoveFont(m_DeriveFonts, pFont); |
| 280 int32_t iFind = m_Fonts.Find(pFont); | 283 int32_t iFind = m_Fonts.Find(pFont); |
| 281 if (iFind > -1) { | 284 if (iFind > -1) { |
| 282 m_Fonts.RemoveAt(iFind, 1); | 285 m_Fonts.RemoveAt(iFind, 1); |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); | 627 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); |
| 625 while (pos) { | 628 while (pos) { |
| 626 uint32_t dwHash; | 629 uint32_t dwHash; |
| 627 CFX_FontDescriptorInfos* pDescs; | 630 CFX_FontDescriptorInfos* pDescs; |
| 628 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); | 631 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); |
| 629 delete pDescs; | 632 delete pDescs; |
| 630 } | 633 } |
| 631 pos = m_Hash2Fonts.GetStartPosition(); | 634 pos = m_Hash2Fonts.GetStartPosition(); |
| 632 while (pos) { | 635 while (pos) { |
| 633 uint32_t dwHash; | 636 uint32_t dwHash; |
| 634 CFX_ArrayTemplate<IFGAS_Font*>* pFonts; | 637 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; |
| 635 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); | 638 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); |
| 636 delete pFonts; | 639 delete pFonts; |
| 637 } | 640 } |
| 638 m_Hash2Fonts.RemoveAll(); | 641 m_Hash2Fonts.RemoveAll(); |
| 639 pos = m_Hash2FileAccess.GetStartPosition(); | 642 pos = m_Hash2FileAccess.GetStartPosition(); |
| 640 while (pos) { | 643 while (pos) { |
| 641 uint32_t dwHash; | 644 uint32_t dwHash; |
| 642 IFX_FileAccess* pFileAccess; | 645 IFX_FileAccess* pFileAccess; |
| 643 m_Hash2FileAccess.GetNextAssoc(pos, dwHash, pFileAccess); | 646 m_Hash2FileAccess.GetNextAssoc(pos, dwHash, pFileAccess); |
| 644 if (NULL != pFileAccess) { | 647 if (NULL != pFileAccess) { |
| 645 pFileAccess->Release(); | 648 pFileAccess->Release(); |
| 646 } | 649 } |
| 647 } | 650 } |
| 648 pos = m_FileAccess2IFXFont.GetStartPosition(); | 651 pos = m_FileAccess2IFXFont.GetStartPosition(); |
| 649 while (pos) { | 652 while (pos) { |
| 650 uint32_t dwHash; | 653 uint32_t dwHash; |
| 651 IFGAS_Font* pFont; | 654 CFGAS_GEFont* pFont; |
| 652 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pFont); | 655 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pFont); |
| 653 if (NULL != pFont) { | 656 if (NULL != pFont) { |
| 654 pFont->Release(); | 657 pFont->Release(); |
| 655 } | 658 } |
| 656 } | 659 } |
| 657 pos = m_IFXFont2FileRead.GetStartPosition(); | 660 pos = m_IFXFont2FileRead.GetStartPosition(); |
| 658 while (pos) { | 661 while (pos) { |
| 659 IFGAS_Font* pFont; | 662 CFGAS_GEFont* pFont; |
| 660 IFX_FileRead* pFileRead; | 663 IFX_FileRead* pFileRead; |
| 661 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); | 664 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); |
| 662 pFileRead->Release(); | 665 pFileRead->Release(); |
| 663 } | 666 } |
| 664 delete this; | 667 delete this; |
| 665 } | 668 } |
| 666 IFGAS_Font* CFGAS_FontMgrImp::GetDefFontByCodePage( | 669 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCodePage( |
| 667 uint16_t wCodePage, | 670 uint16_t wCodePage, |
| 668 uint32_t dwFontStyles, | 671 uint32_t dwFontStyles, |
| 669 const FX_WCHAR* pszFontFamily) { | 672 const FX_WCHAR* pszFontFamily) { |
| 670 return nullptr; | 673 return nullptr; |
| 671 } | 674 } |
| 672 IFGAS_Font* CFGAS_FontMgrImp::GetDefFontByCharset( | 675 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCharset( |
| 673 uint8_t nCharset, | 676 uint8_t nCharset, |
| 674 uint32_t dwFontStyles, | 677 uint32_t dwFontStyles, |
| 675 const FX_WCHAR* pszFontFamily) { | 678 const FX_WCHAR* pszFontFamily) { |
| 676 return nullptr; | 679 return nullptr; |
| 677 } | 680 } |
| 678 IFGAS_Font* CFGAS_FontMgrImp::GetDefFontByUnicode( | 681 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByUnicode( |
| 679 FX_WCHAR wUnicode, | 682 FX_WCHAR wUnicode, |
| 680 uint32_t dwFontStyles, | 683 uint32_t dwFontStyles, |
| 681 const FX_WCHAR* pszFontFamily) { | 684 const FX_WCHAR* pszFontFamily) { |
| 682 return nullptr; | 685 return nullptr; |
| 683 } | 686 } |
| 684 IFGAS_Font* CFGAS_FontMgrImp::GetDefFontByLanguage( | 687 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByLanguage( |
| 685 uint16_t wLanguage, | 688 uint16_t wLanguage, |
| 686 uint32_t dwFontStyles, | 689 uint32_t dwFontStyles, |
| 687 const FX_WCHAR* pszFontFamily) { | 690 const FX_WCHAR* pszFontFamily) { |
| 688 return nullptr; | 691 return nullptr; |
| 689 } | 692 } |
| 690 | 693 |
| 691 IFGAS_Font* CFGAS_FontMgrImp::GetFontByCodePage(uint16_t wCodePage, | 694 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByCodePage( |
| 692 uint32_t dwFontStyles, | 695 uint16_t wCodePage, |
| 693 const FX_WCHAR* pszFontFamily) { | 696 uint32_t dwFontStyles, |
| 697 const FX_WCHAR* pszFontFamily) { |
| 694 CFX_ByteString bsHash; | 698 CFX_ByteString bsHash; |
| 695 bsHash.Format("%d, %d", wCodePage, dwFontStyles); | 699 bsHash.Format("%d, %d", wCodePage, dwFontStyles); |
| 696 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); | 700 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); |
| 697 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); | 701 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); |
| 698 CFX_ArrayTemplate<IFGAS_Font*>* pFonts = nullptr; | 702 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts = nullptr; |
| 699 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { | 703 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { |
| 700 if (!pFonts) | 704 if (!pFonts) |
| 701 return nullptr; | 705 return nullptr; |
| 702 | 706 |
| 703 if (pFonts->GetSize() != 0) | 707 if (pFonts->GetSize() != 0) |
| 704 return pFonts->GetAt(0)->Retain(); | 708 return pFonts->GetAt(0)->Retain(); |
| 705 } | 709 } |
| 706 | 710 |
| 707 if (!pFonts) | 711 if (!pFonts) |
| 708 pFonts = new CFX_ArrayTemplate<IFGAS_Font*>; | 712 pFonts = new CFX_ArrayTemplate<CFGAS_GEFont*>; |
| 709 | 713 |
| 710 m_Hash2Fonts.SetAt(dwHash, pFonts); | 714 m_Hash2Fonts.SetAt(dwHash, pFonts); |
| 711 CFX_FontDescriptorInfos* sortedFonts = nullptr; | 715 CFX_FontDescriptorInfos* sortedFonts = nullptr; |
| 712 if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) { | 716 if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) { |
| 713 sortedFonts = new CFX_FontDescriptorInfos; | 717 sortedFonts = new CFX_FontDescriptorInfos; |
| 714 MatchFonts(*sortedFonts, wCodePage, dwFontStyles, | 718 MatchFonts(*sortedFonts, wCodePage, dwFontStyles, |
| 715 CFX_WideString(pszFontFamily), 0); | 719 CFX_WideString(pszFontFamily), 0); |
| 716 m_Hash2CandidateList.SetAt(dwHash, sortedFonts); | 720 m_Hash2CandidateList.SetAt(dwHash, sortedFonts); |
| 717 } | 721 } |
| 718 if (sortedFonts->GetSize() == 0) | 722 if (sortedFonts->GetSize() == 0) |
| 719 return nullptr; | 723 return nullptr; |
| 720 | 724 |
| 721 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(0).pFont; | 725 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(0).pFont; |
| 722 IFGAS_Font* pFont = | 726 CFGAS_GEFont* pFont = |
| 723 pDesc->m_pFileAccess | 727 pDesc->m_pFileAccess |
| 724 ? LoadFont(pDesc->m_pFileAccess, pDesc->m_nFaceIndex, nullptr) | 728 ? LoadFont(pDesc->m_pFileAccess, pDesc->m_nFaceIndex, nullptr) |
| 725 : LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); | 729 : LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); |
| 726 if (pFont) | 730 if (pFont) |
| 727 pFont->SetLogicalFontStyle(dwFontStyles); | 731 pFont->SetLogicalFontStyle(dwFontStyles); |
| 728 | 732 |
| 729 pFonts->Add(pFont); | 733 pFonts->Add(pFont); |
| 730 return pFont; | 734 return pFont; |
| 731 } | 735 } |
| 732 IFGAS_Font* CFGAS_FontMgrImp::GetFontByCharset(uint8_t nCharset, | 736 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByCharset( |
| 733 uint32_t dwFontStyles, | 737 uint8_t nCharset, |
| 734 const FX_WCHAR* pszFontFamily) { | 738 uint32_t dwFontStyles, |
| 739 const FX_WCHAR* pszFontFamily) { |
| 735 return GetFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, | 740 return GetFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, |
| 736 pszFontFamily); | 741 pszFontFamily); |
| 737 } | 742 } |
| 738 IFGAS_Font* CFGAS_FontMgrImp::GetFontByUnicode(FX_WCHAR wUnicode, | 743 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByUnicode( |
| 739 uint32_t dwFontStyles, | 744 FX_WCHAR wUnicode, |
| 740 const FX_WCHAR* pszFontFamily) { | 745 uint32_t dwFontStyles, |
| 741 IFGAS_Font* pFont = nullptr; | 746 const FX_WCHAR* pszFontFamily) { |
| 747 CFGAS_GEFont* pFont = nullptr; |
| 742 if (m_FailedUnicodes2NULL.Lookup(wUnicode, pFont)) | 748 if (m_FailedUnicodes2NULL.Lookup(wUnicode, pFont)) |
| 743 return nullptr; | 749 return nullptr; |
| 744 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wUnicode); | 750 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wUnicode); |
| 745 uint16_t wCodePage = x ? x->wCodePage : 0xFFFF; | 751 uint16_t wCodePage = x ? x->wCodePage : 0xFFFF; |
| 746 uint16_t wBitField = x ? x->wBitField : 0x03E7; | 752 uint16_t wBitField = x ? x->wBitField : 0x03E7; |
| 747 CFX_ByteString bsHash; | 753 CFX_ByteString bsHash; |
| 748 if (wCodePage == 0xFFFF) | 754 if (wCodePage == 0xFFFF) |
| 749 bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles); | 755 bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles); |
| 750 else | 756 else |
| 751 bsHash.Format("%d, %d", wCodePage, dwFontStyles); | 757 bsHash.Format("%d, %d", wCodePage, dwFontStyles); |
| 752 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); | 758 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); |
| 753 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); | 759 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); |
| 754 CFX_ArrayTemplate<IFGAS_Font*>* pFonts = nullptr; | 760 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts = nullptr; |
| 755 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { | 761 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { |
| 756 if (!pFonts) | 762 if (!pFonts) |
| 757 return nullptr; | 763 return nullptr; |
| 758 for (int32_t i = 0; i < pFonts->GetSize(); ++i) { | 764 for (int32_t i = 0; i < pFonts->GetSize(); ++i) { |
| 759 if (VerifyUnicode(pFonts->GetAt(i), wUnicode)) | 765 if (VerifyUnicode(pFonts->GetAt(i), wUnicode)) |
| 760 return pFonts->GetAt(i)->Retain(); | 766 return pFonts->GetAt(i)->Retain(); |
| 761 } | 767 } |
| 762 } | 768 } |
| 763 if (!pFonts) | 769 if (!pFonts) |
| 764 pFonts = new CFX_ArrayTemplate<IFGAS_Font*>; | 770 pFonts = new CFX_ArrayTemplate<CFGAS_GEFont*>; |
| 765 m_Hash2Fonts.SetAt(dwHash, pFonts); | 771 m_Hash2Fonts.SetAt(dwHash, pFonts); |
| 766 CFX_FontDescriptorInfos* sortedFonts = nullptr; | 772 CFX_FontDescriptorInfos* sortedFonts = nullptr; |
| 767 if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) { | 773 if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) { |
| 768 sortedFonts = new CFX_FontDescriptorInfos; | 774 sortedFonts = new CFX_FontDescriptorInfos; |
| 769 MatchFonts(*sortedFonts, wCodePage, dwFontStyles, | 775 MatchFonts(*sortedFonts, wCodePage, dwFontStyles, |
| 770 CFX_WideString(pszFontFamily), wUnicode); | 776 CFX_WideString(pszFontFamily), wUnicode); |
| 771 m_Hash2CandidateList.SetAt(dwHash, sortedFonts); | 777 m_Hash2CandidateList.SetAt(dwHash, sortedFonts); |
| 772 } | 778 } |
| 773 for (int32_t i = 0; i < sortedFonts->GetSize(); ++i) { | 779 for (int32_t i = 0; i < sortedFonts->GetSize(); ++i) { |
| 774 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(i).pFont; | 780 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(i).pFont; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 802 FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); | 808 FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); |
| 803 pFileRead->Release(); | 809 pFileRead->Release(); |
| 804 if (!pFace) | 810 if (!pFace) |
| 805 return FALSE; | 811 return FALSE; |
| 806 if (FXFT_Get_Face_External_Stream(pFace)) | 812 if (FXFT_Get_Face_External_Stream(pFace)) |
| 807 FXFT_Clear_Face_External_Stream(pFace); | 813 FXFT_Clear_Face_External_Stream(pFace); |
| 808 FXFT_Done_Face(pFace); | 814 FXFT_Done_Face(pFace); |
| 809 return !retCharmap && retIndex; | 815 return !retCharmap && retIndex; |
| 810 } | 816 } |
| 811 | 817 |
| 812 FX_BOOL CFGAS_FontMgrImp::VerifyUnicode(IFGAS_Font* pFont, FX_WCHAR wcUnicode) { | 818 FX_BOOL CFGAS_FontMgrImp::VerifyUnicode(CFGAS_GEFont* pFont, |
| 819 FX_WCHAR wcUnicode) { |
| 813 if (!pFont) | 820 if (!pFont) |
| 814 return FALSE; | 821 return FALSE; |
| 815 | 822 |
| 816 FXFT_Face pFace = pFont->GetDevFont()->GetFace(); | 823 FXFT_Face pFace = pFont->GetDevFont()->GetFace(); |
| 817 FXFT_CharMap charmap = FXFT_Get_Face_Charmap(pFace); | 824 FXFT_CharMap charmap = FXFT_Get_Face_Charmap(pFace); |
| 818 if (FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE) != 0) | 825 if (FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE) != 0) |
| 819 return FALSE; | 826 return FALSE; |
| 820 | 827 |
| 821 if (FXFT_Get_Char_Index(pFace, wcUnicode) == 0) { | 828 if (FXFT_Get_Char_Index(pFace, wcUnicode) == 0) { |
| 822 FXFT_Set_Charmap(pFace, charmap); | 829 FXFT_Set_Charmap(pFace, charmap); |
| 823 return FALSE; | 830 return FALSE; |
| 824 } | 831 } |
| 825 return TRUE; | 832 return TRUE; |
| 826 } | 833 } |
| 827 | 834 |
| 828 IFGAS_Font* CFGAS_FontMgrImp::GetFontByLanguage(uint16_t wLanguage, | 835 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByLanguage( |
| 829 uint32_t dwFontStyles, | 836 uint16_t wLanguage, |
| 830 const FX_WCHAR* pszFontFamily) { | 837 uint32_t dwFontStyles, |
| 838 const FX_WCHAR* pszFontFamily) { |
| 831 return GetFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), dwFontStyles, | 839 return GetFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), dwFontStyles, |
| 832 pszFontFamily); | 840 pszFontFamily); |
| 833 } | 841 } |
| 834 | 842 |
| 835 IFGAS_Font* CFGAS_FontMgrImp::LoadFont(const uint8_t* pBuffer, | 843 CFGAS_GEFont* CFGAS_FontMgrImp::LoadFont(const uint8_t* pBuffer, |
| 836 int32_t iLength, | 844 int32_t iLength, |
| 837 int32_t iFaceIndex, | 845 int32_t iFaceIndex, |
| 838 int32_t* pFaceCount) { | 846 int32_t* pFaceCount) { |
| 839 void* Hash[2] = {(void*)(uintptr_t)pBuffer, (void*)(uintptr_t)iLength}; | 847 void* Hash[2] = {(void*)(uintptr_t)pBuffer, (void*)(uintptr_t)iLength}; |
| 840 uint32_t dwHash = | 848 uint32_t dwHash = |
| 841 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)Hash, sizeof(Hash)), false); | 849 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)Hash, sizeof(Hash)), false); |
| 842 IFX_FileAccess* pFontAccess = nullptr; | 850 IFX_FileAccess* pFontAccess = nullptr; |
| 843 m_Hash2FileAccess.Lookup(dwHash, pFontAccess); | 851 m_Hash2FileAccess.Lookup(dwHash, pFontAccess); |
| 844 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) | 852 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) |
| 845 : nullptr; | 853 : nullptr; |
| 846 } | 854 } |
| 847 | 855 |
| 848 IFGAS_Font* CFGAS_FontMgrImp::LoadFont(const FX_WCHAR* pszFileName, | 856 CFGAS_GEFont* CFGAS_FontMgrImp::LoadFont(const FX_WCHAR* pszFileName, |
| 849 int32_t iFaceIndex, | 857 int32_t iFaceIndex, |
| 850 int32_t* pFaceCount) { | 858 int32_t* pFaceCount) { |
| 851 CFX_ByteString bsHash; | 859 CFX_ByteString bsHash; |
| 852 bsHash += CFX_WideString(pszFileName).UTF8Encode(); | 860 bsHash += CFX_WideString(pszFileName).UTF8Encode(); |
| 853 | 861 |
| 854 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); | 862 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); |
| 855 IFX_FileAccess* pFontAccess = nullptr; | 863 IFX_FileAccess* pFontAccess = nullptr; |
| 856 if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) { | 864 if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) { |
| 857 pFontAccess = FX_CreateDefaultFileAccess(pszFileName); | 865 pFontAccess = FX_CreateDefaultFileAccess(pszFileName); |
| 858 m_Hash2FileAccess.SetAt(dwHash, pFontAccess); | 866 m_Hash2FileAccess.SetAt(dwHash, pFontAccess); |
| 859 } | 867 } |
| 860 | 868 |
| 861 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) | 869 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) |
| 862 : nullptr; | 870 : nullptr; |
| 863 } | 871 } |
| 864 | 872 |
| 865 IFGAS_Font* CFGAS_FontMgrImp::LoadFont(IFX_Stream* pFontStream, | 873 CFGAS_GEFont* CFGAS_FontMgrImp::LoadFont(IFX_Stream* pFontStream, |
| 866 int32_t iFaceIndex, | 874 int32_t iFaceIndex, |
| 867 int32_t* pFaceCount, | 875 int32_t* pFaceCount, |
| 868 FX_BOOL bSaveStream) { | 876 FX_BOOL bSaveStream) { |
| 869 void* Hash[1] = {(void*)(uintptr_t)pFontStream}; | 877 void* Hash[1] = {(void*)(uintptr_t)pFontStream}; |
| 870 uint32_t dwHash = | 878 uint32_t dwHash = |
| 871 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)Hash, sizeof(Hash)), false); | 879 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)Hash, sizeof(Hash)), false); |
| 872 IFX_FileAccess* pFontAccess = nullptr; | 880 IFX_FileAccess* pFontAccess = nullptr; |
| 873 m_Hash2FileAccess.Lookup(dwHash, pFontAccess); | 881 m_Hash2FileAccess.Lookup(dwHash, pFontAccess); |
| 874 | 882 |
| 875 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) | 883 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) |
| 876 : nullptr; | 884 : nullptr; |
| 877 } | 885 } |
| 878 | 886 |
| 879 IFGAS_Font* CFGAS_FontMgrImp::LoadFont(IFX_FileAccess* pFontAccess, | 887 CFGAS_GEFont* CFGAS_FontMgrImp::LoadFont(IFX_FileAccess* pFontAccess, |
| 880 int32_t iFaceIndex, | 888 int32_t iFaceIndex, |
| 881 int32_t* pFaceCount, | 889 int32_t* pFaceCount, |
| 882 FX_BOOL bWantCache) { | 890 FX_BOOL bWantCache) { |
| 883 uint32_t dwHash = 0; | 891 uint32_t dwHash = 0; |
| 884 IFGAS_Font* pFont = nullptr; | 892 CFGAS_GEFont* pFont = nullptr; |
| 885 if (bWantCache) { | 893 if (bWantCache) { |
| 886 CFX_ByteString bsHash; | 894 CFX_ByteString bsHash; |
| 887 bsHash.Format("%d, %d", (uintptr_t)pFontAccess, iFaceIndex); | 895 bsHash.Format("%d, %d", (uintptr_t)pFontAccess, iFaceIndex); |
| 888 dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); | 896 dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); |
| 889 if (m_FileAccess2IFXFont.Lookup(dwHash, pFont)) { | 897 if (m_FileAccess2IFXFont.Lookup(dwHash, pFont)) { |
| 890 if (pFont) { | 898 if (pFont) { |
| 891 if (pFaceCount) | 899 if (pFaceCount) |
| 892 *pFaceCount = pFont->GetDevFont()->GetFace()->num_faces; | 900 *pFaceCount = pFont->GetDevFont()->GetFace()->num_faces; |
| 893 return pFont->Retain(); | 901 return pFont->Retain(); |
| 894 } | 902 } |
| 895 } | 903 } |
| 896 } | 904 } |
| 897 | 905 |
| 898 CFX_Font* pInternalFont = new CFX_Font; | 906 CFX_Font* pInternalFont = new CFX_Font; |
| 899 IFX_FileRead* pFontStream = | 907 IFX_FileRead* pFontStream = |
| 900 pFontAccess->CreateFileStream(FX_FILEMODE_ReadOnly); | 908 pFontAccess->CreateFileStream(FX_FILEMODE_ReadOnly); |
| 901 if (!pFontStream) { | 909 if (!pFontStream) { |
| 902 delete pInternalFont; | 910 delete pInternalFont; |
| 903 return nullptr; | 911 return nullptr; |
| 904 } | 912 } |
| 905 if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) { | 913 if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) { |
| 906 delete pInternalFont; | 914 delete pInternalFont; |
| 907 pFontStream->Release(); | 915 pFontStream->Release(); |
| 908 return nullptr; | 916 return nullptr; |
| 909 } | 917 } |
| 910 pFont = IFGAS_Font::LoadFont(pInternalFont, this, TRUE); | 918 pFont = CFGAS_GEFont::LoadFont(pInternalFont, this, TRUE); |
| 911 if (!pFont) { | 919 if (!pFont) { |
| 912 delete pInternalFont; | 920 delete pInternalFont; |
| 913 pFontStream->Release(); | 921 pFontStream->Release(); |
| 914 return nullptr; | 922 return nullptr; |
| 915 } | 923 } |
| 916 if (bWantCache) | 924 if (bWantCache) |
| 917 m_FileAccess2IFXFont.SetAt(dwHash, pFont); | 925 m_FileAccess2IFXFont.SetAt(dwHash, pFont); |
| 918 | 926 |
| 919 m_IFXFont2FileRead.SetAt(pFont, pFontStream); | 927 m_IFXFont2FileRead.SetAt(pFont, pFontStream); |
| 920 if (pFaceCount) | 928 if (pFaceCount) |
| 921 *pFaceCount = pFont->GetDevFont()->GetFace()->num_faces; | 929 *pFaceCount = pFont->GetDevFont()->GetFace()->num_faces; |
| 922 | 930 |
| 923 return pFont; | 931 return pFont; |
| 924 } | 932 } |
| 925 | 933 |
| 926 IFGAS_Font* CFGAS_FontMgrImp::LoadFont(const CFX_WideString& wsFaceName, | 934 CFGAS_GEFont* CFGAS_FontMgrImp::LoadFont(const CFX_WideString& wsFaceName, |
| 927 int32_t iFaceIndex, | 935 int32_t iFaceIndex, |
| 928 int32_t* pFaceCount) { | 936 int32_t* pFaceCount) { |
| 929 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); | 937 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); |
| 930 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); | 938 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); |
| 931 if (!pFontMapper) | 939 if (!pFontMapper) |
| 932 return nullptr; | 940 return nullptr; |
| 933 | 941 |
| 934 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); | 942 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); |
| 935 if (!pSystemFontInfo) | 943 if (!pSystemFontInfo) |
| 936 return nullptr; | 944 return nullptr; |
| 937 | 945 |
| 938 IFX_FileRead* pFontStream = CreateFontStream(wsFaceName.UTF8Encode()); | 946 IFX_FileRead* pFontStream = CreateFontStream(wsFaceName.UTF8Encode()); |
| 939 if (!pFontStream) | 947 if (!pFontStream) |
| 940 return nullptr; | 948 return nullptr; |
| 941 | 949 |
| 942 if (!LoadFace(pFontStream, 0)) { | 950 if (!LoadFace(pFontStream, 0)) { |
| 943 pFontStream->Release(); | 951 pFontStream->Release(); |
| 944 return nullptr; | 952 return nullptr; |
| 945 } | 953 } |
| 946 | 954 |
| 947 CFX_Font* pInternalFont = new CFX_Font(); | 955 CFX_Font* pInternalFont = new CFX_Font(); |
| 948 if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) { | 956 if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) { |
| 949 pFontStream->Release(); | 957 pFontStream->Release(); |
| 950 return nullptr; | 958 return nullptr; |
| 951 } | 959 } |
| 952 | 960 |
| 953 IFGAS_Font* pFont = IFGAS_Font::LoadFont(pInternalFont, this, FALSE); | 961 CFGAS_GEFont* pFont = CFGAS_GEFont::LoadFont(pInternalFont, this, FALSE); |
| 954 if (!pFont) { | 962 if (!pFont) { |
| 955 pFontStream->Release(); | 963 pFontStream->Release(); |
| 956 return nullptr; | 964 return nullptr; |
| 957 } | 965 } |
| 958 | 966 |
| 959 m_IFXFont2FileRead.SetAt(pFont, pFontStream); | 967 m_IFXFont2FileRead.SetAt(pFont, pFontStream); |
| 960 if (pFaceCount) | 968 if (pFaceCount) |
| 961 *pFaceCount = pFont->GetDevFont()->GetFace()->num_faces; | 969 *pFaceCount = pFont->GetDevFont()->GetFace()->num_faces; |
| 962 | 970 |
| 963 return pFont; | 971 return pFont; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1207 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); | 1215 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); |
| 1208 while (pos) { | 1216 while (pos) { |
| 1209 uint32_t dwHash; | 1217 uint32_t dwHash; |
| 1210 CFX_FontDescriptorInfos* pDescs; | 1218 CFX_FontDescriptorInfos* pDescs; |
| 1211 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); | 1219 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); |
| 1212 delete pDescs; | 1220 delete pDescs; |
| 1213 } | 1221 } |
| 1214 pos = m_FileAccess2IFXFont.GetStartPosition(); | 1222 pos = m_FileAccess2IFXFont.GetStartPosition(); |
| 1215 while (pos) { | 1223 while (pos) { |
| 1216 uint32_t dwHash; | 1224 uint32_t dwHash; |
| 1217 IFGAS_Font* pFont; | 1225 CFGAS_GEFont* pFont; |
| 1218 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pFont); | 1226 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pFont); |
| 1219 if (NULL != pFont) { | 1227 if (NULL != pFont) { |
| 1220 pFont->Release(); | 1228 pFont->Release(); |
| 1221 } | 1229 } |
| 1222 } | 1230 } |
| 1223 pos = m_IFXFont2FileRead.GetStartPosition(); | 1231 pos = m_IFXFont2FileRead.GetStartPosition(); |
| 1224 while (pos) { | 1232 while (pos) { |
| 1225 IFGAS_Font* pFont; | 1233 CFGAS_GEFont* pFont; |
| 1226 IFX_FileRead* pFileRead; | 1234 IFX_FileRead* pFileRead; |
| 1227 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); | 1235 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); |
| 1228 pFileRead->Release(); | 1236 pFileRead->Release(); |
| 1229 } | 1237 } |
| 1230 } | 1238 } |
| 1231 void CFGAS_FontMgrImp::RemoveFont(IFGAS_Font* pEFont) { | 1239 void CFGAS_FontMgrImp::RemoveFont(CFGAS_GEFont* pEFont) { |
| 1232 if (NULL == pEFont) { | 1240 if (NULL == pEFont) { |
| 1233 return; | 1241 return; |
| 1234 } | 1242 } |
| 1235 IFX_FileRead* pFileRead; | 1243 IFX_FileRead* pFileRead; |
| 1236 if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) { | 1244 if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) { |
| 1237 pFileRead->Release(); | 1245 pFileRead->Release(); |
| 1238 m_IFXFont2FileRead.RemoveKey(pEFont); | 1246 m_IFXFont2FileRead.RemoveKey(pEFont); |
| 1239 } | 1247 } |
| 1240 FX_POSITION pos; | 1248 FX_POSITION pos; |
| 1241 pos = m_FileAccess2IFXFont.GetStartPosition(); | 1249 pos = m_FileAccess2IFXFont.GetStartPosition(); |
| 1242 while (pos) { | 1250 while (pos) { |
| 1243 uint32_t dwHash; | 1251 uint32_t dwHash; |
| 1244 IFGAS_Font* pCFont; | 1252 CFGAS_GEFont* pCFont; |
| 1245 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pCFont); | 1253 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pCFont); |
| 1246 if (pCFont == pEFont) { | 1254 if (pCFont == pEFont) { |
| 1247 m_FileAccess2IFXFont.RemoveKey(dwHash); | 1255 m_FileAccess2IFXFont.RemoveKey(dwHash); |
| 1248 break; | 1256 break; |
| 1249 } | 1257 } |
| 1250 } | 1258 } |
| 1251 pos = m_Hash2Fonts.GetStartPosition(); | 1259 pos = m_Hash2Fonts.GetStartPosition(); |
| 1252 while (pos) { | 1260 while (pos) { |
| 1253 uint32_t dwHash; | 1261 uint32_t dwHash; |
| 1254 CFX_ArrayTemplate<IFGAS_Font*>* pFonts; | 1262 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; |
| 1255 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); | 1263 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); |
| 1256 if (NULL != pFonts) { | 1264 if (NULL != pFonts) { |
| 1257 for (int32_t i = 0; i < pFonts->GetSize(); i++) { | 1265 for (int32_t i = 0; i < pFonts->GetSize(); i++) { |
| 1258 if (pFonts->GetAt(i) == pEFont) { | 1266 if (pFonts->GetAt(i) == pEFont) { |
| 1259 pFonts->SetAt(i, NULL); | 1267 pFonts->SetAt(i, NULL); |
| 1260 } | 1268 } |
| 1261 } | 1269 } |
| 1262 } else { | 1270 } else { |
| 1263 m_Hash2Fonts.RemoveKey(dwHash); | 1271 m_Hash2Fonts.RemoveKey(dwHash); |
| 1264 } | 1272 } |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1494 } | 1502 } |
| 1495 } | 1503 } |
| 1496 int32_t CFGAS_FontMgrImp::IsPartName(const CFX_WideString& Name1, | 1504 int32_t CFGAS_FontMgrImp::IsPartName(const CFX_WideString& Name1, |
| 1497 const CFX_WideString& Name2) { | 1505 const CFX_WideString& Name2) { |
| 1498 if (Name1.Find(Name2.c_str()) != -1) { | 1506 if (Name1.Find(Name2.c_str()) != -1) { |
| 1499 return 1; | 1507 return 1; |
| 1500 } | 1508 } |
| 1501 return 0; | 1509 return 0; |
| 1502 } | 1510 } |
| 1503 #endif | 1511 #endif |
| OLD | NEW |