gfxFT2Utils.h (2552B)
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 GFX_FT2UTILS_H 7 #define GFX_FT2UTILS_H 8 9 #include "cairo-ft.h" 10 #include "gfxFT2FontBase.h" 11 12 // Rounding and truncation functions for a FreeType fixed point number 13 // (FT26Dot6) stored in a 32bit integer with high 26 bits for the integer 14 // part and low 6 bits for the fractional part. 15 #define FLOAT_FROM_26_6(x) ((x) / 64.0) 16 #define FLOAT_FROM_16_16(x) ((x) / 65536.0) 17 #define ROUND_26_6_TO_INT(x) ((x) >= 0 ? ((32 + (x)) >> 6) : -((32 - (x)) >> 6)) 18 19 typedef struct FT_FaceRec_* FT_Face; 20 21 /** 22 * BEWARE: Recursively locking with gfxFT2LockedFace is not supported. 23 * Do not instantiate gfxFT2LockedFace within the scope of another instance. 24 * Do not attempt to call into Cairo within the scope of gfxFT2LockedFace, 25 * as that may accidentally try to re-lock the face within Cairo itself 26 * and thus deadlock. 27 */ 28 class MOZ_STACK_CLASS gfxFT2LockedFace { 29 public: 30 explicit gfxFT2LockedFace(const gfxFT2FontBase* aFont) 31 : mGfxFont(aFont), mFace(aFont->LockFTFace()) {} 32 ~gfxFT2LockedFace() { 33 if (mFace) { 34 mGfxFont->UnlockFTFace(); 35 } 36 } 37 38 FT_Face get() { return mFace; }; 39 40 /** 41 * Get the glyph id for a Unicode character representable by a single 42 * glyph, or return zero if there is no such glyph. This does no caching, 43 * so you probably want gfxFcFont::GetGlyph. 44 */ 45 uint32_t GetGlyph(uint32_t aCharCode); 46 /** 47 * Returns 0 if there is no variation selector cmap subtable. 48 */ 49 uint32_t GetUVSGlyph(uint32_t aCharCode, uint32_t aVariantSelector); 50 51 protected: 52 typedef FT_UInt (*CharVariantFunction)(FT_Face face, FT_ULong charcode, 53 FT_ULong variantSelector); 54 CharVariantFunction FindCharVariantFunction(); 55 56 const gfxFT2FontBase* MOZ_NON_OWNING_REF mGfxFont; // owned by caller 57 FT_Face mFace; 58 }; 59 60 // A couple of FreeType-based utilities shared by gfxFontconfigFontEntry 61 // and FT2FontEntry. 62 63 typedef struct FT_MM_Var_ FT_MM_Var; 64 65 class gfxFT2Utils { 66 public: 67 static void GetVariationAxes(const FT_MM_Var* aMMVar, 68 nsTArray<gfxFontVariationAxis>& aAxes); 69 70 static void GetVariationInstances( 71 gfxFontEntry* aFontEntry, const FT_MM_Var* aMMVar, 72 nsTArray<gfxFontVariationInstance>& aInstances); 73 }; 74 75 #endif /* GFX_FT2UTILS_H */