| 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 CreateDWriteFactory(&factory_); | 28 DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), |
| 29 &factory_); |
| 29 | 30 |
| 30 factory_->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD_NONE, | 31 factory_->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD_NONE, |
| 31 L"en-us", true /* ignoreUserOverride */, | 32 L"en-us", true /* ignoreUserOverride */, |
| 32 &number_substitution_); | 33 &number_substitution_); |
| 33 | 34 |
| 34 std::vector<base::char16> font_path; | 35 std::vector<base::char16> font_path; |
| 35 font_path.resize(MAX_PATH); | 36 font_path.resize(MAX_PATH); |
| 36 SHGetSpecialFolderPath(nullptr /* hwndOwner - reserved */, font_path.data(), | 37 SHGetSpecialFolderPath(nullptr /* hwndOwner - reserved */, font_path.data(), |
| 37 CSIDL_FONTS, FALSE /* fCreate*/); | 38 CSIDL_FONTS, FALSE /* fCreate*/); |
| 38 base::string16 segoe_path; | 39 base::string16 segoe_path; |
| 39 segoe_path.append(font_path.data()).append(L"\\seguisym.ttf"); | 40 segoe_path.append(font_path.data()).append(L"\\seguisym.ttf"); |
| 40 | 41 |
| 41 fake_collection_ = new FakeFontCollection(); | 42 fake_collection_ = new FakeFontCollection(); |
| 42 fake_collection_->AddFont(L"Segoe UI Symbol") | 43 fake_collection_->AddFont(L"Segoe UI Symbol") |
| 43 .AddFamilyName(L"en-us", L"Segoe UI Symbol") | 44 .AddFamilyName(L"en-us", L"Segoe UI Symbol") |
| 44 .AddFilePath(segoe_path); | 45 .AddFilePath(segoe_path); |
| 45 | 46 |
| 46 mswr::MakeAndInitialize<DWriteFontCollectionProxy>( | 47 mswr::MakeAndInitialize<DWriteFontCollectionProxy>( |
| 47 &collection_, factory_.Get(), fake_collection_->GetSender()); | 48 &collection_, factory_.Get(), fake_collection_->GetSender()); |
| 48 } | 49 } |
| 49 | 50 |
| 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 | |
| 66 scoped_refptr<FakeFontCollection> fake_collection_; | 51 scoped_refptr<FakeFontCollection> fake_collection_; |
| 67 mswr::ComPtr<IDWriteFactory> factory_; | 52 mswr::ComPtr<IDWriteFactory> factory_; |
| 68 mswr::ComPtr<DWriteFontCollectionProxy> collection_; | 53 mswr::ComPtr<DWriteFontCollectionProxy> collection_; |
| 69 mswr::ComPtr<IDWriteNumberSubstitution> number_substitution_; | 54 mswr::ComPtr<IDWriteNumberSubstitution> number_substitution_; |
| 70 }; | 55 }; |
| 71 | 56 |
| 72 TEST_F(FontFallbackUnitTest, MapCharacters) { | 57 TEST_F(FontFallbackUnitTest, MapCharacters) { |
| 73 mswr::ComPtr<FontFallback> fallback; | 58 mswr::ComPtr<FontFallback> fallback; |
| 74 mswr::MakeAndInitialize<FontFallback>(&fallback, collection_.Get(), | 59 mswr::MakeAndInitialize<FontFallback>(&fallback, collection_.Get(), |
| 75 fake_collection_->GetSender()); | 60 fake_collection_->GetSender()); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, | 182 DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, |
| 198 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, &font, | 183 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, &font, |
| 199 &scale); | 184 &scale); |
| 200 | 185 |
| 201 EXPECT_EQ(1u, fake_collection_->MessageCount()); | 186 EXPECT_EQ(1u, fake_collection_->MessageCount()); |
| 202 EXPECT_EQ(2u, mapped_length); | 187 EXPECT_EQ(2u, mapped_length); |
| 203 } | 188 } |
| 204 | 189 |
| 205 } // namespace | 190 } // namespace |
| 206 } // namespace content | 191 } // namespace content |
| OLD | NEW |