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_SCALEDFONTFONTCONFIG_H_ 8 #define MOZILLA_GFX_SCALEDFONTFONTCONFIG_H_ 9 10 #include "ScaledFontBase.h" 11 12 #include <cairo-ft.h> 13 14 namespace mozilla { 15 namespace gfx { 16 17 class NativeFontResourceFontconfig; 18 class UnscaledFontFontconfig; 19 20 class ScaledFontFontconfig : public ScaledFontBase { 21 public: 22 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ScaledFontFontconfig, override) 23 ScaledFontFontconfig(cairo_scaled_font_t* aScaledFont, FcPattern* aPattern, 24 const RefPtr<UnscaledFont>& aUnscaledFont, Float aSize); 25 ~ScaledFontFontconfig(); 26 GetType()27 FontType GetType() const override { return FontType::FONTCONFIG; } 28 29 #ifdef USE_SKIA 30 SkTypeface* GetSkTypeface() override; 31 #endif 32 CanSerialize()33 bool CanSerialize() override { return true; } 34 35 bool GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton) override; 36 37 bool GetWRFontInstanceOptions( 38 Maybe<wr::FontInstanceOptions>* aOutOptions, 39 Maybe<wr::FontInstancePlatformOptions>* aOutPlatformOptions, 40 std::vector<FontVariation>* aOutVariations) override; 41 42 private: 43 friend class NativeFontResourceFontconfig; 44 friend class UnscaledFontFontconfig; 45 46 struct InstanceData { 47 enum { 48 ANTIALIAS = 1 << 0, 49 AUTOHINT = 1 << 1, 50 EMBEDDED_BITMAP = 1 << 2, 51 EMBOLDEN = 1 << 3, 52 VERTICAL_LAYOUT = 1 << 4, 53 HINT_METRICS = 1 << 5 54 }; 55 56 InstanceData(cairo_scaled_font_t* aScaledFont, FcPattern* aPattern); 57 58 void SetupPattern(FcPattern* aPattern) const; 59 void SetupFontOptions(cairo_font_options_t* aFontOptions) const; 60 void SetupFontMatrix(cairo_matrix_t* aFontMatrix) const; 61 62 uint8_t mFlags; 63 uint8_t mHintStyle; 64 uint8_t mSubpixelOrder; 65 uint8_t mLcdFilter; 66 Float mScale; 67 Float mSkew; 68 }; 69 70 static already_AddRefed<ScaledFont> CreateFromInstanceData( 71 const InstanceData& aInstanceData, UnscaledFontFontconfig* aUnscaledFont, 72 Float aSize, NativeFontResource* aNativeFontResource = nullptr); 73 74 FcPattern* mPattern; 75 }; 76 77 } // namespace gfx 78 } // namespace mozilla 79 80 #endif /* MOZILLA_GFX_SCALEDFONTFONTCONFIG_H_ */ 81