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 1706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1717 glyphCount, | 1717 glyphCount, |
1718 glyphIDs, | 1718 glyphIDs, |
1719 glyphIDsCount, | 1719 glyphIDsCount, |
1720 getWidthAdvance)); | 1720 getWidthAdvance)); |
1721 } | 1721 } |
1722 } | 1722 } |
1723 | 1723 |
1724 return info; | 1724 return info; |
1725 } | 1725 } |
1726 | 1726 |
1727 static SkTypeface* create_typeface(const SkTypeface* familyFace, | |
1728 const char familyName[], | |
1729 unsigned style, | |
1730 SkFontMgr_DirectWrite* fontMgr) { | |
1731 HRESULT hr; | |
1732 SkTScopedComPtr<IDWriteFontFamily> fontFamily; | |
1733 if (familyFace) { | |
1734 const DWriteFontTypeface* face = static_cast<const DWriteFontTypeface*>(
familyFace); | |
1735 *(&fontFamily) = SkRefComPtr(face->fDWriteFontFamily.get()); | |
1736 | |
1737 } else if (familyName) { | |
1738 hr = get_by_family_name(familyName, &fontFamily); | |
1739 } | |
1740 | |
1741 if (NULL == fontFamily.get()) { | |
1742 //No good family found, go with default. | |
1743 SkTScopedComPtr<IDWriteFont> font; | |
1744 hr = get_default_font(&font); | |
1745 hr = font->GetFontFamily(&fontFamily); | |
1746 } | |
1747 | |
1748 SkTScopedComPtr<IDWriteFont> font; | |
1749 DWRITE_FONT_WEIGHT weight = (style & SkTypeface::kBold) | |
1750 ? DWRITE_FONT_WEIGHT_BOLD | |
1751 : DWRITE_FONT_WEIGHT_NORMAL; | |
1752 DWRITE_FONT_STRETCH stretch = DWRITE_FONT_STRETCH_UNDEFINED; | |
1753 DWRITE_FONT_STYLE italic = (style & SkTypeface::kItalic) | |
1754 ? DWRITE_FONT_STYLE_ITALIC | |
1755 : DWRITE_FONT_STYLE_NORMAL; | |
1756 hr = fontFamily->GetFirstMatchingFont(weight, stretch, italic, &font); | |
1757 | |
1758 SkTScopedComPtr<IDWriteFontFace> fontFace; | |
1759 hr = font->CreateFontFace(&fontFace); | |
1760 | |
1761 return fontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fon
tFamily.get()); | |
1762 } | |
1763 | |
1764 /////////////////////////////////////////////////////////////////////////////// | 1727 /////////////////////////////////////////////////////////////////////////////// |
1765 | 1728 |
1766 static void get_locale_string(IDWriteLocalizedStrings* names, const WCHAR* prefe
redLocale, | 1729 static void get_locale_string(IDWriteLocalizedStrings* names, const WCHAR* prefe
redLocale, |
1767 SkString* skname) { | 1730 SkString* skname) { |
1768 UINT32 nameIndex = 0; | 1731 UINT32 nameIndex = 0; |
1769 if (preferedLocale) { | 1732 if (preferedLocale) { |
1770 // Ignore any errors and continue with index 0 if there is a problem. | 1733 // Ignore any errors and continue with index 0 if there is a problem. |
1771 BOOL nameExists; | 1734 BOOL nameExists; |
1772 names->FindLocaleName(preferedLocale, &nameIndex, &nameExists); | 1735 names->FindLocaleName(preferedLocale, &nameIndex, &nameExists); |
1773 if (!nameExists) { | 1736 if (!nameExists) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1862 return this->createFromStream(stream, ttcIndex); | 1825 return this->createFromStream(stream, ttcIndex); |
1863 } | 1826 } |
1864 | 1827 |
1865 SkTypeface* SkFontMgr_DirectWrite::onCreateFromFile(const char path[], int ttcIn
dex) { | 1828 SkTypeface* SkFontMgr_DirectWrite::onCreateFromFile(const char path[], int ttcIn
dex) { |
1866 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | 1829 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); |
1867 return this->createFromStream(stream, ttcIndex); | 1830 return this->createFromStream(stream, ttcIndex); |
1868 } | 1831 } |
1869 | 1832 |
1870 SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[
], | 1833 SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[
], |
1871 unsigned styleBits) { | 1834 unsigned styleBits) { |
1872 return create_typeface(NULL, familyName, styleBits, this); | 1835 SkTScopedComPtr<IDWriteFontFamily> fontFamily; |
| 1836 if (familyName) { |
| 1837 get_by_family_name(familyName, &fontFamily); |
| 1838 } |
| 1839 |
| 1840 if (NULL == fontFamily.get()) { |
| 1841 //No good family found, go with default. |
| 1842 SkTScopedComPtr<IDWriteFont> defaultFont; |
| 1843 HRNM(get_default_font(&defaultFont), "Could not get default font."); |
| 1844 HRNM(defaultFont->GetFontFamily(&fontFamily), "Could not get default fon
t family."); |
| 1845 } |
| 1846 |
| 1847 SkTScopedComPtr<IDWriteFont> font; |
| 1848 DWRITE_FONT_WEIGHT weight = (styleBits & SkTypeface::kBold) |
| 1849 ? DWRITE_FONT_WEIGHT_BOLD |
| 1850 : DWRITE_FONT_WEIGHT_NORMAL; |
| 1851 DWRITE_FONT_STRETCH stretch = DWRITE_FONT_STRETCH_UNDEFINED; |
| 1852 DWRITE_FONT_STYLE italic = (styleBits & SkTypeface::kItalic) |
| 1853 ? DWRITE_FONT_STYLE_ITALIC |
| 1854 : DWRITE_FONT_STYLE_NORMAL; |
| 1855 HRNM(fontFamily->GetFirstMatchingFont(weight, stretch, italic, &font), |
| 1856 "Could not get matching font."); |
| 1857 |
| 1858 SkTScopedComPtr<IDWriteFontFace> fontFace; |
| 1859 HRNM(font->CreateFontFace(&fontFace), "Could not create font face."); |
| 1860 |
| 1861 return this->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFa
mily.get()); |
1873 } | 1862 } |
1874 | 1863 |
1875 /////////////////////////////////////////////////////////////////////////////// | 1864 /////////////////////////////////////////////////////////////////////////////// |
1876 | 1865 |
1877 int SkFontStyleSet_DirectWrite::count() { | 1866 int SkFontStyleSet_DirectWrite::count() { |
1878 return fFontFamily->GetFontCount(); | 1867 return fFontFamily->GetFontCount(); |
1879 } | 1868 } |
1880 | 1869 |
1881 SkTypeface* SkFontStyleSet_DirectWrite::createTypeface(int index) { | 1870 SkTypeface* SkFontStyleSet_DirectWrite::createTypeface(int index) { |
1882 SkTScopedComPtr<IDWriteFont> font; | 1871 SkTScopedComPtr<IDWriteFont> font; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1980 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); | 1969 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); |
1981 } else { | 1970 } else { |
1982 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N
AME_MAX_LENGTH); | 1971 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N
AME_MAX_LENGTH); |
1983 if (localeNameLen) { | 1972 if (localeNameLen) { |
1984 localeName = localeNameStorage; | 1973 localeName = localeNameStorage; |
1985 }; | 1974 }; |
1986 } | 1975 } |
1987 | 1976 |
1988 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam
e, localeNameLen)); | 1977 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam
e, localeNameLen)); |
1989 } | 1978 } |
OLD | NEW |