#ifndef CONTENT_CHILD_DWRITE_FONT_PROXY_FONT_FALLBACK_WIN_H_
#define CONTENT_CHILD_DWRITE_FONT_PROXY_FONT_FALLBACK_WIN_H_
#include <dwrite.h>
#include <dwrite_2.h>
#include <wrl.h>
#include <list>
#include <map>
#include "content/child/dwrite_font_proxy/dwrite_font_proxy_win.h"
#include "content/common/content_export.h"
#include "third_party/blink/public/mojom/dwrite_font_proxy/dwrite_font_proxy.mojom.h"
namespace content {
class FontFallback
: public Microsoft::WRL::RuntimeClass<
Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>,
IDWriteFontFallback> {
public:
static CONTENT_EXPORT HRESULT Create(FontFallback** font_fallback_out,
DWriteFontCollectionProxy* collection);
FontFallback();
FontFallback& operator=(const FontFallback&) = delete;
HRESULT STDMETHODCALLTYPE
MapCharacters(IDWriteTextAnalysisSource* source,
UINT32 text_position,
UINT32 text_length,
IDWriteFontCollection* base_font_collection,
const wchar_t* base_family_name,
DWRITE_FONT_WEIGHT base_weight,
DWRITE_FONT_STYLE base_style,
DWRITE_FONT_STRETCH base_stretch,
UINT32* mapped_length,
IDWriteFont** mapped_font,
FLOAT* scale) override;
HRESULT STDMETHODCALLTYPE
RuntimeClassInitialize(DWriteFontCollectionProxy* collection);
protected:
~FontFallback() override;
bool GetCachedFont(const std::u16string& text,
const wchar_t* base_family_name,
const wchar_t* locale,
DWRITE_FONT_WEIGHT base_weight,
DWRITE_FONT_STYLE base_style,
DWRITE_FONT_STRETCH base_stretch,
IDWriteFont** mapped_font,
size_t* mapped_length) LOCKS_EXCLUDED(lock_);
void AddCachedFamily(Microsoft::WRL::ComPtr<IDWriteFontFamily> family,
const wchar_t* base_family_name,
const wchar_t* locale) LOCKS_EXCLUDED(lock_);
private:
blink::mojom::DWriteFontProxy& GetFontProxy();
Microsoft::WRL::ComPtr<DWriteFontCollectionProxy> collection_;
base::Lock lock_;
std::map<std::wstring, std::list<Microsoft::WRL::ComPtr<IDWriteFontFamily>>>
fallback_family_cache_ GUARDED_BY(lock_);
};
}
#endif