Update configs. IGNORE BROKEN CHANGESETS CLOSED TREE NO BUG a=release ba=release
[gecko.git] / gfx / 2d / UnscaledFontFreeType.h
blob2194c8e7764a02c1059613a8187023d955c0a849
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/. */
7 #ifndef MOZILLA_GFX_UNSCALEDFONTFREETYPE_H_
8 #define MOZILLA_GFX_UNSCALEDFONTFREETYPE_H_
10 #include <cairo-ft.h>
12 #include "2D.h"
14 namespace mozilla {
15 namespace gfx {
17 class ScaledFontFreeType;
18 class ScaledFontFontconfig;
20 class UnscaledFontFreeType : public UnscaledFont {
21 public:
22 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(UnscaledFontFreeType, override)
23 explicit UnscaledFontFreeType(const RefPtr<SharedFTFace>& aFace)
24 : mFace(aFace), mIndex(0) {}
25 explicit UnscaledFontFreeType(const char* aFile, uint32_t aIndex = 0,
26 RefPtr<SharedFTFace> aFace = nullptr)
27 : mFace(std::move(aFace)), mFile(aFile), mIndex(aIndex) {}
28 explicit UnscaledFontFreeType(std::string&& aFile, uint32_t aIndex = 0,
29 RefPtr<SharedFTFace> aFace = nullptr)
30 : mFace(std::move(aFace)), mFile(std::move(aFile)), mIndex(aIndex) {}
32 FontType GetType() const override { return FontType::FREETYPE; }
34 const RefPtr<SharedFTFace>& GetFace() const { return mFace; }
35 const std::string& GetFile() const { return mFile; }
36 uint32_t GetIndex() const { return mIndex; }
38 bool GetFontFileData(FontFileDataOutput aDataCallback, void* aBaton) override;
40 bool GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton) override;
42 RefPtr<SharedFTFace> InitFace();
44 #ifdef MOZ_WIDGET_ANDROID
45 static already_AddRefed<UnscaledFont> CreateFromFontDescriptor(
46 const uint8_t* aData, uint32_t aDataLength, uint32_t aIndex);
48 already_AddRefed<ScaledFont> CreateScaledFont(
49 Float aGlyphSize, const uint8_t* aInstanceData,
50 uint32_t aInstanceDataLength, const FontVariation* aVariations,
51 uint32_t aNumVariations) override;
53 already_AddRefed<ScaledFont> CreateScaledFontFromWRFont(
54 Float aGlyphSize, const wr::FontInstanceOptions* aOptions,
55 const wr::FontInstancePlatformOptions* aPlatformOptions,
56 const FontVariation* aVariations, uint32_t aNumVariations) override;
57 #endif
59 protected:
60 RefPtr<SharedFTFace> mFace;
61 std::string mFile;
62 uint32_t mIndex;
64 friend class ScaledFontFreeType;
65 friend class ScaledFontFontconfig;
67 static void GetVariationSettingsFromFace(
68 std::vector<FontVariation>* aVariations, FT_Face aFace);
70 static void ApplyVariationsToFace(const FontVariation* aVariations,
71 uint32_t aNumVariations, FT_Face aFace);
74 #ifdef MOZ_WIDGET_GTK
75 class UnscaledFontFontconfig : public UnscaledFontFreeType {
76 public:
77 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(UnscaledFontFontconfig, override)
78 explicit UnscaledFontFontconfig(const RefPtr<SharedFTFace>& aFace)
79 : UnscaledFontFreeType(aFace) {}
80 explicit UnscaledFontFontconfig(const char* aFile, uint32_t aIndex = 0,
81 RefPtr<SharedFTFace> aFace = nullptr)
82 : UnscaledFontFreeType(aFile, aIndex, std::move(aFace)) {}
83 explicit UnscaledFontFontconfig(std::string&& aFile, uint32_t aIndex = 0,
84 RefPtr<SharedFTFace> aFace = nullptr)
85 : UnscaledFontFreeType(std::move(aFile), aIndex, std::move(aFace)) {}
87 FontType GetType() const override { return FontType::FONTCONFIG; }
89 static already_AddRefed<UnscaledFont> CreateFromFontDescriptor(
90 const uint8_t* aData, uint32_t aDataLength, uint32_t aIndex);
92 already_AddRefed<ScaledFont> CreateScaledFont(
93 Float aGlyphSize, const uint8_t* aInstanceData,
94 uint32_t aInstanceDataLength, const FontVariation* aVariations,
95 uint32_t aNumVariations) override;
97 already_AddRefed<ScaledFont> CreateScaledFontFromWRFont(
98 Float aGlyphSize, const wr::FontInstanceOptions* aOptions,
99 const wr::FontInstancePlatformOptions* aPlatformOptions,
100 const FontVariation* aVariations, uint32_t aNumVariations) override;
103 extern bool FcPatternAllowsBitmaps(FcPattern* aPattern, bool aAntialias,
104 bool aHinting);
105 #endif
107 } // namespace gfx
108 } // namespace mozilla
110 #endif /* MOZILLA_GFX_UNSCALEDFONTFREETYPE_H_ */