| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/font_fallback_win.h" | 5 #include "content/child/dwrite_font_proxy/font_fallback_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 |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_win.h" | 14 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_win.h" |
| 15 #include "content/test/dwrite_font_fake_sender_win.h" | 15 #include "content/test/dwrite_font_fake_sender_win.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/gfx/win/text_analysis_source.h" | 17 #include "ui/gfx/win/text_analysis_source.h" |
| 18 | 18 |
| 19 namespace mswr = Microsoft::WRL; | 19 namespace mswr = Microsoft::WRL; |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 class FontFallbackUnitTest : public testing::Test { | 25 class FontFallbackUnitTest : public testing::Test { |
| 26 public: | 26 public: |
| 27 FontFallbackUnitTest() { | 27 FontFallbackUnitTest() { |
| 28 DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), | 28 CreateDWriteFactory(&factory_); |
| 29 &factory_); | |
| 30 | 29 |
| 31 factory_->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD_NONE, | 30 factory_->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD_NONE, |
| 32 L"en-us", true /* ignoreUserOverride */, | 31 L"en-us", true /* ignoreUserOverride */, |
| 33 &number_substitution_); | 32 &number_substitution_); |
| 34 | 33 |
| 35 std::vector<base::char16> font_path; | 34 std::vector<base::char16> font_path; |
| 36 font_path.resize(MAX_PATH); | 35 font_path.resize(MAX_PATH); |
| 37 SHGetSpecialFolderPath(nullptr /* hwndOwner - reserved */, font_path.data(), | 36 SHGetSpecialFolderPath(nullptr /* hwndOwner - reserved */, font_path.data(), |
| 38 CSIDL_FONTS, FALSE /* fCreate*/); | 37 CSIDL_FONTS, FALSE /* fCreate*/); |
| 39 base::string16 segoe_path; | 38 base::string16 segoe_path; |
| 40 segoe_path.append(font_path.data()).append(L"\\seguisym.ttf"); | 39 segoe_path.append(font_path.data()).append(L"\\seguisym.ttf"); |
| 41 | 40 |
| 42 fake_collection_ = new FakeFontCollection(); | 41 fake_collection_ = new FakeFontCollection(); |
| 43 fake_collection_->AddFont(L"Segoe UI Symbol") | 42 fake_collection_->AddFont(L"Segoe UI Symbol") |
| 44 .AddFamilyName(L"en-us", L"Segoe UI Symbol") | 43 .AddFamilyName(L"en-us", L"Segoe UI Symbol") |
| 45 .AddFilePath(segoe_path); | 44 .AddFilePath(segoe_path); |
| 46 | 45 |
| 47 mswr::MakeAndInitialize<DWriteFontCollectionProxy>( | 46 mswr::MakeAndInitialize<DWriteFontCollectionProxy>( |
| 48 &collection_, factory_.Get(), fake_collection_->GetSender()); | 47 &collection_, factory_.Get(), fake_collection_->GetSender()); |
| 49 } | 48 } |
| 50 | 49 |
| 50 void CreateDWriteFactory(IUnknown** factory) { |
| 51 using DWriteCreateFactoryProc = decltype(DWriteCreateFactory)*; |
| 52 HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll"); |
| 53 if (!dwrite_dll) |
| 54 return; |
| 55 |
| 56 DWriteCreateFactoryProc dwrite_create_factory_proc = |
| 57 reinterpret_cast<DWriteCreateFactoryProc>( |
| 58 GetProcAddress(dwrite_dll, "DWriteCreateFactory")); |
| 59 if (!dwrite_create_factory_proc) |
| 60 return; |
| 61 |
| 62 dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_SHARED, |
| 63 __uuidof(IDWriteFactory), factory); |
| 64 } |
| 65 |
| 51 scoped_refptr<FakeFontCollection> fake_collection_; | 66 scoped_refptr<FakeFontCollection> fake_collection_; |
| 52 mswr::ComPtr<IDWriteFactory> factory_; | 67 mswr::ComPtr<IDWriteFactory> factory_; |
| 53 mswr::ComPtr<DWriteFontCollectionProxy> collection_; | 68 mswr::ComPtr<DWriteFontCollectionProxy> collection_; |
| 54 mswr::ComPtr<IDWriteNumberSubstitution> number_substitution_; | 69 mswr::ComPtr<IDWriteNumberSubstitution> number_substitution_; |
| 55 }; | 70 }; |
| 56 | 71 |
| 57 TEST_F(FontFallbackUnitTest, MapCharacters) { | 72 TEST_F(FontFallbackUnitTest, MapCharacters) { |
| 58 mswr::ComPtr<FontFallback> fallback; | 73 mswr::ComPtr<FontFallback> fallback; |
| 59 mswr::MakeAndInitialize<FontFallback>(&fallback, collection_.Get(), | 74 mswr::MakeAndInitialize<FontFallback>(&fallback, collection_.Get(), |
| 60 fake_collection_->GetSender()); | 75 fake_collection_->GetSender()); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, | 197 DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, |
| 183 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, &font, | 198 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, &font, |
| 184 &scale); | 199 &scale); |
| 185 | 200 |
| 186 EXPECT_EQ(1u, fake_collection_->MessageCount()); | 201 EXPECT_EQ(1u, fake_collection_->MessageCount()); |
| 187 EXPECT_EQ(2u, mapped_length); | 202 EXPECT_EQ(2u, mapped_length); |
| 188 } | 203 } |
| 189 | 204 |
| 190 } // namespace | 205 } // namespace |
| 191 } // namespace content | 206 } // namespace content |
| OLD | NEW |