1/*
2 * Copyright (C) 2014 Frederic Wang (fred.wang@free.fr). All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
17 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef OpenTypeMathData_h
27#define OpenTypeMathData_h
28
29#include "Glyph.h"
30#include "SharedBuffer.h"
31#include <wtf/PassRefPtr.h>
32#include <wtf/RefCounted.h>
33#include <wtf/Vector.h>
34
35namespace WebCore {
36
37class SimpleFontData;
38class FontPlatformData;
39
40class OpenTypeMathData : public RefCounted<OpenTypeMathData> {
41public:
42    static PassRefPtr<OpenTypeMathData> create(const FontPlatformData& fontData)
43    {
44        return adoptRef(new OpenTypeMathData(fontData));
45    }
46
47    bool hasMathData() const { return m_mathBuffer; }
48
49    // These constants are defined in the MATH table.
50    // The implementation of OpenTypeMathData::getMathConstant assumes that they correspond to the indices of the MathContant table.
51    enum MathConstant {
52        ScriptPercentScaleDown,
53        ScriptScriptPercentScaleDown,
54        DelimitedSubFormulaMinHeight,
55        DisplayOperatorMinHeight,
56        MathLeading,
57        AxisHeight,
58        AccentBaseHeight,
59        FlattenedAccentBaseHeight,
60        SubscriptShiftDown,
61        SubscriptTopMax,
62        SubscriptBaselineDropMin,
63        SuperscriptShiftUp,
64        SuperscriptShiftUpCramped,
65        SuperscriptBottomMin,
66        SuperscriptBaselineDropMax,
67        SubSuperscriptGapMin,
68        SuperscriptBottomMaxWithSubscript,
69        SpaceAfterScript,
70        UpperLimitGapMin,
71        UpperLimitBaselineRiseMin,
72        LowerLimitGapMin,
73        LowerLimitBaselineDropMin,
74        StackTopShiftUp,
75        StackTopDisplayStyleShiftUp,
76        StackBottomShiftDown,
77        StackBottomDisplayStyleShiftDown,
78        StackGapMin,
79        StackDisplayStyleGapMin,
80        StretchStackTopShiftUp,
81        StretchStackBottomShiftDown,
82        StretchStackGapAboveMin,
83        StretchStackGapBelowMin,
84        FractionNumeratorShiftUp,
85        FractionNumeratorDisplayStyleShiftUp,
86        FractionDenominatorShiftDown,
87        FractionDenominatorDisplayStyleShiftDown,
88        FractionNumeratorGapMin,
89        FractionNumDisplayStyleGapMin,
90        FractionRuleThickness,
91        FractionDenominatorGapMin,
92        FractionDenomDisplayStyleGapMin,
93        SkewedFractionHorizontalGap,
94        SkewedFractionVerticalGap,
95        OverbarVerticalGap,
96        OverbarRuleThickness,
97        OverbarExtraAscender,
98        UnderbarVerticalGap,
99        UnderbarRuleThickness,
100        UnderbarExtraDescender,
101        RadicalVerticalGap,
102        RadicalDisplayStyleVerticalGap,
103        RadicalRuleThickness,
104        RadicalExtraAscender,
105        RadicalKernBeforeDegree,
106        RadicalKernAfterDegree,
107        RadicalDegreeBottomRaisePercent
108    };
109
110    struct AssemblyPart {
111        Glyph glyph;
112        bool isExtender;
113    };
114
115    float getMathConstant(const SimpleFontData*, MathConstant) const;
116    float getItalicCorrection(const SimpleFontData*, Glyph) const;
117    void getMathVariants(Glyph, bool isVertical, Vector<Glyph>& sizeVariants, Vector<AssemblyPart>& assemblyParts) const;
118
119private:
120    explicit OpenTypeMathData(const FontPlatformData&);
121    RefPtr<SharedBuffer> m_mathBuffer;
122};
123
124} // namespace WebCore
125
126#endif // OpenTypeMathData_h
127