Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkTypes.h" | 8 #include "SkTypes.h" |
| 9 #undef GetGlyphIndices | 9 #undef GetGlyphIndices |
| 10 | 10 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 SkTypeface* FindByProcAndRef(SkTypefaceCache::FindProc proc, void* ctx) { | 122 SkTypeface* FindByProcAndRef(SkTypefaceCache::FindProc proc, void* ctx) { |
| 123 SkAutoMutexAcquire ama(fTFCacheMutex); | 123 SkAutoMutexAcquire ama(fTFCacheMutex); |
| 124 SkTypeface* typeface = fTFCache.findByProcAndRef(proc, ctx); | 124 SkTypeface* typeface = fTFCache.findByProcAndRef(proc, ctx); |
| 125 return typeface; | 125 return typeface; |
| 126 } | 126 } |
| 127 | 127 |
| 128 friend class SkFontStyleSet_DirectWrite; | 128 friend class SkFontStyleSet_DirectWrite; |
| 129 SkTScopedComPtr<IDWriteFontCollection> fFontCollection; | 129 SkTScopedComPtr<IDWriteFontCollection> fFontCollection; |
| 130 SkSMallocWCHAR fLocaleName; | 130 SkSMallocWCHAR fLocaleName; |
| 131 SkTypefaceCache fTFCache; | 131 SkTypefaceCache fTFCache; |
| 132 | |
| 133 HRESULT getByFamilyName(const char familyName[], IDWriteFontFamily** fontFam ily); | |
|
caryclark
2013/11/20 19:09:14
why return HRESULT if caller doesn't check it?
bungeman-skia
2013/11/20 21:38:39
Re-worked, it's now checked (at least in one place
| |
| 134 HRESULT getDefaultFont(IDWriteFont** font); | |
|
caryclark
2013/11/20 19:09:14
looks like the existing pattern is private helper
bungeman-skia
2013/11/20 21:38:39
Done.
| |
| 132 }; | 135 }; |
| 133 | 136 |
| 134 class SkFontStyleSet_DirectWrite : public SkFontStyleSet { | 137 class SkFontStyleSet_DirectWrite : public SkFontStyleSet { |
| 135 public: | 138 public: |
| 136 SkFontStyleSet_DirectWrite(SkFontMgr_DirectWrite* fontMgr, IDWriteFontFamily * fontFamily) | 139 SkFontStyleSet_DirectWrite(SkFontMgr_DirectWrite* fontMgr, IDWriteFontFamily * fontFamily) |
| 137 : fFontMgr(SkRef(fontMgr)) | 140 : fFontMgr(SkRef(fontMgr)) |
| 138 , fFontFamily(SkRefComPtr(fontFamily)) | 141 , fFontFamily(SkRefComPtr(fontFamily)) |
| 139 { } | 142 { } |
| 140 | 143 |
| 141 virtual int count() SK_OVERRIDE; | 144 virtual int count() SK_OVERRIDE; |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 591 virtual void generateFontMetrics(SkPaint::FontMetrics* mX, | 594 virtual void generateFontMetrics(SkPaint::FontMetrics* mX, |
| 592 SkPaint::FontMetrics* mY) SK_OVERRIDE; | 595 SkPaint::FontMetrics* mY) SK_OVERRIDE; |
| 593 | 596 |
| 594 private: | 597 private: |
| 595 DWriteOffscreen fOffscreen; | 598 DWriteOffscreen fOffscreen; |
| 596 DWRITE_MATRIX fXform; | 599 DWRITE_MATRIX fXform; |
| 597 SkAutoTUnref<DWriteFontTypeface> fTypeface; | 600 SkAutoTUnref<DWriteFontTypeface> fTypeface; |
| 598 int fGlyphCount; | 601 int fGlyphCount; |
| 599 }; | 602 }; |
| 600 | 603 |
| 601 #define SK_DWRITE_DEFAULT_FONT_NAMED 1 | |
| 602 #define SK_DWRITE_DEFAULT_FONT_MESSAGE 2 | |
| 603 #define SK_DWRITE_DEFAULT_FONT_THEME 3 | |
| 604 #define SK_DWRITE_DEFAULT_FONT_SHELLDLG 4 | |
| 605 #define SK_DWRITE_DEFAULT_FONT_GDI 5 | |
| 606 #define SK_DWRITE_DEFAULT_FONT_STRATEGY SK_DWRITE_DEFAULT_FONT_MESSAGE | |
| 607 | |
| 608 static HRESULT get_default_font(IDWriteFont** font) { | |
| 609 IDWriteFactory* factory; | |
| 610 HRM(get_dwrite_factory(&factory), "Could not get factory."); | |
| 611 | |
| 612 #if SK_DWRITE_DEFAULT_FONT_STRATEGY == SK_DWRITE_DEFAULT_FONT_NAMED | |
| 613 SkTScopedComPtr<IDWriteFontCollection> sysFonts; | |
| 614 HRM(factory->GetSystemFontCollection(&sysFonts, false), | |
| 615 "Could not get system font collection."); | |
| 616 | |
| 617 UINT32 index; | |
| 618 BOOL exists; | |
| 619 //hr = sysFonts->FindFamilyName(L"Georgia", &index, &exists); | |
| 620 HRM(sysFonts->FindFamilyName(L"Microsoft Sans Serif", &index, &exists), | |
| 621 "Could not access family names."); | |
| 622 | |
| 623 if (!exists) { | |
| 624 SkDEBUGF(("The hard coded font family does not exist.")); | |
| 625 return E_UNEXPECTED; | |
| 626 } | |
| 627 | |
| 628 SkTScopedComPtr<IDWriteFontFamily> fontFamily; | |
| 629 HRM(sysFonts->GetFontFamily(index, &fontFamily), | |
| 630 "Could not load the requested font family."); | |
| 631 | |
| 632 HRM(fontFamily->GetFont(0, font), "Could not get first font from family."); | |
| 633 | |
| 634 #elif SK_DWRITE_DEFAULT_FONT_STRATEGY == SK_DWRITE_DEFAULT_FONT_MESSAGE | |
|
bungeman-skia
2013/11/20 18:45:27
Previously, everything but this block was effectiv
| |
| 635 SkTScopedComPtr<IDWriteGdiInterop> gdi; | |
| 636 HRM(factory->GetGdiInterop(&gdi), "Could not get GDI interop."); | |
| 637 | |
| 638 NONCLIENTMETRICSW metrics; | |
| 639 metrics.cbSize = sizeof(metrics); | |
| 640 if (0 == SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, | |
| 641 sizeof(metrics), | |
| 642 &metrics, | |
| 643 0)) { | |
| 644 return E_UNEXPECTED; | |
| 645 } | |
| 646 HRM(gdi->CreateFontFromLOGFONT(&metrics.lfMessageFont, font), | |
| 647 "Could not create DWrite font from LOGFONT."); | |
| 648 | |
| 649 #elif SK_DWRITE_DEFAULT_FONT_STRATEGY == SK_DWRITE_DEFAULT_FONT_THEME | |
| 650 //Theme body font? | |
| 651 | |
| 652 #elif SK_DWRITE_DEFAULT_FONT_STRATEGY == SK_DWRITE_DEFAULT_FONT_SHELLDLG | |
| 653 //"MS Shell Dlg" or "MS Shell Dlg 2"? | |
| 654 | |
| 655 #elif SK_DWRITE_DEFAULT_FONT_STRATEGY == SK_DWRITE_DEFAULT_FONT_GDI | |
| 656 //Never works. | |
| 657 SkTScopedComPtr<IDWriteGdiInterop> gdi; | |
| 658 HRM(factory->GetGdiInterop(&gdi), "Could not get GDI interop."); | |
| 659 | |
| 660 static LOGFONTW gDefaultFont = {}; | |
| 661 gDefaultFont.lfFaceName | |
| 662 HRM(gdi->CreateFontFromLOGFONT(&gDefaultFont, font), | |
| 663 "Could not create DWrite font from LOGFONT."; | |
| 664 #endif | |
| 665 return S_OK; | |
| 666 } | |
| 667 | |
| 668 static bool are_same(IUnknown* a, IUnknown* b) { | 604 static bool are_same(IUnknown* a, IUnknown* b) { |
| 669 SkTScopedComPtr<IUnknown> iunkA; | 605 SkTScopedComPtr<IUnknown> iunkA; |
| 670 if (FAILED(a->QueryInterface(&iunkA))) { | 606 if (FAILED(a->QueryInterface(&iunkA))) { |
| 671 return false; | 607 return false; |
| 672 } | 608 } |
| 673 | 609 |
| 674 SkTScopedComPtr<IUnknown> iunkB; | 610 SkTScopedComPtr<IUnknown> iunkB; |
| 675 if (FAILED(b->QueryInterface(&iunkB))) { | 611 if (FAILED(b->QueryInterface(&iunkB))) { |
| 676 return false; | 612 return false; |
| 677 } | 613 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 771 | 707 |
| 772 SkSMallocWCHAR dwFontFamilyNameChar(dwFontFamilyNameLength+1); | 708 SkSMallocWCHAR dwFontFamilyNameChar(dwFontFamilyNameLength+1); |
| 773 SkSMallocWCHAR dwFontNameChar(dwFontNameLength+1); | 709 SkSMallocWCHAR dwFontNameChar(dwFontNameLength+1); |
| 774 HRB(dwFontFamilyNames->GetString(0, dwFontFamilyNameChar.get(), dwFontFamily NameLength+1)); | 710 HRB(dwFontFamilyNames->GetString(0, dwFontFamilyNameChar.get(), dwFontFamily NameLength+1)); |
| 775 HRB(dwFontNames->GetString(0, dwFontNameChar.get(), dwFontNameLength+1)); | 711 HRB(dwFontNames->GetString(0, dwFontNameChar.get(), dwFontNameLength+1)); |
| 776 | 712 |
| 777 return wcscmp(dwFaceFontFamilyNameChar.get(), dwFontFamilyNameChar.get()) == 0 && | 713 return wcscmp(dwFaceFontFamilyNameChar.get(), dwFontFamilyNameChar.get()) == 0 && |
| 778 wcscmp(dwFaceFontNameChar.get(), dwFontNameChar.get()) == 0; | 714 wcscmp(dwFaceFontNameChar.get(), dwFontNameChar.get()) == 0; |
| 779 } | 715 } |
| 780 | 716 |
| 781 void SkDWriteFontFromTypeface(const SkTypeface* face, IDWriteFont** font) { | |
|
bungeman-skia
2013/11/20 18:45:27
This was a caller to get_default_font. However, it
| |
| 782 if (NULL == face) { | |
| 783 HRVM(get_default_font(font), "Could not get default font."); | |
| 784 } else { | |
| 785 *font = SkRefComPtr(static_cast<const DWriteFontTypeface*>(face)->fDWrit eFont.get()); | |
| 786 } | |
| 787 } | |
| 788 | |
| 789 SkScalerContext_DW::SkScalerContext_DW(DWriteFontTypeface* typeface, | 717 SkScalerContext_DW::SkScalerContext_DW(DWriteFontTypeface* typeface, |
| 790 const SkDescriptor* desc) | 718 const SkDescriptor* desc) |
| 791 : SkScalerContext(typeface, desc) | 719 : SkScalerContext(typeface, desc) |
| 792 , fTypeface(SkRef(typeface)) | 720 , fTypeface(SkRef(typeface)) |
| 793 , fGlyphCount(-1) { | 721 , fGlyphCount(-1) { |
| 794 SkAutoMutexAcquire ac(gFTMutex); | 722 SkAutoMutexAcquire ac(gFTMutex); |
| 795 | 723 |
| 796 fXform.m11 = SkScalarToFloat(fRec.fPost2x2[0][0]); | 724 fXform.m11 = SkScalarToFloat(fRec.fPost2x2[0][0]); |
| 797 fXform.m12 = SkScalarToFloat(fRec.fPost2x2[1][0]); | 725 fXform.m12 = SkScalarToFloat(fRec.fPost2x2[1][0]); |
| 798 fXform.m21 = SkScalarToFloat(fRec.fPost2x2[0][1]); | 726 fXform.m21 = SkScalarToFloat(fRec.fPost2x2[0][1]); |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1424 &fontFileStream), | 1352 &fontFileStream), |
| 1425 "Could not create font file stream."); | 1353 "Could not create font file stream."); |
| 1426 | 1354 |
| 1427 return SkNEW_ARGS(SkDWriteFontFileStream, (fontFileStream.get())); | 1355 return SkNEW_ARGS(SkDWriteFontFileStream, (fontFileStream.get())); |
| 1428 } | 1356 } |
| 1429 | 1357 |
| 1430 SkScalerContext* DWriteFontTypeface::onCreateScalerContext(const SkDescriptor* d esc) const { | 1358 SkScalerContext* DWriteFontTypeface::onCreateScalerContext(const SkDescriptor* d esc) const { |
| 1431 return SkNEW_ARGS(SkScalerContext_DW, (const_cast<DWriteFontTypeface*>(this) , desc)); | 1359 return SkNEW_ARGS(SkScalerContext_DW, (const_cast<DWriteFontTypeface*>(this) , desc)); |
| 1432 } | 1360 } |
| 1433 | 1361 |
| 1434 static HRESULT get_by_family_name(const char familyName[], IDWriteFontFamily** f ontFamily) { | |
|
bungeman-skia
2013/11/20 18:45:27
This is moved into getByFamilyName and changed to
| |
| 1435 IDWriteFactory* factory; | |
| 1436 HR(get_dwrite_factory(&factory)); | |
| 1437 | |
| 1438 SkTScopedComPtr<IDWriteFontCollection> sysFontCollection; | |
| 1439 HR(factory->GetSystemFontCollection(&sysFontCollection, FALSE)); | |
| 1440 | |
| 1441 SkSMallocWCHAR wideFamilyName; | |
| 1442 HR(cstring_to_wchar(familyName, &wideFamilyName)); | |
| 1443 | |
| 1444 UINT32 index; | |
| 1445 BOOL exists; | |
| 1446 HR(sysFontCollection->FindFamilyName(wideFamilyName.get(), &index, &exists)) ; | |
| 1447 | |
| 1448 if (exists) { | |
| 1449 HR(sysFontCollection->GetFontFamily(index, fontFamily)); | |
| 1450 return S_OK; | |
| 1451 } | |
| 1452 return S_FALSE; | |
| 1453 } | |
| 1454 | |
| 1455 void DWriteFontTypeface::onFilterRec(SkScalerContext::Rec* rec) const { | 1362 void DWriteFontTypeface::onFilterRec(SkScalerContext::Rec* rec) const { |
| 1456 if (rec->fFlags & SkScalerContext::kLCD_BGROrder_Flag || | 1363 if (rec->fFlags & SkScalerContext::kLCD_BGROrder_Flag || |
| 1457 rec->fFlags & SkScalerContext::kLCD_Vertical_Flag) | 1364 rec->fFlags & SkScalerContext::kLCD_Vertical_Flag) |
| 1458 { | 1365 { |
| 1459 rec->fMaskFormat = SkMask::kA8_Format; | 1366 rec->fMaskFormat = SkMask::kA8_Format; |
| 1460 } | 1367 } |
| 1461 | 1368 |
| 1462 unsigned flagsWeDontSupport = SkScalerContext::kDevKernText_Flag | | 1369 unsigned flagsWeDontSupport = SkScalerContext::kDevKernText_Flag | |
| 1463 SkScalerContext::kAutohinting_Flag | | 1370 SkScalerContext::kAutohinting_Flag | |
| 1464 SkScalerContext::kEmbeddedBitmapText_Flag | | 1371 SkScalerContext::kEmbeddedBitmapText_Flag | |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1823 SkTypeface* SkFontMgr_DirectWrite::onCreateFromData(SkData* data, int ttcIndex) { | 1730 SkTypeface* SkFontMgr_DirectWrite::onCreateFromData(SkData* data, int ttcIndex) { |
| 1824 SkAutoTUnref<SkStream> stream(SkNEW_ARGS(SkMemoryStream, (data))); | 1731 SkAutoTUnref<SkStream> stream(SkNEW_ARGS(SkMemoryStream, (data))); |
| 1825 return this->createFromStream(stream, ttcIndex); | 1732 return this->createFromStream(stream, ttcIndex); |
| 1826 } | 1733 } |
| 1827 | 1734 |
| 1828 SkTypeface* SkFontMgr_DirectWrite::onCreateFromFile(const char path[], int ttcIn dex) { | 1735 SkTypeface* SkFontMgr_DirectWrite::onCreateFromFile(const char path[], int ttcIn dex) { |
| 1829 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | 1736 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); |
| 1830 return this->createFromStream(stream, ttcIndex); | 1737 return this->createFromStream(stream, ttcIndex); |
| 1831 } | 1738 } |
| 1832 | 1739 |
| 1740 HRESULT SkFontMgr_DirectWrite::getByFamilyName(const char familyName[], | |
| 1741 IDWriteFontFamily** fontFamily) { | |
| 1742 SkSMallocWCHAR wideFamilyName; | |
| 1743 HR(cstring_to_wchar(familyName, &wideFamilyName)); | |
| 1744 | |
| 1745 UINT32 index; | |
| 1746 BOOL exists; | |
| 1747 HR(fFontCollection->FindFamilyName(wideFamilyName.get(), &index, &exists)); | |
| 1748 | |
| 1749 if (exists) { | |
| 1750 HR(fFontCollection->GetFontFamily(index, fontFamily)); | |
| 1751 return S_OK; | |
| 1752 } | |
| 1753 return S_FALSE; | |
| 1754 } | |
| 1755 | |
| 1756 HRESULT SkFontMgr_DirectWrite::getDefaultFont(IDWriteFont** font) { | |
| 1757 IDWriteFactory* factory; | |
| 1758 HRM(get_dwrite_factory(&factory), "Could not get factory."); | |
| 1759 | |
| 1760 SkTScopedComPtr<IDWriteGdiInterop> gdi; | |
| 1761 HRM(factory->GetGdiInterop(&gdi), "Could not get GDI interop."); | |
| 1762 | |
| 1763 NONCLIENTMETRICSW metrics; | |
| 1764 metrics.cbSize = sizeof(metrics); | |
| 1765 if (0 == SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, | |
| 1766 sizeof(metrics), | |
| 1767 &metrics, | |
| 1768 0)) { | |
| 1769 return E_UNEXPECTED; | |
| 1770 } | |
| 1771 HRM(gdi->CreateFontFromLOGFONT(&metrics.lfMessageFont, font), | |
| 1772 "Could not create DWrite font from LOGFONT."); | |
| 1773 | |
| 1774 return S_OK; | |
| 1775 } | |
|
caryclark
2013/11/20 19:09:14
getDefaultFont could be a local static function, r
bungeman-skia
2013/11/20 21:38:39
That was going to be my next change, to get rid of
| |
| 1776 | |
| 1833 SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[ ], | 1777 SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[ ], |
| 1834 unsigned styleBits) { | 1778 unsigned styleBits) { |
| 1835 SkTScopedComPtr<IDWriteFontFamily> fontFamily; | 1779 SkTScopedComPtr<IDWriteFontFamily> fontFamily; |
| 1836 if (familyName) { | 1780 if (familyName) { |
| 1837 get_by_family_name(familyName, &fontFamily); | 1781 this->getByFamilyName(familyName, &fontFamily); |
| 1838 } | 1782 } |
| 1839 | 1783 |
| 1840 if (NULL == fontFamily.get()) { | 1784 if (NULL == fontFamily.get()) { |
| 1841 //No good family found, go with default. | 1785 //No good family found, go with default. |
| 1842 SkTScopedComPtr<IDWriteFont> defaultFont; | 1786 SkTScopedComPtr<IDWriteFont> defaultFont; |
| 1843 HRNM(get_default_font(&defaultFont), "Could not get default font."); | 1787 HRNM(this->getDefaultFont(&defaultFont), "Could not get default font."); |
| 1844 HRNM(defaultFont->GetFontFamily(&fontFamily), "Could not get default fon t family."); | 1788 HRNM(defaultFont->GetFontFamily(&fontFamily), "Could not get default fon t family."); |
| 1845 } | 1789 } |
| 1846 | 1790 |
| 1847 SkTScopedComPtr<IDWriteFont> font; | 1791 SkTScopedComPtr<IDWriteFont> font; |
| 1848 DWRITE_FONT_WEIGHT weight = (styleBits & SkTypeface::kBold) | 1792 DWRITE_FONT_WEIGHT weight = (styleBits & SkTypeface::kBold) |
| 1849 ? DWRITE_FONT_WEIGHT_BOLD | 1793 ? DWRITE_FONT_WEIGHT_BOLD |
| 1850 : DWRITE_FONT_WEIGHT_NORMAL; | 1794 : DWRITE_FONT_WEIGHT_NORMAL; |
| 1851 DWRITE_FONT_STRETCH stretch = DWRITE_FONT_STRETCH_UNDEFINED; | 1795 DWRITE_FONT_STRETCH stretch = DWRITE_FONT_STRETCH_UNDEFINED; |
| 1852 DWRITE_FONT_STYLE italic = (styleBits & SkTypeface::kItalic) | 1796 DWRITE_FONT_STYLE italic = (styleBits & SkTypeface::kItalic) |
| 1853 ? DWRITE_FONT_STYLE_ITALIC | 1797 ? DWRITE_FONT_STYLE_ITALIC |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1969 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); | 1913 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); |
| 1970 } else { | 1914 } else { |
| 1971 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N AME_MAX_LENGTH); | 1915 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N AME_MAX_LENGTH); |
| 1972 if (localeNameLen) { | 1916 if (localeNameLen) { |
| 1973 localeName = localeNameStorage; | 1917 localeName = localeNameStorage; |
| 1974 }; | 1918 }; |
| 1975 } | 1919 } |
| 1976 | 1920 |
| 1977 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam e, localeNameLen)); | 1921 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam e, localeNameLen)); |
| 1978 } | 1922 } |
| OLD | NEW |