Line data Source code
1 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef MOZILLA_GFX_UNSCALEDFONTFREETYPE_H_
7 : #define MOZILLA_GFX_UNSCALEDFONTFREETYPE_H_
8 :
9 : #include <cairo-ft.h>
10 :
11 : #include "2D.h"
12 :
13 : namespace mozilla {
14 : namespace gfx {
15 :
16 : class UnscaledFontFreeType : public UnscaledFont
17 : {
18 : public:
19 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(UnscaledFontFreeType, override)
20 0 : explicit UnscaledFontFreeType(FT_Face aFace,
21 : bool aOwnsFace = false)
22 0 : : mFace(aFace)
23 : , mOwnsFace(aOwnsFace)
24 0 : , mIndex(0)
25 0 : {}
26 6 : explicit UnscaledFontFreeType(const char* aFile,
27 : uint32_t aIndex = 0)
28 6 : : mFace(nullptr)
29 : , mOwnsFace(false)
30 : , mFile(aFile)
31 6 : , mIndex(aIndex)
32 6 : {}
33 0 : ~UnscaledFontFreeType()
34 0 : {
35 0 : if (mOwnsFace) {
36 0 : Factory::ReleaseFTFace(mFace);
37 : }
38 0 : }
39 :
40 0 : FontType GetType() const override { return FontType::FREETYPE; }
41 :
42 0 : FT_Face GetFace() const { return mFace; }
43 2 : const char* GetFile() const { return mFile.c_str(); }
44 2 : uint32_t GetIndex() const { return mIndex; }
45 :
46 : struct FontDescriptor
47 : {
48 : uint32_t mPathLength;
49 : uint32_t mIndex;
50 : };
51 :
52 : bool GetFontFileData(FontFileDataOutput aDataCallback, void* aBaton) override;
53 :
54 : bool GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton) override;
55 :
56 : private:
57 : FT_Face mFace;
58 : bool mOwnsFace;
59 : std::string mFile;
60 : uint32_t mIndex;
61 : };
62 :
63 : #ifdef MOZ_WIDGET_GTK
64 0 : class UnscaledFontFontconfig : public UnscaledFontFreeType
65 : {
66 : public:
67 151 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(UnscaledFontFontconfig, override)
68 0 : explicit UnscaledFontFontconfig(FT_Face aFace,
69 : bool aOwnsFace = false)
70 0 : : UnscaledFontFreeType(aFace, aOwnsFace)
71 0 : {}
72 6 : explicit UnscaledFontFontconfig(const char* aFile,
73 : uint32_t aIndex = 0)
74 6 : : UnscaledFontFreeType(aFile, aIndex)
75 6 : {}
76 0 : UnscaledFontFontconfig(FT_Face aFace,
77 : NativeFontResource* aNativeFontResource)
78 0 : : UnscaledFontFreeType(aFace, false)
79 0 : , mNativeFontResource(aNativeFontResource)
80 0 : {}
81 :
82 0 : FontType GetType() const override { return FontType::FONTCONFIG; }
83 :
84 : static already_AddRefed<UnscaledFont>
85 : CreateFromFontDescriptor(const uint8_t* aData, uint32_t aDataLength);
86 :
87 : already_AddRefed<ScaledFont>
88 : CreateScaledFont(Float aGlyphSize,
89 : const uint8_t* aInstanceData,
90 : uint32_t aInstanceDataLength) override;
91 :
92 : private:
93 : RefPtr<NativeFontResource> mNativeFontResource;
94 : };
95 : #endif
96 :
97 : } // namespace gfx
98 : } // namespace mozilla
99 :
100 : #endif /* MOZILLA_GFX_UNSCALEDFONTFREETYPE_H_ */
101 :
|