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

Side by Side Diff: content/test/dwrite_font_fake_sender_win.cc

Issue 1378353006: Implementation of dwrite font proxy and removal of dwrite font cache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge to head Created 5 years, 1 month 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/test/dwrite_font_fake_sender_win.h"
6
7 #include <shlobj.h>
8
9 #include "content/common/dwrite_font_proxy_messages.h"
10
11 namespace content {
12
13 void AddFamily(FakeFontCollection* collection,
14 const base::string16& fontPath,
15 const base::string16& familyName,
16 const base::string16& baseFileName) {
17 collection->AddFont(familyName)
18 .AddFamilyName(L"en-us", familyName)
19 .AddFilePath(fontPath + L"\\" + baseFileName + L".ttf")
20 .AddFilePath(fontPath + L"\\" + baseFileName + L"bd.ttf")
21 .AddFilePath(fontPath + L"\\" + baseFileName + L"bi.ttf")
22 .AddFilePath(fontPath + L"\\" + baseFileName + L"i.ttf");
23 }
24
25 IPC::Sender* CreateFakeCollectionSender() {
26 std::vector<base::char16> fontPathChars;
27 fontPathChars.resize(MAX_PATH);
28 SHGetSpecialFolderPath(NULL /* hwndOwner - reserved */, fontPathChars.data(),
29 CSIDL_FONTS, FALSE /* fCreate */);
30 base::string16 fontPath(fontPathChars.data());
31 FakeFontCollection* fakeCollection = new FakeFontCollection();
32 AddFamily(fakeCollection, fontPath, L"Arial", L"arial");
33 AddFamily(fakeCollection, fontPath, L"Courier New", L"cour");
34 AddFamily(fakeCollection, fontPath, L"Times New Roman", L"times");
35 return fakeCollection->GetSender();
36 }
37
38 FakeFont& FakeFontCollection::AddFont(const base::string16& fontName) {
39 fonts_.emplace_back(fontName);
40 return fonts_.back();
41 }
42
43 unsigned int FakeFontCollection::MessageCount() {
44 return messages_.size();
45 }
46
47 IPC::Message* FakeFontCollection::GetMessage(unsigned int index) {
48 return messages_[index].get();
49 }
50
51 IPC::Sender* FakeFontCollection::GetSender() {
52 return new FakeSender(this, false);
53 }
54
55 IPC::Sender* FakeFontCollection::GetTrackingSender() {
56 return new FakeSender(this, true);
57 }
58
59 scoped_ptr<IPC::Message>& FakeFontCollection::ReplySender::OnMessageReceived(
60 const IPC::Message& msg) {
61 reply_.reset();
62 bool handled = true;
63 IPC_BEGIN_MESSAGE_MAP(ReplySender, msg)
64 IPC_MESSAGE_HANDLER(DWriteFontProxyMsg_FindFamily, OnFindFamily)
65 IPC_MESSAGE_HANDLER(DWriteFontProxyMsg_GetFamilyCount, OnGetFamilyCount)
66 IPC_MESSAGE_HANDLER(DWriteFontProxyMsg_GetFamilyNames, OnGetFamilyNames)
67 IPC_MESSAGE_HANDLER(DWriteFontProxyMsg_GetFontFiles, OnGetFontFiles)
68 IPC_MESSAGE_UNHANDLED(handled = false)
69 IPC_END_MESSAGE_MAP()
70 return reply_;
71 }
72
73 bool FakeFontCollection::ReplySender::Send(IPC::Message* msg) {
74 reply_.reset(msg);
75 return true;
76 }
77
78 void FakeFontCollection::ReplySender::OnFindFamily(
79 const base::string16& familyName,
80 uint32* index) {
81 collection_->OnFindFamily(familyName, index);
82 }
83
84 void FakeFontCollection::ReplySender::OnGetFamilyCount(uint32* count) {
85 collection_->OnGetFamilyCount(count);
86 }
87
88 void FakeFontCollection::ReplySender::OnGetFamilyNames(
89 uint32 familyIndex,
90 std::vector<StringPair>* familyNames) {
91 collection_->OnGetFamilyNames(familyIndex, familyNames);
92 }
93
94 void FakeFontCollection::ReplySender::OnGetFontFiles(
95 uint32 familyIndex,
96 std::vector<base::string16>* filePaths) {
97 collection_->OnGetFontFiles(familyIndex, filePaths);
98 }
99
100 bool FakeFontCollection::FakeSender::Send(IPC::Message* message) {
101 std::unique_ptr<IPC::Message> incomingMessage;
102 if (trackMessages_)
103 collection_->messages_.emplace_back(message);
104 else
105 incomingMessage.reset(message); // Ensure message is deleted.
106 std::unique_ptr<ReplySender> sender = collection_->GetReplySender();
107 scoped_ptr<IPC::Message> reply;
108 reply.swap(sender->OnMessageReceived(*message));
109
110 IPC::SyncMessage* syncMessage = reinterpret_cast<IPC::SyncMessage*>(message);
111 scoped_ptr<IPC::MessageReplyDeserializer> serializer(
112 syncMessage->GetReplyDeserializer());
113 serializer->SerializeOutputParameters(*(reply.get()));
114 return true;
115 }
116
117 void FakeFontCollection::OnFindFamily(const base::string16& familyName,
118 uint32* index) {
119 for (unsigned int n = 0; n < fonts_.size(); n++) {
120 if (_wcsicmp(familyName.data(), fonts_[n].fontName.data()) == 0) {
121 *index = n;
122 return;
123 }
124 }
125 *index = UINT32_MAX;
126 }
127
128 void FakeFontCollection::OnGetFamilyCount(uint32* count) {
129 *count = fonts_.size();
130 }
131
132 void FakeFontCollection::OnGetFamilyNames(
133 uint32 familyIndex,
134 std::vector<StringPair>* familyNames) {
135 if (familyIndex >= fonts_.size())
136 return;
137 *familyNames = fonts_[familyIndex].familyNames;
138 }
139
140 void FakeFontCollection::OnGetFontFiles(
141 uint32 familyIndex,
142 std::vector<base::string16>* filePaths) {
143 if (familyIndex >= fonts_.size())
144 return;
145 *filePaths = fonts_[familyIndex].filePaths;
146 }
147
148 std::unique_ptr<FakeFontCollection::ReplySender>
149 FakeFontCollection::GetReplySender() {
150 return std::unique_ptr<FakeFontCollection::ReplySender>(
151 new FakeFontCollection::ReplySender(this));
152 }
153
154 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698