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

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

Issue 1872463002: Remove IFX_AdditionalFontMgr and IFX_FontMgrDelegate. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 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
« xfa/fgas/font/fgas_font.h ('K') | « xfa/fgas/font/fgas_stdfontmgr.h ('k') | no next file » | 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/fxcrt/include/fx_stream.h" 9 #include "core/fxcrt/include/fx_stream.h"
10 #include "xfa/fgas/crt/fgas_codepage.h" 10 #include "xfa/fgas/crt/fgas_codepage.h"
11 #include "xfa/fgas/font/fgas_fontutils.h" 11 #include "xfa/fgas/font/fgas_fontutils.h"
12 12
13 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 13 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
14 IFX_FontMgr* IFX_FontMgr::Create(FX_LPEnumAllFonts pEnumerator, 14 IFX_FontMgr* IFX_FontMgr::Create(FX_LPEnumAllFonts pEnumerator) {
15 FX_LPMatchFont pMatcher, 15 return new CFX_StdFontMgrImp(pEnumerator);
16 void* pUserData) {
17 return new CFX_StdFontMgrImp(pEnumerator, pMatcher, pUserData);
18 } 16 }
19 CFX_StdFontMgrImp::CFX_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator, 17 CFX_StdFontMgrImp::CFX_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator)
20 FX_LPMatchFont pMatcher, 18 : m_pEnumerator(pEnumerator),
21 void* pUserData)
22 : m_pMatcher(pMatcher),
23 m_pEnumerator(pEnumerator),
24 m_FontFaces(), 19 m_FontFaces(),
25 m_Fonts(), 20 m_Fonts(),
26 m_CPFonts(8), 21 m_CPFonts(8),
27 m_FamilyFonts(16), 22 m_FamilyFonts(16),
28 m_UnicodeFonts(16), 23 m_UnicodeFonts(16),
29 m_BufferFonts(4), 24 m_BufferFonts(4),
30 m_FileFonts(4), 25 m_FileFonts(4),
31 m_StreamFonts(4), 26 m_StreamFonts(4),
32 m_DeriveFonts(4), 27 m_DeriveFonts(4) {
33 m_pUserData(pUserData) {
34 if (m_pEnumerator != NULL) { 28 if (m_pEnumerator != NULL) {
35 m_pEnumerator(m_FontFaces, m_pUserData, NULL, 0xFEFF); 29 m_pEnumerator(m_FontFaces, NULL, 0xFEFF);
36 } 30 }
37 if (m_pMatcher == NULL) {
38 m_pMatcher = FX_DefFontMatcher;
39 }
40 FXSYS_assert(m_pMatcher != NULL);
41 } 31 }
32
42 CFX_StdFontMgrImp::~CFX_StdFontMgrImp() { 33 CFX_StdFontMgrImp::~CFX_StdFontMgrImp() {
43 m_FontFaces.RemoveAll(); 34 m_FontFaces.RemoveAll();
44 m_CPFonts.RemoveAll(); 35 m_CPFonts.RemoveAll();
45 m_FamilyFonts.RemoveAll(); 36 m_FamilyFonts.RemoveAll();
46 m_UnicodeFonts.RemoveAll(); 37 m_UnicodeFonts.RemoveAll();
47 m_BufferFonts.RemoveAll(); 38 m_BufferFonts.RemoveAll();
48 m_FileFonts.RemoveAll(); 39 m_FileFonts.RemoveAll();
49 m_StreamFonts.RemoveAll(); 40 m_StreamFonts.RemoveAll();
50 m_DeriveFonts.RemoveAll(); 41 m_DeriveFonts.RemoveAll();
51 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) { 42 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) {
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 if (iFind > -1) { 286 if (iFind > -1) {
296 m_Fonts.RemoveAt(iFind, 1); 287 m_Fonts.RemoveAt(iFind, 1);
297 } 288 }
298 } 289 }
299 FX_LPCFONTDESCRIPTOR CFX_StdFontMgrImp::FindFont(const FX_WCHAR* pszFontFamily, 290 FX_LPCFONTDESCRIPTOR CFX_StdFontMgrImp::FindFont(const FX_WCHAR* pszFontFamily,
300 uint32_t dwFontStyles, 291 uint32_t dwFontStyles,
301 uint32_t dwMatchFlags, 292 uint32_t dwMatchFlags,
302 uint16_t wCodePage, 293 uint16_t wCodePage,
303 uint32_t dwUSB, 294 uint32_t dwUSB,
304 FX_WCHAR wUnicode) { 295 FX_WCHAR wUnicode) {
305 if (m_pMatcher == NULL) {
306 return NULL;
307 }
308 FX_FONTMATCHPARAMS params; 296 FX_FONTMATCHPARAMS params;
309 FXSYS_memset(&params, 0, sizeof(params)); 297 FXSYS_memset(&params, 0, sizeof(params));
310 params.dwUSB = dwUSB; 298 params.dwUSB = dwUSB;
311 params.wUnicode = wUnicode; 299 params.wUnicode = wUnicode;
312 params.wCodePage = wCodePage; 300 params.wCodePage = wCodePage;
313 params.pwsFamily = pszFontFamily; 301 params.pwsFamily = pszFontFamily;
314 params.dwFontStyles = dwFontStyles; 302 params.dwFontStyles = dwFontStyles;
315 params.dwMatchFlags = dwMatchFlags; 303 params.dwMatchFlags = dwMatchFlags;
316 FX_LPCFONTDESCRIPTOR pDesc = m_pMatcher(&params, m_FontFaces, m_pUserData); 304 FX_LPCFONTDESCRIPTOR pDesc = FX_DefFontMatcher(&params, m_FontFaces);
317 if (pDesc) { 305 if (pDesc) {
318 return pDesc; 306 return pDesc;
319 } 307 }
320 if (pszFontFamily && m_pEnumerator) { 308 if (pszFontFamily && m_pEnumerator) {
321 CFX_FontDescriptors namedFonts; 309 CFX_FontDescriptors namedFonts;
322 m_pEnumerator(namedFonts, m_pUserData, pszFontFamily, wUnicode); 310 m_pEnumerator(namedFonts, pszFontFamily, wUnicode);
323 params.pwsFamily = NULL; 311 params.pwsFamily = NULL;
324 pDesc = m_pMatcher(&params, namedFonts, m_pUserData); 312 pDesc = FX_DefFontMatcher(&params, namedFonts);
325 if (pDesc == NULL) { 313 if (pDesc == NULL) {
326 return NULL; 314 return NULL;
327 } 315 }
328 for (int32_t i = m_FontFaces.GetSize() - 1; i >= 0; i--) { 316 for (int32_t i = m_FontFaces.GetSize() - 1; i >= 0; i--) {
329 FX_LPCFONTDESCRIPTOR pMatch = m_FontFaces.GetPtrAt(i); 317 FX_LPCFONTDESCRIPTOR pMatch = m_FontFaces.GetPtrAt(i);
330 if (*pMatch == *pDesc) { 318 if (*pMatch == *pDesc) {
331 return pMatch; 319 return pMatch;
332 } 320 }
333 } 321 }
334 int index = m_FontFaces.Add(*pDesc); 322 int index = m_FontFaces.Add(*pDesc);
335 return m_FontFaces.GetPtrAt(index); 323 return m_FontFaces.GetPtrAt(index);
336 } 324 }
337 return NULL; 325 return NULL;
338 } 326 }
339 FX_LPCFONTDESCRIPTOR FX_DefFontMatcher(FX_LPFONTMATCHPARAMS pParams, 327 FX_LPCFONTDESCRIPTOR FX_DefFontMatcher(FX_LPFONTMATCHPARAMS pParams,
340 const CFX_FontDescriptors& fonts, 328 const CFX_FontDescriptors& fonts) {
341 void* pUserData) {
342 FX_LPCFONTDESCRIPTOR pBestFont = NULL; 329 FX_LPCFONTDESCRIPTOR pBestFont = NULL;
343 int32_t iBestSimilar = 0; 330 int32_t iBestSimilar = 0;
344 FX_BOOL bMatchStyle = 331 FX_BOOL bMatchStyle =
345 (pParams->dwMatchFlags & FX_FONTMATCHPARA_MacthStyle) > 0; 332 (pParams->dwMatchFlags & FX_FONTMATCHPARA_MacthStyle) > 0;
346 int32_t iCount = fonts.GetSize(); 333 int32_t iCount = fonts.GetSize();
347 for (int32_t i = 0; i < iCount; ++i) { 334 for (int32_t i = 0; i < iCount; ++i) {
348 FX_LPCFONTDESCRIPTOR pFont = fonts.GetPtrAt(i); 335 FX_LPCFONTDESCRIPTOR pFont = fonts.GetPtrAt(i);
349 if ((pFont->dwFontStyles & FX_FONTSTYLE_BoldItalic) == 336 if ((pFont->dwFontStyles & FX_FONTSTYLE_BoldItalic) ==
350 FX_FONTSTYLE_BoldItalic) { 337 FX_FONTSTYLE_BoldItalic) {
351 continue; 338 continue;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 pFont->dwFontStyles = FX_GetGdiFontStyles(lf); 438 pFont->dwFontStyles = FX_GetGdiFontStyles(lf);
452 FXSYS_wcsncpy(pFont->wsFontFace, (const FX_WCHAR*)lf.lfFaceName, 31); 439 FXSYS_wcsncpy(pFont->wsFontFace, (const FX_WCHAR*)lf.lfFaceName, 31);
453 pFont->wsFontFace[31] = 0; 440 pFont->wsFontFace[31] = 0;
454 FXSYS_memcpy(&pFont->FontSignature, &lpntme->ntmFontSig, 441 FXSYS_memcpy(&pFont->FontSignature, &lpntme->ntmFontSig,
455 sizeof(lpntme->ntmFontSig)); 442 sizeof(lpntme->ntmFontSig));
456 ((CFX_FontDescriptors*)lParam)->Add(*pFont); 443 ((CFX_FontDescriptors*)lParam)->Add(*pFont);
457 FX_Free(pFont); 444 FX_Free(pFont);
458 return 1; 445 return 1;
459 } 446 }
460 static void FX_EnumGdiFonts(CFX_FontDescriptors& fonts, 447 static void FX_EnumGdiFonts(CFX_FontDescriptors& fonts,
461 void* pUserData,
462 const FX_WCHAR* pwsFaceName, 448 const FX_WCHAR* pwsFaceName,
463 FX_WCHAR wUnicode) { 449 FX_WCHAR wUnicode) {
464 HDC hDC = ::GetDC(NULL); 450 HDC hDC = ::GetDC(NULL);
465 LOGFONTW lfFind; 451 LOGFONTW lfFind;
466 FXSYS_memset(&lfFind, 0, sizeof(lfFind)); 452 FXSYS_memset(&lfFind, 0, sizeof(lfFind));
467 lfFind.lfCharSet = DEFAULT_CHARSET; 453 lfFind.lfCharSet = DEFAULT_CHARSET;
468 if (pwsFaceName) { 454 if (pwsFaceName) {
469 FXSYS_wcsncpy((FX_WCHAR*)lfFind.lfFaceName, pwsFaceName, 31); 455 FXSYS_wcsncpy((FX_WCHAR*)lfFind.lfFaceName, pwsFaceName, 31);
470 lfFind.lfFaceName[31] = 0; 456 lfFind.lfFaceName[31] = 0;
471 } 457 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 pCurHandle = hpp.pFileHandle; 531 pCurHandle = hpp.pFileHandle;
546 continue; 532 continue;
547 } 533 }
548 bsName = 534 bsName =
549 m_FolderQueue.GetDataPtr(m_FolderQueue.GetSize() - 1)->bsParentPath + 535 m_FolderQueue.GetDataPtr(m_FolderQueue.GetSize() - 1)->bsParentPath +
550 bsFolderSpearator + bsName; 536 bsFolderSpearator + bsName;
551 break; 537 break;
552 } 538 }
553 return bsName; 539 return bsName;
554 } 540 }
555 FX_POSITION CFX_FontSourceEnum_File::GetStartPosition(void* pUserData) { 541 FX_POSITION CFX_FontSourceEnum_File::GetStartPosition() {
556 m_wsNext = GetNextFile().UTF8Decode(); 542 m_wsNext = GetNextFile().UTF8Decode();
557 if (0 == m_wsNext.GetLength()) { 543 if (0 == m_wsNext.GetLength()) {
558 return (FX_POSITION)0; 544 return (FX_POSITION)0;
559 } 545 }
560 return (FX_POSITION)-1; 546 return (FX_POSITION)-1;
561 } 547 }
562 IFX_FileAccess* CFX_FontSourceEnum_File::GetNext(FX_POSITION& pos, 548 IFX_FileAccess* CFX_FontSourceEnum_File::GetNext(FX_POSITION& pos) {
563 void* pUserData) {
564 IFX_FileAccess* pAccess = 549 IFX_FileAccess* pAccess =
565 FX_CreateDefaultFileAccess(m_wsNext.AsWideStringC()); 550 FX_CreateDefaultFileAccess(m_wsNext.AsWideStringC());
566 m_wsNext = GetNextFile().UTF8Decode(); 551 m_wsNext = GetNextFile().UTF8Decode();
567 pos = 0 != m_wsNext.GetLength() ? pAccess : NULL; 552 pos = 0 != m_wsNext.GetLength() ? pAccess : NULL;
568 return (IFX_FileAccess*)pAccess; 553 return (IFX_FileAccess*)pAccess;
569 } 554 }
570 IFX_FontSourceEnum* FX_CreateDefaultFontSourceEnum() { 555 IFX_FontSourceEnum* FX_CreateDefaultFontSourceEnum() {
571 return (IFX_FontSourceEnum*)new CFX_FontSourceEnum_File; 556 return (IFX_FontSourceEnum*)new CFX_FontSourceEnum_File;
572 } 557 }
573 IFX_FontMgr* IFX_FontMgr::Create(IFX_FontSourceEnum* pFontEnum, 558 IFX_FontMgr* IFX_FontMgr::Create(IFX_FontSourceEnum* pFontEnum) {
574 IFX_FontMgrDelegate* pDelegate,
575 void* pUserData) {
576 if (NULL == pFontEnum) { 559 if (NULL == pFontEnum) {
577 return NULL; 560 return NULL;
578 } 561 }
579 CFX_FontMgrImp* pFontMgr = 562 CFX_FontMgrImp* pFontMgr = new CFX_FontMgrImp(pFontEnum);
580 new CFX_FontMgrImp(pFontEnum, pDelegate, pUserData);
581 if (pFontMgr->EnumFonts()) { 563 if (pFontMgr->EnumFonts()) {
582 return pFontMgr; 564 return pFontMgr;
583 } 565 }
584 delete pFontMgr; 566 delete pFontMgr;
585 return NULL; 567 return NULL;
586 } 568 }
587 CFX_FontMgrImp::CFX_FontMgrImp(IFX_FontSourceEnum* pFontEnum, 569 CFX_FontMgrImp::CFX_FontMgrImp(IFX_FontSourceEnum* pFontEnum)
588 IFX_FontMgrDelegate* pDelegate, 570 : m_pFontSource(pFontEnum) {}
589 void* pUserData)
590 : m_pFontSource(pFontEnum),
591 m_pDelegate(pDelegate),
592 m_pUserData(pUserData) {}
593 571
594 FX_BOOL CFX_FontMgrImp::EnumFontsFromFontMapper() { 572 FX_BOOL CFX_FontMgrImp::EnumFontsFromFontMapper() {
595 CFX_FontMapper* pFontMapper = 573 CFX_FontMapper* pFontMapper =
596 CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper(); 574 CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper();
597 if (!pFontMapper) 575 if (!pFontMapper)
598 return FALSE; 576 return FALSE;
599 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); 577 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo();
600 if (!pSystemFontInfo) 578 if (!pSystemFontInfo)
601 return FALSE; 579 return FALSE;
602 pSystemFontInfo->EnumFontList(pFontMapper); 580 pSystemFontInfo->EnumFontList(pFontMapper);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 IFX_Font* pFont; 663 IFX_Font* pFont;
686 IFX_FileRead* pFileRead; 664 IFX_FileRead* pFileRead;
687 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); 665 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead);
688 pFileRead->Release(); 666 pFileRead->Release();
689 } 667 }
690 delete this; 668 delete this;
691 } 669 }
692 IFX_Font* CFX_FontMgrImp::GetDefFontByCodePage(uint16_t wCodePage, 670 IFX_Font* CFX_FontMgrImp::GetDefFontByCodePage(uint16_t wCodePage,
693 uint32_t dwFontStyles, 671 uint32_t dwFontStyles,
694 const FX_WCHAR* pszFontFamily) { 672 const FX_WCHAR* pszFontFamily) {
695 return NULL == m_pDelegate ? NULL : m_pDelegate->GetDefFontByCodePage( 673 return nullptr;
696 this, wCodePage, dwFontStyles,
697 pszFontFamily);
698 } 674 }
699 IFX_Font* CFX_FontMgrImp::GetDefFontByCharset(uint8_t nCharset, 675 IFX_Font* CFX_FontMgrImp::GetDefFontByCharset(uint8_t nCharset,
700 uint32_t dwFontStyles, 676 uint32_t dwFontStyles,
701 const FX_WCHAR* pszFontFamily) { 677 const FX_WCHAR* pszFontFamily) {
702 return NULL == m_pDelegate ? NULL 678 return nullptr;
703 : m_pDelegate->GetDefFontByCharset(
704 this, nCharset, dwFontStyles, pszFontFamily);
705 } 679 }
706 IFX_Font* CFX_FontMgrImp::GetDefFontByUnicode(FX_WCHAR wUnicode, 680 IFX_Font* CFX_FontMgrImp::GetDefFontByUnicode(FX_WCHAR wUnicode,
707 uint32_t dwFontStyles, 681 uint32_t dwFontStyles,
708 const FX_WCHAR* pszFontFamily) { 682 const FX_WCHAR* pszFontFamily) {
709 return NULL == m_pDelegate ? NULL 683 return nullptr;
710 : m_pDelegate->GetDefFontByUnicode(
711 this, wUnicode, dwFontStyles, pszFontFamily);
712 } 684 }
713 IFX_Font* CFX_FontMgrImp::GetDefFontByLanguage(uint16_t wLanguage, 685 IFX_Font* CFX_FontMgrImp::GetDefFontByLanguage(uint16_t wLanguage,
714 uint32_t dwFontStyles, 686 uint32_t dwFontStyles,
715 const FX_WCHAR* pszFontFamily) { 687 const FX_WCHAR* pszFontFamily) {
716 return NULL == m_pDelegate ? NULL : m_pDelegate->GetDefFontByLanguage( 688 return nullptr;
717 this, wLanguage, dwFontStyles,
718 pszFontFamily);
719 } 689 }
720 IFX_Font* CFX_FontMgrImp::GetFontByCodePage(uint16_t wCodePage, 690 IFX_Font* CFX_FontMgrImp::GetFontByCodePage(uint16_t wCodePage,
721 uint32_t dwFontStyles, 691 uint32_t dwFontStyles,
722 const FX_WCHAR* pszFontFamily) { 692 const FX_WCHAR* pszFontFamily) {
723 CFX_ByteString bsHash; 693 CFX_ByteString bsHash;
724 bsHash.Format("%d, %d", wCodePage, dwFontStyles); 694 bsHash.Format("%d, %d", wCodePage, dwFontStyles);
725 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); 695 bsHash += CFX_WideString(pszFontFamily).UTF8Encode();
726 uint32_t dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength()); 696 uint32_t dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength());
727 CFX_ArrayTemplate<IFX_Font*>* pFonts = NULL; 697 CFX_ArrayTemplate<IFX_Font*>* pFonts = NULL;
728 IFX_Font* pFont = NULL; 698 IFX_Font* pFont = NULL;
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 } 1478 }
1509 } 1479 }
1510 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1, 1480 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1,
1511 const CFX_WideString& Name2) { 1481 const CFX_WideString& Name2) {
1512 if (Name1.Find((const FX_WCHAR*)Name2) != -1) { 1482 if (Name1.Find((const FX_WCHAR*)Name2) != -1) {
1513 return 1; 1483 return 1;
1514 } 1484 }
1515 return 0; 1485 return 0;
1516 } 1486 }
1517 #endif 1487 #endif
OLDNEW
« xfa/fgas/font/fgas_font.h ('K') | « xfa/fgas/font/fgas_stdfontmgr.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698