| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_win.h" | 5 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_win.h" |
| 6 | 6 |
| 7 #include <dwrite.h> | 7 #include <dwrite.h> |
| 8 #include <shlobj.h> | 8 #include <shlobj.h> |
| 9 #include <wrl.h> | 9 #include <wrl.h> |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 } | 41 } |
| 42 | 42 |
| 43 class DWriteFontProxyUnitTest : public testing::Test { | 43 class DWriteFontProxyUnitTest : public testing::Test { |
| 44 public: | 44 public: |
| 45 DWriteFontProxyUnitTest() { | 45 DWriteFontProxyUnitTest() { |
| 46 if (!factory) | 46 if (!factory) |
| 47 return; | 47 return; |
| 48 fake_collection_ = new FakeFontCollection(); | 48 fake_collection_ = new FakeFontCollection(); |
| 49 SetupFonts(fake_collection_.get()); | 49 SetupFonts(fake_collection_.get()); |
| 50 mswr::MakeAndInitialize<DWriteFontCollectionProxy>( | 50 mswr::MakeAndInitialize<DWriteFontCollectionProxy>( |
| 51 &collection_, factory.Get(), fake_collection_->GetTrackingSender()); | 51 &collection_, factory.Get(), |
| 52 base::Bind(&FakeFontCollection::GetTrackingSender, fake_collection_)); |
| 52 } | 53 } |
| 53 | 54 |
| 54 ~DWriteFontProxyUnitTest() override { | 55 ~DWriteFontProxyUnitTest() override { |
| 55 if (collection_) | 56 if (collection_) |
| 56 collection_->Unregister(); | 57 collection_->Unregister(); |
| 57 } | 58 } |
| 58 | 59 |
| 59 static void SetupFonts(FakeFontCollection* fonts) { | 60 static void SetupFonts(FakeFontCollection* fonts) { |
| 60 fonts->AddFont(L"Aardvark") | 61 fonts->AddFont(L"Aardvark") |
| 61 .AddFamilyName(L"en-us", L"Aardvark") | 62 .AddFamilyName(L"en-us", L"Aardvark") |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 scoped_refptr<FakeFontCollection> fonts = new FakeFontCollection(); | 378 scoped_refptr<FakeFontCollection> fonts = new FakeFontCollection(); |
| 378 FakeFont& arial = fonts->AddFont(L"Arial").AddFamilyName(L"en-us", L"Arial"); | 379 FakeFont& arial = fonts->AddFont(L"Arial").AddFamilyName(L"en-us", L"Arial"); |
| 379 for (auto& path : arial_font_files) { | 380 for (auto& path : arial_font_files) { |
| 380 base::File file(base::FilePath(path), base::File::FLAG_OPEN | | 381 base::File file(base::FilePath(path), base::File::FLAG_OPEN | |
| 381 base::File::FLAG_READ | | 382 base::File::FLAG_READ | |
| 382 base::File::FLAG_EXCLUSIVE_WRITE); | 383 base::File::FLAG_EXCLUSIVE_WRITE); |
| 383 arial.AddFileHandle(IPC::TakePlatformFileForTransit(std::move(file))); | 384 arial.AddFileHandle(IPC::TakePlatformFileForTransit(std::move(file))); |
| 384 } | 385 } |
| 385 mswr::ComPtr<DWriteFontCollectionProxy> collection; | 386 mswr::ComPtr<DWriteFontCollectionProxy> collection; |
| 386 mswr::MakeAndInitialize<DWriteFontCollectionProxy>( | 387 mswr::MakeAndInitialize<DWriteFontCollectionProxy>( |
| 387 &collection, factory.Get(), fonts->GetTrackingSender()); | 388 &collection, factory.Get(), |
| 389 base::Bind(&FakeFontCollection::GetTrackingSender, fonts)); |
| 388 | 390 |
| 389 // Check that we can get the font family and match a font. | 391 // Check that we can get the font family and match a font. |
| 390 UINT32 index = UINT_MAX; | 392 UINT32 index = UINT_MAX; |
| 391 BOOL exists = FALSE; | 393 BOOL exists = FALSE; |
| 392 collection->FindFamilyName(L"Arial", &index, &exists); | 394 collection->FindFamilyName(L"Arial", &index, &exists); |
| 393 mswr::ComPtr<IDWriteFontFamily> family; | 395 mswr::ComPtr<IDWriteFontFamily> family; |
| 394 collection->GetFontFamily(index, &family); | 396 collection->GetFontFamily(index, &family); |
| 395 | 397 |
| 396 mswr::ComPtr<IDWriteFont> font; | 398 mswr::ComPtr<IDWriteFont> font; |
| 397 HRESULT hr = family->GetFirstMatchingFont(DWRITE_FONT_WEIGHT_NORMAL, | 399 HRESULT hr = family->GetFirstMatchingFont(DWRITE_FONT_WEIGHT_NORMAL, |
| 398 DWRITE_FONT_STRETCH_NORMAL, | 400 DWRITE_FONT_STRETCH_NORMAL, |
| 399 DWRITE_FONT_STYLE_NORMAL, &font); | 401 DWRITE_FONT_STYLE_NORMAL, &font); |
| 400 | 402 |
| 401 EXPECT_TRUE(SUCCEEDED(hr)); | 403 EXPECT_TRUE(SUCCEEDED(hr)); |
| 402 EXPECT_NE(nullptr, font.Get()); | 404 EXPECT_NE(nullptr, font.Get()); |
| 403 | 405 |
| 404 mswr::ComPtr<IDWriteFontFace> font_face; | 406 mswr::ComPtr<IDWriteFontFace> font_face; |
| 405 hr = font->CreateFontFace(&font_face); | 407 hr = font->CreateFontFace(&font_face); |
| 406 EXPECT_TRUE(SUCCEEDED(hr)); | 408 EXPECT_TRUE(SUCCEEDED(hr)); |
| 407 } | 409 } |
| 408 | 410 |
| 409 } // namespace | 411 } // namespace |
| 410 | 412 |
| 411 } // namespace content | 413 } // namespace content |
| OLD | NEW |