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

Side by Side Diff: src/ports/SkFontMgr_win_dw.cpp

Issue 1107283003: Remove system call in DW for default font. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 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
« gm/fontmgr.cpp ('K') | « gm/fontmgr.cpp ('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 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkDWrite.h" 8 #include "SkDWrite.h"
9 #include "SkDWriteFontFileStream.h" 9 #include "SkDWriteFontFileStream.h"
10 #include "SkFontMgr.h" 10 #include "SkFontMgr.h"
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 622
623 SkTypeface* FallbackTypeface() { return fResolvedTypeface; } 623 SkTypeface* FallbackTypeface() { return fResolvedTypeface; }
624 624
625 protected: 625 protected:
626 ULONG fRefCount; 626 ULONG fRefCount;
627 SkAutoTUnref<const SkFontMgr_DirectWrite> fOuter; 627 SkAutoTUnref<const SkFontMgr_DirectWrite> fOuter;
628 UINT32 fCharacter; 628 UINT32 fCharacter;
629 SkTypeface* fResolvedTypeface; 629 SkTypeface* fResolvedTypeface;
630 }; 630 };
631 631
632 static HRESULT getDefaultFontFamilyName(SkSMallocWCHAR* name) {
633 NONCLIENTMETRICSW metrics;
634 metrics.cbSize = sizeof(metrics);
635 if (0 == SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(metrics), &me trics, 0)) {
636 return E_UNEXPECTED;
637 }
638
639 size_t len = wcsnlen_s(metrics.lfMessageFont.lfFaceName, LF_FACESIZE) + 1;
640 if (0 != wcsncpy_s(name->reset(len), len, metrics.lfMessageFont.lfFaceName, _TRUNCATE)) {
641 return E_UNEXPECTED;
642 }
643
644 return S_OK;
645 }
646
647 class FontFallbackSource : public IDWriteTextAnalysisSource { 632 class FontFallbackSource : public IDWriteTextAnalysisSource {
648 public: 633 public:
649 FontFallbackSource(const WCHAR* string, UINT32 length, const WCHAR* locale, 634 FontFallbackSource(const WCHAR* string, UINT32 length, const WCHAR* locale,
650 IDWriteNumberSubstitution* numberSubstitution) 635 IDWriteNumberSubstitution* numberSubstitution)
651 : fString(string) 636 : fString(string)
652 , fLength(length) 637 , fLength(length)
653 , fLocale(locale) 638 , fLocale(locale)
654 , fNumberSubstitution(numberSubstitution) 639 , fNumberSubstitution(numberSubstitution)
655 { } 640 { }
656 641
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 IDWriteNumberSubstitution* fNumberSubstitution; 728 IDWriteNumberSubstitution* fNumberSubstitution;
744 }; 729 };
745 730
746 SkTypeface* SkFontMgr_DirectWrite::onMatchFamilyStyleCharacter(const char family Name[], 731 SkTypeface* SkFontMgr_DirectWrite::onMatchFamilyStyleCharacter(const char family Name[],
747 const SkFontStyle & style, 732 const SkFontStyle & style,
748 const char* bcp47 [], int bcp47Count, 733 const char* bcp47 [], int bcp47Count,
749 SkUnichar charact er) const 734 SkUnichar charact er) const
750 { 735 {
751 const DWriteStyle dwStyle(style); 736 const DWriteStyle dwStyle(style);
752 737
753 SkSMallocWCHAR dwFamilyName; 738 const WCHAR* dwFamilyName = NULL;
754 if (NULL == familyName) { 739 SkSMallocWCHAR dwFamilyNameLocal;
755 HRN(getDefaultFontFamilyName(&dwFamilyName)); 740 if (familyName) {
756 } else { 741 HRN(sk_cstring_to_wchar(familyName, &dwFamilyNameLocal));
757 HRN(sk_cstring_to_wchar(familyName, &dwFamilyName)); 742 dwFamilyName = dwFamilyNameLocal;
758 } 743 }
759 744
760 WCHAR str[16]; 745 WCHAR str[16];
761 UINT32 strLen = static_cast<UINT32>( 746 UINT32 strLen = static_cast<UINT32>(
762 SkUTF16_FromUnichar(character, reinterpret_cast<uint16_t*>(str))); 747 SkUTF16_FromUnichar(character, reinterpret_cast<uint16_t*>(str)));
763 748
764 const SkSMallocWCHAR* dwBcp47; 749 const SkSMallocWCHAR* dwBcp47;
765 SkSMallocWCHAR dwBcp47Local; 750 SkSMallocWCHAR dwBcp47Local;
766 if (bcp47Count < 1) { 751 if (bcp47Count < 1) {
767 dwBcp47 = &fLocaleName; 752 dwBcp47 = &fLocaleName;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 794
810 SkTScopedComPtr<IDWriteFontFamily> fontFamily; 795 SkTScopedComPtr<IDWriteFontFamily> fontFamily;
811 HRNM(font->GetFontFamily(&fontFamily), "Could not get family from font." ); 796 HRNM(font->GetFontFamily(&fontFamily), "Could not get family from font." );
812 return this->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fo ntFamily.get()); 797 return this->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fo ntFamily.get());
813 } 798 }
814 #else 799 #else
815 # pragma message("No dwrite_2.h is available, font fallback may be affected.") 800 # pragma message("No dwrite_2.h is available, font fallback may be affected.")
816 #endif 801 #endif
817 802
818 SkTScopedComPtr<IDWriteTextFormat> fallbackFormat; 803 SkTScopedComPtr<IDWriteTextFormat> fallbackFormat;
819 HRNM(fFactory->CreateTextFormat(dwFamilyName, 804 HRNM(fFactory->CreateTextFormat(dwFamilyName ? dwFamilyName : L"",
820 fFontCollection.get(), 805 fFontCollection.get(),
821 dwStyle.fWeight, 806 dwStyle.fWeight,
822 dwStyle.fSlant, 807 dwStyle.fSlant,
823 dwStyle.fWidth, 808 dwStyle.fWidth,
824 72.0f, 809 72.0f,
825 *dwBcp47, 810 *dwBcp47,
826 &fallbackFormat), 811 &fallbackFormat),
827 "Could not create text format."); 812 "Could not create text format.");
828 813
829 SkTScopedComPtr<IDWriteTextLayout> fallbackLayout; 814 SkTScopedComPtr<IDWriteTextLayout> fallbackLayout;
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 } 1097 }
1113 1098
1114 #include "SkFontMgr_indirect.h" 1099 #include "SkFontMgr_indirect.h"
1115 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { 1100 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) {
1116 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); 1101 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite());
1117 if (impl.get() == NULL) { 1102 if (impl.get() == NULL) {
1118 return NULL; 1103 return NULL;
1119 } 1104 }
1120 return SkNEW_ARGS(SkFontMgr_Indirect, (impl.get(), proxy)); 1105 return SkNEW_ARGS(SkFontMgr_Indirect, (impl.get(), proxy));
1121 } 1106 }
OLDNEW
« gm/fontmgr.cpp ('K') | « gm/fontmgr.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698