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

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

Issue 134643028: Make SkFontMgr interface const. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: dw fixes Created 6 years, 10 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 | « src/ports/SkFontHost_win.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 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 public: 121 public:
122 /** localeNameLength must include the null terminator. */ 122 /** localeNameLength must include the null terminator. */
123 SkFontMgr_DirectWrite(IDWriteFontCollection* fontCollection, 123 SkFontMgr_DirectWrite(IDWriteFontCollection* fontCollection,
124 WCHAR* localeName, int localeNameLength) 124 WCHAR* localeName, int localeNameLength)
125 : fFontCollection(SkRefComPtr(fontCollection)) 125 : fFontCollection(SkRefComPtr(fontCollection))
126 , fLocaleName(localeNameLength) 126 , fLocaleName(localeNameLength)
127 { 127 {
128 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR)); 128 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR));
129 } 129 }
130 130
131 SkTypefaceCache* getTypefaceCache() { return &fTFCache; }
132
133 SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace, 131 SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace,
134 IDWriteFont* font, 132 IDWriteFont* font,
135 IDWriteFontFamily* fontFamily, 133 IDWriteFontFamily* fontFamily,
136 StreamFontFileLoader* = NULL, 134 StreamFontFileLoader* = NULL,
137 IDWriteFontCollectionLoader* = NULL ); 135 IDWriteFontCollectionLoader* = NULL ) const;
138 136
139 protected: 137 protected:
140 virtual int onCountFamilies() SK_OVERRIDE; 138 virtual int onCountFamilies() const SK_OVERRIDE;
141 virtual void onGetFamilyName(int index, SkString* familyName) SK_OVERRIDE; 139 virtual void onGetFamilyName(int index, SkString* familyName) const SK_OVERR IDE;
142 virtual SkFontStyleSet* onCreateStyleSet(int index) SK_OVERRIDE; 140 virtual SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE;
143 virtual SkFontStyleSet* onMatchFamily(const char familyName[]) SK_OVERRIDE; 141 virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const SK_OVER RIDE;
144 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], 142 virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
145 const SkFontStyle& fontstyle) SK_OVER RIDE; 143 const SkFontStyle& fontstyle) const S K_OVERRIDE;
146 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, 144 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
147 const SkFontStyle& fontstyle) SK_OVERRI DE; 145 const SkFontStyle& fontstyle) const SK_ OVERRIDE;
148 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) SK_OV ERRIDE; 146 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVERRIDE;
149 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) SK_OVERRIDE ; 147 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OV ERRIDE;
150 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) SK_OVE RRIDE; 148 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERRIDE;
151 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], 149 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
152 unsigned styleBits) SK_OVERRIDE; 150 unsigned styleBits) const SK_OVER RIDE;
153 151
154 private: 152 private:
155 HRESULT getByFamilyName(const WCHAR familyName[], IDWriteFontFamily** fontFa mily); 153 HRESULT getByFamilyName(const WCHAR familyName[], IDWriteFontFamily** fontFa mily) const;
156 HRESULT getDefaultFontFamily(IDWriteFontFamily** fontFamily); 154 HRESULT getDefaultFontFamily(IDWriteFontFamily** fontFamily) const;
157 155
158 SkMutex fTFCacheMutex; 156 void Add(SkTypeface* face, SkTypeface::Style requestedStyle, bool strong) co nst {
159 void Add(SkTypeface* face, SkTypeface::Style requestedStyle, bool strong) {
160 SkAutoMutexAcquire ama(fTFCacheMutex); 157 SkAutoMutexAcquire ama(fTFCacheMutex);
161 fTFCache.add(face, requestedStyle, strong); 158 fTFCache.add(face, requestedStyle, strong);
162 } 159 }
163 160
164 SkTypeface* FindByProcAndRef(SkTypefaceCache::FindProc proc, void* ctx) { 161 SkTypeface* FindByProcAndRef(SkTypefaceCache::FindProc proc, void* ctx) cons t {
165 SkAutoMutexAcquire ama(fTFCacheMutex); 162 SkAutoMutexAcquire ama(fTFCacheMutex);
166 SkTypeface* typeface = fTFCache.findByProcAndRef(proc, ctx); 163 SkTypeface* typeface = fTFCache.findByProcAndRef(proc, ctx);
167 return typeface; 164 return typeface;
168 } 165 }
169 166
170 friend class SkFontStyleSet_DirectWrite;
171 SkTScopedComPtr<IDWriteFontCollection> fFontCollection; 167 SkTScopedComPtr<IDWriteFontCollection> fFontCollection;
172 SkSMallocWCHAR fLocaleName; 168 SkSMallocWCHAR fLocaleName;
173 SkTypefaceCache fTFCache; 169 mutable SkMutex fTFCacheMutex;
170 mutable SkTypefaceCache fTFCache;
171
172 friend class SkFontStyleSet_DirectWrite;
174 }; 173 };
175 174
176 class SkFontStyleSet_DirectWrite : public SkFontStyleSet { 175 class SkFontStyleSet_DirectWrite : public SkFontStyleSet {
177 public: 176 public:
178 SkFontStyleSet_DirectWrite(SkFontMgr_DirectWrite* fontMgr, IDWriteFontFamily * fontFamily) 177 SkFontStyleSet_DirectWrite(const SkFontMgr_DirectWrite* fontMgr,
178 IDWriteFontFamily* fontFamily)
179 : fFontMgr(SkRef(fontMgr)) 179 : fFontMgr(SkRef(fontMgr))
180 , fFontFamily(SkRefComPtr(fontFamily)) 180 , fFontFamily(SkRefComPtr(fontFamily))
181 { } 181 { }
182 182
183 virtual int count() SK_OVERRIDE; 183 virtual int count() SK_OVERRIDE;
184 virtual void getStyle(int index, SkFontStyle* fs, SkString* styleName) SK_OV ERRIDE; 184 virtual void getStyle(int index, SkFontStyle* fs, SkString* styleName) SK_OV ERRIDE;
185 virtual SkTypeface* createTypeface(int index) SK_OVERRIDE; 185 virtual SkTypeface* createTypeface(int index) SK_OVERRIDE;
186 virtual SkTypeface* matchStyle(const SkFontStyle& pattern) SK_OVERRIDE; 186 virtual SkTypeface* matchStyle(const SkFontStyle& pattern) SK_OVERRIDE;
187 187
188 private: 188 private:
189 SkAutoTUnref<SkFontMgr_DirectWrite> fFontMgr; 189 SkAutoTUnref<const SkFontMgr_DirectWrite> fFontMgr;
190 SkTScopedComPtr<IDWriteFontFamily> fFontFamily; 190 SkTScopedComPtr<IDWriteFontFamily> fFontFamily;
191 }; 191 };
192 192
193 /////////////////////////////////////////////////////////////////////////////// 193 ///////////////////////////////////////////////////////////////////////////////
194 194
195 class DWriteOffscreen { 195 class DWriteOffscreen {
196 public: 196 public:
197 DWriteOffscreen() : fWidth(0), fHeight(0) { 197 DWriteOffscreen() : fWidth(0), fHeight(0) {
198 } 198 }
199 199
(...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1654 HRVM(names->GetStringLength(nameIndex, &nameLength), "Could not get name len gth."); 1654 HRVM(names->GetStringLength(nameIndex, &nameLength), "Could not get name len gth.");
1655 nameLength += 1; 1655 nameLength += 1;
1656 1656
1657 SkSMallocWCHAR name(nameLength); 1657 SkSMallocWCHAR name(nameLength);
1658 HRVM(names->GetString(nameIndex, name.get(), nameLength), "Could not get str ing."); 1658 HRVM(names->GetString(nameIndex, name.get(), nameLength), "Could not get str ing.");
1659 1659
1660 HRV(wchar_to_skstring(name.get(), skname)); 1660 HRV(wchar_to_skstring(name.get(), skname));
1661 } 1661 }
1662 1662
1663 SkTypeface* SkFontMgr_DirectWrite::createTypefaceFromDWriteFont( 1663 SkTypeface* SkFontMgr_DirectWrite::createTypefaceFromDWriteFont(
1664 IDWriteFontFace* fontFace, 1664 IDWriteFontFace* fontFace,
1665 IDWriteFont* font, 1665 IDWriteFont* font,
1666 IDWriteFontFamily* fontFamily, 1666 IDWriteFontFamily* fontFamily,
1667 StreamFontFileLoader* fontFileLoader, 1667 StreamFontFileLoader* fontFileLoader,
1668 IDWriteFontCollectionLoader* fontColl ectionLoader) { 1668 IDWriteFontCollectionLoader* fontCollectionLoader) const {
1669 SkTypeface* face = FindByProcAndRef(FindByDWriteFont, font); 1669 SkTypeface* face = FindByProcAndRef(FindByDWriteFont, font);
1670 if (NULL == face) { 1670 if (NULL == face) {
1671 face = DWriteFontTypeface::Create(fontFace, font, fontFamily, 1671 face = DWriteFontTypeface::Create(fontFace, font, fontFamily,
1672 fontFileLoader, fontCollectionLoader); 1672 fontFileLoader, fontCollectionLoader);
1673 if (face) { 1673 if (face) {
1674 Add(face, get_style(font), fontCollectionLoader != NULL); 1674 Add(face, get_style(font), fontCollectionLoader != NULL);
1675 } 1675 }
1676 } 1676 }
1677 return face; 1677 return face;
1678 } 1678 }
1679 1679
1680 int SkFontMgr_DirectWrite::onCountFamilies() { 1680 int SkFontMgr_DirectWrite::onCountFamilies() const {
1681 return fFontCollection->GetFontFamilyCount(); 1681 return fFontCollection->GetFontFamilyCount();
1682 } 1682 }
1683 1683
1684 void SkFontMgr_DirectWrite::onGetFamilyName(int index, SkString* familyName) { 1684 void SkFontMgr_DirectWrite::onGetFamilyName(int index, SkString* familyName) con st {
1685 SkTScopedComPtr<IDWriteFontFamily> fontFamily; 1685 SkTScopedComPtr<IDWriteFontFamily> fontFamily;
1686 HRVM(fFontCollection->GetFontFamily(index, &fontFamily), "Could not get requ ested family."); 1686 HRVM(fFontCollection->GetFontFamily(index, &fontFamily), "Could not get requ ested family.");
1687 1687
1688 SkTScopedComPtr<IDWriteLocalizedStrings> familyNames; 1688 SkTScopedComPtr<IDWriteLocalizedStrings> familyNames;
1689 HRVM(fontFamily->GetFamilyNames(&familyNames), "Could not get family names." ); 1689 HRVM(fontFamily->GetFamilyNames(&familyNames), "Could not get family names." );
1690 1690
1691 get_locale_string(familyNames.get(), fLocaleName.get(), familyName); 1691 get_locale_string(familyNames.get(), fLocaleName.get(), familyName);
1692 } 1692 }
1693 1693
1694 SkFontStyleSet* SkFontMgr_DirectWrite::onCreateStyleSet(int index) { 1694 SkFontStyleSet* SkFontMgr_DirectWrite::onCreateStyleSet(int index) const {
1695 SkTScopedComPtr<IDWriteFontFamily> fontFamily; 1695 SkTScopedComPtr<IDWriteFontFamily> fontFamily;
1696 HRNM(fFontCollection->GetFontFamily(index, &fontFamily), "Could not get requ ested family."); 1696 HRNM(fFontCollection->GetFontFamily(index, &fontFamily), "Could not get requ ested family.");
1697 1697
1698 return SkNEW_ARGS(SkFontStyleSet_DirectWrite, (this, fontFamily.get())); 1698 return SkNEW_ARGS(SkFontStyleSet_DirectWrite, (this, fontFamily.get()));
1699 } 1699 }
1700 1700
1701 SkFontStyleSet* SkFontMgr_DirectWrite::onMatchFamily(const char familyName[]) { 1701 SkFontStyleSet* SkFontMgr_DirectWrite::onMatchFamily(const char familyName[]) co nst {
1702 SkSMallocWCHAR dwFamilyName; 1702 SkSMallocWCHAR dwFamilyName;
1703 HRN(cstring_to_wchar(familyName, &dwFamilyName)); 1703 HRN(cstring_to_wchar(familyName, &dwFamilyName));
1704 1704
1705 UINT32 index; 1705 UINT32 index;
1706 BOOL exists; 1706 BOOL exists;
1707 HRNM(fFontCollection->FindFamilyName(dwFamilyName.get(), &index, &exists), 1707 HRNM(fFontCollection->FindFamilyName(dwFamilyName.get(), &index, &exists),
1708 "Failed while finding family by name."); 1708 "Failed while finding family by name.");
1709 if (!exists) { 1709 if (!exists) {
1710 return NULL; 1710 return NULL;
1711 } 1711 }
1712 1712
1713 return this->onCreateStyleSet(index); 1713 return this->onCreateStyleSet(index);
1714 } 1714 }
1715 1715
1716 SkTypeface* SkFontMgr_DirectWrite::onMatchFamilyStyle(const char familyName[], 1716 SkTypeface* SkFontMgr_DirectWrite::onMatchFamilyStyle(const char familyName[],
1717 const SkFontStyle& fontsty le) { 1717 const SkFontStyle& fontsty le) const {
1718 SkAutoTUnref<SkFontStyleSet> sset(this->matchFamily(familyName)); 1718 SkAutoTUnref<SkFontStyleSet> sset(this->matchFamily(familyName));
1719 return sset->matchStyle(fontstyle); 1719 return sset->matchStyle(fontstyle);
1720 } 1720 }
1721 1721
1722 SkTypeface* SkFontMgr_DirectWrite::onMatchFaceStyle(const SkTypeface* familyMemb er, 1722 SkTypeface* SkFontMgr_DirectWrite::onMatchFaceStyle(const SkTypeface* familyMemb er,
1723 const SkFontStyle& fontstyle ) { 1723 const SkFontStyle& fontstyle ) const {
1724 SkString familyName; 1724 SkString familyName;
1725 SkFontStyleSet_DirectWrite sset( 1725 SkFontStyleSet_DirectWrite sset(
1726 this, ((DWriteFontTypeface*)familyMember)->fDWriteFontFamily.get() 1726 this, ((DWriteFontTypeface*)familyMember)->fDWriteFontFamily.get()
1727 ); 1727 );
1728 return sset.matchStyle(fontstyle); 1728 return sset.matchStyle(fontstyle);
1729 } 1729 }
1730 1730
1731 SkTypeface* SkFontMgr_DirectWrite::onCreateFromStream(SkStream* stream, int ttcI ndex) { 1731 SkTypeface* SkFontMgr_DirectWrite::onCreateFromStream(SkStream* stream, int ttcI ndex) const {
1732 return create_from_stream(stream, ttcIndex); 1732 return create_from_stream(stream, ttcIndex);
1733 } 1733 }
1734 1734
1735 SkTypeface* SkFontMgr_DirectWrite::onCreateFromData(SkData* data, int ttcIndex) { 1735 SkTypeface* SkFontMgr_DirectWrite::onCreateFromData(SkData* data, int ttcIndex) const {
1736 SkAutoTUnref<SkStream> stream(SkNEW_ARGS(SkMemoryStream, (data))); 1736 SkAutoTUnref<SkStream> stream(SkNEW_ARGS(SkMemoryStream, (data)));
1737 return this->createFromStream(stream, ttcIndex); 1737 return this->createFromStream(stream, ttcIndex);
1738 } 1738 }
1739 1739
1740 SkTypeface* SkFontMgr_DirectWrite::onCreateFromFile(const char path[], int ttcIn dex) { 1740 SkTypeface* SkFontMgr_DirectWrite::onCreateFromFile(const char path[], int ttcIn dex) const {
1741 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 1741 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
1742 return this->createFromStream(stream, ttcIndex); 1742 return this->createFromStream(stream, ttcIndex);
1743 } 1743 }
1744 1744
1745 HRESULT SkFontMgr_DirectWrite::getByFamilyName(const WCHAR wideFamilyName[], 1745 HRESULT SkFontMgr_DirectWrite::getByFamilyName(const WCHAR wideFamilyName[],
1746 IDWriteFontFamily** fontFamily) { 1746 IDWriteFontFamily** fontFamily) c onst {
1747 UINT32 index; 1747 UINT32 index;
1748 BOOL exists; 1748 BOOL exists;
1749 HR(fFontCollection->FindFamilyName(wideFamilyName, &index, &exists)); 1749 HR(fFontCollection->FindFamilyName(wideFamilyName, &index, &exists));
1750 1750
1751 if (exists) { 1751 if (exists) {
1752 HR(fFontCollection->GetFontFamily(index, fontFamily)); 1752 HR(fFontCollection->GetFontFamily(index, fontFamily));
1753 return S_OK; 1753 return S_OK;
1754 } 1754 }
1755 return S_FALSE; 1755 return S_FALSE;
1756 } 1756 }
1757 1757
1758 HRESULT SkFontMgr_DirectWrite::getDefaultFontFamily(IDWriteFontFamily** fontFami ly) { 1758 HRESULT SkFontMgr_DirectWrite::getDefaultFontFamily(IDWriteFontFamily** fontFami ly) const {
1759 NONCLIENTMETRICSW metrics; 1759 NONCLIENTMETRICSW metrics;
1760 metrics.cbSize = sizeof(metrics); 1760 metrics.cbSize = sizeof(metrics);
1761 if (0 == SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, 1761 if (0 == SystemParametersInfoW(SPI_GETNONCLIENTMETRICS,
1762 sizeof(metrics), 1762 sizeof(metrics),
1763 &metrics, 1763 &metrics,
1764 0)) { 1764 0)) {
1765 return E_UNEXPECTED; 1765 return E_UNEXPECTED;
1766 } 1766 }
1767 HRM(this->getByFamilyName(metrics.lfMessageFont.lfFaceName, fontFamily), 1767 HRM(this->getByFamilyName(metrics.lfMessageFont.lfFaceName, fontFamily),
1768 "Could not create DWrite font family from LOGFONT."); 1768 "Could not create DWrite font family from LOGFONT.");
1769 1769
1770 return S_OK; 1770 return S_OK;
1771 } 1771 }
1772 1772
1773 SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[ ], 1773 SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[ ],
1774 unsigned styleBits) { 1774 unsigned styleBits) co nst {
1775 SkTScopedComPtr<IDWriteFontFamily> fontFamily; 1775 SkTScopedComPtr<IDWriteFontFamily> fontFamily;
1776 if (familyName) { 1776 if (familyName) {
1777 SkSMallocWCHAR wideFamilyName; 1777 SkSMallocWCHAR wideFamilyName;
1778 if (SUCCEEDED(cstring_to_wchar(familyName, &wideFamilyName))) { 1778 if (SUCCEEDED(cstring_to_wchar(familyName, &wideFamilyName))) {
1779 this->getByFamilyName(wideFamilyName, &fontFamily); 1779 this->getByFamilyName(wideFamilyName, &fontFamily);
1780 } 1780 }
1781 } 1781 }
1782 1782
1783 if (NULL == fontFamily.get()) { 1783 if (NULL == fontFamily.get()) {
1784 // No family with given name, try default. 1784 // No family with given name, try default.
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1912 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); 1912 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName.");
1913 } else { 1913 } else {
1914 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N AME_MAX_LENGTH); 1914 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N AME_MAX_LENGTH);
1915 if (localeNameLen) { 1915 if (localeNameLen) {
1916 localeName = localeNameStorage; 1916 localeName = localeNameStorage;
1917 }; 1917 };
1918 } 1918 }
1919 1919
1920 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam e, localeNameLen)); 1920 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam e, localeNameLen));
1921 } 1921 }
OLDNEW
« no previous file with comments | « src/ports/SkFontHost_win.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698