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