Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/gfxMathTable.h
Line
Count
Source (jump to first uncovered line)
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#ifndef GFX_MATH_TABLE_H
6
#define GFX_MATH_TABLE_H
7
8
#include "gfxFont.h"
9
10
/**
11
 * Used by |gfxFont| to represent the MATH table of an OpenType font.
12
 * Each |gfxFont| owns at most one |gfxMathTable| instance.
13
 */
14
class gfxMathTable
15
{
16
public:
17
    /**
18
     * @param aFace The HarfBuzz face containing the math table.
19
     * @param aSize The font size to pass to HarfBuzz.
20
     */
21
    gfxMathTable(hb_face_t *aFace, gfxFloat aSize);
22
23
    /**
24
     * Releases our reference to the MATH table and cleans up everything else.
25
     */
26
    ~gfxMathTable();
27
28
    enum MathConstant {
29
        // The order of the constants must match the order of the fields
30
        // defined in the MATH table.
31
        ScriptPercentScaleDown,
32
        ScriptScriptPercentScaleDown,
33
        DelimitedSubFormulaMinHeight,
34
        DisplayOperatorMinHeight,
35
        MathLeading,
36
        AxisHeight,
37
        AccentBaseHeight,
38
        FlattenedAccentBaseHeight,
39
        SubscriptShiftDown,
40
        SubscriptTopMax,
41
        SubscriptBaselineDropMin,
42
        SuperscriptShiftUp,
43
        SuperscriptShiftUpCramped,
44
        SuperscriptBottomMin,
45
        SuperscriptBaselineDropMax,
46
        SubSuperscriptGapMin,
47
        SuperscriptBottomMaxWithSubscript,
48
        SpaceAfterScript,
49
        UpperLimitGapMin,
50
        UpperLimitBaselineRiseMin,
51
        LowerLimitGapMin,
52
        LowerLimitBaselineDropMin,
53
        StackTopShiftUp,
54
        StackTopDisplayStyleShiftUp,
55
        StackBottomShiftDown,
56
        StackBottomDisplayStyleShiftDown,
57
        StackGapMin,
58
        StackDisplayStyleGapMin,
59
        StretchStackTopShiftUp,
60
        StretchStackBottomShiftDown,
61
        StretchStackGapAboveMin,
62
        StretchStackGapBelowMin,
63
        FractionNumeratorShiftUp,
64
        FractionNumeratorDisplayStyleShiftUp,
65
        FractionDenominatorShiftDown,
66
        FractionDenominatorDisplayStyleShiftDown,
67
        FractionNumeratorGapMin,
68
        FractionNumDisplayStyleGapMin,
69
        FractionRuleThickness,
70
        FractionDenominatorGapMin,
71
        FractionDenomDisplayStyleGapMin,
72
        SkewedFractionHorizontalGap,
73
        SkewedFractionVerticalGap,
74
        OverbarVerticalGap,
75
        OverbarRuleThickness,
76
        OverbarExtraAscender,
77
        UnderbarVerticalGap,
78
        UnderbarRuleThickness,
79
        UnderbarExtraDescender,
80
        RadicalVerticalGap,
81
        RadicalDisplayStyleVerticalGap,
82
        RadicalRuleThickness,
83
        RadicalExtraAscender,
84
        RadicalKernBeforeDegree,
85
        RadicalKernAfterDegree,
86
        RadicalDegreeBottomRaisePercent
87
    };
88
89
    /**
90
     * Returns the value of the specified constant from the MATH table.
91
     */
92
    gfxFloat Constant(MathConstant aConstant) const;
93
94
    /**
95
     * Returns the value of the specified constant in app units.
96
     */
97
    nscoord Constant(MathConstant aConstant,
98
                     uint32_t aAppUnitsPerDevPixel) const
99
0
    {
100
0
        return NSToCoordRound(Constant(aConstant) * aAppUnitsPerDevPixel);
101
0
    }
102
103
    /**
104
     *  If the MATH table contains an italic correction for that glyph, this
105
     *  function returns the corresponding value. Otherwise it returns 0.
106
     */
107
    gfxFloat
108
    ItalicsCorrection(uint32_t aGlyphID) const;
109
110
    /**
111
     * @param aGlyphID  glyph index of the character we want to stretch
112
     * @param aVertical direction of the stretching (vertical/horizontal)
113
     * @param aSize     the desired size variant
114
     *
115
     * Returns the glyph index of the desired size variant or 0 if there is not
116
     * any such size variant.
117
     */
118
    uint32_t VariantsSize(uint32_t aGlyphID, bool aVertical,
119
                          uint16_t aSize) const;
120
121
    /**
122
     * @param aGlyphID  glyph index of the character we want to stretch
123
     * @param aVertical direction of the stretching (vertical/horizontal)
124
     * @param aGlyphs   pre-allocated buffer of 4 elements where the glyph
125
     * indexes (or 0 for absent parts) will be stored. The parts are stored in
126
     * the order expected by the nsMathMLChar: Top (or Left), Middle, Bottom
127
     * (or Right), Glue.
128
     *
129
     * Tries to fill-in aGlyphs with the relevant glyph indexes and returns
130
     * whether the operation was successful. The function returns false if
131
     * there is not any assembly for the character we want to stretch or if
132
     * the format is not supported by the nsMathMLChar code.
133
     *
134
     */
135
    bool VariantsParts(uint32_t aGlyphID, bool aVertical,
136
                       uint32_t aGlyphs[4]) const;
137
138
private:
139
    // size-specific font object, owned by the gfxMathTable
140
    hb_font_t *mHBFont;
141
142
    static const unsigned int kMaxCachedSizeCount = 10;
143
    struct MathVariantCacheEntry {
144
      uint32_t glyphID;
145
      bool vertical;
146
      uint32_t sizes[kMaxCachedSizeCount];
147
      uint32_t parts[4];
148
      bool arePartsValid;
149
    };
150
    mutable MathVariantCacheEntry mMathVariantCache;
151
    void ClearCache() const;
152
    void UpdateMathVariantCache(uint32_t aGlyphID, bool aVertical) const;
153
};
154
155
#endif