OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 #if defined(SK_BUILD_FOR_WIN32) | 9 #if defined(SK_BUILD_FOR_WIN32) |
10 | 10 |
(...skipping 1699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1710 } | 1710 } |
1711 | 1711 |
1712 void LogFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc, | 1712 void LogFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc, |
1713 bool* isLocalStream) const { | 1713 bool* isLocalStream) const { |
1714 SkString familyName; | 1714 SkString familyName; |
1715 this->onGetFamilyName(&familyName); | 1715 this->onGetFamilyName(&familyName); |
1716 desc->setFamilyName(familyName.c_str()); | 1716 desc->setFamilyName(familyName.c_str()); |
1717 *isLocalStream = this->fSerializeAsStream; | 1717 *isLocalStream = this->fSerializeAsStream; |
1718 } | 1718 } |
1719 | 1719 |
1720 static bool getWidthAdvance(HDC hdc, int gId, int16_t* advance) { | |
1721 // Initialize the MAT2 structure to the identify transformation matrix. | |
1722 static const MAT2 mat2 = {SkScalarToFIXED(1), SkScalarToFIXED(0), | |
1723 SkScalarToFIXED(0), SkScalarToFIXED(1)}; | |
1724 int flags = GGO_METRICS | GGO_GLYPH_INDEX; | |
1725 GLYPHMETRICS gm; | |
1726 if (GDI_ERROR == GetGlyphOutline(hdc, gId, flags, &gm, 0, nullptr, &mat2)) { | |
1727 return false; | |
1728 } | |
1729 SkASSERT(advance); | |
1730 *advance = gm.gmCellIncX; | |
1731 return true; | |
1732 } | |
1733 | |
1734 SkAdvancedTypefaceMetrics* LogFontTypeface::onGetAdvancedTypefaceMetrics( | 1720 SkAdvancedTypefaceMetrics* LogFontTypeface::onGetAdvancedTypefaceMetrics( |
1735 PerGlyphInfo perGlyphInfo, | 1721 PerGlyphInfo perGlyphInfo, |
1736 const uint32_t* glyphIDs, | 1722 const uint32_t* glyphIDs, |
1737 uint32_t glyphIDsCount) const { | 1723 uint32_t glyphIDsCount) const { |
1738 LOGFONT lf = fLogFont; | 1724 LOGFONT lf = fLogFont; |
1739 SkAdvancedTypefaceMetrics* info = nullptr; | 1725 SkAdvancedTypefaceMetrics* info = nullptr; |
1740 | 1726 |
1741 HDC hdc = CreateCompatibleDC(nullptr); | 1727 HDC hdc = CreateCompatibleDC(nullptr); |
1742 HFONT font = CreateFontIndirect(&lf); | 1728 HFONT font = CreateFontIndirect(&lf); |
1743 HFONT savefont = (HFONT)SelectObject(hdc, font); | 1729 HFONT savefont = (HFONT)SelectObject(hdc, font); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1832 } | 1818 } |
1833 | 1819 |
1834 if (perGlyphInfo & kHAdvance_PerGlyphInfo) { | 1820 if (perGlyphInfo & kHAdvance_PerGlyphInfo) { |
1835 if (info->fStyle & SkAdvancedTypefaceMetrics::kFixedPitch_Style) { | 1821 if (info->fStyle & SkAdvancedTypefaceMetrics::kFixedPitch_Style) { |
1836 SkAdvancedTypefaceMetrics::WidthRange range(0); | 1822 SkAdvancedTypefaceMetrics::WidthRange range(0); |
1837 range.fAdvance.append(1, &min_width); | 1823 range.fAdvance.append(1, &min_width); |
1838 SkAdvancedTypefaceMetrics::FinishRange( | 1824 SkAdvancedTypefaceMetrics::FinishRange( |
1839 &range, 0, SkAdvancedTypefaceMetrics::WidthRange::kDefault); | 1825 &range, 0, SkAdvancedTypefaceMetrics::WidthRange::kDefault); |
1840 info->fGlyphWidths.emplace_back(std::move(range)); | 1826 info->fGlyphWidths.emplace_back(std::move(range)); |
1841 } else { | 1827 } else { |
1842 info->setGlyphWidths(hdc, glyphCount, glyphIDs, | 1828 info->setGlyphWidths( |
1843 glyphIDsCount, &getWidthAdvance); | 1829 glyphCount, glyphIDs, glyphIDsCount, |
| 1830 SkAdvancedTypefaceMetrics::GetAdvance( |
| 1831 [hdc](int gId, int16_t* advance) { |
| 1832 // Initialize the MAT2 structure to |
| 1833 // the identify transformation matrix. |
| 1834 static const MAT2 mat2 = { |
| 1835 SkScalarToFIXED(1), SkScalarToFIXED(0), |
| 1836 SkScalarToFIXED(0), SkScalarToFIXED(1)}; |
| 1837 int flags = GGO_METRICS | GGO_GLYPH_INDEX; |
| 1838 GLYPHMETRICS gm; |
| 1839 if (GDI_ERROR == GetGlyphOutline( |
| 1840 hdc, gId, flags, &gm, 0, nullptr, &m
at2)) { |
| 1841 return false; |
| 1842 } |
| 1843 SkASSERT(advance); |
| 1844 *advance = gm.gmCellIncX; |
| 1845 return true; |
| 1846 })); |
1844 } | 1847 } |
1845 } | 1848 } |
1846 | 1849 |
1847 Error: | 1850 Error: |
1848 ReturnInfo: | 1851 ReturnInfo: |
1849 SelectObject(hdc, savefont); | 1852 SelectObject(hdc, savefont); |
1850 DeleteObject(designFont); | 1853 DeleteObject(designFont); |
1851 DeleteObject(font); | 1854 DeleteObject(font); |
1852 DeleteDC(hdc); | 1855 DeleteDC(hdc); |
1853 | 1856 |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2509 | 2512 |
2510 private: | 2513 private: |
2511 SkTDArray<ENUMLOGFONTEX> fLogFontArray; | 2514 SkTDArray<ENUMLOGFONTEX> fLogFontArray; |
2512 }; | 2515 }; |
2513 | 2516 |
2514 /////////////////////////////////////////////////////////////////////////////// | 2517 /////////////////////////////////////////////////////////////////////////////// |
2515 | 2518 |
2516 SkFontMgr* SkFontMgr_New_GDI() { return new SkFontMgrGDI; } | 2519 SkFontMgr* SkFontMgr_New_GDI() { return new SkFontMgrGDI; } |
2517 | 2520 |
2518 #endif//defined(SK_BUILD_FOR_WIN32) | 2521 #endif//defined(SK_BUILD_FOR_WIN32) |
OLD | NEW |