Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(697)

Side by Side Diff: content/child/dwrite_font_proxy/font_fallback_win.cc

Issue 1846433005: Implement direct write fallback proxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Style fixes Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 (FAILED(source->GetTextAtPosition(text_position, &text, &chunk_length))) {
36 DCHECK(false);
37 return E_FAIL;
38 }
39 base::string16 text_chunk(text, chunk_length);
40
41 const WCHAR* locale = nullptr;
42 // |locale_text_length| is actually the length of text with the locale, not
43 // the length of the locale string itself.
44 UINT32 locale_text_length = 0;
45 source->GetLocaleName(text_position /*textPosition*/, &locale_text_length,
46 &locale);
47
48 if (locale == nullptr)
49 locale = L"";
50
51 DWriteFontStyle style;
52 style.font_weight = base_weight;
53 style.font_slant = base_style;
54 style.font_stretch = base_stretch;
55
56 MapCharactersResult result;
57
58 IPC::Sender* sender =
59 sender_override_ ? sender_override_ : ChildThread::Get();
60 if (!sender->Send(new DWriteFontProxyMsg_MapCharacters(
61 text_chunk, style, locale, source->GetParagraphReadingDirection(),
62 base_family_name ? base_family_name : L"", &result)))
63 return E_FAIL;
64
65 *mapped_length = result.mapped_length;
66 *scale = result.scale;
67
68 if (result.family_index == UINT32_MAX)
69 return S_OK;
70
71 mswr::ComPtr<IDWriteFontFamily> family;
72 // It would be nice to find a way to determine at runtime if |collection_| is
73 // a proxy collection, or just a generic IDWriteFontCollection. Unfortunately
74 // I can't find a way to get QueryInterface to return the actual class when
75 // using mswr::RuntimeClass. If we could use QI, we can fallback on
76 // FindFontFamily if the proxy is not available.
77 if (!collection_->GetFontFamily(result.family_index, result.family_name,
78 &family)) {
79 DCHECK(false);
80 return E_FAIL;
81 }
82
83 if (FAILED(family->GetFirstMatchingFont(
84 static_cast<DWRITE_FONT_WEIGHT>(result.font_style.font_weight),
85 static_cast<DWRITE_FONT_STRETCH>(result.font_style.font_stretch),
86 static_cast<DWRITE_FONT_STYLE>(result.font_style.font_slant),
87 mapped_font))) {
88 DCHECK(false);
89 return E_FAIL;
90 }
91
92 DCHECK(*mapped_font);
93
94 return S_OK;
95 }
96
97 HRESULT STDMETHODCALLTYPE
98 FontFallback::RuntimeClassInitialize(DWriteFontCollectionProxy* collection,
99 IPC::Sender* sender_override) {
100 sender_override_ = sender_override;
101 collection_ = collection;
102 return S_OK;
103 }
104
105 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698