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

Unified 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: More codereview fixes. Jumped the gun on previous patchset. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/test/dwrite_font_fake_sender_win.h ('k') | content/test/layouttest_support.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/dwrite_font_fake_sender_win.cc
diff --git a/content/test/dwrite_font_fake_sender_win.cc b/content/test/dwrite_font_fake_sender_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4f24593e1b249130a17d5d4be4d33db22e943591
--- /dev/null
+++ b/content/test/dwrite_font_fake_sender_win.cc
@@ -0,0 +1,155 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/test/dwrite_font_fake_sender_win.h"
+
+#include <shlobj.h>
+
+#include "content/common/dwrite_font_proxy_messages.h"
+
+namespace content {
+
+void AddFamily(FakeFontCollection* collection,
+ const base::string16& font_path,
+ const base::string16& family_name,
+ const base::string16& base_family_name) {
+ collection->AddFont(family_name)
+ .AddFamilyName(L"en-us", family_name)
+ .AddFilePath(font_path + L"\\" + base_family_name + L".ttf")
+ .AddFilePath(font_path + L"\\" + base_family_name + L"bd.ttf")
+ .AddFilePath(font_path + L"\\" + base_family_name + L"bi.ttf")
+ .AddFilePath(font_path + L"\\" + base_family_name + L"i.ttf");
+}
+
+IPC::Sender* CreateFakeCollectionSender() {
+ std::vector<base::char16> font_path_chars;
+ font_path_chars.resize(MAX_PATH);
+ SHGetSpecialFolderPath(NULL /* hwndOwner - reserved */,
+ font_path_chars.data(), CSIDL_FONTS,
+ FALSE /* fCreate */);
+ base::string16 font_path(font_path_chars.data());
+ FakeFontCollection* fake_collection = new FakeFontCollection();
+ AddFamily(fake_collection, font_path, L"Arial", L"arial");
+ AddFamily(fake_collection, font_path, L"Courier New", L"cour");
+ AddFamily(fake_collection, font_path, L"Times New Roman", L"times");
+ return fake_collection->GetSender();
+}
+
+FakeFont& FakeFontCollection::AddFont(const base::string16& font_name) {
+ fonts_.emplace_back(font_name);
+ return fonts_.back();
+}
+
+unsigned int FakeFontCollection::MessageCount() {
+ return messages_.size();
+}
+
+IPC::Message* FakeFontCollection::GetMessage(unsigned int index) {
+ return messages_[index].get();
+}
+
+IPC::Sender* FakeFontCollection::GetSender() {
+ return new FakeSender(this, false);
+}
+
+IPC::Sender* FakeFontCollection::GetTrackingSender() {
+ return new FakeSender(this, true);
+}
+
+scoped_ptr<IPC::Message>& FakeFontCollection::ReplySender::OnMessageReceived(
+ const IPC::Message& msg) {
+ reply_.reset();
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(ReplySender, msg)
+ IPC_MESSAGE_HANDLER(DWriteFontProxyMsg_FindFamily, OnFindFamily)
+ IPC_MESSAGE_HANDLER(DWriteFontProxyMsg_GetFamilyCount, OnGetFamilyCount)
+ IPC_MESSAGE_HANDLER(DWriteFontProxyMsg_GetFamilyNames, OnGetFamilyNames)
+ IPC_MESSAGE_HANDLER(DWriteFontProxyMsg_GetFontFiles, OnGetFontFiles)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return reply_;
+}
+
+bool FakeFontCollection::ReplySender::Send(IPC::Message* msg) {
+ reply_.reset(msg);
+ return true;
+}
+
+void FakeFontCollection::ReplySender::OnFindFamily(
+ const base::string16& family_name,
+ uint32* index) {
+ collection_->OnFindFamily(family_name, index);
+}
+
+void FakeFontCollection::ReplySender::OnGetFamilyCount(uint32* count) {
+ collection_->OnGetFamilyCount(count);
+}
+
+void FakeFontCollection::ReplySender::OnGetFamilyNames(
+ uint32 family_index,
+ std::vector<StringPair>* family_names) {
+ collection_->OnGetFamilyNames(family_index, family_names);
+}
+
+void FakeFontCollection::ReplySender::OnGetFontFiles(
+ uint32 family_index,
+ std::vector<base::string16>* file_paths) {
+ collection_->OnGetFontFiles(family_index, file_paths);
+}
+
+bool FakeFontCollection::FakeSender::Send(IPC::Message* message) {
+ std::unique_ptr<IPC::Message> incoming_message;
+ if (track_messages_)
+ collection_->messages_.emplace_back(message);
+ else
+ incoming_message.reset(message); // Ensure message is deleted.
+ std::unique_ptr<ReplySender> sender = collection_->GetReplySender();
+ scoped_ptr<IPC::Message> reply;
+ reply.swap(sender->OnMessageReceived(*message));
+
+ IPC::SyncMessage* sync_message = reinterpret_cast<IPC::SyncMessage*>(message);
+ scoped_ptr<IPC::MessageReplyDeserializer> serializer(
+ sync_message->GetReplyDeserializer());
+ serializer->SerializeOutputParameters(*(reply.get()));
+ return true;
+}
+
+void FakeFontCollection::OnFindFamily(const base::string16& family_name,
+ uint32* index) {
+ for (unsigned int n = 0; n < fonts_.size(); n++) {
+ if (_wcsicmp(family_name.data(), fonts_[n].font_name_.data()) == 0) {
+ *index = n;
+ return;
+ }
+ }
+ *index = UINT32_MAX;
+}
+
+void FakeFontCollection::OnGetFamilyCount(uint32* count) {
+ *count = fonts_.size();
+}
+
+void FakeFontCollection::OnGetFamilyNames(
+ uint32 family_index,
+ std::vector<StringPair>* family_names) {
+ if (family_index >= fonts_.size())
+ return;
+ *family_names = fonts_[family_index].family_names_;
+}
+
+void FakeFontCollection::OnGetFontFiles(
+ uint32 family_index,
+ std::vector<base::string16>* file_paths) {
+ if (family_index >= fonts_.size())
+ return;
+ *file_paths = fonts_[family_index].file_paths_;
+}
+
+std::unique_ptr<FakeFontCollection::ReplySender>
+FakeFontCollection::GetReplySender() {
+ return std::unique_ptr<FakeFontCollection::ReplySender>(
+ new FakeFontCollection::ReplySender(this));
+}
+
+} // namespace content
« no previous file with comments | « content/test/dwrite_font_fake_sender_win.h ('k') | content/test/layouttest_support.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698