Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: xfa/fgas/font/fgas_stdfontmgr.cpp

Issue 1821043003: Remove FX_WORD in favor of uint16_t. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Use stdint.h directly, bitfield minefield. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fgas/font/fgas_stdfontmgr.h ('k') | xfa/fgas/layout/fgas_linebreak.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_stdfontmgr.h" 7 #include "xfa/fgas/font/fgas_stdfontmgr.h"
8 8
9 #include "core/include/fxcrt/fx_stream.h" 9 #include "core/include/fxcrt/fx_stream.h"
10 #include "xfa/fgas/crt/fgas_codepage.h" 10 #include "xfa/fgas/crt/fgas_codepage.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 m_DeriveFonts.RemoveAll(); 50 m_DeriveFonts.RemoveAll();
51 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) { 51 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) {
52 IFX_Font* pFont = (IFX_Font*)m_Fonts[i]; 52 IFX_Font* pFont = (IFX_Font*)m_Fonts[i];
53 if (pFont != NULL) { 53 if (pFont != NULL) {
54 pFont->Release(); 54 pFont->Release();
55 } 55 }
56 } 56 }
57 m_Fonts.RemoveAll(); 57 m_Fonts.RemoveAll();
58 } 58 }
59 IFX_Font* CFX_StdFontMgrImp::GetDefFontByCodePage( 59 IFX_Font* CFX_StdFontMgrImp::GetDefFontByCodePage(
60 FX_WORD wCodePage, 60 uint16_t wCodePage,
61 FX_DWORD dwFontStyles, 61 FX_DWORD dwFontStyles,
62 const FX_WCHAR* pszFontFamily) { 62 const FX_WCHAR* pszFontFamily) {
63 FX_DWORD dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); 63 FX_DWORD dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles);
64 IFX_Font* pFont = NULL; 64 IFX_Font* pFont = NULL;
65 if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { 65 if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) {
66 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; 66 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL;
67 } 67 }
68 FX_LPCFONTDESCRIPTOR pFD; 68 FX_LPCFONTDESCRIPTOR pFD;
69 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) { 69 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) {
70 if ((pFD = FindFont(NULL, dwFontStyles, TRUE, wCodePage)) == NULL) { 70 if ((pFD = FindFont(NULL, dwFontStyles, TRUE, wCodePage)) == NULL) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 FX_LPCFONTDESCRIPTOR pFD = 108 FX_LPCFONTDESCRIPTOR pFD =
109 FindFont(pszFontFamily, dwFontStyles, FALSE, pRet->wCodePage, 109 FindFont(pszFontFamily, dwFontStyles, FALSE, pRet->wCodePage,
110 pRet->wBitField, wUnicode); 110 pRet->wBitField, wUnicode);
111 if (!pFD && pszFontFamily) { 111 if (!pFD && pszFontFamily) {
112 pFD = FindFont(nullptr, dwFontStyles, FALSE, pRet->wCodePage, 112 pFD = FindFont(nullptr, dwFontStyles, FALSE, pRet->wCodePage,
113 pRet->wBitField, wUnicode); 113 pRet->wBitField, wUnicode);
114 } 114 }
115 if (!pFD) 115 if (!pFD)
116 return nullptr; 116 return nullptr;
117 117
118 FX_WORD wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); 118 uint16_t wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet);
119 const FX_WCHAR* pFontFace = pFD->wsFontFace; 119 const FX_WCHAR* pFontFace = pFD->wsFontFace;
120 pFont = IFX_Font::LoadFont(pFontFace, dwFontStyles, wCodePage, this); 120 pFont = IFX_Font::LoadFont(pFontFace, dwFontStyles, wCodePage, this);
121 if (pFont) { 121 if (pFont) {
122 m_Fonts.Add(pFont); 122 m_Fonts.Add(pFont);
123 m_UnicodeFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); 123 m_UnicodeFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
124 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); 124 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles);
125 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); 125 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
126 dwHash = FGAS_GetFontFamilyHash(pFontFace, dwFontStyles, wCodePage); 126 dwHash = FGAS_GetFontFamilyHash(pFontFace, dwFontStyles, wCodePage);
127 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); 127 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
128 return LoadFont(pFont, dwFontStyles, wCodePage); 128 return LoadFont(pFont, dwFontStyles, wCodePage);
129 } 129 }
130 return nullptr; 130 return nullptr;
131 } 131 }
132 132
133 IFX_Font* CFX_StdFontMgrImp::GetDefFontByLanguage( 133 IFX_Font* CFX_StdFontMgrImp::GetDefFontByLanguage(
134 FX_WORD wLanguage, 134 uint16_t wLanguage,
135 FX_DWORD dwFontStyles, 135 FX_DWORD dwFontStyles,
136 const FX_WCHAR* pszFontFamily) { 136 const FX_WCHAR* pszFontFamily) {
137 return GetDefFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), 137 return GetDefFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage),
138 dwFontStyles, pszFontFamily); 138 dwFontStyles, pszFontFamily);
139 } 139 }
140 IFX_Font* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFontFamily, 140 IFX_Font* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFontFamily,
141 FX_DWORD dwFontStyles, 141 FX_DWORD dwFontStyles,
142 FX_WORD wCodePage) { 142 uint16_t wCodePage) {
143 FX_DWORD dwHash = 143 FX_DWORD dwHash =
144 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, wCodePage); 144 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, wCodePage);
145 IFX_Font* pFont = NULL; 145 IFX_Font* pFont = NULL;
146 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { 146 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) {
147 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; 147 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL;
148 } 148 }
149 FX_LPCFONTDESCRIPTOR pFD = NULL; 149 FX_LPCFONTDESCRIPTOR pFD = NULL;
150 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) { 150 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) {
151 if ((pFD = FindFont(pszFontFamily, dwFontStyles, FALSE, wCodePage)) == 151 if ((pFD = FindFont(pszFontFamily, dwFontStyles, FALSE, wCodePage)) ==
152 NULL) { 152 NULL) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 if (pFont != NULL) { 196 if (pFont != NULL) {
197 m_Fonts.Add(pFont); 197 m_Fonts.Add(pFont);
198 m_FileFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); 198 m_FileFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
199 return pFont->Retain(); 199 return pFont->Retain();
200 } 200 }
201 return NULL; 201 return NULL;
202 } 202 }
203 IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Stream* pFontStream, 203 IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Stream* pFontStream,
204 const FX_WCHAR* pszFontAlias, 204 const FX_WCHAR* pszFontAlias,
205 FX_DWORD dwFontStyles, 205 FX_DWORD dwFontStyles,
206 FX_WORD wCodePage, 206 uint16_t wCodePage,
207 FX_BOOL bSaveStream) { 207 FX_BOOL bSaveStream) {
208 FXSYS_assert(pFontStream != NULL && pFontStream->GetLength() > 0); 208 FXSYS_assert(pFontStream != NULL && pFontStream->GetLength() > 0);
209 IFX_Font* pFont = NULL; 209 IFX_Font* pFont = NULL;
210 if (m_StreamFonts.Lookup((void*)pFontStream, (void*&)pFont)) { 210 if (m_StreamFonts.Lookup((void*)pFontStream, (void*&)pFont)) {
211 if (pFont != NULL) { 211 if (pFont != NULL) {
212 if (pszFontAlias != NULL) { 212 if (pszFontAlias != NULL) {
213 FX_DWORD dwHash = 213 FX_DWORD dwHash =
214 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); 214 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage);
215 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); 215 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
216 } 216 }
217 return LoadFont(pFont, dwFontStyles, wCodePage); 217 return LoadFont(pFont, dwFontStyles, wCodePage);
218 } 218 }
219 } 219 }
220 pFont = IFX_Font::LoadFont(pFontStream, this, bSaveStream); 220 pFont = IFX_Font::LoadFont(pFontStream, this, bSaveStream);
221 if (pFont != NULL) { 221 if (pFont != NULL) {
222 m_Fonts.Add(pFont); 222 m_Fonts.Add(pFont);
223 m_StreamFonts.SetAt((void*)pFontStream, (void*)pFont); 223 m_StreamFonts.SetAt((void*)pFontStream, (void*)pFont);
224 if (pszFontAlias != NULL) { 224 if (pszFontAlias != NULL) {
225 FX_DWORD dwHash = 225 FX_DWORD dwHash =
226 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); 226 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage);
227 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); 227 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
228 } 228 }
229 return LoadFont(pFont, dwFontStyles, wCodePage); 229 return LoadFont(pFont, dwFontStyles, wCodePage);
230 } 230 }
231 return NULL; 231 return NULL;
232 } 232 }
233 IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Font* pSrcFont, 233 IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Font* pSrcFont,
234 FX_DWORD dwFontStyles, 234 FX_DWORD dwFontStyles,
235 FX_WORD wCodePage) { 235 uint16_t wCodePage) {
236 FXSYS_assert(pSrcFont != NULL); 236 FXSYS_assert(pSrcFont != NULL);
237 if (pSrcFont->GetFontStyles() == dwFontStyles) { 237 if (pSrcFont->GetFontStyles() == dwFontStyles) {
238 return pSrcFont->Retain(); 238 return pSrcFont->Retain();
239 } 239 }
240 void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles, 240 void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles,
241 (void*)(uintptr_t)wCodePage}; 241 (void*)(uintptr_t)wCodePage};
242 FX_DWORD dwHash = 242 FX_DWORD dwHash =
243 FX_HashCode_String_GetA((const FX_CHAR*)buffer, 3 * sizeof(void*)); 243 FX_HashCode_String_GetA((const FX_CHAR*)buffer, 3 * sizeof(void*));
244 IFX_Font* pFont = NULL; 244 IFX_Font* pFont = NULL;
245 if (m_DeriveFonts.GetCount() > 0) { 245 if (m_DeriveFonts.GetCount() > 0) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 RemoveFont(m_StreamFonts, pFont); 292 RemoveFont(m_StreamFonts, pFont);
293 RemoveFont(m_DeriveFonts, pFont); 293 RemoveFont(m_DeriveFonts, pFont);
294 int32_t iFind = m_Fonts.Find(pFont); 294 int32_t iFind = m_Fonts.Find(pFont);
295 if (iFind > -1) { 295 if (iFind > -1) {
296 m_Fonts.RemoveAt(iFind, 1); 296 m_Fonts.RemoveAt(iFind, 1);
297 } 297 }
298 } 298 }
299 FX_LPCFONTDESCRIPTOR CFX_StdFontMgrImp::FindFont(const FX_WCHAR* pszFontFamily, 299 FX_LPCFONTDESCRIPTOR CFX_StdFontMgrImp::FindFont(const FX_WCHAR* pszFontFamily,
300 FX_DWORD dwFontStyles, 300 FX_DWORD dwFontStyles,
301 FX_DWORD dwMatchFlags, 301 FX_DWORD dwMatchFlags,
302 FX_WORD wCodePage, 302 uint16_t wCodePage,
303 FX_DWORD dwUSB, 303 FX_DWORD dwUSB,
304 FX_WCHAR wUnicode) { 304 FX_WCHAR wUnicode) {
305 if (m_pMatcher == NULL) { 305 if (m_pMatcher == NULL) {
306 return NULL; 306 return NULL;
307 } 307 }
308 FX_FONTMATCHPARAMS params; 308 FX_FONTMATCHPARAMS params;
309 FXSYS_memset(&params, 0, sizeof(params)); 309 FXSYS_memset(&params, 0, sizeof(params));
310 params.dwUSB = dwUSB; 310 params.dwUSB = dwUSB;
311 params.wUnicode = wUnicode; 311 params.wUnicode = wUnicode;
312 params.wCodePage = wCodePage; 312 params.wCodePage = wCodePage;
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 } 681 }
682 pos = m_IFXFont2FileRead.GetStartPosition(); 682 pos = m_IFXFont2FileRead.GetStartPosition();
683 while (pos) { 683 while (pos) {
684 IFX_Font* pFont; 684 IFX_Font* pFont;
685 IFX_FileRead* pFileRead; 685 IFX_FileRead* pFileRead;
686 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); 686 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead);
687 pFileRead->Release(); 687 pFileRead->Release();
688 } 688 }
689 delete this; 689 delete this;
690 } 690 }
691 IFX_Font* CFX_FontMgrImp::GetDefFontByCodePage(FX_WORD wCodePage, 691 IFX_Font* CFX_FontMgrImp::GetDefFontByCodePage(uint16_t wCodePage,
692 FX_DWORD dwFontStyles, 692 FX_DWORD dwFontStyles,
693 const FX_WCHAR* pszFontFamily) { 693 const FX_WCHAR* pszFontFamily) {
694 return NULL == m_pDelegate ? NULL : m_pDelegate->GetDefFontByCodePage( 694 return NULL == m_pDelegate ? NULL : m_pDelegate->GetDefFontByCodePage(
695 this, wCodePage, dwFontStyles, 695 this, wCodePage, dwFontStyles,
696 pszFontFamily); 696 pszFontFamily);
697 } 697 }
698 IFX_Font* CFX_FontMgrImp::GetDefFontByCharset(uint8_t nCharset, 698 IFX_Font* CFX_FontMgrImp::GetDefFontByCharset(uint8_t nCharset,
699 FX_DWORD dwFontStyles, 699 FX_DWORD dwFontStyles,
700 const FX_WCHAR* pszFontFamily) { 700 const FX_WCHAR* pszFontFamily) {
701 return NULL == m_pDelegate ? NULL 701 return NULL == m_pDelegate ? NULL
702 : m_pDelegate->GetDefFontByCharset( 702 : m_pDelegate->GetDefFontByCharset(
703 this, nCharset, dwFontStyles, pszFontFamily); 703 this, nCharset, dwFontStyles, pszFontFamily);
704 } 704 }
705 IFX_Font* CFX_FontMgrImp::GetDefFontByUnicode(FX_WCHAR wUnicode, 705 IFX_Font* CFX_FontMgrImp::GetDefFontByUnicode(FX_WCHAR wUnicode,
706 FX_DWORD dwFontStyles, 706 FX_DWORD dwFontStyles,
707 const FX_WCHAR* pszFontFamily) { 707 const FX_WCHAR* pszFontFamily) {
708 return NULL == m_pDelegate ? NULL 708 return NULL == m_pDelegate ? NULL
709 : m_pDelegate->GetDefFontByUnicode( 709 : m_pDelegate->GetDefFontByUnicode(
710 this, wUnicode, dwFontStyles, pszFontFamily); 710 this, wUnicode, dwFontStyles, pszFontFamily);
711 } 711 }
712 IFX_Font* CFX_FontMgrImp::GetDefFontByLanguage(FX_WORD wLanguage, 712 IFX_Font* CFX_FontMgrImp::GetDefFontByLanguage(uint16_t wLanguage,
713 FX_DWORD dwFontStyles, 713 FX_DWORD dwFontStyles,
714 const FX_WCHAR* pszFontFamily) { 714 const FX_WCHAR* pszFontFamily) {
715 return NULL == m_pDelegate ? NULL : m_pDelegate->GetDefFontByLanguage( 715 return NULL == m_pDelegate ? NULL : m_pDelegate->GetDefFontByLanguage(
716 this, wLanguage, dwFontStyles, 716 this, wLanguage, dwFontStyles,
717 pszFontFamily); 717 pszFontFamily);
718 } 718 }
719 IFX_Font* CFX_FontMgrImp::GetFontByCodePage(FX_WORD wCodePage, 719 IFX_Font* CFX_FontMgrImp::GetFontByCodePage(uint16_t wCodePage,
720 FX_DWORD dwFontStyles, 720 FX_DWORD dwFontStyles,
721 const FX_WCHAR* pszFontFamily) { 721 const FX_WCHAR* pszFontFamily) {
722 CFX_ByteString bsHash; 722 CFX_ByteString bsHash;
723 bsHash.Format("%d, %d", wCodePage, dwFontStyles); 723 bsHash.Format("%d, %d", wCodePage, dwFontStyles);
724 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); 724 bsHash += CFX_WideString(pszFontFamily).UTF8Encode();
725 FX_DWORD dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength()); 725 FX_DWORD dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength());
726 CFX_ArrayTemplate<IFX_Font*>* pFonts = NULL; 726 CFX_ArrayTemplate<IFX_Font*>* pFonts = NULL;
727 IFX_Font* pFont = NULL; 727 IFX_Font* pFont = NULL;
728 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { 728 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) {
729 if (NULL == pFonts) { 729 if (NULL == pFonts) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 return GetFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, 763 return GetFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles,
764 pszFontFamily); 764 pszFontFamily);
765 } 765 }
766 IFX_Font* CFX_FontMgrImp::GetFontByUnicode(FX_WCHAR wUnicode, 766 IFX_Font* CFX_FontMgrImp::GetFontByUnicode(FX_WCHAR wUnicode,
767 FX_DWORD dwFontStyles, 767 FX_DWORD dwFontStyles,
768 const FX_WCHAR* pszFontFamily) { 768 const FX_WCHAR* pszFontFamily) {
769 IFX_Font* pFont = nullptr; 769 IFX_Font* pFont = nullptr;
770 if (m_FailedUnicodes2NULL.Lookup(wUnicode, pFont)) 770 if (m_FailedUnicodes2NULL.Lookup(wUnicode, pFont))
771 return nullptr; 771 return nullptr;
772 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wUnicode); 772 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wUnicode);
773 FX_WORD wCodePage = x ? x->wCodePage : 0xFFFF; 773 uint16_t wCodePage = x ? x->wCodePage : 0xFFFF;
774 FX_WORD wBitField = x ? x->wBitField : 0x03E7; 774 uint16_t wBitField = x ? x->wBitField : 0x03E7;
775 CFX_ByteString bsHash; 775 CFX_ByteString bsHash;
776 if (wCodePage == 0xFFFF) 776 if (wCodePage == 0xFFFF)
777 bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles); 777 bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles);
778 else 778 else
779 bsHash.Format("%d, %d", wCodePage, dwFontStyles); 779 bsHash.Format("%d, %d", wCodePage, dwFontStyles);
780 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); 780 bsHash += CFX_WideString(pszFontFamily).UTF8Encode();
781 FX_DWORD dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength()); 781 FX_DWORD dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength());
782 CFX_ArrayTemplate<IFX_Font*>* pFonts = nullptr; 782 CFX_ArrayTemplate<IFX_Font*>* pFonts = nullptr;
783 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { 783 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) {
784 if (!pFonts) 784 if (!pFonts)
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 FXFT_CharMap charmap = FXFT_Get_Face_Charmap(pFace); 844 FXFT_CharMap charmap = FXFT_Get_Face_Charmap(pFace);
845 if (0 != FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE)) { 845 if (0 != FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE)) {
846 return FALSE; 846 return FALSE;
847 } 847 }
848 if (0 == FXFT_Get_Char_Index(pFace, wcUnicode)) { 848 if (0 == FXFT_Get_Char_Index(pFace, wcUnicode)) {
849 FXFT_Set_Charmap(pFace, charmap); 849 FXFT_Set_Charmap(pFace, charmap);
850 return FALSE; 850 return FALSE;
851 } 851 }
852 return TRUE; 852 return TRUE;
853 } 853 }
854 IFX_Font* CFX_FontMgrImp::GetFontByLanguage(FX_WORD wLanguage, 854 IFX_Font* CFX_FontMgrImp::GetFontByLanguage(uint16_t wLanguage,
855 FX_DWORD dwFontStyles, 855 FX_DWORD dwFontStyles,
856 const FX_WCHAR* pszFontFamily) { 856 const FX_WCHAR* pszFontFamily) {
857 return GetFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), dwFontStyles, 857 return GetFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), dwFontStyles,
858 pszFontFamily); 858 pszFontFamily);
859 } 859 }
860 IFX_Font* CFX_FontMgrImp::LoadFont(const uint8_t* pBuffer, 860 IFX_Font* CFX_FontMgrImp::LoadFont(const uint8_t* pBuffer,
861 int32_t iLength, 861 int32_t iLength,
862 int32_t iFaceIndex, 862 int32_t iFaceIndex,
863 int32_t* pFaceCount) { 863 int32_t* pFaceCount) {
864 void* Hash[2] = {(void*)(uintptr_t)pBuffer, (void*)(uintptr_t)iLength}; 864 void* Hash[2] = {(void*)(uintptr_t)pBuffer, (void*)(uintptr_t)iLength};
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 if (!pSystemFontInfo) 1065 if (!pSystemFontInfo)
1066 return nullptr; 1066 return nullptr;
1067 pSystemFontInfo->EnumFontList(pFontMapper); 1067 pSystemFontInfo->EnumFontList(pFontMapper);
1068 for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) { 1068 for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) {
1069 if (pFontMapper->GetFaceName(i) == bsFaceName) 1069 if (pFontMapper->GetFaceName(i) == bsFaceName)
1070 return CreateFontStream(pFontMapper, pSystemFontInfo, i); 1070 return CreateFontStream(pFontMapper, pSystemFontInfo, i);
1071 } 1071 }
1072 return nullptr; 1072 return nullptr;
1073 } 1073 }
1074 int32_t CFX_FontMgrImp::MatchFonts(CFX_FontDescriptorInfos& MatchedFonts, 1074 int32_t CFX_FontMgrImp::MatchFonts(CFX_FontDescriptorInfos& MatchedFonts,
1075 FX_WORD wCodePage, 1075 uint16_t wCodePage,
1076 FX_DWORD dwFontStyles, 1076 FX_DWORD dwFontStyles,
1077 const CFX_WideString& FontName, 1077 const CFX_WideString& FontName,
1078 FX_WCHAR wcUnicode) { 1078 FX_WCHAR wcUnicode) {
1079 MatchedFonts.RemoveAll(); 1079 MatchedFonts.RemoveAll();
1080 CFX_WideString wsNormalizedFontName = FontName; 1080 CFX_WideString wsNormalizedFontName = FontName;
1081 static const int32_t nMax = 0xffff; 1081 static const int32_t nMax = 0xffff;
1082 CFX_FontDescriptor* pFont = NULL; 1082 CFX_FontDescriptor* pFont = NULL;
1083 int32_t nCount = m_InstalledFonts.GetSize(); 1083 int32_t nCount = m_InstalledFonts.GetSize();
1084 for (int32_t i = 0; i < nCount; i++) { 1084 for (int32_t i = 0; i < nCount; i++) {
1085 pFont = m_InstalledFonts[i]; 1085 pFont = m_InstalledFonts[i];
(...skipping 11 matching lines...) Expand all
1097 } 1097 }
1098 } 1098 }
1099 if (MatchedFonts.GetSize() == 0) { 1099 if (MatchedFonts.GetSize() == 0) {
1100 return 0; 1100 return 0;
1101 } 1101 }
1102 CFX_SSortTemplate<FX_FontDescriptorInfo> ssort; 1102 CFX_SSortTemplate<FX_FontDescriptorInfo> ssort;
1103 ssort.ShellSort(MatchedFonts.GetData(), MatchedFonts.GetSize()); 1103 ssort.ShellSort(MatchedFonts.GetData(), MatchedFonts.GetSize());
1104 return MatchedFonts.GetSize(); 1104 return MatchedFonts.GetSize();
1105 } 1105 }
1106 struct FX_BitCodePage { 1106 struct FX_BitCodePage {
1107 FX_WORD wBit; 1107 uint16_t wBit;
1108 FX_WORD wCodePage; 1108 uint16_t wCodePage;
1109 }; 1109 };
1110 static const FX_BitCodePage g_Bit2CodePage[] = { 1110 static const FX_BitCodePage g_Bit2CodePage[] = {
1111 {0, 1252}, {1, 1250}, {2, 1251}, {3, 1253}, {4, 1254}, {5, 1255}, 1111 {0, 1252}, {1, 1250}, {2, 1251}, {3, 1253}, {4, 1254}, {5, 1255},
1112 {6, 1256}, {7, 1257}, {8, 1258}, {9, 0}, {10, 0}, {11, 0}, 1112 {6, 1256}, {7, 1257}, {8, 1258}, {9, 0}, {10, 0}, {11, 0},
1113 {12, 0}, {13, 0}, {14, 0}, {15, 0}, {16, 874}, {17, 932}, 1113 {12, 0}, {13, 0}, {14, 0}, {15, 0}, {16, 874}, {17, 932},
1114 {18, 936}, {19, 949}, {20, 950}, {21, 1361}, {22, 0}, {23, 0}, 1114 {18, 936}, {19, 949}, {20, 950}, {21, 1361}, {22, 0}, {23, 0},
1115 {24, 0}, {25, 0}, {26, 0}, {27, 0}, {28, 0}, {29, 0}, 1115 {24, 0}, {25, 0}, {26, 0}, {27, 0}, {28, 0}, {29, 0},
1116 {30, 0}, {31, 0}, {32, 0}, {33, 0}, {34, 0}, {35, 0}, 1116 {30, 0}, {31, 0}, {32, 0}, {33, 0}, {34, 0}, {35, 0},
1117 {36, 0}, {37, 0}, {38, 0}, {39, 0}, {40, 0}, {41, 0}, 1117 {36, 0}, {37, 0}, {38, 0}, {39, 0}, {40, 0}, {41, 0},
1118 {42, 0}, {43, 0}, {44, 0}, {45, 0}, {46, 0}, {47, 0}, 1118 {42, 0}, {43, 0}, {44, 0}, {45, 0}, {46, 0}, {47, 0},
1119 {48, 869}, {49, 866}, {50, 865}, {51, 864}, {52, 863}, {53, 862}, 1119 {48, 869}, {49, 866}, {50, 865}, {51, 864}, {52, 863}, {53, 862},
1120 {54, 861}, {55, 860}, {56, 857}, {57, 855}, {58, 852}, {59, 775}, 1120 {54, 861}, {55, 860}, {56, 857}, {57, 855}, {58, 852}, {59, 775},
1121 {60, 737}, {61, 708}, {62, 850}, {63, 437}, 1121 {60, 737}, {61, 708}, {62, 850}, {63, 437},
1122 }; 1122 };
1123 1123
1124 FX_WORD FX_GetCodePageBit(FX_WORD wCodePage) { 1124 uint16_t FX_GetCodePageBit(uint16_t wCodePage) {
1125 for (size_t i = 0; i < FX_ArraySize(g_Bit2CodePage); ++i) { 1125 for (size_t i = 0; i < FX_ArraySize(g_Bit2CodePage); ++i) {
1126 if (g_Bit2CodePage[i].wCodePage == wCodePage) 1126 if (g_Bit2CodePage[i].wCodePage == wCodePage)
1127 return g_Bit2CodePage[i].wBit; 1127 return g_Bit2CodePage[i].wBit;
1128 } 1128 }
1129 return (FX_WORD)-1; 1129 return (uint16_t)-1;
1130 } 1130 }
1131 1131
1132 FX_WORD FX_GetUnicodeBit(FX_WCHAR wcUnicode) { 1132 uint16_t FX_GetUnicodeBit(FX_WCHAR wcUnicode) {
1133 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wcUnicode); 1133 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wcUnicode);
1134 return x ? x->wBitField : 999; 1134 return x ? x->wBitField : 999;
1135 } 1135 }
1136 1136
1137 int32_t CFX_FontMgrImp::CalcPenalty(CFX_FontDescriptor* pInstalled, 1137 int32_t CFX_FontMgrImp::CalcPenalty(CFX_FontDescriptor* pInstalled,
1138 FX_WORD wCodePage, 1138 uint16_t wCodePage,
1139 FX_DWORD dwFontStyles, 1139 FX_DWORD dwFontStyles,
1140 const CFX_WideString& FontName, 1140 const CFX_WideString& FontName,
1141 FX_WCHAR wcUnicode) { 1141 FX_WCHAR wcUnicode) {
1142 int32_t nPenalty = 30000; 1142 int32_t nPenalty = 30000;
1143 if (0 != FontName.GetLength()) { 1143 if (0 != FontName.GetLength()) {
1144 if (FontName != pInstalled->m_wsFaceName) { 1144 if (FontName != pInstalled->m_wsFaceName) {
1145 int32_t i; 1145 int32_t i;
1146 for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) { 1146 for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) {
1147 if (pInstalled->m_wsFamilyNames[i] == FontName) { 1147 if (pInstalled->m_wsFamilyNames[i] == FontName) {
1148 break; 1148 break;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 } 1185 }
1186 if (dwStyleMask & FX_FONTSTYLE_Serif) { 1186 if (dwStyleMask & FX_FONTSTYLE_Serif) {
1187 nPenalty += 500; 1187 nPenalty += 500;
1188 } 1188 }
1189 if (dwStyleMask & FX_FONTSTYLE_Symbolic) { 1189 if (dwStyleMask & FX_FONTSTYLE_Symbolic) {
1190 nPenalty += 0xFFFF; 1190 nPenalty += 0xFFFF;
1191 } 1191 }
1192 if (nPenalty >= 0xFFFF) { 1192 if (nPenalty >= 0xFFFF) {
1193 return 0xFFFF; 1193 return 0xFFFF;
1194 } 1194 }
1195 FX_WORD wBit = 1195 uint16_t wBit =
1196 ((0 == wCodePage || 0xFFFF == wCodePage) ? (FX_WORD)-1 1196 ((0 == wCodePage || 0xFFFF == wCodePage) ? (uint16_t)-1
1197 : FX_GetCodePageBit(wCodePage)); 1197 : FX_GetCodePageBit(wCodePage));
1198 if (wBit != (FX_WORD)-1) { 1198 if (wBit != (uint16_t)-1) {
1199 FXSYS_assert(wBit < 64); 1199 FXSYS_assert(wBit < 64);
1200 if (0 == (pInstalled->m_dwCsb[wBit / 32] & (1 << (wBit % 32)))) { 1200 if (0 == (pInstalled->m_dwCsb[wBit / 32] & (1 << (wBit % 32)))) {
1201 nPenalty += 0xFFFF; 1201 nPenalty += 0xFFFF;
1202 } else { 1202 } else {
1203 nPenalty -= 60000; 1203 nPenalty -= 60000;
1204 } 1204 }
1205 } 1205 }
1206 wBit = 1206 wBit =
1207 ((0 == wcUnicode || 0xFFFE == wcUnicode) ? (FX_WORD)999 1207 ((0 == wcUnicode || 0xFFFE == wcUnicode) ? (uint16_t)999
1208 : FX_GetUnicodeBit(wcUnicode)); 1208 : FX_GetUnicodeBit(wcUnicode));
1209 if (wBit != (FX_WORD)999) { 1209 if (wBit != (uint16_t)999) {
1210 FXSYS_assert(wBit < 128); 1210 FXSYS_assert(wBit < 128);
1211 if (0 == (pInstalled->m_dwUsb[wBit / 32] & (1 << (wBit % 32)))) { 1211 if (0 == (pInstalled->m_dwUsb[wBit / 32] & (1 << (wBit % 32)))) {
1212 nPenalty += 0xFFFF; 1212 nPenalty += 0xFFFF;
1213 } else { 1213 } else {
1214 nPenalty -= 60000; 1214 nPenalty -= 60000;
1215 } 1215 }
1216 } 1216 }
1217 return nPenalty; 1217 return nPenalty;
1218 } 1218 }
1219 void CFX_FontMgrImp::ClearFontCache() { 1219 void CFX_FontMgrImp::ClearFontCache() {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 CFX_FontDescriptors& Fonts, 1283 CFX_FontDescriptors& Fonts,
1284 const CFX_WideString* pFaceName, 1284 const CFX_WideString* pFaceName,
1285 IFX_FileAccess* pFontAccess) { 1285 IFX_FileAccess* pFontAccess) {
1286 if (0 == (pFace->face_flags & FT_FACE_FLAG_SCALABLE)) { 1286 if (0 == (pFace->face_flags & FT_FACE_FLAG_SCALABLE)) {
1287 return; 1287 return;
1288 } 1288 }
1289 CFX_FontDescriptor* pFont = new CFX_FontDescriptor; 1289 CFX_FontDescriptor* pFont = new CFX_FontDescriptor;
1290 pFont->m_dwFontStyles |= FXFT_Is_Face_Bold(pFace) ? FX_FONTSTYLE_Bold : 0; 1290 pFont->m_dwFontStyles |= FXFT_Is_Face_Bold(pFace) ? FX_FONTSTYLE_Bold : 0;
1291 pFont->m_dwFontStyles |= FXFT_Is_Face_Italic(pFace) ? FX_FONTSTYLE_Italic : 0; 1291 pFont->m_dwFontStyles |= FXFT_Is_Face_Italic(pFace) ? FX_FONTSTYLE_Italic : 0;
1292 pFont->m_dwFontStyles |= GetFlags(pFace); 1292 pFont->m_dwFontStyles |= GetFlags(pFace);
1293 CFX_WordArray Charsets; 1293 CFX_ArrayTemplate<uint16_t> Charsets;
1294 GetCharsets(pFace, Charsets); 1294 GetCharsets(pFace, Charsets);
1295 GetUSBCSB(pFace, pFont->m_dwUsb, pFont->m_dwCsb); 1295 GetUSBCSB(pFace, pFont->m_dwUsb, pFont->m_dwCsb);
1296 unsigned long nLength = 0; 1296 unsigned long nLength = 0;
1297 FT_ULong dwTag; 1297 FT_ULong dwTag;
1298 uint8_t* pTable = NULL; 1298 uint8_t* pTable = NULL;
1299 FT_ENC_TAG(dwTag, 'n', 'a', 'm', 'e'); 1299 FT_ENC_TAG(dwTag, 'n', 'a', 'm', 'e');
1300 unsigned int error = FXFT_Load_Sfnt_Table(pFace, dwTag, 0, NULL, &nLength); 1300 unsigned int error = FXFT_Load_Sfnt_Table(pFace, dwTag, 0, NULL, &nLength);
1301 if (0 == error && 0 != nLength) { 1301 if (0 == error && 0 != nLength) {
1302 pTable = FX_Alloc(uint8_t, nLength); 1302 pTable = FX_Alloc(uint8_t, nLength);
1303 error = FXFT_Load_Sfnt_Table(pFace, dwTag, 0, pTable, NULL); 1303 error = FXFT_Load_Sfnt_Table(pFace, dwTag, 0, pTable, NULL);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 wsFamily += wcTemp; 1397 wsFamily += wcTemp;
1398 } 1398 }
1399 Names.Add(wsFamily); 1399 Names.Add(wsFamily);
1400 } 1400 }
1401 } 1401 }
1402 } 1402 }
1403 #undef GetUInt8 1403 #undef GetUInt8
1404 #undef GetUInt16 1404 #undef GetUInt16
1405 #undef GetUInt32 1405 #undef GetUInt32
1406 struct FX_BIT2CHARSET { 1406 struct FX_BIT2CHARSET {
1407 FX_WORD wBit; 1407 uint16_t wBit;
1408 FX_WORD wCharset; 1408 uint16_t wCharset;
1409 }; 1409 };
1410 FX_BIT2CHARSET g_FX_Bit2Charset1[16] = { 1410 FX_BIT2CHARSET g_FX_Bit2Charset1[16] = {
1411 {1 << 0, FX_CHARSET_ANSI}, 1411 {1 << 0, FX_CHARSET_ANSI},
1412 {1 << 1, FX_CHARSET_MSWin_EasterEuropean}, 1412 {1 << 1, FX_CHARSET_MSWin_EasterEuropean},
1413 {1 << 2, FX_CHARSET_MSWin_Cyrillic}, 1413 {1 << 2, FX_CHARSET_MSWin_Cyrillic},
1414 {1 << 3, FX_CHARSET_MSWin_Greek}, 1414 {1 << 3, FX_CHARSET_MSWin_Greek},
1415 {1 << 4, FX_CHARSET_MSWin_Turkish}, 1415 {1 << 4, FX_CHARSET_MSWin_Turkish},
1416 {1 << 5, FX_CHARSET_MSWin_Hebrew}, 1416 {1 << 5, FX_CHARSET_MSWin_Hebrew},
1417 {1 << 6, FX_CHARSET_MSWin_Arabic}, 1417 {1 << 6, FX_CHARSET_MSWin_Arabic},
1418 {1 << 7, FX_CHARSET_MSWin_Baltic}, 1418 {1 << 7, FX_CHARSET_MSWin_Baltic},
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 {1 << 10, FX_CHARSET_Default}, {1 << 11, FX_CHARSET_Default}, 1462 {1 << 10, FX_CHARSET_Default}, {1 << 11, FX_CHARSET_Default},
1463 {1 << 12, FX_CHARSET_Default}, {1 << 13, FX_CHARSET_Default}, 1463 {1 << 12, FX_CHARSET_Default}, {1 << 13, FX_CHARSET_Default},
1464 {1 << 14, FX_CHARSET_Default}, {1 << 15, FX_CHARSET_US}, 1464 {1 << 14, FX_CHARSET_Default}, {1 << 15, FX_CHARSET_US},
1465 }; 1465 };
1466 #define CODEPAGERANGE_IMPLEMENT(n) \ 1466 #define CODEPAGERANGE_IMPLEMENT(n) \
1467 for (int32_t i = 0; i < 16; i++) { \ 1467 for (int32_t i = 0; i < 16; i++) { \
1468 if ((a##n & g_FX_Bit2Charset##n[i].wBit) != 0) { \ 1468 if ((a##n & g_FX_Bit2Charset##n[i].wBit) != 0) { \
1469 Charsets.Add(g_FX_Bit2Charset##n[i].wCharset); \ 1469 Charsets.Add(g_FX_Bit2Charset##n[i].wCharset); \
1470 } \ 1470 } \
1471 } 1471 }
1472 void CFX_FontMgrImp::GetCharsets(FXFT_Face pFace, CFX_WordArray& Charsets) { 1472 void CFX_FontMgrImp::GetCharsets(FXFT_Face pFace,
1473 CFX_ArrayTemplate<uint16_t>& Charsets) {
1473 Charsets.RemoveAll(); 1474 Charsets.RemoveAll();
1474 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); 1475 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2);
1475 if (NULL != pOS2) { 1476 if (NULL != pOS2) {
1476 FX_WORD a1, a2, a3, a4; 1477 uint16_t a1, a2, a3, a4;
1477 a1 = pOS2->ulCodePageRange1 & 0x0000ffff; 1478 a1 = pOS2->ulCodePageRange1 & 0x0000ffff;
1478 CODEPAGERANGE_IMPLEMENT(1); 1479 CODEPAGERANGE_IMPLEMENT(1);
1479 a2 = (pOS2->ulCodePageRange1 >> 16) & 0x0000ffff; 1480 a2 = (pOS2->ulCodePageRange1 >> 16) & 0x0000ffff;
1480 CODEPAGERANGE_IMPLEMENT(2); 1481 CODEPAGERANGE_IMPLEMENT(2);
1481 a3 = pOS2->ulCodePageRange2 & 0x0000ffff; 1482 a3 = pOS2->ulCodePageRange2 & 0x0000ffff;
1482 CODEPAGERANGE_IMPLEMENT(3); 1483 CODEPAGERANGE_IMPLEMENT(3);
1483 a4 = (pOS2->ulCodePageRange2 >> 16) & 0x0000ffff; 1484 a4 = (pOS2->ulCodePageRange2 >> 16) & 0x0000ffff;
1484 CODEPAGERANGE_IMPLEMENT(4); 1485 CODEPAGERANGE_IMPLEMENT(4);
1485 } else { 1486 } else {
1486 Charsets.Add(FX_CHARSET_Default); 1487 Charsets.Add(FX_CHARSET_Default);
(...skipping 19 matching lines...) Expand all
1506 } 1507 }
1507 } 1508 }
1508 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1, 1509 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1,
1509 const CFX_WideString& Name2) { 1510 const CFX_WideString& Name2) {
1510 if (Name1.Find((const FX_WCHAR*)Name2) != -1) { 1511 if (Name1.Find((const FX_WCHAR*)Name2) != -1) {
1511 return 1; 1512 return 1;
1512 } 1513 }
1513 return 0; 1514 return 0;
1514 } 1515 }
1515 #endif 1516 #endif
OLDNEW
« no previous file with comments | « xfa/fgas/font/fgas_stdfontmgr.h ('k') | xfa/fgas/layout/fgas_linebreak.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698