Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 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/child/dwrite_font_proxy/font_fallback_win.h" | |
| 6 | |
| 7 #include <dwrite.h> | |
| 8 #include <shlobj.h> | |
| 9 #include <wrl.h> | |
| 10 | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_win.h" | |
| 15 #include "content/common/dwrite_text_analysis_source_win.h" | |
| 16 #include "content/test/dwrite_font_fake_sender_win.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | |
| 18 | |
| 19 namespace mswr = Microsoft::WRL; | |
| 20 | |
| 21 namespace content { | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 class FontFallbackUnitTest : public testing::Test { | |
| 26 public: | |
| 27 FontFallbackUnitTest() { | |
| 28 CreateDWriteFactory(&factory_); | |
| 29 | |
| 30 std::vector<base::char16> font_path; | |
| 31 font_path.resize(MAX_PATH); | |
| 32 SHGetSpecialFolderPath(nullptr /* hwndOwner - reserved */, font_path.data(), | |
| 33 CSIDL_FONTS, FALSE /* fCreate*/); | |
| 34 base::string16 arial; | |
| 35 arial.append(font_path.data()).append(L"\\arial.ttf"); | |
| 36 | |
| 37 fake_collection_ = new FakeFontCollection(); | |
| 38 fake_collection_->AddFont(L"Arial") | |
| 39 .AddFamilyName(L"en-us", L"Arial") | |
|
ananta
2016/04/12 23:44:39
Please split these statements up. Difficult to rea
Ilya Kulshin
2016/04/13 01:33:29
This is just using the builder pattern. I find it
| |
| 40 .AddFilePath(arial); | |
| 41 | |
| 42 mswr::MakeAndInitialize<DWriteFontCollectionProxy>( | |
| 43 &collection_, factory_.Get(), fake_collection_->GetSender()); | |
| 44 } | |
| 45 | |
| 46 void CreateDWriteFactory(IUnknown** factory) { | |
| 47 using DWriteCreateFactoryProc = decltype(DWriteCreateFactory)*; | |
| 48 HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll"); | |
| 49 if (!dwrite_dll) | |
| 50 return; | |
| 51 | |
| 52 DWriteCreateFactoryProc dwrite_create_factory_proc = | |
| 53 reinterpret_cast<DWriteCreateFactoryProc>( | |
| 54 GetProcAddress(dwrite_dll, "DWriteCreateFactory")); | |
| 55 if (!dwrite_create_factory_proc) | |
| 56 return; | |
| 57 | |
| 58 dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_SHARED, | |
| 59 __uuidof(IDWriteFactory), factory); | |
| 60 } | |
| 61 | |
| 62 scoped_refptr<FakeFontCollection> fake_collection_; | |
| 63 mswr::ComPtr<IDWriteFactory> factory_; | |
| 64 mswr::ComPtr<DWriteFontCollectionProxy> collection_; | |
| 65 }; | |
| 66 | |
| 67 TEST_F(FontFallbackUnitTest, MapCharacters) { | |
| 68 mswr::ComPtr<FontFallback> fallback; | |
| 69 mswr::MakeAndInitialize<FontFallback>(&fallback, collection_.Get(), | |
| 70 fake_collection_->GetTrackingSender()); | |
| 71 | |
| 72 mswr::ComPtr<IDWriteFont> font; | |
| 73 UINT32 mapped_length = 0; | |
| 74 float scale = 0.0; | |
| 75 | |
| 76 mswr::ComPtr<TextAnalysisSource> text; | |
| 77 mswr::MakeAndInitialize<TextAnalysisSource>( | |
| 78 &text, L"hello", L"en-us", nullptr, | |
| 79 DWRITE_READING_DIRECTION_LEFT_TO_RIGHT); | |
| 80 fallback->MapCharacters(text.Get(), 0, 1, nullptr, nullptr, | |
| 81 DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, | |
| 82 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, &font, | |
| 83 &scale); | |
| 84 | |
| 85 EXPECT_EQ(1, mapped_length); // The fake sender only maps one character | |
| 86 EXPECT_NE(nullptr, font.Get()); | |
| 87 } | |
| 88 | |
| 89 } // namespace | |
| 90 } // namespace content | |
| OLD | NEW |