1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef MOZILLA_GFX_UNSCALEDFONTDWRITE_H_
8 #define MOZILLA_GFX_UNSCALEDFONTDWRITE_H_
9 
10 #include <dwrite.h>
11 
12 #include "2D.h"
13 
14 namespace mozilla {
15 namespace gfx {
16 
17 class ScaledFontDWrite;
18 
19 class UnscaledFontDWrite final : public UnscaledFont {
20  public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(UnscaledFontDWrite,override)21   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(UnscaledFontDWrite, override)
22   UnscaledFontDWrite(const RefPtr<IDWriteFontFace>& aFontFace,
23                      const RefPtr<IDWriteFont>& aFont)
24       : mFontFace(aFontFace), mFont(aFont) {}
25 
GetType()26   FontType GetType() const override { return FontType::DWRITE; }
27 
GetFontFace()28   const RefPtr<IDWriteFontFace>& GetFontFace() const { return mFontFace; }
GetFont()29   const RefPtr<IDWriteFont>& GetFont() const { return mFont; }
30 
31   bool GetFontFileData(FontFileDataOutput aDataCallback, void* aBaton) override;
32 
33   already_AddRefed<ScaledFont> CreateScaledFont(
34       Float aGlyphSize, const uint8_t* aInstanceData,
35       uint32_t aInstanceDataLength, const FontVariation* aVariations,
36       uint32_t aNumVariations) override;
37 
38   already_AddRefed<ScaledFont> CreateScaledFontFromWRFont(
39       Float aGlyphSize, const wr::FontInstanceOptions* aOptions,
40       const wr::FontInstancePlatformOptions* aPlatformOptions,
41       const FontVariation* aVariations, uint32_t aNumVariations) override;
42 
43   bool GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton) override;
44 
45   static already_AddRefed<UnscaledFont> CreateFromFontDescriptor(
46       const uint8_t* aData, uint32_t aDataLength, uint32_t aIndex);
47 
48  private:
49   bool InitBold();
50 
51   RefPtr<IDWriteFontFace> mFontFace;
52   RefPtr<IDWriteFontFace> mFontFaceBold;
53   RefPtr<IDWriteFont> mFont;
54 };
55 
56 }  // namespace gfx
57 }  // namespace mozilla
58 
59 #endif /* MOZILLA_GFX_UNSCALEDFONTDWRITE_H_ */
60