| 1 | /* |
| 2 | * Copyright (C) 2016 Igalia S.L. All rights reserved. |
| 3 | * Copyright (C) 2016 Apple Inc. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 15 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 16 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 17 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 18 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 19 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 20 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | #pragma once |
| 28 | |
| 29 | #if ENABLE(MATHML) |
| 30 | |
| 31 | #include "GlyphPage.h" |
| 32 | #include "LayoutUnit.h" |
| 33 | #include "OpenTypeMathData.h" |
| 34 | #include "PaintInfo.h" |
| 35 | #include <unicode/utypes.h> |
| 36 | |
| 37 | namespace WebCore { |
| 38 | |
| 39 | class RenderStyle; |
| 40 | |
| 41 | class MathOperator { |
| 42 | public: |
| 43 | MathOperator(); |
| 44 | enum class Type { NormalOperator, DisplayOperator, VerticalOperator, HorizontalOperator }; |
| 45 | void setOperator(const RenderStyle&, UChar32 baseCharacter, Type); |
| 46 | void reset(const RenderStyle&); |
| 47 | |
| 48 | LayoutUnit width() const { return m_width; } |
| 49 | LayoutUnit maxPreferredWidth() const { return m_maxPreferredWidth; } |
| 50 | LayoutUnit ascent() const { return m_ascent; } |
| 51 | LayoutUnit descent() const { return m_descent; } |
| 52 | LayoutUnit italicCorrection() const { return m_italicCorrection; } |
| 53 | |
| 54 | void stretchTo(const RenderStyle&, LayoutUnit ascent, LayoutUnit descent); |
| 55 | void stretchTo(const RenderStyle&, LayoutUnit width); |
| 56 | |
| 57 | void paint(const RenderStyle&, PaintInfo&, const LayoutPoint&); |
| 58 | |
| 59 | private: |
| 60 | struct GlyphAssemblyData { |
| 61 | UChar32 topOrRightCodePoint { 0 }; |
| 62 | Glyph topOrRightFallbackGlyph { 0 }; |
| 63 | UChar32 extensionCodePoint { 0 }; |
| 64 | Glyph extensionFallbackGlyph { 0 }; |
| 65 | UChar32 bottomOrLeftCodePoint { 0 }; |
| 66 | Glyph bottomOrLeftFallbackGlyph { 0 }; |
| 67 | UChar32 middleCodePoint { 0 }; |
| 68 | Glyph middleFallbackGlyph { 0 }; |
| 69 | |
| 70 | bool hasExtension() const { return extensionCodePoint || extensionFallbackGlyph; } |
| 71 | bool hasMiddle() const { return middleCodePoint || middleFallbackGlyph; } |
| 72 | void initialize(); |
| 73 | }; |
| 74 | enum class StretchType { Unstretched, SizeVariant, GlyphAssembly }; |
| 75 | enum GlyphPaintTrimming { |
| 76 | TrimTop, |
| 77 | TrimBottom, |
| 78 | TrimTopAndBottom, |
| 79 | TrimLeft, |
| 80 | TrimRight, |
| 81 | TrimLeftAndRight |
| 82 | }; |
| 83 | |
| 84 | LayoutUnit stretchSize() const; |
| 85 | bool getGlyph(const RenderStyle&, UChar32 character, GlyphData&) const; |
| 86 | bool getBaseGlyph(const RenderStyle& style, GlyphData& baseGlyph) const { return getGlyph(style, m_baseCharacter, baseGlyph); } |
| 87 | void setSizeVariant(const GlyphData&); |
| 88 | void setGlyphAssembly(const RenderStyle&, const GlyphAssemblyData&); |
| 89 | void getMathVariantsWithFallback(const RenderStyle&, bool isVertical, Vector<Glyph>&, Vector<OpenTypeMathData::AssemblyPart>&); |
| 90 | void calculateDisplayStyleLargeOperator(const RenderStyle&); |
| 91 | void calculateStretchyData(const RenderStyle&, bool calculateMaxPreferredWidth, LayoutUnit targetSize = 0_lu); |
| 92 | bool calculateGlyphAssemblyFallback(const Vector<OpenTypeMathData::AssemblyPart>&, GlyphAssemblyData&) const; |
| 93 | |
| 94 | LayoutRect paintGlyph(const RenderStyle&, PaintInfo&, const GlyphData&, const LayoutPoint& origin, GlyphPaintTrimming); |
| 95 | void fillWithVerticalExtensionGlyph(const RenderStyle&, PaintInfo&, const LayoutPoint& from, const LayoutPoint& to); |
| 96 | void fillWithHorizontalExtensionGlyph(const RenderStyle&, PaintInfo&, const LayoutPoint& from, const LayoutPoint& to); |
| 97 | void paintVerticalGlyphAssembly(const RenderStyle&, PaintInfo&, const LayoutPoint&); |
| 98 | void paintHorizontalGlyphAssembly(const RenderStyle&, PaintInfo&, const LayoutPoint&); |
| 99 | |
| 100 | UChar32 m_baseCharacter { 0 }; |
| 101 | Type m_operatorType { Type::NormalOperator }; |
| 102 | StretchType m_stretchType { StretchType::Unstretched }; |
| 103 | union { |
| 104 | Glyph m_variantGlyph; |
| 105 | GlyphAssemblyData m_assembly; |
| 106 | }; |
| 107 | LayoutUnit m_maxPreferredWidth { 0 }; |
| 108 | LayoutUnit m_width { 0 }; |
| 109 | LayoutUnit m_ascent { 0 }; |
| 110 | LayoutUnit m_descent { 0 }; |
| 111 | LayoutUnit m_italicCorrection { 0 }; |
| 112 | float m_radicalVerticalScale { 1 }; |
| 113 | }; |
| 114 | |
| 115 | } |
| 116 | |
| 117 | #endif // ENABLE(MATHML) |
| 118 | |