OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/child/dwrite_font_proxy/font_fallback_win.h" | |
6 | |
7 #include "base/strings/string16.h" | |
8 | |
9 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_win.h" | |
10 #include "content/common/dwrite_font_proxy_messages.h" | |
11 #include "content/public/child/child_thread.h" | |
12 #include "ipc/ipc_sender.h" | |
13 | |
14 namespace mswr = Microsoft::WRL; | |
15 | |
16 namespace content { | |
17 | |
18 HRESULT FontFallback::MapCharacters(IDWriteTextAnalysisSource* source, | |
19 UINT32 text_position, | |
20 UINT32 text_length, | |
21 IDWriteFontCollection* base_font_collection, | |
22 const wchar_t* base_family_name, | |
23 DWRITE_FONT_WEIGHT base_weight, | |
24 DWRITE_FONT_STYLE base_style, | |
25 DWRITE_FONT_STRETCH base_stretch, | |
26 UINT32* mapped_length, | |
27 IDWriteFont** mapped_font, | |
28 FLOAT* scale) { | |
29 *mapped_font = nullptr; | |
30 *mapped_length = 1; | |
31 *scale = 1.0; | |
32 | |
33 const WCHAR* text = nullptr; | |
34 UINT32 chunk_length = 0; | |
35 if (!SUCCEEDED( | |
ananta
2016/04/12 23:44:39
Please change to if (FAILED. Easier to read
Ilya Kulshin
2016/04/13 01:33:28
Done.
| |
36 source->GetTextAtPosition(text_position, &text, &chunk_length))) { | |
37 DCHECK(false); | |
38 return E_FAIL; | |
39 } | |
40 base::string16 text_chunk(text, chunk_length); | |
41 | |
42 const WCHAR* locale = nullptr; | |
43 // |locale_text_length| is actually the length of text with the locale, not | |
44 // the length of the locale string itself. | |
45 UINT32 locale_text_length = 0; | |
46 source->GetLocaleName(text_position /*textPosition*/, &locale_text_length, | |
47 &locale); | |
48 | |
49 if (locale == nullptr) | |
50 locale = L""; | |
51 | |
52 DWriteFontStyle style; | |
53 style.font_weight = base_weight; | |
54 style.font_slant = base_style; | |
55 style.font_stretch = base_stretch; | |
56 | |
57 MapCharactersResult result; | |
58 | |
59 IPC::Sender* sender = | |
60 sender_override_ ? sender_override_ : ChildThread::Get(); | |
61 if (!sender->Send(new DWriteFontProxyMsg_MapCharacters( | |
62 text_chunk, style, locale, source->GetParagraphReadingDirection(), | |
63 base_family_name ? base_family_name : L"", &result))) | |
64 return E_FAIL; | |
65 | |
66 *mapped_length = result.mapped_length; | |
67 *scale = result.scale; | |
68 | |
69 if (result.family_index == UINT32_MAX) | |
70 return S_OK; | |
71 | |
72 mswr::ComPtr<IDWriteFontFamily> family; | |
73 // It would be nice to find a way to determine at runtime if |collection_| is | |
74 // a proxy collection, or just a generic IDWriteFontCollection. Unfortunately | |
75 // I can't find a way to get QueryInterface to return the actual class when | |
76 // using mswr::RuntimeClass. If we could use QI, we can fallback on | |
77 // FindFontFamily if the proxy is not available. | |
78 if (!collection_->GetFontFamily(result.family_index, result.family_name, | |
79 &family)) { | |
80 DCHECK(false); | |
81 return E_FAIL; | |
82 } | |
83 | |
84 if (!SUCCEEDED(family->GetFirstMatchingFont( | |
ananta
2016/04/12 23:44:39
Please change to if (FAILED
Ilya Kulshin
2016/04/13 01:33:28
Done.
| |
85 static_cast<DWRITE_FONT_WEIGHT>(result.font_style.font_weight), | |
86 static_cast<DWRITE_FONT_STRETCH>(result.font_style.font_stretch), | |
87 static_cast<DWRITE_FONT_STYLE>(result.font_style.font_slant), | |
88 mapped_font))) { | |
89 DCHECK(false); | |
90 return E_FAIL; | |
91 } | |
92 | |
93 DCHECK(*mapped_font); | |
94 | |
95 return S_OK; | |
96 } | |
97 | |
98 } // namespace content | |
OLD | NEW |