| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/child/dwrite_font_proxy/dwrite_localized_strings_win.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 namespace content { | |
| 10 | |
| 11 DWriteLocalizedStrings::~DWriteLocalizedStrings() {} | |
| 12 | |
| 13 HRESULT DWriteLocalizedStrings::FindLocaleName(const WCHAR* locale_name, | |
| 14 UINT32* index, | |
| 15 BOOL* exists) { | |
| 16 for (size_t n = 0; n < strings_.size(); ++n) { | |
| 17 if (_wcsicmp(strings_[n].first.data(), locale_name) == 0) { | |
| 18 *index = n; | |
| 19 *exists = TRUE; | |
| 20 return S_OK; | |
| 21 } | |
| 22 } | |
| 23 | |
| 24 *index = UINT_MAX; | |
| 25 *exists = FALSE; | |
| 26 return S_OK; | |
| 27 } | |
| 28 | |
| 29 UINT32 DWriteLocalizedStrings::GetCount() { | |
| 30 return strings_.size(); | |
| 31 } | |
| 32 | |
| 33 HRESULT DWriteLocalizedStrings::GetLocaleName(UINT32 index, | |
| 34 WCHAR* locale_name, | |
| 35 UINT32 size) { | |
| 36 if (index >= strings_.size()) | |
| 37 return E_INVALIDARG; | |
| 38 // string16::size does not count the null terminator as part of the string, | |
| 39 // but GetLocaleName requires the caller to reserve space for the null | |
| 40 // terminator, so we need to ensure |size| is greater than the count of | |
| 41 // characters. | |
| 42 if (size <= strings_[index].first.size()) | |
| 43 return E_INVALIDARG; | |
| 44 wcsncpy(locale_name, strings_[index].first.c_str(), size); | |
| 45 return S_OK; | |
| 46 } | |
| 47 | |
| 48 HRESULT DWriteLocalizedStrings::GetLocaleNameLength(UINT32 index, | |
| 49 UINT32* length) { | |
| 50 if (index >= strings_.size()) | |
| 51 return E_INVALIDARG; | |
| 52 // Oddly, GetLocaleNameLength requires the length to not count the null | |
| 53 // terminator, even though GetLocaleName requires the output to be null | |
| 54 // terminated. | |
| 55 *length = strings_[index].first.size(); | |
| 56 return S_OK; | |
| 57 } | |
| 58 | |
| 59 HRESULT DWriteLocalizedStrings::GetString(UINT32 index, | |
| 60 WCHAR* string_buffer, | |
| 61 UINT32 size) { | |
| 62 if (index >= strings_.size()) | |
| 63 return E_INVALIDARG; | |
| 64 // string16::size does not count the null terminator as part of the string, | |
| 65 // but GetString requires the caller to reserve space for the null terminator, | |
| 66 // so we need to ensure |size| is greater than the count of characters. | |
| 67 if (size <= strings_[index].second.size()) | |
| 68 return E_INVALIDARG; | |
| 69 wcsncpy(string_buffer, strings_[index].second.c_str(), size); | |
| 70 return S_OK; | |
| 71 } | |
| 72 | |
| 73 HRESULT DWriteLocalizedStrings::GetStringLength(UINT32 index, UINT32* length) { | |
| 74 if (index >= strings_.size()) | |
| 75 return E_INVALIDARG; | |
| 76 // Oddly, GetStringLength requires the length to not count the null | |
| 77 // terminator, even though GetString requires the output to be null | |
| 78 // terminated. | |
| 79 *length = strings_[index].second.size(); | |
| 80 return S_OK; | |
| 81 } | |
| 82 | |
| 83 HRESULT DWriteLocalizedStrings::RuntimeClassInitialize( | |
| 84 std::vector<std::pair<base::string16, base::string16>>* strings) { | |
| 85 strings_.swap(*strings); | |
| 86 return S_OK; | |
| 87 } | |
| 88 | |
| 89 } // namespace content | |
| OLD | NEW |