Index: content/common/dwrite_font_proxy_win.h |
diff --git a/content/common/dwrite_font_proxy_win.h b/content/common/dwrite_font_proxy_win.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d540e05d340ce79fdd82e8c7422726b34013056c |
--- /dev/null |
+++ b/content/common/dwrite_font_proxy_win.h |
@@ -0,0 +1,186 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_COMMON_DWRITE_FONT_PROXY_WIN_H_ |
+#define CONTENT_COMMON_DWRITE_FONT_PROXY_WIN_H_ |
+ |
+#include <dwrite.h> |
+#include <wrl.h> |
+ |
+#include <map> |
+#include <vector> |
+ |
+#include "base/callback.h" |
+#include "base/files/memory_mapped_file.h" |
+#include "base/strings/string16.h" |
+#include "content/common/content_export.h" |
+ |
+namespace mswr = Microsoft::WRL; |
+ |
+namespace IPC { |
+class Sender; |
+} |
+ |
+namespace content { |
+ |
+typedef IPC::Sender* (*GetSenderFn)(); |
+ |
+class DWriteFontFamilyProxy; |
+ |
+// Implements a direct write font collection that uses IPC to the browser to do |
jam
2015/11/03 00:18:54
this should be in content/child
content/common is
Ilya Kulshin
2015/11/03 18:56:22
Done.
|
+// font enumeration. If a matching family is found, it will be loaded locally |
+// into a custom font collection. |
+// This is needed because the sandbox interferes with direct write's |
+// communication with the system font service. |
+class CONTENT_EXPORT DWriteFontCollectionProxy |
+ : public mswr::RuntimeClass<mswr::RuntimeClassFlags<mswr::ClassicCom>, |
+ IDWriteFontCollection, |
+ IDWriteFontCollectionLoader, |
+ IDWriteFontFileLoader> { |
+ public: |
+ HRESULT STDMETHODCALLTYPE FindFamilyName(const WCHAR* familyName, |
+ UINT32* index, |
+ BOOL* exists) override; |
+ |
+ HRESULT STDMETHODCALLTYPE |
+ GetFontFamily(UINT32 index, IDWriteFontFamily** fontFamily) override; |
+ |
+ UINT32 STDMETHODCALLTYPE GetFontFamilyCount() override; |
+ |
+ HRESULT STDMETHODCALLTYPE GetFontFromFontFace(IDWriteFontFace* fontFace, |
+ IDWriteFont** font) override; |
+ |
+ HRESULT STDMETHODCALLTYPE CreateEnumeratorFromKey( |
+ IDWriteFactory* factory, |
+ const void* collectionKey, |
+ UINT32 collectionKeySize, |
+ IDWriteFontFileEnumerator** fontFileEnumerator) override; |
+ |
+ HRESULT STDMETHODCALLTYPE |
+ CreateStreamFromKey(const void* fontFileReferenceKey, |
+ uint32 fontFileReferenceKeySize, |
+ IDWriteFontFileStream** fontFileStream) override; |
+ |
+ HRESULT STDMETHODCALLTYPE |
+ RuntimeClassInitialize(IDWriteFactory* factory, |
+ const base::Callback<IPC::Sender*(void)>& getSender); |
+ |
+ void Unregister(); |
+ |
+ bool LoadFamily(unsigned int familyIndex, |
+ IDWriteFontCollection** containingCollection); |
+ |
+ bool LoadFamilyNames(unsigned int familyIndex, |
+ IDWriteLocalizedStrings** strings); |
+ |
+ bool CreateFamily(unsigned int familyIndex); |
+ |
+ private: |
+ mswr::ComPtr<IDWriteFactory> factory_; |
+ std::vector<mswr::ComPtr<DWriteFontFamilyProxy>> families_; |
+ std::map<base::string16, unsigned int> familyNames_; |
+ UINT32 familyCount_ = UINT_MAX; |
+ base::Callback<IPC::Sender*(void)> getSender_; |
+}; |
+ |
+// Implements the direct write font family interface. This class is just a |
+// stub, until something calls a method that requires actual font data. At that |
+// point this will load the font files into a custom collection and |
+// subsequently calls will be proxied to the resulting direct write object. |
+class CONTENT_EXPORT DWriteFontFamilyProxy |
+ : public mswr::RuntimeClass<mswr::RuntimeClassFlags<mswr::ClassicCom>, |
+ IDWriteFontFamily> { |
+ public: |
+ HRESULT STDMETHODCALLTYPE |
+ GetFontCollection(IDWriteFontCollection** fontCollection) override; |
+ |
+ UINT32 STDMETHODCALLTYPE GetFontCount() override; |
+ |
+ HRESULT STDMETHODCALLTYPE GetFont(UINT32 index, IDWriteFont** font) override; |
+ |
+ HRESULT STDMETHODCALLTYPE |
+ GetFamilyNames(IDWriteLocalizedStrings** names) override; |
+ |
+ HRESULT STDMETHODCALLTYPE |
+ GetFirstMatchingFont(DWRITE_FONT_WEIGHT weight, |
+ DWRITE_FONT_STRETCH stretch, |
+ DWRITE_FONT_STYLE style, |
+ IDWriteFont** matchingFont) override; |
+ |
+ HRESULT STDMETHODCALLTYPE |
+ GetMatchingFonts(DWRITE_FONT_WEIGHT weight, |
+ DWRITE_FONT_STRETCH stretch, |
+ DWRITE_FONT_STYLE style, |
+ IDWriteFontList** matchingFonts) override; |
+ |
+ HRESULT STDMETHODCALLTYPE |
+ RuntimeClassInitialize(DWriteFontCollectionProxy* collection, |
+ unsigned int index); |
+ |
+ bool GetFontFromFontFace(IDWriteFontFace* fontFace, IDWriteFont** font); |
+ |
+ void SetName(base::string16 familyName) { familyName_.assign(familyName); } |
+ |
+ bool IsLoaded() { return family_ != nullptr; } |
+ |
+ protected: |
+ bool LoadFamily(); |
+ |
+ private: |
+ unsigned int familyIndex_; |
+ base::string16 familyName_; |
+ mswr::ComPtr<DWriteFontCollectionProxy> proxyCollection_; |
+ mswr::ComPtr<IDWriteFontFamily> family_; |
+ mswr::ComPtr<IDWriteLocalizedStrings> familyNames_; |
+}; |
+ |
+// Implements the direct write font file enumerator interface, backed by a list |
+// of font files. |
+class CONTENT_EXPORT FontFileEnumerator |
+ : public mswr::RuntimeClass<mswr::RuntimeClassFlags<mswr::ClassicCom>, |
+ IDWriteFontFileEnumerator> { |
+ public: |
+ HRESULT STDMETHODCALLTYPE GetCurrentFontFile(IDWriteFontFile** file) override; |
+ |
+ HRESULT STDMETHODCALLTYPE MoveNext(BOOL* hasCurrentFile) override; |
+ |
+ HRESULT STDMETHODCALLTYPE |
+ RuntimeClassInitialize(IDWriteFactory* factory, |
+ IDWriteFontFileLoader* loader, |
+ std::vector<base::string16>* fileNames); |
+ |
+ private: |
+ mswr::ComPtr<IDWriteFactory> factory_; |
+ mswr::ComPtr<IDWriteFontFileLoader> loader_; |
+ std::vector<base::string16> fileNames_; |
+ std::vector<mswr::ComPtr<IDWriteFontFileStream>> fileStreams_; |
+ unsigned int nextFile_ = 0; |
+ unsigned int currentFile_ = UINT_MAX; |
+}; |
+ |
+// Implements the direct write font file stream interface that maps the file to |
+// be loaded as a memory mapped file, and subsequently returns pointers into |
+// the mapped memory block. |
+// TODO(kulshin): confirm that using custom streams is actually an improvement |
+class CONTENT_EXPORT FontFileStream |
+ : public mswr::RuntimeClass<mswr::RuntimeClassFlags<mswr::ClassicCom>, |
+ IDWriteFontFileStream> { |
+ public: |
+ HRESULT STDMETHODCALLTYPE GetFileSize(UINT64* fileSize) override; |
+ HRESULT STDMETHODCALLTYPE GetLastWriteTime(UINT64* lastWriteTime) override; |
+ HRESULT STDMETHODCALLTYPE ReadFileFragment(const void** fragmentStart, |
+ UINT64 fileOffset, |
+ UINT64 fragmentSize, |
+ void** fragmentContext) override; |
+ void STDMETHODCALLTYPE ReleaseFileFragment(void* fragmentContext) override {} |
+ |
+ HRESULT STDMETHODCALLTYPE |
+ RuntimeClassInitialize(const base::string16& fileName); |
+ |
+ private: |
+ base::MemoryMappedFile data_; |
+}; |
+ |
+} // namespace content |
+#endif // CONTENT_COMMON_DWRITE_FONT_PROXY_WIN_H_ |