2 * Copyright (C) 2016 Igalia S.L. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef MathOperator_h
27 #define MathOperator_h
30 #include "GlyphPage.h"
31 #include "LayoutUnit.h"
32 #include "OpenTypeMathData.h"
33 #include "PaintInfo.h"
34 #include <unicode/utypes.h>
43 enum class Type { UndefinedOperator, DisplayOperator, VerticalOperator, HorizontalOperator };
44 void setOperator(const RenderStyle&, UChar baseCharacter, Type);
45 void reset(const RenderStyle&);
47 LayoutUnit width() const { return m_width; }
48 LayoutUnit maxPreferredWidth() const { return m_maxPreferredWidth; }
49 LayoutUnit ascent() const { return m_ascent; }
50 LayoutUnit descent() const { return m_descent; }
51 LayoutUnit italicCorrection() const { return m_italicCorrection; }
53 void stretchTo(const RenderStyle&, LayoutUnit ascent, LayoutUnit descent);
54 void stretchTo(const RenderStyle&, LayoutUnit width);
55 bool isStretched() const { return m_stretchType != StretchType::Unstretched || m_radicalVerticalScale > 1; }
56 void unstretch() { m_stretchType = StretchType::Unstretched; }
58 void paint(const RenderStyle&, PaintInfo&, const LayoutPoint&);
61 struct GlyphAssemblyData {
64 GlyphData bottomOrLeft;
67 enum class StretchType { Unstretched, SizeVariant, GlyphAssembly };
68 enum GlyphPaintTrimming {
77 LayoutUnit stretchSize() const;
78 bool getBaseGlyph(const RenderStyle&, GlyphData&) const;
79 void setSizeVariant(const GlyphData&);
80 void setGlyphAssembly(const GlyphAssemblyData&);
81 void calculateDisplayStyleLargeOperator(const RenderStyle&);
82 void calculateStretchyData(const RenderStyle&, bool calculateMaxPreferredWidth, LayoutUnit targetSize = 0);
83 bool calculateGlyphAssemblyFallback(const RenderStyle&, const Vector<OpenTypeMathData::AssemblyPart>&, GlyphAssemblyData&) const;
85 LayoutRect paintGlyph(const RenderStyle&, PaintInfo&, const GlyphData&, const LayoutPoint& origin, GlyphPaintTrimming);
86 void fillWithVerticalExtensionGlyph(const RenderStyle&, PaintInfo&, const LayoutPoint& from, const LayoutPoint& to);
87 void fillWithHorizontalExtensionGlyph(const RenderStyle&, PaintInfo&, const LayoutPoint& from, const LayoutPoint& to);
88 void paintVerticalGlyphAssembly(const RenderStyle&, PaintInfo&, const LayoutPoint&);
89 void paintHorizontalGlyphAssembly(const RenderStyle&, PaintInfo&, const LayoutPoint&);
91 UChar m_baseCharacter { 0 };
92 Type m_operatorType { Type::UndefinedOperator };
93 StretchType m_stretchType { StretchType::Unstretched };
96 GlyphAssemblyData m_assembly;
98 LayoutUnit m_maxPreferredWidth { 0 };
99 LayoutUnit m_width { 0 };
100 LayoutUnit m_ascent { 0 };
101 LayoutUnit m_descent { 0 };
102 LayoutUnit m_italicCorrection { 0 };
103 float m_radicalVerticalScale { 1 };
108 #endif // ENABLE(MATHML)
109 #endif // MathOperator_h