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 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 HRESULT hr; |
| 1836 SkTScopedComPtr<IDWriteFontFamily> fontFamily; | |
| 1837 if (familyName) { | |
| 1838 hr = get_by_family_name(familyName, &fontFamily); | |
|
caryclark
2013/11/19 21:56:39
if 'hr' is always effectively discarded, would
bungeman-skia
2013/11/19 22:27:34
Yes, well, it's here because it's a big red flag t
| |
| 1839 } | |
| 1840 | |
| 1841 if (NULL == fontFamily.get()) { | |
| 1842 //No good family found, go with default. | |
| 1843 SkTScopedComPtr<IDWriteFont> font; | |
| 1844 hr = get_default_font(&font); | |
|
caryclark
2013/11/19 21:56:39
I see that 'font' here is not the same as 'font' b
bungeman-skia
2013/11/19 22:27:34
Done. Yes, this is a bit confusing, renamed this o
| |
| 1845 hr = font->GetFontFamily(&fontFamily); | |
| 1846 } | |
| 1847 | |
| 1848 SkTScopedComPtr<IDWriteFont> font; | |
| 1849 DWRITE_FONT_WEIGHT weight = (styleBits & SkTypeface::kBold) | |
| 1850 ? DWRITE_FONT_WEIGHT_BOLD | |
| 1851 : DWRITE_FONT_WEIGHT_NORMAL; | |
| 1852 DWRITE_FONT_STRETCH stretch = DWRITE_FONT_STRETCH_UNDEFINED; | |
| 1853 DWRITE_FONT_STYLE italic = (styleBits & SkTypeface::kItalic) | |
| 1854 ? DWRITE_FONT_STYLE_ITALIC | |
| 1855 : DWRITE_FONT_STYLE_NORMAL; | |
| 1856 hr = fontFamily->GetFirstMatchingFont(weight, stretch, italic, &font); | |
| 1857 | |
| 1858 SkTScopedComPtr<IDWriteFontFace> fontFace; | |
| 1859 hr = font->CreateFontFace(&fontFace); | |
| 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 |