OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
scottmg
2016/04/13 21:23:16
nit; no (c) (in a couple others too)
Ilya Kulshin
2016/04/13 22:31:29
Done.
| |
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 factory_->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD_NONE, | |
31 L"en-us", true /* ignoreUserOverride */, | |
32 &number_substitution_); | |
33 | |
34 std::vector<base::char16> font_path; | |
35 font_path.resize(MAX_PATH); | |
36 SHGetSpecialFolderPath(nullptr /* hwndOwner - reserved */, font_path.data(), | |
37 CSIDL_FONTS, FALSE /* fCreate*/); | |
38 base::string16 arial_path; | |
39 arial_path.append(font_path.data()).append(L"\\arial.ttf"); | |
40 | |
41 fake_collection_ = new FakeFontCollection(); | |
42 fake_collection_->AddFont(L"Arial") | |
43 .AddFamilyName(L"en-us", L"Arial") | |
44 .AddFilePath(arial_path); | |
45 | |
46 mswr::MakeAndInitialize<DWriteFontCollectionProxy>( | |
47 &collection_, factory_.Get(), fake_collection_->GetSender()); | |
48 } | |
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 | |
66 scoped_refptr<FakeFontCollection> fake_collection_; | |
67 mswr::ComPtr<IDWriteFactory> factory_; | |
68 mswr::ComPtr<DWriteFontCollectionProxy> collection_; | |
69 mswr::ComPtr<IDWriteNumberSubstitution> number_substitution_; | |
70 }; | |
71 | |
72 TEST_F(FontFallbackUnitTest, MapCharacters) { | |
73 mswr::ComPtr<FontFallback> fallback; | |
74 mswr::MakeAndInitialize<FontFallback>(&fallback, collection_.Get(), | |
75 fake_collection_->GetTrackingSender()); | |
76 | |
77 mswr::ComPtr<IDWriteFont> font; | |
78 UINT32 mapped_length = 0; | |
79 float scale = 0.0; | |
80 | |
81 mswr::ComPtr<TextAnalysisSource> text; | |
82 mswr::MakeAndInitialize<TextAnalysisSource>( | |
83 &text, L"hello", L"en-us", number_substitution_.Get(), | |
84 DWRITE_READING_DIRECTION_LEFT_TO_RIGHT); | |
85 fallback->MapCharacters(text.Get(), 0, 1, nullptr, nullptr, | |
86 DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, | |
87 DWRITE_FONT_STRETCH_NORMAL, &mapped_length, &font, | |
88 &scale); | |
89 | |
90 EXPECT_EQ(1, mapped_length); // The fake sender only maps one character | |
91 EXPECT_NE(nullptr, font.Get()); | |
92 } | |
93 | |
94 } // namespace | |
95 } // namespace content | |
OLD | NEW |