Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: content/child/dwrite_font_proxy/dwrite_localized_strings_win.cc

Issue 1514183002: Revert "Create direct write font proxy classes and unit tests." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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() = default;
12
13 DWriteLocalizedStrings::~DWriteLocalizedStrings() = default;
14
15 HRESULT DWriteLocalizedStrings::FindLocaleName(const WCHAR* locale_name,
16 UINT32* index,
17 BOOL* exists) {
18 for (size_t n = 0; n < strings_.size(); ++n) {
19 if (_wcsicmp(strings_[n].first.data(), locale_name) == 0) {
20 *index = n;
21 *exists = TRUE;
22 return S_OK;
23 }
24 }
25
26 *index = UINT_MAX;
27 *exists = FALSE;
28 return S_OK;
29 }
30
31 UINT32 DWriteLocalizedStrings::GetCount() {
32 return strings_.size();
33 }
34
35 HRESULT DWriteLocalizedStrings::GetLocaleName(UINT32 index,
36 WCHAR* locale_name,
37 UINT32 size) {
38 if (index >= strings_.size())
39 return E_INVALIDARG;
40 // string16::size does not count the null terminator as part of the string,
41 // but GetLocaleName requires the caller to reserve space for the null
42 // terminator, so we need to ensure |size| is greater than the count of
43 // characters.
44 if (size <= strings_[index].first.size())
45 return E_INVALIDARG;
46 wcsncpy(locale_name, strings_[index].first.c_str(), size);
47 return S_OK;
48 }
49
50 HRESULT DWriteLocalizedStrings::GetLocaleNameLength(UINT32 index,
51 UINT32* length) {
52 if (index >= strings_.size())
53 return E_INVALIDARG;
54 // Oddly, GetLocaleNameLength requires the length to not count the null
55 // terminator, even though GetLocaleName requires the output to be null
56 // terminated.
57 *length = strings_[index].first.size();
58 return S_OK;
59 }
60
61 HRESULT DWriteLocalizedStrings::GetString(UINT32 index,
62 WCHAR* string_buffer,
63 UINT32 size) {
64 if (index >= strings_.size())
65 return E_INVALIDARG;
66 // string16::size does not count the null terminator as part of the string,
67 // but GetString requires the caller to reserve space for the null terminator,
68 // so we need to ensure |size| is greater than the count of characters.
69 if (size <= strings_[index].second.size())
70 return E_INVALIDARG;
71 wcsncpy(string_buffer, strings_[index].second.c_str(), size);
72 return S_OK;
73 }
74
75 HRESULT DWriteLocalizedStrings::GetStringLength(UINT32 index, UINT32* length) {
76 if (index >= strings_.size())
77 return E_INVALIDARG;
78 // Oddly, GetStringLength requires the length to not count the null
79 // terminator, even though GetString requires the output to be null
80 // terminated.
81 *length = strings_[index].second.size();
82 return S_OK;
83 }
84
85 HRESULT DWriteLocalizedStrings::RuntimeClassInitialize(
86 std::vector<std::pair<base::string16, base::string16>>* strings) {
87 strings_.swap(*strings);
88 return S_OK;
89 }
90
91 } // namespace content
OLDNEW
« no previous file with comments | « content/child/dwrite_font_proxy/dwrite_localized_strings_win.h ('k') | content/common/content_message_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698