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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } | 61 } |
62 | 62 |
63 /** Converts a WCHAR string to a utf8 string. */ | 63 /** Converts a WCHAR string to a utf8 string. */ |
64 static HRESULT wchar_to_skstring(WCHAR* name, SkString* skname) { | 64 static HRESULT wchar_to_skstring(WCHAR* name, SkString* skname) { |
65 int len = WideCharToMultiByte(CP_UTF8, 0, name, -1, NULL, 0, NULL, NULL); | 65 int len = WideCharToMultiByte(CP_UTF8, 0, name, -1, NULL, 0, NULL, NULL); |
66 if (0 == len) { | 66 if (0 == len) { |
67 HRM(HRESULT_FROM_WIN32(GetLastError()), | 67 HRM(HRESULT_FROM_WIN32(GetLastError()), |
68 "Could not get length for utf-8 to wchar conversion."); | 68 "Could not get length for utf-8 to wchar conversion."); |
69 } | 69 } |
70 skname->resize(len - 1); | 70 skname->resize(len - 1); |
| 71 |
| 72 // TODO: remove after https://code.google.com/p/skia/issues/detail?id=1989 i
s fixed. |
| 73 // If we resize to 0 then the skname points to gEmptyRec (the unique empty S
kString::Rec). |
| 74 // gEmptyRec is static const and on Windows this means the value is in a rea
d only page. |
| 75 // Writing to it in the following call to WideCharToMultiByte will cause an
access violation. |
| 76 if (1 == len) { |
| 77 return S_OK; |
| 78 } |
| 79 |
71 len = WideCharToMultiByte(CP_UTF8, 0, name, -1, skname->writable_str(), len,
NULL, NULL); | 80 len = WideCharToMultiByte(CP_UTF8, 0, name, -1, skname->writable_str(), len,
NULL, NULL); |
72 if (0 == len) { | 81 if (0 == len) { |
73 HRM(HRESULT_FROM_WIN32(GetLastError()), "Could not convert utf-8 to wcha
r."); | 82 HRM(HRESULT_FROM_WIN32(GetLastError()), "Could not convert utf-8 to wcha
r."); |
74 } | 83 } |
75 return S_OK; | 84 return S_OK; |
76 } | 85 } |
77 | 86 |
78 /////////////////////////////////////////////////////////////////////////////// | 87 /////////////////////////////////////////////////////////////////////////////// |
79 | 88 |
80 static void create_dwrite_factory(IDWriteFactory** factory) { | 89 static void create_dwrite_factory(IDWriteFactory** factory) { |
(...skipping 1822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1903 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); | 1912 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); |
1904 } else { | 1913 } else { |
1905 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N
AME_MAX_LENGTH); | 1914 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N
AME_MAX_LENGTH); |
1906 if (localeNameLen) { | 1915 if (localeNameLen) { |
1907 localeName = localeNameStorage; | 1916 localeName = localeNameStorage; |
1908 }; | 1917 }; |
1909 } | 1918 } |
1910 | 1919 |
1911 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam
e, localeNameLen)); | 1920 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam
e, localeNameLen)); |
1912 } | 1921 } |
OLD | NEW |