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

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

Issue 23058002: allow both GDI and DW fontmgrs at the same time (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: make cache private to DW Created 7 years, 4 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 | Annotate | Revision Log
« 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 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 697
698 SkSMallocWCHAR dwFontFamilyNameChar(dwFontFamilyNameLength+1); 698 SkSMallocWCHAR dwFontFamilyNameChar(dwFontFamilyNameLength+1);
699 SkSMallocWCHAR dwFontNameChar(dwFontNameLength+1); 699 SkSMallocWCHAR dwFontNameChar(dwFontNameLength+1);
700 HRB(dwFontFamilyNames->GetString(0, dwFontFamilyNameChar.get(), dwFontFamily NameLength+1)); 700 HRB(dwFontFamilyNames->GetString(0, dwFontFamilyNameChar.get(), dwFontFamily NameLength+1));
701 HRB(dwFontNames->GetString(0, dwFontNameChar.get(), dwFontNameLength+1)); 701 HRB(dwFontNames->GetString(0, dwFontNameChar.get(), dwFontNameLength+1));
702 702
703 return wcscmp(dwFaceFontFamilyNameChar.get(), dwFontFamilyNameChar.get()) == 0 && 703 return wcscmp(dwFaceFontFamilyNameChar.get(), dwFontFamilyNameChar.get()) == 0 &&
704 wcscmp(dwFaceFontNameChar.get(), dwFontNameChar.get()) == 0; 704 wcscmp(dwFaceFontNameChar.get(), dwFontNameChar.get()) == 0;
705 } 705 }
706 706
707 SkTypeface* SkCreateTypefaceFromDWriteFont(IDWriteFontFace* fontFace, 707 SkTypeface* SkCreateTypefaceFromDWriteFont(SkTypefaceCache* cache,
bungeman-skia 2013/08/13 15:53:45 This is really odd looking, I think what we logica
708 IDWriteFontFace* fontFace,
708 IDWriteFont* font, 709 IDWriteFont* font,
709 IDWriteFontFamily* fontFamily, 710 IDWriteFontFamily* fontFamily,
710 StreamFontFileLoader* fontFileLoader = NULL, 711 StreamFontFileLoader* fontFileLoader = NULL,
711 IDWriteFontCollectionLoader* fontColl ectionLoader = NULL) { 712 IDWriteFontCollectionLoader* fontColl ectionLoader = NULL) {
712 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(FindByDWriteFont, font) ; 713 SkTypeface* face = NULL;
714 if (cache) {
715 face = cache->findByProcAndRef(FindByDWriteFont, font);
716 }
713 if (NULL == face) { 717 if (NULL == face) {
714 face = DWriteFontTypeface::Create(fontFace, font, fontFamily, 718 face = DWriteFontTypeface::Create(fontFace, font, fontFamily,
715 fontFileLoader, fontCollectionLoader); 719 fontFileLoader, fontCollectionLoader);
716 SkTypefaceCache::Add(face, get_style(font), fontCollectionLoader != NULL ); 720 if (face) {
bungeman-skia 2013/08/13 15:53:45 && cache
721 cache->add(face, get_style(font), fontCollectionLoader != NULL);
722 }
717 } 723 }
718 return face; 724 return face;
719 } 725 }
720 726
721 void SkDWriteFontFromTypeface(const SkTypeface* face, IDWriteFont** font) { 727 void SkDWriteFontFromTypeface(const SkTypeface* face, IDWriteFont** font) {
722 if (NULL == face) { 728 if (NULL == face) {
723 HRVM(get_default_font(font), "Could not get default font."); 729 HRVM(get_default_font(font), "Could not get default font.");
724 } else { 730 } else {
725 *font = SkRefComPtr(static_cast<const DWriteFontTypeface*>(face)->fDWrit eFont.get()); 731 *font = SkRefComPtr(static_cast<const DWriteFontTypeface*>(face)->fDWrit eFont.get());
726 } 732 }
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 } 1219 }
1214 1220
1215 HRESULT unregister(IDWriteFactory* factory, IDWriteFontCollectionLoader* unr egister) { 1221 HRESULT unregister(IDWriteFactory* factory, IDWriteFontCollectionLoader* unr egister) {
1216 return factory->UnregisterFontCollectionLoader(unregister); 1222 return factory->UnregisterFontCollectionLoader(unregister);
1217 } 1223 }
1218 1224
1219 IDWriteFactory* fFactory; 1225 IDWriteFactory* fFactory;
1220 T* fUnregister; 1226 T* fUnregister;
1221 }; 1227 };
1222 1228
1223 static SkTypeface* create_from_stream(SkStream* stream, int ttcIndex) { 1229 static SkTypeface* create_from_stream(SkStream* stream, int ttcIndex,
bungeman-skia 2013/08/13 15:53:45 I've been debating this for a while, but should th
1230 SkTypefaceCache* cache) {
1224 IDWriteFactory* factory; 1231 IDWriteFactory* factory;
1225 HRN(get_dwrite_factory(&factory)); 1232 HRN(get_dwrite_factory(&factory));
1226 1233
1227 SkTScopedComPtr<StreamFontFileLoader> fontFileLoader; 1234 SkTScopedComPtr<StreamFontFileLoader> fontFileLoader;
1228 HRN(StreamFontFileLoader::Create(stream, &fontFileLoader)); 1235 HRN(StreamFontFileLoader::Create(stream, &fontFileLoader));
1229 HRN(factory->RegisterFontFileLoader(fontFileLoader.get())); 1236 HRN(factory->RegisterFontFileLoader(fontFileLoader.get()));
1230 SkAutoIDWriteUnregister<StreamFontFileLoader> autoUnregisterFontFileLoader( 1237 SkAutoIDWriteUnregister<StreamFontFileLoader> autoUnregisterFontFileLoader(
1231 factory, fontFileLoader.get()); 1238 factory, fontFileLoader.get());
1232 1239
1233 SkTScopedComPtr<StreamFontCollectionLoader> fontCollectionLoader; 1240 SkTScopedComPtr<StreamFontCollectionLoader> fontCollectionLoader;
(...skipping 17 matching lines...) Expand all
1251 HRN(fontFamily->GetFont(fontIndex, &font)); 1258 HRN(fontFamily->GetFont(fontIndex, &font));
1252 if (font->GetSimulations() != DWRITE_FONT_SIMULATIONS_NONE) { 1259 if (font->GetSimulations() != DWRITE_FONT_SIMULATIONS_NONE) {
1253 continue; 1260 continue;
1254 } 1261 }
1255 1262
1256 SkTScopedComPtr<IDWriteFontFace> fontFace; 1263 SkTScopedComPtr<IDWriteFontFace> fontFace;
1257 HRN(font->CreateFontFace(&fontFace)); 1264 HRN(font->CreateFontFace(&fontFace));
1258 1265
1259 UINT32 faceIndex = fontFace->GetIndex(); 1266 UINT32 faceIndex = fontFace->GetIndex();
1260 if (faceIndex == ttcIndex) { 1267 if (faceIndex == ttcIndex) {
1261 return SkCreateTypefaceFromDWriteFont(fontFace.get(), font.get() , fontFamily.get(), 1268 return SkCreateTypefaceFromDWriteFont(cache, fontFace.get(), fon t.get(), fontFamily.get(),
1262 autoUnregisterFontFileLoad er.detatch(), 1269 autoUnregisterFontFileLoad er.detatch(),
1263 autoUnregisterFontCollecti onLoader.detatch()); 1270 autoUnregisterFontCollecti onLoader.detatch());
1264 } 1271 }
1265 } 1272 }
1266 } 1273 }
1267 1274
1268 return NULL; 1275 return NULL;
1269 } 1276 }
1270 1277
1271 SkStream* DWriteFontTypeface::onOpenStream(int* ttcIndex) const { 1278 SkStream* DWriteFontTypeface::onOpenStream(int* ttcIndex) const {
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 glyphIDsCount, 1596 glyphIDsCount,
1590 getWidthAdvance)); 1597 getWidthAdvance));
1591 } 1598 }
1592 } 1599 }
1593 1600
1594 return info; 1601 return info;
1595 } 1602 }
1596 1603
1597 static SkTypeface* create_typeface(const SkTypeface* familyFace, 1604 static SkTypeface* create_typeface(const SkTypeface* familyFace,
1598 const char familyName[], 1605 const char familyName[],
1599 unsigned style) { 1606 unsigned style,
1607 SkTypefaceCache* cache) {
1600 HRESULT hr; 1608 HRESULT hr;
1601 SkTScopedComPtr<IDWriteFontFamily> fontFamily; 1609 SkTScopedComPtr<IDWriteFontFamily> fontFamily;
1602 if (familyFace) { 1610 if (familyFace) {
1603 const DWriteFontTypeface* face = static_cast<const DWriteFontTypeface*>( familyFace); 1611 const DWriteFontTypeface* face = static_cast<const DWriteFontTypeface*>( familyFace);
1604 *(&fontFamily) = SkRefComPtr(face->fDWriteFontFamily.get()); 1612 *(&fontFamily) = SkRefComPtr(face->fDWriteFontFamily.get());
1605 1613
1606 } else if (familyName) { 1614 } else if (familyName) {
1607 hr = get_by_family_name(familyName, &fontFamily); 1615 hr = get_by_family_name(familyName, &fontFamily);
1608 } 1616 }
1609 1617
(...skipping 10 matching lines...) Expand all
1620 : DWRITE_FONT_WEIGHT_NORMAL; 1628 : DWRITE_FONT_WEIGHT_NORMAL;
1621 DWRITE_FONT_STRETCH stretch = DWRITE_FONT_STRETCH_UNDEFINED; 1629 DWRITE_FONT_STRETCH stretch = DWRITE_FONT_STRETCH_UNDEFINED;
1622 DWRITE_FONT_STYLE italic = (style & SkTypeface::kItalic) 1630 DWRITE_FONT_STYLE italic = (style & SkTypeface::kItalic)
1623 ? DWRITE_FONT_STYLE_ITALIC 1631 ? DWRITE_FONT_STYLE_ITALIC
1624 : DWRITE_FONT_STYLE_NORMAL; 1632 : DWRITE_FONT_STYLE_NORMAL;
1625 hr = fontFamily->GetFirstMatchingFont(weight, stretch, italic, &font); 1633 hr = fontFamily->GetFirstMatchingFont(weight, stretch, italic, &font);
1626 1634
1627 SkTScopedComPtr<IDWriteFontFace> fontFace; 1635 SkTScopedComPtr<IDWriteFontFace> fontFace;
1628 hr = font->CreateFontFace(&fontFace); 1636 hr = font->CreateFontFace(&fontFace);
1629 1637
1630 return SkCreateTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily .get()); 1638 return SkCreateTypefaceFromDWriteFont(cache, fontFace.get(), font.get(), fon tFamily.get());
1631 } 1639 }
1632 1640
1633 SkTypeface* DWriteFontTypeface::onRefMatchingStyle(Style style) const { 1641 SkTypeface* DWriteFontTypeface::onRefMatchingStyle(Style style) const {
1634 return create_typeface(this, NULL, style); 1642 SkTypefaceCache* cache = NULL;
1643 // todo: should each typeface have a ref to its fontmgr/cache?
1644 return create_typeface(this, NULL, style, cache);
1635 } 1645 }
1636 1646
1637 /////////////////////////////////////////////////////////////////////////////// 1647 ///////////////////////////////////////////////////////////////////////////////
1638 1648
1639 #include "SkFontMgr.h" 1649 #include "SkFontMgr.h"
1640 1650
1641 static void get_locale_string(IDWriteLocalizedStrings* names, const WCHAR* prefe redLocale, 1651 static void get_locale_string(IDWriteLocalizedStrings* names, const WCHAR* prefe redLocale,
1642 SkString* skname) { 1652 SkString* skname) {
1643 UINT32 nameIndex = 0; 1653 UINT32 nameIndex = 0;
1644 if (preferedLocale) { 1654 if (preferedLocale) {
(...skipping 12 matching lines...) Expand all
1657 SkSMallocWCHAR name(nameLength); 1667 SkSMallocWCHAR name(nameLength);
1658 HRVM(names->GetString(nameIndex, name.get(), nameLength), "Could not get str ing."); 1668 HRVM(names->GetString(nameIndex, name.get(), nameLength), "Could not get str ing.");
1659 1669
1660 HRV(wchar_to_skstring(name.get(), skname)); 1670 HRV(wchar_to_skstring(name.get(), skname));
1661 } 1671 }
1662 1672
1663 class SkFontMgr_DirectWrite; 1673 class SkFontMgr_DirectWrite;
1664 1674
1665 class SkFontStyleSet_DirectWrite : public SkFontStyleSet { 1675 class SkFontStyleSet_DirectWrite : public SkFontStyleSet {
1666 public: 1676 public:
1667 SkFontStyleSet_DirectWrite(const SkFontMgr_DirectWrite* fontMgr, IDWriteFont Family* fontFamily) 1677 SkFontStyleSet_DirectWrite(SkFontMgr_DirectWrite* fontMgr, IDWriteFontFamily * fontFamily)
1668 : fFontMgr(SkRef(fontMgr)) 1678 : fFontMgr(SkRef(fontMgr))
1669 , fFontFamily(SkRefComPtr(fontFamily)) 1679 , fFontFamily(SkRefComPtr(fontFamily))
1670 { } 1680 { }
1671 1681
1672 virtual int count() SK_OVERRIDE { 1682 virtual int count() SK_OVERRIDE;
1673 return fFontFamily->GetFontCount(); 1683 virtual void getStyle(int index, SkFontStyle* fs, SkString* styleName) SK_OV ERRIDE;
1674 } 1684 virtual SkTypeface* createTypeface(int index) SK_OVERRIDE;
1675 1685 virtual SkTypeface* matchStyle(const SkFontStyle& pattern) SK_OVERRIDE;
1676 virtual void getStyle(int index, SkFontStyle* fs, SkString* styleName);
1677
1678 virtual SkTypeface* createTypeface(int index) SK_OVERRIDE {
1679 SkTScopedComPtr<IDWriteFont> font;
1680 HRNM(fFontFamily->GetFont(index, &font), "Could not get font.");
1681
1682 SkTScopedComPtr<IDWriteFontFace> fontFace;
1683 HRNM(font->CreateFontFace(&fontFace), "Could not create font face.");
1684
1685 return SkCreateTypefaceFromDWriteFont(fontFace.get(), font.get(), fFontF amily.get());
1686 }
1687
1688 virtual SkTypeface* matchStyle(const SkFontStyle& pattern) SK_OVERRIDE {
1689 DWRITE_FONT_STYLE slant;
1690 switch (pattern.slant()) {
1691 case SkFontStyle::kUpright_Slant:
1692 slant = DWRITE_FONT_STYLE_NORMAL;
1693 break;
1694 case SkFontStyle::kItalic_Slant:
1695 slant = DWRITE_FONT_STYLE_ITALIC;
1696 break;
1697 default:
1698 SkASSERT(false);
1699 }
1700
1701 DWRITE_FONT_WEIGHT weight = (DWRITE_FONT_WEIGHT)pattern.weight();
1702 DWRITE_FONT_STRETCH width = (DWRITE_FONT_STRETCH)pattern.width();
1703
1704 SkTScopedComPtr<IDWriteFont> font;
1705 // TODO: perhaps use GetMatchingFonts and get the least simulated?
1706 HRNM(fFontFamily->GetFirstMatchingFont(weight, width, slant, &font),
1707 "Could not match font in family.");
1708
1709 SkTScopedComPtr<IDWriteFontFace> fontFace;
1710 HRNM(font->CreateFontFace(&fontFace), "Could not create font face.");
1711
1712 return SkCreateTypefaceFromDWriteFont(fontFace.get(), font.get(), fFontF amily.get());
1713 }
1714 1686
1715 private: 1687 private:
1716 SkAutoTUnref<const SkFontMgr_DirectWrite> fFontMgr; 1688 SkAutoTUnref<SkFontMgr_DirectWrite> fFontMgr;
1717 SkTScopedComPtr<IDWriteFontFamily> fFontFamily; 1689 SkTScopedComPtr<IDWriteFontFamily> fFontFamily;
1718 }; 1690 };
1719 1691
1720 class SkFontMgr_DirectWrite : public SkFontMgr { 1692 class SkFontMgr_DirectWrite : public SkFontMgr {
1721 public: 1693 public:
1722 /** localeNameLength must include the null terminator. */ 1694 /** localeNameLength must include the null terminator. */
1723 SkFontMgr_DirectWrite(IDWriteFontCollection* fontCollection, 1695 SkFontMgr_DirectWrite(IDWriteFontCollection* fontCollection,
1724 WCHAR* localeName, int localeNameLength) 1696 WCHAR* localeName, int localeNameLength)
1725 : fFontCollection(SkRefComPtr(fontCollection)) 1697 : fFontCollection(SkRefComPtr(fontCollection))
1726 , fLocaleName(localeNameLength) 1698 , fLocaleName(localeNameLength)
1727 { 1699 {
1728 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR)); 1700 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR));
1729 } 1701 }
1730 1702
1703 SkTypefaceCache* getTypefaceCache() { return &fTFCache; }
1704
1731 private: 1705 private:
1732 friend class SkFontStyleSet_DirectWrite; 1706 friend class SkFontStyleSet_DirectWrite;
1733 SkTScopedComPtr<IDWriteFontCollection> fFontCollection; 1707 SkTScopedComPtr<IDWriteFontCollection> fFontCollection;
1734 SkSMallocWCHAR fLocaleName; 1708 SkSMallocWCHAR fLocaleName;
1709 SkTypefaceCache fTFCache;
1735 1710
1736 protected: 1711 protected:
1737 virtual int onCountFamilies() SK_OVERRIDE { 1712 virtual int onCountFamilies() SK_OVERRIDE {
1738 return fFontCollection->GetFontFamilyCount(); 1713 return fFontCollection->GetFontFamilyCount();
1739 } 1714 }
1740 virtual void onGetFamilyName(int index, SkString* familyName) SK_OVERRIDE { 1715 virtual void onGetFamilyName(int index, SkString* familyName) SK_OVERRIDE {
1741 SkTScopedComPtr<IDWriteFontFamily> fontFamily; 1716 SkTScopedComPtr<IDWriteFontFamily> fontFamily;
1742 HRVM(fFontCollection->GetFontFamily(index, &fontFamily), "Could not get requested family."); 1717 HRVM(fFontCollection->GetFontFamily(index, &fontFamily), "Could not get requested family.");
1743 1718
1744 SkTScopedComPtr<IDWriteLocalizedStrings> familyNames; 1719 SkTScopedComPtr<IDWriteLocalizedStrings> familyNames;
(...skipping 29 matching lines...) Expand all
1774 } 1749 }
1775 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, 1750 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
1776 const SkFontStyle& fontstyle) SK_OVERRI DE { 1751 const SkFontStyle& fontstyle) SK_OVERRI DE {
1777 SkString familyName; 1752 SkString familyName;
1778 SkFontStyleSet_DirectWrite sset( 1753 SkFontStyleSet_DirectWrite sset(
1779 this, ((DWriteFontTypeface*)familyMember)->fDWriteFontFamily.get() 1754 this, ((DWriteFontTypeface*)familyMember)->fDWriteFontFamily.get()
1780 ); 1755 );
1781 return sset.matchStyle(fontstyle); 1756 return sset.matchStyle(fontstyle);
1782 } 1757 }
1783 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) SK_OV ERRIDE { 1758 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) SK_OV ERRIDE {
1784 return create_from_stream(stream, ttcIndex); 1759 return create_from_stream(stream, ttcIndex, this->getTypefaceCache());
1785 } 1760 }
1786 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) SK_OVERRIDE { 1761 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) SK_OVERRIDE {
1787 SkAutoTUnref<SkStream> stream(SkNEW_ARGS(SkMemoryStream, (data))); 1762 SkAutoTUnref<SkStream> stream(SkNEW_ARGS(SkMemoryStream, (data)));
1788 return this->createFromStream(stream, ttcIndex); 1763 return this->createFromStream(stream, ttcIndex);
1789 } 1764 }
1790 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) SK_OVE RRIDE { 1765 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) SK_OVE RRIDE {
1791 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 1766 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
1792 return this->createFromStream(stream, ttcIndex); 1767 return this->createFromStream(stream, ttcIndex);
1793 } 1768 }
1794 1769
1795 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], 1770 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
1796 unsigned styleBits) SK_OVERRIDE { 1771 unsigned styleBits) SK_OVERRIDE {
1797 return create_typeface(NULL, familyName, styleBits); 1772 return create_typeface(NULL, familyName, styleBits, this->getTypefaceCac he());
1798 } 1773 }
1799 }; 1774 };
1800 1775
1776 ///////////////////////////////////////////////////////////////////////////////
1777
1778 int SkFontStyleSet_DirectWrite::count() {
1779 return fFontFamily->GetFontCount();
1780 }
1781
1782 SkTypeface* SkFontStyleSet_DirectWrite::createTypeface(int index) {
1783 SkTScopedComPtr<IDWriteFont> font;
1784 HRNM(fFontFamily->GetFont(index, &font), "Could not get font.");
1785
1786 SkTScopedComPtr<IDWriteFontFace> fontFace;
1787 HRNM(font->CreateFontFace(&fontFace), "Could not create font face.");
1788
1789 return SkCreateTypefaceFromDWriteFont(fFontMgr->getTypefaceCache(),
1790 fontFace.get(), font.get(), fFontFam ily.get());
1791 }
1792
1801 void SkFontStyleSet_DirectWrite::getStyle(int index, SkFontStyle* fs, SkString* styleName) { 1793 void SkFontStyleSet_DirectWrite::getStyle(int index, SkFontStyle* fs, SkString* styleName) {
1802 SkTScopedComPtr<IDWriteFont> font; 1794 SkTScopedComPtr<IDWriteFont> font;
1803 HRVM(fFontFamily->GetFont(index, &font), "Could not get font."); 1795 HRVM(fFontFamily->GetFont(index, &font), "Could not get font.");
1804 1796
1805 SkFontStyle::Slant slant; 1797 SkFontStyle::Slant slant;
1806 switch (font->GetStyle()) { 1798 switch (font->GetStyle()) {
1807 case DWRITE_FONT_STYLE_NORMAL: 1799 case DWRITE_FONT_STYLE_NORMAL:
1808 slant = SkFontStyle::kUpright_Slant; 1800 slant = SkFontStyle::kUpright_Slant;
1809 break; 1801 break;
1810 case DWRITE_FONT_STYLE_OBLIQUE: 1802 case DWRITE_FONT_STYLE_OBLIQUE:
1811 case DWRITE_FONT_STYLE_ITALIC: 1803 case DWRITE_FONT_STYLE_ITALIC:
1812 slant = SkFontStyle::kItalic_Slant; 1804 slant = SkFontStyle::kItalic_Slant;
1813 break; 1805 break;
1814 default: 1806 default:
1815 SkASSERT(false); 1807 SkASSERT(false);
1816 } 1808 }
1817 1809
1818 int weight = font->GetWeight(); 1810 int weight = font->GetWeight();
1819 int width = font->GetStretch(); 1811 int width = font->GetStretch();
1820 1812
1821 *fs = SkFontStyle(weight, width, slant); 1813 *fs = SkFontStyle(weight, width, slant);
1822 1814
1823 SkTScopedComPtr<IDWriteLocalizedStrings> faceNames; 1815 SkTScopedComPtr<IDWriteLocalizedStrings> faceNames;
1824 if (SUCCEEDED(font->GetFaceNames(&faceNames))) { 1816 if (SUCCEEDED(font->GetFaceNames(&faceNames))) {
1825 get_locale_string(faceNames.get(), fFontMgr->fLocaleName.get(), styleNam e); 1817 get_locale_string(faceNames.get(), fFontMgr->fLocaleName.get(), styleNam e);
1826 } 1818 }
1827 } 1819 }
1828 1820
1821 SkTypeface* SkFontStyleSet_DirectWrite::matchStyle(const SkFontStyle& pattern) {
1822 DWRITE_FONT_STYLE slant;
1823 switch (pattern.slant()) {
1824 case SkFontStyle::kUpright_Slant:
1825 slant = DWRITE_FONT_STYLE_NORMAL;
1826 break;
1827 case SkFontStyle::kItalic_Slant:
1828 slant = DWRITE_FONT_STYLE_ITALIC;
1829 break;
1830 default:
1831 SkASSERT(false);
1832 }
1833
1834 DWRITE_FONT_WEIGHT weight = (DWRITE_FONT_WEIGHT)pattern.weight();
1835 DWRITE_FONT_STRETCH width = (DWRITE_FONT_STRETCH)pattern.width();
1836
1837 SkTScopedComPtr<IDWriteFont> font;
1838 // TODO: perhaps use GetMatchingFonts and get the least simulated?
1839 HRNM(fFontFamily->GetFirstMatchingFont(weight, width, slant, &font),
1840 "Could not match font in family.");
1841
1842 SkTScopedComPtr<IDWriteFontFace> fontFace;
1843 HRNM(font->CreateFontFace(&fontFace), "Could not create font face.");
1844
1845 return SkCreateTypefaceFromDWriteFont(fFontMgr->getTypefaceCache(),
1846 fontFace.get(), font.get(), fFontFam ily.get());
1847 }
1848
1829 /////////////////////////////////////////////////////////////////////////////// 1849 ///////////////////////////////////////////////////////////////////////////////
1830 1850
1831 #ifndef SK_FONTHOST_USES_FONTMGR 1851 #ifndef SK_FONTHOST_USES_FONTMGR
1832 1852
1833 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, 1853 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
1834 const char familyName[], 1854 const char familyName[],
1835 SkTypeface::Style style) { 1855 SkTypeface::Style style) {
1836 return create_typeface(familyFace, familyName, style); 1856 return create_typeface(familyFace, familyName, style);
1837 } 1857 }
1838 1858
1839 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { 1859 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
1840 printf("SkFontHost::CreateTypefaceFromFile unimplemented"); 1860 printf("SkFontHost::CreateTypefaceFromFile unimplemented");
1841 return NULL; 1861 return NULL;
1842 } 1862 }
1843 1863
1844 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { 1864 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
1845 return create_from_stream(stream, 0); 1865 return create_from_stream(stream, 0, NULL);
1846 } 1866 }
1847 1867
1848 #endif 1868 #endif
1849 1869
1850 SkFontMgr* SkFontMgr::Factory() { 1870 extern SkFontMgr* SkFontMgr_New_DirectWrite();
1871 SkFontMgr* SkFontMgr_New_DirectWrite() {
1851 IDWriteFactory* factory; 1872 IDWriteFactory* factory;
1852 HRNM(get_dwrite_factory(&factory), "Could not get factory."); 1873 HRNM(get_dwrite_factory(&factory), "Could not get factory.");
1853 1874
1854 SkTScopedComPtr<IDWriteFontCollection> sysFontCollection; 1875 SkTScopedComPtr<IDWriteFontCollection> sysFontCollection;
1855 HRNM(factory->GetSystemFontCollection(&sysFontCollection, FALSE), 1876 HRNM(factory->GetSystemFontCollection(&sysFontCollection, FALSE),
1856 "Could not get system font collection."); 1877 "Could not get system font collection.");
1857 1878
1858 WCHAR localeNameStorage[LOCALE_NAME_MAX_LENGTH]; 1879 WCHAR localeNameStorage[LOCALE_NAME_MAX_LENGTH];
1859 WCHAR* localeName = NULL; 1880 WCHAR* localeName = NULL;
1860 int localeNameLen = GetUserDefaultLocaleName(localeNameStorage, LOCALE_NAME_ MAX_LENGTH); 1881 int localeNameLen = GetUserDefaultLocaleName(localeNameStorage, LOCALE_NAME_ MAX_LENGTH);
1861 if (localeNameLen) { 1882 if (localeNameLen) {
1862 localeName = localeNameStorage; 1883 localeName = localeNameStorage;
1863 }; 1884 };
1864 1885
1865 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam e, localeNameLen)); 1886 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam e, localeNameLen));
1866 } 1887 }
1888
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