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_NativeFontResourceFreeType_h
8 #define mozilla_gfx_NativeFontResourceFreeType_h
9 
10 #include "2D.h"
11 
12 #include <cairo-ft.h>
13 #include "mozilla/UniquePtr.h"
14 
15 namespace mozilla {
16 namespace gfx {
17 
18 class NativeFontResourceFreeType
19     : public NativeFontResource,
20       public SharedFTFaceRefCountedData<NativeFontResourceFreeType> {
21  public:
22   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(NativeFontResourceFreeType, override)
23 
24 #ifdef MOZ_WIDGET_ANDROID
25   static already_AddRefed<NativeFontResourceFreeType> Create(
26       uint8_t* aFontData, uint32_t aDataLength,
27       FT_Library aFTLibrary = nullptr);
28 
29   already_AddRefed<UnscaledFont> CreateUnscaledFont(
30       uint32_t aIndex, const uint8_t* aInstanceData,
31       uint32_t aInstanceDataLength) override;
32 #endif
33 
34   ~NativeFontResourceFreeType();
35 
36   already_AddRefed<SharedFTFace> CloneFace(int aFaceIndex = 0) override;
37 
38  protected:
39   NativeFontResourceFreeType(UniquePtr<uint8_t[]>&& aFontData,
40                              uint32_t aDataLength,
41                              FT_Library aFTLibrary = nullptr);
42 
43   template <class T>
44   static already_AddRefed<T> CreateInternal(uint8_t* aFontData,
45                                             uint32_t aDataLength,
46                                             FT_Library aFTLibrary);
47 
48   UniquePtr<uint8_t[]> mFontData;
49   uint32_t mDataLength;
50   FT_Library mFTLibrary;
51 };
52 
53 #ifdef MOZ_WIDGET_GTK
54 class NativeFontResourceFontconfig final : public NativeFontResourceFreeType {
55  public:
56   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(NativeFontResourceFontconfig,
57                                           override)
58 
59   static already_AddRefed<NativeFontResourceFontconfig> Create(
60       uint8_t* aFontData, uint32_t aDataLength,
61       FT_Library aFTLibrary = nullptr);
62 
63   already_AddRefed<UnscaledFont> CreateUnscaledFont(
64       uint32_t aIndex, const uint8_t* aInstanceData,
65       uint32_t aInstanceDataLength) final;
66 
67  private:
68   friend class NativeFontResourceFreeType;
69 
70   NativeFontResourceFontconfig(UniquePtr<uint8_t[]>&& aFontData,
71                                uint32_t aDataLength,
72                                FT_Library aFTLibrary = nullptr);
73 };
74 #endif
75 
76 }  // namespace gfx
77 }  // namespace mozilla
78 
79 #endif  // mozilla_gfx_NativeFontResourceFreeType_h
80