| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkDWrite.h" | 8 #include "SkDWrite.h" |
| 9 #include "SkHRESULT.h" | 9 #include "SkHRESULT.h" |
| 10 #include "SkOnce.h" | 10 #include "SkOnce.h" |
| 11 #include "SkString.h" | 11 #include "SkString.h" |
| 12 | 12 |
| 13 #include <dwrite.h> | 13 #include <dwrite.h> |
| 14 | 14 |
| 15 static IDWriteFactory* gDWriteFactory = NULL; | 15 static IDWriteFactory* gDWriteFactory = nullptr; |
| 16 | 16 |
| 17 static void release_dwrite_factory() { | 17 static void release_dwrite_factory() { |
| 18 if (gDWriteFactory) { | 18 if (gDWriteFactory) { |
| 19 gDWriteFactory->Release(); | 19 gDWriteFactory->Release(); |
| 20 } | 20 } |
| 21 } | 21 } |
| 22 | 22 |
| 23 static void create_dwrite_factory(IDWriteFactory** factory) { | 23 static void create_dwrite_factory(IDWriteFactory** factory) { |
| 24 typedef decltype(DWriteCreateFactory)* DWriteCreateFactoryProc; | 24 typedef decltype(DWriteCreateFactory)* DWriteCreateFactoryProc; |
| 25 DWriteCreateFactoryProc dWriteCreateFactoryProc = reinterpret_cast<DWriteCre
ateFactoryProc>( | 25 DWriteCreateFactoryProc dWriteCreateFactoryProc = reinterpret_cast<DWriteCre
ateFactoryProc>( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 45 IDWriteFactory* sk_get_dwrite_factory() { | 45 IDWriteFactory* sk_get_dwrite_factory() { |
| 46 SkOnce(&once, create_dwrite_factory, &gDWriteFactory); | 46 SkOnce(&once, create_dwrite_factory, &gDWriteFactory); |
| 47 return gDWriteFactory; | 47 return gDWriteFactory; |
| 48 } | 48 } |
| 49 | 49 |
| 50 //////////////////////////////////////////////////////////////////////////////// | 50 //////////////////////////////////////////////////////////////////////////////// |
| 51 // String conversion | 51 // String conversion |
| 52 | 52 |
| 53 /** Converts a utf8 string to a WCHAR string. */ | 53 /** Converts a utf8 string to a WCHAR string. */ |
| 54 HRESULT sk_cstring_to_wchar(const char* skname, SkSMallocWCHAR* name) { | 54 HRESULT sk_cstring_to_wchar(const char* skname, SkSMallocWCHAR* name) { |
| 55 int wlen = MultiByteToWideChar(CP_UTF8, 0, skname, -1, NULL, 0); | 55 int wlen = MultiByteToWideChar(CP_UTF8, 0, skname, -1, nullptr, 0); |
| 56 if (0 == wlen) { | 56 if (0 == wlen) { |
| 57 HRM(HRESULT_FROM_WIN32(GetLastError()), | 57 HRM(HRESULT_FROM_WIN32(GetLastError()), |
| 58 "Could not get length for wchar to utf-8 conversion."); | 58 "Could not get length for wchar to utf-8 conversion."); |
| 59 } | 59 } |
| 60 name->reset(wlen); | 60 name->reset(wlen); |
| 61 wlen = MultiByteToWideChar(CP_UTF8, 0, skname, -1, name->get(), wlen); | 61 wlen = MultiByteToWideChar(CP_UTF8, 0, skname, -1, name->get(), wlen); |
| 62 if (0 == wlen) { | 62 if (0 == wlen) { |
| 63 HRM(HRESULT_FROM_WIN32(GetLastError()), "Could not convert wchar to utf-
8."); | 63 HRM(HRESULT_FROM_WIN32(GetLastError()), "Could not convert wchar to utf-
8."); |
| 64 } | 64 } |
| 65 return S_OK; | 65 return S_OK; |
| 66 } | 66 } |
| 67 | 67 |
| 68 /** Converts a WCHAR string to a utf8 string. */ | 68 /** Converts a WCHAR string to a utf8 string. */ |
| 69 HRESULT sk_wchar_to_skstring(WCHAR* name, int nameLen, SkString* skname) { | 69 HRESULT sk_wchar_to_skstring(WCHAR* name, int nameLen, SkString* skname) { |
| 70 int len = WideCharToMultiByte(CP_UTF8, 0, name, nameLen, NULL, 0, NULL, NULL
); | 70 int len = WideCharToMultiByte(CP_UTF8, 0, name, nameLen, nullptr, 0, nullptr
, nullptr); |
| 71 if (0 == len) { | 71 if (0 == len) { |
| 72 if (nameLen <= 0) { | 72 if (nameLen <= 0) { |
| 73 skname->reset(); | 73 skname->reset(); |
| 74 return S_OK; | 74 return S_OK; |
| 75 } | 75 } |
| 76 HRM(HRESULT_FROM_WIN32(GetLastError()), | 76 HRM(HRESULT_FROM_WIN32(GetLastError()), |
| 77 "Could not get length for utf-8 to wchar conversion."); | 77 "Could not get length for utf-8 to wchar conversion."); |
| 78 } | 78 } |
| 79 skname->resize(len); | 79 skname->resize(len); |
| 80 | 80 |
| 81 len = WideCharToMultiByte(CP_UTF8, 0, name, nameLen, skname->writable_str(),
len, NULL, NULL); | 81 len = WideCharToMultiByte(CP_UTF8, 0, name, nameLen, skname->writable_str(),
len, nullptr, nullptr); |
| 82 if (0 == len) { | 82 if (0 == len) { |
| 83 HRM(HRESULT_FROM_WIN32(GetLastError()), "Could not convert utf-8 to wcha
r."); | 83 HRM(HRESULT_FROM_WIN32(GetLastError()), "Could not convert utf-8 to wcha
r."); |
| 84 } | 84 } |
| 85 return S_OK; | 85 return S_OK; |
| 86 } | 86 } |
| 87 | 87 |
| 88 //////////////////////////////////////////////////////////////////////////////// | 88 //////////////////////////////////////////////////////////////////////////////// |
| 89 // Locale | 89 // Locale |
| 90 | 90 |
| 91 void sk_get_locale_string(IDWriteLocalizedStrings* names, const WCHAR* preferedL
ocale, | 91 void sk_get_locale_string(IDWriteLocalizedStrings* names, const WCHAR* preferedL
ocale, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 115 ); | 115 ); |
| 116 if (!*proc) { | 116 if (!*proc) { |
| 117 HRESULT hr = HRESULT_FROM_WIN32(GetLastError()); | 117 HRESULT hr = HRESULT_FROM_WIN32(GetLastError()); |
| 118 if (!IS_ERROR(hr)) { | 118 if (!IS_ERROR(hr)) { |
| 119 hr = ERROR_PROC_NOT_FOUND; | 119 hr = ERROR_PROC_NOT_FOUND; |
| 120 } | 120 } |
| 121 return hr; | 121 return hr; |
| 122 } | 122 } |
| 123 return S_OK; | 123 return S_OK; |
| 124 } | 124 } |
| OLD | NEW |