| Index: content/child/dwrite_font_proxy/dwrite_font_proxy_win.h
|
| diff --git a/content/child/dwrite_font_proxy/dwrite_font_proxy_win.h b/content/child/dwrite_font_proxy/dwrite_font_proxy_win.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..481ccf86e847ac29aec1aa6387402da7c6e3bac4
|
| --- /dev/null
|
| +++ b/content/child/dwrite_font_proxy/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_CHILD_DWRITE_FONT_PROXY_DWRITE_FONT_PROXY_WIN_H_
|
| +#define CONTENT_CHILD_DWRITE_FONT_PROXY_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
|
| +// 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)>& sender);
|
| +
|
| + void Unregister();
|
| +
|
| + bool LoadFamily(unsigned int family_index,
|
| + IDWriteFontCollection** containing_collection);
|
| +
|
| + bool LoadFamilyNames(unsigned int family_index,
|
| + IDWriteLocalizedStrings** strings);
|
| +
|
| + bool CreateFamily(unsigned int family_index);
|
| +
|
| + private:
|
| + mswr::ComPtr<IDWriteFactory> factory_;
|
| + std::vector<mswr::ComPtr<DWriteFontFamilyProxy>> families_;
|
| + std::map<base::string16, unsigned int> family_names_;
|
| + UINT32 family_count_ = UINT_MAX;
|
| + base::Callback<IPC::Sender*(void)> sender_;
|
| +};
|
| +
|
| +// 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* font_face, IDWriteFont** font);
|
| +
|
| + void SetName(base::string16 family_name) { family_name_.assign(family_name); }
|
| +
|
| + bool IsLoaded() { return family_ != nullptr; }
|
| +
|
| + protected:
|
| + bool LoadFamily();
|
| +
|
| + private:
|
| + unsigned int family_index_;
|
| + base::string16 family_name_;
|
| + mswr::ComPtr<DWriteFontCollectionProxy> proxy_collection_;
|
| + mswr::ComPtr<IDWriteFontFamily> family_;
|
| + mswr::ComPtr<IDWriteLocalizedStrings> family_names_;
|
| +};
|
| +
|
| +// 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>* file_names);
|
| +
|
| + private:
|
| + mswr::ComPtr<IDWriteFactory> factory_;
|
| + mswr::ComPtr<IDWriteFontFileLoader> loader_;
|
| + std::vector<base::string16> file_names_;
|
| + std::vector<mswr::ComPtr<IDWriteFontFileStream>> file_streams_;
|
| + unsigned int next_file_ = 0;
|
| + unsigned int current_file_ = 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& file_name);
|
| +
|
| + private:
|
| + base::MemoryMappedFile data_;
|
| +};
|
| +
|
| +} // namespace content
|
| +#endif // CONTENT_CHILD_DWRITE_FONT_PROXY_DWRITE_FONT_PROXY_WIN_H_
|
|
|