| 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" |
| 11 #include "xfa/fxfa/include/xfa_fontmgr.h" | 11 #include "xfa/fxfa/include/xfa_fontmgr.h" |
| 12 | 12 |
| 13 IFGAS_Font* IFGAS_Font::LoadFont(const FX_WCHAR* pszFontFamily, | 13 IFGAS_Font* IFGAS_Font::LoadFont(const FX_WCHAR* pszFontFamily, |
| 14 uint32_t dwFontStyles, | 14 uint32_t dwFontStyles, |
| 15 uint16_t wCodePage, | 15 uint16_t wCodePage, |
| 16 IFGAS_FontMgr* pFontMgr) { | 16 IFGAS_FontMgr* pFontMgr) { |
| 17 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 17 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 18 if (NULL != pFontMgr) { | 18 if (NULL != pFontMgr) { |
| 19 return pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily); | 19 return pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily); |
| 20 } | 20 } |
| 21 return NULL; | 21 return NULL; |
| 22 #else | 22 #else |
| 23 CFX_GEFont* pFont = new CFX_GEFont(pFontMgr); | 23 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); |
| 24 if (!pFont->LoadFont(pszFontFamily, dwFontStyles, wCodePage)) { | 24 if (!pFont->LoadFont(pszFontFamily, dwFontStyles, wCodePage)) { |
| 25 pFont->Release(); | 25 pFont->Release(); |
| 26 return NULL; | 26 return NULL; |
| 27 } | 27 } |
| 28 return pFont; | 28 return pFont; |
| 29 #endif | 29 #endif |
| 30 } | 30 } |
| 31 IFGAS_Font* IFGAS_Font::LoadFont(const uint8_t* pBuffer, | 31 IFGAS_Font* IFGAS_Font::LoadFont(const uint8_t* pBuffer, |
| 32 int32_t iLength, | 32 int32_t iLength, |
| 33 IFGAS_FontMgr* pFontMgr) { | 33 IFGAS_FontMgr* pFontMgr) { |
| 34 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 34 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 35 if (NULL != pFontMgr) { | 35 if (NULL != pFontMgr) { |
| 36 return pFontMgr->LoadFont(pBuffer, iLength, 0, NULL); | 36 return pFontMgr->LoadFont(pBuffer, iLength, 0, NULL); |
| 37 } | 37 } |
| 38 return NULL; | 38 return NULL; |
| 39 #else | 39 #else |
| 40 CFX_GEFont* pFont = new CFX_GEFont(pFontMgr); | 40 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); |
| 41 if (!pFont->LoadFont(pBuffer, iLength)) { | 41 if (!pFont->LoadFont(pBuffer, iLength)) { |
| 42 pFont->Release(); | 42 pFont->Release(); |
| 43 return NULL; | 43 return NULL; |
| 44 } | 44 } |
| 45 return pFont; | 45 return pFont; |
| 46 #endif | 46 #endif |
| 47 } | 47 } |
| 48 IFGAS_Font* IFGAS_Font::LoadFont(const FX_WCHAR* pszFileName, | 48 IFGAS_Font* IFGAS_Font::LoadFont(const FX_WCHAR* pszFileName, |
| 49 IFGAS_FontMgr* pFontMgr) { | 49 IFGAS_FontMgr* pFontMgr) { |
| 50 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 50 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 51 if (NULL != pFontMgr) { | 51 if (NULL != pFontMgr) { |
| 52 return pFontMgr->LoadFont(pszFileName, 0, NULL); | 52 return pFontMgr->LoadFont(pszFileName, 0, NULL); |
| 53 } | 53 } |
| 54 return NULL; | 54 return NULL; |
| 55 #else | 55 #else |
| 56 CFX_GEFont* pFont = new CFX_GEFont(pFontMgr); | 56 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); |
| 57 if (!pFont->LoadFont(pszFileName)) { | 57 if (!pFont->LoadFont(pszFileName)) { |
| 58 pFont->Release(); | 58 pFont->Release(); |
| 59 return NULL; | 59 return NULL; |
| 60 } | 60 } |
| 61 return pFont; | 61 return pFont; |
| 62 #endif | 62 #endif |
| 63 } | 63 } |
| 64 IFGAS_Font* IFGAS_Font::LoadFont(IFX_Stream* pFontStream, | 64 IFGAS_Font* IFGAS_Font::LoadFont(IFX_Stream* pFontStream, |
| 65 IFGAS_FontMgr* pFontMgr, | 65 IFGAS_FontMgr* pFontMgr, |
| 66 FX_BOOL bSaveStream) { | 66 FX_BOOL bSaveStream) { |
| 67 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 67 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 68 if (NULL != pFontMgr) { | 68 if (NULL != pFontMgr) { |
| 69 return pFontMgr->LoadFont(pFontStream, 0, NULL); | 69 return pFontMgr->LoadFont(pFontStream, 0, NULL); |
| 70 } | 70 } |
| 71 return NULL; | 71 return NULL; |
| 72 #else | 72 #else |
| 73 CFX_GEFont* pFont = new CFX_GEFont(pFontMgr); | 73 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); |
| 74 if (!pFont->LoadFont(pFontStream, bSaveStream)) { | 74 if (!pFont->LoadFont(pFontStream, bSaveStream)) { |
| 75 pFont->Release(); | 75 pFont->Release(); |
| 76 return NULL; | 76 return NULL; |
| 77 } | 77 } |
| 78 return pFont; | 78 return pFont; |
| 79 #endif | 79 #endif |
| 80 } | 80 } |
| 81 IFGAS_Font* IFGAS_Font::LoadFont(CFX_Font* pExtFont, | 81 IFGAS_Font* IFGAS_Font::LoadFont(CFX_Font* pExtFont, |
| 82 IFGAS_FontMgr* pFontMgr, | 82 IFGAS_FontMgr* pFontMgr, |
| 83 FX_BOOL bTakeOver) { | 83 FX_BOOL bTakeOver) { |
| 84 CFX_GEFont* pFont = new CFX_GEFont(pFontMgr); | 84 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); |
| 85 if (!pFont->LoadFont(pExtFont, bTakeOver)) { | 85 if (!pFont->LoadFont(pExtFont, bTakeOver)) { |
| 86 pFont->Release(); | 86 pFont->Release(); |
| 87 return NULL; | 87 return NULL; |
| 88 } | 88 } |
| 89 return pFont; | 89 return pFont; |
| 90 } | 90 } |
| 91 CFX_GEFont::CFX_GEFont(IFGAS_FontMgr* pFontMgr) | 91 |
| 92 CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr) |
| 92 : | 93 : |
| 93 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 94 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 94 m_bUseLogFontStyle(FALSE), | 95 m_bUseLogFontStyle(FALSE), |
| 95 m_dwLogFontStyle(0), | 96 m_dwLogFontStyle(0), |
| 96 #endif | 97 #endif |
| 97 m_pFont(NULL), | 98 m_pFont(NULL), |
| 98 m_pFontMgr(pFontMgr), | 99 m_pFontMgr(pFontMgr), |
| 99 m_iRefCount(1), | 100 m_iRefCount(1), |
| 100 m_bExtFont(FALSE), | 101 m_bExtFont(FALSE), |
| 101 m_pStream(NULL), | 102 m_pStream(NULL), |
| 102 m_pFileRead(NULL), | 103 m_pFileRead(NULL), |
| 103 m_pFontEncoding(NULL), | 104 m_pFontEncoding(NULL), |
| 104 m_pCharWidthMap(NULL), | 105 m_pCharWidthMap(NULL), |
| 105 m_pRectArray(NULL), | 106 m_pRectArray(NULL), |
| 106 m_pBBoxMap(NULL), | 107 m_pBBoxMap(NULL), |
| 107 m_pProvider(NULL), | 108 m_pProvider(NULL), |
| 108 m_wCharSet(0xFFFF) { | 109 m_wCharSet(0xFFFF) { |
| 109 } | 110 } |
| 110 | 111 |
| 111 CFX_GEFont::CFX_GEFont(const CFX_GEFont& src, uint32_t dwFontStyles) | 112 CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles) |
| 112 : | 113 : |
| 113 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 114 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 114 m_bUseLogFontStyle(FALSE), | 115 m_bUseLogFontStyle(FALSE), |
| 115 m_dwLogFontStyle(0), | 116 m_dwLogFontStyle(0), |
| 116 #endif | 117 #endif |
| 117 m_pFont(NULL), | 118 m_pFont(NULL), |
| 118 m_pFontMgr(src.m_pFontMgr), | 119 m_pFontMgr(src.m_pFontMgr), |
| 119 m_iRefCount(1), | 120 m_iRefCount(1), |
| 120 m_bExtFont(FALSE), | 121 m_bExtFont(FALSE), |
| 121 m_pStream(NULL), | 122 m_pStream(NULL), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 135 m_pFont->SetSubstFont(pSubst); | 136 m_pFont->SetSubstFont(pSubst); |
| 136 } | 137 } |
| 137 pSubst->m_Weight = | 138 pSubst->m_Weight = |
| 138 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; | 139 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; |
| 139 if (dwFontStyles & FX_FONTSTYLE_Italic) { | 140 if (dwFontStyles & FX_FONTSTYLE_Italic) { |
| 140 pSubst->m_SubstFlags |= FXFONT_SUBST_ITALIC; | 141 pSubst->m_SubstFlags |= FXFONT_SUBST_ITALIC; |
| 141 } | 142 } |
| 142 InitFont(); | 143 InitFont(); |
| 143 } | 144 } |
| 144 | 145 |
| 145 CFX_GEFont::~CFX_GEFont() { | 146 CFGAS_GEFont::~CFGAS_GEFont() { |
| 146 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++) | 147 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++) |
| 147 m_SubstFonts[i]->Release(); | 148 m_SubstFonts[i]->Release(); |
| 148 | 149 |
| 149 m_SubstFonts.RemoveAll(); | 150 m_SubstFonts.RemoveAll(); |
| 150 m_FontMapper.clear(); | 151 m_FontMapper.clear(); |
| 151 if (m_pFileRead) | 152 if (m_pFileRead) |
| 152 m_pFileRead->Release(); | 153 m_pFileRead->Release(); |
| 153 | 154 |
| 154 if (m_pStream) | 155 if (m_pStream) |
| 155 m_pStream->Release(); | 156 m_pStream->Release(); |
| 156 | 157 |
| 157 delete m_pFontEncoding; | 158 delete m_pFontEncoding; |
| 158 delete m_pCharWidthMap; | 159 delete m_pCharWidthMap; |
| 159 delete m_pRectArray; | 160 delete m_pRectArray; |
| 160 delete m_pBBoxMap; | 161 delete m_pBBoxMap; |
| 161 if (!m_bExtFont) | 162 if (!m_bExtFont) |
| 162 delete m_pFont; | 163 delete m_pFont; |
| 163 } | 164 } |
| 164 | 165 |
| 165 void CFX_GEFont::Release() { | 166 void CFGAS_GEFont::Release() { |
| 166 if (--m_iRefCount < 1) { | 167 if (--m_iRefCount < 1) { |
| 167 if (m_pFontMgr != NULL) { | 168 if (m_pFontMgr != NULL) { |
| 168 m_pFontMgr->RemoveFont(this); | 169 m_pFontMgr->RemoveFont(this); |
| 169 } | 170 } |
| 170 delete this; | 171 delete this; |
| 171 } | 172 } |
| 172 } | 173 } |
| 173 IFGAS_Font* CFX_GEFont::Retain() { | 174 IFGAS_Font* CFGAS_GEFont::Retain() { |
| 174 ++m_iRefCount; | 175 ++m_iRefCount; |
| 175 return this; | 176 return this; |
| 176 } | 177 } |
| 177 FX_BOOL CFX_GEFont::LoadFont(const FX_WCHAR* pszFontFamily, | 178 FX_BOOL CFGAS_GEFont::LoadFont(const FX_WCHAR* pszFontFamily, |
| 178 uint32_t dwFontStyles, | 179 uint32_t dwFontStyles, |
| 179 uint16_t wCodePage) { | 180 uint16_t wCodePage) { |
| 180 if (m_pFont) { | 181 if (m_pFont) { |
| 181 return FALSE; | 182 return FALSE; |
| 182 } | 183 } |
| 183 CFX_ByteString csFontFamily; | 184 CFX_ByteString csFontFamily; |
| 184 if (pszFontFamily != NULL) { | 185 if (pszFontFamily != NULL) { |
| 185 csFontFamily = CFX_ByteString::FromUnicode(pszFontFamily); | 186 csFontFamily = CFX_ByteString::FromUnicode(pszFontFamily); |
| 186 } | 187 } |
| 187 uint32_t dwFlags = 0; | 188 uint32_t dwFlags = 0; |
| 188 if (dwFontStyles & FX_FONTSTYLE_FixedPitch) { | 189 if (dwFontStyles & FX_FONTSTYLE_FixedPitch) { |
| 189 dwFlags |= FXFONT_FIXED_PITCH; | 190 dwFlags |= FXFONT_FIXED_PITCH; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 } else if (dwFlags & FXFONT_ITALIC) { | 222 } else if (dwFlags & FXFONT_ITALIC) { |
| 222 csFontFamily += ",Italic"; | 223 csFontFamily += ",Italic"; |
| 223 } | 224 } |
| 224 m_pFont->LoadSubst(csFontFamily, TRUE, dwFlags, iWeight, 0, wCodePage); | 225 m_pFont->LoadSubst(csFontFamily, TRUE, dwFlags, iWeight, 0, wCodePage); |
| 225 FX_BOOL bRet = m_pFont->GetFace() != nullptr; | 226 FX_BOOL bRet = m_pFont->GetFace() != nullptr; |
| 226 if (bRet) { | 227 if (bRet) { |
| 227 bRet = InitFont(); | 228 bRet = InitFont(); |
| 228 } | 229 } |
| 229 return bRet; | 230 return bRet; |
| 230 } | 231 } |
| 231 FX_BOOL CFX_GEFont::LoadFont(const uint8_t* pBuffer, int32_t length) { | 232 FX_BOOL CFGAS_GEFont::LoadFont(const uint8_t* pBuffer, int32_t length) { |
| 232 if (m_pFont) { | 233 if (m_pFont) { |
| 233 return FALSE; | 234 return FALSE; |
| 234 } | 235 } |
| 235 m_pFont = new CFX_Font; | 236 m_pFont = new CFX_Font; |
| 236 FX_BOOL bRet = m_pFont->LoadEmbedded(pBuffer, length); | 237 FX_BOOL bRet = m_pFont->LoadEmbedded(pBuffer, length); |
| 237 if (bRet) { | 238 if (bRet) { |
| 238 bRet = InitFont(); | 239 bRet = InitFont(); |
| 239 } | 240 } |
| 240 m_wCharSet = 0xFFFF; | 241 m_wCharSet = 0xFFFF; |
| 241 return bRet; | 242 return bRet; |
| 242 } | 243 } |
| 243 FX_BOOL CFX_GEFont::LoadFont(const FX_WCHAR* pszFileName) { | 244 FX_BOOL CFGAS_GEFont::LoadFont(const FX_WCHAR* pszFileName) { |
| 244 if (m_pFont || m_pStream || m_pFileRead) { | 245 if (m_pFont || m_pStream || m_pFileRead) { |
| 245 return FALSE; | 246 return FALSE; |
| 246 } | 247 } |
| 247 m_pStream = IFX_Stream::CreateStream( | 248 m_pStream = IFX_Stream::CreateStream( |
| 248 pszFileName, FX_STREAMACCESS_Binary | FX_STREAMACCESS_Read); | 249 pszFileName, FX_STREAMACCESS_Binary | FX_STREAMACCESS_Read); |
| 249 m_pFileRead = FX_CreateFileRead(m_pStream); | 250 m_pFileRead = FX_CreateFileRead(m_pStream); |
| 250 FX_BOOL bRet = FALSE; | 251 FX_BOOL bRet = FALSE; |
| 251 if (m_pStream && m_pFileRead) { | 252 if (m_pStream && m_pFileRead) { |
| 252 m_pFont = new CFX_Font; | 253 m_pFont = new CFX_Font; |
| 253 bRet = m_pFont->LoadFile(m_pFileRead); | 254 bRet = m_pFont->LoadFile(m_pFileRead); |
| 254 if (bRet) { | 255 if (bRet) { |
| 255 bRet = InitFont(); | 256 bRet = InitFont(); |
| 256 } else { | 257 } else { |
| 257 m_pFileRead->Release(); | 258 m_pFileRead->Release(); |
| 258 m_pFileRead = nullptr; | 259 m_pFileRead = nullptr; |
| 259 } | 260 } |
| 260 } | 261 } |
| 261 m_wCharSet = 0xFFFF; | 262 m_wCharSet = 0xFFFF; |
| 262 return bRet; | 263 return bRet; |
| 263 } | 264 } |
| 264 FX_BOOL CFX_GEFont::LoadFont(IFX_Stream* pFontStream, FX_BOOL bSaveStream) { | 265 FX_BOOL CFGAS_GEFont::LoadFont(IFX_Stream* pFontStream, FX_BOOL bSaveStream) { |
| 265 if (m_pFont || m_pFileRead || !pFontStream || pFontStream->GetLength() < 1) { | 266 if (m_pFont || m_pFileRead || !pFontStream || pFontStream->GetLength() < 1) { |
| 266 return FALSE; | 267 return FALSE; |
| 267 } | 268 } |
| 268 if (bSaveStream) { | 269 if (bSaveStream) { |
| 269 m_pStream = pFontStream; | 270 m_pStream = pFontStream; |
| 270 } | 271 } |
| 271 m_pFileRead = FX_CreateFileRead(pFontStream); | 272 m_pFileRead = FX_CreateFileRead(pFontStream); |
| 272 m_pFont = new CFX_Font; | 273 m_pFont = new CFX_Font; |
| 273 FX_BOOL bRet = m_pFont->LoadFile(m_pFileRead); | 274 FX_BOOL bRet = m_pFont->LoadFile(m_pFileRead); |
| 274 if (bRet) { | 275 if (bRet) { |
| 275 bRet = InitFont(); | 276 bRet = InitFont(); |
| 276 } else { | 277 } else { |
| 277 m_pFileRead->Release(); | 278 m_pFileRead->Release(); |
| 278 m_pFileRead = nullptr; | 279 m_pFileRead = nullptr; |
| 279 } | 280 } |
| 280 m_wCharSet = 0xFFFF; | 281 m_wCharSet = 0xFFFF; |
| 281 return bRet; | 282 return bRet; |
| 282 } | 283 } |
| 283 FX_BOOL CFX_GEFont::LoadFont(CFX_Font* pExtFont, FX_BOOL bTakeOver) { | 284 FX_BOOL CFGAS_GEFont::LoadFont(CFX_Font* pExtFont, FX_BOOL bTakeOver) { |
| 284 if (m_pFont || !pExtFont) { | 285 if (m_pFont || !pExtFont) { |
| 285 return FALSE; | 286 return FALSE; |
| 286 } | 287 } |
| 287 m_pFont = pExtFont; | 288 m_pFont = pExtFont; |
| 288 FX_BOOL bRet = !!m_pFont; | 289 FX_BOOL bRet = !!m_pFont; |
| 289 if (bRet) { | 290 if (bRet) { |
| 290 m_bExtFont = !bTakeOver; | 291 m_bExtFont = !bTakeOver; |
| 291 bRet = InitFont(); | 292 bRet = InitFont(); |
| 292 } else { | 293 } else { |
| 293 m_bExtFont = TRUE; | 294 m_bExtFont = TRUE; |
| 294 } | 295 } |
| 295 m_wCharSet = 0xFFFF; | 296 m_wCharSet = 0xFFFF; |
| 296 return bRet; | 297 return bRet; |
| 297 } | 298 } |
| 298 FX_BOOL CFX_GEFont::InitFont() { | 299 FX_BOOL CFGAS_GEFont::InitFont() { |
| 299 if (!m_pFont) | 300 if (!m_pFont) |
| 300 return FALSE; | 301 return FALSE; |
| 301 if (!m_pFontEncoding) { | 302 if (!m_pFontEncoding) { |
| 302 m_pFontEncoding = FX_CreateFontEncodingEx(m_pFont); | 303 m_pFontEncoding = FX_CreateFontEncodingEx(m_pFont); |
| 303 if (!m_pFontEncoding) | 304 if (!m_pFontEncoding) |
| 304 return FALSE; | 305 return FALSE; |
| 305 } | 306 } |
| 306 if (!m_pCharWidthMap) | 307 if (!m_pCharWidthMap) |
| 307 m_pCharWidthMap = new CFX_WordDiscreteArray(1024); | 308 m_pCharWidthMap = new CFX_WordDiscreteArray(1024); |
| 308 if (!m_pRectArray) | 309 if (!m_pRectArray) |
| 309 m_pRectArray = new CFX_MassArrayTemplate<CFX_Rect>(16); | 310 m_pRectArray = new CFX_MassArrayTemplate<CFX_Rect>(16); |
| 310 if (!m_pBBoxMap) | 311 if (!m_pBBoxMap) |
| 311 m_pBBoxMap = new CFX_MapPtrToPtr(16); | 312 m_pBBoxMap = new CFX_MapPtrToPtr(16); |
| 312 | 313 |
| 313 return TRUE; | 314 return TRUE; |
| 314 } | 315 } |
| 315 IFGAS_Font* CFX_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) { | 316 IFGAS_Font* CFGAS_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) { |
| 316 if (GetFontStyles() == dwFontStyles) { | 317 if (GetFontStyles() == dwFontStyles) { |
| 317 return Retain(); | 318 return Retain(); |
| 318 } | 319 } |
| 319 return new CFX_GEFont(*this, dwFontStyles); | 320 return new CFGAS_GEFont(*this, dwFontStyles); |
| 320 } | 321 } |
| 321 uint8_t CFX_GEFont::GetCharSet() const { | 322 uint8_t CFGAS_GEFont::GetCharSet() const { |
| 322 if (m_wCharSet != 0xFFFF) { | 323 if (m_wCharSet != 0xFFFF) { |
| 323 return (uint8_t)m_wCharSet; | 324 return (uint8_t)m_wCharSet; |
| 324 } | 325 } |
| 325 if (!m_pFont->GetSubstFont()) { | 326 if (!m_pFont->GetSubstFont()) { |
| 326 return FX_CHARSET_Default; | 327 return FX_CHARSET_Default; |
| 327 } | 328 } |
| 328 return m_pFont->GetSubstFont()->m_Charset; | 329 return m_pFont->GetSubstFont()->m_Charset; |
| 329 } | 330 } |
| 330 void CFX_GEFont::GetFamilyName(CFX_WideString& wsFamily) const { | 331 void CFGAS_GEFont::GetFamilyName(CFX_WideString& wsFamily) const { |
| 331 if (!m_pFont->GetSubstFont() || | 332 if (!m_pFont->GetSubstFont() || |
| 332 m_pFont->GetSubstFont()->m_Family.GetLength() == 0) { | 333 m_pFont->GetSubstFont()->m_Family.GetLength() == 0) { |
| 333 wsFamily = CFX_WideString::FromLocal(m_pFont->GetFamilyName().AsStringC()); | 334 wsFamily = CFX_WideString::FromLocal(m_pFont->GetFamilyName().AsStringC()); |
| 334 } else { | 335 } else { |
| 335 wsFamily = CFX_WideString::FromLocal( | 336 wsFamily = CFX_WideString::FromLocal( |
| 336 m_pFont->GetSubstFont()->m_Family.AsStringC()); | 337 m_pFont->GetSubstFont()->m_Family.AsStringC()); |
| 337 } | 338 } |
| 338 } | 339 } |
| 339 | 340 |
| 340 uint32_t CFX_GEFont::GetFontStyles() const { | 341 uint32_t CFGAS_GEFont::GetFontStyles() const { |
| 341 ASSERT(m_pFont != NULL); | 342 ASSERT(m_pFont != NULL); |
| 342 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 343 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 343 if (m_bUseLogFontStyle) { | 344 if (m_bUseLogFontStyle) { |
| 344 return m_dwLogFontStyle; | 345 return m_dwLogFontStyle; |
| 345 } | 346 } |
| 346 #endif | 347 #endif |
| 347 uint32_t dwStyles = 0; | 348 uint32_t dwStyles = 0; |
| 348 if (!m_pFont->GetSubstFont()) { | 349 if (!m_pFont->GetSubstFont()) { |
| 349 if (m_pFont->IsBold()) { | 350 if (m_pFont->IsBold()) { |
| 350 dwStyles |= FX_FONTSTYLE_Bold; | 351 dwStyles |= FX_FONTSTYLE_Bold; |
| 351 } | 352 } |
| 352 if (m_pFont->IsItalic()) { | 353 if (m_pFont->IsItalic()) { |
| 353 dwStyles |= FX_FONTSTYLE_Italic; | 354 dwStyles |= FX_FONTSTYLE_Italic; |
| 354 } | 355 } |
| 355 } else { | 356 } else { |
| 356 if (m_pFont->GetSubstFont()->m_Weight == FXFONT_FW_BOLD) { | 357 if (m_pFont->GetSubstFont()->m_Weight == FXFONT_FW_BOLD) { |
| 357 dwStyles |= FX_FONTSTYLE_Bold; | 358 dwStyles |= FX_FONTSTYLE_Bold; |
| 358 } | 359 } |
| 359 if (m_pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_ITALIC) { | 360 if (m_pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_ITALIC) { |
| 360 dwStyles |= FX_FONTSTYLE_Italic; | 361 dwStyles |= FX_FONTSTYLE_Italic; |
| 361 } | 362 } |
| 362 } | 363 } |
| 363 return dwStyles; | 364 return dwStyles; |
| 364 } | 365 } |
| 365 FX_BOOL CFX_GEFont::GetCharWidth(FX_WCHAR wUnicode, | 366 FX_BOOL CFGAS_GEFont::GetCharWidth(FX_WCHAR wUnicode, |
| 366 int32_t& iWidth, | 367 int32_t& iWidth, |
| 367 FX_BOOL bCharCode) { | 368 FX_BOOL bCharCode) { |
| 368 return GetCharWidth(wUnicode, iWidth, TRUE, bCharCode); | 369 return GetCharWidth(wUnicode, iWidth, TRUE, bCharCode); |
| 369 } | 370 } |
| 370 FX_BOOL CFX_GEFont::GetCharWidth(FX_WCHAR wUnicode, | 371 FX_BOOL CFGAS_GEFont::GetCharWidth(FX_WCHAR wUnicode, |
| 371 int32_t& iWidth, | 372 int32_t& iWidth, |
| 372 FX_BOOL bRecursive, | 373 FX_BOOL bRecursive, |
| 373 FX_BOOL bCharCode) { | 374 FX_BOOL bCharCode) { |
| 374 ASSERT(m_pCharWidthMap != NULL); | 375 ASSERT(m_pCharWidthMap != NULL); |
| 375 iWidth = m_pCharWidthMap->GetAt(wUnicode, 0); | 376 iWidth = m_pCharWidthMap->GetAt(wUnicode, 0); |
| 376 if (iWidth < 1) { | 377 if (iWidth < 1) { |
| 377 if (!m_pProvider || | 378 if (!m_pProvider || |
| 378 !m_pProvider->GetCharWidth(this, wUnicode, iWidth, bCharCode)) { | 379 !m_pProvider->GetCharWidth(this, wUnicode, iWidth, bCharCode)) { |
| 379 IFGAS_Font* pFont = NULL; | 380 IFGAS_Font* pFont = NULL; |
| 380 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); | 381 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); |
| 381 if (iGlyph != 0xFFFF && pFont != NULL) { | 382 if (iGlyph != 0xFFFF && pFont != NULL) { |
| 382 if (pFont == (IFGAS_Font*)this) { | 383 if (pFont == (IFGAS_Font*)this) { |
| 383 iWidth = m_pFont->GetGlyphWidth(iGlyph); | 384 iWidth = m_pFont->GetGlyphWidth(iGlyph); |
| 384 if (iWidth < 0) { | 385 if (iWidth < 0) { |
| 385 iWidth = -1; | 386 iWidth = -1; |
| 386 } | 387 } |
| 387 } else if (((CFX_GEFont*)pFont) | 388 } else if (((CFGAS_GEFont*)pFont) |
| 388 ->GetCharWidth(wUnicode, iWidth, FALSE, bCharCode)) { | 389 ->GetCharWidth(wUnicode, iWidth, FALSE, bCharCode)) { |
| 389 return TRUE; | 390 return TRUE; |
| 390 } | 391 } |
| 391 } else { | 392 } else { |
| 392 iWidth = -1; | 393 iWidth = -1; |
| 393 } | 394 } |
| 394 } | 395 } |
| 395 m_pCharWidthMap->SetAtGrow(wUnicode, (int16_t)iWidth); | 396 m_pCharWidthMap->SetAtGrow(wUnicode, (int16_t)iWidth); |
| 396 } else if (iWidth == 65535) { | 397 } else if (iWidth == 65535) { |
| 397 iWidth = -1; | 398 iWidth = -1; |
| 398 } | 399 } |
| 399 return iWidth > 0; | 400 return iWidth > 0; |
| 400 } | 401 } |
| 401 FX_BOOL CFX_GEFont::GetCharBBox(FX_WCHAR wUnicode, | 402 FX_BOOL CFGAS_GEFont::GetCharBBox(FX_WCHAR wUnicode, |
| 402 CFX_Rect& bbox, | 403 CFX_Rect& bbox, |
| 403 FX_BOOL bCharCode) { | 404 FX_BOOL bCharCode) { |
| 404 return GetCharBBox(wUnicode, bbox, TRUE, bCharCode); | 405 return GetCharBBox(wUnicode, bbox, TRUE, bCharCode); |
| 405 } | 406 } |
| 406 FX_BOOL CFX_GEFont::GetCharBBox(FX_WCHAR wUnicode, | 407 FX_BOOL CFGAS_GEFont::GetCharBBox(FX_WCHAR wUnicode, |
| 407 CFX_Rect& bbox, | 408 CFX_Rect& bbox, |
| 408 FX_BOOL bRecursive, | 409 FX_BOOL bRecursive, |
| 409 FX_BOOL bCharCode) { | 410 FX_BOOL bCharCode) { |
| 410 ASSERT(m_pRectArray != NULL); | 411 ASSERT(m_pRectArray != NULL); |
| 411 ASSERT(m_pBBoxMap != NULL); | 412 ASSERT(m_pBBoxMap != NULL); |
| 412 void* pRect = NULL; | 413 void* pRect = NULL; |
| 413 if (!m_pBBoxMap->Lookup((void*)(uintptr_t)wUnicode, pRect)) { | 414 if (!m_pBBoxMap->Lookup((void*)(uintptr_t)wUnicode, pRect)) { |
| 414 IFGAS_Font* pFont = NULL; | 415 IFGAS_Font* pFont = NULL; |
| 415 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); | 416 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); |
| 416 if (iGlyph != 0xFFFF && pFont != NULL) { | 417 if (iGlyph != 0xFFFF && pFont != NULL) { |
| 417 if (pFont == (IFGAS_Font*)this) { | 418 if (pFont == (IFGAS_Font*)this) { |
| 418 FX_RECT rtBBox; | 419 FX_RECT rtBBox; |
| 419 if (m_pFont->GetGlyphBBox(iGlyph, rtBBox)) { | 420 if (m_pFont->GetGlyphBBox(iGlyph, rtBBox)) { |
| 420 CFX_Rect rt; | 421 CFX_Rect rt; |
| 421 rt.Set(rtBBox.left, rtBBox.top, rtBBox.Width(), rtBBox.Height()); | 422 rt.Set(rtBBox.left, rtBBox.top, rtBBox.Width(), rtBBox.Height()); |
| 422 int32_t index = m_pRectArray->Add(rt); | 423 int32_t index = m_pRectArray->Add(rt); |
| 423 pRect = m_pRectArray->GetPtrAt(index); | 424 pRect = m_pRectArray->GetPtrAt(index); |
| 424 m_pBBoxMap->SetAt((void*)(uintptr_t)wUnicode, pRect); | 425 m_pBBoxMap->SetAt((void*)(uintptr_t)wUnicode, pRect); |
| 425 } | 426 } |
| 426 } else if (((CFX_GEFont*)pFont) | 427 } else if (((CFGAS_GEFont*)pFont) |
| 427 ->GetCharBBox(wUnicode, bbox, FALSE, bCharCode)) { | 428 ->GetCharBBox(wUnicode, bbox, FALSE, bCharCode)) { |
| 428 return TRUE; | 429 return TRUE; |
| 429 } | 430 } |
| 430 } | 431 } |
| 431 } | 432 } |
| 432 if (!pRect) | 433 if (!pRect) |
| 433 return FALSE; | 434 return FALSE; |
| 434 | 435 |
| 435 bbox = *static_cast<const CFX_Rect*>(pRect); | 436 bbox = *static_cast<const CFX_Rect*>(pRect); |
| 436 return TRUE; | 437 return TRUE; |
| 437 } | 438 } |
| 438 FX_BOOL CFX_GEFont::GetBBox(CFX_Rect& bbox) { | 439 FX_BOOL CFGAS_GEFont::GetBBox(CFX_Rect& bbox) { |
| 439 FX_RECT rt(0, 0, 0, 0); | 440 FX_RECT rt(0, 0, 0, 0); |
| 440 FX_BOOL bRet = m_pFont->GetBBox(rt); | 441 FX_BOOL bRet = m_pFont->GetBBox(rt); |
| 441 if (bRet) { | 442 if (bRet) { |
| 442 bbox.left = rt.left; | 443 bbox.left = rt.left; |
| 443 bbox.width = rt.Width(); | 444 bbox.width = rt.Width(); |
| 444 bbox.top = rt.bottom; | 445 bbox.top = rt.bottom; |
| 445 bbox.height = -rt.Height(); | 446 bbox.height = -rt.Height(); |
| 446 } | 447 } |
| 447 return bRet; | 448 return bRet; |
| 448 } | 449 } |
| 449 int32_t CFX_GEFont::GetItalicAngle() const { | 450 int32_t CFGAS_GEFont::GetItalicAngle() const { |
| 450 if (!m_pFont->GetSubstFont()) { | 451 if (!m_pFont->GetSubstFont()) { |
| 451 return 0; | 452 return 0; |
| 452 } | 453 } |
| 453 return m_pFont->GetSubstFont()->m_ItalicAngle; | 454 return m_pFont->GetSubstFont()->m_ItalicAngle; |
| 454 } | 455 } |
| 455 int32_t CFX_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, FX_BOOL bCharCode) { | 456 int32_t CFGAS_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, FX_BOOL bCharCode) { |
| 456 return GetGlyphIndex(wUnicode, TRUE, NULL, bCharCode); | 457 return GetGlyphIndex(wUnicode, TRUE, NULL, bCharCode); |
| 457 } | 458 } |
| 458 int32_t CFX_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, | 459 int32_t CFGAS_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, |
| 459 FX_BOOL bRecursive, | 460 FX_BOOL bRecursive, |
| 460 IFGAS_Font** ppFont, | 461 IFGAS_Font** ppFont, |
| 461 FX_BOOL bCharCode) { | 462 FX_BOOL bCharCode) { |
| 462 ASSERT(m_pFontEncoding != NULL); | 463 ASSERT(m_pFontEncoding != NULL); |
| 463 int32_t iGlyphIndex = m_pFontEncoding->GlyphFromCharCode(wUnicode); | 464 int32_t iGlyphIndex = m_pFontEncoding->GlyphFromCharCode(wUnicode); |
| 464 if (iGlyphIndex > 0) { | 465 if (iGlyphIndex > 0) { |
| 465 if (ppFont != NULL) { | 466 if (ppFont != NULL) { |
| 466 *ppFont = (IFGAS_Font*)this; | 467 *ppFont = (IFGAS_Font*)this; |
| 467 } | 468 } |
| 468 return iGlyphIndex; | 469 return iGlyphIndex; |
| 469 } | 470 } |
| 470 const FGAS_FONTUSB* pFontUSB = FGAS_GetUnicodeBitField(wUnicode); | 471 const FGAS_FONTUSB* pFontUSB = FGAS_GetUnicodeBitField(wUnicode); |
| 471 if (pFontUSB == NULL) { | 472 if (pFontUSB == NULL) { |
| 472 return 0xFFFF; | 473 return 0xFFFF; |
| 473 } | 474 } |
| 474 uint16_t wBitField = pFontUSB->wBitField; | 475 uint16_t wBitField = pFontUSB->wBitField; |
| 475 if (wBitField >= 128) { | 476 if (wBitField >= 128) { |
| 476 return 0xFFFF; | 477 return 0xFFFF; |
| 477 } | 478 } |
| 478 auto it = m_FontMapper.find(wUnicode); | 479 auto it = m_FontMapper.find(wUnicode); |
| 479 IFGAS_Font* pFont = it != m_FontMapper.end() ? it->second : nullptr; | 480 IFGAS_Font* pFont = it != m_FontMapper.end() ? it->second : nullptr; |
| 480 if (pFont && pFont != this) { | 481 if (pFont && pFont != this) { |
| 481 iGlyphIndex = | 482 iGlyphIndex = |
| 482 ((CFX_GEFont*)pFont)->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); | 483 ((CFGAS_GEFont*)pFont)->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); |
| 483 if (iGlyphIndex != 0xFFFF) { | 484 if (iGlyphIndex != 0xFFFF) { |
| 484 int32_t i = m_SubstFonts.Find(pFont); | 485 int32_t i = m_SubstFonts.Find(pFont); |
| 485 if (i > -1) { | 486 if (i > -1) { |
| 486 iGlyphIndex |= ((i + 1) << 24); | 487 iGlyphIndex |= ((i + 1) << 24); |
| 487 if (ppFont) | 488 if (ppFont) |
| 488 *ppFont = pFont; | 489 *ppFont = pFont; |
| 489 return iGlyphIndex; | 490 return iGlyphIndex; |
| 490 } | 491 } |
| 491 } | 492 } |
| 492 } | 493 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 503 pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), NULL); | 504 pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), NULL); |
| 504 #endif | 505 #endif |
| 505 if (pFont) { | 506 if (pFont) { |
| 506 if (pFont == this) { | 507 if (pFont == this) { |
| 507 pFont->Release(); | 508 pFont->Release(); |
| 508 return 0xFFFF; | 509 return 0xFFFF; |
| 509 } | 510 } |
| 510 m_FontMapper[wUnicode] = pFont; | 511 m_FontMapper[wUnicode] = pFont; |
| 511 int32_t i = m_SubstFonts.GetSize(); | 512 int32_t i = m_SubstFonts.GetSize(); |
| 512 m_SubstFonts.Add(pFont); | 513 m_SubstFonts.Add(pFont); |
| 513 iGlyphIndex = | 514 iGlyphIndex = ((CFGAS_GEFont*)pFont) |
| 514 ((CFX_GEFont*)pFont)->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); | 515 ->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); |
| 515 if (iGlyphIndex != 0xFFFF) { | 516 if (iGlyphIndex != 0xFFFF) { |
| 516 iGlyphIndex |= ((i + 1) << 24); | 517 iGlyphIndex |= ((i + 1) << 24); |
| 517 if (ppFont) | 518 if (ppFont) |
| 518 *ppFont = pFont; | 519 *ppFont = pFont; |
| 519 return iGlyphIndex; | 520 return iGlyphIndex; |
| 520 } | 521 } |
| 521 } | 522 } |
| 522 } | 523 } |
| 523 return 0xFFFF; | 524 return 0xFFFF; |
| 524 } | 525 } |
| 525 int32_t CFX_GEFont::GetAscent() const { | 526 int32_t CFGAS_GEFont::GetAscent() const { |
| 526 return m_pFont->GetAscent(); | 527 return m_pFont->GetAscent(); |
| 527 } | 528 } |
| 528 int32_t CFX_GEFont::GetDescent() const { | 529 int32_t CFGAS_GEFont::GetDescent() const { |
| 529 return m_pFont->GetDescent(); | 530 return m_pFont->GetDescent(); |
| 530 } | 531 } |
| 531 void CFX_GEFont::Reset() { | 532 void CFGAS_GEFont::Reset() { |
| 532 int32_t iCount = m_SubstFonts.GetSize(); | 533 int32_t iCount = m_SubstFonts.GetSize(); |
| 533 for (int32_t i = 0; i < iCount; i++) { | 534 for (int32_t i = 0; i < iCount; i++) { |
| 534 IFGAS_Font* pFont = m_SubstFonts[i]; | 535 IFGAS_Font* pFont = m_SubstFonts[i]; |
| 535 ((CFX_GEFont*)pFont)->Reset(); | 536 ((CFGAS_GEFont*)pFont)->Reset(); |
| 536 } | 537 } |
| 537 if (m_pCharWidthMap != NULL) { | 538 if (m_pCharWidthMap != NULL) { |
| 538 m_pCharWidthMap->RemoveAll(); | 539 m_pCharWidthMap->RemoveAll(); |
| 539 } | 540 } |
| 540 if (m_pBBoxMap != NULL) { | 541 if (m_pBBoxMap != NULL) { |
| 541 m_pBBoxMap->RemoveAll(); | 542 m_pBBoxMap->RemoveAll(); |
| 542 } | 543 } |
| 543 if (m_pRectArray != NULL) { | 544 if (m_pRectArray != NULL) { |
| 544 m_pRectArray->RemoveAll(); | 545 m_pRectArray->RemoveAll(); |
| 545 } | 546 } |
| 546 } | 547 } |
| 547 IFGAS_Font* CFX_GEFont::GetSubstFont(int32_t iGlyphIndex) const { | 548 IFGAS_Font* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { |
| 548 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; | 549 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; |
| 549 return iGlyphIndex == 0 ? const_cast<CFX_GEFont*>(this) | 550 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) |
| 550 : m_SubstFonts[iGlyphIndex - 1]; | 551 : m_SubstFonts[iGlyphIndex - 1]; |
| 551 } | 552 } |
| OLD | NEW |